DPsim
Loading...
Searching...
No Matches
EMT_Ph3_SynchronGeneratorIdeal.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 CPS::GeneratorType sourceType)
16 : CompositePowerComp<Real>(uid, name, true, true, logLevel),
17 mRefVoltage(mAttributes->createDynamic<MatrixComp>("V_ref")) {
19 mSourceType = sourceType;
20
23 else
25
27 **mIntfVoltage = Matrix::Zero(3, 1);
28 **mIntfCurrent = Matrix::Zero(3, 1);
29}
30
34
38
41 return;
42 mSubCompCreated = true;
43
44 if (mSourceType == CPS::GeneratorType::IdealVoltageSource) {
45 mSubVoltageSource =
47 addMNASubComponent(mSubVoltageSource,
50 } else {
51 mSubCurrentSource =
53 addMNASubComponent(mSubCurrentSource,
56 }
57
58 mSubComponents[0]->connect({SimNode::GND, node(0)});
59
61 mSubComponents[0]->setVirtualNodeAt(mVirtualNodes[0], 0);
62
64 mSubComponents[0]->setTerminalAt(terminal(0), 1);
65
67 mRefVoltage->setReference(
69}
70
72 Real frequency) {
73 SPDLOG_LOGGER_INFO(mSLog,
74 "\n--- Initialization from powerflow ---"
75 "\nTerminal 0 voltage: {:s}"
76 "\nTerminal 0 power: {:s}"
77 "\n--- Initialization from powerflow finished ---",
79 Logger::complexToString(terminal(0)->singlePower()));
80}
81
83 AttributeBase::List &prevStepDependencies,
84 AttributeBase::List &attributeDependencies,
85 AttributeBase::List &modifiedAttributes) {
86 prevStepDependencies.push_back(mIntfCurrent);
87 prevStepDependencies.push_back(mIntfVoltage);
88 modifiedAttributes.push_back(mRightVector);
89}
90
95
97 AttributeBase::List &prevStepDependencies,
98 AttributeBase::List &attributeDependencies,
99 AttributeBase::List &modifiedAttributes,
100 Attribute<Matrix>::Ptr &leftVector) {
101 attributeDependencies.push_back(leftVector);
102 modifiedAttributes.push_back(mIntfVoltage);
103 modifiedAttributes.push_back(mIntfCurrent);
104}
105
107 Real time, Int timeStepCount, Attribute<Matrix>::Ptr &leftVector) {
108 mnaCompUpdateCurrent(**leftVector);
109 mnaCompUpdateVoltage(**leftVector);
110}
111
113 const Matrix &leftvector) {
114 **mIntfCurrent = **mSubComponents[0]->mIntfCurrent;
115}
116
118 const Matrix &leftVector) {
119 **mIntfVoltage = **mSubComponents[0]->mIntfVoltage;
120}
std::vector< Ptr > List
Definition Attribute.h:123
AttributePointer< Attribute< T > > Ptr
Definition Attribute.h:250
void addMNASubComponent(typename SimPowerComp< Real >::Ptr subc, MNA_SUBCOMP_TASK_ORDER preStepOrder, MNA_SUBCOMP_TASK_ORDER postStepOrder, Bool contributeToRightVector)
void mnaCompApplyRightSideVectorStamp(Matrix &rightVector) override
CompositePowerComp(String uid, String name, Bool hasPreStep, Bool hasPostStep, Logger::Level logLevel)
void mnaCompUpdateCurrent(const Matrix &leftVector) override
Updates current through the component.
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 mnaParentAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector) override
Add MNA post step dependencies.
void mnaParentAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes) override
Add MNA pre step dependencies.
void mnaParentPreStep(Real time, Int timeStepCount) override
MNA pre step operations.
const Attribute< MatrixComp >::Ptr mRefVoltage
CHECK: Is this actually necessary? It is never read from within the component's code.
SynchronGeneratorIdeal(String uid, String name, Logger::Level logLevel=Logger::Level::off, CPS::GeneratorType sourceType=CPS::GeneratorType::IdealVoltageSource)
Defines UID, name, component parameters and logging level.
void createSubComponents() override
Constructs and registers MNA subcomponents; idempotent.
void mnaCompUpdateVoltage(const Matrix &leftVector) override
Updates voltage across component.
void mnaParentPostStep(Real time, Int timeStepCount, Attribute< Matrix >::Ptr &leftVector) override
MNA post step operations.
void initializeParentFromNodesAndTerminals(Real frequency) override
Initializes component from power flow data.
const Attribute< String >::Ptr mName
Human readable name.
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 complexToString(const Complex &num)
Definition Logger.cpp:63
static String phasorToString(const Complex &num)
Definition Logger.cpp:57
Attribute< Matrix >::Ptr mRightVector
static Ptr GND
Definition SimNode.h:35
const Attribute< MatrixVar< Real > >::Ptr mIntfCurrent
SimNode< Real >::Ptr node(UInt index)
SimTerminal< Real >::Ptr terminal(UInt index)
void setVirtualNodeNumber(UInt num)
const Attribute< MatrixVar< Real > >::Ptr mIntfVoltage
std::shared_ptr< SimPowerComp< VarType > > Ptr
SimNode< Real >::List mVirtualNodes
std::vector< std::shared_ptr< SimPowerComp< Real > > > mSubComponents
Complex initialSingleVoltage(UInt index)
void setTerminalNumber(UInt num)
Logger::Level mLogLevel
Component logger control for internal variables.
Logger::Log mSLog
Component logger.
static std::shared_ptr< SynchronGeneratorIdeal > 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
Eigen::Matrix< Complex, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor > MatrixComp
Dense matrix for complex numbers.
Definition Definitions.h:84
GeneratorType