11 #include <dpsim/DataLogger.h>
12 #include <dpsim/DenseLUAdapter.h>
13 #include <dpsim/DirectLinearSolverConfiguration.h>
14 #include <dpsim/MNASolver.h>
15 #include <dpsim/MNASolverDirect.h>
16 #include <dpsim/SparseLUAdapter.h>
18 #include <dpsim/KLUAdapter.h>
21 #include <dpsim/GpuDenseAdapter.h>
22 #ifdef WITH_CUDA_SPARSE
23 #include <dpsim/GpuSparseAdapter.h>
26 #include <dpsim/GpuMagmaAdapter.h>
29 #ifdef WITH_MNASOLVERPLUGIN
30 #include <dpsim/MNASolverPlugin.h>
39 static std::vector<DirectLinearSolverImpl> ret = {
40 #ifdef WITH_MNASOLVERPLUGIN
41 DirectLinearSolverImpl::Plugin,
44 DirectLinearSolverImpl::CUDADense,
45 #ifdef WITH_CUDA_SPARSE
47 DirectLinearSolverImpl::CUDASparse,
49 DirectLinearSolverImpl::CUDAMagma,
52 DirectLinearSolverImpl::DenseLU, DirectLinearSolverImpl::SparseLU,
54 DirectLinearSolverImpl::KLU
61 template <
typename VarType>
62 static std::shared_ptr<MnaSolver<VarType>>
factory(
63 String name, CPS::Domain domain = CPS::Domain::DP,
64 CPS::Logger::Level logLevel = CPS::Logger::Level::info,
66 String pluginName =
"plugin.so") {
68 if (implementation == DirectLinearSolverImpl::Undef) {
70 implementation = DirectLinearSolverImpl::KLU;
75 CPS::Logger::Log log = CPS::Logger::get(
76 "MnaSolverFactory", CPS::Logger::Level::info, CPS::Logger::Level::info);
78 switch (implementation) {
82 case DirectLinearSolverImpl::SparseLU: {
83 log->info(
"creating SparseLUAdapter solver implementation");
84 std::shared_ptr<MnaSolverDirect<VarType>> sparseSolver =
85 std::make_shared<MnaSolverDirect<VarType>>(name, domain, logLevel);
86 sparseSolver->setDirectLinearSolverImplementation(
87 DirectLinearSolverImpl::SparseLU);
90 case DirectLinearSolverImpl::DenseLU: {
91 log->info(
"creating DenseLUAdapter solver implementation");
92 std::shared_ptr<MnaSolverDirect<VarType>> denseSolver =
93 std::make_shared<MnaSolverDirect<VarType>>(name, domain, logLevel);
94 denseSolver->setDirectLinearSolverImplementation(
95 DirectLinearSolverImpl::DenseLU);
99 case DirectLinearSolverImpl::KLU: {
100 log->info(
"creating KLUAdapter solver implementation");
101 std::shared_ptr<MnaSolverDirect<VarType>> kluSolver =
102 std::make_shared<MnaSolverDirect<VarType>>(name, domain, logLevel);
103 kluSolver->setDirectLinearSolverImplementation(
104 DirectLinearSolverImpl::KLU);
109 case DirectLinearSolverImpl::CUDADense: {
110 log->info(
"creating GpuDenseAdapter solver implementation");
111 std::shared_ptr<MnaSolverDirect<VarType>> gpuDenseSolver =
112 std::make_shared<MnaSolverDirect<VarType>>(name, domain, logLevel);
113 gpuDenseSolver->setDirectLinearSolverImplementation(
114 DirectLinearSolverImpl::CUDADense);
115 return gpuDenseSolver;
117 #ifdef WITH_CUDA_SPARSE
118 case DirectLinearSolverImpl::CUDASparse: {
119 log->info(
"creating GpuSparseAdapter solver implementation");
120 std::shared_ptr<MnaSolverDirect<VarType>> gpuSparseSolver =
121 std::make_shared<MnaSolverDirect<VarType>>(name, domain, logLevel);
122 gpuSparseSolver->setDirectLinearSolverImplementation(
123 DirectLinearSolverImpl::CUDASparse);
124 return gpuSparseSolver;
128 case DirectLinearSolverImpl::CUDAMagma: {
129 log->info(
"creating GpuMagmaAdapter solver implementation");
130 std::shared_ptr<MnaSolverDirect<VarType>> gpuMagmaSolver =
131 std::make_shared<MnaSolverDirect<VarType>>(name, domain, logLevel);
132 gpuMagmaSolver->setDirectLinearSolverImplementation(
133 DirectLinearSolverImpl::CUDAMagma);
134 return gpuMagmaSolver;
138 #ifdef WITH_MNASOLVERPLUGIN
139 case DirectLinearSolverImpl::Plugin:
140 log->info(
"creating Plugin solver implementation");
141 return std::make_shared<MnaSolverPlugin<VarType>>(pluginName, name,
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