DPsim
Loading...
Searching...
No Matches
EMT_Ph1_Switch.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 : MNASimPowerComp<Real>(uid, name, false, true, logLevel),
17 **mIntfVoltage = Matrix::Zero(1, 1);
18 **mIntfCurrent = Matrix::Zero(1, 1);
19}
20
22 auto copy = Switch::make(name, mLogLevel);
23 copy->setParameters(**mOpenResistance, **mClosedResistance, **mIsClosed);
24 return copy;
25}
26
28
29 Real resistance = (**mIsClosed) ? **mClosedResistance : **mOpenResistance;
30
31 (**mIntfVoltage)(0, 0) =
34 (**mIntfCurrent)(0, 0) = (**mIntfVoltage)(0, 0) / resistance;
35
36 SPDLOG_LOGGER_INFO(mSLog,
37 "\n--- Initialization from powerflow ---"
38 "\nVoltage across: {:s}"
39 "\nCurrent: {:s}"
40 "\nTerminal 0 voltage: {:s}"
41 "\nTerminal 1 voltage: {:s}"
42 "\n--- Initialization from powerflow finished ---",
46 initialSingleVoltage(0).real()),
48 initialSingleVoltage(1).real()));
49}
50
52 Attribute<Matrix>::Ptr leftVector) {
54 mMnaTasks.push_back(std::make_shared<MnaPostStep>(*this, leftVector));
55}
56
58
60 SparseMatrixRow &systemMatrix) {
61 Real conductance;
62
63 conductance =
64 (**mIsClosed) ? 1. / (**mClosedResistance) : 1. / (**mOpenResistance);
65
66 MNAStampUtils::stampConductance(conductance, systemMatrix, matrixNodeIndex(0),
69}
70
72 Bool closed, SparseMatrixRow &systemMatrix, Int freqIdx) {
73 Real conductance;
74
75 conductance =
76 (closed) ? 1. / (**mClosedResistance) : 1. / (**mOpenResistance);
77
78 MNAStampUtils::stampConductance(conductance, systemMatrix, matrixNodeIndex(0),
81}
82
84
86 AttributeBase::List &prevStepDependencies,
87 AttributeBase::List &attributeDependencies,
88 AttributeBase::List &modifiedAttributes,
89 Attribute<Matrix>::Ptr &leftVector) {
90 attributeDependencies.push_back(leftVector);
91 modifiedAttributes.push_back(mIntfVoltage);
92 modifiedAttributes.push_back(mIntfCurrent);
93}
94
96 Attribute<Matrix>::Ptr &leftVector) {
97 mnaCompUpdateVoltage(**leftVector);
98 mnaCompUpdateCurrent(**leftVector);
99}
100
102 // Voltage across component is defined as V1 - V0
103 **mIntfVoltage = Matrix::Zero(1, 1);
104 if (terminalNotGrounded(1)) {
105 (**mIntfVoltage)(0, 0) =
107 }
108 if (terminalNotGrounded(0)) {
109 (**mIntfVoltage)(0, 0) =
110 (**mIntfVoltage)(0, 0) -
112 }
113}
114
116 (**mIntfCurrent)(0, 0) = (**mIsClosed)
117 ? (**mIntfVoltage)(0, 0) / (**mClosedResistance)
118 : (**mIntfVoltage)(0, 0) / (**mOpenResistance);
119}
120
122 // Check if state of switch changed
123 if (!(mIsClosedPrev == this->mnaIsClosed())) {
124 mIsClosedPrev = this->mnaIsClosed();
125 return 1; //recompute system matrix
126 } else {
127 return 0; // do not recompute system matrix
128 }
129};
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].
const Attribute< Real >::Ptr mOpenResistance
Resistance if switch is open [ohm].
const Attribute< Bool >::Ptr mIsClosed
Defines if Switch is open or closed.
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.
Bool hasParameterChanged() override
Returns true if one of the element paramters has changed.
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.
void mnaCompInitialize(Real omega, Real timeStep, Attribute< Matrix >::Ptr leftVector) override
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.
String uid()
Returns unique id.
AttributeList::Ptr mAttributes
Attribute List.
spdlog::level::level_enum Level
Definition Logger.h:33
static String matrixToString(const Matrix &mat)
Definition Logger.cpp:31
static String phasorToString(const Complex &num)
Definition Logger.cpp:57
MNASimPowerComp(String uid, String name, Bool hasPreStep, Bool hasPostStep, Logger::Level logLevel)
static void stampConductance(Real conductance, SparseMatrixRow &mat, UInt node1Index, UInt node2Index, Bool isTerminal1NotGrounded, Bool isTerminal2NotGrounded, const Logger::Log &mSLog)
static Real realFromVectorElement(const Matrix &mat, Matrix::Index row)
UInt matrixNodeIndex(UInt nodeIndex)
const Attribute< MatrixVar< Real > >::Ptr mIntfCurrent
const Attribute< MatrixVar< Real > >::Ptr mIntfVoltage
std::shared_ptr< SimPowerComp< VarType > > Ptr
Bool terminalNotGrounded(UInt index)
Complex initialSingleVoltage(UInt index)
void setTerminalNumber(UInt num)
Logger::Level mLogLevel
Component logger control for internal variables.
Logger::Log mSLog
Component logger.
static std::shared_ptr< Switch > make(Args &&...args)
Definition PtrFactory.h:19
#define RMS3PH_TO_PEAK1PH
Definition Definitions.h:50
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
bool Bool
Definition Definitions.h:64
Eigen::SparseMatrix< Real, Eigen::RowMajor > SparseMatrixRow
Sparse matrix for real numbers (row major).
Definition Definitions.h:74