DPsim
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 
11 using namespace CPS;
12 
13 SP::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 
24 void 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 ####
33 void SP::Ph1::Shunt::setBaseVoltage(Real baseVoltage) {
34  mBaseVoltage = baseVoltage;
35 }
36 
37 void SP::Ph1::Shunt::calculatePerUnitParameters(Real baseApparentPower,
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]",
52  **mSusceptancePerUnit, **mConductancePerUnit);
53 };
54 
55 void SP::Ph1::Shunt::pfApplyAdmittanceMatrixStamp(SparseMatrixCompRow &Y) {
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 }
String type()
Get component type (cross-platform)
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.
void calculatePerUnitParameters(Real baseApparentPower, Real baseOmega)
Initializes component from power flow data.
void setParameters(Real conductance, Real susceptance)
Set shunt specific parameters.
Base class for all components that are transmitting power.
Definition: SimPowerComp.h:17
Logger::Log mSLog
Component logger.