Skip to main content

cimstructs/
ExcSCRX.rs

1/// Simple excitation system with generic characteristics typical of many excitation systems; intended for use where negative field current could be a problem.
2#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]
3pub struct ExcSCRX {
4    #[serde(flatten)]
5    pub base: super::ExcitationSystemDynamics,
6    /// Power source switch (Cswitch). true = fixed voltage of 1.0 PU false = generator terminal voltage.
7    #[serde(skip_serializing_if = "Option::is_none")]
8    pub cswitch: Option<bool>,
9    /// Maximum field voltage output (Emax) (> ExcSCRX.emin). Typical value = 5.
10    #[serde(skip_serializing_if = "Option::is_none")]
11    pub emax: Option<f64>,
12    /// Minimum field voltage output (Emin) (< ExcSCRX.emax). Typical value = 0.
13    #[serde(skip_serializing_if = "Option::is_none")]
14    pub emin: Option<f64>,
15    /// Gain (K) (> 0). Typical value = 200.
16    #[serde(skip_serializing_if = "Option::is_none")]
17    pub k: Option<f64>,
18    /// Ratio of field discharge resistance to field winding resistance ([rc / rfd]). Typical value = 0.
19    #[serde(skip_serializing_if = "Option::is_none")]
20    pub rcrfd: Option<f64>,
21    /// Gain reduction ratio of lag-lead element ([Ta / Tb]). The parameter Ta is not defined explicitly. Typical value = 0.1.
22    #[serde(skip_serializing_if = "Option::is_none")]
23    pub tatb: Option<f64>,
24    /// Denominator time constant of lag-lead block (Tb) (>= 0). Typical value = 10.
25    #[serde(skip_serializing_if = "Option::is_none")]
26    pub tb: Option<f64>,
27    /// Time constant of gain block (Te) (> 0). Typical value = 0,02.
28    #[serde(skip_serializing_if = "Option::is_none")]
29    pub te: Option<f64>,
30}
31impl crate::base::CimElement for ExcSCRX {
32    fn mrid(&self) -> &str { &self.base.base.base.id }
33    fn type_name(&self) -> &'static str { "ExcSCRX" }
34    fn as_any(&self) -> &dyn std::any::Any { self }
35    fn to_json_value(&self) -> serde_json::Value {
36        serde_json::to_value(self).unwrap_or(serde_json::Value::Null)
37    }
38    fn to_block(&self) -> crate::base::RdfBlock {
39        let mut block = self.base.to_block();
40        block.type_name = "ExcSCRX".to_string();
41        if let Some(v) = self.cswitch {
42            block.fields.insert("ExcSCRX.cswitch".into(), crate::base::FieldValue::Text(v.to_string()));
43        }
44        if let Some(v) = self.emax {
45            block.fields.insert("ExcSCRX.emax".into(), crate::base::FieldValue::Text(v.to_string()));
46        }
47        if let Some(v) = self.emin {
48            block.fields.insert("ExcSCRX.emin".into(), crate::base::FieldValue::Text(v.to_string()));
49        }
50        if let Some(v) = self.k {
51            block.fields.insert("ExcSCRX.k".into(), crate::base::FieldValue::Text(v.to_string()));
52        }
53        if let Some(v) = self.rcrfd {
54            block.fields.insert("ExcSCRX.rcrfd".into(), crate::base::FieldValue::Text(v.to_string()));
55        }
56        if let Some(v) = self.tatb {
57            block.fields.insert("ExcSCRX.tatb".into(), crate::base::FieldValue::Text(v.to_string()));
58        }
59        if let Some(v) = self.tb {
60            block.fields.insert("ExcSCRX.tb".into(), crate::base::FieldValue::Text(v.to_string()));
61        }
62        if let Some(v) = self.te {
63            block.fields.insert("ExcSCRX.te".into(), crate::base::FieldValue::Text(v.to_string()));
64        }
65        block
66    }
67}
68
69impl ExcSCRX {
70    pub fn from_block(b: &crate::base::RdfBlock) -> Self {
71        let mut obj = Self::default();
72        obj.base.base.base.id.clone_from(&b.mrid);
73        for (key, val) in &b.fields {
74            match key.as_str() {
75                "ExcSCRX.cswitch" => {
76                    match val {
77                        crate::base::FieldValue::Text(sv) => { obj.cswitch = Some(sv.trim() == "true"); }
78                        crate::base::FieldValue::TextList(svs) => {
79                            if let Some(sv) = svs.last() { obj.cswitch = Some(sv.trim() == "true"); }
80                        }
81                        _ => {}
82                    }
83                }
84                "ExcSCRX.emax" => {
85                    match val {
86                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.emax = Some(v); } }
87                        crate::base::FieldValue::TextList(svs) => {
88                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.emax = Some(v); } }
89                        }
90                        _ => {}
91                    }
92                }
93                "ExcSCRX.emin" => {
94                    match val {
95                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.emin = Some(v); } }
96                        crate::base::FieldValue::TextList(svs) => {
97                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.emin = Some(v); } }
98                        }
99                        _ => {}
100                    }
101                }
102                "ExcSCRX.k" => {
103                    match val {
104                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.k = Some(v); } }
105                        crate::base::FieldValue::TextList(svs) => {
106                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.k = Some(v); } }
107                        }
108                        _ => {}
109                    }
110                }
111                "ExcSCRX.rcrfd" => {
112                    match val {
113                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.rcrfd = Some(v); } }
114                        crate::base::FieldValue::TextList(svs) => {
115                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.rcrfd = Some(v); } }
116                        }
117                        _ => {}
118                    }
119                }
120                "ExcSCRX.tatb" => {
121                    match val {
122                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.tatb = Some(v); } }
123                        crate::base::FieldValue::TextList(svs) => {
124                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.tatb = Some(v); } }
125                        }
126                        _ => {}
127                    }
128                }
129                "ExcSCRX.tb" => {
130                    match val {
131                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.tb = Some(v); } }
132                        crate::base::FieldValue::TextList(svs) => {
133                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.tb = Some(v); } }
134                        }
135                        _ => {}
136                    }
137                }
138                "ExcSCRX.te" => {
139                    match val {
140                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.te = Some(v); } }
141                        crate::base::FieldValue::TextList(svs) => {
142                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.te = Some(v); } }
143                        }
144                        _ => {}
145                    }
146                }
147                "ExcitationSystemDynamics.SynchronousMachineDynamics" => {
148                    if let crate::base::FieldValue::Resource(sv) = val {
149                        obj.base.synchronous_machine_dynamics = Some(crate::base::MridRef { mrid: sv.clone() });
150                    }
151                }
152                "DynamicsFunctionBlock.enabled" => {
153                    match val {
154                        crate::base::FieldValue::Text(sv) => { obj.base.base.enabled = Some(sv.trim() == "true"); }
155                        crate::base::FieldValue::TextList(svs) => {
156                            if let Some(sv) = svs.last() { obj.base.base.enabled = Some(sv.trim() == "true"); }
157                        }
158                        _ => {}
159                    }
160                }
161                "IdentifiedObject.description" => {
162                    match val {
163                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.description = sv.clone(); }
164                        crate::base::FieldValue::TextList(svs) => {
165                            if let Some(sv) = svs.last() { obj.base.base.base.description = sv.clone(); }
166                        }
167                        _ => {}
168                    }
169                }
170                "IdentifiedObject.energyIdentCodeEic" => {
171                    match val {
172                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.energy_ident_code_eic = sv.clone(); }
173                        crate::base::FieldValue::TextList(svs) => {
174                            if let Some(sv) = svs.last() { obj.base.base.base.energy_ident_code_eic = sv.clone(); }
175                        }
176                        _ => {}
177                    }
178                }
179                "IdentifiedObject.mRID" => {
180                    match val {
181                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.m_rid = sv.clone(); }
182                        crate::base::FieldValue::TextList(svs) => {
183                            if let Some(sv) = svs.last() { obj.base.base.base.m_rid = sv.clone(); }
184                        }
185                        _ => {}
186                    }
187                }
188                "IdentifiedObject.name" => {
189                    match val {
190                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.name = sv.clone(); }
191                        crate::base::FieldValue::TextList(svs) => {
192                            if let Some(sv) = svs.last() { obj.base.base.base.name = sv.clone(); }
193                        }
194                        _ => {}
195                    }
196                }
197                "IdentifiedObject.shortName" => {
198                    match val {
199                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.short_name = sv.clone(); }
200                        crate::base::FieldValue::TextList(svs) => {
201                            if let Some(sv) = svs.last() { obj.base.base.base.short_name = sv.clone(); }
202                        }
203                        _ => {}
204                    }
205                }
206                _ => {}
207            }
208        }
209        obj
210    }
211}