DPsim
Loading...
Searching...
No Matches
DP_Ph3_SeriesSwitch.cpp
Go to the documentation of this file.
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
10
11using namespace CPS;
12
14 Logger::Level logLevel)
15 : MNASimPowerComp<Complex>(uid, name, false, true, logLevel),
18 **mIntfVoltage = MatrixComp::Zero(3, 1);
19 **mIntfCurrent = MatrixComp::Zero(3, 1);
20}
21
23
24 mTerminals[0]->setPhaseType(PhaseType::ABC);
25 mTerminals[1]->setPhaseType(PhaseType::ABC);
26
27 Real impedance = (**mIsClosed) ? **mClosedResistance : **mOpenResistance;
28 MatrixComp vInitABC = MatrixComp::Zero(3, 1);
29 vInitABC(0, 0) =
31 vInitABC(1, 0) = vInitABC(0, 0) * SHIFT_TO_PHASE_B;
32 vInitABC(2, 0) = vInitABC(0, 0) * SHIFT_TO_PHASE_C;
33
34 **mIntfVoltage = vInitABC;
35 **mIntfCurrent = vInitABC / impedance;
36
37 SPDLOG_LOGGER_INFO(mSLog,
38 "\n--- Initialization from powerflow ---"
39 "\nVoltage across phasor: \n{}"
40 "\nCurrent phasor: \n{}"
41 "\nTerminal 0 voltage phasor: \n{}"
42 "\nTerminal 1 voltage phasor: \n{}",
47}
48
50
52 Real omega, Real timeStep, Attribute<Matrix>::Ptr leftVector) {
54 **mRightVector = Matrix::Zero(0, 0);
55}
56
58 SparseMatrixRow &systemMatrix) {
59 Complex conductance = (**mIsClosed) ? Complex(1. / **mClosedResistance, 0)
60 : Complex(1. / **mOpenResistance, 0);
61
63 conductance, systemMatrix, matrixNodeIndex(0), matrixNodeIndex(1),
65}
66
68 Bool closed, SparseMatrixRow &systemMatrix, Int freqIdx) {
69 Complex conductance = (closed) ? Complex(1. / **mClosedResistance, 0)
70 : Complex(1. / **mOpenResistance, 0);
71
73 conductance, systemMatrix, matrixNodeIndex(0), matrixNodeIndex(1),
75}
76
78 AttributeBase::List &prevStepDependencies,
79 AttributeBase::List &attributeDependencies,
80 AttributeBase::List &modifiedAttributes,
81 Attribute<Matrix>::Ptr &leftVector) {
82 attributeDependencies.push_back(leftVector);
83 modifiedAttributes.push_back(mIntfVoltage);
84 modifiedAttributes.push_back(mIntfCurrent);
85}
86
88 Real time, Int timeStepCount, Attribute<Matrix>::Ptr &leftVector) {
89 mnaCompUpdateVoltage(**leftVector);
90 mnaCompUpdateCurrent(**leftVector);
91}
92
94 // Voltage across component is defined as V1 - V0
95 (**mIntfVoltage).setZero();
96 if (terminalNotGrounded(1)) {
97 (**mIntfVoltage)(0, 0) =
99 (**mIntfVoltage)(1, 0) =
101 (**mIntfVoltage)(2, 0) =
103 }
104 if (terminalNotGrounded(0)) {
105 (**mIntfVoltage)(0, 0) =
106 (**mIntfVoltage)(0, 0) -
108 (**mIntfVoltage)(1, 0) =
109 (**mIntfVoltage)(1, 0) -
111 (**mIntfVoltage)(2, 0) =
112 (**mIntfVoltage)(2, 0) -
114 }
115
116 SPDLOG_LOGGER_DEBUG(mSLog, "Voltage A: {} < {}",
117 std::abs((**mIntfVoltage)(0, 0)),
118 std::arg((**mIntfVoltage)(0, 0)));
119}
120
122 Real impedance = (**mIsClosed) ? **mClosedResistance : **mOpenResistance;
123 const Real conductance = 1. / impedance;
124 **mIntfCurrent = **mIntfVoltage * conductance;
125
126 SPDLOG_LOGGER_DEBUG(mSLog, "Current A: {} < {}",
127 std::abs((**mIntfCurrent)(0, 0)),
128 std::arg((**mIntfCurrent)(0, 0)));
129}
130
132 // Check if state of switch changed
133 if (!(mIsClosedPrev == this->mnaIsClosed())) {
134 mIsClosedPrev = this->mnaIsClosed();
135 return 1; //recompute system matrix
136 } else {
137 return 0; // do not recompute system matrix
138 }
139};
std::vector< Ptr > List
Definition Attribute.h:123
AttributePointer< Attribute< T > > Ptr
Definition Attribute.h:249
const Attribute< Real >::Ptr mClosedResistance
Resistance if switch is closed [ohm].
Switch(CPS::AttributeList::Ptr attributeList)
const Attribute< Real >::Ptr mOpenResistance
Resistance if switch is open [ohm].
const Attribute< Bool >::Ptr mIsClosed
Defines if Switch is open or closed.
void initializeFromNodesAndTerminals(Real frequency) override
Initializes component from power flow data.
void mnaCompInitialize(Real omega, Real timeStep, Attribute< Matrix >::Ptr leftVector) override
void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override
Stamps system matrix.
Bool mnaIsClosed() override
Check if switch is closed.
void mnaCompUpdateVoltage(const Matrix &leftVector) override
Update interface voltage from MNA system result.
void mnaCompUpdateCurrent(const Matrix &leftVector) override
Update interface current from MNA system result.
void mnaCompPostStep(Real time, Int timeStepCount, Attribute< Matrix >::Ptr &leftVector) override
void mnaCompApplySwitchSystemMatrixStamp(Bool closed, SparseMatrixRow &systemMatrix, Int freqIdx) override
Stamps system matrix considering the defined switch position.
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 logging level.
Bool hasParameterChanged() override
Returns true if one of the element paramters has changed.
String uid()
Returns unique id.
AttributeList::Ptr mAttributes
Attribute List.
spdlog::level::level_enum Level
Definition Logger.h:33
static String phasorToString(const Complex &num)
Definition Logger.cpp:57
MNASimPowerComp(String uid, String name, Bool hasPreStep, Bool hasPostStep, Logger::Level logLevel)
Attribute< Matrix >::Ptr mRightVector
static void stampAdmittanceAs3x3ScalarMatrix(Complex admittance, SparseMatrixRow &mat, UInt node1Index, UInt node2Index, Bool isTerminal1NotGrounded, Bool isTerminal2NotGrounded, const Logger::Log &mSLog, Int maxFreq=1, Int freqIdx=0)
Stamps admittance as a 3x3 scalar matrix (a diagonal matrix, where all diagonal elements are equal to...
static Complex complexFromVectorElement(const Matrix &mat, Matrix::Index row, Int maxFreq=1, Int freqIdx=0)
UInt matrixNodeIndex(UInt nodeIndex)
const Attribute< MatrixVar< Complex > >::Ptr mIntfCurrent
SimTerminal< Complex >::List mTerminals
const Attribute< MatrixVar< Complex > >::Ptr mIntfVoltage
MatrixComp initialVoltage(UInt index)
Bool terminalNotGrounded(UInt index)
Complex initialSingleVoltage(UInt index)
Logger::Log mSLog
Component logger.
#define RMS3PH_TO_PEAK1PH
Definition Definitions.h:50
#define SHIFT_TO_PHASE_C
Definition Definitions.h:47
#define SHIFT_TO_PHASE_B
Definition Definitions.h:46
Eigen::Matrix< Real, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor > Matrix
Dense matrix for real numbers.
Definition Definitions.h:79
std::string String
Definition Definitions.h:63
double Real
Definition Definitions.h:60
int Int
Definition Definitions.h:59
std::complex< Real > Complex
Definition Definitions.h:61
Eigen::Matrix< Complex, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor > MatrixComp
Dense matrix for complex numbers.
Definition Definitions.h:82
bool Bool
Definition Definitions.h:62
Eigen::SparseMatrix< Real, Eigen::RowMajor > SparseMatrixRow
Sparse matrix for real numbers (row major).
Definition Definitions.h:72