DPsim
Loading...
Searching...
No Matches
DP_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<Complex>(uid, name, false, true, logLevel),
17 **mIntfVoltage = MatrixComp::Zero(1, 1);
18 **mIntfCurrent = MatrixComp::Zero(1, 1);
19}
20
26
28
29 Real impedance = (**mIsClosed) ? **mClosedResistance : **mOpenResistance;
30 (**mIntfVoltage)(0, 0) = initialSingleVoltage(1) - initialSingleVoltage(0);
31 (**mIntfCurrent)(0, 0) = (**mIntfVoltage)(0, 0) / impedance;
32
33 SPDLOG_LOGGER_INFO(mSLog,
34 "\n--- Initialization from powerflow ---"
35 "\nVoltage across: {:s}"
36 "\nCurrent: {:s}"
37 "\nTerminal 0 voltage: {:s}"
38 "\nTerminal 1 voltage: {:s}"
39 "\n--- Initialization from powerflow finished ---",
44}
45
47 Attribute<Matrix>::Ptr leftVector) {
49 **mRightVector = Matrix::Zero(0, 0);
50}
51
53 SparseMatrixRow &systemMatrix) {
54 Complex conductance = (**mIsClosed) ? Complex(1. / **mClosedResistance, 0)
55 : Complex(1. / **mOpenResistance, 0);
56
57 MNAStampUtils::stampAdmittance(conductance, systemMatrix, matrixNodeIndex(0),
60}
61
63 Bool closed, SparseMatrixRow &systemMatrix, Int freqIdx) {
64 Complex conductance = (closed) ? Complex(1. / **mClosedResistance, 0)
65 : Complex(1. / **mOpenResistance, 0);
66
67 MNAStampUtils::stampAdmittance(conductance, systemMatrix, matrixNodeIndex(0),
70}
71
73
75
77 // Voltage across component is defined as V1 - V0
78 (**mIntfVoltage)(0, 0) = 0;
80 (**mIntfVoltage)(0, 0) =
83 (**mIntfVoltage)(0, 0) =
84 (**mIntfVoltage)(0, 0) -
86}
87
89 (**mIntfCurrent)(0, 0) = (**mIsClosed)
90 ? (**mIntfVoltage)(0, 0) / **mClosedResistance
91 : (**mIntfVoltage)(0, 0) / **mOpenResistance;
92}
93
95 AttributeBase::List &prevStepDependencies,
96 AttributeBase::List &attributeDependencies,
97 AttributeBase::List &modifiedAttributes,
98 Attribute<Matrix>::Ptr &leftVector) {
99
100 attributeDependencies.push_back(leftVector);
101 modifiedAttributes.push_back(mIntfVoltage);
102 modifiedAttributes.push_back(mIntfCurrent);
103}
104
106 Attribute<Matrix>::Ptr &leftVector) {
107 mnaCompUpdateVoltage(**leftVector);
108 mnaCompUpdateCurrent(**leftVector);
109}
110
112 // Check if state of switch changed
113 if (!(mIsClosedPrev == this->mnaIsClosed())) {
114 mIsClosedPrev = this->mnaIsClosed();
115 return 1; //recompute system matrix
116 } else {
117 return 0; // do not recompute system matrix
118 }
119};
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].
Bool isClosed()
Check if switch is closed.
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)
Initializes component from power flow data.
void mnaCompInitialize(Real omega, Real timeStep, Attribute< Matrix >::Ptr leftVector)
SimPowerComp< Complex >::Ptr clone(String name)
Returns a modified copy of the component with the given suffix added to the name and without.
void mnaCompUpdateVoltage(const Matrix &leftVector)
Update interface voltage from MNA system result.
void mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector)
Add MNA post step dependencies.
void mnaCompUpdateCurrent(const Matrix &leftVector)
Update interface current from MNA system result.
Bool mnaIsClosed()
Check if switch is closed.
void mnaCompPostStep(Real time, Int timeStepCount, Attribute< Matrix >::Ptr &leftVector)
MNA post step operations.
Switch(String uid, String name, Logger::Level loglevel=Logger::Level::off)
Defines UID, name, component parameters and logging level.
void mnaCompApplySwitchSystemMatrixStamp(Bool closed, SparseMatrixRow &systemMatrix, Int freqIdx)
Stamps system matrix considering the defined switch position.
void mnaCompApplyRightSideVectorStamp(Matrix &rightVector)
Stamps right side (source) vector.
void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix)
Stamps system matrix.
Bool hasParameterChanged()
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 stampAdmittance(Complex admittance, SparseMatrixRow &mat, UInt node1Index, UInt node2Index, Bool isTerminal1NotGrounded, Bool isTerminal2NotGrounded, const Logger::Log &mSLog, Int maxFreq=1, Int freqIdx=0)
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
const Attribute< MatrixVar< Complex > >::Ptr mIntfVoltage
std::shared_ptr< SimPowerComp< VarType > > Ptr
Bool terminalNotGrounded(UInt index)
Complex initialSingleVoltage(UInt index)
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
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