9 #include <dpsim-models/EMT/EMT_Ph3_RXLoad.h>
15 mActivePower(mAttributes->create<Matrix>(
"P")),
16 mReactivePower(mAttributes->create<Matrix>(
"Q")),
17 mNomVoltage(mAttributes->create<Real>(
"V_nom")) {
18 mPhaseType = PhaseType::ABC;
21 SPDLOG_LOGGER_INFO(
mSLog,
"Create {} {}", this->
type(), name);
28 :
RXLoad(name, name, logLevel) {}
31 Real volt, Logger::Level logLevel)
35 mPower = MatrixComp::Zero(3, 3);
47 initPowerFromTerminal =
false;
50 void EMT::Ph3::RXLoad::setParameters(Matrix activePower, Matrix reactivePower,
52 **mActivePower = activePower;
53 **mReactivePower = reactivePower;
56 mPower = MatrixComp::Zero(3, 3);
57 mPower(0, 0) = {(**mActivePower)(0, 0), (**mReactivePower)(0, 0)};
58 mPower(1, 1) = {(**mActivePower)(1, 1), (**mReactivePower)(1, 1)};
59 mPower(2, 2) = {(**mActivePower)(2, 2), (**mReactivePower)(2, 2)};
63 SPDLOG_LOGGER_INFO(mSLog,
64 "\nActive Power [W]: {}"
65 "\nReactive Power [VAr]: {}",
66 Logger::matrixToString(**mActivePower),
67 Logger::matrixToString(**mReactivePower));
68 SPDLOG_LOGGER_INFO(mSLog,
"Nominal Voltage={} [V]", **mNomVoltage);
70 initPowerFromTerminal =
false;
75 if (initPowerFromTerminal) {
76 **mActivePower = Matrix::Zero(3, 3);
77 (**mActivePower)(0, 0) = mTerminals[0]->singleActivePower() / 3.;
78 (**mActivePower)(1, 1) = mTerminals[0]->singleActivePower() / 3.;
79 (**mActivePower)(2, 2) = mTerminals[0]->singleActivePower() / 3.;
81 **mReactivePower = Matrix::Zero(3, 3);
82 (**mReactivePower)(0, 0) = mTerminals[0]->singleReactivePower() / 3.;
83 (**mReactivePower)(1, 1) = mTerminals[0]->singleReactivePower() / 3.;
84 (**mReactivePower)(2, 2) = mTerminals[0]->singleReactivePower() / 3.;
87 mPower = MatrixComp::Zero(3, 3);
88 mPower(0, 0) = {(**mActivePower)(0, 0), (**mReactivePower)(0, 0)};
89 mPower(1, 1) = {(**mActivePower)(1, 1), (**mReactivePower)(1, 1)};
90 mPower(2, 2) = {(**mActivePower)(2, 2), (**mReactivePower)(2, 2)};
92 **mNomVoltage = std::abs(mTerminals[0]->initialSingleVoltage());
94 SPDLOG_LOGGER_INFO(mSLog,
95 "\nActive Power [W]: {}"
96 "\nReactive Power [VAr]: {}",
97 Logger::matrixToString(**mActivePower),
98 Logger::matrixToString(**mReactivePower));
99 SPDLOG_LOGGER_INFO(mSLog,
"Nominal Voltage={} [V]", **mNomVoltage);
102 if ((**mActivePower)(0, 0) != 0) {
104 std::pow(**mNomVoltage / sqrt(3), 2) * (**mActivePower).inverse();
106 std::make_shared<EMT::Ph3::Resistor>(**mName +
"_res", mLogLevel);
107 mSubResistor->setParameters(mResistance);
108 mSubResistor->connect({SimNode::GND, mTerminals[0]->node()});
109 mSubResistor->initialize(mFrequencies);
110 mSubResistor->initializeFromNodesAndTerminals(frequency);
111 addMNASubComponent(mSubResistor, MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
112 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
true);
113 **mIntfCurrent += mSubResistor->intfCurrent();
116 if ((**mReactivePower)(0, 0) != 0)
118 std::pow(**mNomVoltage / sqrt(3), 2) * (**mReactivePower).inverse();
120 mReactance = Matrix::Zero(1, 1);
122 if (mReactance(0, 0) > 0) {
123 mInductance = mReactance / (2 * PI * frequency);
126 std::make_shared<EMT::Ph3::Inductor>(**mName +
"_ind", mLogLevel);
127 mSubInductor->setParameters(mInductance);
128 mSubInductor->connect({SimNode::GND, mTerminals[0]->node()});
129 mSubInductor->initialize(mFrequencies);
130 mSubInductor->initializeFromNodesAndTerminals(frequency);
131 addMNASubComponent(mSubInductor, MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
132 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
true);
133 **mIntfCurrent += mSubInductor->intfCurrent();
134 }
else if (mReactance(0, 0) < 0) {
135 mCapacitance = -1 / (2 * PI * frequency) * mReactance.inverse();
138 std::make_shared<EMT::Ph3::Capacitor>(**mName +
"_cap", mLogLevel);
139 mSubCapacitor->setParameters(mCapacitance);
140 mSubCapacitor->connect({SimNode::GND, mTerminals[0]->node()});
141 mSubCapacitor->initialize(mFrequencies);
142 mSubCapacitor->initializeFromNodesAndTerminals(frequency);
143 addMNASubComponent(mSubCapacitor,
144 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
145 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
true);
146 **mIntfCurrent += mSubCapacitor->intfCurrent();
149 MatrixComp vInitABC = MatrixComp::Zero(3, 1);
150 vInitABC(0, 0) = RMS3PH_TO_PEAK1PH * mTerminals[0]->initialSingleVoltage();
151 vInitABC(1, 0) = vInitABC(0, 0) * SHIFT_TO_PHASE_B;
152 vInitABC(2, 0) = vInitABC(0, 0) * SHIFT_TO_PHASE_C;
153 **mIntfVoltage = vInitABC.real();
157 "\n--- Initialization from powerflow ---"
158 "\nVoltage across: {:s}"
160 "\nTerminal 0 voltage: {:s}"
161 "\nActive Power: {:s}"
162 "\nReactive Power: {:s}"
165 "\n--- Initialization from powerflow finished ---",
166 Logger::matrixToString(**mIntfVoltage),
167 Logger::matrixToString(**mIntfCurrent),
168 Logger::phasorToString(RMS3PH_TO_PEAK1PH * initialSingleVoltage(0)),
169 Logger::matrixToString(**mActivePower),
170 Logger::matrixToString(**mReactivePower),
171 Logger::matrixToString(mResistance), Logger::matrixToString(mReactance));
175 void EMT::Ph3::RXLoad::mnaParentAddPreStepDependencies(
176 AttributeBase::List &prevStepDependencies,
177 AttributeBase::List &attributeDependencies,
178 AttributeBase::List &modifiedAttributes) {
179 modifiedAttributes.push_back(mRightVector);
182 void EMT::Ph3::RXLoad::mnaParentAddPostStepDependencies(
183 AttributeBase::List &prevStepDependencies,
184 AttributeBase::List &attributeDependencies,
185 AttributeBase::List &modifiedAttributes,
187 attributeDependencies.push_back(leftVector);
188 modifiedAttributes.push_back(mIntfCurrent);
189 modifiedAttributes.push_back(mIntfVoltage);
193 mnaCompApplyRightSideVectorStamp(**mRightVector);
196 void EMT::Ph3::RXLoad::mnaParentPostStep(Real time, Int timeStepCount,
198 mnaCompUpdateVoltage(**leftVector);
199 mnaCompUpdateCurrent(**leftVector);
202 void EMT::Ph3::RXLoad::mnaCompUpdateVoltage(
const Matrix &leftVector) {
203 **mIntfVoltage = Matrix::Zero(3, 1);
204 (**mIntfVoltage)(0, 0) =
205 Math::realFromVectorElement(leftVector, matrixNodeIndex(0, 0));
206 (**mIntfVoltage)(1, 0) =
207 Math::realFromVectorElement(leftVector, matrixNodeIndex(0, 1));
208 (**mIntfVoltage)(2, 0) =
209 Math::realFromVectorElement(leftVector, matrixNodeIndex(0, 2));
212 void EMT::Ph3::RXLoad::mnaCompUpdateCurrent(
const Matrix &leftVector) {
213 **mIntfCurrent = Matrix::Zero(3, 1);
214 for (
auto &subc : mSubComponents) {
215 **mIntfCurrent += subc->intfCurrent();
Base class for composite power components.
TODO: currently modelled as an impedance, which obviously doesn't have a constant power characteristi...
const Attribute< Matrix >::Ptr mActivePower
Active power [Watt].
RXLoad(String uid, String name, Logger::Level logLevel=Logger::Level::off)
Defines UID, name and logging level.
MatrixComp mPower
Power [Watt].
const Attribute< Real >::Ptr mNomVoltage
Nominal voltage [V].
void initializeFromNodesAndTerminals(Real frequency) override
Initializes component from power flow data.
void mnaParentPreStep(Real time, Int timeStepCount) override
MNA pre and post step operations.
const Attribute< Matrix >::Ptr mReactivePower
Reactive power [VAr].
String type()
Get component type (cross-platform)
const Attribute< MatrixVar< Real > >::Ptr mIntfCurrent
Current through component.
const Attribute< MatrixVar< Real > >::Ptr mIntfVoltage
Voltage between terminals.
Logger::Log mSLog
Component logger.