15 #include <unordered_map>
18 #include <dpsim/Config.h>
19 #include <dpsim/DataLogger.h>
20 #include <dpsim/DenseLUAdapter.h>
21 #include <dpsim/DirectLinearSolver.h>
22 #include <dpsim/DirectLinearSolverConfiguration.h>
23 #include <dpsim/Solver.h>
25 #include <dpsim/KLUAdapter.h>
27 #include <dpsim/SparseLUAdapter.h>
29 #include <dpsim/GpuDenseAdapter.h>
30 #ifdef WITH_CUDA_SPARSE
31 #include <dpsim/GpuSparseAdapter.h>
34 #include <dpsim/GpuMagmaAdapter.h>
37 #include <dpsim-models/AttributeList.h>
38 #include <dpsim-models/SimPowerComp.h>
39 #include <dpsim-models/SimSignalComp.h>
40 #include <dpsim-models/Solver/MNASwitchInterface.h>
41 #include <dpsim-models/Solver/MNAVariableCompInterface.h>
42 #include <dpsim/MNASolver.h>
46 enum DirectLinearSolverImpl {
63 std::unordered_map<std::bitset<SWITCH_NUM>, std::vector<SparseMatrix>>
66 std::unordered_map<std::bitset<SWITCH_NUM>,
67 std::vector<std::shared_ptr<DirectLinearSolver>>>
119 std::vector<std::shared_ptr<CPS::MNAInterface>> &comp)
override;
126 Int timeStepCount)
override;
142 void solve(Real time, Int timeStepCount)
override;
154 std::shared_ptr<DirectLinearSolver>
161 CPS::Logger::Level logLevel = CPS::Logger::Level::info);
185 : Task(solver.
mName +
".Solve"), mSolver(solver) {
188 if (it->getRightVector()->get().size() != 0)
189 mAttributeDependencies.push_back(it->getRightVector());
191 for (
auto node : solver.
mNodes) {
192 mModifiedAttributes.push_back(node->mVoltage);
197 void execute(Real time, Int timeStepCount) {
198 mSolver.solve(time, timeStepCount);
209 : Task(solver.
mName +
".Solve"), mSolver(solver), mFreqIdx(freqIdx) {
212 if (it->getRightVector()->get().size() != 0)
213 mAttributeDependencies.push_back(it->getRightVector());
215 for (
auto node : solver.
mNodes) {
216 mModifiedAttributes.push_back(node->mVoltage);
219 mModifiedAttributes.push_back(leftVec);
223 void execute(Real time, Int timeStepCount) {
224 mSolver.solveWithHarmonics(time, timeStepCount, mFreqIdx);
236 : Task(solver.
mName +
".Solve"), mSolver(solver) {
239 if (it->getRightVector()->get().size() != 0)
240 mAttributeDependencies.push_back(it->getRightVector());
243 if (it->getRightVector()->get().size() != 0)
244 mAttributeDependencies.push_back(it->getRightVector());
246 for (
auto node : solver.
mNodes) {
247 mModifiedAttributes.push_back(node->mVoltage);
252 void execute(Real time, Int timeStepCount) {
253 mSolver.solveWithSystemMatrixRecomputation(time, timeStepCount);
254 mSolver.log(time, timeStepCount);
265 : Task(solver.
mName +
".Log"), mSolver(solver) {
267 mModifiedAttributes.push_back(Scheduler::external);
270 void execute(Real time, Int timeStepCount) {
271 mSolver.log(time, timeStepCount);
Tasks to be defined by every component.
Solver class using Modified Nodal Analysis (MNA).
std::shared_ptr< CPS::Task > createSolveTask() override
Create a solve task for this solver implementation.
void stampVariableSystemMatrix() override
Stamps components into the variable system matrix.
void logSolveTime()
Logging of the right-hand-side solution time.
virtual ~MnaSolverDirect()=default
Destructor.
void logFactorizationTime()
Logging of the LU factorization time.
void solve(Real time, Int timeStepCount) override
Solves system for single frequency.
void logRecomputationTime()
Logging of the LU refactorization time.
virtual void recomputeSystemMatrix(Real time)
Recomputes systems matrix.
SparseMatrix mVariableSystemMatrix
System matrix including stamp of static and variable elements.
SparseMatrix mBaseSystemMatrix
System matrix including all static elements.
std::unordered_map< std::bitset< SWITCH_NUM >, std::vector< SparseMatrix > > mSwitchedMatrices
Map of system matrices where the key is the bitset describing the switch states.
void switchedMatrixStamp(std::size_t index, std::vector< std::shared_ptr< CPS::MNAInterface >> &comp) override
Applies a component stamp to the matrix with the given switch index.
std::shared_ptr< DirectLinearSolver > createDirectSolverImplementation(CPS::Logger::Log mSLog)
Returns a pointer to an object of type DirectLinearSolver.
void setDirectLinearSolverConfiguration(DirectLinearSolverConfiguration &configuration) override
Sets the linear solver configuration.
DirectLinearSolverImpl mImplementationInUse
LU factorization indicator.
std::shared_ptr< DirectLinearSolver > mDirectLinearSolverVariableSystemMatrix
LU factorization of variable system matrix.
void setDirectLinearSolverImplementation(DirectLinearSolverImpl implementation)
Sets the linear solver to "implementation" and creates an object.
std::shared_ptr< CPS::Task > createSolveTaskHarm(UInt freqIdx) override
Create a solve task for this solver implementation.
std::shared_ptr< CPS::Task > createSolveTaskRecomp() override
Create a solve task for recomputation solver.
void logSystemMatrices() override
Logging of system matrices and source vector.
void createEmptySystemMatrix() override
Create system matrix.
std::shared_ptr< CPS::Task > createLogTask() override
Create a solve task for this solver implementation.
void logLUTimes() override
log LU decomposition times
void switchedMatrixEmpty(std::size_t index) override
Sets all entries in the matrix with the given switch index to zero.
void solveWithSystemMatrixRecomputation(Real time, Int timeStepCount) override
Solves the system with variable system matrix.
std::unordered_map< std::bitset< SWITCH_NUM >, std::vector< std::shared_ptr< DirectLinearSolver > > > mDirectLinearSolvers
Map of direct linear solvers related to the system matrices.
MnaSolverDirect(String name, CPS::Domain domain=CPS::Domain::DP, CPS::Logger::Level logLevel=CPS::Logger::Level::info)
DirectLinearSolverConfiguration mConfigurationInUse
LU factorization configuration.
void solveWithHarmonics(Real time, Int timeStepCount, Int freqIdx) override
Solves system for multiple frequencies.
Solver class using Modified Nodal Analysis (MNA).
std::vector< CPS::Attribute< Matrix >::Ptr > mLeftSideVectorHarm
Solution vector of unknown quantities (parallel frequencies)
CPS::MNAInterface::List mMNAIntfVariableComps
List of variable components if they must be accessed as MNAInterface objects.
CPS::MNAInterface::List mMNAComponents
List of MNA components with static stamp into system matrix.
CPS::Attribute< Matrix >::Ptr mLeftSideVector
Solution vector of unknown quantities.
CPS::SimNode< VarType >::List mNodes
List of simulation nodes.
String mName
Name for logging.
CPS::Logger::Log mSLog
Logger.