From 2a8a43838025a7b05ae3ea3e9c08e8105b54b668 Mon Sep 17 00:00:00 2001 From: pelesh Date: Wed, 4 Mar 2026 18:59:58 -0500 Subject: [PATCH] Update experimental models to work with new tolerance settings. --- .../Model/PowerFlow/Generator2/Generator2.cpp | 19 +++++++++++++++++++ .../Model/PowerFlow/Generator2/Generator2.hpp | 1 + .../Generator4Governor/Generator4Governor.cpp | 19 +++++++++++++++++++ .../Generator4Governor/Generator4Governor.hpp | 1 + .../Generator4Param/Generator4Param.cpp | 19 +++++++++++++++++++ .../Generator4Param/Generator4Param.hpp | 1 + .../DynamicConstrainedOpt.cpp | 1 + .../GenConstLoad/GenConstLoad.cpp | 1 + .../GenInfiniteBus/GenInfiniteBus.cpp | 1 + .../ParameterEstimation.cpp | 1 + 10 files changed, 64 insertions(+) diff --git a/GridKit/Model/PowerFlow/Generator2/Generator2.cpp b/GridKit/Model/PowerFlow/Generator2/Generator2.cpp index b3be65808..636ccbb9f 100644 --- a/GridKit/Model/PowerFlow/Generator2/Generator2.cpp +++ b/GridKit/Model/PowerFlow/Generator2/Generator2.cpp @@ -61,6 +61,25 @@ namespace GridKit return 0; } + /** + * @brief Compute the absolute tolerance for each variable in the model + * + * @param rel_tol The relative tolerance which can be used to pick the + * absolute tolerance. + * @tparam ScalarT Scalar data type + * @tparam IdxT Index data type + * @return int 0 if successful, non-zero otherwise. + * + * This represents a "noise" level close to zero for which pure relative + * error cannot be used. + */ + template + int Generator2::setAbsoluteTolerance(RealT rel_tol) + { + std::fill(abs_tol_.begin(), abs_tol_.end(), rel_tol); + return 0; + } + template int Generator2::initialize() { diff --git a/GridKit/Model/PowerFlow/Generator2/Generator2.hpp b/GridKit/Model/PowerFlow/Generator2/Generator2.hpp index b0541ea5e..de429e06c 100644 --- a/GridKit/Model/PowerFlow/Generator2/Generator2.hpp +++ b/GridKit/Model/PowerFlow/Generator2/Generator2.hpp @@ -46,6 +46,7 @@ namespace GridKit int allocate(); int initialize(); int tagDifferentiable(); + int setAbsoluteTolerance(RealT); int evaluateResidual(); int evaluateJacobian(); int evaluateIntegrand(); diff --git a/GridKit/Model/PowerFlow/Generator4Governor/Generator4Governor.cpp b/GridKit/Model/PowerFlow/Generator4Governor/Generator4Governor.cpp index eaed1772a..2f5624c50 100644 --- a/GridKit/Model/PowerFlow/Generator4Governor/Generator4Governor.cpp +++ b/GridKit/Model/PowerFlow/Generator4Governor/Generator4Governor.cpp @@ -168,6 +168,25 @@ namespace GridKit return 0; } + /** + * @brief Compute the absolute tolerance for each variable in the model + * + * @param rel_tol The relative tolerance which can be used to pick the + * absolute tolerance. + * @tparam ScalarT Scalar data type + * @tparam IdxT Index data type + * @return int 0 if successful, non-zero otherwise. + * + * This represents a "noise" level close to zero for which pure relative + * error cannot be used. + */ + template + int Generator4Governor::setAbsoluteTolerance(RealT rel_tol) + { + std::fill(abs_tol_.begin(), abs_tol_.end(), rel_tol); + return 0; + } + /** * @brief Computes residual vector for the generator model. * diff --git a/GridKit/Model/PowerFlow/Generator4Governor/Generator4Governor.hpp b/GridKit/Model/PowerFlow/Generator4Governor/Generator4Governor.hpp index 74e6eeb47..52f400157 100644 --- a/GridKit/Model/PowerFlow/Generator4Governor/Generator4Governor.hpp +++ b/GridKit/Model/PowerFlow/Generator4Governor/Generator4Governor.hpp @@ -47,6 +47,7 @@ namespace GridKit int allocate(); int initialize(); int tagDifferentiable(); + int setAbsoluteTolerance(RealT); int evaluateResidual(); int evaluateJacobian(); int evaluateIntegrand(); diff --git a/GridKit/Model/PowerFlow/Generator4Param/Generator4Param.cpp b/GridKit/Model/PowerFlow/Generator4Param/Generator4Param.cpp index cd6500f6e..261779aa2 100644 --- a/GridKit/Model/PowerFlow/Generator4Param/Generator4Param.cpp +++ b/GridKit/Model/PowerFlow/Generator4Param/Generator4Param.cpp @@ -150,6 +150,25 @@ namespace GridKit return 0; } + /** + * @brief Compute the absolute tolerance for each variable in the model + * + * @param rel_tol The relative tolerance which can be used to pick the + * absolute tolerance. + * @tparam ScalarT Scalar data type + * @tparam IdxT Index data type + * @return int 0 if successful, non-zero otherwise. + * + * This represents a "noise" level close to zero for which pure relative + * error cannot be used. + */ + template + int Generator4Param::setAbsoluteTolerance(RealT rel_tol) + { + std::fill(abs_tol_.begin(), abs_tol_.end(), rel_tol); + return 0; + } + /** * @brief Computes residual vector for the generator model. * diff --git a/GridKit/Model/PowerFlow/Generator4Param/Generator4Param.hpp b/GridKit/Model/PowerFlow/Generator4Param/Generator4Param.hpp index 871e89693..bc1b94321 100644 --- a/GridKit/Model/PowerFlow/Generator4Param/Generator4Param.hpp +++ b/GridKit/Model/PowerFlow/Generator4Param/Generator4Param.hpp @@ -46,6 +46,7 @@ namespace GridKit int allocate(); int initialize(); int tagDifferentiable(); + int setAbsoluteTolerance(RealT); int evaluateResidual(); int evaluateJacobian(); int evaluateIntegrand(); diff --git a/examples/Experimental/DynamicConstrainedOpt/DynamicConstrainedOpt.cpp b/examples/Experimental/DynamicConstrainedOpt/DynamicConstrainedOpt.cpp index 58f7e9bb9..58c053b47 100644 --- a/examples/Experimental/DynamicConstrainedOpt/DynamicConstrainedOpt.cpp +++ b/examples/Experimental/DynamicConstrainedOpt/DynamicConstrainedOpt.cpp @@ -42,6 +42,7 @@ int main() // setup simulation idas.configureSimulation(); + idas.setTolerance(1e-7, 1e-9); idas.configureAdjoint(); idas.getDefaultInitialCondition(); idas.initializeSimulation(t_init); diff --git a/examples/Experimental/GenConstLoad/GenConstLoad.cpp b/examples/Experimental/GenConstLoad/GenConstLoad.cpp index d2d01d76a..9a45c7763 100644 --- a/examples/Experimental/GenConstLoad/GenConstLoad.cpp +++ b/examples/Experimental/GenConstLoad/GenConstLoad.cpp @@ -46,6 +46,7 @@ int main() // setup simulation idas->configureSimulation(); + idas->setTolerance(1e-7, 1e-9); idas->configureAdjoint(); idas->getDefaultInitialCondition(); idas->initializeSimulation(t_init, true); diff --git a/examples/Experimental/GenInfiniteBus/GenInfiniteBus.cpp b/examples/Experimental/GenInfiniteBus/GenInfiniteBus.cpp index 48c2650d1..92cc9b68a 100644 --- a/examples/Experimental/GenInfiniteBus/GenInfiniteBus.cpp +++ b/examples/Experimental/GenInfiniteBus/GenInfiniteBus.cpp @@ -42,6 +42,7 @@ int main() // setup simulation idas.configureSimulation(); + idas.setTolerance(1e-7, 1e-9); idas.configureAdjoint(); idas.getDefaultInitialCondition(); idas.initializeSimulation(t_init); diff --git a/examples/Experimental/ParameterEstimation/ParameterEstimation.cpp b/examples/Experimental/ParameterEstimation/ParameterEstimation.cpp index cb7c2aff9..7b3914780 100644 --- a/examples/Experimental/ParameterEstimation/ParameterEstimation.cpp +++ b/examples/Experimental/ParameterEstimation/ParameterEstimation.cpp @@ -52,6 +52,7 @@ int main() // setup simulation idas.configureSimulation(); + idas.setTolerance(1e-7, 1e-9); idas.configureAdjoint(); idas.getDefaultInitialCondition(); idas.initializeSimulation(t_init);