My Project
VectorVectorDataHandle.hpp
Go to the documentation of this file.
1 // -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=4:
3 /*
4  Copyright 2021 Equinor AS.
5 
6  This file is part of the Open Porous Media project (OPM).
7 
8  OPM is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 3 of the License, or
11  (at your option) any later version.
12 
13  OPM is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with OPM. If not, see <http://www.gnu.org/licenses/>.
20 
21  Consult the COPYING file in the top-level source directory of this
22  module for the precise wording of the license and the list of
23  copyright holders.
24 */
31 #include <dune/grid/common/datahandleif.hh>
32 
33 #include <cstddef>
34 
35 namespace Opm
36 {
37 
45 template<class GridView, class Vector>
47  : public Dune::CommDataHandleIF<VectorVectorDataHandle<GridView,Vector>,
48  std::decay_t<decltype(Vector()[0][0])>>
49 {
50 public:
51 
53  using DataType = std::decay_t<decltype(Vector()[0][0])>;
54 
58  VectorVectorDataHandle(Vector& data, const GridView& gridView)
59  : data_(data), gridView_(gridView)
60  {}
61 
62  bool contains(int /* dim */, int codim) const
63  {
64  return codim == 0;
65  }
66 
67 #if DUNE_VERSION_LT(DUNE_GRID, 2, 8)
68  bool fixedsize(int /* dim */, int /* codim */) const
69  {
70  return true;
71  }
72 #else
73 
74  bool fixedSize(int /* dim */, int /* codim */) const
75  {
76  return true;
77  }
78 #endif
79  template<class EntityType>
80  std::size_t size(const EntityType /* entity */) const
81  {
82  return data_.size();
83  }
84 
85 
86  template<class BufferType, class EntityType>
87  void gather(BufferType& buffer, const EntityType& e) const
88  {
89  for(const auto& vec: data_)
90  {
91  buffer.write(vec[gridView_.indexSet().index(e)]);
92  }
93  }
94 
95  template<class BufferType, class EntityType>
96  void scatter(BufferType& buffer, const EntityType& e,
97  [[maybe_unused]] std::size_t n)
98  {
99  assert(n == data_.size());
100  for(auto& vec: data_)
101  {
102  buffer.read(vec[gridView_.indexSet().index(e)]);
103  }
104  }
105 private:
106  Vector& data_;
107  const GridView& gridView_;
108 };
109 
110 } // end namespace Opm
A data handle sending multiple data store in vectors attached to cells.
Definition: VectorVectorDataHandle.hpp:49
std::decay_t< decltype(Vector()[0][0])> DataType
the data type we send
Definition: VectorVectorDataHandle.hpp:53
VectorVectorDataHandle(Vector &data, const GridView &gridView)
Constructor.
Definition: VectorVectorDataHandle.hpp:58
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition: BlackoilPhases.hpp:27