DPsim
Loading...
Searching...
No Matches
Factory.h
1#include <dpsim-models/Definitions.h>
2#include <dpsim-models/Logger.h>
3#include <map>
4
5#include <dpsim-models/Base/Base_ReducedOrderSynchronGenerator.h>
6#include <dpsim-models/DP/DP_Ph1_SynchronGenerator4OrderPCM.h>
7#include <dpsim-models/DP/DP_Ph1_SynchronGenerator4OrderTPM.h>
8#include <dpsim-models/DP/DP_Ph1_SynchronGenerator6OrderPCM.h>
9
10#pragma once
11
12template <class BaseClass> class Creator {
13
14public:
15 virtual ~Creator() {}
16
17 virtual std::shared_ptr<BaseClass>
18 Create(const std::string &name,
19 CPS::Logger::Level logLevel = CPS::Logger::Level::debug) = 0;
20};
21
22template <class DerivedClass, class BaseClass>
23class DerivedCreator : public Creator<BaseClass> {
24
25public:
26 std::shared_ptr<BaseClass>
27 Create(const std::string &name,
28 CPS::Logger::Level logLevel = CPS::Logger::Level::debug) {
29 return std::shared_ptr<BaseClass>(new DerivedClass(name, logLevel));
30 }
31};
32
33template <class BaseClass> class Factory {
34public:
35 static Factory &get() {
36 static Factory instance;
37 return instance;
38 }
39
40 std::vector<std::string> getItems() {
41
42 std::vector<std::string> items;
43 for (auto g : functionMap) {
44 items.push_back(g.first);
45 }
46
47 return items;
48 }
49
50 std::shared_ptr<BaseClass>
51 create(std::string type, const std::string &name,
52 CPS::Logger::Level logLevel = CPS::Logger::Level::debug) {
53
54 auto it = functionMap.find(type);
55 if (it != functionMap.end())
56 return it->second->Create(name, logLevel);
57 else
58 throw CPS::SystemError("Unsupported type '" + type + "'!");
59 }
60
61 void registerExciter(const std::string &type, Creator<BaseClass> *Fn) {
62
63 functionMap[type] = Fn;
64 }
65
66private:
67 Factory() {}
68 Factory(const Factory &);
69 ~Factory() {
70 auto i = functionMap.begin();
71 while (i != functionMap.end()) {
72 delete (*i).second;
73 ++i;
74 }
75 }
76
77 std::map<std::string, Creator<BaseClass> *> functionMap;
78};
79
80template <class BaseClass> class FactoryRegistration {
81public:
82 FactoryRegistration(std::string type, Creator<BaseClass> *Fn) {
83 Factory<BaseClass>::get().registerExciter(type, Fn);
84 }
85};
86
87namespace SynchronGeneratorFactory {
88namespace SP {
89namespace Ph1 {
90void registerSynchronGenerators() {
101 _6aOrderSP(
102 "6a",
106 _6bOrderSP(
107 "6b",
110}
111} // namespace Ph1
112} // namespace SP
113
114namespace DP {
115namespace Ph1 {
116void registerSynchronGenerators() {
117 FactoryRegistration<CPS::Base::ReducedOrderSynchronGenerator<CPS::Complex>>
118 _4OrderDPIter(
119 "4PCM", new DerivedCreator<
120 CPS::DP::Ph1::SynchronGenerator4OrderPCM,
121 CPS::Base::ReducedOrderSynchronGenerator<CPS::Complex>>);
122 FactoryRegistration<CPS::Base::ReducedOrderSynchronGenerator<CPS::Complex>>
123 _4OrderDPTPM("4TPM",
124 new DerivedCreator<
125 CPS::DP::Ph1::SynchronGenerator4OrderTPM,
126 CPS::Base::ReducedOrderSynchronGenerator<CPS::Complex>>);
127 FactoryRegistration<CPS::Base::ReducedOrderSynchronGenerator<CPS::Complex>>
128 _6OrderDPIter(
129 "6PCM", new DerivedCreator<
130 CPS::DP::Ph1::SynchronGenerator6OrderPCM,
131 CPS::Base::ReducedOrderSynchronGenerator<CPS::Complex>>);
132}
133} // namespace Ph1
134} // namespace DP
135} // namespace SynchronGeneratorFactory
Base class for SP VBR synchronous generator model single phase.
Voltage-Behind-Reactance (VBR) implementation of 3rd order synchronous generator model.
Voltage-Behind-Reactance (VBR) implementation of 4th order synchronous generator model.
Voltage-Behind-Reactance (VBR) implementation of 5th type 2 order synchronous generator model Ref: Mi...
Voltage-Behind-Reactance (VBR) implementation of 6th order synchronous generator model Marconato's mo...
Voltage-Behind-Reactance (VBR) implementation of 6th order synchronous generator model Anderson-Fouad...