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 void mnaCompInitialize(Real omega, Real timeStep,
54 Attribute<Matrix>::Ptr leftVector) override;
55 void mnaCompInitializeHarm(
56 Real omega, Real timeStep,
57 std::vector<Attribute<Matrix>::Ptr> leftVector) override;
59 void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override;
60 void mnaCompApplySystemMatrixStampHarm(SparseMatrixRow &systemMatrix,
61 Int freqIdx) override;
63 void mnaCompApplyRightSideVectorStamp(Matrix &rightVector) override;
64 void mnaCompApplyRightSideVectorStampHarm(Matrix &rightVector) override;
66 void mnaCompUpdateVoltage(const Matrix &leftVector) override;
67 void mnaCompUpdateVoltageHarm(const Matrix &leftVector, Int freqIdx);
68 void mnaCompApplyRightSideVectorStampHarm(Matrix &sourceVector,
69 Int freqIdx) override;
71 void mnaCompUpdateCurrent(const Matrix &leftVector) override;
72 void mnaCompUpdateCurrentHarm();
74 void mnaCompPreStep(Real time, Int timeStepCount) override;
76 void mnaCompPostStep(Real time, Int timeStepCount,
77 Attribute<Matrix>::Ptr &leftVector) override;
80 AttributeBase::List &prevStepDependencies,
81 AttributeBase::List &attributeDependencies,
82 AttributeBase::List &modifiedAttributes) override;
84 void
85 mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies,
86 AttributeBase::List &attributeDependencies,
87 AttributeBase::List &modifiedAttributes,
88 Attribute<Matrix>::Ptr &leftVector) override;
89
90 class MnaPreStepHarm : public CPS::Task {
91 public:
92 MnaPreStepHarm(Capacitor &capacitor)
93 : Task(**capacitor.mName + ".MnaPreStepHarm"), mCapacitor(capacitor) {
94 // actually depends on C, but then we'd have to modify the system matrix anyway
95 mModifiedAttributes.push_back(capacitor.attribute("right_vector"));
96 mPrevStepDependencies.push_back(capacitor.attribute("i_intf"));
97 mPrevStepDependencies.push_back(capacitor.attribute("v_intf"));
98 }
99 void execute(Real time, Int timeStepCount);
100
101 private:
102 Capacitor &mCapacitor;
103 };
104
105 class MnaPostStepHarm : public CPS::Task {
106 public:
107 MnaPostStepHarm(Capacitor &capacitor,
108 const std::vector<Attribute<Matrix>::Ptr> &leftVectors)
109 : Task(**capacitor.mName + ".MnaPostStepHarm"), mCapacitor(capacitor),
110 mLeftVectors(leftVectors) {
111 for (UInt i = 0; i < mLeftVectors.size(); i++)
112 mAttributeDependencies.push_back(mLeftVectors[i]);
113 mModifiedAttributes.push_back(mCapacitor.attribute("v_intf"));
114 mModifiedAttributes.push_back(mCapacitor.attribute("i_intf"));
115 }
116 void execute(Real time, Int timeStepCount);
117
118 private:
119 Capacitor &mCapacitor;
120 std::vector<Attribute<Matrix>::Ptr> mLeftVectors;
121 };
122};
123} // namespace Ph1
124} // namespace DP
125} // 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].
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