Skip to main content

cimstructs/
GovHydro1.rs

1/// Basic hydro turbine governor.
2#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]
3pub struct GovHydro1 {
4    #[serde(flatten)]
5    pub base: super::TurbineGovernorDynamics,
6    /// Turbine gain (At) (> 0). Typical value = 1,2.
7    #[serde(skip_serializing_if = "Option::is_none")]
8    pub at: Option<f64>,
9    /// Turbine damping factor (Dturb) (>= 0). Typical value = 0,5.
10    #[serde(skip_serializing_if = "Option::is_none")]
11    pub dturb: Option<f64>,
12    /// Maximum gate opening (Gmax) (> 0 and > GovHydro.gmin). Typical value = 1.
13    #[serde(skip_serializing_if = "Option::is_none")]
14    pub gmax: Option<f64>,
15    /// Minimum gate opening (Gmin) (>= 0 and < GovHydro1.gmax). Typical value = 0.
16    #[serde(skip_serializing_if = "Option::is_none")]
17    pub gmin: Option<f64>,
18    /// Turbine nominal head (hdam). Typical value = 1.
19    #[serde(skip_serializing_if = "Option::is_none")]
20    pub hdam: Option<f64>,
21    /// Base for power values (MWbase) (> 0). Unit = MW.
22    #[serde(skip_serializing_if = "Option::is_none")]
23    pub mwbase: Option<f64>,
24    /// No-load flow at nominal head (qnl) (>= 0). Typical value = 0,08.
25    #[serde(skip_serializing_if = "Option::is_none")]
26    pub qnl: Option<f64>,
27    /// Permanent droop (R) (> 0). Typical value = 0,04.
28    #[serde(skip_serializing_if = "Option::is_none")]
29    pub rperm: Option<f64>,
30    /// Temporary droop (r) (> GovHydro1.rperm). Typical value = 0,3.
31    #[serde(skip_serializing_if = "Option::is_none")]
32    pub rtemp: Option<f64>,
33    /// Filter time constant (Tf) (> 0). Typical value = 0,05.
34    #[serde(skip_serializing_if = "Option::is_none")]
35    pub tf: Option<f64>,
36    /// Gate servo time constant (Tg) (> 0). Typical value = 0,5.
37    #[serde(skip_serializing_if = "Option::is_none")]
38    pub tg: Option<f64>,
39    /// Washout time constant (Tr) (> 0). Typical value = 5.
40    #[serde(skip_serializing_if = "Option::is_none")]
41    pub tr: Option<f64>,
42    /// Water inertia time constant (Tw) (> 0). Typical value = 1.
43    #[serde(skip_serializing_if = "Option::is_none")]
44    pub tw: Option<f64>,
45    /// Maximum gate velocity (Vlem) (> 0). Typical value = 0,2.
46    #[serde(skip_serializing_if = "Option::is_none")]
47    pub velm: Option<f64>,
48}
49impl crate::base::CimElement for GovHydro1 {
50    fn mrid(&self) -> &str { &self.base.base.base.id }
51    fn type_name(&self) -> &'static str { "GovHydro1" }
52    fn as_any(&self) -> &dyn std::any::Any { self }
53    fn to_json_value(&self) -> serde_json::Value {
54        serde_json::to_value(self).unwrap_or(serde_json::Value::Null)
55    }
56    fn to_block(&self) -> crate::base::RdfBlock {
57        let mut block = self.base.to_block();
58        block.type_name = "GovHydro1".to_string();
59        if let Some(v) = self.at {
60            block.fields.insert("GovHydro1.at".into(), crate::base::FieldValue::Text(v.to_string()));
61        }
62        if let Some(v) = self.dturb {
63            block.fields.insert("GovHydro1.dturb".into(), crate::base::FieldValue::Text(v.to_string()));
64        }
65        if let Some(v) = self.gmax {
66            block.fields.insert("GovHydro1.gmax".into(), crate::base::FieldValue::Text(v.to_string()));
67        }
68        if let Some(v) = self.gmin {
69            block.fields.insert("GovHydro1.gmin".into(), crate::base::FieldValue::Text(v.to_string()));
70        }
71        if let Some(v) = self.hdam {
72            block.fields.insert("GovHydro1.hdam".into(), crate::base::FieldValue::Text(v.to_string()));
73        }
74        if let Some(v) = self.mwbase {
75            block.fields.insert("GovHydro1.mwbase".into(), crate::base::FieldValue::Text(v.to_string()));
76        }
77        if let Some(v) = self.qnl {
78            block.fields.insert("GovHydro1.qnl".into(), crate::base::FieldValue::Text(v.to_string()));
79        }
80        if let Some(v) = self.rperm {
81            block.fields.insert("GovHydro1.rperm".into(), crate::base::FieldValue::Text(v.to_string()));
82        }
83        if let Some(v) = self.rtemp {
84            block.fields.insert("GovHydro1.rtemp".into(), crate::base::FieldValue::Text(v.to_string()));
85        }
86        if let Some(v) = self.tf {
87            block.fields.insert("GovHydro1.tf".into(), crate::base::FieldValue::Text(v.to_string()));
88        }
89        if let Some(v) = self.tg {
90            block.fields.insert("GovHydro1.tg".into(), crate::base::FieldValue::Text(v.to_string()));
91        }
92        if let Some(v) = self.tr {
93            block.fields.insert("GovHydro1.tr".into(), crate::base::FieldValue::Text(v.to_string()));
94        }
95        if let Some(v) = self.tw {
96            block.fields.insert("GovHydro1.tw".into(), crate::base::FieldValue::Text(v.to_string()));
97        }
98        if let Some(v) = self.velm {
99            block.fields.insert("GovHydro1.velm".into(), crate::base::FieldValue::Text(v.to_string()));
100        }
101        block
102    }
103}
104
105impl GovHydro1 {
106    pub fn from_block(b: &crate::base::RdfBlock) -> Self {
107        let mut obj = Self::default();
108        obj.base.base.base.id.clone_from(&b.mrid);
109        for (key, val) in &b.fields {
110            match key.as_str() {
111                "GovHydro1.at" => {
112                    match val {
113                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.at = Some(v); } }
114                        crate::base::FieldValue::TextList(svs) => {
115                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.at = Some(v); } }
116                        }
117                        _ => {}
118                    }
119                }
120                "GovHydro1.dturb" => {
121                    match val {
122                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.dturb = Some(v); } }
123                        crate::base::FieldValue::TextList(svs) => {
124                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.dturb = Some(v); } }
125                        }
126                        _ => {}
127                    }
128                }
129                "GovHydro1.gmax" => {
130                    match val {
131                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.gmax = Some(v); } }
132                        crate::base::FieldValue::TextList(svs) => {
133                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.gmax = Some(v); } }
134                        }
135                        _ => {}
136                    }
137                }
138                "GovHydro1.gmin" => {
139                    match val {
140                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.gmin = Some(v); } }
141                        crate::base::FieldValue::TextList(svs) => {
142                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.gmin = Some(v); } }
143                        }
144                        _ => {}
145                    }
146                }
147                "GovHydro1.hdam" => {
148                    match val {
149                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.hdam = Some(v); } }
150                        crate::base::FieldValue::TextList(svs) => {
151                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.hdam = Some(v); } }
152                        }
153                        _ => {}
154                    }
155                }
156                "GovHydro1.mwbase" => {
157                    match val {
158                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.mwbase = Some(v); } }
159                        crate::base::FieldValue::TextList(svs) => {
160                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.mwbase = Some(v); } }
161                        }
162                        _ => {}
163                    }
164                }
165                "GovHydro1.qnl" => {
166                    match val {
167                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.qnl = Some(v); } }
168                        crate::base::FieldValue::TextList(svs) => {
169                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.qnl = Some(v); } }
170                        }
171                        _ => {}
172                    }
173                }
174                "GovHydro1.rperm" => {
175                    match val {
176                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.rperm = Some(v); } }
177                        crate::base::FieldValue::TextList(svs) => {
178                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.rperm = Some(v); } }
179                        }
180                        _ => {}
181                    }
182                }
183                "GovHydro1.rtemp" => {
184                    match val {
185                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.rtemp = Some(v); } }
186                        crate::base::FieldValue::TextList(svs) => {
187                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.rtemp = Some(v); } }
188                        }
189                        _ => {}
190                    }
191                }
192                "GovHydro1.tf" => {
193                    match val {
194                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.tf = Some(v); } }
195                        crate::base::FieldValue::TextList(svs) => {
196                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.tf = Some(v); } }
197                        }
198                        _ => {}
199                    }
200                }
201                "GovHydro1.tg" => {
202                    match val {
203                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.tg = Some(v); } }
204                        crate::base::FieldValue::TextList(svs) => {
205                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.tg = Some(v); } }
206                        }
207                        _ => {}
208                    }
209                }
210                "GovHydro1.tr" => {
211                    match val {
212                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.tr = Some(v); } }
213                        crate::base::FieldValue::TextList(svs) => {
214                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.tr = Some(v); } }
215                        }
216                        _ => {}
217                    }
218                }
219                "GovHydro1.tw" => {
220                    match val {
221                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.tw = Some(v); } }
222                        crate::base::FieldValue::TextList(svs) => {
223                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.tw = Some(v); } }
224                        }
225                        _ => {}
226                    }
227                }
228                "GovHydro1.velm" => {
229                    match val {
230                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.velm = Some(v); } }
231                        crate::base::FieldValue::TextList(svs) => {
232                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.velm = Some(v); } }
233                        }
234                        _ => {}
235                    }
236                }
237                "TurbineGovernorDynamics.AsynchronousMachineDynamics" => {
238                    if let crate::base::FieldValue::Resource(sv) = val {
239                        obj.base.asynchronous_machine_dynamics = Some(crate::base::MridRef { mrid: sv.clone() });
240                    }
241                }
242                "TurbineGovernorDynamics.SynchronousMachineDynamics" => {
243                    if let crate::base::FieldValue::Resource(sv) = val {
244                        obj.base.synchronous_machine_dynamics = Some(crate::base::MridRef { mrid: sv.clone() });
245                    }
246                }
247                "DynamicsFunctionBlock.enabled" => {
248                    match val {
249                        crate::base::FieldValue::Text(sv) => { obj.base.base.enabled = Some(sv.trim() == "true"); }
250                        crate::base::FieldValue::TextList(svs) => {
251                            if let Some(sv) = svs.last() { obj.base.base.enabled = Some(sv.trim() == "true"); }
252                        }
253                        _ => {}
254                    }
255                }
256                "IdentifiedObject.description" => {
257                    match val {
258                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.description = sv.clone(); }
259                        crate::base::FieldValue::TextList(svs) => {
260                            if let Some(sv) = svs.last() { obj.base.base.base.description = sv.clone(); }
261                        }
262                        _ => {}
263                    }
264                }
265                "IdentifiedObject.energyIdentCodeEic" => {
266                    match val {
267                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.energy_ident_code_eic = sv.clone(); }
268                        crate::base::FieldValue::TextList(svs) => {
269                            if let Some(sv) = svs.last() { obj.base.base.base.energy_ident_code_eic = sv.clone(); }
270                        }
271                        _ => {}
272                    }
273                }
274                "IdentifiedObject.mRID" => {
275                    match val {
276                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.m_rid = sv.clone(); }
277                        crate::base::FieldValue::TextList(svs) => {
278                            if let Some(sv) = svs.last() { obj.base.base.base.m_rid = sv.clone(); }
279                        }
280                        _ => {}
281                    }
282                }
283                "IdentifiedObject.name" => {
284                    match val {
285                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.name = sv.clone(); }
286                        crate::base::FieldValue::TextList(svs) => {
287                            if let Some(sv) = svs.last() { obj.base.base.base.name = sv.clone(); }
288                        }
289                        _ => {}
290                    }
291                }
292                "IdentifiedObject.shortName" => {
293                    match val {
294                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.short_name = sv.clone(); }
295                        crate::base::FieldValue::TextList(svs) => {
296                            if let Some(sv) = svs.last() { obj.base.base.base.short_name = sv.clone(); }
297                        }
298                        _ => {}
299                    }
300                }
301                _ => {}
302            }
303        }
304        obj
305    }
306}