Skip to main content

cimstructs/
WindGenType3IEC.rs

1/// Parent class supporting relationships to IEC wind turbines type 3 generator models of IEC type 3A and 3B.
2#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]
3pub struct WindGenType3IEC {
4    #[serde(flatten)]
5    pub base: super::IdentifiedObject,
6    /// Maximum active current ramp rate (dipmax). It is a project-dependent parameter.
7    #[serde(skip_serializing_if = "Option::is_none")]
8    pub dipmax: Option<f64>,
9    /// Maximum reactive current ramp rate (diqmax). It is a project-dependent parameter.
10    #[serde(skip_serializing_if = "Option::is_none")]
11    pub diqmax: Option<f64>,
12    /// Electromagnetic transient reactance (xS). It is a type-dependent parameter.
13    #[serde(skip_serializing_if = "Option::is_none")]
14    pub xs: Option<f64>,
15}
16impl crate::base::CimElement for WindGenType3IEC {
17    fn mrid(&self) -> &str { &self.base.id }
18    fn type_name(&self) -> &'static str { "WindGenType3IEC" }
19    fn as_any(&self) -> &dyn std::any::Any { self }
20    fn to_json_value(&self) -> serde_json::Value {
21        serde_json::to_value(self).unwrap_or(serde_json::Value::Null)
22    }
23    fn to_block(&self) -> crate::base::RdfBlock {
24        let mut block = self.base.to_block();
25        block.type_name = "WindGenType3IEC".to_string();
26        if let Some(v) = self.dipmax {
27            block.fields.insert("WindGenType3IEC.dipmax".into(), crate::base::FieldValue::Text(v.to_string()));
28        }
29        if let Some(v) = self.diqmax {
30            block.fields.insert("WindGenType3IEC.diqmax".into(), crate::base::FieldValue::Text(v.to_string()));
31        }
32        if let Some(v) = self.xs {
33            block.fields.insert("WindGenType3IEC.xs".into(), crate::base::FieldValue::Text(v.to_string()));
34        }
35        block
36    }
37}
38
39impl WindGenType3IEC {
40    pub fn from_block(b: &crate::base::RdfBlock) -> Self {
41        let mut obj = Self::default();
42        obj.base.id.clone_from(&b.mrid);
43        for (key, val) in &b.fields {
44            match key.as_str() {
45                "WindGenType3IEC.dipmax" => {
46                    match val {
47                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.dipmax = Some(v); } }
48                        crate::base::FieldValue::TextList(svs) => {
49                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.dipmax = Some(v); } }
50                        }
51                        _ => {}
52                    }
53                }
54                "WindGenType3IEC.diqmax" => {
55                    match val {
56                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.diqmax = Some(v); } }
57                        crate::base::FieldValue::TextList(svs) => {
58                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.diqmax = Some(v); } }
59                        }
60                        _ => {}
61                    }
62                }
63                "WindGenType3IEC.xs" => {
64                    match val {
65                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.xs = Some(v); } }
66                        crate::base::FieldValue::TextList(svs) => {
67                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.xs = Some(v); } }
68                        }
69                        _ => {}
70                    }
71                }
72                "IdentifiedObject.description" => {
73                    match val {
74                        crate::base::FieldValue::Text(sv) => { obj.base.description = sv.clone(); }
75                        crate::base::FieldValue::TextList(svs) => {
76                            if let Some(sv) = svs.last() { obj.base.description = sv.clone(); }
77                        }
78                        _ => {}
79                    }
80                }
81                "IdentifiedObject.energyIdentCodeEic" => {
82                    match val {
83                        crate::base::FieldValue::Text(sv) => { obj.base.energy_ident_code_eic = sv.clone(); }
84                        crate::base::FieldValue::TextList(svs) => {
85                            if let Some(sv) = svs.last() { obj.base.energy_ident_code_eic = sv.clone(); }
86                        }
87                        _ => {}
88                    }
89                }
90                "IdentifiedObject.mRID" => {
91                    match val {
92                        crate::base::FieldValue::Text(sv) => { obj.base.m_rid = sv.clone(); }
93                        crate::base::FieldValue::TextList(svs) => {
94                            if let Some(sv) = svs.last() { obj.base.m_rid = sv.clone(); }
95                        }
96                        _ => {}
97                    }
98                }
99                "IdentifiedObject.name" => {
100                    match val {
101                        crate::base::FieldValue::Text(sv) => { obj.base.name = sv.clone(); }
102                        crate::base::FieldValue::TextList(svs) => {
103                            if let Some(sv) = svs.last() { obj.base.name = sv.clone(); }
104                        }
105                        _ => {}
106                    }
107                }
108                "IdentifiedObject.shortName" => {
109                    match val {
110                        crate::base::FieldValue::Text(sv) => { obj.base.short_name = sv.clone(); }
111                        crate::base::FieldValue::TextList(svs) => {
112                            if let Some(sv) = svs.last() { obj.base.short_name = sv.clone(); }
113                        }
114                        _ => {}
115                    }
116                }
117                _ => {}
118            }
119        }
120        obj
121    }
122}