Skip to main content

cimstructs/
WindTurbineType1or2IEC.rs

1/// Parent class supporting relationships to IEC wind turbines type 1 and type 2 including their control models. Generator model for wind turbine of IEC type 1 or type 2 is a standard asynchronous generator model. Reference: IEC 61400-27-1:2015, 5.5.2 and 5.5.3.
2#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]
3pub struct WindTurbineType1or2IEC {
4    #[serde(flatten)]
5    pub base: super::WindTurbineType1or2Dynamics,
6    /// Wind mechanical model associated with this wind generator type 1 or type 2 model.
7    #[serde(skip_serializing_if = "Option::is_none")]
8    pub wind_mech_iec: Option<super::base::MridRef>,
9    /// Wind turbune protection model associated with this wind generator type 1 or type 2 model.
10    #[serde(skip_serializing_if = "Option::is_none")]
11    pub wind_protection_iec: Option<super::base::MridRef>,
12}
13impl crate::base::CimElement for WindTurbineType1or2IEC {
14    fn mrid(&self) -> &str { &self.base.base.base.id }
15    fn type_name(&self) -> &'static str { "WindTurbineType1or2IEC" }
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 = "WindTurbineType1or2IEC".to_string();
23        if let Some(ref v) = self.wind_mech_iec {
24            block.fields.insert("WindTurbineType1or2IEC.WindMechIEC".into(), crate::base::FieldValue::Resource(v.mrid.clone()));
25        }
26        if let Some(ref v) = self.wind_protection_iec {
27            block.fields.insert("WindTurbineType1or2IEC.WindProtectionIEC".into(), crate::base::FieldValue::Resource(v.mrid.clone()));
28        }
29        block
30    }
31}
32
33impl WindTurbineType1or2IEC {
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                "WindTurbineType1or2IEC.WindMechIEC" => {
40                    if let crate::base::FieldValue::Resource(sv) = val {
41                        obj.wind_mech_iec = Some(crate::base::MridRef { mrid: sv.clone() });
42                    }
43                }
44                "WindTurbineType1or2IEC.WindProtectionIEC" => {
45                    if let crate::base::FieldValue::Resource(sv) = val {
46                        obj.wind_protection_iec = Some(crate::base::MridRef { mrid: sv.clone() });
47                    }
48                }
49                "WindTurbineType1or2Dynamics.AsynchronousMachineDynamics" => {
50                    if let crate::base::FieldValue::Resource(sv) = val {
51                        obj.base.asynchronous_machine_dynamics = Some(crate::base::MridRef { mrid: sv.clone() });
52                    }
53                }
54                "WindTurbineType1or2Dynamics.RemoteInputSignal" => {
55                    if let crate::base::FieldValue::Resource(sv) = val {
56                        obj.base.remote_input_signal = Some(crate::base::MridRef { mrid: sv.clone() });
57                    }
58                }
59                "DynamicsFunctionBlock.enabled" => {
60                    match val {
61                        crate::base::FieldValue::Text(sv) => { obj.base.base.enabled = Some(sv.trim() == "true"); }
62                        crate::base::FieldValue::TextList(svs) => {
63                            if let Some(sv) = svs.last() { obj.base.base.enabled = Some(sv.trim() == "true"); }
64                        }
65                        _ => {}
66                    }
67                }
68                "IdentifiedObject.description" => {
69                    match val {
70                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.description = sv.clone(); }
71                        crate::base::FieldValue::TextList(svs) => {
72                            if let Some(sv) = svs.last() { obj.base.base.base.description = sv.clone(); }
73                        }
74                        _ => {}
75                    }
76                }
77                "IdentifiedObject.energyIdentCodeEic" => {
78                    match val {
79                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.energy_ident_code_eic = sv.clone(); }
80                        crate::base::FieldValue::TextList(svs) => {
81                            if let Some(sv) = svs.last() { obj.base.base.base.energy_ident_code_eic = sv.clone(); }
82                        }
83                        _ => {}
84                    }
85                }
86                "IdentifiedObject.mRID" => {
87                    match val {
88                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.m_rid = sv.clone(); }
89                        crate::base::FieldValue::TextList(svs) => {
90                            if let Some(sv) = svs.last() { obj.base.base.base.m_rid = sv.clone(); }
91                        }
92                        _ => {}
93                    }
94                }
95                "IdentifiedObject.name" => {
96                    match val {
97                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.name = sv.clone(); }
98                        crate::base::FieldValue::TextList(svs) => {
99                            if let Some(sv) = svs.last() { obj.base.base.base.name = sv.clone(); }
100                        }
101                        _ => {}
102                    }
103                }
104                "IdentifiedObject.shortName" => {
105                    match val {
106                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.short_name = sv.clone(); }
107                        crate::base::FieldValue::TextList(svs) => {
108                            if let Some(sv) = svs.last() { obj.base.base.base.short_name = sv.clone(); }
109                        }
110                        _ => {}
111                    }
112                }
113                _ => {}
114            }
115        }
116        obj
117    }
118}