DPsim
Loading...
Searching...
No Matches
DP_Ph1_SynchronGeneratorIdeal.cpp
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
9#include <dpsim-models/DP/DP_Ph1_SynchronGeneratorIdeal.h>
10
11using namespace CPS;
12
14 Logger::Level logLevel)
15 : CompositePowerComp<Complex>(uid, name, true, true, logLevel),
16 mVoltageRef(mAttributes->createDynamic<Complex>("V_ref")) {
17 setVirtualNodeNumber(1);
18 setTerminalNumber(1);
19 **mIntfVoltage = MatrixComp::Zero(1, 1);
20 **mIntfCurrent = MatrixComp::Zero(1, 1);
21}
22
24 Logger::Level logLevel)
25 : SynchronGeneratorIdeal(name, name, logLevel) {}
26
27SimPowerComp<Complex>::Ptr DP::Ph1::SynchronGeneratorIdeal::clone(String name) {
28 return SynchronGeneratorIdeal::make(name, mLogLevel);
29}
30
32 Real frequency) {
33 mSubVoltageSource = DP::Ph1::VoltageSource::make(**mName + "_src", mLogLevel);
34 mSubVoltageSource->mVoltageRef->setReference(mVoltageRef);
35 mSubVoltageSource->connect({SimNode::GND, node(0)});
36 mSubVoltageSource->setVirtualNodeAt(mVirtualNodes[0], 0);
37 mSubVoltageSource->initialize(mFrequencies);
38 mSubVoltageSource->initializeFromNodesAndTerminals(frequency);
39 addMNASubComponent(mSubVoltageSource,
40 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
41 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT, true);
42
43 SPDLOG_LOGGER_INFO(mSLog,
44 "\n--- Initialization from powerflow ---"
45 "\nVoltage across: {:s}"
46 "\nCurrent: {:s}"
47 "\nTerminal 0 voltage: {:s}"
48 "\n--- Initialization from powerflow finished ---",
49 Logger::phasorToString((**mIntfVoltage)(0, 0)),
50 Logger::phasorToString((**mIntfCurrent)(0, 0)),
51 Logger::phasorToString(initialSingleVoltage(0)));
52}
53
55 AttributeBase::List &prevStepDependencies,
56 AttributeBase::List &attributeDependencies,
57 AttributeBase::List &modifiedAttributes) {
58 prevStepDependencies.push_back(mIntfCurrent);
59 prevStepDependencies.push_back(mIntfVoltage);
60 modifiedAttributes.push_back(mRightVector);
61}
62
67
69 AttributeBase::List &prevStepDependencies,
70 AttributeBase::List &attributeDependencies,
71 AttributeBase::List &modifiedAttributes,
72 Attribute<Matrix>::Ptr &leftVector) {
73 attributeDependencies.push_back(leftVector);
74 modifiedAttributes.push_back(mIntfVoltage);
75 modifiedAttributes.push_back(mIntfCurrent);
76}
77
79 Real time, Int timeStepCount, Attribute<Matrix>::Ptr &leftVector) {
80 mnaCompUpdateCurrent(**leftVector);
81 mnaCompUpdateVoltage(**leftVector);
82}
83
85 const Matrix &leftvector) {
86 **mIntfCurrent = **mSubComponents[0]->mIntfCurrent;
87}
88
90 const Matrix &leftVector) {
91 **mIntfVoltage = **mSubComponents[0]->mIntfVoltage;
92}
void addMNASubComponent(typename SimPowerComp< Complex >::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)
SynchronGeneratorIdeal(String uid, String name, Logger::Level logLevel=Logger::Level::off)
Defines UID, name, component parameters and logging level.
void initializeFromNodesAndTerminals(Real frequency) override
Initializes component from power flow data.
void mnaCompUpdateVoltage(const Matrix &leftVector) override
Updates voltage across component.
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.
SimPowerComp< Complex >::Ptr clone(String name) override
Returns a modified copy of the component with the given suffix added to the name and without.
void mnaParentPostStep(Real time, Int timeStepCount, Attribute< Matrix >::Ptr &leftVector) override
MNA post step operations.
void mnaParentAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector) override
Add MNA post step dependencies.
void mnaCompUpdateCurrent(const Matrix &leftVector) override
Updates current through the component.
const Attribute< String >::Ptr mName
Human readable name.
String uid()
Returns unique id.
AttributeList::Ptr mAttributes
Attribute List.
Attribute< Matrix >::Ptr mRightVector
const Attribute< MatrixVar< Complex > >::Ptr mIntfCurrent
SimNode< Complex >::Ptr node(UInt index)
const Attribute< MatrixVar< Complex > >::Ptr mIntfVoltage
SimNode< Complex >::List mVirtualNodes
std::vector< std::shared_ptr< SimPowerComp< Complex > > > mSubComponents
Logger::Level mLogLevel
Component logger control for internal variables.
Logger::Log mSLog
Component logger.