DPsim
Loading...
Searching...
No Matches
EMT_Ph1_CurrentSource.cpp
Go to the documentation of this file.
1/* Copyright 2017-2021 Institute for Automation of Complex Power Systems,
2 * EONERC, RWTH Aachen University
3 *
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
7 *********************************************************************************/
8
10
11using namespace CPS;
12
14 Logger::Level logLevel)
15 : MNASimPowerComp<Real>(uid, name, true, true, logLevel),
16 mCurrentRef(mAttributes->create<Complex>("I_ref")),
17 mSrcFreq(mAttributes->create<Real>("f_src")) {
19 **mIntfVoltage = Matrix::Zero(1, 1);
20 **mIntfCurrent = Matrix::Zero(1, 1);
21}
22
25 copy->setParameters(**mCurrentRef, **mSrcFreq);
26 return copy;
27}
28
30 **mCurrentRef = currentRef;
31 **mSrcFreq = srcFreq;
32
33 mParametersSet = true;
34}
35
37 Real omega, Real timeStep, Attribute<Matrix>::Ptr leftVector) {
39 (**mIntfCurrent)(0, 0) =
41}
42
44 Matrix &rightVector) {
47 -(**mIntfCurrent)(0, 0));
48
51 (**mIntfCurrent)(0, 0));
52}
53
55 Complex currentRef = mCurrentRef->get();
56 Real srcFreq = mSrcFreq->get();
57 if (srcFreq > 0)
58 (**mIntfCurrent)(0, 0) =
59 Math::abs(currentRef) *
60 cos(time * 2. * PI * srcFreq + Math::phase(currentRef));
61 else
62 (**mIntfCurrent)(0, 0) = currentRef.real();
63}
64
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);
72}
73
78
80 AttributeBase::List &prevStepDependencies,
81 AttributeBase::List &attributeDependencies,
82 AttributeBase::List &modifiedAttributes,
83 Attribute<Matrix>::Ptr &leftVector) {
84 attributeDependencies.push_back(leftVector);
85 modifiedAttributes.push_back(mIntfVoltage);
86}
87
89 Real time, Int timeStepCount, Attribute<Matrix>::Ptr &leftVector) {
90 mnaCompUpdateVoltage(**leftVector);
91}
92
94 (**mIntfVoltage)(0, 0) = 0;
96 (**mIntfVoltage)(0, 0) =
99 (**mIntfVoltage)(0, 0) =
100 (**mIntfVoltage)(0, 0) -
102}
std::vector< Ptr > List
Definition Attribute.h:123
AttributePointer< Attribute< T > > Ptr
Definition Attribute.h:250
void mnaCompInitialize(Real omega, Real timeStep, Attribute< Matrix >::Ptr leftVector) override
Initializes internal variables of the component.
const Attribute< Real >::Ptr mSrcFreq
void mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector) override
Add MNA post step dependencies.
const Attribute< Complex >::Ptr mCurrentRef
void mnaCompAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes) override
Add MNA pre step dependencies.
void mnaCompUpdateVoltage(const Matrix &leftVector) override
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.
void mnaCompPreStep(Real time, Int timeStepCount) override
void setParameters(Complex currentRef, Real srcFreq=-1)
void mnaCompPostStep(Real time, Int timeStepCount, Attribute< Matrix >::Ptr &leftVector) override
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.
spdlog::level::level_enum Level
Definition Logger.h:33
MNASimPowerComp(String uid, String name, Bool hasPreStep, Bool hasPostStep, Logger::Level logLevel)
Attribute< Matrix >::Ptr mRightVector
static Real realFromVectorElement(const Matrix &mat, Matrix::Index row)
static void setVectorElement(Matrix &mat, Matrix::Index row, Complex value, Int maxFreq=1, Int freqIdx=0, Matrix::Index colOffset=0)
Definition MathUtils.cpp:73
static Real phase(Complex value)
Definition MathUtils.cpp:23
static Real abs(Complex value)
Definition MathUtils.cpp:27
UInt matrixNodeIndex(UInt nodeIndex)
const Attribute< MatrixVar< Real > >::Ptr mIntfCurrent
const Attribute< MatrixVar< Real > >::Ptr mIntfVoltage
std::shared_ptr< SimPowerComp< VarType > > Ptr
Bool terminalNotGrounded(UInt index)
void setTerminalNumber(UInt num)
Logger::Level mLogLevel
Component logger control for internal variables.
bool mParametersSet
Flag indicating that parameters are set via setParameters() function.
static std::shared_ptr< CurrentSource > make(Args &&...args)
Definition PtrFactory.h:19
#define PI
Definition Definitions.h:43
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