9#include <dpsim-models/DP/DP_Ph1_CurrentSource.h>
14 Logger::Level logLevel)
16 mCurrentRef(
mAttributes->createDynamic<Complex>(
"I_ref")) {
23 Logger::Level logLevel)
25 setParameters(current);
28void DP::Ph1::CurrentSource::setParameters(Complex current) {
29 **mCurrentRef = current;
30 mParametersSet =
true;
34 auto copy = CurrentSource::make(name,
mLogLevel);
35 copy->setParameters(**mCurrentRef);
41 (**mIntfVoltage)(0, 0) = initialSingleVoltage(0) - initialSingleVoltage(1);
42 (**mIntfCurrent)(0, 0) = **mCurrentRef;
44 SPDLOG_LOGGER_INFO(
mSLog,
45 "\n--- Initialization from powerflow ---"
46 "\nVoltage across: {:s}"
48 "\nTerminal 0 voltage: {:s}"
49 "\nTerminal 1 voltage: {:s}"
50 "\n--- Initialization from powerflow finished ---",
53 Logger::phasorToString(initialSingleVoltage(0)),
54 Logger::phasorToString(initialSingleVoltage(1)));
57void DP::Ph1::CurrentSource::mnaCompInitialize(
58 Real omega, Real timeStep, Attribute<Matrix>::Ptr leftVector) {
59 updateMatrixNodeIndices();
60 (**mIntfCurrent)(0, 0) = **mCurrentRef;
64 AttributeBase::List &prevStepDependencies,
65 AttributeBase::List &attributeDependencies,
66 AttributeBase::List &modifiedAttributes) {
67 attributeDependencies.push_back(mCurrentRef);
72void DP::Ph1::CurrentSource::mnaCompPreStep(Real time, Int timeStepCount) {
73 mnaCompApplyRightSideVectorStamp(**mRightVector);
77 Matrix &rightVector) {
78 (**mIntfCurrent)(0, 0) = **mCurrentRef;
80 if (terminalNotGrounded(0))
81 Math::setVectorElement(rightVector, matrixNodeIndex(0),
83 if (terminalNotGrounded(1))
84 Math::setVectorElement(rightVector, matrixNodeIndex(1),
89 AttributeBase::List &prevStepDependencies,
90 AttributeBase::List &attributeDependencies,
91 AttributeBase::List &modifiedAttributes,
92 Attribute<Matrix>::Ptr &leftVector) {
93 attributeDependencies.push_back(leftVector);
97void DP::Ph1::CurrentSource::mnaCompPostStep(
98 Real time, Int timeStepCount, Attribute<Matrix>::Ptr &leftVector) {
99 mnaCompUpdateVoltage(**leftVector);
102void DP::Ph1::CurrentSource::mnaCompUpdateVoltage(
const Matrix &leftVector) {
103 (**mIntfVoltage)(0, 0) = 0;
104 if (terminalNotGrounded(0))
105 (**mIntfVoltage)(0, 0) =
106 Math::complexFromVectorElement(leftVector, matrixNodeIndex(0));
107 if (terminalNotGrounded(1))
108 (**mIntfVoltage)(0, 0) =
109 (**mIntfVoltage)(0, 0) -
110 Math::complexFromVectorElement(leftVector, matrixNodeIndex(1));
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.
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 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.
MNASimPowerComp(String uid, String name, Bool hasPreStep, Bool hasPostStep, Logger::Level logLevel)
Attribute< Matrix >::Ptr mRightVector
const Attribute< MatrixVar< Complex > >::Ptr mIntfCurrent
const Attribute< MatrixVar< Complex > >::Ptr mIntfVoltage
Logger::Level mLogLevel
Component logger control for internal variables.
Logger::Log mSLog
Component logger.