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")),
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);
57 Real freqStart, Real rocof,
58 Real timeStart, Real duration,
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,
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));
94Real SP::Ph1::NetworkInjection::getBaseVoltage()
const {
return mBaseVoltage; }
97 mBaseVoltage = baseVoltage;
101 Real baseApparentPower, Real baseOmega) {
102 SPDLOG_LOGGER_INFO(
mSLog,
"#### Calculate Per Unit Parameters for {}",
104 SPDLOG_LOGGER_INFO(
mSLog,
"Base Voltage={} [V]", mBaseVoltage);
108 SPDLOG_LOGGER_INFO(
mSLog,
"Voltage Set-Point ={} [pu]",
114 PowerflowBusType powerflowBusType) {
129 mSubVoltageSource->setParameters(voltageRef, srcFreq);
131 SPDLOG_LOGGER_INFO(
mSLog,
132 "\nVoltage Ref={:s} [V]"
133 "\nFrequency={:s} [Hz]",
134 Logger::phasorToString(voltageRef),
135 Logger::realToString(srcFreq));
139 auto copy = NetworkInjection::make(name,
mLogLevel);
140 copy->setParameters(**mVoltageRef);
147 mSubVoltageSource->connect({SimNode::GND,
node(0)});
152 subcomp->initializeFromNodesAndTerminals(frequency);
158 Matrix &rightVector) {
159 SPDLOG_LOGGER_DEBUG(
mSLog,
"Right Side Vector: {:s}",
160 Logger::matrixToString(rightVector));
164 AttributeBase::List &prevStepDependencies,
165 AttributeBase::List &attributeDependencies,
166 AttributeBase::List &modifiedAttributes) {
177 AttributeBase::List &prevStepDependencies,
178 AttributeBase::List &attributeDependencies,
179 AttributeBase::List &modifiedAttributes,
180 Attribute<Matrix>::Ptr &leftVector) {
181 attributeDependencies.push_back(leftVector);
187 Real time, Int timeStepCount, Attribute<Matrix>::Ptr &leftVector) {
201 const double dstate_dt[],
203 std::vector<int> &off) {
216 int Pos1 = matrixNodeIndex(0);
217 int Pos2 = matrixNodeIndex(1);
218 int c_offset = off[0] + off[1];
223 resid[c_offset] = (state[Pos2] - state[Pos1]) -
226 resid[n_offset_1] += (**mIntfCurrent)(0, 0).real();
227 resid[n_offset_2] += (**mIntfCurrent)(0, 0).real();
232 (**mIntfVoltage)(0, 0) = (**mSubVoltageSource->mIntfVoltage)(0, 0);
233 return (**mSubVoltageSource->mIntfVoltage)(0, 0);
void addMNASubComponent(typename SimPowerComp< Complex >::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< 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
PowerflowBusType mPowerflowBusType
Define the type of bus the component is modelled by.
const Attribute< Real >::Ptr mActivePowerInjection
Active Power Injection [W].
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.
const Attribute< Real >::Ptr mVoltageSetPoint
Voltage set point [V].
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.
const Attribute< Real >::Ptr mVoltageSetPointPerUnit
Voltage set point [pu].
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.
const Attribute< Real >::Ptr mReactivePowerInjection
Reactive Power Injection [Var].
const Attribute< MatrixVar< Complex > >::Ptr mIntfCurrent
SimNode< Complex >::Ptr node(UInt index)
const Attribute< MatrixVar< Complex > >::Ptr mIntfVoltage
std::vector< std::shared_ptr< SimPowerComp< Complex > > > mSubComponents
Logger::Level mLogLevel
Component logger control for internal variables.
bool mParametersSet
Flag indicating that parameters are set via setParameters() function.
Logger::Log mSLog
Component logger.