| 1 |
// ------------------------------------------------------------------------ |
| 2 |
// |
| 3 |
// SPDX-License-Identifier: LGPL-2.1-or-later |
| 4 |
// Copyright (C) 2018 - 2025 by the deal.II authors |
| 5 |
// |
| 6 |
// This file is part of the deal.II library. |
| 7 |
// |
| 8 |
// Part of the source code is dual licensed under Apache-2.0 WITH |
| 9 |
// LLVM-exception OR LGPL-2.1-or-later. Detailed license information |
| 10 |
// governing the source code and code contributions can be found in |
| 11 |
// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II. |
| 12 |
// |
| 13 |
// ------------------------------------------------------------------------ |
| 14 |
|
| 15 |
|
| 16 |
#ifndef dealii_matrix_free_face_info_h |
| 17 |
#define dealii_matrix_free_face_info_h |
| 18 |
|
| 19 |
|
| 20 |
#include <deal.II/base/config.h> |
| 21 |
|
| 22 |
#include <deal.II/base/exceptions.h> |
| 23 |
#include <deal.II/base/memory_consumption.h> |
| 24 |
#include <deal.II/base/table.h> |
| 25 |
|
| 26 |
|
| 27 |
DEAL_II_NAMESPACE_OPEN |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
namespace internal |
| 32 |
{ |
| 33 |
namespace MatrixFreeFunctions |
| 34 |
{ |
| 35 |
/** |
| 36 |
* Data type for information about the batches build for vectorization of |
| 37 |
* the face integrals. The setup of the batches for the faces is |
| 38 |
* independent of the cells, and thus, we must store the relation to the |
| 39 |
* cell indexing for accessing the degrees of freedom. |
| 40 |
* |
| 41 |
* Interior faces are stored by the two adjacent cells, which we label as |
| 42 |
* "interior" and "exterior" side of the face. Normal vectors stored in |
| 43 |
* MappingInfo are only stored once and are the outer normals to the cells |
| 44 |
* on the "interior" side, whereas the sign is the opposite for the |
| 45 |
* "exterior" side. |
| 46 |
* |
| 47 |
* This data field is stored as a vector for all faces involved in the |
| 48 |
* computation. In order to avoid gaps in the memory representation, the |
| 49 |
* four 'char' variables are put next to each other which occupies the |
| 50 |
* same size as the unsigned integers on most architectures. |
| 51 |
*/ |
| 52 |
template <int vectorization_width> |
| 53 |
struct FaceToCellTopology |
| 54 |
{ |
| 55 |
/** |
| 56 |
* Indices of the faces in the current face batch as compared to the |
| 57 |
* numbers of the cells on the logical "interior" side of the face which |
| 58 |
* is aligned to the direction of FEEvaluation::normal_vector(). |
| 59 |
*/ |
| 60 |
std::array<unsigned int, vectorization_width> cells_interior; |
| 61 |
|
| 62 |
/** |
| 63 |
* Indices of the faces in the current face batch as compared to the |
| 64 |
* numbers of the cells on the logical "exterior" side of the face which |
| 65 |
* is aligned to the opposite direction of |
| 66 |
* FEEvaluation::normal_vector(). Note that the distinction into |
| 67 |
* interior and exterior faces is purely logical and refers to the |
| 68 |
* direction of the normal only. In the actual discretization of a |
| 69 |
* problem, the discretization typically needs to make sure that interior |
| 70 |
* and exterior sides are treated properly, such as with upwind fluxes. |
| 71 |
* |
| 72 |
* For boundary faces, the numbers are set to |
| 73 |
* `numbers::invalid_unsigned_int`. |
| 74 |
*/ |
| 75 |
std::array<unsigned int, vectorization_width> cells_exterior; |
| 76 |
|
| 77 |
/** |
| 78 |
* Index of the face between 0 and GeometryInfo::faces_per_cell within |
| 79 |
* the cells on the "exterior" side of the faces. |
| 80 |
* |
| 81 |
* For a boundary face, this data field stores the boundary id. |
| 82 |
*/ |
| 83 |
types::boundary_id exterior_face_no; |
| 84 |
|
| 85 |
/** |
| 86 |
* Index of the face between 0 and GeometryInfo::faces_per_cell within |
| 87 |
* the cells on the "interior" side of the faces. |
| 88 |
*/ |
| 89 |
unsigned char interior_face_no; |
| 90 |
|
| 91 |
/** |
| 92 |
* For adaptively refined meshes, the cell on the exterior side of the |
| 93 |
* face might be less refined than the interior side. This index |
| 94 |
* indicates the possible subface index on the exterior side. |
| 95 |
*/ |
| 96 |
unsigned char subface_index; |
| 97 |
|
| 98 |
/** |
| 99 |
* In 3d, one of the two cells adjacent to a face might use a different |
| 100 |
* orientation (also called as face orientation, face rotation and face |
| 101 |
* flip) than the standard orientation. This variable stores the |
| 102 |
* values of face orientation, face flip and face |
| 103 |
* rotation (for one of the interior or exterior side) for the present |
| 104 |
* batch of faces in the first free bits. The forth bit is one if the |
| 105 |
* internal cell has non-standard orientation. |
| 106 |
* |
| 107 |
* @note In contrast to other place in the library, the face-orientation |
| 108 |
* bit (first bit) is flipped. |
| 109 |
*/ |
| 110 |
unsigned char face_orientation; |
| 111 |
|
| 112 |
/** |
| 113 |
* Reference-cell type of the given face: 0 for line or quadrilateral, |
| 114 |
* 1 for triangle. |
| 115 |
*/ |
| 116 |
unsigned char face_type; |
| 117 |
|
| 118 |
/** |
| 119 |
* Return the memory consumption of the present data structure. |
| 120 |
*/ |
| 121 |
std::size_t |
| 122 |
memory_consumption() const |
| 123 |
{ |
| 124 |
return sizeof(*this); |
| 125 |
} |
| 126 |
}; |
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
/** |
| 131 |
* A data structure that holds the connectivity between the faces and the |
| 132 |
* cells. |
| 133 |
*/ |
| 134 |
template <int vectorization_width> |
| 135 |
struct FaceInfo |
| 136 |
{ |
| 137 |
/** |
| 138 |
* Clear all data fields to be in a state similar to after having |
| 139 |
* called the default constructor. |
| 140 |
*/ |
| 141 |
void |
| 142 |
clear() |
| 143 |
{ |
| 144 |
faces.clear(); |
| 145 |
cell_and_face_to_plain_faces.reinit(TableIndices<3>(0, 0, 0)); |
| 146 |
cell_and_face_boundary_id.reinit(TableIndices<3>(0, 0, 0)); |
| 147 |
} |
| 148 |
|
| 149 |
/** |
| 150 |
* Return the memory consumption of the present data structure. |
| 151 |
*/ |
| 152 |
std::size_t |
| 153 |
memory_consumption() const |
| 154 |
{ |
| 155 |
return sizeof(faces) + |
| 156 |
cell_and_face_to_plain_faces.memory_consumption() + |
| 157 |
cell_and_face_boundary_id.memory_consumption(); |
| 158 |
} |
| 159 |
|
| 160 |
/** |
| 161 |
* Vectorized storage of interior faces, linking to the two cells in the |
| 162 |
* vectorized cell storage. |
| 163 |
*/ |
| 164 |
std::vector<FaceToCellTopology<vectorization_width>> faces; |
| 165 |
|
| 166 |
/** |
| 167 |
* This table translates a triple of the cell-batch number number, the |
| 168 |
* index of a face within a cell and the index within the cell batch of |
| 169 |
* vectorization |
| 170 |
* into the index within the @p faces array. |
| 171 |
*/ |
| 172 |
::dealii::Table<3, unsigned int> cell_and_face_to_plain_faces; |
| 173 |
|
| 174 |
/** |
| 175 |
* Stores the boundary ids of the faces in vectorized format using the |
| 176 |
* same indexing as the cell_and_face_to_plain_faces data structure |
| 177 |
*/ |
| 178 |
::dealii::Table<3, types::boundary_id> cell_and_face_boundary_id; |
| 179 |
}; |
| 180 |
} // end of namespace MatrixFreeFunctions |
| 181 |
} // end of namespace internal |
| 182 |
|
| 183 |
DEAL_II_NAMESPACE_CLOSE |
| 184 |
|
| 185 |
#endif |