DPsim
Loading...
Searching...
No Matches
EMT_Ph3_SeriesResistor.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
13// !!! TODO: Adaptions to use in EMT_Ph3 models phase-to-ground peak variables
14// !!! with initialization from phase-to-phase RMS variables
15
24
27 copy->setParameters(**mResistance);
28 return copy;
29}
30
32
34 (**mIntfVoltage)(0, 0) = phasorA.real();
35 Complex alpha(cos(2. / 3. * PI), sin(2. / 3. * PI));
36 (**mIntfVoltage)(1, 0) = Complex(phasorA * pow(alpha, 2)).real();
37 (**mIntfVoltage)(2, 0) = Complex(phasorA * alpha).real();
38
40
41 SPDLOG_LOGGER_INFO(mSLog,
42 "\n--- Initialization from powerflow ---"
43 "\nVoltage across amplitude and phase: \n{}"
44 "\nCurrent amplitude and phase: \n{}"
45 "\nTerminal 0 voltage amplitude and phase: \n{}"
46 "\nTerminal 1 voltage amplitude and phase: \n{}"
47 "\n--- Initialization from powerflow finished ---",
52}
53
55 Real omega, Real timeStep, Attribute<Matrix>::Ptr leftVector) {
57 **mRightVector = Matrix::Zero(0, 0);
58}
59
61 SparseMatrixRow &systemMatrix) {
62 Real conductance = 1. / **mResistance;
63
64 // Set diagonal entries
67 matrixNodeIndices(0), conductance);
70 matrixNodeIndices(1), conductance);
71 // Set off diagonal entries
74 matrixNodeIndices(1), -conductance);
76 matrixNodeIndices(0), -conductance);
77 }
78
80 SPDLOG_LOGGER_INFO(mSLog, "Add {} to {}, {}", conductance,
81 matrixNodeIndex(0, 0), matrixNodeIndex(0, 0));
83 SPDLOG_LOGGER_INFO(mSLog, "Add {} to {}, {}", conductance,
84 matrixNodeIndex(1, 0), matrixNodeIndex(1, 0));
86 SPDLOG_LOGGER_INFO(mSLog, "Add {} to {}, {}", -conductance,
87 matrixNodeIndex(0, 0), matrixNodeIndex(1, 0));
88 SPDLOG_LOGGER_INFO(mSLog, "Add {} to {}, {}", -conductance,
89 matrixNodeIndex(1, 0), matrixNodeIndex(0, 0));
90 }
91}
92
94 AttributeBase::List &prevStepDependencies,
95 AttributeBase::List &attributeDependencies,
96 AttributeBase::List &modifiedAttributes,
97 Attribute<Matrix>::Ptr &leftVector) {
98
99 attributeDependencies.push_back(leftVector);
100 modifiedAttributes.push_back(mIntfVoltage);
101 modifiedAttributes.push_back(mIntfCurrent);
102}
103
105 Real time, Int timeStepCount, Attribute<Matrix>::Ptr &leftVector) {
106 mnaCompUpdateVoltage(**leftVector);
107 mnaCompUpdateCurrent(**leftVector);
108}
109
111 // Voltage across component is defined as V1 - V0
112 **mIntfVoltage = Matrix::Zero(3, 1);
113 if (terminalNotGrounded(1)) {
114 (**mIntfVoltage)(0, 0) =
116 (**mIntfVoltage)(1, 0) =
118 (**mIntfVoltage)(2, 0) =
120 }
121 if (terminalNotGrounded(0)) {
122 (**mIntfVoltage)(0, 0) =
123 (**mIntfVoltage)(0, 0) -
125 (**mIntfVoltage)(1, 0) =
126 (**mIntfVoltage)(1, 0) -
128 (**mIntfVoltage)(2, 0) =
129 (**mIntfVoltage)(2, 0) -
131 }
132
133 SPDLOG_LOGGER_DEBUG(mSLog, "Voltage A: {}", (**mIntfVoltage)(0, 0));
134}
135
138
139 SPDLOG_LOGGER_DEBUG(mSLog, "Current A: {} < {}", (**mIntfCurrent)(0, 0));
140}
std::vector< Ptr > List
Definition Attribute.h:123
AttributePointer< Attribute< T > > Ptr
Definition Attribute.h:250
const CPS::Attribute< Real >::Ptr mResistance
Resistance [ohm].
Resistor(CPS::AttributeList::Ptr attributeList)
void mnaCompUpdateCurrent(const Matrix &leftVector) override
Update interface voltage from MNA system results.
void mnaCompInitialize(Real omega, Real timeStep, Attribute< Matrix >::Ptr leftVector) override
Initializes MNA specific variables.
void mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector) override
Add MNA post step dependencies.
SimPowerComp< Real >::Ptr clone(String name) override
Return new instance with the same parameters.
SeriesResistor(String uid, String name, Logger::Level logLevel=Logger::Level::off)
Defines UID, name and log level.
void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override
Stamps system matrix.
void initializeFromNodesAndTerminals(Real frequency) override
Initializes states from power flow data.
void mnaCompUpdateVoltage(const Matrix &leftVector) override
Update interface voltage from MNA system results.
void mnaCompPostStep(Real time, Int timeStepCount, Attribute< Matrix >::Ptr &leftVector) override
String uid()
Returns unique id.
AttributeList::Ptr mAttributes
Attribute List.
spdlog::level::level_enum Level
Definition Logger.h:33
static String phasorMatrixToString(const MatrixComp &mat)
Definition Logger.cpp:51
MNASimPowerComp(String uid, String name, Bool hasPreStep, Bool hasPostStep, Logger::Level logLevel)
Attribute< Matrix >::Ptr mRightVector
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)
UInt matrixNodeIndex(UInt nodeIndex)
const Attribute< MatrixVar< Real > >::Ptr mIntfCurrent
const Attribute< MatrixVar< Real > >::Ptr mIntfVoltage
MatrixComp initialVoltage(UInt index)
std::shared_ptr< SimPowerComp< VarType > > Ptr
Bool terminalNotGrounded(UInt index)
Complex initialSingleVoltage(UInt index)
void setTerminalNumber(UInt num)
std::vector< UInt > matrixNodeIndices(UInt index)
Logger::Level mLogLevel
Component logger control for internal variables.
Logger::Log mSLog
Component logger.
static std::shared_ptr< SeriesResistor > make(Args &&...args)
Definition PtrFactory.h:19
#define PI
Definition Definitions.h:43
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
double Real
Definition Definitions.h:62
int Int
Definition Definitions.h:61
std::complex< Real > Complex
Definition Definitions.h:63
Eigen::SparseMatrix< Real, Eigen::RowMajor > SparseMatrixRow
Sparse matrix for real numbers (row major).
Definition Definitions.h:74