DPsim
Loading...
Searching...
No Matches
SP_Ph1_Resistor.cpp
Go to the documentation of this file.
1/* Copyright 2017-2021 Institute for Automation of Complex Power Systems,
2 * EONERC, RWTH Aachen University
3 *
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
7 *********************************************************************************/
8
11
12using namespace CPS;
13
15 : MNASimPowerComp<Complex>(uid, name, false, true, logLevel),
18 **mIntfVoltage = MatrixComp::Zero(1, 1);
19 **mIntfCurrent = MatrixComp::Zero(1, 1);
20}
21
23 auto copy = Resistor::make(name, mLogLevel);
24 copy->setParameters(**mResistance);
25 return copy;
26}
27
29
30 (**mIntfVoltage)(0, 0) = initialSingleVoltage(1) - initialSingleVoltage(0);
32
33 SPDLOG_LOGGER_INFO(mSLog, "\nResistance [Ohm]: {:s}",
35 SPDLOG_LOGGER_INFO(mSLog,
36 "\n--- Initialization from powerflow ---"
37 "\nVoltage across: {:s}"
38 "\nCurrent: {:s}"
39 "\nTerminal 0 voltage: {:s}"
40 "\nTerminal 1 voltage: {:s}"
41 "\n--- Initialization from powerflow finished ---",
46}
47
48// #### Powerflow section ####
49
51 mBaseVoltage = baseVoltage;
52}
53
55 SPDLOG_LOGGER_INFO(mSLog, "#### Calculate Per Unit Parameters for {}",
56 **mName);
57 mBaseApparentPower = baseApparentPower;
58 SPDLOG_LOGGER_INFO(mSLog, "Base Power={} [VA]", baseApparentPower);
59
60 mBaseImpedance = mBaseVoltage * mBaseVoltage / mBaseApparentPower;
61 mBaseAdmittance = 1.0 / mBaseImpedance;
62 mBaseCurrent = baseApparentPower /
63 (mBaseVoltage *
64 sqrt(3)); // I_base=(S_threephase/3)/(V_line_to_line/sqrt(3))
65 SPDLOG_LOGGER_INFO(mSLog, "Base Voltage={} [V] Base Impedance={} [Ohm]",
66 mBaseVoltage, mBaseImpedance);
67
68 mResistancePerUnit = **mResistance / mBaseImpedance;
69 mConductancePerUnit = 1. / mResistancePerUnit;
70 SPDLOG_LOGGER_INFO(mSLog, "Resistance={} [pu] Conductance={} [pu]",
71 mResistancePerUnit, mConductancePerUnit);
72}
73
75 int bus1 = this->matrixNodeIndex(0);
76 Complex Y_element = Complex(mConductancePerUnit, 0);
77
78 if (!Math::isFinite(Y_element)) {
79 SPDLOG_LOGGER_ERROR(mSLog,
80 "Resistor {}: non-finite per-unit admittance {} at "
81 "node {}",
82 this->name(), Logger::complexToString(Y_element), bus1);
84 }
85
86 //set the circuit matrix values
87 Y.coeffRef(bus1, bus1) += Y_element;
88 SPDLOG_LOGGER_INFO(mSLog, "#### Y matrix stamping: {}", Y_element);
89}
90
91// #### MNA section ####
92
94 Attribute<Matrix>::Ptr leftVector) {
96 **mRightVector = Matrix::Zero(0, 0);
97
98 SPDLOG_LOGGER_INFO(mSLog,
99 "\n--- MNA initialization ---"
100 "\nInitial voltage {:s}"
101 "\nInitial current {:s}"
102 "\n--- MNA initialization finished ---",
105}
106
108 SparseMatrixRow &systemMatrix) {
109 Complex conductance = Complex(1. / **mResistance, 0);
110
111 MNAStampUtils::stampAdmittance(conductance, systemMatrix, matrixNodeIndex(0),
114}
115
117 AttributeBase::List &prevStepDependencies,
118 AttributeBase::List &attributeDependencies,
119 AttributeBase::List &modifiedAttributes,
120 Attribute<Matrix>::Ptr &leftVector) {
121 attributeDependencies.push_back(leftVector);
122 modifiedAttributes.push_back(mIntfVoltage);
123 modifiedAttributes.push_back(mIntfCurrent);
124}
125
127 Attribute<Matrix>::Ptr &leftVector) {
128 this->mnaUpdateVoltage(**leftVector);
129 this->mnaUpdateCurrent(**leftVector);
130}
131
133 // v1 - v0
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) =
141 (**mIntfVoltage)(0, freq) -
143 mNumFreqs, freq);
144
145 SPDLOG_LOGGER_DEBUG(mSLog, "Voltage {:s}",
147 }
148}
149
151 for (UInt freq = 0; freq < mNumFreqs; freq++) {
152 (**mIntfCurrent)(0, freq) = (**mIntfVoltage)(0, freq) / **mResistance;
153 SPDLOG_LOGGER_DEBUG(mSLog, "Current {:s}",
155 }
156}
157
std::vector< Ptr > List
Definition Attribute.h:123
AttributePointer< Attribute< T > > Ptr
Definition Attribute.h:250
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.
spdlog::level::level_enum Level
Definition Logger.h:33
static String complexToString(const Complex &num)
Definition Logger.cpp:63
static String realToString(const Real &num)
Definition Logger.cpp:69
static String phasorToString(const Complex &num)
Definition Logger.cpp:57
void mnaUpdateCurrent(const Matrix &leftVector) final
void mnaUpdateVoltage(const Matrix &leftVector) final
MNASimPowerComp(String uid, String name, Bool hasPreStep, Bool hasPostStep, Logger::Level logLevel)
Attribute< Matrix >::Ptr mRightVector
static void stampAdmittance(Complex admittance, 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)
Definition MathUtils.cpp:94
static bool isFinite(Real value)
Definition MathUtils.cpp:63
static void addToMatrixElement(SparseMatrixRow &mat, Matrix::Index row, Matrix::Index column, Complex value, Int maxFreq=1, Int freqIdx=0)
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 mnaCompInitialize(Real omega, Real timeStep, Attribute< Matrix >::Ptr leftVector)
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 mnaTearApplyMatrixStamp(SparseMatrixRow &tearMatrix)
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.
UInt matrixNodeIndex(UInt nodeIndex)
const Attribute< MatrixVar< Complex > >::Ptr mIntfCurrent
const Attribute< MatrixVar< Complex > >::Ptr mIntfVoltage
std::shared_ptr< SimPowerComp< VarType > > Ptr
Bool terminalNotGrounded(UInt index)
Complex initialSingleVoltage(UInt index)
Logger::Level mLogLevel
Component logger control for internal variables.
Logger::Log mSLog
Component logger.
static std::shared_ptr< Resistor > make(Args &&...args)
Definition PtrFactory.h:19
Eigen::Matrix< Real, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor > Matrix
Dense matrix for real numbers.
Definition Definitions.h:81
std::string String
Definition Definitions.h:65
Eigen::SparseMatrix< Complex, Eigen::RowMajor > SparseMatrixCompRow
Sparse matrix for complex numbers (row major).
Definition Definitions.h:78
double Real
Definition Definitions.h:62
int Int
Definition Definitions.h:61
std::complex< Real > Complex
Definition Definitions.h:63
unsigned int UInt
Definition Definitions.h:60
Eigen::SparseMatrix< Real, Eigen::RowMajor > SparseMatrixRow
Sparse matrix for real numbers (row major).
Definition Definitions.h:74