DPsim
Loading...
Searching...
No Matches
SP_Ph1_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
11
12using namespace CPS;
13
15 : MNASimPowerComp<Complex>(uid, name, false, true, logLevel),
17 **mIntfVoltage = MatrixComp::Zero(1, 1);
18 **mIntfCurrent = MatrixComp::Zero(1, 1);
20}
21
23 auto copy = Capacitor::make(name, mLogLevel);
24 copy->setParameters(**mCapacitance);
25 return copy;
26}
27
29
30 Real omega = 2 * PI * frequency;
31 mSusceptance = Complex(0, omega * **mCapacitance);
32 // Capacitor admittance is the susceptance (jwC); compute it directly to
33 // avoid manufacturing NaN at C = 0 via a 1/impedance round-trip.
35 (**mIntfVoltage)(0, 0) = initialSingleVoltage(1) - initialSingleVoltage(0);
37
38 SPDLOG_LOGGER_INFO(mSLog,
39 "\nCapacitance [F]: {:s}"
40 "\nAdmittance [S]: {:s}",
43 SPDLOG_LOGGER_INFO(mSLog,
44 "\n--- Initialization from powerflow ---"
45 "\nVoltage across: {:s}"
46 "\nCurrent: {:s}"
47 "\nTerminal 0 voltage: {:s}"
48 "\nTerminal 1 voltage: {:s}"
49 "\n--- Initialization from powerflow finished ---",
54}
55
56// #### MNA section ####
57
59 Attribute<Matrix>::Ptr leftVector) {
61 SPDLOG_LOGGER_INFO(mSLog,
62 "\n--- MNA initialization ---"
63 "\nInitial voltage {:s}"
64 "\nInitial current {:s}"
65 "\n--- MNA initialization finished ---",
68}
69
76
78 AttributeBase::List &prevStepDependencies,
79 AttributeBase::List &attributeDependencies,
80 AttributeBase::List &modifiedAttributes,
81 Attribute<Matrix>::Ptr &leftVector) {
82 attributeDependencies.push_back(leftVector);
83 modifiedAttributes.push_back(mIntfVoltage);
84 modifiedAttributes.push_back(mIntfCurrent);
85}
86
88 Attribute<Matrix>::Ptr &leftVector) {
89 this->mnaUpdateVoltage(**leftVector);
90 this->mnaUpdateCurrent(**leftVector);
91}
92
94 // v1 - v0
95 **mIntfVoltage = Matrix::Zero(3, 1);
96 if (terminalNotGrounded(1)) {
97 (**mIntfVoltage)(0, 0) =
99 }
100 if (terminalNotGrounded(0)) {
101 (**mIntfVoltage)(0, 0) =
102 (**mIntfVoltage)(0, 0) -
104 }
105}
106
110
111// #### Powerflow section ####
112
114 mBaseVoltage = baseVoltage;
115}
116
118 SPDLOG_LOGGER_INFO(mSLog, "#### Calculate Per Unit Parameters for {}",
119 **mName);
120 mBaseApparentPower = baseApparentPower;
121 SPDLOG_LOGGER_INFO(mSLog, "Base Power={} [VA]", baseApparentPower);
122
125 mBaseCurrent = baseApparentPower /
126 (mBaseVoltage *
127 sqrt(3)); // I_base=(S_threephase/3)/(V_line_to_line/sqrt(3))
128 SPDLOG_LOGGER_INFO(mSLog, "Base Voltage={} [V] Base Impedance={} [Ohm]",
130
132 SPDLOG_LOGGER_INFO(mSLog, "Admittance={} [pu]",
134}
135
137 int bus1 = this->matrixNodeIndex(0);
138
140 SPDLOG_LOGGER_ERROR(mSLog,
141 "Capacitor {}: non-finite per-unit admittance {} at "
142 "node {}",
143 this->name(),
146 }
147
148 //set the circuit matrix values
149 Y.coeffRef(bus1, bus1) += mAdmittancePerUnit;
150 SPDLOG_LOGGER_INFO(mSLog, "#### Y matrix stamping: {}", mAdmittancePerUnit);
151}
std::vector< Ptr > List
Definition Attribute.h:123
AttributePointer< Attribute< T > > Ptr
Definition Attribute.h:250
const CPS::Attribute< Real >::Ptr mCapacitance
Capacitance [F].
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)
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
void mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector) override
Add MNA post step dependencies.
void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override
Stamps system matrix.
void mnaCompUpdateVoltage(const Matrix &leftVector) override
Update interface voltage from MNA system result.
void setBaseVoltage(Real baseVoltage)
Set base voltage.
Real mBaseApparentPower
base apparent power[VA]
void mnaCompUpdateCurrent(const Matrix &leftVector) override
Update interface current from MNA system result.
SimPowerComp< Complex >::Ptr clone(String name) override
Returns a modified copy of the component with the given suffix added to the name and without.
Capacitor(String uid, String name, Logger::Level logLevel=Logger::Level::off)
Defines UID, name and logging level.
void calculatePerUnitParameters(Real baseApparentPower)
Initializes component from power flow data.
Complex mSusceptance
Susceptance [S].
Complex mAdmittance
Admittance [S].
Real mBaseAdmittance
base admittance [S]
void initializeFromNodesAndTerminals(Real frequency) override
Initializes component from power flow data.
void mnaCompPostStep(Real time, Int timeStepCount, Attribute< Matrix >::Ptr &leftVector) override
MNA post step operations.
Complex mAdmittancePerUnit
Admittance [pu].
Real mBaseImpedance
base impedance [ohm]
void mnaCompInitialize(Real omega, Real timeStep, Attribute< Matrix >::Ptr leftVector) override
Initializes internal variables of the component.
Real mBaseVoltage
base voltage [V]
void pfApplyAdmittanceMatrixStamp(SparseMatrixCompRow &Y) override
Stamps admittance matrix.
Real mBaseCurrent
base current [A]
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< Capacitor > 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
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
Eigen::SparseMatrix< Real, Eigen::RowMajor > SparseMatrixRow
Sparse matrix for real numbers (row major).
Definition Definitions.h:74