DPsim
Loading...
Searching...
No Matches
DP_Ph1_RXLoadSwitch.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_RXLoadSwitch.h>
10
11using namespace CPS;
12
14 Logger::Level logLevel)
15 : CompositePowerComp<Complex>(uid, name, true, true, logLevel) {
16 setTerminalNumber(1);
17 setVirtualNodeNumber(1);
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);
26 addMNASubComponent(mSubRXLoad, MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
27 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT, true);
28 addMNASubComponent(mSubSwitch, MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
29 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT, false);
30 // Set switch default values
31 mSubSwitch->setParameters(1e9, 1e-9, true);
32}
33
34DP::Ph1::RXLoadSwitch::RXLoadSwitch(String name, Logger::Level logLevel)
35 : RXLoadSwitch(name, name, logLevel) {}
36
37Bool DP::Ph1::RXLoadSwitch::mnaIsClosed() { return mSubSwitch->isClosed(); }
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->initialize(mFrequencies);
51 mSubRXLoad->initializeFromNodesAndTerminals(frequency);
52
53 mSubSwitch->connect({node(0)});
54 mSubSwitch->initialize(mFrequencies);
55 mSubSwitch->initializeFromNodesAndTerminals(frequency);
56
57 **mIntfVoltage = **mSubRXLoad->mIntfVoltage;
58 **mIntfCurrent = **mSubRXLoad->mIntfCurrent;
59
60 SPDLOG_LOGGER_INFO(mSLog,
61 "\n--- Initialization from powerflow ---"
62 "\nVoltage across: {:s}"
63 "\nCurrent: {:s}"
64 "\nTerminal 0 voltage: {:s}"
65 "\n--- Initialization from powerflow finished ---",
66 Logger::phasorToString((**mIntfVoltage)(0, 0)),
67 Logger::phasorToString((**mIntfCurrent)(0, 0)),
68 Logger::phasorToString(initialSingleVoltage(0)));
69}
70
71void DP::Ph1::RXLoadSwitch::setParameters(Real activePower, Real reactivePower,
72 Real nomVolt, Real openResistance,
73 Real closedResistance, Bool closed) {
74 mParametersSet = true;
75 mSubRXLoad->setParameters(activePower, reactivePower, nomVolt);
76 mSubSwitch->setParameters(openResistance, closedResistance, closed);
77}
78
80 Real closedResistance,
81 Bool closed) {
82 mSubSwitch->setParameters(openResistance, closedResistance, closed);
83}
84
86 Bool closed, SparseMatrixRow &systemMatrix, Int freqIdx) {
87 mSubRXLoad->mnaApplySystemMatrixStamp(systemMatrix);
88 mSubSwitch->mnaCompApplySwitchSystemMatrixStamp(closed, systemMatrix,
89 freqIdx);
90}
91
93 AttributeBase::List &prevStepDependencies,
94 AttributeBase::List &attributeDependencies,
95 AttributeBase::List &modifiedAttributes) {
96 prevStepDependencies.push_back(mIntfCurrent);
97 prevStepDependencies.push_back(mIntfVoltage);
98 modifiedAttributes.push_back(mRightVector);
99}
100
105
107 AttributeBase::List &prevStepDependencies,
108 AttributeBase::List &attributeDependencies,
109 AttributeBase::List &modifiedAttributes,
110 Attribute<Matrix>::Ptr &leftVector) {
111 attributeDependencies.push_back(leftVector);
112 modifiedAttributes.push_back(mIntfVoltage);
113 modifiedAttributes.push_back(mIntfCurrent);
114}
115
117 Real time, Int timeStepCount, Attribute<Matrix>::Ptr &leftVector) {
118 **mIntfVoltage = **mSubRXLoad->mIntfVoltage;
119 **mIntfCurrent = **mSubRXLoad->mIntfCurrent;
120}
121
123
124 if (time > mSwitchTimeOffset && mSubSwitch->isClosed()) {
125 Real VRef = Math::abs(**mSubRXLoad->mNomVoltage);
126 Real V = Math::abs((**mIntfVoltage)(0, 0));
127
128 Real deltaV = Math::abs((V - VRef) / VRef);
129
130 if (deltaV > 0.1) {
131 mSubSwitch->open();
132 SPDLOG_LOGGER_INFO(mSLog, "Opened Switch at {}", (float)time);
133 }
134 }
135}
136
138 return mSubSwitch->hasParameterChanged();
139};
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.
Attribute< Matrix >::Ptr mRightVector
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)
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.