DPsim
Loading...
Searching...
No Matches
DP_Ph3_Switch.cpp
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
5
6using namespace CPS;
7
9 : MNASimPowerComp<Complex>(uid, name, false, true, logLevel),
13 **mIntfVoltage = MatrixComp::Zero(3, 1);
14 **mIntfCurrent = MatrixComp::Zero(3, 1);
15}
16
22
24 mTerminals[0]->setPhaseType(PhaseType::ABC);
25 mTerminals[1]->setPhaseType(PhaseType::ABC);
26
27 Matrix impedance = (**mIsClosed) ? **mClosedResistance : **mOpenResistance;
28 // Voltage across component is defined as V1 - V0.
30 **mIntfCurrent = impedance.inverse() * **mIntfVoltage;
31
32 SPDLOG_LOGGER_INFO(mSLog,
33 "\n--- Initialization from powerflow ---"
34 "\nVoltage across phasor: \n{:s}"
35 "\nCurrent phasor: \n{:s}"
36 "\nTerminal 0 voltage phasor: \n{:s}"
37 "\nTerminal 1 voltage phasor: \n{:s}"
38 "\n--- Initialization from powerflow finished ---",
43}
44
46 Attribute<Matrix>::Ptr leftVector) {
48 **mRightVector = Matrix::Zero(0, 0);
49}
50
52
54 SparseMatrixRow &systemMatrix) {
55 MatrixFixedSizeComp<3, 3> conductance = Matrix::Zero(3, 3);
56 conductance.real() = (**mIsClosed) ? (**mClosedResistance).inverse()
57 : (**mOpenResistance).inverse();
58
60 conductance, systemMatrix, matrixNodeIndex(0), matrixNodeIndex(1),
62}
63
65 Bool closed, SparseMatrixRow &systemMatrix, Int freqIdx) {
66 MatrixFixedSizeComp<3, 3> conductance = Matrix::Zero(3, 3);
67 conductance.real() = (closed) ? (**mClosedResistance).inverse()
68 : (**mOpenResistance).inverse();
69
71 conductance, systemMatrix, matrixNodeIndex(0), matrixNodeIndex(1),
73}
74
76 AttributeBase::List &prevStepDependencies,
77 AttributeBase::List &attributeDependencies,
78 AttributeBase::List &modifiedAttributes,
79 Attribute<Matrix>::Ptr &leftVector) {
80 attributeDependencies.push_back(leftVector);
81 modifiedAttributes.push_back(mIntfVoltage);
82 modifiedAttributes.push_back(mIntfCurrent);
83}
84
85void DP::Ph3::Switch::mnaCompPostStep(Real time, Int timeStepCount,
86 Attribute<Matrix>::Ptr &leftVector) {
87 mnaCompUpdateVoltage(**leftVector);
88 mnaCompUpdateCurrent(**leftVector);
89}
90
92 // Voltage across component is defined as V1 - V0.
93 **mIntfVoltage = MatrixComp::Zero(3, 1);
94 if (terminalNotGrounded(1)) {
95 (**mIntfVoltage)(0, 0) =
97 (**mIntfVoltage)(1, 0) =
99 (**mIntfVoltage)(2, 0) =
101 }
102 if (terminalNotGrounded(0)) {
103 (**mIntfVoltage)(0, 0) =
104 (**mIntfVoltage)(0, 0) -
106 (**mIntfVoltage)(1, 0) =
107 (**mIntfVoltage)(1, 0) -
109 (**mIntfVoltage)(2, 0) =
110 (**mIntfVoltage)(2, 0) -
112 }
113}
114
116 MatrixFixedSizeComp<3, 3> conductance = Matrix::Zero(3, 3);
117 conductance.real() = (**mIsClosed) ? (**mClosedResistance).inverse()
118 : (**mOpenResistance).inverse();
119
120 **mIntfCurrent = conductance * **mIntfVoltage;
121}
122
124 // Recompute the system matrix only when the switch state changed.
125 if (!(mIsClosedPrev == this->mnaIsClosed())) {
126 mIsClosedPrev = this->mnaIsClosed();
127 return 1;
128 } else {
129 return 0;
130 }
131}
std::vector< Ptr > List
Definition Attribute.h:123
AttributePointer< Attribute< T > > Ptr
Definition Attribute.h:250
const CPS::Attribute< Matrix >::Ptr mClosedResistance
Resistance if switch is closed [ohm].
const CPS::Attribute< Matrix >::Ptr mOpenResistance
Resistance if switch is open [ohm].
const CPS::Attribute< Bool >::Ptr mIsClosed
Defines if Switch is open or closed.
Bool hasParameterChanged() override
Returns true if one of the element paramters has changed.
void mnaCompUpdateCurrent(const Matrix &leftVector) override
Update interface current from MNA system result.
void mnaCompUpdateVoltage(const Matrix &leftVector) override
Update interface voltage from MNA system result.
Switch(String uid, String name, Logger::Level loglevel=Logger::Level::off)
Defines UID, name, component parameters and logging level.
Bool mnaIsClosed() override
Check if switch is closed.
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
void initializeFromNodesAndTerminals(Real frequency) override
Initializes component from power flow data.
void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override
Stamps system matrix.
void mnaCompApplySwitchSystemMatrixStamp(Bool closed, SparseMatrixRow &systemMatrix, Int freqIdx) override
Stamps system matrix considering the defined switch position.
void mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector) override
Add MNA post step dependencies.
void mnaCompInitialize(Real omega, Real timeStep, Attribute< Matrix >::Ptr leftVector) override
String uid()
Returns unique id.
AttributeList::Ptr mAttributes
Attribute List.
spdlog::level::level_enum Level
Definition Logger.h:33
static String phasorMatrixToString(const MatrixComp &mat)
Definition Logger.cpp:51
MNASimPowerComp(String uid, String name, Bool hasPreStep, Bool hasPostStep, Logger::Level logLevel)
Attribute< Matrix >::Ptr mRightVector
static void stampAdmittanceMatrix(const MatrixComp &admittanceMat, SparseMatrixRow &mat, UInt node1Index, UInt node2Index, Bool isTerminal1NotGrounded, Bool isTerminal2NotGrounded, const Logger::Log &mSLog, Int maxFreq=1, Int freqIdx=0)
static Complex complexFromVectorElement(const Matrix &mat, Matrix::Index row, Int maxFreq=1, Int freqIdx=0)
Definition MathUtils.cpp:94
UInt matrixNodeIndex(UInt nodeIndex)
const Attribute< MatrixVar< Complex > >::Ptr mIntfCurrent
SimTerminal< Complex >::List mTerminals
const Attribute< MatrixVar< Complex > >::Ptr mIntfVoltage
MatrixComp initialVoltage(UInt index)
std::shared_ptr< SimPowerComp< VarType > > Ptr
Bool terminalNotGrounded(UInt index)
Logger::Level mLogLevel
Component logger control for internal variables.
Logger::Log mSLog
Component logger.
static std::shared_ptr< Switch > make(Args &&...args)
Definition PtrFactory.h:19
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::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