9 #include <dpsim-models/DP/DP_Ph1_varResSwitch.h>
14 Logger::Level logLevel)
16 Base::Ph1::
Switch(mAttributes) {
23 auto copy = varResSwitch::make(name, mLogLevel);
24 copy->setParameters(**mOpenResistance, **mClosedResistance, **mIsClosed);
33 Real impedance = (**mIsClosed) ? **mClosedResistance : **mOpenResistance;
35 (**mIntfVoltage)(0, 0) = initialSingleVoltage(1) - initialSingleVoltage(0);
36 (**mIntfCurrent)(0, 0) = (**mIntfVoltage)(0, 0) / impedance;
42 updateMatrixNodeIndices();
46 SparseMatrixRow &systemMatrix) {
47 Complex conductance = (**mIsClosed) ? Complex(1. / **mClosedResistance, 0)
48 : Complex(1. / **mOpenResistance, 0);
50 MNAStampUtils::stampAdmittance(conductance, systemMatrix, matrixNodeIndex(0),
51 matrixNodeIndex(1), terminalNotGrounded(0),
52 terminalNotGrounded(1), mSLog);
56 Bool closed, SparseMatrixRow &systemMatrix, Int freqIdx) {
57 Complex conductance = (closed) ? Complex(1. / **mClosedResistance, 0)
58 : Complex(1. / **mOpenResistance, 0);
60 MNAStampUtils::stampAdmittance(conductance, systemMatrix, matrixNodeIndex(0),
61 matrixNodeIndex(1), terminalNotGrounded(0),
62 terminalNotGrounded(1), mSLog);
66 Matrix &rightVector) {}
71 AttributeBase::List &prevStepDependencies,
72 AttributeBase::List &attributeDependencies,
73 AttributeBase::List &modifiedAttributes,
76 attributeDependencies.push_back(leftVector);
77 modifiedAttributes.push_back(mIntfVoltage);
78 modifiedAttributes.push_back(mIntfCurrent);
83 mnaCompUpdateVoltage(**leftVector);
84 mnaCompUpdateCurrent(**leftVector);
89 (**mIntfVoltage)(0, 0) = 0;
90 if (terminalNotGrounded(1))
91 (**mIntfVoltage)(0, 0) =
92 Math::complexFromVectorElement(leftVector, matrixNodeIndex(1));
93 if (terminalNotGrounded(0))
94 (**mIntfVoltage)(0, 0) =
95 (**mIntfVoltage)(0, 0) -
96 Math::complexFromVectorElement(leftVector, matrixNodeIndex(0));
100 (**mIntfCurrent)(0, 0) = (**mIsClosed)
101 ? (**mIntfVoltage)(0, 0) / **mClosedResistance
102 : (**mIntfVoltage)(0, 0) / **mOpenResistance;
107 Bool presentState = this->mnaIsClosed();
110 if (!(mPrevState == presentState)) {
112 if (this->mnaIsClosed() ==
true) {
114 **mClosedResistance = mDeltaResClosed * mPrevRes;
115 mPrevRes = **mClosedResistance;
117 if (**mClosedResistance < mInitClosedRes) {
118 **mClosedResistance = mInitClosedRes;
119 mPrevRes = **mClosedResistance;
120 mPrevState = this->mnaIsClosed();
124 else if (this->mnaIsClosed() ==
false) {
125 **mOpenResistance = mDeltaResOpen * mPrevRes;
126 mPrevRes = **mOpenResistance;
128 if (**mOpenResistance > mInitOpenRes) {
129 **mOpenResistance = mInitOpenRes;
130 mPrevRes = **mOpenResistance;
131 mPrevState = this->mnaIsClosed();
140 void DP::Ph1::varResSwitch::setInitParameters(Real timestep) {
144 mDeltaResOpen = 0.5 * timestep / 0.001 + 1;
145 mPrevState = **mIsClosed;
146 mPrevRes = (**mIsClosed) ? **mClosedResistance : **mOpenResistance;
147 mInitClosedRes = **mClosedResistance;
148 mInitOpenRes = **mOpenResistance;
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 mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector)
void initializeFromNodesAndTerminals(Real frequency)
Initializes states from power flow data.
void mnaCompApplySwitchSystemMatrixStamp(Bool closed, SparseMatrixRow &systemMatrix, Int freqIdx)
Stamps system matrix considering the defined switch position.
void mnaCompUpdateCurrent(const Matrix &leftVector)
Update interface current from MNA system results.
void mnaCompUpdateVoltage(const Matrix &leftVector)
Update interface voltage from MNA system results.
void mnaCompApplyRightSideVectorStamp(Matrix &rightVector)
Stamps right side (source) vector.
void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix)
Stamps system matrix.
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.
Bool mnaIsClosed()
Check if switch is closed.
void mnaCompPostStep(Real time, Int timeStepCount, Attribute< Matrix >::Ptr &leftVector)
MNA pre step operations.
Base class for all MNA components that are transmitting power.
Base class for all components that are transmitting power.
const Attribute< MatrixVar< Complex > >::Ptr mIntfCurrent
Current through component.
const Attribute< MatrixVar< Complex > >::Ptr mIntfVoltage
Voltage between terminals.