Skip to main content

cimstructs/
VCompIEEEType1.rs

1/// Terminal voltage transducer and load compensator as defined in IEEE 421.5-2005, 4. This model is common to all excitation system models described in the IEEE Standard. Parameter details: If Rc and Xc are set to zero, the load compensation is not employed and the behaviour is as a simple sensing circuit. If all parameters (Rc, Xc and Tr) are set to zero, the standard model VCompIEEEType1 is bypassed. Reference: IEEE 421.5-2005 4.
2#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]
3pub struct VCompIEEEType1 {
4    #[serde(flatten)]
5    pub base: super::VoltageCompensatorDynamics,
6    /// Resistive component of compensation of a generator (Rc) (>= 0).
7    #[serde(skip_serializing_if = "Option::is_none")]
8    pub rc: Option<f64>,
9    /// Time constant which is used for the combined voltage sensing and compensation signal (Tr) (>= 0).
10    #[serde(skip_serializing_if = "Option::is_none")]
11    pub tr: Option<f64>,
12    /// Reactive component of compensation of a generator (Xc) (>= 0).
13    #[serde(skip_serializing_if = "Option::is_none")]
14    pub xc: Option<f64>,
15}
16impl crate::base::CimElement for VCompIEEEType1 {
17    fn mrid(&self) -> &str { &self.base.base.base.id }
18    fn type_name(&self) -> &'static str { "VCompIEEEType1" }
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 = "VCompIEEEType1".to_string();
26        if let Some(v) = self.rc {
27            block.fields.insert("VCompIEEEType1.rc".into(), crate::base::FieldValue::Text(v.to_string()));
28        }
29        if let Some(v) = self.tr {
30            block.fields.insert("VCompIEEEType1.tr".into(), crate::base::FieldValue::Text(v.to_string()));
31        }
32        if let Some(v) = self.xc {
33            block.fields.insert("VCompIEEEType1.xc".into(), crate::base::FieldValue::Text(v.to_string()));
34        }
35        block
36    }
37}
38
39impl VCompIEEEType1 {
40    pub fn from_block(b: &crate::base::RdfBlock) -> Self {
41        let mut obj = Self::default();
42        obj.base.base.base.id.clone_from(&b.mrid);
43        for (key, val) in &b.fields {
44            match key.as_str() {
45                "VCompIEEEType1.rc" => {
46                    match val {
47                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.rc = Some(v); } }
48                        crate::base::FieldValue::TextList(svs) => {
49                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.rc = Some(v); } }
50                        }
51                        _ => {}
52                    }
53                }
54                "VCompIEEEType1.tr" => {
55                    match val {
56                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.tr = Some(v); } }
57                        crate::base::FieldValue::TextList(svs) => {
58                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.tr = Some(v); } }
59                        }
60                        _ => {}
61                    }
62                }
63                "VCompIEEEType1.xc" => {
64                    match val {
65                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.xc = Some(v); } }
66                        crate::base::FieldValue::TextList(svs) => {
67                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.xc = Some(v); } }
68                        }
69                        _ => {}
70                    }
71                }
72                "VoltageCompensatorDynamics.ExcitationSystemDynamics" => {
73                    if let crate::base::FieldValue::Resource(sv) = val {
74                        obj.base.excitation_system_dynamics = Some(crate::base::MridRef { mrid: sv.clone() });
75                    }
76                }
77                "DynamicsFunctionBlock.enabled" => {
78                    match val {
79                        crate::base::FieldValue::Text(sv) => { obj.base.base.enabled = Some(sv.trim() == "true"); }
80                        crate::base::FieldValue::TextList(svs) => {
81                            if let Some(sv) = svs.last() { obj.base.base.enabled = Some(sv.trim() == "true"); }
82                        }
83                        _ => {}
84                    }
85                }
86                "IdentifiedObject.description" => {
87                    match val {
88                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.description = sv.clone(); }
89                        crate::base::FieldValue::TextList(svs) => {
90                            if let Some(sv) = svs.last() { obj.base.base.base.description = sv.clone(); }
91                        }
92                        _ => {}
93                    }
94                }
95                "IdentifiedObject.energyIdentCodeEic" => {
96                    match val {
97                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.energy_ident_code_eic = sv.clone(); }
98                        crate::base::FieldValue::TextList(svs) => {
99                            if let Some(sv) = svs.last() { obj.base.base.base.energy_ident_code_eic = sv.clone(); }
100                        }
101                        _ => {}
102                    }
103                }
104                "IdentifiedObject.mRID" => {
105                    match val {
106                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.m_rid = sv.clone(); }
107                        crate::base::FieldValue::TextList(svs) => {
108                            if let Some(sv) = svs.last() { obj.base.base.base.m_rid = sv.clone(); }
109                        }
110                        _ => {}
111                    }
112                }
113                "IdentifiedObject.name" => {
114                    match val {
115                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.name = sv.clone(); }
116                        crate::base::FieldValue::TextList(svs) => {
117                            if let Some(sv) = svs.last() { obj.base.base.base.name = sv.clone(); }
118                        }
119                        _ => {}
120                    }
121                }
122                "IdentifiedObject.shortName" => {
123                    match val {
124                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.short_name = sv.clone(); }
125                        crate::base::FieldValue::TextList(svs) => {
126                            if let Some(sv) = svs.last() { obj.base.base.base.short_name = sv.clone(); }
127                        }
128                        _ => {}
129                    }
130                }
131                _ => {}
132            }
133        }
134        obj
135    }
136}