Skip to main content

cimstructs/
SeriesCompensator.rs

1/// A Series Compensator is a series capacitor or reactor or an AC transmission line without charging susceptance. It is a two terminal device.
2#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]
3pub struct SeriesCompensator {
4    #[serde(flatten)]
5    pub base: super::ConductingEquipment,
6    /// Positive sequence resistance.
7    #[serde(skip_serializing_if = "Option::is_none")]
8    pub r: Option<f64>,
9    /// Zero sequence resistance.
10    #[serde(skip_serializing_if = "Option::is_none")]
11    pub r0: Option<f64>,
12    /// Describe if a metal oxide varistor (mov) for over voltage protection is configured in parallel with the series compensator. It is used for short circuit calculations.
13    #[serde(skip_serializing_if = "Option::is_none")]
14    pub varistor_present: Option<bool>,
15    /// The maximum current the varistor is designed to handle at specified duration. It is used for short circuit calculations and exchanged only if SeriesCompensator.varistorPresent is true. The attribute shall be a positive value.
16    #[serde(skip_serializing_if = "Option::is_none")]
17    pub varistor_rated_current: Option<f64>,
18    /// The dc voltage at which the varistor starts conducting. It is used for short circuit calculations and exchanged only if SeriesCompensator.varistorPresent is true.
19    #[serde(skip_serializing_if = "Option::is_none")]
20    pub varistor_voltage_threshold: Option<f64>,
21    /// Positive sequence reactance.
22    #[serde(skip_serializing_if = "Option::is_none")]
23    pub x: Option<f64>,
24    /// Zero sequence reactance.
25    #[serde(skip_serializing_if = "Option::is_none")]
26    pub x0: Option<f64>,
27}
28impl crate::base::CimElement for SeriesCompensator {
29    fn mrid(&self) -> &str { &self.base.base.base.base.id }
30    fn type_name(&self) -> &'static str { "SeriesCompensator" }
31    fn as_any(&self) -> &dyn std::any::Any { self }
32    fn to_json_value(&self) -> serde_json::Value {
33        serde_json::to_value(self).unwrap_or(serde_json::Value::Null)
34    }
35    fn to_block(&self) -> crate::base::RdfBlock {
36        let mut block = self.base.to_block();
37        block.type_name = "SeriesCompensator".to_string();
38        if let Some(v) = self.r {
39            block.fields.insert("SeriesCompensator.r".into(), crate::base::FieldValue::Text(v.to_string()));
40        }
41        if let Some(v) = self.r0 {
42            block.fields.insert("SeriesCompensator.r0".into(), crate::base::FieldValue::Text(v.to_string()));
43        }
44        if let Some(v) = self.varistor_present {
45            block.fields.insert("SeriesCompensator.varistorPresent".into(), crate::base::FieldValue::Text(v.to_string()));
46        }
47        if let Some(v) = self.varistor_rated_current {
48            block.fields.insert("SeriesCompensator.varistorRatedCurrent".into(), crate::base::FieldValue::Text(v.to_string()));
49        }
50        if let Some(v) = self.varistor_voltage_threshold {
51            block.fields.insert("SeriesCompensator.varistorVoltageThreshold".into(), crate::base::FieldValue::Text(v.to_string()));
52        }
53        if let Some(v) = self.x {
54            block.fields.insert("SeriesCompensator.x".into(), crate::base::FieldValue::Text(v.to_string()));
55        }
56        if let Some(v) = self.x0 {
57            block.fields.insert("SeriesCompensator.x0".into(), crate::base::FieldValue::Text(v.to_string()));
58        }
59        block
60    }
61}
62
63impl SeriesCompensator {
64    pub fn from_block(b: &crate::base::RdfBlock) -> Self {
65        let mut obj = Self::default();
66        obj.base.base.base.base.id.clone_from(&b.mrid);
67        for (key, val) in &b.fields {
68            match key.as_str() {
69                "SeriesCompensator.r" => {
70                    match val {
71                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.r = Some(v); } }
72                        crate::base::FieldValue::TextList(svs) => {
73                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.r = Some(v); } }
74                        }
75                        _ => {}
76                    }
77                }
78                "SeriesCompensator.r0" => {
79                    match val {
80                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.r0 = Some(v); } }
81                        crate::base::FieldValue::TextList(svs) => {
82                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.r0 = Some(v); } }
83                        }
84                        _ => {}
85                    }
86                }
87                "SeriesCompensator.varistorPresent" => {
88                    match val {
89                        crate::base::FieldValue::Text(sv) => { obj.varistor_present = Some(sv.trim() == "true"); }
90                        crate::base::FieldValue::TextList(svs) => {
91                            if let Some(sv) = svs.last() { obj.varistor_present = Some(sv.trim() == "true"); }
92                        }
93                        _ => {}
94                    }
95                }
96                "SeriesCompensator.varistorRatedCurrent" => {
97                    match val {
98                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.varistor_rated_current = Some(v); } }
99                        crate::base::FieldValue::TextList(svs) => {
100                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.varistor_rated_current = Some(v); } }
101                        }
102                        _ => {}
103                    }
104                }
105                "SeriesCompensator.varistorVoltageThreshold" => {
106                    match val {
107                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.varistor_voltage_threshold = Some(v); } }
108                        crate::base::FieldValue::TextList(svs) => {
109                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.varistor_voltage_threshold = Some(v); } }
110                        }
111                        _ => {}
112                    }
113                }
114                "SeriesCompensator.x" => {
115                    match val {
116                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.x = Some(v); } }
117                        crate::base::FieldValue::TextList(svs) => {
118                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.x = Some(v); } }
119                        }
120                        _ => {}
121                    }
122                }
123                "SeriesCompensator.x0" => {
124                    match val {
125                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.x0 = Some(v); } }
126                        crate::base::FieldValue::TextList(svs) => {
127                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.x0 = Some(v); } }
128                        }
129                        _ => {}
130                    }
131                }
132                "ConductingEquipment.BaseVoltage" => {
133                    if let crate::base::FieldValue::Resource(sv) = val {
134                        obj.base.base_voltage = Some(crate::base::MridRef { mrid: sv.clone() });
135                    }
136                }
137                "Equipment.EquipmentContainer" => {
138                    if let crate::base::FieldValue::Resource(sv) = val {
139                        obj.base.base.equipment_container = Some(crate::base::MridRef { mrid: sv.clone() });
140                    }
141                }
142                "Equipment.aggregate" => {
143                    match val {
144                        crate::base::FieldValue::Text(sv) => { obj.base.base.aggregate = Some(sv.trim() == "true"); }
145                        crate::base::FieldValue::TextList(svs) => {
146                            if let Some(sv) = svs.last() { obj.base.base.aggregate = Some(sv.trim() == "true"); }
147                        }
148                        _ => {}
149                    }
150                }
151                "Equipment.inService" => {
152                    match val {
153                        crate::base::FieldValue::Text(sv) => { obj.base.base.in_service = Some(sv.trim() == "true"); }
154                        crate::base::FieldValue::TextList(svs) => {
155                            if let Some(sv) = svs.last() { obj.base.base.in_service = Some(sv.trim() == "true"); }
156                        }
157                        _ => {}
158                    }
159                }
160                "Equipment.normallyInService" => {
161                    match val {
162                        crate::base::FieldValue::Text(sv) => { obj.base.base.normally_in_service = Some(sv.trim() == "true"); }
163                        crate::base::FieldValue::TextList(svs) => {
164                            if let Some(sv) = svs.last() { obj.base.base.normally_in_service = Some(sv.trim() == "true"); }
165                        }
166                        _ => {}
167                    }
168                }
169                "IdentifiedObject.description" => {
170                    match val {
171                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.base.description = sv.clone(); }
172                        crate::base::FieldValue::TextList(svs) => {
173                            if let Some(sv) = svs.last() { obj.base.base.base.base.description = sv.clone(); }
174                        }
175                        _ => {}
176                    }
177                }
178                "IdentifiedObject.energyIdentCodeEic" => {
179                    match val {
180                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.base.energy_ident_code_eic = sv.clone(); }
181                        crate::base::FieldValue::TextList(svs) => {
182                            if let Some(sv) = svs.last() { obj.base.base.base.base.energy_ident_code_eic = sv.clone(); }
183                        }
184                        _ => {}
185                    }
186                }
187                "IdentifiedObject.mRID" => {
188                    match val {
189                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.base.m_rid = sv.clone(); }
190                        crate::base::FieldValue::TextList(svs) => {
191                            if let Some(sv) = svs.last() { obj.base.base.base.base.m_rid = sv.clone(); }
192                        }
193                        _ => {}
194                    }
195                }
196                "IdentifiedObject.name" => {
197                    match val {
198                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.base.name = sv.clone(); }
199                        crate::base::FieldValue::TextList(svs) => {
200                            if let Some(sv) = svs.last() { obj.base.base.base.base.name = sv.clone(); }
201                        }
202                        _ => {}
203                    }
204                }
205                "IdentifiedObject.shortName" => {
206                    match val {
207                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.base.short_name = sv.clone(); }
208                        crate::base::FieldValue::TextList(svs) => {
209                            if let Some(sv) = svs.last() { obj.base.base.base.base.short_name = sv.clone(); }
210                        }
211                        _ => {}
212                    }
213                }
214                _ => {}
215            }
216        }
217        obj
218    }
219}