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);
28 void 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 ---",
51 Logger::phasorToString((**mIntfVoltage)(0, 0)),
52 Logger::phasorToString((**mIntfCurrent)(0, 0)),
53 Logger::phasorToString(initialSingleVoltage(0)),
54 Logger::phasorToString(initialSingleVoltage(1)));
57 void DP::Ph1::CurrentSource::mnaCompInitialize(
59 updateMatrixNodeIndices();
60 (**mIntfCurrent)(0, 0) = **mCurrentRef;
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);
72 void 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),
82 -(**mIntfCurrent)(0, 0));
83 if (terminalNotGrounded(1))
84 Math::setVectorElement(rightVector, matrixNodeIndex(1),
85 (**mIntfCurrent)(0, 0));
89 AttributeBase::List &prevStepDependencies,
90 AttributeBase::List &attributeDependencies,
91 AttributeBase::List &modifiedAttributes,
93 attributeDependencies.push_back(leftVector);
94 modifiedAttributes.push_back(mIntfVoltage);
97 void DP::Ph1::CurrentSource::mnaCompPostStep(
99 mnaCompUpdateVoltage(**leftVector);
102 void 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));
Dynamic phasor ideal current source.
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.
Base class for all MNA components that are transmitting power.
Base class for all components that are transmitting power.
const Attribute< MatrixVar< Complex > >::Ptr mIntfCurrent
Current through component.
const Attribute< MatrixVar< Complex > >::Ptr mIntfVoltage
Voltage between terminals.