DPsim
Loading...
Searching...
No Matches
DP_Ph1_ControlledCurrentSource.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 Institute for Automation of Complex Power Systems, EONERC, RWTH Aachen University
2// SPDX-License-Identifier: MPL-2.0
3
5
6using namespace CPS;
7
10 : MNASimPowerComp<Complex>(uid, name, true, true, logLevel),
11 mCurrentRef(mAttributes->createDynamic<Complex>("I_ref")) {
13 **mIntfVoltage = MatrixComp::Zero(1, 1);
14 **mIntfCurrent = MatrixComp::Zero(1, 1);
15}
16
18 **mCurrentRef = currentRef;
19 mParametersSet = true;
20}
21
25 copy->setParameters(**mCurrentRef);
26 return copy;
27}
28
30 Real frequency) {
31
32 (**mIntfVoltage)(0, 0) = initialSingleVoltage(0) - initialSingleVoltage(1);
33 (**mIntfCurrent)(0, 0) = **mCurrentRef;
34
35 SPDLOG_LOGGER_INFO(mSLog,
36 "\n--- Initialization from powerflow ---"
37 "\nVoltage across: {:s}"
38 "\nCurrent: {:s}"
39 "\nTerminal 0 voltage: {:s}"
40 "\nTerminal 1 voltage: {:s}"
41 "\n--- Initialization from powerflow finished ---",
46}
47
49 Real omega, Real timeStep, Attribute<Matrix>::Ptr leftVector) {
51 (**mIntfCurrent)(0, 0) = **mCurrentRef;
52}
53
55 (**mIntfCurrent)(0, 0) = **mCurrentRef;
56
57 SPDLOG_LOGGER_DEBUG(mSLog, "\nUpdate current: {:s}",
59}
60
62 AttributeBase::List &prevStepDependencies,
63 AttributeBase::List &attributeDependencies,
64 AttributeBase::List &modifiedAttributes) {
65 attributeDependencies.push_back(mCurrentRef);
66 modifiedAttributes.push_back(mRightVector);
67 modifiedAttributes.push_back(mIntfCurrent);
68}
69
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 const Matrix &leftVector) {
104 (**mIntfVoltage)(0, 0) = 0;
105 if (terminalNotGrounded(0))
106 (**mIntfVoltage)(0, 0) =
108 if (terminalNotGrounded(1))
109 (**mIntfVoltage)(0, 0) =
110 (**mIntfVoltage)(0, 0) -
112}
std::vector< Ptr > List
Definition Attribute.h:123
AttributePointer< Attribute< T > > Ptr
Definition Attribute.h:250
void mnaCompUpdateVoltage(const Matrix &leftVector) override
void mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector) override
Add MNA post step dependencies.
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 mnaCompInitialize(Real omega, Real timeStep, Attribute< Matrix >::Ptr leftVector) override
void mnaCompPostStep(Real time, Int timeStepCount, Attribute< Matrix >::Ptr &leftVector) override
void mnaCompPreStep(Real time, Int timeStepCount) override
void mnaCompApplyRightSideVectorStamp(Matrix &rightVector) override
Stamps right side (source) vector.
void mnaCompAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes) override
Add MNA pre step dependencies.
void initializeFromNodesAndTerminals(Real frequency) override
Initializes component from power flow data.
ControlledCurrentSource(String uid, String name, Logger::Level loglevel=Logger::Level::off)
Defines UID, name and logging level.
String uid()
Returns unique id.
AttributeList::Ptr mAttributes
Attribute List.
spdlog::level::level_enum Level
Definition Logger.h:33
static String matrixToString(const Matrix &mat)
Definition Logger.cpp:31
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< ControlledCurrentSource > 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