Skip to main content

cimstructs/
TieFlow.rs

1/// Defines the structure (in terms of location and direction) of the net interchange constraint for a control area. This constraint may be used by either AGC or power flow.
2#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]
3pub struct TieFlow {
4    #[serde(flatten)]
5    pub base: super::IdentifiedObject,
6    /// The control area of the tie flows.
7    #[serde(skip_serializing_if = "Option::is_none")]
8    pub control_area: Option<super::base::MridRef>,
9    /// The terminal to which this tie flow belongs.
10    #[serde(skip_serializing_if = "Option::is_none")]
11    pub terminal: Option<super::base::MridRef>,
12    /// Specifies the sign of the tie flow associated with a control area. True if positive flow into the terminal (load convention) is also positive flow into the control area. See the description of ControlArea for further explanation of how TieFlow.positiveFlowIn is used.
13    #[serde(skip_serializing_if = "Option::is_none")]
14    pub positive_flow_in: Option<bool>,
15}
16impl crate::base::CimElement for TieFlow {
17    fn mrid(&self) -> &str { &self.base.id }
18    fn type_name(&self) -> &'static str { "TieFlow" }
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 = "TieFlow".to_string();
26        if let Some(ref v) = self.control_area {
27            block.fields.insert("TieFlow.ControlArea".into(), crate::base::FieldValue::Resource(v.mrid.clone()));
28        }
29        if let Some(ref v) = self.terminal {
30            block.fields.insert("TieFlow.Terminal".into(), crate::base::FieldValue::Resource(v.mrid.clone()));
31        }
32        if let Some(v) = self.positive_flow_in {
33            block.fields.insert("TieFlow.positiveFlowIn".into(), crate::base::FieldValue::Text(v.to_string()));
34        }
35        block
36    }
37}
38
39impl TieFlow {
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                "TieFlow.ControlArea" => {
46                    if let crate::base::FieldValue::Resource(sv) = val {
47                        obj.control_area = Some(crate::base::MridRef { mrid: sv.clone() });
48                    }
49                }
50                "TieFlow.Terminal" => {
51                    if let crate::base::FieldValue::Resource(sv) = val {
52                        obj.terminal = Some(crate::base::MridRef { mrid: sv.clone() });
53                    }
54                }
55                "TieFlow.positiveFlowIn" => {
56                    match val {
57                        crate::base::FieldValue::Text(sv) => { obj.positive_flow_in = Some(sv.trim() == "true"); }
58                        crate::base::FieldValue::TextList(svs) => {
59                            if let Some(sv) = svs.last() { obj.positive_flow_in = Some(sv.trim() == "true"); }
60                        }
61                        _ => {}
62                    }
63                }
64                "IdentifiedObject.description" => {
65                    match val {
66                        crate::base::FieldValue::Text(sv) => { obj.base.description = sv.clone(); }
67                        crate::base::FieldValue::TextList(svs) => {
68                            if let Some(sv) = svs.last() { obj.base.description = sv.clone(); }
69                        }
70                        _ => {}
71                    }
72                }
73                "IdentifiedObject.energyIdentCodeEic" => {
74                    match val {
75                        crate::base::FieldValue::Text(sv) => { obj.base.energy_ident_code_eic = sv.clone(); }
76                        crate::base::FieldValue::TextList(svs) => {
77                            if let Some(sv) = svs.last() { obj.base.energy_ident_code_eic = sv.clone(); }
78                        }
79                        _ => {}
80                    }
81                }
82                "IdentifiedObject.mRID" => {
83                    match val {
84                        crate::base::FieldValue::Text(sv) => { obj.base.m_rid = sv.clone(); }
85                        crate::base::FieldValue::TextList(svs) => {
86                            if let Some(sv) = svs.last() { obj.base.m_rid = sv.clone(); }
87                        }
88                        _ => {}
89                    }
90                }
91                "IdentifiedObject.name" => {
92                    match val {
93                        crate::base::FieldValue::Text(sv) => { obj.base.name = sv.clone(); }
94                        crate::base::FieldValue::TextList(svs) => {
95                            if let Some(sv) = svs.last() { obj.base.name = sv.clone(); }
96                        }
97                        _ => {}
98                    }
99                }
100                "IdentifiedObject.shortName" => {
101                    match val {
102                        crate::base::FieldValue::Text(sv) => { obj.base.short_name = sv.clone(); }
103                        crate::base::FieldValue::TextList(svs) => {
104                            if let Some(sv) = svs.last() { obj.base.short_name = sv.clone(); }
105                        }
106                        _ => {}
107                    }
108                }
109                _ => {}
110            }
111        }
112        obj
113    }
114}