DPsim
Loading...
Searching...
No Matches
SP_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 **mIntfVoltage = MatrixComp::Zero(3, 1);
19 **mIntfCurrent = MatrixComp::Zero(3, 1);
20}
21
23 auto copy = Resistor::make(name, mLogLevel);
24 copy->setParameters(**mResistance);
25 return copy;
26}
27
29
30 Real voltMag = Math::abs((**mIntfVoltage)(0, 0));
31 Real voltPhase = Math::phase((**mIntfVoltage)(0, 0));
32 (**mIntfVoltage)(1, 0) = Complex(voltMag * cos(voltPhase - 2. / 3. * M_PI),
33 voltMag * sin(voltPhase - 2. / 3. * M_PI));
34 (**mIntfVoltage)(2, 0) = Complex(voltMag * cos(voltPhase + 2. / 3. * M_PI),
35 voltMag * sin(voltPhase + 2. / 3. * M_PI));
36 **mIntfCurrent = (**mResistance).inverse() * **mIntfVoltage;
37
38 SPDLOG_LOGGER_INFO(mSLog, "Node 1 : {}",
40 SPDLOG_LOGGER_INFO(mSLog, "Node 2 : {}",
42 SPDLOG_LOGGER_INFO(mSLog, "initialize {} {} voltage to {} and current to {}",
43 this->type(), this->name(),
46}
47
49 Attribute<Matrix>::Ptr leftVector) {
51 mConductance = (**mResistance).inverse();
52 **mRightVector = Matrix::Zero(0, 0);
53}
54
56 SparseMatrixRow &systemMatrix) {
57 MatrixFixedSizeComp<3, 3> conductance = Matrix::Zero(3, 3);
58 conductance.real() = mConductance;
59
61 conductance, systemMatrix, matrixNodeIndex(0), matrixNodeIndex(1),
63}
64
66 AttributeBase::List &prevStepDependencies,
67 AttributeBase::List &attributeDependencies,
68 AttributeBase::List &modifiedAttributes,
69 Attribute<Matrix>::Ptr &leftVector) {
70 attributeDependencies.push_back(leftVector);
71 modifiedAttributes.push_back(mIntfVoltage);
72 modifiedAttributes.push_back(mIntfCurrent);
73}
74
76 Attribute<Matrix>::Ptr &leftVector) {
77 mnaCompUpdateVoltage(**leftVector);
78 mnaCompUpdateCurrent(**leftVector);
79}
80
82 // Voltage across component is defined as V1 - V0
83 (**mIntfVoltage).setZero();
84 if (terminalNotGrounded(1)) {
85 (**mIntfVoltage)(0, 0) =
87 (**mIntfVoltage)(1, 0) =
89 (**mIntfVoltage)(2, 0) =
91 }
92 if (terminalNotGrounded(0)) {
93 (**mIntfVoltage)(0, 0) =
94 (**mIntfVoltage)(0, 0) -
96 (**mIntfVoltage)(1, 0) =
97 (**mIntfVoltage)(1, 0) -
99 (**mIntfVoltage)(2, 0) =
100 (**mIntfVoltage)(2, 0) -
102 }
103
104 //mLog.debug() << "Voltage A: " << std::abs((**mIntfVoltage)(0, 0))
105 // << "<" << std::arg((**mIntfVoltage)(0, 0)) << std::endl;
106}
107
109 **mIntfCurrent = mConductance * **mIntfVoltage;
110 //mLog.debug() << "Current A: " << std::abs((**mIntfCurrent)(0, 0))
111 // << "<" << std::arg((**mIntfCurrent)(0, 0)) << std::endl;
112}
113
115 // TODO
117 Complex((**mResistance)(0, 0), 0));
119 Complex((**mResistance)(1, 1), 0));
121 Complex((**mResistance)(2, 2), 0));
122}
std::vector< Ptr > List
Definition Attribute.h:123
AttributePointer< Attribute< T > > Ptr
Definition Attribute.h:249
const CPS::Attribute< Matrix >::Ptr mResistance
Resistance [ohm].
String uid()
Returns unique id.
String type()
Get component type (cross-platform)
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 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)
static Real phase(Complex value)
Definition MathUtils.cpp:67
static Real abs(Complex value)
Definition MathUtils.cpp:71
static void addToMatrixElement(SparseMatrixRow &mat, Matrix::Index row, Matrix::Index column, Complex value, Int maxFreq=1, Int freqIdx=0)
void mnaTearApplyMatrixStamp(SparseMatrixRow &tearMatrix) override
void mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector) override
Add MNA post step dependencies.
void initializeFromNodesAndTerminals(Real frequency) override
Initializes component from power flow data.
void mnaCompPostStep(Real time, Int timeStepCount, Attribute< Matrix >::Ptr &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 mnaCompUpdateCurrent(const Matrix &leftVector) override
Resistor(String uid, String name, Logger::Level logLevel=Logger::Level::off)
Defines UID, name and logging level.
void mnaCompUpdateVoltage(const Matrix &leftVector) override
void mnaCompInitialize(Real omega, Real timeStep, Attribute< Matrix >::Ptr leftVector) override
void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override
Stamps system matrix.
UInt matrixNodeIndex(UInt nodeIndex)
const Attribute< MatrixVar< Complex > >::Ptr mIntfCurrent
const Attribute< MatrixVar< Complex > >::Ptr mIntfVoltage
MatrixComp initialVoltage(UInt index)
std::shared_ptr< SimPowerComp< VarType > > Ptr
Bool terminalNotGrounded(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 M_PI
Definition Definitions.h:41
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, 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:72