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
41 return;
42 mSubCompCreated = true;
43
44 if (mSourceType == CPS::GeneratorType::IdealVoltageSource) {
45 mSubVoltageSource =
46 EMT::Ph3::VoltageSource::make(**mName + "_vs", mLogLevel);
47 addMNASubComponent(mSubVoltageSource,
48 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
49 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT, true);
50 } else {
51 mSubCurrentSource =
52 EMT::Ph3::CurrentSource::make(**mName + "_cs", mLogLevel);
53 addMNASubComponent(mSubCurrentSource,
54 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
55 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT, true);
56 }
57
58 mSubComponents[0]->connect({SimNode::GND, node(0)});
59
60 if (mSourceType == CPS::GeneratorType::IdealVoltageSource)
61 mSubComponents[0]->setVirtualNodeAt(mVirtualNodes[0], 0);
62
63 if (mSourceType == CPS::GeneratorType::IdealCurrentSource)
64 mSubComponents[0]->setTerminalAt(terminal(0), 1);
65
66 mSubComponents[0]->initialize(mFrequencies);
67
68 if (mSourceType == CPS::GeneratorType::IdealVoltageSource)
69 mRefVoltage->setReference(
71}
72
74 Real frequency) {
75 SPDLOG_LOGGER_INFO(mSLog,
76 "\n--- Initialization from powerflow ---"
77 "\nTerminal 0 voltage: {:s}"
78 "\nTerminal 0 power: {:s}"
79 "\n--- Initialization from powerflow finished ---",
80 Logger::phasorToString(initialSingleVoltage(0)),
81 Logger::complexToString(terminal(0)->singlePower()));
82}
83
85 AttributeBase::List &prevStepDependencies,
86 AttributeBase::List &attributeDependencies,
87 AttributeBase::List &modifiedAttributes) {
88 prevStepDependencies.push_back(mIntfCurrent);
89 prevStepDependencies.push_back(mIntfVoltage);
90 modifiedAttributes.push_back(mRightVector);
91}
92
97
99 AttributeBase::List &prevStepDependencies,
100 AttributeBase::List &attributeDependencies,
101 AttributeBase::List &modifiedAttributes,
102 Attribute<Matrix>::Ptr &leftVector) {
103 attributeDependencies.push_back(leftVector);
104 modifiedAttributes.push_back(mIntfVoltage);
105 modifiedAttributes.push_back(mIntfCurrent);
106}
107
109 Real time, Int timeStepCount, Attribute<Matrix>::Ptr &leftVector) {
110 mnaCompUpdateCurrent(**leftVector);
111 mnaCompUpdateVoltage(**leftVector);
112}
113
115 const Matrix &leftvector) {
116 **mIntfCurrent = **mSubComponents[0]->mIntfCurrent;
117}
118
120 const Matrix &leftVector) {
121 **mIntfVoltage = **mSubComponents[0]->mIntfVoltage;
122}
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.
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.