15#include <unordered_map>
18#include <dpsim/Config.h>
32#ifdef WITH_CUDA_SPARSE
65 std::unordered_map<std::bitset<SWITCH_NUM>, std::vector<SparseMatrix>>
68 std::unordered_map<std::bitset<SWITCH_NUM>,
69 std::vector<std::shared_ptr<DirectLinearSolver>>>
128 std::vector<std::shared_ptr<CPS::MNAInterface>> &comp)
override;
135 Int timeStepCount)
override;
167 std::shared_ptr<DirectLinearSolver>
198 :
Task(solver.
mName +
".Solve"), mSolver(solver) {
201 if (it->getRightVector()->get().size() != 0)
202 mAttributeDependencies.push_back(it->getRightVector());
204 for (
auto node : solver.
mNodes) {
205 mModifiedAttributes.push_back(node->mVoltage);
211 mSolver.solve(time, timeStepCount);
222 :
Task(solver.
mName +
".Solve"), mSolver(solver), mFreqIdx(freqIdx) {
225 if (it->getRightVector()->get().size() != 0)
226 mAttributeDependencies.push_back(it->getRightVector());
228 for (
auto node : solver.
mNodes) {
229 mModifiedAttributes.push_back(node->mVoltage);
232 mModifiedAttributes.push_back(leftVec);
237 mSolver.solveWithHarmonics(time, timeStepCount, mFreqIdx);
249 :
Task(solver.
mName +
".Solve"), mSolver(solver) {
252 if (it->getRightVector()->get().size() != 0)
253 mAttributeDependencies.push_back(it->getRightVector());
256 if (it->getRightVector()->get().size() != 0)
257 mAttributeDependencies.push_back(it->getRightVector());
259 for (
auto node : solver.
mNodes) {
260 mModifiedAttributes.push_back(node->mVoltage);
266 mSolver.solveWithSystemMatrixRecomputation(time, timeStepCount);
267 mSolver.log(time, timeStepCount);
278 :
Task(solver.
mName +
".StateSpaceExtraction"), mSolver(solver) {
284 mSolver.extractStateSpace(time);
295 :
Task(solver.
mName +
".Log"), mSolver(solver) {
301 mSolver.log(time, timeStepCount);
spdlog::level::level_enum Level
std::shared_ptr< spdlog::logger > Log
Tasks to be defined by every component.
std::vector< AttributeBase::Ptr > mModifiedAttributes
std::vector< AttributeBase::Ptr > mAttributeDependencies
void execute(Real time, Int timeStepCount)
LogTask(MnaSolverDirect< VarType > &solver)
void execute(Real time, Int timeStepCount)
SolveTaskHarm(MnaSolverDirect< VarType > &solver, UInt freqIdx)
void execute(Real time, Int timeStepCount)
SolveTask(MnaSolverDirect< VarType > &solver)
SolveTaskRecomp(MnaSolverDirect< VarType > &solver)
void execute(Real time, Int timeStepCount)
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 extractStateSpace(Real time)
Runs state-space extraction using the active linear solver.
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.
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.
Bool mSystemMatrixChanged
Tracks active MNA system-matrix changes from the last solve step.
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.
Bool mVariableComponentChanged
Tracks variable-component changes from the last solve step.
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::shared_ptr< CPS::Task > createStateSpaceExtractionTask() override
Create state-space extraction task for this solver implementation.
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::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.
std::bitset< SWITCH_NUM > mCurrentSwitchStatus
Current status of all switches encoded as bitset.
std::vector< Matrix > mRightSideVectorHarm
Source vector of known quantities.
Matrix mRightSideVector
Source vector of known quantities.
Bool mStateSpaceExtraction
Enables extraction of the MNA-coupled discrete-time state matrix.
std::vector< Real > mRecomputationTimes
LU refactorization measurements.
std::vector< Real > mFactorizeTimes
LU factorization measurements.
std::vector< CPS::Attribute< Matrix >::Ptr > mLeftSideVectorHarm
Solution vector of unknown quantities (parallel frequencies)
Bool hasVariableComponentChanged()
Checks whether the status of variable MNA elements have changed.
CPS::MNAInterface::List mMNAIntfVariableComps
List of variable components if they must be accessed as MNAInterface objects.
UInt mNumNetNodes
Number of network nodes, single line equivalent.
MNAStateSpaceExtractor::Ptr mStateSpaceExtractor
Extractor for the MNA-coupled state-space model.
CPS::MNASyncGenInterface::List mSyncGen
List of synchronous generators that need iterate to solve the differential equations.
CPS::MNAInterface::List mMNAIntfSwitches
List of switches if they must be accessed as MNAInterface objects.
std::vector< const Matrix * > mRightVectorStamps
List of all right side vector contributions.
std::vector< Real > mSolveTimes
Right-hand side solution measurements.
std::vector< std::pair< UInt, UInt > > mListVariableSystemMatrixEntries
List of index pairs of varying matrix entries.
CPS::MNAVariableCompInterface::List mVariableComps
Int mNumRecomputations
Number of system matrix recomputations.
CPS::MNAInterface::List mMNAComponents
List of MNA components with static stamp into system matrix.
MnaSolver(String name, CPS::Domain domain=CPS::Domain::DP, CPS::Logger::Level logLevel=CPS::Logger::Level::info)
Constructor should not be called by users but by Simulation.
CPS::Attribute< Matrix >::Ptr mLeftSideVector
Solution vector of unknown quantities.
CPS::MNASwitchInterface::List mSwitches
CPS::SimNode< VarType >::List mNodes
List of simulation nodes.
static CPS::AttributeBase::Ptr external
Bool mSystemMatrixRecomputationEnabled
Effective system-matrix recomputation setting used by the solver.
CPS::Logger::Log mSLog
Logger.
Bool mIsInInitialization
Determines if solver is in initialization phase, which requires different behavior.
Bool mFrequencyParallel
Activates parallelized computation of frequencies.
CPS::SparseMatrixRow SparseMatrix