DPsim
Loading...
Searching...
No Matches
Reader.h
Go to the documentation of this file.
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
19#include <dpsim-models/Logger.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;
52class Disconnector;
53class Breaker;
54}; // namespace CIMPP
55#else
56#include <CIMNamespaces.hpp>
57#endif
58
59namespace CPS {
60namespace CIM {
61template <typename T, typename = void>
62struct has_value_member : std::false_type {};
63
64template <typename T>
66 std::void_t<decltype(std::declval<const T &>().value)>>
67 : std::true_type {};
68
69template <typename T> const auto &cimString(const T &field) {
70 if constexpr (has_value_member<T>::value) {
71 return field.value;
72 } else {
73 return field;
74 }
75}
76
78
79class Reader {
80public:
82
83private:
85 Logger::Log mSLog;
87 Logger::Level mComponentLogLevel;
89 CIMModel *mModel;
91 IdentifiedObject::List mComponents;
94 Real mFrequency;
96 Real mOmega;
98 Domain mDomain;
100 GeneratorType mGeneratorType;
104 PhaseType mPhase;
107 std::map<String, TopologicalNode::Ptr> mPowerflowNodes;
109 std::map<String, TopologicalPowerComp::Ptr> mPowerflowEquipment;
111 std::map<String, TopologicalTerminal::Ptr> mPowerflowTerminals;
113 Bool mUseProtectionSwitches = false;
115 VoltageTargetUnit mExtnetVoltageTargetUnit = VoltageTargetUnit::Auto;
116
117 // #### shunt component settings ####
119 Bool mSetShuntCapacitor = false;
121 Real mShuntCapacitorValue = -1;
123 Bool mSetShuntConductance = false;
125 Real mShuntConductanceValue = 1e-6;
126
127 // #### General Functions ####
129 static Real unitValue(Real value, CIMPP::UnitMultiplier mult);
131 void processSvVoltage(CIMPP::SvVoltage *volt);
133 void processSvPowerFlow(CIMPP::SvPowerFlow *flow);
135 template <typename VarType>
136 void processTopologicalNode(CIMPP::TopologicalNode *topNode);
138 void addFiles(const fs::path &filename);
140 void addFiles(const std::list<fs::path> &filenames);
144 void parseFiles();
146 SystemTopology systemTopology();
147
148 // #### Mapping Functions ####
150 Matrix::Index mapTopologicalNode(String mrid);
152 TopologicalPowerComp::Ptr mapComponent(BaseClass *obj);
154 Bool isSupportedConductingEquipment(BaseClass *obj) const;
158 TopologicalPowerComp::Ptr mapACLineSegment(CIMPP::ACLineSegment *line);
160 TopologicalPowerComp::Ptr mapPowerTransformer(CIMPP::PowerTransformer *trans);
165 mapSynchronousMachine(CIMPP::SynchronousMachine *machine);
170 TopologicalPowerComp::Ptr mapEnergyConsumer(CIMPP::EnergyConsumer *consumer);
173 mapExternalNetworkInjection(CIMPP::ExternalNetworkInjection *extnet);
175 TopologicalPowerComp::Ptr mapEquivalentShunt(CIMPP::EquivalentShunt *shunt);
177 TopologicalPowerComp::Ptr mapDisconnector(CIMPP::Disconnector *disc);
179 TopologicalPowerComp::Ptr mapBreaker(CIMPP::Breaker *cb);
180
181 // #### Helper Functions ####
183 Real determineBaseVoltageAssociatedWithEquipment(
184 CIMPP::ConductingEquipment *equipment);
185
186public:
189 Reader(String name, Logger::Level logLevel = Logger::Level::info,
190 Logger::Level componentLogLevel = Logger::Level::off);
192 virtual ~Reader();
193
195 SystemTopology loadCIM(Real systemFrequency, const fs::path &filename,
196 Domain domain = Domain::DP,
200 SystemTopology loadCIM(Real systemFrequency,
201 const std::list<fs::path> &filenames,
202 Domain domain = Domain::DP,
206 SystemTopology loadCIM(Real systemFrequency,
207 const std::list<CPS::String> &filenamesString,
208 Domain domain = Domain::DP,
211
212 // #### shunt component settings ####
214 void setShuntCapacitor(Real v);
218 void useProtectionSwitches(Bool value = true);
220};
221} // namespace CIM
222} // namespace CPS
223
224#if defined(BASECLASS_H) && !defined(READER_CPP)
225#error "Do not include CIMpp headers into CPS/DPsim headers!"
226#endif
void setExtnetVoltageTargetUnit(VoltageTargetUnit unit)
Definition Reader.cpp:62
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:249
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
virtual ~Reader()
Definition Reader.cpp:32
void setShuntCapacitor(Real v)
set shunt capacitor value
Definition Reader.cpp:47
std::vector< Ptr > List
spdlog::level::level_enum Level
Definition Logger.h:33
std::shared_ptr< spdlog::logger > Log
Definition Logger.h:34
std::shared_ptr< TopologicalPowerComp > Ptr
const auto & cimString(const T &field)
Definition Reader.h:69
std::string String
Definition Definitions.h:65
double Real
Definition Definitions.h:62
bool Bool
Definition Definitions.h:64
GeneratorType