9 #include <dpsim-models/EMT/EMT_Ph3_SeriesSwitch.h>
17 Logger::Level logLevel)
19 Base::Ph1::
Switch(mAttributes) {
20 mPhaseType = PhaseType::ABC;
25 auto copy = SeriesSwitch::make(name, mLogLevel);
26 copy->setParameters(**mOpenResistance, **mClosedResistance);
32 Real impedance = (**mIsClosed) ? **mClosedResistance : **mOpenResistance;
34 Complex phasorA = initialSingleVoltage(1) - initialSingleVoltage(0);
35 (**mIntfVoltage)(0, 0) = phasorA.real();
36 Complex alpha(cos(2. / 3. * PI), sin(2. / 3. * PI));
37 (**mIntfVoltage)(1, 0) = Complex(phasorA * pow(alpha, 2)).real();
38 (**mIntfVoltage)(2, 0) = Complex(phasorA * alpha).real();
40 **mIntfCurrent = **mIntfVoltage / impedance;
42 SPDLOG_LOGGER_INFO(mSLog,
43 "\n--- Initialization from powerflow ---"
44 "\nVoltage across amplitude and phase: \n{}"
45 "\nCurrent amplitude and phase: \n{}"
46 "\nTerminal 0 voltage amplitude and phase: \n{}"
47 "\nTerminal 1 voltage amplitude and phase: \n{}"
48 "\n--- Initialization from powerflow finished ---",
49 Logger::phasorMatrixToString(**mIntfVoltage),
50 Logger::phasorMatrixToString(**mIntfCurrent),
51 Logger::phasorMatrixToString(initialVoltage(0)),
52 Logger::phasorMatrixToString(initialVoltage(1)));
57 updateMatrixNodeIndices();
58 **mRightVector = Matrix::Zero(0, 0);
64 SparseMatrixRow &systemMatrix) {
66 (**mIsClosed) ? 1. / **mClosedResistance : 1. / **mOpenResistance;
69 conductance, systemMatrix, matrixNodeIndex(0), matrixNodeIndex(1),
70 terminalNotGrounded(0), terminalNotGrounded(1), mSLog);
74 Bool closed, SparseMatrixRow &systemMatrix, Int freqIdx) {
76 (closed) ? 1. / **mClosedResistance : 1. / **mOpenResistance;
79 conductance, systemMatrix, matrixNodeIndex(0), matrixNodeIndex(1),
80 terminalNotGrounded(0), terminalNotGrounded(1), mSLog);
84 AttributeBase::List &prevStepDependencies,
85 AttributeBase::List &attributeDependencies,
86 AttributeBase::List &modifiedAttributes,
88 attributeDependencies.push_back(leftVector);
89 modifiedAttributes.push_back(mIntfVoltage);
90 modifiedAttributes.push_back(mIntfCurrent);
93 void EMT::Ph3::SeriesSwitch::mnaCompPostStep(
95 mnaCompUpdateVoltage(**leftVector);
96 mnaCompUpdateCurrent(**leftVector);
101 **mIntfVoltage = Matrix::Zero(3, 1);
102 if (terminalNotGrounded(1)) {
103 (**mIntfVoltage)(0, 0) =
104 Math::realFromVectorElement(leftVector, matrixNodeIndex(1, 0));
105 (**mIntfVoltage)(1, 0) =
106 Math::realFromVectorElement(leftVector, matrixNodeIndex(1, 1));
107 (**mIntfVoltage)(2, 0) =
108 Math::realFromVectorElement(leftVector, matrixNodeIndex(1, 2));
110 if (terminalNotGrounded(0)) {
111 (**mIntfVoltage)(0, 0) =
112 (**mIntfVoltage)(0, 0) -
113 Math::realFromVectorElement(leftVector, matrixNodeIndex(0, 0));
114 (**mIntfVoltage)(1, 0) =
115 (**mIntfVoltage)(1, 0) -
116 Math::realFromVectorElement(leftVector, matrixNodeIndex(0, 1));
117 (**mIntfVoltage)(2, 0) =
118 (**mIntfVoltage)(2, 0) -
119 Math::realFromVectorElement(leftVector, matrixNodeIndex(0, 2));
122 SPDLOG_LOGGER_DEBUG(mSLog,
"Voltage A: {}", (**mIntfVoltage)(0, 0));
126 Real impedance = (**mIsClosed) ? **mClosedResistance : **mOpenResistance;
127 **mIntfCurrent = **mIntfVoltage / impedance;
129 SPDLOG_LOGGER_DEBUG(mSLog,
"Current A: {}", (**mIntfCurrent)(0, 0));
Bool mnaIsClosed() override
Check if switch is closed.
void mnaCompUpdateCurrent(const Matrix &leftVector) override
Update interface voltage from MNA system results.
void mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector) override
Add MNA post step dependencies.
SeriesSwitch(String uid, String name, Logger::Level loglevel=Logger::Level::off)
Defines UID, name and log level.
void initializeFromNodesAndTerminals(Real frequency) override
Initializes states from power flow data.
void mnaCompUpdateVoltage(const Matrix &leftVector) override
Update interface voltage from MNA system results.
void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override
Stamps system matrix.
SimPowerComp< Real >::Ptr clone(String name) override
Return new instance with the same parameters.
void mnaCompInitialize(Real omega, Real timeStep, Attribute< Matrix >::Ptr leftVector) override
Initializes MNA specific variables.
void mnaCompApplySwitchSystemMatrixStamp(Bool closed, SparseMatrixRow &systemMatrix, Int freqIdx) override
Stamps system matrix considering the defined switch position.
Base class for all MNA components that are transmitting power.
static void stampConductanceAs3x3ScalarMatrix(Real conductance, SparseMatrixRow &mat, UInt node1Index, UInt node2Index, Bool isTerminal1NotGrounded, Bool isTerminal2NotGrounded, const Logger::Log &mSLog)
Stamps conductance as a 3x3 scalar matrix (a diagonal matrix, where all diagonal elements are equal t...
Base class for all components that are transmitting power.