Commit 577a2a1d authored by David Deepwell's avatar David Deepwell
Browse files

Moved parameter adjustment for restarting from dump from case file into Options.cpp

Moved the section of gravity_current.cpp regarding the adjustment
of temporal values (restarting, initial_time, etc.) when restarting
from dump into Options.cpp as it is a standard piece of code and
should be in a centralized location.
parent f73b2120
......@@ -189,3 +189,41 @@ void add_option(
add_option<string>(name, location, string(def_value), description);
}
// adjust temporal values when restarting from dump
void adjust_for_dump(bool & restarting, double & restart_time, int & restart_sequence,
const double final_time, const double compute_time, double & avg_write_time,
const int Num_tracers, const int Nx, const int Ny, const int Nz) {
restarting = true; // change restart to true
// open dump time file
string dump_str;
ifstream dump_file;
dump_file.open("dump_time.txt");
// ingnore 1st line
getline(dump_file, dump_str);
// get restart time from 2nd line
getline(dump_file, dump_str);
restart_time = atof(dump_str.c_str());
// ingore 3rd line
getline(dump_file, dump_str);
// get restart sequence from 4th line
getline(dump_file, dump_str);
restart_sequence = atoi(dump_str.c_str());
if (restart_time > final_time) {
// Die, ungracefully
if (master()) {
fprintf(stderr,"Restart dump time (%.4g) is past final time (%.4g). "
"Quitting now.\n",restart_time,final_time);
}
MPI_Finalize(); exit(1);
}
// make an estimate of the average write time
// this will get overwritten once a write occurs
if (compute_time > 0) {
double write_time_per_G = 25.0; // (s) 1 G = 512^3 points
int Num_fields = 3 + Num_tracers; // 3 velocity fields + tracers
avg_write_time = max(write_time_per_G*Num_fields*Nx*Ny*Nz/pow(512.0,3), 20.0);
}
}
......@@ -62,4 +62,9 @@ void options_init();
// Run the options parser, using the passed-in argc/argv from
// main(). This also opens and reads in the configuration file.
void options_parse(int argc, char ** argv);
// adjust temporal values when restarting from dump
void adjust_for_dump(bool & restarting, double & restart_time, int & restart_sequence,
const double final_time, const double compute_time, double & avg_write_time,
const int Num_tracers, const int Nx, const int Ny, const int Nz);
#endif
......@@ -8,7 +8,6 @@
#include "../../Options.hpp" // config-file parser
#include "../../Science.hpp" // Science content
#include <random/normal.h> // Blitz random number generator
#include <fstream>
using namespace ranlib;
......@@ -404,38 +403,10 @@ int main(int argc, char ** argv) {
/* Now, make sense of the options received. Many of these
* can be directly used, but the ones of string-type need further procesing. */
// adjust time if starting from a dump
// adjust temporal values when restarting from dump
if (restart_from_dump) {
restarting = true;
string dump_str;
ifstream dump_file;
dump_file.open ("dump_time.txt");
getline (dump_file,dump_str); // ingnore 1st line
getline (dump_file,dump_str);
initial_time = atof(dump_str.c_str());
getline (dump_file,dump_str); // ingore 3rd line
getline (dump_file,dump_str);
restart_sequence = atoi(dump_str.c_str());
if (initial_time > final_time){
// Die, ungracefully
if (master()){
fprintf(stderr,"Restart dump time (%.4g) is past final time (%.4g). "
"Quitting now.\n",initial_time,final_time);
}
MPI_Finalize(); exit(1);
}
}
// make an estimate of the average write time
// this will get overwritten once a write occurs
if (compute_time > 0){
double write_time_per_G = 25.0; // (s) 1 G = 512^3 points
int Num_fields = 3 + Num_tracers; // 3 velocity fields + tracers
avg_write_time = max(write_time_per_G*Num_fields*Nx*Ny*Nz/pow(512.0,3), 20.0);
adjust_for_dump(restarting, initial_time, restart_sequence,
final_time, compute_time, avg_write_time, Num_tracers, Nx, Ny, Nz);
}
// Grid types:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment