11 Bool withResistiveLosses)
16 Bool withResistiveLosses)
19 mUseSubcomponents(useSubcomponents) {
21 mWithResistiveLosses = withResistiveLosses;
22 if (withResistiveLosses)
28 SPDLOG_LOGGER_INFO(
mSLog,
"Create {} {}", this->
type(), name);
44 Real nomVoltageSecondary,
49 ratedPower, ratioAbs, ratioPhase,
50 resistance, inductance);
54void DP::Ph3::Transformer::resolveWindingRoles() {
55 switch (mReferenceWinding) {
57 mReferenceTerminal = 0;
60 mReferenceTerminal = 1;
63 SPDLOG_LOGGER_ERROR(mSLog,
64 "Transformer {}: three-winding transformers are "
70 (mNominalVoltagePrimary >= mNominalVoltageSecondary) ? 0 : 1;
75 (mReferenceTerminal == 0) ? effectiveRatio() : 1. / effectiveRatio();
76 mOrientationSign = (mReferenceTerminal == 0) ? 1. : -1.;
80 "Impedance referred to winding {} ({} [V]), remaining winding "
81 "at terminal {} ({} [V]), ratio = {}",
82 mReferenceTerminal + 1, nominalVoltageAt(mReferenceTerminal),
83 nonReferenceTerminal(), nominalVoltageAt(nonReferenceTerminal()),
87void DP::Ph3::Transformer::createSubComponents() {
88 if (!mUseSubcomponents)
92 mSubCompCreated =
true;
94 resolveWindingRoles();
96 auto midpoint = mVirtualNodes[2];
99 std::make_shared<DP::Ph3::Inductor>(**mName +
"_ind", mLogLevel);
100 mSubInductor->setParameters(mInductance / 2.);
105 std::make_shared<DP::Ph3::Inductor>(**mName +
"_ind2", mLogLevel);
106 mSubInductor2->setParameters(mInductance / 2.);
110 if (mNumVirtualNodes == 5) {
112 std::make_shared<DP::Ph3::Resistor>(**mName +
"_res", mLogLevel);
113 mSubResistor->setParameters(mResistance / 2.);
114 mSubResistor->connect({node(mReferenceTerminal), mVirtualNodes[3]});
115 mSubInductor->connect({mVirtualNodes[3], midpoint});
120 std::make_shared<DP::Ph3::Resistor>(**mName +
"_res2", mLogLevel);
121 mSubResistor2->setParameters(mResistance / 2.);
122 mSubResistor2->connect({midpoint, mVirtualNodes[4]});
123 mSubInductor2->connect({mVirtualNodes[4], mVirtualNodes[0]});
124 addMNASubComponent(mSubResistor2,
128 mSubInductor->connect({node(mReferenceTerminal), midpoint});
129 mSubInductor2->connect({midpoint, mVirtualNodes[0]});
132 if (mRatedPower <= 0) {
133 SPDLOG_LOGGER_WARN(mSLog,
134 "Transformer {}: rated power is {} [VA], so the "
135 "magnetizing branch cannot be sized and is omitted",
136 this->name(), mRatedPower);
140 if (mNoLoadCurrent <= mNoLoadLoss) {
141 SPDLOG_LOGGER_ERROR(mSLog,
142 "Transformer {}: no-load current {} must exceed the "
144 this->name(), mNoLoadCurrent, mNoLoadLoss);
145 throw InvalidArgumentException();
148 Real magnetizingResistance =
149 std::pow(nominalVoltageAt(mReferenceTerminal), 2) /
150 (mNoLoadLoss * mRatedPower);
151 mMagnetizingResistance =
153 mSubMagnetizingResistor =
154 std::make_shared<DP::Ph3::Resistor>(**mName +
"_mag_res", mLogLevel);
155 mSubMagnetizingResistor->setParameters(mMagnetizingResistance);
157 addMNASubComponent(mSubMagnetizingResistor,
161 mSubMagnetizingInductor =
162 std::make_shared<DP::Ph3::Inductor>(**mName +
"_mag_ind", mLogLevel);
164 addMNASubComponent(mSubMagnetizingInductor,
171 Real omega = 2. *
PI * frequency;
172 if (!mUseSubcomponents)
173 resolveWindingRoles();
181 if (mUseSubcomponents ?
static_cast<Bool>(mSubMagnetizingInductor)
183 if (!mUseSubcomponents) {
184 if (mNoLoadCurrent <= mNoLoadLoss)
186 const Real resistance =
189 mMagnetizingResistance =
192 Real magnetizingSusceptance =
193 std::sqrt(std::pow(mNoLoadCurrent, 2) - std::pow(mNoLoadLoss, 2)) *
195 Real magnetizingInductance = 1. / (omega * magnetizingSusceptance);
196 mMagnetizingInductance =
198 if (mUseSubcomponents)
199 mSubMagnetizingInductor->setParameters(mMagnetizingInductance);
205 mVirtualNodes[0]->setInitialVoltage(secondaryVoltage * mRatioFromReference);
210 if (mUseSubcomponents ?
static_cast<Bool>(mSubMagnetizingInductor)
212 magnetizingAdmittance =
213 1. / mMagnetizingResistance(0, 0) +
214 1. /
Complex(0, omega * mMagnetizingInductance(0, 0));
219 (2. + halfImpedance * magnetizingAdmittance);
224 (referenceVoltage - midpointVoltage) / halfImpedance;
226 (midpointVoltage -
mVirtualNodes[0]->initialVoltage()) / halfImpedance;
228 referenceVoltage - referenceCurrent *
mResistance(0, 0) / 2.);
230 midpointVoltage - nonReferenceCurrent *
mResistance(0, 0) / 2.);
235 MatrixComp impedance = MatrixComp::Zero(3, 3);
236 for (
UInt row = 0; row < 3; row++)
237 for (
UInt col = 0; col < 3; col++)
238 impedance(row, col) =
244 **
mIntfCurrent = impedance.inverse() * impedanceVoltage;
249 if (mUseSubcomponents)
252 const Real b = timeStep * omega / 2.;
254 const Matrix a = (timeStep / 2.) * halfInductance.inverse();
255 mDirectInductorAdmittance = MatrixComp::Zero(3, 3);
256 mDirectInductorAdmittance.real() = a / (1. + b * b);
257 mDirectInductorAdmittance.imag() = -a * b / (1. + b * b);
258 mDirectInductorPrevCurrentFactor =
259 Complex((1. - b * b) / (1. + b * b), -2. * b / (1. + b * b));
260 mDirectInductorCurrent0.setZero();
261 mDirectInductorCurrent1.setZero();
262 mDirectInductorVoltage0.setZero();
263 mDirectInductorVoltage1.setZero();
264 mDirectInductorHistory0.setZero();
265 mDirectInductorHistory1.setZero();
266 mDirectMagnetizingAdmittance.setZero();
267 mDirectMagnetizingCurrent.setZero();
268 mDirectMagnetizingVoltage.setZero();
269 mDirectMagnetizingHistory.setZero();
271 const Matrix magA = (timeStep / 2.) * mMagnetizingInductance.inverse();
272 mDirectMagnetizingAdmittance.real() = magA / (1. + b * b);
273 mDirectMagnetizingAdmittance.imag() = -magA * b / (1. + b * b);
274 mDirectMagnetizingPrevCurrentFactor = mDirectInductorPrevCurrentFactor;
288 mDirectInductorCurrent0 =
290 mDirectInductorVoltage0;
291 mDirectInductorCurrent1 =
293 mDirectInductorVoltage1;
296 mDirectMagnetizingCurrent =
299 mDirectMagnetizingVoltage;
306 for (
UInt phase = 0; phase < 3; phase++) {
320 for (
UInt phase = 0; phase < 3; phase++) {
324 std::conj(mRatioFromReference));
331 if (!mUseSubcomponents) {
337 const UInt secondNode =
346 secondNode,
true,
true,
mSLog);
349 systemMatrix, firstNode, midpoint,
352 systemMatrix, secondNode, ratioNode,
356 mMagnetizingResistance.inverse().cast<
Complex>(), systemMatrix,
357 midpoint, 0,
true,
false,
mSLog);
359 systemMatrix, midpoint, 0,
true,
367 if (mUseSubcomponents)
377 mDirectInductorHistory0 =
378 mDirectInductorAdmittance * mDirectInductorVoltage0 +
379 mDirectInductorPrevCurrentFactor * mDirectInductorCurrent0;
380 mDirectInductorHistory1 =
381 mDirectInductorAdmittance * mDirectInductorVoltage1 +
382 mDirectInductorPrevCurrentFactor * mDirectInductorCurrent1;
384 mDirectMagnetizingHistory =
385 mDirectMagnetizingAdmittance * mDirectMagnetizingVoltage +
386 mDirectMagnetizingPrevCurrentFactor * mDirectMagnetizingCurrent;
387 for (
UInt phase = 0; phase < 3; ++phase) {
390 mDirectInductorHistory0(phase, 0));
391 Complex midpointHistory = -mDirectInductorHistory0(phase, 0);
394 mDirectInductorHistory1(phase, 0));
396 midpointHistory += mDirectInductorHistory1(phase, 0);
398 midpointHistory += mDirectMagnetizingHistory(phase, 0);
401 -mDirectInductorHistory1(phase, 0));
423 attributeDependencies.push_back(leftVector);
435 (**mIntfVoltage).setZero();
436 for (
UInt phase = 0; phase < 3; phase++) {
438 (**mIntfVoltage)(phase, 0) =
441 (**mIntfVoltage)(phase, 0) =
448 if (mUseSubcomponents) {
449 **
mIntfCurrent = mOrientationSign * mSubInductor->intfCurrent();
459 for (
UInt phase = 0; phase < 3; ++phase) {
460 mDirectInductorVoltage0(phase, 0) =
465 mDirectInductorVoltage1(phase, 0) =
470 mDirectMagnetizingVoltage(phase, 0) =
473 mDirectInductorCurrent0 =
474 mDirectInductorAdmittance * mDirectInductorVoltage0 +
475 mDirectInductorHistory0;
476 mDirectInductorCurrent1 =
477 mDirectInductorAdmittance * mDirectInductorVoltage1 +
478 mDirectInductorHistory1;
480 mDirectMagnetizingCurrent =
481 mDirectMagnetizingAdmittance * mDirectMagnetizingVoltage +
482 mDirectMagnetizingHistory;
483 **
mIntfCurrent = mOrientationSign * mDirectInductorCurrent0;
AttributePointer< Attribute< T > > Ptr
CompositePowerComp(String uid, String name, Bool hasPreStep, Bool hasPostStep, Logger::Level logLevel)
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)
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)
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.
UInt matrixNodeIndex(UInt nodeIndex)
const Attribute< MatrixVar< Complex > >::Ptr mIntfCurrent
void setVirtualNodeNumber(UInt num)
const Attribute< MatrixVar< Complex > >::Ptr mIntfVoltage
MatrixComp initialVoltage(UInt index)
SimNode< Complex >::Ptr virtualNode(UInt index)
std::shared_ptr< SimPowerComp< VarType > > Ptr
SimNode< Complex >::List mVirtualNodes
Bool terminalNotGrounded(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
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).