9#include <dpsim-models/SP/SP_Ph1_PiLine.h>
22 SPDLOG_LOGGER_INFO(
mSLog,
"Create {} {}", this->
type(), name);
25 setVirtualNodeNumber(1);
34void SP::Ph1::PiLine::setParameters(Real resistance, Real inductance,
35 Real capacitance, Real conductance) {
37 **mSeriesRes = resistance;
38 **mSeriesInd = inductance;
39 SPDLOG_LOGGER_INFO(mSLog,
"Resistance={} [Ohm] Inductance={} [H]",
40 **mSeriesRes, **mSeriesInd);
42 if (capacitance > 0) {
43 **mParallelCap = capacitance;
45 **mParallelCap = 1e-12;
47 mSLog,
"Zero value for Capacitance, setting default value of C={} [F]",
50 if (conductance > 0) {
51 **mParallelCond = conductance;
53 if (mBehaviour == Behaviour::Initialization)
59 **mParallelCond = (conductance > 0) ? conductance : 1e-6;
61 mSLog,
"Zero value for Conductance, setting default value of G={} [S]",
64 SPDLOG_LOGGER_INFO(mSLog,
"Capacitance={} [F] Conductance={} [S]",
65 **mParallelCap, **mParallelCond);
67 mParametersSet =
true;
72 auto copy = PiLine::make(name,
mLogLevel);
82 mBaseVoltage = baseVoltage;
87 SPDLOG_LOGGER_INFO(
mSLog,
"#### Calculate Per Unit Parameters for {}",
91 SPDLOG_LOGGER_INFO(
mSLog,
"Base Power={} [VA] Base Omega={} [1/s]",
92 baseApparentPower, baseOmega);
101 SPDLOG_LOGGER_INFO(
mSLog,
"Base Voltage={} [V] Base Impedance={} [Ohm]",
109 SPDLOG_LOGGER_INFO(
mSLog,
"Resistance={} [pu] Reactance={} [pu]",
111 SPDLOG_LOGGER_INFO(
mSLog,
"Susceptance={} [pu] Conductance={} [pu]",
117 int bus1 = this->matrixNodeIndex(0);
118 int bus2 = this->matrixNodeIndex(1);
127 mY_element = MatrixComp(2, 2);
128 mY_element(0, 0) = y + ys;
129 mY_element(0, 1) = -y;
130 mY_element(1, 0) = -y;
131 mY_element(1, 1) = y + ys;
134 for (
int i = 0; i < 2; i++)
135 for (
int j = 0; j < 2; j++)
136 if (std::isinf(mY_element.coeff(i, j).real()) ||
137 std::isinf(mY_element.coeff(i, j).imag())) {
138 std::cout << mY_element << std::endl;
139 std::stringstream ss;
140 ss <<
"Line>>" << this->name()
141 <<
": infinite or nan values in the element Y at: " << i <<
"," << j;
142 throw std::invalid_argument(ss.str());
143 std::cout <<
"Line>>" << this->name()
144 <<
": infinite or nan values in the element Y at: " << i
145 <<
"," << j << std::endl;
149 Y.coeffRef(bus1, bus1) += mY_element.coeff(0, 0);
150 Y.coeffRef(bus1, bus2) += mY_element.coeff(0, 1);
151 Y.coeffRef(bus2, bus2) += mY_element.coeff(1, 1);
152 Y.coeffRef(bus2, bus1) += mY_element.coeff(1, 0);
154 SPDLOG_LOGGER_INFO(
mSLog,
"#### PF Y matrix stamping #### ");
155 SPDLOG_LOGGER_INFO(
mSLog,
"{}", mY_element);
160 VectorComp &powerflow) {
180 Real omega = 2. * PI * frequency;
182 (**mIntfVoltage)(0, 0) = initialSingleVoltage(1) - initialSingleVoltage(0);
183 (**mIntfCurrent)(0, 0) = (**
mIntfVoltage)(0, 0) / impedance;
186 mVirtualNodes[0]->setInitialVoltage(initialSingleVoltage(0) +
197 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
false);
206 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
true);
211 std::make_shared<SP::Ph1::Resistor>(**
mName +
"_con0",
mLogLevel);
214 SimNode::List{SimNode::GND,
mTerminals[0]->node()});
218 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
false);
221 std::make_shared<SP::Ph1::Resistor>(**
mName +
"_con1",
mLogLevel);
224 SimNode::List{SimNode::GND,
mTerminals[1]->node()});
228 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
false);
232 mSubParallelCapacitor0 =
233 std::make_shared<SP::Ph1::Capacitor>(**
mName +
"_cap0",
mLogLevel);
234 mSubParallelCapacitor0->setParameters(**
mParallelCap / 2.);
235 mSubParallelCapacitor0->connect(
236 SimNode::List{SimNode::GND,
mTerminals[0]->node()});
238 mSubParallelCapacitor0->initializeFromNodesAndTerminals(frequency);
240 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
true);
243 std::make_shared<SP::Ph1::Capacitor>(**
mName +
"_cap1",
mLogLevel);
246 SimNode::List{SimNode::GND,
mTerminals[1]->node()});
250 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
true);
255 "\n--- Initialization from powerflow ---"
256 "\nVoltage across: {:s}"
258 "\nTerminal 0 voltage: {:s}"
259 "\nTerminal 1 voltage: {:s}"
260 "\nVirtual Node 1 voltage: {:s}"
261 "\n--- Initialization from powerflow finished ---",
264 Logger::phasorToString(initialSingleVoltage(0)),
265 Logger::phasorToString(initialSingleVoltage(1)),
266 Logger::phasorToString(
mVirtualNodes[0]->initialSingleVoltage()));
270 AttributeBase::List &prevStepDependencies,
271 AttributeBase::List &attributeDependencies,
272 AttributeBase::List &modifiedAttributes,
273 Attribute<Matrix>::Ptr &leftVector) {
274 attributeDependencies.push_back(leftVector);
280 Attribute<Matrix>::Ptr &leftVector) {
286 (**mIntfVoltage)(0, 0) = 0;
287 if (terminalNotGrounded(1))
288 (**mIntfVoltage)(0, 0) =
289 Math::complexFromVectorElement(leftVector, matrixNodeIndex(1));
290 if (terminalNotGrounded(0))
291 (**mIntfVoltage)(0, 0) =
293 Math::complexFromVectorElement(leftVector, matrixNodeIndex(0));
300MNAInterface::List SP::Ph1::PiLine::mnaTearGroundComponents() {
301 MNAInterface::List gndComponents;
303 gndComponents.push_back(mSubParallelResistor0);
304 gndComponents.push_back(mSubParallelResistor1);
306 if (**mParallelCap >= 0) {
307 gndComponents.push_back(mSubParallelCapacitor0);
308 gndComponents.push_back(mSubParallelCapacitor1);
311 return gndComponents;
314void SP::Ph1::PiLine::mnaTearInitialize(Real omega, Real timeStep) {
315 mSubSeriesResistor->mnaTearSetIdx(mTearIdx);
316 mSubSeriesResistor->mnaTearInitialize(omega, timeStep);
317 mSubSeriesInductor->mnaTearSetIdx(mTearIdx);
318 mSubSeriesInductor->mnaTearInitialize(omega, timeStep);
321void SP::Ph1::PiLine::mnaTearApplyMatrixStamp(SparseMatrixRow &tearMatrix) {
322 mSubSeriesResistor->mnaTearApplyMatrixStamp(tearMatrix);
323 mSubSeriesInductor->mnaTearApplyMatrixStamp(tearMatrix);
326void SP::Ph1::PiLine::mnaTearApplyVoltageStamp(Matrix &voltageVector) {
327 mSubSeriesInductor->mnaTearApplyVoltageStamp(voltageVector);
330void SP::Ph1::PiLine::mnaTearPostStep(Complex voltage, Complex current) {
331 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 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 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 initializeFromNodesAndTerminals(Real frequency) override
Initializes component from power flow data.
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.