9#include <dpsim-models/MathUtils.h>
10#include <dpsim-models/SP/SP_Ph1_PiLine.h>
23 SPDLOG_LOGGER_INFO(
mSLog,
"Create {} {}", this->
type(), name);
26 setVirtualNodeNumber(1);
35void SP::Ph1::PiLine::setParameters(Real resistance, Real inductance,
36 Real capacitance, Real conductance) {
38 **mSeriesRes = resistance;
39 **mSeriesInd = inductance;
40 SPDLOG_LOGGER_INFO(mSLog,
"Resistance={} [Ohm] Inductance={} [H]",
41 **mSeriesRes, **mSeriesInd);
43 if (capacitance > 0) {
44 **mParallelCap = capacitance;
45 mParallelCapIsFallback =
false;
47 **mParallelCap = 1e-12;
48 mParallelCapIsFallback =
true;
50 mSLog,
"Zero value for Capacitance, setting default value of C={} [F]",
53 if (conductance > 0) {
54 **mParallelCond = conductance;
55 mParallelCondIsFallback =
false;
57 if (mBehaviour == Behaviour::Initialization)
63 **mParallelCond = (conductance > 0) ? conductance : 1e-6;
64 mParallelCondIsFallback =
true;
66 mSLog,
"Zero value for Conductance, setting default value of G={} [S]",
69 SPDLOG_LOGGER_INFO(mSLog,
"Capacitance={} [F] Conductance={} [S]",
70 **mParallelCap, **mParallelCond);
72 mParametersSet =
true;
77 auto copy = PiLine::make(name,
mLogLevel);
87 mBaseVoltage = baseVoltage;
92 SPDLOG_LOGGER_INFO(
mSLog,
"#### Calculate Per Unit Parameters for {}",
96 SPDLOG_LOGGER_INFO(
mSLog,
"Base Power={} [VA] Base Omega={} [1/s]",
97 baseApparentPower, baseOmega);
106 SPDLOG_LOGGER_INFO(
mSLog,
"Base Voltage={} [V] Base Impedance={} [Ohm]",
114 SPDLOG_LOGGER_INFO(
mSLog,
"Resistance={} [pu] Reactance={} [pu]",
116 SPDLOG_LOGGER_INFO(
mSLog,
"Susceptance={} [pu] Conductance={} [pu]",
122 int bus1 = this->matrixNodeIndex(0);
123 int bus2 = this->matrixNodeIndex(1);
126 Real parallelCondPerUnit =
127 (
mBehaviour == Behaviour::PFSimulation && mParallelCondIsFallback)
130 Real parallelCapPerUnit =
131 (
mBehaviour == Behaviour::PFSimulation && mParallelCapIsFallback)
139 Complex(parallelCondPerUnit, 1. * parallelCapPerUnit) / Complex(2, 0);
142 mY_element = MatrixComp(2, 2);
143 mY_element(0, 0) = y + ys;
144 mY_element(0, 1) = -y;
145 mY_element(1, 0) = -y;
146 mY_element(1, 1) = y + ys;
149 for (
int i = 0; i < 2; i++)
150 for (
int j = 0; j < 2; j++)
151 if (!Math::isFinite(mY_element.coeff(i, j))) {
154 "Line {}: non-finite per-unit admittance {} in element Y({},{})",
155 this->name(), Logger::complexToString(mY_element.coeff(i, j)), i,
161 Y.coeffRef(bus1, bus1) += mY_element.coeff(0, 0);
162 Y.coeffRef(bus1, bus2) += mY_element.coeff(0, 1);
163 Y.coeffRef(bus2, bus2) += mY_element.coeff(1, 1);
164 Y.coeffRef(bus2, bus1) += mY_element.coeff(1, 0);
166 SPDLOG_LOGGER_INFO(
mSLog,
"#### PF Y matrix stamping #### ");
167 SPDLOG_LOGGER_INFO(
mSLog,
"{}", mY_element);
172 VectorComp &powerflow) {
200 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
false);
207 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
true);
212 std::make_shared<SP::Ph1::Resistor>(**
mName +
"_con0",
mLogLevel);
215 SimNode::List{SimNode::GND,
mTerminals[0]->node()});
217 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
false);
220 std::make_shared<SP::Ph1::Resistor>(**
mName +
"_con1",
mLogLevel);
223 SimNode::List{SimNode::GND,
mTerminals[1]->node()});
225 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
false);
229 mSubParallelCapacitor0 =
230 std::make_shared<SP::Ph1::Capacitor>(**
mName +
"_cap0",
mLogLevel);
231 mSubParallelCapacitor0->setParameters(**
mParallelCap / 2.);
232 mSubParallelCapacitor0->connect(
233 SimNode::List{SimNode::GND,
mTerminals[0]->node()});
235 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
true);
238 std::make_shared<SP::Ph1::Capacitor>(**
mName +
"_cap1",
mLogLevel);
241 SimNode::List{SimNode::GND,
mTerminals[1]->node()});
243 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
true);
249 Real omega = 2. * PI * frequency;
251 (**mIntfVoltage)(0, 0) = initialSingleVoltage(1) - initialSingleVoltage(0);
252 (**mIntfCurrent)(0, 0) = (**
mIntfVoltage)(0, 0) / impedance;
255 mVirtualNodes[0]->setInitialVoltage(initialSingleVoltage(0) +
260 "\n--- Initialization from powerflow ---"
261 "\nVoltage across: {:s}"
263 "\nTerminal 0 voltage: {:s}"
264 "\nTerminal 1 voltage: {:s}"
265 "\nVirtual Node 1 voltage: {:s}"
266 "\n--- Initialization from powerflow finished ---",
269 Logger::phasorToString(initialSingleVoltage(0)),
270 Logger::phasorToString(initialSingleVoltage(1)),
271 Logger::phasorToString(
mVirtualNodes[0]->initialSingleVoltage()));
275 AttributeBase::List &prevStepDependencies,
276 AttributeBase::List &attributeDependencies,
277 AttributeBase::List &modifiedAttributes,
278 Attribute<Matrix>::Ptr &leftVector) {
279 attributeDependencies.push_back(leftVector);
285 Attribute<Matrix>::Ptr &leftVector) {
291 (**mIntfVoltage)(0, 0) = 0;
292 if (terminalNotGrounded(1))
293 (**mIntfVoltage)(0, 0) =
294 Math::complexFromVectorElement(leftVector, matrixNodeIndex(1));
295 if (terminalNotGrounded(0))
296 (**mIntfVoltage)(0, 0) =
298 Math::complexFromVectorElement(leftVector, matrixNodeIndex(0));
305MNAInterface::List SP::Ph1::PiLine::mnaTearGroundComponents() {
306 MNAInterface::List gndComponents;
308 gndComponents.push_back(mSubParallelResistor0);
309 gndComponents.push_back(mSubParallelResistor1);
311 if (**mParallelCap > 0) {
312 gndComponents.push_back(mSubParallelCapacitor0);
313 gndComponents.push_back(mSubParallelCapacitor1);
316 return gndComponents;
319void SP::Ph1::PiLine::mnaTearInitialize(Real omega, Real timeStep) {
320 mSubSeriesResistor->mnaTearSetIdx(mTearIdx);
321 mSubSeriesResistor->mnaTearInitialize(omega, timeStep);
322 mSubSeriesInductor->mnaTearSetIdx(mTearIdx);
323 mSubSeriesInductor->mnaTearInitialize(omega, timeStep);
326void SP::Ph1::PiLine::mnaTearApplyMatrixStamp(SparseMatrixRow &tearMatrix) {
327 mSubSeriesResistor->mnaTearApplyMatrixStamp(tearMatrix);
328 mSubSeriesInductor->mnaTearApplyMatrixStamp(tearMatrix);
331void SP::Ph1::PiLine::mnaTearApplyVoltageStamp(Matrix &voltageVector) {
332 mSubSeriesInductor->mnaTearApplyVoltageStamp(voltageVector);
335void SP::Ph1::PiLine::mnaTearPostStep(Complex voltage, Complex current) {
336 mSubSeriesInductor->mnaTearPostStep(voltage - current * **mSeriesRes,
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)
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.
void mnaUpdateCurrent(const Matrix &leftVector) final
void mnaUpdateVoltage(const Matrix &leftVector) final
void createSubComponents() override
Constructs and registers MNA subcomponents; idempotent.
void setBaseVoltage(Real baseVoltage)
Set base voltage.
Real mBaseCapacitance
base capacitance [F]
void calculatePerUnitParameters(Real baseApparentPower, Real baseOmega)
Calculates component's parameters in specified per-unit system.
std::shared_ptr< Resistor > mSubSeriesResistor
Series Resistor submodel.
const Attribute< Matrix >::Ptr mActivePowerBranch
branch active powerflow [W], coef(0) has data from node 0, coef(1) from node 1.
Real mSeriesIndPerUnit
Inductance of the line in [pu].
const Attribute< Real >::Ptr mReactivePowerInjection
nodal reactive power injection
const Attribute< MatrixComp >::Ptr mCurrent
branch Current flow [A], coef(0) has data from node 0, coef(1) from node 1.
Real mBaseAdmittance
base admittance [S]
Real mBaseInductance
base inductance [H]
Real mParallelCapPerUnit
Capacitance of the line in [pu].
std::shared_ptr< Resistor > mSubParallelResistor1
Parallel resistor submodel at Terminal 1.
const Attribute< Matrix >::Ptr mReactivePowerBranch
branch reactive powerflow [Var], coef(0) has data from node 0, coef(1) from node 1.
void mnaParentAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector) override
add MNA post-step dependencies
void updateBranchFlow(VectorComp ¤t, VectorComp &powerflow)
updates branch current and power flow, input pu value, update with real value
void mnaParentPostStep(Real time, Int timeStepCount, Attribute< Matrix >::Ptr &leftVector) override
MNA post-step operations.
MatrixComp Y_element()
get admittance matrix
Real mSeriesResPerUnit
resistance in [pu]
std::shared_ptr< Resistor > mSubParallelResistor0
Parallel Resistor submodel at Terminal 0.
void initializeParentFromNodesAndTerminals(Real frequency) override
Derives values from power flow data and pushes them to subcomponents.
void pfApplyAdmittanceMatrixStamp(SparseMatrixCompRow &Y) override
Stamps admittance matrix.
void mnaCompUpdateCurrent(const Matrix &leftVector) override
Updates internal current variable of the component.
std::shared_ptr< Capacitor > mSubParallelCapacitor1
Parallel capacitor submodel at Terminal 1.
Real getBaseVoltage() const
Get base voltage.
PiLine(String uid, String name, Logger::Level logLevel=Logger::Level::off)
Defines UID, name and logging level.
SimPowerComp< Complex >::Ptr clone(String copySuffix) override
DEPRECATED: Delete method.
std::shared_ptr< Inductor > mSubSeriesInductor
Series Inductance submodel.
const Attribute< Real >::Ptr mActivePowerInjection
nodal active power injection
Real mParallelCondPerUnit
Conductance of the line in [pu].
Real mBaseApparentPower
base apparent power [VA]
Real mBaseImpedance
base impedance [Ohm]
void mnaCompUpdateVoltage(const Matrix &leftVector) override
Updates internal voltage variable of the component.
Real mBaseOmega
base omega [1/s]
void storeNodalInjection(Complex powerInjection)
stores nodal injection power in this line object
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.