17 Bool withResistiveLosses)
26 if (withResistiveLosses)
31 SPDLOG_LOGGER_INFO(
mSLog,
"Create {} {}", this->
type(), name);
42 Real nomVoltageSecondary,
48 ratioAbs, ratioPhase, resistance,
52 mSLog,
"Nominal Voltage Primary={} [V] Nominal Voltage Secondary={} [V]",
55 mSLog,
"Resistance={} [Ohm] Inductance={} [H] (referred to primary side)",
57 SPDLOG_LOGGER_INFO(
mSLog,
"Tap Ratio={} [/] Phase Shift={} [deg]",
61 mRatioAbs = std::abs(**
mRatio);
62 mRatioPhase = std::arg(**
mRatio);
68 Real nomVoltageSecondary,
76 SPDLOG_LOGGER_ERROR(
mSLog,
"Rated power {} [VA] is negative; must be >= 0",
85 ratioAbs, ratioPhase, resistance,
99void SP::Ph1::Transformer::resolveWindingRoles() {
100 switch (mReferenceWinding) {
102 mReferenceTerminal = 0;
105 mReferenceTerminal = 1;
108 SPDLOG_LOGGER_ERROR(mSLog,
109 "Transformer {}: three-winding transformers are "
115 (mNominalVoltagePrimary >= mNominalVoltageSecondary) ? 0 : 1;
118 mRatioFromReference =
119 (mReferenceTerminal == 0) ? effectiveRatio() : 1. / effectiveRatio();
120 mOrientationSign = (mReferenceTerminal == 0) ? 1. : -1.;
122 if ((mReferenceTerminal == 0) != (
Math::abs(effectiveRatio()) >= 1.) &&
126 "Nominal voltages put the higher-voltage winding at terminal {} ({} "
127 "[V] against {} [V]) but the turns ratio {} points the other way; "
128 "check the argument order of setParameters()",
129 mReferenceTerminal, nominalVoltageAt(mReferenceTerminal),
130 nominalVoltageAt(nonReferenceTerminal()),
139 resolveWindingRoles();
143 mSubInductor = std::make_shared<SP::Ph1::Inductor>(
144 **
mUID +
"_ind", **
mName +
"_ind", Logger::Level::off);
149 mSubInductor2 = std::make_shared<SP::Ph1::Inductor>(
150 **
mUID +
"_ind2", **
mName +
"_ind2", Logger::Level::off);
156 mSubResistor = std::make_shared<SP::Ph1::Resistor>(
157 **
mUID +
"_res", **
mName +
"_res", Logger::Level::off);
164 mSubResistor2 = std::make_shared<SP::Ph1::Resistor>(
165 **
mUID +
"_res2", **
mName +
"_res2", Logger::Level::off);
173 mSubInductor->connect({
node(mReferenceTerminal), midpoint});
177 bool magnetizingEnabled =
180 if (!magnetizingEnabled)
184 SPDLOG_LOGGER_WARN(
mSLog,
185 "Transformer {}: rated power is {} [VA], so the "
186 "magnetizing branch cannot be sized and is omitted",
191 if (mNoLoadCurrent <= mNoLoadLoss) {
192 SPDLOG_LOGGER_ERROR(
mSLog,
193 "Transformer {}: no-load current {} must exceed the "
195 this->
name(), mNoLoadCurrent, mNoLoadLoss);
199 mSubMagnetizingResistor = std::make_shared<SP::Ph1::Resistor>(
200 **
mUID +
"_mag_res", **
mName +
"_mag_res", Logger::Level::off);
206 mSubMagnetizingInductor = std::make_shared<SP::Ph1::Inductor>(
207 **
mUID +
"_mag_ind", **
mName +
"_mag_ind", Logger::Level::off);
216 mNominalOmega = 2. *
PI * frequency;
218 SPDLOG_LOGGER_INFO(
mSLog,
"Reactance={} [Ohm] (referred to primary side)",
221 if (mSubMagnetizingResistor) {
222 mMagnetizingResistance = std::pow(
nominalVoltageAt(mReferenceTerminal), 2) /
224 mSubMagnetizingResistor->setParameters(mMagnetizingResistance);
225 mSubMagnetizingResistor->setBaseVoltage(
228 Real magnetizingSusceptance =
229 std::sqrt(std::pow(mNoLoadCurrent, 2) - std::pow(mNoLoadLoss, 2)) *
231 mMagnetizingInductance = 1. / (mNominalOmega * magnetizingSusceptance);
232 mSubMagnetizingInductor->setParameters(mMagnetizingInductance);
234 SPDLOG_LOGGER_INFO(
mSLog,
235 "Magnetizing resistance = {} [Ohm], inductance = {} [H]",
247 mOrientationSign * (
mVirtualNodes[0]->initialSingleVoltage() -
250 (**mIntfCurrent)(0, 0) = impedanceVoltage / impedance;
258 "\n--- Initialization from powerflow ---"
259 "\nVoltage across: {:s}"
261 "\nTerminal 0 voltage: {:s}"
262 "\nTerminal 1 voltage: {:s}"
263 "\nVirtual Node 1 voltage: {:s}"
264 "\n--- Initialization from powerflow finished ---",
290 SPDLOG_LOGGER_INFO(
mSLog,
"#### Calculate Per Unit Parameters for {}",
292 mBaseApparentPower = baseApparentPower;
293 mBaseOmega = baseOmega;
294 SPDLOG_LOGGER_INFO(
mSLog,
"Base Power={} [VA] Base Omega={} [1/s]",
295 baseApparentPower, baseOmega);
297 resolveWindingRoles();
301 SPDLOG_LOGGER_INFO(
mSLog,
302 "Transformer {}: no base voltage was set, using the "
303 "reference winding {} [V]",
304 this->
name(), referenceVoltage);
306 }
else if (std::abs(**
mBaseVoltage - referenceVoltage) >
308 SPDLOG_LOGGER_WARN(
mSLog,
309 "Transformer {}: base voltage {} [V] does not match the "
310 "reference winding {} [V]; the impedances are referred "
311 "to the reference winding, so that is used as the base",
317 mBaseAdmittance = 1.0 / mBaseImpedance;
318 mBaseCurrent = baseApparentPower /
321 SPDLOG_LOGGER_INFO(
mSLog,
"Base Voltage={} [V] Base Impedance={} [Ohm]",
324 mResistancePerUnit = **
mResistance / mBaseImpedance;
325 mReactancePerUnit = mReactance / mBaseImpedance;
326 SPDLOG_LOGGER_INFO(
mSLog,
"Resistance={} [pu] Reactance={} [pu]",
327 mResistancePerUnit, mReactancePerUnit);
329 mBaseInductance = mBaseImpedance / mBaseOmega;
330 mInductancePerUnit = **
mInductance / mBaseInductance;
332 mLeakagePerUnit =
Complex(mResistancePerUnit, 1. * mInductancePerUnit);
333 SPDLOG_LOGGER_INFO(
mSLog,
"Leakage Impedance={} [pu] ", mLeakagePerUnit);
337 mRatioPerUnit = mRatioFromReference /
341 SPDLOG_LOGGER_INFO(
mSLog,
"Tap Ratio={} [pu]", mRatioAbsPerUnit);
344 bool magnetizingEnabled =
347 if (magnetizingEnabled && **
mRatedPower > 0 && mNoLoadCurrent > mNoLoadLoss)
348 mMagnetizingPerUnit =
349 Complex(mNoLoadLoss, -std::sqrt(std::pow(mNoLoadCurrent, 2) -
350 std::pow(mNoLoadLoss, 2))) *
354 mMagnetizingPerUnit =
Complex(0, 0);
361 Complex halfLeakage = mLeakagePerUnit / 2.;
363 mLeakagePerUnit + halfLeakage * halfLeakage * mMagnetizingPerUnit;
364 Complex yShunted = (1. + halfLeakage * mMagnetizingPerUnit) / determinant;
365 Complex ySeries = 1. / determinant;
367 mY_element(0, 0) = yShunted;
368 mY_element(0, 1) = -ySeries * mRatioPerUnit;
369 mY_element(1, 0) = -ySeries * std::conj(mRatioPerUnit);
370 mY_element(1, 1) = yShunted * std::norm(mRatioPerUnit);
373 for (
int i = 0; i < 2; i++)
374 for (
int j = 0; j < 2; j++)
378 "Transformer {}: non-finite per-unit admittance {} "
379 "in element Y({},{}) (leakage {}, tap {})",
388 mY_element.coeff(0, 0));
391 mY_element.coeff(0, 1));
394 mY_element.coeff(1, 1));
397 mY_element.coeff(1, 0));
399 SPDLOG_LOGGER_INFO(
mSLog,
"#### Y matrix stamping: {}", mY_element);
404 **
mCurrent = current * mBaseCurrent;
422 "\nTerminal 0 connected to {:s} = sim node {:d}"
423 "\nTerminal 1 connected to {:s} = sim node {:d}",
445 -mRatioFromReference);
450 if (
auto mnasubcomp = std::dynamic_pointer_cast<MNAInterface>(subcomp))
451 mnasubcomp->mnaApplySystemMatrixStamp(systemMatrix);
454 SPDLOG_LOGGER_INFO(
mSLog,
"Add {:s} to system at ({:d},{:d})",
458 SPDLOG_LOGGER_INFO(
mSLog,
"Add {:s} to system at ({:d},{:d})",
464 SPDLOG_LOGGER_INFO(
mSLog,
"Add {:s} to system at ({:d},{:d})",
467 SPDLOG_LOGGER_INFO(
mSLog,
"Add {:s} to system at ({:d},{:d})",
491 attributeDependencies.push_back(leftVector);
503 (**mIntfCurrent)(0, 0) = mOrientationSign * mSubInductor->intfCurrent()(0, 0);
504 SPDLOG_LOGGER_DEBUG(
mSLog,
"Current {:s}",
510 (**mIntfVoltage)(0, 0) = 0;
512 (**mIntfVoltage)(0, 0) =
515 (**mIntfVoltage)(0, 0) =
519 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)
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)
const Attribute< String >::Ptr mUID
Unique identifier.
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
static Complex complexFromVectorElement(const Matrix &mat, Matrix::Index row, 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 bool isFinite(Real value)
static Real abs(Complex value)
static void addToMatrixElement(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.
Eigen::SparseMatrix< Complex, Eigen::RowMajor > SparseMatrixCompRow
Sparse matrix for complex numbers (row major).
Eigen::Matrix< Complex, Eigen::Dynamic, 1 > VectorComp
Dense vector for complex 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).