DPsim
Reader.h
1 /* Copyright 2017-2021 Institute for Automation of Complex Power Systems,
2  * EONERC, RWTH Aachen University
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, You can obtain one at https://mozilla.org/MPL/2.0/.
7  *********************************************************************************/
8 
9 #pragma once
10 
11 #include <list>
12 #include <map>
13 
14 #include <dpsim-models/Components.h>
15 #include <dpsim-models/Definitions.h>
16 #include <dpsim-models/Filesystem.h>
17 #include <dpsim-models/Logger.h>
18 #include <dpsim-models/SimNode.h>
19 #include <dpsim-models/SimPowerComp.h>
20 #include <dpsim-models/SimTerminal.h>
21 #include <dpsim-models/SystemTopology.h>
22 
23 /* ====== WARNING =======
24  *
25  * DO NOT INCLUDE ANY CIM++ Headers here!
26  *
27  * CIM++ has more than 600 Headers files.
28  * Including them here will also include them in <DPsim.h>
29  * Which will have a huge impact on compile time!
30  *
31  * Use forward declarations instead!
32  */
33 
34 /* Forward declarations */
35 class CIMModel;
36 class BaseClass;
37 #ifdef CGMES_BUILD
38 #include <UnitMultiplier.hpp>
39 namespace CIMPP {
40 class SvVoltage;
41 class SvPowerFlow;
42 class ACLineSegment;
43 class SynchronousMachine;
44 class ExternalNetworkInjection;
45 class EnergyConsumer;
46 class PowerTransformer;
47 class EquivalentShunt;
48 class TopologicalNode;
49 class ConductingEquipment;
50 }; // namespace CIMPP
51 #else
52 #include <CIMNamespaces.hpp>
53 #endif
54 
55 namespace CPS {
56 namespace CIM {
57 class InvalidTopology {};
58 
59 class Reader {
60 private:
62  Logger::Log mSLog;
64  Logger::Level mComponentLogLevel;
66  CIMModel *mModel;
68  IdentifiedObject::List mComponents;
71  Real mFrequency;
73  Real mOmega;
75  Domain mDomain;
77  GeneratorType mGeneratorType;
81  PhaseType mPhase;
84  std::map<String, TopologicalNode::Ptr> mPowerflowNodes;
86  std::map<String, TopologicalPowerComp::Ptr> mPowerflowEquipment;
88  std::map<String, TopologicalTerminal::Ptr> mPowerflowTerminals;
90  Bool mUseProtectionSwitches = false;
91 
92  // #### shunt component settings ####
94  Bool mSetShuntCapacitor = false;
96  Real mShuntCapacitorValue = -1;
98  Bool mSetShuntConductance = false;
100  Real mShuntConductanceValue = 1e-6;
101 
102  // #### General Functions ####
104  static Real unitValue(Real value, CIMPP::UnitMultiplier mult);
106  void processSvVoltage(CIMPP::SvVoltage *volt);
108  void processSvPowerFlow(CIMPP::SvPowerFlow *flow);
110  template <typename VarType>
111  void processTopologicalNode(CIMPP::TopologicalNode *topNode);
113  void addFiles(const fs::path &filename);
115  void addFiles(const std::list<fs::path> &filenames);
119  void parseFiles();
121  SystemTopology systemTopology();
122 
123  // #### Mapping Functions ####
125  Matrix::Index mapTopologicalNode(String mrid);
127  TopologicalPowerComp::Ptr mapComponent(BaseClass *obj);
131  TopologicalPowerComp::Ptr mapACLineSegment(CIMPP::ACLineSegment *line);
133  TopologicalPowerComp::Ptr mapPowerTransformer(CIMPP::PowerTransformer *trans);
137  TopologicalPowerComp::Ptr
138  mapSynchronousMachine(CIMPP::SynchronousMachine *machine);
143  TopologicalPowerComp::Ptr mapEnergyConsumer(CIMPP::EnergyConsumer *consumer);
145  TopologicalPowerComp::Ptr
146  mapExternalNetworkInjection(CIMPP::ExternalNetworkInjection *extnet);
148  TopologicalPowerComp::Ptr mapEquivalentShunt(CIMPP::EquivalentShunt *shunt);
149 
150  // #### Helper Functions ####
152  Real determineBaseVoltageAssociatedWithEquipment(
153  CIMPP::ConductingEquipment *equipment);
154 
155 public:
158  Reader(String name, Logger::Level logLevel = Logger::Level::info,
159  Logger::Level componentLogLevel = Logger::Level::off);
161  virtual ~Reader();
162 
164  SystemTopology loadCIM(Real systemFrequency, const fs::path &filename,
165  Domain domain = Domain::DP,
166  PhaseType phase = PhaseType::Single,
167  GeneratorType genType = GeneratorType::None);
169  SystemTopology loadCIM(Real systemFrequency,
170  const std::list<fs::path> &filenames,
171  Domain domain = Domain::DP,
172  PhaseType phase = PhaseType::Single,
173  GeneratorType genType = GeneratorType::None);
175  SystemTopology loadCIM(Real systemFrequency,
176  const std::list<CPS::String> &filenamesString,
177  Domain domain = Domain::DP,
178  PhaseType phase = PhaseType::Single,
179  GeneratorType genType = GeneratorType::None);
180 
181  // #### shunt component settings ####
183  void setShuntCapacitor(Real v);
185  void setShuntConductance(Real v);
187  void useProtectionSwitches(Bool value = true);
188 };
189 } // namespace CIM
190 } // namespace CPS
191 
192 #if defined(BASECLASS_H) && !defined(READER_CPP)
193 #error "Do not include CIMpp headers into CPS/DPsim headers!"
194 #endif
void setShuntConductance(Real v)
set shunt conductance value
Definition: Reader.cpp:50
SystemTopology loadCIM(Real systemFrequency, const fs::path &filename, Domain domain=Domain::DP, PhaseType phase=PhaseType::Single, GeneratorType genType=GeneratorType::None)
Parses data from CIM files into the CPS data structure.
Definition: Reader.cpp:209
void useProtectionSwitches(Bool value=true)
If set, some components like loads include protection switches.
Definition: Reader.cpp:56
Reader(String name, Logger::Level logLevel=Logger::Level::info, Logger::Level componentLogLevel=Logger::Level::off)
Definition: Reader.cpp:21
void setShuntCapacitor(Real v)
set shunt capacitor value
Definition: Reader.cpp:45