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 mConductance.real() = (**mResistance).inverse();
75 **mRightVector = Matrix::Zero(0, 0);
76}
77
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 const bool terminal0Connected = terminalNotGrounded(0);
103 const bool terminal1Connected = terminalNotGrounded(1);
104 const Matrix::Index imaginaryOffset = leftVector.rows() / 2;
105 for (UInt phase = 0; phase < 3; ++phase) {
106 Complex voltage(0., 0.);
107 if (terminal1Connected) {
108 const Matrix::Index row = matrixNodeIndex(1, phase);
109 voltage =
110 Complex(leftVector(row, 0), leftVector(row + imaginaryOffset, 0));
111 }
112 if (terminal0Connected) {
113 const Matrix::Index row = matrixNodeIndex(0, phase);
114 voltage -=
115 Complex(leftVector(row, 0), leftVector(row + imaginaryOffset, 0));
116 }
117 (**mIntfVoltage)(phase, 0) = voltage;
118 }
119
120 SPDLOG_LOGGER_DEBUG(mSLog, "Voltage A: {} < {}",
121 std::abs((**mIntfVoltage)(0, 0)),
122 std::arg((**mIntfVoltage)(0, 0)));
123}
124
126 // The dimensions are fixed at 3x3; scalar rows avoid dynamic GEMV setup in
127 // this per-step post-processing path.
128 const MatrixComp &voltage = **mIntfVoltage;
129 MatrixComp &current = **mIntfCurrent;
130 for (Int phase = 0; phase < 3; ++phase)
131 current(phase, 0) = mConductance(phase, 0) * voltage(0, 0) +
132 mConductance(phase, 1) * voltage(1, 0) +
133 mConductance(phase, 2) * voltage(2, 0);
134
135 SPDLOG_LOGGER_DEBUG(mSLog, "Current A: {} < {}",
136 std::abs((**mIntfCurrent)(0, 0)),
137 std::arg((**mIntfCurrent)(0, 0)));
138}
139
140// #### Tear Methods ####
141
143 // Keep mutual phase coupling in the tear system. Stamping only the
144 // diagonal here disagrees with the full resistance matrix used by MNA.
145 for (UInt row = 0; row < 3; ++row) {
146 for (UInt col = 0; col < 3; ++col) {
147 Math::addToMatrixElement(tearMatrix, mTearIdx * 3 + row,
148 mTearIdx * 3 + col,
149 Complex((**mResistance)(row, col), 0.0));
150 }
151 }
152}
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 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: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
unsigned int UInt
Definition Definitions.h:58
Eigen::SparseMatrix< Real, Eigen::RowMajor > SparseMatrixRow
Sparse matrix for real numbers (row major).
Definition Definitions.h:72