14 #include <unordered_map>
17 #include <dpsim-models/AttributeList.h>
18 #include <dpsim-models/SimPowerComp.h>
19 #include <dpsim-models/SimSignalComp.h>
20 #include <dpsim-models/Solver/MNAInterface.h>
21 #include <dpsim-models/Solver/MNASwitchInterface.h>
22 #include <dpsim-models/Solver/MNASyncGenInterface.h>
23 #include <dpsim-models/Solver/MNAVariableCompInterface.h>
24 #include <dpsim/Config.h>
25 #include <dpsim/DataLogger.h>
26 #include <dpsim/Solver.h>
34 #define SWITCH_NUM sizeof(std::size_t) * 8
65 typename CPS::SimNode<VarType>::List
mNodes;
124 MnaSolver(String name, CPS::Domain domain = CPS::Domain::DP,
125 CPS::Logger::Level logLevel = CPS::Logger::Level::info);
145 void steadyStateInitialization();
158 std::vector<std::shared_ptr<CPS::MNAInterface>> &comp) = 0;
161 CPS::MNAInterface::List &components,
162 CPS::MNASwitchInterface::List &switches) {}
171 Int timeStepCount) = 0;
187 virtual void solve(Real time, Int timeStepCount) = 0;
192 virtual void log(Real time, Int timeStepCount)
override;
204 SPDLOG_LOGGER_INFO(
mSLog,
"Number of system matrix recomputations: {:}",
219 virtual CPS::Task::List
getTasks()
override;
Solver class using Modified Nodal Analysis (MNA).
std::bitset< SWITCH_NUM > mCurrentSwitchStatus
Current status of all switches encoded as bitset.
CPS::Domain mDomain
Simulation domain, which can be dynamic phasor (DP) or EMT.
virtual std::shared_ptr< CPS::Task > createSolveTaskHarm(UInt freqIdx)=0
Create a solve task for this solver implementation.
void identifyTopologyObjects()
Identify Nodes and SimPowerComps and SimSignalComps.
std::vector< Matrix > mRightSideVectorHarm
Source vector of known quantities.
Matrix mRightSideVector
Source vector of known quantities.
CPS::SystemTopology mSystem
System topology.
virtual void switchedMatrixEmpty(std::size_t swIdx, Int freqIdx)=0
Sets all entries in the matrix with the given switch index and frequency index to zero.
virtual ~MnaSolver()
Destructor.
std::vector< Real > mRecomputationTimes
LU refactorization measurements.
void initializeSystemWithVariableMatrix()
Initialization of system matrices and source vector.
virtual void initialize() override
Calls subroutines to set up everything that is required before simulation.
virtual void logSystemMatrices()=0
Logging of system matrices and source vector.
virtual void initializeSystem()
Initialization of system matrices and source vector.
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 mNumNetMatrixNodeIndices
Number of network nodes, considering individual phases.
UInt mNumNetNodes
Number of network nodes, single line equivalent.
virtual void log(Real time, Int timeStepCount) override
Logs left and right vector.
UInt mNumTotalMatrixNodeIndices
Total number of network and virtual nodes, considering individual phases and additional frequencies.
UInt mNumVirtualMatrixNodeIndices
Number of virtual nodes, considering individual phases.
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.
virtual std::shared_ptr< CPS::Task > createSolveTaskRecomp()=0
Create a solve task for recomputation solver.
std::shared_ptr< DataLogger > mRightVectorLog
Right side vector logger.
virtual void solve(Real time, Int timeStepCount)=0
Solves system for single frequency.
UInt mSwitchTimeIndex
Index of the next switching event.
virtual void switchedMatrixStamp(std::size_t swIdx, Int freqIdx, CPS::MNAInterface::List &components, CPS::MNASwitchInterface::List &switches)
Applies a component and switch stamp to the matrix with the given switch index.
std::vector< const Matrix * > mRightVectorStamps
List of all right side vector contributions.
void initializeComponents()
Initialization of individual components.
void updateSwitchStatus()
Collects the status of switches to select correct system matrix.
std::vector< Real > mSolveTimes
Right-hand side solution measurements.
Int mLastLogTimeStep
Last simulation time step when log was updated.
std::vector< std::pair< UInt, UInt > > mListVariableSystemMatrixEntries
List of index pairs of varying matrix entries.
CPS::MNAVariableCompInterface::List mVariableComps
virtual std::shared_ptr< CPS::Task > createLogTask()=0
Create a solve task for this solver implementation.
virtual void solveWithHarmonics(Real time, Int timeStepCount, Int freqIdx)=0
Solves system for multiple frequencies.
Int mNumRecomputations
Number of system matrix recomputations.
CPS::MNAInterface::List mMNAComponents
List of MNA components with static stamp into system matrix.
virtual void stampVariableSystemMatrix()=0
Stamps components into the variable system matrix.
std::shared_ptr< DataLogger > mLeftVectorLog
Left side vector logger.
virtual std::shared_ptr< CPS::Task > createSolveTask()=0
Create a solve task for this solver implementation.
UInt mNumMatrixNodeIndices
Number of network and virtual nodes, considering individual phases.
void initializeSystemWithParallelFrequencies()
Initialization of system matrices and source vector.
void collectVirtualNodes()
UInt mNumHarmMatrixNodeIndices
Number of nodes, excluding the primary frequency.
UInt mNumNodes
Number of network and virtual nodes, single line equivalent.
std::vector< SwitchConfiguration > mSwitchEvents
Vector of switch times.
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.
void assignMatrixNodeIndices()
Assign simulation node index according to index in the vector.
UInt mNumVirtualNodes
Number of virtual nodes, single line equivalent.
void initializeSystemWithPrecomputedMatrices()
Initialization of system matrices and source vector.
CPS::Attribute< Matrix >::Ptr mLeftSideVector
Solution vector of unknown quantities.
CPS::SimSignalComp::List mSimSignalComps
List of signal type components that do not directly interact with the MNA solver.
virtual void switchedMatrixStamp(std::size_t index, std::vector< std::shared_ptr< CPS::MNAInterface >> &comp)=0
Applies a component stamp to the matrix with the given switch index.
virtual void createEmptySystemMatrix()=0
Create system matrix.
virtual void solveWithSystemMatrixRecomputation(Real time, Int timeStepCount)=0
Solves the system with variable system matrix.
CPS::MNASwitchInterface::List mSwitches
void createEmptyVectors()
Create left and right side vector.
virtual void switchedMatrixEmpty(std::size_t index)=0
Sets all entries in the matrix with the given switch index to zero.
CPS::SimNode< VarType >::List mNodes
List of simulation nodes.
virtual CPS::Task::List getTasks() override
Get tasks for scheduler.
Base class for more specific solvers such as MNA, ODE or IDA.
Bool mSystemMatrixRecomputation
Enable recomputation of system matrix during simulation.
CPS::Logger::Log mSLog
Logger.