DPsim
Loading...
Searching...
No Matches
EMT_Ph3_HalfDecouplingLine.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 Institute for Automation of Complex Power Systems, EONERC, RWTH Aachen University
2// SPDX-License-Identifier: MPL-2.0
3
7
8using namespace CPS;
9
11 Logger::Level logLevel)
12 : CompositePowerComp<Real>(uid, name, true, true, logLevel),
14 mAttributes->create<Matrix>("i_src_ctrl", Matrix::Zero(3, 1))),
15 mSrcRes(mAttributes->create<Matrix>("src_res", Matrix::Zero(3, 3))),
16 mReceivingVolt(mAttributes->createDynamic<Matrix>("receiving_volt")),
17 mReceivingCur(mAttributes->createDynamic<Matrix>("receiving_cur")),
19 mAttributes->create<Matrix>("sending_volt", Matrix::Zero(3, 1))),
21 mAttributes->create<Matrix>("sending_cur", Matrix::Zero(3, 1))) {
22
26 **mIntfVoltage = Matrix::Zero(3, 1);
27 **mIntfCurrent = Matrix::Zero(3, 1);
28}
29
31 Bool useSubcomponents,
32 Logger::Level logLevel)
33 : HalfDecouplingLine(uid, name, logLevel) {
34 mUseSubcomponents = useSubcomponents;
35}
36
38 Matrix inductance,
39 Matrix capacitance) {
40
41 mResistance = resistance;
42 mInductance = inductance;
43 mCapacitance = capacitance;
44
45 mSurgeImpedance = (inductance * capacitance.inverse()).array().sqrt();
46 mDelay = (inductance.array() * capacitance.array()).sqrt().maxCoeff();
47
49 mSrcResInverse = (**mSrcRes).inverse();
50 mSrcResSquaredInverse = ((**mSrcRes) * (**mSrcRes)).inverse();
51
52 SPDLOG_LOGGER_INFO(mSLog, "surge impedance: {}", mSurgeImpedance);
53 SPDLOG_LOGGER_INFO(mSLog, "delay: {}", mDelay);
54
55 mParametersSet = true;
56}
57
59 Attribute<Matrix>::Ptr receivingVolt, Attribute<Matrix>::Ptr receivingCur) {
60 mReceivingVolt->setReference(receivingVolt);
61 mReceivingCur->setReference(receivingCur);
62}
63
84
93
95 Matrix &rightVector) {
97 return;
98 for (UInt phase = 0; phase < 3; ++phase)
99 Math::setVectorElement(rightVector, matrixNodeIndex(0, phase),
100 (**mSrcCtrledCurrent)(phase, 0));
101}
102
104 Real frequency) {
105
106 **mIntfVoltage = initialVoltage(0).real();
107 **mIntfCurrent = Matrix::Zero(3, 1);
108
109 **mSendingVolt = -(**mIntfVoltage);
110 **mSendingCur = Matrix::Zero(3, 1);
111}
112
114 Real omega, Real timeStep, Attribute<Matrix>::Ptr leftVector) {
115 if (mDelay < timeStep)
116 throw SystemError("Timestep too large for decoupling");
117
118 mBufSize = static_cast<UInt>(ceil(mDelay / timeStep));
119 mAlpha = 1 - (mBufSize - mDelay / timeStep);
120 SPDLOG_LOGGER_INFO(mSLog, "bufsize {} alpha {}", mBufSize, mAlpha);
121
122 MatrixComp voltNear = -initialVoltage(0);
123 MatrixComp voltFar = (**mReceivingVolt).cast<Complex>();
124
125 MatrixComp seriesAdmittance =
126 (mResistance + Complex(0, omega) * mInductance).inverse();
127 MatrixComp initAdmittance =
128 seriesAdmittance + Complex(0, omega) * mCapacitance / 2;
129 MatrixComp curNear = initAdmittance * voltNear - seriesAdmittance * voltFar;
130
131 SPDLOG_LOGGER_INFO(mSLog, "initial voltage: v_k {}", voltNear);
132 SPDLOG_LOGGER_INFO(mSLog, "initial current: i_k {}", curNear);
133
134 mVoltBuf = voltNear.real().transpose().replicate(mBufSize, 1);
135 mCurBuf = curNear.real().transpose().replicate(mBufSize, 1);
136
137 **mSendingVolt = voltNear.real();
138 **mSendingCur = curNear.real();
139}
140
143 const UInt nextIdx = (mBufIdx + 1 == mBufSize) ? 0 : mBufIdx + 1;
145 const Real nextWeight = 1 - mAlpha;
146 for (UInt phase = 0; phase < 3; ++phase)
147 result(phase) =
148 mAlpha * data(mBufIdx, phase) + nextWeight * data(nextIdx, phase);
149 return result;
150}
151
152void EMT::Ph3::HalfDecouplingLine::step(Real time, Int timeStepCount) {
153 const Matrix &voltNear = **mSendingVolt;
154 const Matrix &curNear = **mSendingCur;
155 const Matrix &voltFar = **mReceivingVolt;
156 const Matrix &curFar = **mReceivingCur;
157
158 if (timeStepCount == 0) {
159 **mSrcCtrledCurrent = curNear - mSrcResInverse * voltNear;
160 } else {
163 (voltFar + (mSurgeImpedance - mResistance / 4) * curFar) -
165 (voltNear + (mSurgeImpedance - mResistance / 4) * curNear);
166 }
167
169 mSubCtrledCurrentSource->mCurrentRef->set(**mSrcCtrledCurrent);
170}
171
173 if (mUseSubcomponents) {
174 mVoltBuf.row(mBufIdx) = -mSubRes->intfVoltage().transpose();
175 mCurBuf.row(mBufIdx) =
176 -mSubRes->intfCurrent().transpose() + (**mSrcCtrledCurrent).transpose();
177 } else {
178 mVoltBuf.row(mBufIdx) = -(**mIntfVoltage).transpose();
179 mCurBuf.row(mBufIdx) = (**mIntfCurrent).transpose();
180 }
181
182 mBufIdx++;
183 if (mBufIdx == mBufSize)
184 mBufIdx = 0;
185
188}
189
191 Int timeStepCount) {
192 step(time, timeStepCount);
194 mSubCtrledCurrentSource->mnaPreStep(time, timeStepCount);
196}
197
199 Real time, Int timeStepCount, Attribute<Matrix>::Ptr &leftVector) {
200 mnaCompUpdateVoltage(**leftVector);
201 mnaCompUpdateCurrent(**leftVector);
202 postStep();
203}
204
206 const Matrix &leftVector) {
207 (**mIntfVoltage)(0, 0) =
209 (**mIntfVoltage)(1, 0) =
211 (**mIntfVoltage)(2, 0) =
213}
214
216 const Matrix &leftVector) {
217 if (mUseSubcomponents) {
218 **mIntfCurrent = -mSubRes->intfCurrent() + **mSrcCtrledCurrent;
219 return;
220 }
222}
223
225 AttributeBase::List &prevStepDependencies,
226 AttributeBase::List &attributeDependencies,
227 AttributeBase::List &modifiedAttributes) {
228 prevStepDependencies.push_back(mIntfCurrent);
229 prevStepDependencies.push_back(mIntfVoltage);
230 prevStepDependencies.push_back(mReceivingVolt);
231 prevStepDependencies.push_back(mReceivingCur);
232 modifiedAttributes.push_back(mRightVector);
233}
234
236 AttributeBase::List &prevStepDependencies,
237 AttributeBase::List &attributeDependencies,
238 AttributeBase::List &modifiedAttributes,
239 Attribute<Matrix>::Ptr &leftVector) {
240 attributeDependencies.push_back(leftVector);
241 modifiedAttributes.push_back(mIntfVoltage);
242 modifiedAttributes.push_back(mIntfCurrent);
243 modifiedAttributes.push_back(mSendingVolt);
244 modifiedAttributes.push_back(mSendingCur);
245}
std::vector< Ptr > List
Definition Attribute.h:123
AttributePointer< Attribute< T > > Ptr
Definition Attribute.h:249
void addMNASubComponent(typename SimPowerComp< Real >::Ptr subc, MNA_SUBCOMP_TASK_ORDER preStepOrder, MNA_SUBCOMP_TASK_ORDER postStepOrder, Bool contributeToRightVector)
void mnaCompApplyRightSideVectorStamp(Matrix &rightVector) override
CompositePowerComp(String uid, String name, Bool hasPreStep, Bool hasPostStep, Logger::Level logLevel)
const Attribute< Matrix >::Ptr mSrcCtrledCurrent
History current fed into the controlled current source.
Real mDelay
Travel time of the whole line.
std::shared_ptr< EMT::Ph3::ControlledCurrentSource > mSubCtrledCurrentSource
Controlled current source carrying the history term.
Matrix mSurgeImpedance
Surge impedance, sqrt(L/C)
void mnaParentApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override
const Attribute< Matrix >::Ptr mReceivingCur
Far-end current one travel time ago, supplied by the other half.
void mnaParentAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector) override
Add MNA post step dependencies.
void mnaCompUpdateCurrent(const Matrix &leftVector) override
Updates internal current variable of the component.
void createSubComponents() override
Creates the terminating resistor and the history current source.
void mnaParentInitialize(Real omega, Real timeStep, Attribute< Matrix >::Ptr leftVector) override
Sizes the ring buffers and seeds them from the steady state.
void mnaParentPreStep(Real time, Int timeStepCount) override
MNA pre step operations.
const Attribute< Matrix >::Ptr mReceivingVolt
Far-end voltage one travel time ago, supplied by the other half.
void mnaParentPostStep(Real time, Int timeStepCount, Attribute< Matrix >::Ptr &leftVector) override
MNA post step operations.
MatrixFixedSize< 3, 1 > interpolate(const Matrix &data) const
Reads a ring buffer one travel time back.
const Attribute< Matrix >::Ptr mSendingVolt
This end's voltage one travel time ago, for the other half to read.
void setParameters(Matrix resistance, Matrix inductance, Matrix capacitance)
Line data. Give the parameters of the whole line, not of this half.
std::shared_ptr< EMT::Ph3::Resistor > mSubRes
Terminating impedance calculated from line parameters.
void mnaCompUpdateVoltage(const Matrix &leftVector) override
Updates internal voltage variable of the component.
HalfDecouplingLine(String name, Logger::Level logLevel=Logger::Level::off)
Defines name and logging level.
void initializeParentFromNodesAndTerminals(Real frequency) override
Seeds the interface quantities and the sending attributes.
const Attribute< Matrix >::Ptr mSrcRes
Terminating resistance.
void mnaParentApplyRightSideVectorStamp(Matrix &rightVector) override
Matrix mVoltBuf
Ring buffers for the values of previous timesteps, one row per stored step.
const Attribute< Matrix >::Ptr mSendingCur
This end's current one travel time ago, for the other half to read.
Matrix mSrcResInverse
Constant inverses used by the half-line history source update.
void step(Real time, Int timeStepCount)
Updates the history current from the exchanged quantities.
void mnaParentAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes) override
Add MNA pre step dependencies.
void setCouplingSource(Attribute< Matrix >::Ptr receivingVolt, Attribute< Matrix >::Ptr receivingCur)
void postStep()
Records this end's quantities and publishes them one travel time delayed.
const Attribute< String >::Ptr mName
Human readable name.
String uid()
Returns unique id.
AttributeList::Ptr mAttributes
Attribute List.
spdlog::level::level_enum Level
Definition Logger.h:33
Attribute< Matrix >::Ptr mRightVector
static void stampConductanceMatrix(const Matrix &conductanceMat, SparseMatrixRow &mat, UInt node1Index, UInt node2Index, Bool isTerminal1NotGrounded, Bool isTerminal2NotGrounded, const Logger::Log &mSLog)
static Real realFromVectorElement(const Matrix &mat, Matrix::Index row)
static void setVectorElement(Matrix &mat, Matrix::Index row, Complex value, Int maxFreq=1, Int freqIdx=0, Matrix::Index colOffset=0)
static Ptr GND
Definition SimNode.h:37
UInt matrixNodeIndex(UInt nodeIndex)
const Attribute< MatrixVar< Real > >::Ptr mIntfCurrent
SimTerminal< Real >::List mTerminals
void setVirtualNodeNumber(UInt num)
const Attribute< MatrixVar< Real > >::Ptr mIntfVoltage
MatrixComp initialVoltage(UInt index)
Bool terminalNotGrounded(UInt index)
void setTerminalNumber(UInt num)
Logger::Level mLogLevel
Component logger control for internal variables.
bool mParametersSet
Flag indicating that parameters are set via setParameters() function.
Logger::Log mSLog
Component logger.
static std::shared_ptr< Resistor > make(Args &&...args)
Definition PtrFactory.h:19
struct dps_magma_data data
Eigen::Matrix< Real, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor > Matrix
Dense matrix for real numbers.
Definition Definitions.h:79
std::string String
Definition Definitions.h:63
Eigen::Matrix< Real, rows, cols, Eigen::ColMajor > MatrixFixedSize
Dense matrix for real numbers with fixed dimension.
Definition Definitions.h:99
double Real
Definition Definitions.h:60
int Int
Definition Definitions.h:59
std::complex< Real > Complex
Definition Definitions.h:61
Eigen::Matrix< Complex, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor > MatrixComp
Dense matrix for complex numbers.
Definition Definitions.h:82
bool Bool
Definition Definitions.h:62
unsigned int UInt
Definition Definitions.h:58
Eigen::SparseMatrix< Real, Eigen::RowMajor > SparseMatrixRow
Sparse matrix for real numbers (row major).
Definition Definitions.h:72