DPsim
DP_Ph1_Inductor.h
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 <dpsim-models/Base/Base_Ph1_Inductor.h>
12 #include <dpsim-models/MNASimPowerComp.h>
13 #include <dpsim-models/Solver/MNATearInterface.h>
14 
15 namespace CPS {
16 namespace DP {
17 namespace Ph1 {
25 class Inductor : public MNASimPowerComp<Complex>,
26  public Base::Ph1::Inductor,
27  public MNATearInterface,
28  public SharedFactory<Inductor> {
29 protected:
31  MatrixComp mEquivCurrent;
33  MatrixComp mEquivCond;
35  MatrixComp mPrevCurrFac;
37  void initVars(Real timeStep);
38 
39 public:
41  Inductor(String uid, String name,
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 ####
49  SimPowerComp<Complex>::Ptr clone(String name) override;
51  void initialize(Matrix frequencies) override;
53  void initializeFromNodesAndTerminals(Real frequency) override;
54 
55  // #### MNA section ####
57  void mnaCompInitialize(Real omega, Real timeStep,
58  Attribute<Matrix>::Ptr leftVector) override;
59  void mnaCompInitializeHarm(
60  Real omega, Real timeStep,
61  std::vector<Attribute<Matrix>::Ptr> leftVectors) override;
63  void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override;
64  void mnaCompApplySystemMatrixStampHarm(SparseMatrixRow &systemMatrix,
65  Int freqIdx) override;
67  void mnaCompApplyRightSideVectorStamp(Matrix &rightVector) override;
68  void mnaCompApplyRightSideVectorStampHarm(Matrix &rightVector) override;
70  void mnaCompUpdateVoltage(const Matrix &leftVector) override;
71  void mnaCompUpdateVoltageHarm(const Matrix &leftVector, Int freqIdx);
73  void mnaCompUpdateCurrent(const Matrix &leftVector) override;
74  void mnaCompUpdateCurrentHarm();
76  void mnaCompPreStep(Real time, Int timeStepCount) override;
78  void mnaCompPostStep(Real time, Int timeStepCount,
79  Attribute<Matrix>::Ptr &leftVector) override;
82  AttributeBase::List &prevStepDependencies,
83  AttributeBase::List &attributeDependencies,
84  AttributeBase::List &modifiedAttributes) override;
86  void
87  mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies,
88  AttributeBase::List &attributeDependencies,
89  AttributeBase::List &modifiedAttributes,
90  Attribute<Matrix>::Ptr &leftVector) override;
91 
92  // #### Tearing methods ####
93  void mnaTearInitialize(Real omega, Real timestep) override;
94  void mnaTearApplyMatrixStamp(SparseMatrixRow &tearMatrix) override;
95  void mnaTearApplyVoltageStamp(Matrix &voltageVector) override;
96  void mnaTearPostStep(Complex voltage, Complex current) override;
97 
98  class MnaPreStepHarm : public Task {
99  public:
100  MnaPreStepHarm(Inductor &inductor)
101  : Task(**inductor.mName + ".MnaPreStepHarm"), mInductor(inductor) {
102  // actually depends on L, but then we'd have to modify the system matrix anyway
103  mModifiedAttributes.push_back(inductor.attribute("right_vector"));
104  mPrevStepDependencies.push_back(inductor.attribute("v_intf"));
105  mPrevStepDependencies.push_back(inductor.attribute("i_intf"));
106  }
107  void execute(Real time, Int timeStepCount);
108 
109  private:
110  Inductor &mInductor;
111  };
112 
113  class MnaPostStepHarm : public Task {
114  public:
115  MnaPostStepHarm(Inductor &inductor,
116  const std::vector<Attribute<Matrix>::Ptr> &leftVectors)
117  : Task(**inductor.mName + ".MnaPostStepHarm"), mInductor(inductor),
118  mLeftVectors(leftVectors) {
119  for (UInt i = 0; i < mLeftVectors.size(); i++)
120  mAttributeDependencies.push_back(mLeftVectors[i]);
121  mModifiedAttributes.push_back(mInductor.attribute("v_intf"));
122  mModifiedAttributes.push_back(mInductor.attribute("i_intf"));
123  }
124  void execute(Real time, Int timeStepCount);
125 
126  private:
127  Inductor &mInductor;
128  std::vector<Attribute<Matrix>::Ptr> mLeftVectors;
129  };
130 };
131 } // namespace Ph1
132 } // namespace DP
133 } // namespace CPS
MatrixComp mEquivCond
Equivalent conductance for harmonics [S].
void mnaCompUpdateCurrent(const Matrix &leftVector) override
Update interface current from MNA system results.
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.
SimPowerComp< Complex >::Ptr clone(String name) override
Return new instance with the same parameters.
MatrixComp mEquivCurrent
DC equivalent current source for harmonics [A].
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.
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 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.
const Attribute< String >::Ptr mName
Human readable name.
String uid()
Returns unique id.
AttributeBase::Ptr attribute(const String &name) const
Return pointer to an attribute.
Base class for all MNA components that are transmitting power.
Base class for all components that are transmitting power.
Definition: SimPowerComp.h:17
Tasks to be defined by every component.
Definition: Task.h:25