diff --git a/include/base/checkpoint.h b/include/base/checkpoint.h index 7626d1a..d9ca9ee 100644 --- a/include/base/checkpoint.h +++ b/include/base/checkpoint.h @@ -62,28 +62,28 @@ namespace Utilities * @param name * @param t */ - // template - // void - // load_checkpoint( - // const dealii::parallel::distributed::Triangulation &triangulation, - // const dealii::DoFHandler & dof_handler, - // const std::vector & vectors, - // const std::string & name, - // const double t) - // { - // parallel::distributed::SolutionTransfer solution_transfer( - // dof_handler); - - // solution_transfer.deserialize(vectors); - - // for (auto &it : vectors) - // it.update_ghost_values(); - - // std::ifstream file(name + "-checkpoint.metadata", std::ios::binary); - - // boost::archive::binary_iarchive ia(file); - // ia >> t; - // } + template + void + load_checkpoint( + const dealii::DoFHandler & dof_handler, + std::vector & vectors, + const std::string & name, + double & t) + { + // triangulation.load(name + "-checkpoint.mesh"); + dealii::parallel::distributed::SolutionTransfer + solution_transfer(dof_handler); + + solution_transfer.deserialize(vectors); + + for (auto &it : vectors) + it->update_ghost_values(); + + std::ifstream file(name + "-checkpoint.metadata", std::ios::binary); + + boost::archive::binary_iarchive ia(file); + ia >> t; + } } // namespace Utilities DEAL_II_NAMESPACE_CLOSE diff --git a/include/parameter/parameter_handling.h b/include/parameter/parameter_handling.h index 65a5f85..210ddca 100644 --- a/include/parameter/parameter_handling.h +++ b/include/parameter/parameter_handling.h @@ -311,8 +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.; + double delta_t = 0.1; + double end_time = 1.; + bool read_checkpoint = false; void add_parameters(ParameterHandler &prm); @@ -329,6 +330,10 @@ namespace Parameters delta_t, "Time step size", Patterns::Double(0.)); + prm.add_parameter("Resume checkpoint", + read_checkpoint, + "Resume from a checkpoint", + Patterns::Bool()); } prm.leave_subsection(); } diff --git a/include/solid_mechanics/mf_elasticity.h b/include/solid_mechanics/mf_elasticity.h index 2be73d0..fc45560 100644 --- a/include/solid_mechanics/mf_elasticity.h +++ b/include/solid_mechanics/mf_elasticity.h @@ -149,6 +149,10 @@ namespace FSI void write_checkpoint(); + + void + load_checkpoint(); + // Set up an Additional data object template void @@ -576,7 +580,10 @@ namespace FSI mf_data_reference); precice_adapter->initialize(total_displacement); - write_checkpoint(); + if (parameters.read_checkpoint) + load_checkpoint(); + else + write_checkpoint(); // At the beginning, we reset the solution update for this time step... while (precice_adapter->is_coupling_ongoing()) @@ -619,6 +626,8 @@ namespace FSI time.increment(); } } + write_checkpoint(); + // for post-processing, print average CG iterations over the whole run: timer_out << std::endl @@ -640,7 +649,11 @@ namespace FSI { Assert(testcase.get() != nullptr, ExcInternalError()); testcase->make_coarse_grid_and_bcs(triangulation); - triangulation.refine_global(parameters.n_global_refinement); + + if (parameters.read_checkpoint) + triangulation.load("test-checkpoint.mesh"); + else + triangulation.refine_global(parameters.n_global_refinement); if (testcase->body_force.get() == nullptr) testcase->body_force = @@ -2036,16 +2049,62 @@ namespace FSI void Solid::write_checkpoint() { - // pcout << "checkpoint computation"; - - Utilities::create_checkpoint(triangulation, - dof_handler, - {&total_displacement, - &velocity}, - "test", - time.current() - ); - // pcout << "resume interrupted computation"; + pcout << "checkpoint computation" + << "\n"; + std::vector in_vectors({&total_displacement, + &velocity, + &acceleration, + &old_displacement, + &velocity_old, + &acceleration_old}); + + Utilities::create_checkpoint( + triangulation, dof_handler, in_vectors, "test", time.current()); + } + + + + template + void + Solid::load_checkpoint() + { + std::vector in_vectors({&total_displacement, + &velocity, + &acceleration, + &old_displacement, + &velocity_old, + &acceleration_old}); + + auto partitioner = std::make_shared( + dof_handler.locally_owned_dofs(), + locally_relevant_dofs, + mpi_communicator); + + // We need something temporarily because the reloading doesn't allow for + // ghosted vectors + std::vector tmp_vectors(in_vectors.size()); + std::vector tmp_vectors_ptr; + + for (auto &vec : tmp_vectors) + { + vec.reinit(partitioner); + tmp_vectors_ptr.emplace_back(&vec); + } + + double new_time = 0; + Utilities::load_checkpoint(dof_handler, + tmp_vectors_ptr, + "test", + new_time); + + + for (unsigned int i = 0; i < tmp_vectors_ptr.size(); ++i) + { + in_vectors[i]->copy_locally_owned_data_from(*(tmp_vectors_ptr[i])); + in_vectors[i]->update_ghost_values(); + } + + pcout << "resume interrupted computation at t = " << new_time << "\n"; }