DPsim
Loading...
Searching...
No Matches
EMT_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 *********************************************************************************/
8
10
11using namespace CPS;
12
21
24 copy->setParameters(**mResistance);
25 return copy;
26}
27
29
30 // Convert line-line RMS PF voltage to balanced phase-ground peak values,
31 // matching EMT::Ph3::Resistor and the time-domain signal convention.
32 MatrixComp vInitABC = MatrixComp::Zero(3, 1);
33 vInitABC(0, 0) =
35 vInitABC(1, 0) = vInitABC(0, 0) * SHIFT_TO_PHASE_B;
36 vInitABC(2, 0) = vInitABC(0, 0) * SHIFT_TO_PHASE_C;
37 **mIntfVoltage = vInitABC.real();
38 **mIntfCurrent = (vInitABC / **mResistance).real();
39
40 SPDLOG_LOGGER_INFO(mSLog,
41 "\n--- Initialization from powerflow ---"
42 "\nVoltage across amplitude and phase: \n{}"
43 "\nCurrent amplitude and phase: \n{}"
44 "\nTerminal 0 voltage amplitude and phase: \n{}"
45 "\nTerminal 1 voltage amplitude and phase: \n{}"
46 "\n--- Initialization from powerflow finished ---",
51}
52
54 Real omega, Real timeStep, Attribute<Matrix>::Ptr leftVector) {
56 **mRightVector = Matrix::Zero(0, 0);
57}
58
60 SparseMatrixRow &systemMatrix) {
61 Real conductance = 1. / **mResistance;
62
63 // Set diagonal entries
66 matrixNodeIndices(0), conductance);
69 matrixNodeIndices(1), conductance);
70 // Set off diagonal entries
73 matrixNodeIndices(1), -conductance);
75 matrixNodeIndices(0), -conductance);
76 }
77
79 SPDLOG_LOGGER_INFO(mSLog, "Add {} to {}, {}", conductance,
80 matrixNodeIndex(0, 0), matrixNodeIndex(0, 0));
82 SPDLOG_LOGGER_INFO(mSLog, "Add {} to {}, {}", conductance,
83 matrixNodeIndex(1, 0), matrixNodeIndex(1, 0));
85 SPDLOG_LOGGER_INFO(mSLog, "Add {} to {}, {}", -conductance,
86 matrixNodeIndex(0, 0), matrixNodeIndex(1, 0));
87 SPDLOG_LOGGER_INFO(mSLog, "Add {} to {}, {}", -conductance,
88 matrixNodeIndex(1, 0), matrixNodeIndex(0, 0));
89 }
90}
91
93 AttributeBase::List &prevStepDependencies,
94 AttributeBase::List &attributeDependencies,
95 AttributeBase::List &modifiedAttributes,
96 Attribute<Matrix>::Ptr &leftVector) {
97
98 attributeDependencies.push_back(leftVector);
99 modifiedAttributes.push_back(mIntfVoltage);
100 modifiedAttributes.push_back(mIntfCurrent);
101}
102
104 Real time, Int timeStepCount, Attribute<Matrix>::Ptr &leftVector) {
105 mnaCompUpdateVoltage(**leftVector);
106 mnaCompUpdateCurrent(**leftVector);
107}
108
110 // Voltage across component is defined as V1 - V0
111 (**mIntfVoltage).setZero();
112 if (terminalNotGrounded(1)) {
113 (**mIntfVoltage)(0, 0) =
115 (**mIntfVoltage)(1, 0) =
117 (**mIntfVoltage)(2, 0) =
119 }
120 if (terminalNotGrounded(0)) {
121 (**mIntfVoltage)(0, 0) =
122 (**mIntfVoltage)(0, 0) -
124 (**mIntfVoltage)(1, 0) =
125 (**mIntfVoltage)(1, 0) -
127 (**mIntfVoltage)(2, 0) =
128 (**mIntfVoltage)(2, 0) -
130 }
131
132 SPDLOG_LOGGER_DEBUG(mSLog, "Voltage A: {}", (**mIntfVoltage)(0, 0));
133}
134
136 const Real conductance = 1. / **mResistance;
137 **mIntfCurrent = **mIntfVoltage * conductance;
138
139 SPDLOG_LOGGER_DEBUG(mSLog, "Current A: {} < {}", (**mIntfCurrent)(0, 0));
140}
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)
void mnaCompUpdateCurrent(const Matrix &leftVector) override
Update interface voltage from MNA system results.
void mnaCompInitialize(Real omega, Real timeStep, Attribute< Matrix >::Ptr leftVector) override
Initializes MNA specific variables.
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
Return new instance with the same parameters.
SeriesResistor(String uid, String name, Logger::Level logLevel=Logger::Level::off)
Defines UID, name and log level.
void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override
Stamps system matrix.
void initializeFromNodesAndTerminals(Real frequency) override
Initializes states from power flow data.
void mnaCompUpdateVoltage(const Matrix &leftVector) override
Update interface voltage from MNA system results.
void mnaCompPostStep(Real time, Int timeStepCount, 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 Real realFromVectorElement(const Matrix &mat, Matrix::Index row)
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< Real > >::Ptr mIntfCurrent
const Attribute< MatrixVar< Real > >::Ptr mIntfVoltage
MatrixComp initialVoltage(UInt index)
std::shared_ptr< SimPowerComp< VarType > > Ptr
Bool terminalNotGrounded(UInt index)
Complex initialSingleVoltage(UInt index)
void setTerminalNumber(UInt num)
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:79
std::string String
Definition Definitions.h:63
double Real
Definition Definitions.h:60
int Int
Definition Definitions.h:59
Eigen::Matrix< Complex, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor > MatrixComp
Dense matrix for complex numbers.
Definition Definitions.h:82
Eigen::SparseMatrix< Real, Eigen::RowMajor > SparseMatrixRow
Sparse matrix for real numbers (row major).
Definition Definitions.h:72