DPsim
SP_Ph1_SolidStateTransformer.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_SolidStateTransformer.h>
10 
11 using namespace CPS;
12 
13 SP::Ph1::SolidStateTransformer::SolidStateTransformer(String uid, String name,
14  Logger::Level logLevel)
15  : CompositePowerComp<Complex>(uid, name, false, false, logLevel),
16  mPref(mAttributes->create<Real>("P_ref",
17  std::numeric_limits<double>::infinity())),
18  mQ1ref(mAttributes->create<Real>("Q1_ref")),
19  mQ2ref(mAttributes->create<Real>("Q2_ref")) {
20  SPDLOG_LOGGER_INFO(mSLog, "Create {} of type {}", **mName, this->type());
21  mSLog->flush();
22  **mIntfVoltage = MatrixComp::Zero(1, 1);
23  **mIntfCurrent = MatrixComp::Zero(1, 1);
24  setTerminalNumber(2);
25 };
26 
27 SimPowerComp<Complex>::Ptr SP::Ph1::SolidStateTransformer::clone(String name) {
28  // everything set by initializeFromNodesAndTerminals
29  return SolidStateTransformer::make(name, mLogLevel);
30 }
31 
32 void SP::Ph1::SolidStateTransformer::setParameters(Real nomV1, Real nomV2,
33  Real Pref, Real Q1ref,
34  Real Q2ref) {
35  mNominalVoltageEnd1 = nomV1;
36  mNominalVoltageEnd2 = nomV2;
37  **mPref = Pref;
38  **mQ1ref = Q1ref;
39  **mQ2ref = Q2ref;
40  mP2 = -1 * std::sqrt(Pref * Pref + Q1ref * Q1ref - Q2ref * Q2ref);
41 }
42 
44  Real frequency) {
45 
46  if (std::isinf(mP2)) {
47  std::stringstream ss;
48  ss << "SST >>" << this->name()
49  << ": infinite or nan values. Or initialized before setting parameters.";
50  throw std::invalid_argument(ss.str());
51  }
52  if ((**mPref * mP2) > 0) {
53  throw std::invalid_argument(
54  "power at primary and secondary sides should be opposite");
55  }
56  mSubLoadSide1 = Load::make(**mName + "_subLoad1", mLogLevel);
57  mSubLoadSide1->setParameters(**mPref, **mQ1ref, mNominalVoltageEnd1);
58  mSubLoadSide2 = Load::make(**mName + "_subLoad2", mLogLevel);
59  mSubLoadSide2->setParameters(mP2, **mQ2ref, mNominalVoltageEnd2);
60  mSubLoadSide1->connect({mTerminals[0]->node()});
61  mSubLoadSide2->connect({mTerminals[1]->node()});
62 
63  addMNASubComponent(mSubLoadSide1, MNA_SUBCOMP_TASK_ORDER::NO_TASK,
64  MNA_SUBCOMP_TASK_ORDER::NO_TASK, false);
65  addMNASubComponent(mSubLoadSide2, MNA_SUBCOMP_TASK_ORDER::NO_TASK,
66  MNA_SUBCOMP_TASK_ORDER::NO_TASK, false);
67 
68  SPDLOG_LOGGER_INFO(mSLog,
69  "\n--- Initialization from powerflow ---"
70  "\nTerminal 0 power flow: {:s} VA"
71  "\nTerminal 1 power flow: {:s} VA"
72  "\n--- Initialization from powerflow finished ---",
73  Logger::complexToString(Complex(**mPref, **mQ1ref)),
74  Logger::complexToString(Complex(mP2, **mQ2ref)));
75 }
76 
77 void SP::Ph1::SolidStateTransformer::calculatePerUnitParameters(
78  Real baseApparentPower, Real baseOmega) {
79  mPref_perUnit = **mPref / baseApparentPower;
80  mP2_perUnit = mP2 / baseApparentPower;
81  mQ1ref_perUnit = **mQ1ref / baseApparentPower;
82  mQ2ref_perUnit = **mQ2ref / baseApparentPower;
83  mSubLoadSide1->calculatePerUnitParameters(baseApparentPower, baseOmega);
84  mSubLoadSide2->calculatePerUnitParameters(baseApparentPower, baseOmega);
85  SPDLOG_LOGGER_INFO(
86  mSLog,
87  "\n#### Calculate Per Unit Parameters for {}"
88  "\nTerminal 0 power flow: {:s} p.u."
89  "\nTerminal 1 power flow: {:s} p.u."
90  "\n#### Calculate Per Unit Parameters finished ---",
91  **mName, Logger::complexToString(Complex(mPref_perUnit, mQ1ref_perUnit)),
92  Logger::complexToString(Complex(mP2_perUnit, mQ2ref_perUnit)));
93 }
94 
95 Complex SP::Ph1::SolidStateTransformer::getNodalInjection(
96  CPS::TopologicalNode::Ptr node) {
97  if (node->name() == mTerminals[0]->node()->name()) {
98  SPDLOG_LOGGER_INFO(
99  mSLog,
100  "\n#### get nodal injection for primary side"
101  "\nreturned {:s} p.u.",
102  Logger::complexToString(Complex(mPref_perUnit, mQ1ref_perUnit)));
103  return Complex(mPref_perUnit, mQ1ref_perUnit);
104  } else if (node->name() == mTerminals[1]->node()->name()) {
105  SPDLOG_LOGGER_INFO(
106  mSLog,
107  "\n#### get nodal injection for secondary side"
108  "\nreturned {:s} p.u.",
109  Logger::complexToString(Complex(mP2_perUnit, mQ2ref_perUnit)));
110  return Complex(mP2_perUnit, mQ2ref_perUnit);
111  } else {
112  throw std::invalid_argument(
113  "Failed to process nodal power injection of Solid State Transformer" +
114  this->name());
115  }
116 }
Base class for composite power components.
void initializeFromNodesAndTerminals(Real frequency)
Initializes component.
Base class for all components that are transmitting power.
Definition: SimPowerComp.h:17
Logger::Level mLogLevel
Component logger control for internal variables.