From 5960adaa4fc39a894dc4589aef034b0b5b96d9a0 Mon Sep 17 00:00:00 2001 From: lukelowry Date: Thu, 27 Aug 2026 20:52:08 -0500 Subject: [PATCH 1/3] reduce unecessary state --- .../SynchronousMachine/GENROU/GenrouImpl.hpp | 24 ++++++------------- .../SynchronousMachine/GENSAL/Gensal.hpp | 2 -- .../SynchronousMachine/GENSAL/GensalImpl.hpp | 16 +++---------- .../UnitTests/PhasorDynamics/GenrouTests.hpp | 8 ++----- .../UnitTests/PhasorDynamics/GensalTests.hpp | 8 ++----- 5 files changed, 14 insertions(+), 44 deletions(-) diff --git a/GridKit/Model/PhasorDynamics/SynchronousMachine/GENROU/GenrouImpl.hpp b/GridKit/Model/PhasorDynamics/SynchronousMachine/GENROU/GenrouImpl.hpp index 2169ea443..39be5957c 100644 --- a/GridKit/Model/PhasorDynamics/SynchronousMachine/GENROU/GenrouImpl.hpp +++ b/GridKit/Model/PhasorDynamics/SynchronousMachine/GENROU/GenrouImpl.hpp @@ -48,7 +48,7 @@ namespace GridKit S12_(0.), mva_base_(100.) { - size_ = 19; + size_ = 17; setDerivedParams(); } @@ -97,7 +97,7 @@ namespace GridKit S12_(S12), mva_base_(100.) { - size_ = 19; + size_ = 17; setDerivedParams(); } @@ -112,7 +112,7 @@ namespace GridKit initializeParameters(data); initializeMonitor(); - size_ = 19; + size_ = 17; setDerivedParams(); } @@ -129,7 +129,7 @@ namespace GridKit initializeParameters(data); initializeMonitor(); - size_ = 19; + size_ = 17; setDerivedParams(); } @@ -147,7 +147,7 @@ namespace GridKit initializeParameters(data); initializeMonitor(); - size_ = 19; + size_ = 17; setDerivedParams(); } @@ -451,10 +451,6 @@ namespace GridKit y[14] = iq; y[15] = ir; y[16] = ii; - y[17] = G_ * (vd * std::sin(delta) + vq * std::cos(delta)) - - B_ * (vd * -std::cos(delta) + vq * std::sin(delta)); - y[18] = B_ * (vd * std::sin(delta) + vq * std::cos(delta)) - + G_ * (vd * -std::cos(delta) + vq * std::sin(delta)); ScalarT Te = y[12]; // Convert Te to system base for governor PM signal. @@ -543,8 +539,6 @@ namespace GridKit ScalarT iq = y[14]; ScalarT ir = y[15]; ScalarT ii = y[16]; - ScalarT inr = y[17]; - ScalarT ini = y[18]; /* Read derivatives */ ScalarT delta_dot = yp[0]; @@ -582,12 +576,8 @@ namespace GridKit f[12] = telec - ((psidpp - id * Xdpp_) * iq - (psiqpp - iq * Xdpp_) * id); f[13] = id - (ir * std::sin(delta) - ii * std::cos(delta)); f[14] = iq - (ir * std::cos(delta) + ii * std::sin(delta)); - f[15] = ir + G_ * vr - B_ * vi - inr; - f[16] = ii + B_ * vr + G_ * vi - ini; - - /* 2 Genrou current source definitions */ - f[17] = inr - (G_ * (std::sin(delta) * vd + std::cos(delta) * vq) - B_ * (-std::cos(delta) * vd + std::sin(delta) * vq)); - f[18] = ini - (B_ * (std::sin(delta) * vd + std::cos(delta) * vq) + G_ * (-std::cos(delta) * vd + std::sin(delta) * vq)); + f[15] = ir - (G_ * (std::sin(delta) * vd + std::cos(delta) * vq - vr) - B_ * (-std::cos(delta) * vd + std::sin(delta) * vq - vi)); + f[16] = ii - (B_ * (std::sin(delta) * vd + std::cos(delta) * vq - vr) + G_ * (-std::cos(delta) * vd + std::sin(delta) * vq - vi)); return 0; } diff --git a/GridKit/Model/PhasorDynamics/SynchronousMachine/GENSAL/Gensal.hpp b/GridKit/Model/PhasorDynamics/SynchronousMachine/GENSAL/Gensal.hpp index 74655e7f1..210a42b9b 100644 --- a/GridKit/Model/PhasorDynamics/SynchronousMachine/GENSAL/Gensal.hpp +++ b/GridKit/Model/PhasorDynamics/SynchronousMachine/GENSAL/Gensal.hpp @@ -46,8 +46,6 @@ namespace GridKit IQ, ///< \f$I_q\f$ q-axis current IR, ///< \f$I_r\f$ network real current II, ///< \f$I_i\f$ network imaginary current - INR, ///< \f$I_{\mathrm{N},r}\f$ Norton source real current - INI, ///< \f$I_{\mathrm{N},i}\f$ Norton source imaginary current MAXIMUM, }; diff --git a/GridKit/Model/PhasorDynamics/SynchronousMachine/GENSAL/GensalImpl.hpp b/GridKit/Model/PhasorDynamics/SynchronousMachine/GENSAL/GensalImpl.hpp index 385eda4d6..f24db895c 100644 --- a/GridKit/Model/PhasorDynamics/SynchronousMachine/GENSAL/GensalImpl.hpp +++ b/GridKit/Model/PhasorDynamics/SynchronousMachine/GENSAL/GensalImpl.hpp @@ -25,7 +25,7 @@ namespace GridKit initializeParameters(data); initializeMonitor(); - size_ = 16; + size_ = 14; setDerivedParams(); } @@ -314,10 +314,6 @@ namespace GridKit y[11] = iq; y[12] = ir; y[13] = ii; - y[14] = G_ * (vd * std::sin(delta) + vq * std::cos(delta)) - - B_ * (vd * -std::cos(delta) + vq * std::sin(delta)); - y[15] = B_ * (vd * std::sin(delta) + vq * std::cos(delta)) - + G_ * (vd * -std::cos(delta) + vq * std::sin(delta)); // Convert Te to system base for governor PM signal. pmech_set_ = toSystemBase(Te); @@ -402,8 +398,6 @@ namespace GridKit ScalarT iq = y[11]; ScalarT ir = y[12]; ScalarT ii = y[13]; - ScalarT inr = y[14]; - ScalarT ini = y[15]; /* Read derivatives */ ScalarT delta_dot = yp[0]; @@ -437,12 +431,8 @@ namespace GridKit f[9] = telec - ((psidpp - id * Xdpp_) * iq - (psiqpp - iq * Xdpp_) * id); f[10] = id - (ir * std::sin(delta) - ii * std::cos(delta)); f[11] = iq - (ir * std::cos(delta) + ii * std::sin(delta)); - f[12] = ir + G_ * vr - B_ * vi - inr; - f[13] = ii + B_ * vr + G_ * vi - ini; - - /* 2 Gensal current source definitions */ - f[14] = inr - (G_ * (std::sin(delta) * vd + std::cos(delta) * vq) - B_ * (-std::cos(delta) * vd + std::sin(delta) * vq)); - f[15] = ini - (B_ * (std::sin(delta) * vd + std::cos(delta) * vq) + G_ * (-std::cos(delta) * vd + std::sin(delta) * vq)); + f[12] = ir - (G_ * (std::sin(delta) * vd + std::cos(delta) * vq - vr) - B_ * (-std::cos(delta) * vd + std::sin(delta) * vq - vi)); + f[13] = ii - (B_ * (std::sin(delta) * vd + std::cos(delta) * vq - vr) + G_ * (-std::cos(delta) * vd + std::sin(delta) * vq - vi)); return 0; } diff --git a/tests/UnitTests/PhasorDynamics/GenrouTests.hpp b/tests/UnitTests/PhasorDynamics/GenrouTests.hpp index 57eab5d65..1d81ae2f6 100644 --- a/tests/UnitTests/PhasorDynamics/GenrouTests.hpp +++ b/tests/UnitTests/PhasorDynamics/GenrouTests.hpp @@ -236,10 +236,8 @@ namespace GridKit 2.211, 0.85, 1.2, - static_cast(64.) / static_cast(65.), - -static_cast(237.) / static_cast(130.), - -static_cast(141.) / static_cast(130.), - -static_cast(241.) / static_cast(260.)}; + -static_cast(13.) / static_cast(130.), + -static_cast(143.) / static_cast(52.)}; bus.allocate(); bus.initialize(); @@ -273,8 +271,6 @@ namespace GridKit y[14] = .3; // iq y[15] = .9; // ir y[16] = .25; // ii - y[17] = .3; // inr - y[18] = .15; // ini // Set derivative values matching the answer key yp[0] = 2.0 * pi * 60.0; // delta_dot diff --git a/tests/UnitTests/PhasorDynamics/GensalTests.hpp b/tests/UnitTests/PhasorDynamics/GensalTests.hpp index ae15c4e9f..ba62c8f65 100644 --- a/tests/UnitTests/PhasorDynamics/GensalTests.hpp +++ b/tests/UnitTests/PhasorDynamics/GensalTests.hpp @@ -277,10 +277,8 @@ namespace GridKit 1.8125, 0.5, 0.25, - 2.65, - -0.05, - 0.3, - -1.2}; + 2.95, + -1.25}; bus.allocate(); bus.initialize(); @@ -306,8 +304,6 @@ namespace GridKit y[11] = -0.5; // iq y[12] = 0.75; // ir y[13] = -0.25; // ii - y[14] = 0.1; // inr - y[15] = -0.2; // ini yp[0] = 2.0 * pi * 60.0; // delta_dot yp[1] = -1.0; // omega_dot From 0504a1ec67f55688ef7da5a20a0e2e58b9d409b3 Mon Sep 17 00:00:00 2001 From: lukelowry Date: Thu, 27 Aug 2026 23:42:36 -0500 Subject: [PATCH 2/3] tiny tol adjust --- tests/IntegrationTests/PhasorDynamics/PDIntegrationTests.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/IntegrationTests/PhasorDynamics/PDIntegrationTests.hpp b/tests/IntegrationTests/PhasorDynamics/PDIntegrationTests.hpp index 689107267..939c6625e 100644 --- a/tests/IntegrationTests/PhasorDynamics/PDIntegrationTests.hpp +++ b/tests/IntegrationTests/PhasorDynamics/PDIntegrationTests.hpp @@ -330,7 +330,7 @@ namespace GridKit auto error_set = runSimulation(set_data, base_name + ".ref.csv"); - RealT error_V_allowed = 2.01e-4; + RealT error_V_allowed = 2.1e-4; RealT error_w_allowed = 1e-4; success *= error_set->var_errors[0].max_value < error_V_allowed; From cf5239e649d3eab7fcd06af30bda79d0d7ced309 Mon Sep 17 00:00:00 2001 From: lukelowry Date: Fri, 28 Aug 2026 19:02:04 -0500 Subject: [PATCH 3/3] fix example usage of ida --- .../Tiny/TwoBus/Basic/TwoBusBasicJson.cpp | 16 +++++++--------- .../PhasorDynamics/PDIntegrationTests.hpp | 4 +++- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/examples/PhasorDynamics/Tiny/TwoBus/Basic/TwoBusBasicJson.cpp b/examples/PhasorDynamics/Tiny/TwoBus/Basic/TwoBusBasicJson.cpp index e9306b286..a80392dc1 100644 --- a/examples/PhasorDynamics/Tiny/TwoBus/Basic/TwoBusBasicJson.cpp +++ b/examples/PhasorDynamics/Tiny/TwoBus/Basic/TwoBusBasicJson.cpp @@ -78,32 +78,30 @@ int main(int argc, const char* argv[]) // Get access to the fault auto* fault = sys.getBusFault(0); - // Set time step to 1/4 of a 60Hz cycle - real_type dt = 1.0 / 4.0 / 60.0; + // Monitor every quarter cycle at 60 Hz + real_type dt_monitor = 1.0 / 4.0 / 60.0; // Set up simulation Ida ida(&sys); + ida.setMaxSteps(10000); ida.configureSimulation(); - // Run simulation - making sure to pass the callback to record output + // Run simulation real_type start = static_cast(clock()); // Run for 1s ida.initializeSimulation(0.0, false); - int nout = static_cast(std::round((1.0 - 0.0) / dt)); - ida.runSimulation(1.0, nout); + ida.runSimulation(1.0, dt_monitor); // Introduce fault and run for the next 0.1s fault->setStatus(true); ida.initializeSimulation(1.0); - nout = static_cast(std::round((1.1 - 1.0) / dt)); - ida.runSimulation(1.1, nout); + ida.runSimulation(1.1, dt_monitor); // Clear the fault and run until t = 10s. fault->setStatus(false); ida.initializeSimulation(1.1); - nout = static_cast(std::round((10.0 - 1.1) / dt)); - ida.runSimulation(10.0, nout); + ida.runSimulation(10.0, dt_monitor); real_type stop = static_cast(clock()); std::cout << "\n\nComplete in " << (stop - start) / CLOCKS_PER_SEC << " seconds\n"; diff --git a/tests/IntegrationTests/PhasorDynamics/PDIntegrationTests.hpp b/tests/IntegrationTests/PhasorDynamics/PDIntegrationTests.hpp index 939c6625e..be76719bf 100644 --- a/tests/IntegrationTests/PhasorDynamics/PDIntegrationTests.hpp +++ b/tests/IntegrationTests/PhasorDynamics/PDIntegrationTests.hpp @@ -243,6 +243,8 @@ namespace GridKit // Set up simulation AnalysisManager::Sundials::Ida ida(&sys); + ida.setTolerance(static_cast(1.0e-7), + static_cast(1.0e-9)); ida.configureSimulation(); // Run for 1s @@ -330,7 +332,7 @@ namespace GridKit auto error_set = runSimulation(set_data, base_name + ".ref.csv"); - RealT error_V_allowed = 2.1e-4; + RealT error_V_allowed = 2.01e-4; RealT error_w_allowed = 1e-4; success *= error_set->var_errors[0].max_value < error_V_allowed;