DPsim
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 
12 template <class BaseClass> class Creator {
13 
14 public:
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 
22 template <class DerivedClass, class BaseClass>
23 class DerivedCreator : public Creator<BaseClass> {
24 
25 public:
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 
33 template <class BaseClass> class Factory {
34 public:
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 
66 private:
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 
80 template <class BaseClass> class FactoryRegistration {
81 public:
82  FactoryRegistration(std::string type, Creator<BaseClass> *Fn) {
83  Factory<BaseClass>::get().registerExciter(type, Fn);
84  }
85 };
86 
87 namespace SynchronGeneratorFactory {
88 namespace SP {
89 namespace Ph1 {
90 void registerSynchronGenerators() {
101  _6aOrderSP(
102  "6a",
106  _6bOrderSP(
107  "6b",
110 }
111 } // namespace Ph1
112 } // namespace SP
113 
114 namespace DP {
115 namespace Ph1 {
116 void registerSynchronGenerators() {
118  _4OrderDPIter(
119  "4PCM", new DerivedCreator<
123  _4OrderDPTPM("4TPM",
124  new DerivedCreator<
128  _6OrderDPIter(
129  "6PCM", new DerivedCreator<
132 }
133 } // namespace Ph1
134 } // namespace DP
135 } // namespace SynchronGeneratorFactory
4 Order Synchronous generator model for transient stability analysis
4 Order Synchronous generator model for transient stability analysis
6 Order Synchronous generator model for transient stability analysis
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...