DPsim
Loading...
Searching...
No Matches
SP_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/MathUtils.h>
10#include <dpsim-models/SP/SP_Ph1_Shunt.h>
11
12using namespace CPS;
13
14SP::Ph1::Shunt::Shunt(String uid, String name, Logger::Level logLevel)
15 : SimPowerComp<Complex>(uid, name, logLevel),
16 mConductance(mAttributes->create<Real>("G")),
17 mSusceptance(mAttributes->create<Real>("B")),
18 mConductancePerUnit(mAttributes->create<Real>("Gpu")),
19 mSusceptancePerUnit(mAttributes->create<Real>("Bpu")) {
20
21 SPDLOG_LOGGER_INFO(mSLog, "Create {} of type {}", this->type(), name);
22 setTerminalNumber(1);
23}
24
25void SP::Ph1::Shunt::setParameters(Real conductance, Real susceptance) {
26 **mConductance = conductance;
27 **mSusceptance = susceptance;
28 SPDLOG_LOGGER_INFO(mSLog, "Conductance={} [S] Susceptance={} [Ohm] ",
29 conductance, susceptance);
30 mParametersSet = true;
31}
32
33// #### Powerflow section ####
34Real SP::Ph1::Shunt::getBaseVoltage() const { return mBaseVoltage; }
35
36void SP::Ph1::Shunt::setBaseVoltage(Real baseVoltage) {
37 mBaseVoltage = baseVoltage;
38}
39
41 Real baseOmega) {
42 SPDLOG_LOGGER_INFO(mSLog, "#### Calculate Per Unit Parameters for {}",
43 **mName);
44 SPDLOG_LOGGER_INFO(mSLog, "Base Power={} [VA] Base Omega={} [1/s]",
45 baseApparentPower, baseOmega);
46
47 auto baseImpedance = (mBaseVoltage * mBaseVoltage) / baseApparentPower;
48 auto baseAdmittance = 1.0 / baseImpedance;
49 SPDLOG_LOGGER_INFO(mSLog, "Base Voltage={} [V] Base Admittance={} [S]",
50 mBaseVoltage, baseAdmittance);
51
52 **mConductancePerUnit = **mConductance / baseAdmittance;
53 **mSusceptancePerUnit = **mSusceptance / baseAdmittance;
54 SPDLOG_LOGGER_INFO(mSLog, "Susceptance={} [pu] Conductance={} [pu]",
56};
57
59 int bus1 = this->matrixNodeIndex(0);
60 Complex Y_element = Complex(**mConductancePerUnit, **mSusceptancePerUnit);
61
62 if (!Math::isFinite(Y_element)) {
63 SPDLOG_LOGGER_ERROR(mSLog,
64 "Shunt {}: non-finite per-unit admittance {} at "
65 "node {}",
66 this->name(), Logger::complexToString(Y_element), bus1);
68 }
69
70 //set the circuit matrix values
71 Y.coeffRef(bus1, bus1) += Y_element;
72 SPDLOG_LOGGER_INFO(mSLog, "#### Y matrix stamping: {}", Y_element);
73}
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.
const Attribute< Real >::Ptr mConductance
Conductance [S].
const Attribute< Real >::Ptr mSusceptance
Susceptance [S].
void setBaseVoltage(Real baseVoltage)
Set base voltage.
Real getBaseVoltage() const
Get base voltage.
void pfApplyAdmittanceMatrixStamp(SparseMatrixCompRow &Y)
Stamps admittance matrix.
Shunt(String uid, String name, Logger::Level logLevel=Logger::Level::off)
Defines UID, name, component parameters and logging level.
const Attribute< Real >::Ptr mSusceptancePerUnit
Susceptance [pu].
const Attribute< Real >::Ptr mConductancePerUnit
Conductance [pu].
void calculatePerUnitParameters(Real baseApparentPower, Real baseOmega)
Initializes component from power flow data.
void setParameters(Real conductance, Real susceptance)
Set shunt specific parameters.
SimPowerComp(String uid, String name, Logger::Level logLevel=Logger::Level::off)
bool mParametersSet
Flag indicating that parameters are set via setParameters() function.
Logger::Log mSLog
Component logger.