DPsim
Loading...
Searching...
No Matches
DP_Ph3_PiLine.cpp
Go to the documentation of this file.
1/* Author: Christoph Wirtz <christoph.wirtz@fgh-ma.de>
2 * SPDX-FileCopyrightText: 2025 FGH e.V.
3 * SPDX-License-Identifier: MPL-2.0
4 */
5
8
9using namespace CPS;
10
13
15 Logger::Level logLevel)
17 CompositePowerComp<Complex>(uid, name, true, true, logLevel),
18 mUseSubcomponents(useSubcomponents) {
22
23 SPDLOG_LOGGER_INFO(mSLog, "Create {} {}", this->type(), name);
24 **mIntfVoltage = MatrixComp::Zero(3, 1);
25 **mIntfCurrent = MatrixComp::Zero(3, 1);
26}
27
35
38 return;
40 return;
41 mSubCompCreated = true;
42
43 // By default there is always a small conductance to ground to
44 // avoid problems with floating nodes.
45 Matrix defaultParallelCond = Matrix::Zero(3, 3);
46 defaultParallelCond << 1e-6, 0, 0, 0, 1e-6, 0, 0, 0, 1e-6;
48 ((**mParallelCond)(0, 0) > 0) ? **mParallelCond : defaultParallelCond;
49
50 // Create series sub components
52 std::make_shared<DP::Ph3::Resistor>(**mName + "_res", mLogLevel);
53 mSubSeriesResistor->setParameters(**mSeriesRes);
54 mSubSeriesResistor->connect({mTerminals[0]->node(), mVirtualNodes[0]});
58
60 std::make_shared<DP::Ph3::Inductor>(**mName + "_ind", mLogLevel);
61 mSubSeriesInductor->setParameters(**mSeriesInd);
62 mSubSeriesInductor->connect({mVirtualNodes[0], mTerminals[1]->node()});
66
67 // Create parallel sub components
69 std::make_shared<DP::Ph3::Resistor>(**mName + "_con0", mLogLevel);
70 mSubParallelResistor0->setParameters(2. * (**mParallelCond).inverse());
71 mSubParallelResistor0->connect(
76
78 std::make_shared<DP::Ph3::Resistor>(**mName + "_con1", mLogLevel);
79 mSubParallelResistor1->setParameters(2. * (**mParallelCond).inverse());
80 mSubParallelResistor1->connect(
85
86 if ((**mParallelCap)(0, 0) > 0) {
88 std::make_shared<DP::Ph3::Capacitor>(**mName + "_cap0", mLogLevel);
89 mSubParallelCapacitor0->setParameters(**mParallelCap / 2.);
95
97 std::make_shared<DP::Ph3::Capacitor>(**mName + "_cap1", mLogLevel);
98 mSubParallelCapacitor1->setParameters(**mParallelCap / 2.);
104 }
105}
106
108 if (!mUseSubcomponents && (**mParallelCond)(0, 0) <= 0.) {
109 **mParallelCond = Matrix::Zero(3, 3);
110 (**mParallelCond).diagonal().setConstant(1e-6);
111 }
112 // Static calculation
113 Real omega = 2. * PI * frequency;
114 MatrixComp impedance = MatrixComp::Zero(3, 3);
115 impedance << Complex((**mSeriesRes)(0, 0), omega * (**mSeriesInd)(0, 0)),
116 Complex((**mSeriesRes)(0, 1), omega * (**mSeriesInd)(0, 1)),
117 Complex((**mSeriesRes)(0, 2), omega * (**mSeriesInd)(0, 2)),
118 Complex((**mSeriesRes)(1, 0), omega * (**mSeriesInd)(1, 0)),
119 Complex((**mSeriesRes)(1, 1), omega * (**mSeriesInd)(1, 1)),
120 Complex((**mSeriesRes)(1, 2), omega * (**mSeriesInd)(1, 2)),
121 Complex((**mSeriesRes)(2, 0), omega * (**mSeriesInd)(2, 0)),
122 Complex((**mSeriesRes)(2, 1), omega * (**mSeriesInd)(2, 1)),
123 Complex((**mSeriesRes)(2, 2), omega * (**mSeriesInd)(2, 2));
124 MatrixComp vInitABC = MatrixComp::Zero(3, 1);
125 vInitABC(0, 0) = RMS3PH_TO_PEAK1PH * initialSingleVoltage(1) -
127 vInitABC(1, 0) = vInitABC(0, 0) * SHIFT_TO_PHASE_B;
128 vInitABC(2, 0) = vInitABC(0, 0) * SHIFT_TO_PHASE_C;
129 MatrixComp iInit = impedance.inverse() * vInitABC;
130 **mIntfCurrent = iInit;
131 **mIntfVoltage = vInitABC;
132
133 // Initialization of virtual node
134 // Initial voltage of phase B,C is set after A
135 MatrixComp vInitTerm0 = MatrixComp::Zero(3, 1);
136 vInitTerm0(0, 0) = RMS3PH_TO_PEAK1PH * initialSingleVoltage(0);
137 vInitTerm0(1, 0) = vInitTerm0(0, 0) * SHIFT_TO_PHASE_B;
138 vInitTerm0(2, 0) = vInitTerm0(0, 0) * SHIFT_TO_PHASE_C;
139
141 mVirtualNodes[0]->setInitialVoltage(PEAK1PH_TO_RMS3PH *
142 (vInitTerm0 + **mSeriesRes * iInit));
143
144 SPDLOG_LOGGER_INFO(
145 mSLog,
146 "\n--- Initialization from powerflow ---"
147 "\nVoltage across: {:s}"
148 "\nCurrent: {:s}"
149 "\nTerminal 0 voltage: {:s}"
150 "\nTerminal 1 voltage: {:s}"
151 "\nVirtual Node 1 voltage: {:s}"
152 "\n--- Initialization from powerflow finished ---",
159 : Complex(0., 0.)));
160}
161
163 Attribute<Matrix>::Ptr leftVector) {
165 return;
167 const Real b = timeStep * omega / 2.;
168 const Matrix seriesA = timeStep / 2. * (**mSeriesInd).inverse();
169 const Matrix seriesG = seriesA / (1. + b * b);
170 mDirectInductorAdmittance = MatrixComp::Zero(3, 3);
171 mDirectInductorAdmittance.real() = seriesG;
172 mDirectInductorAdmittance.imag() = -b * seriesG;
174 Complex((1. - b * b) / (1. + b * b), -2. * b / (1. + b * b));
175 mDirectSeriesSystemInverse = MatrixComp::Identity(3, 3);
178 mDirectSeriesVoltage = MatrixComp::Zero(3, 1);
179 mDirectSeriesHistory = MatrixComp::Zero(3, 1);
180
181 const Matrix cap = **mParallelCap / 2.;
182 const Matrix capG = (timeStep / 2. * cap.inverse()).inverse();
183 const Real capB = timeStep * omega / 2.;
184 mDirectCapCond = MatrixComp::Zero(3, 3);
185 mDirectCapCond.real() = capG;
186 mDirectCapCond.imag() = capB * capG;
187 mDirectCapPrevVoltCoeff = MatrixComp::Zero(3, 3);
188 mDirectCapPrevVoltCoeff.real() = capG;
189 mDirectCapPrevVoltCoeff.imag() = -capB * capG;
190 mDirectCapCurrent0 = MatrixComp::Zero(3, 1);
191 mDirectCapCurrent1 = MatrixComp::Zero(3, 1);
192 mDirectCapVoltage0 = MatrixComp::Zero(3, 1);
193 mDirectCapVoltage1 = MatrixComp::Zero(3, 1);
194 mDirectCapHistory0 = MatrixComp::Zero(3, 1);
195 mDirectCapHistory1 = MatrixComp::Zero(3, 1);
196 const MatrixComp capAdmittance = Complex(0., omega) * cap.cast<Complex>();
203 mDirectCapCurrent0 = capAdmittance * mDirectCapVoltage0;
204 mDirectCapCurrent1 = capAdmittance * mDirectCapVoltage1;
206 (**mSeriesRes).cast<Complex>() * mDirectSeriesCurrent;
207}
208
210 SparseMatrixRow &systemMatrix) {
212 return;
213 const MatrixComp shuntG = 0.5 * (**mParallelCond).cast<Complex>();
214 const MatrixComp capY = mDirectCapCond;
215 MNAStampUtils::stampAdmittanceMatrix((**mSeriesRes).cast<Complex>().inverse(),
216 systemMatrix, matrixNodeIndex(0),
218 terminalNotGrounded(0), true, mSLog);
220 mDirectSeriesCond, systemMatrix, virtualNode(0)->matrixNodeIndex(),
222 MNAStampUtils::stampAdmittanceMatrix(shuntG + capY, systemMatrix,
223 matrixNodeIndex(0), 0,
224 terminalNotGrounded(0), false, mSLog);
225 MNAStampUtils::stampAdmittanceMatrix(shuntG + capY, systemMatrix,
226 matrixNodeIndex(1), 0,
227 terminalNotGrounded(1), false, mSLog);
228}
229
252
254 AttributeBase::List &prevStepDependencies,
255 AttributeBase::List &attributeDependencies,
256 AttributeBase::List &modifiedAttributes) {
257 // add pre-step dependencies of component itself
258 prevStepDependencies.push_back(mIntfCurrent);
259 prevStepDependencies.push_back(mIntfVoltage);
260 modifiedAttributes.push_back(mRightVector);
261}
262
263void DP::Ph3::PiLine::mnaParentPreStep(Real time, Int timeStepCount) {
264 // pre-step of component itself
266}
267
269 AttributeBase::List &prevStepDependencies,
270 AttributeBase::List &attributeDependencies,
271 AttributeBase::List &modifiedAttributes,
272 Attribute<Matrix>::Ptr &leftVector) {
273 // add post-step dependencies of component itself
274 attributeDependencies.push_back(leftVector);
275 modifiedAttributes.push_back(mIntfVoltage);
276 modifiedAttributes.push_back(mIntfCurrent);
277}
278
280 Attribute<Matrix>::Ptr &leftVector) {
281 // post-step of component itself
282 this->mnaUpdateVoltage(**leftVector);
283 this->mnaUpdateCurrent(**leftVector);
284}
285
287 // v1 - v0
288 (**mIntfVoltage).setZero();
289 if (terminalNotGrounded(1)) {
290 (**mIntfVoltage)(0, 0) =
292 (**mIntfVoltage)(1, 0) =
294 (**mIntfVoltage)(2, 0) =
296 }
297 if (terminalNotGrounded(0)) {
298 (**mIntfVoltage)(0, 0) =
299 (**mIntfVoltage)(0, 0) -
301 (**mIntfVoltage)(1, 0) =
302 (**mIntfVoltage)(1, 0) -
304 (**mIntfVoltage)(2, 0) =
305 (**mIntfVoltage)(2, 0) -
307 }
308}
309
311 if (mUseSubcomponents) {
312 **mIntfCurrent = mSubSeriesInductor->intfCurrent();
313 return;
314 }
315 for (UInt phase = 0; phase < 3; ++phase) {
316 const Complex internalVoltage = Math::complexFromVectorElement(
317 leftVector, virtualNode(0)->matrixNodeIndex() + phase);
318 const Complex terminalVoltage =
320 leftVector, matrixNodeIndex(1, phase))
321 : Complex(0., 0.);
322 mDirectSeriesVoltage(phase, 0) = terminalVoltage - internalVoltage;
323 }
327 for (UInt phase = 0; phase < 3; ++phase) {
328 mDirectCapVoltage0(phase, 0) =
330 leftVector, matrixNodeIndex(0, phase))
331 : Complex(0., 0.);
332 mDirectCapVoltage1(phase, 0) =
334 leftVector, matrixNodeIndex(1, phase))
335 : Complex(0., 0.);
336 }
339}
340
341// #### Tear Methods ####
343 MNAInterface::List gndComponents;
344
346 return gndComponents;
347
348 gndComponents.push_back(mSubParallelResistor0);
349 gndComponents.push_back(mSubParallelResistor1);
350
351 if ((**mParallelCap)(0, 0) > 0) {
352 gndComponents.push_back(mSubParallelCapacitor0);
353 gndComponents.push_back(mSubParallelCapacitor1);
354 }
355
356 return gndComponents;
357}
358
361 return;
362 mSubSeriesResistor->mnaTearSetIdx(mTearIdx);
363 mSubSeriesResistor->mnaTearInitialize(omega, timeStep);
364 mSubSeriesInductor->mnaTearSetIdx(mTearIdx);
365 mSubSeriesInductor->mnaTearInitialize(omega, timeStep);
366}
367
370 return;
371 mSubSeriesResistor->mnaTearApplyMatrixStamp(tearMatrix);
372 mSubSeriesInductor->mnaTearApplyMatrixStamp(tearMatrix);
373}
374
377 return;
378 mSubSeriesInductor->mnaTearApplyVoltageStamp(voltageVector);
379}
380
382 if (!mUseSubcomponents) {
383 mDirectSeriesVoltage = voltage - (**mSeriesRes).cast<Complex>() * current;
384 mDirectSeriesCurrent = current;
385 **mIntfCurrent = current;
386 return;
387 }
388 mSubSeriesInductor->mnaTearPostStep(voltage - (**mSeriesRes * current),
389 current);
390 (**mIntfCurrent) = mSubSeriesInductor->intfCurrent();
391}
std::vector< Ptr > List
Definition Attribute.h:123
AttributePointer< Attribute< T > > Ptr
Definition Attribute.h:249
const Attribute< Matrix >::Ptr mParallelCond
Conductance in parallel to the line [S].
const Attribute< Matrix >::Ptr mSeriesRes
Resistance along the line [ohms].
const Attribute< Matrix >::Ptr mSeriesInd
Inductance along the line [H].
const Attribute< Matrix >::Ptr mParallelCap
Capacitance in parallel to the line [F].
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)
MatrixComp mDirectCapCond
MatrixComp mDirectSeriesCond
void mnaParentPreStep(Real time, Int timeStepCount) override
MNA pre and post step operations.
std::shared_ptr< Resistor > mSubSeriesResistor
Series Resistor submodel.
void mnaTearApplyMatrixStamp(SparseMatrixRow &tearMatrix) override
void mnaCompUpdateCurrent(const Matrix &leftVector) override
Updates internal current variable of the component.
PiLine(String uid, String name, Logger::Level logLevel=Logger::Level::off)
Defines UID, name and logging level.
MatrixComp mDirectSeriesVoltage
void mnaTearInitialize(Real omega, Real timeStep) override
void mnaParentAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector) override
MatrixComp mDirectSeriesHistory
void mnaTearPostStep(MatrixComp voltage, MatrixComp current) override
std::shared_ptr< Capacitor > mSubParallelCapacitor1
Parallel capacitor submodel at Terminal 1.
std::shared_ptr< Capacitor > mSubParallelCapacitor0
void mnaCompUpdateVoltage(const Matrix &leftVector) override
Updates internal voltage variable of the component.
MatrixComp mDirectSeriesCurrent
MatrixComp mDirectSeriesSystemInverse
void mnaTearApplyVoltageStamp(Matrix &voltageVector) override
void mnaParentPostStep(Real time, Int timeStepCount, Attribute< Matrix >::Ptr &leftVector) override
SimPowerComp< Complex >::Ptr clone(String copySuffix) override
DEPRECATED: Remove method.
std::shared_ptr< Inductor > mSubSeriesInductor
std::shared_ptr< Resistor > mSubParallelResistor0
Parallel Resistor submodel at Terminal 0.
MatrixComp mDirectCapVoltage1
void mnaParentAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes) override
add MNA pre and post step dependencies
void mnaParentApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override
void initializeParentFromNodesAndTerminals(Real frequency) override
Derives values from power flow data and pushes them to subcomponents.
void createSubComponents() override
Constructs and registers MNA subcomponents; idempotent.
MatrixComp mDirectCapCurrent0
void mnaParentInitialize(Real omega, Real timeStep, Attribute< Matrix >::Ptr leftVector) override
void mnaParentApplyRightSideVectorStamp(Matrix &rightVector) override
MatrixComp mDirectCapHistory0
MatrixComp mDirectInductorAdmittance
std::shared_ptr< Resistor > mSubParallelResistor1
Parallel resistor submodel at Terminal 1.
MatrixComp mDirectCapHistory1
MatrixComp mDirectCapVoltage0
Complex mDirectSeriesPrevCurrentFactor
MNAInterface::List mnaTearGroundComponents() override
MatrixComp mDirectCapPrevVoltCoeff
MatrixComp mDirectCapCurrent1
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.
spdlog::level::level_enum Level
Definition Logger.h:33
static String matrixCompToString(const MatrixComp &mat)
Definition Logger.cpp:37
static String phasorToString(const Complex &num)
Definition Logger.cpp:57
std::vector< Ptr > List
void mnaUpdateCurrent(const Matrix &leftVector) final
void mnaUpdateVoltage(const Matrix &leftVector) final
Attribute< Matrix >::Ptr mRightVector
void mnaApplyRightSideVectorStamp(Matrix &rightVector) final
static void stampAdmittanceMatrix(const MatrixComp &admittanceMat, SparseMatrixRow &mat, UInt node1Index, UInt node2Index, Bool isTerminal1NotGrounded, Bool isTerminal2NotGrounded, const Logger::Log &mSLog, Int maxFreq=1, Int freqIdx=0)
static Complex complexFromVectorElement(const Matrix &mat, Matrix::Index row, Int maxFreq=1, Int freqIdx=0)
static void setVectorElement(Matrix &mat, Matrix::Index row, Complex value, Int maxFreq=1, Int freqIdx=0, Matrix::Index colOffset=0)
std::vector< Ptr > List
Definition SimNode.h:35
UInt matrixNodeIndex(UInt nodeIndex)
const Attribute< MatrixVar< Complex > >::Ptr mIntfCurrent
SimTerminal< Complex >::List mTerminals
const Attribute< MatrixVar< Complex > >::Ptr mIntfVoltage
SimNode< Complex >::Ptr virtualNode(UInt index)
std::shared_ptr< SimPowerComp< VarType > > Ptr
SimNode< Complex >::List mVirtualNodes
Bool terminalNotGrounded(UInt index)
Complex initialSingleVoltage(UInt index)
Logger::Level mLogLevel
Component logger control for internal variables.
Logger::Log mSLog
Component logger.
static std::shared_ptr< PiLine > make(Args &&...args)
Definition PtrFactory.h:19
#define PI
Definition Definitions.h:43
#define RMS3PH_TO_PEAK1PH
Definition Definitions.h:50
#define SHIFT_TO_PHASE_C
Definition Definitions.h:47
#define PEAK1PH_TO_RMS3PH
Definition Definitions.h:51
#define SHIFT_TO_PHASE_B
Definition Definitions.h:46
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
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