Skip to content

Commit

Permalink
Cosmetics for the file naming
Browse files Browse the repository at this point in the history
  • Loading branch information
davidscn committed Oct 3, 2023
1 parent 683624d commit 66f7db7
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 22 deletions.
14 changes: 7 additions & 7 deletions include/parameter/parameter_handling.h
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,9 @@ namespace Parameters
// Set the timestep size $ \varDelta t $ and the simulation end-time.
struct Time
{
double delta_t = 0.1;
double end_time = 1.;
bool read_checkpoint = false;
double delta_t = 0.1;
double end_time = 1.;
double start_time = 0;

void
add_parameters(ParameterHandler &prm);
Expand All @@ -324,16 +324,16 @@ namespace Parameters
{
prm.enter_subsection("Time");
{
prm.add_parameter("Start time",
start_time,
"Restart simulation or start from the beginning",
Patterns::Double(0.));
prm.add_parameter("End time", end_time, "End time", Patterns::Double());

prm.add_parameter("Time step size",
delta_t,
"Time step size",
Patterns::Double(0.));
prm.add_parameter("Resume checkpoint",
read_checkpoint,
"Resume from a checkpoint",
Patterns::Bool());
}
prm.leave_subsection();
}
Expand Down
50 changes: 35 additions & 15 deletions include/solid_mechanics/mf_elasticity.h
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ namespace FSI
mf_data_reference);
precice_adapter->initialize(total_displacement);

if (parameters.read_checkpoint)
if (parameters.start_time != 0)
load_restart();

// At the beginning, we reset the solution update for this time step...
Expand Down Expand Up @@ -647,8 +647,9 @@ namespace FSI
Assert(testcase.get() != nullptr, ExcInternalError());
testcase->make_coarse_grid_and_bcs(triangulation);

if (parameters.read_checkpoint)
triangulation.load(parameters.output_folder + "restart.mesh");
if (parameters.start_time != 0)
triangulation.load(parameters.output_folder + "restart-t-" +
std::to_string(parameters.start_time) + ".mesh");
else
triangulation.refine_global(parameters.n_global_refinement);

Expand Down Expand Up @@ -2062,8 +2063,28 @@ namespace FSI
void
Solid<dim, Number>::write_restart()
{
pcout << "-- Creating restart files for t = " +
std::to_string(time.current())
// We need to apply some cosmetics to t to make it usable
std::string t_string = std::to_string(time.current());
for (int i = t_string.size() - 1; i >= 1; i--)
{
if (t_string.at(i) == '0')
{
t_string.pop_back(); // Remove if last digit is '0'.
}
else if (t_string.at(i) == '.')
{
t_string.pop_back(); // Remove dot.
break; // Break after '.' is removed.
}
else
{
break; // Or break before a digit is removed.
}
}
std::string restart_file(parameters.output_folder + "restart-t-" +
t_string);
pcout << "-- Creating restart files \"" + restart_file +
"\" for t = " + t_string
<< " ( timestep " << time.get_timestep() << " ) "
<< "\n";
std::vector<const VectorType *> in_vectors({&total_displacement,
Expand All @@ -2082,7 +2103,7 @@ namespace FSI
dof_handler,
total_displacement.get_partitioner(),
in_vectors,
parameters.output_folder + "restart",
restart_file,
time.current(),
time.get_timestep());
}
Expand All @@ -2100,18 +2121,17 @@ namespace FSI
&velocity_old,
&acceleration_old});

std::string restart_file(parameters.output_folder + "restart-t-" +
std::to_string(parameters.start_time));

double loaded_time = 0;
unsigned int loaded_timestep = 0;
Utilities::load_restart_snapshot<dim, VectorType>(dof_handler,
in_vectors,
parameters.output_folder +
"restart",
loaded_time,
loaded_timestep);

pcout << "-- Loaded interrupted computation at t = " << loaded_time
<< " ( timestep " << loaded_timestep << " ) "
Utilities::load_restart_snapshot<dim, VectorType>(
dof_handler, in_vectors, restart_file, loaded_time, loaded_timestep);

pcout << "-- Restarting computation from files \"" + restart_file +
"\" at t = "
<< loaded_time << " ( timestep " << loaded_timestep << " ) "
<< "\n";
time.set_time(loaded_time, loaded_timestep);
}
Expand Down

0 comments on commit 66f7db7

Please sign in to comment.