9#include <dpsim-models/EMT/EMT_Ph1_CurrentSource.h>
14 Logger::Level logLevel)
24 auto copy = CurrentSource::make(name,
mLogLevel);
25 copy->setParameters(**mCurrentRef, **mSrcFreq);
29void EMT::Ph1::CurrentSource::setParameters(Complex currentRef, Real srcFreq) {
30 **mCurrentRef = currentRef;
33 mParametersSet =
true;
37 Real omega, Real timeStep, Attribute<Matrix>::Ptr leftVector) {
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),
49 if (terminalNotGrounded(1))
50 Math::setVectorElement(rightVector, matrixNodeIndex(1),
54void 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);
74void EMT::Ph1::CurrentSource::mnaCompPreStep(Real time, Int timeStepCount) {
76 mnaCompApplyRightSideVectorStamp(**mRightVector);
80 AttributeBase::List &prevStepDependencies,
81 AttributeBase::List &attributeDependencies,
82 AttributeBase::List &modifiedAttributes,
83 Attribute<Matrix>::Ptr &leftVector) {
84 attributeDependencies.push_back(leftVector);
88void EMT::Ph1::CurrentSource::mnaCompPostStep(
89 Real time, Int timeStepCount, Attribute<Matrix>::Ptr &leftVector) {
90 mnaCompUpdateVoltage(**leftVector);
93void 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.
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< Real > >::Ptr mIntfCurrent
const Attribute< MatrixVar< Real > >::Ptr mIntfVoltage
void updateMatrixNodeIndices()
Logger::Level mLogLevel
Component logger control for internal variables.