DPsim
Loading...
Searching...
No Matches
EMT_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<Real>(uid, name, true, true, logLevel),
16 mEquivCurrent = 0;
17 **mIntfVoltage = Matrix::Zero(1, 1);
18 **mIntfCurrent = Matrix::Zero(1, 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 Complex impedance = {0, omega * **mInductance};
32 Complex voltage =
34 (**mIntfVoltage)(0, 0) = voltage.real();
35 (**mIntfCurrent)(0, 0) = (voltage / impedance).real();
36
37 SPDLOG_LOGGER_INFO(mSLog,
38 "\n--- Initialization from powerflow ---"
39 "\nVoltage across: {:f}"
40 "\nCurrent: {:f}"
41 "\nTerminal 0 voltage: {:f}"
42 "\nTerminal 1 voltage: {:f}"
43 "\n--- Initialization from powerflow finished ---",
44 (**mIntfVoltage)(0, 0), (**mIntfCurrent)(0, 0),
47}
48
50 Attribute<Matrix>::Ptr leftVector) {
52
53 mEquivCond = timeStep / (2.0 * **mInductance);
54 // Update internal state
55 mEquivCurrent = mEquivCond * (**mIntfVoltage)(0, 0) + (**mIntfCurrent)(0, 0);
56}
57
64
66 // Update internal state
67 mEquivCurrent = mEquivCond * (**mIntfVoltage)(0, 0) + (**mIntfCurrent)(0, 0);
72}
73
75 AttributeBase::List &prevStepDependencies,
76 AttributeBase::List &attributeDependencies,
77 AttributeBase::List &modifiedAttributes) {
78 // actually depends on L, but then we'd have to modify the system matrix anyway
79 modifiedAttributes.push_back(mRightVector);
80 prevStepDependencies.push_back(mIntfCurrent);
81 prevStepDependencies.push_back(mIntfVoltage);
82}
83
87
89 AttributeBase::List &prevStepDependencies,
90 AttributeBase::List &attributeDependencies,
91 AttributeBase::List &modifiedAttributes,
92 Attribute<Matrix>::Ptr &leftVector) {
93 attributeDependencies.push_back(leftVector);
94 modifiedAttributes.push_back(mIntfVoltage);
95 modifiedAttributes.push_back(mIntfCurrent);
96}
97
99 Attribute<Matrix>::Ptr &leftVector) {
100 mnaCompUpdateVoltage(**leftVector);
101 mnaCompUpdateCurrent(**leftVector);
102}
103
105 // v1 - v0
106 (**mIntfVoltage)(0, 0) = 0;
107 if (terminalNotGrounded(1))
108 (**mIntfVoltage)(0, 0) =
110 if (terminalNotGrounded(0))
111 (**mIntfVoltage)(0, 0) =
112 (**mIntfVoltage)(0, 0) -
114}
115
117 (**mIntfCurrent)(0, 0) = mEquivCond * (**mIntfVoltage)(0, 0) + mEquivCurrent;
118}
119
120// #### Tear Methods ####
123 mEquivCond = timeStep / (2.0 * **mInductance);
124 // Update internal state
125 mEquivCurrent = mEquivCond * (**mIntfVoltage)(0, 0) + (**mIntfCurrent)(0, 0);
126}
127
131
133 mEquivCurrent = mEquivCond * (**mIntfVoltage)(0, 0) + (**mIntfCurrent)(0, 0);
135}
136
138 (**mIntfVoltage)(0, 0) = voltage.real();
139 (**mIntfCurrent)(0, 0) = mEquivCond * voltage.real() + mEquivCurrent;
140}
std::vector< Ptr > List
Definition Attribute.h:123
AttributePointer< Attribute< T > > Ptr
Definition Attribute.h:250
const CPS::Attribute< Real >::Ptr mInductance
Inductance [H].
void mnaCompPostStep(Real time, Int timeStepCount, Attribute< Matrix >::Ptr &leftVector) override
void mnaTearPostStep(Complex voltage, Complex current) override
void mnaCompUpdateVoltage(const Matrix &leftVector) override
Update interface voltage from MNA system result.
Real mEquivCond
Equivalent conductance [S].
void mnaCompInitialize(Real omega, Real timeStep, Attribute< Matrix >::Ptr leftVector) override
Initializes internal variables of the component.
Inductor(String uid, String name, Logger::Level logLevel=Logger::Level::off)
Defines UID, name, component parameters and logging level.
void mnaTearApplyMatrixStamp(SparseMatrixRow &tearMatrix) override
void mnaTearApplyVoltageStamp(Matrix &voltageVector) override
SimPowerComp< Real >::Ptr clone(String name) override
Returns a modified copy of the component with the given suffix added to the name and without.
void mnaCompAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes) override
Add MNA pre step dependencies.
void mnaCompApplyRightSideVectorStamp(Matrix &rightVector) override
Stamps right side (source) vector.
void mnaCompPreStep(Real time, Int timeStepCount) override
void mnaTearInitialize(Real omega, Real timestep) override
void mnaCompUpdateCurrent(const Matrix &leftVector) override
Update interface current from MNA system result.
void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override
Stamps system matrix.
void mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector) override
Add MNA post step dependencies.
void initializeFromNodesAndTerminals(Real frequency) override
Initializes component from power flow data.
Real mEquivCurrent
DC equivalent current source [A].
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)
Attribute< Matrix >::Ptr mRightVector
static void stampConductance(Real conductance, 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)
Definition MathUtils.cpp:73
static void addToVectorElement(Matrix &mat, Matrix::Index row, Complex value, Int maxFreq=1, Int freqIdx=0)
Definition MathUtils.cpp:83
static void addToMatrixElement(SparseMatrixRow &mat, Matrix::Index row, Matrix::Index column, Complex value, Int maxFreq=1, Int freqIdx=0)
UInt matrixNodeIndex(UInt nodeIndex)
const Attribute< MatrixVar< Real > >::Ptr mIntfCurrent
const Attribute< MatrixVar< Real > >::Ptr mIntfVoltage
std::shared_ptr< SimPowerComp< VarType > > Ptr
Bool terminalNotGrounded(UInt index)
Complex initialSingleVoltage(UInt index)
void setTerminalNumber(UInt num)
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 RMS3PH_TO_PEAK1PH
Definition Definitions.h:50
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