9 #include <dpsim-models/EMT/EMT_Ph1_Switch.h>
15 Base::Ph1::
Switch(mAttributes) {
22 auto copy = Switch::make(name, mLogLevel);
23 copy->setParameters(**mOpenResistance, **mClosedResistance, **mIsClosed);
29 Real resistance = (**mIsClosed) ? **mClosedResistance : **mOpenResistance;
31 (**mIntfVoltage)(0, 0) =
32 RMS3PH_TO_PEAK1PH * (initialSingleVoltage(1) - initialSingleVoltage(0)).real();
33 (**mIntfCurrent)(0, 0) = (**mIntfVoltage)(0, 0) / resistance;
35 SPDLOG_LOGGER_INFO(mSLog,
36 "\n--- Initialization from powerflow ---"
37 "\nVoltage across: {:s}"
39 "\nTerminal 0 voltage: {:s}"
40 "\nTerminal 1 voltage: {:s}"
41 "\n--- Initialization from powerflow finished ---",
42 Logger::matrixToString(**mIntfVoltage),
43 Logger::matrixToString(**mIntfCurrent),
44 Logger::phasorToString(RMS3PH_TO_PEAK1PH * initialSingleVoltage(0).real()),
45 Logger::phasorToString(RMS3PH_TO_PEAK1PH * initialSingleVoltage(1).real()));
48 void EMT::Ph1::Switch::mnaCompInitialize(Real omega, Real timeStep,
50 updateMatrixNodeIndices();
51 mMnaTasks.push_back(std::make_shared<MnaPostStep>(*
this, leftVector));
57 SparseMatrixRow &systemMatrix) {
61 (**mIsClosed) ? 1. / (**mClosedResistance) : 1. / (**mOpenResistance);
63 MNAStampUtils::stampConductance(conductance, systemMatrix, matrixNodeIndex(0),
64 matrixNodeIndex(1), terminalNotGrounded(0),
65 terminalNotGrounded(1), mSLog);
69 Bool closed, SparseMatrixRow &systemMatrix, Int freqIdx) {
73 (closed) ? 1. / (**mClosedResistance) : 1. / (**mOpenResistance);
75 MNAStampUtils::stampConductance(conductance, systemMatrix, matrixNodeIndex(0),
76 matrixNodeIndex(1), terminalNotGrounded(0),
77 terminalNotGrounded(1), mSLog);
83 AttributeBase::List &prevStepDependencies,
84 AttributeBase::List &attributeDependencies,
85 AttributeBase::List &modifiedAttributes,
87 attributeDependencies.push_back(leftVector);
88 modifiedAttributes.push_back(mIntfVoltage);
89 modifiedAttributes.push_back(mIntfCurrent);
94 mnaCompUpdateVoltage(**leftVector);
95 mnaCompUpdateCurrent(**leftVector);
100 **mIntfVoltage = Matrix::Zero(1, 1);
101 if (terminalNotGrounded(1)) {
102 (**mIntfVoltage)(0, 0) =
103 Math::realFromVectorElement(leftVector, matrixNodeIndex(1, 0));
105 if (terminalNotGrounded(0)) {
106 (**mIntfVoltage)(0, 0) =
107 (**mIntfVoltage)(0, 0) -
108 Math::realFromVectorElement(leftVector, matrixNodeIndex(0, 0));
113 (**mIntfCurrent)(0, 0) = (**mIsClosed)
114 ? (**mIntfVoltage)(0, 0) / (**mClosedResistance)
115 : (**mIntfVoltage)(0, 0) / (**mOpenResistance);
void mnaCompUpdateCurrent(const Matrix &leftVector) override
Update interface current from MNA system result.
void mnaCompApplyRightSideVectorStamp(Matrix &rightVector) override
Stamps right side (source) vector.
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.
Bool mnaIsClosed() override
Check if switch is closed.
void mnaCompUpdateVoltage(const Matrix &leftVector) override
Update interface voltage from MNA system result.
void mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector) override
Add MNA post step dependencies.
SimPowerComp< Real >::Ptr clone(String name) override
Returns a modified copy of the component with the given suffix added to the name and without.
Switch(String uid, String name, Logger::Level loglevel=Logger::Level::off)
Defines UID, name, component parameters and logging level.
void mnaCompPostStep(Real time, Int timeStepCount, Attribute< Matrix >::Ptr &leftVector) override
MNA post step operations.
void initializeFromNodesAndTerminals(Real frequency) override
Initializes component from power flow data.
Base class for all MNA components that are transmitting power.
Base class for all components that are transmitting power.
const Attribute< MatrixVar< Real > >::Ptr mIntfCurrent
Current through component.
const Attribute< MatrixVar< Real > >::Ptr mIntfVoltage
Voltage between terminals.