DPsim
Loading...
Searching...
No Matches
DP_Ph1_Switch.h
Go to the documentation of this file.
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
13#include <dpsim-models/Logger.h>
17
18namespace CPS {
19namespace DP {
20namespace Ph1 {
47class Switch : public MNASimPowerComp<Complex>,
48 public Base::Ph1::Switch,
49 public SharedFactory<Switch>,
50 public MNASwitchInterface,
52public:
58
60
62
65
67
77
80
82 Switch(String uid, String name, Logger::Level loglevel = Logger::Level::off);
84 Switch(String name, Logger::Level logLevel = Logger::Level::off)
85 : Switch(name, name, logLevel) {}
86
88
90 SwitchingMode switchingMode() const { return mSwitchingMode; }
91
92 void setZeroCrossingTolerance(Real tolerance);
93
94 void setExponentialSwitchingTime(Real switchingTime);
95 Real exponentialSwitchingTime() const { return mExponentialSwitchingTime; }
96
97 void openSwitch() override;
98 void closeSwitch() override;
99
100 // #### General ####
102 void initializeFromNodesAndTerminals(Real frequency) override;
103
104 // #### General MNA section ####
105 void mnaCompInitialize(Real omega, Real timeStep,
106 Attribute<Matrix>::Ptr leftVector) override;
108 void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override;
110 void mnaCompApplyRightSideVectorStamp(Matrix &rightVector) override;
112 void mnaCompUpdateVoltage(const Matrix &leftVector) override;
114 void mnaCompUpdateCurrent(const Matrix &leftVector) override;
116 void mnaCompPostStep(Real time, Int timeStepCount,
117 Attribute<Matrix>::Ptr &leftVector) override;
119 void
121 AttributeBase::List &attributeDependencies,
122 AttributeBase::List &modifiedAttributes,
123 Attribute<Matrix>::Ptr &leftVector) override;
124
125 // #### MNA section for switch ####
127 Bool mnaIsClosed() override;
130 SparseMatrixRow &systemMatrix,
131 Int freqIdx) override;
132
134
135 // #### MNA section for variable component ####
136 Bool hasParameterChanged() override;
137
138private:
139 SwitchingMode mSwitchingMode = SwitchingMode::Ideal;
140
141 Real mZeroCrossingTolerance = 1e-6;
142 Real mExponentialSwitchingTime = 0.01;
143 Real mTimeStep = 0.0;
144
146 Real mShiftOmega = 0.0;
147
148 Bool mPoleClosedPrev = false;
149 Real mEffectiveResistancePrev = 0.0;
150
151 Real mPreviousInstantaneousCurrent = 0.0;
152 Real mPreviousCurrentTime = 0.0;
153 Bool mPreviousCurrentValid = false;
154
155 Bool mResetZeroCrossingHistory = false;
156 Bool mExponentialTransitionStarted = false;
157
158 void setPoleClosed(Bool closed);
159
160 void resetZeroCrossingTime();
161
162 void synchronizeEffectiveResistance(Bool closed);
163
164 void resetExponentialTransition();
165 void validateExponentialResistanceParameters() const;
166 Real exponentialResistance(Real alpha) const;
167 void updateExponentialTransition(Real time);
168
169 Complex currentConductance() const;
170
171 Real reconstructInstantaneousCurrent(Real time) const;
172
173 Bool currentCrossedZero(Real previousCurrent, Real current) const;
174
175 Real interpolateZeroCrossingTime(Real previousCurrent, Real current,
176 Real previousTime, Real currentTime) const;
177
178 void updateZeroCrossingState(Real time);
179};
180} // namespace Ph1
181} // namespace DP
182} // namespace CPS
std::vector< Ptr > List
Definition Attribute.h:123
AttributePointer< Attribute< T > > Ptr
Definition Attribute.h:249
Dynamic Phasor Three-Phase Switch.
SimPowerComp< Complex >::Ptr clone(String name) override
Returns a modified copy of the component with the given suffix added to the name and without.
const Attribute< Real >::Ptr mInstantCurrent
Reconstructed physical instantaneous current [A].
void setSwitchingMode(SwitchingMode mode)
void initializeFromNodesAndTerminals(Real frequency) override
Initializes component from power flow data.
const Attribute< Bool >::Ptr mPoleClosed
void closeSwitch() override
Bool mnaIsClosed() override
Check if switch is closed.
void setExponentialSwitchingTime(Real switchingTime)
Switch(String name, Logger::Level logLevel=Logger::Level::off)
Defines name, component parameters and logging level.
void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override
Stamps system matrix.
void mnaCompApplyRightSideVectorStamp(Matrix &rightVector) override
Stamps right side (source) vector.
Bool hasParameterChanged() override
Returns true if one of the element paramters has changed.
void mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector) override
Add MNA post step dependencies.
const Attribute< Real >::Ptr mEffectiveResistance
Effective resistance currently stamped into the MNA matrix [ohm].
Switch(String uid, String name, Logger::Level loglevel=Logger::Level::off)
Defines UID, name, component parameters and logging level.
const Attribute< Real >::Ptr mZeroCrossingTime
const Attribute< Bool >::Ptr mExponentialTransitionActive
Exponential-transition diagnostics.
const Attribute< Bool >::Ptr mOpeningRequested
Real exponentialSwitchingTime() const
void mnaCompUpdateCurrent(const Matrix &leftVector) override
Update interface current from MNA system result.
const Attribute< Bool >::Ptr mExponentialTransitionClosing
True while the active exponential transition is a closing transition.
void setZeroCrossingTolerance(Real tolerance)
const Attribute< Real >::Ptr mExponentialTransitionEndTime
void mnaCompApplySwitchSystemMatrixStamp(Bool closed, SparseMatrixRow &systemMatrix, Int freqIdx) override
Stamps system matrix considering the defined switch position.
void mnaCompInitialize(Real omega, Real timeStep, Attribute< Matrix >::Ptr leftVector) override
void mnaCompPostStep(Real time, Int timeStepCount, Attribute< Matrix >::Ptr &leftVector) override
MNA post step operations.
void openSwitch() override
void mnaCompUpdateVoltage(const Matrix &leftVector) override
Update interface voltage from MNA system result.
const Attribute< Real >::Ptr mExponentialProgress
const Attribute< Real >::Ptr mExponentialTransitionStartTime
SwitchingMode switchingMode() const
Bool supportsPrecomputedSystemMatrices() const override
String uid()
Returns unique id.
spdlog::level::level_enum Level
Definition Logger.h:33
MNASimPowerComp(String uid, String name, Bool hasPreStep, Bool hasPostStep, Logger::Level logLevel)
MNA interface to be used by switching devices.
MNA interface to be used by elements that require recomputing of the system matrix.
std::shared_ptr< SimPowerComp< VarType > > Ptr
Eigen::Matrix< Real, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor > Matrix
Dense matrix for real numbers.
Definition Definitions.h:81
std::string String
Definition Definitions.h:65
double Real
Definition Definitions.h:62
int Int
Definition Definitions.h:61
std::complex< Real > Complex
Definition Definitions.h:63
bool Bool
Definition Definitions.h:64
Eigen::SparseMatrix< Real, Eigen::RowMajor > SparseMatrixRow
Sparse matrix for real numbers (row major).
Definition Definitions.h:74