Skip to main content

cimstructs/
SynchronousMachineDynamics.rs

1/// Synchronous machine whose behaviour is described by reference to a standard model expressed in one of the following forms: - simplified (or classical), where a group of generators or motors is not modelled in detail; - detailed, in equivalent circuit form; - detailed, in time constant reactance form; or - by definition of a user-defined model. It is a common practice to represent small generators by a negative load rather than by a dynamic generator model when performing dynamics simulations. In this case, a SynchronousMachine in the static model is not represented by anything in the dynamics model, instead it is treated as an ordinary load. Parameter details: Synchronous machine parameters such as Xl, Xd, Xp etc. are actually used as inductances in the models, but are commonly referred to as reactances since, at nominal frequency, the PU values are the same. However, some references use the symbol L instead of X.
2#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]
3pub struct SynchronousMachineDynamics {
4    #[serde(flatten)]
5    pub base: super::RotatingMachineDynamics,
6    /// Synchronous machine to which synchronous machine dynamics model applies.
7    #[serde(skip_serializing_if = "Option::is_none")]
8    pub synchronous_machine: Option<super::base::MridRef>,
9}
10impl crate::base::CimElement for SynchronousMachineDynamics {
11    fn mrid(&self) -> &str { &self.base.base.base.id }
12    fn type_name(&self) -> &'static str { "SynchronousMachineDynamics" }
13    fn as_any(&self) -> &dyn std::any::Any { self }
14    fn to_json_value(&self) -> serde_json::Value {
15        serde_json::to_value(self).unwrap_or(serde_json::Value::Null)
16    }
17    fn to_block(&self) -> crate::base::RdfBlock {
18        let mut block = self.base.to_block();
19        block.type_name = "SynchronousMachineDynamics".to_string();
20        if let Some(ref v) = self.synchronous_machine {
21            block.fields.insert("SynchronousMachineDynamics.SynchronousMachine".into(), crate::base::FieldValue::Resource(v.mrid.clone()));
22        }
23        block
24    }
25}
26
27impl SynchronousMachineDynamics {
28    pub fn from_block(b: &crate::base::RdfBlock) -> Self {
29        let mut obj = Self::default();
30        obj.base.base.base.id.clone_from(&b.mrid);
31        for (key, val) in &b.fields {
32            match key.as_str() {
33                "SynchronousMachineDynamics.SynchronousMachine" => {
34                    if let crate::base::FieldValue::Resource(sv) = val {
35                        obj.synchronous_machine = Some(crate::base::MridRef { mrid: sv.clone() });
36                    }
37                }
38                "RotatingMachineDynamics.damping" => {
39                    match val {
40                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.base.damping = Some(v); } }
41                        crate::base::FieldValue::TextList(svs) => {
42                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.base.damping = Some(v); } }
43                        }
44                        _ => {}
45                    }
46                }
47                "RotatingMachineDynamics.inertia" => {
48                    match val {
49                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.base.inertia = Some(v); } }
50                        crate::base::FieldValue::TextList(svs) => {
51                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.base.inertia = Some(v); } }
52                        }
53                        _ => {}
54                    }
55                }
56                "RotatingMachineDynamics.saturationFactor" => {
57                    match val {
58                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.base.saturation_factor = Some(v); } }
59                        crate::base::FieldValue::TextList(svs) => {
60                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.base.saturation_factor = Some(v); } }
61                        }
62                        _ => {}
63                    }
64                }
65                "RotatingMachineDynamics.saturationFactor120" => {
66                    match val {
67                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.base.saturation_factor120 = Some(v); } }
68                        crate::base::FieldValue::TextList(svs) => {
69                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.base.saturation_factor120 = Some(v); } }
70                        }
71                        _ => {}
72                    }
73                }
74                "RotatingMachineDynamics.statorLeakageReactance" => {
75                    match val {
76                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.base.stator_leakage_reactance = Some(v); } }
77                        crate::base::FieldValue::TextList(svs) => {
78                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.base.stator_leakage_reactance = Some(v); } }
79                        }
80                        _ => {}
81                    }
82                }
83                "RotatingMachineDynamics.statorResistance" => {
84                    match val {
85                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.base.stator_resistance = Some(v); } }
86                        crate::base::FieldValue::TextList(svs) => {
87                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.base.stator_resistance = Some(v); } }
88                        }
89                        _ => {}
90                    }
91                }
92                "DynamicsFunctionBlock.enabled" => {
93                    match val {
94                        crate::base::FieldValue::Text(sv) => { obj.base.base.enabled = Some(sv.trim() == "true"); }
95                        crate::base::FieldValue::TextList(svs) => {
96                            if let Some(sv) = svs.last() { obj.base.base.enabled = Some(sv.trim() == "true"); }
97                        }
98                        _ => {}
99                    }
100                }
101                "IdentifiedObject.description" => {
102                    match val {
103                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.description = sv.clone(); }
104                        crate::base::FieldValue::TextList(svs) => {
105                            if let Some(sv) = svs.last() { obj.base.base.base.description = sv.clone(); }
106                        }
107                        _ => {}
108                    }
109                }
110                "IdentifiedObject.energyIdentCodeEic" => {
111                    match val {
112                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.energy_ident_code_eic = sv.clone(); }
113                        crate::base::FieldValue::TextList(svs) => {
114                            if let Some(sv) = svs.last() { obj.base.base.base.energy_ident_code_eic = sv.clone(); }
115                        }
116                        _ => {}
117                    }
118                }
119                "IdentifiedObject.mRID" => {
120                    match val {
121                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.m_rid = sv.clone(); }
122                        crate::base::FieldValue::TextList(svs) => {
123                            if let Some(sv) = svs.last() { obj.base.base.base.m_rid = sv.clone(); }
124                        }
125                        _ => {}
126                    }
127                }
128                "IdentifiedObject.name" => {
129                    match val {
130                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.name = sv.clone(); }
131                        crate::base::FieldValue::TextList(svs) => {
132                            if let Some(sv) = svs.last() { obj.base.base.base.name = sv.clone(); }
133                        }
134                        _ => {}
135                    }
136                }
137                "IdentifiedObject.shortName" => {
138                    match val {
139                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.short_name = sv.clone(); }
140                        crate::base::FieldValue::TextList(svs) => {
141                            if let Some(sv) = svs.last() { obj.base.base.base.short_name = sv.clone(); }
142                        }
143                        _ => {}
144                    }
145                }
146                _ => {}
147            }
148        }
149        obj
150    }
151}