Skip to main content

cimstructs/
MutualCoupling.rs

1/// This class represents the zero sequence line mutual coupling.
2#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]
3pub struct MutualCoupling {
4    #[serde(flatten)]
5    pub base: super::IdentifiedObject,
6    /// The starting terminal for the calculation of distances along the first branch of the mutual coupling. Normally MutualCoupling would only be used for terminals of AC line segments. The first and second terminals of a mutual coupling should point to different AC line segments.
7    #[serde(skip_serializing_if = "Option::is_none")]
8    pub first_terminal: Option<super::base::MridRef>,
9    /// The starting terminal for the calculation of distances along the second branch of the mutual coupling.
10    #[serde(skip_serializing_if = "Option::is_none")]
11    pub second_terminal: Option<super::base::MridRef>,
12    /// Zero sequence mutual coupling shunt (charging) susceptance, uniformly distributed, of the entire line section.
13    #[serde(skip_serializing_if = "Option::is_none")]
14    pub b0ch: Option<f64>,
15    /// Distance to the start of the coupled region from the first line's terminal having sequence number equal to 1.
16    #[serde(skip_serializing_if = "Option::is_none")]
17    pub distance11: Option<f64>,
18    /// Distance to the end of the coupled region from the first line's terminal with sequence number equal to 1.
19    #[serde(skip_serializing_if = "Option::is_none")]
20    pub distance12: Option<f64>,
21    /// Distance to the start of coupled region from the second line's terminal with sequence number equal to 1.
22    #[serde(skip_serializing_if = "Option::is_none")]
23    pub distance21: Option<f64>,
24    /// Distance to the end of coupled region from the second line's terminal with sequence number equal to 1.
25    #[serde(skip_serializing_if = "Option::is_none")]
26    pub distance22: Option<f64>,
27    /// Zero sequence mutual coupling shunt (charging) conductance, uniformly distributed, of the entire line section.
28    #[serde(skip_serializing_if = "Option::is_none")]
29    pub g0ch: Option<f64>,
30    /// Zero sequence branch-to-branch mutual impedance coupling, resistance.
31    #[serde(skip_serializing_if = "Option::is_none")]
32    pub r0: Option<f64>,
33    /// Zero sequence branch-to-branch mutual impedance coupling, reactance.
34    #[serde(skip_serializing_if = "Option::is_none")]
35    pub x0: Option<f64>,
36}
37impl crate::base::CimElement for MutualCoupling {
38    fn mrid(&self) -> &str { &self.base.id }
39    fn type_name(&self) -> &'static str { "MutualCoupling" }
40    fn as_any(&self) -> &dyn std::any::Any { self }
41    fn to_json_value(&self) -> serde_json::Value {
42        serde_json::to_value(self).unwrap_or(serde_json::Value::Null)
43    }
44    fn to_block(&self) -> crate::base::RdfBlock {
45        let mut block = self.base.to_block();
46        block.type_name = "MutualCoupling".to_string();
47        if let Some(ref v) = self.first_terminal {
48            block.fields.insert("MutualCoupling.First_Terminal".into(), crate::base::FieldValue::Resource(v.mrid.clone()));
49        }
50        if let Some(ref v) = self.second_terminal {
51            block.fields.insert("MutualCoupling.Second_Terminal".into(), crate::base::FieldValue::Resource(v.mrid.clone()));
52        }
53        if let Some(v) = self.b0ch {
54            block.fields.insert("MutualCoupling.b0ch".into(), crate::base::FieldValue::Text(v.to_string()));
55        }
56        if let Some(v) = self.distance11 {
57            block.fields.insert("MutualCoupling.distance11".into(), crate::base::FieldValue::Text(v.to_string()));
58        }
59        if let Some(v) = self.distance12 {
60            block.fields.insert("MutualCoupling.distance12".into(), crate::base::FieldValue::Text(v.to_string()));
61        }
62        if let Some(v) = self.distance21 {
63            block.fields.insert("MutualCoupling.distance21".into(), crate::base::FieldValue::Text(v.to_string()));
64        }
65        if let Some(v) = self.distance22 {
66            block.fields.insert("MutualCoupling.distance22".into(), crate::base::FieldValue::Text(v.to_string()));
67        }
68        if let Some(v) = self.g0ch {
69            block.fields.insert("MutualCoupling.g0ch".into(), crate::base::FieldValue::Text(v.to_string()));
70        }
71        if let Some(v) = self.r0 {
72            block.fields.insert("MutualCoupling.r0".into(), crate::base::FieldValue::Text(v.to_string()));
73        }
74        if let Some(v) = self.x0 {
75            block.fields.insert("MutualCoupling.x0".into(), crate::base::FieldValue::Text(v.to_string()));
76        }
77        block
78    }
79}
80
81impl MutualCoupling {
82    pub fn from_block(b: &crate::base::RdfBlock) -> Self {
83        let mut obj = Self::default();
84        obj.base.id.clone_from(&b.mrid);
85        for (key, val) in &b.fields {
86            match key.as_str() {
87                "MutualCoupling.First_Terminal" => {
88                    if let crate::base::FieldValue::Resource(sv) = val {
89                        obj.first_terminal = Some(crate::base::MridRef { mrid: sv.clone() });
90                    }
91                }
92                "MutualCoupling.Second_Terminal" => {
93                    if let crate::base::FieldValue::Resource(sv) = val {
94                        obj.second_terminal = Some(crate::base::MridRef { mrid: sv.clone() });
95                    }
96                }
97                "MutualCoupling.b0ch" => {
98                    match val {
99                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.b0ch = Some(v); } }
100                        crate::base::FieldValue::TextList(svs) => {
101                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.b0ch = Some(v); } }
102                        }
103                        _ => {}
104                    }
105                }
106                "MutualCoupling.distance11" => {
107                    match val {
108                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.distance11 = Some(v); } }
109                        crate::base::FieldValue::TextList(svs) => {
110                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.distance11 = Some(v); } }
111                        }
112                        _ => {}
113                    }
114                }
115                "MutualCoupling.distance12" => {
116                    match val {
117                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.distance12 = Some(v); } }
118                        crate::base::FieldValue::TextList(svs) => {
119                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.distance12 = Some(v); } }
120                        }
121                        _ => {}
122                    }
123                }
124                "MutualCoupling.distance21" => {
125                    match val {
126                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.distance21 = Some(v); } }
127                        crate::base::FieldValue::TextList(svs) => {
128                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.distance21 = Some(v); } }
129                        }
130                        _ => {}
131                    }
132                }
133                "MutualCoupling.distance22" => {
134                    match val {
135                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.distance22 = Some(v); } }
136                        crate::base::FieldValue::TextList(svs) => {
137                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.distance22 = Some(v); } }
138                        }
139                        _ => {}
140                    }
141                }
142                "MutualCoupling.g0ch" => {
143                    match val {
144                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.g0ch = Some(v); } }
145                        crate::base::FieldValue::TextList(svs) => {
146                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.g0ch = Some(v); } }
147                        }
148                        _ => {}
149                    }
150                }
151                "MutualCoupling.r0" => {
152                    match val {
153                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.r0 = Some(v); } }
154                        crate::base::FieldValue::TextList(svs) => {
155                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.r0 = Some(v); } }
156                        }
157                        _ => {}
158                    }
159                }
160                "MutualCoupling.x0" => {
161                    match val {
162                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.x0 = Some(v); } }
163                        crate::base::FieldValue::TextList(svs) => {
164                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.x0 = Some(v); } }
165                        }
166                        _ => {}
167                    }
168                }
169                "IdentifiedObject.description" => {
170                    match val {
171                        crate::base::FieldValue::Text(sv) => { obj.base.description = sv.clone(); }
172                        crate::base::FieldValue::TextList(svs) => {
173                            if let Some(sv) = svs.last() { obj.base.description = sv.clone(); }
174                        }
175                        _ => {}
176                    }
177                }
178                "IdentifiedObject.energyIdentCodeEic" => {
179                    match val {
180                        crate::base::FieldValue::Text(sv) => { obj.base.energy_ident_code_eic = sv.clone(); }
181                        crate::base::FieldValue::TextList(svs) => {
182                            if let Some(sv) = svs.last() { obj.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.m_rid = sv.clone(); }
190                        crate::base::FieldValue::TextList(svs) => {
191                            if let Some(sv) = svs.last() { obj.base.m_rid = sv.clone(); }
192                        }
193                        _ => {}
194                    }
195                }
196                "IdentifiedObject.name" => {
197                    match val {
198                        crate::base::FieldValue::Text(sv) => { obj.base.name = sv.clone(); }
199                        crate::base::FieldValue::TextList(svs) => {
200                            if let Some(sv) = svs.last() { obj.base.name = sv.clone(); }
201                        }
202                        _ => {}
203                    }
204                }
205                "IdentifiedObject.shortName" => {
206                    match val {
207                        crate::base::FieldValue::Text(sv) => { obj.base.short_name = sv.clone(); }
208                        crate::base::FieldValue::TextList(svs) => {
209                            if let Some(sv) = svs.last() { obj.base.short_name = sv.clone(); }
210                        }
211                        _ => {}
212                    }
213                }
214                _ => {}
215            }
216        }
217        obj
218    }
219}