DPsim
Loading...
Searching...
No Matches
DP_Ph1_Inductor.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
14
15namespace CPS {
16namespace DP {
17namespace Ph1 {
25class Inductor : public MNASimPowerComp<Complex>,
27 public MNATearInterface,
28 public SharedFactory<Inductor> {
29protected:
37 void initVars(Real timeStep);
38
39public:
42 Logger::Level logLevel = Logger::Level::off);
44 Inductor(String name, Logger::Level logLevel = Logger::Level::off)
45 : Inductor(name, name, logLevel) {}
46
47 // #### General ####
51 void initialize(Matrix frequencies) override;
53 void initializeFromNodesAndTerminals(Real frequency) override;
54
55 // #### MNA section ####
59 void mnaCompInitialize(Real omega, Real timeStep,
60 Attribute<Matrix>::Ptr leftVector) override;
62 Real omega, Real timeStep,
63 std::vector<Attribute<Matrix>::Ptr> leftVectors) override;
65 void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override;
67 Int freqIdx) override;
69 void mnaCompApplyRightSideVectorStamp(Matrix &rightVector) override;
70 void mnaCompApplyRightSideVectorStampHarm(Matrix &rightVector) override;
72 void mnaCompUpdateVoltage(const Matrix &leftVector) override;
73 void mnaCompUpdateVoltageHarm(const Matrix &leftVector, Int freqIdx);
75 void mnaCompUpdateCurrent(const Matrix &leftVector) override;
78 void mnaCompPreStep(Real time, Int timeStepCount) override;
80 void mnaCompPostStep(Real time, Int timeStepCount,
81 Attribute<Matrix>::Ptr &leftVector) override;
84 AttributeBase::List &prevStepDependencies,
85 AttributeBase::List &attributeDependencies,
86 AttributeBase::List &modifiedAttributes) override;
88 void
90 AttributeBase::List &attributeDependencies,
91 AttributeBase::List &modifiedAttributes,
92 Attribute<Matrix>::Ptr &leftVector) override;
93
94 // #### Tearing methods ####
95 void mnaTearInitialize(Real omega, Real timestep) override;
96 void mnaTearApplyMatrixStamp(SparseMatrixRow &tearMatrix) override;
97 void mnaTearApplyVoltageStamp(Matrix &voltageVector) override;
98 void mnaTearPostStep(Complex voltage, Complex current) override;
99
100 class MnaPreStepHarm : public Task {
101 public:
103 : Task(**inductor.mName + ".MnaPreStepHarm"), mInductor(inductor) {
104 // actually depends on L, but then we'd have to modify the system matrix anyway
105 mModifiedAttributes.push_back(inductor.attribute("right_vector"));
106 mPrevStepDependencies.push_back(inductor.attribute("v_intf"));
107 mPrevStepDependencies.push_back(inductor.attribute("i_intf"));
108 }
109 void execute(Real time, Int timeStepCount);
110
111 private:
112 Inductor &mInductor;
113 };
114
115 class MnaPostStepHarm : public Task {
116 public:
118 const std::vector<Attribute<Matrix>::Ptr> &leftVectors)
119 : Task(**inductor.mName + ".MnaPostStepHarm"), mInductor(inductor),
120 mLeftVectors(leftVectors) {
121 for (UInt i = 0; i < mLeftVectors.size(); i++)
122 mAttributeDependencies.push_back(mLeftVectors[i]);
123 mModifiedAttributes.push_back(mInductor.attribute("v_intf"));
124 mModifiedAttributes.push_back(mInductor.attribute("i_intf"));
125 }
126 void execute(Real time, Int timeStepCount);
127
128 private:
129 Inductor &mInductor;
130 std::vector<Attribute<Matrix>::Ptr> mLeftVectors;
131 };
132};
133} // namespace Ph1
134} // namespace DP
135} // namespace CPS
std::vector< Ptr > List
Definition Attribute.h:123
AttributePointer< Attribute< T > > Ptr
Definition Attribute.h:250
void execute(Real time, Int timeStepCount)
MnaPostStepHarm(Inductor &inductor, const std::vector< Attribute< Matrix >::Ptr > &leftVectors)
void execute(Real time, Int timeStepCount)
void mnaTearApplyVoltageStamp(Matrix &voltageVector) override
MatrixComp mEquivCond
Equivalent conductance for harmonics [S].
void mnaTearApplyMatrixStamp(SparseMatrixRow &tearMatrix) override
void mnaCompUpdateCurrent(const Matrix &leftVector) override
Update interface current from MNA system results.
void mnaCompInitializeHarm(Real omega, Real timeStep, std::vector< Attribute< Matrix >::Ptr > leftVectors) override
Inductor(String name, Logger::Level logLevel=Logger::Level::off)
Defines name and log level.
void mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector) override
Add MNA post step dependencies.
void mnaCompApplySystemMatrixStampHarm(SparseMatrixRow &systemMatrix, Int freqIdx) override
void mnaCompUpdateVoltageHarm(const Matrix &leftVector, Int freqIdx)
void initVars(Real timeStep)
void mnaTearInitialize(Real omega, Real timestep) override
SimPowerComp< Complex >::Ptr clone(String name) override
Return new instance with the same parameters.
MatrixComp mEquivCurrent
DC equivalent current source for harmonics [A].
void mnaTearPostStep(Complex voltage, Complex current) override
void mnaCompAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes) override
Add MNA pre step dependencies.
void mnaCompInitialize(Real omega, Real timeStep, Attribute< Matrix >::Ptr leftVector) override
Initializes MNA specific variables.
void mnaCompUpdateVoltage(const Matrix &leftVector) override
Update interface voltage from MNA system results.
Complex getMNAConductance() const
Return single-frequency MNA companion conductance.
void mnaCompPostStep(Real time, Int timeStepCount, Attribute< Matrix >::Ptr &leftVector) override
MNA post step operations.
MatrixComp mPrevCurrFac
Coefficient in front of previous current value for harmonics.
void mnaCompApplyRightSideVectorStamp(Matrix &rightVector) override
Stamps right side (source) vector.
void initializeFromNodesAndTerminals(Real frequency) override
Initializes states from power flow data.
void initialize(Matrix frequencies) override
Initializes state variables considering the number of frequencies.
void mnaCompApplyRightSideVectorStampHarm(Matrix &rightVector) override
void mnaCompPreStep(Real time, Int timeStepCount) override
MNA pre step operations.
void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override
Stamps system matrix.
Inductor(String uid, String name, Logger::Level logLevel=Logger::Level::off)
Defines UID, name and log level.
String uid()
Returns unique id.
AttributeBase::Ptr attribute(const String &name) const
Return pointer to an attribute.
spdlog::level::level_enum Level
Definition Logger.h:33
MNASimPowerComp(String uid, String name, Bool hasPreStep, Bool hasPostStep, Logger::Level logLevel)
std::shared_ptr< SimPowerComp< VarType > > Ptr
std::vector< AttributeBase::Ptr > mModifiedAttributes
Definition Task.h:53
std::vector< AttributeBase::Ptr > mPrevStepDependencies
Definition Task.h:54
std::vector< AttributeBase::Ptr > mAttributeDependencies
Definition Task.h:52
Task()
Definition Task.h:30
std::string mName
Definition Task.h:51
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
unsigned int UInt
Definition Definitions.h:60
Eigen::SparseMatrix< Real, Eigen::RowMajor > SparseMatrixRow
Sparse matrix for real numbers (row major).
Definition Definitions.h:74