DPsim
Loading...
Searching...
No Matches
DP_Ph1_Transformer.cpp
Go to the documentation of this file.
1/* Copyright 2017-2021 Institute for Automation of Complex Power Systems,
2 * EONERC, RWTH Aachen University
3 *
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
7 *********************************************************************************/
8
11
12using namespace CPS;
13
15 Logger::Level logLevel,
16 Bool withResistiveLosses)
17 : Transformer(uid, name, true, logLevel, withResistiveLosses) {}
18
20 Bool useSubcomponents, Logger::Level logLevel,
21 Bool withResistiveLosses)
23 CompositePowerComp<Complex>(uid, name, true, true, logLevel),
24 mUseSubcomponents(useSubcomponents) {
25 if (withResistiveLosses)
27 else
29
31
32 SPDLOG_LOGGER_INFO(mSLog, "Create {} {}", this->type(), name);
33 **mIntfVoltage = MatrixComp::Zero(1, 1);
34 **mIntfCurrent = MatrixComp::Zero(1, 1);
35}
36
39 auto copy = Transformer::make(name, mUseSubcomponents, mLogLevel,
40 mNumVirtualNodes == 5);
42 std::abs(**mRatio), std::arg(**mRatio), **mResistance,
43 **mInductance);
44 copy->setTapRatio(tapRatio());
45 return copy;
46}
47
49 Real nomVoltageSecondary,
50 Real ratioAbs, Real ratioPhase,
51 Real resistance, Real inductance) {
52
53 Base::Ph1::Transformer::setParameters(nomVoltagePrimary, nomVoltageSecondary,
54 ratioAbs, ratioPhase, resistance,
55 inductance);
56
57 SPDLOG_LOGGER_INFO(
58 mSLog, "Nominal Voltage Primary={} [V] Nominal Voltage Secondary={} [V]",
60 SPDLOG_LOGGER_INFO(
61 mSLog,
62 "Resistance={} [Ohm] Inductance={} [Ohm] (referred to primary side)",
64 SPDLOG_LOGGER_INFO(mSLog, "Tap Ratio={} [ ] Phase Shift={} [deg]",
65 std::abs(effectiveRatio()), std::arg(effectiveRatio()));
66 SPDLOG_LOGGER_INFO(mSLog, "Rated Power ={} [W]", **mRatedPower);
67
68 mParametersSet = true;
69}
70
72 Real nomVoltageSecondary,
73 Real ratedPower, Real ratioAbs,
74 Real ratioPhase, Real resistance,
75 Real inductance) {
76
77 **mRatedPower = ratedPower;
78 SPDLOG_LOGGER_INFO(mSLog, "Rated Power ={} [W]", **mRatedPower);
79
80 DP::Ph1::Transformer::setParameters(nomVoltagePrimary, nomVoltageSecondary,
81 ratioAbs, ratioPhase, resistance,
82 inductance);
83}
84
85void DP::Ph1::Transformer::resolveWindingRoles() {
86 switch (mReferenceWinding) {
88 mReferenceTerminal = 0;
89 break;
91 mReferenceTerminal = 1;
92 break;
94 SPDLOG_LOGGER_ERROR(mSLog,
95 "Transformer {}: three-winding transformers are "
96 "not implemented",
97 this->name());
100 mReferenceTerminal =
101 (mNominalVoltagePrimary >= mNominalVoltageSecondary) ? 0 : 1;
102 break;
103 }
104
105 mRatioFromReference =
106 (mReferenceTerminal == 0) ? effectiveRatio() : 1. / effectiveRatio();
107 mOrientationSign = (mReferenceTerminal == 0) ? 1. : -1.;
108
109 if (mReferenceWinding == WindingReference::Auto &&
110 std::abs(mNominalVoltagePrimary - mNominalVoltageSecondary) <=
111 DOUBLE_EPSILON * mNominalVoltagePrimary)
112 SPDLOG_LOGGER_WARN(mSLog,
113 "Transformer {}: both windings are nominally {} [V], so "
114 "the reference winding cannot be resolved from the "
115 "nominal voltages; winding 1 assumed. Pass an explicit "
116 "WindingReference to remove the ambiguity.",
117 this->name(), mNominalVoltagePrimary);
118
119 SPDLOG_LOGGER_INFO(
120 mSLog,
121 "Impedance referred to winding {} ({} [V]) {}, remaining "
122 "winding at terminal {} ({} [V]), ratio = {}",
123 mReferenceTerminal + 1, nominalVoltageAt(mReferenceTerminal),
124 mReferenceWinding == WindingReference::Auto
125 ? "(resolved from the nominal voltages)"
126 : "(set explicitly)",
127 nonReferenceTerminal(), nominalVoltageAt(nonReferenceTerminal()),
128 Logger::complexToString(mRatioFromReference));
129}
130
132 if (!mUseSubcomponents)
133 return;
134 if (mSubCompCreated)
135 return;
136 mSubCompCreated = true;
137
138 resolveWindingRoles();
139
140 auto midpoint = mVirtualNodes[2];
141
142 mSubInductor =
143 std::make_shared<DP::Ph1::Inductor>(**mName + "_ind", mLogLevel);
144 mSubInductor->setParameters(**mInductance / 2.);
147
148 mSubInductor2 =
149 std::make_shared<DP::Ph1::Inductor>(**mName + "_ind2", mLogLevel);
150 mSubInductor2->setParameters(**mInductance / 2.);
153
154 if (mNumVirtualNodes == 5) {
155 mSubResistor =
156 std::make_shared<DP::Ph1::Resistor>(**mName + "_res", mLogLevel);
157 mSubResistor->setParameters(**mResistance / 2.);
158 mSubResistor->connect({node(mReferenceTerminal), mVirtualNodes[3]});
159 mSubInductor->connect({mVirtualNodes[3], midpoint});
162
163 mSubResistor2 =
164 std::make_shared<DP::Ph1::Resistor>(**mName + "_res2", mLogLevel);
165 mSubResistor2->setParameters(**mResistance / 2.);
166 mSubResistor2->connect({midpoint, mVirtualNodes[4]});
167 mSubInductor2->connect({mVirtualNodes[4], mVirtualNodes[0]});
168 addMNASubComponent(mSubResistor2,
171 } else {
172 mSubInductor->connect({node(mReferenceTerminal), midpoint});
173 mSubInductor2->connect({midpoint, mVirtualNodes[0]});
174 }
175
176 if (**mRatedPower <= 0) {
177 SPDLOG_LOGGER_WARN(mSLog,
178 "Transformer {}: rated power is {} [VA], so the "
179 "magnetizing branch cannot be sized and is omitted",
180 this->name(), **mRatedPower);
181 return;
182 }
183
184 if (mNoLoadCurrent <= mNoLoadLoss) {
185 SPDLOG_LOGGER_ERROR(mSLog,
186 "Transformer {}: no-load current {} must exceed the "
187 "no-load loss {}; the magnetizing branch has no "
188 "reactive part otherwise",
189 this->name(), mNoLoadCurrent, mNoLoadLoss);
191 }
192
193 mMagnetizingResistance = std::pow(nominalVoltageAt(mReferenceTerminal), 2) /
194 (mNoLoadLoss * **mRatedPower);
195 mSubMagnetizingResistor =
196 std::make_shared<DP::Ph1::Resistor>(**mName + "_mag_res", mLogLevel);
197 mSubMagnetizingResistor->setParameters(mMagnetizingResistance);
198 mSubMagnetizingResistor->connect({midpoint, DP::SimNode::GND});
199 SPDLOG_LOGGER_INFO(mSLog,
200 "Magnetizing resistance = {} [Ohm] at the T midpoint",
201 Logger::realToString(mMagnetizingResistance));
202 addMNASubComponent(mSubMagnetizingResistor,
205
206 mSubMagnetizingInductor =
207 std::make_shared<DP::Ph1::Inductor>(**mName + "_mag_ind", mLogLevel);
208 mSubMagnetizingInductor->connect({midpoint, DP::SimNode::GND});
209 addMNASubComponent(mSubMagnetizingInductor,
212}
213
215 Real frequency) {
216 Real omega = 2. * PI * frequency;
217 if (!mUseSubcomponents)
218 resolveWindingRoles();
219 if (mUseSubcomponents ? static_cast<Bool>(mSubMagnetizingInductor)
220 : **mRatedPower > 0.) {
221 if (!mUseSubcomponents) {
222 if (mNoLoadCurrent <= mNoLoadLoss)
224 mMagnetizingResistance =
225 std::pow(nominalVoltageAt(mReferenceTerminal), 2) /
226 (mNoLoadLoss * **mRatedPower);
227 }
228 Real magnetizingSusceptance =
229 std::sqrt(std::pow(mNoLoadCurrent, 2) - std::pow(mNoLoadLoss, 2)) *
230 **mRatedPower / std::pow(nominalVoltageAt(mReferenceTerminal), 2);
231 mMagnetizingInductance = 1. / (omega * magnetizingSusceptance);
232 if (mUseSubcomponents)
233 mSubMagnetizingInductor->setParameters(mMagnetizingInductance);
234 SPDLOG_LOGGER_INFO(mSLog, "Magnetizing inductance = {} [H]",
235 Logger::realToString(mMagnetizingInductance));
236 }
237
238 // Set initial voltage of virtual node in between
239 mVirtualNodes[0]->setInitialVoltage(
240 initialSingleVoltage(nonReferenceTerminal()) * mRatioFromReference);
241
242 Complex halfImpedance =
243 Complex(**mResistance / 2., omega * **mInductance / 2.);
244 Complex magnetizingAdmittance = Complex(0, 0);
245 if (mUseSubcomponents ? static_cast<Bool>(mSubMagnetizingInductor)
246 : **mRatedPower > 0.)
247 magnetizingAdmittance = 1. / mMagnetizingResistance +
248 1. / Complex(0, omega * mMagnetizingInductance);
249
250 Complex referenceVoltage = initialSingleVoltage(mReferenceTerminal);
251 Complex midpointVoltage =
252 (referenceVoltage + mVirtualNodes[0]->initialSingleVoltage()) /
253 (2. + halfImpedance * magnetizingAdmittance);
254 mVirtualNodes[2]->setInitialVoltage(midpointVoltage);
255
256 if (mNumVirtualNodes == 5) {
257 Complex referenceCurrent =
258 (referenceVoltage - midpointVoltage) / halfImpedance;
259 Complex nonReferenceCurrent =
260 (midpointVoltage - mVirtualNodes[0]->initialSingleVoltage()) /
261 halfImpedance;
262 mVirtualNodes[3]->setInitialVoltage(referenceVoltage -
263 referenceCurrent * **mResistance / 2.);
264 mVirtualNodes[4]->setInitialVoltage(
265 midpointVoltage - nonReferenceCurrent * **mResistance / 2.);
266 }
267
268 // Static calculations from load flow data
269 Complex impedance = {**mResistance, omega * **mInductance};
270 SPDLOG_LOGGER_INFO(mSLog, "Reactance={} [Ohm] (referred to primary side)",
271 omega * **mInductance);
272 Complex impedanceVoltage =
273 mOrientationSign * (mVirtualNodes[0]->initialSingleVoltage() -
274 initialSingleVoltage(mReferenceTerminal));
275 (**mIntfVoltage)(0, 0) = initialSingleVoltage(1) - initialSingleVoltage(0);
276 (**mIntfCurrent)(0, 0) = impedanceVoltage / impedance;
277
278 SPDLOG_LOGGER_INFO(
279 mSLog,
280 "\n--- Initialization from powerflow ---"
281 "\nVoltage across: {:s}"
282 "\nCurrent: {:s}"
283 "\nTerminal 0 voltage: {:s}"
284 "\nTerminal 1 voltage: {:s}"
285 "\nVirtual Node 1 voltage: {:s}"
286 "\n--- Initialization from powerflow finished ---",
292}
293
295 Real omega, Real timeStep, Attribute<Matrix>::Ptr leftVector) {
296 if (!mUseSubcomponents) {
297 const Real b = timeStep * omega / 2.;
298 const Real inductance = **mInductance / 2.;
299 const Real a = timeStep / (2. * inductance);
300 const Complex y(a / (1. + b * b), -a * b / (1. + b * b));
301 const Complex f((1. - b * b) / (1. + b * b), -2. * b / (1. + b * b));
302 mDirectInductorAdmittance = MatrixComp::Constant(mNumFreqs, 1, y);
303 mDirectInductorPrevCurrentFactor = MatrixComp::Constant(mNumFreqs, 1, f);
304 mDirectInductorCurrent0 = MatrixComp::Zero(mNumFreqs, 1);
305 mDirectInductorCurrent1 = MatrixComp::Zero(mNumFreqs, 1);
306 mDirectInductorVoltage0 = MatrixComp::Zero(mNumFreqs, 1);
307 mDirectInductorVoltage1 = MatrixComp::Zero(mNumFreqs, 1);
308 mDirectInductorHistory0 = MatrixComp::Zero(mNumFreqs, 1);
309 mDirectInductorHistory1 = MatrixComp::Zero(mNumFreqs, 1);
310 mDirectMagnetizingAdmittance = MatrixComp::Zero(mNumFreqs, 1);
311 mDirectMagnetizingPrevCurrentFactor = MatrixComp::Zero(mNumFreqs, 1);
312 mDirectMagnetizingCurrent = MatrixComp::Zero(mNumFreqs, 1);
313 mDirectMagnetizingVoltage = MatrixComp::Zero(mNumFreqs, 1);
314 mDirectMagnetizingHistory = MatrixComp::Zero(mNumFreqs, 1);
315 if (**mRatedPower > 0.) {
316 const Real am = timeStep / (2. * mMagnetizingInductance);
317 mDirectMagnetizingAdmittance(0, 0) =
318 Complex(am / (1. + b * b), -am * b / (1. + b * b));
319 mDirectMagnetizingPrevCurrentFactor(0, 0) = f;
320 }
321 const auto voltageAt = [&](UInt nodeIndex) {
322 return nodeIndex == 0
323 ? Complex(0., 0.)
324 : mVirtualNodes[nodeIndex - 1]->initialSingleVoltage();
325 };
326 const Complex midpoint = mVirtualNodes[2]->initialSingleVoltage();
327 const Complex firstNode = mNumVirtualNodes == 5
328 ? mVirtualNodes[3]->initialSingleVoltage()
329 : initialSingleVoltage(mReferenceTerminal);
330 const Complex secondNode = mNumVirtualNodes == 5
331 ? mVirtualNodes[4]->initialSingleVoltage()
332 : midpoint;
333 const Complex ratioNode = mVirtualNodes[0]->initialSingleVoltage();
334 for (UInt freq = 0; freq < mNumFreqs; ++freq) {
335 const Real harmonicOmega = 2. * PI * mFrequencies(freq, 0);
336 if (harmonicOmega != 0.) {
337 mDirectInductorCurrent0(freq, 0) =
338 (midpoint - firstNode) / Complex(0., harmonicOmega * inductance);
339 mDirectInductorCurrent1(freq, 0) =
340 (ratioNode - secondNode) / Complex(0., harmonicOmega * inductance);
341 if (**mRatedPower > 0.)
342 mDirectMagnetizingCurrent(freq, 0) =
343 -midpoint / Complex(0., harmonicOmega * mMagnetizingInductance);
344 }
345 mDirectInductorVoltage0(freq, 0) = midpoint - firstNode;
346 mDirectInductorVoltage1(freq, 0) = ratioNode - secondNode;
347 mDirectMagnetizingVoltage(freq, 0) = -midpoint;
348 }
349 return;
350 }
351 SPDLOG_LOGGER_INFO(
352 mSLog,
353 "\nTerminal 0 connected to {:s} = sim node {:d}"
354 "\nTerminal 1 connected to {:s} = sim node {:d}",
357}
358
360 SparseMatrixRow &systemMatrix) {
361 if (!mUseSubcomponents) {
362 if (terminalNotGrounded(mReferenceTerminal)) {
364 mVirtualNodes[1]->matrixNodeIndex(), -1.);
367 }
368 if (terminalNotGrounded(nonReferenceTerminal())) {
370 systemMatrix, matrixNodeIndex(nonReferenceTerminal()),
371 mVirtualNodes[1]->matrixNodeIndex(), std::conj(mRatioFromReference));
373 matrixNodeIndex(nonReferenceTerminal()),
374 -mRatioFromReference);
375 }
376 const UInt midpoint = mVirtualNodes[2]->matrixNodeIndex();
377 const UInt ratioNode = mVirtualNodes[0]->matrixNodeIndex();
378 const UInt firstNode = mNumVirtualNodes == 5
379 ? mVirtualNodes[3]->matrixNodeIndex()
380 : matrixNodeIndex(mReferenceTerminal);
381 const UInt secondNode =
382 mNumVirtualNodes == 5 ? mVirtualNodes[4]->matrixNodeIndex() : midpoint;
383 if (mNumVirtualNodes == 5) {
385 Complex(2. / **mResistance, 0.), systemMatrix,
386 matrixNodeIndex(mReferenceTerminal), firstNode,
387 terminalNotGrounded(mReferenceTerminal), true, mSLog);
389 systemMatrix, midpoint, secondNode, true,
390 true, mSLog);
391 }
392 MNAStampUtils::stampAdmittance(mDirectInductorAdmittance(0, 0),
393 systemMatrix, firstNode, midpoint, true,
394 true, mSLog);
395 MNAStampUtils::stampAdmittance(mDirectInductorAdmittance(0, 0),
396 systemMatrix, secondNode, ratioNode, true,
397 true, mSLog);
398 if (**mRatedPower > 0.) {
399 MNAStampUtils::stampAdmittance(Complex(1. / mMagnetizingResistance, 0.),
400 systemMatrix, midpoint, 0, true, false,
401 mSLog);
402 MNAStampUtils::stampAdmittance(mDirectMagnetizingAdmittance(0, 0),
403 systemMatrix, midpoint, 0, true, false,
404 mSLog);
405 }
406 return;
407 }
408 // Ideal transformer equations
409 if (terminalNotGrounded(mReferenceTerminal)) {
412 Complex(-1.0, 0));
415 Complex(1.0, 0));
416 }
417 if (terminalNotGrounded(nonReferenceTerminal())) {
419 systemMatrix, matrixNodeIndex(nonReferenceTerminal()),
420 mVirtualNodes[1]->matrixNodeIndex(), std::conj(mRatioFromReference));
422 matrixNodeIndex(nonReferenceTerminal()),
423 -mRatioFromReference);
424 }
425
426 // Add subcomps to system matrix
427 for (auto subcomp : mSubComponents)
428 if (auto mnasubcomp = std::dynamic_pointer_cast<MNAInterface>(subcomp))
429 mnasubcomp->mnaApplySystemMatrixStamp(systemMatrix);
430
431 if (terminalNotGrounded(mReferenceTerminal)) {
432 SPDLOG_LOGGER_INFO(mSLog, "Add {:s} to system at ({:d},{:d})",
436 SPDLOG_LOGGER_INFO(mSLog, "Add {:s} to system at ({:d},{:d})",
440 }
441 if (terminalNotGrounded(nonReferenceTerminal())) {
442 SPDLOG_LOGGER_INFO(mSLog, "Add {:s} to system at ({:d},{:d})",
443 Logger::complexToString(mRatioFromReference),
444 matrixNodeIndex(nonReferenceTerminal()),
446 SPDLOG_LOGGER_INFO(mSLog, "Add {:s} to system at ({:d},{:d})",
447 Logger::complexToString(-mRatioFromReference),
449 matrixNodeIndex(nonReferenceTerminal()));
450 }
451}
452
454 Matrix &rightVector) {
455 if (mUseSubcomponents)
456 return;
457 const UInt midpoint = mVirtualNodes[2]->matrixNodeIndex();
458 const UInt ratioNode = mVirtualNodes[0]->matrixNodeIndex();
459 const UInt firstNode = mNumVirtualNodes == 5
460 ? mVirtualNodes[3]->matrixNodeIndex()
461 : matrixNodeIndex(mReferenceTerminal);
462 const UInt secondNode =
463 mNumVirtualNodes == 5 ? mVirtualNodes[4]->matrixNodeIndex() : midpoint;
464 for (UInt freq = 0; freq < mNumFreqs; ++freq) {
465 const Complex y = mDirectInductorAdmittance(freq, 0);
466 mDirectInductorHistory0(freq, 0) =
467 y * mDirectInductorVoltage0(freq, 0) +
468 mDirectInductorPrevCurrentFactor(freq, 0) *
469 mDirectInductorCurrent0(freq, 0);
470 mDirectInductorHistory1(freq, 0) =
471 y * mDirectInductorVoltage1(freq, 0) +
472 mDirectInductorPrevCurrentFactor(freq, 0) *
473 mDirectInductorCurrent1(freq, 0);
474 if (mNumVirtualNodes == 5 || terminalNotGrounded(mReferenceTerminal))
475 Math::setVectorElement(rightVector, firstNode,
476 mDirectInductorHistory0(freq, 0), mNumFreqs, freq);
477 Complex midpointHistory = -mDirectInductorHistory0(freq, 0);
478 if (mNumVirtualNodes == 5)
479 Math::setVectorElement(rightVector, secondNode,
480 mDirectInductorHistory1(freq, 0), mNumFreqs, freq);
481 else
482 midpointHistory += mDirectInductorHistory1(freq, 0);
483 Math::setVectorElement(rightVector, ratioNode,
484 -mDirectInductorHistory1(freq, 0), mNumFreqs, freq);
485 if (**mRatedPower > 0.) {
486 mDirectMagnetizingHistory(freq, 0) =
487 mDirectMagnetizingAdmittance(freq, 0) *
488 mDirectMagnetizingVoltage(freq, 0) +
489 mDirectMagnetizingPrevCurrentFactor(freq, 0) *
490 mDirectMagnetizingCurrent(freq, 0);
491 midpointHistory += mDirectMagnetizingHistory(freq, 0);
492 }
493 Math::setVectorElement(rightVector, midpoint, midpointHistory, mNumFreqs,
494 freq);
495 }
496}
497
499 AttributeBase::List &prevStepDependencies,
500 AttributeBase::List &attributeDependencies,
501 AttributeBase::List &modifiedAttributes) {
502 prevStepDependencies.push_back(mIntfCurrent);
503 prevStepDependencies.push_back(mIntfVoltage);
504 modifiedAttributes.push_back(mRightVector);
505}
506
510
512 AttributeBase::List &prevStepDependencies,
513 AttributeBase::List &attributeDependencies,
514 AttributeBase::List &modifiedAttributes,
515 Attribute<Matrix>::Ptr &leftVector) {
516 attributeDependencies.push_back(leftVector);
517 modifiedAttributes.push_back(mIntfVoltage);
518 modifiedAttributes.push_back(mIntfCurrent);
519}
520
522 Real time, Int timeStepCount, Attribute<Matrix>::Ptr &leftVector) {
523 this->mnaUpdateVoltage(**leftVector);
524 this->mnaUpdateCurrent(**leftVector);
525}
526
528 if (mUseSubcomponents) {
529 (**mIntfCurrent)(0, 0) =
530 mOrientationSign * mSubInductor->intfCurrent()(0, 0);
531 return;
532 }
533 const UInt midpoint = mVirtualNodes[2]->matrixNodeIndex();
534 const UInt firstNode = mNumVirtualNodes == 5
535 ? mVirtualNodes[3]->matrixNodeIndex()
536 : matrixNodeIndex(mReferenceTerminal);
537 const auto voltage = [&](UInt row) {
538 return Math::complexFromVectorElement(leftVector, row);
539 };
540 mDirectInductorVoltage0(0, 0) = voltage(midpoint) - voltage(firstNode);
541 mDirectInductorVoltage1(0, 0) =
542 voltage(mVirtualNodes[0]->matrixNodeIndex()) -
543 (mNumVirtualNodes == 5 ? voltage(mVirtualNodes[4]->matrixNodeIndex())
544 : voltage(midpoint));
545 mDirectInductorCurrent0(0, 0) =
546 mDirectInductorAdmittance(0, 0) * mDirectInductorVoltage0(0, 0) +
547 mDirectInductorHistory0(0, 0);
548 mDirectInductorCurrent1(0, 0) =
549 mDirectInductorAdmittance(0, 0) * mDirectInductorVoltage1(0, 0) +
550 mDirectInductorHistory1(0, 0);
551 mDirectMagnetizingVoltage(0, 0) = -voltage(midpoint);
552 if (**mRatedPower > 0.)
553 mDirectMagnetizingCurrent(0, 0) =
554 mDirectMagnetizingAdmittance(0, 0) * mDirectMagnetizingVoltage(0, 0) +
555 mDirectMagnetizingHistory(0, 0);
556 (**mIntfCurrent)(0, 0) = mOrientationSign * mDirectInductorCurrent0(0, 0);
557}
558
560 // v1 - v0
561 (**mIntfVoltage)(0, 0) = 0;
562 if (terminalNotGrounded(1))
563 (**mIntfVoltage)(0, 0) =
565 if (terminalNotGrounded(0))
566 (**mIntfVoltage)(0, 0) =
567 (**mIntfVoltage)(0, 0) -
569
570 SPDLOG_LOGGER_DEBUG(mSLog, "Voltage {:s}",
572}
std::vector< Ptr > List
Definition Attribute.h:123
AttributePointer< Attribute< T > > Ptr
Definition Attribute.h:249
const Attribute< Real >::Ptr mRatedPower
Rated Apparent Power [VA].
const Attribute< Real >::Ptr mInductance
Inductance [H].
void setParameters(Real nomVoltagePrimary, Real nomVoltageSecondary, Real ratioAbs, Real ratioPhase, Real resistance, Real inductance)
Real mNominalVoltageSecondary
Nominal voltage of secondary side.
const Attribute< Real >::Ptr mResistance
Resistance [Ohm].
Real mNominalVoltagePrimary
Nominal voltage of primary side.
Real nominalVoltageAt(UInt terminal) const
Nominal voltage of the winding at the given terminal.
const Attribute< Complex >::Ptr mRatio
Complex transformer ratio.
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)
void mnaParentApplyRightSideVectorStamp(Matrix &rightVector) override
Transformer(String uid, String name, Logger::Level logLevel=Logger::Level::off, Bool withResistiveLosses=false)
Defines UID, name and logging level.
void setParameters(Real nomVoltagePrimary, Real nomVoltageSecondary, Real ratioAbs, Real ratioPhase, Real resistance, Real inductance)
Defines component parameters.
void createSubComponents() override
Constructs and registers MNA subcomponents (incl. terminal swap); idempotent.
void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override
Stamps system matrix.
void mnaParentPreStep(Real time, Int timeStepCount) override
MNA pre step operations.
void mnaParentInitialize(Real omega, Real timeStep, Attribute< Matrix >::Ptr leftVector) override
Initializes internal variables of the component.
void initializeParentFromNodesAndTerminals(Real frequency) override
Initializes component from power flow data.
void mnaParentAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector) override
Add MNA post step dependencies.
void mnaCompUpdateVoltage(const Matrix &leftVector) override
Updates internal voltage variable of the component.
SimPowerComp< Complex >::Ptr clone(String name) override
DEPRECATED: Delete method.
void mnaCompUpdateCurrent(const Matrix &leftVector) override
Updates internal current variable of the component.
void mnaParentAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes) override
Add MNA pre step dependencies.
void mnaParentPostStep(Real time, Int timeStepCount, Attribute< Matrix >::Ptr &leftVector) override
MNA post step operations.
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 complexToString(const Complex &num)
Definition Logger.cpp:63
static String realToString(const Real &num)
Definition Logger.cpp:69
static String phasorToString(const Complex &num)
Definition Logger.cpp:57
void mnaUpdateCurrent(const Matrix &leftVector) final
void mnaUpdateVoltage(const Matrix &leftVector) final
Attribute< Matrix >::Ptr mRightVector
void mnaApplyRightSideVectorStamp(Matrix &rightVector) final
static void stampAdmittance(Complex admittance, 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)
static void setMatrixElement(SparseMatrixRow &mat, Matrix::Index row, Matrix::Index column, Complex value, Int maxFreq=1, Int freqIdx=0)
UInt matrixNodeIndex(UInt nodeIndex)
const Attribute< MatrixVar< Complex > >::Ptr mIntfCurrent
SimTerminal< Complex >::List mTerminals
SimNode< Complex >::Ptr node(UInt index)
const Attribute< MatrixVar< Complex > >::Ptr mIntfVoltage
std::shared_ptr< SimPowerComp< VarType > > Ptr
SimNode< Complex >::List mVirtualNodes
std::vector< std::shared_ptr< SimPowerComp< Complex > > > mSubComponents
Bool terminalNotGrounded(UInt index)
Complex initialSingleVoltage(UInt index)
Logger::Level mLogLevel
Component logger control for internal variables.
UInt mNumVirtualNodes
Determines the number of virtual or internal Nodes.
bool mParametersSet
Flag indicating that parameters are set via setParameters() function.
Logger::Log mSLog
Component logger.
static std::shared_ptr< Transformer > make(Args &&...args)
Definition PtrFactory.h:19
#define PI
Definition Definitions.h:43
#define DOUBLE_EPSILON
Definition Definitions.h:14
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
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