DPsim
Loading...
Searching...
No Matches
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
15namespace CPS {
16namespace DP {
17namespace Ph1 {
25class Inductor : public MNASimPowerComp<Complex>,
27 public MNATearInterface,
28 public SharedFactory<Inductor> {
29protected:
31 MatrixComp mEquivCurrent;
33 MatrixComp mEquivCond;
35 MatrixComp mPrevCurrFac;
37 void initVars(Real timeStep);
38
39public:
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 Complex getMNAConductance() const;
59 void mnaCompInitialize(Real omega, Real timeStep,
60 Attribute<Matrix>::Ptr leftVector) override;
61 void mnaCompInitializeHarm(
62 Real omega, Real timeStep,
63 std::vector<Attribute<Matrix>::Ptr> leftVectors) override;
65 void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override;
66 void mnaCompApplySystemMatrixStampHarm(SparseMatrixRow &systemMatrix,
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;
76 void mnaCompUpdateCurrentHarm();
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
89 mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies,
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:
102 MnaPreStepHarm(Inductor &inductor)
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:
117 MnaPostStepHarm(Inductor &inductor,
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
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.
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 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.
MNASimPowerComp(String uid, String name, Bool hasPreStep, Bool hasPostStep, Logger::Level logLevel)