DPsim
Exciter.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/Signal/Exciter.h>
11 
12 using namespace CPS;
13 
14 Signal::Exciter::Exciter(const String &name, CPS::Logger::Level logLevel)
15  : SimSignalComp(name, name, logLevel),
16  mVm(mAttributes->create<Real>("Vm", 0)),
17  mVh(mAttributes->create<Real>("Vh", 0)),
18  mVis(mAttributes->create<Real>("Vis", 0)),
19  mVse(mAttributes->create<Real>("Vse", 0)),
20  mVr(mAttributes->create<Real>("Vr", 0)),
21  mEf(mAttributes->create<Real>("Ef", 0)) {}
22 
23 void Signal::Exciter::setParameters(Real Ta, Real Ka, Real Te, Real Ke, Real Tf,
24  Real Kf, Real Tr, Real maxVr, Real minVr) {
25  mTa = Ta;
26  mKa = Ka;
27  mTe = Te;
28  mKe = Ke;
29  mTf = Tf;
30  mKf = Kf;
31  mTr = Tr;
32  mMaxVr = maxVr;
33  mMinVr = minVr;
34 
35  SPDLOG_LOGGER_INFO(mSLog,
36  "Exciter parameters: \n"
37  "Ta: {:e}"
38  "\nKa: {:e}"
39  "\nTe: {:e}"
40  "\nKe: {:e}"
41  "\nTf: {:e}"
42  "\nKf: {:e}"
43  "\nTr: {:e}"
44  "\nMaximum regulator Voltage: {:e}"
45  "\nMinimum regulator Voltage: {:e}\n",
46  mTa, mKa, mTe, mKe, mTf, mKf, mTr, mMaxVr, mMinVr);
47 }
48 
49 void Signal::Exciter::initialize(Real Vh_init, Real Ef_init) {
50 
51  SPDLOG_LOGGER_INFO(mSLog,
52  "Initially set excitation system initial values: \n"
53  "Vh_init: {:e}\nEf_init: {:e}\n",
54  Vh_init, Ef_init);
55 
56  **mVm = Vh_init;
57  **mEf = Ef_init;
58 
59  // mVse is the ceiling function in PSAT
60  // mVse = mEf * (0.33 * (exp(0.1 * abs(mEf)) - 1.));
61  **mVse = **mEf * (0.33 * exp(0.1 * abs(**mEf)));
62 
63  // mVis = vr2 in PSAT
64  **mVis = -mKf / mTf * **mEf;
65 
66  // mVr = vr1 in PSAT
67  **mVr = mKe * **mEf + **mVse;
68  if (**mVr > mMaxVr)
69  **mVr = mMaxVr;
70  else if (**mVr < mMinVr)
71  **mVr = mMinVr;
72 
73  mVref = **mVr / mKa + **mVm;
74  SPDLOG_LOGGER_INFO(mSLog,
75  "Actually applied excitation system initial values:"
76  "\nVref : {:e}"
77  "\ninit_Vm: {:e}"
78  "\ninit_Ef: {:e}"
79  "\ninit_Vc: {:e}"
80  "\ninit_Vr: {:e}"
81  "\ninit_Vr2: {:e}",
82  mVref, **mVm, **mEf, **mVse, **mVr, **mVis);
83 }
84 
85 Real Signal::Exciter::step(Real mVd, Real mVq, Real dt) {
86  // Voltage magnitude calculation
87  **mVh = sqrt(pow(mVd, 2.) + pow(mVq, 2.));
88 
89  // update state variables at time k-1
90  mVm_prev = **mVm;
91  mVis_prev = **mVis;
92  mVr_prev = **mVr;
93  mEf_prev = **mEf;
94 
95  // compute state variables at time k using euler forward
96 
97  // Voltage Transducer equation
98  **mVm = Math::StateSpaceEuler(mVm_prev, -1 / mTr, 1 / mTr, dt, **mVh);
99 
100  // Stabilizing feedback equation
101  // mVse = mEf * (0.33 * (exp(0.1 * abs(mEf)) - 1.));
102  **mVse = mEf_prev * (0.33 * exp(0.1 * abs(mEf_prev)));
103  **mVis = Math::StateSpaceEuler(mVis_prev, -1 / mTf, -mKf / mTf / mTf, dt,
104  mEf_prev);
105 
106  // Voltage regulator equation
107  **mVr =
108  Math::StateSpaceEuler(mVr_prev, -1 / mTa, mKa / mTa, dt,
109  mVref - **mVm - mVis_prev - mKf / mTf * mEf_prev);
110  if (**mVr > mMaxVr)
111  **mVr = mMaxVr;
112  else if (**mVr < mMinVr)
113  **mVr = mMinVr;
114 
115  // Exciter equation
116  **mEf = Math::StateSpaceEuler(mEf_prev, -mKe / mTe, 1. / mTe, dt,
117  mVr_prev - **mVse);
118 
119  return **mEf;
120 }
121 
122 /*
123 // Saturation function according to Viviane thesis
124 Real Signal::Exciter::saturation_fcn1(Real mVd, Real mVq, Real Vref, Real dt) {
125  if (mEf <= 2.3)
126  mVse = (0.1 / 2.3)*mEf;
127  else
128  mVse = (0.33 / 3.1)*mEf;
129  mVse = mVse*mEf;
130 }
131 
132 // Saturation function according to PSAT
133 Real Signal::Exciter::saturation_fcn2() {
134  return mA * (exp(mB * abs(mEf)) - 1);
135 }
136 
137 */
void setParameters(Real Ta, Real Ka, Real Te, Real Ke, Real Tf, Real Kf, Real Tr, Real maxVr=1.0, Real minVr=-0.9)
Initializes exciter parameters.
Definition: Exciter.cpp:23
Real step(Real mVd, Real mVq, Real dt)
Performs an step to update field voltage value.
Definition: Exciter.cpp:85
void initialize(Real Vh_init, Real Vf_init)
Initializes exciter variables.
Definition: Exciter.cpp:49