Skip to main content

cimstructs/
SvInjection.rs

1/// The SvInjection reports the calculated bus injection minus the sum of the terminal flows. The terminal flow is positive out from the bus (load sign convention) and bus injection has positive flow into the bus. SvInjection may have the remainder after state estimation or slack after power flow calculation.
2#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]
3pub struct SvInjection {
4    pub id: String,
5    /// The topological node associated with the flow injection state variable.
6    #[serde(skip_serializing_if = "Option::is_none")]
7    pub topological_node: Option<super::base::MridRef>,
8    /// The active power mismatch between calculated injection and initial injection. Positive sign means injection into the TopologicalNode (bus).
9    #[serde(skip_serializing_if = "Option::is_none")]
10    pub p_injection: Option<f64>,
11    /// The reactive power mismatch between calculated injection and initial injection. Positive sign means injection into the TopologicalNode (bus).
12    #[serde(skip_serializing_if = "Option::is_none")]
13    pub q_injection: Option<f64>,
14}
15impl crate::base::CimElement for SvInjection {
16    fn mrid(&self) -> &str { &self.id }
17    fn type_name(&self) -> &'static str { "SvInjection" }
18    fn as_any(&self) -> &dyn std::any::Any { self }
19    fn to_json_value(&self) -> serde_json::Value {
20        serde_json::to_value(self).unwrap_or(serde_json::Value::Null)
21    }
22    fn to_block(&self) -> crate::base::RdfBlock {
23        let mut block = crate::base::RdfBlock {
24            type_name: "SvInjection".to_string(),
25            mrid: self.id.clone(),
26            fields: std::collections::HashMap::new(),
27            duplicate_fields: std::collections::HashSet::new(),
28        };
29        if let Some(ref v) = self.topological_node {
30            block.fields.insert("SvInjection.TopologicalNode".into(), crate::base::FieldValue::Resource(v.mrid.clone()));
31        }
32        if let Some(v) = self.p_injection {
33            block.fields.insert("SvInjection.pInjection".into(), crate::base::FieldValue::Text(v.to_string()));
34        }
35        if let Some(v) = self.q_injection {
36            block.fields.insert("SvInjection.qInjection".into(), crate::base::FieldValue::Text(v.to_string()));
37        }
38        block
39    }
40}
41
42impl SvInjection {
43    pub fn from_block(b: &crate::base::RdfBlock) -> Self {
44        let mut obj = Self::default();
45        obj.id.clone_from(&b.mrid);
46        for (key, val) in &b.fields {
47            match key.as_str() {
48                "SvInjection.TopologicalNode" => {
49                    if let crate::base::FieldValue::Resource(sv) = val {
50                        obj.topological_node = Some(crate::base::MridRef { mrid: sv.clone() });
51                    }
52                }
53                "SvInjection.pInjection" => {
54                    match val {
55                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.p_injection = Some(v); } }
56                        crate::base::FieldValue::TextList(svs) => {
57                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.p_injection = Some(v); } }
58                        }
59                        _ => {}
60                    }
61                }
62                "SvInjection.qInjection" => {
63                    match val {
64                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.q_injection = Some(v); } }
65                        crate::base::FieldValue::TextList(svs) => {
66                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.q_injection = Some(v); } }
67                        }
68                        _ => {}
69                    }
70                }
71                _ => {}
72            }
73        }
74        obj
75    }
76}