DPsim
Loading...
Searching...
No Matches
EMT_Ph3_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
12#include <stdexcept>
13
14using namespace CPS;
15
17 : CompositePowerComp<Real>(uid, name, true, true, logLevel) {
19 mConductance = Matrix::Zero(3, 3);
20 mSusceptance = Matrix::Zero(3, 3);
21 SPDLOG_LOGGER_INFO(mSLog, "Create {} of type {}", this->type(), name);
23}
24
26 Logger::Level logLevel)
27 : Shunt(uid, name, logLevel) {
28 mUseSubcomponents = useSubcomponents;
29}
30
35
36void EMT::Ph3::Shunt::setParameters(Matrix conductance, Matrix susceptance) {
37 mConductance = conductance;
38 mSusceptance = susceptance;
39 SPDLOG_LOGGER_INFO(mSLog, "Conductance={} [S] Susceptance={} [Ohm] ",
40 Logger::matrixToString(mConductance),
41 Logger::matrixToString(mSusceptance));
42 mParametersSet = true;
43}
44
47
48 // If no dynamic-domain admittance was configured, derive it from the
49 // power-flow operating point copied to this terminal by
50 // SystemTopology::initWithPowerflow(). Terminal power uses the network
51 // injection sign here: a positive conductance consumes active power.
52 if (!mParametersSet) {
53 const Complex voltage = mTerminals[0]->initialSingleVoltage();
54 if (std::norm(voltage) <= 0.0)
55 throw std::invalid_argument(
56 "Shunt requires a non-zero terminal voltage when initialized from "
57 "power-flow data.");
58
59 const Complex terminalPower = mTerminals[0]->singlePower();
60 const Real conductance = -terminalPower.real() / std::norm(voltage);
61 const Real susceptance = terminalPower.imag() / std::norm(voltage);
62 setParameters(conductance, susceptance);
63 }
64
65 // Static calculation
66 Real omega = 2. * PI * frequency;
67 MatrixComp admittance = Matrix::Zero(3, 3);
68 admittance << Complex(mConductance(0, 0), mSusceptance(0, 0)), 0, 0, 0,
69 Complex(mConductance(1, 1), mSusceptance(1, 1)), 0, 0, 0,
70 Complex(mConductance(2, 2), mSusceptance(2, 2));
71 MatrixComp vInitABC = MatrixComp::Zero(3, 1);
72 vInitABC(0, 0) = RMS3PH_TO_PEAK1PH * mTerminals[0]->initialSingleVoltage();
73 vInitABC(1, 0) = vInitABC(0, 0) * SHIFT_TO_PHASE_B;
74 vInitABC(2, 0) = vInitABC(0, 0) * SHIFT_TO_PHASE_C;
75 **mIntfVoltage = vInitABC.real();
76 // The passive subcomponents use the same terminal orientation as the DP
77 // shunt: ground is terminal 0 and the live bus is terminal 1.
78 **mIntfCurrent = (admittance * vInitABC).real();
79
80 if (!mUseSubcomponents) {
81 MatrixComp susceptiveAdmittance =
82 MatrixComp(Complex(0, 1) * mSusceptance) * vInitABC;
83 if (mSusceptance(0, 0) > 0)
84 mCapBranchCurrent = susceptiveAdmittance.real();
85 if (mSusceptance(0, 0) < 0)
86 mIndBranchCurrent = susceptiveAdmittance.real();
87 return;
88 }
89
90 // Create series rl sub component
91 if (mConductance(0, 0) > 0) {
92 mSubResistor =
93 std::make_shared<EMT::Ph3::Resistor>(**mName + "_Res", mLogLevel);
94 mSubResistor->connect({SimNode::GND, mTerminals[0]->node()});
95 mSubResistor->setParameters(mConductance.inverse());
96 mSubResistor->initialize(mFrequencies);
97 mSubResistor->initializeFromNodesAndTerminals(frequency);
100 }
101
102 if (mSusceptance(0, 0) > 0) {
103 mSubCapacitor =
104 std::make_shared<EMT::Ph3::Capacitor>(**mName + "_cap", mLogLevel);
105 mSubCapacitor->setParameters(mSusceptance * (1 / omega));
106 mSubCapacitor->connect({SimNode::GND, mTerminals[0]->node()});
107 mSubCapacitor->initialize(mFrequencies);
108 mSubCapacitor->initializeFromNodesAndTerminals(frequency);
109 addMNASubComponent(mSubCapacitor,
112 }
113
114 if (mSusceptance(0, 0) < 0) {
115 mSubInductor =
116 std::make_shared<EMT::Ph3::Inductor>(**mName + "_ind", mLogLevel);
117 mSubInductor->setParameters(-mSusceptance.inverse() * (1 / omega));
118 mSubInductor->connect({SimNode::GND, mTerminals[0]->node()});
119 mSubInductor->initialize(mFrequencies);
120 mSubInductor->initializeFromNodesAndTerminals(frequency);
123 }
124
125 SPDLOG_LOGGER_INFO(mSLog,
126 "\n--- Initialization from powerflow ---"
127 "\nVoltage across: {:s}"
128 "\nCurrent: {:s}"
129 "\nTerminal voltage: {:s}"
130 "\n--- Initialization from powerflow finished ---",
134}
135
137 Attribute<Matrix>::Ptr leftVector) {
138 if (mUseSubcomponents)
139 return;
140
141 if (mSusceptance(0, 0) > 0)
142 mCapEquivalentConductance = (2.0 / (omega * timeStep)) * mSusceptance;
143 if (mSusceptance(0, 0) < 0)
144 mIndEquivalentConductance = (-0.5 * omega * timeStep) * mSusceptance;
145 mCapEquivalentCurrent =
146 -mCapBranchCurrent - mCapEquivalentConductance * **mIntfVoltage;
147 mIndEquivalentCurrent =
148 mIndEquivalentConductance * **mIntfVoltage + mIndBranchCurrent;
149}
150
152 SparseMatrixRow &systemMatrix) {
153 if (mUseSubcomponents)
154 return;
155 const Matrix conductance =
156 mConductance + mCapEquivalentConductance + mIndEquivalentConductance;
157 MNAStampUtils::stampConductanceMatrix(conductance, systemMatrix,
158 matrixNodeIndex(0), 0,
159 terminalNotGrounded(0), false, mSLog);
160}
161
163 if (mUseSubcomponents || !terminalNotGrounded(0))
164 return;
165 for (Int phase = 0; phase < 3; ++phase) {
166 Math::setVectorElement(rightVector, matrixNodeIndex(0, phase),
167 mCapEquivalentCurrent(phase, 0) +
168 mIndEquivalentCurrent(phase, 0));
169 }
170}
171
173 AttributeBase::List &prevStepDependencies,
174 AttributeBase::List &attributeDependencies,
175 AttributeBase::List &modifiedAttributes) {
176 modifiedAttributes.push_back(mRightVector);
177}
178
179void EMT::Ph3::Shunt::mnaParentPreStep(Real time, Int timeStepCount) {
180 if (!mUseSubcomponents) {
181 mCapEquivalentCurrent =
182 -mCapBranchCurrent - mCapEquivalentConductance * **mIntfVoltage;
183 mIndEquivalentCurrent =
184 mIndEquivalentConductance * **mIntfVoltage + mIndBranchCurrent;
185 }
187}
188
190 AttributeBase::List &prevStepDependencies,
191 AttributeBase::List &attributeDependencies,
192 AttributeBase::List &modifiedAttributes,
193 Attribute<Matrix>::Ptr &leftVector) {
194 attributeDependencies.push_back(leftVector);
195 modifiedAttributes.push_back(mIntfVoltage);
196 modifiedAttributes.push_back(mIntfCurrent);
197}
198
200 Attribute<Matrix>::Ptr &leftVector) {
201 this->mnaUpdateVoltage(**leftVector);
202 this->mnaUpdateCurrent(**leftVector);
203}
204
206 (**mIntfVoltage)(0, 0) =
208 (**mIntfVoltage)(1, 0) =
210 (**mIntfVoltage)(2, 0) =
212}
213
215 if (!mUseSubcomponents) {
216 mCapBranchCurrent =
217 mCapEquivalentConductance * **mIntfVoltage + mCapEquivalentCurrent;
218 mIndBranchCurrent =
219 mIndEquivalentConductance * **mIntfVoltage + mIndEquivalentCurrent;
220 **mIntfCurrent = -(
221 (mConductance + mCapEquivalentConductance + mIndEquivalentConductance) *
222 **mIntfVoltage +
223 mCapEquivalentCurrent + mIndEquivalentCurrent);
224 return;
225 }
226 (**mIntfCurrent).setZero();
227
228 if (mConductance(0, 0) > 0)
229 **mIntfCurrent += mSubResistor->intfCurrent();
230 if (mSusceptance(0, 0) > 0)
231 **mIntfCurrent += mSubCapacitor->intfCurrent();
232 if (mSusceptance(0, 0) < 0)
233 **mIntfCurrent += mSubInductor->intfCurrent();
234}
std::vector< Ptr > List
Definition Attribute.h:123
AttributePointer< Attribute< T > > Ptr
Definition Attribute.h:249
void addMNASubComponent(typename SimPowerComp< Real >::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 mnaParentPostStep(Real time, Int timeStepCount, Attribute< Matrix >::Ptr &leftVector) final
MNA post-step operations.
void mnaCompUpdateVoltage(const Matrix &leftVector) final
Updates internal voltage variable of the component.
void mnaParentApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override
void mnaParentPreStep(Real time, Int timeStepCount) final
MNA pre 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
void mnaParentInitialize(Real omega, Real timeStep, Attribute< Matrix >::Ptr leftVector) override
void mnaParentApplyRightSideVectorStamp(Matrix &rightVector) override
void initializeParentFromNodesAndTerminals(Real frequency) final
Initializes component from power flow data.
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.
void mnaCompUpdateCurrent(const Matrix &leftVector) final
Updates internal current variable of the component.
const Attribute< String >::Ptr mName
Human readable name.
String uid()
Returns unique id.
String type()
Get component type (cross-platform)
spdlog::level::level_enum Level
Definition Logger.h:33
static String matrixToString(const Matrix &mat)
Definition Logger.cpp:31
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 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)
static Matrix singlePhaseParameterToThreePhase(Real parameter)
To convert single phase parameters to symmetrical three phase ones.
static Ptr GND
Definition SimNode.h:37
UInt matrixNodeIndex(UInt nodeIndex)
const Attribute< MatrixVar< Real > >::Ptr mIntfCurrent
SimTerminal< Real >::List mTerminals
const Attribute< MatrixVar< Real > >::Ptr mIntfVoltage
Bool terminalNotGrounded(UInt index)
Complex initialSingleVoltage(UInt index)
void setTerminalNumber(UInt num)
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
#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: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
Eigen::Matrix< Complex, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor > MatrixComp
Dense matrix for complex numbers.
Definition Definitions.h:82
bool Bool
Definition Definitions.h:62
Eigen::SparseMatrix< Real, Eigen::RowMajor > SparseMatrixRow
Sparse matrix for real numbers (row major).
Definition Definitions.h:72