16 Bool withResistiveLosses)
21 Bool withResistiveLosses)
24 mUseSubcomponents(useSubcomponents) {
25 if (withResistiveLosses)
32 SPDLOG_LOGGER_INFO(
mSLog,
"Create {} {}", this->
type(), name);
49 Real nomVoltageSecondary,
54 ratioAbs, ratioPhase, resistance,
58 mSLog,
"Nominal Voltage Primary={} [V] Nominal Voltage Secondary={} [V]",
62 "Resistance={} [Ohm] Inductance={} [Ohm] (referred to primary side)",
64 SPDLOG_LOGGER_INFO(
mSLog,
"Tap Ratio={} [ ] Phase Shift={} [deg]",
72 Real nomVoltageSecondary,
81 ratioAbs, ratioPhase, resistance,
85void DP::Ph1::Transformer::resolveWindingRoles() {
86 switch (mReferenceWinding) {
88 mReferenceTerminal = 0;
91 mReferenceTerminal = 1;
94 SPDLOG_LOGGER_ERROR(mSLog,
95 "Transformer {}: three-winding transformers are "
101 (mNominalVoltagePrimary >= mNominalVoltageSecondary) ? 0 : 1;
105 mRatioFromReference =
106 (mReferenceTerminal == 0) ? effectiveRatio() : 1. / effectiveRatio();
107 mOrientationSign = (mReferenceTerminal == 0) ? 1. : -1.;
110 std::abs(mNominalVoltagePrimary - mNominalVoltageSecondary) <=
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);
121 "Impedance referred to winding {} ({} [V]) {}, remaining "
122 "winding at terminal {} ({} [V]), ratio = {}",
123 mReferenceTerminal + 1, nominalVoltageAt(mReferenceTerminal),
125 ?
"(resolved from the nominal voltages)"
126 :
"(set explicitly)",
127 nonReferenceTerminal(), nominalVoltageAt(nonReferenceTerminal()),
132 if (!mUseSubcomponents)
138 resolveWindingRoles();
149 std::make_shared<DP::Ph1::Inductor>(**
mName +
"_ind2",
mLogLevel);
164 std::make_shared<DP::Ph1::Resistor>(**
mName +
"_res2",
mLogLevel);
172 mSubInductor->connect({
node(mReferenceTerminal), midpoint});
177 SPDLOG_LOGGER_WARN(
mSLog,
178 "Transformer {}: rated power is {} [VA], so the "
179 "magnetizing branch cannot be sized and is omitted",
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);
193 mMagnetizingResistance = std::pow(
nominalVoltageAt(mReferenceTerminal), 2) /
195 mSubMagnetizingResistor =
196 std::make_shared<DP::Ph1::Resistor>(**
mName +
"_mag_res",
mLogLevel);
197 mSubMagnetizingResistor->setParameters(mMagnetizingResistance);
199 SPDLOG_LOGGER_INFO(
mSLog,
200 "Magnetizing resistance = {} [Ohm] at the T midpoint",
206 mSubMagnetizingInductor =
207 std::make_shared<DP::Ph1::Inductor>(**
mName +
"_mag_ind",
mLogLevel);
216 Real omega = 2. *
PI * frequency;
217 if (!mUseSubcomponents)
218 resolveWindingRoles();
219 if (mUseSubcomponents ?
static_cast<Bool>(mSubMagnetizingInductor)
221 if (!mUseSubcomponents) {
222 if (mNoLoadCurrent <= mNoLoadLoss)
224 mMagnetizingResistance =
228 Real magnetizingSusceptance =
229 std::sqrt(std::pow(mNoLoadCurrent, 2) - std::pow(mNoLoadLoss, 2)) *
231 mMagnetizingInductance = 1. / (omega * magnetizingSusceptance);
232 if (mUseSubcomponents)
233 mSubMagnetizingInductor->setParameters(mMagnetizingInductance);
234 SPDLOG_LOGGER_INFO(
mSLog,
"Magnetizing inductance = {} [H]",
245 if (mUseSubcomponents ?
static_cast<Bool>(mSubMagnetizingInductor)
247 magnetizingAdmittance = 1. / mMagnetizingResistance +
248 1. /
Complex(0, omega * mMagnetizingInductance);
252 (referenceVoltage +
mVirtualNodes[0]->initialSingleVoltage()) /
253 (2. + halfImpedance * magnetizingAdmittance);
258 (referenceVoltage - midpointVoltage) / halfImpedance;
260 (midpointVoltage -
mVirtualNodes[0]->initialSingleVoltage()) /
265 midpointVoltage - nonReferenceCurrent * **
mResistance / 2.);
270 SPDLOG_LOGGER_INFO(
mSLog,
"Reactance={} [Ohm] (referred to primary side)",
273 mOrientationSign * (
mVirtualNodes[0]->initialSingleVoltage() -
276 (**mIntfCurrent)(0, 0) = impedanceVoltage / impedance;
280 "\n--- Initialization from powerflow ---"
281 "\nVoltage across: {:s}"
283 "\nTerminal 0 voltage: {:s}"
284 "\nTerminal 1 voltage: {:s}"
285 "\nVirtual Node 1 voltage: {:s}"
286 "\n--- Initialization from powerflow finished ---",
296 if (!mUseSubcomponents) {
297 const Real b = timeStep * omega / 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);
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;
321 const auto voltageAt = [&](
UInt nodeIndex) {
322 return nodeIndex == 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);
342 mDirectMagnetizingCurrent(freq, 0) =
343 -midpoint /
Complex(0., harmonicOmega * mMagnetizingInductance);
345 mDirectInductorVoltage0(freq, 0) = midpoint - firstNode;
346 mDirectInductorVoltage1(freq, 0) = ratioNode - secondNode;
347 mDirectMagnetizingVoltage(freq, 0) = -midpoint;
353 "\nTerminal 0 connected to {:s} = sim node {:d}"
354 "\nTerminal 1 connected to {:s} = sim node {:d}",
361 if (!mUseSubcomponents) {
374 -mRatioFromReference);
381 const UInt secondNode =
389 systemMatrix, midpoint, secondNode,
true,
393 systemMatrix, firstNode, midpoint,
true,
396 systemMatrix, secondNode, ratioNode,
true,
400 systemMatrix, midpoint, 0,
true,
false,
403 systemMatrix, midpoint, 0,
true,
false,
423 -mRatioFromReference);
428 if (
auto mnasubcomp = std::dynamic_pointer_cast<MNAInterface>(subcomp))
429 mnasubcomp->mnaApplySystemMatrixStamp(systemMatrix);
432 SPDLOG_LOGGER_INFO(
mSLog,
"Add {:s} to system at ({:d},{:d})",
436 SPDLOG_LOGGER_INFO(
mSLog,
"Add {:s} to system at ({:d},{:d})",
442 SPDLOG_LOGGER_INFO(
mSLog,
"Add {:s} to system at ({:d},{:d})",
446 SPDLOG_LOGGER_INFO(
mSLog,
"Add {:s} to system at ({:d},{:d})",
455 if (mUseSubcomponents)
462 const UInt secondNode =
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);
476 mDirectInductorHistory0(freq, 0),
mNumFreqs, freq);
477 Complex midpointHistory = -mDirectInductorHistory0(freq, 0);
480 mDirectInductorHistory1(freq, 0),
mNumFreqs, freq);
482 midpointHistory += mDirectInductorHistory1(freq, 0);
484 -mDirectInductorHistory1(freq, 0),
mNumFreqs, freq);
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);
516 attributeDependencies.push_back(leftVector);
528 if (mUseSubcomponents) {
529 (**mIntfCurrent)(0, 0) =
530 mOrientationSign * mSubInductor->intfCurrent()(0, 0);
537 const auto voltage = [&](
UInt row) {
540 mDirectInductorVoltage0(0, 0) = voltage(midpoint) - voltage(firstNode);
541 mDirectInductorVoltage1(0, 0) =
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);
553 mDirectMagnetizingCurrent(0, 0) =
554 mDirectMagnetizingAdmittance(0, 0) * mDirectMagnetizingVoltage(0, 0) +
555 mDirectMagnetizingHistory(0, 0);
556 (**mIntfCurrent)(0, 0) = mOrientationSign * mDirectInductorCurrent0(0, 0);
561 (**mIntfVoltage)(0, 0) = 0;
563 (**mIntfVoltage)(0, 0) =
566 (**mIntfVoltage)(0, 0) =
570 SPDLOG_LOGGER_DEBUG(
mSLog,
"Voltage {:s}",
AttributePointer< Attribute< T > > Ptr
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.
spdlog::level::level_enum Level
static String complexToString(const Complex &num)
static String realToString(const Real &num)
static String phasorToString(const Complex &num)
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)
void setVirtualNodeNumber(UInt num)
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)
void setTerminalNumber(UInt num)
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)
Eigen::Matrix< Real, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor > Matrix
Dense matrix for real numbers.
std::complex< Real > Complex
Eigen::SparseMatrix< Real, Eigen::RowMajor > SparseMatrixRow
Sparse matrix for real numbers (row major).