3.3.0
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
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 * See the file COPYING for full copying permissions. *
5 * *
6 * This program is free software: you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation, either version 3 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
18 *****************************************************************************/
24#ifndef DUMUX_ADAPTIVEGRIDRESTART_HH
25#define DUMUX_ADAPTIVEGRIDRESTART_HH
26
27
28#if HAVE_DUNE_ALUGRID
29#include <dune/alugrid/grid.hh>
30#endif
31
32#include <dune/grid/common/backuprestore.hh>
33
36
37namespace Dumux {
38
45template<class Grid>
46struct GridRestartCheck
47{
48 static const bool allowRestart = false;
49};
50
51// the specializations for grid managers that support restart
52#if HAVE_DUNE_ALUGRID
53template<int dim, int dimworld, Dune::ALUGridElementType elType, Dune::ALUGridRefinementType refinementType>
54struct GridRestartCheck<Dune::ALUGrid<dim, dimworld, elType, refinementType> >
55{
56 static const bool allowRestart = true;
57};
58#endif
60
61
65template <class Grid, bool allowGridRestart = GridRestartCheck<Grid>::allowRestart >
67{
68public:
72 template<class Problem>
73 static void serializeGrid(Problem& problem)
74 {
75 DUNE_THROW(Dune::NotImplemented,
76 "Adaptive restart functionality currently only works for dune-ALUGrid.");
77 }
78
82 template<class Problem>
83 static void restartGrid(Problem& problem)
84 {
85 DUNE_THROW(Dune::NotImplemented,
86 "Adaptive restart functionality currently only works for dune-ALUGrid.");
87 }
88};
89
93template <class Grid>
94class AdaptiveGridRestart<Grid, true>
95{
96public:
100 template<class Problem>
101 static void serializeGrid(Problem& problem)
102 {
103 std::string gridName = restartGridFileName_(problem);
104#if HAVE_DUNE_ALUGRID
105 Dune::BackupRestoreFacility<Grid>::backup(problem.grid(), gridName);
106#else
107 problem.grid().template writeGrid(gridName, problem.timeManager().time()
108 + problem.timeManager().timeStepSize());
109#endif
110 }
111
115 template<class Problem>
116 static void restartGrid(Problem& problem)
117 {}
118
119private:
121 template<class Problem>
122 static const std::string restartGridFileName_(Problem& problem)
123 {
124 int rank = problem.gridView().comm().rank();
125 std::ostringstream oss;
126 try {
127 std::string name = getParam<std::string>("Problem.Name");
128 oss << name;
129 }
130 catch (ParameterException &e)
131 {
132 std::cerr << e.what() << std::endl;
133 std::cerr << "Taking name from problem.name(): " << problem.name() << std::endl;
134 std::cerr << "Be sure to provide a parameter Problem.Name if you want to restart." << std::endl;
135 oss << problem.name();
136 }
137 oss << "_time=" << problem.timeManager().time() + problem.timeManager().timeStepSize()
138 << "_rank=" << rank << ".grs";
139 return oss.str();
140 }
141};
142
143
144} // namespace Dumux
145#endif
Some exceptions thrown in DuMux
The infrastructure to retrieve run-time parameters from Dune::ParameterTrees.
Definition: adapt.hh:29
Definition: common/pdesolver.hh:35
Indices denoting the different grid types.
Definition: adaptivegridrestart.hh:67
static void restartGrid(Problem &problem)
Restart the grid from the file.
Definition: adaptivegridrestart.hh:83
static void serializeGrid(Problem &problem)
Write the grid to a file.
Definition: adaptivegridrestart.hh:73
static void restartGrid(Problem &problem)
Restart the grid from the file.
Definition: adaptivegridrestart.hh:116
static void serializeGrid(Problem &problem)
Write the grid to a file.
Definition: adaptivegridrestart.hh:101