Skip to main content

cimstructs/
UnderexcLim2Simplified.rs

1/// Simplified type UEL2 underexcitation limiter. This model can be derived from UnderexcLimIEEE2. The limit characteristic (look -up table) is a single straight-line, the same as UnderexcLimIEEE2 (see Figure 10.4 (p 32), IEEE 421.5-2005 Section 10.2).
2#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]
3pub struct UnderexcLim2Simplified {
4    #[serde(flatten)]
5    pub base: super::UnderexcitationLimiterDynamics,
6    /// Gain Under excitation limiter (KUI). Typical value = 0,1.
7    #[serde(skip_serializing_if = "Option::is_none")]
8    pub kui: Option<f64>,
9    /// Segment P initial point (P0). Typical value = 0.
10    #[serde(skip_serializing_if = "Option::is_none")]
11    pub p0: Option<f64>,
12    /// Segment P end point (P1). Typical value = 1.
13    #[serde(skip_serializing_if = "Option::is_none")]
14    pub p1: Option<f64>,
15    /// Segment Q initial point (Q0). Typical value = -0,31.
16    #[serde(skip_serializing_if = "Option::is_none")]
17    pub q0: Option<f64>,
18    /// Segment Q end point (Q1). Typical value = -0,1.
19    #[serde(skip_serializing_if = "Option::is_none")]
20    pub q1: Option<f64>,
21    /// Maximum error signal (VUIMAX) (> UnderexcLim2Simplified.vuimin). Typical value = 1.
22    #[serde(skip_serializing_if = "Option::is_none")]
23    pub vuimax: Option<f64>,
24    /// Minimum error signal (VUIMIN) (< UnderexcLim2Simplified.vuimax). Typical value = 0.
25    #[serde(skip_serializing_if = "Option::is_none")]
26    pub vuimin: Option<f64>,
27}
28impl crate::base::CimElement for UnderexcLim2Simplified {
29    fn mrid(&self) -> &str { &self.base.base.base.id }
30    fn type_name(&self) -> &'static str { "UnderexcLim2Simplified" }
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 = "UnderexcLim2Simplified".to_string();
38        if let Some(v) = self.kui {
39            block.fields.insert("UnderexcLim2Simplified.kui".into(), crate::base::FieldValue::Text(v.to_string()));
40        }
41        if let Some(v) = self.p0 {
42            block.fields.insert("UnderexcLim2Simplified.p0".into(), crate::base::FieldValue::Text(v.to_string()));
43        }
44        if let Some(v) = self.p1 {
45            block.fields.insert("UnderexcLim2Simplified.p1".into(), crate::base::FieldValue::Text(v.to_string()));
46        }
47        if let Some(v) = self.q0 {
48            block.fields.insert("UnderexcLim2Simplified.q0".into(), crate::base::FieldValue::Text(v.to_string()));
49        }
50        if let Some(v) = self.q1 {
51            block.fields.insert("UnderexcLim2Simplified.q1".into(), crate::base::FieldValue::Text(v.to_string()));
52        }
53        if let Some(v) = self.vuimax {
54            block.fields.insert("UnderexcLim2Simplified.vuimax".into(), crate::base::FieldValue::Text(v.to_string()));
55        }
56        if let Some(v) = self.vuimin {
57            block.fields.insert("UnderexcLim2Simplified.vuimin".into(), crate::base::FieldValue::Text(v.to_string()));
58        }
59        block
60    }
61}
62
63impl UnderexcLim2Simplified {
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                "UnderexcLim2Simplified.kui" => {
70                    match val {
71                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.kui = Some(v); } }
72                        crate::base::FieldValue::TextList(svs) => {
73                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.kui = Some(v); } }
74                        }
75                        _ => {}
76                    }
77                }
78                "UnderexcLim2Simplified.p0" => {
79                    match val {
80                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.p0 = Some(v); } }
81                        crate::base::FieldValue::TextList(svs) => {
82                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.p0 = Some(v); } }
83                        }
84                        _ => {}
85                    }
86                }
87                "UnderexcLim2Simplified.p1" => {
88                    match val {
89                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.p1 = Some(v); } }
90                        crate::base::FieldValue::TextList(svs) => {
91                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.p1 = Some(v); } }
92                        }
93                        _ => {}
94                    }
95                }
96                "UnderexcLim2Simplified.q0" => {
97                    match val {
98                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.q0 = Some(v); } }
99                        crate::base::FieldValue::TextList(svs) => {
100                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.q0 = Some(v); } }
101                        }
102                        _ => {}
103                    }
104                }
105                "UnderexcLim2Simplified.q1" => {
106                    match val {
107                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.q1 = Some(v); } }
108                        crate::base::FieldValue::TextList(svs) => {
109                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.q1 = Some(v); } }
110                        }
111                        _ => {}
112                    }
113                }
114                "UnderexcLim2Simplified.vuimax" => {
115                    match val {
116                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.vuimax = Some(v); } }
117                        crate::base::FieldValue::TextList(svs) => {
118                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.vuimax = Some(v); } }
119                        }
120                        _ => {}
121                    }
122                }
123                "UnderexcLim2Simplified.vuimin" => {
124                    match val {
125                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.vuimin = Some(v); } }
126                        crate::base::FieldValue::TextList(svs) => {
127                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.vuimin = 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}