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/SP/SP_Ph1_Shunt.h>
10
11using namespace CPS;
12
13SP::Ph1::Shunt::Shunt(String uid, String name, Logger::Level logLevel)
14 : SimPowerComp<Complex>(uid, name, logLevel),
15 mConductance(mAttributes->create<Real>("G")),
16 mSusceptance(mAttributes->create<Real>("B")),
17 mConductancePerUnit(mAttributes->create<Real>("Gpu")),
18 mSusceptancePerUnit(mAttributes->create<Real>("Bpu")) {
19
20 SPDLOG_LOGGER_INFO(mSLog, "Create {} of type {}", this->type(), name);
21 setTerminalNumber(1);
22}
23
24void SP::Ph1::Shunt::setParameters(Real conductance, Real susceptance) {
25 **mConductance = conductance;
26 **mSusceptance = susceptance;
27 SPDLOG_LOGGER_INFO(mSLog, "Conductance={} [S] Susceptance={} [Ohm] ",
28 conductance, susceptance);
29 mParametersSet = true;
30}
31
32// #### Powerflow section ####
33void SP::Ph1::Shunt::setBaseVoltage(Real baseVoltage) {
34 mBaseVoltage = baseVoltage;
35}
36
38 Real baseOmega) {
39 SPDLOG_LOGGER_INFO(mSLog, "#### Calculate Per Unit Parameters for {}",
40 **mName);
41 SPDLOG_LOGGER_INFO(mSLog, "Base Power={} [VA] Base Omega={} [1/s]",
42 baseApparentPower, baseOmega);
43
44 auto baseImpedance = (mBaseVoltage * mBaseVoltage) / baseApparentPower;
45 auto baseAdmittance = 1.0 / baseImpedance;
46 SPDLOG_LOGGER_INFO(mSLog, "Base Voltage={} [V] Base Admittance={} [S]",
47 mBaseVoltage, baseAdmittance);
48
49 **mConductancePerUnit = **mConductance / baseAdmittance;
50 **mSusceptancePerUnit = **mSusceptance / baseAdmittance;
51 SPDLOG_LOGGER_INFO(mSLog, "Susceptance={} [pu] Conductance={} [pu]",
53};
54
56 int bus1 = this->matrixNodeIndex(0);
57 Complex Y_element = Complex(**mConductancePerUnit, **mSusceptancePerUnit);
58
59 if (std::isinf(Y_element.real()) || std::isinf(Y_element.imag())) {
60 std::cout << "Y:" << Y_element << std::endl;
61 std::stringstream ss;
62 ss << "Shunt>>" << this->name()
63 << ": infinite or nan values at node: " << bus1;
64 throw std::invalid_argument(ss.str());
65 }
66
67 //set the circuit matrix values
68 Y.coeffRef(bus1, bus1) += Y_element;
69 SPDLOG_LOGGER_INFO(mSLog, "#### Y matrix stamping: {}", Y_element);
70}
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.
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.