9 #include "dpsim-models/SP/SP_Ph1_RXLine.h"
14 Real resistance, Real inductance,
15 Logger::Level logLevel)
16 : Base::Ph1::
PiLine(mAttributes),
18 mBaseVoltage(mAttributes->create<Real>(
"base_Voltage", baseVoltage)),
19 mInductance(mAttributes->create<Real>(
"L_series")),
20 mActivePowerInjection(mAttributes->create<Real>(
"p_inj")),
21 mReactivePowerInjection(mAttributes->create<Real>(
"q_inj")),
22 mCurrent(mAttributes->create<MatrixComp>(
"current_vector")),
23 mActivePowerBranch(mAttributes->create<Matrix>(
"p_branch_vector")),
24 mReactivePowerBranch(mAttributes->create<Matrix>(
"q_branch_vector")) {
40 : Base::Ph1::
PiLine(mAttributes),
42 mBaseVoltage(mAttributes->create<Real>(
"base_Voltage")),
43 mInductance(mAttributes->create<Real>(
"L_series")),
44 mActivePowerInjection(mAttributes->create<Real>(
"p_inj")),
45 mReactivePowerInjection(mAttributes->create<Real>(
"q_inj")),
46 mCurrent(mAttributes->create<MatrixComp>(
"current_vector")),
47 mActivePowerBranch(mAttributes->create<Matrix>(
"p_branch_vector")),
48 mReactivePowerBranch(mAttributes->create<Matrix>(
"q_branch_vector")) {
50 setVirtualNodeNumber(1);
57 mBaseApparentPower = baseApparentPower;
58 mBaseOmega = baseOmega;
59 mBaseImpedance = (**mBaseVoltage * **mBaseVoltage) / mBaseApparentPower;
60 mBaseAdmittance = 1.0 / mBaseImpedance;
61 mBaseInductance = mBaseImpedance / mBaseOmega;
63 mBaseCurrent = baseApparentPower / (**mBaseVoltage * sqrt(3));
69 mSeriesResPerUnit = **mSeriesRes / mBaseImpedance;
70 mSeriesIndPerUnit = **mInductance / mBaseInductance;
79 updateMatrixNodeIndices();
80 int bus1 = this->matrixNodeIndex(0);
81 int bus2 = this->matrixNodeIndex(1);
96 Complex(1, 0) / Complex(mSeriesResPerUnit, 1. * mSeriesIndPerUnit);
99 mY_element = MatrixComp(2, 2);
100 mY_element(0, 0) = y;
101 mY_element(0, 1) = -y;
102 mY_element(1, 0) = -y;
103 mY_element(1, 1) = y;
106 for (
int i = 0; i < 2; i++)
107 for (
int j = 0; j < 2; j++)
108 if (std::isinf(mY_element.coeff(i, j).real()) ||
109 std::isinf(mY_element.coeff(i, j).imag())) {
110 std::cout << mY_element << std::endl;
111 std::stringstream ss;
112 ss <<
"Line>>" << this->name()
113 <<
": infinite or nan values in the element Y at: " << i <<
"," << j;
114 throw std::invalid_argument(ss.str());
115 std::cout <<
"Line>>" << this->name()
116 <<
": infinite or nan values in the element Y at: " << i
117 <<
"," << j << std::endl;
121 Y.coeffRef(bus1, bus1) += mY_element.coeff(0, 0);
122 Y.coeffRef(bus1, bus2) += mY_element.coeff(0, 1);
123 Y.coeffRef(bus2, bus1) += mY_element.coeff(1, 0);
124 Y.coeffRef(bus2, bus2) += mY_element.coeff(1, 1);
131 VectorComp &powerflow) {
132 **mCurrent = current * mBaseCurrent;
133 **mActivePowerBranch = powerflow.real() * mBaseApparentPower;
134 **mReactivePowerBranch = powerflow.imag() * mBaseApparentPower;
138 **mActivePowerInjection = std::real(powerInjection) * mBaseApparentPower;
139 **mReactivePowerInjection = std::imag(powerInjection) * mBaseApparentPower;
146 auto copy = RXLine::make(name, mLogLevel);
147 copy->setParameters(**mSeriesRes, **mSeriesInd);
153 (**mIntfVoltage)(0, 0) = initialSingleVoltage(1) - initialSingleVoltage(0);
154 Complex impedance = {**mSeriesRes, **mSeriesInd * 2. * PI * frequency};
155 (**mIntfCurrent)(0, 0) = (**mIntfVoltage)(0, 0) / impedance;
156 mVirtualNodes[0]->setInitialVoltage(initialSingleVoltage(0) +
157 (**mIntfCurrent)(0, 0) * **mSeriesRes);
161 std::make_shared<SP::Ph1::Resistor>(**mName +
"_res", mLogLevel);
162 mSubResistor->setParameters(**mSeriesRes);
163 mSubResistor->connect({mTerminals[0]->node(), mVirtualNodes[0]});
164 mSubResistor->initializeFromNodesAndTerminals(frequency);
165 addMNASubComponent(mSubResistor, MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
166 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
true);
169 std::make_shared<SP::Ph1::Inductor>(**mName +
"_ind", mLogLevel);
170 mSubInductor->setParameters(**mSeriesInd);
171 mSubInductor->connect({mVirtualNodes[0], mTerminals[1]->node()});
172 mSubInductor->initializeFromNodesAndTerminals(frequency);
173 addMNASubComponent(mSubInductor, MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
174 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
true);
177 std::make_shared<SP::Ph1::Resistor>(**mName +
"_snubber_res", mLogLevel);
178 mInitialResistor->setParameters(1e6);
179 mInitialResistor->connect({SimNode::GND, mTerminals[1]->node()});
180 mInitialResistor->initializeFromNodesAndTerminals(frequency);
181 addMNASubComponent(mInitialResistor,
182 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
183 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
true);
185 SPDLOG_LOGGER_INFO(mSLog,
186 "\n--- Initialization from powerflow ---"
187 "\nVoltage across: {:s}"
189 "\nTerminal 0 voltage: {:s}"
190 "\nTerminal 1 voltage: {:s}"
191 "\n--- Initialization from powerflow finished ---",
192 Logger::phasorToString((**mIntfVoltage)(0, 0)),
193 Logger::phasorToString((**mIntfCurrent)(0, 0)),
194 Logger::phasorToString(initialSingleVoltage(0)),
195 Logger::phasorToString(initialSingleVoltage(1)));
198 void SP::Ph1::RXLine::mnaParentAddPreStepDependencies(
199 AttributeBase::List &prevStepDependencies,
200 AttributeBase::List &attributeDependencies,
201 AttributeBase::List &modifiedAttributes) {
202 modifiedAttributes.push_back(mRightVector);
205 void SP::Ph1::RXLine::mnaParentAddPostStepDependencies(
206 AttributeBase::List &prevStepDependencies,
207 AttributeBase::List &attributeDependencies,
208 AttributeBase::List &modifiedAttributes,
210 attributeDependencies.push_back(leftVector);
211 modifiedAttributes.push_back(mIntfCurrent);
212 modifiedAttributes.push_back(mIntfVoltage);
215 void SP::Ph1::RXLine::mnaParentPreStep(Real time, Int timeStepCount) {
216 mnaCompApplyRightSideVectorStamp(**mRightVector);
219 void SP::Ph1::RXLine::mnaParentPostStep(Real time, Int timeStepCount,
221 mnaCompUpdateVoltage(**leftVector);
222 mnaCompUpdateCurrent(**leftVector);
225 void SP::Ph1::RXLine::mnaCompUpdateVoltage(
const Matrix &leftVector) {
226 (**mIntfVoltage)(0, 0) = 0;
227 if (terminalNotGrounded(1))
228 (**mIntfVoltage)(0, 0) =
229 Math::complexFromVectorElement(leftVector, matrixNodeIndex(1));
230 if (terminalNotGrounded(0))
231 (**mIntfVoltage)(0, 0) =
232 (**mIntfVoltage)(0, 0) -
233 Math::complexFromVectorElement(leftVector, matrixNodeIndex(0));
236 void SP::Ph1::RXLine::mnaCompUpdateCurrent(
const Matrix &leftVector) {
237 (**mIntfCurrent)(0, 0) = mSubInductor->intfCurrent()(0, 0);
const Attribute< Real >::Ptr mSeriesRes
Resistance along the line [ohms].
Base class for composite power components.
PI-line static phasor model.
void initializeFromNodesAndTerminals(Real frequency) override
Initializes component from power flow data.
const Attribute< Real >::Ptr mInductance
SimPowerComp< Complex >::Ptr clone(String name) override
DEPRECATED: Delete method.
void setPerUnitSystem(Real baseApparentPower, Real baseOmega)
Specify per-unit system by base voltage, base apparent power and omega (rms value for voltage expecte...
const Attribute< Matrix >::Ptr mActivePowerBranch
branch active powerflow [W], coef(0) has data from node 0, coef(1) from node 1.
void pfApplyAdmittanceMatrixStamp(SparseMatrixCompRow &Y) override
Stamps admittance matrix.
void updateBranchFlow(VectorComp ¤t, VectorComp &powerflow)
updates branch current and power flow, input pu value, update with real value
const Attribute< MatrixComp >::Ptr mCurrent
branch Current flow [A], coef(0) has data from node 0, coef(1) from node 1.
const Attribute< Matrix >::Ptr mReactivePowerBranch
branch reactive powerflow [Var], coef(0) has data from node 0, coef(1) from node 1.
RXLine(String uid, String name, Real baseVoltage, Real resistance, Real inductance, Logger::Level logLevel=Logger::Level::off)
Defines UID, name, base voltage, component parameters and logging level.
void storeNodalInjection(Complex powerInjection)
stores nodal injection power in this line object
MatrixComp Y_element()
get admittance matrix
Base class for all components that are transmitting power.
const Attribute< MatrixVar< Complex > >::Ptr mIntfCurrent
Current through component.
const Attribute< MatrixVar< Complex > >::Ptr mIntfVoltage
Voltage between terminals.