DPsim
Loading...
Searching...
No Matches
SP_Ph3_Inductor.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<Complex>(uid, name, false, true, logLevel),
18 **mIntfVoltage = MatrixComp::Zero(3, 1);
19 **mIntfCurrent = MatrixComp::Zero(3, 1);
20}
21
23 auto copy = Inductor::make(name, mLogLevel);
24 copy->setParameters(**mInductance);
25 return copy;
26}
27
29
30 Real omega = 2 * PI * frequency;
31 MatrixComp reactance = MatrixComp::Zero(3, 3);
32 reactance << Complex(0, omega * (**mInductance)(0, 0)),
33 Complex(0, omega * (**mInductance)(0, 1)),
34 Complex(0, omega * (**mInductance)(0, 2)),
35 Complex(0, omega * (**mInductance)(1, 0)),
36 Complex(0, omega * (**mInductance)(1, 1)),
37 Complex(0, omega * (**mInductance)(1, 2)),
38 Complex(0, omega * (**mInductance)(2, 0)),
39 Complex(0, omega * (**mInductance)(2, 1)),
40 Complex(0, omega * (**mInductance)(2, 2));
41 mSusceptance = reactance.inverse();
42
43 // IntfVoltage initialization for each phase
44 (**mIntfVoltage)(0, 0) = initialSingleVoltage(1) - initialSingleVoltage(0);
45 (**mIntfVoltage)(1, 0) = (**mIntfVoltage)(0, 0) *
46 Complex(cos(-2. / 3. * M_PI), sin(-2. / 3. * M_PI));
47 (**mIntfVoltage)(2, 0) = (**mIntfVoltage)(0, 0) *
48 Complex(cos(2. / 3. * M_PI), sin(2. / 3. * M_PI));
50
51 SPDLOG_LOGGER_INFO(mSLog, "--- Initialize according to power flow ---");
52}
53
58
65
67 AttributeBase::List &prevStepDependencies,
68 AttributeBase::List &attributeDependencies,
69 AttributeBase::List &modifiedAttributes,
70 Attribute<Matrix>::Ptr &leftVector) {
71 attributeDependencies.push_back(leftVector);
72 modifiedAttributes.push_back(mIntfVoltage);
73 modifiedAttributes.push_back(mIntfCurrent);
74}
75
77 Attribute<Matrix>::Ptr &leftVector) {
78 mnaCompUpdateVoltage(**leftVector);
79 mnaCompUpdateCurrent(**leftVector);
80}
81
83 // v1 - v0
84 **mIntfVoltage = Matrix::Zero(3, 1);
85 if (terminalNotGrounded(1)) {
86 (**mIntfVoltage)(0, 0) =
88 (**mIntfVoltage)(1, 0) =
90 (**mIntfVoltage)(2, 0) =
92 }
93 if (terminalNotGrounded(0)) {
94 (**mIntfVoltage)(0, 0) =
95 (**mIntfVoltage)(0, 0) -
97 (**mIntfVoltage)(1, 0) =
98 (**mIntfVoltage)(1, 0) -
100 (**mIntfVoltage)(2, 0) =
101 (**mIntfVoltage)(2, 0) -
103 }
104}
105
109
110// #### Tear Methods ####
112 // TODO
114 1. / mSusceptance(0, 0));
116 1. / mSusceptance(1, 0));
118 1. / mSusceptance(2, 0));
119}
std::vector< Ptr > List
Definition Attribute.h:123
AttributePointer< Attribute< T > > Ptr
Definition Attribute.h:250
const CPS::Attribute< Matrix >::Ptr mInductance
Inductance [H].
String uid()
Returns unique id.
AttributeList::Ptr mAttributes
Attribute List.
spdlog::level::level_enum Level
Definition Logger.h:33
MNASimPowerComp(String uid, String name, Bool hasPreStep, Bool hasPostStep, Logger::Level logLevel)
static void stampAdmittanceMatrix(const MatrixComp &admittanceMat, 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 void addToMatrixElement(SparseMatrixRow &mat, Matrix::Index row, Matrix::Index column, Complex value, Int maxFreq=1, Int freqIdx=0)
void mnaCompPostStep(Real time, Int timeStepCount, Attribute< Matrix >::Ptr &leftVector) override
void mnaTearApplyMatrixStamp(SparseMatrixRow &tearMatrix) override
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 mnaCompInitialize(Real omega, Real timeStep, Attribute< Matrix >::Ptr leftVector) override
Initializes internal variables of the component.
void mnaCompUpdateCurrent(const Matrix &leftVector) override
Update interface current from MNA system result.
MatrixComp mSusceptance
susceptance [S]
void mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector) override
Add MNA post step dependencies.
Inductor(String uid, String name, Logger::Level logLevel=Logger::Level::off)
Defines UID, name, component parameters and logging level.
void mnaCompUpdateVoltage(const Matrix &leftVector) override
Update interface voltage from MNA system result.
void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override
Stamps system matrix.
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< Inductor > make(Args &&...args)
Definition PtrFactory.h:19
#define PI
Definition Definitions.h:43
#define M_PI
Definition Definitions.h:41
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