9 #include <dpsim-models/DP/DP_Ph1_PQLoadCS.h>
15 mActivePower(mAttributes->create<Real>(
"P", 0)),
16 mReactivePower(mAttributes->create<Real>(
"Q", 0)),
17 mNomVoltage(mAttributes->create<Real>(
"V_nom")) {
24 Real reactivePower, Real nomVolt,
25 Logger::Level logLevel)
28 setParameters(activePower, reactivePower, nomVolt);
35 Real nomVolt, Logger::Level logLevel)
36 :
PQLoadCS(name, name, activePower, reactivePower, nomVolt, logLevel) {}
38 void DP::Ph1::PQLoadCS::setParameters(Real activePower, Real reactivePower,
40 **mActivePower = activePower;
41 **mReactivePower = reactivePower;
42 **mNomVoltage = nomVolt;
43 mParametersSet =
true;
48 auto copy = PQLoadCS::make(name, mLogLevel);
49 copy->setParameters(**mActivePower, **mReactivePower, **mNomVoltage);
55 if (**mActivePower == 0 && **mReactivePower == 0 && !mParametersSet) {
56 **mActivePower = mTerminals[0]->singleActivePower();
57 **mReactivePower = mTerminals[0]->singleReactivePower();
58 **mNomVoltage = std::abs(mTerminals[0]->initialSingleVoltage());
60 Complex power = Complex(**mActivePower, **mReactivePower);
63 if (**mNomVoltage != 0)
64 current = std::conj(power / **mNomVoltage);
69 std::make_shared<DP::Ph1::CurrentSource>(**mName +
"_cs", mLogLevel);
70 mSubCurrentSource->setParameters(current);
72 mSubCurrentSource->connect({mTerminals[0]->node(), SimNode::GND});
73 mSubCurrentSource->initializeFromNodesAndTerminals(frequency);
74 addMNASubComponent(mSubCurrentSource,
75 MNA_SUBCOMP_TASK_ORDER::TASK_AFTER_PARENT,
76 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
true);
79 SPDLOG_LOGGER_INFO(mSLog,
80 "\n--- Initialization from powerflow ---"
81 "\nVoltage across: {:s}"
83 "\nTerminal 0 voltage: {:s}"
84 "\nCurrent set point: {:s}"
85 "\n--- Initialization from powerflow finished ---",
86 Logger::phasorToString((**mIntfVoltage)(0, 0)),
87 Logger::phasorToString((**mIntfCurrent)(0, 0)),
88 Logger::phasorToString(initialSingleVoltage(0)),
89 Logger::phasorToString(current));
92 void DP::Ph1::PQLoadCS::updateSetPoint() {
94 Complex power = {**mActivePower, **mReactivePower};
95 Complex current = power / **mNomVoltage;
98 **mSubCurrentSource->mCurrentRef = std::conj(current);
99 SPDLOG_LOGGER_DEBUG(mSLog,
100 "\n--- update set points ---"
103 Logger::phasorToString(power),
104 Logger::phasorToString(std::conj(current)));
107 void DP::Ph1::PQLoadCS::mnaParentAddPreStepDependencies(
108 AttributeBase::List &prevStepDependencies,
109 AttributeBase::List &attributeDependencies,
110 AttributeBase::List &modifiedAttributes) {
111 attributeDependencies.push_back(mActivePower);
112 attributeDependencies.push_back(mReactivePower);
113 attributeDependencies.push_back(mNomVoltage);
116 void DP::Ph1::PQLoadCS::mnaParentAddPostStepDependencies(
117 AttributeBase::List &prevStepDependencies,
118 AttributeBase::List &attributeDependencies,
119 AttributeBase::List &modifiedAttributes,
121 modifiedAttributes.push_back(mIntfCurrent);
122 modifiedAttributes.push_back(mIntfVoltage);
127 mnaCompApplyRightSideVectorStamp(**mRightVector);
130 void DP::Ph1::PQLoadCS::updateIntfValues() {
131 **mIntfCurrent = mSubCurrentSource->intfCurrent();
132 **mIntfVoltage = mSubCurrentSource->intfVoltage();
135 void DP::Ph1::PQLoadCS::mnaParentPostStep(Real time, Int timeStepCount,
Base class for composite power components.
PQ-load represented by a current source.
PQLoadCS(String uid, String name, Logger::Level logLevel=Logger::Level::off)
Defines UID, name and logging level.
void mnaParentPreStep(Real time, Int timeStepCount) override
MNA pre and post step operations.
SimPowerComp< Complex >::Ptr clone(String name) override
DEPRECATED: Delete method.
void initializeFromNodesAndTerminals(Real frequency) override
Initializes component from power flow data.
Base class for all components that are transmitting power.
const Attribute< MatrixVar< Complex > >::Ptr mIntfCurrent
Current through component.
const Attribute< MatrixVar< Complex > >::Ptr mIntfVoltage
Voltage between terminals.