Skip to content

ConvertCheckpointGrids: TimeAverage file is rewritten as a single (time_avg, time_avg_fluct) pair, dropping dt_avg and every level above 0 #218

Description

@WeiqunZhang

Location: Util/ConvertCheckpoint/ConvertCheckpointGrids.cpp:340, Util/ConvertCheckpoint/ConvertCheckpointGrids.cpp:574
Severity: Medium — wrong time-average statistics after restarting from a converted checkpoint whenever ns.avg_interval>0 (non-default path)
Category: IO-restart
Based on commit bb697bf5 (line numbers refer to that tree).

Problem

Since PR #205 (issue #195) NavierStokesBase::checkPoint writes one
(time_avg, time_avg_fluct, dt_avg) triple per level after the title line
(Source/NavierStokesBase.cpp:905-917) and post_restart reads forward to its level's triple
(Source/NavierStokesBase.cpp:2580-2585). The converter still implements the old format:

// Util/ConvertCheckpoint/ConvertCheckpointGrids.cpp:340-343, 574-576
      std::getline(is_avg,first_line_avg);
      is_avg >> avg_time;
      is_avg >> avg_time_fluct;
...
        HeaderFile << "Writing time_average to checkpoint" << '\n'
                   << avg_time       << '\n'
                   << avg_time_fluct           << '\n';

Only level 0's first two numbers survive. None of these quantities depend on the resolution.

Impact

On restart from the converted file, level 0 gets dt_avg=0 (failed extraction, failbit
set) and every level >= 1 gets time_avg = time_avg_fluct = 0. NS_derive.cpp:27-37 then
plots the accumulated averages un-normalised (inv_time = 1) and time_average
(Source/NS_average.cpp:59) forms the fluctuation S - S_avg/(time_avg+dt_avg) with the
wrong time, so the running statistics on refined levels stay wrong. Reached by any run with
ns.avg_interval>0 and amr.max_level>0 converted with either interp_kind.

Suggested fix

Copy the TimeAverage file verbatim; this also keeps old single-pair files readable.

--- a/Util/ConvertCheckpoint/ConvertCheckpointGrids.cpp
+++ b/Util/ConvertCheckpoint/ConvertCheckpointGrids.cpp
@@ -9,6 +9,7 @@
 #include <iomanip>
 #include <iostream>
 #include <fstream>
+#include <sstream>
 #include <cmath>
 #include <cstdlib>
 #include <cstring>
@@ -60,8 +61,7 @@
 const std::string CheckPointVersion = "CheckPointVersion_1.0";
 std::string interp_kind;
 
-Real avg_time;
-Real avg_time_fluct;
+std::string TimeAverageContents;
 bool TimeAverageFile_exist = false;
 int flag_eb = 0;
 
@@ -337,10 +337,12 @@
     if(  is_avg.good()) {
       TimeAverageFile_exist = true;
 
-      std::string first_line_avg;
-      std::getline(is_avg,first_line_avg);
-      is_avg >> avg_time;
-      is_avg >> avg_time_fluct;
+      // Copy the file verbatim. IAMR writes a title line and then one
+      // (time_avg, time_avg_fluct, dt_avg) triple per level; none of these
+      // change when the grids are refined or coarsened.
+      std::ostringstream oss;
+      oss << is_avg.rdbuf();
+      TimeAverageContents = oss.str();
     }
 
 }
@@ -571,9 +573,7 @@
           amrex::FileOpenFailed(HeaderFileName);
         }
 
-        HeaderFile << "Writing time_average to checkpoint" << '\n'
-                   << avg_time       << '\n'
-                   << avg_time_fluct           << '\n';
+        HeaderFile << TimeAverageContents;
       }
     }
 

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions