Skip to main content

cimstructs/
TapChanger.rs

1/// Mechanism for changing transformer winding tap positions.
2#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]
3pub struct TapChanger {
4    #[serde(flatten)]
5    pub base: super::PowerSystemResource,
6    /// The regulating control scheme in which this tap changer participates.
7    #[serde(skip_serializing_if = "Option::is_none")]
8    pub tap_changer_control: Option<super::base::MridRef>,
9    /// Specifies the regulation status of the equipment. True is regulating, false is not regulating.
10    #[serde(skip_serializing_if = "Option::is_none")]
11    pub control_enabled: Option<bool>,
12    /// Highest possible tap step position, advance from neutral. The attribute shall be greater than lowStep.
13    #[serde(skip_serializing_if = "Option::is_none")]
14    pub high_step: Option<i64>,
15    /// Lowest possible tap step position, retard from neutral.
16    #[serde(skip_serializing_if = "Option::is_none")]
17    pub low_step: Option<i64>,
18    /// Specifies whether or not a TapChanger has load tap changing capabilities.
19    #[serde(skip_serializing_if = "Option::is_none")]
20    pub ltc_flag: Option<bool>,
21    /// The neutral tap step position for this winding. The attribute shall be equal to or greater than lowStep and equal or less than highStep. It is the step position where the voltage is neutralU when the other terminals of the transformer are at the ratedU. If there are other tap changers on the transformer those taps are kept constant at their neutralStep.
22    #[serde(skip_serializing_if = "Option::is_none")]
23    pub neutral_step: Option<i64>,
24    /// Voltage at which the winding operates at the neutral tap setting. It is the voltage at the terminal of the PowerTransformerEnd associated with the tap changer when all tap changers on the transformer are at their neutralStep position. Normally neutralU of the tap changer is the same as ratedU of the PowerTransformerEnd, but it can differ in special cases such as when the tapping mechanism is separate from the winding more common on lower voltage transformers. This attribute is not relevant for PhaseTapChangerAsymmetrical, PhaseTapChangerSymmetrical and PhaseTapChangerLinear.
25    #[serde(skip_serializing_if = "Option::is_none")]
26    pub neutral_u: Option<f64>,
27    /// The tap step position used in 'normal' network operation for this winding. For a 'Fixed' tap changer indicates the current physical tap setting. The attribute shall be equal to or greater than lowStep and equal to or less than highStep.
28    #[serde(skip_serializing_if = "Option::is_none")]
29    pub normal_step: Option<i64>,
30    /// Tap changer position. Starting step for a steady state solution. Non integer values are allowed to support continuous tap variables. The reasons for continuous value are to support study cases where no discrete tap changer has yet been designed, a solution where a narrow voltage band forces the tap step to oscillate or to accommodate for a continuous solution as input. The attribute shall be equal to or greater than lowStep and equal to or less than highStep.
31    #[serde(skip_serializing_if = "Option::is_none")]
32    pub step: Option<f64>,
33}
34impl crate::base::CimElement for TapChanger {
35    fn mrid(&self) -> &str { &self.base.base.id }
36    fn type_name(&self) -> &'static str { "TapChanger" }
37    fn as_any(&self) -> &dyn std::any::Any { self }
38    fn to_json_value(&self) -> serde_json::Value {
39        serde_json::to_value(self).unwrap_or(serde_json::Value::Null)
40    }
41    fn to_block(&self) -> crate::base::RdfBlock {
42        let mut block = self.base.to_block();
43        block.type_name = "TapChanger".to_string();
44        if let Some(ref v) = self.tap_changer_control {
45            block.fields.insert("TapChanger.TapChangerControl".into(), crate::base::FieldValue::Resource(v.mrid.clone()));
46        }
47        if let Some(v) = self.control_enabled {
48            block.fields.insert("TapChanger.controlEnabled".into(), crate::base::FieldValue::Text(v.to_string()));
49        }
50        if let Some(v) = self.high_step {
51            block.fields.insert("TapChanger.highStep".into(), crate::base::FieldValue::Text(v.to_string()));
52        }
53        if let Some(v) = self.low_step {
54            block.fields.insert("TapChanger.lowStep".into(), crate::base::FieldValue::Text(v.to_string()));
55        }
56        if let Some(v) = self.ltc_flag {
57            block.fields.insert("TapChanger.ltcFlag".into(), crate::base::FieldValue::Text(v.to_string()));
58        }
59        if let Some(v) = self.neutral_step {
60            block.fields.insert("TapChanger.neutralStep".into(), crate::base::FieldValue::Text(v.to_string()));
61        }
62        if let Some(v) = self.neutral_u {
63            block.fields.insert("TapChanger.neutralU".into(), crate::base::FieldValue::Text(v.to_string()));
64        }
65        if let Some(v) = self.normal_step {
66            block.fields.insert("TapChanger.normalStep".into(), crate::base::FieldValue::Text(v.to_string()));
67        }
68        if let Some(v) = self.step {
69            block.fields.insert("TapChanger.step".into(), crate::base::FieldValue::Text(v.to_string()));
70        }
71        block
72    }
73}
74
75impl TapChanger {
76    pub fn from_block(b: &crate::base::RdfBlock) -> Self {
77        let mut obj = Self::default();
78        obj.base.base.id.clone_from(&b.mrid);
79        for (key, val) in &b.fields {
80            match key.as_str() {
81                "TapChanger.TapChangerControl" => {
82                    if let crate::base::FieldValue::Resource(sv) = val {
83                        obj.tap_changer_control = Some(crate::base::MridRef { mrid: sv.clone() });
84                    }
85                }
86                "TapChanger.controlEnabled" => {
87                    match val {
88                        crate::base::FieldValue::Text(sv) => { obj.control_enabled = Some(sv.trim() == "true"); }
89                        crate::base::FieldValue::TextList(svs) => {
90                            if let Some(sv) = svs.last() { obj.control_enabled = Some(sv.trim() == "true"); }
91                        }
92                        _ => {}
93                    }
94                }
95                "TapChanger.highStep" => {
96                    match val {
97                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.high_step = Some(v); } }
98                        crate::base::FieldValue::TextList(svs) => {
99                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.high_step = Some(v); } }
100                        }
101                        _ => {}
102                    }
103                }
104                "TapChanger.lowStep" => {
105                    match val {
106                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.low_step = Some(v); } }
107                        crate::base::FieldValue::TextList(svs) => {
108                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.low_step = Some(v); } }
109                        }
110                        _ => {}
111                    }
112                }
113                "TapChanger.ltcFlag" => {
114                    match val {
115                        crate::base::FieldValue::Text(sv) => { obj.ltc_flag = Some(sv.trim() == "true"); }
116                        crate::base::FieldValue::TextList(svs) => {
117                            if let Some(sv) = svs.last() { obj.ltc_flag = Some(sv.trim() == "true"); }
118                        }
119                        _ => {}
120                    }
121                }
122                "TapChanger.neutralStep" => {
123                    match val {
124                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.neutral_step = Some(v); } }
125                        crate::base::FieldValue::TextList(svs) => {
126                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.neutral_step = Some(v); } }
127                        }
128                        _ => {}
129                    }
130                }
131                "TapChanger.neutralU" => {
132                    match val {
133                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.neutral_u = Some(v); } }
134                        crate::base::FieldValue::TextList(svs) => {
135                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.neutral_u = Some(v); } }
136                        }
137                        _ => {}
138                    }
139                }
140                "TapChanger.normalStep" => {
141                    match val {
142                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.normal_step = Some(v); } }
143                        crate::base::FieldValue::TextList(svs) => {
144                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.normal_step = Some(v); } }
145                        }
146                        _ => {}
147                    }
148                }
149                "TapChanger.step" => {
150                    match val {
151                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.step = Some(v); } }
152                        crate::base::FieldValue::TextList(svs) => {
153                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.step = Some(v); } }
154                        }
155                        _ => {}
156                    }
157                }
158                "IdentifiedObject.description" => {
159                    match val {
160                        crate::base::FieldValue::Text(sv) => { obj.base.base.description = sv.clone(); }
161                        crate::base::FieldValue::TextList(svs) => {
162                            if let Some(sv) = svs.last() { obj.base.base.description = sv.clone(); }
163                        }
164                        _ => {}
165                    }
166                }
167                "IdentifiedObject.energyIdentCodeEic" => {
168                    match val {
169                        crate::base::FieldValue::Text(sv) => { obj.base.base.energy_ident_code_eic = sv.clone(); }
170                        crate::base::FieldValue::TextList(svs) => {
171                            if let Some(sv) = svs.last() { obj.base.base.energy_ident_code_eic = sv.clone(); }
172                        }
173                        _ => {}
174                    }
175                }
176                "IdentifiedObject.mRID" => {
177                    match val {
178                        crate::base::FieldValue::Text(sv) => { obj.base.base.m_rid = sv.clone(); }
179                        crate::base::FieldValue::TextList(svs) => {
180                            if let Some(sv) = svs.last() { obj.base.base.m_rid = sv.clone(); }
181                        }
182                        _ => {}
183                    }
184                }
185                "IdentifiedObject.name" => {
186                    match val {
187                        crate::base::FieldValue::Text(sv) => { obj.base.base.name = sv.clone(); }
188                        crate::base::FieldValue::TextList(svs) => {
189                            if let Some(sv) = svs.last() { obj.base.base.name = sv.clone(); }
190                        }
191                        _ => {}
192                    }
193                }
194                "IdentifiedObject.shortName" => {
195                    match val {
196                        crate::base::FieldValue::Text(sv) => { obj.base.base.short_name = sv.clone(); }
197                        crate::base::FieldValue::TextList(svs) => {
198                            if let Some(sv) = svs.last() { obj.base.base.short_name = sv.clone(); }
199                        }
200                        _ => {}
201                    }
202                }
203                _ => {}
204            }
205        }
206        obj
207    }
208}