9#include <dpsim-models/EMT/EMT_Ph3_Switch.h>
25 auto copy = Switch::make(name,
mLogLevel);
33 MatrixComp vInitABC = MatrixComp::Zero(3, 1);
34 vInitABC(0, 0) = initialSingleVoltage(1) - initialSingleVoltage(0);
35 vInitABC(1, 0) = vInitABC(0, 0) * SHIFT_TO_PHASE_B;
36 vInitABC(2, 0) = vInitABC(0, 0) * SHIFT_TO_PHASE_C;
38 **
mIntfCurrent = (impedance.inverse() * vInitABC).real();
40 SPDLOG_LOGGER_INFO(
mSLog,
41 "\n--- Initialization from powerflow ---"
42 "\nVoltage across: {:s}"
44 "\nTerminal 0 voltage: {:s}"
45 "\nTerminal 1 voltage: {:s}"
46 "\n--- Initialization from powerflow finished ---",
49 Logger::phasorToString(initialSingleVoltage(0)),
50 Logger::phasorToString(initialSingleVoltage(1)));
53void EMT::Ph3::Switch::mnaCompInitialize(Real omega, Real timeStep,
54 Attribute<Matrix>::Ptr leftVector) {
55 updateMatrixNodeIndices();
56 **mRightVector = Matrix::Zero(0, 0);
62 SparseMatrixRow &systemMatrix) {
63 MatrixFixedSize<3, 3> conductance = (**mIsClosed)
64 ? (**mClosedResistance).inverse()
65 : (**mOpenResistance).inverse();
67 MNAStampUtils::stampConductanceMatrix(
68 conductance, systemMatrix, matrixNodeIndex(0), matrixNodeIndex(1),
69 terminalNotGrounded(0), terminalNotGrounded(1),
mSLog);
71 SPDLOG_LOGGER_TRACE(
mSLog,
"\nConductance matrix: {:s}",
72 Logger::matrixToString(conductance));
76 Bool closed, SparseMatrixRow &systemMatrix, Int freqIdx) {
77 MatrixFixedSize<3, 3> conductance = (closed) ? (**mClosedResistance).inverse()
78 : (**mOpenResistance).inverse();
80 MNAStampUtils::stampConductanceMatrix(
81 conductance, systemMatrix, matrixNodeIndex(0), matrixNodeIndex(1),
82 terminalNotGrounded(0), terminalNotGrounded(1),
mSLog);
84 SPDLOG_LOGGER_TRACE(
mSLog,
"\nConductance matrix: {:s}",
85 Logger::matrixToString(conductance));
91 AttributeBase::List &prevStepDependencies,
92 AttributeBase::List &attributeDependencies,
93 AttributeBase::List &modifiedAttributes,
94 Attribute<Matrix>::Ptr &leftVector) {
95 attributeDependencies.push_back(leftVector);
100void EMT::Ph3::Switch::mnaCompPostStep(Real time, Int timeStepCount,
101 Attribute<Matrix>::Ptr &leftVector) {
102 mnaCompUpdateVoltage(**leftVector);
103 mnaCompUpdateCurrent(**leftVector);
109 if (terminalNotGrounded(1)) {
110 (**mIntfVoltage)(0, 0) =
111 Math::realFromVectorElement(leftVector, matrixNodeIndex(1, 0));
112 (**mIntfVoltage)(1, 0) =
113 Math::realFromVectorElement(leftVector, matrixNodeIndex(1, 1));
114 (**mIntfVoltage)(2, 0) =
115 Math::realFromVectorElement(leftVector, matrixNodeIndex(1, 2));
117 if (terminalNotGrounded(0)) {
118 (**mIntfVoltage)(0, 0) =
120 Math::realFromVectorElement(leftVector, matrixNodeIndex(0, 0));
121 (**mIntfVoltage)(1, 0) =
123 Math::realFromVectorElement(leftVector, matrixNodeIndex(0, 1));
124 (**mIntfVoltage)(2, 0) =
126 Math::realFromVectorElement(leftVector, matrixNodeIndex(0, 2));
131 Matrix conductance = Matrix::Zero(3, 3);
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.
void mnaCompUpdateCurrent(const Matrix &leftVector) override
Update interface current from MNA system result.
SimPowerComp< Real >::Ptr clone(String name) override
Returns a modified copy of the component with the given suffix added to the name and without.
void mnaCompApplySwitchSystemMatrixStamp(Bool closed, SparseMatrixRow &systemMatrix, Int freqIdx) override
Stamps system matrix considering the defined switch position.
Switch(String uid, String name, Logger::Level loglevel=Logger::Level::off)
Defines UID, name, component parameters and logging level.
void mnaCompUpdateVoltage(const Matrix &leftVector) override
Update interface voltage from MNA system result.
void initializeFromNodesAndTerminals(Real frequency) override
Initializes component from power flow data.
void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override
Stamps system matrix.
void mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector) override
Add MNA post step dependencies.
void mnaCompApplyRightSideVectorStamp(Matrix &rightVector) override
Stamps right side (source) vector.
Bool mnaIsClosed() override
Check if switch is closed.
String uid()
Returns unique id.
AttributeList::Ptr mAttributes
Attribute List.
MNASimPowerComp(String uid, String name, Bool hasPreStep, Bool hasPostStep, Logger::Level logLevel)
const Attribute< MatrixVar< Real > >::Ptr mIntfCurrent
const Attribute< MatrixVar< Real > >::Ptr mIntfVoltage
Logger::Level mLogLevel
Component logger control for internal variables.
Logger::Log mSLog
Component logger.