DPsim
Loading...
Searching...
No Matches
DP_Ph1_RXLoadSwitch.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 Logger::Level logLevel)
15 : CompositePowerComp<Complex>(uid, name, true, true, logLevel) {
18 **mIntfVoltage = MatrixComp::Zero(1, 1);
19 **mIntfCurrent = MatrixComp::Zero(1, 1);
20
21 // Create sub components
23 std::make_shared<DP::Ph1::RXLoad>(**mName + "_rxload", mLogLevel);
25 std::make_shared<DP::Ph1::Switch>(**mName + "_switch", mLogLevel);
30 // Set switch default values
31 mSubSwitch->setParameters(1e9, 1e-9, true);
32}
33
36
38
40 Real frequency) {
41
42 if (!mParametersSet) {
43 // use powerflow results
44 mSubRXLoad->setParameters(mTerminals[0]->singleActivePower(),
45 mTerminals[0]->singleReactivePower(),
46 std::abs(mTerminals[0]->initialSingleVoltage()));
47 }
48
49 mSubRXLoad->connect({virtualNode(0)});
50 mSubRXLoad->initializeFromNodesAndTerminals(frequency);
51
52 mSubSwitch->connect({node(0)});
53 mSubSwitch->initializeFromNodesAndTerminals(frequency);
54
55 **mIntfVoltage = **mSubRXLoad->mIntfVoltage;
56 **mIntfCurrent = **mSubRXLoad->mIntfCurrent;
57
58 SPDLOG_LOGGER_INFO(mSLog,
59 "\n--- Initialization from powerflow ---"
60 "\nVoltage across: {:s}"
61 "\nCurrent: {:s}"
62 "\nTerminal 0 voltage: {:s}"
63 "\n--- Initialization from powerflow finished ---",
67}
68
69void DP::Ph1::RXLoadSwitch::setParameters(Real activePower, Real reactivePower,
70 Real nomVolt, Real openResistance,
71 Real closedResistance, Bool closed) {
72 mParametersSet = true;
73 mSubRXLoad->setParameters(activePower, reactivePower, nomVolt);
74 mSubSwitch->setParameters(openResistance, closedResistance, closed);
75}
76
78 Real closedResistance,
79 Bool closed) {
80 mSubSwitch->setParameters(openResistance, closedResistance, closed);
81}
82
84 Bool closed, SparseMatrixRow &systemMatrix, Int freqIdx) {
85 mSubRXLoad->mnaApplySystemMatrixStamp(systemMatrix);
86 mSubSwitch->mnaCompApplySwitchSystemMatrixStamp(closed, systemMatrix,
87 freqIdx);
88}
89
91 AttributeBase::List &prevStepDependencies,
92 AttributeBase::List &attributeDependencies,
93 AttributeBase::List &modifiedAttributes) {
94 prevStepDependencies.push_back(mIntfCurrent);
95 prevStepDependencies.push_back(mIntfVoltage);
96 modifiedAttributes.push_back(mRightVector);
97}
98
103
105 AttributeBase::List &prevStepDependencies,
106 AttributeBase::List &attributeDependencies,
107 AttributeBase::List &modifiedAttributes,
108 Attribute<Matrix>::Ptr &leftVector) {
109 attributeDependencies.push_back(leftVector);
110 modifiedAttributes.push_back(mIntfVoltage);
111 modifiedAttributes.push_back(mIntfCurrent);
112}
113
115 Real time, Int timeStepCount, Attribute<Matrix>::Ptr &leftVector) {
116 **mIntfVoltage = **mSubRXLoad->mIntfVoltage;
117 **mIntfCurrent = **mSubRXLoad->mIntfCurrent;
118}
119
121
122 if (time > mSwitchTimeOffset && mSubSwitch->isClosed()) {
123 Real VRef = Math::abs(**mSubRXLoad->mNomVoltage);
124 Real V = Math::abs((**mIntfVoltage)(0, 0));
125
126 Real deltaV = Math::abs((V - VRef) / VRef);
127
128 if (deltaV > 0.1) {
129 mSubSwitch->open();
130 SPDLOG_LOGGER_INFO(mSLog, "Opened Switch at {}", (float)time);
131 }
132 }
133}
134
136 return mSubSwitch->hasParameterChanged();
137};
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)
void updateSwitchState(Real time)
built-in logic for protection switch
void initializeParentFromNodesAndTerminals(Real frequency) override
Derives values from power flow data and pushes them to subcomponents.
void setParameters(Real activePower, Real reactivePower, Real nomVolt, Real openResistance, Real closedResistance, Bool closed=false)
Sets model specific parameters.
Real mSwitchTimeOffset
internal switch is only opened after this time offset
void mnaCompApplySwitchSystemMatrixStamp(Bool closed, SparseMatrixRow &systemMatrix, Int freqIdx) override
Stamps system matrix considering the defined switch position.
void setSwitchParameters(Real openResistance, Real closedResistance, Bool closed=false)
Sets only switch parameters so that load parameters could be calculated from powerflow.
RXLoadSwitch(String uid, String name, Logger::Level logLevel=Logger::Level::off)
Defines UID, name and logging level.
void mnaParentAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes) override
Add MNA pre step dependencies.
void mnaParentAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector) override
Add MNA post step dependencies.
Bool mnaIsClosed() override
Check if switch is closed.
Bool hasParameterChanged() override
Returns true if one of the element paramters has changed.
void mnaParentPreStep(Real time, Int timeStepCount) override
MNA pre step operations.
void mnaParentPostStep(Real time, Int timeStepCount, Attribute< Matrix >::Ptr &leftVector) override
MNA post step operations.
std::shared_ptr< DP::Ph1::RXLoad > mSubRXLoad
Internal RXLoad.
std::shared_ptr< DP::Ph1::Switch > mSubSwitch
Internal protection switch.
const Attribute< String >::Ptr mName
Human readable name.
String uid()
Returns unique id.
spdlog::level::level_enum Level
Definition Logger.h:33
static String phasorToString(const Complex &num)
Definition Logger.cpp:57
Attribute< Matrix >::Ptr mRightVector
static Real abs(Complex value)
Definition MathUtils.cpp:27
const Attribute< MatrixVar< Complex > >::Ptr mIntfCurrent
SimTerminal< Complex >::List mTerminals
SimNode< Complex >::Ptr node(UInt index)
const Attribute< MatrixVar< Complex > >::Ptr mIntfVoltage
SimNode< Complex >::Ptr virtualNode(UInt index)
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.
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
bool Bool
Definition Definitions.h:64
Eigen::SparseMatrix< Real, Eigen::RowMajor > SparseMatrixRow
Sparse matrix for real numbers (row major).
Definition Definitions.h:74