DPsim
Loading...
Searching...
No Matches
DP_Ph1_Shunt.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_Shunt.h>
10
11using namespace CPS;
12
13DP::Ph1::Shunt::Shunt(String uid, String name, Logger::Level logLevel)
14 : CompositePowerComp<Complex>(uid, name, true, true, logLevel),
15 mConductance(mAttributes->create<Real>("G")),
16 mSusceptance(mAttributes->create<Real>("B")) {
17
18 SPDLOG_LOGGER_INFO(mSLog, "Create {} of type {}", this->type(), name);
19 setTerminalNumber(1);
20}
21
22void DP::Ph1::Shunt::setParameters(Real conductance, Real susceptance) {
23 **mConductance = conductance;
24 **mSusceptance = susceptance;
25 SPDLOG_LOGGER_INFO(mSLog, "Conductance={} [S] Susceptance={} [Ohm] ",
26 conductance, susceptance);
27 mParametersSet = true;
28}
29
32
33 // Static calculation
34 Real omega = 2. * PI * frequency;
35 Complex admittance = Complex(**mConductance, **mSusceptance);
36 (**mIntfVoltage)(0, 0) = initialSingleVoltage(0);
37 (**mIntfCurrent)(0, 0) = (**mIntfVoltage)(0, 0) * admittance;
38
39 // Create series rl sub component
40 if (**mConductance > 0) {
42 std::make_shared<DP::Ph1::Resistor>(**mName + "_Res", mLogLevel);
43 mSubResistor->connect(SimNode::List{SimNode::GND, mTerminals[0]->node()});
44 mSubResistor->setParameters(1. / **mConductance);
45 mSubResistor->initialize(mFrequencies);
46 mSubResistor->initializeFromNodesAndTerminals(frequency);
47 addMNASubComponent(mSubResistor, MNA_SUBCOMP_TASK_ORDER::NO_TASK,
48 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT, false);
49 }
50
51 if (**mSusceptance > 0) {
53 std::make_shared<DP::Ph1::Capacitor>(**mName + "_cap", mLogLevel);
54 mSubCapacitor->setParameters(**mSusceptance / omega);
55 mSubCapacitor->connect(SimNode::List{SimNode::GND, mTerminals[0]->node()});
56 mSubCapacitor->initialize(mFrequencies);
57 mSubCapacitor->initializeFromNodesAndTerminals(frequency);
59 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
60 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT, true);
61 }
62
63 SPDLOG_LOGGER_INFO(mSLog,
64 "\n--- Initialization from powerflow ---"
65 "\nVoltage across: {:s}"
66 "\nCurrent: {:s}"
67 "\nTerminal voltage: {:s}"
68 "\n--- Initialization from powerflow finished ---",
69 Logger::phasorToString((**mIntfVoltage)(0, 0)),
70 Logger::phasorToString((**mIntfCurrent)(0, 0)),
71 Logger::phasorToString(initialSingleVoltage(0)));
72}
73
75 AttributeBase::List &prevStepDependencies,
76 AttributeBase::List &attributeDependencies,
77 AttributeBase::List &modifiedAttributes) {
78 modifiedAttributes.push_back(mRightVector);
79}
80
84
86 AttributeBase::List &prevStepDependencies,
87 AttributeBase::List &attributeDependencies,
88 AttributeBase::List &modifiedAttributes,
89 Attribute<Matrix>::Ptr &leftVector) {
90 attributeDependencies.push_back(leftVector);
91 modifiedAttributes.push_back(mIntfVoltage);
92 modifiedAttributes.push_back(mIntfCurrent);
93}
94
95void DP::Ph1::Shunt::mnaParentPostStep(Real time, Int timeStepCount,
96 Attribute<Matrix>::Ptr &leftVector) {
97 this->mnaUpdateVoltage(**leftVector);
98 this->mnaUpdateCurrent(**leftVector);
99}
100
101void DP::Ph1::Shunt::mnaCompUpdateVoltage(const Matrix &leftVector) {
102 (**mIntfVoltage)(0, 0) =
103 Math::complexFromVectorElement(leftVector, matrixNodeIndex(0));
104}
105
106void DP::Ph1::Shunt::mnaCompUpdateCurrent(const Matrix &leftVector) {
107 (**mIntfCurrent)(0, 0) = 0;
108
109 if (**mConductance > 0)
110 (**mIntfCurrent)(0, 0) += mSubResistor->intfCurrent()(0, 0);
111 if (**mSusceptance > 0)
112 (**mIntfCurrent)(0, 0) += mSubCapacitor->intfCurrent()(0, 0);
113}
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 mnaCompUpdateCurrent(const Matrix &leftVector) final
Updates internal current variable of the component.
const Attribute< Real >::Ptr mConductance
Conductance [S].
void mnaParentPreStep(Real time, Int timeStepCount) final
MNA pre step operations.
const Attribute< Real >::Ptr mSusceptance
Susceptance [S].
void mnaCompUpdateVoltage(const Matrix &leftVector) final
Updates internal voltage variable of the component.
std::shared_ptr< Resistor > mSubResistor
Resistor between terminal and ground.
void setParameters(Real conductance, Real susceptance)
Set shunt specific parameters.
Shunt(String uid, String name, Logger::Level logLevel=Logger::Level::off)
Defines UID, name, component parameters and logging level.
std::shared_ptr< Capacitor > mSubCapacitor
Capacitor between terminal and ground.
void initializeParentFromNodesAndTerminals(Real frequency)
Initializes component from power flow data.
void mnaParentPostStep(Real time, Int timeStepCount, Attribute< Matrix >::Ptr &leftVector) final
MNA post-step operations.
void mnaParentAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes) final
Add MNA pre step dependencies.
void mnaParentAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector) final
add MNA post-step dependencies
const Attribute< String >::Ptr mName
Human readable name.
String uid()
Returns unique id.
String type()
Get component type (cross-platform)
AttributeList::Ptr mAttributes
Attribute List.
void mnaUpdateCurrent(const Matrix &leftVector) final
void mnaUpdateVoltage(const Matrix &leftVector) final
Attribute< Matrix >::Ptr mRightVector
const Attribute< MatrixVar< Complex > >::Ptr mIntfCurrent
SimTerminal< Complex >::List mTerminals
const Attribute< MatrixVar< Complex > >::Ptr mIntfVoltage
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.