9#include <dpsim-models/MathUtils.h>
10#include <dpsim-models/SP/SP_Ph1_Resistor.h>
23 auto copy = Resistor::make(name,
mLogLevel);
30 (**mIntfVoltage)(0, 0) = initialSingleVoltage(1) - initialSingleVoltage(0);
33 SPDLOG_LOGGER_INFO(
mSLog,
"\nResistance [Ohm]: {:s}",
35 SPDLOG_LOGGER_INFO(
mSLog,
36 "\n--- Initialization from powerflow ---"
37 "\nVoltage across: {:s}"
39 "\nTerminal 0 voltage: {:s}"
40 "\nTerminal 1 voltage: {:s}"
41 "\n--- Initialization from powerflow finished ---",
44 Logger::phasorToString(initialSingleVoltage(0)),
45 Logger::phasorToString(initialSingleVoltage(1)));
51 mBaseVoltage = baseVoltage;
55 SPDLOG_LOGGER_INFO(
mSLog,
"#### Calculate Per Unit Parameters for {}",
57 mBaseApparentPower = baseApparentPower;
58 SPDLOG_LOGGER_INFO(
mSLog,
"Base Power={} [VA]", baseApparentPower);
60 mBaseImpedance = mBaseVoltage * mBaseVoltage / mBaseApparentPower;
61 mBaseAdmittance = 1.0 / mBaseImpedance;
62 mBaseCurrent = baseApparentPower /
65 SPDLOG_LOGGER_INFO(
mSLog,
"Base Voltage={} [V] Base Impedance={} [Ohm]",
66 mBaseVoltage, mBaseImpedance);
68 mResistancePerUnit = **
mResistance / mBaseImpedance;
69 mConductancePerUnit = 1. / mResistancePerUnit;
70 SPDLOG_LOGGER_INFO(
mSLog,
"Resistance={} [pu] Conductance={} [pu]",
71 mResistancePerUnit, mConductancePerUnit);
75 int bus1 = this->matrixNodeIndex(0);
76 Complex Y_element = Complex(mConductancePerUnit, 0);
78 if (!Math::isFinite(Y_element)) {
79 SPDLOG_LOGGER_ERROR(
mSLog,
80 "Resistor {}: non-finite per-unit admittance {} at "
82 this->name(), Logger::complexToString(Y_element), bus1);
87 Y.coeffRef(bus1, bus1) += Y_element;
88 SPDLOG_LOGGER_INFO(
mSLog,
"#### Y matrix stamping: {}", Y_element);
93void SP::Ph1::Resistor::mnaCompInitialize(Real omega, Real timeStep,
94 Attribute<Matrix>::Ptr leftVector) {
95 updateMatrixNodeIndices();
96 **mRightVector = Matrix::Zero(0, 0);
98 SPDLOG_LOGGER_INFO(mSLog,
99 "\n--- MNA initialization ---"
100 "\nInitial voltage {:s}"
101 "\nInitial current {:s}"
102 "\n--- MNA initialization finished ---",
103 Logger::phasorToString((**mIntfVoltage)(0, 0)),
104 Logger::phasorToString((**mIntfCurrent)(0, 0)));
108 SparseMatrixRow &systemMatrix) {
109 Complex conductance = Complex(1. / **
mResistance, 0);
111 MNAStampUtils::stampAdmittance(conductance, systemMatrix, matrixNodeIndex(0),
112 matrixNodeIndex(1), terminalNotGrounded(0),
113 terminalNotGrounded(1),
mSLog);
117 AttributeBase::List &prevStepDependencies,
118 AttributeBase::List &attributeDependencies,
119 AttributeBase::List &modifiedAttributes,
120 Attribute<Matrix>::Ptr &leftVector) {
121 attributeDependencies.push_back(leftVector);
127 Attribute<Matrix>::Ptr &leftVector) {
134 for (UInt freq = 0; freq <
mNumFreqs; freq++) {
135 (**mIntfVoltage)(0, freq) = 0;
136 if (terminalNotGrounded(1))
137 (**mIntfVoltage)(0, freq) = Math::complexFromVectorElement(
138 leftVector, matrixNodeIndex(1),
mNumFreqs, freq);
139 if (terminalNotGrounded(0))
140 (**mIntfVoltage)(0, freq) =
142 Math::complexFromVectorElement(leftVector, matrixNodeIndex(0),
145 SPDLOG_LOGGER_DEBUG(
mSLog,
"Voltage {:s}",
151 for (UInt freq = 0; freq <
mNumFreqs; freq++) {
153 SPDLOG_LOGGER_DEBUG(
mSLog,
"Current {:s}",
158void SP::Ph1::Resistor::mnaTearApplyMatrixStamp(SparseMatrixRow &tearMatrix) {
159 Math::addToMatrixElement(tearMatrix, mTearIdx, mTearIdx,
160 Complex(**mResistance, 0));
const CPS::Attribute< Real >::Ptr mResistance
Resistance [ohm].
const Attribute< String >::Ptr mName
Human readable name.
String uid()
Returns unique id.
AttributeList::Ptr mAttributes
Attribute List.
void mnaUpdateCurrent(const Matrix &leftVector) final
void mnaUpdateVoltage(const Matrix &leftVector) final
MNASimPowerComp(String uid, String name, Bool hasPreStep, Bool hasPostStep, Logger::Level logLevel)
void mnaCompUpdateCurrent(const Matrix &leftVector)
Update interface current from MNA system result.
void mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector)
add MNA pre and post step dependencies
SimPowerComp< Complex >::Ptr clone(String name)
Returns a modified copy of the component with the given suffix added to the name and without.
void mnaCompPostStep(Real time, Int timeStepCount, Attribute< Matrix >::Ptr &leftVector)
MNA pre and post step operations.
void mnaCompUpdateVoltage(const Matrix &leftVector)
Update interface voltage from MNA system result.
void setBaseVoltage(Real baseVoltage)
Set base voltage.
Resistor(String uid, String name, Logger::Level logLevel=Logger::Level::off)
Defines UID, name and logging level.
void initializeFromNodesAndTerminals(Real frequency)
Initializes component from power flow data.
void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix)
Stamps system matrix.
void pfApplyAdmittanceMatrixStamp(SparseMatrixCompRow &Y)
Stamps admittance matrix.
void calculatePerUnitParameters(Real baseApparentPower)
Initializes component from power flow data.
const Attribute< MatrixVar< Complex > >::Ptr mIntfCurrent
const Attribute< MatrixVar< Complex > >::Ptr mIntfVoltage
Logger::Level mLogLevel
Component logger control for internal variables.
Logger::Log mSLog
Component logger.