From 72b4340dbc1e81b09b229465d85f40f7c00fe881 Mon Sep 17 00:00:00 2001 From: Nicholson Koukpaizan Date: Wed, 19 Aug 2026 11:45:18 -0400 Subject: [PATCH 1/9] std::abs--> isEqual --- tests/UnitTests/Solver/Dynamic/IdaTests.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/UnitTests/Solver/Dynamic/IdaTests.hpp b/tests/UnitTests/Solver/Dynamic/IdaTests.hpp index 0e02f0800..bcd177b85 100644 --- a/tests/UnitTests/Solver/Dynamic/IdaTests.hpp +++ b/tests/UnitTests/Solver/Dynamic/IdaTests.hpp @@ -584,8 +584,8 @@ namespace GridKit ida.configureSimulation(); ida.initializeSimulation(0.0); - success *= (std::abs(model.yp().getData()[0] - 1.0) < 1.0e-10); - success *= (std::abs(model.y().getData()[1]) < 1.0e-10); + success *= isEqual(model.yp().getData()[0], 1.0); + success *= isEqual(model.y().getData()[1], 0.0); } { @@ -596,7 +596,7 @@ namespace GridKit ida.configureSimulation(); ida.initializeSimulation(0.0); - success *= (std::abs(model.y().getData()[0]) < 1.0e-10); + success *= isEqual(model.y().getData()[0], 0.0); } return success.report(__func__); From a2925e270820f66ac345ade6866f9d6a06692523 Mon Sep 17 00:00:00 2001 From: Nicholson Koukpaizan Date: Wed, 19 Aug 2026 11:53:41 -0400 Subject: [PATCH 2/9] Make all checks explicity in IDATest::consistentICType, including unchanged states. --- tests/UnitTests/Solver/Dynamic/IdaTests.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/UnitTests/Solver/Dynamic/IdaTests.hpp b/tests/UnitTests/Solver/Dynamic/IdaTests.hpp index bcd177b85..ffbd37975 100644 --- a/tests/UnitTests/Solver/Dynamic/IdaTests.hpp +++ b/tests/UnitTests/Solver/Dynamic/IdaTests.hpp @@ -585,6 +585,8 @@ namespace GridKit ida.initializeSimulation(0.0); success *= isEqual(model.yp().getData()[0], 1.0); + success *= isEqual(model.yp().getData()[1], 0.0); + success *= isEqual(model.y().getData()[0], 0.0); success *= isEqual(model.y().getData()[1], 0.0); } From 86c2c5260dd021a30531d09e38a9d4721cc6e37b Mon Sep 17 00:00:00 2001 From: Nicholson Koukpaizan Date: Wed, 19 Aug 2026 12:03:55 -0400 Subject: [PATCH 3/9] Add test for IDATest::consistentICType with initially consistent derivative. --- tests/UnitTests/Solver/Dynamic/IdaTests.hpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tests/UnitTests/Solver/Dynamic/IdaTests.hpp b/tests/UnitTests/Solver/Dynamic/IdaTests.hpp index ffbd37975..9840f901f 100644 --- a/tests/UnitTests/Solver/Dynamic/IdaTests.hpp +++ b/tests/UnitTests/Solver/Dynamic/IdaTests.hpp @@ -577,7 +577,21 @@ namespace GridKit TestStatus success = true; { - Model::ConsistentICTypeEvaluator model; + Model::ConsistentICTypeEvaluator model(false); + + Ida ida(&model); + ida.setConsistentICType(AnalysisManager::Sundials::IdaConsistentICType::YA_YDP); + ida.configureSimulation(); + ida.initializeSimulation(0.0); + + success *= isEqual(model.yp().getData()[0], 1.0); + success *= isEqual(model.yp().getData()[1], 0.0); + success *= isEqual(model.y().getData()[0], 0.0); + success *= isEqual(model.y().getData()[1], 0.0); + } + + { + Model::ConsistentICTypeEvaluator model(true); Ida ida(&model); ida.setConsistentICType(AnalysisManager::Sundials::IdaConsistentICType::YA_YDP); From 9682912329114c34953e2253dbfc85da2003ab9f Mon Sep 17 00:00:00 2001 From: Nicholson Koukpaizan Date: Wed, 19 Aug 2026 12:29:47 -0400 Subject: [PATCH 4/9] Change IDATest::consistentICType model to something that admits a steady-state solution. --- tests/UnitTests/Solver/Dynamic/IdaTests.hpp | 26 +++++++++++++-------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/tests/UnitTests/Solver/Dynamic/IdaTests.hpp b/tests/UnitTests/Solver/Dynamic/IdaTests.hpp index 9840f901f..703d507e4 100644 --- a/tests/UnitTests/Solver/Dynamic/IdaTests.hpp +++ b/tests/UnitTests/Solver/Dynamic/IdaTests.hpp @@ -384,8 +384,8 @@ namespace GridKit public: ConsistentICTypeEvaluator() = default; - explicit ConsistentICTypeEvaluator(bool consistent_derivative) - : consistent_derivative_(consistent_derivative) + explicit ConsistentICTypeEvaluator(bool steady_state) + : steady_state_(steady_state) { } @@ -402,8 +402,8 @@ namespace GridKit auto* f = f_.getData(); y[0] = 0.0; - y[1] = 10.0; - yp[0] = consistent_derivative_ ? 1.0 : 0.0; + y[1] = 1.0; // Carefully chosen non-zero guess. Initialization will fail with bad initial guesses. + yp[0] = steady_state_ ? 0.0 : 2.0; // Purposefully inconsistent guess for non-steady-state case. yp[1] = 0.0; tag_ = {true, false}; abs_tol[0] = 0.0; @@ -428,14 +428,14 @@ namespace GridKit const auto* y = y_.getData(); const auto* yp = yp_.getData(); - f[0] = yp[0] - 1.0; + f[0] = yp[0] + y[0] + y[1] - 1.0; f[1] = y[1] - y[0]; f_.setDataUpdated(); return 0; } private: - bool consistent_derivative_{false}; + bool steady_state_{false}; }; } // namespace Model @@ -576,11 +576,15 @@ namespace GridKit { TestStatus success = true; + using RealT = typename ScalarTraits::RealT; + + // IdaConsistentICType::YA_YDP with non-steady-state initial guess for the derivatives { Model::ConsistentICTypeEvaluator model(false); Ida ida(&model); ida.setConsistentICType(AnalysisManager::Sundials::IdaConsistentICType::YA_YDP); + ida.setTolerance(std::numeric_limits::epsilon()); ida.configureSimulation(); ida.initializeSimulation(0.0); @@ -590,18 +594,20 @@ namespace GridKit success *= isEqual(model.y().getData()[1], 0.0); } + // IdaConsistentICType::Y with steady-state initial guess for the derivatives { Model::ConsistentICTypeEvaluator model(true); Ida ida(&model); - ida.setConsistentICType(AnalysisManager::Sundials::IdaConsistentICType::YA_YDP); + ida.setConsistentICType(AnalysisManager::Sundials::IdaConsistentICType::Y); + ida.setTolerance(std::numeric_limits::epsilon()); ida.configureSimulation(); ida.initializeSimulation(0.0); - success *= isEqual(model.yp().getData()[0], 1.0); + success *= isEqual(model.yp().getData()[0], 0.0); success *= isEqual(model.yp().getData()[1], 0.0); - success *= isEqual(model.y().getData()[0], 0.0); - success *= isEqual(model.y().getData()[1], 0.0); + success *= isEqual(model.y().getData()[0], 0.5); + success *= isEqual(model.y().getData()[1], 0.5); } { From d7c7a88d7eeb7e69b7c8fcceaae83fe1edee53cd Mon Sep 17 00:00:00 2001 From: nkoukpaizan Date: Wed, 19 Aug 2026 16:53:16 +0000 Subject: [PATCH 5/9] Apply pre-commit fixes --- tests/UnitTests/Solver/Dynamic/IdaTests.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/UnitTests/Solver/Dynamic/IdaTests.hpp b/tests/UnitTests/Solver/Dynamic/IdaTests.hpp index 703d507e4..4e64f730a 100644 --- a/tests/UnitTests/Solver/Dynamic/IdaTests.hpp +++ b/tests/UnitTests/Solver/Dynamic/IdaTests.hpp @@ -402,7 +402,7 @@ namespace GridKit auto* f = f_.getData(); y[0] = 0.0; - y[1] = 1.0; // Carefully chosen non-zero guess. Initialization will fail with bad initial guesses. + y[1] = 1.0; // Carefully chosen non-zero guess. Initialization will fail with bad initial guesses. yp[0] = steady_state_ ? 0.0 : 2.0; // Purposefully inconsistent guess for non-steady-state case. yp[1] = 0.0; tag_ = {true, false}; From 0c854bb0be1ceac297a84db45809f9dff969fd18 Mon Sep 17 00:00:00 2001 From: Nicholson Koukpaizan Date: Wed, 19 Aug 2026 14:52:24 -0400 Subject: [PATCH 6/9] Increasing consistentICType tolerances. --- tests/UnitTests/Solver/Dynamic/IdaTests.hpp | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/tests/UnitTests/Solver/Dynamic/IdaTests.hpp b/tests/UnitTests/Solver/Dynamic/IdaTests.hpp index 4e64f730a..3ec889ead 100644 --- a/tests/UnitTests/Solver/Dynamic/IdaTests.hpp +++ b/tests/UnitTests/Solver/Dynamic/IdaTests.hpp @@ -577,6 +577,7 @@ namespace GridKit TestStatus success = true; using RealT = typename ScalarTraits::RealT; + static constexpr auto tol = std::numeric_limits::epsilon(); // IdaConsistentICType::YA_YDP with non-steady-state initial guess for the derivatives { @@ -584,14 +585,14 @@ namespace GridKit Ida ida(&model); ida.setConsistentICType(AnalysisManager::Sundials::IdaConsistentICType::YA_YDP); - ida.setTolerance(std::numeric_limits::epsilon()); + ida.setTolerance(tol); ida.configureSimulation(); ida.initializeSimulation(0.0); - success *= isEqual(model.yp().getData()[0], 1.0); - success *= isEqual(model.yp().getData()[1], 0.0); - success *= isEqual(model.y().getData()[0], 0.0); - success *= isEqual(model.y().getData()[1], 0.0); + success *= isEqual(model.yp().getData()[0], 1.0, tol); + success *= isEqual(model.yp().getData()[1], 0.0, tol); + success *= isEqual(model.y().getData()[0], 0.0, tol); + success *= isEqual(model.y().getData()[1], 0.0, tol); } // IdaConsistentICType::Y with steady-state initial guess for the derivatives @@ -600,14 +601,14 @@ namespace GridKit Ida ida(&model); ida.setConsistentICType(AnalysisManager::Sundials::IdaConsistentICType::Y); - ida.setTolerance(std::numeric_limits::epsilon()); + ida.setTolerance(tol); ida.configureSimulation(); ida.initializeSimulation(0.0); - success *= isEqual(model.yp().getData()[0], 0.0); - success *= isEqual(model.yp().getData()[1], 0.0); - success *= isEqual(model.y().getData()[0], 0.5); - success *= isEqual(model.y().getData()[1], 0.5); + success *= isEqual(model.yp().getData()[0], 0.0, tol); + success *= isEqual(model.yp().getData()[1], 0.0, tol); + success *= isEqual(model.y().getData()[0], 0.5, tol); + success *= isEqual(model.y().getData()[1], 0.5, tol); } { From 4f3391fc0f73b987a55d90c01f33d07ac24a8385 Mon Sep 17 00:00:00 2001 From: Nicholson Koukpaizan Date: Wed, 19 Aug 2026 14:53:48 -0400 Subject: [PATCH 7/9] Increasing consistentICType tolerances. --- tests/UnitTests/Solver/Dynamic/IdaTests.hpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/UnitTests/Solver/Dynamic/IdaTests.hpp b/tests/UnitTests/Solver/Dynamic/IdaTests.hpp index 3ec889ead..fcbcdc2a8 100644 --- a/tests/UnitTests/Solver/Dynamic/IdaTests.hpp +++ b/tests/UnitTests/Solver/Dynamic/IdaTests.hpp @@ -402,7 +402,7 @@ namespace GridKit auto* f = f_.getData(); y[0] = 0.0; - y[1] = 1.0; // Carefully chosen non-zero guess. Initialization will fail with bad initial guesses. + y[1] = 10.0; // Initialization will fail with bad initial guesses. yp[0] = steady_state_ ? 0.0 : 2.0; // Purposefully inconsistent guess for non-steady-state case. yp[1] = 0.0; tag_ = {true, false}; @@ -577,7 +577,8 @@ namespace GridKit TestStatus success = true; using RealT = typename ScalarTraits::RealT; - static constexpr auto tol = std::numeric_limits::epsilon(); + + static constexpr auto tol = 100.0 * std::numeric_limits::epsilon(); // IdaConsistentICType::YA_YDP with non-steady-state initial guess for the derivatives { From bedb2afca6b581b04a5a912f9c4b3fd2d6a2d506 Mon Sep 17 00:00:00 2001 From: Nicholson Koukpaizan Date: Wed, 19 Aug 2026 15:05:09 -0400 Subject: [PATCH 8/9] Update tolerance comment. --- tests/UnitTests/Solver/Dynamic/IdaTests.hpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/UnitTests/Solver/Dynamic/IdaTests.hpp b/tests/UnitTests/Solver/Dynamic/IdaTests.hpp index fcbcdc2a8..27552745c 100644 --- a/tests/UnitTests/Solver/Dynamic/IdaTests.hpp +++ b/tests/UnitTests/Solver/Dynamic/IdaTests.hpp @@ -402,7 +402,7 @@ namespace GridKit auto* f = f_.getData(); y[0] = 0.0; - y[1] = 10.0; // Initialization will fail with bad initial guesses. + y[1] = 10.0; yp[0] = steady_state_ ? 0.0 : 2.0; // Purposefully inconsistent guess for non-steady-state case. yp[1] = 0.0; tag_ = {true, false}; @@ -578,6 +578,8 @@ namespace GridKit using RealT = typename ScalarTraits::RealT; + // If the tolerances are too tight, a finite difference approximation to the Jacobian + // cannot be generated, and initialization will fail with bad initial guesses. static constexpr auto tol = 100.0 * std::numeric_limits::epsilon(); // IdaConsistentICType::YA_YDP with non-steady-state initial guess for the derivatives From 02c74dc6681dcf62a378dde556a8fe56313517e8 Mon Sep 17 00:00:00 2001 From: nkoukpaizan Date: Wed, 19 Aug 2026 19:05:38 +0000 Subject: [PATCH 9/9] Apply pre-commit fixes --- tests/UnitTests/Solver/Dynamic/IdaTests.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/UnitTests/Solver/Dynamic/IdaTests.hpp b/tests/UnitTests/Solver/Dynamic/IdaTests.hpp index 27552745c..aea551aa5 100644 --- a/tests/UnitTests/Solver/Dynamic/IdaTests.hpp +++ b/tests/UnitTests/Solver/Dynamic/IdaTests.hpp @@ -402,7 +402,7 @@ namespace GridKit auto* f = f_.getData(); y[0] = 0.0; - y[1] = 10.0; + y[1] = 10.0; yp[0] = steady_state_ ? 0.0 : 2.0; // Purposefully inconsistent guess for non-steady-state case. yp[1] = 0.0; tag_ = {true, false}; @@ -578,7 +578,7 @@ namespace GridKit using RealT = typename ScalarTraits::RealT; - // If the tolerances are too tight, a finite difference approximation to the Jacobian + // If the tolerances are too tight, a finite difference approximation to the Jacobian // cannot be generated, and initialization will fail with bad initial guesses. static constexpr auto tol = 100.0 * std::numeric_limits::epsilon();