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);
32 Real omega = 2. * PI * frequency;
34 (**mIntfVoltage)(0, 0) = initialSingleVoltage(1) - initialSingleVoltage(0);
35 (**mIntfCurrent)(0, 0) = (**
mIntfVoltage)(0, 0) / impedance;
49 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
50 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
false);
59 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
60 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
true);
64 Real defaultParallelCond = 1e-6;
73 SimNode::List{SimNode::GND,
mTerminals[0]->node()});
77 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
78 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
false);
84 SimNode::List{SimNode::GND,
mTerminals[1]->node()});
88 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
89 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
false);
92 mSubParallelCapacitor0 =
93 std::make_shared<DP::Ph1::Capacitor>(**
mName +
"_cap0",
mLogLevel);
94 mSubParallelCapacitor0->setParameters(**
mParallelCap / 2.);
95 mSubParallelCapacitor0->connect(
96 SimNode::List{SimNode::GND,
mTerminals[0]->node()});
98 mSubParallelCapacitor0->initializeFromNodesAndTerminals(frequency);
100 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
101 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
true);
104 std::make_shared<DP::Ph1::Capacitor>(**
mName +
"_cap1",
mLogLevel);
107 SimNode::List{SimNode::GND,
mTerminals[1]->node()});
111 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
112 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
true);
117 "\n--- Initialization from powerflow ---"
118 "\nVoltage across: {:s}"
120 "\nTerminal 0 voltage: {:s}"
121 "\nTerminal 1 voltage: {:s}"
122 "\nVirtual Node 1 voltage: {:s}"
123 "\n--- Initialization from powerflow finished ---",
126 Logger::phasorToString(initialSingleVoltage(0)),
127 Logger::phasorToString(initialSingleVoltage(1)),
128 Logger::phasorToString(
mVirtualNodes[0]->initialSingleVoltage()));
132 AttributeBase::List &prevStepDependencies,
133 AttributeBase::List &attributeDependencies,
134 AttributeBase::List &modifiedAttributes) {
146void DP::Ph1::PiLine::mnaParentAddPostStepDependencies(
147 AttributeBase::List &prevStepDependencies,
148 AttributeBase::List &attributeDependencies,
149 AttributeBase::List &modifiedAttributes,
150 Attribute<Matrix>::Ptr &leftVector) {
152 attributeDependencies.push_back(leftVector);
153 modifiedAttributes.push_back(mIntfVoltage);
154 modifiedAttributes.push_back(mIntfCurrent);
157void DP::Ph1::PiLine::mnaParentPostStep(Real time, Int timeStepCount,
158 Attribute<Matrix>::Ptr &leftVector) {
160 this->mnaUpdateVoltage(**leftVector);
161 this->mnaUpdateCurrent(**leftVector);
165 (**mIntfVoltage)(0, 0) = 0;
166 if (terminalNotGrounded(1))
167 (**mIntfVoltage)(0, 0) =
168 Math::complexFromVectorElement(leftVector, matrixNodeIndex(1));
169 if (terminalNotGrounded(0))
170 (**mIntfVoltage)(0, 0) =
172 Math::complexFromVectorElement(leftVector, matrixNodeIndex(0));
180MNAInterface::List DP::Ph1::PiLine::mnaTearGroundComponents() {
181 MNAInterface::List gndComponents;
183 gndComponents.push_back(mSubParallelResistor0);
184 gndComponents.push_back(mSubParallelResistor1);
186 if (**mParallelCap >= 0) {
187 gndComponents.push_back(mSubParallelCapacitor0);
188 gndComponents.push_back(mSubParallelCapacitor1);
191 return gndComponents;
194void DP::Ph1::PiLine::mnaTearInitialize(Real omega, Real timeStep) {
195 mSubSeriesResistor->mnaTearSetIdx(mTearIdx);
196 mSubSeriesResistor->mnaTearInitialize(omega, timeStep);
197 mSubSeriesInductor->mnaTearSetIdx(mTearIdx);
198 mSubSeriesInductor->mnaTearInitialize(omega, timeStep);
201void DP::Ph1::PiLine::mnaTearApplyMatrixStamp(SparseMatrixRow &tearMatrix) {
202 mSubSeriesResistor->mnaTearApplyMatrixStamp(tearMatrix);
203 mSubSeriesInductor->mnaTearApplyMatrixStamp(tearMatrix);
206void DP::Ph1::PiLine::mnaTearApplyVoltageStamp(Matrix &voltageVector) {
207 mSubSeriesInductor->mnaTearApplyVoltageStamp(voltageVector);
210void DP::Ph1::PiLine::mnaTearPostStep(Complex voltage, Complex current) {
211 mSubSeriesInductor->mnaTearPostStep(voltage - current * **mSeriesRes,
213 (**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.
void initializeFromNodesAndTerminals(Real frequency) override
Initializes component from power flow data.
std::shared_ptr< Inductor > mSubSeriesInductor
Series Inductance submodel.
PiLine(String uid, String name, Logger::Level logLevel=Logger::Level::off)
Defines UID, name and logging level.
std::shared_ptr< Resistor > mSubParallelResistor0
Parallel Resistor submodel at Terminal 0.
void mnaParentAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes) override
add MNA pre and post step dependencies
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.