6#include <dpsim-models/DP/DP_Ph1_PiLine.h>
13 setVirtualNodeNumber(1);
16 SPDLOG_LOGGER_INFO(
mSLog,
"Create {} {}", this->
type(), name);
23 auto copy = PiLine::make(name,
mLogLevel);
36 Real defaultParallelCond = 1e-6;
46 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
47 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
false);
55 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
56 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
true);
62 SimNode::List{SimNode::GND,
mTerminals[0]->node()});
65 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
66 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
false);
72 SimNode::List{SimNode::GND,
mTerminals[1]->node()});
75 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
76 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
false);
79 mSubParallelCapacitor0 =
80 std::make_shared<DP::Ph1::Capacitor>(**
mName +
"_cap0",
mLogLevel);
81 mSubParallelCapacitor0->setParameters(**
mParallelCap / 2.);
82 mSubParallelCapacitor0->connect(
83 SimNode::List{SimNode::GND,
mTerminals[0]->node()});
86 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
87 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
true);
90 std::make_shared<DP::Ph1::Capacitor>(**
mName +
"_cap1",
mLogLevel);
93 SimNode::List{SimNode::GND,
mTerminals[1]->node()});
96 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
97 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
true);
103 Real omega = 2. * PI * frequency;
105 (**mIntfVoltage)(0, 0) = initialSingleVoltage(1) - initialSingleVoltage(0);
106 (**mIntfCurrent)(0, 0) = (**
mIntfVoltage)(0, 0) / impedance;
109 mVirtualNodes[0]->setInitialVoltage(initialSingleVoltage(0) +
114 "\n--- Initialization from powerflow ---"
115 "\nVoltage across: {:s}"
117 "\nTerminal 0 voltage: {:s}"
118 "\nTerminal 1 voltage: {:s}"
119 "\nVirtual Node 1 voltage: {:s}"
120 "\n--- Initialization from powerflow finished ---",
123 Logger::phasorToString(initialSingleVoltage(0)),
124 Logger::phasorToString(initialSingleVoltage(1)),
125 Logger::phasorToString(
mVirtualNodes[0]->initialSingleVoltage()));
129 AttributeBase::List &prevStepDependencies,
130 AttributeBase::List &attributeDependencies,
131 AttributeBase::List &modifiedAttributes) {
143void DP::Ph1::PiLine::mnaParentAddPostStepDependencies(
144 AttributeBase::List &prevStepDependencies,
145 AttributeBase::List &attributeDependencies,
146 AttributeBase::List &modifiedAttributes,
147 Attribute<Matrix>::Ptr &leftVector) {
149 attributeDependencies.push_back(leftVector);
150 modifiedAttributes.push_back(mIntfVoltage);
151 modifiedAttributes.push_back(mIntfCurrent);
154void DP::Ph1::PiLine::mnaParentPostStep(Real time, Int timeStepCount,
155 Attribute<Matrix>::Ptr &leftVector) {
157 this->mnaUpdateVoltage(**leftVector);
158 this->mnaUpdateCurrent(**leftVector);
162 (**mIntfVoltage)(0, 0) = 0;
163 if (terminalNotGrounded(1))
164 (**mIntfVoltage)(0, 0) =
165 Math::complexFromVectorElement(leftVector, matrixNodeIndex(1));
166 if (terminalNotGrounded(0))
167 (**mIntfVoltage)(0, 0) =
169 Math::complexFromVectorElement(leftVector, matrixNodeIndex(0));
177MNAInterface::List DP::Ph1::PiLine::mnaTearGroundComponents() {
178 MNAInterface::List gndComponents;
180 gndComponents.push_back(mSubParallelResistor0);
181 gndComponents.push_back(mSubParallelResistor1);
183 if (**mParallelCap > 0) {
184 gndComponents.push_back(mSubParallelCapacitor0);
185 gndComponents.push_back(mSubParallelCapacitor1);
188 return gndComponents;
191void DP::Ph1::PiLine::mnaTearInitialize(Real omega, Real timeStep) {
192 mSubSeriesResistor->mnaTearSetIdx(mTearIdx);
193 mSubSeriesResistor->mnaTearInitialize(omega, timeStep);
194 mSubSeriesInductor->mnaTearSetIdx(mTearIdx);
195 mSubSeriesInductor->mnaTearInitialize(omega, timeStep);
198void DP::Ph1::PiLine::mnaTearApplyMatrixStamp(SparseMatrixRow &tearMatrix) {
199 mSubSeriesResistor->mnaTearApplyMatrixStamp(tearMatrix);
200 mSubSeriesInductor->mnaTearApplyMatrixStamp(tearMatrix);
203void DP::Ph1::PiLine::mnaTearApplyVoltageStamp(Matrix &voltageVector) {
204 mSubSeriesInductor->mnaTearApplyVoltageStamp(voltageVector);
207void DP::Ph1::PiLine::mnaTearPostStep(Complex voltage, Complex current) {
208 mSubSeriesInductor->mnaTearPostStep(voltage - current * **mSeriesRes,
210 (**mIntfCurrent)(0, 0) = mSubSeriesInductor->intfCurrent()(0, 0);
const Attribute< Real >::Ptr mParallelCap
Capacitance in parallel to the line [F].
const Attribute< Real >::Ptr mParallelCond
Conductance in parallel to the line [S].
const Attribute< Real >::Ptr mSeriesInd
Inductance along the line [H].
const Attribute< Real >::Ptr mSeriesRes
Resistance along the line [ohms].
void addMNASubComponent(typename SimPowerComp< Complex >::Ptr subc, MNA_SUBCOMP_TASK_ORDER preStepOrder, MNA_SUBCOMP_TASK_ORDER postStepOrder, Bool contributeToRightVector)
CompositePowerComp(String uid, String name, Bool hasPreStep, Bool hasPostStep, Logger::Level logLevel)
void mnaParentPreStep(Real time, Int timeStepCount) override
MNA pre and post step operations.
std::shared_ptr< Capacitor > mSubParallelCapacitor1
Parallel capacitor submodel at Terminal 1.
SimPowerComp< Complex >::Ptr clone(String copySuffix) override
DEPRECATED: Remove method.
void mnaCompUpdateCurrent(const Matrix &leftVector) override
Updates internal current variable of the component.
std::shared_ptr< Resistor > mSubParallelResistor1
Parallel resistor submodel at Terminal 1.
std::shared_ptr< Resistor > mSubSeriesResistor
Series Resistor submodel.
std::shared_ptr< Inductor > mSubSeriesInductor
Series Inductance submodel.
PiLine(String uid, String name, Logger::Level logLevel=Logger::Level::off)
True after createSubComponents() runs; prevents double-construction.
std::shared_ptr< Resistor > mSubParallelResistor0
Parallel Resistor submodel at Terminal 0.
void createSubComponents() override
Constructs and registers MNA subcomponents; idempotent.
void mnaParentAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes) override
add MNA pre and post step dependencies
void initializeParentFromNodesAndTerminals(Real frequency) override
Derives values from power flow data and pushes them to subcomponents.
void mnaCompUpdateVoltage(const Matrix &leftVector) override
Updates internal voltage variable of the component.
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
void mnaApplyRightSideVectorStamp(Matrix &rightVector) final
const Attribute< MatrixVar< Complex > >::Ptr mIntfCurrent
SimTerminal< Complex >::List mTerminals
const Attribute< MatrixVar< Complex > >::Ptr mIntfVoltage
SimNode< Complex >::List mVirtualNodes
Logger::Level mLogLevel
Component logger control for internal variables.
Logger::Log mSLog
Component logger.