DPsim
Loading...
Searching...
No Matches
MNASolverFactory.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 <dpsim/DataLogger.h>
14#include <dpsim/MNASolver.h>
16#ifdef WITH_SPARSE
18#endif
19#ifdef WITH_KLU
20#include <dpsim/KLUAdapter.h>
21#endif
22#ifdef WITH_CUDA
24#ifdef WITH_CUDA_SPARSE
26#endif
27#ifdef WITH_MAGMA
29#endif
30#endif
31#ifdef WITH_MNASOLVERPLUGIN
33#endif
34
35namespace DPsim {
36
38public:
40 static const std::vector<DirectLinearSolverImpl> mSupportedSolverImpls(void) {
41 static std::vector<DirectLinearSolverImpl> ret = {
42#ifdef WITH_MNASOLVERPLUGIN
44#endif //WITH_MNASOLVERPLUGIN
45#ifdef WITH_CUDA
47#ifdef WITH_CUDA_SPARSE
48#endif // WITH_CUDA_SPARSE
50#ifdef WITH_MAGMA
52#endif // WITH_MAGMA
53#endif // WITH_CUDA
55#ifdef WITH_SPARSE
57#endif // WITH_SPARSE
58#ifdef WITH_KLU
60#endif // WITH_KLU
61 };
62 return ret;
63 }
64
66 template <typename VarType>
67 static std::shared_ptr<MnaSolver<VarType>> factory(
68 String name, CPS::Domain domain = CPS::Domain::DP,
69 CPS::Logger::Level logLevel = CPS::Logger::Level::info,
70 DirectLinearSolverImpl implementation = mSupportedSolverImpls().back(),
71 String pluginName = "plugin.so") {
72 //To avoid regression we use KLU in case of undefined implementation
73 if (implementation == DirectLinearSolverImpl::Undef) {
74#ifdef WITH_KLU
75 implementation = DirectLinearSolverImpl::KLU;
76#else
77 implementation = mSupportedSolverImpls().back();
78#endif
79 }
81 "MnaSolverFactory", CPS::Logger::Level::info, CPS::Logger::Level::info);
82
83 switch (implementation) {
84 /* TODO: have only one "solver" object of type MnaSolverDirect and only use setDirectLinearSolverImplementation in the switch-case.
85 * This is not done now, since MnaSolverDirect and MnaSolver are distinct classes - and someone might add another subclass of MnaSolver
86 * to the project (MnaSolverIterative?). It is planned to merge MnaSolverDirect and MnaSolver anyway, so this won't happen.
87 */
88#ifdef WITH_SPARSE
90 SPDLOG_LOGGER_INFO(log, "creating SparseLUAdapter solver implementation");
91 std::shared_ptr<MnaSolverDirect<VarType>> sparseSolver =
92 std::make_shared<MnaSolverDirect<VarType>>(name, domain, logLevel);
93 sparseSolver->setDirectLinearSolverImplementation(
95 return sparseSolver;
96 }
97#endif // WITH_SPARSE
99 SPDLOG_LOGGER_INFO(log, "creating DenseLUAdapter solver implementation");
100 std::shared_ptr<MnaSolverDirect<VarType>> denseSolver =
101 std::make_shared<MnaSolverDirect<VarType>>(name, domain, logLevel);
102 denseSolver->setDirectLinearSolverImplementation(
104 return denseSolver;
105 }
106#ifdef WITH_KLU
108 SPDLOG_LOGGER_INFO(log, "creating KLUAdapter solver implementation");
109 std::shared_ptr<MnaSolverDirect<VarType>> kluSolver =
110 std::make_shared<MnaSolverDirect<VarType>>(name, domain, logLevel);
111 kluSolver->setDirectLinearSolverImplementation(
113 return kluSolver;
114 }
115#endif
116#ifdef WITH_CUDA
118 SPDLOG_LOGGER_INFO(log, "creating GpuDenseAdapter solver implementation");
119 std::shared_ptr<MnaSolverDirect<VarType>> gpuDenseSolver =
120 std::make_shared<MnaSolverDirect<VarType>>(name, domain, logLevel);
121 gpuDenseSolver->setDirectLinearSolverImplementation(
123 return gpuDenseSolver;
124 }
125#ifdef WITH_CUDA_SPARSE
127 SPDLOG_LOGGER_INFO(log,
128 "creating GpuSparseAdapter solver implementation");
129 std::shared_ptr<MnaSolverDirect<VarType>> gpuSparseSolver =
130 std::make_shared<MnaSolverDirect<VarType>>(name, domain, logLevel);
131 gpuSparseSolver->setDirectLinearSolverImplementation(
133 return gpuSparseSolver;
134 }
135#endif
136#ifdef WITH_MAGMA
138 SPDLOG_LOGGER_INFO(log, "creating GpuMagmaAdapter solver implementation");
139 std::shared_ptr<MnaSolverDirect<VarType>> gpuMagmaSolver =
140 std::make_shared<MnaSolverDirect<VarType>>(name, domain, logLevel);
141 gpuMagmaSolver->setDirectLinearSolverImplementation(
143 return gpuMagmaSolver;
144 }
145#endif
146#endif
147#ifdef WITH_MNASOLVERPLUGIN
149 SPDLOG_LOGGER_INFO(log, "creating Plugin solver implementation");
150 return std::make_shared<MnaSolverPlugin<VarType>>(pluginName, name,
151 domain, logLevel);
152#endif
153 default:
154 throw CPS::SystemError("unsupported MNA implementation.");
155 }
156 }
157};
158} // namespace DPsim
spdlog::level::level_enum Level
Definition Logger.h:33
std::shared_ptr< spdlog::logger > Log
Definition Logger.h:34
static Log get(const std::string &name, Level filelevel=Level::info, Level clilevel=Level::off)
Definition Logger.cpp:139
static const std::vector< DirectLinearSolverImpl > mSupportedSolverImpls(void)
MNA implementations supported by this compilation.
static std::shared_ptr< MnaSolver< VarType > > factory(String name, CPS::Domain domain=CPS::Domain::DP, CPS::Logger::Level logLevel=CPS::Logger::Level::info, DirectLinearSolverImpl implementation=mSupportedSolverImpls().back(), String pluginName="plugin.so")
sovlerImpl: choose the most advanced solver implementation available by default
CPS::String String
Definition Definitions.h:20
DirectLinearSolverImpl