Skip to main content

cimstructs/
UnderexcLimX2.rs

1/// Westinghouse minimum excitation limiter.
2#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]
3pub struct UnderexcLimX2 {
4    #[serde(flatten)]
5    pub base: super::UnderexcitationLimiterDynamics,
6    /// Differential gain (KF2).
7    #[serde(skip_serializing_if = "Option::is_none")]
8    pub kf2: Option<f64>,
9    /// Minimum excitation limit gain (KM).
10    #[serde(skip_serializing_if = "Option::is_none")]
11    pub km: Option<f64>,
12    /// Minimum excitation limit value (MELMAX).
13    #[serde(skip_serializing_if = "Option::is_none")]
14    pub melmax: Option<f64>,
15    /// Excitation centre setting (QO).
16    #[serde(skip_serializing_if = "Option::is_none")]
17    pub qo: Option<f64>,
18    /// Excitation radius (R).
19    #[serde(skip_serializing_if = "Option::is_none")]
20    pub r: Option<f64>,
21    /// Differential time constant (TF2) (>= 0).
22    #[serde(skip_serializing_if = "Option::is_none")]
23    pub tf2: Option<f64>,
24    /// Minimum excitation limit time constant (TM) (>= 0).
25    #[serde(skip_serializing_if = "Option::is_none")]
26    pub tm: Option<f64>,
27}
28impl crate::base::CimElement for UnderexcLimX2 {
29    fn mrid(&self) -> &str { &self.base.base.base.id }
30    fn type_name(&self) -> &'static str { "UnderexcLimX2" }
31    fn as_any(&self) -> &dyn std::any::Any { self }
32    fn to_json_value(&self) -> serde_json::Value {
33        serde_json::to_value(self).unwrap_or(serde_json::Value::Null)
34    }
35    fn to_block(&self) -> crate::base::RdfBlock {
36        let mut block = self.base.to_block();
37        block.type_name = "UnderexcLimX2".to_string();
38        if let Some(v) = self.kf2 {
39            block.fields.insert("UnderexcLimX2.kf2".into(), crate::base::FieldValue::Text(v.to_string()));
40        }
41        if let Some(v) = self.km {
42            block.fields.insert("UnderexcLimX2.km".into(), crate::base::FieldValue::Text(v.to_string()));
43        }
44        if let Some(v) = self.melmax {
45            block.fields.insert("UnderexcLimX2.melmax".into(), crate::base::FieldValue::Text(v.to_string()));
46        }
47        if let Some(v) = self.qo {
48            block.fields.insert("UnderexcLimX2.qo".into(), crate::base::FieldValue::Text(v.to_string()));
49        }
50        if let Some(v) = self.r {
51            block.fields.insert("UnderexcLimX2.r".into(), crate::base::FieldValue::Text(v.to_string()));
52        }
53        if let Some(v) = self.tf2 {
54            block.fields.insert("UnderexcLimX2.tf2".into(), crate::base::FieldValue::Text(v.to_string()));
55        }
56        if let Some(v) = self.tm {
57            block.fields.insert("UnderexcLimX2.tm".into(), crate::base::FieldValue::Text(v.to_string()));
58        }
59        block
60    }
61}
62
63impl UnderexcLimX2 {
64    pub fn from_block(b: &crate::base::RdfBlock) -> Self {
65        let mut obj = Self::default();
66        obj.base.base.base.id.clone_from(&b.mrid);
67        for (key, val) in &b.fields {
68            match key.as_str() {
69                "UnderexcLimX2.kf2" => {
70                    match val {
71                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.kf2 = Some(v); } }
72                        crate::base::FieldValue::TextList(svs) => {
73                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.kf2 = Some(v); } }
74                        }
75                        _ => {}
76                    }
77                }
78                "UnderexcLimX2.km" => {
79                    match val {
80                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.km = Some(v); } }
81                        crate::base::FieldValue::TextList(svs) => {
82                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.km = Some(v); } }
83                        }
84                        _ => {}
85                    }
86                }
87                "UnderexcLimX2.melmax" => {
88                    match val {
89                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.melmax = Some(v); } }
90                        crate::base::FieldValue::TextList(svs) => {
91                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.melmax = Some(v); } }
92                        }
93                        _ => {}
94                    }
95                }
96                "UnderexcLimX2.qo" => {
97                    match val {
98                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.qo = Some(v); } }
99                        crate::base::FieldValue::TextList(svs) => {
100                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.qo = Some(v); } }
101                        }
102                        _ => {}
103                    }
104                }
105                "UnderexcLimX2.r" => {
106                    match val {
107                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.r = Some(v); } }
108                        crate::base::FieldValue::TextList(svs) => {
109                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.r = Some(v); } }
110                        }
111                        _ => {}
112                    }
113                }
114                "UnderexcLimX2.tf2" => {
115                    match val {
116                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.tf2 = Some(v); } }
117                        crate::base::FieldValue::TextList(svs) => {
118                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.tf2 = Some(v); } }
119                        }
120                        _ => {}
121                    }
122                }
123                "UnderexcLimX2.tm" => {
124                    match val {
125                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.tm = Some(v); } }
126                        crate::base::FieldValue::TextList(svs) => {
127                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.tm = Some(v); } }
128                        }
129                        _ => {}
130                    }
131                }
132                "UnderexcitationLimiterDynamics.ExcitationSystemDynamics" => {
133                    if let crate::base::FieldValue::Resource(sv) = val {
134                        obj.base.excitation_system_dynamics = Some(crate::base::MridRef { mrid: sv.clone() });
135                    }
136                }
137                "DynamicsFunctionBlock.enabled" => {
138                    match val {
139                        crate::base::FieldValue::Text(sv) => { obj.base.base.enabled = Some(sv.trim() == "true"); }
140                        crate::base::FieldValue::TextList(svs) => {
141                            if let Some(sv) = svs.last() { obj.base.base.enabled = Some(sv.trim() == "true"); }
142                        }
143                        _ => {}
144                    }
145                }
146                "IdentifiedObject.description" => {
147                    match val {
148                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.description = sv.clone(); }
149                        crate::base::FieldValue::TextList(svs) => {
150                            if let Some(sv) = svs.last() { obj.base.base.base.description = sv.clone(); }
151                        }
152                        _ => {}
153                    }
154                }
155                "IdentifiedObject.energyIdentCodeEic" => {
156                    match val {
157                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.energy_ident_code_eic = sv.clone(); }
158                        crate::base::FieldValue::TextList(svs) => {
159                            if let Some(sv) = svs.last() { obj.base.base.base.energy_ident_code_eic = sv.clone(); }
160                        }
161                        _ => {}
162                    }
163                }
164                "IdentifiedObject.mRID" => {
165                    match val {
166                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.m_rid = sv.clone(); }
167                        crate::base::FieldValue::TextList(svs) => {
168                            if let Some(sv) = svs.last() { obj.base.base.base.m_rid = sv.clone(); }
169                        }
170                        _ => {}
171                    }
172                }
173                "IdentifiedObject.name" => {
174                    match val {
175                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.name = sv.clone(); }
176                        crate::base::FieldValue::TextList(svs) => {
177                            if let Some(sv) = svs.last() { obj.base.base.base.name = sv.clone(); }
178                        }
179                        _ => {}
180                    }
181                }
182                "IdentifiedObject.shortName" => {
183                    match val {
184                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.short_name = sv.clone(); }
185                        crate::base::FieldValue::TextList(svs) => {
186                            if let Some(sv) = svs.last() { obj.base.base.base.short_name = sv.clone(); }
187                        }
188                        _ => {}
189                    }
190                }
191                _ => {}
192            }
193        }
194        obj
195    }
196}