Skip to main content

cimstructs/
HydroPump.rs

1/// A synchronous motor-driven pump, typically associated with a pumped storage plant.
2#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]
3pub struct HydroPump {
4    #[serde(flatten)]
5    pub base: super::Equipment,
6    /// The hydro pump may be a member of a pumped storage plant or a pump for distributing water.
7    #[serde(skip_serializing_if = "Option::is_none")]
8    pub hydro_power_plant: Option<super::base::MridRef>,
9    /// The synchronous machine drives the turbine which moves the water from a low elevation to a higher elevation. The direction of machine rotation for pumping may or may not be the same as for generating.
10    #[serde(skip_serializing_if = "Option::is_none")]
11    pub rotating_machine: Option<super::base::MridRef>,
12}
13impl crate::base::CimElement for HydroPump {
14    fn mrid(&self) -> &str { &self.base.base.base.id }
15    fn type_name(&self) -> &'static str { "HydroPump" }
16    fn as_any(&self) -> &dyn std::any::Any { self }
17    fn to_json_value(&self) -> serde_json::Value {
18        serde_json::to_value(self).unwrap_or(serde_json::Value::Null)
19    }
20    fn to_block(&self) -> crate::base::RdfBlock {
21        let mut block = self.base.to_block();
22        block.type_name = "HydroPump".to_string();
23        if let Some(ref v) = self.hydro_power_plant {
24            block.fields.insert("HydroPump.HydroPowerPlant".into(), crate::base::FieldValue::Resource(v.mrid.clone()));
25        }
26        if let Some(ref v) = self.rotating_machine {
27            block.fields.insert("HydroPump.RotatingMachine".into(), crate::base::FieldValue::Resource(v.mrid.clone()));
28        }
29        block
30    }
31}
32
33impl HydroPump {
34    pub fn from_block(b: &crate::base::RdfBlock) -> Self {
35        let mut obj = Self::default();
36        obj.base.base.base.id.clone_from(&b.mrid);
37        for (key, val) in &b.fields {
38            match key.as_str() {
39                "HydroPump.HydroPowerPlant" => {
40                    if let crate::base::FieldValue::Resource(sv) = val {
41                        obj.hydro_power_plant = Some(crate::base::MridRef { mrid: sv.clone() });
42                    }
43                }
44                "HydroPump.RotatingMachine" => {
45                    if let crate::base::FieldValue::Resource(sv) = val {
46                        obj.rotating_machine = Some(crate::base::MridRef { mrid: sv.clone() });
47                    }
48                }
49                "Equipment.EquipmentContainer" => {
50                    if let crate::base::FieldValue::Resource(sv) = val {
51                        obj.base.equipment_container = Some(crate::base::MridRef { mrid: sv.clone() });
52                    }
53                }
54                "Equipment.aggregate" => {
55                    match val {
56                        crate::base::FieldValue::Text(sv) => { obj.base.aggregate = Some(sv.trim() == "true"); }
57                        crate::base::FieldValue::TextList(svs) => {
58                            if let Some(sv) = svs.last() { obj.base.aggregate = Some(sv.trim() == "true"); }
59                        }
60                        _ => {}
61                    }
62                }
63                "Equipment.inService" => {
64                    match val {
65                        crate::base::FieldValue::Text(sv) => { obj.base.in_service = Some(sv.trim() == "true"); }
66                        crate::base::FieldValue::TextList(svs) => {
67                            if let Some(sv) = svs.last() { obj.base.in_service = Some(sv.trim() == "true"); }
68                        }
69                        _ => {}
70                    }
71                }
72                "Equipment.normallyInService" => {
73                    match val {
74                        crate::base::FieldValue::Text(sv) => { obj.base.normally_in_service = Some(sv.trim() == "true"); }
75                        crate::base::FieldValue::TextList(svs) => {
76                            if let Some(sv) = svs.last() { obj.base.normally_in_service = Some(sv.trim() == "true"); }
77                        }
78                        _ => {}
79                    }
80                }
81                "IdentifiedObject.description" => {
82                    match val {
83                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.description = sv.clone(); }
84                        crate::base::FieldValue::TextList(svs) => {
85                            if let Some(sv) = svs.last() { obj.base.base.base.description = sv.clone(); }
86                        }
87                        _ => {}
88                    }
89                }
90                "IdentifiedObject.energyIdentCodeEic" => {
91                    match val {
92                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.energy_ident_code_eic = sv.clone(); }
93                        crate::base::FieldValue::TextList(svs) => {
94                            if let Some(sv) = svs.last() { obj.base.base.base.energy_ident_code_eic = sv.clone(); }
95                        }
96                        _ => {}
97                    }
98                }
99                "IdentifiedObject.mRID" => {
100                    match val {
101                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.m_rid = sv.clone(); }
102                        crate::base::FieldValue::TextList(svs) => {
103                            if let Some(sv) = svs.last() { obj.base.base.base.m_rid = sv.clone(); }
104                        }
105                        _ => {}
106                    }
107                }
108                "IdentifiedObject.name" => {
109                    match val {
110                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.name = sv.clone(); }
111                        crate::base::FieldValue::TextList(svs) => {
112                            if let Some(sv) = svs.last() { obj.base.base.base.name = sv.clone(); }
113                        }
114                        _ => {}
115                    }
116                }
117                "IdentifiedObject.shortName" => {
118                    match val {
119                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.short_name = sv.clone(); }
120                        crate::base::FieldValue::TextList(svs) => {
121                            if let Some(sv) = svs.last() { obj.base.base.base.short_name = sv.clone(); }
122                        }
123                        _ => {}
124                    }
125                }
126                _ => {}
127            }
128        }
129        obj
130    }
131}