DPsim
Loading...
Searching...
No Matches
DP_Ph1_Shunt.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 : Shunt(uid, name, true, logLevel) {}
16
18 Logger::Level logLevel)
19 : CompositePowerComp<Complex>(uid, name, true, true, logLevel),
20 mUseSubcomponents(useSubcomponents),
21 mConductance(mAttributes->create<Real>("G")),
22 mSusceptance(mAttributes->create<Real>("B")) {
23
24 SPDLOG_LOGGER_INFO(mSLog, "Create {} of type {}", this->type(), name);
26}
27
28void DP::Ph1::Shunt::setParameters(Real conductance, Real susceptance) {
29 **mConductance = conductance;
30 **mSusceptance = susceptance;
31 SPDLOG_LOGGER_INFO(mSLog, "Conductance={} [S] Susceptance={} [Ohm] ",
32 conductance, susceptance);
33 mParametersSet = true;
34}
35
38
39 // Static calculation
40 Real omega = 2. * PI * frequency;
41 Complex admittance = Complex(**mConductance, **mSusceptance);
42 (**mIntfVoltage)(0, 0) = initialSingleVoltage(0);
43 (**mIntfCurrent)(0, 0) = (**mIntfVoltage)(0, 0) * admittance;
44
45 if (mUseSubcomponents && **mConductance > 0) {
47 std::make_shared<DP::Ph1::Resistor>(**mName + "_Res", mLogLevel);
49 mSubResistor->setParameters(1. / **mConductance);
50 mSubResistor->initialize(mFrequencies);
51 mSubResistor->initializeFromNodesAndTerminals(frequency);
54 }
55
56 if (**mSusceptance > 0) {
57 mDirectCapacitance = **mSusceptance / omega;
58 if (mUseSubcomponents) {
60 std::make_shared<DP::Ph1::Capacitor>(**mName + "_cap", mLogLevel);
61 mSubCapacitor->setParameters(mDirectCapacitance);
62 mSubCapacitor->connect(
64 mSubCapacitor->initialize(mFrequencies);
65 mSubCapacitor->initializeFromNodesAndTerminals(frequency);
69 }
70 }
71
72 SPDLOG_LOGGER_INFO(mSLog,
73 "\n--- Initialization from powerflow ---"
74 "\nVoltage across: {:s}"
75 "\nCurrent: {:s}"
76 "\nTerminal voltage: {:s}"
77 "\n--- Initialization from powerflow finished ---",
81}
82
84 Attribute<Matrix>::Ptr leftVector) {
85 mDirectEquivCond = MatrixComp::Zero(mNumFreqs, 1);
86 mDirectPrevVoltCoeff = MatrixComp::Zero(mNumFreqs, 1);
87 mDirectCapCurrent = MatrixComp::Zero(mNumFreqs, 1);
88 mDirectHistory = MatrixComp::Zero(mNumFreqs, 1);
89 if (mUseSubcomponents || mDirectCapacitance <= 0.)
90 return;
91
92 for (UInt freq = 0; freq < mNumFreqs; ++freq) {
93 const Real capacitiveConductance = 2. * mDirectCapacitance / timeStep;
94 const Real harmonicSusceptance =
95 2. * PI * mFrequencies(freq, 0) * mDirectCapacitance;
96 mDirectEquivCond(freq, 0) =
97 Complex(capacitiveConductance, harmonicSusceptance);
98 mDirectPrevVoltCoeff(freq, 0) =
99 Complex(capacitiveConductance, -harmonicSusceptance);
100 if (freq == 0)
101 mDirectCapCurrent(freq, 0) =
102 Complex(0., 2. * PI * mFrequencies(freq, 0) * mDirectCapacitance) *
103 (**mIntfVoltage)(0, 0);
104 }
105}
106
108 SparseMatrixRow &systemMatrix) {
109 if (mUseSubcomponents)
110 return;
111 for (UInt freq = 0; freq < mNumFreqs; ++freq) {
112 const Complex admittance =
113 Complex(**mConductance, 0.) + mDirectEquivCond(freq, 0);
114 MNAStampUtils::stampAdmittance(admittance, systemMatrix, matrixNodeIndex(0),
115 0, terminalNotGrounded(0), false, mSLog,
116 mNumFreqs, freq);
117 }
118}
119
121 if (mUseSubcomponents || mDirectCapacitance <= 0.)
122 return;
123 for (UInt freq = 0; freq < mNumFreqs; ++freq) {
124 const Complex history =
125 -mDirectCapCurrent(freq, 0) -
126 mDirectPrevVoltCoeff(freq, 0) * (**mIntfVoltage)(0, freq);
127 mDirectHistory(freq, 0) = history;
128 if (terminalNotGrounded(0))
129 Math::setVectorElement(rightVector, matrixNodeIndex(0), -history,
130 mNumFreqs, freq);
131 }
132}
133
135 AttributeBase::List &prevStepDependencies,
136 AttributeBase::List &attributeDependencies,
137 AttributeBase::List &modifiedAttributes) {
138 if (!mUseSubcomponents) {
139 prevStepDependencies.push_back(mIntfVoltage);
140 prevStepDependencies.push_back(mIntfCurrent);
141 }
142 modifiedAttributes.push_back(mRightVector);
143}
144
148
150 AttributeBase::List &prevStepDependencies,
151 AttributeBase::List &attributeDependencies,
152 AttributeBase::List &modifiedAttributes,
153 Attribute<Matrix>::Ptr &leftVector) {
154 attributeDependencies.push_back(leftVector);
155 modifiedAttributes.push_back(mIntfVoltage);
156 modifiedAttributes.push_back(mIntfCurrent);
157}
158
160 Attribute<Matrix>::Ptr &leftVector) {
161 this->mnaUpdateVoltage(**leftVector);
162 this->mnaUpdateCurrent(**leftVector);
163}
164
166 for (UInt freq = 0; freq < mNumFreqs; ++freq)
168 leftVector, matrixNodeIndex(0), mNumFreqs, freq);
169}
170
172 if (!mUseSubcomponents) {
173 for (UInt freq = 0; freq < mNumFreqs; ++freq) {
174 const Complex voltage = (**mIntfVoltage)(0, freq);
175 const Complex capCurrent =
176 mDirectCapacitance > 0.
177 ? mDirectEquivCond(freq, 0) * voltage + mDirectHistory(freq, 0)
178 : Complex(0., 0.);
179 mDirectCapCurrent(freq, 0) = capCurrent;
180 (**mIntfCurrent)(0, freq) =
181 Complex(**mConductance, 0.) * voltage + capCurrent;
182 }
183 return;
184 }
185
186 (**mIntfCurrent)(0, 0) = 0;
187 if (**mConductance > 0)
188 (**mIntfCurrent)(0, 0) += mSubResistor->intfCurrent()(0, 0);
189 if (**mSusceptance > 0)
190 (**mIntfCurrent)(0, 0) += mSubCapacitor->intfCurrent()(0, 0);
191}
std::vector< Ptr > List
Definition Attribute.h:123
AttributePointer< Attribute< T > > Ptr
Definition Attribute.h:249
void addMNASubComponent(typename SimPowerComp< Complex >::Ptr subc, MNA_SUBCOMP_TASK_ORDER preStepOrder, MNA_SUBCOMP_TASK_ORDER postStepOrder, Bool contributeToRightVector)
void mnaCompApplyRightSideVectorStamp(Matrix &rightVector) override
CompositePowerComp(String uid, String name, Bool hasPreStep, Bool hasPostStep, Logger::Level logLevel)
void initializeParentFromNodesAndTerminals(Real frequency) override
Initializes component from power flow data.
void mnaCompUpdateCurrent(const Matrix &leftVector) final
Updates internal current variable of the component.
const Attribute< Real >::Ptr mConductance
Conductance [S].
void mnaParentPreStep(Real time, Int timeStepCount) final
MNA pre step operations.
void mnaParentApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override
const Attribute< Real >::Ptr mSusceptance
Susceptance [S].
void mnaCompUpdateVoltage(const Matrix &leftVector) final
Updates internal voltage variable of the component.
void mnaParentApplyRightSideVectorStamp(Matrix &rightVector) override
std::shared_ptr< Resistor > mSubResistor
Resistor between terminal and ground.
void setParameters(Real conductance, Real susceptance)
Set shunt specific parameters.
Shunt(String uid, String name, Logger::Level logLevel=Logger::Level::off)
Defines UID, name, component parameters and logging level.
std::shared_ptr< Capacitor > mSubCapacitor
Capacitor between terminal and ground.
void mnaParentInitialize(Real omega, Real timeStep, Attribute< Matrix >::Ptr leftVector) override
void mnaParentPostStep(Real time, Int timeStepCount, Attribute< Matrix >::Ptr &leftVector) final
MNA post-step operations.
void mnaParentAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes) final
Add MNA pre step dependencies.
void mnaParentAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector) final
add MNA post-step dependencies
const Attribute< String >::Ptr mName
Human readable name.
String uid()
Returns unique id.
String type()
Get component type (cross-platform)
AttributeList::Ptr mAttributes
Attribute List.
spdlog::level::level_enum Level
Definition Logger.h:33
static String phasorToString(const Complex &num)
Definition Logger.cpp:57
void mnaUpdateCurrent(const Matrix &leftVector) final
void mnaUpdateVoltage(const Matrix &leftVector) final
Attribute< Matrix >::Ptr mRightVector
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)
static void setVectorElement(Matrix &mat, Matrix::Index row, Complex value, Int maxFreq=1, Int freqIdx=0, Matrix::Index colOffset=0)
std::vector< Ptr > List
Definition SimNode.h:35
UInt matrixNodeIndex(UInt nodeIndex)
const Attribute< MatrixVar< Complex > >::Ptr mIntfCurrent
SimTerminal< Complex >::List mTerminals
const Attribute< MatrixVar< Complex > >::Ptr mIntfVoltage
Bool terminalNotGrounded(UInt index)
Complex initialSingleVoltage(UInt index)
Logger::Level mLogLevel
Component logger control for internal variables.
bool mParametersSet
Flag indicating that parameters are set via setParameters() function.
Logger::Log mSLog
Component logger.
#define PI
Definition Definitions.h:43
Eigen::Matrix< Real, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor > Matrix
Dense matrix for real numbers.
Definition Definitions.h:79
std::string String
Definition Definitions.h:63
double Real
Definition Definitions.h:60
int Int
Definition Definitions.h:59
std::complex< Real > Complex
Definition Definitions.h:61
bool Bool
Definition Definitions.h:62
unsigned int UInt
Definition Definitions.h:58
Eigen::SparseMatrix< Real, Eigen::RowMajor > SparseMatrixRow
Sparse matrix for real numbers (row major).
Definition Definitions.h:72