DPsim
Loading...
Searching...
No Matches
Factory.h
1#include <map>
2
3#include <dpsim-models/Definitions.h>
4#include <dpsim-models/Logger.h>
5
6#include <dpsim-models/Base/Base_Exciter.h>
7#include <dpsim-models/Base/Base_Governor.h>
8#include <dpsim-models/Base/Base_PSS.h>
9#include <dpsim-models/Base/Base_ReducedOrderSynchronGenerator.h>
10#include <dpsim-models/Base/Base_Turbine.h>
11
12#include <dpsim-models/DP/DP_Ph1_SynchronGenerator4OrderPCM.h>
13#include <dpsim-models/DP/DP_Ph1_SynchronGenerator4OrderTPM.h>
14#include <dpsim-models/DP/DP_Ph1_SynchronGenerator6OrderPCM.h>
15#include <dpsim-models/Signal/HydroTurbine.h>
16#include <dpsim-models/Signal/HydroTurbineGovernor.h>
17#include <dpsim-models/Signal/PSS1A.h>
18#include <dpsim-models/Signal/SteamTurbine.h>
19#include <dpsim-models/Signal/SteamTurbineGovernor.h>
20
21#include <dpsim-models/Signal/ExciterDC1.h>
22#include <dpsim-models/Signal/ExciterDC1Simp.h>
23#include <dpsim-models/Signal/ExciterST1Simp.h>
24#include <dpsim-models/Signal/ExciterStatic.h>
25
26#pragma once
27
28template <class BaseClass> class Creator {
29
30public:
31 virtual ~Creator() {}
32
33 virtual std::shared_ptr<BaseClass>
34 Create(const std::string &name,
35 CPS::Logger::Level logLevel = CPS::Logger::Level::debug) = 0;
36};
37
38template <class DerivedClass, class BaseClass>
39class DerivedCreator : public Creator<BaseClass> {
40
41public:
42 std::shared_ptr<BaseClass>
43 Create(const std::string &name,
44 CPS::Logger::Level logLevel = CPS::Logger::Level::debug) {
45 return std::shared_ptr<BaseClass>(new DerivedClass(name, logLevel));
46 }
47};
48
49template <class BaseClass> class Factory {
50public:
51 static Factory &get() {
52 static Factory instance;
53 return instance;
54 }
55
56 std::vector<std::string> getItems() {
57
58 std::vector<std::string> items;
59 for (auto g : functionMap) {
60 items.push_back(g.first);
61 }
62
63 return items;
64 }
65
66 std::shared_ptr<BaseClass>
67 create(std::string type, const std::string &name,
68 CPS::Logger::Level logLevel = CPS::Logger::Level::debug) {
69
70 auto it = functionMap.find(type);
71 if (it != functionMap.end())
72 return it->second->Create(name, logLevel);
73 else
74 throw CPS::SystemError("Unsupported type '" + type + "'!");
75 }
76
77 void registerExciter(const std::string &type, Creator<BaseClass> *Fn) {
78
79 functionMap[type] = Fn;
80 }
81
82private:
83 Factory() {}
84 Factory(const Factory &);
85 ~Factory() {
86 auto i = functionMap.begin();
87 while (i != functionMap.end()) {
88 delete (*i).second;
89 ++i;
90 }
91 }
92
93 std::map<std::string, Creator<BaseClass> *> functionMap;
94};
95
96template <class BaseClass> class FactoryRegistration {
97public:
98 FactoryRegistration(std::string type, Creator<BaseClass> *Fn) {
99 Factory<BaseClass>::get().registerExciter(type, Fn);
100 }
101};
102
103namespace ExciterFactory {
104void registerExciters() {
108 "DC1Simp",
111 "ST1",
114 "Static",
116}
117} // namespace ExciterFactory
118
119namespace SynchronGeneratorFactory {
120namespace SP {
121namespace Ph1 {
122void registerSynchronGenerators() {
123 FactoryRegistration<CPS::SP::Ph1::ReducedOrderSynchronGeneratorVBR> _3OrderSP(
124 "3", new DerivedCreator<CPS::SP::Ph1::SynchronGenerator3OrderVBR,
125 CPS::SP::Ph1::ReducedOrderSynchronGeneratorVBR>);
126 FactoryRegistration<CPS::SP::Ph1::ReducedOrderSynchronGeneratorVBR> _4OrderSP(
127 "4", new DerivedCreator<CPS::SP::Ph1::SynchronGenerator4OrderVBR,
128 CPS::SP::Ph1::ReducedOrderSynchronGeneratorVBR>);
129 FactoryRegistration<CPS::SP::Ph1::ReducedOrderSynchronGeneratorVBR> _5OrderSP(
130 "5", new DerivedCreator<CPS::SP::Ph1::SynchronGenerator5OrderVBR,
131 CPS::SP::Ph1::ReducedOrderSynchronGeneratorVBR>);
132 FactoryRegistration<CPS::SP::Ph1::ReducedOrderSynchronGeneratorVBR>
133 _6aOrderSP(
134 "6a",
135 new DerivedCreator<CPS::SP::Ph1::SynchronGenerator6aOrderVBR,
136 CPS::SP::Ph1::ReducedOrderSynchronGeneratorVBR>);
137 FactoryRegistration<CPS::SP::Ph1::ReducedOrderSynchronGeneratorVBR>
138 _6bOrderSP(
139 "6b",
140 new DerivedCreator<CPS::SP::Ph1::SynchronGenerator6bOrderVBR,
141 CPS::SP::Ph1::ReducedOrderSynchronGeneratorVBR>);
142}
143} // namespace Ph1
144} // namespace SP
145
146namespace DP {
147namespace Ph1 {
148void registerSynchronGenerators() {
149 FactoryRegistration<CPS::Base::ReducedOrderSynchronGenerator<CPS::Complex>>
150 _4OrderDPIter(
151 "4PCM", new DerivedCreator<
152 CPS::DP::Ph1::SynchronGenerator4OrderPCM,
153 CPS::Base::ReducedOrderSynchronGenerator<CPS::Complex>>);
154 FactoryRegistration<CPS::Base::ReducedOrderSynchronGenerator<CPS::Complex>>
155 _4OrderDPTPM("4TPM",
156 new DerivedCreator<
157 CPS::DP::Ph1::SynchronGenerator4OrderTPM,
158 CPS::Base::ReducedOrderSynchronGenerator<CPS::Complex>>);
159 FactoryRegistration<CPS::Base::ReducedOrderSynchronGenerator<CPS::Complex>>
160 _6OrderDPIter(
161 "6PCM", new DerivedCreator<
162 CPS::DP::Ph1::SynchronGenerator6OrderPCM,
163 CPS::Base::ReducedOrderSynchronGenerator<CPS::Complex>>);
164}
165} // namespace Ph1
166} // namespace DP
167} // namespace SynchronGeneratorFactory
168
169namespace PSSFactory {
170void registerPSSs() {
171 FactoryRegistration<CPS::Base::PSS> _PSS1A(
172 "PSS1A", new DerivedCreator<CPS::Signal::PSS1A, CPS::Base::PSS>);
173}
174} // namespace PSSFactory
175
176namespace GovernorFactory {
177void registerGovernors() {
178 FactoryRegistration<CPS::Base::Governor> _SteamGovernor(
179 "SteamGovernor", new DerivedCreator<CPS::Signal::SteamTurbineGovernor,
180 CPS::Base::Governor>);
181 FactoryRegistration<CPS::Base::Governor> _HydroGovernor(
182 "HydroGovernor", new DerivedCreator<CPS::Signal::HydroTurbineGovernor,
183 CPS::Base::Governor>);
184}
185} // namespace GovernorFactory
186
187namespace TurbineFactory {
188void registerTurbines() {
189 FactoryRegistration<CPS::Base::Turbine> _SteamTurbine(
190 "SteamTurbine",
191 new DerivedCreator<CPS::Signal::SteamTurbine, CPS::Base::Turbine>);
192 FactoryRegistration<CPS::Base::Turbine> _HydroTurbine(
193 "HydroTurbine",
194 new DerivedCreator<CPS::Signal::HydroTurbine, CPS::Base::Turbine>);
195}
196} // namespace TurbineFactory