From b63ff48508efb2fd5497ae6003fda14bf146b8e6 Mon Sep 17 00:00:00 2001 From: BSzymanowski Date: Mon, 10 Nov 2025 14:35:04 -0600 Subject: [PATCH 1/4] Tgov1 test update --- Testing/Temporary/CTestCostData.txt | 1 + Testing/Temporary/LastTest.log | 3 + .../PhasorDynamics/GovernorTgov1Tests.hpp | 60 ++++++++++++++++++- .../PhasorDynamics/runGovernorTgov1Tests.cpp | 1 + 4 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 Testing/Temporary/CTestCostData.txt create mode 100644 Testing/Temporary/LastTest.log diff --git a/Testing/Temporary/CTestCostData.txt b/Testing/Temporary/CTestCostData.txt new file mode 100644 index 000000000..ed97d539c --- /dev/null +++ b/Testing/Temporary/CTestCostData.txt @@ -0,0 +1 @@ +--- diff --git a/Testing/Temporary/LastTest.log b/Testing/Temporary/LastTest.log new file mode 100644 index 000000000..592c6017c --- /dev/null +++ b/Testing/Temporary/LastTest.log @@ -0,0 +1,3 @@ +Start testing: Nov 07 18:41 CST +---------------------------------------------------------- +End testing: Nov 07 18:41 CST diff --git a/tests/UnitTests/PhasorDynamics/GovernorTgov1Tests.hpp b/tests/UnitTests/PhasorDynamics/GovernorTgov1Tests.hpp index 94914bacd..a90114834 100644 --- a/tests/UnitTests/PhasorDynamics/GovernorTgov1Tests.hpp +++ b/tests/UnitTests/PhasorDynamics/GovernorTgov1Tests.hpp @@ -1,5 +1,8 @@ +#define _USE_MATH_DEFINES /* need this since directly including GenClassical.cpp for MSVC compiler */ #include #include +#include + #include #include @@ -50,6 +53,59 @@ namespace GridKit return success.report(__func__); } + /** + * For Tgov: + * This section is the updated residual, not residual initialization. + */ + + TestOutcome residual() + { + TestStatus success = true; + + // T1 governor parameters + real_type R{0.05}; + real_type Pvmin{0}; + real_type Pvmax{1}; + real_type T1{0.5}; + real_type T2{2.5}; + real_type T3{7.5}; + real_type Dt{0}; + + // Tgov1 external inputs + real_type omega{60}; + real_type Pref{1}; + + // Test answer keys + const std::vector res_answer = {0.0, + -2364.0, + -0.2}; + + // Set variable values matching the answer key + gov.y()[0] = 1; // Ptx + gov.y()[1] = 1.0; // Pv + gov.y()[2] = 10/15; // Pmech + + // Set derivative values matching the answer key + gov.yp()[0] = 8/15; // ptx_dot + gov.yp()[1] = 2; // pv_dot + + gov.evaluateResidual(); + std::vector& residual = gov.getResidual(); + + for (size_t i = 0; i < res_answer.size(); ++i) + { + if (!isEqual(residual[i], res_answer[i], tol_)) + { + std::cout << "Incorrect result for residual " << i << ": " + << residual[i] << " != " << res_answer[i] << "\n"; + success = false; + break; + } + } + + return success.report(__func__); + } + /** * @brief Checks residual evaluation. * @@ -58,8 +114,10 @@ namespace GridKit * precision. * * @return TestOutcome - wheter test was successful + * + * (Verifies the residual evaluates to zero for the initial conditions) */ - TestOutcome residual() + TestOutcome zeroInitialResidual() { TestStatus success = true; diff --git a/tests/UnitTests/PhasorDynamics/runGovernorTgov1Tests.cpp b/tests/UnitTests/PhasorDynamics/runGovernorTgov1Tests.cpp index d11c07df9..81a716d67 100644 --- a/tests/UnitTests/PhasorDynamics/runGovernorTgov1Tests.cpp +++ b/tests/UnitTests/PhasorDynamics/runGovernorTgov1Tests.cpp @@ -9,6 +9,7 @@ int main() result += test.constructor(); result += test.accessors(); result += test.residual(); + result += test.zeroInitialResidual(); #ifdef GRIDKIT_ENABLE_ENZYME result += test.jacobian(); #endif From 753c9c040cf84f7b79f62a98d90d72bd1cc5d2b1 Mon Sep 17 00:00:00 2001 From: BSzymanowski Date: Mon, 10 Nov 2025 15:14:34 -0600 Subject: [PATCH 2/4] Tgov newest update --- .../PhasorDynamics/GovernorTgov1Tests.hpp | 71 ++++++++++++++----- 1 file changed, 55 insertions(+), 16 deletions(-) diff --git a/tests/UnitTests/PhasorDynamics/GovernorTgov1Tests.hpp b/tests/UnitTests/PhasorDynamics/GovernorTgov1Tests.hpp index a90114834..acb3f9b41 100644 --- a/tests/UnitTests/PhasorDynamics/GovernorTgov1Tests.hpp +++ b/tests/UnitTests/PhasorDynamics/GovernorTgov1Tests.hpp @@ -27,6 +27,8 @@ namespace GridKit { private: using RealT = typename PhasorDynamics::Component::RealT; + using real_type = typename PhasorDynamics::Component::RealT; + static constexpr ScalarT tol_ = 10 * std::numeric_limits::epsilon(); public: GovernorTgov1Tests() = default; @@ -62,32 +64,69 @@ namespace GridKit { TestStatus success = true; - // T1 governor parameters - real_type R{0.05}; - real_type Pvmin{0}; - real_type Pvmax{1}; - real_type T1{0.5}; - real_type T2{2.5}; - real_type T3{7.5}; - real_type Dt{0}; + using BusType = PhasorDynamics::BusData::BusType; + using GenrouParameters = PhasorDynamics::GenrouData::Parameters; + using GenrouPorts = PhasorDynamics::GenrouData::Ports; + + PhasorDynamics::BusData busdata; + busdata.bus_id = 0; + busdata.bus_type = BusType::DEFAULT; + busdata.Vr0 = 1.0; + busdata.Vi0 = 0.0; - // Tgov1 external inputs - real_type omega{60}; - real_type Pref{1}; + PhasorDynamics::GenrouData gendata; + gendata.ports[GenrouPorts::bus] = 0; + + gendata.parameters[GenrouParameters::p0] = 1.; + gendata.parameters[GenrouParameters::q0] = 0.05013; + gendata.parameters[GenrouParameters::H] = 3.; + gendata.parameters[GenrouParameters::D] = 0.; + gendata.parameters[GenrouParameters::Ra] = 0.; + gendata.parameters[GenrouParameters::Tdop] = 7.; + gendata.parameters[GenrouParameters::Tdopp] = .04; + gendata.parameters[GenrouParameters::Tqopp] = .05; + gendata.parameters[GenrouParameters::Tqop] = .75; + gendata.parameters[GenrouParameters::Xd] = 2.1; + gendata.parameters[GenrouParameters::Xdp] = 0.2; + gendata.parameters[GenrouParameters::Xdpp] = 0.18; + gendata.parameters[GenrouParameters::Xq] = 0.5; + gendata.parameters[GenrouParameters::Xqp] = 0.5; + gendata.parameters[GenrouParameters::Xqpp] = 0.18; + gendata.parameters[GenrouParameters::Xl] = 0.15; + gendata.parameters[GenrouParameters::S10] = 0.; + gendata.parameters[GenrouParameters::S12] = 0.; + + PhasorDynamics::Bus bus(busdata); + PhasorDynamics::SignalNode pmech; + PhasorDynamics::SignalNode omega; + PhasorDynamics::Genrou gen(&bus, &omega, &pmech, gendata); + PhasorDynamics::Governor::Tgov1 gov(&pmech, &omega); // Test answer keys const std::vector res_answer = {0.0, - -2364.0, + -2.0, -0.2}; + bus.allocate(); + gen.allocate(); + gov.allocate(); + + bus.initialize(); + gen.initialize(); + gov.initialize(); + + bus.evaluateResidual(); + gen.evaluateResidual(); + gov.evaluateResidual(); + // Set variable values matching the answer key - gov.y()[0] = 1; // Ptx + gov.y()[0] = 1.0; // Ptx gov.y()[1] = 1.0; // Pv - gov.y()[2] = 10/15; // Pmech + gov.y()[2] = static_cast(10.0)/static_cast(15.0); // Pmech // Set derivative values matching the answer key - gov.yp()[0] = 8/15; // ptx_dot - gov.yp()[1] = 2; // pv_dot + gov.yp()[0] = static_cast(8.0)/static_cast(15.0); // ptx_dot + gov.yp()[1] = 2.0; // pv_dot gov.evaluateResidual(); std::vector& residual = gov.getResidual(); From ec9dd9991027dc6dce115efae55a48f82edcf4b7 Mon Sep 17 00:00:00 2001 From: BSzymanowski Date: Sat, 13 Dec 2025 04:02:03 +0000 Subject: [PATCH 3/4] Apply pre-commmit fixes --- .../PhasorDynamics/GovernorTgov1Tests.hpp | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/tests/UnitTests/PhasorDynamics/GovernorTgov1Tests.hpp b/tests/UnitTests/PhasorDynamics/GovernorTgov1Tests.hpp index acb3f9b41..99d0e84c8 100644 --- a/tests/UnitTests/PhasorDynamics/GovernorTgov1Tests.hpp +++ b/tests/UnitTests/PhasorDynamics/GovernorTgov1Tests.hpp @@ -3,7 +3,6 @@ #include #include - #include #include #include @@ -26,8 +25,8 @@ namespace GridKit class GovernorTgov1Tests { private: - using RealT = typename PhasorDynamics::Component::RealT; - using real_type = typename PhasorDynamics::Component::RealT; + using RealT = typename PhasorDynamics::Component::RealT; + using real_type = typename PhasorDynamics::Component::RealT; static constexpr ScalarT tol_ = 10 * std::numeric_limits::epsilon(); public: @@ -60,7 +59,7 @@ namespace GridKit * This section is the updated residual, not residual initialization. */ - TestOutcome residual() + TestOutcome residual() { TestStatus success = true; @@ -100,7 +99,7 @@ namespace GridKit PhasorDynamics::SignalNode pmech; PhasorDynamics::SignalNode omega; PhasorDynamics::Genrou gen(&bus, &omega, &pmech, gendata); - PhasorDynamics::Governor::Tgov1 gov(&pmech, &omega); + PhasorDynamics::Governor::Tgov1 gov(&pmech, &omega); // Test answer keys const std::vector res_answer = {0.0, @@ -120,13 +119,13 @@ namespace GridKit gov.evaluateResidual(); // Set variable values matching the answer key - gov.y()[0] = 1.0; // Ptx - gov.y()[1] = 1.0; // Pv - gov.y()[2] = static_cast(10.0)/static_cast(15.0); // Pmech + gov.y()[0] = 1.0; // Ptx + gov.y()[1] = 1.0; // Pv + gov.y()[2] = static_cast(10.0) / static_cast(15.0); // Pmech // Set derivative values matching the answer key - gov.yp()[0] = static_cast(8.0)/static_cast(15.0); // ptx_dot - gov.yp()[1] = 2.0; // pv_dot + gov.yp()[0] = static_cast(8.0) / static_cast(15.0); // ptx_dot + gov.yp()[1] = 2.0; // pv_dot gov.evaluateResidual(); std::vector& residual = gov.getResidual(); @@ -153,7 +152,7 @@ namespace GridKit * precision. * * @return TestOutcome - wheter test was successful - * + * * (Verifies the residual evaluates to zero for the initial conditions) */ TestOutcome zeroInitialResidual() From 5926445c6dbf675bad8c2ee9246a5db99673e091 Mon Sep 17 00:00:00 2001 From: pelesh Date: Thu, 18 Dec 2025 17:10:36 -0500 Subject: [PATCH 4/4] Remove stray files from the source code. --- Testing/Temporary/CTestCostData.txt | 1 - Testing/Temporary/LastTest.log | 3 --- 2 files changed, 4 deletions(-) delete mode 100644 Testing/Temporary/CTestCostData.txt delete mode 100644 Testing/Temporary/LastTest.log diff --git a/Testing/Temporary/CTestCostData.txt b/Testing/Temporary/CTestCostData.txt deleted file mode 100644 index ed97d539c..000000000 --- a/Testing/Temporary/CTestCostData.txt +++ /dev/null @@ -1 +0,0 @@ ---- diff --git a/Testing/Temporary/LastTest.log b/Testing/Temporary/LastTest.log deleted file mode 100644 index 592c6017c..000000000 --- a/Testing/Temporary/LastTest.log +++ /dev/null @@ -1,3 +0,0 @@ -Start testing: Nov 07 18:41 CST ----------------------------------------------------------- -End testing: Nov 07 18:41 CST