DPsim
Loading...
Searching...
No Matches
DP_Ph1_SynchronGeneratorIdeal.cpp
Go to the documentation of this file.
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
11
12using namespace CPS;
13
17
19 Bool useSubcomponents,
20 Logger::Level logLevel)
21 : CompositePowerComp<Complex>(uid, name, true, true, logLevel),
22 mUseSubcomponents(useSubcomponents),
23 mVoltageRef(mAttributes->createDynamic<Complex>("V_ref")) {
26 **mIntfVoltage = MatrixComp::Zero(1, 1);
27 **mIntfCurrent = MatrixComp::Zero(1, 1);
28}
29
33
37
39 if (!mUseSubcomponents)
40 return;
42 return;
43 mSubCompCreated = true;
44
45 mSubVoltageSource = DP::Ph1::VoltageSource::make(**mName + "_src", mLogLevel);
46 mSubVoltageSource->mVoltageRef->setReference(mVoltageRef);
47 mSubVoltageSource->connect({SimNode::GND, node(0)});
48 // Alias the sub-source's virtual node to parent VN0 so the transformer row
49 // in the system matrix uses the same index.
50 mSubVoltageSource->setVirtualNodeAt(mVirtualNodes[0], 0);
51 addMNASubComponent(mSubVoltageSource,
54}
55
57 Real omega, Real timeStep, Attribute<Matrix>::Ptr leftVector) {
58 if (!mUseSubcomponents)
60}
61
63 SparseMatrixRow &systemMatrix) {
64 if (mUseSubcomponents)
65 return;
66 const UInt sourceCurrent = virtualNode(0)->matrixNodeIndex();
67 const UInt terminal = matrixNodeIndex(0);
68 for (UInt freq = 0; freq < mNumFreqs; ++freq) {
69 Math::setMatrixElement(systemMatrix, sourceCurrent, terminal,
70 Complex(1., 0.), mNumFreqs, freq);
71 Math::setMatrixElement(systemMatrix, terminal, sourceCurrent,
72 Complex(1., 0.), mNumFreqs, freq);
73 }
74}
75
77 Matrix &rightVector) {
78 if (!mUseSubcomponents)
81}
82
84 Real frequency) {
85 // This composite is an ideal voltage source whose positive terminal is
86 // connected directly to the PF bus. The child VoltageSource does not have
87 // enough terminal information to infer this reference after its virtual
88 // node is aliased, so transfer the bus phasor to the shared reference here.
89 // This keeps init_with_powerflow self-contained for the composite model.
91 (**mIntfVoltage)(0, 0) = **mVoltageRef;
92
93 SPDLOG_LOGGER_INFO(mSLog,
94 "\n--- Initialization from powerflow ---"
95 "\nVoltage across: {:s}"
96 "\nCurrent: {:s}"
97 "\nTerminal 0 voltage: {:s}"
98 "\n--- Initialization from powerflow finished ---",
102}
103
105 AttributeBase::List &prevStepDependencies,
106 AttributeBase::List &attributeDependencies,
107 AttributeBase::List &modifiedAttributes) {
108 prevStepDependencies.push_back(mIntfCurrent);
109 prevStepDependencies.push_back(mIntfVoltage);
110 modifiedAttributes.push_back(mRightVector);
111}
112
117
119 AttributeBase::List &prevStepDependencies,
120 AttributeBase::List &attributeDependencies,
121 AttributeBase::List &modifiedAttributes,
122 Attribute<Matrix>::Ptr &leftVector) {
123 attributeDependencies.push_back(leftVector);
124 modifiedAttributes.push_back(mIntfVoltage);
125 modifiedAttributes.push_back(mIntfCurrent);
126}
127
129 Real time, Int timeStepCount, Attribute<Matrix>::Ptr &leftVector) {
130 mnaCompUpdateCurrent(**leftVector);
131 mnaCompUpdateVoltage(**leftVector);
132}
133
135 const Matrix &leftvector) {
136 if (mUseSubcomponents)
137 **mIntfCurrent = **mSubComponents[0]->mIntfCurrent;
138 else
140 leftvector, virtualNode(0)->matrixNodeIndex(), mNumFreqs, 0);
141}
142
144 const Matrix &leftVector) {
145 if (mUseSubcomponents)
146 **mIntfVoltage = **mSubComponents[0]->mIntfVoltage;
147 else
149 leftVector, matrixNodeIndex(0), mNumFreqs, 0);
150}
std::vector< Ptr > List
Definition Attribute.h:123
AttributePointer< Attribute< T > > Ptr
Definition Attribute.h:249
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)
void mnaParentApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override
const Attribute< Complex >::Ptr mVoltageRef
True after createSubComponents() runs; prevents double-construction.
SynchronGeneratorIdeal(String uid, String name, Logger::Level logLevel=Logger::Level::off)
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 mnaParentAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes) override
Add MNA pre step dependencies.
void initializeParentFromNodesAndTerminals(Real frequency) override
Initializes component from power flow data.
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 mnaParentInitialize(Real omega, Real timeStep, Attribute< Matrix >::Ptr leftVector) override
void mnaParentApplyRightSideVectorStamp(Matrix &rightVector) override
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.
spdlog::level::level_enum Level
Definition Logger.h:33
static String phasorToString(const Complex &num)
Definition Logger.cpp:57
Attribute< Matrix >::Ptr mRightVector
static Complex complexFromVectorElement(const Matrix &mat, Matrix::Index row, Int maxFreq=1, Int freqIdx=0)
static void setVectorElement(Matrix &mat, Matrix::Index row, Complex value, Int maxFreq=1, Int freqIdx=0, Matrix::Index colOffset=0)
static void setMatrixElement(SparseMatrixRow &mat, Matrix::Index row, Matrix::Index column, Complex value, Int maxFreq=1, Int freqIdx=0)
UInt matrixNodeIndex(UInt nodeIndex)
const Attribute< MatrixVar< Complex > >::Ptr mIntfCurrent
SimNode< Complex >::Ptr node(UInt index)
SimTerminal< Complex >::Ptr terminal(UInt index)
const Attribute< MatrixVar< Complex > >::Ptr mIntfVoltage
SimNode< Complex >::Ptr virtualNode(UInt index)
std::shared_ptr< SimPowerComp< VarType > > Ptr
SimNode< Complex >::List mVirtualNodes
std::vector< std::shared_ptr< SimPowerComp< Complex > > > mSubComponents
Complex initialSingleVoltage(UInt index)
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:79
std::string String
Definition Definitions.h:63
double Real
Definition Definitions.h:60
int Int
Definition Definitions.h:59
std::complex< Real > Complex
Definition Definitions.h:61
bool Bool
Definition Definitions.h:62
unsigned int UInt
Definition Definitions.h:58
Eigen::SparseMatrix< Real, Eigen::RowMajor > SparseMatrixRow
Sparse matrix for real numbers (row major).
Definition Definitions.h:72