DPsim
Loading...
Searching...
No Matches
DP_Ph1_Capacitor.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_Capacitor.h>
12#include <dpsim-models/MNASimPowerComp.h>
13
14namespace CPS {
15namespace DP {
16namespace Ph1 {
24class Capacitor : public MNASimPowerComp<Complex>,
26 public SharedFactory<Capacitor> {
27protected:
29 MatrixComp mEquivCurrent;
31 MatrixComp mEquivCond;
33 MatrixComp mPrevVoltCoeff;
34
35public:
37 Capacitor(String uid, String name,
38 Logger::Level logLevel = Logger::Level::off);
40 Capacitor(String name, Logger::Level logLevel = Logger::Level::off)
41 : Capacitor(name, name, logLevel) {}
42
43 SimPowerComp<Complex>::Ptr clone(String name) override;
44
45 // #### General ####
47 void initializeFromNodesAndTerminals(Real frequency) override;
49 void initialize(Matrix frequencies) override;
50
51 // #### MNA section ####
53 Complex getMNAConductance() const;
55 void mnaCompInitialize(Real omega, Real timeStep,
56 Attribute<Matrix>::Ptr leftVector) override;
57 void mnaCompInitializeHarm(
58 Real omega, Real timeStep,
59 std::vector<Attribute<Matrix>::Ptr> leftVector) override;
61 void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override;
62 void mnaCompApplySystemMatrixStampHarm(SparseMatrixRow &systemMatrix,
63 Int freqIdx) override;
65 void mnaCompApplyRightSideVectorStamp(Matrix &rightVector) override;
66 void mnaCompApplyRightSideVectorStampHarm(Matrix &rightVector) override;
68 void mnaCompUpdateVoltage(const Matrix &leftVector) override;
69 void mnaCompUpdateVoltageHarm(const Matrix &leftVector, Int freqIdx);
70 void mnaCompApplyRightSideVectorStampHarm(Matrix &sourceVector,
71 Int freqIdx) override;
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 class MnaPreStepHarm : public CPS::Task {
93 public:
94 MnaPreStepHarm(Capacitor &capacitor)
95 : Task(**capacitor.mName + ".MnaPreStepHarm"), mCapacitor(capacitor) {
96 // actually depends on C, but then we'd have to modify the system matrix anyway
97 mModifiedAttributes.push_back(capacitor.attribute("right_vector"));
98 mPrevStepDependencies.push_back(capacitor.attribute("i_intf"));
99 mPrevStepDependencies.push_back(capacitor.attribute("v_intf"));
100 }
101 void execute(Real time, Int timeStepCount);
102
103 private:
104 Capacitor &mCapacitor;
105 };
106
107 class MnaPostStepHarm : public CPS::Task {
108 public:
109 MnaPostStepHarm(Capacitor &capacitor,
110 const std::vector<Attribute<Matrix>::Ptr> &leftVectors)
111 : Task(**capacitor.mName + ".MnaPostStepHarm"), mCapacitor(capacitor),
112 mLeftVectors(leftVectors) {
113 for (UInt i = 0; i < mLeftVectors.size(); i++)
114 mAttributeDependencies.push_back(mLeftVectors[i]);
115 mModifiedAttributes.push_back(mCapacitor.attribute("v_intf"));
116 mModifiedAttributes.push_back(mCapacitor.attribute("i_intf"));
117 }
118 void execute(Real time, Int timeStepCount);
119
120 private:
121 Capacitor &mCapacitor;
122 std::vector<Attribute<Matrix>::Ptr> mLeftVectors;
123 };
124};
125} // namespace Ph1
126} // namespace DP
127} // namespace CPS
Capacitor(String name, Logger::Level logLevel=Logger::Level::off)
Defines name, component parameters and logging level.
void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override
Stamps system matrix.
Capacitor(String uid, String name, Logger::Level logLevel=Logger::Level::off)
Defines UID, name and logging level.
void mnaCompPreStep(Real time, Int timeStepCount) override
MNA pre step operations.
void mnaCompAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes) override
Add MNA pre step dependencies.
void initializeFromNodesAndTerminals(Real frequency) override
Initializes component from power flow data.
MatrixComp mPrevVoltCoeff
Coefficient in front of previous voltage value for harmonics.
void mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector) override
Add MNA post step dependencies.
void initialize(Matrix frequencies) override
Initialize components with correct network frequencies.
MatrixComp mEquivCurrent
DC equivalent current source for harmonics [A].
Complex getMNAConductance() const
Return single-frequency MNA companion conductance.
void mnaCompInitialize(Real omega, Real timeStep, Attribute< Matrix >::Ptr leftVector) override
Initializes internal variables of the component.
void mnaCompUpdateVoltage(const Matrix &leftVector) override
Update interface voltage from MNA system result.
MatrixComp mEquivCond
Equivalent conductance for harmonics [S].
void mnaCompUpdateCurrent(const Matrix &leftVector) override
Update interface current from MNA system result.
void mnaCompApplyRightSideVectorStamp(Matrix &rightVector) override
Stamps right side (source) vector.
SimPowerComp< Complex >::Ptr clone(String name) override
Returns a modified copy of the component with the given suffix added to the name and without.
void mnaCompPostStep(Real time, Int timeStepCount, Attribute< Matrix >::Ptr &leftVector) override
MNA post step operations.
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)
Tasks to be defined by every component.
Definition Task.h:25