deal.II version GIT relicensing-6809-ge913b9bb34 2026-09-25 17:20:01+00:00
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
fe_poly.h
Go to the documentation of this file.
1// -----------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
4// Copyright (C) 2004 - 2023 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Detailed license information governing the source code and contributions
9// can be found in LICENSE.md and CONTRIBUTING.md at the top level directory.
10//
11// -----------------------------------------------------------------------------
12
13#ifndef dealii_fe_poly_h
14#define dealii_fe_poly_h
15
16
17#include <deal.II/base/config.h>
18
21
22#include <deal.II/fe/fe.h>
23
24#include <memory>
25
27
72template <int dim, int spacedim = dim>
73class FE_Poly : public FiniteElement<dim, spacedim>
74{
75public:
80 const FiniteElementData<dim> &fe_data,
81 const std::vector<bool> &restriction_is_additive_flags,
82 const std::vector<ComponentMask> &nonzero_components);
83
87 FE_Poly(const FE_Poly &fe);
88
93 unsigned int
94 get_degree() const;
95
96 // for documentation, see the FiniteElement base class
97 virtual UpdateFlags
98 requires_update_flags(const UpdateFlags update_flags) const override;
99
105
115 std::vector<unsigned int>
117
124 std::vector<unsigned int>
126
132 virtual double
133 shape_value(const unsigned int i, const Point<dim> &p) const override;
134
145 virtual double
146 shape_value_component(const unsigned int i,
147 const Point<dim> &p,
148 const unsigned int component) const override;
149
155 virtual Tensor<1, dim>
156 shape_grad(const unsigned int i, const Point<dim> &p) const override;
157
168 virtual Tensor<1, dim>
169 shape_grad_component(const unsigned int i,
170 const Point<dim> &p,
171 const unsigned int component) const override;
172
178 virtual Tensor<2, dim>
179 shape_grad_grad(const unsigned int i, const Point<dim> &p) const override;
180
191 virtual Tensor<2, dim>
192 shape_grad_grad_component(const unsigned int i,
193 const Point<dim> &p,
194 const unsigned int component) const override;
195
201 virtual Tensor<3, dim>
202 shape_3rd_derivative(const unsigned int i,
203 const Point<dim> &p) const override;
204
215 virtual Tensor<3, dim>
216 shape_3rd_derivative_component(const unsigned int i,
217 const Point<dim> &p,
218 const unsigned int component) const override;
219
225 virtual Tensor<4, dim>
226 shape_4th_derivative(const unsigned int i,
227 const Point<dim> &p) const override;
228
239 virtual Tensor<4, dim>
240 shape_4th_derivative_component(const unsigned int i,
241 const Point<dim> &p,
242 const unsigned int component) const override;
243
247 virtual std::size_t
248 memory_consumption() const override;
249
250protected:
251 /*
252 * NOTE: The following function has its definition inlined into the class
253 * declaration because we otherwise run into a compiler error with MS Visual
254 * Studio.
255 */
256
257
258 virtual std::unique_ptr<
261 const UpdateFlags update_flags,
262 const Mapping<dim, spacedim> &mapping,
263 const Quadrature<dim> &quadrature,
265 spacedim>
266 &output_data) const override
267 {
268 (void)mapping;
269
270 // generate a new data object and
271 // initialize some fields
272 std::unique_ptr<typename FiniteElement<dim, spacedim>::InternalDataBase>
273 data_ptr = std::make_unique<InternalData>();
274 auto &data = dynamic_cast<InternalData &>(*data_ptr);
275 data.update_each = requires_update_flags(update_flags);
276
277 const unsigned int n_q_points = quadrature.size();
278
279 // initialize some scratch arrays. we need them for the underlying
280 // polynomial to put the values and derivatives of shape functions
281 // to put there, depending on what the user requested
282 std::vector<double> values(
283 update_flags & update_values ? this->n_dofs_per_cell() : 0);
284 std::vector<Tensor<1, dim>> grads(
285 update_flags & update_gradients ? this->n_dofs_per_cell() : 0);
286 std::vector<Tensor<2, dim>> grad_grads(
287 update_flags & update_hessians ? this->n_dofs_per_cell() : 0);
288 std::vector<Tensor<3, dim>> third_derivatives(
289 update_flags & update_3rd_derivatives ? this->n_dofs_per_cell() : 0);
290 std::vector<Tensor<4, dim>>
291 fourth_derivatives; // won't be needed, so leave empty
292
293 // now also initialize fields the fields of this class's own
294 // temporary storage, depending on what we need for the given
295 // update flags.
296 //
297 // there is one exception from the rule: if we are dealing with
298 // cells (i.e., if this function is not called via
299 // get_(sub)face_data()), then we can already store things in the
300 // final location where FEValues::reinit() later wants to see
301 // things. we then don't need the intermediate space. we determine
302 // whether we are on a cell by asking whether the number of
303 // elements in the output array equals the number of quadrature
304 // points (yes, it's a cell) or not (because in that case the
305 // number of quadrature points we use here equals the number of
306 // quadrature points summed over *all* faces or subfaces, whereas
307 // the number of output slots equals the number of quadrature
308 // points on only *one* face)
309 if ((update_flags & update_values) &&
310 !((output_data.shape_values.n_rows() > 0) &&
311 (output_data.shape_values.n_cols() == n_q_points)))
312 data.shape_values.reinit(this->n_dofs_per_cell(), n_q_points);
313
314 if (update_flags & update_gradients)
315 data.shape_gradients.reinit(this->n_dofs_per_cell(), n_q_points);
316
317 if (update_flags & update_hessians)
318 data.shape_hessians.reinit(this->n_dofs_per_cell(), n_q_points);
319
320 if (update_flags & update_3rd_derivatives)
321 data.shape_3rd_derivatives.reinit(this->n_dofs_per_cell(), n_q_points);
322
323 // next already fill those fields of which we have information by
324 // now. note that the shape gradients are only those on the unit
325 // cell, and need to be transformed when visiting an actual cell
326 if (update_flags & (update_values | update_gradients | update_hessians |
328 for (unsigned int i = 0; i < n_q_points; ++i)
329 {
330 poly_space->evaluate(quadrature.point(i),
331 values,
332 grads,
333 grad_grads,
334 third_derivatives,
335 fourth_derivatives);
336
337 // the values of shape functions at quadrature points don't change.
338 // consequently, write these values right into the output array if
339 // we can, i.e., if the output array has the correct size. this is
340 // the case on cells. on faces, we already precompute data on *all*
341 // faces and subfaces, but we later on copy only a portion of it
342 // into the output object; in that case, copy the data from all
343 // faces into the scratch object
344 if (update_flags & update_values)
345 if (output_data.shape_values.n_rows() > 0)
346 {
347 if (output_data.shape_values.n_cols() == n_q_points)
348 for (unsigned int k = 0; k < this->n_dofs_per_cell(); ++k)
349 output_data.shape_values[k][i] = values[k];
350 else
351 for (unsigned int k = 0; k < this->n_dofs_per_cell(); ++k)
352 data.shape_values[k][i] = values[k];
353 }
354
355 // for everything else, derivatives need to be transformed,
356 // so we write them into our scratch space and only later
357 // copy stuff into where FEValues wants it
358 if (update_flags & update_gradients)
359 for (unsigned int k = 0; k < this->n_dofs_per_cell(); ++k)
360 data.shape_gradients[k][i] = grads[k];
361
362 if (update_flags & update_hessians)
363 for (unsigned int k = 0; k < this->n_dofs_per_cell(); ++k)
364 data.shape_hessians[k][i] = grad_grads[k];
365
366 if (update_flags & update_3rd_derivatives)
367 for (unsigned int k = 0; k < this->n_dofs_per_cell(); ++k)
368 data.shape_3rd_derivatives[k][i] = third_derivatives[k];
369 }
370 return data_ptr;
371 }
372
373 virtual void
376 const CellSimilarity::Similarity cell_similarity,
377 const Quadrature<dim> &quadrature,
378 const Mapping<dim, spacedim> &mapping,
379 const typename Mapping<dim, spacedim>::InternalDataBase &mapping_internal,
381 &mapping_data,
382 const typename FiniteElement<dim, spacedim>::InternalDataBase &fe_internal,
384 spacedim>
385 &output_data) const override;
386
387 using FiniteElement<dim, spacedim>::fill_fe_face_values;
388
389 virtual void
392 const unsigned int face_no,
393 const hp::QCollection<dim - 1> &quadrature,
394 const Mapping<dim, spacedim> &mapping,
395 const typename Mapping<dim, spacedim>::InternalDataBase &mapping_internal,
397 &mapping_data,
398 const typename FiniteElement<dim, spacedim>::InternalDataBase &fe_internal,
400 spacedim>
401 &output_data) const override;
402
403 virtual void
406 const unsigned int face_no,
407 const unsigned int sub_no,
408 const Quadrature<dim - 1> &quadrature,
409 const Mapping<dim, spacedim> &mapping,
410 const typename Mapping<dim, spacedim>::InternalDataBase &mapping_internal,
412 &mapping_data,
413 const typename FiniteElement<dim, spacedim>::InternalDataBase &fe_internal,
415 spacedim>
416 &output_data) const override;
417
471
488 void
491 &output_data,
493 &mapping_data,
494 const unsigned int n_q_points) const;
495
518 void
521 &output_data,
523 &mapping_data,
524 const unsigned int n_q_points) const;
525
526
530 const std::unique_ptr<ScalarPolynomialsBase<dim>> poly_space;
531};
532
536
537#endif
Table< 2, double > shape_values
Definition fe_poly.h:436
Table< 2, Tensor< 3, dim > > shape_3rd_derivatives
Definition fe_poly.h:469
Table< 2, Tensor< 2, dim > > shape_hessians
Definition fe_poly.h:458
Table< 2, Tensor< 1, dim > > shape_gradients
Definition fe_poly.h:447
virtual Tensor< 2, dim > shape_grad_grad(const unsigned int i, const Point< dim > &p) const override
virtual Tensor< 2, dim > shape_grad_grad_component(const unsigned int i, const Point< dim > &p, const unsigned int component) const override
FE_Poly(const FE_Poly &fe)
virtual Tensor< 3, dim > shape_3rd_derivative_component(const unsigned int i, const Point< dim > &p, const unsigned int component) const override
std::vector< unsigned int > get_poly_space_numbering_inverse() const
virtual double shape_value_component(const unsigned int i, const Point< dim > &p, const unsigned int component) const override
virtual std::unique_ptr< typename FiniteElement< dim, spacedim >::InternalDataBase > get_data(const UpdateFlags update_flags, const Mapping< dim, spacedim > &mapping, const Quadrature< dim > &quadrature, ::internal::FEValuesImplementation::FiniteElementRelatedData< dim, spacedim > &output_data) const override
Definition fe_poly.h:260
FE_Poly(const ScalarPolynomialsBase< dim > &poly_space, const FiniteElementData< dim > &fe_data, const std::vector< bool > &restriction_is_additive_flags, const std::vector< ComponentMask > &nonzero_components)
void correct_hessians(internal::FEValuesImplementation::FiniteElementRelatedData< dim, spacedim > &output_data, const internal::FEValuesImplementation::MappingRelatedData< dim, spacedim > &mapping_data, const unsigned int n_q_points) const
virtual void fill_fe_values(const typename Triangulation< dim, spacedim >::cell_iterator &cell, const CellSimilarity::Similarity cell_similarity, const Quadrature< dim > &quadrature, const Mapping< dim, spacedim > &mapping, const typename Mapping< dim, spacedim >::InternalDataBase &mapping_internal, const internal::FEValuesImplementation::MappingRelatedData< dim, spacedim > &mapping_data, const typename FiniteElement< dim, spacedim >::InternalDataBase &fe_internal, ::internal::FEValuesImplementation::FiniteElementRelatedData< dim, spacedim > &output_data) const override
virtual Tensor< 1, dim > shape_grad(const unsigned int i, const Point< dim > &p) const override
unsigned int get_degree() const
const ScalarPolynomialsBase< dim > & get_poly_space() const
virtual Tensor< 4, dim > shape_4th_derivative_component(const unsigned int i, const Point< dim > &p, const unsigned int component) const override
void correct_third_derivatives(internal::FEValuesImplementation::FiniteElementRelatedData< dim, spacedim > &output_data, const internal::FEValuesImplementation::MappingRelatedData< dim, spacedim > &mapping_data, const unsigned int n_q_points) const
virtual double shape_value(const unsigned int i, const Point< dim > &p) const override
const std::unique_ptr< ScalarPolynomialsBase< dim > > poly_space
Definition fe_poly.h:530
virtual Tensor< 3, dim > shape_3rd_derivative(const unsigned int i, const Point< dim > &p) const override
virtual void fill_fe_face_values(const typename Triangulation< dim, spacedim >::cell_iterator &cell, const unsigned int face_no, const hp::QCollection< dim - 1 > &quadrature, const Mapping< dim, spacedim > &mapping, const typename Mapping< dim, spacedim >::InternalDataBase &mapping_internal, const internal::FEValuesImplementation::MappingRelatedData< dim, spacedim > &mapping_data, const typename FiniteElement< dim, spacedim >::InternalDataBase &fe_internal, ::internal::FEValuesImplementation::FiniteElementRelatedData< dim, spacedim > &output_data) const override
virtual UpdateFlags requires_update_flags(const UpdateFlags update_flags) const override
virtual Tensor< 4, dim > shape_4th_derivative(const unsigned int i, const Point< dim > &p) const override
std::vector< unsigned int > get_poly_space_numbering() const
virtual std::size_t memory_consumption() const override
virtual void fill_fe_subface_values(const typename Triangulation< dim, spacedim >::cell_iterator &cell, const unsigned int face_no, const unsigned int sub_no, const Quadrature< dim - 1 > &quadrature, const Mapping< dim, spacedim > &mapping, const typename Mapping< dim, spacedim >::InternalDataBase &mapping_internal, const internal::FEValuesImplementation::MappingRelatedData< dim, spacedim > &mapping_data, const typename FiniteElement< dim, spacedim >::InternalDataBase &fe_internal, ::internal::FEValuesImplementation::FiniteElementRelatedData< dim, spacedim > &output_data) const override
virtual Tensor< 1, dim > shape_grad_component(const unsigned int i, const Point< dim > &p, const unsigned int component) const override
unsigned int n_dofs_per_cell() const
const std::vector< bool > restriction_is_additive_flags
Definition fe.h:2713
const std::vector< ComponentMask > nonzero_components
Definition fe.h:2722
Abstract base class for mapping classes.
Definition mapping.h:318
Definition point.h:111
const Point< dim > & point(const unsigned int i) const
unsigned int size() const
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:38
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
UpdateFlags
@ update_hessians
Second derivatives of shape functions.
@ update_values
Shape function values.
@ update_3rd_derivatives
Third derivatives of shape functions.
@ update_gradients
Shape function gradients.
std::vector< index_type > data
Definition mpi.cc:734