All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
pffgridvector.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_PFF_GRID_VECTOR_HH
28 #define EWOMS_PFF_GRID_VECTOR_HH
29 
30 #include <ewoms/common/prefetch.hh>
31 
32 #include <dune/grid/common/mcmgmapper.hh>
33 #include <dune/common/version.hh>
34 
35 #include <vector>
36 
37 namespace Ewoms {
47 template <class GridView, class Stencil, class Data, class DofMapper>
49 {
50  typedef typename GridView::template Codim<0>::Entity Element;
51  typedef Dune::MultipleCodimMultipleGeomTypeMapper<GridView, Dune::MCMGElementLayout> ElementMapper;
52 
53 public:
54  PffGridVector(const GridView& gridView, const DofMapper& dofMapper)
55  : gridView_(gridView)
56  , elementMapper_(gridView_)
57  , dofMapper_(dofMapper)
58  { }
59 
60  template <class DistFn>
61  void update(const DistFn& distFn)
62  {
63  unsigned numElements = gridView_.size(/*codim=*/0);
64  unsigned numLocalDofs = computeNumLocalDofs_();
65 
66  elemData_.resize(numElements);
67  data_.resize(numLocalDofs);
68 
69  // update the pointers for the element data: for this, we need to loop over the
70  // whole grid and update a stencil for each element
71  Data *curElemDataPtr = &data_[0];
72  Stencil stencil(gridView_, dofMapper_);
73  auto elemIt = gridView_.template begin</*codim=*/0>();
74  const auto& elemEndIt = gridView_.template end</*codim=*/0>();
75  for (; elemIt != elemEndIt; ++elemIt) {
76  // set the DOF data pointer for the current element
77  const auto& elem = *elemIt;
78  unsigned elemIdx = elementMapper_.index(elem);
79  elemData_[elemIdx] = curElemDataPtr;
80 
81  stencil.update(elem);
82  unsigned numDof = stencil.numDof();
83  for (unsigned localDofIdx = 0; localDofIdx < numDof; ++ localDofIdx)
84  distFn(curElemDataPtr[localDofIdx], stencil, localDofIdx);
85 
86  // update the element data pointer to make it point to the beginning of the
87  // data for DOFs of the next element
88  curElemDataPtr += numDof;
89  }
90  }
91 
92  void prefetch(const Element& elem) const
93  {
94  unsigned elemIdx = elementMapper_.index(elem);
95 
96  // we use 0 as the temporal locality, because it is reasonable to assume that an
97  // entry will only be accessed once.
98  Ewoms::prefetch</*temporalLocality=*/0>(elemData_[elemIdx]);
99  }
100 
101  const Data& get(const Element& elem, unsigned localDofIdx) const
102  {
103  unsigned elemIdx = elementMapper_.index(elem);
104  return elemData_[elemIdx][localDofIdx];
105  }
106 
107 private:
108  unsigned computeNumLocalDofs_() const
109  {
110  unsigned result = 0;
111 
112  // loop over the whole grid and sum up the number of local DOFs of all Stencils
113  Stencil stencil(gridView_, dofMapper_);
114  auto elemIt = gridView_.template begin</*codim=*/0>();
115  const auto& elemEndIt = gridView_.template end</*codim=*/0>();
116  for (; elemIt != elemEndIt; ++elemIt) {
117  stencil.update(*elemIt);
118  result += stencil.numDof();
119  }
120 
121  return result;
122  }
123 
124  GridView gridView_;
125  ElementMapper elementMapper_;
126  const DofMapper& dofMapper_;
127  std::vector<Data> data_;
128  std::vector<Data*> elemData_;
129 };
130 
131 } // namespace Ewoms
132 
133 #endif
A random-access container which stores data attached to a grid&#39;s degrees of freedom in a prefetch fri...
Definition: pffgridvector.hh:48