DPsim
Loading...
Searching...
No Matches
DP_Ph1_CurrentSource.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 Logger::Level logLevel)
15 : MNASimPowerComp<Complex>(uid, name, true, true, logLevel),
16 mCurrentRef(mAttributes->createDynamic<Complex>("I_ref")) {
18 **mIntfVoltage = MatrixComp::Zero(1, 1);
19 **mIntfCurrent = MatrixComp::Zero(1, 1);
20}
21
27
29 **mCurrentRef = current;
30 mParametersSet = true;
31}
32
35 copy->setParameters(**mCurrentRef);
36 return copy;
37}
38
40
41 (**mIntfVoltage)(0, 0) = initialSingleVoltage(0) - initialSingleVoltage(1);
42 (**mIntfCurrent)(0, 0) = **mCurrentRef;
43
44 SPDLOG_LOGGER_INFO(mSLog,
45 "\n--- Initialization from powerflow ---"
46 "\nVoltage across: {:s}"
47 "\nCurrent: {:s}"
48 "\nTerminal 0 voltage: {:s}"
49 "\nTerminal 1 voltage: {:s}"
50 "\n--- Initialization from powerflow finished ---",
55}
56
58 Real omega, Real timeStep, Attribute<Matrix>::Ptr leftVector) {
60 (**mIntfCurrent)(0, 0) = **mCurrentRef;
61}
62
64 AttributeBase::List &prevStepDependencies,
65 AttributeBase::List &attributeDependencies,
66 AttributeBase::List &modifiedAttributes) {
67 attributeDependencies.push_back(mCurrentRef);
68 modifiedAttributes.push_back(mRightVector);
69 modifiedAttributes.push_back(mIntfCurrent);
70}
71
75
77 Matrix &rightVector) {
78 (**mIntfCurrent)(0, 0) = **mCurrentRef;
79
82 -(**mIntfCurrent)(0, 0));
85 (**mIntfCurrent)(0, 0));
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}
96
98 Real time, Int timeStepCount, Attribute<Matrix>::Ptr &leftVector) {
99 mnaCompUpdateVoltage(**leftVector);
100}
101
103 (**mIntfVoltage)(0, 0) = 0;
104 if (terminalNotGrounded(0))
105 (**mIntfVoltage)(0, 0) =
107 if (terminalNotGrounded(1))
108 (**mIntfVoltage)(0, 0) =
109 (**mIntfVoltage)(0, 0) -
111}
std::vector< Ptr > List
Definition Attribute.h:123
AttributePointer< Attribute< T > > Ptr
Definition Attribute.h:250
void mnaCompPreStep(Real time, Int timeStepCount) override
CurrentSource(String uid, String name, Logger::Level loglevel=Logger::Level::off)
Defines UID, name and logging level.
SimPowerComp< Complex >::Ptr clone(String copySuffix) override
Returns a modified copy of the component with the given suffix added to the name and without.
void initializeFromNodesAndTerminals(Real frequency) override
Initializes component from power flow data.
const Attribute< Complex >::Ptr mCurrentRef
void mnaCompInitialize(Real omega, Real timeStep, Attribute< Matrix >::Ptr leftVector) override
void mnaCompPostStep(Real time, Int timeStepCount, Attribute< Matrix >::Ptr &leftVector) override
void mnaCompApplyRightSideVectorStamp(Matrix &rightVector) override
Stamps right side (source) vector.
void mnaCompUpdateVoltage(const Matrix &leftVector) override
void mnaCompAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes) override
Add MNA pre step dependencies.
void setParameters(Complex current)
void mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector) override
Add MNA post step dependencies.
String uid()
Returns unique id.
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 Complex complexFromVectorElement(const Matrix &mat, Matrix::Index row, Int maxFreq=1, Int freqIdx=0)
Definition MathUtils.cpp:94
static void setVectorElement(Matrix &mat, Matrix::Index row, Complex value, Int maxFreq=1, Int freqIdx=0, Matrix::Index colOffset=0)
Definition MathUtils.cpp:73
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.
bool mParametersSet
Flag indicating that parameters are set via setParameters() function.
Logger::Log mSLog
Component logger.
static std::shared_ptr< CurrentSource > make(Args &&...args)
Definition PtrFactory.h:19
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