9 #include <dpsim-models/EMT/EMT_Ph1_CurrentSource.h>
14 Logger::Level logLevel)
16 mCurrentRef(mAttributes->create<Complex>(
"I_ref")),
17 mSrcFreq(mAttributes->create<Real>(
"f_src")) {
24 auto copy = CurrentSource::make(name, mLogLevel);
25 copy->setParameters(**mCurrentRef, **mSrcFreq);
29 void EMT::Ph1::CurrentSource::setParameters(Complex currentRef, Real srcFreq) {
30 **mCurrentRef = currentRef;
33 mParametersSet =
true;
38 updateMatrixNodeIndices();
39 (**mIntfCurrent)(0, 0) =
40 Math::abs(**mCurrentRef) * cos(Math::phase(**mCurrentRef));
44 Matrix &rightVector) {
45 if (terminalNotGrounded(0))
46 Math::setVectorElement(rightVector, matrixNodeIndex(0),
47 -(**mIntfCurrent)(0, 0));
49 if (terminalNotGrounded(1))
50 Math::setVectorElement(rightVector, matrixNodeIndex(1),
51 (**mIntfCurrent)(0, 0));
54 void EMT::Ph1::CurrentSource::updateState(Real time) {
55 Complex currentRef = mCurrentRef->get();
56 Real srcFreq = mSrcFreq->get();
58 (**mIntfCurrent)(0, 0) =
59 Math::abs(currentRef) *
60 cos(time * 2. * PI * srcFreq + Math::phase(currentRef));
62 (**mIntfCurrent)(0, 0) = currentRef.real();
66 AttributeBase::List &prevStepDependencies,
67 AttributeBase::List &attributeDependencies,
68 AttributeBase::List &modifiedAttributes) {
69 attributeDependencies.push_back(mCurrentRef);
70 modifiedAttributes.push_back(mRightVector);
71 modifiedAttributes.push_back(mIntfCurrent);
74 void EMT::Ph1::CurrentSource::mnaCompPreStep(Real time, Int timeStepCount) {
76 mnaCompApplyRightSideVectorStamp(**mRightVector);
80 AttributeBase::List &prevStepDependencies,
81 AttributeBase::List &attributeDependencies,
82 AttributeBase::List &modifiedAttributes,
84 attributeDependencies.push_back(leftVector);
85 modifiedAttributes.push_back(mIntfVoltage);
88 void EMT::Ph1::CurrentSource::mnaCompPostStep(
90 mnaCompUpdateVoltage(**leftVector);
93 void EMT::Ph1::CurrentSource::mnaCompUpdateVoltage(
const Matrix &leftVector) {
94 (**mIntfVoltage)(0, 0) = 0;
95 if (terminalNotGrounded(0))
96 (**mIntfVoltage)(0, 0) =
97 Math::realFromVectorElement(leftVector, matrixNodeIndex(0));
98 if (terminalNotGrounded(1))
99 (**mIntfVoltage)(0, 0) =
100 (**mIntfVoltage)(0, 0) -
101 Math::realFromVectorElement(leftVector, matrixNodeIndex(1));
void mnaCompInitialize(Real omega, Real timeStep, Attribute< Matrix >::Ptr leftVector) override
Initializes internal variables of the component.
void mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector) override
Add MNA post step dependencies.
void mnaCompAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes) override
Add MNA pre step dependencies.
void mnaCompApplyRightSideVectorStamp(Matrix &rightVector) override
Stamps right side (source) vector.
SimPowerComp< Real >::Ptr clone(String name) override
Returns a modified copy of the component with the given suffix added to the name and without.
CurrentSource(String uid, String name, Logger::Level logLevel=Logger::Level::off)
Defines UID, name and logging level.
Base class for all MNA components that are transmitting power.
Base class for all components that are transmitting power.
const Attribute< MatrixVar< Real > >::Ptr mIntfCurrent
Current through component.
const Attribute< MatrixVar< Real > >::Ptr mIntfVoltage
Voltage between terminals.