DPsim
Loading...
Searching...
No Matches
EMT_Ph3_ControlledCurrentSource.cpp
Go to the documentation of this file.
1/* Copyright 2017-2020 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
15 : MNASimPowerComp<Real>(uid, name, true, true, logLevel),
16 mCurrentRef(mAttributes->create<Matrix>("I_ref")) {
20 **mIntfVoltage = Matrix::Zero(3, 1);
21 **mIntfCurrent = Matrix::Zero(3, 1);
22}
28
30 **mCurrentRef = currentRef;
31 SPDLOG_LOGGER_INFO(mSLog, "\nCurrent reference phasor [I]: {:s}",
32 Logger::matrixCompToString(currentRef));
33 mParametersSet = true;
34}
35
37 Real frequency) {
38 SPDLOG_LOGGER_INFO(
39 mSLog, "\n--- Initialization from node voltages and terminal ---");
40 if (!mParametersSet) {
41 **mCurrentRef = Matrix::Zero(3, 1);
42
43 SPDLOG_LOGGER_INFO(mSLog,
44 "\nTerminal 0 voltage: {:s}"
45 "\nTerminal 1 voltage: {:s}"
46 "\nTerminal 0 power: {:s}"
47 "\nTerminal 1 power: {:s}",
50 Logger::complexToString(terminal(0)->singlePower()),
51 Logger::complexToString(terminal(1)->singlePower()));
52 } else {
53 SPDLOG_LOGGER_INFO(
54 mSLog,
55 "\nInitialization from node voltages and terminal omitted (parameter "
56 "already set)."
57 "\nReference voltage: {:s}",
59 }
60 SPDLOG_LOGGER_INFO(
61 mSLog, "\n--- Initialization from node voltages and terminal ---");
62 mSLog->flush();
63}
64
69
71 Matrix &rightVector) {
72 if (terminalNotGrounded(1)) {
73 Math::setVectorElement(rightVector, matrixNodeIndex(1, 0),
74 -(**mIntfCurrent)(0, 0));
75 Math::setVectorElement(rightVector, matrixNodeIndex(1, 1),
76 -(**mIntfCurrent)(1, 0));
77 Math::setVectorElement(rightVector, matrixNodeIndex(1, 2),
78 -(**mIntfCurrent)(2, 0));
79 }
80 if (terminalNotGrounded(0)) {
81 Math::setVectorElement(rightVector, matrixNodeIndex(0, 0),
82 (**mIntfCurrent)(0, 0));
83 Math::setVectorElement(rightVector, matrixNodeIndex(0, 1),
84 (**mIntfCurrent)(1, 0));
85 Math::setVectorElement(rightVector, matrixNodeIndex(0, 2),
86 (**mIntfCurrent)(2, 0));
87 }
88}
89
92
93 SPDLOG_LOGGER_DEBUG(mSLog, "\nUpdate current: {:s}",
95}
96
98 AttributeBase::List &prevStepDependencies,
99 AttributeBase::List &attributeDependencies,
100 AttributeBase::List &modifiedAttributes) {
101 attributeDependencies.push_back(mCurrentRef);
102 modifiedAttributes.push_back(mRightVector);
103 modifiedAttributes.push_back(mIntfVoltage);
104}
105
111
113 AttributeBase::List &prevStepDependencies,
114 AttributeBase::List &attributeDependencies,
115 AttributeBase::List &modifiedAttributes,
116 Attribute<Matrix>::Ptr &leftVector) {
117 attributeDependencies.push_back(leftVector);
118 modifiedAttributes.push_back(mIntfVoltage);
119};
120
122 Real time, Int timeStepCount, Attribute<Matrix>::Ptr &leftVector) {
123 mnaCompUpdateVoltage(**leftVector);
124}
125
127 const Matrix &leftVector) {
128 // v1 - v0
129 **mIntfVoltage = Matrix::Zero(3, 1);
130 if (terminalNotGrounded(1)) {
131 (**mIntfVoltage)(0, 0) =
133 (**mIntfVoltage)(1, 0) =
135 (**mIntfVoltage)(2, 0) =
137 }
138 if (terminalNotGrounded(0)) {
139 (**mIntfVoltage)(0, 0) =
140 (**mIntfVoltage)(0, 0) -
142 (**mIntfVoltage)(1, 0) =
143 (**mIntfVoltage)(1, 0) -
145 (**mIntfVoltage)(2, 0) =
146 (**mIntfVoltage)(2, 0) -
148 }
149}
std::vector< Ptr > List
Definition Attribute.h:123
AttributePointer< Attribute< T > > Ptr
Definition Attribute.h:250
void setParameters(Matrix currentRef)
Setter for reference current.
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 mnaCompPostStep(Real time, Int timeStepCount, Attribute< Matrix >::Ptr &leftVector) override
MNA post step operations.
void mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector) override
Add MNA post step dependencies.
void mnaCompPreStep(Real time, Int timeStepCount) override
MNA pre step operations.
void mnaCompInitialize(Real omega, Real timeStep, Attribute< Matrix >::Ptr leftVector) override
Initializes internal variables of the component.
void mnaCompAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes) override
Add MNA pre step dependencies.
void initializeFromNodesAndTerminals(Real frequency) override
Initializes component from power flow data.
void mnaCompUpdateVoltage(const Matrix &leftVector) override
Returns voltage through the component.
ControlledCurrentSource(String uid, String name, Logger::Level logLevel=Logger::Level::off)
Defines UID, name and logging level.
void mnaCompApplyRightSideVectorStamp(Matrix &rightVector) override
Stamps right side (source) vector.
Attribute< T >::Ptr attributeTyped(const String &name) const
Return pointer to an attribute.
String uid()
Returns unique id.
AttributeList::Ptr mAttributes
Attribute List.
spdlog::level::level_enum Level
Definition Logger.h:33
static String matrixCompToString(const MatrixComp &mat)
Definition Logger.cpp:37
static String complexToString(const Complex &num)
Definition Logger.cpp:63
static String matrixToString(const Matrix &mat)
Definition Logger.cpp:31
static String phasorToString(const Complex &num)
Definition Logger.cpp:57
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
UInt matrixNodeIndex(UInt nodeIndex)
const Attribute< MatrixVar< Real > >::Ptr mIntfCurrent
SimTerminal< Real >::Ptr terminal(UInt index)
void setVirtualNodeNumber(UInt num)
const Attribute< MatrixVar< Real > >::Ptr mIntfVoltage
std::shared_ptr< SimPowerComp< VarType > > Ptr
Bool terminalNotGrounded(UInt index)
Complex initialSingleVoltage(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.
Logger::Log mSLog
Component logger.
static std::shared_ptr< ControlledCurrentSource > make(Args &&...args)
Definition PtrFactory.h:19
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