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;
29 **mIntfCurrent = **mIntfVoltage / impedance;
30
31 SPDLOG_LOGGER_INFO(mSLog,
32 "\n--- Initialization from powerflow ---"
33 "\nVoltage across phasor: \n{}"
34 "\nCurrent phasor: \n{}"
35 "\nTerminal 0 voltage phasor: \n{}"
36 "\nTerminal 1 voltage phasor: \n{}",
41}
42
44
46 Real omega, Real timeStep, Attribute<Matrix>::Ptr leftVector) {
48 **mRightVector = Matrix::Zero(0, 0);
49}
50
52 SparseMatrixRow &systemMatrix) {
53 Complex conductance = (**mIsClosed) ? Complex(1. / **mClosedResistance, 0)
54 : Complex(1. / **mOpenResistance, 0);
55
57 conductance, systemMatrix, matrixNodeIndex(0), matrixNodeIndex(1),
59}
60
62 Bool closed, SparseMatrixRow &systemMatrix, Int freqIdx) {
63 Complex conductance = (closed) ? Complex(1. / **mClosedResistance, 0)
64 : Complex(1. / **mOpenResistance, 0);
65
67 conductance, systemMatrix, matrixNodeIndex(0), matrixNodeIndex(1),
69}
70
72 AttributeBase::List &prevStepDependencies,
73 AttributeBase::List &attributeDependencies,
74 AttributeBase::List &modifiedAttributes,
75 Attribute<Matrix>::Ptr &leftVector) {
76 attributeDependencies.push_back(leftVector);
77 modifiedAttributes.push_back(mIntfVoltage);
78 modifiedAttributes.push_back(mIntfCurrent);
79}
80
82 Real time, Int timeStepCount, Attribute<Matrix>::Ptr &leftVector) {
83 mnaCompUpdateVoltage(**leftVector);
84 mnaCompUpdateCurrent(**leftVector);
85}
86
88 // Voltage across component is defined as V1 - V0
89 **mIntfVoltage = MatrixComp::Zero(3, 1);
90 if (terminalNotGrounded(1)) {
91 (**mIntfVoltage)(0, 0) =
93 (**mIntfVoltage)(1, 0) =
95 (**mIntfVoltage)(2, 0) =
97 }
98 if (terminalNotGrounded(0)) {
99 (**mIntfVoltage)(0, 0) =
100 (**mIntfVoltage)(0, 0) -
102 (**mIntfVoltage)(1, 0) =
103 (**mIntfVoltage)(1, 0) -
105 (**mIntfVoltage)(2, 0) =
106 (**mIntfVoltage)(2, 0) -
108 }
109
110 SPDLOG_LOGGER_DEBUG(mSLog, "Voltage A: {} < {}",
111 std::abs((**mIntfVoltage)(0, 0)),
112 std::arg((**mIntfVoltage)(0, 0)));
113}
114
116 Real impedance = (**mIsClosed) ? **mClosedResistance : **mOpenResistance;
117 **mIntfCurrent = **mIntfVoltage / impedance;
118
119 SPDLOG_LOGGER_DEBUG(mSLog, "Current A: {} < {}",
120 std::abs((**mIntfCurrent)(0, 0)),
121 std::arg((**mIntfCurrent)(0, 0)));
122}
123
125 // Check if state of switch changed
126 if (!(mIsClosedPrev == this->mnaIsClosed())) {
127 mIsClosedPrev = this->mnaIsClosed();
128 return 1; //recompute system matrix
129 } else {
130 return 0; // do not recompute system matrix
131 }
132};
std::vector< Ptr > List
Definition Attribute.h:123
AttributePointer< Attribute< T > > Ptr
Definition Attribute.h:250
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)
Definition MathUtils.cpp:94
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)
Logger::Log mSLog
Component logger.
Eigen::Matrix< Real, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor > Matrix
Dense matrix for real numbers.
Definition Definitions.h:81
std::string String
Definition Definitions.h:65
double Real
Definition Definitions.h:62
int Int
Definition Definitions.h:61
std::complex< Real > Complex
Definition Definitions.h:63
bool Bool
Definition Definitions.h:64
Eigen::SparseMatrix< Real, Eigen::RowMajor > SparseMatrixRow
Sparse matrix for real numbers (row major).
Definition Definitions.h:74