DPsim
Loading...
Searching...
No Matches
DP_Ph3_NetworkInjection.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
9 Logger::Level logLevel)
10 : CompositePowerComp<Complex>(uid, name, true, true, logLevel),
11 mVoltageRef(mAttributes->createDynamic<MatrixComp>("V_ref")),
12 mSrcFreq(mAttributes->createDynamic<Real>("f_src")) {
16 **mIntfVoltage = MatrixComp::Zero(3, 1);
17 **mIntfCurrent = MatrixComp::Zero(3, 1);
18
19 SPDLOG_LOGGER_INFO(mSLog, "Create {} {}", this->type(), name);
20
21 // Create electrical sub components
22 mSubVoltageSource =
23 std::make_shared<DP::Ph3::VoltageSource>(**mName + "_vs", mLogLevel);
24 addMNASubComponent(mSubVoltageSource,
27 SPDLOG_LOGGER_INFO(mSLog, "Electrical subcomponents: ");
28 for (auto subcomp : mSubComponents)
29 SPDLOG_LOGGER_INFO(mSLog, "- {}", subcomp->name());
30
31 mSubVoltageSource->mVoltageRef->setReference(mVoltageRef);
32 mSubVoltageSource->mSrcFreq->setReference(mSrcFreq);
33}
34
40
42 Real srcFreq) {
43 mParametersSet = true;
44
45 mSubVoltageSource->setParameters(voltageRef, srcFreq);
46
47 SPDLOG_LOGGER_INFO(mSLog,
48 "\nVoltage Ref={:s} [V]"
49 "\nFrequency={:s} [Hz]",
51 Logger::realToString(srcFreq));
52}
53
55 Real frequency) {
56 // Connect electrical subcomponents
57 mSubVoltageSource->connect({SimNode::GND, node(0)});
58}
59
60// #### MNA functions ####
62 Matrix &rightVector) {
63 SPDLOG_LOGGER_DEBUG(mSLog, "Right Side Vector: {:s}",
64 Logger::matrixToString(rightVector));
65}
66
68 AttributeBase::List &prevStepDependencies,
69 AttributeBase::List &attributeDependencies,
70 AttributeBase::List &modifiedAttributes) {
71 prevStepDependencies.push_back(mIntfCurrent);
72 prevStepDependencies.push_back(mIntfVoltage);
73 modifiedAttributes.push_back(mRightVector);
74}
75
79
81 AttributeBase::List &prevStepDependencies,
82 AttributeBase::List &attributeDependencies,
83 AttributeBase::List &modifiedAttributes,
84 Attribute<Matrix>::Ptr &leftVector) {
85 attributeDependencies.push_back(leftVector);
86 modifiedAttributes.push_back(mIntfVoltage);
87 modifiedAttributes.push_back(mIntfCurrent);
88}
89
91 Real time, Int timeStepCount, Attribute<Matrix>::Ptr &leftVector) {
92 mnaCompUpdateCurrent(**leftVector);
93 mnaCompUpdateVoltage(**leftVector);
94}
95
97 **mIntfVoltage = **mSubVoltageSource->mIntfVoltage;
98}
99
101 **mIntfCurrent = **mSubVoltageSource->mIntfCurrent;
102}
std::vector< Ptr > List
Definition Attribute.h:123
AttributePointer< Attribute< T > > Ptr
Definition Attribute.h:250
void addMNASubComponent(typename SimPowerComp< Complex >::Ptr subc, MNA_SUBCOMP_TASK_ORDER preStepOrder, MNA_SUBCOMP_TASK_ORDER postStepOrder, Bool contributeToRightVector)
void mnaCompApplyRightSideVectorStamp(Matrix &rightVector) override
CompositePowerComp(String uid, String name, Bool hasPreStep, Bool hasPostStep, Logger::Level logLevel)
NetworkInjection(String uid, String name, Logger::Level loglevel=Logger::Level::off)
Defines UID, name, component parameters and logging level.
void mnaParentAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector) override
Add MNA post step dependencies.
void mnaParentPreStep(Real time, Int timeStepCount) override
MNA pre step operations.
void mnaParentApplyRightSideVectorStamp(Matrix &rightVector) override
Stamps right side (source) vector.
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 mnaParentAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes) override
Add MNA pre step dependencies.
void initializeParentFromNodesAndTerminals(Real frequency) override
Initializes component from power flow data.
const CPS::Attribute< MatrixComp >::Ptr mVoltageRef
void mnaCompUpdateCurrent(const Matrix &leftVector) override
Returns current through the component.
void setParameters(MatrixComp voltageRef, Real srcFreq=0.0)
Setter for reference voltage parameters.
void mnaCompUpdateVoltage(const Matrix &leftVector) override
Updates voltage across component.
void mnaParentPostStep(Real time, Int timeStepCount, Attribute< Matrix >::Ptr &leftVector) override
MNA post step operations.
const CPS::Attribute< Real >::Ptr mSrcFreq
const Attribute< String >::Ptr mName
Human readable name.
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 matrixCompToString(const MatrixComp &mat)
Definition Logger.cpp:37
static String matrixToString(const Matrix &mat)
Definition Logger.cpp:31
static String realToString(const Real &num)
Definition Logger.cpp:69
Attribute< Matrix >::Ptr mRightVector
const Attribute< MatrixVar< Complex > >::Ptr mIntfCurrent
SimNode< Complex >::Ptr node(UInt index)
const Attribute< MatrixVar< Complex > >::Ptr mIntfVoltage
std::shared_ptr< SimPowerComp< VarType > > Ptr
std::vector< std::shared_ptr< SimPowerComp< Complex > > > mSubComponents
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< NetworkInjection > 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
Eigen::Matrix< Complex, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor > MatrixComp
Dense matrix for complex numbers.
Definition Definitions.h:84