9 #include <dpsim-models/DP/DP_Ph1_RXLoad.h>
15 mActivePower(mAttributes->create<Real>(
"P")),
16 mReactivePower(mAttributes->create<Real>(
"Q")),
17 mNomVoltage(mAttributes->create<Real>(
"V_nom")) {
20 SPDLOG_LOGGER_INFO(
mSLog,
"Create {} {}", this->
type(), name);
26 :
RXLoad(name, name, logLevel) {}
30 if (!mParametersSet) {
31 setParameters(mTerminals[0]->singleActivePower(),
32 mTerminals[0]->singleReactivePower(),
33 std::abs(mTerminals[0]->initialSingleVoltage()));
36 if (**mActivePower != 0) {
37 mResistance = std::pow(**mNomVoltage, 2) / **mActivePower;
39 std::make_shared<DP::Ph1::Resistor>(**mName +
"_res", mLogLevel);
40 mSubResistor->setParameters(mResistance);
41 mSubResistor->connect({SimNode::GND, mTerminals[0]->node()});
42 mSubResistor->initialize(mFrequencies);
43 mSubResistor->initializeFromNodesAndTerminals(frequency);
44 addMNASubComponent(mSubResistor, MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
45 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
false);
50 if (**mReactivePower != 0)
51 mReactance = std::pow(**mNomVoltage, 2) / **mReactivePower;
56 mInductance = mReactance / (2. * PI * frequency);
58 std::make_shared<DP::Ph1::Inductor>(**mName +
"_ind", mLogLevel);
59 mSubInductor->setParameters(mInductance);
60 mSubInductor->connect({SimNode::GND, mTerminals[0]->node()});
61 mSubInductor->initialize(mFrequencies);
62 mSubInductor->initializeFromNodesAndTerminals(frequency);
63 addMNASubComponent(mSubInductor, MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
64 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
true);
65 }
else if (mReactance < 0) {
66 mCapacitance = -1. / (2. * PI * frequency) / mReactance;
68 std::make_shared<DP::Ph1::Capacitor>(**mName +
"_cap", mLogLevel);
69 mSubCapacitor->setParameters(mCapacitance);
70 mSubCapacitor->connect({SimNode::GND, mTerminals[0]->node()});
71 mSubCapacitor->initialize(mFrequencies);
72 mSubCapacitor->initializeFromNodesAndTerminals(frequency);
73 addMNASubComponent(mSubCapacitor,
74 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
75 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
true);
78 (**mIntfVoltage)(0, 0) = mTerminals[0]->initialSingleVoltage();
79 (**mIntfCurrent)(0, 0) = std::conj(Complex(**mActivePower, **mReactivePower) /
80 (**mIntfVoltage)(0, 0));
82 SPDLOG_LOGGER_INFO(mSLog,
83 "\n--- Initialization from powerflow ---"
84 "\nVoltage across: {:s}"
86 "\nTerminal 0 voltage: {:s}"
89 "\n--- Initialization from powerflow finished ---",
90 Logger::phasorToString((**mIntfVoltage)(0, 0)),
91 Logger::phasorToString((**mIntfCurrent)(0, 0)),
92 Logger::phasorToString(initialSingleVoltage(0)),
93 mResistance, mReactance);
98 mParametersSet =
true;
99 **mActivePower = activePower;
100 **mReactivePower = reactivePower;
101 **mNomVoltage = volt;
103 SPDLOG_LOGGER_INFO(mSLog,
"Active Power={} [W] Reactive Power={} [VAr]",
104 **mActivePower, **mReactivePower);
105 SPDLOG_LOGGER_INFO(mSLog,
"Nominal Voltage={} [V]", **mNomVoltage);
109 (**mIntfVoltage)(0, 0) =
110 Math::complexFromVectorElement(leftVector, matrixNodeIndex(0));
114 (**mIntfCurrent)(0, 0) = 0;
116 for (
auto subComp : mSubComponents) {
117 (**mIntfCurrent)(0, 0) += subComp->intfCurrent()(0, 0);
122 AttributeBase::List &prevStepDependencies,
123 AttributeBase::List &attributeDependencies,
124 AttributeBase::List &modifiedAttributes) {
125 modifiedAttributes.push_back(mRightVector);
129 mnaCompApplyRightSideVectorStamp(**mRightVector);
133 AttributeBase::List &prevStepDependencies,
134 AttributeBase::List &attributeDependencies,
135 AttributeBase::List &modifiedAttributes,
137 attributeDependencies.push_back(leftVector);
138 modifiedAttributes.push_back(mIntfVoltage);
139 modifiedAttributes.push_back(mIntfCurrent);
144 mnaCompUpdateVoltage(**leftVector);
145 mnaCompUpdateCurrent(**leftVector);
Base class for composite power components.
Constant impedance load model consisting of RLC elements.
RXLoad(String uid, String name, Logger::Level logLevel=Logger::Level::off)
Defines UID, name and logging level.
void mnaParentPostStep(Real time, Int timeStepCount, Attribute< Matrix >::Ptr &leftVector) override
MNA post step operations.
void mnaParentAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector) override
Add MNA post step dependencies.
void setParameters(Real activePower, Real ReactivePower, Real volt)
Set model specific parameters.
void mnaParentAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes) override
Add MNA pre step dependencies.
void mnaParentPreStep(Real time, Int timeStepCount) override
MNA pre step operations.
void mnaCompUpdateVoltage(const Matrix &leftVector) override
Update interface voltage from MNA system result.
void initializeFromNodesAndTerminals(Real frequency) override
Initialize component from power flow data.
void mnaCompUpdateCurrent(const Matrix &leftVector) override
Update interface current from MNA system result.
String type()
Get component type (cross-platform)
const Attribute< MatrixVar< Complex > >::Ptr mIntfCurrent
Current through component.
const Attribute< MatrixVar< Complex > >::Ptr mIntfVoltage
Voltage between terminals.
Logger::Log mSLog
Component logger.