DPsim
Loading...
Searching...
No Matches
DP_Ph1_Inverter.h
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
9#pragma once
10
11#include <map>
12
15
16namespace CPS {
17namespace DP {
18namespace Ph1 {
22class Inverter : public MNASimPowerComp<Complex>,
23 public SharedFactory<Inverter> {
24protected:
25 // #### Model specific variables ####
27 Real mVin = 360;
33 Real mFreqCar = 10e3;
37 Real mModIdx = 0.87;
38 //mMr = sqrt(2)*mV_grid/mV_in;
43
59 std::vector<Int> mCarHarms;
61 std::vector<Int> mModHarms;
62
73 std::vector<Real> mFactorials;
75 std::map<Int, Real> mMultInvFactorials;
76
78
79 // #### Math functions ####
80
82 Real besselFirstKind_n(Int n, Int k_max, Real x) const;
85 long long factorial(Int n) const;
86 Real multInvFactorial(Int n) const;
87 Real multInvIntGamma(Real n) const;
88
89public:
92 Logger::Level logLevel = Logger::Level::off);
94 Inverter(String name, Logger::Level logLevel = Logger::Level::off)
95 : Inverter(name, name, logLevel) {}
96
97 // #### General ####
99 void initializeFromNodesAndTerminals(Real frequency) override;
101 void initialize(Matrix frequencies) override;
103 void setParameters(const std::vector<Int> &carrierHarms,
104 const std::vector<Int> &modulHarms, Real inputVoltage,
105 Real ratio, Real phase);
107 void calculatePhasors();
108
109 // #### MNA Functions ####
111 void mnaCompInitialize(Real omega, Real timeStep,
112 Attribute<Matrix>::Ptr leftVector) override;
114 Real omega, Real timeStep,
115 std::vector<Attribute<Matrix>::Ptr> leftVectors) override;
117 void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override;
119 Int freqIdx) override;
121 void mnaCompApplyRightSideVectorStamp(Matrix &rightVector) override;
122 void mnaCompApplyRightSideVectorStampHarm(Matrix &rightVector) override;
124 Int freqIdx) override;
127 AttributeBase::List &prevStepDependencies,
128 AttributeBase::List &attributeDependencies,
129 AttributeBase::List &modifiedAttributes) override;
131 void
133 AttributeBase::List &attributeDependencies,
134 AttributeBase::List &modifiedAttributes,
135 Attribute<Matrix>::Ptr &leftVector) override;
136 void mnaCompPreStep(Real time, Int timeStepCount) override;
137 void mnaCompPostStep(Real time, Int timeStepCount,
138 Attribute<Matrix>::Ptr &leftVector) override;
139
140 class MnaPreStepHarm : public CPS::Task {
141 public:
143 : Task(**inverter.mName + ".MnaPreStepHarm"), mInverter(inverter) {
144 mModifiedAttributes.push_back(mInverter.attribute("right_vector"));
145 mModifiedAttributes.push_back(mInverter.attribute("v_intf"));
146 }
147 void execute(Real time, Int timeStepCount);
148
149 private:
150 Inverter &mInverter;
151 };
152
153 class MnaPostStepHarm : public CPS::Task {
154 public:
156 const std::vector<Attribute<Matrix>::Ptr> &leftVectors)
157 : Task(**inverter.mName + ".MnaPostStepHarm"), mInverter(inverter),
158 mLeftVectors(leftVectors) {
159 for (UInt i = 0; i < mLeftVectors.size(); i++)
160 mAttributeDependencies.push_back(mLeftVectors[i]);
161 mModifiedAttributes.push_back(mInverter.attribute("i_intf"));
162 }
163 void execute(Real time, Int timeStepCount);
164
165 private:
166 Inverter &mInverter;
167 std::vector<Attribute<Matrix>::Ptr> mLeftVectors;
168 };
169};
170} // namespace Ph1
171} // namespace DP
172} // namespace CPS
std::vector< Ptr > List
Definition Attribute.h:123
AttributePointer< Attribute< T > > Ptr
Definition Attribute.h:249
MnaPostStepHarm(Inverter &inverter, const std::vector< Attribute< Matrix >::Ptr > &leftVectors)
void execute(Real time, Int timeStepCount)
void execute(Real time, Int timeStepCount)
Int mMaxModulHarm
Maximum number of modulation signal harmonics.
void mnaCompInitializeHarm(Real omega, Real timeStep, std::vector< Attribute< Matrix >::Ptr > leftVectors) override
void setParameters(const std::vector< Int > &carrierHarms, const std::vector< Int > &modulHarms, Real inputVoltage, Real ratio, Real phase)
void mnaCompPostStep(Real time, Int timeStepCount, Attribute< Matrix >::Ptr &leftVector) override
std::vector< Int > mModHarms
Vector of modulation signal harmonics.
void mnaCompApplySystemMatrixStampHarm(SparseMatrixRow &systemMatrix, Int freqIdx) override
Real multInvIntGamma(Real n) const
Real mModIdx
Modulation Index.
Real mOmCar
switching angular frequency
void mnaCompAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes) override
Add MNA pre step dependencies.
Inverter(String name, Logger::Level logLevel=Logger::Level::off)
Defines name and logging level.
Real mFreqMod
system frequency (should be updated every step)
void mnaCompApplyRightSideVectorStampHarm(Matrix &rightVector) override
void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override
Stamps system matrix.
Real multInvFactorial(Int n) const
UInt mHarNum
Number of harmonics.
Int mMaxCarrierHarm
Maximum number of carrier signal harmonics.
Matrix mPhasorPhases
Vector of phasor phases.
Real mPhaseCar
Carrier phase.
void initialize(Matrix frequencies) override
Initialize components with correct network frequencies.
Real besselFirstKind_n(Int n, Int k_max, Real x) const
Bessel function.
Real besselFirstKind_n_opt(Int n, Int k_max, Real x)
Bessel function using look up tables for factorials.
Inverter(String name, String uid, Logger::Level logLevel=Logger::Level::off)
Defines UID, name and logging level.
std::map< Int, Real > mMultInvFactorials
Real mOmMod
system angular frequency
Real mFreqCar
switching frequency (constant)
Matrix mPhasorMags
Vector of phasor magnitudes.
Real mVin
DC bus voltage.
void mnaCompApplyRightSideVectorStamp(Matrix &rightVector) override
Stamps right side (source) vector.
void initializeFromNodesAndTerminals(Real frequency) override
Initializes Component variables according to power flow data stored in Nodes.
std::vector< Real > mFactorials
long long factorial(Int n) const
Int mMaxBesselSumIdx
Maximum upper limit for Bessel function 1st kind summation.
void mnaCompPreStep(Real time, Int timeStepCount) override
Real mPhaseMod
Modulation phase.
std::vector< Int > mCarHarms
Vector of carrier signal harmonics.
Matrix mPhasorFreqs
Vector of phasor frequencies.
void mnaCompInitialize(Real omega, Real timeStep, Attribute< Matrix >::Ptr leftVector) override
Initializes internal variables of the component.
Real mVfund
voltage part of system fundamental
void mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector) override
Add MNA post step dependencies.
String uid()
Returns unique id.
spdlog::level::level_enum Level
Definition Logger.h:33
MNASimPowerComp(String uid, String name, Bool hasPreStep, Bool hasPostStep, Logger::Level logLevel)
Tasks to be defined by every component.
Definition Task.h:25
std::vector< AttributeBase::Ptr > mModifiedAttributes
Definition Task.h:70
std::vector< AttributeBase::Ptr > mAttributeDependencies
Definition Task.h:69
Task()
Definition Task.h:30
std::string mName
Definition Task.h:68
#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
Eigen::Matrix< Int, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor > MatrixInt
Dense matrix for integers.
Definition Definitions.h:85
double Real
Definition Definitions.h:60
int Int
Definition Definitions.h:59
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