DPsim
Loading...
Searching...
No Matches
EMT_Ph3_Capacitor.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, true, true, logLevel),
18 mEquivCurrent = Matrix::Zero(3, 1);
19 **mIntfVoltage = Matrix::Zero(3, 1);
20 **mIntfCurrent = Matrix::Zero(3, 1);
21}
22
24 auto copy = Capacitor::make(name, mLogLevel);
25 copy->setParameters(**mCapacitance);
26 return copy;
27}
29
30 Real omega = 2 * PI * frequency;
31 MatrixComp admittance = MatrixComp::Zero(3, 3);
32 admittance << Complex(0, omega * (**mCapacitance)(0, 0)),
33 Complex(0, omega * (**mCapacitance)(0, 1)),
34 Complex(0, omega * (**mCapacitance)(0, 2)),
35 Complex(0, omega * (**mCapacitance)(1, 0)),
36 Complex(0, omega * (**mCapacitance)(1, 1)),
37 Complex(0, omega * (**mCapacitance)(1, 2)),
38 Complex(0, omega * (**mCapacitance)(2, 0)),
39 Complex(0, omega * (**mCapacitance)(2, 1)),
40 Complex(0, omega * (**mCapacitance)(2, 2));
41
42 MatrixComp vInitABC = Matrix::Zero(3, 1);
43 vInitABC(0, 0) = RMS3PH_TO_PEAK1PH * initialSingleVoltage(1) -
45 vInitABC(1, 0) = vInitABC(0, 0) * SHIFT_TO_PHASE_B;
46 vInitABC(2, 0) = vInitABC(0, 0) * SHIFT_TO_PHASE_C;
47 **mIntfVoltage = vInitABC.real();
48 **mIntfCurrent = (admittance * vInitABC).real();
49
50 SPDLOG_LOGGER_INFO(mSLog,
51 "\nCapacitance [F]: {:s}"
52 "\nAdmittance [S]: {:s}",
54 Logger::matrixCompToString(admittance));
55 SPDLOG_LOGGER_INFO(
56 mSLog,
57 "\n--- Initialization from powerflow ---"
58 "\nVoltage across: {:s}"
59 "\nCurrent: {:s}"
60 "\nTerminal 0 voltage: {:s}"
61 "\nTerminal 1 voltage: {:s}"
62 "\n--- Initialization from powerflow finished ---",
67}
68
70 Attribute<Matrix>::Ptr leftVector) {
72 mEquivCond = (2.0 * **mCapacitance) / timeStep;
73 // Update internal state
75}
76
78 SparseMatrixRow &systemMatrix) {
80 mEquivCond, systemMatrix, matrixNodeIndex(0), matrixNodeIndex(1),
82
83 SPDLOG_LOGGER_INFO(mSLog, "\nEquivalent Conductance: {:s}",
85}
86
88 Matrix &rightVector) {
90 if (terminalNotGrounded(0)) {
91 Math::setVectorElement(rightVector, matrixNodeIndex(0, 0),
92 mEquivCurrent(0, 0));
93 Math::setVectorElement(rightVector, matrixNodeIndex(0, 1),
94 mEquivCurrent(1, 0));
95 Math::setVectorElement(rightVector, matrixNodeIndex(0, 2),
96 mEquivCurrent(2, 0));
97 }
98 if (terminalNotGrounded(1)) {
99 Math::setVectorElement(rightVector, matrixNodeIndex(1, 0),
100 -mEquivCurrent(0, 0));
101 Math::setVectorElement(rightVector, matrixNodeIndex(1, 1),
102 -mEquivCurrent(1, 0));
103 Math::setVectorElement(rightVector, matrixNodeIndex(1, 2),
104 -mEquivCurrent(2, 0));
105 }
106 SPDLOG_LOGGER_DEBUG(mSLog, "\nEquivalent Current: {:s}",
108}
109
111 AttributeBase::List &prevStepDependencies,
112 AttributeBase::List &attributeDependencies,
113 AttributeBase::List &modifiedAttributes) {
114 // actually depends on C, but then we'd have to modify the system matrix anyway
115 prevStepDependencies.push_back(mIntfCurrent);
116 prevStepDependencies.push_back(mIntfVoltage);
117 modifiedAttributes.push_back(mRightVector);
118}
119
123
125 AttributeBase::List &prevStepDependencies,
126 AttributeBase::List &attributeDependencies,
127 AttributeBase::List &modifiedAttributes,
128 Attribute<Matrix>::Ptr &leftVector) {
129 attributeDependencies.push_back(leftVector);
130 modifiedAttributes.push_back(mIntfVoltage);
131 modifiedAttributes.push_back(mIntfCurrent);
132}
133
135 Attribute<Matrix>::Ptr &leftVector) {
136 mnaCompUpdateVoltage(**leftVector);
137 mnaCompUpdateCurrent(**leftVector);
138}
139
141 // v1 - v0
142 **mIntfVoltage = Matrix::Zero(3, 1);
143 if (terminalNotGrounded(1)) {
144 (**mIntfVoltage)(0, 0) =
146 (**mIntfVoltage)(1, 0) =
148 (**mIntfVoltage)(2, 0) =
150 }
151 if (terminalNotGrounded(0)) {
152 (**mIntfVoltage)(0, 0) =
153 (**mIntfVoltage)(0, 0) -
155 (**mIntfVoltage)(1, 0) =
156 (**mIntfVoltage)(1, 0) -
158 (**mIntfVoltage)(2, 0) =
159 (**mIntfVoltage)(2, 0) -
161 }
162}
163
166 SPDLOG_LOGGER_DEBUG(mSLog, "\nCurrent: {:s}",
168}
std::vector< Ptr > List
Definition Attribute.h:123
AttributePointer< Attribute< T > > Ptr
Definition Attribute.h:250
const CPS::Attribute< Matrix >::Ptr mCapacitance
Capacitance [F].
Capacitor(String uid, String name, Logger::Level logLevel=Logger::Level::off)
Defines UID, name and logging level.
void mnaCompAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes) override
Add MNA pre step dependencies.
void mnaCompUpdateVoltage(const Matrix &leftVector) override
Update interface voltage from MNA system result.
void mnaCompPreStep(Real time, Int timeStepCount) override
MNA pre step operations.
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
Update interface current from MNA system result.
void mnaCompInitialize(Real omega, Real timeStep, Attribute< Matrix >::Ptr leftVector) override
Initializes internal variables of the component.
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 mnaCompPostStep(Real time, Int timeStepCount, Attribute< Matrix >::Ptr &leftVector) override
MNA post step operations.
void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override
Stamps system matrix.
void initializeFromNodesAndTerminals(Real frequency) override
Initializes component from power flow data.
void mnaCompApplyRightSideVectorStamp(Matrix &rightVector) override
Stamps right side (source) vector.
Matrix mEquivCurrent
DC equivalent current source [A].
Matrix mEquivCond
Equivalent conductance [S].
String uid()
Returns unique id.
AttributeList::Ptr mAttributes
Attribute List.
spdlog::level::level_enum Level
Definition Logger.h:33
static String matrixCompToString(const MatrixComp &mat)
Definition Logger.cpp:37
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 setVectorElement(Matrix &mat, Matrix::Index row, Complex value, Int maxFreq=1, Int freqIdx=0, Matrix::Index colOffset=0)
Definition MathUtils.cpp:73
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< Capacitor > make(Args &&...args)
Definition PtrFactory.h:19
#define PI
Definition Definitions.h:43
#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
double Real
Definition Definitions.h:62
int Int
Definition Definitions.h:61
std::complex< Real > Complex
Definition Definitions.h:63
Eigen::Matrix< Complex, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor > MatrixComp
Dense matrix for complex numbers.
Definition Definitions.h:84
Eigen::SparseMatrix< Real, Eigen::RowMajor > SparseMatrixRow
Sparse matrix for real numbers (row major).
Definition Definitions.h:74