DPsim
Loading...
Searching...
No Matches
DP_Ph3_SeriesResistor.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 *********************************************************************************/
9
10using namespace CPS;
11
13 Logger::Level logLevel)
14 : MNASimPowerComp<Complex>(uid, name, false, true, logLevel),
18 **mIntfVoltage = MatrixComp::Zero(3, 1);
19 **mIntfCurrent = MatrixComp::Zero(3, 1);
20}
21
24 copy->setParameters(**mResistance);
25 return copy;
26}
27
29
30 mTerminals[0]->setPhaseType(PhaseType::ABC);
31 mTerminals[1]->setPhaseType(PhaseType::ABC);
32
33 MatrixComp vInitABC = MatrixComp::Zero(3, 1);
34 vInitABC(0, 0) =
36 vInitABC(1, 0) = vInitABC(0, 0) * SHIFT_TO_PHASE_B;
37 vInitABC(2, 0) = vInitABC(0, 0) * SHIFT_TO_PHASE_C;
38
39 **mIntfVoltage = vInitABC;
41
42 SPDLOG_LOGGER_INFO(mSLog,
43 "\n--- Initialization from powerflow ---"
44 "\nVoltage across amplitude and phase: \n{:s}"
45 "\nCurrent amplitude and phase: \n{:s}"
46 "\nTerminal 0 voltage amplitude and phase: \n{:s}"
47 "\nTerminal 1 voltage amplitude and phase: \n{:s}"
48 "\n--- Initialization from powerflow finished ---",
53}
54
56 Real omega, Real timeStep, Attribute<Matrix>::Ptr leftVector) {
58 **mRightVector = Matrix::Zero(0, 0);
59}
60
62 SparseMatrixRow &systemMatrix) {
63 Complex conductance = {(1. / **mResistance), 0};
64
66 //if (terminalNotGrounded(0))
67 // Math::addToMatrixElement(systemMatrix, matrixNodeIndices(0), matrixNodeIndices(0), conductance);
68 //if (terminalNotGrounded(1))
69 // Math::addToMatrixElement(systemMatrix, matrixNodeIndices(1), matrixNodeIndices(1), conductance);
71 //if (terminalNotGrounded(0) && terminalNotGrounded(1)) {
72 // Math::addToMatrixElement(systemMatrix, matrixNodeIndices(0), matrixNodeIndices(1), -conductance);
73 // Math::addToMatrixElement(systemMatrix, matrixNodeIndices(1), matrixNodeIndices(0), -conductance);
74 //}
75 // Set diagonal entries
76 if (terminalNotGrounded(0)) {
78 matrixNodeIndices(0), conductance);
79 }
80 if (terminalNotGrounded(1)) {
82 matrixNodeIndices(1), conductance);
83 }
84 // Set off diagonal entries
87 matrixNodeIndices(1), -conductance);
89 matrixNodeIndices(0), -conductance);
90 }
91
93 SPDLOG_LOGGER_INFO(mSLog, "Add {} to {}, {}", conductance,
94 matrixNodeIndex(0, 0), matrixNodeIndex(0, 0));
96 SPDLOG_LOGGER_INFO(mSLog, "Add {} to {}, {}", conductance,
97 matrixNodeIndex(1, 0), matrixNodeIndex(1, 0));
99 SPDLOG_LOGGER_INFO(mSLog, "Add {} to {}, {}", -conductance,
100 matrixNodeIndex(0, 0), matrixNodeIndex(1, 0));
101 SPDLOG_LOGGER_INFO(mSLog, "Add {} to {}, {}", -conductance,
102 matrixNodeIndex(1, 0), matrixNodeIndex(0, 0));
103 }
104}
105
107 AttributeBase::List &prevStepDependencies,
108 AttributeBase::List &attributeDependencies,
109 AttributeBase::List &modifiedAttributes,
110 Attribute<Matrix>::Ptr &leftVector) {
111 attributeDependencies.push_back(leftVector);
112 modifiedAttributes.push_back(mIntfVoltage);
113 modifiedAttributes.push_back(mIntfCurrent);
114}
115
117 Real time, Int timeStepCount, Attribute<Matrix>::Ptr &leftVector) {
118 mnaCompUpdateVoltage(**leftVector);
119 mnaCompUpdateCurrent(**leftVector);
120}
121
123 // Voltage across component is defined as V1 - V0
124 **mIntfVoltage = MatrixComp::Zero(3, 1);
125 if (terminalNotGrounded(1)) {
126 (**mIntfVoltage)(0, 0) =
128 (**mIntfVoltage)(1, 0) =
130 (**mIntfVoltage)(2, 0) =
132 }
133 if (terminalNotGrounded(0)) {
134 (**mIntfVoltage)(0, 0) =
135 (**mIntfVoltage)(0, 0) -
137 (**mIntfVoltage)(1, 0) =
138 (**mIntfVoltage)(1, 0) -
140 (**mIntfVoltage)(2, 0) =
141 (**mIntfVoltage)(2, 0) -
143 }
144
145 SPDLOG_LOGGER_DEBUG(mSLog, "Voltage A: {} < {}",
146 std::abs((**mIntfVoltage)(0, 0)),
147 std::arg((**mIntfVoltage)(0, 0)));
148}
149
152
153 SPDLOG_LOGGER_DEBUG(mSLog, "Current A: {} < {}",
154 std::abs((**mIntfCurrent)(0, 0)),
155 std::arg((**mIntfCurrent)(0, 0)));
156}
std::vector< Ptr > List
Definition Attribute.h:123
AttributePointer< Attribute< T > > Ptr
Definition Attribute.h:249
const CPS::Attribute< Real >::Ptr mResistance
Resistance [ohm].
Resistor(CPS::AttributeList::Ptr attributeList)
SeriesResistor(String uid, String name, Logger::Level logLevel=Logger::Level::off)
Defines UID, name and logging level.
void initializeFromNodesAndTerminals(Real frequency) override
Initializes component from power flow data.
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 mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector) override
Add MNA post step dependencies.
void mnaCompUpdateCurrent(const Matrix &leftVector) override
void mnaCompPostStep(Real time, Int timeStepCount, Attribute< Matrix >::Ptr &leftVector) override
void mnaCompUpdateVoltage(const Matrix &leftVector) override
void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override
Stamps system matrix.
void mnaCompInitialize(Real omega, Real timeStep, 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 phasorMatrixToString(const MatrixComp &mat)
Definition Logger.cpp:51
MNASimPowerComp(String uid, String name, Bool hasPreStep, Bool hasPostStep, Logger::Level logLevel)
Attribute< Matrix >::Ptr mRightVector
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
SimTerminal< Complex >::List mTerminals
const Attribute< MatrixVar< Complex > >::Ptr mIntfVoltage
MatrixComp initialVoltage(UInt index)
std::shared_ptr< SimPowerComp< VarType > > Ptr
Bool terminalNotGrounded(UInt index)
Complex initialSingleVoltage(UInt index)
std::vector< UInt > matrixNodeIndices(UInt index)
Logger::Level mLogLevel
Component logger control for internal variables.
Logger::Log mSLog
Component logger.
static std::shared_ptr< SeriesResistor > 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::SparseMatrix< Real, Eigen::RowMajor > SparseMatrixRow
Sparse matrix for real numbers (row major).
Definition Definitions.h:74