Debian Codegraph @

include/deal.II/matrix_free/fe_point_evaluation.h

raw
1 // ------------------------------------------------------------------------
2 //
3 // SPDX-License-Identifier: LGPL-2.1-or-later
4 // Copyright (C) 2020 - 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 #ifndef dealii_fe_point_evaluation_h
16 #define dealii_fe_point_evaluation_h
17
18 #include <deal.II/base/config.h>
19
20 #include <deal.II/base/array_view.h>
21 #include <deal.II/base/exceptions.h>
22 #include <deal.II/base/polynomial.h>
23 #include <deal.II/base/signaling_nan.h>
24 #include <deal.II/base/tensor.h>
25 #include <deal.II/base/vectorization.h>
26
27 #include <deal.II/fe/fe_values.h>
28 #include <deal.II/fe/mapping.h>
29
30 #include <deal.II/matrix_free/evaluation_flags.h>
31 #include <deal.II/matrix_free/evaluation_kernels_face.h>
32 #include <deal.II/matrix_free/mapping_info_storage.h>
33 #include <deal.II/matrix_free/shape_info.h>
34 #include <deal.II/matrix_free/tensor_product_point_kernels.h>
35
36 #include <deal.II/non_matching/mapping_info.h>
37
38 DEAL_II_NAMESPACE_OPEN
39
40 namespace internal
41 {
42 namespace FEPointEvaluation
43 {
44 DeclException1(
45 ExcFEPointEvaluationAccessToUninitializedMappingField,
46 std::string,
47 << "You are requesting information from an FEPointEvaluationBase "
48 << "object for which this kind of information has not been computed. "
49 << "What information these objects compute is determined by the update_* "
50 << "flags you pass to MappingInfo() in the Constructor. Here, "
51 << "the operation you are attempting requires the <" << arg1
52 << "> flag to be set, but it was apparently not specified "
53 << "upon initialization.");
54
55 /**
56 * Struct to distinguish between the value and gradient types of different
57 * numbers of components used by the FlexibleEvaluator class.
58 */
59 template <int dim,
60 int spacedim,
61 int n_components,
62 typename Number,
63 typename Enable = void>
64 struct EvaluatorTypeTraits
65 {
66 using ScalarNumber =
67 typename internal::VectorizedArrayTrait<Number>::value_type;
68 using VectorizedArrayType =
69 typename dealii::internal::VectorizedArrayTrait<
70 Number>::vectorized_value_type;
71 using value_type = Tensor<1, n_components, Number>;
72 using scalar_value_type = Tensor<1, n_components, ScalarNumber>;
73 using vectorized_value_type =
74 Tensor<1, n_components, VectorizedArrayType>;
75 using unit_gradient_type =
76 Tensor<1, n_components, Tensor<1, dim, Number>>;
77 using real_gradient_type = std::conditional_t<
78 n_components == spacedim,
79 Tensor<2, spacedim, Number>,
80 Tensor<1, n_components, Tensor<1, spacedim, Number>>>;
81 using scalar_unit_gradient_type =
82 Tensor<1, n_components, Tensor<1, dim, ScalarNumber>>;
83 using vectorized_unit_gradient_type =
84 Tensor<1, n_components, Tensor<1, dim, VectorizedArrayType>>;
85 using interface_vectorized_unit_gradient_type =
86 Tensor<1, dim, Tensor<1, n_components, VectorizedArrayType>>;
87
88 static void
89 read_value(const ScalarNumber vector_entry,
90 const unsigned int component,
91 scalar_value_type &result)
92 {
93 AssertIndexRange(component, n_components);
94 result[component] = vector_entry;
95 }
96
97 static scalar_value_type
98 sum_value(const scalar_value_type &result)
99 {
100 return result;
101 }
102
103 static scalar_value_type
104 sum_value(const vectorized_value_type &result)
105 {
106 scalar_value_type result_scalar = {};
107
108 for (unsigned int c = 0; c < n_components; ++c)
109 result_scalar[c] = result[c].sum();
110
111 return result_scalar;
112 }
113
114 static ScalarNumber
115 sum_value(const unsigned int component,
116 const vectorized_value_type &result)
117 {
118 AssertIndexRange(component, n_components);
119 return result[component].sum();
120 }
121
122 static void
123 set_gradient(const interface_vectorized_unit_gradient_type &value,
124 const unsigned int vector_lane,
125 unit_gradient_type &result)
126 {
127 for (unsigned int i = 0; i < n_components; ++i)
128 for (unsigned int d = 0; d < dim; ++d)
129 result[i][d] =
130 internal::VectorizedArrayTrait<Number>::get_from_vectorized(
131 value[d][i], vector_lane);
132 }
133
134 static void
135 get_gradient(interface_vectorized_unit_gradient_type &value,
136 const unsigned int vector_lane,
137 const unit_gradient_type &result)
138 {
139 for (unsigned int i = 0; i < n_components; ++i)
140 for (unsigned int d = 0; d < dim; ++d)
141 internal::VectorizedArrayTrait<Number>::get_from_vectorized(
142 value[d][i], vector_lane) = result[i][d];
143 }
144
145 static void
146 get_gradient(interface_vectorized_unit_gradient_type &value,
147 const unsigned int vector_lane,
148 const DerivativeForm<1, dim, n_components, Number> &result)
149 {
150 for (unsigned int i = 0; i < n_components; ++i)
151 for (unsigned int d = 0; d < dim; ++d)
152 internal::VectorizedArrayTrait<Number>::get_from_vectorized(
153 value[d][i], vector_lane) = result[i][d];
154 }
155
156 static void
157 set_zero_gradient(real_gradient_type &value,
158 const unsigned int vector_lane)
159 {
160 for (unsigned int i = 0; i < n_components; ++i)
161 for (unsigned int d = 0; d < spacedim; ++d)
162 internal::VectorizedArrayTrait<Number>::get(value[i][d],
163 vector_lane) = 0.;
164 }
165
166 static void
167 set_value(const vectorized_value_type &value,
168 const unsigned int vector_lane,
169 scalar_value_type &result)
170 {
171 for (unsigned int i = 0; i < n_components; ++i)
172 result[i] = value[i][vector_lane];
173 }
174
175 static void
176 set_value(const vectorized_value_type &value,
177 const unsigned int,
178 vectorized_value_type &result)
179 {
180 result = value;
181 }
182
183 static void
184 get_value(vectorized_value_type &value,
185 const unsigned int vector_lane,
186 const scalar_value_type &result)
187 {
188 for (unsigned int i = 0; i < n_components; ++i)
189 value[i][vector_lane] = result[i];
190 }
191
192 static void
193 get_value(vectorized_value_type &value,
194 const unsigned int,
195 const vectorized_value_type &result)
196 {
197 value = result;
198 }
199
200 static void
201 set_zero_value(value_type &value, const unsigned int vector_lane)
202 {
203 for (unsigned int i = 0; i < n_components; ++i)
204 internal::VectorizedArrayTrait<Number>::get(value[i], vector_lane) =
205 0.;
206 }
207
208 static void
209 access(value_type &value,
210 const unsigned int vector_lane,
211 const unsigned int component,
212 const ScalarNumber &shape_value)
213 {
214 internal::VectorizedArrayTrait<Number>::get(value[component],
215 vector_lane) += shape_value;
216 }
217
218 static ScalarNumber
219 access(const value_type &value,
220 const unsigned int vector_lane,
221 const unsigned int component)
222 {
223 return internal::VectorizedArrayTrait<Number>::get(value[component],
224 vector_lane);
225 }
226
227 static void
228 access(real_gradient_type &value,
229 const unsigned int vector_lane,
230 const unsigned int component,
231 const Tensor<1, spacedim, ScalarNumber> &shape_gradient)
232 {
233 for (unsigned int d = 0; d < spacedim; ++d)
234 internal::VectorizedArrayTrait<Number>::get(value[component][d],
235 vector_lane) +=
236 shape_gradient[d];
237 }
238
239 static Tensor<1, spacedim, ScalarNumber>
240 access(const real_gradient_type &value,
241 const unsigned int vector_lane,
242 const unsigned int component)
243 {
244 Tensor<1, spacedim, ScalarNumber> result;
245 for (unsigned int d = 0; d < spacedim; ++d)
246 result[d] =
247 internal::VectorizedArrayTrait<Number>::get(value[component][d],
248 vector_lane);
249 return result;
250 }
251 };
252
253 template <int dim, int spacedim, typename Number>
254 struct EvaluatorTypeTraits<dim, spacedim, 1, Number>
255 {
256 using ScalarNumber =
257 typename internal::VectorizedArrayTrait<Number>::value_type;
258 using VectorizedArrayType =
259 typename dealii::internal::VectorizedArrayTrait<
260 Number>::vectorized_value_type;
261 using value_type = Number;
262 using scalar_value_type = ScalarNumber;
263 using vectorized_value_type = VectorizedArrayType;
264 using unit_gradient_type = Tensor<1, dim, Number>;
265 using real_gradient_type = Tensor<1, spacedim, Number>;
266 using scalar_unit_gradient_type = Tensor<1, dim, ScalarNumber>;
267 using vectorized_unit_gradient_type = Tensor<1, dim, VectorizedArrayType>;
268 using interface_vectorized_unit_gradient_type =
269 vectorized_unit_gradient_type;
270
271 static void
272 read_value(const ScalarNumber vector_entry,
273 const unsigned int,
274 scalar_value_type &result)
275 {
276 result = vector_entry;
277 }
278
279 static scalar_value_type
280 sum_value(const scalar_value_type &result)
281 {
282 return result;
283 }
284
285 static scalar_value_type
286 sum_value(const vectorized_value_type &result)
287 {
288 return result.sum();
289 }
290
291 static ScalarNumber
292 sum_value(const unsigned int, const vectorized_value_type &result)
293 {
294 return result.sum();
295 }
296
297 static void
298 set_gradient(const vectorized_unit_gradient_type &value,
299 const unsigned int vector_lane,
300 scalar_unit_gradient_type &result)
301 {
302 for (unsigned int d = 0; d < dim; ++d)
303 result[d] = value[d][vector_lane];
304 }
305
306 static void
307 set_gradient(const vectorized_unit_gradient_type &value,
308 const unsigned int,
309 vectorized_unit_gradient_type &result)
310 {
311 result = value;
312 }
313
314 static void
315 get_gradient(vectorized_unit_gradient_type &value,
316 const unsigned int vector_lane,
317 const scalar_unit_gradient_type &result)
318 {
319 for (unsigned int d = 0; d < dim; ++d)
320 value[d][vector_lane] = result[d];
321 }
322
323 static void
324 get_gradient(vectorized_unit_gradient_type &value,
325 const unsigned int,
326 const vectorized_unit_gradient_type &result)
327 {
328 value = result;
329 }
330
331 static void
332 set_zero_gradient(real_gradient_type &value,
333 const unsigned int vector_lane)
334 {
335 for (unsigned int d = 0; d < spacedim; ++d)
336 internal::VectorizedArrayTrait<Number>::get(value[d], vector_lane) =
337 0.;
338 }
339
340 static void
341 set_value(const vectorized_value_type &value,
342 const unsigned int vector_lane,
343 scalar_value_type &result)
344 {
345 result = value[vector_lane];
346 }
347
348 static void
349 set_value(const vectorized_value_type &value,
350 const unsigned int,
351 vectorized_value_type &result)
352 {
353 result = value;
354 }
355
356 static void
357 get_value(vectorized_value_type &value,
358 const unsigned int vector_lane,
359 const scalar_value_type &result)
360 {
361 value[vector_lane] = result;
362 }
363
364 static void
365 get_value(vectorized_value_type &value,
366 const unsigned int,
367 const vectorized_value_type &result)
368 {
369 value = result;
370 }
371
372 static void
373 set_zero_value(value_type &value, const unsigned int vector_lane)
374 {
375 internal::VectorizedArrayTrait<Number>::get(value, vector_lane) = 0.;
376 }
377
378 static void
379 access(value_type &value,
380 const unsigned int vector_lane,
381 const unsigned int,
382 const ScalarNumber &shape_value)
383 {
384 internal::VectorizedArrayTrait<Number>::get(value, vector_lane) +=
385 shape_value;
386 }
387
388 static ScalarNumber
389 access(const value_type &value,
390 const unsigned int vector_lane,
391 const unsigned int)
392 {
393 return internal::VectorizedArrayTrait<Number>::get(value, vector_lane);
394 }
395
396 static void
397 access(real_gradient_type &value,
398 const unsigned int vector_lane,
399 const unsigned int,
400 const Tensor<1, spacedim, ScalarNumber> &shape_gradient)
401 {
402 for (unsigned int d = 0; d < spacedim; ++d)
403 internal::VectorizedArrayTrait<Number>::get(value[d], vector_lane) +=
404 shape_gradient[d];
405 }
406
407 static Tensor<1, spacedim, ScalarNumber>
408 access(const real_gradient_type &value,
409 const unsigned int vector_lane,
410 const unsigned int)
411 {
412 Tensor<1, spacedim, ScalarNumber> result;
413 for (unsigned int d = 0; d < spacedim; ++d)
414 result[d] =
415 internal::VectorizedArrayTrait<Number>::get(value[d], vector_lane);
416 return result;
417 }
418 };
419
420 template <int dim, typename Number>
421 struct EvaluatorTypeTraits<dim,
422 dim,
423 dim,
424 Number,
425 std::enable_if_t<dim != 1>>
426 {
427 using ScalarNumber =
428 typename internal::VectorizedArrayTrait<Number>::value_type;
429 using VectorizedArrayType =
430 typename dealii::internal::VectorizedArrayTrait<
431 Number>::vectorized_value_type;
432 using value_type = Tensor<1, dim, Number>;
433 using scalar_value_type = Tensor<1, dim, ScalarNumber>;
434 using vectorized_value_type = Tensor<1, dim, VectorizedArrayType>;
435 using unit_gradient_type = Tensor<2, dim, Number>;
436 using real_gradient_type = unit_gradient_type;
437 using scalar_unit_gradient_type = Tensor<2, dim, ScalarNumber>;
438 using vectorized_unit_gradient_type = Tensor<2, dim, VectorizedArrayType>;
439 using interface_vectorized_unit_gradient_type =
440 Tensor<1, dim, Tensor<1, dim, VectorizedArrayType>>;
441
442 static void
443 read_value(const ScalarNumber vector_entry,
444 const unsigned int component,
445 scalar_value_type &result)
446 {
447 AssertIndexRange(component, dim);
448 result[component] = vector_entry;
449 }
450
451 static scalar_value_type
452 sum_value(const scalar_value_type &result)
453 {
454 return result;
455 }
456
457 static scalar_value_type
458 sum_value(const vectorized_value_type &result)
459 {
460 scalar_value_type result_scalar = {};
461
462 for (unsigned int c = 0; c < dim; ++c)
463 result_scalar[c] = result[c].sum();
464
465 return result_scalar;
466 }
467
468 static ScalarNumber
469 sum_value(const unsigned int component,
470 const vectorized_value_type &result)
471 {
472 AssertIndexRange(component, dim);
473 return result[component].sum();
474 }
475
476 static void
477 set_gradient(const interface_vectorized_unit_gradient_type &value,
478 const unsigned int vector_lane,
479 unit_gradient_type &result)
480 {
481 for (unsigned int i = 0; i < dim; ++i)
482 for (unsigned int d = 0; d < dim; ++d)
483 result[i][d] =
484 internal::VectorizedArrayTrait<Number>::get_from_vectorized(
485 value[d][i], vector_lane);
486 }
487
488 static void
489 get_gradient(interface_vectorized_unit_gradient_type &value,
490 const unsigned int vector_lane,
491 const unit_gradient_type &result)
492 {
493 for (unsigned int i = 0; i < dim; ++i)
494 for (unsigned int d = 0; d < dim; ++d)
495 internal::VectorizedArrayTrait<Number>::get_from_vectorized(
496 value[d][i], vector_lane) = result[i][d];
497 }
498
499 static void
500 set_zero_gradient(unit_gradient_type &value,
501 const unsigned int vector_lane)
502 {
503 for (unsigned int i = 0; i < dim; ++i)
504 for (unsigned int d = 0; d < dim; ++d)
505 internal::VectorizedArrayTrait<Number>::get(value[i][d],
506 vector_lane) = 0.;
507 }
508
509 static void
510 set_value(const vectorized_value_type &value,
511 const unsigned int vector_lane,
512 scalar_value_type &result)
513 {
514 for (unsigned int i = 0; i < dim; ++i)
515 result[i] = value[i][vector_lane];
516 }
517
518 static void
519 set_value(const vectorized_value_type &value,
520 const unsigned int,
521 vectorized_value_type &result)
522 {
523 result = value;
524 }
525
526 static void
527 get_value(vectorized_value_type &value,
528 const unsigned int vector_lane,
529 const scalar_value_type &result)
530 {
531 for (unsigned int i = 0; i < dim; ++i)
532 value[i][vector_lane] = result[i];
533 }
534
535 static void
536 get_value(vectorized_value_type &value,
537 const unsigned int,
538 const vectorized_value_type &result)
539 {
540 value = result;
541 }
542
543 static void
544 set_zero_value(value_type &value, const unsigned int vector_lane)
545 {
546 for (unsigned int i = 0; i < dim; ++i)
547 internal::VectorizedArrayTrait<Number>::get(value[i], vector_lane) =
548 0.;
549 }
550
551 static void
552 access(value_type &value,
553 const unsigned int vector_lane,
554 const unsigned int component,
555 const ScalarNumber &shape_value)
556 {
557 internal::VectorizedArrayTrait<Number>::get(value[component],
558 vector_lane) += shape_value;
559 }
560
561 static ScalarNumber
562 access(const value_type &value,
563 const unsigned int vector_lane,
564 const unsigned int component)
565 {
566 return internal::VectorizedArrayTrait<Number>::get(value[component],
567 vector_lane);
568 }
569
570 static void
571 access(real_gradient_type &value,
572 const unsigned int vector_lane,
573 const unsigned int component,
574 const Tensor<1, dim, ScalarNumber> &shape_gradient)
575 {
576 for (unsigned int d = 0; d < dim; ++d)
577 internal::VectorizedArrayTrait<Number>::get(value[component][d],
578 vector_lane) +=
579 shape_gradient[d];
580 }
581
582 static Tensor<1, dim, ScalarNumber>
583 access(const real_gradient_type &value,
584 const unsigned int vector_lane,
585 const unsigned int component)
586 {
587 Tensor<1, dim, ScalarNumber> result;
588 for (unsigned int d = 0; d < dim; ++d)
589 result[d] =
590 internal::VectorizedArrayTrait<Number>::get(value[component][d],
591 vector_lane);
592 return result;
593 }
594 };
595
596 template <int dim, int spacedim>
597 bool
598 is_fast_path_supported(const FiniteElement<dim, spacedim> &fe,
599 const unsigned int base_element_number);
600
601 template <int dim, int spacedim>
602 bool
603 is_fast_path_supported(const Mapping<dim, spacedim> &mapping);
604
605 template <int dim, int spacedim>
606 std::vector<Polynomials::Polynomial<double>>
607 get_polynomial_space(const FiniteElement<dim, spacedim> &fe);
608 } // namespace FEPointEvaluation
609 } // namespace internal
610
611
612
613 /**
614 * Base class of FEPointEvaluation and FEFacePointEvaluation. This class needs
615 * usually not be called in user code and does not have any public
616 * constructor. The usage is through the class
617 * FEPointEvaluation/FEFacePointEvaluation instead.
618 */
619 template <int n_components_,
620 int dim,
621 int spacedim = dim,
622 typename Number = double>
623 class FEPointEvaluationBase
624 {
625 public:
626 static constexpr unsigned int dimension = dim;
627 static constexpr unsigned int n_components = n_components_;
628
629 using number_type = Number;
630
631 using ScalarNumber =
632 typename internal::VectorizedArrayTrait<Number>::value_type;
633 using VectorizedArrayType = typename dealii::internal::VectorizedArrayTrait<
634 Number>::vectorized_value_type;
635 using ETT = typename internal::FEPointEvaluation::
636 EvaluatorTypeTraits<dim, spacedim, n_components, Number>;
637 using value_type = typename ETT::value_type;
638 using scalar_value_type = typename ETT::scalar_value_type;
639 using vectorized_value_type = typename ETT::vectorized_value_type;
640 using gradient_type = typename ETT::real_gradient_type;
641 using interface_vectorized_unit_gradient_type =
642 typename ETT::interface_vectorized_unit_gradient_type;
643
644 protected:
645 /**
646 * Constructor.
647 *
648 * @param mapping The Mapping class describing the actual geometry of a cell
649 * passed to the evaluate() function.
650 *
651 * @param fe The FiniteElement object that is used for the evaluation, which
652 * is typically the same on all cells to be evaluated.
653 *
654 * @param update_flags Specify the quantities to be computed by the mapping
655 * during the call of reinit(). During evaluate() or integrate(), this data
656 * is queried to produce the desired result (e.g., the gradient of a finite
657 * element solution).
658 *
659 * @param first_selected_component For multi-component FiniteElement
660 * objects, this parameter allows to select a range of `n_components`
661 * components starting from this parameter.
662 */
663 FEPointEvaluationBase(const Mapping<dim, spacedim> &mapping,
664 const FiniteElement<dim, spacedim> &fe,
665 const UpdateFlags update_flags,
666 const unsigned int first_selected_component = 0);
667
668 /**
669 * Constructor to make the present class able to re-use the geometry
670 * data also used by other `FEPointEvaluationBase` objects.
671 *
672 * @param mapping_info The MappingInfo class describes the geometry-related
673 * data for evaluating finite-element solutions. This object enables to
674 * construct such an object on the outside, possibly re-using it between
675 * several objects or between several calls to the same cell and unit points.
676 *
677 * @param fe The FiniteElement object that is used for the evaluation, which
678 * is typically the same on all cells to be evaluated.
679 *
680 * @param first_selected_component For multi-component FiniteElement
681 * objects, this parameter allows to select a range of `n_components`
682 * components starting from this parameter.
683 *
684 * @param is_interior Defines if interior or exterior. Only makes sense for
685 * faces.
686 */
687 FEPointEvaluationBase(
688 const NonMatching::MappingInfo<dim, spacedim, Number> &mapping_info,
689 const FiniteElement<dim, spacedim> &fe,
690 const unsigned int first_selected_component = 0,
691 const bool is_interior = true);
692
693 /**
694 * Copy constructor.
695 */
696 FEPointEvaluationBase(FEPointEvaluationBase &other) noexcept;
697
698 /**
699 * Move constructor.
700 */
701 FEPointEvaluationBase(FEPointEvaluationBase &&other) noexcept;
702
703 public:
704 /**
705 * Return the value at quadrature point number @p point_index after a call to
706 * FEPointEvaluation::evaluate() with EvaluationFlags::values set, or
707 * the value that has been stored there with a call to
708 * FEPointEvaluationBase::submit_value(). If the object is vector-valued, a
709 * vector-valued return argument is given.
710 */
711 const value_type &
712 get_value(const unsigned int point_index) const;
713
714 /**
715 * Write a value to the field containing the values on points
716 * with component point_index. Access to the same field as through
717 * get_value(). If applied before the function
718 * FEPointEvaluation::integrate() with EvaluationFlags::values set is
719 * called, this specifies the value which is tested by all basis function on
720 * the current cell and integrated over.
721 */
722 void
723 submit_value(const value_type &value, const unsigned int point_index);
724
725 /**
726 * Return the gradient in real coordinates at the point with index
727 * `point_index` after a call to FEPointEvaluation::evaluate() with
728 * EvaluationFlags::gradients set, or the gradient that has been stored there
729 * with a call to FEPointEvaluationBase::submit_gradient(). The gradient in
730 * real coordinates is obtained by taking the unit gradient (also accessible
731 * via get_unit_gradient()) and applying the inverse Jacobian of the mapping.
732 * If the object is vector-valued, a vector-valued return argument is given.
733 */
734 const gradient_type &
735 get_gradient(const unsigned int point_index) const;
736
737 /**
738 * Write a contribution that is tested by the gradient to the field
739 * containing the values on points with the given `point_index`. Access to
740 * the same field as through get_gradient(). If applied before the function
741 * FEPointEvaluation::integrate(EvaluationFlags::gradients) is called,
742 * this specifies what is tested by all basis function gradients on the
743 * current cell and integrated over.
744 */
745 void
746 submit_gradient(const gradient_type &, const unsigned int point_index);
747
748 /**
749 * Return the divergence in real coordinates at the point with index
750 * `point_index` after a call to FEPointEvaluation::evaluate() with
751 * EvaluationFlags::gradients set, or the divergence that has been stored
752 * there with a call to FEPointEvaluationBase::submit_divergence(). This
753 * functions only makes sense for a vector field with dim components.
754 */
755 Number
756 get_divergence(const unsigned int point_index) const;
757
758 /**
759 * Write a contribution that is tested by the divergence to the field
760 * containing the values on points with the given `point_index`. Access to
761 * the same field as through get_divergence(). If applied before the function
762 * FEPointEvaluation::integrate(EvaluationFlags::gradients) is called,
763 * this specifies what is tested by all basis function gradients on the
764 * current cell and integrated over.
765 *
766 * @note This operation writes the data to the same field as
767 * submit_gradient(). As a consequence, only one of these functions can be
768 * used. In case several terms of this kind appear in a weak form, the
769 * contribution of a potential call to this function must be added into the
770 * diagonal of the rank-2 tensor contribution passed to submit_gradient(),
771 * in order not to overwrite information.
772 */
773 void
774 submit_divergence(const Number &value, const unsigned int point_index);
775
776 /**
777 * Return the curl in real coordinates at the point with index
778 * `point_index` after a call to FEPointEvaluation::evaluate() with
779 * EvaluationFlags::gradients set. This functions only makes sense for a
780 * vector field with dim components and dim > 1.
781 */
782 Tensor<1, (dim == 2 ? 1 : dim), Number>
783 get_curl(const unsigned int point_index) const;
784
785 /**
786 * Return the Jacobian of the transformation on the current cell with the
787 * given point index. Prerequisite: This class needs to be constructed with
788 * UpdateFlags containing `update_jacobian`.
789 */
790 DerivativeForm<1, dim, spacedim, Number>
791 jacobian(const unsigned int point_index) const;
792
793 /**
794 * Return the inverse of the Jacobian of the transformation on the current
795 * cell with the given point index. Prerequisite: This class needs to be
796 * constructed with UpdateFlags containing `update_inverse_jacobian` or
797 * `update_gradients`.
798 */
799 DerivativeForm<1, spacedim, dim, Number>
800 inverse_jacobian(const unsigned int point_index) const;
801
802 /**
803 * Return the Jacobian determinant multiplied by the quadrature weight. This
804 * class or the MappingInfo object passed to this function needs to be
805 * constructed with UpdateFlags containing `update_JxW_values`.
806 */
807 Number
808 JxW(const unsigned int point_index) const;
809
810 /**
811 * Return the position in real coordinates of the given point index among
812 * the points passed to reinit().
813 *
814 * @deprecated Use the function quadrature_point() instead.
815 */
816 DEAL_II_DEPRECATED Point<spacedim, Number>
817 real_point(const unsigned int point_index) const;
818
819 /**
820 * Return the position in real coordinates of the given point index among
821 * the points passed to reinit().
822 */
823 Point<spacedim, Number>
824 quadrature_point(const unsigned int point_index) const;
825
826 /**
827 * Return the position in unit/reference coordinates of the given point
828 * index, i.e., the respective point passed to the reinit() function.
829 */
830 Point<dim, Number>
831 unit_point(const unsigned int point_index) const;
832
833 /**
834  * Take values collected at quadrature points via the submit_value()
835 * function, multiply by the Jacobian determinant
836 * and quadrature weights (JxW) and sum the values for all quadrature
837  * points on the cell. The result is a scalar, representing the integral
838  * of the function over the cell.
839  */
840 scalar_value_type
841 integrate_value() const;
842
843 /**
844 * Return an object that can be thought of as an array containing all indices
845 * from zero to n_quadrature_points. This allows to write code using
846 * range-based for loops.
847 */
848 inline std_cxx20::ranges::iota_view<unsigned int, unsigned int>
849 quadrature_point_indices() const;
850
851 /**
852 * Returns how many lanes of a quadrature batch are active.
853 */
854 unsigned int
855 n_active_entries_per_quadrature_batch(unsigned int q);
856
857 protected:
858 static constexpr std::size_t n_lanes_user_interface =
859 internal::VectorizedArrayTrait<Number>::width();
860 static constexpr std::size_t n_lanes_internal =
861 internal::VectorizedArrayTrait<VectorizedArrayType>::width();
862 static constexpr std::size_t stride =
863 internal::VectorizedArrayTrait<Number>::stride();
864
865 /**
866 * Common setup function for both constructors. Does the setup for both fast
867 * and slow path.
868 *
869 * @param first_selected_component For multi-component FiniteElement
870 * objects, this parameter allows to select a range of `n_components`
871 * components starting from this parameter.
872 */
873 void
874 setup(const unsigned int first_selected_component);
875
876 /**
877 * Shared functionality of all @p reinit() functions. Resizes data fields and
878 * precomputes the @p shapes vector, holding the evaluation of 1D basis
879 * functions of tensor product polynomials, if necessary.
880 */
881 template <bool is_face, bool is_linear>
882 void
883 do_reinit();
884
885 /**
886 * Number of quadrature batches of the current cell/face.
887 */
888 const unsigned int n_q_batches;
889
890 /**
891 * Number of quadrature points/batches of the current cell/face.
892 */
893 const unsigned int n_q_points;
894
895 /**
896 * Number of quadrature points of the current cell/face.
897 */
898 const unsigned int n_q_points_scalar;
899
900 /**
901 * Pointer to the Mapping object passed to the constructor.
902 */
903 ObserverPointer<const Mapping<dim, spacedim>> mapping;
904
905 /**
906 * Pointer to the FiniteElement object passed to the constructor.
907 */
908 ObserverPointer<const FiniteElement<dim, spacedim>> fe;
909
910 /**
911 * Description of the 1d polynomial basis for tensor product elements used
912 * for the fast path of this class using tensor product evaluators.
913 */
914 std::vector<Polynomials::Polynomial<double>> poly;
915
916 /**
917 * Store whether the linear path should be used.
918 */
919 bool use_linear_path;
920
921 /**
922 * Renumbering between the unknowns of unknowns implied by the FiniteElement
923 * class and a lexicographic numbering used for the tensorized code path.
924 */
925 std::vector<unsigned int> renumber;
926
927 /**
928 * Temporary array to store the `solution_values` passed to the evaluate()
929 * function in a format compatible with the tensor product evaluators. For
930 * vector-valued setups, this array uses a `Tensor<1, n_components,
931 * ScalarNumber>` type to collect the unknowns for a particular basis
932 * function.
933 */
934 std::vector<scalar_value_type> solution_renumbered;
935
936 /**
937 * Temporary array to store a vectorized version of the `solution_values`
938 * computed during `integrate()` in a format compatible with the tensor
939 * product evaluators. For vector-valued setups, this array uses a
940 * `Tensor<1, n_components, VectorizedArrayType>` format.
941 */
942 AlignedVector<vectorized_value_type> solution_renumbered_vectorized;
943
944 /**
945 * Temporary array for the face path (scalar).
946 */
947 AlignedVector<ScalarNumber> scratch_data_scalar;
948
949 /**
950 * Temporary array to store the values at the points.
951 */
952 std::vector<value_type> values;
953
954 /**
955 * Temporary array to store the gradients in real coordinates at the points.
956 */
957 std::vector<gradient_type> gradients;
958
959 /**
960 * Pointer to first unit point batch of current cell/face from MappingInfo,
961 * set internally during do_reinit().
962 */
963 const Point<dim, VectorizedArrayType> *unit_point_ptr;
964
965 /**
966 * Pointer to first unit point batch of current face from MappingInfo,
967 * set internally during do_reinit(). Needed for face path.
968 */
969 const Point<dim - 1, VectorizedArrayType> *unit_point_faces_ptr;
970
971 /**
972 * Pointer to real point of first quadrature point of current cell/face from
973 * MappingInfo, set internally during do_reinit().
974 */
975 const Point<spacedim, Number> *real_point_ptr;
976
977 /**
978 * Pointer to Jacobian of first quadrature point of current cell/face from
979 * MappingInfo, set internally during do_reinit().
980 */
981 const DerivativeForm<1, dim, spacedim, Number> *jacobian_ptr;
982
983 /**
984 * Pointer to inverse Jacobian of first quadrature point of current cell/face
985 * from MappingInfo, set internally during do_reinit().
986 */
987 const DerivativeForm<1, spacedim, dim, Number> *inverse_jacobian_ptr;
988
989 /**
990 * Pointer to normal vector of first quadrature point of current cell/face
991 * from MappingInfo, set internally during do_reinit().
992 */
993 const Tensor<1, spacedim, Number> *normal_ptr;
994
995 /**
996 * Pointer to Jacobian determinant times quadrature weight of first quadrature
997 * point of current cell/face from MappingInfo, set internally during
998 * do_reinit().
999 */
1000 const Number *JxW_ptr;
1001
1002 /**
1003 * Cell type describing the geometry of the cell and compression of jacobians.
1004 */
1005 internal::MatrixFreeFunctions::GeometryType cell_type;
1006
1007 /**
1008 * Number of unknowns per component, i.e., number of unique basis functions,
1009 * for the chosen FiniteElement (or base element).
1010 */
1011 unsigned int dofs_per_component;
1012
1013 /**
1014 * Number of unknowns per component, i.e., number of unique basis functions,
1015 * for a restriction to the face of the chosen FiniteElement (or base
1016 * element). This means a (dim-1)-dimensional basis.
1017 */
1018 unsigned int dofs_per_component_face;
1019
1020 /**
1021 * Scalar ShapeInfo object needed for face path.
1022 */
1023 internal::MatrixFreeFunctions::ShapeInfo<ScalarNumber> shape_info;
1024
1025 /**
1026 * The first selected component in the active base element.
1027 */
1028 unsigned int component_in_base_element;
1029
1030 /**
1031 * For complicated FiniteElement objects this variable informs us about
1032 * which unknowns actually carry degrees of freedom in the selected
1033 * components.
1034 */
1035 std::vector<std::array<bool, n_components>> nonzero_shape_function_component;
1036
1037 /**
1038 * The desired update flags for the evaluation.
1039 */
1040 const UpdateFlags update_flags;
1041
1042 /**
1043 * The FEValues object underlying the slow evaluation path.
1044 */
1045 std::shared_ptr<FEValues<dim, spacedim>> fe_values;
1046
1047 /**
1048 * Pointer to mapping info on the fly computed during reinit.
1049 */
1050 std::unique_ptr<NonMatching::MappingInfo<dim, spacedim, Number>>
1051 mapping_info_on_the_fly;
1052
1053 /**
1054 * Pointer to currently used mapping info (either on the fly or external
1055 * precomputed).
1056 */
1057 ObserverPointer<const NonMatching::MappingInfo<dim, spacedim, Number>>
1058 mapping_info;
1059
1060 /**
1061 * The current cell index to access mapping data from mapping info.
1062 */
1063 unsigned int current_cell_index;
1064
1065 /**
1066 * The current face number to access mapping data from mapping info.
1067 */
1068 unsigned int current_face_number;
1069
1070 /**
1071 * Bool indicating if fast path is chosen.
1072 */
1073 bool fast_path;
1074
1075 /**
1076 * Bool indicating if class needs to call reinit() inside
1077 * evaluate()/integrate() functions, which is the case when the present
1078 * class does not own the MappingInfo object but shares evaluation points
1079 * with another object.
1080 */
1081 bool must_reinitialize_pointers;
1082
1083 /**
1084 * Vector containing tensor product shape functions evaluated (during
1085 * reinit()) at the vectorized unit points.
1086 */
1087 AlignedVector<dealii::ndarray<VectorizedArrayType, 2, dim>> shapes;
1088
1089 /**
1090 * Vector containing tensor product shape functions evaluated (during
1091 * reinit()) at the vectorized unit points on faces.
1092 */
1093 AlignedVector<dealii::ndarray<VectorizedArrayType, 2, dim - 1>> shapes_faces;
1094
1095 const bool is_interior;
1096 };
1097
1098
1099
1100 /**
1101 * This class provides an interface to the evaluation of interpolated solution
1102 * values and gradients on cells on arbitrary reference point positions. These
1103 * points can change from cell to cell, both with respect to their quantity as
1104 * well to the location. The two typical use cases are evaluations on
1105 * non-matching grids and particle simulations.
1106 *
1107 * The use of this class is similar to FEValues or FEEvaluation: The class is
1108 * first initialized to a cell by calling `FEPointEvaluation::reinit(cell,
1109 * unit_points)`, with the main difference to the other concepts that the
1110 * underlying points in reference coordinates need to be passed along. Then,
1111 * upon call to evaluate() or integrate(), the user can compute information at
1112 * the give points. Eventually, the access functions get_value() or
1113 * get_gradient() allow to query this information at a specific point index.
1114 *
1115 * The functionality is similar to creating an FEValues object with a
1116 * Quadrature object on the `unit_points` on every cell separately and then
1117 * calling FEValues::get_function_values or FEValues::get_function_gradients,
1118 * and for some elements and mappings this is what actually happens
1119 * internally. For specific combinations of Mapping and FiniteElement
1120 * realizations, however, there is a much more efficient implementation that
1121 * avoids the memory allocation and other expensive start-up cost of
1122 * FEValues. Currently, the functionality is specialized for mappings derived
1123 * from MappingQ and MappingCartesian and for finite elements with tensor
1124 * product structure that work with the
1125 * @ref matrixfree
1126 * topic. In those cases, the cost implied
1127 * by this class is similar (or sometimes even somewhat lower) than using
1128 * `FEValues::reinit(cell)` followed by `FEValues::get_function_gradients`.
1129 */
1130 template <int n_components_,
1131 int dim,
1132 int spacedim = dim,
1133 typename Number = double>
1134 class FEPointEvaluation
1135 : public FEPointEvaluationBase<n_components_, dim, spacedim, Number>
1136 {
1137 public:
1138 static constexpr unsigned int dimension = dim;
1139 static constexpr unsigned int n_components = n_components_;
1140
1141 using number_type = Number;
1142
1143 using ScalarNumber =
1144 typename internal::VectorizedArrayTrait<Number>::value_type;
1145 using VectorizedArrayType = typename dealii::internal::VectorizedArrayTrait<
1146 Number>::vectorized_value_type;
1147 using ETT = typename internal::FEPointEvaluation::
1148 EvaluatorTypeTraits<dim, spacedim, n_components, Number>;
1149 using value_type = typename ETT::value_type;
1150 using scalar_value_type = typename ETT::scalar_value_type;
1151 using vectorized_value_type = typename ETT::vectorized_value_type;
1152 using unit_gradient_type = typename ETT::unit_gradient_type;
1153 using gradient_type = typename ETT::real_gradient_type;
1154 using interface_vectorized_unit_gradient_type =
1155 typename ETT::interface_vectorized_unit_gradient_type;
1156
1157 /**
1158 * Constructor.
1159 *
1160 * @param mapping The Mapping class describing the actual geometry of a cell
1161 * passed to the evaluate() function.
1162 *
1163 * @param fe The FiniteElement object that is used for the evaluation, which
1164 * is typically the same on all cells to be evaluated.
1165 *
1166 * @param update_flags Specify the quantities to be computed by the mapping
1167 * during the call of reinit(). During evaluate() or integrate(), this data
1168 * is queried to produce the desired result (e.g., the gradient of a finite
1169 * element solution).
1170 *
1171 * @param first_selected_component For multi-component FiniteElement
1172 * objects, this parameter allows to select a range of `n_components`
1173 * components starting from this parameter.
1174 *
1175 * @param force_lexicographic_numbering By default, this class uses the DoF
1176 * numbering detected from the FiniteElement passed to this class (which is
1177 * lexicographic for e.g. FE_DGQ but hierarchic for FE_Q). However, it is
1178 * possible to force a lexicographic numbering of DoFs instead by setting this
1179 * parameter to true, which is useful if this class is used together with
1180 * FEEvaluation, for instance. This is because DoF values within FEEvaluation
1181 * are stored in lexicographic numbering.
1182 */
1183 FEPointEvaluation(const Mapping<dim, spacedim> &mapping,
1184 const FiniteElement<dim, spacedim> &fe,
1185 const UpdateFlags update_flags,
1186 const unsigned int first_selected_component = 0,
1187 const bool force_lexicographic_numbering = false);
1188
1189 /**
1190 * Constructor to make the present class able to re-use the geometry
1191 * data also used by other `FEPointEvaluation` objects.
1192 *
1193 * @param mapping_info The MappingInfo class describes the geometry-related
1194 * data for evaluating finite-element solutions. This object enables to
1195 * construct such an object on the outside, possibly re-using it between
1196 * several objects or between several calls to the same cell and unit points.
1197 *
1198 * @param fe The FiniteElement object that is used for the evaluation, which
1199 * is typically the same on all cells to be evaluated.
1200 *
1201 * @param first_selected_component For multi-component FiniteElement
1202 * objects, this parameter allows to select a range of `n_components`
1203 * components starting from this parameter.
1204 *
1205 * @param force_lexicographic_numbering By default, this class uses the DoF
1206 * numbering detected from the FiniteElement passed to this class (which is
1207 * lexicographic for e.g. FE_DGQ but hierarchic for FE_Q). However, it is
1208 * possible to force a lexicographic numbering of DoFs instead by setting this
1209 * parameter to true, which is useful if this class is used together with
1210 * FEEvaluation, for instance. This is because DoF values within FEEvaluation
1211 * are stored in lexicographic numbering.
1212 */
1213 FEPointEvaluation(
1214 const NonMatching::MappingInfo<dim, spacedim, Number> &mapping_info,
1215 const FiniteElement<dim, spacedim> &fe,
1216 const unsigned int first_selected_component = 0,
1217 const bool force_lexicographic_numbering = false);
1218
1219 /**
1220 * Set up the mapping information for the given cell, e.g., by computing the
1221 * Jacobian of the mapping for the given points if gradients of the functions
1222 * are requested.
1223 *
1224 * @param[in] cell An iterator to the current cell
1225 *
1226 * @param[in] unit_points List of points in the reference locations of the
1227 * current cell where the FiniteElement object should be
1228 * evaluated/integrated in the evaluate() and integrate() functions.
1229 */
1230 void
1231 reinit(const typename Triangulation<dim, spacedim>::cell_iterator &cell,
1232 const ArrayView<const Point<dim>> &unit_points);
1233
1234 /**
1235 * Reinitialize the evaluator to point to the correct precomputed mapping of
1236 * the single cell in the MappingInfo object.
1237 */
1238 void
1239 reinit();
1240
1241 /**
1242 * Reinitialize the evaluator to point to the correct precomputed mapping of
1243 * the cell in the MappingInfo object.
1244 */
1245 void
1246 reinit(const unsigned int cell_index);
1247
1248
1249 /**
1250 * This function interpolates the finite element solution, represented by
1251 * `solution_values`, on the cell and `unit_points` passed to reinit().
1252 *
1253 * @param[in] solution_values This array is supposed to contain the unknown
1254 * values on the element read out by
1255 * `FEEvaluation::read_dof_values(global_vector)`.
1256 *
1257 * @param[in] evaluation_flags Flags specifying which quantities should be
1258 * evaluated at the points.
1259 */
1260 template <std::size_t stride_view>
1261 void
1262 evaluate(
1263 const StridedArrayView<const ScalarNumber, stride_view> &solution_values,
1264 const EvaluationFlags::EvaluationFlags &evaluation_flags);
1265
1266 /**
1267 * This function interpolates the finite element solution, represented by
1268 * `solution_values`, on the cell and `unit_points` passed to reinit().
1269 *
1270 * @param[in] solution_values This array is supposed to contain the unknown
1271 * values on the element as returned by `cell->get_dof_values(global_vector,
1272 * solution_values)`.
1273 *
1274 * @param[in] evaluation_flags Flags specifying which quantities should be
1275 * evaluated at the points.
1276 */
1277 void
1278 evaluate(const ArrayView<const ScalarNumber> &solution_values,
1279 const EvaluationFlags::EvaluationFlags &evaluation_flags);
1280
1281 /**
1282 * This function multiplies the quantities passed in by previous
1283 * submit_value() or submit_gradient() calls by the value or gradient of the
1284 * test functions, and performs summation over all given points multiplied be
1285 * the Jacobian determinant times the quadrature weight (JxW).
1286 *
1287 * @param[out] solution_values This array will contain the result of the
1288 * integral, which can be used during
1289 * `FEEvaluation::set_dof_values(global_vector)` or
1290 * `FEEvaluation::distribute_local_to_global(global_vector)`. Note
1291 * that for multi-component systems where only some of the components are
1292 * selected by the present class, the entries in `solution_values` not touched
1293 * by this class will be set to zero.
1294 *
1295 * @param[in] integration_flags Flags specifying which quantities should be
1296 * integrated at the points.
1297 *
1298 * @param[in] sum_into_values Flag specifying if the integrated values
1299 * should be summed into the solution values. For the default value
1300 * `sum_into_values=false` every value of @p solution_values is zeroed out.
1301 *
1302 */
1303 template <std::size_t stride_view>
1304 void
1305 integrate(const StridedArrayView<ScalarNumber, stride_view> &solution_values,
1306 const EvaluationFlags::EvaluationFlags &integration_flags,
1307 const bool sum_into_values = false);
1308
1309 /**
1310 * This function multiplies the quantities passed in by previous
1311 * submit_value() or submit_gradient() calls by the value or gradient of the
1312 * test functions, and performs summation over all given points multiplied be
1313 * the Jacobian determinant times the quadrature weight (JxW).
1314 *
1315 * @param[out] solution_values This array will contain the result of the
1316 * integral, which can be used to during
1317 * `cell->set_dof_values(solution_values, global_vector)` or
1318 * `cell->distribute_local_to_global(solution_values, global_vector)`. Note
1319 * that for multi-component systems where only some of the components are
1320 * selected by the present class, the entries in `solution_values` not touched
1321 * by this class will be set to zero.
1322 *
1323 * @param[in] integration_flags Flags specifying which quantities should be
1324 * integrated at the points.
1325 *
1326 * @param[in] sum_into_values Flag specifying if the integrated values
1327 * should be summed into the solution values. For the default value
1328 * `sum_into_values=false` every value of @p solution_values is zeroed out.
1329 *
1330 */
1331 void
1332 integrate(const ArrayView<ScalarNumber> &solution_values,
1333 const EvaluationFlags::EvaluationFlags &integration_flags,
1334 const bool sum_into_values = false);
1335
1336 /**
1337 * This function multiplies the quantities passed in by previous
1338 * submit_value() or submit_gradient() calls by the value or gradient of the
1339 * test functions, and performs summation over all given points. This is
1340 * similar to the integration of a bilinear form in terms of the test
1341 * function, with the difference that this formula does not include a `JxW`
1342 * factor (in contrast to the integrate function of this class). This allows
1343 * the class to naturally embed point information (e.g. particles) into a
1344 * finite element formulation.
1345 *
1346 * @param[out] solution_values This array will contain the result of the
1347 * integral, which can be used during
1348 * `FEEvaluation::set_dof_values(global_vector)` or
1349 * `FEEvaluation::distribute_local_to_global(global_vector)`. Note
1350 * that for multi-component systems where only some of the components are
1351 * selected by the present class, the entries in `solution_values` not touched
1352 * by this class will be set to zero.
1353 *
1354 * @param[in] integration_flags Flags specifying which quantities should be
1355 * integrated at the points.
1356 *
1357 * @param[in] sum_into_values Flag specifying if the integrated values
1358 * should be summed into the solution values. For the default value
1359 * `sum_into_values=false` every value of @p solution_values is zeroed out.
1360 *
1361 */
1362 template <std::size_t stride_view>
1363 void
1364 test_and_sum(
1365 const StridedArrayView<ScalarNumber, stride_view> &solution_values,
1366 const EvaluationFlags::EvaluationFlags &integration_flags,
1367 const bool sum_into_values = false);
1368
1369 /**
1370 * This function multiplies the quantities passed in by previous
1371 * submit_value() or submit_gradient() calls by the value or gradient of the
1372 * test functions, and performs summation over all given points. This is
1373 * similar to the integration of a bilinear form in terms of the test
1374 * function, with the difference that this formula does not include a `JxW`
1375 * factor (in contrast to the integrate function of this class). This allows
1376 * the class to naturally embed point information (e.g. particles) into a
1377 * finite element formulation.
1378 *
1379 * @param[out] solution_values This array will contain the result of the
1380 * integral, which can be used during
1381 * `cell->set_dof_values(solution_values, global_vector)` or
1382 * `cell->distribute_local_to_global(solution_values, global_vector)`. Note
1383 * that for multi-component systems where only some of the components are
1384 * selected by the present class, the entries in `solution_values` not touched
1385 * by this class will be set to zero.
1386 *
1387 * @param[in] integration_flags Flags specifying which quantities should be
1388 * integrated at the points.
1389 *
1390 * @param[in] sum_into_values Flag specifying if the integrated values
1391 * should be summed into the solution values. For the default value
1392 * `sum_into_values=false` every value of @p solution_values is zeroed out.
1393 *
1394 */
1395 void
1396 test_and_sum(const ArrayView<ScalarNumber> &solution_values,
1397 const EvaluationFlags::EvaluationFlags &integration_flags,
1398 const bool sum_into_values = false);
1399
1400 /**
1401 * Return the normal vector. This class or the MappingInfo object passed to
1402 * this function needs to be constructed with UpdateFlags containing
1403 * `update_normal_vectors`.
1404 */
1405 Tensor<1, spacedim, Number>
1406 normal_vector(const unsigned int point_index) const;
1407
1408 /**
1409 * Return the normal derivative in real coordinates at the point with index
1410 * `point_index` after a call to FEPointEvaluation::evaluate() with
1411 * EvaluationFlags::gradients set.
1412 */
1413 const value_type
1414 get_normal_derivative(const unsigned int point_index) const;
1415
1416 /**
1417 * Write a contribution that is tested by the normal derivative to the field
1418 * containing the values on points with the given `point_index`. Access to
1419 * the same field as through set_gradient()/get_gradient.
1420 */
1421 void
1422 submit_normal_derivative(const value_type &, const unsigned int point_index);
1423
1424 private:
1425 static constexpr std::size_t n_lanes_user_interface =
1426 internal::VectorizedArrayTrait<Number>::width();
1427 static constexpr std::size_t n_lanes_internal =
1428 internal::VectorizedArrayTrait<VectorizedArrayType>::width();
1429 static constexpr std::size_t stride =
1430 internal::VectorizedArrayTrait<Number>::stride();
1431
1432 const bool lexicographic_numbering;
1433
1434 /**
1435 * Resizes necessary data fields, reads in and renumbers solution values.
1436 * Interpolates onto face if face path is selected.
1437 */
1438 template <bool is_linear, std::size_t stride_view>
1439 void
1440 prepare_evaluate_fast(
1441 const StridedArrayView<const ScalarNumber, stride_view> &solution_values);
1442
1443 /**
1444 * Evaluates the actual interpolation on the cell or face for a quadrature
1445 * batch.
1446 */
1447 template <bool is_linear, std::size_t stride_view>
1448 void
1449 compute_evaluate_fast(
1450 const StridedArrayView<const ScalarNumber, stride_view> &solution_values,
1451 const EvaluationFlags::EvaluationFlags &evaluation_flags,
1452 const unsigned int n_shapes,
1453 const unsigned int qb,
1454 vectorized_value_type &value,
1455 interface_vectorized_unit_gradient_type &gradient);
1456
1457 /**
1458 * Fast path of the evaluate function.
1459 */
1460 template <bool is_linear, std::size_t stride_view>
1461 void
1462 evaluate_fast(
1463 const StridedArrayView<const ScalarNumber, stride_view> &solution_values,
1464 const EvaluationFlags::EvaluationFlags &evaluation_flags);
1465
1466 /**
1467 * Slow path of the evaluate function using FEValues.
1468 */
1469 template <std::size_t stride_view>
1470 void
1471 evaluate_slow(
1472 const StridedArrayView<const ScalarNumber, stride_view> &solution_values,
1473 const EvaluationFlags::EvaluationFlags &evaluation_flags);
1474
1475 /**
1476 * Integrates the product of the data passed in by submit_value() and
1477 * submit_gradient() with the values or gradients of test functions on the
1478 * cell or face for a given quadrature batch.
1479 */
1480 template <bool is_linear>
1481 void
1482 compute_integrate_fast(
1483 const EvaluationFlags::EvaluationFlags &integration_flags,
1484 const unsigned int n_shapes,
1485 const unsigned int qb,
1486 const vectorized_value_type value,
1487 const interface_vectorized_unit_gradient_type gradient,
1488 vectorized_value_type *solution_values_vectorized_linear);
1489
1490 /**
1491 * Addition across the lanes of VectorizedArray as accumulated by the
1492 * compute_integrate_fast_function(), writing the sum into the result vector.
1493 * Applies face contributions to cell contributions for face path.
1494 */
1495 template <bool is_linear, std::size_t stride_view>
1496 void
1497 finish_integrate_fast(
1498 const StridedArrayView<ScalarNumber, stride_view> &solution_values,
1499 vectorized_value_type *solution_values_vectorized_linear,
1500 const bool sum_into_values);
1501
1502 /**
1503 * Fast path of the integrate function.
1504 */
1505 template <bool do_JxW, bool is_linear, std::size_t stride_view>
1506 void
1507 integrate_fast(
1508 const StridedArrayView<ScalarNumber, stride_view> &solution_values,
1509 const EvaluationFlags::EvaluationFlags &integration_flags,
1510 const bool sum_into_values);
1511
1512 /**
1513 * Slow path of the integrate function using FEValues.
1514 */
1515 template <bool do_JxW, std::size_t stride_view>
1516 void
1517 integrate_slow(
1518 const StridedArrayView<ScalarNumber, stride_view> &solution_values,
1519 const EvaluationFlags::EvaluationFlags &integration_flags,
1520 const bool sum_into_values);
1521
1522 /**
1523 * Implementation of the integrate/test_and_sum function.
1524 */
1525 template <bool do_JxW, std::size_t stride_view>
1526 void
1527 do_integrate(
1528 const StridedArrayView<ScalarNumber, stride_view> &solution_values,
1529 const EvaluationFlags::EvaluationFlags &integration_flags,
1530 const bool sum_into_values);
1531
1532 /**
1533 * Internal function to initialize the pointers of this class when an
1534 * external MappingInfo has already queried the mapping for the relevant
1535 * information.
1536 */
1537 void
1538 internal_reinit_single_cell_state_mapping_info();
1539 };
1540
1541
1542
1543 /**
1544 * This class provides an interface to the evaluation of interpolated solution
1545 * values and gradients on faces on arbitrary reference point positions. These
1546 * points can change from face to face, both with respect to their quantity as
1547 * well to the location. A typical use case is evaluations on non-matching
1548 * grids.
1549 *
1550 * The use of this class is similar to FEEvaluation: In the constructor, a
1551 * reference to a NonMatching::MappingInfo object is passed, where the
1552 * quadrature points in reference position is stored together with the mapping
1553 * information. The class is then reinitialized to a cell by calling
1554 * `FEFacePointEvaluation::reinit(face_index)` or
1555 * `FEFacePointEvaluation::reinit(cell_index, face_number)`. Then, upon call to
1556 * evaluate() or integrate(), the user can compute information at the given
1557 * points. Eventually, the access functions get_value() or get_gradient() allow
1558 * to query this information at a specific point index.
1559 */
1560 template <int n_components_,
1561 int dim,
1562 int spacedim = dim,
1563 typename Number = double>
1564 class FEFacePointEvaluation
1565 : public FEPointEvaluationBase<n_components_, dim, spacedim, Number>
1566 {
1567 public:
1568 static constexpr unsigned int dimension = dim;
1569 static constexpr unsigned int n_components = n_components_;
1570
1571 using number_type = Number;
1572
1573 using ScalarNumber =
1574 typename internal::VectorizedArrayTrait<Number>::value_type;
1575 using VectorizedArrayType = typename dealii::internal::VectorizedArrayTrait<
1576 Number>::vectorized_value_type;
1577 using ETT = typename internal::FEPointEvaluation::
1578 EvaluatorTypeTraits<dim, spacedim, n_components, Number>;
1579 using value_type = typename ETT::value_type;
1580 using scalar_value_type = typename ETT::scalar_value_type;
1581 using vectorized_value_type = typename ETT::vectorized_value_type;
1582 using unit_gradient_type = typename ETT::unit_gradient_type;
1583 using gradient_type = typename ETT::real_gradient_type;
1584 using interface_vectorized_unit_gradient_type =
1585 typename ETT::interface_vectorized_unit_gradient_type;
1586
1587 /**
1588 * Constructor. Allows to select if interior or exterior face is selected.
1589 */
1590 FEFacePointEvaluation(
1591 const NonMatching::MappingInfo<dim, spacedim, Number> &mapping_info,
1592 const FiniteElement<dim, spacedim> &fe,
1593 const bool is_interior = true,
1594 const unsigned int first_selected_component = 0);
1595
1596 /**
1597 * Reinitialize the evaluator to point to the correct precomputed mapping of
1598 * the face in the MappingInfo object. Used in element-centric loops (ECL).
1599 */
1600 void
1601 reinit(const unsigned int cell_index, const unsigned int face_number);
1602
1603 /**
1604 * Reinitialize the evaluator to point to the correct precomputed mapping of
1605 * the face in the MappingInfo object. Used in face-centric loops (FCL).
1606 */
1607 void
1608 reinit(const unsigned int face_index);
1609
1610 /**
1611 * This function interpolates the finite element solution, represented by
1612 * `solution_values`, on the cell and `unit_points` passed to reinit().
1613 *
1614 * @param[in] solution_values This array is supposed to contain the unknown
1615 * values on the element read out by
1616 * `FEEvaluation::read_dof_values(global_vector)`.
1617 *
1618 * @param[in] evaluation_flags Flags specifying which quantities should be
1619 * evaluated at the points.
1620 */
1621 template <std::size_t stride_view>
1622 void
1623 evaluate(
1624 const StridedArrayView<const ScalarNumber, stride_view> &solution_values,
1625 const EvaluationFlags::EvaluationFlags &evaluation_flags);
1626
1627 /**
1628 * This function interpolates the finite element solution, represented by
1629 * `solution_values`, on the cell and `unit_points` passed to reinit().
1630 *
1631 * @param[in] solution_values This array is supposed to contain the unknown
1632 * values on the element as returned by `cell->get_dof_values(global_vector,
1633 * solution_values)`.
1634 *
1635 * @param[in] evaluation_flags Flags specifying which quantities should be
1636 * evaluated at the points.
1637 */
1638 void
1639 evaluate(const ArrayView<const ScalarNumber> &solution_values,
1640 const EvaluationFlags::EvaluationFlags &evaluation_flags);
1641
1642 /**
1643 * This function multiplies the quantities passed in by previous
1644 * submit_value() or submit_gradient() calls by the value or gradient of the
1645 * test functions, and performs summation over all given points multiplied be
1646 * the Jacobian determinant times the quadrature weight (JxW).
1647 *
1648 * @param[out] solution_values This array will contain the result of the
1649 * integral, which can be used during
1650 * `FEEvaluation::set_dof_values(global_vector)` or
1651 * `FEEvaluation::distribute_local_to_global(global_vector)`. Note
1652 * that for multi-component systems where only some of the components are
1653 * selected by the present class, the entries in `solution_values` not touched
1654 * by this class will be set to zero.
1655 *
1656 * @param[in] integration_flags Flags specifying which quantities should be
1657 * integrated at the points.
1658 *
1659 * @param[in] sum_into_values Flag specifying if the integrated values
1660 * should be summed into the solution values. For the default value
1661 * `sum_into_values=false` every value of @p solution_values is zeroed out.
1662 *
1663 */
1664 template <std::size_t stride_view>
1665 void
1666 integrate(const StridedArrayView<ScalarNumber, stride_view> &solution_values,
1667 const EvaluationFlags::EvaluationFlags &integration_flags,
1668 const bool sum_into_values = false);
1669
1670 /**
1671 * This function multiplies the quantities passed in by previous
1672 * submit_value() or submit_gradient() calls by the value or gradient of the
1673 * test functions, and performs summation over all given points multiplied be
1674 * the Jacobian determinant times the quadrature weight (JxW).
1675 *
1676 * @param[out] solution_values This array will contain the result of the
1677 * integral, which can be used to during
1678 * `cell->set_dof_values(solution_values, global_vector)` or
1679 * `cell->distribute_local_to_global(solution_values, global_vector)`. Note
1680 * that for multi-component systems where only some of the components are
1681 * selected by the present class, the entries in `solution_values` not touched
1682 * by this class will be set to zero.
1683 *
1684 * @param[in] integration_flags Flags specifying which quantities should be
1685 * integrated at the points.
1686 *
1687 * @param[in] sum_into_values Flag specifying if the integrated values
1688 * should be summed into the solution values. For the default value
1689 * `sum_into_values=false` every value of @p solution_values is zeroed out.
1690 *
1691 */
1692 void
1693 integrate(const ArrayView<ScalarNumber> &solution_values,
1694 const EvaluationFlags::EvaluationFlags &integration_flags,
1695 const bool sum_into_values = false);
1696
1697 /**
1698 * This function multiplies the quantities passed in by previous
1699 * submit_value() or submit_gradient() calls by the value or gradient of the
1700 * test functions, and performs summation over all given points multiplied be
1701 * the Jacobian determinant times the quadrature weight (JxW).
1702 *
1703 * @param[out] solution_values This array will contain the result of the
1704 * integral, which can be used during
1705 * `FEEvaluation::set_dof_values(global_vector)` or
1706 * `FEEvaluation::distribute_local_to_global(global_vector)`. Note
1707 * that for multi-component systems where only some of the components are
1708 * selected by the present class, the entries in `solution_values` not touched
1709 * by this class will be set to zero.
1710 *
1711 * @param[in] integration_flags Flags specifying which quantities should be
1712 * integrated at the points.
1713 *
1714 * @param[in] sum_into_values Flag specifying if the integrated values
1715 * should be summed into the solution values. For the default value
1716 * `sum_into_values=false` every value of @p solution_values is zeroed out.
1717 *
1718 */
1719 template <std::size_t stride_view>
1720 void
1721 test_and_sum(
1722 const StridedArrayView<ScalarNumber, stride_view> &solution_values,
1723 const EvaluationFlags::EvaluationFlags &integration_flags,
1724 const bool sum_into_values = false);
1725
1726 /**
1727 * This function multiplies the quantities passed in by previous
1728 * submit_value() or submit_gradient() calls by the value or gradient of the
1729 * test functions, and performs summation over all given points multiplied be
1730 * the Jacobian determinant times the quadrature weight (JxW).
1731 *
1732 * @param[out] solution_values This array will contain the result of the
1733 * integral, which can be used to during
1734 * `cell->set_dof_values(solution_values, global_vector)` or
1735 * `cell->distribute_local_to_global(solution_values, global_vector)`. Note
1736 * that for multi-component systems where only some of the components are
1737 * selected by the present class, the entries in `solution_values` not touched
1738 * by this class will be set to zero.
1739 *
1740 * @param[in] integration_flags Flags specifying which quantities should be
1741 * integrated at the points.
1742 *
1743 * @param[in] sum_into_values Flag specifying if the integrated values
1744 * should be summed into the solution values. For the default value
1745 * `sum_into_values=false` every value of @p solution_values is zeroed out.
1746 *
1747 */
1748 void
1749 test_and_sum(const ArrayView<ScalarNumber> &solution_values,
1750 const EvaluationFlags::EvaluationFlags &integration_flags,
1751 const bool sum_into_values = false);
1752
1753 /**
1754 * Evaluate values and gradients in face for the selected face (lane) of the
1755 * batch. Default stride into the face dofs is width of
1756 * VectorizedArray<selected_floating_point_type> which is the default
1757 * vectorization over faces for FEFaceEvaluation.
1758 */
1759 template <int stride_face_dof = VectorizedArrayType::size()>
1760 void
1761 evaluate_in_face(const ScalarNumber *face_dof_values,
1762 const EvaluationFlags::EvaluationFlags &evaluation_flags);
1763
1764 /**
1765 * Integrate values and gradients in face for the selected face (lane) of the
1766 * batch. Default stride into the face dofs is width of
1767 * VectorizedArray<selected_floating_point_type> which is the default
1768 * vectorization over faces for FEFaceEvaluation.
1769 */
1770 template <int stride_face_dof = VectorizedArrayType::size()>
1771 void
1772 integrate_in_face(ScalarNumber *face_dof_values,
1773 const EvaluationFlags::EvaluationFlags &integration_flags,
1774 const bool sum_into_values = false);
1775
1776 /**
1777 * Return the normal vector. This class or the MappingInfo object passed to
1778 * this function needs to be constructed with UpdateFlags containing
1779 * `update_normal_vectors`.
1780 */
1781 Tensor<1, spacedim, Number>
1782 normal_vector(const unsigned int point_index) const;
1783
1784 /**
1785 * Return the normal derivative in real coordinates at the point with index
1786 * `point_index` after a call to FEFacePointEvaluation::evaluate() with
1787 * EvaluationFlags::gradients set.
1788 */
1789 const value_type
1790 get_normal_derivative(const unsigned int point_index) const;
1791
1792 /**
1793 * Write a contribution that is tested by the normal derivative to the field
1794 * containing the values on points with the given `point_index`. Access to
1795 * the same field as through set_gradient()/get_gradient.
1796 */
1797 void
1798 submit_normal_derivative(const value_type &, const unsigned int point_index);
1799
1800 private:
1801 static constexpr std::size_t n_lanes_user_interface =
1802 internal::VectorizedArrayTrait<Number>::width();
1803 static constexpr std::size_t n_lanes_internal =
1804 internal::VectorizedArrayTrait<VectorizedArrayType>::width();
1805 static constexpr std::size_t stride =
1806 internal::VectorizedArrayTrait<Number>::stride();
1807
1808 template <bool is_linear, std::size_t stride_view>
1809 void
1810 do_evaluate(
1811 const StridedArrayView<const ScalarNumber, stride_view> &solution_values,
1812 const EvaluationFlags::EvaluationFlags &evaluation_flags);
1813
1814 template <bool do_JxW, bool is_linear, std::size_t stride_view>
1815 void
1816 do_integrate(
1817 const StridedArrayView<ScalarNumber, stride_view> &solution_values,
1818 const EvaluationFlags::EvaluationFlags &integration_flags,
1819 const bool sum_into_values);
1820
1821 /**
1822 * Actually does the evaluation templated on the chosen code path (linear or
1823 * higher order).
1824 */
1825 template <bool is_linear, int stride_face_dof>
1826 void
1827 do_evaluate_in_face(const ScalarNumber *face_dof_values,
1828 const EvaluationFlags::EvaluationFlags &evaluation_flags);
1829
1830 /**
1831 * Actually does the integration templated on the chosen code path (linear or
1832 * higher order).
1833 */
1834 template <bool do_JxW, bool is_linear, int stride_face_dof>
1835 void
1836 do_integrate_in_face(
1837 ScalarNumber *face_dof_values,
1838 const EvaluationFlags::EvaluationFlags &integration_flags,
1839 const bool sum_into_values);
1840 };
1841
1842
1843
1844 // ----------------------- template and inline function ----------------------
1845
1846
1847 template <int n_components_, int dim, int spacedim, typename Number>
1848 FEPointEvaluationBase<n_components_, dim, spacedim, Number>::
1849 FEPointEvaluationBase(const Mapping<dim, spacedim> &mapping,
1850 const FiniteElement<dim, spacedim> &fe,
1851 const UpdateFlags update_flags,
1852 const unsigned int first_selected_component)
1853 : n_q_batches(numbers::invalid_unsigned_int)
1854 , n_q_points(numbers::invalid_unsigned_int)
1855 , n_q_points_scalar(numbers::invalid_unsigned_int)
1856 , mapping(&mapping)
1857 , fe(&fe)
1858 , JxW_ptr(nullptr)
1859 , update_flags(update_flags)
1860 , mapping_info_on_the_fly(
1861 std::make_unique<NonMatching::MappingInfo<dim, spacedim, Number>>(
1862 mapping,
1863 update_flags))
1864 , mapping_info(mapping_info_on_the_fly.get())
1865 , current_cell_index(numbers::invalid_unsigned_int)
1866 , current_face_number(numbers::invalid_unsigned_int)
1867 , must_reinitialize_pointers(false)
1868 , is_interior(true)
1869 {
1870 setup(first_selected_component);
1871 }
1872
1873
1874
1875 template <int n_components_, int dim, int spacedim, typename Number>
1876 FEPointEvaluationBase<n_components_, dim, spacedim, Number>::
1877 FEPointEvaluationBase(
1878 const NonMatching::MappingInfo<dim, spacedim, Number> &mapping_info,
1879 const FiniteElement<dim, spacedim> &fe,
1880 const unsigned int first_selected_component,
1881 const bool is_interior)
1882 : n_q_batches(numbers::invalid_unsigned_int)
1883 , n_q_points(numbers::invalid_unsigned_int)
1884 , n_q_points_scalar(numbers::invalid_unsigned_int)
1885 , mapping(&mapping_info.get_mapping())
1886 , fe(&fe)
1887 , JxW_ptr(nullptr)
1888 , update_flags(mapping_info.get_update_flags())
1889 , mapping_info(&mapping_info)
1890 , current_cell_index(numbers::invalid_unsigned_int)
1891 , current_face_number(numbers::invalid_unsigned_int)
1892 , must_reinitialize_pointers(true)
1893 , is_interior(is_interior)
1894 {
1895 setup(first_selected_component);
1896 }
1897
1898
1899
1900 template <int n_components_, int dim, int spacedim, typename Number>
1901 FEPointEvaluationBase<n_components_, dim, spacedim, Number>::
1902 FEPointEvaluationBase(
1903 FEPointEvaluationBase<n_components_, dim, spacedim, Number> &other) noexcept
1904 : n_q_batches(other.n_q_batches)
1905 , n_q_points(other.n_q_points)
1906 , n_q_points_scalar(other.n_q_points_scalar)
1907 , mapping(other.mapping)
1908 , fe(other.fe)
1909 , poly(other.poly)
1910 , use_linear_path(other.use_linear_path)
1911 , renumber(other.renumber)
1912 , solution_renumbered(other.solution_renumbered)
1913 , solution_renumbered_vectorized(other.solution_renumbered_vectorized)
1914 , values(other.values)
1915 , gradients(other.gradients)
1916 , dofs_per_component(other.dofs_per_component)
1917 , dofs_per_component_face(other.dofs_per_component_face)
1918 , component_in_base_element(other.component_in_base_element)
1919 , nonzero_shape_function_component(other.nonzero_shape_function_component)
1920 , update_flags(other.update_flags)
1921 , fe_values(other.fe_values)
1922 , mapping_info_on_the_fly(
1923 other.mapping_info_on_the_fly ?
1924 std::make_unique<NonMatching::MappingInfo<dim, spacedim, Number>>(
1925 *mapping,
1926 update_flags) :
1927 nullptr)
1928 , mapping_info(other.mapping_info)
1929 , current_cell_index(other.current_cell_index)
1930 , current_face_number(other.current_face_number)
1931 , fast_path(other.fast_path)
1932 , must_reinitialize_pointers(true)
1933 , is_interior(other.is_interior)
1934 {}
1935
1936
1937
1938 template <int n_components_, int dim, int spacedim, typename Number>
1939 FEPointEvaluationBase<n_components_, dim, spacedim, Number>::
1940 FEPointEvaluationBase(FEPointEvaluationBase &&other) noexcept = default;
1941
1942
1943
1944 template <int n_components_, int dim, int spacedim, typename Number>
1945 void
1946 FEPointEvaluationBase<n_components_, dim, spacedim, Number>::setup(
1947 const unsigned int first_selected_component)
1948 {
1949 AssertIndexRange(first_selected_component + n_components,
1950 fe->n_components() + 1);
1951
1952 shapes.reserve(100);
1953
1954 bool same_base_element = true;
1955 unsigned int base_element_number = 0;
1956 component_in_base_element = 0;
1957 unsigned int component = 0;
1958 for (; base_element_number < fe->n_base_elements(); ++base_element_number)
1959 if (component + fe->element_multiplicity(base_element_number) >
1960 first_selected_component)
1961 {
1962 if (first_selected_component + n_components >
1963 component + fe->element_multiplicity(base_element_number))
1964 same_base_element = false;
1965 component_in_base_element = first_selected_component - component;
1966 break;
1967 }
1968 else
1969 component += fe->element_multiplicity(base_element_number);
1970
1971 if (internal::FEPointEvaluation::is_fast_path_supported(*mapping) &&
1972 internal::FEPointEvaluation::is_fast_path_supported(
1973 *fe, base_element_number) &&
1974 same_base_element)
1975 {
1976 shape_info.reinit(QMidpoint<1>(), *fe, base_element_number);
1977 renumber = shape_info.lexicographic_numbering;
1978 dofs_per_component = shape_info.dofs_per_component_on_cell;
1979 dofs_per_component_face = shape_info.dofs_per_component_on_face;
1980 poly = internal::FEPointEvaluation::get_polynomial_space(
1981 fe->base_element(base_element_number));
1982
1983 bool is_lexicographic = true;
1984 for (unsigned int i = 0; i < renumber.size(); ++i)
1985 if (i != renumber[i])
1986 is_lexicographic = false;
1987
1988 if (is_lexicographic)
1989 renumber.clear();
1990
1991 use_linear_path = (poly.size() == 2 && poly[0].value(0.) == 1. &&
1992 poly[0].value(1.) == 0. && poly[1].value(0.) == 0. &&
1993 poly[1].value(1.) == 1.) &&
1994 (fe->n_components() == n_components);
1995
1996 const unsigned int size_face = 3 * dofs_per_component_face * n_components;
1997 const unsigned int size_cell = dofs_per_component * n_components;
1998 scratch_data_scalar.resize(size_face + size_cell);
1999
2000 solution_renumbered.resize(dofs_per_component);
2001 solution_renumbered_vectorized.resize(dofs_per_component);
2002
2003 fast_path = true;
2004 }
2005 else
2006 {
2007 nonzero_shape_function_component.resize(fe->n_dofs_per_cell());
2008 for (unsigned int d = 0; d < n_components; ++d)
2009 {
2010 const unsigned int component = first_selected_component + d;
2011 for (unsigned int i = 0; i < fe->n_dofs_per_cell(); ++i)
2012 {
2013 const bool is_primitive =
2014 fe->is_primitive() || fe->is_primitive(i);
2015 if (is_primitive)
2016 nonzero_shape_function_component[i][d] =
2017 (component == fe->system_to_component_index(i).first);
2018 else
2019 nonzero_shape_function_component[i][d] =
2020 (fe->get_nonzero_components(i)[component] == true);
2021 }
2022 }
2023
2024 fast_path = false;
2025 }
2026 }
2027
2028
2029
2030 template <int n_components_, int dim, int spacedim, typename Number>
2031 template <bool is_face, bool is_linear>
2032 inline void
2033 FEPointEvaluationBase<n_components_, dim, spacedim, Number>::do_reinit()
2034 {
2035 const unsigned int geometry_index =
2036 mapping_info->template compute_geometry_index_offset<is_face>(
2037 current_cell_index, current_face_number);
2038
2039 cell_type = mapping_info->get_cell_type(geometry_index);
2040
2041 const_cast<unsigned int &>(n_q_points_scalar) =
2042 mapping_info->get_n_q_points_unvectorized(geometry_index);
2043
2044 // round up n_q_points_scalar / n_lanes_internal
2045 const_cast<unsigned int &>(n_q_batches) =
2046 (n_q_points_scalar + n_lanes_internal - 1) / n_lanes_internal;
2047
2048 const unsigned int n_q_points_before = n_q_points;
2049
2050 const_cast<unsigned int &>(n_q_points) =
2051 (stride == 1) ? n_q_batches : n_q_points_scalar;
2052
2053 if (n_q_points != n_q_points_before)
2054 {
2055 if (update_flags & update_values)
2056 values.resize(n_q_points);
2057 if (update_flags & update_gradients)
2058 gradients.resize(n_q_points);
2059 }
2060
2061 if (n_q_points == 0)
2062 return;
2063
2064 // set unit point pointer
2065 const unsigned int unit_point_offset =
2066 mapping_info->compute_unit_point_index_offset(geometry_index);
2067
2068 if (is_face)
2069 unit_point_faces_ptr =
2070 mapping_info->get_unit_point_faces(unit_point_offset);
2071 else
2072 unit_point_ptr = mapping_info->get_unit_point(unit_point_offset);
2073
2074 // set data pointers
2075 const unsigned int data_offset =
2076 mapping_info->compute_data_index_offset(geometry_index);
2077 const unsigned int compressed_data_offset =
2078 mapping_info->compute_compressed_data_index_offset(geometry_index);
2079 if constexpr (running_in_debug_mode())
2080 {
2081 const UpdateFlags update_flags_mapping =
2082 mapping_info->get_update_flags_mapping();
2083 if (update_flags_mapping & UpdateFlags::update_quadrature_points)
2084 real_point_ptr = mapping_info->get_real_point(data_offset);
2085 if (update_flags_mapping & UpdateFlags::update_jacobians)
2086 jacobian_ptr =
2087 mapping_info->get_jacobian(compressed_data_offset, is_interior);
2088 if (update_flags_mapping & UpdateFlags::update_inverse_jacobians)
2089 inverse_jacobian_ptr =
2090 mapping_info->get_inverse_jacobian(compressed_data_offset,
2091 is_interior);
2092 if (update_flags_mapping & UpdateFlags::update_normal_vectors)
2093 normal_ptr = mapping_info->get_normal_vector(data_offset);
2094 if (update_flags_mapping & UpdateFlags::update_JxW_values)
2095 JxW_ptr = mapping_info->get_JxW(data_offset);
2096 }
2097 else
2098 {
2099 real_point_ptr = mapping_info->get_real_point(data_offset);
2100 jacobian_ptr =
2101 mapping_info->get_jacobian(compressed_data_offset, is_interior);
2102 inverse_jacobian_ptr =
2103 mapping_info->get_inverse_jacobian(compressed_data_offset, is_interior);
2104 normal_ptr = mapping_info->get_normal_vector(data_offset);
2105 JxW_ptr = mapping_info->get_JxW(data_offset);
2106 }
2107
2108 if (!is_linear && fast_path)
2109 {
2110 const std::size_t n_shapes = poly.size();
2111 if (is_face)
2112 shapes_faces.resize_fast(n_q_batches * n_shapes);
2113 else
2114 shapes.resize_fast(n_q_batches * n_shapes);
2115
2116 for (unsigned int qb = 0; qb < n_q_batches; ++qb)
2117 if (is_face)
2118 {
2119 if (dim > 1)
2120 {
2121 internal::compute_values_of_array(
2122 shapes_faces.data() + qb * n_shapes,
2123 poly,
2124 unit_point_faces_ptr[qb],
2125 update_flags & UpdateFlags::update_gradients ? 1 : 0);
2126 }
2127 }
2128 else
2129 {
2130 if (update_flags & UpdateFlags::update_gradients)
2131 {
2132 internal::compute_values_of_array(shapes.data() + qb * n_shapes,
2133 poly,
2134 unit_point_ptr[qb],
2135 1);
2136 }
2137 else if (qb + 1 < n_q_batches)
2138 {
2139 // Use function with reduced overhead to compute for two
2140 // points at once
2141 internal::compute_values_of_array_in_pairs(
2142 shapes.data() + qb * n_shapes,
2143 poly,
2144 unit_point_ptr[qb],
2145 unit_point_ptr[qb + 1]);
2146 ++qb;
2147 }
2148 else
2149 {
2150 internal::compute_values_of_array(shapes.data() + qb * n_shapes,
2151 poly,
2152 unit_point_ptr[qb],
2153 0);
2154 }
2155 }
2156 }
2157 }
2158
2159
2160
2161 template <int n_components_, int dim, int spacedim, typename Number>
2162 inline const typename FEPointEvaluationBase<n_components_,
2163 dim,
2164 spacedim,
2165 Number>::value_type &
2166 FEPointEvaluationBase<n_components_, dim, spacedim, Number>::get_value(
2167 const unsigned int point_index) const
2168 {
2169 AssertIndexRange(point_index, values.size());
2170 return values[point_index];
2171 }
2172
2173
2174
2175 template <int n_components_, int dim, int spacedim, typename Number>
2176 inline const typename FEPointEvaluationBase<n_components_,
2177 dim,
2178 spacedim,
2179 Number>::gradient_type &
2180 FEPointEvaluationBase<n_components_, dim, spacedim, Number>::get_gradient(
2181 const unsigned int point_index) const
2182 {
2183 AssertIndexRange(point_index, gradients.size());
2184 return gradients[point_index];
2185 }
2186
2187
2188
2189 template <int n_components_, int dim, int spacedim, typename Number>
2190 inline Number
2191 FEPointEvaluationBase<n_components_, dim, spacedim, Number>::get_divergence(
2192 const unsigned int point_index) const
2193 {
2194 static_assert(n_components == dim,
2195 "Only makes sense for a vector field with dim components");
2196
2197 AssertIndexRange(point_index, values.size());
2198 return trace(gradients[point_index]);
2199 }
2200
2201
2202
2203 template <int n_components_, int dim, int spacedim, typename Number>
2204 inline void
2205 FEPointEvaluationBase<n_components_, dim, spacedim, Number>::submit_value(
2206 const value_type &value,
2207 const unsigned int point_index)
2208 {
2209 AssertIndexRange(point_index, n_q_points);
2210 values[point_index] = value;
2211 }
2212
2213
2214
2215 template <int n_components_, int dim, int spacedim, typename Number>
2216 inline void
2217 FEPointEvaluationBase<n_components_, dim, spacedim, Number>::submit_gradient(
2218 const gradient_type &gradient,
2219 const unsigned int point_index)
2220 {
2221 AssertIndexRange(point_index, n_q_points);
2222 gradients[point_index] = gradient;
2223 }
2224
2225
2226
2227 template <int n_components_, int dim, int spacedim, typename Number>
2228 inline void
2229 FEPointEvaluationBase<n_components_, dim, spacedim, Number>::submit_divergence(
2230 const Number &value,
2231 const unsigned int point_index)
2232 {
2233 static_assert(n_components == dim,
2234 "Only makes sense for a vector field with dim components");
2235
2236 AssertIndexRange(point_index, n_q_points);
2237 gradients[point_index] = gradient_type();
2238 for (unsigned int d = 0; d < dim; ++d)
2239 gradients[point_index][d][d] = value;
2240 }
2241
2242
2243
2244 template <int n_components_, int dim, int spacedim, typename Number>
2245 Tensor<1, (dim == 2 ? 1 : dim), Number>
2246 FEPointEvaluationBase<n_components_, dim, spacedim, Number>::get_curl(
2247 const unsigned int point_index) const
2248 {
2249 static_assert(
2250 dim > 1 && n_components == dim,
2251 "Only makes sense for a vector field with dim components and dim > 1");
2252
2253 const Tensor<2, dim, Number> grad = get_gradient(point_index);
2254 Tensor<1, (dim == 2 ? 1 : dim), Number> curl;
2255 switch (dim)
2256 {
2257 case 2:
2258 curl[0] = grad[1][0] - grad[0][1];
2259 break;
2260 case 3:
2261 curl[0] = grad[2][1] - grad[1][2];
2262 curl[1] = grad[0][2] - grad[2][0];
2263 curl[2] = grad[1][0] - grad[0][1];
2264 break;
2265 default:
2266 DEAL_II_NOT_IMPLEMENTED();
2267 }
2268 return curl;
2269 }
2270
2271
2272
2273 template <int n_components_, int dim, int spacedim, typename Number>
2274 inline DerivativeForm<1, dim, spacedim, Number>
2275 FEPointEvaluationBase<n_components_, dim, spacedim, Number>::jacobian(
2276 const unsigned int point_index) const
2277 {
2278 AssertIndexRange(point_index, n_q_points);
2279 Assert(jacobian_ptr != nullptr,
2280 internal::FEPointEvaluation::
2281 ExcFEPointEvaluationAccessToUninitializedMappingField(
2282 "update_jacobians"));
2283 return jacobian_ptr[cell_type <= ::dealii::internal::MatrixFreeFunctions::
2284 GeometryType::affine ?
2285 0 :
2286 point_index];
2287 }
2288
2289
2290
2291 template <int n_components_, int dim, int spacedim, typename Number>
2292 inline DerivativeForm<1, spacedim, dim, Number>
2293 FEPointEvaluationBase<n_components_, dim, spacedim, Number>::inverse_jacobian(
2294 const unsigned int point_index) const
2295 {
2296 AssertIndexRange(point_index, n_q_points);
2297 Assert(inverse_jacobian_ptr != nullptr,
2298 internal::FEPointEvaluation::
2299 ExcFEPointEvaluationAccessToUninitializedMappingField(
2300 "update_inverse_jacobians"));
2301 return inverse_jacobian_ptr
2302 [cell_type <=
2303 ::dealii::internal::MatrixFreeFunctions::GeometryType::affine ?
2304 0 :
2305 point_index];
2306 }
2307
2308
2309
2310 template <int n_components_, int dim, int spacedim, typename Number>
2311 inline Number
2312 FEPointEvaluationBase<n_components_, dim, spacedim, Number>::JxW(
2313 const unsigned int point_index) const
2314 {
2315 AssertIndexRange(point_index, n_q_points);
2316 Assert(JxW_ptr != nullptr,
2317 internal::FEPointEvaluation::
2318 ExcFEPointEvaluationAccessToUninitializedMappingField(
2319 "update_JxW_values"));
2320 return JxW_ptr[point_index];
2321 }
2322
2323
2324
2325 template <int n_components_, int dim, int spacedim, typename Number>
2326 inline Point<spacedim, Number>
2327 FEPointEvaluationBase<n_components_, dim, spacedim, Number>::real_point(
2328 const unsigned int point_index) const
2329 {
2330 return quadrature_point(point_index);
2331 }
2332
2333
2334
2335 template <int n_components_, int dim, int spacedim, typename Number>
2336 inline Point<spacedim, Number>
2337 FEPointEvaluationBase<n_components_, dim, spacedim, Number>::quadrature_point(
2338 const unsigned int point_index) const
2339 {
2340 AssertIndexRange(point_index, n_q_points);
2341 Assert(real_point_ptr != nullptr,
2342 internal::FEPointEvaluation::
2343 ExcFEPointEvaluationAccessToUninitializedMappingField(
2344 "update_quadrature_points"));
2345 return real_point_ptr[point_index];
2346 }
2347
2348
2349
2350 template <int n_components_, int dim, int spacedim, typename Number>
2351 inline Point<dim, Number>
2352 FEPointEvaluationBase<n_components_, dim, spacedim, Number>::unit_point(
2353 const unsigned int point_index) const
2354 {
2355 AssertIndexRange(point_index, n_q_points);
2356 Assert(unit_point_ptr != nullptr, ExcMessage("unit_point_ptr is not set!"));
2357 Point<dim, Number> unit_point;
2358 for (unsigned int d = 0; d < dim; ++d)
2359 unit_point[d] = internal::VectorizedArrayTrait<Number>::get_from_vectorized(
2360 unit_point_ptr[point_index / stride][d], point_index % stride);
2361 return unit_point;
2362 }
2363
2364
2365
2366 template <int n_components_, int dim, int spacedim, typename Number>
2367 inline std_cxx20::ranges::iota_view<unsigned int, unsigned int>
2368 FEPointEvaluationBase<n_components_, dim, spacedim, Number>::
2369 quadrature_point_indices() const
2370 {
2371 return std_cxx20::ranges::iota_view<unsigned int, unsigned int>(0U,
2372 n_q_points);
2373 }
2374
2375
2376
2377 template <int n_components_, int dim, int spacedim, typename Number>
2378 FEPointEvaluation<n_components_, dim, spacedim, Number>::FEPointEvaluation(
2379 const NonMatching::MappingInfo<dim, spacedim, Number> &mapping_info,
2380 const FiniteElement<dim, spacedim> &fe,
2381 const unsigned int first_selected_component,
2382 const bool force_lexicographic_numbering)
2383 : FEPointEvaluationBase<n_components_, dim, spacedim, Number>(
2384 mapping_info,
2385 fe,
2386 first_selected_component)
2387 , lexicographic_numbering(force_lexicographic_numbering ||
2388 this->renumber.empty())
2389 {}
2390
2391
2392
2393 template <int n_components_, int dim, int spacedim, typename Number>
2394 FEPointEvaluation<n_components_, dim, spacedim, Number>::FEPointEvaluation(
2395 const Mapping<dim, spacedim> &mapping,
2396 const FiniteElement<dim, spacedim> &fe,
2397 const UpdateFlags update_flags,
2398 const unsigned int first_selected_component,
2399 const bool force_lexicographic_numbering)
2400 : FEPointEvaluationBase<n_components_, dim, spacedim, Number>(
2401 mapping,
2402 fe,
2403 update_flags,
2404 first_selected_component)
2405 , lexicographic_numbering(force_lexicographic_numbering ||
2406 this->renumber.empty())
2407 {}
2408
2409
2410
2411 template <int n_components_, int dim, int spacedim, typename Number>
2412 inline void
2413 FEPointEvaluation<n_components_, dim, spacedim, Number>::
2414 internal_reinit_single_cell_state_mapping_info()
2415 {
2416 this->current_cell_index = numbers::invalid_unsigned_int;
2417 this->current_face_number = numbers::invalid_unsigned_int;
2418
2419 if (this->use_linear_path)
2420 this->template do_reinit<false, true>();
2421 else
2422 this->template do_reinit<false, false>();
2423 }
2424
2425
2426
2427 template <int n_components_, int dim, int spacedim, typename Number>
2428 inline void
2429 FEPointEvaluation<n_components_, dim, spacedim, Number>::reinit()
2430 {
2431 internal_reinit_single_cell_state_mapping_info();
2432 this->must_reinitialize_pointers = false;
2433 }
2434
2435
2436
2437 template <int n_components_, int dim, int spacedim, typename Number>
2438 inline void
2439 FEPointEvaluation<n_components_, dim, spacedim, Number>::reinit(
2440 const typename Triangulation<dim, spacedim>::cell_iterator &cell,
2441 const ArrayView<const Point<dim>> &unit_points)
2442 {
2443 // reinit is only allowed for mapping computation on the fly
2444 AssertThrow(this->mapping_info_on_the_fly.get() != nullptr,
2445 ExcNotImplemented());
2446
2447 this->mapping_info_on_the_fly->reinit(cell, unit_points);
2448 this->must_reinitialize_pointers = false;
2449
2450 if (!this->fast_path)
2451 {
2452 this->fe_values = std::make_shared<FEValues<dim, spacedim>>(
2453 *this->mapping,
2454 *this->fe,
2455 Quadrature<dim>(
2456 std::vector<Point<dim>>(unit_points.begin(), unit_points.end())),
2457 this->update_flags);
2458 this->fe_values->reinit(cell);
2459 }
2460
2461 if (this->use_linear_path)
2462 this->template do_reinit<false, true>();
2463 else
2464 this->template do_reinit<false, false>();
2465 }
2466
2467
2468
2469 template <int n_components_, int dim, int spacedim, typename Number>
2470 inline void
2471 FEPointEvaluation<n_components_, dim, spacedim, Number>::reinit(
2472 const unsigned int cell_index)
2473 {
2474 this->current_cell_index = cell_index;
2475 this->current_face_number = numbers::invalid_unsigned_int;
2476 this->must_reinitialize_pointers = false;
2477
2478 if (this->use_linear_path)
2479 this->template do_reinit<false, true>();
2480 else
2481 this->template do_reinit<false, false>();
2482
2483 if (!this->fast_path)
2484 {
2485 std::vector<Point<dim>> unit_points(this->n_q_points_scalar);
2486
2487 for (unsigned int v = 0; v < this->n_q_points_scalar; ++v)
2488 for (unsigned int d = 0; d < dim; ++d)
2489 unit_points[v][d] =
2490 this->unit_point_ptr[v / n_lanes_internal][d][v % n_lanes_internal];
2491
2492 this->fe_values = std::make_shared<FEValues<dim, spacedim>>(
2493 *this->mapping,
2494 *this->fe,
2495 Quadrature<dim>(
2496 std::vector<Point<dim>>(unit_points.begin(), unit_points.end())),
2497 this->update_flags);
2498
2499 this->fe_values->reinit(
2500 this->mapping_info->get_cell_iterator(this->current_cell_index));
2501 }
2502 }
2503
2504
2505
2506 template <int n_components_, int dim, int spacedim, typename Number>
2507 template <std::size_t stride_view>
2508 void
2509 FEPointEvaluation<n_components_, dim, spacedim, Number>::evaluate(
2510 const StridedArrayView<const ScalarNumber, stride_view> &solution_values,
2511 const EvaluationFlags::EvaluationFlags &evaluation_flags)
2512 {
2513 Assert(!(evaluation_flags & EvaluationFlags::hessians), ExcNotImplemented());
2514
2515 if (!((evaluation_flags & EvaluationFlags::values) ||
2516 (evaluation_flags & EvaluationFlags::gradients))) // no evaluation flags
2517 return;
2518
2519 if (this->must_reinitialize_pointers)
2520 internal_reinit_single_cell_state_mapping_info();
2521
2522 if (this->n_q_points == 0)
2523 return;
2524
2525 AssertDimension(solution_values.size(), this->fe->dofs_per_cell);
2526 if (this->fast_path)
2527 {
2528 if (this->use_linear_path)
2529 evaluate_fast<true>(solution_values, evaluation_flags);
2530 else
2531 evaluate_fast<false>(solution_values, evaluation_flags);
2532 }
2533 else
2534 evaluate_slow(solution_values, evaluation_flags);
2535 }
2536
2537
2538
2539 template <int n_components_, int dim, int spacedim, typename Number>
2540 void
2541 FEPointEvaluation<n_components_, dim, spacedim, Number>::evaluate(
2542 const ArrayView<const ScalarNumber> &solution_values,
2543 const EvaluationFlags::EvaluationFlags &evaluation_flags)
2544 {
2545 evaluate(StridedArrayView<const ScalarNumber, 1>(solution_values.data(),
2546 solution_values.size()),
2547 evaluation_flags);
2548 }
2549
2550
2551
2552 template <int n_components_, int dim, int spacedim, typename Number>
2553 template <std::size_t stride_view>
2554 void
2555 FEPointEvaluation<n_components_, dim, spacedim, Number>::integrate(
2556 const StridedArrayView<ScalarNumber, stride_view> &solution_values,
2557 const EvaluationFlags::EvaluationFlags &integration_flags,
2558 const bool sum_into_values)
2559 {
2560 do_integrate<true>(solution_values, integration_flags, sum_into_values);
2561 }
2562
2563
2564
2565 template <int n_components_, int dim, int spacedim, typename Number>
2566 void
2567 FEPointEvaluation<n_components_, dim, spacedim, Number>::integrate(
2568 const ArrayView<ScalarNumber> &solution_values,
2569 const EvaluationFlags::EvaluationFlags &integration_flags,
2570 const bool sum_into_values)
2571 {
2572 integrate(StridedArrayView<ScalarNumber, 1>(solution_values.data(),
2573 solution_values.size()),
2574 integration_flags,
2575 sum_into_values);
2576 }
2577
2578
2579
2580 template <int n_components_, int dim, int spacedim, typename Number>
2581 inline typename FEPointEvaluationBase<n_components_, dim, spacedim, Number>::
2582 scalar_value_type
2583 FEPointEvaluationBase<n_components_, dim, spacedim, Number>::integrate_value()
2584 const
2585 {
2586 value_type return_value = {};
2587
2588 for (const auto point_index : this->quadrature_point_indices())
2589 return_value += values[point_index] * this->JxW(point_index);
2590
2591 return ETT::sum_value(return_value);
2592 }
2593
2594
2595
2596 template <int n_components_, int dim, int spacedim, typename Number>
2597 unsigned int
2598 FEPointEvaluationBase<n_components_, dim, spacedim, Number>::
2599 n_active_entries_per_quadrature_batch(unsigned int q)
2600 {
2601 Assert(stride == 1,
2602 ExcMessage(
2603 "Calling this function only makes sense in fully vectorized mode."));
2604 if (q == n_q_batches - 1)
2605 {
2606 const unsigned int n_filled_lanes =
2607 n_q_points_scalar & (n_lanes_user_interface - 1);
2608 if (n_filled_lanes == 0)
2609 return n_lanes_user_interface;
2610 else
2611 return n_filled_lanes;
2612 }
2613 else
2614 return n_lanes_user_interface;
2615 }
2616
2617
2618
2619 template <int n_components_, int dim, int spacedim, typename Number>
2620 template <std::size_t stride_view>
2621 void
2622 FEPointEvaluation<n_components_, dim, spacedim, Number>::test_and_sum(
2623 const StridedArrayView<ScalarNumber, stride_view> &solution_values,
2624 const EvaluationFlags::EvaluationFlags &integration_flags,
2625 const bool sum_into_values)
2626 {
2627 do_integrate<false>(solution_values, integration_flags, sum_into_values);
2628 }
2629
2630
2631
2632 template <int n_components_, int dim, int spacedim, typename Number>
2633 void
2634 FEPointEvaluation<n_components_, dim, spacedim, Number>::test_and_sum(
2635 const ArrayView<ScalarNumber> &solution_values,
2636 const EvaluationFlags::EvaluationFlags &integration_flags,
2637 const bool sum_into_values)
2638 {
2639 test_and_sum(StridedArrayView<ScalarNumber, 1>(solution_values.data(),
2640 solution_values.size()),
2641 integration_flags,
2642 sum_into_values);
2643 }
2644
2645
2646
2647 template <int n_components_, int dim, int spacedim, typename Number>
2648 template <bool is_linear, std::size_t stride_view>
2649 inline void
2650 FEPointEvaluation<n_components_, dim, spacedim, Number>::prepare_evaluate_fast(
2651 const StridedArrayView<const ScalarNumber, stride_view> &solution_values)
2652 {
2653 const unsigned int dofs_per_comp =
2654 is_linear ? Utilities::pow(2, dim) : this->dofs_per_component;
2655
2656 for (unsigned int comp = 0; comp < n_components; ++comp)
2657 {
2658 const std::size_t offset =
2659 (this->component_in_base_element + comp) * dofs_per_comp;
2660
2661 if ((is_linear && n_components == 1) || lexicographic_numbering)
2662 {
2663 for (unsigned int i = 0; i < dofs_per_comp; ++i)
2664 ETT::read_value(solution_values[i + offset],
2665 comp,
2666 this->solution_renumbered[i]);
2667 }
2668 else
2669 {
2670 const unsigned int *renumber_ptr = this->renumber.data() + offset;
2671 for (unsigned int i = 0; i < dofs_per_comp; ++i)
2672 ETT::read_value(solution_values[renumber_ptr[i]],
2673 comp,
2674 this->solution_renumbered[i]);
2675 }
2676 }
2677 }
2678
2679
2680
2681 template <int n_components_, int dim, int spacedim, typename Number>
2682 template <bool is_linear, std::size_t stride_view>
2683 inline void
2684 FEPointEvaluation<n_components_, dim, spacedim, Number>::compute_evaluate_fast(
2685 const StridedArrayView<const ScalarNumber, stride_view> &solution_values,
2686 const EvaluationFlags::EvaluationFlags &evaluation_flags,
2687 const unsigned int n_shapes,
2688 const unsigned int qb,
2689 vectorized_value_type &value,
2690 interface_vectorized_unit_gradient_type &gradient)
2691 {
2692 if (evaluation_flags & EvaluationFlags::gradients)
2693 {
2694 std::array<vectorized_value_type, dim + 1> result;
2695 if constexpr (is_linear)
2696 {
2697 if constexpr (n_components == 1)
2698 result =
2699 internal::evaluate_tensor_product_value_and_gradient_linear<
2700 dim,
2701 scalar_value_type,
2702 VectorizedArrayType,
2703 1,
2704 stride_view>(solution_values.data(), this->unit_point_ptr[qb]);
2705 else
2706 result =
2707 internal::evaluate_tensor_product_value_and_gradient_linear(
2708 this->solution_renumbered.data(), this->unit_point_ptr[qb]);
2709 }
2710 else
2711 result = internal::evaluate_tensor_product_value_and_gradient_shapes<
2712 dim,
2713 scalar_value_type,
2714 VectorizedArrayType,
2715 1,
2716 false>(this->shapes.data() + qb * n_shapes,
2717 n_shapes,
2718 this->solution_renumbered.data());
2719 gradient[0] = result[0];
2720 if (dim > 1)
2721 gradient[1] = result[1];
2722 if (dim > 2)
2723 gradient[2] = result[2];
2724 value = result[dim];
2725 }
2726 else
2727 {
2728 if constexpr (is_linear)
2729 {
2730 if constexpr (n_components == 1)
2731 value = internal::evaluate_tensor_product_value_linear<
2732 dim,
2733 scalar_value_type,
2734 VectorizedArrayType,
2735 stride_view>(solution_values.data(), this->unit_point_ptr[qb]);
2736 else
2737 value = internal::evaluate_tensor_product_value_linear(
2738 this->solution_renumbered.data(), this->unit_point_ptr[qb]);
2739 }
2740 else
2741 value =
2742 internal::evaluate_tensor_product_value_shapes<dim,
2743 scalar_value_type,
2744 VectorizedArrayType,
2745 false>(
2746 this->shapes.data() + qb * n_shapes,
2747 n_shapes,
2748 this->solution_renumbered.data());
2749 }
2750 }
2751
2752
2753
2754 template <int n_components_, int dim, int spacedim, typename Number>
2755 template <bool is_linear, std::size_t stride_view>
2756 inline void
2757 FEPointEvaluation<n_components_, dim, spacedim, Number>::evaluate_fast(
2758 const StridedArrayView<const ScalarNumber, stride_view> &solution_values,
2759 const EvaluationFlags::EvaluationFlags &evaluation_flags)
2760 {
2761 if (!(is_linear && n_components == 1))
2762 prepare_evaluate_fast<is_linear>(solution_values);
2763
2764 // loop over quadrature batches qb
2765 const unsigned int n_shapes = is_linear ? 2 : this->poly.size();
2766
2767 for (unsigned int qb = 0; qb < this->n_q_batches; ++qb)
2768 {
2769 vectorized_value_type value;
2770 interface_vectorized_unit_gradient_type gradient;
2771
2772 compute_evaluate_fast<is_linear>(
2773 solution_values, evaluation_flags, n_shapes, qb, value, gradient);
2774
2775 if (evaluation_flags & EvaluationFlags::values)
2776 {
2777 for (unsigned int v = 0, offset = qb * stride;
2778 v < stride && (stride == 1 || offset < this->n_q_points_scalar);
2779 ++v, ++offset)
2780 ETT::set_value(value, v, this->values[offset]);
2781 }
2782 if (evaluation_flags & EvaluationFlags::gradients)
2783 {
2784 Assert(this->update_flags & update_gradients ||
2785 this->update_flags & update_inverse_jacobians,
2786 ExcNotInitialized());
2787
2788 for (unsigned int v = 0, offset = qb * stride;
2789 v < stride && (stride == 1 || offset < this->n_q_points_scalar);
2790 ++v, ++offset)
2791 {
2792 unit_gradient_type unit_gradient;
2793 ETT::set_gradient(gradient, v, unit_gradient);
2794 this->gradients[offset] =
2795 this->cell_type <=
2796 internal::MatrixFreeFunctions::GeometryType::cartesian ?
2797 apply_diagonal_transformation(
2798 this->inverse_jacobian_ptr[0].transpose(), unit_gradient) :
2799 apply_transformation(
2800 this
2801 ->inverse_jacobian_ptr[this->cell_type <=
2802 internal::MatrixFreeFunctions::
2803 GeometryType::affine ?
2804 0 :
2805 offset]
2806 .transpose(),
2807 unit_gradient);
2808 }
2809 }
2810 }
2811 }
2812
2813
2814
2815 template <int n_components_, int dim, int spacedim, typename Number>
2816 template <std::size_t stride_view>
2817 inline void
2818 FEPointEvaluation<n_components_, dim, spacedim, Number>::evaluate_slow(
2819 const StridedArrayView<const ScalarNumber, stride_view> &solution_values,
2820 const EvaluationFlags::EvaluationFlags &evaluation_flags)
2821 {
2822 // slow path with FEValues
2823 Assert(this->fe_values.get() != nullptr,
2824 ExcMessage(
2825 "Not initialized. Please call FEPointEvaluation::reinit()!"));
2826
2827 const std::size_t n_points = this->fe_values->get_quadrature().size();
2828
2829 if (evaluation_flags & EvaluationFlags::values)
2830 {
2831 this->values.resize(this->n_q_points);
2832 std::fill(this->values.begin(), this->values.end(), value_type());
2833 for (unsigned int i = 0; i < this->fe->n_dofs_per_cell(); ++i)
2834 {
2835 const ScalarNumber value = solution_values[i];
2836 for (unsigned int d = 0; d < n_components; ++d)
2837 if (this->nonzero_shape_function_component[i][d] &&
2838 (this->fe->is_primitive(i) || this->fe->is_primitive()))
2839 for (unsigned int qb = 0, q = 0; q < n_points;
2840 ++qb, q += n_lanes_user_interface)
2841 for (unsigned int v = 0;
2842 v < n_lanes_user_interface && q + v < n_points;
2843 ++v)
2844 ETT::access(this->values[qb],
2845 v,
2846 d,
2847 this->fe_values->shape_value(i, q + v) * value);
2848 else if (this->nonzero_shape_function_component[i][d])
2849 for (unsigned int qb = 0, q = 0; q < n_points;
2850 ++qb, q += n_lanes_user_interface)
2851 for (unsigned int v = 0;
2852 v < n_lanes_user_interface && q + v < n_points;
2853 ++v)
2854 ETT::access(this->values[qb],
2855 v,
2856 d,
2857 this->fe_values->shape_value_component(i,
2858 q + v,
2859 d) *
2860 value);
2861 }
2862 }
2863
2864 if (evaluation_flags & EvaluationFlags::gradients)
2865 {
2866 this->gradients.resize(this->n_q_points);
2867 std::fill(this->gradients.begin(),
2868 this->gradients.end(),
2869 gradient_type());
2870 for (unsigned int i = 0; i < this->fe->n_dofs_per_cell(); ++i)
2871 {
2872 const ScalarNumber value = solution_values[i];
2873 for (unsigned int d = 0; d < n_components; ++d)
2874 if (this->nonzero_shape_function_component[i][d] &&
2875 (this->fe->is_primitive(i) || this->fe->is_primitive()))
2876 for (unsigned int qb = 0, q = 0; q < n_points;
2877 ++qb, q += n_lanes_user_interface)
2878 for (unsigned int v = 0;
2879 v < n_lanes_user_interface && q + v < n_points;
2880 ++v)
2881 ETT::access(this->gradients[qb],
2882 v,
2883 d,
2884 this->fe_values->shape_grad(i, q + v) * value);
2885 else if (this->nonzero_shape_function_component[i][d])
2886 for (unsigned int qb = 0, q = 0; q < n_points;
2887 ++qb, q += n_lanes_user_interface)
2888 for (unsigned int v = 0;
2889 v < n_lanes_user_interface && q + v < n_points;
2890 ++v)
2891 ETT::access(
2892 this->gradients[qb],
2893 v,
2894 d,
2895 this->fe_values->shape_grad_component(i, q + v, d) * value);
2896 }
2897 }
2898 }
2899
2900
2901
2902 template <int n_components_, int dim, int spacedim, typename Number>
2903 template <bool is_linear>
2904 inline void
2905 FEPointEvaluation<n_components_, dim, spacedim, Number>::compute_integrate_fast(
2906 const EvaluationFlags::EvaluationFlags &integration_flags,
2907 const unsigned int n_shapes,
2908 const unsigned int qb,
2909 const vectorized_value_type value,
2910 const interface_vectorized_unit_gradient_type gradient,
2911 vectorized_value_type *solution_values_vectorized_linear)
2912 {
2913 if (integration_flags & EvaluationFlags::gradients)
2914 internal::integrate_tensor_product_value_and_gradient<
2915 is_linear,
2916 dim,
2917 VectorizedArrayType,
2918 vectorized_value_type>(this->shapes.data() + qb * n_shapes,
2919 n_shapes,
2920 &value,
2921 gradient,
2922 is_linear ?
2923 solution_values_vectorized_linear :
2924 this->solution_renumbered_vectorized.data(),
2925 this->unit_point_ptr[qb],
2926 qb != 0);
2927 else
2928 internal::integrate_tensor_product_value<is_linear,
2929 dim,
2930 VectorizedArrayType,
2931 vectorized_value_type>(
2932 this->shapes.data() + qb * n_shapes,
2933 n_shapes,
2934 value,
2935 is_linear ? solution_values_vectorized_linear :
2936 this->solution_renumbered_vectorized.data(),
2937 this->unit_point_ptr[qb],
2938 qb != 0);
2939 }
2940
2941
2942
2943 template <int n_components_, int dim, int spacedim, typename Number>
2944 template <bool is_linear, std::size_t stride_view>
2945 inline void
2946 FEPointEvaluation<n_components_, dim, spacedim, Number>::finish_integrate_fast(
2947 const StridedArrayView<ScalarNumber, stride_view> &solution_values,
2948 vectorized_value_type *solution_values_vectorized_linear,
2949 const bool sum_into_values)
2950 {
2951 if (!sum_into_values && this->fe->n_components() > n_components)
2952 for (unsigned int i = 0; i < solution_values.size(); ++i)
2953 solution_values[i] = 0;
2954
2955 const unsigned int dofs_per_comp =
2956 is_linear ? Utilities::pow(2, dim) : this->dofs_per_component;
2957
2958 for (unsigned int comp = 0; comp < n_components; ++comp)
2959 {
2960 const std::size_t offset =
2961 (this->component_in_base_element + comp) * dofs_per_comp;
2962
2963 if (is_linear || lexicographic_numbering)
2964 {
2965 for (unsigned int i = 0; i < dofs_per_comp; ++i)
2966 if (sum_into_values)
2967 solution_values[i + offset] +=
2968 ETT::sum_value(comp,
2969 is_linear ?
2970 *(solution_values_vectorized_linear + i) :
2971 this->solution_renumbered_vectorized[i]);
2972 else
2973 solution_values[i + offset] =
2974 ETT::sum_value(comp,
2975 is_linear ?
2976 *(solution_values_vectorized_linear + i) :
2977 this->solution_renumbered_vectorized[i]);
2978 }
2979 else
2980 {
2981 const unsigned int *renumber_ptr = this->renumber.data() + offset;
2982 for (unsigned int i = 0; i < dofs_per_comp; ++i)
2983 if (sum_into_values)
2984 solution_values[renumber_ptr[i]] +=
2985 ETT::sum_value(comp, this->solution_renumbered_vectorized[i]);
2986 else
2987 solution_values[renumber_ptr[i]] =
2988 ETT::sum_value(comp, this->solution_renumbered_vectorized[i]);
2989 }
2990 }
2991 }
2992
2993
2994
2995 template <int n_components_, int dim, int spacedim, typename Number>
2996 template <bool do_JxW, bool is_linear, std::size_t stride_view>
2997 inline void
2998 FEPointEvaluation<n_components_, dim, spacedim, Number>::integrate_fast(
2999 const StridedArrayView<ScalarNumber, stride_view> &solution_values,
3000 const EvaluationFlags::EvaluationFlags &integration_flags,
3001 const bool sum_into_values)
3002 {
3003 // zero out lanes of incomplete last quadrature point batch
3004 if constexpr (stride == 1)
3005 if (const unsigned int n_filled_lanes =
3006 this->n_q_points_scalar & (n_lanes_internal - 1);
3007 n_filled_lanes > 0)
3008 {
3009 if (integration_flags & EvaluationFlags::values)
3010 for (unsigned int v = n_filled_lanes; v < n_lanes_internal; ++v)
3011 ETT::set_zero_value(this->values.back(), v);
3012 if (integration_flags & EvaluationFlags::gradients)
3013 for (unsigned int v = n_filled_lanes; v < n_lanes_internal; ++v)
3014 ETT::set_zero_gradient(this->gradients.back(), v);
3015 }
3016
3017 std::array<vectorized_value_type, is_linear ? Utilities::pow(2, dim) : 0>
3018 solution_values_vectorized_linear = {};
3019
3020 // loop over quadrature batches qb
3021 const unsigned int n_shapes = is_linear ? 2 : this->poly.size();
3022
3023 const bool cartesian_cell =
3024 this->cell_type <= internal::MatrixFreeFunctions::GeometryType::cartesian;
3025 const bool affine_cell =
3026 this->cell_type <= internal::MatrixFreeFunctions::GeometryType::affine;
3027 for (unsigned int qb = 0; qb < this->n_q_batches; ++qb)
3028 {
3029 vectorized_value_type value = {};
3030 Tensor<1, dim, vectorized_value_type> gradient;
3031
3032 if (integration_flags & EvaluationFlags::values)
3033 for (unsigned int v = 0, offset = qb * stride;
3034 v < stride && (stride == 1 || offset < this->n_q_points_scalar);
3035 ++v, ++offset)
3036 ETT::get_value(value,
3037 v,
3038 do_JxW ? this->values[offset] * this->JxW_ptr[offset] :
3039 this->values[offset]);
3040
3041 if (integration_flags & EvaluationFlags::gradients)
3042 for (unsigned int v = 0, offset = qb * stride;
3043 v < stride && (stride == 1 || offset < this->n_q_points_scalar);
3044 ++v, ++offset)
3045 {
3046 const gradient_type grad_w =
3047 do_JxW ? this->gradients[offset] * this->JxW_ptr[offset] :
3048 this->gradients[offset];
3049 ETT::get_gradient(
3050 gradient,
3051 v,
3052 cartesian_cell ?
3053 apply_diagonal_transformation(this->inverse_jacobian_ptr[0],
3054 grad_w) :
3055 apply_transformation(
3056 this->inverse_jacobian_ptr[affine_cell ? 0 : offset],
3057 grad_w));
3058 }
3059
3060 compute_integrate_fast<is_linear>(
3061 integration_flags,
3062 n_shapes,
3063 qb,
3064 value,
3065 gradient,
3066 solution_values_vectorized_linear.data());
3067 }
3068
3069 // add between the lanes and write into the result
3070 finish_integrate_fast<is_linear>(solution_values,
3071 solution_values_vectorized_linear.data(),
3072 sum_into_values);
3073 }
3074
3075
3076
3077 template <int n_components_, int dim, int spacedim, typename Number>
3078 template <bool do_JxW, std::size_t stride_view>
3079 inline void
3080 FEPointEvaluation<n_components_, dim, spacedim, Number>::integrate_slow(
3081 const StridedArrayView<ScalarNumber, stride_view> &solution_values,
3082 const EvaluationFlags::EvaluationFlags &integration_flags,
3083 const bool sum_into_values)
3084 {
3085 // slow path with FEValues
3086 Assert(this->fe_values.get() != nullptr,
3087 ExcMessage(
3088 "Not initialized. Please call FEPointEvaluation::reinit()!"));
3089 if (!sum_into_values)
3090 for (unsigned int i = 0; i < solution_values.size(); ++i)
3091 solution_values[i] = 0;
3092
3093 const std::size_t n_points = this->fe_values->get_quadrature().size();
3094
3095 if (integration_flags & EvaluationFlags::values)
3096 {
3097 AssertIndexRange(this->n_q_points, this->values.size() + 1);
3098 for (unsigned int i = 0; i < this->fe->n_dofs_per_cell(); ++i)
3099 {
3100 for (unsigned int d = 0; d < n_components; ++d)
3101 if (this->nonzero_shape_function_component[i][d] &&
3102 (this->fe->is_primitive(i) || this->fe->is_primitive()))
3103 for (unsigned int qb = 0, q = 0; q < n_points;
3104 ++qb, q += n_lanes_user_interface)
3105 for (unsigned int v = 0;
3106 v < n_lanes_user_interface && q + v < n_points;
3107 ++v)
3108 solution_values[i] +=
3109 this->fe_values->shape_value(i, q + v) *
3110 ETT::access(this->values[qb], v, d) *
3111 (do_JxW ? this->fe_values->JxW(q + v) : 1.);
3112 else if (this->nonzero_shape_function_component[i][d])
3113 for (unsigned int qb = 0, q = 0; q < n_points;
3114 ++qb, q += n_lanes_user_interface)
3115 for (unsigned int v = 0;
3116 v < n_lanes_user_interface && q + v < n_points;
3117 ++v)
3118 solution_values[i] +=
3119 this->fe_values->shape_value_component(i, q + v, d) *
3120 ETT::access(this->values[qb], v, d) *
3121 (do_JxW ? this->fe_values->JxW(q + v) : 1.);
3122 }
3123 }
3124
3125 if (integration_flags & EvaluationFlags::gradients)
3126 {
3127 AssertIndexRange(this->n_q_points, this->gradients.size() + 1);
3128 for (unsigned int i = 0; i < this->fe->n_dofs_per_cell(); ++i)
3129 {
3130 for (unsigned int d = 0; d < n_components; ++d)
3131 if (this->nonzero_shape_function_component[i][d] &&
3132 (this->fe->is_primitive(i) || this->fe->is_primitive()))
3133 for (unsigned int qb = 0, q = 0; q < n_points;
3134 ++qb, q += n_lanes_user_interface)
3135 for (unsigned int v = 0;
3136 v < n_lanes_user_interface && q + v < n_points;
3137 ++v)
3138 solution_values[i] +=
3139 this->fe_values->shape_grad(i, q + v) *
3140 ETT::access(this->gradients[qb], v, d) *
3141 (do_JxW ? this->fe_values->JxW(q + v) : 1.);
3142 else if (this->nonzero_shape_function_component[i][d])
3143 for (unsigned int qb = 0, q = 0; q < n_points;
3144 ++qb, q += n_lanes_user_interface)
3145 for (unsigned int v = 0;
3146 v < n_lanes_user_interface && q + v < n_points;
3147 ++v)
3148 solution_values[i] +=
3149 this->fe_values->shape_grad_component(i, q + v, d) *
3150 ETT::access(this->gradients[qb], v, d) *
3151 (do_JxW ? this->fe_values->JxW(q + v) : 1.);
3152 }
3153 }
3154 }
3155
3156
3157
3158 template <int n_components_, int dim, int spacedim, typename Number>
3159 template <bool do_JxW, std::size_t stride_view>
3160 void
3161 FEPointEvaluation<n_components_, dim, spacedim, Number>::do_integrate(
3162 const StridedArrayView<ScalarNumber, stride_view> &solution_values,
3163 const EvaluationFlags::EvaluationFlags &integration_flags,
3164 const bool sum_into_values)
3165 {
3166 if (this->must_reinitialize_pointers)
3167 internal_reinit_single_cell_state_mapping_info();
3168
3169 Assert(!(integration_flags & EvaluationFlags::hessians), ExcNotImplemented());
3170
3171 if (this->n_q_points == 0 || // no evaluation points provided
3172 !((integration_flags & EvaluationFlags::values) ||
3173 (integration_flags &
3174 EvaluationFlags::gradients))) // no integration flags
3175 {
3176 if (!sum_into_values)
3177 for (unsigned int i = 0; i < solution_values.size(); ++i)
3178 solution_values[i] = 0;
3179 return;
3180 }
3181
3182 Assert(
3183 !do_JxW || this->JxW_ptr != nullptr,
3184 ExcMessage(
3185 "JxW pointer is not set! If you do not want to integrate() use test_and_sum()"));
3186
3187 AssertDimension(solution_values.size(), this->fe->dofs_per_cell);
3188 if (this->fast_path)
3189 {
3190 if (this->use_linear_path)
3191 integrate_fast<do_JxW, true>(solution_values,
3192 integration_flags,
3193 sum_into_values);
3194 else
3195 integrate_fast<do_JxW, false>(solution_values,
3196 integration_flags,
3197 sum_into_values);
3198 }
3199 else
3200 integrate_slow<do_JxW>(solution_values, integration_flags, sum_into_values);
3201 }
3202
3203
3204
3205 template <int n_components_, int dim, int spacedim, typename Number>
3206 inline Tensor<1, spacedim, Number>
3207 FEPointEvaluation<n_components_, dim, spacedim, Number>::normal_vector(
3208 const unsigned int point_index) const
3209 {
3210 AssertIndexRange(point_index, this->n_q_points);
3211 Assert(this->normal_ptr != nullptr,
3212 internal::FEPointEvaluation::
3213 ExcFEPointEvaluationAccessToUninitializedMappingField(
3214 "update_normal_vectors"));
3215 return this->normal_ptr[point_index];
3216 }
3217
3218
3219
3220 template <int n_components_, int dim, int spacedim, typename Number>
3221 inline const typename FEPointEvaluation<n_components_,
3222 dim,
3223 spacedim,
3224 Number>::value_type
3225 FEPointEvaluation<n_components_, dim, spacedim, Number>::get_normal_derivative(
3226 const unsigned int point_index) const
3227 {
3228 AssertIndexRange(point_index, this->gradients.size());
3229
3230 value_type normal_derivative;
3231 if constexpr (n_components == 1)
3232 normal_derivative =
3233 this->gradients[point_index] * normal_vector(point_index);
3234 else
3235 for (unsigned int comp = 0; comp < n_components; ++comp)
3236 normal_derivative[comp] =
3237 this->gradients[point_index][comp] * normal_vector(point_index);
3238
3239 return normal_derivative;
3240 }
3241
3242
3243
3244 template <int n_components_, int dim, int spacedim, typename Number>
3245 inline void
3246 FEPointEvaluation<n_components_, dim, spacedim, Number>::
3247 submit_normal_derivative(const value_type &value,
3248 const unsigned int point_index)
3249 {
3250 AssertIndexRange(point_index, this->gradients.size());
3251 if constexpr (n_components == 1)
3252 this->gradients[point_index] = value * normal_vector(point_index);
3253 else
3254 for (unsigned int comp = 0; comp < n_components; ++comp)
3255 this->gradients[point_index][comp] =
3256 value[comp] * normal_vector(point_index);
3257 }
3258
3259
3260
3261 template <int n_components_, int dim, int spacedim, typename Number>
3262 FEFacePointEvaluation<n_components_, dim, spacedim, Number>::
3263 FEFacePointEvaluation(
3264 const NonMatching::MappingInfo<dim, spacedim, Number> &mapping_info,
3265 const FiniteElement<dim, spacedim> &fe,
3266 const bool is_interior,
3267 const unsigned int first_selected_component)
3268 : FEPointEvaluationBase<n_components_, dim, spacedim, Number>(
3269 mapping_info,
3270 fe,
3271 first_selected_component,
3272 is_interior)
3273 {}
3274
3275
3276
3277 template <int n_components_, int dim, int spacedim, typename Number>
3278 inline void
3279 FEFacePointEvaluation<n_components_, dim, spacedim, Number>::reinit(
3280 const unsigned int cell_index,
3281 const unsigned int face_number)
3282 {
3283 this->current_cell_index = cell_index;
3284 this->current_face_number = face_number;
3285 this->must_reinitialize_pointers = false;
3286
3287 if (this->use_linear_path)
3288 this->template do_reinit<true, true>();
3289 else
3290 this->template do_reinit<true, false>();
3291 }
3292
3293
3294
3295 template <int n_components_, int dim, int spacedim, typename Number>
3296 inline void
3297 FEFacePointEvaluation<n_components_, dim, spacedim, Number>::reinit(
3298 const unsigned int face_index)
3299 {
3300 this->current_cell_index = face_index;
3301 this->current_face_number =
3302 this->mapping_info->get_face_number(face_index, this->is_interior);
3303 this->must_reinitialize_pointers = false;
3304
3305 if (this->use_linear_path)
3306 this->template do_reinit<true, true>();
3307 else
3308 this->template do_reinit<true, false>();
3309 }
3310
3311
3312
3313 template <int n_components_, int dim, int spacedim, typename Number>
3314 template <std::size_t stride_view>
3315 void
3316 FEFacePointEvaluation<n_components_, dim, spacedim, Number>::evaluate(
3317 const StridedArrayView<const ScalarNumber, stride_view> &solution_values,
3318 const EvaluationFlags::EvaluationFlags &evaluation_flags)
3319 {
3320 Assert(!this->must_reinitialize_pointers,
3321 ExcMessage("Object has not been reinitialized!"));
3322
3323 if (this->n_q_points == 0)
3324 return;
3325
3326 Assert(!(evaluation_flags & EvaluationFlags::hessians), ExcNotImplemented());
3327
3328 if (!((evaluation_flags & EvaluationFlags::values) ||
3329 (evaluation_flags & EvaluationFlags::gradients))) // no evaluation flags
3330 return;
3331
3332 AssertDimension(solution_values.size(), this->fe->dofs_per_cell);
3333
3334 if (this->use_linear_path)
3335 do_evaluate<true>(solution_values, evaluation_flags);
3336 else
3337 do_evaluate<false>(solution_values, evaluation_flags);
3338 }
3339
3340
3341
3342 template <int n_components_, int dim, int spacedim, typename Number>
3343 void
3344 FEFacePointEvaluation<n_components_, dim, spacedim, Number>::evaluate(
3345 const ArrayView<const ScalarNumber> &solution_values,
3346 const EvaluationFlags::EvaluationFlags &evaluation_flags)
3347 {
3348 evaluate(StridedArrayView<const ScalarNumber, 1>(solution_values.data(),
3349 solution_values.size()),
3350 evaluation_flags);
3351 }
3352
3353
3354
3355 template <int n_components_, int dim, int spacedim, typename Number>
3356 template <bool is_linear, std::size_t stride_view>
3357 void
3358 FEFacePointEvaluation<n_components_, dim, spacedim, Number>::do_evaluate(
3359 const StridedArrayView<const ScalarNumber, stride_view> &solution_values,
3360 const EvaluationFlags::EvaluationFlags &evaluation_flags)
3361 {
3362 const unsigned int dofs_per_comp =
3363 is_linear ? Utilities::pow(2, dim) : this->dofs_per_component;
3364
3365 const ScalarNumber *input;
3366 if (stride_view == 1 && this->component_in_base_element == 0 &&
3367 (is_linear || this->renumber.empty()))
3368 input = solution_values.data();
3369 else
3370 {
3371 for (unsigned int comp = 0; comp < n_components; ++comp)
3372 {
3373 const std::size_t offset =
3374 (this->component_in_base_element + comp) * dofs_per_comp;
3375
3376 if (is_linear || this->renumber.empty())
3377 {
3378 for (unsigned int i = 0; i < dofs_per_comp; ++i)
3379 this->scratch_data_scalar[i + comp * dofs_per_comp] =
3380 solution_values[i + offset];
3381 }
3382 else
3383 {
3384 const unsigned int *renumber_ptr = this->renumber.data() + offset;
3385 for (unsigned int i = 0; i < dofs_per_comp; ++i)
3386 this->scratch_data_scalar[i + comp * dofs_per_comp] =
3387 solution_values[renumber_ptr[i]];
3388 }
3389 }
3390 input = this->scratch_data_scalar.data();
3391 }
3392
3393 ScalarNumber *output =
3394 this->scratch_data_scalar.begin() + dofs_per_comp * n_components;
3395
3396 internal::FEFaceNormalEvaluationImpl<dim, is_linear ? 1 : -1, ScalarNumber>::
3397 template interpolate<true, false>(n_components,
3398 evaluation_flags,
3399 this->shape_info,
3400 input,
3401 output,
3402 this->current_face_number);
3403
3404 do_evaluate_in_face<is_linear, 1>(output, evaluation_flags);
3405 }
3406
3407
3408
3409 template <int n_components_, int dim, int spacedim, typename Number>
3410 template <std::size_t stride_view>
3411 void
3412 FEFacePointEvaluation<n_components_, dim, spacedim, Number>::integrate(
3413 const StridedArrayView<ScalarNumber, stride_view> &solution_values,
3414 const EvaluationFlags::EvaluationFlags &integration_flags,
3415 const bool sum_into_values)
3416 {
3417 Assert(!this->must_reinitialize_pointers,
3418 ExcMessage("Object has not been reinitialized!"));
3419
3420 Assert(!(integration_flags & EvaluationFlags::hessians), ExcNotImplemented());
3421
3422 if (this->n_q_points == 0 || // no evaluation points provided
3423 !((integration_flags & EvaluationFlags::values) ||
3424 (integration_flags &
3425 EvaluationFlags::gradients))) // no integration flags
3426 {
3427 if (!sum_into_values)
3428 for (unsigned int i = 0; i < solution_values.size(); ++i)
3429 solution_values[i] = 0;
3430 return;
3431 }
3432
3433 AssertDimension(solution_values.size(), this->fe->dofs_per_cell);
3434
3435 if (this->use_linear_path)
3436 do_integrate<true, true>(solution_values,
3437 integration_flags,
3438 sum_into_values);
3439 else
3440 do_integrate<true, false>(solution_values,
3441 integration_flags,
3442 sum_into_values);
3443 }
3444
3445
3446
3447 template <int n_components_, int dim, int spacedim, typename Number>
3448 void
3449 FEFacePointEvaluation<n_components_, dim, spacedim, Number>::integrate(
3450 const ArrayView<ScalarNumber> &solution_values,
3451 const EvaluationFlags::EvaluationFlags &integration_flags,
3452 const bool sum_into_values)
3453 {
3454 integrate(StridedArrayView<ScalarNumber, 1>(solution_values.data(),
3455 solution_values.size()),
3456 integration_flags,
3457 sum_into_values);
3458 }
3459
3460
3461
3462 template <int n_components_, int dim, int spacedim, typename Number>
3463 template <std::size_t stride_view>
3464 void
3465 FEFacePointEvaluation<n_components_, dim, spacedim, Number>::test_and_sum(
3466 const StridedArrayView<ScalarNumber, stride_view> &solution_values,
3467 const EvaluationFlags::EvaluationFlags &integration_flags,
3468 const bool sum_into_values)
3469 {
3470 Assert(!this->must_reinitialize_pointers,
3471 ExcMessage("Object has not been reinitialized!"));
3472
3473 Assert(!(integration_flags & EvaluationFlags::hessians), ExcNotImplemented());
3474
3475 if (this->n_q_points == 0 || // no evaluation points provided
3476 !((integration_flags & EvaluationFlags::values) ||
3477 (integration_flags &
3478 EvaluationFlags::gradients))) // no integration flags
3479 {
3480 if (!sum_into_values)
3481 for (unsigned int i = 0; i < solution_values.size(); ++i)
3482 solution_values[i] = 0;
3483 return;
3484 }
3485
3486 AssertDimension(solution_values.size(), this->fe->dofs_per_cell);
3487
3488 if (this->use_linear_path)
3489 do_integrate<false, true>(solution_values,
3490 integration_flags,
3491 sum_into_values);
3492 else
3493 do_integrate<false, false>(solution_values,
3494 integration_flags,
3495 sum_into_values);
3496 }
3497
3498
3499
3500 template <int n_components_, int dim, int spacedim, typename Number>
3501 void
3502 FEFacePointEvaluation<n_components_, dim, spacedim, Number>::test_and_sum(
3503 const ArrayView<ScalarNumber> &solution_values,
3504 const EvaluationFlags::EvaluationFlags &integration_flags,
3505 const bool sum_into_values)
3506 {
3507 test_and_sum(StridedArrayView<ScalarNumber, 1>(solution_values.data(),
3508 solution_values.size()),
3509 integration_flags,
3510 sum_into_values);
3511 }
3512
3513
3514
3515 template <int n_components_, int dim, int spacedim, typename Number>
3516 template <bool do_JxW, bool is_linear, std::size_t stride_view>
3517 void
3518 FEFacePointEvaluation<n_components_, dim, spacedim, Number>::do_integrate(
3519 const StridedArrayView<ScalarNumber, stride_view> &solution_values,
3520 const EvaluationFlags::EvaluationFlags &integration_flags,
3521 const bool sum_into_values)
3522 {
3523 if (!sum_into_values && this->fe->n_components() > n_components)
3524 for (unsigned int i = 0; i < solution_values.size(); ++i)
3525 solution_values[i] = 0;
3526
3527 do_integrate_in_face<do_JxW, is_linear, 1>(this->scratch_data_scalar.begin(),
3528 integration_flags,
3529 false);
3530
3531 ScalarNumber *input = this->scratch_data_scalar.begin();
3532
3533 if (stride_view == 1 && this->component_in_base_element == 0 &&
3534 (is_linear || this->renumber.empty()))
3535 {
3536 if (sum_into_values)
3537 internal::
3538 FEFaceNormalEvaluationImpl<dim, is_linear ? 1 : -1, ScalarNumber>::
3539 template interpolate<false, true>(n_components,
3540 integration_flags,
3541 this->shape_info,
3542 input,
3543 solution_values.data(),
3544 this->current_face_number);
3545 else
3546 internal::
3547 FEFaceNormalEvaluationImpl<dim, is_linear ? 1 : -1, ScalarNumber>::
3548 template interpolate<false, false>(n_components,
3549 integration_flags,
3550 this->shape_info,
3551 input,
3552 solution_values.data(),
3553 this->current_face_number);
3554 }
3555 else
3556 {
3557 const unsigned int dofs_per_comp_face =
3558 is_linear ? Utilities::pow(2, dim - 1) : this->dofs_per_component_face;
3559
3560 const unsigned int size_input = 3 * dofs_per_comp_face * n_components;
3561 ScalarNumber *output = input + size_input;
3562
3563 internal::
3564 FEFaceNormalEvaluationImpl<dim, is_linear ? 1 : -1, ScalarNumber>::
3565 template interpolate<false, false>(n_components,
3566 integration_flags,
3567 this->shape_info,
3568 input,
3569 output,
3570 this->current_face_number);
3571
3572 const unsigned int dofs_per_comp =
3573 is_linear ? Utilities::pow(2, dim) : this->dofs_per_component;
3574
3575 for (unsigned int comp = 0; comp < n_components; ++comp)
3576 {
3577 const std::size_t offset =
3578 (this->component_in_base_element + comp) * dofs_per_comp;
3579
3580 if (is_linear || this->renumber.empty())
3581 {
3582 for (unsigned int i = 0; i < dofs_per_comp; ++i)
3583 if (sum_into_values)
3584 solution_values[i + offset] +=
3585 output[i + comp * dofs_per_comp];
3586 else
3587 solution_values[i + offset] =
3588 output[i + comp * dofs_per_comp];
3589 }
3590 else
3591 {
3592 const unsigned int *renumber_ptr = this->renumber.data() + offset;
3593 for (unsigned int i = 0; i < dofs_per_comp; ++i)
3594 if (sum_into_values)
3595 solution_values[renumber_ptr[i]] +=
3596 output[i + comp * dofs_per_comp];
3597 else
3598 solution_values[renumber_ptr[i]] =
3599 output[i + comp * dofs_per_comp];
3600 }
3601 }
3602 }
3603 }
3604
3605
3606
3607 template <int n_components_, int dim, int spacedim, typename Number>
3608 template <int stride_face_dof>
3609 void
3610 FEFacePointEvaluation<n_components_, dim, spacedim, Number>::evaluate_in_face(
3611 const ScalarNumber *face_dof_values,
3612 const EvaluationFlags::EvaluationFlags &evaluation_flags)
3613 {
3614 if (this->use_linear_path)
3615 do_evaluate_in_face<true, stride_face_dof>(face_dof_values,
3616 evaluation_flags);
3617 else
3618 do_evaluate_in_face<false, stride_face_dof>(face_dof_values,
3619 evaluation_flags);
3620 }
3621
3622
3623
3624 template <int n_components_, int dim, int spacedim, typename Number>
3625 template <bool is_linear, int stride_face_dof>
3626 inline void
3627 FEFacePointEvaluation<n_components_, dim, spacedim, Number>::
3628 do_evaluate_in_face(const ScalarNumber *face_dof_values,
3629 const EvaluationFlags::EvaluationFlags &evaluation_flags)
3630 {
3631 const scalar_value_type *face_dof_values_ptr;
3632 if constexpr (n_components == 1)
3633 face_dof_values_ptr = face_dof_values;
3634 else
3635 {
3636 const unsigned int dofs_per_comp_face =
3637 is_linear ? Utilities::pow(2, dim - 1) : this->dofs_per_component_face;
3638 for (unsigned int comp = 0; comp < n_components; ++comp)
3639 for (unsigned int i = 0; i < 2 * dofs_per_comp_face; ++i)
3640 ETT::read_value(face_dof_values[(i + comp * 3 * dofs_per_comp_face) *
3641 stride_face_dof],
3642 comp,
3643 this->solution_renumbered[i]);
3644
3645 face_dof_values_ptr = this->solution_renumbered.data();
3646 }
3647
3648 constexpr int stride_face_dof_actual =
3649 n_components == 1 ? stride_face_dof : 1;
3650
3651 // loop over quadrature batches qb
3652 const unsigned int n_shapes = is_linear ? 2 : this->poly.size();
3653
3654 for (unsigned int qb = 0; qb < this->n_q_batches; ++qb)
3655 {
3656 vectorized_value_type value;
3657 interface_vectorized_unit_gradient_type gradient;
3658
3659 if (evaluation_flags & EvaluationFlags::gradients)
3660 {
3661 const std::array<vectorized_value_type, dim + 1> interpolated_value =
3662 is_linear ?
3663 internal::evaluate_tensor_product_value_and_gradient_linear<
3664 dim - 1,
3665 scalar_value_type,
3666 VectorizedArrayType,
3667 2,
3668 stride_face_dof_actual>(face_dof_values_ptr,
3669 this->unit_point_faces_ptr[qb]) :
3670 internal::evaluate_tensor_product_value_and_gradient_shapes<
3671 dim - 1,
3672 scalar_value_type,
3673 VectorizedArrayType,
3674 2,
3675 false,
3676 stride_face_dof_actual>(this->shapes_faces.data() +
3677 qb * n_shapes,
3678 n_shapes,
3679 face_dof_values_ptr);
3680
3681 value = interpolated_value[dim - 1];
3682 // reorder derivative from tangential/normal derivatives into tensor
3683 // in physical coordinates
3684 if (this->current_face_number / 2 == 0)
3685 {
3686 gradient[0] = interpolated_value[dim];
3687 if (dim > 1)
3688 gradient[1] = interpolated_value[0];
3689 if (dim > 2)
3690 gradient[2] = interpolated_value[1];
3691 }
3692 else if (this->current_face_number / 2 == 1)
3693 {
3694 if (dim > 1)
3695 gradient[1] = interpolated_value[dim];
3696 if (dim == 3)
3697 {
3698 gradient[0] = interpolated_value[1];
3699 gradient[2] = interpolated_value[0];
3700 }
3701 else if (dim == 2)
3702 gradient[0] = interpolated_value[0];
3703 else
3704 DEAL_II_ASSERT_UNREACHABLE();
3705 }
3706 else if (this->current_face_number / 2 == 2)
3707 {
3708 if (dim > 2)
3709 {
3710 gradient[0] = interpolated_value[0];
3711 gradient[1] = interpolated_value[1];
3712 gradient[2] = interpolated_value[dim];
3713 }
3714 else
3715 DEAL_II_ASSERT_UNREACHABLE();
3716 }
3717 else
3718 DEAL_II_ASSERT_UNREACHABLE();
3719 }
3720 else
3721 {
3722 value = is_linear ?
3723 internal::evaluate_tensor_product_value_linear<
3724 dim - 1,
3725 scalar_value_type,
3726 VectorizedArrayType,
3727 stride_face_dof_actual>(face_dof_values_ptr,
3728 this->unit_point_faces_ptr[qb]) :
3729 internal::evaluate_tensor_product_value_shapes<
3730 dim - 1,
3731 scalar_value_type,
3732 VectorizedArrayType,
3733 false,
3734 stride_face_dof_actual>(this->shapes_faces.data() +
3735 qb * n_shapes,
3736 n_shapes,
3737 face_dof_values_ptr);
3738 }
3739
3740 if (evaluation_flags & EvaluationFlags::values)
3741 {
3742 for (unsigned int v = 0, offset = qb * stride;
3743 v < stride && (stride == 1 || offset < this->n_q_points_scalar);
3744 ++v, ++offset)
3745 ETT::set_value(value, v, this->values[offset]);
3746 }
3747 if (evaluation_flags & EvaluationFlags::gradients)
3748 {
3749 Assert(this->update_flags & update_gradients ||
3750 this->update_flags & update_inverse_jacobians,
3751 ExcNotInitialized());
3752
3753 for (unsigned int v = 0, offset = qb * stride;
3754 v < stride && (stride == 1 || offset < this->n_q_points_scalar);
3755 ++v, ++offset)
3756 {
3757 unit_gradient_type unit_gradient;
3758 ETT::set_gradient(gradient, v, unit_gradient);
3759 this->gradients[offset] =
3760 this->cell_type <=
3761 internal::MatrixFreeFunctions::GeometryType::cartesian ?
3762 apply_diagonal_transformation(
3763 this->inverse_jacobian_ptr[0].transpose(), unit_gradient) :
3764 apply_transformation(
3765 this
3766 ->inverse_jacobian_ptr[this->cell_type <=
3767 internal::MatrixFreeFunctions::
3768 GeometryType::affine ?
3769 0 :
3770 offset]
3771 .transpose(),
3772 unit_gradient);
3773 }
3774 }
3775 }
3776 }
3777
3778
3779
3780 template <int n_components_, int dim, int spacedim, typename Number>
3781 template <int stride_face_dof>
3782 void
3783 FEFacePointEvaluation<n_components_, dim, spacedim, Number>::integrate_in_face(
3784 ScalarNumber *face_dof_values,
3785 const EvaluationFlags::EvaluationFlags &integration_flags,
3786 const bool sum_into_values)
3787 {
3788 if (this->use_linear_path)
3789 do_integrate_in_face<true, true, stride_face_dof>(face_dof_values,
3790 integration_flags,
3791 sum_into_values);
3792 else
3793 do_integrate_in_face<true, false, stride_face_dof>(face_dof_values,
3794 integration_flags,
3795 sum_into_values);
3796 }
3797
3798
3799
3800 template <int n_components_, int dim, int spacedim, typename Number>
3801 template <bool do_JxW, bool is_linear, int stride_face_dof>
3802 inline void
3803 FEFacePointEvaluation<n_components_, dim, spacedim, Number>::
3804 do_integrate_in_face(
3805 ScalarNumber *face_dof_values,
3806 const EvaluationFlags::EvaluationFlags &integration_flags,
3807 const bool sum_into_values)
3808 {
3809 // zero out lanes of incomplete last quadrature point batch
3810 if constexpr (stride == 1)
3811 if (const unsigned int n_filled_lanes =
3812 this->n_q_points_scalar & (n_lanes_internal - 1);
3813 n_filled_lanes > 0)
3814 {
3815 if (integration_flags & EvaluationFlags::values)
3816 for (unsigned int v = n_filled_lanes; v < n_lanes_internal; ++v)
3817 ETT::set_zero_value(this->values.back(), v);
3818 if (integration_flags & EvaluationFlags::gradients)
3819 for (unsigned int v = n_filled_lanes; v < n_lanes_internal; ++v)
3820 ETT::set_zero_gradient(this->gradients.back(), v);
3821 }
3822
3823 std::array<vectorized_value_type,
3824 is_linear ? 2 * Utilities::pow(2, dim - 1) : 0>
3825 solution_values_vectorized_linear = {};
3826
3827 // loop over quadrature batches qb
3828 const unsigned int n_shapes = is_linear ? 2 : this->poly.size();
3829
3830 const bool cartesian_cell =
3831 this->cell_type <= internal::MatrixFreeFunctions::GeometryType::cartesian;
3832 const bool affine_cell =
3833 this->cell_type <= internal::MatrixFreeFunctions::GeometryType::affine;
3834 for (unsigned int qb = 0; qb < this->n_q_batches; ++qb)
3835 {
3836 vectorized_value_type value = {};
3837 Tensor<1, dim, vectorized_value_type> gradient;
3838
3839 if (integration_flags & EvaluationFlags::values)
3840 for (unsigned int v = 0, offset = qb * stride;
3841 v < stride && (stride == 1 || offset < this->n_q_points_scalar);
3842 ++v, ++offset)
3843 ETT::get_value(value,
3844 v,
3845 do_JxW ? this->values[offset] * this->JxW_ptr[offset] :
3846 this->values[offset]);
3847
3848 if (integration_flags & EvaluationFlags::gradients)
3849 for (unsigned int v = 0, offset = qb * stride;
3850 v < stride && (stride == 1 || offset < this->n_q_points_scalar);
3851 ++v, ++offset)
3852 {
3853 const auto grad_w =
3854 do_JxW ? this->gradients[offset] * this->JxW_ptr[offset] :
3855 this->gradients[offset];
3856 ETT::get_gradient(
3857 gradient,
3858 v,
3859 cartesian_cell ?
3860 apply_diagonal_transformation(this->inverse_jacobian_ptr[0],
3861 grad_w) :
3862 apply_transformation(
3863 this->inverse_jacobian_ptr[affine_cell ? 0 : offset],
3864 grad_w));
3865 }
3866
3867 if (integration_flags & EvaluationFlags::gradients)
3868 {
3869 std::array<vectorized_value_type, 2> value_face = {};
3870 Tensor<1, dim - 1, vectorized_value_type> gradient_in_face;
3871
3872 value_face[0] = value;
3873 // fill derivative in physical coordinates into tangential/normal
3874 // derivatives
3875 if (this->current_face_number / 2 == 0)
3876 {
3877 value_face[1] = gradient[0];
3878 if (dim > 1)
3879 gradient_in_face[0] = gradient[1];
3880 if (dim > 2)
3881 gradient_in_face[1] = gradient[2];
3882 }
3883 else if (this->current_face_number / 2 == 1)
3884 {
3885 if (dim > 1)
3886 value_face[1] = gradient[1];
3887 if (dim == 3)
3888 {
3889 gradient_in_face[0] = gradient[2];
3890 gradient_in_face[1] = gradient[0];
3891 }
3892 else if (dim == 2)
3893 gradient_in_face[0] = gradient[0];
3894 else
3895 DEAL_II_ASSERT_UNREACHABLE();
3896 }
3897 else if (this->current_face_number / 2 == 2)
3898 {
3899 if (dim > 2)
3900 {
3901 value_face[1] = gradient[2];
3902 gradient_in_face[0] = gradient[0];
3903 gradient_in_face[1] = gradient[1];
3904 }
3905 else
3906 DEAL_II_ASSERT_UNREACHABLE();
3907 }
3908 else
3909 DEAL_II_ASSERT_UNREACHABLE();
3910
3911 internal::integrate_tensor_product_value_and_gradient<
3912 is_linear,
3913 dim - 1,
3914 VectorizedArrayType,
3915 vectorized_value_type,
3916 2>(this->shapes_faces.data() + qb * n_shapes,
3917 n_shapes,
3918 value_face.data(),
3919 gradient_in_face,
3920 is_linear ? solution_values_vectorized_linear.data() :
3921 this->solution_renumbered_vectorized.data(),
3922 this->unit_point_faces_ptr[qb],
3923 qb != 0);
3924 }
3925 else
3926 internal::integrate_tensor_product_value<is_linear,
3927 dim - 1,
3928 VectorizedArrayType,
3929 vectorized_value_type>(
3930 this->shapes_faces.data() + qb * n_shapes,
3931 n_shapes,
3932 value,
3933 is_linear ? solution_values_vectorized_linear.data() :
3934 this->solution_renumbered_vectorized.data(),
3935 this->unit_point_faces_ptr[qb],
3936 qb != 0);
3937 }
3938
3939 const unsigned int dofs_per_comp_face =
3940 is_linear ? Utilities::pow(2, dim - 1) : this->dofs_per_component_face;
3941
3942 for (unsigned int comp = 0; comp < n_components; ++comp)
3943 for (unsigned int i = 0; i < 2 * dofs_per_comp_face; ++i)
3944 if (sum_into_values)
3945 face_dof_values[(i + comp * 3 * dofs_per_comp_face) *
3946 stride_face_dof] +=
3947 ETT::sum_value(comp,
3948 is_linear ?
3949 *(solution_values_vectorized_linear.data() + i) :
3950 this->solution_renumbered_vectorized[i]);
3951 else
3952 face_dof_values[(i + comp * 3 * dofs_per_comp_face) * stride_face_dof] =
3953 ETT::sum_value(comp,
3954 is_linear ?
3955 *(solution_values_vectorized_linear.data() + i) :
3956 this->solution_renumbered_vectorized[i]);
3957 }
3958
3959
3960
3961 template <int n_components_, int dim, int spacedim, typename Number>
3962 inline Tensor<1, spacedim, Number>
3963 FEFacePointEvaluation<n_components_, dim, spacedim, Number>::normal_vector(
3964 const unsigned int point_index) const
3965 {
3966 AssertIndexRange(point_index, this->n_q_points);
3967 Assert(this->normal_ptr != nullptr,
3968 internal::FEPointEvaluation::
3969 ExcFEPointEvaluationAccessToUninitializedMappingField(
3970 "update_normal_vectors"));
3971 if (this->cell_type <= dealii::internal::MatrixFreeFunctions::affine)
3972 {
3973 Tensor<1, spacedim, Number> normal;
3974 for (unsigned int d = 0; d < dim; ++d)
3975 normal[d] =
3976 internal::VectorizedArrayTrait<Number>::get(this->normal_ptr[0][d],
3977 0);
3978
3979 return normal;
3980 }
3981 else
3982 {
3983 return this->normal_ptr[point_index];
3984 }
3985 }
3986
3987
3988
3989 template <int n_components_, int dim, int spacedim, typename Number>
3990 inline const typename FEFacePointEvaluation<n_components_,
3991 dim,
3992 spacedim,
3993 Number>::value_type
3994 FEFacePointEvaluation<n_components_, dim, spacedim, Number>::
3995 get_normal_derivative(const unsigned int point_index) const
3996 {
3997 AssertIndexRange(point_index, this->gradients.size());
3998
3999 value_type normal_derivative;
4000 if constexpr (n_components == 1)
4001 normal_derivative =
4002 this->gradients[point_index] * normal_vector(point_index);
4003 else
4004 for (unsigned int comp = 0; comp < n_components; ++comp)
4005 normal_derivative[comp] =
4006 this->gradients[point_index][comp] * normal_vector(point_index);
4007
4008 return normal_derivative;
4009 }
4010
4011
4012
4013 template <int n_components_, int dim, int spacedim, typename Number>
4014 inline void
4015 FEFacePointEvaluation<n_components_, dim, spacedim, Number>::
4016 submit_normal_derivative(const value_type &value,
4017 const unsigned int point_index)
4018 {
4019 AssertIndexRange(point_index, this->gradients.size());
4020 if constexpr (n_components == 1)
4021 this->gradients[point_index] = value * normal_vector(point_index);
4022 else
4023 for (unsigned int comp = 0; comp < n_components; ++comp)
4024 this->gradients[point_index][comp] =
4025 value[comp] * normal_vector(point_index);
4026 }
4027
4028 DEAL_II_NAMESPACE_CLOSE
4029
4030 #endif