Skip to main content

cimstructs/
RatioTapChanger.rs

1/// A tap changer that changes the voltage ratio impacting the voltage magnitude but not the phase angle across the transformer. Angle sign convention (general): Positive value indicates a positive phase shift from the winding where the tap is located to the other winding (for a two-winding transformer).
2#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]
3pub struct RatioTapChanger {
4    #[serde(flatten)]
5    pub base: super::TapChanger,
6    /// The tap ratio table for this ratio tap changer.
7    #[serde(skip_serializing_if = "Option::is_none")]
8    pub ratio_tap_changer_table: Option<super::base::MridRef>,
9    /// Transformer end to which this ratio tap changer belongs.
10    #[serde(skip_serializing_if = "Option::is_none")]
11    pub transformer_end: Option<super::base::MridRef>,
12    /// Tap step increment, in per cent of rated voltage of the power transformer end, per step position. When the increment is negative, the voltage decreases when the tap step increases.
13    #[serde(skip_serializing_if = "Option::is_none")]
14    pub step_voltage_increment: Option<f64>,
15}
16impl crate::base::CimElement for RatioTapChanger {
17    fn mrid(&self) -> &str { &self.base.base.base.id }
18    fn type_name(&self) -> &'static str { "RatioTapChanger" }
19    fn as_any(&self) -> &dyn std::any::Any { self }
20    fn to_json_value(&self) -> serde_json::Value {
21        serde_json::to_value(self).unwrap_or(serde_json::Value::Null)
22    }
23    fn to_block(&self) -> crate::base::RdfBlock {
24        let mut block = self.base.to_block();
25        block.type_name = "RatioTapChanger".to_string();
26        if let Some(ref v) = self.ratio_tap_changer_table {
27            block.fields.insert("RatioTapChanger.RatioTapChangerTable".into(), crate::base::FieldValue::Resource(v.mrid.clone()));
28        }
29        if let Some(ref v) = self.transformer_end {
30            block.fields.insert("RatioTapChanger.TransformerEnd".into(), crate::base::FieldValue::Resource(v.mrid.clone()));
31        }
32        if let Some(v) = self.step_voltage_increment {
33            block.fields.insert("RatioTapChanger.stepVoltageIncrement".into(), crate::base::FieldValue::Text(v.to_string()));
34        }
35        block
36    }
37}
38
39impl RatioTapChanger {
40    pub fn from_block(b: &crate::base::RdfBlock) -> Self {
41        let mut obj = Self::default();
42        obj.base.base.base.id.clone_from(&b.mrid);
43        for (key, val) in &b.fields {
44            match key.as_str() {
45                "RatioTapChanger.RatioTapChangerTable" => {
46                    if let crate::base::FieldValue::Resource(sv) = val {
47                        obj.ratio_tap_changer_table = Some(crate::base::MridRef { mrid: sv.clone() });
48                    }
49                }
50                "RatioTapChanger.TransformerEnd" => {
51                    if let crate::base::FieldValue::Resource(sv) = val {
52                        obj.transformer_end = Some(crate::base::MridRef { mrid: sv.clone() });
53                    }
54                }
55                "RatioTapChanger.stepVoltageIncrement" => {
56                    match val {
57                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.step_voltage_increment = Some(v); } }
58                        crate::base::FieldValue::TextList(svs) => {
59                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.step_voltage_increment = Some(v); } }
60                        }
61                        _ => {}
62                    }
63                }
64                "TapChanger.TapChangerControl" => {
65                    if let crate::base::FieldValue::Resource(sv) = val {
66                        obj.base.tap_changer_control = Some(crate::base::MridRef { mrid: sv.clone() });
67                    }
68                }
69                "TapChanger.controlEnabled" => {
70                    match val {
71                        crate::base::FieldValue::Text(sv) => { obj.base.control_enabled = Some(sv.trim() == "true"); }
72                        crate::base::FieldValue::TextList(svs) => {
73                            if let Some(sv) = svs.last() { obj.base.control_enabled = Some(sv.trim() == "true"); }
74                        }
75                        _ => {}
76                    }
77                }
78                "TapChanger.highStep" => {
79                    match val {
80                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.base.high_step = Some(v); } }
81                        crate::base::FieldValue::TextList(svs) => {
82                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.base.high_step = Some(v); } }
83                        }
84                        _ => {}
85                    }
86                }
87                "TapChanger.lowStep" => {
88                    match val {
89                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.base.low_step = Some(v); } }
90                        crate::base::FieldValue::TextList(svs) => {
91                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.base.low_step = Some(v); } }
92                        }
93                        _ => {}
94                    }
95                }
96                "TapChanger.ltcFlag" => {
97                    match val {
98                        crate::base::FieldValue::Text(sv) => { obj.base.ltc_flag = Some(sv.trim() == "true"); }
99                        crate::base::FieldValue::TextList(svs) => {
100                            if let Some(sv) = svs.last() { obj.base.ltc_flag = Some(sv.trim() == "true"); }
101                        }
102                        _ => {}
103                    }
104                }
105                "TapChanger.neutralStep" => {
106                    match val {
107                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.base.neutral_step = Some(v); } }
108                        crate::base::FieldValue::TextList(svs) => {
109                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.base.neutral_step = Some(v); } }
110                        }
111                        _ => {}
112                    }
113                }
114                "TapChanger.neutralU" => {
115                    match val {
116                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.base.neutral_u = Some(v); } }
117                        crate::base::FieldValue::TextList(svs) => {
118                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.base.neutral_u = Some(v); } }
119                        }
120                        _ => {}
121                    }
122                }
123                "TapChanger.normalStep" => {
124                    match val {
125                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.base.normal_step = Some(v); } }
126                        crate::base::FieldValue::TextList(svs) => {
127                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.base.normal_step = Some(v); } }
128                        }
129                        _ => {}
130                    }
131                }
132                "TapChanger.step" => {
133                    match val {
134                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.base.step = Some(v); } }
135                        crate::base::FieldValue::TextList(svs) => {
136                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.base.step = Some(v); } }
137                        }
138                        _ => {}
139                    }
140                }
141                "IdentifiedObject.description" => {
142                    match val {
143                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.description = sv.clone(); }
144                        crate::base::FieldValue::TextList(svs) => {
145                            if let Some(sv) = svs.last() { obj.base.base.base.description = sv.clone(); }
146                        }
147                        _ => {}
148                    }
149                }
150                "IdentifiedObject.energyIdentCodeEic" => {
151                    match val {
152                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.energy_ident_code_eic = sv.clone(); }
153                        crate::base::FieldValue::TextList(svs) => {
154                            if let Some(sv) = svs.last() { obj.base.base.base.energy_ident_code_eic = sv.clone(); }
155                        }
156                        _ => {}
157                    }
158                }
159                "IdentifiedObject.mRID" => {
160                    match val {
161                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.m_rid = sv.clone(); }
162                        crate::base::FieldValue::TextList(svs) => {
163                            if let Some(sv) = svs.last() { obj.base.base.base.m_rid = sv.clone(); }
164                        }
165                        _ => {}
166                    }
167                }
168                "IdentifiedObject.name" => {
169                    match val {
170                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.name = sv.clone(); }
171                        crate::base::FieldValue::TextList(svs) => {
172                            if let Some(sv) = svs.last() { obj.base.base.base.name = sv.clone(); }
173                        }
174                        _ => {}
175                    }
176                }
177                "IdentifiedObject.shortName" => {
178                    match val {
179                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.short_name = sv.clone(); }
180                        crate::base::FieldValue::TextList(svs) => {
181                            if let Some(sv) = svs.last() { obj.base.base.base.short_name = sv.clone(); }
182                        }
183                        _ => {}
184                    }
185                }
186                _ => {}
187            }
188        }
189        obj
190    }
191}