Skip to main content

cimstructs/
NonlinearShuntCompensatorPoint.rs

1/// A non linear shunt compensator bank or section admittance value. The number of NonlinearShuntCompenstorPoint instances associated with a NonlinearShuntCompensator shall be equal to ShuntCompensator.maximumSections. ShuntCompensator.sections shall only be set to one of the NonlinearShuntCompenstorPoint.sectionNumber. There is no interpolation between NonlinearShuntCompenstorPoint-s.
2#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]
3pub struct NonlinearShuntCompensatorPoint {
4    pub id: String,
5    /// Non-linear shunt compensator owning this point.
6    #[serde(skip_serializing_if = "Option::is_none")]
7    pub nonlinear_shunt_compensator: Option<super::base::MridRef>,
8    /// Positive sequence shunt (charging) susceptance per section.
9    #[serde(skip_serializing_if = "Option::is_none")]
10    pub b: Option<f64>,
11    /// Zero sequence shunt (charging) susceptance per section.
12    #[serde(skip_serializing_if = "Option::is_none")]
13    pub b0: Option<f64>,
14    /// Positive sequence shunt (charging) conductance per section.
15    #[serde(skip_serializing_if = "Option::is_none")]
16    pub g: Option<f64>,
17    /// Zero sequence shunt (charging) conductance per section.
18    #[serde(skip_serializing_if = "Option::is_none")]
19    pub g0: Option<f64>,
20    /// The number of the section.
21    #[serde(skip_serializing_if = "Option::is_none")]
22    pub section_number: Option<i64>,
23}
24impl crate::base::CimElement for NonlinearShuntCompensatorPoint {
25    fn mrid(&self) -> &str { &self.id }
26    fn type_name(&self) -> &'static str { "NonlinearShuntCompensatorPoint" }
27    fn as_any(&self) -> &dyn std::any::Any { self }
28    fn to_json_value(&self) -> serde_json::Value {
29        serde_json::to_value(self).unwrap_or(serde_json::Value::Null)
30    }
31    fn to_block(&self) -> crate::base::RdfBlock {
32        let mut block = crate::base::RdfBlock {
33            type_name: "NonlinearShuntCompensatorPoint".to_string(),
34            mrid: self.id.clone(),
35            fields: std::collections::HashMap::new(),
36            duplicate_fields: std::collections::HashSet::new(),
37        };
38        if let Some(ref v) = self.nonlinear_shunt_compensator {
39            block.fields.insert("NonlinearShuntCompensatorPoint.NonlinearShuntCompensator".into(), crate::base::FieldValue::Resource(v.mrid.clone()));
40        }
41        if let Some(v) = self.b {
42            block.fields.insert("NonlinearShuntCompensatorPoint.b".into(), crate::base::FieldValue::Text(v.to_string()));
43        }
44        if let Some(v) = self.b0 {
45            block.fields.insert("NonlinearShuntCompensatorPoint.b0".into(), crate::base::FieldValue::Text(v.to_string()));
46        }
47        if let Some(v) = self.g {
48            block.fields.insert("NonlinearShuntCompensatorPoint.g".into(), crate::base::FieldValue::Text(v.to_string()));
49        }
50        if let Some(v) = self.g0 {
51            block.fields.insert("NonlinearShuntCompensatorPoint.g0".into(), crate::base::FieldValue::Text(v.to_string()));
52        }
53        if let Some(v) = self.section_number {
54            block.fields.insert("NonlinearShuntCompensatorPoint.sectionNumber".into(), crate::base::FieldValue::Text(v.to_string()));
55        }
56        block
57    }
58}
59
60impl NonlinearShuntCompensatorPoint {
61    pub fn from_block(b: &crate::base::RdfBlock) -> Self {
62        let mut obj = Self::default();
63        obj.id.clone_from(&b.mrid);
64        for (key, val) in &b.fields {
65            match key.as_str() {
66                "NonlinearShuntCompensatorPoint.NonlinearShuntCompensator" => {
67                    if let crate::base::FieldValue::Resource(sv) = val {
68                        obj.nonlinear_shunt_compensator = Some(crate::base::MridRef { mrid: sv.clone() });
69                    }
70                }
71                "NonlinearShuntCompensatorPoint.b" => {
72                    match val {
73                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.b = Some(v); } }
74                        crate::base::FieldValue::TextList(svs) => {
75                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.b = Some(v); } }
76                        }
77                        _ => {}
78                    }
79                }
80                "NonlinearShuntCompensatorPoint.b0" => {
81                    match val {
82                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.b0 = Some(v); } }
83                        crate::base::FieldValue::TextList(svs) => {
84                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.b0 = Some(v); } }
85                        }
86                        _ => {}
87                    }
88                }
89                "NonlinearShuntCompensatorPoint.g" => {
90                    match val {
91                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.g = Some(v); } }
92                        crate::base::FieldValue::TextList(svs) => {
93                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.g = Some(v); } }
94                        }
95                        _ => {}
96                    }
97                }
98                "NonlinearShuntCompensatorPoint.g0" => {
99                    match val {
100                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.g0 = Some(v); } }
101                        crate::base::FieldValue::TextList(svs) => {
102                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.g0 = Some(v); } }
103                        }
104                        _ => {}
105                    }
106                }
107                "NonlinearShuntCompensatorPoint.sectionNumber" => {
108                    match val {
109                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.section_number = Some(v); } }
110                        crate::base::FieldValue::TextList(svs) => {
111                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.section_number = Some(v); } }
112                        }
113                        _ => {}
114                    }
115                }
116                _ => {}
117            }
118        }
119        obj
120    }
121}