DPsim
Loading...
Searching...
No Matches
DP_Ph1_PQLoadCS.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
10
11using namespace CPS;
12
14 : CompositePowerComp<Complex>(uid, name, true, true, logLevel),
15 mActivePower(mAttributes->create<Real>("P", 0)),
16 mReactivePower(mAttributes->create<Real>("Q", 0)),
17 mNomVoltage(mAttributes->create<Real>("V_nom")) {
19 **mIntfVoltage = MatrixComp::Zero(1, 1);
20 **mIntfCurrent = MatrixComp::Zero(1, 1);
21}
22
24 Real reactivePower, Real nomVolt,
25 Logger::Level logLevel)
26 : PQLoadCS(uid, name, logLevel) {
27
28 setParameters(activePower, reactivePower, nomVolt);
29}
30
33
34DP::Ph1::PQLoadCS::PQLoadCS(String name, Real activePower, Real reactivePower,
35 Real nomVolt, Logger::Level logLevel)
36 : PQLoadCS(name, name, activePower, reactivePower, nomVolt, logLevel) {}
37
38void DP::Ph1::PQLoadCS::setParameters(Real activePower, Real reactivePower,
39 Real nomVolt) {
40 **mActivePower = activePower;
41 **mReactivePower = reactivePower;
42 **mNomVoltage = nomVolt;
43 mParametersSet = true;
44}
45
52
55 return;
56 mSubCompCreated = true;
57
59 std::make_shared<DP::Ph1::CurrentSource>(**mName + "_cs", mLogLevel);
60 // A positive power should result in a positive current to ground.
61 mSubCurrentSource->connect({mTerminals[0]->node(), SimNode::GND});
65}
66
68 // Read power from terminals here, not in createSubComponents(): power-flow results aren't available that early.
69 if (**mActivePower == 0 && **mReactivePower == 0 && !mParametersSet) {
70 **mActivePower = mTerminals[0]->singleActivePower();
71 **mReactivePower = mTerminals[0]->singleReactivePower();
73 }
75 Complex current =
76 (**mNomVoltage != 0) ? std::conj(power / **mNomVoltage) : Complex(0);
77 mSubCurrentSource->setParameters(current);
78
79 mSubCurrentSource->initializeFromNodesAndTerminals(frequency);
81
82 SPDLOG_LOGGER_INFO(mSLog,
83 "\n--- Initialization from powerflow ---"
84 "\nVoltage across: {:s}"
85 "\nCurrent: {:s}"
86 "\nTerminal 0 voltage: {:s}"
87 "\nCurrent set point: {:s}"
88 "\n--- Initialization from powerflow finished ---",
92 Logger::phasorToString(current));
93}
94
96 // Calculate new current set point.
97 Complex power = {**mActivePower, **mReactivePower};
98 Complex current = power / **mNomVoltage;
99 //Complex current = power / (**mIntfVoltage)(0,0);
100
101 **mSubCurrentSource->mCurrentRef = std::conj(current);
102 SPDLOG_LOGGER_DEBUG(mSLog,
103 "\n--- update set points ---"
104 "\npower: {:s}"
105 "\nCurrent: {:s}",
107 Logger::phasorToString(std::conj(current)));
108}
109
111 AttributeBase::List &prevStepDependencies,
112 AttributeBase::List &attributeDependencies,
113 AttributeBase::List &modifiedAttributes) {
114 attributeDependencies.push_back(mActivePower);
115 attributeDependencies.push_back(mReactivePower);
116 attributeDependencies.push_back(mNomVoltage);
117}
118
120 AttributeBase::List &prevStepDependencies,
121 AttributeBase::List &attributeDependencies,
122 AttributeBase::List &modifiedAttributes,
123 Attribute<Matrix>::Ptr &leftVector) {
124 modifiedAttributes.push_back(mIntfCurrent);
125 modifiedAttributes.push_back(mIntfVoltage);
126}
127
132
134 **mIntfCurrent = mSubCurrentSource->intfCurrent();
135 **mIntfVoltage = mSubCurrentSource->intfVoltage();
136}
137
139 Attribute<Matrix>::Ptr &leftVector) {
141}
std::vector< Ptr > List
Definition Attribute.h:123
AttributePointer< Attribute< T > > Ptr
Definition Attribute.h:250
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)
PQLoadCS(String uid, String name, Logger::Level logLevel=Logger::Level::off)
Defines UID, name and logging level.
void initializeParentFromNodesAndTerminals(Real frequency) override
Initializes component from power flow data.
void mnaParentAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes) override
void mnaParentPreStep(Real time, Int timeStepCount) override
MNA pre and post step operations.
void mnaParentPostStep(Real time, Int timeStepCount, Attribute< Matrix >::Ptr &leftVector) override
SimPowerComp< Complex >::Ptr clone(String name) override
DEPRECATED: Delete method.
void createSubComponents() override
Constructs and registers MNA subcomponents; idempotent.
void updateSetPoint()
True after createSubComponents() runs; prevents double-construction.
const Attribute< Real >::Ptr mActivePower
std::shared_ptr< DP::Ph1::CurrentSource > mSubCurrentSource
Internal current source.
void setParameters(Real activePower, Real reactivePower, Real nomVolt)
void mnaParentAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector) override
const Attribute< Real >::Ptr mReactivePower
const Attribute< Real >::Ptr mNomVoltage
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
const Attribute< MatrixVar< Complex > >::Ptr mIntfCurrent
SimTerminal< Complex >::List mTerminals
const Attribute< MatrixVar< Complex > >::Ptr mIntfVoltage
std::shared_ptr< SimPowerComp< VarType > > Ptr
Complex initialSingleVoltage(UInt index)
Logger::Level mLogLevel
Component logger control for internal variables.
bool mParametersSet
Flag indicating that parameters are set via setParameters() function.
Logger::Log mSLog
Component logger.
static std::shared_ptr< PQLoadCS > make(Args &&...args)
Definition PtrFactory.h:19
std::string String
Definition Definitions.h:65
double Real
Definition Definitions.h:62
int Int
Definition Definitions.h:61
std::complex< Real > Complex
Definition Definitions.h:63