Skip to content

Commit 1e5a07d

Browse files
committed
implemented checkpoint-restart
1 parent c81f2d9 commit 1e5a07d

30 files changed

+1387
-16
lines changed

include/pidomus.h

Lines changed: 81 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,17 @@
1717

1818

1919
#include <deal.II/base/timer.h>
20-
// #include <deal.II/base/parameter_handler.h>
2120

2221
#include <deal.II/lac/trilinos_precondition.h>
2322
#include <deal.II/lac/trilinos_block_sparse_matrix.h>
2423
#include <deal.II/lac/linear_operator.h>
2524

26-
27-
2825
#include <mpi.h>
2926

30-
31-
// #include <deal.II/lac/precondition.h>
32-
33-
3427
#include "base_interface.h"
3528
#include "simulator_access.h"
3629
#include "pidomus_signals.h"
30+
#include "copy_data.h"
3731

3832
#include <deal2lkit/parsed_grid_generator.h>
3933
#include <deal2lkit/parsed_finite_element.h>
@@ -522,6 +516,86 @@ class piDoMUS : public ParameterAcceptor, public SundialsInterface<typename LAC:
522516
const typename LAC::VectorType &solution_dot);
523517

524518

519+
// checkpoint restart
520+
521+
// used in output solution
522+
unsigned int step_number;
523+
524+
unsigned int old_step;
525+
526+
/** resume compuatation
527+
* from a previously created snapshot
528+
*/
529+
bool resume_computation;
530+
531+
/**
532+
* create snapshot throughout the simulation
533+
*/
534+
bool save_snapshot;
535+
536+
/**
537+
* this prefix is put in front of the
538+
* common names used for checkpoint- restart
539+
*/
540+
std::string snap_prefix;
541+
542+
/**
543+
* Save the state of this program to a set of files in the output
544+
* directory. In reality, however, only some variables are stored (in
545+
* particular the mesh, the solution vectors, etc) whereas others can
546+
* either be re-generated (matrices, DoFHandler objects, etc) or are
547+
* read from the input parameter file.
548+
*
549+
* This function is implemented in
550+
* <code>source/checkpoint_restart.cc</code>.
551+
*/
552+
void create_snapshot() const;
553+
554+
void save_solutions_and_triangulation(const LADealII::VectorType &y,
555+
const LADealII::VectorType &y_dot,
556+
const LADealII::VectorType &locally_relevant_y_expl,
557+
const LADealII::VectorType &,
558+
const LADealII::VectorType &) const;
559+
560+
void save_solutions_and_triangulation(const LATrilinos::VectorType &y,
561+
const LATrilinos::VectorType &y_dot,
562+
const LATrilinos::VectorType &locally_relevant_y_expl,
563+
const LATrilinos::VectorType &,
564+
const LATrilinos::VectorType &) const;
565+
566+
567+
/**
568+
* Restore the state of this program from a set of files in the output
569+
* directory.
570+
*
571+
* This function is implemented in
572+
* <code>source/checkpoint_restart.cc</code>.
573+
*/
574+
void resume_from_snapshot();
575+
576+
void load_solutions(LADealII::VectorType &y,
577+
LADealII::VectorType &y_expl,
578+
LADealII::VectorType &y_dot);
579+
580+
void load_solutions(LATrilinos::VectorType &y,
581+
LATrilinos::VectorType &y_expl,
582+
LATrilinos::VectorType &y_dot);
583+
584+
public:
585+
/**
586+
* Save a number of variables using BOOST serialization mechanism.
587+
*
588+
* This function is implemented in
589+
* <code>source/checkpoint_restart.cc</code>.
590+
*/
591+
template <class Archive>
592+
void serialize (Archive &ar, const unsigned int /*version*/);
593+
594+
private:
595+
596+
597+
598+
525599
/**
526600
* Struct containing the signals
527601
*/

source/pidomus.cc

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@ piDoMUS<dim, spacedim, LAC>::piDoMUS (const std::string &name,
100100
101101
ida(*this),
102102
euler(*this),
103-
we_are_parallel(Utilities::MPI::n_mpi_processes(comm) > 1)
103+
we_are_parallel(Utilities::MPI::n_mpi_processes(comm) > 1),
104+
step_number(0),
105+
old_step(0)
104106
{
105107
106108
interface.initialize_simulator (*this);
@@ -123,15 +125,31 @@ void piDoMUS<dim, spacedim, LAC>::run ()
123125
124126
interface.connect_to_signals();
125127
126-
for (current_cycle = 0; current_cycle < n_cycles; ++current_cycle)
128+
if (resume_computation)
127129
{
128-
if (current_cycle == 0)
130+
resume_from_snapshot();
131+
132+
syncronize(current_time,solution,solution_dot);
133+
ida.set_initial_time(current_time);
134+
euler.set_initial_time(current_time+current_dt);
135+
}
136+
137+
current_cycle = (resume_computation? current_cycle : 0);
138+
old_step = (resume_computation? step_number : 0);
139+
140+
for (; current_cycle < n_cycles; ++current_cycle)
141+
{
142+
if (!resume_computation)
129143
{
130-
make_grid_fe();
131-
setup_dofs(true);
144+
if (current_cycle == 0)
145+
{
146+
make_grid_fe();
147+
setup_dofs(true);
148+
}
149+
else
150+
refine_mesh();
132151
}
133-
else
134-
refine_mesh();
152+
resume_computation = false;
135153
136154
constraints.distribute(solution);
137155
constraints_dot.distribute(solution_dot);

0 commit comments

Comments
 (0)