adaptivegridrestart.hh 5.49 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
// vi: set et ts=4 sw=4 sts=4:
/*****************************************************************************
 *   See the file COPYING for full copying permissions.                      *
 *                                                                           *
 *   This program is free software: you can redistribute it and/or modify    *
 *   it under the terms of the GNU General Public License as published by    *
 *   the Free Software Foundation, either version 2 of the License, or       *
 *   (at your option) any later version.                                     *
 *                                                                           *
 *   This program is distributed in the hope that it will be useful,         *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of          *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the            *
 *   GNU General Public License for more details.                            *
 *                                                                           *
 *   You should have received a copy of the GNU General Public License       *
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.   *
 *****************************************************************************/
/*!
 * \file
 * \brief Provides a restart functionality for adaptive grids
 */
#ifndef DUMUX_ADAPTIVEGRIDRESTART_HH
#define DUMUX_ADAPTIVEGRIDRESTART_HH

#include <dune/grid/yaspgrid.hh>
#include <dune/grid/sgrid.hh>
#if HAVE_ALUGRID
#include <dune/grid/alugrid/2d/alugrid.hh>
#include <dune/grid/alugrid/3d/alugrid.hh>
31
32
#elif HAVE_DUNE_ALUGRID
#include <dune/alugrid/grid.hh>
33
34
35
36
37
38
39
#endif
#if HAVE_UG
#include <dune/grid/uggrid.hh>
#endif
#if HAVE_ALBERTA
#include <dune/grid/albertagrid/agrid.hh>
#endif
40
41

#include <dune/grid/common/backuprestore.hh>
42
#include <dune/grid/utility/grapedataioformattypes.hh>
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68

namespace Dumux
{
/*!
 * \brief Indices denoting the different grid types.
 */

//! \cond \private
template<class Grid, int dim>
struct GridRestartCheck
{
    static const bool allowRestart = false;
};

template<int dim>
struct GridRestartCheck<Dune::YaspGrid<dim>, dim>
{
    static const bool allowRestart = false;
};

template<int dim>
struct GridRestartCheck<Dune::SGrid<dim, dim>, dim>
{
    static const bool allowRestart = false;
};

69
#if HAVE_ALUGRID || HAVE_DUNE_ALUGRID
70
71
72
template<int dim>
struct GridRestartCheck<Dune::ALUGrid<dim, dim, Dune::cube, Dune::nonconforming>, dim>
{
73
#if HAVE_ALUGRID
74
    static const bool allowRestart = true;
75
76
77
#else
    static const bool allowRestart = false;
#endif
78
79
80
81
82
};

template<int dim>
struct GridRestartCheck<Dune::ALUGrid<dim, dim, Dune::simplex, Dune::conforming>, dim>
{
83
#if HAVE_ALUGRID
84
    static const bool allowRestart = true;
85
86
87
#else
    static const bool allowRestart = false;
#endif
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
};
#endif

#if HAVE_UG
template<int dim>
struct GridRestartCheck<Dune::UGGrid<dim>, dim>
{
    static const bool allowRestart = false;
};
#endif
#if HAVE_ALBERTA
template<int dim>
struct GridRestartCheck<Dune::AlbertaGrid< dim, dim>, dim>
{
    static const bool allowRestart = true;
};
#endif
//! \endcond


/*!
 * \brief Default class for restart functionality for non-adaptive grids
 */
template <class Grid, int dim, bool allowGridRestart = GridRestartCheck<Grid, dim>::allowRestart >
class AdaptiveGridRestart
{
public:
    /*!
     * \brief Write the grid to a file.
     */
    template<class Problem>
    static void serializeGrid(Problem& problem)
    {
121
122
        DUNE_THROW(Dune::NotImplemented,
                   "Adaptive restart functionality currently only works for ALUGrid (not dune-alugrid).");
123
    }
124

125
126
127
128
129
130
    /*!
     * \brief Restart the grid from the file.
     */
    template<class Problem>
    static void restartGrid(Problem& problem)
    {
131
132
        DUNE_THROW(Dune::NotImplemented,
                   "Adaptive restart functionality currently only works for ALUGrid (not dune-alugrid).");
133
    }
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
};

/*!
 * \brief Provides a restart functionality for adaptive grids
 */
template <class Grid, int dim>
class AdaptiveGridRestart<Grid, dim, true>
{
public:
    /*!
     * \brief Write the grid to a file.
     */
    template<class Problem>
    static void serializeGrid(Problem& problem)
    {
149
150
151
152
153
154
        std::string gridName = restartGridFileName_(problem);
        double time = problem.timeManager().time();
        problem.grid().template writeGrid<Dune::xdr> (gridName, time);
        // TODO use the BackupRestoreFacility with dune-alugrid, see FS#237
        //Dune::BackupRestoreFacility<Grid>::backup(
        //    problem.grid(), restartGridFileName_(problem));
155
    }
156

157
158
159
160
161
162
    /*!
     * \brief Restart the grid from the file.
     */
    template<class Problem>
    static void restartGrid(Problem& problem)
    {
163
164
165
166
167
168
        std::string gridName = restartGridFileName_(problem);
        double time = problem.timeManager().time();
        problem.grid().template readGrid<Dune::xdr> (gridName, time);
        // TODO use the BackupRestoreFacility with dune-alugrid, see FS#237
        //problem.setGrid(*Dune::BackupRestoreFacility<Grid>::restore(
        //    restartGridFileName_(problem)));
169
    }
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185

private:
    //! \brief Return the restart file name.
    template<class Problem>
    static const std::string restartGridFileName_(Problem& problem)
    {
        int rank = problem.gridView().comm().rank();
        std::ostringstream oss;
        oss << problem.name()<<"_time="<<problem.timeManager().time()<<"_rank="<<rank<<".grs";
        return oss.str();
    }
};


} // namespace Dumux
#endif