diff --git a/ComponentLib/Bus/BusPV.cpp b/ComponentLib/Bus/BusPV.cpp index 5daafa102..d5a05dc98 100644 --- a/ComponentLib/Bus/BusPV.cpp +++ b/ComponentLib/Bus/BusPV.cpp @@ -74,7 +74,7 @@ namespace ModelLib { */ template BusPV::BusPV() - : BaseBus(0), V_(0.0), theta0_(0.0), Pg_(0.0) + : BaseBus(0), V_(0.0), theta0_(0.0) { //std::cout << "Create BusPV..." << std::endl; //std::cout << "Number of equations is " << size_ << std::endl; @@ -83,9 +83,7 @@ BusPV::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_) @@ -94,10 +92,10 @@ BusPV::BusPV() * - Number of optimization parameters = 0 */ template -BusPV::BusPV(ScalarT V, ScalarT theta0, ScalarT Pg) - : BaseBus(0), V_(V), theta0_(theta0), Pg_(Pg) +BusPV::BusPV(ScalarT V, ScalarT theta0) + : BaseBus(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; @@ -171,8 +169,8 @@ template int BusPV::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; } diff --git a/ComponentLib/Bus/BusPV.hpp b/ComponentLib/Bus/BusPV.hpp index fd0291b69..cf645d591 100644 --- a/ComponentLib/Bus/BusPV.hpp +++ b/ComponentLib/Bus/BusPV.hpp @@ -91,7 +91,7 @@ namespace ModelLib using BusData = GridKit::PowerSystemData::BusData; BusPV(); - BusPV(ScalarT V, ScalarT theta0, ScalarT P); + BusPV(ScalarT V, ScalarT theta0); BusPV(BusData& data); virtual ~BusPV(); @@ -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_; diff --git a/ComponentLib/Generator/GeneratorPV.hpp b/ComponentLib/Generator/GeneratorPV.hpp index 5e3be2041..c34df84ad 100644 --- a/ComponentLib/Generator/GeneratorPV.hpp +++ b/ComponentLib/Generator/GeneratorPV.hpp @@ -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: diff --git a/Examples/Grid3Bus/Grid3BusSys.cpp b/Examples/Grid3Bus/Grid3BusSys.cpp index a379f4015..02985ff1d 100644 --- a/Examples/Grid3Bus/Grid3BusSys.cpp +++ b/Examples/Grid3Bus/Grid3BusSys.cpp @@ -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 @@ -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"; @@ -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"; @@ -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";