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 namespace Opm
32 {
33 
41 template<class GridView, class Vector>
43  : public Dune::CommDataHandleIF<VectorVectorDataHandle<GridView,Vector>,
44  std::decay_t<decltype(Vector()[0][0])>>
45 {
46 public:
47 
49  using DataType = std::decay_t<decltype(Vector()[0][0])>;
50 
54  VectorVectorDataHandle(Vector& data, const GridView& gridView)
55  : data_(data), gridView_(gridView)
56  {}
57 
58  bool contains(int /* dim */, int codim) const
59  {
60  return codim == 0;
61  }
62 
63  bool fixedsize(int /* dim */, int /* codim */) const
64  {
65  return true;
66  }
67  bool fixedSize(int /* dim */, int /* codim */) const
68  {
69  return true;
70  }
71 
72  template<class EntityType>
73  std::size_t size(const EntityType /* entity */) const
74  {
75  return data_.size();
76  }
77 
78 
79  template<class BufferType, class EntityType>
80  void gather(BufferType& buffer, const EntityType& e) const
81  {
82  for(const auto& vec: data_)
83  {
84  buffer.write(vec[gridView_.indexSet().index(e)]);
85  }
86  }
87 
88  template<class BufferType, class EntityType>
89  void scatter(BufferType& buffer, const EntityType& e, std::size_t n)
90  {
91  assert(n == data_.size());
92  for(auto& vec: data_)
93  {
94  buffer.read(vec[gridView_.indexSet().index(e)]);
95  }
96  }
97 private:
98  Vector& data_;
99  const GridView& gridView_;
100 };
101 
102 } // end namespace Opm
A data handle sending multiple data store in vectors attached to cells.
Definition: VectorVectorDataHandle.hpp:45
std::decay_t< decltype(Vector()[0][0])> DataType
the data type we send
Definition: VectorVectorDataHandle.hpp:49
VectorVectorDataHandle(Vector &data, const GridView &gridView)
Constructor.
Definition: VectorVectorDataHandle.hpp:54
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition: BlackoilPhases.hpp:27