Skip to main content

cimstructs/
PFVArType1IEEEVArController.rs

1/// IEEE VAR controller type 1 which operates by moving the voltage reference directly. Reference: IEEE 421.5-2005, 11.3.
2#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]
3pub struct PFVArType1IEEEVArController {
4    #[serde(flatten)]
5    pub base: super::PFVArControllerType1Dynamics,
6    /// Var controller time delay (TVARC) (>= 0). Typical value = 5.
7    #[serde(skip_serializing_if = "Option::is_none")]
8    pub tvarc: Option<f64>,
9    /// Synchronous machine power factor (VVAR).
10    #[serde(skip_serializing_if = "Option::is_none")]
11    pub vvar: Option<f64>,
12    /// Var controller deadband (VVARC_BW). Typical value = 0,02.
13    #[serde(skip_serializing_if = "Option::is_none")]
14    pub vvarcbw: Option<f64>,
15    /// Var controller reference (VVARREF).
16    #[serde(skip_serializing_if = "Option::is_none")]
17    pub vvarref: Option<f64>,
18    /// Maximum machine terminal voltage needed for pf/VAr controller to be enabled (VVTMAX) (> PVFArType1IEEEVArController.vvtmin).
19    #[serde(skip_serializing_if = "Option::is_none")]
20    pub vvtmax: Option<f64>,
21    /// Minimum machine terminal voltage needed to enable pf/var controller (VVTMIN) (< PVFArType1IEEEVArController.vvtmax).
22    #[serde(skip_serializing_if = "Option::is_none")]
23    pub vvtmin: Option<f64>,
24}
25impl crate::base::CimElement for PFVArType1IEEEVArController {
26    fn mrid(&self) -> &str { &self.base.base.base.id }
27    fn type_name(&self) -> &'static str { "PFVArType1IEEEVArController" }
28    fn as_any(&self) -> &dyn std::any::Any { self }
29    fn to_json_value(&self) -> serde_json::Value {
30        serde_json::to_value(self).unwrap_or(serde_json::Value::Null)
31    }
32    fn to_block(&self) -> crate::base::RdfBlock {
33        let mut block = self.base.to_block();
34        block.type_name = "PFVArType1IEEEVArController".to_string();
35        if let Some(v) = self.tvarc {
36            block.fields.insert("PFVArType1IEEEVArController.tvarc".into(), crate::base::FieldValue::Text(v.to_string()));
37        }
38        if let Some(v) = self.vvar {
39            block.fields.insert("PFVArType1IEEEVArController.vvar".into(), crate::base::FieldValue::Text(v.to_string()));
40        }
41        if let Some(v) = self.vvarcbw {
42            block.fields.insert("PFVArType1IEEEVArController.vvarcbw".into(), crate::base::FieldValue::Text(v.to_string()));
43        }
44        if let Some(v) = self.vvarref {
45            block.fields.insert("PFVArType1IEEEVArController.vvarref".into(), crate::base::FieldValue::Text(v.to_string()));
46        }
47        if let Some(v) = self.vvtmax {
48            block.fields.insert("PFVArType1IEEEVArController.vvtmax".into(), crate::base::FieldValue::Text(v.to_string()));
49        }
50        if let Some(v) = self.vvtmin {
51            block.fields.insert("PFVArType1IEEEVArController.vvtmin".into(), crate::base::FieldValue::Text(v.to_string()));
52        }
53        block
54    }
55}
56
57impl PFVArType1IEEEVArController {
58    pub fn from_block(b: &crate::base::RdfBlock) -> Self {
59        let mut obj = Self::default();
60        obj.base.base.base.id.clone_from(&b.mrid);
61        for (key, val) in &b.fields {
62            match key.as_str() {
63                "PFVArType1IEEEVArController.tvarc" => {
64                    match val {
65                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.tvarc = Some(v); } }
66                        crate::base::FieldValue::TextList(svs) => {
67                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.tvarc = Some(v); } }
68                        }
69                        _ => {}
70                    }
71                }
72                "PFVArType1IEEEVArController.vvar" => {
73                    match val {
74                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.vvar = Some(v); } }
75                        crate::base::FieldValue::TextList(svs) => {
76                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.vvar = Some(v); } }
77                        }
78                        _ => {}
79                    }
80                }
81                "PFVArType1IEEEVArController.vvarcbw" => {
82                    match val {
83                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.vvarcbw = Some(v); } }
84                        crate::base::FieldValue::TextList(svs) => {
85                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.vvarcbw = Some(v); } }
86                        }
87                        _ => {}
88                    }
89                }
90                "PFVArType1IEEEVArController.vvarref" => {
91                    match val {
92                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.vvarref = Some(v); } }
93                        crate::base::FieldValue::TextList(svs) => {
94                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.vvarref = Some(v); } }
95                        }
96                        _ => {}
97                    }
98                }
99                "PFVArType1IEEEVArController.vvtmax" => {
100                    match val {
101                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.vvtmax = Some(v); } }
102                        crate::base::FieldValue::TextList(svs) => {
103                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.vvtmax = Some(v); } }
104                        }
105                        _ => {}
106                    }
107                }
108                "PFVArType1IEEEVArController.vvtmin" => {
109                    match val {
110                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.vvtmin = Some(v); } }
111                        crate::base::FieldValue::TextList(svs) => {
112                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.vvtmin = Some(v); } }
113                        }
114                        _ => {}
115                    }
116                }
117                "PFVArControllerType1Dynamics.ExcitationSystemDynamics" => {
118                    if let crate::base::FieldValue::Resource(sv) = val {
119                        obj.base.excitation_system_dynamics = Some(crate::base::MridRef { mrid: sv.clone() });
120                    }
121                }
122                "DynamicsFunctionBlock.enabled" => {
123                    match val {
124                        crate::base::FieldValue::Text(sv) => { obj.base.base.enabled = Some(sv.trim() == "true"); }
125                        crate::base::FieldValue::TextList(svs) => {
126                            if let Some(sv) = svs.last() { obj.base.base.enabled = Some(sv.trim() == "true"); }
127                        }
128                        _ => {}
129                    }
130                }
131                "IdentifiedObject.description" => {
132                    match val {
133                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.description = sv.clone(); }
134                        crate::base::FieldValue::TextList(svs) => {
135                            if let Some(sv) = svs.last() { obj.base.base.base.description = sv.clone(); }
136                        }
137                        _ => {}
138                    }
139                }
140                "IdentifiedObject.energyIdentCodeEic" => {
141                    match val {
142                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.energy_ident_code_eic = sv.clone(); }
143                        crate::base::FieldValue::TextList(svs) => {
144                            if let Some(sv) = svs.last() { obj.base.base.base.energy_ident_code_eic = sv.clone(); }
145                        }
146                        _ => {}
147                    }
148                }
149                "IdentifiedObject.mRID" => {
150                    match val {
151                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.m_rid = sv.clone(); }
152                        crate::base::FieldValue::TextList(svs) => {
153                            if let Some(sv) = svs.last() { obj.base.base.base.m_rid = sv.clone(); }
154                        }
155                        _ => {}
156                    }
157                }
158                "IdentifiedObject.name" => {
159                    match val {
160                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.name = sv.clone(); }
161                        crate::base::FieldValue::TextList(svs) => {
162                            if let Some(sv) = svs.last() { obj.base.base.base.name = sv.clone(); }
163                        }
164                        _ => {}
165                    }
166                }
167                "IdentifiedObject.shortName" => {
168                    match val {
169                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.short_name = sv.clone(); }
170                        crate::base::FieldValue::TextList(svs) => {
171                            if let Some(sv) = svs.last() { obj.base.base.base.short_name = sv.clone(); }
172                        }
173                        _ => {}
174                    }
175                }
176                _ => {}
177            }
178        }
179        obj
180    }
181}