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*/
30#ifndef OPM_VECTOR_VECTOR_DATA_HANDLE_HPP
31#define OPM_VECTOR_VECTOR_DATA_HANDLE_HPP
32
33#include <dune/grid/common/datahandleif.hh>
34
35#include <cstddef>
36#include <utility>
37
38namespace Opm
39{
40
48template<class GridView, class Vector>
50 : public Dune::CommDataHandleIF<VectorVectorDataHandle<GridView,Vector>,
51 std::decay_t<decltype(std::declval<Vector>()[0][0])>> // NVCC needs declval
52{
53public:
54
56 using DataType = std::decay_t<decltype(std::declval<Vector>()[0][0])>; // NVCC needs declval
57
61 VectorVectorDataHandle(Vector& data, const GridView& gridView)
62 : data_(data), gridView_(gridView)
63 {}
64
65 bool contains(int /* dim */, int codim) const
66 {
67 return codim == 0;
68 }
69
70 bool fixedSize(int /* dim */, int /* codim */) const
71 {
72 return true;
73 }
74
75 template<class EntityType>
76 std::size_t size(const EntityType /* entity */) const
77 {
78 return data_.size();
79 }
80
81
82 template<class BufferType, class EntityType>
83 void gather(BufferType& buffer, const EntityType& e) const
84 {
85 for(const auto& vec: data_)
86 {
87 buffer.write(vec[gridView_.indexSet().index(e)]);
88 }
89 }
90
91 template<class BufferType, class EntityType>
92 void scatter(BufferType& buffer, const EntityType& e,
93 [[maybe_unused]] std::size_t n)
94 {
95 assert(n == data_.size());
96 for(auto& vec: data_)
97 {
98 buffer.read(vec[gridView_.indexSet().index(e)]);
99 }
100 }
101private:
102 Vector& data_;
103 const GridView& gridView_;
104};
105
106} // end namespace Opm
107
108#endif // OPM_VECTOR_VECTOR_DATA_HANDLE_HPP
A data handle sending multiple data store in vectors attached to cells.
Definition: VectorVectorDataHandle.hpp:52
bool contains(int, int codim) const
Definition: VectorVectorDataHandle.hpp:65
std::size_t size(const EntityType) const
Definition: VectorVectorDataHandle.hpp:76
VectorVectorDataHandle(Vector &data, const GridView &gridView)
Constructor.
Definition: VectorVectorDataHandle.hpp:61
std::decay_t< decltype(std::declval< Vector >()[0][0])> DataType
the data type we send
Definition: VectorVectorDataHandle.hpp:56
void scatter(BufferType &buffer, const EntityType &e, std::size_t n)
Definition: VectorVectorDataHandle.hpp:92
bool fixedSize(int, int) const
Definition: VectorVectorDataHandle.hpp:70
void gather(BufferType &buffer, const EntityType &e) const
Definition: VectorVectorDataHandle.hpp:83
Definition: blackoilbioeffectsmodules.hh:45