9 #include <dpsim-models/SP/SP_Ph1_Resistor.h>
22 auto copy = Resistor::make(name, mLogLevel);
23 copy->setParameters(**mResistance);
29 (**mIntfVoltage)(0, 0) = initialSingleVoltage(1) - initialSingleVoltage(0);
30 **mIntfCurrent = (1 / **mResistance) * **mIntfVoltage;
32 SPDLOG_LOGGER_INFO(mSLog,
"\nResistance [Ohm]: {:s}",
33 Logger::realToString(**mResistance));
34 SPDLOG_LOGGER_INFO(mSLog,
35 "\n--- Initialization from powerflow ---"
36 "\nVoltage across: {:s}"
38 "\nTerminal 0 voltage: {:s}"
39 "\nTerminal 1 voltage: {:s}"
40 "\n--- Initialization from powerflow finished ---",
41 Logger::phasorToString((**mIntfVoltage)(0, 0)),
42 Logger::phasorToString((**mIntfCurrent)(0, 0)),
43 Logger::phasorToString(initialSingleVoltage(0)),
44 Logger::phasorToString(initialSingleVoltage(1)));
50 mBaseVoltage = baseVoltage;
54 SPDLOG_LOGGER_INFO(mSLog,
"#### Calculate Per Unit Parameters for {}",
56 mBaseApparentPower = baseApparentPower;
57 SPDLOG_LOGGER_INFO(mSLog,
"Base Power={} [VA]", baseApparentPower);
59 mBaseImpedance = mBaseVoltage * mBaseVoltage / mBaseApparentPower;
60 mBaseAdmittance = 1.0 / mBaseImpedance;
61 mBaseCurrent = baseApparentPower /
64 SPDLOG_LOGGER_INFO(mSLog,
"Base Voltage={} [V] Base Impedance={} [Ohm]",
65 mBaseVoltage, mBaseImpedance);
67 mResistancePerUnit = **mResistance / mBaseImpedance;
68 mConductancePerUnit = 1. / mResistancePerUnit;
69 SPDLOG_LOGGER_INFO(mSLog,
"Resistance={} [pu] Conductance={} [pu]",
70 mResistancePerUnit, mConductancePerUnit);
74 int bus1 = this->matrixNodeIndex(0);
75 Complex Y_element = Complex(mConductancePerUnit, 0);
77 if (std::isinf(Y_element.real()) || std::isinf(Y_element.imag())) {
78 std::cout <<
"Y:" << Y_element << std::endl;
80 ss <<
"Resistor >>" << this->name()
81 <<
": infinite or nan values at node: " << bus1;
82 throw std::invalid_argument(ss.str());
86 Y.coeffRef(bus1, bus1) += Y_element;
87 SPDLOG_LOGGER_INFO(mSLog,
"#### Y matrix stamping: {}", Y_element);
92 void SP::Ph1::Resistor::mnaCompInitialize(Real omega, Real timeStep,
94 updateMatrixNodeIndices();
95 **mRightVector = Matrix::Zero(0, 0);
97 SPDLOG_LOGGER_INFO(mSLog,
98 "\n--- MNA initialization ---"
99 "\nInitial voltage {:s}"
100 "\nInitial current {:s}"
101 "\n--- MNA initialization finished ---",
102 Logger::phasorToString((**mIntfVoltage)(0, 0)),
103 Logger::phasorToString((**mIntfCurrent)(0, 0)));
107 SparseMatrixRow &systemMatrix) {
108 Complex conductance = Complex(1. / **mResistance, 0);
110 MNAStampUtils::stampAdmittance(conductance, systemMatrix, matrixNodeIndex(0),
111 matrixNodeIndex(1), terminalNotGrounded(0),
112 terminalNotGrounded(1), mSLog);
116 AttributeBase::List &prevStepDependencies,
117 AttributeBase::List &attributeDependencies,
118 AttributeBase::List &modifiedAttributes,
120 attributeDependencies.push_back(leftVector);
121 modifiedAttributes.push_back(mIntfVoltage);
122 modifiedAttributes.push_back(mIntfCurrent);
127 this->mnaUpdateVoltage(**leftVector);
128 this->mnaUpdateCurrent(**leftVector);
133 for (UInt freq = 0; freq < mNumFreqs; freq++) {
134 (**mIntfVoltage)(0, freq) = 0;
135 if (terminalNotGrounded(1))
136 (**mIntfVoltage)(0, freq) = Math::complexFromVectorElement(
137 leftVector, matrixNodeIndex(1), mNumFreqs, freq);
138 if (terminalNotGrounded(0))
139 (**mIntfVoltage)(0, freq) =
140 (**mIntfVoltage)(0, freq) -
141 Math::complexFromVectorElement(leftVector, matrixNodeIndex(0),
144 SPDLOG_LOGGER_DEBUG(mSLog,
"Voltage {:s}",
145 Logger::phasorToString((**mIntfVoltage)(0, freq)));
150 for (UInt freq = 0; freq < mNumFreqs; freq++) {
151 (**mIntfCurrent)(0, freq) = (**mIntfVoltage)(0, freq) / **mResistance;
152 SPDLOG_LOGGER_DEBUG(mSLog,
"Current {:s}",
153 Logger::phasorToString((**mIntfCurrent)(0, freq)));
157 void SP::Ph1::Resistor::mnaTearApplyMatrixStamp(SparseMatrixRow &tearMatrix) {
158 Math::addToMatrixElement(tearMatrix, mTearIdx, mTearIdx,
159 Complex(**mResistance, 0));
Base class for all MNA components that are transmitting power.
Static phasor resistor model.
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.
Base class for all components that are transmitting power.
const Attribute< MatrixVar< Complex > >::Ptr mIntfCurrent
Current through component.
const Attribute< MatrixVar< Complex > >::Ptr mIntfVoltage
Voltage between terminals.