Skip to main content

cimstructs/
WindProtectionIEC.rs

1/// The grid protection model includes protection against over- and under-voltage, and against over- and under-frequency. Reference: IEC 61400-27-1:2015, 5.6.6.
2#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]
3pub struct WindProtectionIEC {
4    #[serde(flatten)]
5    pub base: super::IdentifiedObject,
6    /// Maximum rate of change of frequency (dFmax). It is a type-dependent parameter.
7    #[serde(skip_serializing_if = "Option::is_none")]
8    pub dfimax: Option<f64>,
9    /// Wind turbine over frequency protection activation threshold (fover). It is a project-dependent parameter.
10    #[serde(skip_serializing_if = "Option::is_none")]
11    pub fover: Option<f64>,
12    /// Wind turbine under frequency protection activation threshold (funder). It is a project-dependent parameter.
13    #[serde(skip_serializing_if = "Option::is_none")]
14    pub funder: Option<f64>,
15    /// Zero crossing measurement mode (Mzc). It is a type-dependent parameter. true = WT protection system uses zero crossings to detect frequency (1 in the IEC model) false = WT protection system does not use zero crossings to detect frequency (0 in the IEC model).
16    #[serde(skip_serializing_if = "Option::is_none")]
17    pub mzc: Option<bool>,
18    /// Time interval of moving average window (TfMA) (>= 0). It is a type-dependent parameter.
19    #[serde(skip_serializing_if = "Option::is_none")]
20    pub tfma: Option<f64>,
21    /// Wind turbine over voltage protection activation threshold (uover). It is a project-dependent parameter.
22    #[serde(skip_serializing_if = "Option::is_none")]
23    pub uover: Option<f64>,
24    /// Wind turbine under voltage protection activation threshold (uunder). It is a project-dependent parameter.
25    #[serde(skip_serializing_if = "Option::is_none")]
26    pub uunder: Option<f64>,
27}
28impl crate::base::CimElement for WindProtectionIEC {
29    fn mrid(&self) -> &str { &self.base.id }
30    fn type_name(&self) -> &'static str { "WindProtectionIEC" }
31    fn as_any(&self) -> &dyn std::any::Any { self }
32    fn to_json_value(&self) -> serde_json::Value {
33        serde_json::to_value(self).unwrap_or(serde_json::Value::Null)
34    }
35    fn to_block(&self) -> crate::base::RdfBlock {
36        let mut block = self.base.to_block();
37        block.type_name = "WindProtectionIEC".to_string();
38        if let Some(v) = self.dfimax {
39            block.fields.insert("WindProtectionIEC.dfimax".into(), crate::base::FieldValue::Text(v.to_string()));
40        }
41        if let Some(v) = self.fover {
42            block.fields.insert("WindProtectionIEC.fover".into(), crate::base::FieldValue::Text(v.to_string()));
43        }
44        if let Some(v) = self.funder {
45            block.fields.insert("WindProtectionIEC.funder".into(), crate::base::FieldValue::Text(v.to_string()));
46        }
47        if let Some(v) = self.mzc {
48            block.fields.insert("WindProtectionIEC.mzc".into(), crate::base::FieldValue::Text(v.to_string()));
49        }
50        if let Some(v) = self.tfma {
51            block.fields.insert("WindProtectionIEC.tfma".into(), crate::base::FieldValue::Text(v.to_string()));
52        }
53        if let Some(v) = self.uover {
54            block.fields.insert("WindProtectionIEC.uover".into(), crate::base::FieldValue::Text(v.to_string()));
55        }
56        if let Some(v) = self.uunder {
57            block.fields.insert("WindProtectionIEC.uunder".into(), crate::base::FieldValue::Text(v.to_string()));
58        }
59        block
60    }
61}
62
63impl WindProtectionIEC {
64    pub fn from_block(b: &crate::base::RdfBlock) -> Self {
65        let mut obj = Self::default();
66        obj.base.id.clone_from(&b.mrid);
67        for (key, val) in &b.fields {
68            match key.as_str() {
69                "WindProtectionIEC.dfimax" => {
70                    match val {
71                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.dfimax = Some(v); } }
72                        crate::base::FieldValue::TextList(svs) => {
73                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.dfimax = Some(v); } }
74                        }
75                        _ => {}
76                    }
77                }
78                "WindProtectionIEC.fover" => {
79                    match val {
80                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.fover = Some(v); } }
81                        crate::base::FieldValue::TextList(svs) => {
82                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.fover = Some(v); } }
83                        }
84                        _ => {}
85                    }
86                }
87                "WindProtectionIEC.funder" => {
88                    match val {
89                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.funder = Some(v); } }
90                        crate::base::FieldValue::TextList(svs) => {
91                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.funder = Some(v); } }
92                        }
93                        _ => {}
94                    }
95                }
96                "WindProtectionIEC.mzc" => {
97                    match val {
98                        crate::base::FieldValue::Text(sv) => { obj.mzc = Some(sv.trim() == "true"); }
99                        crate::base::FieldValue::TextList(svs) => {
100                            if let Some(sv) = svs.last() { obj.mzc = Some(sv.trim() == "true"); }
101                        }
102                        _ => {}
103                    }
104                }
105                "WindProtectionIEC.tfma" => {
106                    match val {
107                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.tfma = Some(v); } }
108                        crate::base::FieldValue::TextList(svs) => {
109                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.tfma = Some(v); } }
110                        }
111                        _ => {}
112                    }
113                }
114                "WindProtectionIEC.uover" => {
115                    match val {
116                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.uover = Some(v); } }
117                        crate::base::FieldValue::TextList(svs) => {
118                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.uover = Some(v); } }
119                        }
120                        _ => {}
121                    }
122                }
123                "WindProtectionIEC.uunder" => {
124                    match val {
125                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.uunder = Some(v); } }
126                        crate::base::FieldValue::TextList(svs) => {
127                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.uunder = Some(v); } }
128                        }
129                        _ => {}
130                    }
131                }
132                "IdentifiedObject.description" => {
133                    match val {
134                        crate::base::FieldValue::Text(sv) => { obj.base.description = sv.clone(); }
135                        crate::base::FieldValue::TextList(svs) => {
136                            if let Some(sv) = svs.last() { obj.base.description = sv.clone(); }
137                        }
138                        _ => {}
139                    }
140                }
141                "IdentifiedObject.energyIdentCodeEic" => {
142                    match val {
143                        crate::base::FieldValue::Text(sv) => { obj.base.energy_ident_code_eic = sv.clone(); }
144                        crate::base::FieldValue::TextList(svs) => {
145                            if let Some(sv) = svs.last() { obj.base.energy_ident_code_eic = sv.clone(); }
146                        }
147                        _ => {}
148                    }
149                }
150                "IdentifiedObject.mRID" => {
151                    match val {
152                        crate::base::FieldValue::Text(sv) => { obj.base.m_rid = sv.clone(); }
153                        crate::base::FieldValue::TextList(svs) => {
154                            if let Some(sv) = svs.last() { obj.base.m_rid = sv.clone(); }
155                        }
156                        _ => {}
157                    }
158                }
159                "IdentifiedObject.name" => {
160                    match val {
161                        crate::base::FieldValue::Text(sv) => { obj.base.name = sv.clone(); }
162                        crate::base::FieldValue::TextList(svs) => {
163                            if let Some(sv) = svs.last() { obj.base.name = sv.clone(); }
164                        }
165                        _ => {}
166                    }
167                }
168                "IdentifiedObject.shortName" => {
169                    match val {
170                        crate::base::FieldValue::Text(sv) => { obj.base.short_name = sv.clone(); }
171                        crate::base::FieldValue::TextList(svs) => {
172                            if let Some(sv) = svs.last() { obj.base.short_name = sv.clone(); }
173                        }
174                        _ => {}
175                    }
176                }
177                _ => {}
178            }
179        }
180        obj
181    }
182}