DPsim
Loading...
Searching...
No Matches
EMT_Ph3_SeriesSwitch.cpp
1/* Copyright 2017-2021 Institute for Automation of Complex Power Systems,
2 * EONERC, RWTH Aachen University
3 *
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
7 *********************************************************************************/
8
9#include <dpsim-models/EMT/EMT_Ph3_SeriesSwitch.h>
10
11using namespace CPS;
12
13// !!! TODO: Adaptions to use in EMT_Ph3 models phase-to-ground peak variables
14// !!! with initialization from phase-to-phase RMS variables
15
17 Logger::Level logLevel)
18 : MNASimPowerComp<Real>(uid, name, false, true, logLevel),
19 Base::Ph1::Switch(mAttributes) {
20 mPhaseType = PhaseType::ABC;
21 setTerminalNumber(2);
22}
23
24SimPowerComp<Real>::Ptr EMT::Ph3::SeriesSwitch::clone(String name) {
25 auto copy = SeriesSwitch::make(name, mLogLevel);
26 copy->setParameters(**mOpenResistance, **mClosedResistance);
27 return copy;
28}
29
31
32 Real impedance = (**mIsClosed) ? **mClosedResistance : **mOpenResistance;
33
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();
39
40 **mIntfCurrent = **mIntfVoltage / impedance;
41
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)));
53}
54
56 Real omega, Real timeStep, Attribute<Matrix>::Ptr leftVector) {
58 **mRightVector = Matrix::Zero(0, 0);
59}
60
62
64 SparseMatrixRow &systemMatrix) {
65 Real conductance =
66 (**mIsClosed) ? 1. / **mClosedResistance : 1. / **mOpenResistance;
67
69 conductance, systemMatrix, matrixNodeIndex(0), matrixNodeIndex(1),
70 terminalNotGrounded(0), terminalNotGrounded(1), mSLog);
71}
72
74 Bool closed, SparseMatrixRow &systemMatrix, Int freqIdx) {
75 Real conductance =
76 (closed) ? 1. / **mClosedResistance : 1. / **mOpenResistance;
77
79 conductance, systemMatrix, matrixNodeIndex(0), matrixNodeIndex(1),
80 terminalNotGrounded(0), terminalNotGrounded(1), mSLog);
81}
82
84 AttributeBase::List &prevStepDependencies,
85 AttributeBase::List &attributeDependencies,
86 AttributeBase::List &modifiedAttributes,
87 Attribute<Matrix>::Ptr &leftVector) {
88 attributeDependencies.push_back(leftVector);
89 modifiedAttributes.push_back(mIntfVoltage);
90 modifiedAttributes.push_back(mIntfCurrent);
91}
92
93void EMT::Ph3::SeriesSwitch::mnaCompPostStep(
94 Real time, Int timeStepCount, Attribute<Matrix>::Ptr &leftVector) {
95 mnaCompUpdateVoltage(**leftVector);
96 mnaCompUpdateCurrent(**leftVector);
97}
98
99void EMT::Ph3::SeriesSwitch::mnaCompUpdateVoltage(const Matrix &leftVector) {
100 // Voltage across component is defined as V1 - V0
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));
109 }
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));
120 }
121
122 SPDLOG_LOGGER_DEBUG(mSLog, "Voltage A: {}", (**mIntfVoltage)(0, 0));
123}
124
125void EMT::Ph3::SeriesSwitch::mnaCompUpdateCurrent(const Matrix &leftVector) {
126 Real impedance = (**mIsClosed) ? **mClosedResistance : **mOpenResistance;
127 **mIntfCurrent = **mIntfVoltage / impedance;
128
129 SPDLOG_LOGGER_DEBUG(mSLog, "Current A: {}", (**mIntfCurrent)(0, 0));
130}
const Attribute< Real >::Ptr mClosedResistance
Resistance if switch is closed [ohm].
const Attribute< Real >::Ptr mOpenResistance
Resistance if switch is open [ohm].
const Attribute< Bool >::Ptr mIsClosed
Defines if Switch is open or closed.
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.
String uid()
Returns unique id.
AttributeList::Ptr mAttributes
Attribute List.
MNASimPowerComp(String uid, String name, Bool hasPreStep, Bool hasPostStep, Logger::Level logLevel)
Attribute< Matrix >::Ptr mRightVector
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...
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.