DPsim
Loading...
Searching...
No Matches
DP_Ph3_Switch.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 Institute for Automation of Complex Power Systems, EONERC, RWTH Aachen University
2// SPDX-License-Identifier: MPL-2.0
3
4#pragma once
5
6#include <array>
7
10#include <dpsim-models/Logger.h>
14
15namespace CPS {
16namespace DP {
17namespace Ph3 {
18
43class Switch : public MNASimPowerComp<Complex>,
44 public Base::Ph3::Switch,
45 public SharedFactory<Switch>,
47 public MNASwitchInterface {
48public:
54
56
60
65
69
79
84
85 Switch(String uid, String name, Logger::Level loglevel = Logger::Level::off);
86
87 Switch(String name, Logger::Level logLevel = Logger::Level::off)
88 : Switch(name, name, logLevel) {}
89
91
93 SwitchingMode switchingMode() const { return mSwitchingMode; }
94
95 void setZeroCrossingTolerance(Real tolerance);
96
97 void setExponentialSwitchingTime(Real switchingTime);
98 Real exponentialSwitchingTime() const { return mExponentialSwitchingTime; }
99
100 void openSwitch() override;
101 void closeSwitch() override;
102
103 // #### General ####
104 void initializeFromNodesAndTerminals(Real frequency) override;
105
106 // #### General MNA ####
107 void mnaCompInitialize(Real omega, Real timeStep,
108 Attribute<Matrix>::Ptr leftVector) override;
109
110 void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override;
111
112 void mnaCompUpdateVoltage(const Matrix &leftVector) override;
113 void mnaCompUpdateCurrent(const Matrix &leftVector) override;
114
115 void mnaCompPostStep(Real time, Int timeStepCount,
116 Attribute<Matrix>::Ptr &leftVector) override;
117
118 void
120 AttributeBase::List &attributeDependencies,
121 AttributeBase::List &modifiedAttributes,
122 Attribute<Matrix>::Ptr &leftVector) override;
123
124 // #### Switch interface ####
125 Bool mnaIsClosed() override;
126
128 SparseMatrixRow &systemMatrix,
129 Int freqIdx) override;
130
132
133 // #### Variable-component interface ####
134 Bool hasParameterChanged() override;
135
136private:
137 SwitchingMode mSwitchingMode = SwitchingMode::Ideal;
138
139 Real mZeroCrossingTolerance = 1e-6;
140 Real mExponentialSwitchingTime = 0.01;
141 Real mTimeStep = 0.0;
142
144 Real mShiftOmega = 0.0;
145
146 std::array<Bool, 3> mPoleClosedPrev{{false, false, false}};
147 std::array<Real, 3> mEffectiveResistancePrev{{0.0, 0.0, 0.0}};
148
149 Matrix mPreviousInstantaneousCurrent = Matrix::Zero(3, 1);
150 Real mPreviousCurrentTime = 0.0;
151 Bool mPreviousCurrentValid = false;
152
153 Bool mResetZeroCrossingHistory = false;
154 Bool mExponentialTransitionStarted = false;
155
156 Bool poleClosed(UInt phase) const;
157 void setPoleClosed(UInt phase, Bool closed);
158 void setAllPoles(Bool closed);
159
160 Bool allPolesClosed() const;
161 Bool allPolesOpen() const;
162
163 void resetZeroCrossingTimes();
164
165 Real effectiveResistance(UInt phase) const;
166 void setEffectiveResistance(UInt phase, Real resistance);
167 void synchronizeEffectiveResistance(Bool closed);
168
169 void resetExponentialTransition();
170 void validateExponentialResistanceParameters() const;
171 Real exponentialResistance(UInt phase, Real alpha) const;
172 void updateExponentialTransition(Real time);
173
174 MatrixFixedSizeComp<3, 3> currentConductanceMatrix() const;
175
176 Matrix reconstructInstantaneousCurrent(Real time) const;
177 void setInstantaneousCurrentAttributes(const Matrix &current);
178
179 Bool currentCrossedZero(Real previousCurrent, Real current) const;
180
181 Real interpolateZeroCrossingTime(Real previousCurrent, Real current,
182 Real previousTime, Real currentTime) const;
183
184 void setZeroCrossingTime(UInt phase, Real time);
185 void updateZeroCrossingState(Real time);
186};
187
188} // namespace Ph3
189} // namespace DP
190} // namespace CPS
std::vector< Ptr > List
Definition Attribute.h:123
AttributePointer< Attribute< T > > Ptr
Definition Attribute.h:249
Common base for three-phase switches.
const Attribute< Bool >::Ptr mPoleClosedA
Bool hasParameterChanged() override
Returns true if one of the element paramters has changed.
void closeSwitch() override
const Attribute< Bool >::Ptr mPoleClosedB
const Attribute< Real >::Ptr mInstantCurrentA
Reconstructed physical instantaneous currents [A].
void mnaCompUpdateCurrent(const Matrix &leftVector) override
void setZeroCrossingTolerance(Real tolerance)
void setExponentialSwitchingTime(Real switchingTime)
const Attribute< Bool >::Ptr mExponentialTransitionActive
Exponential-transition diagnostics.
const Attribute< Real >::Ptr mEffectiveResistanceA
Effective phase resistances currently stamped into the MNA matrix [ohm].
const Attribute< Real >::Ptr mExponentialTransitionStartTime
Real exponentialSwitchingTime() const
const Attribute< Bool >::Ptr mExponentialTransitionClosing
True while the active exponential transition is a closing transition.
void mnaCompUpdateVoltage(const Matrix &leftVector) override
Switch(String uid, String name, Logger::Level loglevel=Logger::Level::off)
const Attribute< Real >::Ptr mZeroCrossingTimeB
Bool mnaIsClosed() override
Check if switch is closed.
Switch(String name, Logger::Level logLevel=Logger::Level::off)
void setSwitchingMode(SwitchingMode mode)
SwitchingMode switchingMode() const
const Attribute< Real >::Ptr mExponentialTransitionEndTime
const Attribute< Real >::Ptr mZeroCrossingTimeA
const Attribute< Bool >::Ptr mPoleClosedC
void openSwitch() override
Bool supportsPrecomputedSystemMatrices() const override
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
const Attribute< Real >::Ptr mInstantCurrentC
const Attribute< Real >::Ptr mEffectiveResistanceB
const Attribute< Real >::Ptr mInstantCurrentB
void initializeFromNodesAndTerminals(Real frequency) override
Initializes Component variables according to power flow data stored in Nodes.
void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override
const Attribute< Bool >::Ptr mOpeningRequested
void mnaCompApplySwitchSystemMatrixStamp(Bool closed, SparseMatrixRow &systemMatrix, Int freqIdx) override
void mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector) override
void mnaCompInitialize(Real omega, Real timeStep, Attribute< Matrix >::Ptr leftVector) override
const Attribute< Real >::Ptr mEffectiveResistanceC
const Attribute< Real >::Ptr mExponentialProgress
const Attribute< Real >::Ptr mZeroCrossingTimeC
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
bool Bool
Definition Definitions.h:64
unsigned int UInt
Definition Definitions.h:60
Eigen::Matrix< Complex, rows, cols, Eigen::ColMajor > MatrixFixedSizeComp
Dense matrix for complex numbers with fixed dimension.
Eigen::SparseMatrix< Real, Eigen::RowMajor > SparseMatrixRow
Sparse matrix for real numbers (row major).
Definition Definitions.h:74