9 #include <dpsim-models/SP/SP_Ph1_NetworkInjection.h>
14 Logger::Level logLevel)
16 mVoltageRef(mAttributes->createDynamic<Complex>(
"V_ref")),
17 mSrcFreq(mAttributes->createDynamic<Real>(
"f_src")),
18 mVoltageSetPoint(mAttributes->create<Real>(
"V_set")),
19 mVoltageSetPointPerUnit(mAttributes->create<Real>(
"V_set_pu", 1.0)),
20 mActivePowerInjection(mAttributes->create<Real>(
"p_inj")),
21 mReactivePowerInjection(mAttributes->create<Real>(
"q_inj")) {
23 SPDLOG_LOGGER_INFO(
mSLog,
"Create {} of type {}", **
mName, this->
type());
27 setVirtualNodeNumber(0);
32 std::make_shared<SP::Ph1::VoltageSource>(**
mName +
"_vs",
mLogLevel);
34 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
35 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
true);
36 SPDLOG_LOGGER_INFO(
mSLog,
"Electrical subcomponents: ");
38 SPDLOG_LOGGER_INFO(
mSLog,
"- {}", subcomp->name());
41 mSubVoltageSource->mVoltageRef->setReference(mVoltageRef);
42 mSubVoltageSource->mSrcFreq->setReference(mSrcFreq);
48 **mVoltageSetPoint = voltageSetPoint;
50 SPDLOG_LOGGER_INFO(mSLog,
"Voltage Set-Point ={} [V]", **mVoltageSetPoint);
53 mParametersSet =
true;
57 Real freqStart, Real rocof,
58 Real timeStart, Real duration,
60 mParametersSet =
true;
62 mSubVoltageSource->setParameters(initialPhasor, freqStart, rocof, timeStart,
63 duration, smoothRamp);
67 "\nVoltage Ref={:s} [V]"
68 "\nInitial frequency={:s} [Hz]"
69 "\nRamp ROCOF={:s} [Hz/s]"
70 "\nRamp duration={:s} [s]"
71 "\nRamp nadir={:s} [Hz]",
72 Logger::phasorToString(initialPhasor), Logger::realToString(freqStart),
73 Logger::realToString(rocof), Logger::realToString(duration),
74 Logger::realToString(freqStart + rocof * duration));
78 Real modulationFrequency,
79 Real modulationAmplitude,
82 mParametersSet =
true;
84 mSubVoltageSource->setParameters(initialPhasor, modulationFrequency,
85 modulationAmplitude, baseFrequency, zigzag);
87 SPDLOG_LOGGER_INFO(mSLog,
88 "\nVoltage Ref={:s} [V]"
89 "\nFrequency={:s} [Hz]",
90 Logger::phasorToString(initialPhasor),
91 Logger::realToString(baseFrequency));
95 mBaseVoltage = baseVoltage;
99 Real baseApparentPower, Real baseOmega) {
100 SPDLOG_LOGGER_INFO(mSLog,
"#### Calculate Per Unit Parameters for {}",
102 SPDLOG_LOGGER_INFO(mSLog,
"Base Voltage={} [V]", mBaseVoltage);
104 **mVoltageSetPointPerUnit = **mVoltageSetPoint / mBaseVoltage;
106 SPDLOG_LOGGER_INFO(mSLog,
"Voltage Set-Point ={} [pu]",
107 **mVoltageSetPointPerUnit);
112 PowerflowBusType powerflowBusType) {
113 mPowerflowBusType = powerflowBusType;
117 **mActivePowerInjection = powerInj.real();
118 **mReactivePowerInjection = powerInj.imag();
125 mParametersSet =
true;
127 mSubVoltageSource->setParameters(voltageRef, srcFreq);
129 SPDLOG_LOGGER_INFO(mSLog,
130 "\nVoltage Ref={:s} [V]"
131 "\nFrequency={:s} [Hz]",
132 Logger::phasorToString(voltageRef),
133 Logger::realToString(srcFreq));
137 auto copy = NetworkInjection::make(name, mLogLevel);
138 copy->setParameters(**mVoltageRef);
145 mSubVoltageSource->connect({SimNode::GND, node(0)});
148 for (
auto subcomp : mSubComponents) {
149 subcomp->initialize(mFrequencies);
150 subcomp->initializeFromNodesAndTerminals(frequency);
156 Matrix &rightVector) {
157 SPDLOG_LOGGER_DEBUG(mSLog,
"Right Side Vector: {:s}",
158 Logger::matrixToString(rightVector));
162 AttributeBase::List &prevStepDependencies,
163 AttributeBase::List &attributeDependencies,
164 AttributeBase::List &modifiedAttributes) {
165 prevStepDependencies.push_back(mIntfCurrent);
166 prevStepDependencies.push_back(mIntfVoltage);
167 modifiedAttributes.push_back(mRightVector);
171 mnaCompApplyRightSideVectorStamp(**mRightVector);
175 AttributeBase::List &prevStepDependencies,
176 AttributeBase::List &attributeDependencies,
177 AttributeBase::List &modifiedAttributes,
179 attributeDependencies.push_back(leftVector);
180 modifiedAttributes.push_back(mIntfVoltage);
181 modifiedAttributes.push_back(mIntfCurrent);
186 mnaCompUpdateCurrent(**leftVector);
187 mnaCompUpdateVoltage(**leftVector);
191 **mIntfVoltage = **mSubVoltageSource->mIntfVoltage;
195 **mIntfCurrent = **mSubVoltageSource->mIntfCurrent;
199 const double dstate_dt[],
201 std::vector<int> &off) {
214 int Pos1 = matrixNodeIndex(0);
215 int Pos2 = matrixNodeIndex(1);
216 int c_offset = off[0] + off[1];
221 resid[c_offset] = (state[Pos2] - state[Pos1]) -
224 resid[n_offset_1] += (**mIntfCurrent)(0, 0).real();
225 resid[n_offset_2] += (**mIntfCurrent)(0, 0).real();
230 (**mIntfVoltage)(0, 0) = (**mSubVoltageSource->mIntfVoltage)(0, 0);
231 return (**mSubVoltageSource->mIntfVoltage)(0, 0);
Base class for composite power components.
void addMNASubComponent(typename SimPowerComp< Complex >::Ptr subc, MNA_SUBCOMP_TASK_ORDER preStepOrder, MNA_SUBCOMP_TASK_ORDER postStepOrder, Bool contributeToRightVector)
Add a new subcomponent implementing MNA methods.
const Attribute< String >::Ptr mName
Human readable name.
String type()
Get component type (cross-platform)
void setParameters(Real vSetPointPerUnit)
Set parameters relevant for PF solver.
Complex daeInitialize() override
Voltage Getter.
void daeResidual(double ttime, const double state[], const double dstate_dt[], double resid[], std::vector< int > &off) override
Residual function for DAE Solver.
void mnaParentApplyRightSideVectorStamp(Matrix &rightVector) override
Stamps right side (source) vector.
void initializeFromNodesAndTerminals(Real frequency) override
Initializes component from power flow data.
void mnaParentAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes) override
Add MNA pre step dependencies.
void calculatePerUnitParameters(Real baseApparentPower, Real baseOmega)
Calculates component's parameters in specified per-unit system.
void mnaParentAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector) override
Add MNA post step dependencies.
NetworkInjection(String uid, String name, Logger::Level logLevel=Logger::Level::off)
Defines UID, name and logging level.
void mnaCompUpdateVoltage(const Matrix &leftVector) override
Updates voltage across component.
void mnaParentPostStep(Real time, Int timeStepCount, Attribute< Matrix >::Ptr &leftVector) override
MNA post step operations.
void mnaParentPreStep(Real time, Int timeStepCount) override
MNA pre step operations.
void setBaseVoltage(Real baseVoltage)
Set base voltage.
void modifyPowerFlowBusType(PowerflowBusType powerflowBusType) override
Modify powerflow bus type.
void mnaCompUpdateCurrent(const Matrix &leftVector) override
Returns current through the component.
void updatePowerInjection(Complex powerInj)
Update power injection.
SimPowerComp< Complex >::Ptr clone(String name) override
Returns a modified copy of the component with the given suffix added to the name and without.
Base class for all components that are transmitting power.
std::vector< std::shared_ptr< SimPowerComp< Complex > > > mSubComponents
const Attribute< MatrixVar< Complex > >::Ptr mIntfCurrent
Current through component.
const Attribute< MatrixVar< Complex > >::Ptr mIntfVoltage
Voltage between terminals.
Logger::Level mLogLevel
Component logger control for internal variables.
Logger::Log mSLog
Component logger.