DPsim
Loading...
Searching...
No Matches
EMT_Ph3_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/EMT/EMT_Ph3_Shunt.h>
10
11using namespace CPS;
12
13EMT::Ph3::Shunt::Shunt(String uid, String name, Logger::Level logLevel)
14 : CompositePowerComp<Real>(uid, name, true, true, logLevel) {
15 mPhaseType = PhaseType::ABC;
16 mConductance = Matrix::Zero(3, 3);
17 mSusceptance = Matrix::Zero(3, 3);
18 SPDLOG_LOGGER_INFO(mSLog, "Create {} of type {}", this->type(), name);
19 setTerminalNumber(1);
20}
21
22void EMT::Ph3::Shunt::setParameters(Real conductance, Real susceptance) {
25}
26
27void EMT::Ph3::Shunt::setParameters(Matrix conductance, Matrix susceptance) {
28 mConductance = conductance;
29 mSusceptance = susceptance;
30 SPDLOG_LOGGER_INFO(mSLog, "Conductance={} [S] Susceptance={} [Ohm] ",
31 Logger::matrixToString(mConductance),
32 Logger::matrixToString(mSusceptance));
33 mParametersSet = true;
34}
35
38
39 // Static calculation
40 Real omega = 2. * PI * frequency;
41 MatrixComp admittance = Matrix::Zero(3, 3);
42 admittance << Complex(mConductance(0, 0), mSusceptance(0, 0)), 0, 0, 0,
43 Complex(mConductance(1, 1), mSusceptance(1, 1)), 0, 0, 0,
44 Complex(mConductance(2, 2), mSusceptance(2, 2));
45 MatrixComp vInitABC = MatrixComp::Zero(3, 1);
46 vInitABC(0, 0) = RMS3PH_TO_PEAK1PH * mTerminals[0]->initialSingleVoltage();
47 vInitABC(1, 0) = vInitABC(0, 0) * SHIFT_TO_PHASE_B;
48 vInitABC(2, 0) = vInitABC(0, 0) * SHIFT_TO_PHASE_C;
49 **mIntfVoltage = vInitABC.real();
50 **mIntfCurrent = (admittance * vInitABC).real();
51
52 // Create series rl sub component
53 if (mConductance(0, 0) > 0) {
54 mSubResistor =
55 std::make_shared<EMT::Ph3::Resistor>(**mName + "_Res", mLogLevel);
56 mSubResistor->connect({SimNode::GND, mTerminals[0]->node()});
57 mSubResistor->setParameters(mConductance.inverse());
58 mSubResistor->initialize(mFrequencies);
59 mSubResistor->initializeFromNodesAndTerminals(frequency);
60 addMNASubComponent(mSubResistor, MNA_SUBCOMP_TASK_ORDER::NO_TASK,
61 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT, false);
62 }
63
64 if (mSusceptance(0, 0) > 0) {
65 mSubCapacitor =
66 std::make_shared<EMT::Ph3::Capacitor>(**mName + "_cap", mLogLevel);
67 mSubCapacitor->setParameters(mSusceptance * (1 / omega));
68 mSubCapacitor->connect({SimNode::GND, mTerminals[0]->node()});
69 mSubCapacitor->initialize(mFrequencies);
70 mSubCapacitor->initializeFromNodesAndTerminals(frequency);
71 addMNASubComponent(mSubCapacitor,
72 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT,
73 MNA_SUBCOMP_TASK_ORDER::TASK_BEFORE_PARENT, true);
74 }
75
76 SPDLOG_LOGGER_INFO(mSLog,
77 "\n--- Initialization from powerflow ---"
78 "\nVoltage across: {:s}"
79 "\nCurrent: {:s}"
80 "\nTerminal voltage: {:s}"
81 "\n--- Initialization from powerflow finished ---",
82 Logger::phasorToString((**mIntfVoltage)(0, 0)),
83 Logger::phasorToString((**mIntfCurrent)(0, 0)),
84 Logger::phasorToString(initialSingleVoltage(0)));
85}
86
88 AttributeBase::List &prevStepDependencies,
89 AttributeBase::List &attributeDependencies,
90 AttributeBase::List &modifiedAttributes) {
91 modifiedAttributes.push_back(mRightVector);
92}
93
97
99 AttributeBase::List &prevStepDependencies,
100 AttributeBase::List &attributeDependencies,
101 AttributeBase::List &modifiedAttributes,
102 Attribute<Matrix>::Ptr &leftVector) {
103 attributeDependencies.push_back(leftVector);
104 modifiedAttributes.push_back(mIntfVoltage);
105 modifiedAttributes.push_back(mIntfCurrent);
106}
107
108void EMT::Ph3::Shunt::mnaParentPostStep(Real time, Int timeStepCount,
109 Attribute<Matrix>::Ptr &leftVector) {
110 this->mnaUpdateVoltage(**leftVector);
111 this->mnaUpdateCurrent(**leftVector);
112}
113
114void EMT::Ph3::Shunt::mnaCompUpdateVoltage(const Matrix &leftVector) {
115 (**mIntfVoltage)(0, 0) =
116 Math::realFromVectorElement(leftVector, matrixNodeIndex(0, 0));
117 (**mIntfVoltage)(1, 0) =
118 Math::realFromVectorElement(leftVector, matrixNodeIndex(0, 1));
119 (**mIntfVoltage)(2, 0) =
120 Math::realFromVectorElement(leftVector, matrixNodeIndex(0, 2));
121}
122
123void EMT::Ph3::Shunt::mnaCompUpdateCurrent(const Matrix &leftVector) {
124 **mIntfCurrent = Matrix::Zero(3, 1);
125
126 if (mConductance(0, 0) > 0)
127 **mIntfCurrent += mSubResistor->intfCurrent();
128 if (mSusceptance(0, 0) > 0)
129 **mIntfCurrent += mSubCapacitor->intfCurrent();
130}
void addMNASubComponent(typename SimPowerComp< Real >::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 mnaParentPostStep(Real time, Int timeStepCount, Attribute< Matrix >::Ptr &leftVector) final
MNA post-step operations.
void mnaCompUpdateVoltage(const Matrix &leftVector) final
Updates internal voltage variable of the component.
void mnaParentPreStep(Real time, Int timeStepCount) final
MNA pre 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
void initializeParentFromNodesAndTerminals(Real frequency) final
Initializes component from power flow data.
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.
void mnaCompUpdateCurrent(const Matrix &leftVector) final
Updates internal current variable of the component.
const Attribute< String >::Ptr mName
Human readable name.
String uid()
Returns unique id.
String type()
Get component type (cross-platform)
void mnaUpdateCurrent(const Matrix &leftVector) final
void mnaUpdateVoltage(const Matrix &leftVector) final
Attribute< Matrix >::Ptr mRightVector
static Matrix singlePhaseParameterToThreePhase(Real parameter)
To convert single phase parameters to symmetrical three phase ones.
const Attribute< MatrixVar< Real > >::Ptr mIntfCurrent
SimTerminal< Real >::List mTerminals
const Attribute< MatrixVar< Real > >::Ptr mIntfVoltage
Logger::Level mLogLevel
Component logger control for internal variables.
Logger::Log mSLog
Component logger.