#2925: overflow in rat in Arith
Reporter:Roland Haas
Status:new
Milestone:
Version:
Type:bug
Priority:minor
Component:

Arith implements rational numbers which are used by CarpetX to track iterations on refinement levels, so that it can handle the fractional times of the coarse step that are used by refined levels.

In https://github.com/EinsteinToolkit/CarpetX/pull/377#pullrequestreview-3994686849 I had to find the maximum and minimum iteration used during interpolation and a code putting an elephant in a known location:

diff --git a/CarpetX/src/interpolate.cxx b/CarpetX/src/interpolate.cxx
index eee39a9a..2c490c68 100644
--- a/CarpetX/src/interpolate.cxx
+++ b/CarpetX/src/interpolate.cxx
@@ -664,6 +664,11 @@ extern "C" void CarpetX_Interpolate(const CCTK_POINTER_TO_CONST cctkGH_,
     givis.at(v) = {gi, vi};
   }

+  rat64 min_level_iteration_used =
+      std::numeric_limits<decltype(min_level_iteration_used.num)>::max();
+  rat64 max_level_iteration_used =
+      std::numeric_limits<decltype(max_level_iteration_used.num)>::min();
+  bool requires_interpolation_in_time = false;
   for (const auto &patchdata : ghext->patchdata) {
     const int patch = patchdata.patch;
     for (const auto &leveldata : patchdata.leveldata) {
@@ -676,6 +681,11 @@ extern "C" void CarpetX_Interpolate(const CCTK_POINTER_TO_CONST cctkGH_,
         const GridDesc grid(leveldata, mfp);
         // const int component = mfp.index();

+        min_level_iteration_used =
+            std::min(min_level_iteration_used, leveldata.iteration);
+        max_level_iteration_used =
--
Ticket URL: https://bitbucket.org/einsteintoolkit/tickets/issues/2925/overflow-in-rat-in-arith