version 3.8
facecentered/staggered/connectivitymap.hh
Go to the documentation of this file.
1// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2// vi: set et ts=4 sw=4 sts=4:
3//
4// SPDX-FileCopyrightInfo: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
12#ifndef DUMUX_DISCRETIZATION_FACECENTERED_STAGGERED_CONNECTIVITY_MAP_HH
13#define DUMUX_DISCRETIZATION_FACECENTERED_STAGGERED_CONNECTIVITY_MAP_HH
14
15#include <algorithm>
16#include <vector>
17#include <dune/grid/common/partitionset.hh>
18#include <dune/grid/common/gridenums.hh>
20
21namespace Dumux {
22
28template<class GridGeometry>
30{
31 using GridView = typename GridGeometry::GridView;
32 using GridIndexType = typename IndexTraits<GridView>::GridIndex;
33 using Stencil = std::vector<GridIndexType>;
34 using Map = std::vector<Stencil>;
35
36public:
37
39 void update(const GridGeometry& gridGeometry)
40 {
41 map_.clear();
42 map_.resize(gridGeometry.numScv());
43
44 auto fvGeometry = localView(gridGeometry);
45 for (const auto& element : elements(gridGeometry.gridView()))
46 {
47 if (element.partitionType() == Dune::InteriorEntity)
48 continue;
49
50 assert(element.partitionType() == Dune::OverlapEntity);
51
52 // restrict the FvGeometry locally and bind to the element
53 fvGeometry.bind(element);
54 // loop over sub control faces
55 for (const auto& scvf : scvfs(fvGeometry))
56 {
57 if (scvf.isFrontal() && !scvf.boundary() && !scvf.processorBoundary())
58 {
59 const auto& ownScv = fvGeometry.scv(scvf.insideScvIdx());
60 const auto& facet = element.template subEntity <1> (ownScv.indexInElement());
61 if (facet.partitionType() == Dune::BorderEntity)
62 map_[ownScv.index()].push_back(scvf.outsideScvIdx());
63 }
64 }
65 }
66
67 for (const auto& element : elements(gridGeometry.gridView(), Dune::Partitions::interior))
68 {
69 fvGeometry.bind(element);
70
71 // loop over sub control faces
72 for (const auto& scvf : scvfs(fvGeometry))
73 {
74 assert(!scvf.processorBoundary());
75 const auto& ownScv = fvGeometry.scv(scvf.insideScvIdx());
76 const auto ownDofIndex = ownScv.dofIndex();
77 const auto ownScvIndex = ownScv.index();
78
79 if (scvf.isFrontal())
80 {
81 if (!scvf.boundary()) // opposite dof
82 map_[ownScvIndex].push_back(scvf.outsideScvIdx());
83 else
84 {
85 // treat frontal faces on boundaries
86 for (const auto& scv : scvs(fvGeometry))
87 {
88 const auto otherDofIndex = scv.dofIndex();
89 if (ownDofIndex != otherDofIndex)
90 map_[scv.index()].push_back(ownScvIndex);
91 }
92 }
93 }
94 else // lateral face
95 {
96 // the parallel DOF scv
97 // outsideScv insideScv
98 // ###y######|s|#####x####
99 // |c|
100 // |v|
101 // |f|
102 if (!scvf.boundary())
103 map_[ownScvIndex].push_back(scvf.outsideScvIdx());
104
105
106 // the normal DOF scv
107 //
108 // outsideScv
109 //
110 // |s|orthogonalScvf
111 // |c|
112 // |v| insideScv
113 // |f|
114 const auto& orthogonalScvf = fvGeometry.lateralOrthogonalScvf(scvf);
115 assert(orthogonalScvf.isLateral());
116 map_[ownScvIndex].push_back(orthogonalScvf.insideScvIdx());
117 if (!orthogonalScvf.boundary())
118 map_[ownScvIndex].push_back(orthogonalScvf.outsideScvIdx());
119 }
120 }
121 }
122
123 // make stencils unique
124 for (auto& stencil : map_)
125 {
126 std::sort(stencil.begin(), stencil.end());
127 stencil.erase(std::unique(stencil.begin(), stencil.end()), stencil.end());
128 }
129 }
130
131 const Stencil& operator[] (const GridIndexType globalI) const
132 { return map_[globalI]; }
133
134private:
135 Map map_;
136};
137
138} // end namespace Dumux
139
140#endif
Stores the dof indices corresponding to the neighboring scvs that contribute to the derivative calcul...
Definition: facecentered/staggered/connectivitymap.hh:30
void update(const GridGeometry &gridGeometry)
Update the map and prepare the stencils.
Definition: facecentered/staggered/connectivitymap.hh:39
const Stencil & operator[](const GridIndexType globalI) const
Definition: facecentered/staggered/connectivitymap.hh:131
GridCache::LocalView localView(const GridCache &gridCache)
Free function to get the local view of a grid cache object.
Definition: localview.hh:26
Defines the index types used for grid and local indices.
Definition: adapt.hh:17
typename GridView::IndexSet::IndexType GridIndex
Definition: indextraits.hh:27