9 #include <dpsim-models/EMT/EMT_Ph3_NetworkInjection.h>
14 Logger::Level logLevel)
16 mVoltageRef(mAttributes->createDynamic<MatrixComp>(
"V_ref")),
17 mSrcFreq(mAttributes->createDynamic<Real>(
"f_src")) {
18 mPhaseType = PhaseType::ABC;
19 setVirtualNodeNumber(0);
24 SPDLOG_LOGGER_INFO(
mSLog,
"Create {} {}", this->
type(), name);
28 std::make_shared<EMT::Ph3::VoltageSource>(**
mName +
"_vs",
mLogLevel);
30 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
31 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::matrixCompToString(voltageRef),
56 Logger::realToString(srcFreq));
60 Real freqStart, Real rocof,
61 Real timeStart, Real duration,
63 mParametersSet =
true;
65 mSubVoltageSource->setParameters(voltageRef, 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::matrixCompToString(voltageRef), 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(voltageRef, modulationFrequency,
88 modulationAmplitude, baseFrequency, zigzag);
90 SPDLOG_LOGGER_INFO(mSLog,
91 "\nVoltage Ref={:s} [V]"
92 "\nFrequency={:s} [Hz]",
93 Logger::matrixCompToString(voltageRef),
94 Logger::realToString(baseFrequency));
100 mSubVoltageSource->connect({SimNode::GND, node(0)});
103 for (
auto subcomp : mSubComponents) {
104 subcomp->initialize(mFrequencies);
105 subcomp->initializeFromNodesAndTerminals(frequency);
111 Matrix &rightVector) {
112 SPDLOG_LOGGER_DEBUG(mSLog,
"Right Side Vector: {:s}",
113 Logger::matrixToString(rightVector));
117 AttributeBase::List &prevStepDependencies,
118 AttributeBase::List &attributeDependencies,
119 AttributeBase::List &modifiedAttributes) {
120 prevStepDependencies.push_back(mIntfCurrent);
121 prevStepDependencies.push_back(mIntfVoltage);
122 modifiedAttributes.push_back(mRightVector);
127 mnaCompApplyRightSideVectorStamp(**mRightVector);
131 AttributeBase::List &prevStepDependencies,
132 AttributeBase::List &attributeDependencies,
133 AttributeBase::List &modifiedAttributes,
135 attributeDependencies.push_back(leftVector);
136 modifiedAttributes.push_back(mIntfVoltage);
137 modifiedAttributes.push_back(mIntfCurrent);
142 mnaCompUpdateCurrent(**leftVector);
143 mnaCompUpdateVoltage(**leftVector);
147 const Matrix &leftVector) {
148 **mIntfVoltage = **mSubVoltageSource->mIntfVoltage;
152 const Matrix &leftVector) {
153 **mIntfCurrent = **mSubVoltageSource->mIntfCurrent;
Base class for composite power components.
void addMNASubComponent(typename SimPowerComp< Real >::Ptr subc, MNA_SUBCOMP_TASK_ORDER preStepOrder, MNA_SUBCOMP_TASK_ORDER postStepOrder, Bool contributeToRightVector)
Add a new subcomponent implementing MNA methods.
void mnaParentApplyRightSideVectorStamp(Matrix &rightVector) override
Stamps right side (source) vector.
void setParameters(MatrixComp voltageRef, Real srcFreq=50.0)
Setter for reference voltage parameters.
void mnaCompUpdateVoltage(const Matrix &leftVector) override
Updates voltage across component.
void mnaParentAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector) override
Add MNA post step dependencies.
void initializeFromNodesAndTerminals(Real frequency) override
Initializes component from power flow data.
void mnaCompUpdateCurrent(const Matrix &leftVector) override
Returns current through the component.
void mnaParentPostStep(Real time, Int timeStepCount, Attribute< Matrix >::Ptr &leftVector) override
MNA post step operations.
SimPowerComp< Real >::Ptr clone(String name) override
Returns a modified copy of the component with the given suffix added to the name and without.
void mnaParentPreStep(Real time, Int timeStepCount) override
MNA pre step operations.
void mnaParentAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes) override
Add MNA pre step dependencies.
NetworkInjection(String uid, String name, Logger::Level loglevel=Logger::Level::off)
Defines UID, name, component parameters and logging level.
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< Real > > > mSubComponents
const Attribute< MatrixVar< Real > >::Ptr mIntfCurrent
Current through component.
const Attribute< MatrixVar< Real > >::Ptr mIntfVoltage
Voltage between terminals.
Logger::Level mLogLevel
Component logger control for internal variables.
Logger::Log mSLog
Component logger.