Dune-Fufem 2.11-git
Loading...
Searching...
No Matches
p0p1interpolation.hh
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright © DUNE-FUFEM Project contributors, see file AUTHORS.md
2// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception OR LGPL-3.0-or-later
3
4#ifndef DUNE_FUFEM_FUNCTIONTOOLS_P0P1INTERPOLATION_HH
5#define DUNE_FUFEM_FUNCTIONTOOLS_P0P1INTERPOLATION_HH
6
7#include <vector>
8
10
12
14template <class GridView, class Vector>
16 Vector const &p0Data) {
17 auto const &gridView = patch.gridView();
18
20 gridView.size(GridView::dimension));
21 std::fill(surroundingArea.begin(), surroundingArea.end(), 0);
22
23 Vector ret(surroundingArea.size());
24 ret = 0.0;
25
26 auto const &indexSet = gridView.indexSet();
27 for (auto const &intersection : patch) {
28 auto const &inside = intersection.inside();
29 auto refElement =
30 Dune::ReferenceElements<double, GridView::dimension>::general(
31 inside.type());
32 auto const globalElementIndex = indexSet.index(inside);
33
34 auto const localFaceIndex = intersection.indexInInside();
35 auto const &face = inside.template subEntity<1>(localFaceIndex);
36
37 auto const area = face.geometry().volume();
38
39 int const numVertices =
40 refElement.size(localFaceIndex, 1, GridView::dimension);
41 for (int i = 0; i < numVertices; i++) {
42 auto const localVertexIndex =
43 refElement.subEntity(localFaceIndex, 1, i, GridView::dimension);
44 auto const globalVertexIndex =
45 indexSet.subIndex(inside, localVertexIndex, GridView::dimension);
46
47 surroundingArea[globalVertexIndex] += area;
48 ret[globalVertexIndex] += p0Data[globalElementIndex];
49 }
50 }
51
52 for (size_t i = 0; i < ret.size(); ++i)
53 if (patch.containsVertex(i))
54 ret[i] /= surroundingArea[i];
55
56 return ret;
57}
58
60template <class GridView, class Vector>
61Vector interpolateP0ToP1(GridView const &gridView,
62 Vector const &p0Data) {
63
64 unsigned int const dim = GridView::dimension;
66 gridView.size(dim));
67 std::fill(surroundingArea.begin(), surroundingArea.end(), 0);
68
69 Vector ret(surroundingArea.size());
70 ret = 0.0;
71
72 auto const &indexSet = gridView.indexSet();
73 for (auto const &element : elements(gridView)) {
74 auto refElement =
75 Dune::ReferenceElements<double, dim>::general(
76 element.type());
77 auto const globalElementIndex = indexSet.index(element);
78 auto const area = element.geometry().volume();
79
80 int const numVertices = refElement.size(dim);
81 for (int i = 0; i < numVertices; i++) {
82 auto const globalVertexIndex = indexSet.subIndex(element, i, dim);
83
84 surroundingArea[globalVertexIndex] += area;
85 ret[globalVertexIndex] += p0Data[globalElementIndex];
86 }
87 }
88
89 for (size_t i = 0; i < ret.size(); ++i)
90 ret[i] /= surroundingArea[i];
91
92 return ret;
93}
94
95#endif
Vector interpolateP0ToP1(BoundaryPatch< GridView > const &patch, Vector const &p0Data)
Clement-type operator that interpolates P0-data of grid elements to P1-data of vertices that belong t...
Definition p0p1interpolation.hh:15
size_type dim() const
IndexType subIndex(const typename Traits::template Codim< cc >::Entity &e, int i, unsigned int codim) const
IndexType index(const typename Traits::template Codim< cc >::Entity &e) const
Encapsulate a part of a grid boundary.
Definition boundarypatch.hh:218
bool containsVertex(size_t v) const
Definition boundarypatch.hh:366
const GridView & gridView() const
Return reference to the carrier grid view.
Definition domains/boundarypatch.hh:197
T begin(T... args)
T end(T... args)
T fill(T... args)
T size(T... args)