DPsim
Loading...
Searching...
No Matches
EMT_Ph3_SynchronGeneratorIdeal.cpp
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
9#include <dpsim-models/EMT/EMT_Ph3_SynchronGeneratorIdeal.h>
10
11using namespace CPS;
12
14 String uid, String name, Logger::Level logLevel,
15 CPS::GeneratorType sourceType)
16 : CompositePowerComp<Real>(uid, name, true, true, logLevel),
17 mRefVoltage(mAttributes->createDynamic<MatrixComp>("V_ref")) {
18 mPhaseType = PhaseType::ABC;
19 mSourceType = sourceType;
20
21 if (mSourceType == CPS::GeneratorType::IdealVoltageSource)
22 setVirtualNodeNumber(1);
23 else
24 setVirtualNodeNumber(0);
25
26 setTerminalNumber(1);
27 **mIntfVoltage = Matrix::Zero(3, 1);
28 **mIntfCurrent = Matrix::Zero(3, 1);
29}
30
32 Logger::Level logLevel)
33 : SynchronGeneratorIdeal(name, name, logLevel) {}
34
35SimPowerComp<Real>::Ptr EMT::Ph3::SynchronGeneratorIdeal::clone(String name) {
36 return SynchronGeneratorIdeal::make(name, mLogLevel);
37}
38
40 Real frequency) {
41
42 if (mSourceType == CPS::GeneratorType::IdealVoltageSource) {
43 mSubVoltageSource =
44 EMT::Ph3::VoltageSource::make(**mName + "_vs", mLogLevel);
45 addMNASubComponent(mSubVoltageSource,
46 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
47 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT, true);
48 } else {
49 mSubCurrentSource =
50 EMT::Ph3::CurrentSource::make(**mName + "_cs", mLogLevel);
51 addMNASubComponent(mSubCurrentSource,
52 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
53 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT, true);
54 }
55
56 mSubComponents[0]->connect({SimNode::GND, node(0)});
57
58 if (mSourceType == CPS::GeneratorType::IdealVoltageSource)
59 mSubComponents[0]->setVirtualNodeAt(mVirtualNodes[0], 0);
60
61 if (mSourceType == CPS::GeneratorType::IdealCurrentSource)
62 mSubComponents[0]->setTerminalAt(terminal(0), 1);
63
64 mSubComponents[0]->initialize(mFrequencies);
65 mSubComponents[0]->initializeFromNodesAndTerminals(frequency);
66
67 if (mSourceType == CPS::GeneratorType::IdealVoltageSource)
68 mRefVoltage->setReference(
70
71 SPDLOG_LOGGER_INFO(mSLog,
72 "\n--- Initialization from powerflow ---"
73 "\nTerminal 0 voltage: {:s}"
74 "\nTerminal 0 power: {:s}"
75 "\n--- Initialization from powerflow finished ---",
76 Logger::phasorToString(initialSingleVoltage(0)),
77 Logger::complexToString(terminal(0)->singlePower()));
78}
79
81 AttributeBase::List &prevStepDependencies,
82 AttributeBase::List &attributeDependencies,
83 AttributeBase::List &modifiedAttributes) {
84 prevStepDependencies.push_back(mIntfCurrent);
85 prevStepDependencies.push_back(mIntfVoltage);
86 modifiedAttributes.push_back(mRightVector);
87}
88
93
95 AttributeBase::List &prevStepDependencies,
96 AttributeBase::List &attributeDependencies,
97 AttributeBase::List &modifiedAttributes,
98 Attribute<Matrix>::Ptr &leftVector) {
99 attributeDependencies.push_back(leftVector);
100 modifiedAttributes.push_back(mIntfVoltage);
101 modifiedAttributes.push_back(mIntfCurrent);
102}
103
105 Real time, Int timeStepCount, Attribute<Matrix>::Ptr &leftVector) {
106 mnaCompUpdateCurrent(**leftVector);
107 mnaCompUpdateVoltage(**leftVector);
108}
109
111 const Matrix &leftvector) {
112 **mIntfCurrent = **mSubComponents[0]->mIntfCurrent;
113}
114
116 const Matrix &leftVector) {
117 **mIntfVoltage = **mSubComponents[0]->mIntfVoltage;
118}
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 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 initializeFromNodesAndTerminals(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.
Attribute< Matrix >::Ptr mRightVector
const Attribute< MatrixVar< Real > >::Ptr mIntfCurrent
SimNode< Real >::Ptr node(UInt index)
SimTerminal< Real >::Ptr terminal(UInt index)
const Attribute< MatrixVar< Real > >::Ptr mIntfVoltage
SimNode< Real >::List mVirtualNodes
std::vector< std::shared_ptr< SimPowerComp< Real > > > mSubComponents
Logger::Level mLogLevel
Component logger control for internal variables.
Logger::Log mSLog
Component logger.