Skip to main content

cimstructs/
HydroGeneratingUnit.rs

1/// A generating unit whose prime mover is a hydraulic turbine (e.g., Francis, Pelton, Kaplan).
2#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]
3pub struct HydroGeneratingUnit {
4    #[serde(flatten)]
5    pub base: super::GeneratingUnit,
6    /// The hydro generating unit belongs to a hydro power plant.
7    #[serde(skip_serializing_if = "Option::is_none")]
8    pub hydro_power_plant: Option<super::base::MridRef>,
9    /// The height water drops from the reservoir mid-point to the turbine.
10    #[serde(skip_serializing_if = "Option::is_none")]
11    pub drop_height: Option<f64>,
12    /// Energy conversion capability for generating.
13    #[serde(skip_serializing_if = "Option::is_none")]
14    pub energy_conversion_capability: Option<super::base::UriRef>,
15    /// Type of turbine.
16    #[serde(skip_serializing_if = "Option::is_none")]
17    pub turbine_type: Option<super::base::UriRef>,
18}
19impl crate::base::CimElement for HydroGeneratingUnit {
20    fn mrid(&self) -> &str { &self.base.base.base.base.id }
21    fn type_name(&self) -> &'static str { "HydroGeneratingUnit" }
22    fn as_any(&self) -> &dyn std::any::Any { self }
23    fn to_json_value(&self) -> serde_json::Value {
24        serde_json::to_value(self).unwrap_or(serde_json::Value::Null)
25    }
26    fn to_block(&self) -> crate::base::RdfBlock {
27        let mut block = self.base.to_block();
28        block.type_name = "HydroGeneratingUnit".to_string();
29        if let Some(ref v) = self.hydro_power_plant {
30            block.fields.insert("HydroGeneratingUnit.HydroPowerPlant".into(), crate::base::FieldValue::Resource(v.mrid.clone()));
31        }
32        if let Some(v) = self.drop_height {
33            block.fields.insert("HydroGeneratingUnit.dropHeight".into(), crate::base::FieldValue::Text(v.to_string()));
34        }
35        if let Some(ref v) = self.energy_conversion_capability {
36            block.fields.insert("HydroGeneratingUnit.energyConversionCapability".into(), crate::base::FieldValue::Resource(v.uri.clone()));
37        }
38        if let Some(ref v) = self.turbine_type {
39            block.fields.insert("HydroGeneratingUnit.turbineType".into(), crate::base::FieldValue::Resource(v.uri.clone()));
40        }
41        block
42    }
43}
44
45impl HydroGeneratingUnit {
46    pub fn from_block(b: &crate::base::RdfBlock) -> Self {
47        let mut obj = Self::default();
48        obj.base.base.base.base.id.clone_from(&b.mrid);
49        for (key, val) in &b.fields {
50            match key.as_str() {
51                "HydroGeneratingUnit.HydroPowerPlant" => {
52                    if let crate::base::FieldValue::Resource(sv) = val {
53                        obj.hydro_power_plant = Some(crate::base::MridRef { mrid: sv.clone() });
54                    }
55                }
56                "HydroGeneratingUnit.dropHeight" => {
57                    match val {
58                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.drop_height = Some(v); } }
59                        crate::base::FieldValue::TextList(svs) => {
60                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.drop_height = Some(v); } }
61                        }
62                        _ => {}
63                    }
64                }
65                "HydroGeneratingUnit.energyConversionCapability" => {
66                    if let crate::base::FieldValue::Resource(sv) = val {
67                        obj.energy_conversion_capability = Some(crate::base::UriRef { uri: sv.clone() });
68                    }
69                }
70                "HydroGeneratingUnit.turbineType" => {
71                    if let crate::base::FieldValue::Resource(sv) = val {
72                        obj.turbine_type = Some(crate::base::UriRef { uri: sv.clone() });
73                    }
74                }
75                "GeneratingUnit.genControlSource" => {
76                    if let crate::base::FieldValue::Resource(sv) = val {
77                        obj.base.gen_control_source = Some(crate::base::UriRef { uri: sv.clone() });
78                    }
79                }
80                "GeneratingUnit.governorSCD" => {
81                    match val {
82                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.base.governor_scd = Some(v); } }
83                        crate::base::FieldValue::TextList(svs) => {
84                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.base.governor_scd = Some(v); } }
85                        }
86                        _ => {}
87                    }
88                }
89                "GeneratingUnit.longPF" => {
90                    match val {
91                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.base.long_pf = Some(v); } }
92                        crate::base::FieldValue::TextList(svs) => {
93                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.base.long_pf = Some(v); } }
94                        }
95                        _ => {}
96                    }
97                }
98                "GeneratingUnit.maxOperatingP" => {
99                    match val {
100                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.base.max_operating_p = Some(v); } }
101                        crate::base::FieldValue::TextList(svs) => {
102                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.base.max_operating_p = Some(v); } }
103                        }
104                        _ => {}
105                    }
106                }
107                "GeneratingUnit.maximumAllowableSpinningReserve" => {
108                    match val {
109                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.base.maximum_allowable_spinning_reserve = Some(v); } }
110                        crate::base::FieldValue::TextList(svs) => {
111                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.base.maximum_allowable_spinning_reserve = Some(v); } }
112                        }
113                        _ => {}
114                    }
115                }
116                "GeneratingUnit.minOperatingP" => {
117                    match val {
118                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.base.min_operating_p = Some(v); } }
119                        crate::base::FieldValue::TextList(svs) => {
120                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.base.min_operating_p = Some(v); } }
121                        }
122                        _ => {}
123                    }
124                }
125                "GeneratingUnit.nominalP" => {
126                    match val {
127                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.base.nominal_p = Some(v); } }
128                        crate::base::FieldValue::TextList(svs) => {
129                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.base.nominal_p = Some(v); } }
130                        }
131                        _ => {}
132                    }
133                }
134                "GeneratingUnit.normalPF" => {
135                    match val {
136                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.base.normal_pf = Some(v); } }
137                        crate::base::FieldValue::TextList(svs) => {
138                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.base.normal_pf = Some(v); } }
139                        }
140                        _ => {}
141                    }
142                }
143                "GeneratingUnit.ratedGrossMaxP" => {
144                    match val {
145                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.base.rated_gross_max_p = Some(v); } }
146                        crate::base::FieldValue::TextList(svs) => {
147                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.base.rated_gross_max_p = Some(v); } }
148                        }
149                        _ => {}
150                    }
151                }
152                "GeneratingUnit.ratedGrossMinP" => {
153                    match val {
154                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.base.rated_gross_min_p = Some(v); } }
155                        crate::base::FieldValue::TextList(svs) => {
156                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.base.rated_gross_min_p = Some(v); } }
157                        }
158                        _ => {}
159                    }
160                }
161                "GeneratingUnit.ratedNetMaxP" => {
162                    match val {
163                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.base.rated_net_max_p = Some(v); } }
164                        crate::base::FieldValue::TextList(svs) => {
165                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.base.rated_net_max_p = Some(v); } }
166                        }
167                        _ => {}
168                    }
169                }
170                "GeneratingUnit.shortPF" => {
171                    match val {
172                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.base.short_pf = Some(v); } }
173                        crate::base::FieldValue::TextList(svs) => {
174                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.base.short_pf = Some(v); } }
175                        }
176                        _ => {}
177                    }
178                }
179                "GeneratingUnit.startupCost" => {
180                    match val {
181                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.base.startup_cost = Some(v); } }
182                        crate::base::FieldValue::TextList(svs) => {
183                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.base.startup_cost = Some(v); } }
184                        }
185                        _ => {}
186                    }
187                }
188                "GeneratingUnit.startupTime" => {
189                    match val {
190                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.base.startup_time = Some(v); } }
191                        crate::base::FieldValue::TextList(svs) => {
192                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.base.startup_time = Some(v); } }
193                        }
194                        _ => {}
195                    }
196                }
197                "GeneratingUnit.totalEfficiency" => {
198                    match val {
199                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.base.total_efficiency = Some(v); } }
200                        crate::base::FieldValue::TextList(svs) => {
201                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.base.total_efficiency = Some(v); } }
202                        }
203                        _ => {}
204                    }
205                }
206                "GeneratingUnit.variableCost" => {
207                    match val {
208                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.base.variable_cost = Some(v); } }
209                        crate::base::FieldValue::TextList(svs) => {
210                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.base.variable_cost = Some(v); } }
211                        }
212                        _ => {}
213                    }
214                }
215                "Equipment.EquipmentContainer" => {
216                    if let crate::base::FieldValue::Resource(sv) = val {
217                        obj.base.base.equipment_container = Some(crate::base::MridRef { mrid: sv.clone() });
218                    }
219                }
220                "Equipment.aggregate" => {
221                    match val {
222                        crate::base::FieldValue::Text(sv) => { obj.base.base.aggregate = Some(sv.trim() == "true"); }
223                        crate::base::FieldValue::TextList(svs) => {
224                            if let Some(sv) = svs.last() { obj.base.base.aggregate = Some(sv.trim() == "true"); }
225                        }
226                        _ => {}
227                    }
228                }
229                "Equipment.inService" => {
230                    match val {
231                        crate::base::FieldValue::Text(sv) => { obj.base.base.in_service = Some(sv.trim() == "true"); }
232                        crate::base::FieldValue::TextList(svs) => {
233                            if let Some(sv) = svs.last() { obj.base.base.in_service = Some(sv.trim() == "true"); }
234                        }
235                        _ => {}
236                    }
237                }
238                "Equipment.normallyInService" => {
239                    match val {
240                        crate::base::FieldValue::Text(sv) => { obj.base.base.normally_in_service = Some(sv.trim() == "true"); }
241                        crate::base::FieldValue::TextList(svs) => {
242                            if let Some(sv) = svs.last() { obj.base.base.normally_in_service = Some(sv.trim() == "true"); }
243                        }
244                        _ => {}
245                    }
246                }
247                "IdentifiedObject.description" => {
248                    match val {
249                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.base.description = sv.clone(); }
250                        crate::base::FieldValue::TextList(svs) => {
251                            if let Some(sv) = svs.last() { obj.base.base.base.base.description = sv.clone(); }
252                        }
253                        _ => {}
254                    }
255                }
256                "IdentifiedObject.energyIdentCodeEic" => {
257                    match val {
258                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.base.energy_ident_code_eic = sv.clone(); }
259                        crate::base::FieldValue::TextList(svs) => {
260                            if let Some(sv) = svs.last() { obj.base.base.base.base.energy_ident_code_eic = sv.clone(); }
261                        }
262                        _ => {}
263                    }
264                }
265                "IdentifiedObject.mRID" => {
266                    match val {
267                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.base.m_rid = sv.clone(); }
268                        crate::base::FieldValue::TextList(svs) => {
269                            if let Some(sv) = svs.last() { obj.base.base.base.base.m_rid = sv.clone(); }
270                        }
271                        _ => {}
272                    }
273                }
274                "IdentifiedObject.name" => {
275                    match val {
276                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.base.name = sv.clone(); }
277                        crate::base::FieldValue::TextList(svs) => {
278                            if let Some(sv) = svs.last() { obj.base.base.base.base.name = sv.clone(); }
279                        }
280                        _ => {}
281                    }
282                }
283                "IdentifiedObject.shortName" => {
284                    match val {
285                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.base.short_name = sv.clone(); }
286                        crate::base::FieldValue::TextList(svs) => {
287                            if let Some(sv) = svs.last() { obj.base.base.base.base.short_name = sv.clone(); }
288                        }
289                        _ => {}
290                    }
291                }
292                _ => {}
293            }
294        }
295        obj
296    }
297}