DPsim
Loading...
Searching...
No Matches
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#include <type_traits>
14#include <utility>
15
16#include <dpsim-models/Components.h>
17#include <dpsim-models/Definitions.h>
18#include <dpsim-models/Filesystem.h>
19#include <dpsim-models/Logger.h>
20#include <dpsim-models/SimNode.h>
21#include <dpsim-models/SimPowerComp.h>
22#include <dpsim-models/SimTerminal.h>
23#include <dpsim-models/SystemTopology.h>
24
25/* ====== WARNING =======
26 *
27 * DO NOT INCLUDE ANY CIM++ Headers here!
28 *
29 * CIM++ has more than 600 Headers files.
30 * Including them here will also include them in <DPsim.h>
31 * Which will have a huge impact on compile time!
32 *
33 * Use forward declarations instead!
34 */
35
36/* Forward declarations */
37class CIMModel;
38class BaseClass;
39#ifdef CGMES_BUILD
40#include <UnitMultiplier.hpp>
41namespace CIMPP {
42class SvVoltage;
43class SvPowerFlow;
44class ACLineSegment;
45class SynchronousMachine;
46class ExternalNetworkInjection;
47class EnergyConsumer;
48class PowerTransformer;
49class EquivalentShunt;
50class TopologicalNode;
51class ConductingEquipment;
52}; // namespace CIMPP
53#else
54#include <CIMNamespaces.hpp>
55#endif
56
57namespace CPS {
58namespace CIM {
59template <typename T, typename = void>
60struct has_value_member : std::false_type {};
61
62template <typename T>
64 std::void_t<decltype(std::declval<const T &>().value)>>
65 : std::true_type {};
66
67template <typename T> const auto &cimString(const T &field) {
68 if constexpr (has_value_member<T>::value) {
69 return field.value;
70 } else {
71 return field;
72 }
73}
74
76
77class Reader {
78private:
80 Logger::Log mSLog;
82 Logger::Level mComponentLogLevel;
84 CIMModel *mModel;
86 IdentifiedObject::List mComponents;
89 Real mFrequency;
91 Real mOmega;
93 Domain mDomain;
95 GeneratorType mGeneratorType;
99 PhaseType mPhase;
102 std::map<String, TopologicalNode::Ptr> mPowerflowNodes;
104 std::map<String, TopologicalPowerComp::Ptr> mPowerflowEquipment;
106 std::map<String, TopologicalTerminal::Ptr> mPowerflowTerminals;
108 Bool mUseProtectionSwitches = false;
109
110 // #### shunt component settings ####
112 Bool mSetShuntCapacitor = false;
114 Real mShuntCapacitorValue = -1;
116 Bool mSetShuntConductance = false;
118 Real mShuntConductanceValue = 1e-6;
119
120 // #### General Functions ####
122 static Real unitValue(Real value, CIMPP::UnitMultiplier mult);
124 void processSvVoltage(CIMPP::SvVoltage *volt);
126 void processSvPowerFlow(CIMPP::SvPowerFlow *flow);
128 template <typename VarType>
129 void processTopologicalNode(CIMPP::TopologicalNode *topNode);
131 void addFiles(const fs::path &filename);
133 void addFiles(const std::list<fs::path> &filenames);
137 void parseFiles();
139 SystemTopology systemTopology();
140
141 // #### Mapping Functions ####
143 Matrix::Index mapTopologicalNode(String mrid);
145 TopologicalPowerComp::Ptr mapComponent(BaseClass *obj);
149 TopologicalPowerComp::Ptr mapACLineSegment(CIMPP::ACLineSegment *line);
151 TopologicalPowerComp::Ptr mapPowerTransformer(CIMPP::PowerTransformer *trans);
155 TopologicalPowerComp::Ptr
156 mapSynchronousMachine(CIMPP::SynchronousMachine *machine);
161 TopologicalPowerComp::Ptr mapEnergyConsumer(CIMPP::EnergyConsumer *consumer);
163 TopologicalPowerComp::Ptr
164 mapExternalNetworkInjection(CIMPP::ExternalNetworkInjection *extnet);
166 TopologicalPowerComp::Ptr mapEquivalentShunt(CIMPP::EquivalentShunt *shunt);
167
168 // #### Helper Functions ####
170 Real determineBaseVoltageAssociatedWithEquipment(
171 CIMPP::ConductingEquipment *equipment);
172
173public:
176 Reader(String name, Logger::Level logLevel = Logger::Level::info,
177 Logger::Level componentLogLevel = Logger::Level::off);
179 virtual ~Reader();
180
182 SystemTopology loadCIM(Real systemFrequency, const fs::path &filename,
183 Domain domain = Domain::DP,
184 PhaseType phase = PhaseType::Single,
185 GeneratorType genType = GeneratorType::None);
187 SystemTopology loadCIM(Real systemFrequency,
188 const std::list<fs::path> &filenames,
189 Domain domain = Domain::DP,
190 PhaseType phase = PhaseType::Single,
191 GeneratorType genType = GeneratorType::None);
193 SystemTopology loadCIM(Real systemFrequency,
194 const std::list<CPS::String> &filenamesString,
195 Domain domain = Domain::DP,
196 PhaseType phase = PhaseType::Single,
197 GeneratorType genType = GeneratorType::None);
198
199 // #### shunt component settings ####
201 void setShuntCapacitor(Real v);
203 void setShuntConductance(Real v);
205 void useProtectionSwitches(Bool value = true);
206};
207} // namespace CIM
208} // namespace CPS
209
210#if defined(BASECLASS_H) && !defined(READER_CPP)
211#error "Do not include CIMpp headers into CPS/DPsim headers!"
212#endif
void setShuntConductance(Real v)
set shunt conductance value
Definition Reader.cpp:52
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:211
void useProtectionSwitches(Bool value=true)
If set, some components like loads include protection switches.
Definition Reader.cpp:58
Reader(String name, Logger::Level logLevel=Logger::Level::info, Logger::Level componentLogLevel=Logger::Level::off)
Definition Reader.cpp:23
void setShuntCapacitor(Real v)
set shunt capacitor value
Definition Reader.cpp:47