9#include <dpsim-models/EMT/EMT_Ph3_RXLoad.h>
19 mPhaseType = PhaseType::ABC;
22 SPDLOG_LOGGER_INFO(
mSLog,
"Create {} {}", this->
type(), name);
29 :
RXLoad(name, name, logLevel) {}
32 Real volt, Logger::Level logLevel)
36 mPower = MatrixComp::Zero(3, 3);
48 initPowerFromTerminal =
false;
52 auto copy = RXLoad::make(name,
mLogLevel);
53 if (!initPowerFromTerminal)
59void EMT::Ph3::RXLoad::setParameters(Matrix activePower, Matrix reactivePower,
60 Real volt,
bool reactanceInSeries) {
61 **mActivePower = activePower;
62 **mReactivePower = reactivePower;
63 mReactanceInSeries = reactanceInSeries;
65 if (mReactanceInSeries) {
66 setVirtualNodeNumber(1);
69 mPower = MatrixComp::Zero(3, 3);
70 mPower(0, 0) = {(**mActivePower)(0, 0), (**mReactivePower)(0, 0)};
71 mPower(1, 1) = {(**mActivePower)(1, 1), (**mReactivePower)(1, 1)};
72 mPower(2, 2) = {(**mActivePower)(2, 2), (**mReactivePower)(2, 2)};
76 SPDLOG_LOGGER_INFO(mSLog,
77 "\nActive Power [W]: {}"
78 "\nReactive Power [VAr]: {}",
79 Logger::matrixToString(**mActivePower),
80 Logger::matrixToString(**mReactivePower));
81 SPDLOG_LOGGER_INFO(mSLog,
"Nominal Voltage={} [V]", **mNomVoltage);
83 initPowerFromTerminal =
false;
97 Real omega = 2. * PI * frequency;
99 if (initPowerFromTerminal) {
101 (**mActivePower)(0, 0) =
mTerminals[0]->singleActivePower() / 3.;
102 (**mActivePower)(1, 1) =
mTerminals[0]->singleActivePower() / 3.;
103 (**mActivePower)(2, 2) =
mTerminals[0]->singleActivePower() / 3.;
106 (**mReactivePower)(0, 0) =
mTerminals[0]->singleReactivePower() / 3.;
107 (**mReactivePower)(1, 1) =
mTerminals[0]->singleReactivePower() / 3.;
108 (**mReactivePower)(2, 2) =
mTerminals[0]->singleReactivePower() / 3.;
111 mPower = MatrixComp::Zero(3, 3);
118 SPDLOG_LOGGER_INFO(
mSLog,
119 "\nActive Power [W]: {}"
120 "\nReactive Power [VAr]: {}",
130 std::pow(**
mNomVoltage / sqrt(3), 2) * (**mActivePower).inverse();
134 std::pow(**
mNomVoltage / sqrt(3), 2) * (**mReactivePower).inverse();
140 std::make_shared<EMT::Ph3::Resistor>(**
mName +
"_res",
mLogLevel);
148 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
true);
155 std::make_shared<EMT::Ph3::Inductor>(**
mName +
"_ind",
mLogLevel);
163 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
true);
168 std::make_shared<EMT::Ph3::Capacitor>(**
mName +
"_cap",
mLogLevel);
176 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
177 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
true);
180 MatrixComp vInitABC = MatrixComp::Zero(3, 1);
181 vInitABC(0, 0) = RMS3PH_TO_PEAK1PH *
mTerminals[0]->initialSingleVoltage();
182 vInitABC(1, 0) = vInitABC(0, 0) * SHIFT_TO_PHASE_B;
183 vInitABC(2, 0) = vInitABC(0, 0) * SHIFT_TO_PHASE_C;
188 std::pow(**
mNomVoltage / sqrt(3), 2) * (**mActivePower).inverse();
193 std::pow(**
mNomVoltage / sqrt(3), 2) * (**mReactivePower).inverse();
198 MatrixComp impedance = MatrixComp::Zero(3, 3);
208 **
mIntfCurrent = (impedance.inverse() * vInitABC).real();
212 MatrixComp vInitTerm0 = MatrixComp::Zero(3, 1);
213 vInitTerm0(0, 0) = initialSingleVoltage(0);
214 vInitTerm0(1, 0) = vInitTerm0(0, 0) * SHIFT_TO_PHASE_B;
215 vInitTerm0(2, 0) = vInitTerm0(0, 0) * SHIFT_TO_PHASE_C;
221 mSubResistor->initializeFromNodesAndTerminals(frequency);
228 mSubInductor->initializeFromNodesAndTerminals(frequency);
241 "\n--- Initialization from powerflow ---"
242 "\nVoltage across: {:s}"
244 "\nTerminal 0 voltage: {:s}"
245 "\nActive Power: {:s}"
246 "\nReactive Power: {:s}"
249 "\n--- Initialization from powerflow finished ---",
252 Logger::phasorToString(RMS3PH_TO_PEAK1PH * initialSingleVoltage(0)),
259void EMT::Ph3::RXLoad::mnaParentAddPreStepDependencies(
260 AttributeBase::List &prevStepDependencies,
261 AttributeBase::List &attributeDependencies,
262 AttributeBase::List &modifiedAttributes) {
263 modifiedAttributes.push_back(mRightVector);
266void EMT::Ph3::RXLoad::mnaParentAddPostStepDependencies(
267 AttributeBase::List &prevStepDependencies,
268 AttributeBase::List &attributeDependencies,
269 AttributeBase::List &modifiedAttributes,
270 Attribute<Matrix>::Ptr &leftVector) {
271 attributeDependencies.push_back(leftVector);
272 modifiedAttributes.push_back(mIntfCurrent);
273 modifiedAttributes.push_back(mIntfVoltage);
280void EMT::Ph3::RXLoad::mnaParentPostStep(Real time, Int timeStepCount,
281 Attribute<Matrix>::Ptr &leftVector) {
282 mnaCompUpdateVoltage(**leftVector);
283 mnaCompUpdateCurrent(**leftVector);
286void EMT::Ph3::RXLoad::mnaCompUpdateVoltage(
const Matrix &leftVector) {
287 **mIntfVoltage = Matrix::Zero(3, 1);
288 (**mIntfVoltage)(0, 0) =
289 Math::realFromVectorElement(leftVector, matrixNodeIndex(0, 0));
290 (**mIntfVoltage)(1, 0) =
291 Math::realFromVectorElement(leftVector, matrixNodeIndex(0, 1));
292 (**mIntfVoltage)(2, 0) =
293 Math::realFromVectorElement(leftVector, matrixNodeIndex(0, 2));
296void EMT::Ph3::RXLoad::mnaCompUpdateCurrent(
const Matrix &leftVector) {
297 if (mReactanceInSeries) {
298 **mIntfCurrent = mSubInductor->intfCurrent();
300 **mIntfCurrent = Matrix::Zero(3, 1);
301 for (
auto &subc : mSubComponents) {
302 **mIntfCurrent += subc->intfCurrent();
void addMNASubComponent(typename SimPowerComp< Real >::Ptr subc, MNA_SUBCOMP_TASK_ORDER preStepOrder, MNA_SUBCOMP_TASK_ORDER postStepOrder, Bool contributeToRightVector)
void mnaCompApplyRightSideVectorStamp(Matrix &rightVector) override
CompositePowerComp(String uid, String name, Bool hasPreStep, Bool hasPostStep, Logger::Level logLevel)
const Attribute< Matrix >::Ptr mActivePower
Active power [Watt].
Bool mReactanceInSeries
If set to true, the reactance is in series with the resistor. Otherwise it is parallel to the resisto...
RXLoad(String uid, String name, Logger::Level logLevel=Logger::Level::off)
Defines UID, name and logging level.
std::shared_ptr< EMT::Ph3::Resistor > mSubResistor
Internal resistance.
std::shared_ptr< EMT::Ph3::Inductor > mSubInductor
Internal inductor.
void createSubComponents() override
Constructs and registers MNA subcomponents; idempotent.
std::shared_ptr< EMT::Ph3::Capacitor > mSubCapacitor
Internal capacitor.
Matrix mResistance
Resistance [Ohm].
void initializeParentFromNodesAndTerminals(Real frequency) override
Derives values from power flow data and pushes them to subcomponents.
Matrix mReactance
Reactance [Ohm].
const Attribute< Real >::Ptr mNomVoltage
Nominal voltage [V].
SimPowerComp< Real >::Ptr clone(String name) override
Returns a modified copy of the component with the given suffix added to the name and without.
void mnaParentPreStep(Real time, Int timeStepCount) override
MNA pre and post step operations.
Matrix mCapacitance
Capacitance [F].
const Attribute< Matrix >::Ptr mReactivePower
Reactive power [VAr].
Matrix mInductance
Inductance [H].
const Attribute< String >::Ptr mName
Human readable name.
String uid()
Returns unique id.
String type()
Get component type (cross-platform)
AttributeList::Ptr mAttributes
Attribute List.
Attribute< Matrix >::Ptr mRightVector
const Attribute< MatrixVar< Real > >::Ptr mIntfCurrent
SimTerminal< Real >::List mTerminals
const Attribute< MatrixVar< Real > >::Ptr mIntfVoltage
SimNode< Real >::List mVirtualNodes
Logger::Level mLogLevel
Component logger control for internal variables.
Logger::Log mSLog
Component logger.