DPsim
Loading...
Searching...
No Matches
SP_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
22
27
31 copy->setParameters(**mCurrentRef);
32 return copy;
33}
34
36 Real frequency) {
37
38 (**mIntfVoltage)(0, 0) = initialSingleVoltage(0) - initialSingleVoltage(1);
39 (**mIntfCurrent)(0, 0) = **mCurrentRef;
40
41 SPDLOG_LOGGER_INFO(mSLog,
42 "\n--- Initialization from powerflow ---"
43 "\nVoltage across: {:s}"
44 "\nCurrent: {:s}"
45 "\nTerminal 0 voltage: {:s}"
46 "\nTerminal 1 voltage: {:s}"
47 "\n--- Initialization from powerflow finished ---",
52}
53
55 Real omega, Real timeStep, Attribute<Matrix>::Ptr leftVector) {
57 (**mIntfCurrent)(0, 0) = **mCurrentRef;
58}
59
61 (**mIntfCurrent)(0, 0) = **mCurrentRef;
62
63 SPDLOG_LOGGER_DEBUG(mSLog, "\nUpdate current: {:s}",
65}
66
68 AttributeBase::List &prevStepDependencies,
69 AttributeBase::List &attributeDependencies,
70 AttributeBase::List &modifiedAttributes) {
71 attributeDependencies.push_back(mCurrentRef);
72 modifiedAttributes.push_back(mRightVector);
73 modifiedAttributes.push_back(mIntfCurrent);
74}
75
81
83 Matrix &rightVector) {
84 (**mIntfCurrent)(0, 0) = **mCurrentRef;
85
88 -(**mIntfCurrent)(0, 0));
91 (**mIntfCurrent)(0, 0));
92}
93
95 AttributeBase::List &prevStepDependencies,
96 AttributeBase::List &attributeDependencies,
97 AttributeBase::List &modifiedAttributes,
98 Attribute<Matrix>::Ptr &leftVector) {
99 attributeDependencies.push_back(leftVector);
100 modifiedAttributes.push_back(mIntfVoltage);
101}
102
104 Real time, Int timeStepCount, Attribute<Matrix>::Ptr &leftVector) {
105 mnaCompUpdateVoltage(**leftVector);
106}
107
109 const Matrix &leftVector) {
110 (**mIntfVoltage)(0, 0) = 0;
111 if (terminalNotGrounded(0))
112 (**mIntfVoltage)(0, 0) =
114 if (terminalNotGrounded(1))
115 (**mIntfVoltage)(0, 0) =
116 (**mIntfVoltage)(0, 0) -
118}
std::vector< Ptr > List
Definition Attribute.h:123
AttributePointer< Attribute< T > > Ptr
Definition Attribute.h:250
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
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 mnaCompUpdateVoltage(const Matrix &leftVector) override
void mnaCompPostStep(Real time, Int timeStepCount, Attribute< Matrix >::Ptr &leftVector) override
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 mnaCompInitialize(Real omega, Real timeStep, Attribute< Matrix >::Ptr leftVector) override
ControlledCurrentSource(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.
void mnaCompPreStep(Real time, Int timeStepCount) override
void mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector) override
Add MNA post step dependencies.
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