DPsim
Loading...
Searching...
No Matches
SP_Ph1_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),
16 **mIntfVoltage = MatrixComp::Zero(1, 1);
17 **mIntfCurrent = MatrixComp::Zero(1, 1);
19}
20
22 auto copy = Inductor::make(name, mLogLevel);
23 copy->setParameters(**mInductance);
24 return copy;
25}
26
28
29 Real omega = 2 * PI * frequency;
30 mSusceptance = Complex(0, -1 / omega / **mInductance);
31 (**mIntfVoltage)(0, 0) = initialSingleVoltage(1) - initialSingleVoltage(0);
33
34 SPDLOG_LOGGER_INFO(mSLog,
35 "\nInductance [H]: {:s}"
36 "\nImpedance [Ohm]: {:s}",
39 SPDLOG_LOGGER_INFO(mSLog,
40 "\n--- Initialization from powerflow ---"
41 "\nVoltage across: {:s}"
42 "\nCurrent: {:s}"
43 "\nTerminal 0 voltage: {:s}"
44 "\nTerminal 1 voltage: {:s}"
45 "\n--- Initialization from powerflow finished ---",
50}
51
52// #### MNA section ####
53
55 Attribute<Matrix>::Ptr leftVector) {
57
58 SPDLOG_LOGGER_INFO(mSLog,
59 "\n--- MNA initialization ---"
60 "\nInitial voltage {:s}"
61 "\nInitial current {:s}"
62 "\n--- MNA initialization finished ---",
65}
66
73
75 AttributeBase::List &prevStepDependencies,
76 AttributeBase::List &attributeDependencies,
77 AttributeBase::List &modifiedAttributes,
78 Attribute<Matrix>::Ptr &leftVector) {
79 attributeDependencies.push_back(leftVector);
80 modifiedAttributes.push_back(mIntfVoltage);
81 modifiedAttributes.push_back(mIntfCurrent);
82}
83
85 Attribute<Matrix>::Ptr &leftVector) {
86 this->mnaUpdateVoltage(**leftVector);
87 this->mnaUpdateCurrent(**leftVector);
88}
89
91 // v1 - v0
92 **mIntfVoltage = Matrix::Zero(3, 1);
93 if (terminalNotGrounded(1)) {
94 (**mIntfVoltage)(0, 0) =
96 }
97 if (terminalNotGrounded(0)) {
98 (**mIntfVoltage)(0, 0) =
99 (**mIntfVoltage)(0, 0) -
101 }
102}
103
107
108// #### Tear Methods ####
std::vector< Ptr > List
Definition Attribute.h:123
AttributePointer< Attribute< T > > Ptr
Definition Attribute.h:250
const CPS::Attribute< Real >::Ptr mInductance
Inductance [H].
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 void addToMatrixElement(SparseMatrixRow &mat, Matrix::Index row, Matrix::Index column, Complex value, Int maxFreq=1, Int freqIdx=0)
void mnaCompInitialize(Real omega, Real timeStep, Attribute< Matrix >::Ptr leftVector)
Initializes internal variables of the component.
SimPowerComp< Complex >::Ptr clone(String name)
Returns a modified copy of the component with the given suffix added to the name and without.
Complex mSusceptance
susceptance [S]
void initializeFromNodesAndTerminals(Real frequency)
Initializes component from power flow data.
void mnaCompPostStep(Real time, Int timeStepCount, Attribute< Matrix >::Ptr &leftVector)
MNA post step operations.
void mnaTearApplyMatrixStamp(SparseMatrixRow &tearMatrix)
void mnaCompUpdateCurrent(const Matrix &leftVector)
Update interface current from MNA system results.
Inductor(String uid, String name, Logger::Level logLevel=Logger::Level::off)
Defines UID, name and log level.
void mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector)
Add MNA post step dependencies.
void mnaCompUpdateVoltage(const Matrix &leftVector)
Update interface voltage from MNA system results.
void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix)
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
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::SparseMatrix< Real, Eigen::RowMajor > SparseMatrixRow
Sparse matrix for real numbers (row major).
Definition Definitions.h:74