All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
basegridmanager.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  This file is part of the Open Porous Media project (OPM).
5 
6  OPM 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 2 of the License, or
9  (at your option) any later version.
10 
11  OPM 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 OPM. If not, see <http://www.gnu.org/licenses/>.
18 
19  Consult the COPYING file in the top-level source directory of this
20  module for the precise wording of the license and the list of
21  copyright holders.
22 */
27 #ifndef EWOMS_BASE_GRID_MANAGER_HH
28 #define EWOMS_BASE_GRID_MANAGER_HH
29 
32 
33 #include <dune/common/version.hh>
34 
35 #if HAVE_DUNE_FEM
36 #include <dune/fem/space/common/dofmanager.hh>
37 #endif
38 
39 #include <type_traits>
40 #include <memory>
41 
42 namespace Ewoms {
43 namespace Properties {
44 NEW_PROP_TAG(Grid);
45 NEW_PROP_TAG(GridManager);
46 NEW_PROP_TAG(GridView);
47 NEW_PROP_TAG(GridPart);
48 NEW_PROP_TAG(GridViewLevel);
49 NEW_PROP_TAG(GridFile);
50 NEW_PROP_TAG(GridGlobalRefinements);
51 NEW_PROP_TAG(Simulator);
52 } // namespace Properties
53 
57 template <class TypeTag>
59 {
60  typedef typename GET_PROP_TYPE(TypeTag, Simulator) Simulator;
61  typedef typename GET_PROP_TYPE(TypeTag, Grid) Grid;
62  typedef typename GET_PROP_TYPE(TypeTag, GridView) GridView;
63  typedef typename GET_PROP_TYPE(TypeTag, GridManager) Implementation;
64 
65 #if HAVE_DUNE_FEM
66  typedef typename GET_PROP_TYPE(TypeTag, GridPart) GridPart;
67 #endif
68 
69 public:
70  BaseGridManager(Simulator& simulator)
71  : simulator_(simulator)
72  {}
73 
74  BaseGridManager(const BaseGridManager&) = delete;
75 
79  const GridView& gridView() const
80  { return *gridView_; }
81 
82 #if HAVE_DUNE_FEM
83 
86  const GridPart& gridPart() const
87  { return *gridPart_; }
88 
92  GridPart& gridPart()
93  { return *gridPart_; }
94 #endif
95 
102  int gridSequenceNumber () const
103  {
104 #if HAVE_DUNE_FEM
105  typedef Dune::Fem::DofManager< Grid > FemDofManager;
106  return FemDofManager::instance( gridPart().grid() ).sequence();
107 #else
108  return 0; // return the same sequence number >= 0 means the grid never changes
109 #endif
110  }
111 
112 
117  void loadBalance()
118  { asImp_().grid().loadBalance(); }
119 
120 protected:
121  // this method should be called after the grid has been allocated
122  void finalizeInit_()
123  {
124 #if HAVE_DUNE_FEM
125  gridPart_.reset(new GridPart(asImp_().grid()));
126  gridView_.reset(new GridView(static_cast<GridView> (*gridPart_)));
127 #else
128  gridView_.reset(new GridView(asImp_().grid().leafGridView()));
129 #endif
130  }
131 
132 private:
133  Implementation& asImp_()
134  { return *static_cast<Implementation*>(this); }
135 
136  const Implementation& asImp_() const
137  { return *static_cast<const Implementation*>(this); }
138 
139  Simulator& simulator_;
140  std::unique_ptr<GridView> gridView_;
141 #if HAVE_DUNE_FEM
142  std::unique_ptr<GridPart> gridPart_;
143 #endif
144 };
145 
146 } // namespace Ewoms
147 
148 #endif
void loadBalance()
Distribute the grid (and attached data) over all processes.
Definition: basegridmanager.hh:117
Provides the base class for most (all?) grid managers.
Definition: basegridmanager.hh:58
This file provides the infrastructure to retrieve run-time parameters.
const GridView & gridView() const
Returns a reference to the grid view to be used.
Definition: basegridmanager.hh:79
int gridSequenceNumber() const
Returns the number of times the grid has been changed since its creation.
Definition: basegridmanager.hh:102
Provides the magic behind the eWoms property system.
Manages the initializing and running of time dependent problems.
Definition: simulator.hh:75
#define NEW_PROP_TAG(PTagName)
Define a property tag.
Definition: propertysystem.hh:247