Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions ComponentLib/Bus/BusPV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ namespace ModelLib {
*/
template <class ScalarT, typename IdxT>
BusPV<ScalarT, IdxT>::BusPV()
: BaseBus<ScalarT, IdxT>(0), V_(0.0), theta0_(0.0), Pg_(0.0)
: BaseBus<ScalarT, IdxT>(0), V_(0.0), theta0_(0.0)
{
//std::cout << "Create BusPV..." << std::endl;
//std::cout << "Number of equations is " << size_ << std::endl;
Expand All @@ -83,9 +83,7 @@ BusPV<ScalarT, IdxT>::BusPV()
}

/*!
* @brief BusPV constructor.
*
* This constructor sets initial values for voltage and phase angle.
* @brief Constructor for a PV bus
*
* @todo Arguments that should be passed to ModelEvaluatorImpl constructor:
* - Number of equations = 1 (size_)
Expand All @@ -94,10 +92,10 @@ BusPV<ScalarT, IdxT>::BusPV()
* - Number of optimization parameters = 0
*/
template <class ScalarT, typename IdxT>
BusPV<ScalarT, IdxT>::BusPV(ScalarT V, ScalarT theta0, ScalarT Pg)
: BaseBus<ScalarT, IdxT>(0), V_(V), theta0_(theta0), Pg_(Pg)
BusPV<ScalarT, IdxT>::BusPV(ScalarT V, ScalarT theta0)
: BaseBus<ScalarT, IdxT>(0), V_(V), theta0_(theta0)
{
//std::cout << "Create BusPV ..." << std::endl;
//std::cout << "Create BusPV..." << std::endl;
//std::cout << "Number of equations is " << size_ << std::endl;

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

return 0;
}
Expand Down
9 changes: 4 additions & 5 deletions ComponentLib/Bus/BusPV.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ namespace ModelLib
using BusData = GridKit::PowerSystemData::BusData<real_type, IdxT>;

BusPV();
BusPV(ScalarT V, ScalarT theta0, ScalarT P);
BusPV(ScalarT V, ScalarT theta0);
BusPV(BusData& data);
virtual ~BusPV();

Expand Down Expand Up @@ -197,10 +197,9 @@ namespace ModelLib
}

private:
ScalarT V_;
ScalarT theta0_; ///< Default initial value for phase
ScalarT Pg_; ///< Generator injection
ScalarT Q_;
ScalarT V_; ///< Bus voltage magnitude
ScalarT theta0_; ///< Default initial value for phase
ScalarT Q_; ///< Reactive power that generator needs to provide

ScalarT VB_;
ScalarT thetaB_;
Expand Down
8 changes: 6 additions & 2 deletions ComponentLib/Generator/GeneratorPV.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,18 @@ namespace ModelLib
return P_;
}

/// @brief Reactive power excess on PV bus
/// @return reference to negative PV generator reactive power
virtual ScalarT& Q()
{
return bus_->Q();
return (bus_->Q());
}

/// @brief Reactive power excess on PV bus
/// @return const reference to negative PV generator reactive power
virtual const ScalarT& Q() const
{
return bus_->Q();
return (bus_->Q());
}

private:
Expand Down
39 changes: 21 additions & 18 deletions Examples/Grid3Bus/Grid3BusSys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ using namespace AnalysisManager;
using namespace GridKit::Testing;
using namespace GridKit::PowerSystemData;

constexpr double theta2_ref = -4.87979; // [deg]
constexpr double V2_ref = 1.08281; // [p.u.]
constexpr double theta3_ref = 1.46241; // [deg]

/**
* Testing the monlithic case via the class MiniGrid
Expand Down Expand Up @@ -170,17 +173,17 @@ int monolithic_case()
double V2 = model->V2();
double th3 = model->th3() * 180.0/M_PI;
std::cout << "Solution:\n";
std::cout << " theta2 = " << th2 << " deg, expected = " << " -4.87979 deg\n";
std::cout << " V2 = " << V2 << " p.u., expected = " << " 1.08281 p.u.\n";
std::cout << " theta3 = " << th3 << " deg, expected = " << " 1.46241 deg\n\n";
std::cout << " theta2 = " << th2 << " deg, expected = " << theta2_ref << " deg\n";
std::cout << " V2 = " << V2 << " p.u., expected = " << V2_ref << " p.u.\n";
std::cout << " theta3 = " << th3 << " deg, expected = " << theta3_ref << " deg\n\n";

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

int retval1 = 0;
retval1 += !isEqual(th2, -4.87979, 1e-4);
retval1 += !isEqual(V2, 1.08281, 1e-4);
retval1 += !isEqual(th3, 1.46241, 1e-4);
retval1 += !isEqual(th2, theta2_ref, 1e-4);
retval1 += !isEqual(V2, V2_ref , 1e-4);
retval1 += !isEqual(th3, theta3_ref, 1e-4);

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


std::cout << "Solution:\n";
std::cout << " theta2 = " << th2 << " deg, expected = " << " -4.87979 deg\n";
std::cout << " V2 = " << V2 << " p.u., expected = " << " 1.08281 p.u.\n";
std::cout << " theta3 = " << th3 << " deg, expected = " << " 1.46241 deg\n\n";
std::cout << " theta2 = " << th2 << " deg, expected = " << theta2_ref << " deg\n";
std::cout << " V2 = " << V2 << " p.u., expected = " << V2_ref << " p.u.\n";
std::cout << " theta3 = " << th3 << " deg, expected = " << theta3_ref << " deg\n\n";

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

int retval2 = 0;
retval2 += !isEqual(th2, -4.87979, 1e-4);
retval2 += !isEqual(V2, 1.08281, 1e-4);
retval2 += !isEqual(th3, 1.46241, 1e-4);
retval2 += !isEqual(th2, theta2_ref, 1e-4);
retval2 += !isEqual(V2, V2_ref , 1e-4);
retval2 += !isEqual(th3, theta3_ref, 1e-4);

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


std::cout << "Solution:\n";
std::cout << " theta2 = " << th2 << " deg, expected = " << " -4.87979 deg\n";
std::cout << " V2 = " << V2 << " p.u., expected = " << " 1.08281 p.u.\n";
std::cout << " theta3 = " << th3 << " deg, expected = " << " 1.46241 deg\n\n";
std::cout << " theta2 = " << th2 << " deg, expected = " << theta2_ref << " deg\n";
std::cout << " V2 = " << V2 << " p.u., expected = " << V2_ref << " p.u.\n";
std::cout << " theta3 = " << th3 << " deg, expected = " << theta3_ref << " deg\n\n";

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

int retval2 = 0;
retval2 += !isEqual(th2, -4.87979, 1e-4);
retval2 += !isEqual(V2, 1.08281, 1e-4);
retval2 += !isEqual(th3, 1.46241, 1e-4);
retval2 += !isEqual(th2, theta2_ref, 1e-4);
retval2 += !isEqual(V2, V2_ref , 1e-4);
retval2 += !isEqual(th3, theta3_ref, 1e-4);

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