9 #include <dpsim-models/DP/DP_Ph1_NetworkInjection.h>
14 Logger::Level logLevel)
16 mVoltageRef(mAttributes->createDynamic<Complex>(
"V_ref")),
17 mSrcFreq(mAttributes->createDynamic<Real>(
"f_src")) {
18 setVirtualNodeNumber(0);
21 SPDLOG_LOGGER_INFO(
mSLog,
"Create {} {}", this->
type(), name);
27 std::make_shared<DP::Ph1::VoltageSource>(**
mName +
"_vs",
mLogLevel);
29 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
30 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
true);
32 SPDLOG_LOGGER_INFO(
mSLog,
"Electrical subcomponents: ");
34 SPDLOG_LOGGER_INFO(
mSLog,
"- {}", subcomp->name());
36 mSubVoltageSource->mVoltageRef->setReference(mVoltageRef);
37 mSubVoltageSource->mSrcFreq->setReference(mSrcFreq);
41 auto copy = NetworkInjection::make(name, mLogLevel);
42 copy->setParameters(**mVoltageRef);
48 mParametersSet =
true;
50 mSubVoltageSource->setParameters(voltageRef, srcFreq);
52 SPDLOG_LOGGER_INFO(mSLog,
53 "\nVoltage Ref={:s} [V]"
54 "\nFrequency={:s} [Hz]",
55 Logger::phasorToString(voltageRef),
56 Logger::realToString(srcFreq));
60 Real freqStart, Real rocof,
61 Real timeStart, Real duration,
63 mParametersSet =
true;
65 mSubVoltageSource->setParameters(initialPhasor, freqStart, rocof, timeStart,
66 duration, smoothRamp);
70 "\nVoltage Ref={:s} [V]"
71 "\nInitial frequency={:s} [Hz]"
72 "\nRamp ROCOF={:s} [Hz/s]"
73 "\nRamp duration={:s} [s]"
74 "\nRamp nadir={:s} [Hz]",
75 Logger::phasorToString(initialPhasor), Logger::realToString(freqStart),
76 Logger::realToString(rocof), Logger::realToString(duration),
77 Logger::realToString(freqStart + rocof * duration));
81 Real modulationFrequency,
82 Real modulationAmplitude,
85 mParametersSet =
true;
87 mSubVoltageSource->setParameters(initialPhasor, modulationFrequency,
88 modulationAmplitude, baseFrequency, zigzag);
90 SPDLOG_LOGGER_INFO(mSLog,
91 "\nVoltage Ref={:s} [V]"
92 "\nFrequency={:s} [Hz]",
93 Logger::phasorToString(initialPhasor),
94 Logger::realToString(baseFrequency));
100 mSubVoltageSource->connect({SimNode::GND, node(0)});
103 for (
auto subcomp : mSubComponents) {
104 subcomp->initialize(mFrequencies);
105 subcomp->initializeFromNodesAndTerminals(frequency);
112 Matrix &rightVector) {
113 SPDLOG_LOGGER_DEBUG(mSLog,
"Right Side Vector: {:s}",
114 Logger::matrixToString(rightVector));
118 AttributeBase::List &prevStepDependencies,
119 AttributeBase::List &attributeDependencies,
120 AttributeBase::List &modifiedAttributes) {
122 prevStepDependencies.push_back(mIntfCurrent);
123 prevStepDependencies.push_back(mIntfVoltage);
124 modifiedAttributes.push_back(mRightVector);
129 mnaCompApplyRightSideVectorStamp(**mRightVector);
133 AttributeBase::List &prevStepDependencies,
134 AttributeBase::List &attributeDependencies,
135 AttributeBase::List &modifiedAttributes,
138 attributeDependencies.push_back(leftVector);
139 modifiedAttributes.push_back(mIntfVoltage);
140 modifiedAttributes.push_back(mIntfCurrent);
146 mnaCompUpdateCurrent(**leftVector);
147 mnaCompUpdateVoltage(**leftVector);
151 **mIntfVoltage = **mSubVoltageSource->mIntfVoltage;
155 **mIntfCurrent = **mSubVoltageSource->mIntfCurrent;
159 const double dstate_dt[],
161 std::vector<int> &off) {
174 int Pos1 = matrixNodeIndex(0);
175 int Pos2 = matrixNodeIndex(1);
176 int c_offset = off[0] + off[1];
181 resid[c_offset] = (state[Pos2] - state[Pos1]) -
184 resid[n_offset_1] += (**mIntfCurrent)(0, 0).real();
185 resid[n_offset_2] += (**mIntfCurrent)(0, 0).real();
190 (**mIntfVoltage)(0, 0) = (**mSubVoltageSource->mIntfVoltage)(0, 0);
191 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.
SimPowerComp< Complex >::Ptr clone(String name) override
Returns a modified copy of the component with the given suffix added to the name and without.
void daeResidual(double ttime, const double state[], const double dstate_dt[], double resid[], std::vector< int > &off) override
Residual function for DAE Solver.
Complex daeInitialize() override
Voltage Getter.
NetworkInjection(String uid, String name, Logger::Level loglevel=Logger::Level::off)
Defines UID, name and logging level.
void mnaCompUpdateCurrent(const Matrix &leftVector) override
Returns current through the component.
void setParameters(Complex voltageRef, Real srcFreq=0.0)
void mnaCompUpdateVoltage(const Matrix &leftVector) override
Updates voltage across component.
void mnaParentPreStep(Real time, Int timeStepCount) override
MNA pre step operations.
void mnaParentAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector) override
Add MNA post step dependencies.
void mnaParentApplyRightSideVectorStamp(Matrix &rightVector) override
More General setter for voltage source parameters.
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 mnaParentPostStep(Real time, Int timeStepCount, Attribute< Matrix >::Ptr &leftVector) override
MNA post step operations.
const Attribute< String >::Ptr mName
Human readable name.
String type()
Get component type (cross-platform)
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.