DPsim
Loading...
Searching...
No Matches
EMT_Ph3_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
11#include <array>
12
15#include <dpsim-models/Logger.h>
19
20namespace CPS {
21namespace EMT {
22namespace Ph3 {
23
43class Switch : public MNASimPowerComp<Real>,
44 public Base::Ph3::Switch,
45 public SharedFactory<Switch>,
47 public MNASwitchInterface {
48public:
54
58
63
68
78
83
84 Switch(String uid, String name, Logger::Level logLevel = Logger::Level::off);
85
86 Switch(String name, Logger::Level logLevel = Logger::Level::off)
87 : Switch(name, name, logLevel) {}
88
90
93 SwitchingMode switchingMode() const { return mSwitchingMode; }
94
96 void setZeroCrossingTolerance(Real tolerance);
97 Real zeroCrossingTolerance() const { return mZeroCrossingTolerance; }
98
100 void setExponentialSwitchingTime(Real switchingTime);
101 Real exponentialSwitchingTime() const { return mExponentialSwitchingTime; }
102
113 void openSwitch() override;
114
123 void closeSwitch() override;
124
125 // #### General ####
126 void initializeFromNodesAndTerminals(Real frequency) override;
127
128 // #### General MNA section ####
129 void mnaCompInitialize(Real omega, Real timeStep,
130 Attribute<Matrix>::Ptr leftVector) override;
131
132 void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override;
133 void mnaCompApplyRightSideVectorStamp(Matrix &rightVector) override;
134
135 void mnaCompUpdateVoltage(const Matrix &leftVector) override;
136 void mnaCompUpdateCurrent(const Matrix &leftVector) override;
137
138 // #### MNA switch interface ####
139 Bool mnaIsClosed() override;
140
143
145 SparseMatrixRow &systemMatrix,
146 Int freqIdx) override;
147
148 void mnaCompPostStep(Real time, Int timeStepCount,
149 Attribute<Matrix>::Ptr &leftVector) override;
150
151 void
153 AttributeBase::List &attributeDependencies,
154 AttributeBase::List &modifiedAttributes,
155 Attribute<Matrix>::Ptr &leftVector) override;
156
157 // #### Variable component interface ####
158 Bool hasParameterChanged() override;
159
160private:
161 SwitchingMode mSwitchingMode = SwitchingMode::Ideal;
162
163 Real mZeroCrossingTolerance = 1e-6;
164
167 Real mExponentialSwitchingTime = 0.01;
168
171 Real mTimeStep = 0.0;
172
173 std::array<Bool, 3> mPoleClosedPrev{{false, false, false}};
174 std::array<Real, 3> mEffectiveResistancePrev{{0.0, 0.0, 0.0}};
175
176 Matrix mPreviousCurrent = Matrix::Zero(3, 1);
177 Real mPreviousCurrentTime = 0.0;
178 Bool mPreviousCurrentValid = false;
179
180 Bool mResetZeroCrossingHistory = false;
181
182 Bool mExponentialTransitionStarted = false;
183
184 Bool poleClosed(UInt phase) const;
185 void setPoleClosed(UInt phase, Bool closed);
186 void setAllPoles(Bool closed);
187
188 Bool allPolesClosed() const;
189 Bool allPolesOpen() const;
190
191 void resetZeroCrossingTimes();
192
193 Real effectiveResistance(UInt phase) const;
194 void setEffectiveResistance(UInt phase, Real resistance);
195 void synchronizeEffectiveResistance(Bool closed);
196
197 void resetExponentialTransition();
198 void validateExponentialResistanceParameters() const;
199 Real exponentialResistance(UInt phase, Real alpha) const;
200 void updateExponentialTransition(Real time);
201
202 MatrixFixedSize<3, 3> currentConductanceMatrix() const;
203
204 Bool currentCrossedZero(Real previousCurrent, Real current) const;
205
206 Real interpolateZeroCrossingTime(Real previousCurrent, Real current,
207 Real previousTime, Real currentTime) const;
208
209 void setZeroCrossingTime(UInt phase, Real time);
210 void updateZeroCrossingState(Real time);
211};
212
213} // namespace Ph3
214} // namespace EMT
215} // namespace CPS
std::vector< Ptr > List
Definition Attribute.h:123
AttributePointer< Attribute< T > > Ptr
Definition Attribute.h:249
Common base for three-phase switches.
void mnaCompUpdateCurrent(const Matrix &leftVector) override
const Attribute< Bool >::Ptr mPoleClosedB
void setSwitchingMode(SwitchingMode mode)
Select switching model. Configure before simulation initialization.
const Attribute< Real >::Ptr mExponentialTransitionStartTime
const Attribute< Real >::Ptr mExponentialProgress
Bool hasParameterChanged() override
Returns true if one of the element paramters has changed.
const Attribute< Real >::Ptr mEffectiveResistanceC
SimPowerComp< Real >::Ptr clone(String name) override
Returns a modified copy of the component with the given suffix added to the name and without.
const Attribute< Bool >::Ptr mOpeningRequested
const Attribute< Bool >::Ptr mPoleClosedC
const Attribute< Real >::Ptr mExponentialTransitionEndTime
void mnaCompApplySwitchSystemMatrixStamp(Bool closed, SparseMatrixRow &systemMatrix, Int freqIdx) override
const Attribute< Real >::Ptr mEffectiveResistanceB
void closeSwitch() override
void mnaCompPostStep(Real time, Int timeStepCount, Attribute< Matrix >::Ptr &leftVector) override
Real exponentialSwitchingTime() const
const Attribute< Real >::Ptr mZeroCrossingTimeB
Switch(String uid, String name, Logger::Level logLevel=Logger::Level::off)
void setExponentialSwitchingTime(Real switchingTime)
Set total transition time for ExponentialZCSEmulation [s].
Real zeroCrossingTolerance() const
void mnaCompUpdateVoltage(const Matrix &leftVector) override
void mnaCompInitialize(Real omega, Real timeStep, Attribute< Matrix >::Ptr leftVector) override
void initializeFromNodesAndTerminals(Real frequency) override
Initializes Component variables according to power flow data stored in Nodes.
Bool supportsPrecomputedSystemMatrices() const override
Only Ideal is representable by the conventional two precomputed matrices.
void openSwitch() override
SwitchingMode switchingMode() const
const Attribute< Bool >::Ptr mExponentialTransitionClosing
True while the active exponential transition is a closing transition.
void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override
void setZeroCrossingTolerance(Real tolerance)
Absolute current tolerance used by CurrentZero mode [A].
const Attribute< Real >::Ptr mEffectiveResistanceA
Effective phase resistances currently stamped into the MNA matrix [ohm].
const Attribute< Bool >::Ptr mExponentialTransitionActive
Exponential-transition diagnostics.
Switch(String name, Logger::Level logLevel=Logger::Level::off)
void mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector) override
void mnaCompApplyRightSideVectorStamp(Matrix &rightVector) override
const Attribute< Bool >::Ptr mPoleClosedA
Physical pole states.
const Attribute< Real >::Ptr mZeroCrossingTimeC
Bool mnaIsClosed() override
Check if switch is closed.
const Attribute< Real >::Ptr mZeroCrossingTimeA
Estimated physical zero-crossing times [s], -1 if none has been detected.
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
Eigen::Matrix< Real, rows, cols, Eigen::ColMajor > MatrixFixedSize
Dense matrix for real numbers with fixed dimension.
double Real
Definition Definitions.h:62
int Int
Definition Definitions.h:61
bool Bool
Definition Definitions.h:64
unsigned int UInt
Definition Definitions.h:60
Eigen::SparseMatrix< Real, Eigen::RowMajor > SparseMatrixRow
Sparse matrix for real numbers (row major).
Definition Definitions.h:74