Skip to main content

cimstructs/
SynchronousMachineSimplified.rs

1/// The simplified model represents a synchronous generator as a constant internal voltage behind an impedance (Rs + jXp) as shown in the Simplified diagram. Since internal voltage is held constant, there is no Efd input and any excitation system model will be ignored. There is also no Ifd output. This model should not be used for representing a real generator except, perhaps, small generators whose response is insignificant. The parameters used for the simplified model include: - RotatingMachineDynamics.damping (D); - RotatingMachineDynamics.inertia (H); - RotatingMachineDynamics.statorLeakageReactance (used to exchange jXp for SynchronousMachineSimplified); - RotatingMachineDynamics.statorResistance (Rs).
2#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]
3pub struct SynchronousMachineSimplified {
4    #[serde(flatten)]
5    pub base: super::SynchronousMachineDynamics,
6}
7impl crate::base::CimElement for SynchronousMachineSimplified {
8    fn mrid(&self) -> &str { &self.base.base.base.base.id }
9    fn type_name(&self) -> &'static str { "SynchronousMachineSimplified" }
10    fn as_any(&self) -> &dyn std::any::Any { self }
11    fn to_json_value(&self) -> serde_json::Value {
12        serde_json::to_value(self).unwrap_or(serde_json::Value::Null)
13    }
14    fn to_block(&self) -> crate::base::RdfBlock {
15        let mut block = self.base.to_block();
16        block.type_name = "SynchronousMachineSimplified".to_string();
17        block
18    }
19}
20
21impl SynchronousMachineSimplified {
22    pub fn from_block(b: &crate::base::RdfBlock) -> Self {
23        let mut obj = Self::default();
24        obj.base.base.base.base.id.clone_from(&b.mrid);
25        for (key, val) in &b.fields {
26            match key.as_str() {
27                "SynchronousMachineDynamics.SynchronousMachine" => {
28                    if let crate::base::FieldValue::Resource(sv) = val {
29                        obj.base.synchronous_machine = Some(crate::base::MridRef { mrid: sv.clone() });
30                    }
31                }
32                "RotatingMachineDynamics.damping" => {
33                    match val {
34                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.base.base.damping = Some(v); } }
35                        crate::base::FieldValue::TextList(svs) => {
36                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.base.base.damping = Some(v); } }
37                        }
38                        _ => {}
39                    }
40                }
41                "RotatingMachineDynamics.inertia" => {
42                    match val {
43                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.base.base.inertia = Some(v); } }
44                        crate::base::FieldValue::TextList(svs) => {
45                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.base.base.inertia = Some(v); } }
46                        }
47                        _ => {}
48                    }
49                }
50                "RotatingMachineDynamics.saturationFactor" => {
51                    match val {
52                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.base.base.saturation_factor = Some(v); } }
53                        crate::base::FieldValue::TextList(svs) => {
54                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.base.base.saturation_factor = Some(v); } }
55                        }
56                        _ => {}
57                    }
58                }
59                "RotatingMachineDynamics.saturationFactor120" => {
60                    match val {
61                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.base.base.saturation_factor120 = Some(v); } }
62                        crate::base::FieldValue::TextList(svs) => {
63                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.base.base.saturation_factor120 = Some(v); } }
64                        }
65                        _ => {}
66                    }
67                }
68                "RotatingMachineDynamics.statorLeakageReactance" => {
69                    match val {
70                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.base.base.stator_leakage_reactance = Some(v); } }
71                        crate::base::FieldValue::TextList(svs) => {
72                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.base.base.stator_leakage_reactance = Some(v); } }
73                        }
74                        _ => {}
75                    }
76                }
77                "RotatingMachineDynamics.statorResistance" => {
78                    match val {
79                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.base.base.stator_resistance = Some(v); } }
80                        crate::base::FieldValue::TextList(svs) => {
81                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.base.base.stator_resistance = Some(v); } }
82                        }
83                        _ => {}
84                    }
85                }
86                "DynamicsFunctionBlock.enabled" => {
87                    match val {
88                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.enabled = Some(sv.trim() == "true"); }
89                        crate::base::FieldValue::TextList(svs) => {
90                            if let Some(sv) = svs.last() { obj.base.base.base.enabled = Some(sv.trim() == "true"); }
91                        }
92                        _ => {}
93                    }
94                }
95                "IdentifiedObject.description" => {
96                    match val {
97                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.base.description = sv.clone(); }
98                        crate::base::FieldValue::TextList(svs) => {
99                            if let Some(sv) = svs.last() { obj.base.base.base.base.description = sv.clone(); }
100                        }
101                        _ => {}
102                    }
103                }
104                "IdentifiedObject.energyIdentCodeEic" => {
105                    match val {
106                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.base.energy_ident_code_eic = sv.clone(); }
107                        crate::base::FieldValue::TextList(svs) => {
108                            if let Some(sv) = svs.last() { obj.base.base.base.base.energy_ident_code_eic = sv.clone(); }
109                        }
110                        _ => {}
111                    }
112                }
113                "IdentifiedObject.mRID" => {
114                    match val {
115                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.base.m_rid = sv.clone(); }
116                        crate::base::FieldValue::TextList(svs) => {
117                            if let Some(sv) = svs.last() { obj.base.base.base.base.m_rid = sv.clone(); }
118                        }
119                        _ => {}
120                    }
121                }
122                "IdentifiedObject.name" => {
123                    match val {
124                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.base.name = sv.clone(); }
125                        crate::base::FieldValue::TextList(svs) => {
126                            if let Some(sv) = svs.last() { obj.base.base.base.base.name = sv.clone(); }
127                        }
128                        _ => {}
129                    }
130                }
131                "IdentifiedObject.shortName" => {
132                    match val {
133                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.base.short_name = sv.clone(); }
134                        crate::base::FieldValue::TextList(svs) => {
135                            if let Some(sv) = svs.last() { obj.base.base.base.base.short_name = sv.clone(); }
136                        }
137                        _ => {}
138                    }
139                }
140                _ => {}
141            }
142        }
143        obj
144    }
145}