Skip to content

Commit 8f55e94

Browse files
authored
Remove parts of generator model from BusPV (#7)
* Remove parts of generator model from BusPV.
1 parent 2ea954f commit 8f55e94

File tree

4 files changed

+38
-34
lines changed

4 files changed

+38
-34
lines changed

ComponentLib/Bus/BusPV.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ namespace ModelLib {
7474
*/
7575
template <class ScalarT, typename IdxT>
7676
BusPV<ScalarT, IdxT>::BusPV()
77-
: BaseBus<ScalarT, IdxT>(0), V_(0.0), theta0_(0.0), Pg_(0.0)
77+
: BaseBus<ScalarT, IdxT>(0), V_(0.0), theta0_(0.0)
7878
{
7979
//std::cout << "Create BusPV..." << std::endl;
8080
//std::cout << "Number of equations is " << size_ << std::endl;
@@ -83,9 +83,7 @@ BusPV<ScalarT, IdxT>::BusPV()
8383
}
8484

8585
/*!
86-
* @brief BusPV constructor.
87-
*
88-
* This constructor sets initial values for voltage and phase angle.
86+
* @brief Constructor for a PV bus
8987
*
9088
* @todo Arguments that should be passed to ModelEvaluatorImpl constructor:
9189
* - Number of equations = 1 (size_)
@@ -94,10 +92,10 @@ BusPV<ScalarT, IdxT>::BusPV()
9492
* - Number of optimization parameters = 0
9593
*/
9694
template <class ScalarT, typename IdxT>
97-
BusPV<ScalarT, IdxT>::BusPV(ScalarT V, ScalarT theta0, ScalarT Pg)
98-
: BaseBus<ScalarT, IdxT>(0), V_(V), theta0_(theta0), Pg_(Pg)
95+
BusPV<ScalarT, IdxT>::BusPV(ScalarT V, ScalarT theta0)
96+
: BaseBus<ScalarT, IdxT>(0), V_(V), theta0_(theta0)
9997
{
100-
//std::cout << "Create BusPV ..." << std::endl;
98+
//std::cout << "Create BusPV..." << std::endl;
10199
//std::cout << "Number of equations is " << size_ << std::endl;
102100

103101
size_ = 1;
@@ -171,8 +169,8 @@ template <class ScalarT, typename IdxT>
171169
int BusPV<ScalarT, IdxT>::evaluateResidual()
172170
{
173171
// std::cout << "Evaluating residual of a PV bus ...\n";
174-
P() = Pg_;
175-
Q() = 0.0;
172+
P() = 0.0; // <-- Residual P
173+
Q() = 0.0; // <-- Output Qg, the reactive power generator needs to supply
176174

177175
return 0;
178176
}

ComponentLib/Bus/BusPV.hpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ namespace ModelLib
9191
using BusData = GridKit::PowerSystemData::BusData<real_type, IdxT>;
9292

9393
BusPV();
94-
BusPV(ScalarT V, ScalarT theta0, ScalarT P);
94+
BusPV(ScalarT V, ScalarT theta0);
9595
BusPV(BusData& data);
9696
virtual ~BusPV();
9797

@@ -197,10 +197,9 @@ namespace ModelLib
197197
}
198198

199199
private:
200-
ScalarT V_;
201-
ScalarT theta0_; ///< Default initial value for phase
202-
ScalarT Pg_; ///< Generator injection
203-
ScalarT Q_;
200+
ScalarT V_; ///< Bus voltage magnitude
201+
ScalarT theta0_; ///< Default initial value for phase
202+
ScalarT Q_; ///< Reactive power that generator needs to provide
204203

205204
ScalarT VB_;
206205
ScalarT thetaB_;

ComponentLib/Generator/GeneratorPV.hpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,18 @@ namespace ModelLib
124124
return P_;
125125
}
126126

127+
/// @brief Reactive power excess on PV bus
128+
/// @return reference to negative PV generator reactive power
127129
virtual ScalarT& Q()
128130
{
129-
return bus_->Q();
131+
return (bus_->Q());
130132
}
131133

134+
/// @brief Reactive power excess on PV bus
135+
/// @return const reference to negative PV generator reactive power
132136
virtual const ScalarT& Q() const
133137
{
134-
return bus_->Q();
138+
return (bus_->Q());
135139
}
136140

137141
private:

Examples/Grid3Bus/Grid3BusSys.cpp

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ using namespace AnalysisManager;
140140
using namespace GridKit::Testing;
141141
using namespace GridKit::PowerSystemData;
142142

143+
constexpr double theta2_ref = -4.87979; // [deg]
144+
constexpr double V2_ref = 1.08281; // [p.u.]
145+
constexpr double theta3_ref = 1.46241; // [deg]
143146

144147
/**
145148
* Testing the monlithic case via the class MiniGrid
@@ -170,17 +173,17 @@ int monolithic_case()
170173
double V2 = model->V2();
171174
double th3 = model->th3() * 180.0/M_PI;
172175
std::cout << "Solution:\n";
173-
std::cout << " theta2 = " << th2 << " deg, expected = " << " -4.87979 deg\n";
174-
std::cout << " V2 = " << V2 << " p.u., expected = " << " 1.08281 p.u.\n";
175-
std::cout << " theta3 = " << th3 << " deg, expected = " << " 1.46241 deg\n\n";
176+
std::cout << " theta2 = " << th2 << " deg, expected = " << theta2_ref << " deg\n";
177+
std::cout << " V2 = " << V2 << " p.u., expected = " << V2_ref << " p.u.\n";
178+
std::cout << " theta3 = " << th3 << " deg, expected = " << theta3_ref << " deg\n\n";
176179

177180
// Print solver performance statistics
178181
kinsol->printFinalStats();
179182

180183
int retval1 = 0;
181-
retval1 += !isEqual(th2, -4.87979, 1e-4);
182-
retval1 += !isEqual(V2, 1.08281, 1e-4);
183-
retval1 += !isEqual(th3, 1.46241, 1e-4);
184+
retval1 += !isEqual(th2, theta2_ref, 1e-4);
185+
retval1 += !isEqual(V2, V2_ref , 1e-4);
186+
retval1 += !isEqual(th3, theta3_ref, 1e-4);
184187

185188
if(retval1 == 0)
186189
std::cout << "\nSuccess!\n\n\n";
@@ -232,17 +235,17 @@ int parser_case()
232235

233236

234237
std::cout << "Solution:\n";
235-
std::cout << " theta2 = " << th2 << " deg, expected = " << " -4.87979 deg\n";
236-
std::cout << " V2 = " << V2 << " p.u., expected = " << " 1.08281 p.u.\n";
237-
std::cout << " theta3 = " << th3 << " deg, expected = " << " 1.46241 deg\n\n";
238+
std::cout << " theta2 = " << th2 << " deg, expected = " << theta2_ref << " deg\n";
239+
std::cout << " V2 = " << V2 << " p.u., expected = " << V2_ref << " p.u.\n";
240+
std::cout << " theta3 = " << th3 << " deg, expected = " << theta3_ref << " deg\n\n";
238241

239242
// Print solver performance statistics
240243
kinsol->printFinalStats();
241244

242245
int retval2 = 0;
243-
retval2 += !isEqual(th2, -4.87979, 1e-4);
244-
retval2 += !isEqual(V2, 1.08281, 1e-4);
245-
retval2 += !isEqual(th3, 1.46241, 1e-4);
246+
retval2 += !isEqual(th2, theta2_ref, 1e-4);
247+
retval2 += !isEqual(V2, V2_ref , 1e-4);
248+
retval2 += !isEqual(th3, theta3_ref, 1e-4);
246249

247250
if(retval2 == 0)
248251
std::cout << "\nSuccess!\n\n\n";
@@ -355,17 +358,17 @@ int hardwired_case()
355358

356359

357360
std::cout << "Solution:\n";
358-
std::cout << " theta2 = " << th2 << " deg, expected = " << " -4.87979 deg\n";
359-
std::cout << " V2 = " << V2 << " p.u., expected = " << " 1.08281 p.u.\n";
360-
std::cout << " theta3 = " << th3 << " deg, expected = " << " 1.46241 deg\n\n";
361+
std::cout << " theta2 = " << th2 << " deg, expected = " << theta2_ref << " deg\n";
362+
std::cout << " V2 = " << V2 << " p.u., expected = " << V2_ref << " p.u.\n";
363+
std::cout << " theta3 = " << th3 << " deg, expected = " << theta3_ref << " deg\n\n";
361364

362365
// Print solver performance statistics
363366
kinsol->printFinalStats();
364367

365368
int retval2 = 0;
366-
retval2 += !isEqual(th2, -4.87979, 1e-4);
367-
retval2 += !isEqual(V2, 1.08281, 1e-4);
368-
retval2 += !isEqual(th3, 1.46241, 1e-4);
369+
retval2 += !isEqual(th2, theta2_ref, 1e-4);
370+
retval2 += !isEqual(V2, V2_ref , 1e-4);
371+
retval2 += !isEqual(th3, theta3_ref, 1e-4);
369372

370373
if(retval2 == 0)
371374
std::cout << "\nSuccess!\n\n\n";

0 commit comments

Comments
 (0)