17 Bool withResistiveLosses)
26 if (withResistiveLosses)
31 SPDLOG_LOGGER_INFO(
mSLog,
"Create {} {}", this->
type(), name);
48 ratioAbs, ratioPhase, resistance,
52 mSLog,
"Nominal Voltage End 1={} [V] Nominal Voltage End 2={} [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 nomVoltageEnd2,
Real ratedPower,
75 SPDLOG_LOGGER_ERROR(
mSLog,
"Rated power {} [VA] is negative; must be >= 0",
84 ratioPhase, resistance, inductance);
104 mRatioAbs = std::abs(**
mRatio);
105 mRatioPhase = std::arg(**
mRatio);
106 std::shared_ptr<SimTerminal<Complex>> tmp =
mTerminals[0];
112 SPDLOG_LOGGER_INFO(
mSLog,
"Switching terminals to have first terminal at "
113 "higher voltage side. Updated parameters: ");
115 mSLog,
"Nominal Voltage End 1 = {} [V] Nominal Voltage End 2 = {} [V]",
117 SPDLOG_LOGGER_INFO(
mSLog,
"Tap Ratio = {} [ ] Phase Shift = {} [deg]",
118 mRatioAbs, mRatioPhase);
124 mSubInductor = std::make_shared<SP::Ph1::Inductor>(
125 **
mUID +
"_ind", **
mName +
"_ind", Logger::Level::off);
131 mSubResistor = std::make_shared<SP::Ph1::Resistor>(
132 **
mUID +
"_res", **
mName +
"_res", Logger::Level::off);
146 bool snubbersEnabled =
150 SPDLOG_LOGGER_WARN(
mSLog,
151 "Rated power is {} [VA]; snubbers disabled for this "
152 "transformer (cannot be sized off non-positive power).",
154 snubbersEnabled =
false;
156 if (snubbersEnabled) {
159 std::make_shared<SP::Ph1::Resistor>(**
mName +
"_snub_res1",
mLogLevel);
166 std::make_shared<SP::Ph1::Resistor>(**
mName +
"_snub_res2",
mLogLevel);
173 std::make_shared<SP::Ph1::Capacitor>(**
mName +
"_snub_cap2",
mLogLevel);
183 mNominalOmega = 2. *
PI * frequency;
185 SPDLOG_LOGGER_INFO(
mSLog,
"Reactance={} [Ohm] (referred to primary side)",
188 if (mSubSnubResistor1) {
194 mSubSnubResistor1->setParameters(mSnubberResistance1);
197 "Snubber Resistance 1 (connected to higher voltage side {}) = {} [Ohm]",
203 mSubSnubResistor2->setParameters(mSnubberResistance2);
206 "Snubber Resistance 2 (connected to lower voltage side {}) = {} [Ohm]",
220 mSnubberCapacitance2 =
222 mSubSnubCapacitor2->setParameters(mSnubberCapacitance2);
225 "Snubber Capacitance 2 (connected to lower voltage side {}) = {} [F]",
235 (**mIntfVoltage)(0, 0) =
237 (**mIntfCurrent)(0, 0) = (**
mIntfVoltage)(0, 0) / impedance;
244 "\n--- Initialization from powerflow ---"
245 "\nVoltage across: {:s}"
247 "\nTerminal 0 voltage: {:s}"
248 "\nTerminal 1 voltage: {:s}"
249 "\nVirtual Node 1 voltage: {:s}"
250 "\n--- Initialization from powerflow finished ---",
276 SPDLOG_LOGGER_INFO(
mSLog,
"#### Calculate Per Unit Parameters for {}",
278 mBaseApparentPower = baseApparentPower;
279 mBaseOmega = baseOmega;
280 SPDLOG_LOGGER_INFO(
mSLog,
"Base Power={} [VA] Base Omega={} [1/s]",
281 baseApparentPower, baseOmega);
284 mBaseAdmittance = 1.0 / mBaseImpedance;
285 mBaseCurrent = baseApparentPower /
288 SPDLOG_LOGGER_INFO(
mSLog,
"Base Voltage={} [V] Base Impedance={} [Ohm]",
291 mResistancePerUnit = **
mResistance / mBaseImpedance;
292 mReactancePerUnit = mReactance / mBaseImpedance;
293 SPDLOG_LOGGER_INFO(
mSLog,
"Resistance={} [pu] Reactance={} [pu]",
294 mResistancePerUnit, mReactancePerUnit);
296 mBaseInductance = mBaseImpedance / mBaseOmega;
297 mInductancePerUnit = **
mInductance / mBaseInductance;
299 mLeakagePerUnit =
Complex(mResistancePerUnit, 1. * mInductancePerUnit);
300 SPDLOG_LOGGER_INFO(
mSLog,
"Leakage Impedance={} [pu] ", mLeakagePerUnit);
303 SPDLOG_LOGGER_INFO(
mSLog,
"Tap Ratio={} [pu]", mRatioAbsPerUnit);
306 if (mSubSnubResistor1)
307 mSubSnubResistor1->calculatePerUnitParameters(mBaseApparentPower);
308 if (mSubSnubResistor2)
309 mSubSnubResistor2->calculatePerUnitParameters(mBaseApparentPower);
310 if (mSubSnubCapacitor1)
311 mSubSnubCapacitor1->calculatePerUnitParameters(mBaseApparentPower);
312 if (mSubSnubCapacitor2)
313 mSubSnubCapacitor2->calculatePerUnitParameters(mBaseApparentPower);
322 mY_element(0, 0) = y;
323 mY_element(0, 1) = -y * mRatioAbsPerUnit;
324 mY_element(1, 0) = -y * mRatioAbsPerUnit;
325 mY_element(1, 1) = y * std::pow(mRatioAbsPerUnit, 2);
328 for (
int i = 0; i < 2; i++)
329 for (
int j = 0; j < 2; j++)
333 "Transformer {}: non-finite per-unit admittance {} "
334 "in element Y({},{}) (leakage {}, tap {})",
342 mY_element.coeff(0, 0);
344 mY_element.coeff(0, 1);
346 mY_element.coeff(1, 1);
348 mY_element.coeff(1, 0);
350 SPDLOG_LOGGER_INFO(
mSLog,
"#### Y matrix stamping: {}", mY_element);
352 if (mSubSnubResistor1)
353 mSubSnubResistor1->pfApplyAdmittanceMatrixStamp(Y);
354 if (mSubSnubResistor2)
355 mSubSnubResistor2->pfApplyAdmittanceMatrixStamp(Y);
356 if (mSubSnubCapacitor1)
357 mSubSnubCapacitor1->pfApplyAdmittanceMatrixStamp(Y);
358 if (mSubSnubCapacitor2)
359 mSubSnubCapacitor2->pfApplyAdmittanceMatrixStamp(Y);
364 **
mCurrent = current * mBaseCurrent;
382 "\nTerminal 0 connected to {:s} = sim node {:d}"
383 "\nTerminal 1 connected to {:s} = sim node {:d}",
408 if (
auto mnasubcomp = std::dynamic_pointer_cast<MNAInterface>(subcomp))
409 mnasubcomp->mnaApplySystemMatrixStamp(systemMatrix);
412 SPDLOG_LOGGER_INFO(
mSLog,
"Add {:s} to system at ({:d},{:d})",
416 SPDLOG_LOGGER_INFO(
mSLog,
"Add {:s} to system at ({:d},{:d})",
422 SPDLOG_LOGGER_INFO(
mSLog,
"Add {:s} to system at ({:d},{:d})",
425 SPDLOG_LOGGER_INFO(
mSLog,
"Add {:s} to system at ({:d},{:d})",
449 attributeDependencies.push_back(leftVector);
461 (**mIntfCurrent)(0, 0) = mSubInductor->intfCurrent()(0, 0);
462 SPDLOG_LOGGER_DEBUG(
mSLog,
"Current {:s}",
468 (**mIntfVoltage)(0, 0) = 0;
469 (**mIntfVoltage)(0, 0) =
474 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)
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 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 Q_SNUB_TRANSFORMER
#define P_SNUB_TRANSFORMER
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).