DPsim
SP_Ph1_varResSwitch.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_Switch.h>
12 #include <dpsim-models/MNASimPowerComp.h>
13 #include <dpsim-models/Solver/MNAInterface.h>
14 #include <dpsim-models/Solver/MNASwitchInterface.h>
15 #include <dpsim-models/Solver/MNAVariableCompInterface.h>
16 
17 namespace CPS {
18 namespace SP {
19 namespace Ph1 {
24 
27 class varResSwitch : public MNASimPowerComp<Complex>,
28  public Base::Ph1::Switch,
30  public MNASwitchInterface,
31  public SharedFactory<varResSwitch> {
32 
33 protected:
34  Bool mPrevState = false;
35  Real mDeltaResClosed = 0;
36  Real mDeltaResOpen = 1.5;
37  Real mPrevRes; // previous resistance value to multiply with rate of change
38  // because we change the base value mClosedResistance & mOpenResistance to recompute the system Matrix
39  // we need to save the initialisation values to use them as target values in the transition
40  Real mInitClosedRes;
41  Real mInitOpenRes;
42 
43 public:
44  void setInitParameters(Real timestep);
45 
47  varResSwitch(String uid, String name,
48  Logger::Level logLevel = Logger::Level::off);
50  varResSwitch(String name, Logger::Level logLevel = Logger::Level::off)
51  : varResSwitch(name, name, logLevel) {}
52 
53  // varResSwitch(String name, Real openRes, Real closedRes ,
54  // Logger::Level logLevel = Logger::Level::off);
55 
56  SimPowerComp<Complex>::Ptr clone(String name);
57 
58  // #### General ####
60  void initializeFromNodesAndTerminals(Real frequency);
61 
62  // #### MNA section ####
64  void mnaCompInitialize(Real omega, Real timeStep,
65  Attribute<Matrix>::Ptr leftVector);
66  //void mnaCompInitializeHarm(Real omega, Real timeStep, std::vector<Attribute<Matrix>::Ptr> leftVectors);
68  void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix);
70  void mnaCompApplyRightSideVectorStamp(Matrix &rightVector);
72  void mnaCompUpdateVoltage(const Matrix &leftVector);
74  void mnaCompUpdateCurrent(const Matrix &leftVector);
76  // void mnaCompPreStep(Real time, Int timeStepCount);
78  void mnaCompPostStep(Real time, Int timeStepCount,
79  Attribute<Matrix>::Ptr &leftVector);
83  void
84  mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies,
85  AttributeBase::List &attributeDependencies,
86  AttributeBase::List &modifiedAttributes,
87  Attribute<Matrix>::Ptr &leftVector);
88 
89  // #### MNA section for switch ####
91  Bool mnaIsClosed();
93  void mnaCompApplySwitchSystemMatrixStamp(Bool closed,
94  SparseMatrixRow &systemMatrix,
95  Int freqIdx);
96 
97  Bool hasParameterChanged();
98 };
99 } // namespace Ph1
100 } // namespace SP
101 } // namespace CPS
Dynamic Phasor Three-Phase Switch.
String uid()
Returns unique id.
Base class for all MNA components that are transmitting power.
MNA interface to be used by switching devices.
MNA interface to be used by elements that require recomputing of the system matrix.
Switch with variable resistance to avoid numerical oscillations, when an inductive current is suddenl...
void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix)
Stamps system matrix.
Bool mnaIsClosed()
Check if switch is closed.
void mnaCompApplySwitchSystemMatrixStamp(Bool closed, SparseMatrixRow &systemMatrix, Int freqIdx)
Stamps system matrix considering the defined switch position.
SimPowerComp< Complex >::Ptr clone(String name)
Returns a modified copy of the component with the given suffix added to the name and without.
Bool hasParameterChanged()
Returns true if one of the element paramters has changed.
void initializeFromNodesAndTerminals(Real frequency)
Initializes states from power flow data.
void mnaCompUpdateCurrent(const Matrix &leftVector)
Update interface current from MNA system results.
varResSwitch(String uid, String name, Logger::Level logLevel=Logger::Level::off)
Defines UID, name and log level.
void mnaCompInitialize(Real omega, Real timeStep, Attribute< Matrix >::Ptr leftVector)
Initializes MNA specific variables.
void mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector)
void mnaCompPostStep(Real time, Int timeStepCount, Attribute< Matrix >::Ptr &leftVector)
MNA pre step operations.
void mnaCompUpdateVoltage(const Matrix &leftVector)
Update interface voltage from MNA system results.
varResSwitch(String name, Logger::Level logLevel=Logger::Level::off)
Defines name and log level.
void mnaCompApplyRightSideVectorStamp(Matrix &rightVector)
Stamps right side (source) vector.
Base class for all components that are transmitting power.
Definition: SimPowerComp.h:17