9 #include <dpsim-models/SimNode.h>
13 template <
typename VarType>
15 std::vector<UInt> matrixNodeIndex,
17 const std::vector<Complex> &initialVoltage)
19 mVoltage(mAttributes->create<MatrixVar<VarType>>(
"v")),
20 mApparentPower(mAttributes->create<MatrixVar<VarType>>(
"s")) {
22 if (phaseType == PhaseType::ABC) {
24 **mVoltage = MatrixVar<VarType>::Zero(3, 1);
28 **mVoltage = MatrixVar<VarType>::Zero(1, 1);
33 template <
typename VarType>
35 :
SimNode(
"gnd",
"gnd", {0, 0, 0}, phaseType, {0, 0, 0}) {
37 **mInitialVoltage = MatrixComp::Zero(3, 1);
38 **mVoltage = MatrixVar<VarType>::Zero(3, 1);
42 if (phaseType() == PhaseType::Single)
43 (**mVoltage)(0, 0) = (RMS3PH_TO_PEAK1PH * (**mInitialVoltage)(0, 0)).real();
45 **mVoltage = (RMS3PH_TO_PEAK1PH * **mInitialVoltage).real();
49 (**mVoltage)(0, 0) = (**mInitialVoltage)(0, 0);
50 if (phaseType() == PhaseType::ABC) {
51 (**mVoltage)(1, 0) = (**mInitialVoltage)(1, 0);
52 (**mVoltage)(2, 0) = (**mInitialVoltage)(2, 0);
56 template <
typename VarType>
58 mFrequencies = frequencies;
59 mNumFreqs =
static_cast<UInt
>(mFrequencies.size());
60 Matrix::Index rowNum = phaseType() == PhaseType::ABC ? 3 : 1;
61 **mVoltage = MatrixVar<VarType>::Zero(rowNum, mNumFreqs);
64 template <
typename VarType>
66 if (phaseType == PhaseType::B)
67 return (**mVoltage)(1, 0);
68 else if (phaseType == PhaseType::C)
69 return (**mVoltage)(2, 0);
71 return (**mVoltage)(0, 0);
74 template <
typename VarType>
76 if ((phaseType == PhaseType::A || phaseType == PhaseType::Single) &&
77 (mPhaseType == PhaseType::Single || mPhaseType == PhaseType::A ||
78 mPhaseType == PhaseType::ABC))
79 return mMatrixNodeIndex[0];
80 else if (phaseType == PhaseType::B &&
81 (mPhaseType == PhaseType::B || mPhaseType == PhaseType::ABC))
82 return mMatrixNodeIndex[1];
83 else if (phaseType == PhaseType::C &&
84 (mPhaseType == PhaseType::C || mPhaseType == PhaseType::ABC))
85 return mMatrixNodeIndex[2];
90 template <
typename VarType>
92 if (mPhaseType == PhaseType::B)
93 return {mMatrixNodeIndex[1]};
94 else if (mPhaseType == PhaseType::C)
95 return {mMatrixNodeIndex[2]};
96 else if (mPhaseType == PhaseType::ABC)
97 return mMatrixNodeIndex;
99 return {mMatrixNodeIndex[0]};
106 template <
typename VarType>
108 mMatrixNodeIndex[phase] = matrixNodeIndex;
116 (**mVoltage)(0, 0) = newVoltage;
120 (**mApparentPower)(0, 0) = newPower;
124 if (mMatrixNodeIndex[0] >= 0)
126 Math::realFromVectorElement(leftVector, mMatrixNodeIndex[0]);
127 if (mPhaseType == PhaseType::ABC) {
128 if (mMatrixNodeIndex[1] >= 0)
130 Math::realFromVectorElement(leftVector, mMatrixNodeIndex[1]);
131 if (mMatrixNodeIndex[2] >= 0)
133 Math::realFromVectorElement(leftVector, mMatrixNodeIndex[2]);
138 for (UInt freq = 0; freq < mNumFreqs; freq++) {
139 if (mMatrixNodeIndex[0] >= 0)
140 (**mVoltage)(0, freq) = Math::complexFromVectorElement(
141 leftVector, mMatrixNodeIndex[0], mNumFreqs, freq);
142 if (mPhaseType == PhaseType::ABC) {
143 if (mMatrixNodeIndex[1] >= 0)
144 (**mVoltage)(1, freq) = Math::complexFromVectorElement(
145 leftVector, mMatrixNodeIndex[1], mNumFreqs, freq);
146 if (mMatrixNodeIndex[2] >= 0)
147 (**mVoltage)(2, freq) = Math::complexFromVectorElement(
148 leftVector, mMatrixNodeIndex[2], mNumFreqs, freq);
160 if (mMatrixNodeIndex[0] >= 0)
161 (**mVoltage)(0, freqIdx) =
162 Math::complexFromVectorElement(leftVector, mMatrixNodeIndex[0]);
163 if (mPhaseType == PhaseType::ABC) {
164 if (mMatrixNodeIndex[1] >= 0)
165 (**mVoltage)(1, freqIdx) =
166 Math::complexFromVectorElement(leftVector, mMatrixNodeIndex[1]);
167 if (mMatrixNodeIndex[2] >= 0)
168 (**mVoltage)(2, freqIdx) =
169 Math::complexFromVectorElement(leftVector, mMatrixNodeIndex[2]);
180 mMnaTasks = {std::make_shared<MnaPostStepHarm>(*
this, leftVectors)};
185 for (UInt freq = 0; freq < mNode.mNumFreqs; freq++)
186 mNode.mnaUpdateVoltageHarm(**mLeftVectors[freq], freq);
SimNode(String uid, String name, std::vector< UInt > matrixNodeIndex, PhaseType phaseType, const std::vector< Complex > &initialVoltage)
This very general constructor is used by other constructors.
const Attribute< MatrixVar< VarType > >::Ptr mApparentPower
Power injected at node.
void initialize()
Initialize mVoltage according to mInitialVoltage.
UInt matrixNodeIndex(PhaseType phaseType=PhaseType::Single) override
Returns matrix index for specified phase.