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;
51void EMT::Ph3::RXLoad::setParameters(Matrix activePower, Matrix reactivePower,
52 Real volt,
bool reactanceInSeries) {
53 **mActivePower = activePower;
54 **mReactivePower = reactivePower;
55 mReactanceInSeries = reactanceInSeries;
57 if (mReactanceInSeries) {
58 setVirtualNodeNumber(1);
61 mPower = MatrixComp::Zero(3, 3);
62 mPower(0, 0) = {(**mActivePower)(0, 0), (**mReactivePower)(0, 0)};
63 mPower(1, 1) = {(**mActivePower)(1, 1), (**mReactivePower)(1, 1)};
64 mPower(2, 2) = {(**mActivePower)(2, 2), (**mReactivePower)(2, 2)};
68 SPDLOG_LOGGER_INFO(mSLog,
69 "\nActive Power [W]: {}"
70 "\nReactive Power [VAr]: {}",
71 Logger::matrixToString(**mActivePower),
72 Logger::matrixToString(**mReactivePower));
73 SPDLOG_LOGGER_INFO(mSLog,
"Nominal Voltage={} [V]", **mNomVoltage);
75 initPowerFromTerminal =
false;
89 Real omega = 2. * PI * frequency;
91 if (initPowerFromTerminal) {
93 (**mActivePower)(0, 0) =
mTerminals[0]->singleActivePower() / 3.;
94 (**mActivePower)(1, 1) =
mTerminals[0]->singleActivePower() / 3.;
95 (**mActivePower)(2, 2) =
mTerminals[0]->singleActivePower() / 3.;
98 (**mReactivePower)(0, 0) =
mTerminals[0]->singleReactivePower() / 3.;
99 (**mReactivePower)(1, 1) =
mTerminals[0]->singleReactivePower() / 3.;
100 (**mReactivePower)(2, 2) =
mTerminals[0]->singleReactivePower() / 3.;
103 mPower = MatrixComp::Zero(3, 3);
110 SPDLOG_LOGGER_INFO(
mSLog,
111 "\nActive Power [W]: {}"
112 "\nReactive Power [VAr]: {}",
122 std::pow(**
mNomVoltage / sqrt(3), 2) * (**mActivePower).inverse();
126 std::pow(**
mNomVoltage / sqrt(3), 2) * (**mReactivePower).inverse();
132 std::make_shared<EMT::Ph3::Resistor>(**
mName +
"_res",
mLogLevel);
140 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
true);
147 std::make_shared<EMT::Ph3::Inductor>(**
mName +
"_ind",
mLogLevel);
155 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
true);
160 std::make_shared<EMT::Ph3::Capacitor>(**
mName +
"_cap",
mLogLevel);
168 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
169 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
true);
172 MatrixComp vInitABC = MatrixComp::Zero(3, 1);
173 vInitABC(0, 0) = RMS3PH_TO_PEAK1PH *
mTerminals[0]->initialSingleVoltage();
174 vInitABC(1, 0) = vInitABC(0, 0) * SHIFT_TO_PHASE_B;
175 vInitABC(2, 0) = vInitABC(0, 0) * SHIFT_TO_PHASE_C;
180 std::pow(**
mNomVoltage / sqrt(3), 2) * (**mActivePower).inverse();
185 std::pow(**
mNomVoltage / sqrt(3), 2) * (**mReactivePower).inverse();
190 MatrixComp impedance = MatrixComp::Zero(3, 3);
200 **
mIntfCurrent = (impedance.inverse() * vInitABC).real();
204 MatrixComp vInitTerm0 = MatrixComp::Zero(3, 1);
205 vInitTerm0(0, 0) = initialSingleVoltage(0);
206 vInitTerm0(1, 0) = vInitTerm0(0, 0) * SHIFT_TO_PHASE_B;
207 vInitTerm0(2, 0) = vInitTerm0(0, 0) * SHIFT_TO_PHASE_C;
218 mSubResistor->initializeFromNodesAndTerminals(frequency);
226 mSubInductor->initializeFromNodesAndTerminals(frequency);
240 "\n--- Initialization from powerflow ---"
241 "\nVoltage across: {:s}"
243 "\nTerminal 0 voltage: {:s}"
244 "\nActive Power: {:s}"
245 "\nReactive Power: {:s}"
248 "\n--- Initialization from powerflow finished ---",
251 Logger::phasorToString(RMS3PH_TO_PEAK1PH * initialSingleVoltage(0)),
258void EMT::Ph3::RXLoad::mnaParentAddPreStepDependencies(
259 AttributeBase::List &prevStepDependencies,
260 AttributeBase::List &attributeDependencies,
261 AttributeBase::List &modifiedAttributes) {
262 modifiedAttributes.push_back(mRightVector);
265void EMT::Ph3::RXLoad::mnaParentAddPostStepDependencies(
266 AttributeBase::List &prevStepDependencies,
267 AttributeBase::List &attributeDependencies,
268 AttributeBase::List &modifiedAttributes,
269 Attribute<Matrix>::Ptr &leftVector) {
270 attributeDependencies.push_back(leftVector);
271 modifiedAttributes.push_back(mIntfCurrent);
272 modifiedAttributes.push_back(mIntfVoltage);
279void EMT::Ph3::RXLoad::mnaParentPostStep(Real time, Int timeStepCount,
280 Attribute<Matrix>::Ptr &leftVector) {
281 mnaCompUpdateVoltage(**leftVector);
282 mnaCompUpdateCurrent(**leftVector);
285void EMT::Ph3::RXLoad::mnaCompUpdateVoltage(
const Matrix &leftVector) {
286 **mIntfVoltage = Matrix::Zero(3, 1);
287 (**mIntfVoltage)(0, 0) =
288 Math::realFromVectorElement(leftVector, matrixNodeIndex(0, 0));
289 (**mIntfVoltage)(1, 0) =
290 Math::realFromVectorElement(leftVector, matrixNodeIndex(0, 1));
291 (**mIntfVoltage)(2, 0) =
292 Math::realFromVectorElement(leftVector, matrixNodeIndex(0, 2));
295void EMT::Ph3::RXLoad::mnaCompUpdateCurrent(
const Matrix &leftVector) {
296 if (mReactanceInSeries) {
297 **mIntfCurrent = mSubInductor->intfCurrent();
299 **mIntfCurrent = Matrix::Zero(3, 1);
300 for (
auto &subc : mSubComponents) {
301 **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].
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.