opm-grid
Entity2IndexDataHandle.hpp
1 //===========================================================================
2 //
3 // File: Entity2IndexDataHandle.hpp
4 //
5 // Created: Mon Nov 4 2013
6 //
7 // Author(s): Markus Blatt <markus@dr-blatt.de>
8 //
9 // $Date$
10 //
11 // $Revision$
12 //
13 //===========================================================================
14 
15 /*
16  Copyright 2013 Statoil ASA.
17  Copyright 2013 Dr. Markus Blatt - HPC-Simulation-Software & Services
18 
19  This file is part of The Open Porous Media project (OPM).
20 
21  OPM is free software: you can redistribute it and/or modify
22  it under the terms of the GNU General Public License as published by
23  the Free Software Foundation, either version 3 of the License, or
24  (at your option) any later version.
25 
26  OPM is distributed in the hope that it will be useful,
27  but WITHOUT ANY WARRANTY; without even the implied warranty of
28  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29  GNU General Public License for more details.
30 
31  You should have received a copy of the GNU General Public License
32  along with OPM. If not, see <http://www.gnu.org/licenses/>.
33 */
34 #ifndef OPM_ENTITY2INDEXDATAHANDLE_HEADER
35 #define OPM_ENTITY2INDEXDATAHANDLE_HEADER
36 
37 #include <dune/common/version.hh>
38 
39 #include <cstddef>
40 
41 namespace Dune
42 {
43 namespace cpgrid
44 {
45 template<int codim> class Entity;
46 class CpGridData;
47 
54 template<class DataHandle, int codim>
56 {
57 public:
58  typedef typename DataHandle::DataType DataType;
59 
60  Entity2IndexDataHandle(const CpGridData& grid, DataHandle& data)
61  : fromGrid_(grid), toGrid_(grid), data_(data)
62  {}
63  Entity2IndexDataHandle(const CpGridData& fromGrid, const CpGridData& toGrid, DataHandle& data)
64  : fromGrid_(fromGrid), toGrid_(toGrid), data_(data)
65  {}
66 
67  bool fixedSize()
68  {
69  return data_.fixedSize(3, codim);
70  }
71 
72  std::size_t size(std::size_t i)
73  {
74  return data_.size(Entity<codim>(fromGrid_, i, true));
75  }
76 
77  template<class B>
78  void gather(B& buffer, std::size_t i)
79  {
80  data_.gather(buffer, Entity<codim>(fromGrid_, i, true));
81  }
82 
83  template<class B>
84  void scatter(B& buffer, std::size_t i, std::size_t s)
85  {
86  data_.scatter(buffer, Entity<codim>(toGrid_, i, true), s);
87  }
88 
89 private:
90  const CpGridData& fromGrid_;
91  const CpGridData& toGrid_;
92  DataHandle& data_;
93 
94 };
95 } // end namespace cpgrid
96 } // end namespace Dune
97 #endif
Definition: CpGridData.hpp:95
The namespace Dune is the main namespace for all Dune code.
Definition: CartesianIndexMapper.hpp:9
Struct that hods all the data needed to represent a Cpgrid.
Definition: CpGridData.hpp:117
Wrapper that turns a data handle suitable for dune-grid into one based on integers instead of entitie...
Definition: Entity2IndexDataHandle.hpp:55