9#include <dpsim-models/SP/SP_Ph1_Resistor.h>
22 auto copy = Resistor::make(name,
mLogLevel);
29 (**mIntfVoltage)(0, 0) = initialSingleVoltage(1) - initialSingleVoltage(0);
32 SPDLOG_LOGGER_INFO(
mSLog,
"\nResistance [Ohm]: {:s}",
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 ---",
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);
92void SP::Ph1::Resistor::mnaCompInitialize(Real omega, Real timeStep,
93 Attribute<Matrix>::Ptr leftVector) {
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,
119 Attribute<Matrix>::Ptr &leftVector) {
120 attributeDependencies.push_back(leftVector);
126 Attribute<Matrix>::Ptr &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) =
141 Math::complexFromVectorElement(leftVector, matrixNodeIndex(0),
144 SPDLOG_LOGGER_DEBUG(
mSLog,
"Voltage {:s}",
150 for (UInt freq = 0; freq <
mNumFreqs; freq++) {
152 SPDLOG_LOGGER_DEBUG(
mSLog,
"Current {:s}",
157void SP::Ph1::Resistor::mnaTearApplyMatrixStamp(SparseMatrixRow &tearMatrix) {
158 Math::addToMatrixElement(tearMatrix, mTearIdx, mTearIdx,
159 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.