10template <
typename VarType>
19 subComp->initializeFromNodesAndTerminals(frequency);
23template <
typename VarType>
27 Bool contributeToRightVector) {
31 this->mSubcomponentsMNA.push_back(mnasubcomp);
33 if (contributeToRightVector) {
34 this->mRightVectorStamps.push_back(mnasubcomp->mRightVector);
35 this->mRightVectorStampComponents.push_back(subc);
38 switch (preStepOrder) {
42 this->mSubcomponentsPreStepBeforeParent.push_back(mnasubcomp);
46 this->mSubcomponentsPreStepAfterParent.push_back(mnasubcomp);
50 switch (postStepOrder) {
54 this->mSubcomponentsPostStepBeforeParent.push_back(mnasubcomp);
58 this->mSubcomponentsPostStepAfterParent.push_back(mnasubcomp);
65template <
typename VarType>
70 for (
auto subComp : mSubcomponentsMNA) {
71 subComp->mnaInitialize(omega, timeStep, leftVector);
74 **this->mRightVector = Matrix::Zero(leftVector->
get().rows(), 1);
80 const UInt vectorSize =
static_cast<UInt>(leftVector->
get().rows());
81 const UInt baseRowLimit = [&]() {
82 if constexpr (std::is_same_v<VarType, Complex>)
83 return vectorSize / (2 * this->
mNumFreqs);
88 std::vector<UInt> &indices) {
94 if (index < baseRowLimit)
95 indices.push_back(index);
101 if (index < baseRowLimit)
102 indices.push_back(index);
109 indices.insert(indices.end(), nested->mRightVectorAffectedIndices.begin(),
110 nested->mRightVectorAffectedIndices.end());
111 std::sort(indices.begin(), indices.end());
112 indices.erase(std::unique(indices.begin(), indices.end()), indices.end());
115 mRightVectorStampIndices.clear();
116 mRightVectorStampIndices.reserve(mRightVectorStampComponents.size());
117 mRightVectorAffectedIndices.clear();
118 appendNodeIndices(*
this, mRightVectorAffectedIndices);
119 for (
const auto &component : mRightVectorStampComponents) {
120 std::vector<UInt> indices;
121 appendNodeIndices(*component, indices);
122 mRightVectorAffectedIndices.insert(mRightVectorAffectedIndices.end(),
123 indices.begin(), indices.end());
124 mRightVectorStampIndices.push_back(std::move(indices));
126 std::sort(mRightVectorAffectedIndices.begin(),
127 mRightVectorAffectedIndices.end());
128 mRightVectorAffectedIndices.erase(
129 std::unique(mRightVectorAffectedIndices.begin(),
130 mRightVectorAffectedIndices.end()),
131 mRightVectorAffectedIndices.end());
132 mRightVectorStampIndicesInitialized =
true;
134 mnaParentInitialize(omega, timeStep, leftVector);
137template <
typename VarType>
140 for (
auto subComp : mSubcomponentsMNA) {
141 subComp->mnaApplySystemMatrixStamp(systemMatrix);
146template <
typename VarType>
149 if (!mRightVectorStampIndicesInitialized) {
150 rightVector.setZero();
151 for (
const auto &stamp : mRightVectorStamps) {
152 if ((**stamp).size() != 0)
153 rightVector += **stamp;
156 if constexpr (std::is_same_v<VarType, Complex>) {
158 for (
UInt index : mRightVectorAffectedIndices)
160 this->mNumFreqs, freq);
162 for (
UInt index : mRightVectorAffectedIndices)
163 rightVector(index, 0) = 0.;
165 for (std::size_t stampIndex = 0; stampIndex < mRightVectorStamps.size();
167 const auto &stamp = mRightVectorStamps[stampIndex];
168 if ((**stamp).size() == 0)
170 if constexpr (std::is_same_v<VarType, Complex>) {
172 for (
UInt index : mRightVectorStampIndices[stampIndex])
175 **stamp, index, this->mNumFreqs, freq),
176 this->mNumFreqs, freq);
178 for (
UInt index : mRightVectorStampIndices[stampIndex])
179 rightVector(index, 0) += (**stamp)(index, 0);
186template <
typename VarType>
189 if (!mRightVectorStampIndicesInitialized) {
195 if constexpr (std::is_same_v<VarType, Complex>) {
197 for (
UInt index : mRightVectorAffectedIndices)
201 this->mNumFreqs, freq);
203 for (
UInt index : mRightVectorAffectedIndices)
204 rightVector(index, 0) += stamp(index, 0);
208template <
typename VarType>
210 for (
const auto &subComp : mSubcomponentsPreStepBeforeParent) {
211 subComp->mnaPreStep(time, timeStepCount);
214 for (
const auto &subComp : mSubcomponentsPreStepAfterParent) {
215 subComp->mnaPreStep(time, timeStepCount);
219template <
typename VarType>
222 for (
const auto &subComp : mSubcomponentsPostStepBeforeParent) {
223 subComp->mnaPostStep(time, timeStepCount, leftVector);
226 for (
const auto &subComp : mSubcomponentsPostStepAfterParent) {
227 subComp->mnaPostStep(time, timeStepCount, leftVector);
231template <
typename VarType>
236 for (
auto subComp : mSubcomponentsMNA) {
237 subComp->mnaAddPreStepDependencies(
238 prevStepDependencies, attributeDependencies, modifiedAttributes);
244template <
typename VarType>
250 for (
auto subComp : mSubcomponentsMNA) {
251 subComp->mnaAddPostStepDependencies(prevStepDependencies,
252 attributeDependencies,
253 modifiedAttributes, leftVector);
256 modifiedAttributes, leftVector);
AttributePointer< Attribute< T > > Ptr
Base class for composite power components.
virtual void mnaParentApplySystemMatrixStamp(SparseMatrixRow &systemMatrix)
void mnaCompInitialize(Real omega, Real timeStep, Attribute< Matrix >::Ptr leftVector) override
Initializes variables of components.
void addMNASubComponent(typename SimPowerComp< VarType >::Ptr subc, MNA_SUBCOMP_TASK_ORDER preStepOrder, MNA_SUBCOMP_TASK_ORDER postStepOrder, Bool contributeToRightVector)
Add a new subcomponent implementing MNA methods.
void mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector) override
Add MNA post step dependencies.
virtual void initializeParentFromNodesAndTerminals(Real frequency)=0
virtual void mnaParentApplyRightSideVectorStamp(Matrix &rightVector)
void initializeFromNodesAndTerminals(Real frequency) override final
void mnaAddCompactRightSideVectorStamp(Matrix &rightVector) override
virtual void mnaParentAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes)
void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override
Stamps system matrix.
virtual void mnaParentPostStep(Real time, Int timeStepCount, Attribute< Matrix >::Ptr &leftVector)
void mnaCompPreStep(Real time, Int timeStepCount) override
MNA pre step operations.
void mnaCompApplyRightSideVectorStamp(Matrix &rightVector) override
Stamps right side (source) vector.
virtual void mnaParentAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector)
void mnaCompAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes) override
Add MNA pre step dependencies.
virtual void mnaParentPreStep(Real time, Int timeStepCount)
void mnaCompPostStep(Real time, Int timeStepCount, Attribute< Matrix >::Ptr &leftVector) override
MNA post step operations.
CompositePowerComp(String uid, String name, Bool hasPreStep, Bool hasPostStep, Logger::Level logLevel)
virtual void createSubComponents()
Constructs and registers MNA subcomponents; called before collectVirtualNodes so virtual nodes exist ...
MNASimPowerComp(String uid, String name, Bool hasPreStep, Bool hasPostStep, Logger::Level logLevel)
Basic constructor that takes UID, name and log level.
Attribute< Matrix >::Ptr mRightVector
static Complex complexFromVectorElement(const Matrix &mat, Matrix::Index row, Int maxFreq=1, Int freqIdx=0)
static void setVectorElement(Matrix &mat, Matrix::Index row, Complex value, Int maxFreq=1, Int freqIdx=0, Matrix::Index colOffset=0)
static void addToVectorElement(Matrix &mat, Matrix::Index row, Complex value, Int maxFreq=1, Int freqIdx=0)
Base class for all components that are transmitting power.
SimNode< VarType >::Ptr node(UInt index)
Get pointer to node.
Matrix mFrequencies
List of considered network frequencies.
SimTerminal< Complex >::Ptr terminal(UInt index)
std::vector< UInt > virtualMatrixNodeIndices(UInt index)
Get vector of simulation node numbers from virtual Node.
UInt virtualNodesNumber()
Returns nominal number of virtual nodes for this component type.
SimNode< Complex >::Ptr virtualNode(UInt index)
UInt terminalNumberConnected()
Returns the number of connected Terminals.
std::shared_ptr< SimPowerComp< VarType > > Ptr
std::vector< std::shared_ptr< SimPowerComp< VarType > > > mSubComponents
void updateMatrixNodeIndices()
Update the "cached" mMatrixNodeIndices and mMatrixNodeIndexIsGround members.
std::vector< UInt > matrixNodeIndices(UInt index)
TODO replace with access to mMatrixNodeIndices.
Eigen::Matrix< Real, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor > Matrix
Dense matrix for real numbers.
std::complex< Real > Complex
Eigen::SparseMatrix< Real, Eigen::RowMajor > SparseMatrixRow
Sparse matrix for real numbers (row major).