version 3.8
adaptivegridrestart.hh
Go to the documentation of this file.
1// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2// vi: set et ts=4 sw=4 sts=4:
3//
4// SPDX-FileCopyrightInfo: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
12#ifndef DUMUX_ADAPTIVEGRIDRESTART_HH
13#define DUMUX_ADAPTIVEGRIDRESTART_HH
14
15
16#if HAVE_DUNE_ALUGRID
17#include <dune/alugrid/grid.hh>
18#endif
19
20#include <dune/grid/common/backuprestore.hh>
21
24
25namespace Dumux {
26
33template<class Grid>
34struct GridRestartCheck
35{
36 static const bool allowRestart = false;
37};
38
39// the specializations for grid managers that support restart
40#if HAVE_DUNE_ALUGRID
41template<int dim, int dimworld, Dune::ALUGridElementType elType, Dune::ALUGridRefinementType refinementType>
42struct GridRestartCheck<Dune::ALUGrid<dim, dimworld, elType, refinementType> >
43{
44 static const bool allowRestart = true;
45};
46#endif
48
49
53template <class Grid, bool allowGridRestart = GridRestartCheck<Grid>::allowRestart >
55{
56public:
60 template<class Problem>
61 static void serializeGrid(Problem& problem)
62 {
63 DUNE_THROW(Dune::NotImplemented,
64 "Adaptive restart functionality currently only works for dune-ALUGrid.");
65 }
66
70 template<class Problem>
71 static void restartGrid(Problem& problem)
72 {
73 DUNE_THROW(Dune::NotImplemented,
74 "Adaptive restart functionality currently only works for dune-ALUGrid.");
75 }
76};
77
81template <class Grid>
82class AdaptiveGridRestart<Grid, true>
83{
84public:
88 template<class Problem>
89 static void serializeGrid(Problem& problem)
90 {
91 std::string gridName = restartGridFileName_(problem);
92#if HAVE_DUNE_ALUGRID
93 Dune::BackupRestoreFacility<Grid>::backup(problem.grid(), gridName);
94#else
95 problem.grid().template writeGrid(gridName, problem.timeManager().time()
96 + problem.timeManager().timeStepSize());
97#endif
98 }
99
103 template<class Problem>
104 static void restartGrid(Problem& problem)
105 {}
106
107private:
109 template<class Problem>
110 static const std::string restartGridFileName_(Problem& problem)
111 {
112 int rank = problem.gridView().comm().rank();
113 std::ostringstream oss;
114 try {
115 std::string name = getParam<std::string>("Problem.Name");
116 oss << name;
117 }
118 catch (ParameterException &e)
119 {
120 std::cerr << e.what() << std::endl;
121 std::cerr << "Taking name from problem.name(): " << problem.name() << std::endl;
122 std::cerr << "Be sure to provide a parameter Problem.Name if you want to restart." << std::endl;
123 oss << problem.name();
124 }
125 oss << "_time=" << problem.timeManager().time() + problem.timeManager().timeStepSize()
126 << "_rank=" << rank << ".grs";
127 return oss.str();
128 }
129};
130
131
132} // namespace Dumux
133#endif
static void restartGrid(Problem &problem)
Restart the grid from the file.
Definition: adaptivegridrestart.hh:104
static void serializeGrid(Problem &problem)
Write the grid to a file.
Definition: adaptivegridrestart.hh:89
Indices denoting the different grid types.
Definition: adaptivegridrestart.hh:55
static void restartGrid(Problem &problem)
Restart the grid from the file.
Definition: adaptivegridrestart.hh:71
static void serializeGrid(Problem &problem)
Write the grid to a file.
Definition: adaptivegridrestart.hh:61
Some exceptions thrown in DuMux
Definition: adapt.hh:17
Definition: common/pdesolver.hh:24
The infrastructure to retrieve run-time parameters from Dune::ParameterTrees.