| 1 |
// ------------------------------------------------------------------------ |
| 2 |
// |
| 3 |
// SPDX-License-Identifier: LGPL-2.1-or-later |
| 4 |
// Copyright (C) 2009 - 2024 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 |
#ifndef dealii_fe_poly_face_h |
| 16 |
#define dealii_fe_poly_face_h |
| 17 |
|
| 18 |
|
| 19 |
#include <deal.II/base/config.h> |
| 20 |
|
| 21 |
#include <deal.II/base/qprojector.h> |
| 22 |
|
| 23 |
#include <deal.II/fe/fe.h> |
| 24 |
|
| 25 |
#include <memory> |
| 26 |
|
| 27 |
DEAL_II_NAMESPACE_OPEN |
| 28 |
|
| 29 |
/** |
| 30 |
* @addtogroup fe |
| 31 |
* @{ |
| 32 |
*/ |
| 33 |
|
| 34 |
/** |
| 35 |
* @warning This class is not sufficiently tested yet! |
| 36 |
* |
| 37 |
* This class gives a unified framework for the implementation of |
| 38 |
* FiniteElement classes only located on faces of the mesh. They are based on |
| 39 |
* polynomial spaces like the TensorProductPolynomials or a PolynomialSpace |
| 40 |
* classes. |
| 41 |
* |
| 42 |
* Every class that implements the following functions can be used as template |
| 43 |
* parameter PolynomialType. |
| 44 |
* |
| 45 |
* @code |
| 46 |
* double compute_value (const unsigned int i, |
| 47 |
* const Point<dim> &p) const; |
| 48 |
* @endcode |
| 49 |
* Example classes are TensorProductPolynomials, PolynomialSpace or |
| 50 |
* PolynomialsP. |
| 51 |
* |
| 52 |
* This class is not a fully implemented FiniteElement class. Instead there |
| 53 |
* are several pure virtual functions declared in the FiniteElement class |
| 54 |
* which cannot be implemented by this class but are left for implementation |
| 55 |
* in derived classes. |
| 56 |
*/ |
| 57 |
template <typename PolynomialType, |
| 58 |
int dim = PolynomialType::dimension + 1, |
| 59 |
int spacedim = dim> |
| 60 |
class FE_PolyFace : public FiniteElement<dim, spacedim> |
| 61 |
{ |
| 62 |
public: |
| 63 |
/** |
| 64 |
* Constructor. |
| 65 |
*/ |
| 66 |
FE_PolyFace(const PolynomialType &poly_space, |
| 67 |
const FiniteElementData<dim> &fe_data, |
| 68 |
const std::vector<bool> &restriction_is_additive_flags); |
| 69 |
|
| 70 |
/** |
| 71 |
* Return the polynomial degree of this finite element, i.e. the value |
| 72 |
* passed to the constructor. |
| 73 |
*/ |
| 74 |
unsigned int |
| 75 |
get_degree() const; |
| 76 |
|
| 77 |
// for documentation, see the FiniteElement base class |
| 78 |
virtual UpdateFlags |
| 79 |
requires_update_flags(const UpdateFlags update_flags) const override; |
| 80 |
|
| 81 |
protected: |
| 82 |
/* |
| 83 |
* NOTE: The following functions have their definitions inlined into the class |
| 84 |
* declaration because we otherwise run into a compiler error with MS Visual |
| 85 |
* Studio. |
| 86 |
*/ |
| 87 |
|
| 88 |
|
| 89 |
virtual std::unique_ptr< |
| 90 |
typename FiniteElement<dim, spacedim>::InternalDataBase> |
| 91 |
get_data( |
| 92 |
const UpdateFlags update_flags, |
| 93 |
const Mapping<dim, spacedim> &mapping, |
| 94 |
const Quadrature<dim> &quadrature, |
| 95 |
dealii::internal::FEValuesImplementation::FiniteElementRelatedData<dim, |
| 96 |
spacedim> |
| 97 |
&output_data) const override |
| 98 |
{ |
| 99 |
(void)update_flags; |
| 100 |
(void)mapping; |
| 101 |
(void)quadrature; |
| 102 |
(void)output_data; |
| 103 |
return std::make_unique<InternalData>(); |
| 104 |
} |
| 105 |
|
| 106 |
using FiniteElement<dim, spacedim>::get_face_data; |
| 107 |
|
| 108 |
std::unique_ptr<typename FiniteElement<dim, spacedim>::InternalDataBase> |
| 109 |
get_face_data( |
| 110 |
const UpdateFlags update_flags, |
| 111 |
const Mapping<dim, spacedim> &mapping, |
| 112 |
const hp::QCollection<dim - 1> &quadrature, |
| 113 |
dealii::internal::FEValuesImplementation::FiniteElementRelatedData<dim, |
| 114 |
spacedim> |
| 115 |
&output_data) const override |
| 116 |
{ |
| 117 |
(void)mapping; |
| 118 |
(void)output_data; |
| 119 |
AssertDimension(quadrature.size(), 1); |
| 120 |
|
| 121 |
// generate a new data object and |
| 122 |
// initialize some fields |
| 123 |
std::unique_ptr<typename FiniteElement<dim, spacedim>::InternalDataBase> |
| 124 |
data_ptr = std::make_unique<InternalData>(); |
| 125 |
auto &data = dynamic_cast<InternalData &>(*data_ptr); |
| 126 |
data.update_each = requires_update_flags(update_flags); |
| 127 |
|
| 128 |
const unsigned int n_q_points = quadrature[0].size(); |
| 129 |
|
| 130 |
// some scratch arrays |
| 131 |
std::vector<double> values(0); |
| 132 |
std::vector<Tensor<1, dim - 1>> grads(0); |
| 133 |
std::vector<Tensor<2, dim - 1>> grad_grads(0); |
| 134 |
std::vector<Tensor<3, dim - 1>> empty_vector_of_3rd_order_tensors; |
| 135 |
std::vector<Tensor<4, dim - 1>> empty_vector_of_4th_order_tensors; |
| 136 |
|
| 137 |
// initialize fields only if really |
| 138 |
// necessary. otherwise, don't |
| 139 |
// allocate memory |
| 140 |
if (data.update_each & update_values) |
| 141 |
{ |
| 142 |
values.resize(poly_space.n()); |
| 143 |
data.shape_values.resize(poly_space.n(), |
| 144 |
std::vector<double>(n_q_points)); |
| 145 |
for (unsigned int i = 0; i < n_q_points; ++i) |
| 146 |
{ |
| 147 |
poly_space.evaluate(quadrature[0].point(i), |
| 148 |
values, |
| 149 |
grads, |
| 150 |
grad_grads, |
| 151 |
empty_vector_of_3rd_order_tensors, |
| 152 |
empty_vector_of_4th_order_tensors); |
| 153 |
|
| 154 |
for (unsigned int k = 0; k < poly_space.n(); ++k) |
| 155 |
data.shape_values[k][i] = values[k]; |
| 156 |
} |
| 157 |
} |
| 158 |
// No derivatives of this element |
| 159 |
// are implemented. |
| 160 |
if (data.update_each & update_gradients || |
| 161 |
data.update_each & update_hessians) |
| 162 |
{ |
| 163 |
DEAL_II_NOT_IMPLEMENTED(); |
| 164 |
} |
| 165 |
|
| 166 |
return data_ptr; |
| 167 |
} |
| 168 |
|
| 169 |
std::unique_ptr<typename FiniteElement<dim, spacedim>::InternalDataBase> |
| 170 |
get_subface_data( |
| 171 |
const UpdateFlags update_flags, |
| 172 |
const Mapping<dim, spacedim> &mapping, |
| 173 |
const Quadrature<dim - 1> &quadrature, |
| 174 |
dealii::internal::FEValuesImplementation::FiniteElementRelatedData<dim, |
| 175 |
spacedim> |
| 176 |
&output_data) const override |
| 177 |
{ |
| 178 |
return get_face_data( |
| 179 |
update_flags, |
| 180 |
mapping, |
| 181 |
hp::QCollection<dim - 1>(QProjector<dim - 1>::project_to_all_children( |
| 182 |
ReferenceCells::get_hypercube<dim - 1>(), quadrature)), |
| 183 |
output_data); |
| 184 |
} |
| 185 |
|
| 186 |
virtual void |
| 187 |
fill_fe_values( |
| 188 |
const typename Triangulation<dim, spacedim>::cell_iterator &cell, |
| 189 |
const CellSimilarity::Similarity cell_similarity, |
| 190 |
const Quadrature<dim> &quadrature, |
| 191 |
const Mapping<dim, spacedim> &mapping, |
| 192 |
const typename Mapping<dim, spacedim>::InternalDataBase &mapping_internal, |
| 193 |
const internal::FEValuesImplementation::MappingRelatedData<dim, spacedim> |
| 194 |
&mapping_data, |
| 195 |
const typename FiniteElement<dim, spacedim>::InternalDataBase &fe_internal, |
| 196 |
dealii::internal::FEValuesImplementation::FiniteElementRelatedData<dim, |
| 197 |
spacedim> |
| 198 |
&output_data) const override; |
| 199 |
|
| 200 |
using FiniteElement<dim, spacedim>::fill_fe_face_values; |
| 201 |
|
| 202 |
virtual void |
| 203 |
fill_fe_face_values( |
| 204 |
const typename Triangulation<dim, spacedim>::cell_iterator &cell, |
| 205 |
const unsigned int face_no, |
| 206 |
const hp::QCollection<dim - 1> &quadrature, |
| 207 |
const Mapping<dim, spacedim> &mapping, |
| 208 |
const typename Mapping<dim, spacedim>::InternalDataBase &mapping_internal, |
| 209 |
const internal::FEValuesImplementation::MappingRelatedData<dim, spacedim> |
| 210 |
&mapping_data, |
| 211 |
const typename FiniteElement<dim, spacedim>::InternalDataBase &fe_internal, |
| 212 |
dealii::internal::FEValuesImplementation::FiniteElementRelatedData<dim, |
| 213 |
spacedim> |
| 214 |
&output_data) const override; |
| 215 |
|
| 216 |
virtual void |
| 217 |
fill_fe_subface_values( |
| 218 |
const typename Triangulation<dim, spacedim>::cell_iterator &cell, |
| 219 |
const unsigned int face_no, |
| 220 |
const unsigned int sub_no, |
| 221 |
const Quadrature<dim - 1> &quadrature, |
| 222 |
const Mapping<dim, spacedim> &mapping, |
| 223 |
const typename Mapping<dim, spacedim>::InternalDataBase &mapping_internal, |
| 224 |
const internal::FEValuesImplementation::MappingRelatedData<dim, spacedim> |
| 225 |
&mapping_data, |
| 226 |
const typename FiniteElement<dim, spacedim>::InternalDataBase &fe_internal, |
| 227 |
dealii::internal::FEValuesImplementation::FiniteElementRelatedData<dim, |
| 228 |
spacedim> |
| 229 |
&output_data) const override; |
| 230 |
|
| 231 |
/** |
| 232 |
* Fields of cell-independent data. |
| 233 |
* |
| 234 |
* For information about the general purpose of this class, see the |
| 235 |
* documentation of the base class. |
| 236 |
*/ |
| 237 |
class InternalData : public FiniteElement<dim, spacedim>::InternalDataBase |
| 238 |
{ |
| 239 |
public: |
| 240 |
/** |
| 241 |
* Array with shape function values in quadrature points on one face. |
| 242 |
* There is one row for each shape function, containing values for each |
| 243 |
* quadrature point. |
| 244 |
* |
| 245 |
* In this array, we store the values of the shape function in the |
| 246 |
* quadrature points on one face of the unit cell. Since these values do |
| 247 |
* not change under transformation to the real cell, we only need to copy |
| 248 |
* them over when visiting a concrete cell. |
| 249 |
* |
| 250 |
* In particular, we can simply copy the same set of values to each of the |
| 251 |
* faces. |
| 252 |
*/ |
| 253 |
std::vector<std::vector<double>> shape_values; |
| 254 |
}; |
| 255 |
|
| 256 |
/** |
| 257 |
* The polynomial space. Its type is given by the template parameter |
| 258 |
* PolynomialType. |
| 259 |
*/ |
| 260 |
PolynomialType poly_space; |
| 261 |
}; |
| 262 |
|
| 263 |
/** @} */ |
| 264 |
|
| 265 |
DEAL_II_NAMESPACE_CLOSE |
| 266 |
|
| 267 |
#endif |