DPsim
Loading...
Searching...
No Matches
MNAStateSpaceExtractor.h
1// SPDX-FileCopyrightText: 2026 Institute for Automation of Complex Power Systems, EONERC, RWTH Aachen University
2// SPDX-License-Identifier: MPL-2.0
3
4#pragma once
5
6#include <memory>
7#include <vector>
8
9#include <dpsim/Definitions.h>
10#include <dpsim/MNAStateSpaceContributor.h>
11
12namespace DPsim {
13
15
28class MNAStateSpaceExtractor {
29public:
30 using Ptr = std::shared_ptr<MNAStateSpaceExtractor>;
31
32 MNAStateSpaceExtractor() = default;
33
34 void initialize(const CPS::MNAInterface::List &components, UInt mnaVectorSize,
35 Real timeStep);
36
37 void extract(DirectLinearSolver &linearSolver, Bool variableModelChanged,
38 Bool systemMatrixChanged);
39
40 Bool isInitialized() const { return mInitialized; }
41
42 UInt getStateCount() const { return mStateCount; }
43
44 Real getTimeStep() const { return mTimeStep; }
45
46 const Matrix &getDiscreteStateMatrix() const { return mAd; }
47
48private:
49 struct ContributorEntry {
50 MNAStateSpaceContributor::Ptr contributor;
51 UInt stateOffset = 0;
52 };
53
54 void reset();
55
56 void allocateMatrices();
57
58 void stampStaticMatrices();
59
60 void restampVariableMatrices();
61
62 void rebuildCombinedMatrices();
63
64 void computeStateMatrix(DirectLinearSolver &linearSolver);
65
66 Bool mInitialized = false;
67
68 UInt mMnaVectorSize = 0;
69
70 UInt mStateCount = 0;
71
72 Real mTimeStep = 0.0;
73
74 Bool mHasVariableContributors = false;
75
76 Bool mStateMatrixValid = false;
77
78 std::vector<ContributorEntry> mContributorEntries;
79
80 Matrix mAdLocalStatic;
81 Matrix mBdMnaStatic;
82 Matrix mCdMnaStatic;
83
84 Matrix mAdLocalVariable;
85 Matrix mBdMnaVariable;
86 Matrix mCdMnaVariable;
87
88 Matrix mAdLocal;
89 Matrix mBdMna;
90 Matrix mCdMna;
91
92 Matrix mAd;
93};
94
95} // namespace DPsim