DPsim
Loading...
Searching...
No Matches
DP_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 *********************************************************************************/
9
10using namespace CPS;
11
13 Logger::Level logLevel)
14 : MNASimPowerComp<Complex>(uid, name, false, true, logLevel),
18 **mIntfVoltage = MatrixComp::Zero(3, 1);
19 **mIntfCurrent = MatrixComp::Zero(3, 1);
20}
21
24 copy->setParameters(**mResistance);
25 return copy;
26}
27
29
30 mTerminals[0]->setPhaseType(PhaseType::ABC);
31 mTerminals[1]->setPhaseType(PhaseType::ABC);
32
33 Matrix impedance = Matrix::Zero(3, 1);
34 impedance << **mResistance, **mResistance, **mResistance;
35 (**mIntfVoltage)(0, 0) = initialSingleVoltage(1) - initialSingleVoltage(0);
36
37 Real voltMag = Math::abs((**mIntfVoltage)(0, 0));
38 Real voltPhase = Math::phase((**mIntfVoltage)(0, 0));
39 (**mIntfVoltage)(1, 0) = Complex(voltMag * cos(voltPhase - 2. / 3. * PI),
40 voltMag * sin(voltPhase - 2. / 3. * PI));
41 (**mIntfVoltage)(2, 0) = Complex(voltMag * cos(voltPhase + 2. / 3. * PI),
42 voltMag * sin(voltPhase + 2. / 3. * PI));
43
44 **mIntfCurrent = impedance.cwiseInverse().cwiseProduct(**mIntfVoltage);
45
46 SPDLOG_LOGGER_INFO(mSLog,
47 "\n--- Initialization from powerflow ---"
48 "\nVoltage across amplitude and phase: \n{:s}"
49 "\nCurrent amplitude and phase: \n{:s}"
50 "\nTerminal 0 voltage amplitude and phase: \n{:s}"
51 "\nTerminal 1 voltage amplitude and phase: \n{:s}"
52 "\n--- Initialization from powerflow finished ---",
57}
58
60 Real omega, Real timeStep, Attribute<Matrix>::Ptr leftVector) {
62 **mRightVector = Matrix::Zero(0, 0);
63}
64
66 SparseMatrixRow &systemMatrix) {
67 Complex conductance = {(1. / **mResistance), 0};
68
70 //if (terminalNotGrounded(0))
71 // Math::addToMatrixElement(systemMatrix, matrixNodeIndices(0), matrixNodeIndices(0), conductance);
72 //if (terminalNotGrounded(1))
73 // Math::addToMatrixElement(systemMatrix, matrixNodeIndices(1), matrixNodeIndices(1), conductance);
75 //if (terminalNotGrounded(0) && terminalNotGrounded(1)) {
76 // Math::addToMatrixElement(systemMatrix, matrixNodeIndices(0), matrixNodeIndices(1), -conductance);
77 // Math::addToMatrixElement(systemMatrix, matrixNodeIndices(1), matrixNodeIndices(0), -conductance);
78 //}
79 // Set diagonal entries
80 if (terminalNotGrounded(0)) {
82 matrixNodeIndices(0), conductance);
83 }
84 if (terminalNotGrounded(1)) {
86 matrixNodeIndices(1), conductance);
87 }
88 // Set off diagonal entries
91 matrixNodeIndices(1), -conductance);
93 matrixNodeIndices(0), -conductance);
94 }
95
97 SPDLOG_LOGGER_INFO(mSLog, "Add {} to {}, {}", conductance,
98 matrixNodeIndex(0, 0), matrixNodeIndex(0, 0));
100 SPDLOG_LOGGER_INFO(mSLog, "Add {} to {}, {}", conductance,
101 matrixNodeIndex(1, 0), matrixNodeIndex(1, 0));
103 SPDLOG_LOGGER_INFO(mSLog, "Add {} to {}, {}", -conductance,
104 matrixNodeIndex(0, 0), matrixNodeIndex(1, 0));
105 SPDLOG_LOGGER_INFO(mSLog, "Add {} to {}, {}", -conductance,
106 matrixNodeIndex(1, 0), matrixNodeIndex(0, 0));
107 }
108}
109
111 AttributeBase::List &prevStepDependencies,
112 AttributeBase::List &attributeDependencies,
113 AttributeBase::List &modifiedAttributes,
114 Attribute<Matrix>::Ptr &leftVector) {
115 attributeDependencies.push_back(leftVector);
116 modifiedAttributes.push_back(mIntfVoltage);
117 modifiedAttributes.push_back(mIntfCurrent);
118}
119
121 Real time, Int timeStepCount, Attribute<Matrix>::Ptr &leftVector) {
122 mnaCompUpdateVoltage(**leftVector);
123 mnaCompUpdateCurrent(**leftVector);
124}
125
127 // Voltage across component is defined as V1 - V0
128 **mIntfVoltage = MatrixComp::Zero(3, 1);
129 if (terminalNotGrounded(1)) {
130 (**mIntfVoltage)(0, 0) =
132 (**mIntfVoltage)(1, 0) =
134 (**mIntfVoltage)(2, 0) =
136 }
137 if (terminalNotGrounded(0)) {
138 (**mIntfVoltage)(0, 0) =
139 (**mIntfVoltage)(0, 0) -
141 (**mIntfVoltage)(1, 0) =
142 (**mIntfVoltage)(1, 0) -
144 (**mIntfVoltage)(2, 0) =
145 (**mIntfVoltage)(2, 0) -
147 }
148
149 SPDLOG_LOGGER_DEBUG(mSLog, "Voltage A: {} < {}",
150 std::abs((**mIntfVoltage)(0, 0)),
151 std::arg((**mIntfVoltage)(0, 0)));
152}
153
156
157 SPDLOG_LOGGER_DEBUG(mSLog, "Current A: {} < {}",
158 std::abs((**mIntfCurrent)(0, 0)),
159 std::arg((**mIntfCurrent)(0, 0)));
160}
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)
SeriesResistor(String uid, String name, Logger::Level logLevel=Logger::Level::off)
Defines UID, name and logging level.
void initializeFromNodesAndTerminals(Real frequency) override
Initializes component from power flow data.
SimPowerComp< Complex >::Ptr clone(String name) override
Returns a modified copy of the component with the given suffix added to the name and without.
void mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector) override
Add MNA post step dependencies.
void mnaCompUpdateCurrent(const Matrix &leftVector) override
void mnaCompPostStep(Real time, Int timeStepCount, Attribute< Matrix >::Ptr &leftVector) override
void mnaCompUpdateVoltage(const Matrix &leftVector) override
void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override
Stamps system matrix.
void mnaCompInitialize(Real omega, Real timeStep, 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 Complex complexFromVectorElement(const Matrix &mat, Matrix::Index row, Int maxFreq=1, Int freqIdx=0)
Definition MathUtils.cpp:94
static Real phase(Complex value)
Definition MathUtils.cpp:23
static Real abs(Complex value)
Definition MathUtils.cpp:27
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< Complex > >::Ptr mIntfCurrent
SimTerminal< Complex >::List mTerminals
const Attribute< MatrixVar< Complex > >::Ptr mIntfVoltage
MatrixComp initialVoltage(UInt index)
std::shared_ptr< SimPowerComp< VarType > > Ptr
Bool terminalNotGrounded(UInt index)
Complex initialSingleVoltage(UInt index)
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