DPsim
Loading...
Searching...
No Matches
EMT_Ph3_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
10
11using namespace CPS;
12
14 : MNASimPowerComp<Real>(uid, name, false, true, logLevel),
18 **mIntfVoltage = Matrix::Zero(3, 1);
19 **mIntfCurrent = Matrix::Zero(3, 1);
20}
21
23 auto copy = Resistor::make(name, mLogLevel);
24 copy->setParameters(**mResistance);
25 return copy;
26}
27
29
30 // IntfVoltage initialization for each phase
31 MatrixComp vInitABC = Matrix::Zero(3, 1);
32 vInitABC(0, 0) = RMS3PH_TO_PEAK1PH * initialSingleVoltage(1) -
34 vInitABC(1, 0) = vInitABC(0, 0) * SHIFT_TO_PHASE_B;
35 vInitABC(2, 0) = vInitABC(0, 0) * SHIFT_TO_PHASE_C;
36 **mIntfVoltage = vInitABC.real();
37
38 // TODO: here, the custom implementation for matrix inversion is still used, because mResistance is still a generic matrix.
39 // Change the definition in future, if valid. The author currently doesn't know if this is allowed (mResistance is defined in Base)
40 // This is also done in the following
41 Matrix mResistanceInv = Matrix::Zero(3, 3);
42 Math::invertMatrix(**mResistance, mResistanceInv);
43 **mIntfCurrent = (mResistanceInv * vInitABC).real();
44
45 SPDLOG_LOGGER_INFO(mSLog,
46 "\nResistance [Ohm]: {:s}"
47 "\nConductance [S]: {:s}",
49 Logger::matrixToString(mResistanceInv));
50 SPDLOG_LOGGER_INFO(
51 mSLog,
52 "\n--- Initialization from powerflow ---"
53 "\nVoltage across: {:s}"
54 "\nCurrent: {:s}"
55 "\nTerminal 0 voltage: {:s}"
56 "\nTerminal 1 voltage: {:s}"
57 "\n--- Initialization from powerflow finished ---",
62}
63
65 Attribute<Matrix>::Ptr leftVector) {
67 **mRightVector = Matrix::Zero(0, 0);
68}
69
71 SparseMatrixRow &systemMatrix) {
72 MatrixFixedSize<3, 3> conductance = Matrix::Zero(3, 3);
73 conductance = (**mResistance).inverse();
74
76 conductance, systemMatrix, matrixNodeIndex(0), matrixNodeIndex(1),
78
79 SPDLOG_LOGGER_INFO(mSLog, "\nConductance matrix: {:s}",
80 Logger::matrixToString(conductance));
81}
82
84 AttributeBase::List &prevStepDependencies,
85 AttributeBase::List &attributeDependencies,
86 AttributeBase::List &modifiedAttributes,
87 Attribute<Matrix>::Ptr &leftVector) {
88 attributeDependencies.push_back(leftVector);
89 modifiedAttributes.push_back(mIntfVoltage);
90 modifiedAttributes.push_back(mIntfCurrent);
91}
92
94 Attribute<Matrix>::Ptr &leftVector) {
95 mnaCompUpdateVoltage(**leftVector);
96 mnaCompUpdateCurrent(**leftVector);
97}
98
100 // v1 - v0
101 **mIntfVoltage = Matrix::Zero(3, 1);
102 if (terminalNotGrounded(1)) {
103 (**mIntfVoltage)(0, 0) =
105 (**mIntfVoltage)(1, 0) =
107 (**mIntfVoltage)(2, 0) =
109 }
110 if (terminalNotGrounded(0)) {
111 (**mIntfVoltage)(0, 0) =
112 (**mIntfVoltage)(0, 0) -
114 (**mIntfVoltage)(1, 0) =
115 (**mIntfVoltage)(1, 0) -
117 (**mIntfVoltage)(2, 0) =
118 (**mIntfVoltage)(2, 0) -
120 }
121 SPDLOG_LOGGER_DEBUG(mSLog, "\nVoltage: {:s}",
123 mSLog->flush();
124}
125
127 Matrix resistanceInv = Matrix::Zero(3, 3);
128 Math::invertMatrix(**mResistance, resistanceInv);
129 **mIntfCurrent = resistanceInv * **mIntfVoltage;
130 SPDLOG_LOGGER_DEBUG(mSLog, "\nCurrent: {:s}",
132 mSLog->flush();
133}
134
135// #### Tear Methods ####
137 MatrixFixedSizeComp<3, 3> conductance = Matrix::Zero(3, 3);
138 conductance.real() = (**mResistance).inverse();
139 // Set diagonal entries
140 Math::addToMatrixElement(tearMatrix, mTearIdx * 3, mTearIdx * 3,
141 1. / conductance(0, 0).real());
142 Math::addToMatrixElement(tearMatrix, mTearIdx * 3 + 1, mTearIdx * 3 + 1,
143 1. / conductance(1, 1).real());
144 Math::addToMatrixElement(tearMatrix, mTearIdx * 3 + 2, mTearIdx * 3 + 2,
145 1. / conductance(2, 2).real());
146}
std::vector< Ptr > List
Definition Attribute.h:123
AttributePointer< Attribute< T > > Ptr
Definition Attribute.h:250
const CPS::Attribute< Matrix >::Ptr mResistance
Resistance [ohm].
void initializeFromNodesAndTerminals(Real frequency) override
Initializes component from power flow data.
void mnaCompPostStep(Real time, Int timeStepCount, Attribute< Matrix >::Ptr &leftVector) override
MNA pre and post step operations.
void mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector) override
add MNA pre and post step dependencies
SimPowerComp< Real >::Ptr clone(String name) override
Returns a modified copy of the component with the given suffix added to the name and without.
void mnaTearApplyMatrixStamp(SparseMatrixRow &tearMatrix) override
void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override
Stamps system matrix.
void mnaCompInitialize(Real omega, Real timeStep, Attribute< Matrix >::Ptr leftSideVector) override
Initializes internal variables of the component.
Resistor(String uid, String name, Logger::Level logLevel=Logger::Level::off)
Defines UID, name, component parameters and logging level.
void mnaCompUpdateVoltage(const Matrix &leftVector) override
Update interface voltage from MNA system result.
void mnaCompUpdateCurrent(const Matrix &leftVector) override
Update interface current from MNA system result.
String uid()
Returns unique id.
AttributeList::Ptr mAttributes
Attribute List.
spdlog::level::level_enum Level
Definition Logger.h:33
static String matrixToString(const Matrix &mat)
Definition Logger.cpp:31
static String phasorToString(const Complex &num)
Definition Logger.cpp:57
MNASimPowerComp(String uid, String name, Bool hasPreStep, Bool hasPostStep, Logger::Level logLevel)
Attribute< Matrix >::Ptr mRightVector
static void stampConductanceMatrix(const Matrix &conductanceMat, SparseMatrixRow &mat, UInt node1Index, UInt node2Index, Bool isTerminal1NotGrounded, Bool isTerminal2NotGrounded, const Logger::Log &mSLog)
static Real realFromVectorElement(const Matrix &mat, Matrix::Index row)
static void addToMatrixElement(SparseMatrixRow &mat, Matrix::Index row, Matrix::Index column, Complex value, Int maxFreq=1, Int freqIdx=0)
static void invertMatrix(const Matrix &mat, Matrix &matInv)
UInt matrixNodeIndex(UInt nodeIndex)
const Attribute< MatrixVar< Real > >::Ptr mIntfCurrent
const Attribute< MatrixVar< Real > >::Ptr mIntfVoltage
std::shared_ptr< SimPowerComp< VarType > > Ptr
Bool terminalNotGrounded(UInt index)
Complex initialSingleVoltage(UInt index)
void setTerminalNumber(UInt num)
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
#define RMS3PH_TO_PEAK1PH
Definition Definitions.h:50
#define SHIFT_TO_PHASE_C
Definition Definitions.h:47
#define SHIFT_TO_PHASE_B
Definition Definitions.h:46
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::Matrix< Real, rows, cols, Eigen::ColMajor > MatrixFixedSize
Dense matrix for real numbers with fixed dimension.
double Real
Definition Definitions.h:62
int Int
Definition Definitions.h:61
Eigen::Matrix< Complex, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor > MatrixComp
Dense matrix for complex numbers.
Definition Definitions.h:84
Eigen::Matrix< Complex, rows, cols, Eigen::ColMajor > MatrixFixedSizeComp
Dense matrix for complex numbers with fixed dimension.
Eigen::SparseMatrix< Real, Eigen::RowMajor > SparseMatrixRow
Sparse matrix for real numbers (row major).
Definition Definitions.h:74