DPsim
Loading...
Searching...
No Matches
DP_Ph3_Resistor.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),
18
19 **mIntfVoltage = MatrixComp::Zero(3, 1);
20 **mIntfCurrent = MatrixComp::Zero(3, 1);
21}
22
24 auto copy = Resistor::make(name, mLogLevel);
25 copy->setParameters(**mResistance);
26 return copy;
27}
28
30 // ---------------------------------------------------------------------------
31 // DP / PF CONVENTION CONVERSION
32 // ---------------------------------------------------------------------------
33 // Power-flow node voltages are line-line RMS phasors.
34 // DP::Ph3 states use phase-peak complex envelopes.
35 //
36 // The previous implementation constructed B/C from mIntfVoltage(A) without
37 // first assigning phase A from the PF terminal voltages. This made standalone
38 // resistor initialization dependent on stale/default interface state.
39 // ---------------------------------------------------------------------------
40
41 MatrixComp vInitABC = MatrixComp::Zero(3, 1);
42
43 vInitABC(0, 0) =
45
46 vInitABC(1, 0) = vInitABC(0, 0) * SHIFT_TO_PHASE_B;
47
48 vInitABC(2, 0) = vInitABC(0, 0) * SHIFT_TO_PHASE_C;
49
50 **mIntfVoltage = vInitABC;
51
52 **mIntfCurrent = (**mResistance).inverse() * **mIntfVoltage;
53
54 SPDLOG_LOGGER_INFO(
55 mSLog,
56 "\n--- Initialization from powerflow ---"
57 "\nDP convention: phase-peak complex envelopes"
58 "\nVoltage across:"
59 "\n{:s}"
60 "\nCurrent:"
61 "\n{:s}"
62 "\nTerminal 0 PF voltage converted to phase peak: {:s}"
63 "\nTerminal 1 PF voltage converted to phase peak: {:s}"
64 "\n--- Initialization from powerflow finished ---",
69}
70
72 Attribute<Matrix>::Ptr leftVector) {
74 **mRightVector = Matrix::Zero(0, 0);
75}
76
78 SparseMatrixRow &systemMatrix) {
80
81 conductance.real() = (**mResistance).inverse();
82
84 conductance, systemMatrix, matrixNodeIndex(0), matrixNodeIndex(1),
86}
87
89 AttributeBase::List &prevStepDependencies,
90 AttributeBase::List &attributeDependencies,
91 AttributeBase::List &modifiedAttributes,
92 Attribute<Matrix>::Ptr &leftVector) {
93 attributeDependencies.push_back(leftVector);
94 modifiedAttributes.push_back(mIntfVoltage);
95 modifiedAttributes.push_back(mIntfCurrent);
96}
97
99 Attribute<Matrix>::Ptr &leftVector) {
100 mnaCompUpdateVoltage(**leftVector);
101 mnaCompUpdateCurrent(**leftVector);
102}
103
105 **mIntfVoltage = MatrixComp::Zero(3, 1);
106
107 if (terminalNotGrounded(1)) {
108 (**mIntfVoltage)(0, 0) =
110
111 (**mIntfVoltage)(1, 0) =
113
114 (**mIntfVoltage)(2, 0) =
116 }
117
118 if (terminalNotGrounded(0)) {
119 (**mIntfVoltage)(0, 0) -=
121
122 (**mIntfVoltage)(1, 0) -=
124
125 (**mIntfVoltage)(2, 0) -=
127 }
128
129 SPDLOG_LOGGER_DEBUG(mSLog, "Voltage A: {} < {}",
130 std::abs((**mIntfVoltage)(0, 0)),
131 std::arg((**mIntfVoltage)(0, 0)));
132}
133
135 **mIntfCurrent = (**mResistance).inverse() * **mIntfVoltage;
136
137 SPDLOG_LOGGER_DEBUG(mSLog, "Current A: {} < {}",
138 std::abs((**mIntfCurrent)(0, 0)),
139 std::arg((**mIntfCurrent)(0, 0)));
140}
141
142// #### Tear Methods ####
143
146
147 conductance.real() = (**mResistance).inverse();
148
149 Math::addToMatrixElement(tearMatrix, mTearIdx * 3, mTearIdx * 3,
150 1.0 / conductance(0, 0).real());
151
152 Math::addToMatrixElement(tearMatrix, mTearIdx * 3 + 1, mTearIdx * 3 + 1,
153 1.0 / conductance(1, 1).real());
154
155 Math::addToMatrixElement(tearMatrix, mTearIdx * 3 + 2, mTearIdx * 3 + 2,
156 1.0 / conductance(2, 2).real());
157}
std::vector< Ptr > List
Definition Attribute.h:123
AttributePointer< Attribute< T > > Ptr
Definition Attribute.h:249
const CPS::Attribute< Matrix >::Ptr mResistance
Resistance [ohm].
void mnaTearApplyMatrixStamp(SparseMatrixRow &tearMatrix) override
void mnaCompPostStep(Real time, Int timeStepCount, Attribute< Matrix >::Ptr &leftVector) override
void mnaCompUpdateCurrent(const Matrix &leftVector) override
SimPowerComp< Complex >::Ptr clone(String name) override
Returns a modified copy of the component with the given suffix added to the name and without.
void initializeFromNodesAndTerminals(Real frequency) override
Initialize DP phase-peak envelopes from line-line RMS PF node voltages.
void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override
void mnaCompUpdateVoltage(const Matrix &leftVector) override
Resistor(String uid, String name, Logger::Level logLevel=Logger::Level::off)
void mnaCompInitialize(Real omega, Real timeStep, Attribute< Matrix >::Ptr leftVector) override
void mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector) override
String uid()
Returns unique id.
AttributeList::Ptr mAttributes
Attribute List.
spdlog::level::level_enum Level
Definition Logger.h:33
static String matrixCompToString(const MatrixComp &mat)
Definition Logger.cpp:37
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 stampAdmittanceMatrix(const MatrixComp &admittanceMat, 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
static void addToMatrixElement(SparseMatrixRow &mat, Matrix::Index row, Matrix::Index column, Complex value, Int maxFreq=1, Int freqIdx=0)
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< Resistor > make(Args &&...args)
Definition PtrFactory.h:19
#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: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
Eigen::Matrix< Complex, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor > MatrixComp
Dense matrix for complex numbers.
Definition Definitions.h:84
Eigen::Matrix< Complex, rows, cols, Eigen::ColMajor > MatrixFixedSizeComp
Dense matrix for complex numbers with fixed dimension.
Eigen::SparseMatrix< Real, Eigen::RowMajor > SparseMatrixRow
Sparse matrix for real numbers (row major).
Definition Definitions.h:74