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
72 std::vector<Real> mFactorials;
74 std::map<Int, Real> mMultInvFactorials;
75
77
78 // #### Math functions ####
79
81 Real besselFirstKind_n(Int n, Int k_max, Real x) const;
84 long long factorial(Int n) const;
85 Real multInvFactorial(Int n) const;
86 Real multInvIntGamma(Real n) const;
87
88public:
91 Logger::Level logLevel = Logger::Level::off);
93 Inverter(String name, Logger::Level logLevel = Logger::Level::off)
94 : Inverter(name, name, logLevel) {}
95
96 // #### General ####
98 void initializeFromNodesAndTerminals(Real frequency) override;
100 void initialize(Matrix frequencies) override;
102 void setParameters(const std::vector<Int> &carrierHarms,
103 const std::vector<Int> &modulHarms, Real inputVoltage,
104 Real ratio, Real phase);
106 void calculatePhasors();
107
108 // #### MNA Functions ####
110 void mnaCompInitialize(Real omega, Real timeStep,
111 Attribute<Matrix>::Ptr leftVector) override;
113 Real omega, Real timeStep,
114 std::vector<Attribute<Matrix>::Ptr> leftVectors) override;
116 void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override;
118 Int freqIdx) override;
120 void mnaCompApplyRightSideVectorStamp(Matrix &rightVector) override;
121 void mnaCompApplyRightSideVectorStampHarm(Matrix &rightVector) override;
123 Int freqIdx) override;
126 AttributeBase::List &prevStepDependencies,
127 AttributeBase::List &attributeDependencies,
128 AttributeBase::List &modifiedAttributes) override;
130 void
132 AttributeBase::List &attributeDependencies,
133 AttributeBase::List &modifiedAttributes,
134 Attribute<Matrix>::Ptr &leftVector) override;
135 void mnaCompPreStep(Real time, Int timeStepCount) override;
136 void mnaCompPostStep(Real time, Int timeStepCount,
137 Attribute<Matrix>::Ptr &leftVector) override;
138
139 class MnaPreStepHarm : public CPS::Task {
140 public:
142 : Task(**inverter.mName + ".MnaPreStepHarm"), mInverter(inverter) {
143 mModifiedAttributes.push_back(mInverter.attribute("right_vector"));
144 mModifiedAttributes.push_back(mInverter.attribute("v_intf"));
145 }
146 void execute(Real time, Int timeStepCount);
147
148 private:
149 Inverter &mInverter;
150 };
151
152 class MnaPostStepHarm : public CPS::Task {
153 public:
155 const std::vector<Attribute<Matrix>::Ptr> &leftVectors)
156 : Task(**inverter.mName + ".MnaPostStepHarm"), mInverter(inverter),
157 mLeftVectors(leftVectors) {
158 for (UInt i = 0; i < mLeftVectors.size(); i++)
159 mAttributeDependencies.push_back(mLeftVectors[i]);
160 mModifiedAttributes.push_back(mInverter.attribute("i_intf"));
161 }
162 void execute(Real time, Int timeStepCount);
163
164 private:
165 Inverter &mInverter;
166 std::vector<Attribute<Matrix>::Ptr> mLeftVectors;
167 };
168};
169} // namespace Ph1
170} // namespace DP
171} // namespace CPS
std::vector< Ptr > List
Definition Attribute.h:123
AttributePointer< Attribute< T > > Ptr
Definition Attribute.h:250
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:53
std::vector< AttributeBase::Ptr > mAttributeDependencies
Definition Task.h:52
Task()
Definition Task.h:30
std::string mName
Definition Task.h:51
#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
Eigen::Matrix< Int, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor > MatrixInt
Dense matrix for integers.
Definition Definitions.h:87
double Real
Definition Definitions.h:62
int Int
Definition Definitions.h:61
unsigned int UInt
Definition Definitions.h:60
Eigen::SparseMatrix< Real, Eigen::RowMajor > SparseMatrixRow
Sparse matrix for real numbers (row major).
Definition Definitions.h:74