16 Bool withResistiveLosses)
20 Bool useSubcomponents,
22 Bool withResistiveLosses)
25 mUseSubcomponents = useSubcomponents;
27 **mDirectState = Matrix::Zero(18, 1);
29 mWithResistiveLosses = withResistiveLosses;
30 if (withResistiveLosses)
37 SPDLOG_LOGGER_INFO(
mSLog,
"Create {} {}", this->
type(), name);
45 mWithResistiveLosses);
54 Real nomVoltageSecondary,
60 ratedPower, ratioAbs, ratioPhase,
61 resistance, inductance);
65 "Nominal Voltage Primary = {} [V] Nominal Voltage Secondary = {} [V]",
68 SPDLOG_LOGGER_INFO(
mSLog,
"Tap Ratio = {} [ ] Phase Shift = {} [deg]",
74void EMT::Ph3::Transformer::resolveWindingRoles() {
75 switch (mReferenceWinding) {
77 mReferenceTerminal = 0;
80 mReferenceTerminal = 1;
83 SPDLOG_LOGGER_ERROR(mSLog,
84 "Transformer {}: three-winding transformers are "
90 (mNominalVoltagePrimary >= mNominalVoltageSecondary) ? 0 : 1;
94 (mReferenceTerminal == 0) ? effectiveRatio() : 1. / effectiveRatio();
95 mOrientationSign = (mReferenceTerminal == 0) ? 1. : -1.;
97 if (
Math::abs(std::arg(mRatioFromReference)) > 1e-9) {
98 SPDLOG_LOGGER_ERROR(mSLog,
99 "Turns ratio {} has a phase shift of {} rad. "
100 "EMT::Ph3::Transformer models in-phase turns ratios "
101 "only; a phase-shifting winding connection is not "
104 std::arg(mRatioFromReference));
114 if (!mUseSubcomponents) {
115 resolveWindingRoles();
119 resolveWindingRoles();
124 std::make_shared<EMT::Ph3::Inductor>(**
mName +
"_ind",
mLogLevel);
130 std::make_shared<EMT::Ph3::Inductor>(**
mName +
"_ind2",
mLogLevel);
137 std::make_shared<EMT::Ph3::Resistor>(**
mName +
"_res",
mLogLevel);
145 std::make_shared<EMT::Ph3::Resistor>(**
mName +
"_res2",
mLogLevel);
153 mSubInductor->connect({
node(mReferenceTerminal), midpoint});
158 SPDLOG_LOGGER_WARN(
mSLog,
159 "Transformer {}: rated power is {} [VA], so the "
160 "magnetizing branch cannot be sized and is omitted",
165 if (mNoLoadCurrent <= mNoLoadLoss) {
166 SPDLOG_LOGGER_ERROR(
mSLog,
167 "Transformer {}: no-load current {} must exceed the "
169 this->
name(), mNoLoadCurrent, mNoLoadLoss);
173 Real magnetizingResistance =
176 mMagnetizingResistance =
178 mSubMagnetizingResistor =
179 std::make_shared<EMT::Ph3::Resistor>(**
mName +
"_mag_res",
mLogLevel);
180 mSubMagnetizingResistor->setParameters(mMagnetizingResistance);
186 mSubMagnetizingInductor =
187 std::make_shared<EMT::Ph3::Inductor>(**
mName +
"_mag_ind",
mLogLevel);
196 if (!mUseSubcomponents) {
197 resolveWindingRoles();
198 const Real omega = 2. *
PI * frequency;
200 mSeriesResistanceHalf.setZero();
201 if (mWithResistiveLosses)
204 const Real bmag = std::sqrt(mNoLoadCurrent * mNoLoadCurrent -
205 mNoLoadLoss * mNoLoadLoss) *
210 mMagnetizingInductance =
213 mDirectMagnetizingConductance = mMagnetizingResistance.inverse();
215 mMagnetizingInductance = Matrix::Zero(3, 3);
216 mDirectMagnetizingConductance = Matrix::Zero(3, 3);
218 MatrixComp v0 = MatrixComp::Zero(3, 1), v1 = MatrixComp::Zero(3, 1);
225 const MatrixComp vref = mReferenceTerminal == 0 ? v0 : v1;
226 const MatrixComp vother = mReferenceTerminal == 0 ? v1 : v0;
227 const MatrixComp vreferred = mRatioFromReference.real() * vother;
229 mSeriesResistanceHalf.cast<
Complex>() +
234 ymag +=
Complex(0., -1. / omega) *
235 mMagnetizingInductance.inverse().cast<
Complex>();
236 const MatrixComp midpointInv = (2. * yseries + ymag).inverse();
237 const MatrixComp vmid = midpointInv * yseries * (vref + vreferred);
238 const MatrixComp i0 = yseries * (vmid - vref);
239 const MatrixComp i1 = yseries * (vreferred - vmid);
241 (ymag - mDirectMagnetizingConductance.cast<
Complex>()) * (-vmid);
242 (**mDirectState).setZero();
243 (**mDirectState).block<3, 1>(0, 0) =
246 (**mDirectState).block<3, 1>(3, 0) = i0.real();
247 (**mDirectState).block<3, 1>(6, 0) =
250 (**mDirectState).block<3, 1>(9, 0) = i1.real();
251 const Complex ratioNodeVoltage =
255 if (mWithResistiveLosses) {
258 const Complex referenceCurrent = (vref(0) - vmid(0)) / halfImpedance;
259 const Complex nonReferenceCurrent =
260 (vmid(0) - vreferred(0)) / halfImpedance;
269 (**mDirectState).block<3, 1>(12, 0) =
270 (
Complex(0., omega) * mMagnetizingInductance.cast<
Complex>() * imag)
272 (**mDirectState).block<3, 1>(15, 0) = imag.real();
287 Real omega = 2. *
PI * frequency;
289 if (mSubMagnetizingInductor) {
290 Real magnetizingSusceptance =
291 std::sqrt(std::pow(mNoLoadCurrent, 2) - std::pow(mNoLoadLoss, 2)) *
293 Real magnetizingInductance = 1. / (omega * magnetizingSusceptance);
294 mMagnetizingInductance =
296 mSubMagnetizingInductor->setParameters(mMagnetizingInductance);
297 SPDLOG_LOGGER_INFO(
mSLog,
"Magnetizing inductance = {} [H]",
301 MatrixComp impedance = MatrixComp::Zero(3, 3);
312 SPDLOG_LOGGER_INFO(
mSLog,
313 "Resistance (referred to higher voltage side) = {} [Ohm]",
315 SPDLOG_LOGGER_INFO(
mSLog,
316 "Inductance (referred to higher voltage side) = {} [H]",
318 SPDLOG_LOGGER_INFO(
mSLog,
319 "Reactance (referred to higher voltage side) = {} [Ohm]",
329 MatrixComp vTerminalABC = MatrixComp::Zero(3, 1);
335 MatrixComp iInit = impedance.inverse() * vInitABC;
342 if (mSubMagnetizingInductor)
343 magnetizingAdmittance =
344 1. / mMagnetizingResistance(0, 0) +
345 1. /
Complex(0, omega * mMagnetizingInductance(0, 0));
349 (referenceVoltage +
mVirtualNodes[0]->initialSingleVoltage()) /
350 (2. + halfImpedance * magnetizingAdmittance);
355 (referenceVoltage - midpointVoltage) / halfImpedance;
357 (midpointVoltage -
mVirtualNodes[0]->initialSingleVoltage()) /
360 referenceVoltage - referenceCurrent *
mResistance(0, 0) / 2.);
362 midpointVoltage - nonReferenceCurrent *
mResistance(0, 0) / 2.);
367 "\n--- Initialization from powerflow ---"
368 "\nVoltage across: {:s}"
370 "\nTerminal 0 voltage: {:s}"
371 "\nTerminal 1 voltage: {:s}"
372 "\nVirtual Node 1 voltage: {:s}"
373 "\n--- Initialization from powerflow finished ---",
384 if (!mUseSubcomponents) {
386 mDirectInductorAdmittance =
387 (timeStep / 2.) * mSeriesInductanceHalf.inverse();
388 mDirectMagnetizingInductorAdmittance.setZero();
390 mDirectMagnetizingInductorAdmittance =
391 (timeStep / 2.) * mMagnetizingInductance.inverse();
396 "\nTerminal 0 connected to {:s} = sim node {:d}"
397 "\nTerminal 1 connected to {:s} = sim node {:d}",
404 if (!mUseSubcomponents) {
406 auto stampIdealTransformer = [&]() {
408 for (
UInt phase = 0; phase < 3; ++phase) {
416 const UInt other = nonReferenceTerminal();
418 for (
UInt phase = 0; phase < 3; ++phase) {
420 const UInt idealIndex =
423 mRatioFromReference.real());
425 -mRatioFromReference.real());
428 stampIdealTransformer();
431 const bool withLosses = mWithResistiveLosses;
432 const UInt firstInductor =
435 const UInt secondInductor =
440 halfResistanceConductance, systemMatrix,
444 systemMatrix, midpoint,
445 secondInductor,
true,
true,
mSLog);
448 systemMatrix, firstInductor, midpoint,
451 systemMatrix, secondInductor,
452 ratioNode,
true,
true,
mSLog);
454 systemMatrix, midpoint, 0,
true,
457 systemMatrix, midpoint, 0,
true,
487 mRatioFromReference.real());
491 mRatioFromReference.real());
495 mRatioFromReference.real());
499 -mRatioFromReference.real());
503 -mRatioFromReference.real());
507 -mRatioFromReference.real());
512 if (
auto mnasubcomp = std::dynamic_pointer_cast<MNAInterface>(subcomp))
513 mnasubcomp->mnaApplySystemMatrixStamp(systemMatrix);
516 SPDLOG_LOGGER_INFO(
mSLog,
"Add {:s} to system at ({:d},{:d})",
520 SPDLOG_LOGGER_INFO(
mSLog,
"Add {:s} to system at ({:d},{:d})",
524 SPDLOG_LOGGER_INFO(
mSLog,
"Add {:s} to system at ({:d},{:d})",
529 SPDLOG_LOGGER_INFO(
mSLog,
"Add {:s} to system at ({:d},{:d})",
533 SPDLOG_LOGGER_INFO(
mSLog,
"Add {:s} to system at ({:d},{:d})",
537 SPDLOG_LOGGER_INFO(
mSLog,
"Add {:s} to system at ({:d},{:d})",
543 SPDLOG_LOGGER_INFO(
mSLog,
"Add {:s} to system at ({:d},{:d})",
547 SPDLOG_LOGGER_INFO(
mSLog,
"Add {:s} to system at ({:d},{:d})",
551 SPDLOG_LOGGER_INFO(
mSLog,
"Add {:s} to system at ({:d},{:d})",
556 SPDLOG_LOGGER_INFO(
mSLog,
"Add {:s} to system at ({:d},{:d})",
560 SPDLOG_LOGGER_INFO(
mSLog,
"Add {:s} to system at ({:d},{:d})",
564 SPDLOG_LOGGER_INFO(
mSLog,
"Add {:s} to system at ({:d},{:d})",
575 if (!mUseSubcomponents)
576 prevStepDependencies.push_back(mDirectState);
585 if (!mUseSubcomponents) {
586 const auto &state = **mDirectState;
587 mDirectHistory0 = mDirectInductorAdmittance * state.block<3, 1>(0, 0) +
588 state.block<3, 1>(3, 0);
589 mDirectHistory1 = mDirectInductorAdmittance * state.block<3, 1>(6, 0) +
590 state.block<3, 1>(9, 0);
592 mDirectMagnetizingInductorAdmittance * state.block<3, 1>(12, 0) +
593 state.block<3, 1>(15, 0);
600 if (mUseSubcomponents)
604 const UInt firstInductor =
607 const UInt secondInductor =
610 for (
UInt phase = 0; phase < 3; ++phase) {
611 const UInt midpointIndex = midpoint + phase;
612 const UInt ratioIndex = ratioNode + phase;
613 const UInt firstIndex = firstInductor + phase;
614 const UInt secondIndex = secondInductor + phase;
621 rightVector, midpointIndex,
622 -mDirectHistory0(phase) +
623 (mWithResistiveLosses ? 0. : mDirectHistory1(phase)) +
624 mDirectHistoryMag(phase));
625 if (mWithResistiveLosses)
632 return !mUseSubcomponents ||
638 if (mUseSubcomponents) {
644 const UInt firstInductor =
647 const UInt secondInductor =
650 for (
UInt phase = 0; phase < 3; ++phase) {
651 const UInt midpointIndex = midpoint + phase;
652 const UInt ratioIndex = ratioNode + phase;
653 const UInt firstIndex = firstInductor + phase;
654 const UInt secondIndex = secondInductor + phase;
658 rightVector, midpointIndex,
659 -mDirectHistory0(phase) +
660 (mWithResistiveLosses ? 0. : mDirectHistory1(phase)) +
661 mDirectHistoryMag(phase));
662 if (mWithResistiveLosses)
664 mDirectHistory1(phase));
674 attributeDependencies.push_back(leftVector);
677 if (!mUseSubcomponents)
678 modifiedAttributes.push_back(mDirectState);
683 if (!mUseSubcomponents) {
684 Eigen::Matrix<Real, 3, 1> v0 = Eigen::Matrix<Real, 3, 1>::Zero();
685 Eigen::Matrix<Real, 3, 1> v1 = Eigen::Matrix<Real, 3, 1>::Zero();
686 Eigen::Matrix<Real, 3, 1> virtualVoltage[5];
687 for (
auto &voltage : virtualVoltage)
689 for (
UInt phase = 0; phase < 3; ++phase) {
701 const auto vmid = virtualVoltage[2];
702 const auto firstEndpoint = mWithResistiveLosses
704 : (mReferenceTerminal == 0 ? v0 : v1);
705 const auto secondEndpoint = mWithResistiveLosses ? virtualVoltage[4] : vmid;
706 const auto vratio = virtualVoltage[0];
707 const auto vInductor0 = vmid - firstEndpoint;
708 const auto vInductor1 = vratio - secondEndpoint;
709 const auto i0 = mDirectInductorAdmittance * vInductor0 + mDirectHistory0;
710 const auto i1 = mDirectInductorAdmittance * vInductor1 + mDirectHistory1;
712 mDirectMagnetizingInductorAdmittance * (-vmid) + mDirectHistoryMag;
713 (**mDirectState).block<3, 1>(0, 0) = vInductor0;
714 (**mDirectState).block<3, 1>(3, 0) = i0;
715 (**mDirectState).block<3, 1>(6, 0) = vInductor1;
716 (**mDirectState).block<3, 1>(9, 0) = i1;
717 (**mDirectState).block<3, 1>(12, 0) = -vmid;
718 (**mDirectState).block<3, 1>(15, 0) = imag;
728 if (!mUseSubcomponents) {
729 **
mIntfCurrent = mOrientationSign * (**mDirectState).block<3, 1>(3, 0);
732 **
mIntfCurrent = mOrientationSign * mSubInductor->intfCurrent();
737 (**mIntfVoltage).setZero();
739 (**mIntfVoltage)(0, 0) =
741 (**mIntfVoltage)(1, 0) =
743 (**mIntfVoltage)(2, 0) =
747 (**mIntfVoltage)(0, 0) =
750 (**mIntfVoltage)(1, 0) =
753 (**mIntfVoltage)(2, 0) =
AttributePointer< Attribute< T > > Ptr
void addMNASubComponent(typename SimPowerComp< Real >::Ptr subc, MNA_SUBCOMP_TASK_ORDER preStepOrder, MNA_SUBCOMP_TASK_ORDER postStepOrder, Bool contributeToRightVector)
Bool mnaHasCompactRightSideVectorStamp() const override
Composite stamps touch only their cached terminal and virtual-node rows.
void mnaAddCompactRightSideVectorStamp(Matrix &rightVector) override
void mnaCompApplyRightSideVectorStamp(Matrix &rightVector) override
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 matrixToString(const Matrix &mat)
static String phasorToString(const Complex &num)
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 void addToVectorElement(Matrix &mat, Matrix::Index row, Complex value, Int maxFreq=1, Int freqIdx=0)
static void setMatrixElement(SparseMatrixRow &mat, Matrix::Index row, Matrix::Index column, Complex value, Int maxFreq=1, Int freqIdx=0)
static Matrix singlePhaseParameterToThreePhase(Real parameter)
To convert single phase parameters to symmetrical three phase ones.
static Real abs(Complex value)
UInt matrixNodeIndex(UInt nodeIndex)
const Attribute< MatrixVar< Real > >::Ptr mIntfCurrent
SimTerminal< Real >::List mTerminals
SimNode< Real >::Ptr node(UInt index)
void setVirtualNodeNumber(UInt num)
const Attribute< MatrixVar< Real > >::Ptr mIntfVoltage
std::shared_ptr< SimPowerComp< VarType > > Ptr
SimNode< Real >::List mVirtualNodes
std::vector< std::shared_ptr< SimPowerComp< Real > > > mSubComponents
Bool terminalNotGrounded(UInt index)
Complex initialSingleVoltage(UInt index)
void updateMatrixNodeIndices()
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)
#define RMS3PH_TO_PEAK1PH
#define PEAK1PH_TO_RMS3PH
Eigen::Matrix< Real, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor > Matrix
Dense matrix for real numbers.
std::complex< Real > Complex
Eigen::Matrix< Complex, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor > MatrixComp
Dense matrix for complex numbers.
Eigen::SparseMatrix< Real, Eigen::RowMajor > SparseMatrixRow
Sparse matrix for real numbers (row major).