deal.II version GIT relicensing-7182-g951947b1c4 2026-11-26 10:30:01+00:00
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
fe_evaluation.h
Go to the documentation of this file.
1// -----------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
4// Copyright (C) 2012 - 2026 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Detailed license information governing the source code and contributions
9// can be found in LICENSE.md and CONTRIBUTING.md at the top level directory.
10//
11// -----------------------------------------------------------------------------
12
13
14#ifndef dealii_matrix_free_fe_evaluation_h
15#define dealii_matrix_free_fe_evaluation_h
16
17
18#include <deal.II/base/config.h>
19
26
28
30
43
44#include <type_traits>
45
46
48
49
50
88template <int dim,
89 int n_components_,
90 typename Number,
91 bool is_face,
92 typename VectorizedArrayType>
94 : public FEEvaluationData<dim, VectorizedArrayType, is_face>
95{
96public:
97 using number_type = Number;
98 using value_type =
99 std::conditional_t<n_components_ == 1,
100 VectorizedArrayType,
102 using gradient_type = std::conditional_t<
103 n_components_ == 1,
105 std::conditional_t<
106 n_components_ == dim,
110 using hessian_type = std::conditional_t<
111 n_components_ == 1,
113 std::conditional_t<
114 n_components_ == dim,
117 static constexpr unsigned int dimension = dim;
118 static constexpr unsigned int n_components = n_components_;
119 static constexpr unsigned int n_lanes = VectorizedArrayType::size();
120
158 template <typename VectorType>
159 void
161 const VectorType &src,
162 const unsigned int first_index = 0,
163 const std::bitset<n_lanes> &mask = std::bitset<n_lanes>().flip());
164
196 template <typename VectorType>
197 void
199 const VectorType &src,
200 const unsigned int first_index = 0,
201 const std::bitset<n_lanes> &mask = std::bitset<n_lanes>().flip());
202
234 template <typename VectorType>
235 void
237 VectorType &dst,
238 const unsigned int first_index = 0,
239 const std::bitset<n_lanes> &mask = std::bitset<n_lanes>().flip()) const;
240
279 template <typename VectorType>
280 void
282 VectorType &dst,
283 const unsigned int first_index = 0,
284 const std::bitset<n_lanes> &mask = std::bitset<n_lanes>().flip()) const;
285
289 template <typename VectorType>
290 void
292 VectorType &dst,
293 const unsigned int first_index = 0,
294 const std::bitset<n_lanes> &mask = std::bitset<n_lanes>().flip()) const;
295
318 get_dof_value(const unsigned int dof) const;
319
328 void
329 submit_dof_value(const value_type val_in, const unsigned int dof);
330
342 get_value(const unsigned int q_point) const;
343
359 void
360 submit_value(const value_type val_in, const unsigned int q_point);
361
369 template <int n_components_local = n_components,
370 typename = std::enable_if_t<n_components == n_components_local>>
371 void
373 const unsigned int q_point);
374
385 get_gradient(const unsigned int q_point) const;
386
398 get_normal_derivative(const unsigned int q_point) const;
399
414 void
415 submit_gradient(const gradient_type grad_in, const unsigned int q_point);
416
424 template <int dim_ = dim,
425 typename = std::enable_if_t<dim_ == 1 && n_components == dim_>>
426 void
428 const unsigned int q_point);
429
445 void
447 const unsigned int q_point);
448
457 get_hessian(const unsigned int q_point) const;
458
465 get_hessian_diagonal(const unsigned int q_point) const;
466
475 get_laplacian(const unsigned int q_point) const;
476
487 get_normal_hessian(const unsigned int q_point) const;
488
503 void
504 submit_hessian(const hessian_type hessian_in, const unsigned int q_point);
505
521 void
522 submit_normal_hessian(const value_type normal_hessian_in,
523 const unsigned int q_point);
524
532 template <int dim_ = dim, typename = std::enable_if_t<n_components_ == dim_>>
533 VectorizedArrayType
534 get_divergence(const unsigned int q_point) const;
535
551 template <int dim_ = dim, typename = std::enable_if_t<n_components_ == dim_>>
552 void
553 submit_divergence(const VectorizedArrayType div_in,
554 const unsigned int q_point);
555
564 template <int dim_ = dim, typename = std::enable_if_t<n_components_ == dim_>>
566 get_symmetric_gradient(const unsigned int q_point) const;
567
583 template <int dim_ = dim, typename = std::enable_if_t<n_components_ == dim_>>
584 void
587 const unsigned int q_point);
588
597 template <int dim_ = dim,
598 typename = std::enable_if_t<n_components_ == dim_ && dim_ != 1>>
600 get_curl(const unsigned int q_point) const;
601
615 template <int dim_ = dim,
616 typename = std::enable_if_t<n_components_ == dim_ && dim != 1>>
617 void
618 submit_curl(const curl_type curl_in, const unsigned int q_point);
619
639
647
648protected:
658 const unsigned int dof_handler_index,
659 const unsigned int first_selected_component,
660 const unsigned int quadrature_index,
661 const unsigned int fe_degree,
662 const unsigned int n_q_points,
663 const bool is_interior_face,
664 const unsigned int active_fe_index,
665 const unsigned int active_quad_index,
666 const unsigned int face_type);
667
705 const Mapping<dim> &mapping,
706 const FiniteElement<dim> &fe,
707 const Quadrature<1> &quadrature,
708 const UpdateFlags update_flags,
709 const unsigned int first_selected_component,
711
719
728
733
740 template <typename VectorType, typename VectorOperation>
741 void
743 const VectorOperation &operation,
744 const std::array<VectorType *, n_components_> &vectors,
745 const std::array<
747 n_components_> &vectors_sm,
748 const std::bitset<n_lanes> &mask,
749 const bool apply_constraints = true) const;
750
758 template <typename VectorType, typename VectorOperation>
759 void
761 const VectorOperation &operation,
762 const std::array<VectorType *, n_components_> &vectors,
763 const std::array<
765 n_components_> &vectors_sm,
766 const std::bitset<n_lanes> &mask) const;
767
775 template <typename VectorType, typename VectorOperation>
776 void
778 const VectorOperation &operation,
779 const std::array<VectorType *, n_components_> &vectors) const;
780
784 void
786
796 void
798 const EvaluationFlags::EvaluationFlags evaluation_flag);
799
804
809
814 mutable std::vector<types::global_dof_index> local_dof_indices;
815};
816
817
818
1382template <int dim,
1383 int fe_degree,
1384 int n_q_points_1d,
1385 int n_components_,
1386 typename Number,
1387 typename VectorizedArrayType>
1389 n_components_,
1390 Number,
1391 false,
1392 VectorizedArrayType>
1393{
1394 static_assert(
1395 std::is_same_v<Number, typename VectorizedArrayType::value_type>,
1396 "Type of Number and of VectorizedArrayType do not match.");
1397
1398public:
1404
1408 using number_type = Number;
1409
1416
1423
1427 static constexpr unsigned int dimension = dim;
1428
1433 static constexpr unsigned int n_components = n_components_;
1434
1438 static constexpr unsigned int n_lanes = VectorizedArrayType::size();
1439
1448 static constexpr unsigned int static_n_q_points =
1449 Utilities::pow(n_q_points_1d, dim);
1450
1460 static constexpr unsigned int static_dofs_per_component =
1461 Utilities::pow(fe_degree + 1, dim);
1462
1472 static constexpr unsigned int tensor_dofs_per_cell =
1474
1484 static constexpr unsigned int static_dofs_per_cell =
1486
1523 const unsigned int dof_handler_index = 0,
1524 const unsigned int quadrature_index = 0,
1525 const unsigned int first_selected_component = 0,
1528
1537 const std::pair<unsigned int, unsigned int> &range,
1538 const unsigned int dof_handler_index = 0,
1539 const unsigned int quadrature_index = 0,
1540 const unsigned int first_selected_component = 0);
1541
1571 const FiniteElement<dim> &fe,
1572 const Quadrature<1> &quadrature,
1573 const UpdateFlags update_flags,
1574 const unsigned int first_selected_component = 0);
1575
1582 const Quadrature<1> &quadrature,
1583 const UpdateFlags update_flags,
1584 const unsigned int first_selected_component = 0);
1585
1598 const unsigned int first_selected_component = 0);
1599
1607
1614 FEEvaluation &
1616
1625 void
1626 reinit(const unsigned int cell_batch_index);
1627
1634 void
1635 reinit(const std::array<unsigned int, n_lanes> &cell_ids);
1636
1649 template <bool level_dof_access>
1650 void
1652
1663 void
1665
1669 static bool
1670 fast_evaluation_supported(const unsigned int given_degree,
1671 const unsigned int given_n_q_points_1d);
1672
1682 void
1684
1697 void
1698 evaluate(const VectorizedArrayType *values_array,
1699 const EvaluationFlags::EvaluationFlags evaluation_flag);
1700
1714 template <typename VectorType>
1715 void
1716 gather_evaluate(const VectorType &input_vector,
1717 const EvaluationFlags::EvaluationFlags evaluation_flag);
1718
1728 void
1730
1742 void
1744 VectorizedArrayType *values_array,
1745 const bool sum_into_values = false);
1746
1760 template <typename VectorType>
1761 void
1763 VectorType &output_vector);
1764
1772
1779 const unsigned int dofs_per_component;
1780
1787 const unsigned int dofs_per_cell;
1788
1796 const unsigned int n_q_points;
1797
1798private:
1803 void
1804 check_template_arguments(const unsigned int fe_no,
1805 const unsigned int first_selected_component);
1806};
1807
1808
1809
1845template <int dim,
1846 int fe_degree,
1847 int n_q_points_1d = fe_degree + 1,
1848 int n_components_ = 1,
1849 typename Number = double,
1850 typename VectorizedArrayType = VectorizedArray<Number>>
1852 n_components_,
1853 Number,
1854 true,
1855 VectorizedArrayType>
1856{
1857 static_assert(
1858 std::is_same_v<Number, typename VectorizedArrayType::value_type>,
1859 "Type of Number and of VectorizedArrayType do not match.");
1860
1861public:
1867
1871 using number_type = Number;
1872
1879
1886
1890 static constexpr unsigned int dimension = dim;
1891
1896 static constexpr unsigned int n_components = n_components_;
1897
1901 static constexpr unsigned int n_lanes = VectorizedArrayType::size();
1902
1912 static constexpr unsigned int static_n_q_points =
1913 Utilities::pow(n_q_points_1d, dim - 1);
1914
1923 static constexpr unsigned int static_n_q_points_cell =
1924 Utilities::pow(n_q_points_1d, dim);
1925
1934 static constexpr unsigned int static_dofs_per_component =
1935 Utilities::pow(fe_degree + 1, dim);
1936
1945 static constexpr unsigned int tensor_dofs_per_cell =
1947
1956 static constexpr unsigned int static_dofs_per_cell =
1958
2002 const bool is_interior_face = true,
2003 const unsigned int dof_handler_index = 0,
2004 const unsigned int quadrature_index = 0,
2005 const unsigned int first_selected_component = 0,
2008 const unsigned int face_type = numbers::invalid_unsigned_int);
2009
2019 const std::pair<unsigned int, unsigned int> &range,
2020 const bool is_interior_face = true,
2021 const unsigned int dof_handler_index = 0,
2022 const unsigned int quadrature_index = 0,
2023 const unsigned int first_selected_component = 0);
2024
2035 void
2036 reinit(const unsigned int face_batch_number);
2037
2045 void
2046 reinit(const unsigned int cell_batch_number, const unsigned int face_number);
2047
2051 static bool
2052 fast_evaluation_supported(const unsigned int given_degree,
2053 const unsigned int given_n_q_points_1d);
2054
2065 void
2067
2080 void
2081 evaluate(const VectorizedArrayType *values_array,
2082 const EvaluationFlags::EvaluationFlags evaluation_flag);
2083
2088 void
2090
2095 void
2096 project_to_face(const VectorizedArrayType *values_array,
2097 const EvaluationFlags::EvaluationFlags evaluation_flag);
2098
2103 void
2105
2117 template <typename VectorType>
2118 void
2119 gather_evaluate(const VectorType &input_vector,
2120 const EvaluationFlags::EvaluationFlags evaluation_flag);
2121
2131 void
2133 const bool sum_into_values = false);
2134
2144 void
2146 VectorizedArrayType *values_array,
2147 const bool sum_into_values = false);
2148
2155 void
2157
2162 void
2164 const bool sum_into_values = false);
2165
2170 void
2172 VectorizedArrayType *values_array,
2173 const bool sum_into_values = false);
2174
2186 template <typename VectorType>
2187 void
2189 VectorType &output_vector);
2190
2194 template <typename VectorType>
2195 void
2196 integrate_scatter(const bool integrate_values,
2197 const bool integrate_gradients,
2198 VectorType &output_vector);
2199
2207
2212 bool
2214
2229
2234 unsigned int
2236
2241 unsigned int
2243
2250 const unsigned int dofs_per_component;
2251
2258 const unsigned int dofs_per_cell;
2259
2267 const unsigned int n_q_points;
2268};
2269
2270
2271
2272namespace internal
2273{
2274 namespace MatrixFreeFunctions
2275 {
2276 // a helper function to compute the number of DoFs of a DGP element at
2277 // compile time, depending on the degree
2278 template <int dim, int degree>
2280 {
2281 // this division is always without remainder
2282 static constexpr unsigned int value =
2283 (DGP_dofs_per_component<dim - 1, degree>::value * (degree + dim)) / dim;
2284 };
2285
2286 // base specialization: 1d elements have 'degree+1' degrees of freedom
2287 template <int degree>
2288 struct DGP_dofs_per_component<1, degree>
2289 {
2290 static constexpr unsigned int value = degree + 1;
2291 };
2292 } // namespace MatrixFreeFunctions
2293} // namespace internal
2294
2295
2296/*----------------------- Inline functions ----------------------------------*/
2297
2298#ifndef DOXYGEN
2299
2300
2301namespace internal
2302{
2303 // Extract all internal data pointers and indices in a single function that
2304 // get passed on to the constructor of FEEvaluationData, avoiding to look
2305 // things up multiple times
2306 template <bool is_face,
2307 int dim,
2308 typename Number,
2309 typename VectorizedArrayType>
2311 InitializationData
2312 extract_initialization_data(
2314 const unsigned int dof_handler_index,
2315 const unsigned int first_selected_component,
2316 const unsigned int quadrature_index,
2317 const unsigned int fe_degree,
2318 const unsigned int n_q_points,
2319 const unsigned int active_fe_index_given,
2320 const unsigned int active_quad_index_given,
2321 const unsigned int face_type)
2322 {
2324 InitializationData init_data;
2325
2326 init_data.dof_info = &matrix_free.get_dof_info(dof_handler_index);
2327 init_data.mapping_data =
2328 &internal::MatrixFreeFunctions::
2329 MappingInfoCellsOrFaces<dim, Number, is_face, VectorizedArrayType>::get(
2330 matrix_free.get_mapping_info(), quadrature_index);
2331
2332 init_data.active_fe_index =
2333 fe_degree != numbers::invalid_unsigned_int ?
2334 init_data.dof_info->fe_index_from_degree(first_selected_component,
2335 fe_degree) :
2336 (active_fe_index_given != numbers::invalid_unsigned_int ?
2337 active_fe_index_given :
2338 0);
2339
2340 init_data.active_quad_index =
2341 fe_degree == numbers::invalid_unsigned_int ?
2342 (active_quad_index_given != numbers::invalid_unsigned_int ?
2343 active_quad_index_given :
2344 std::min<unsigned int>(
2345 init_data.active_fe_index,
2346 init_data.mapping_data->descriptor.size() /
2347 (is_face ? std::max<unsigned int>(1, dim - 1) : 1) -
2348 1)) :
2349 init_data.mapping_data->quad_index_from_n_q_points(n_q_points);
2350
2351 init_data.shape_info = &matrix_free.get_shape_info(
2352 dof_handler_index,
2353 quadrature_index,
2354 init_data.dof_info->component_to_base_index[first_selected_component],
2355 init_data.active_fe_index,
2356 init_data.active_quad_index);
2357 init_data.descriptor =
2358 &init_data.mapping_data->descriptor
2359 [is_face ?
2360 (init_data.active_quad_index * std::max<unsigned int>(1, dim - 1) +
2361 (face_type == numbers::invalid_unsigned_int ? 0 : face_type)) :
2362 init_data.active_quad_index];
2363
2364 return init_data;
2365 }
2366} // namespace internal
2367
2368
2369
2370/*----------------------- FEEvaluationBase ----------------------------------*/
2371
2372template <int dim,
2373 int n_components_,
2374 typename Number,
2375 bool is_face,
2376 typename VectorizedArrayType>
2377inline FEEvaluationBase<dim,
2378 n_components_,
2379 Number,
2380 is_face,
2381 VectorizedArrayType>::
2382 FEEvaluationBase(
2384 const unsigned int dof_handler_index,
2385 const unsigned int first_selected_component,
2386 const unsigned int quadrature_index,
2387 const unsigned int fe_degree,
2388 const unsigned int n_q_points,
2389 const bool is_interior_face,
2390 const unsigned int active_fe_index,
2391 const unsigned int active_quad_index,
2392 const unsigned int face_type)
2393 : FEEvaluationData<dim, VectorizedArrayType, is_face>(
2394 internal::extract_initialization_data<is_face>(matrix_free,
2395 dof_handler_index,
2396 first_selected_component,
2397 quadrature_index,
2398 fe_degree,
2399 n_q_points,
2400 active_fe_index,
2401 active_quad_index,
2402 face_type),
2403 is_interior_face,
2404 quadrature_index,
2405 first_selected_component)
2406 , scratch_data_array(matrix_free.acquire_scratch_data())
2407 , matrix_free(&matrix_free)
2408{
2409 this->set_data_pointers(scratch_data_array, n_components_);
2410 Assert(
2411 this->dof_info->start_components.back() == 1 ||
2412 static_cast<int>(n_components_) <=
2413 static_cast<int>(
2414 this->dof_info->start_components
2415 [this->dof_info->component_to_base_index[first_selected_component] +
2416 1]) -
2417 first_selected_component,
2418 ExcMessage(
2419 "You tried to construct a vector-valued evaluator with " +
2420 std::to_string(n_components) +
2421 " components. However, "
2422 "the current base element has only " +
2423 std::to_string(
2424 this->dof_info->start_components
2425 [this->dof_info->component_to_base_index[first_selected_component] +
2426 1] -
2427 first_selected_component) +
2428 " components left when starting from local element index " +
2429 std::to_string(
2430 first_selected_component -
2431 this->dof_info->start_components
2432 [this->dof_info->component_to_base_index[first_selected_component]]) +
2433 " (global index " + std::to_string(first_selected_component) + ")"));
2434
2435 // do not check for correct dimensions of data fields here, should be done
2436 // in derived classes
2437}
2438
2439
2440
2441template <int dim,
2442 int n_components_,
2443 typename Number,
2444 bool is_face,
2445 typename VectorizedArrayType>
2446inline FEEvaluationBase<dim,
2447 n_components_,
2448 Number,
2449 is_face,
2450 VectorizedArrayType>::
2451 FEEvaluationBase(
2452 const Mapping<dim> &mapping,
2453 const FiniteElement<dim> &fe,
2454 const Quadrature<1> &quadrature,
2455 const UpdateFlags update_flags,
2456 const unsigned int first_selected_component,
2458 : FEEvaluationData<dim, VectorizedArrayType, is_face>(
2459 other != nullptr &&
2460 other->mapped_geometry->get_quadrature() == quadrature ?
2461 other->mapped_geometry :
2462 std::make_shared<internal::MatrixFreeFunctions::
2463 MappingDataOnTheFly<dim, VectorizedArrayType>>(
2464 mapping,
2465 quadrature,
2466 update_flags),
2467 n_components_,
2468 first_selected_component)
2469 , scratch_data_array(new AlignedVector<VectorizedArrayType>())
2470 , matrix_free(nullptr)
2471{
2472 const unsigned int base_element_number =
2473 fe.component_to_base_index(first_selected_component).first;
2474 Assert(fe.element_multiplicity(base_element_number) == 1 ||
2475 fe.element_multiplicity(base_element_number) -
2476 first_selected_component >=
2477 n_components_,
2478 ExcMessage("The underlying element must at least contain as many "
2479 "components as requested by this class"));
2480 (void)base_element_number;
2481
2482 Assert(this->data == nullptr, ExcInternalError());
2484 Quadrature<(is_face ? dim - 1 : dim)>(quadrature),
2485 fe,
2486 fe.component_to_base_index(first_selected_component).first);
2487
2488 this->set_data_pointers(scratch_data_array, n_components_);
2489}
2490
2491
2492
2493template <int dim,
2494 int n_components_,
2495 typename Number,
2496 bool is_face,
2497 typename VectorizedArrayType>
2498inline FEEvaluationBase<dim,
2499 n_components_,
2500 Number,
2501 is_face,
2502 VectorizedArrayType>::
2503 FEEvaluationBase(const FEEvaluationBase<dim,
2504 n_components_,
2505 Number,
2506 is_face,
2507 VectorizedArrayType> &other)
2508 : FEEvaluationData<dim, VectorizedArrayType, is_face>(other)
2509 , scratch_data_array(other.matrix_free == nullptr ?
2510 new AlignedVector<VectorizedArrayType>() :
2511 other.matrix_free->acquire_scratch_data())
2512 , matrix_free(other.matrix_free)
2513{
2514 if (other.matrix_free == nullptr)
2515 {
2516 Assert(other.mapped_geometry.get() != nullptr, ExcInternalError());
2517 this->data =
2519
2520 // Create deep copy of mapped geometry for use in parallel
2521 this->mapped_geometry =
2522 std::make_shared<internal::MatrixFreeFunctions::
2523 MappingDataOnTheFly<dim, VectorizedArrayType>>(
2524 other.mapped_geometry->get_fe_values().get_mapping(),
2525 other.mapped_geometry->get_quadrature(),
2526 other.mapped_geometry->get_fe_values().get_update_flags());
2527
2528 if constexpr (is_face == false)
2529 this->mapping_data = &this->mapped_geometry->get_data_storage();
2530 else
2531 Assert(false,
2532 ExcNotImplemented("On-the-fly geometry evaluation with "
2533 "face evaluators is not currently "
2534 "implemented!"));
2535
2536 this->cell = 0;
2537
2538 this->jacobian =
2539 this->mapped_geometry->get_data_storage().jacobians[0].begin();
2540 this->J_value =
2541 this->mapped_geometry->get_data_storage().JxW_values.begin();
2542 this->jacobian_gradients =
2543 this->mapped_geometry->get_data_storage().jacobian_gradients[0].begin();
2544 this->jacobian_gradients_non_inverse =
2545 this->mapped_geometry->get_data_storage()
2546 .jacobian_gradients_non_inverse[0]
2547 .begin();
2548 this->quadrature_points =
2549 this->mapped_geometry->get_data_storage().quadrature_points.begin();
2550 }
2551
2552 this->set_data_pointers(scratch_data_array, n_components_);
2553}
2554
2555
2556
2557template <int dim,
2558 int n_components_,
2559 typename Number,
2560 bool is_face,
2561 typename VectorizedArrayType>
2562inline FEEvaluationBase<dim,
2563 n_components_,
2564 Number,
2565 is_face,
2566 VectorizedArrayType> &
2568operator=(const FEEvaluationBase<dim,
2569 n_components_,
2570 Number,
2571 is_face,
2572 VectorizedArrayType> &other)
2573{
2574 // release old memory
2575 if (matrix_free == nullptr)
2576 {
2577 delete this->data;
2578 delete scratch_data_array;
2579 }
2580 else
2581 {
2582 matrix_free->release_scratch_data(scratch_data_array);
2583 }
2584
2586
2587 matrix_free = other.matrix_free;
2588
2589 if (other.matrix_free == nullptr)
2590 {
2591 Assert(other.mapped_geometry.get() != nullptr, ExcInternalError());
2592 this->data =
2594 scratch_data_array = new AlignedVector<VectorizedArrayType>();
2595
2596 // Create deep copy of mapped geometry for use in parallel
2597 this->mapped_geometry =
2598 std::make_shared<internal::MatrixFreeFunctions::
2599 MappingDataOnTheFly<dim, VectorizedArrayType>>(
2600 other.mapped_geometry->get_fe_values().get_mapping(),
2601 other.mapped_geometry->get_quadrature(),
2602 other.mapped_geometry->get_fe_values().get_update_flags());
2603
2604 if constexpr (is_face == false)
2605 this->mapping_data = &this->mapped_geometry->get_data_storage();
2606 else
2607 Assert(false,
2608 ExcNotImplemented("On-the-fly geometry evaluation with "
2609 "face evaluators is not currently "
2610 "implemented!"));
2611 this->cell = 0;
2612
2613 this->jacobian =
2614 this->mapped_geometry->get_data_storage().jacobians[0].begin();
2615 this->J_value =
2616 this->mapped_geometry->get_data_storage().JxW_values.begin();
2617 this->jacobian_gradients =
2618 this->mapped_geometry->get_data_storage().jacobian_gradients[0].begin();
2619 this->jacobian_gradients_non_inverse =
2620 this->mapped_geometry->get_data_storage()
2621 .jacobian_gradients_non_inverse[0]
2622 .begin();
2623 this->quadrature_points =
2624 this->mapped_geometry->get_data_storage().quadrature_points.begin();
2625 }
2626 else
2627 {
2628 scratch_data_array = matrix_free->acquire_scratch_data();
2629 }
2630
2631 this->set_data_pointers(scratch_data_array, n_components_);
2632
2633 return *this;
2634}
2635
2636
2637
2638template <int dim,
2639 int n_components_,
2640 typename Number,
2641 bool is_face,
2642 typename VectorizedArrayType>
2643inline FEEvaluationBase<dim,
2644 n_components_,
2645 Number,
2646 is_face,
2647 VectorizedArrayType>::~FEEvaluationBase()
2648{
2649 if (matrix_free != nullptr)
2650 {
2651 try
2652 {
2653 matrix_free->release_scratch_data(scratch_data_array);
2654 }
2655 catch (...)
2656 {}
2657 }
2658 else
2659 {
2660 delete scratch_data_array;
2661 delete this->data;
2662 }
2663}
2664
2665
2666
2667template <int dim,
2668 int n_components_,
2669 typename Number,
2670 bool is_face,
2671 typename VectorizedArrayType>
2674 get_matrix_free() const
2675{
2676 Assert(matrix_free != nullptr,
2677 ExcMessage(
2678 "FEEvaluation was not initialized with a MatrixFree object!"));
2679 return *matrix_free;
2680}
2681
2682
2683
2684namespace internal
2685{
2686 // given a block vector return the underlying vector type
2687 // including constness (specified by bool)
2688 template <typename VectorType, bool>
2689 struct ConstBlockVectorSelector;
2690
2691 template <typename VectorType>
2692 struct ConstBlockVectorSelector<VectorType, true>
2693 {
2694 using BaseVectorType = const typename VectorType::BlockType;
2695 };
2696
2697 template <typename VectorType>
2698 struct ConstBlockVectorSelector<VectorType, false>
2699 {
2700 using BaseVectorType = typename VectorType::BlockType;
2701 };
2702
2703 // allows to select between block vectors and non-block vectors, which
2704 // allows to use a unified interface for extracting blocks on block vectors
2705 // and doing nothing on usual vectors
2706 template <typename VectorType, bool>
2707 struct BlockVectorSelector;
2708
2709 template <typename VectorType>
2710 struct BlockVectorSelector<VectorType, true>
2711 {
2712 using BaseVectorType = typename ConstBlockVectorSelector<
2713 VectorType,
2714 std::is_const_v<VectorType>>::BaseVectorType;
2715
2716 static BaseVectorType *
2717 get_vector_component(VectorType &vec, const unsigned int component)
2718 {
2719 AssertIndexRange(component, vec.n_blocks());
2720 return &vec.block(component);
2721 }
2722 };
2723
2724 template <typename VectorType>
2725 struct BlockVectorSelector<VectorType, false>
2726 {
2727 using BaseVectorType = VectorType;
2728
2729 static BaseVectorType *
2730 get_vector_component(VectorType &vec, const unsigned int component)
2731 {
2732 // FEEvaluation allows to combine several vectors from a scalar
2733 // FiniteElement into a "vector-valued" FEEvaluation object with
2734 // multiple components. These components can be extracted with the other
2735 // get_vector_component functions. If we do not get a vector of vectors
2736 // (std::vector<VectorType>, std::vector<VectorType*>, BlockVector), we
2737 // must make sure that we do not duplicate the components in input
2738 // and/or duplicate the resulting integrals. In such a case, we should
2739 // only get the zeroth component in the vector contained set nullptr for
2740 // the others which allows us to catch unintended use in
2741 // read_write_operation.
2742 if (component == 0)
2743 return &vec;
2744 else
2745 return nullptr;
2746 }
2747 };
2748
2749 template <typename VectorType>
2750 struct BlockVectorSelector<std::vector<VectorType>, false>
2751 {
2752 using BaseVectorType = VectorType;
2753
2754 static BaseVectorType *
2755 get_vector_component(std::vector<VectorType> &vec,
2756 const unsigned int component)
2757 {
2758 AssertIndexRange(component, vec.size());
2759 return &vec[component];
2760 }
2761 };
2762
2763 template <typename VectorType>
2764 struct BlockVectorSelector<const std::vector<VectorType>, false>
2765 {
2766 using BaseVectorType = const VectorType;
2767
2768 static const BaseVectorType *
2769 get_vector_component(const std::vector<VectorType> &vec,
2770 const unsigned int component)
2771 {
2772 AssertIndexRange(component, vec.size());
2773 return &vec[component];
2774 }
2775 };
2776
2777 template <typename VectorType>
2778 struct BlockVectorSelector<std::vector<VectorType *>, false>
2779 {
2780 using BaseVectorType = VectorType;
2781
2782 static BaseVectorType *
2783 get_vector_component(std::vector<VectorType *> &vec,
2784 const unsigned int component)
2785 {
2786 AssertIndexRange(component, vec.size());
2787 return vec[component];
2788 }
2789 };
2790
2791 template <typename VectorType>
2792 struct BlockVectorSelector<const std::vector<VectorType *>, false>
2793 {
2794 using BaseVectorType = const VectorType;
2795
2796 static const BaseVectorType *
2797 get_vector_component(const std::vector<VectorType *> &vec,
2798 const unsigned int component)
2799 {
2800 AssertIndexRange(component, vec.size());
2801 return vec[component];
2802 }
2803 };
2804
2805 template <typename VectorType, std::size_t N>
2806 struct BlockVectorSelector<std::array<VectorType *, N>, false>
2807 {
2808 using BaseVectorType = VectorType;
2809
2810 static BaseVectorType *
2811 get_vector_component(std::array<VectorType *, N> &vec,
2812 const unsigned int component)
2813 {
2814 AssertIndexRange(component, vec.size());
2815 return vec[component];
2816 }
2817 };
2818} // namespace internal
2819
2820
2821
2822template <int dim,
2823 int n_components_,
2824 typename Number,
2825 bool is_face,
2826 typename VectorizedArrayType>
2827template <typename VectorType, typename VectorOperation>
2828inline void
2831 const VectorOperation &operation,
2832 const std::array<VectorType *, n_components_> &src,
2833 const std::array<
2835 n_components_> &src_sm,
2836 const std::bitset<n_lanes> &mask,
2837 const bool apply_constraints) const
2838{
2839 // Case 1: No MatrixFree object given, simple case because we do not need to
2840 // process constraints and need not care about vectorization -> go to
2841 // separate function
2842 if (this->matrix_free == nullptr)
2843 {
2844 read_write_operation_global(operation, src);
2845 return;
2846 }
2847
2848 Assert(this->dof_info != nullptr, ExcNotInitialized());
2849 const internal::MatrixFreeFunctions::DoFInfo &dof_info = *this->dof_info;
2850 Assert(this->matrix_free->indices_initialized() == true, ExcNotInitialized());
2851 if (this->n_fe_components == 1)
2852 for (unsigned int comp = 0; comp < n_components; ++comp)
2853 {
2854 Assert(src[comp] != nullptr,
2855 ExcMessage("The finite element underlying this FEEvaluation "
2856 "object is scalar, but you requested " +
2857 std::to_string(n_components) +
2858 " components via the template argument in "
2859 "FEEvaluation. In that case, you must pass an "
2860 "std::vector<VectorType> or a BlockVector to " +
2861 "read_dof_values and distribute_local_to_global."));
2863 *this->matrix_free,
2864 *this->dof_info);
2865 }
2866 else
2867 {
2869 *this->matrix_free,
2870 *this->dof_info);
2871 }
2872
2873 const bool accesses_exterior_dofs =
2874 this->dof_access_index ==
2876 this->is_interior_face() == false;
2877
2878 // Case 2: contiguous indices which use reduced storage of indices and can
2879 // use vectorized load/store operations -> go to separate function
2880 if (this->cell != numbers::invalid_unsigned_int)
2881 {
2883 this->cell,
2884 dof_info.index_storage_variants[this->dof_access_index].size());
2885
2886 bool is_contiguous = true;
2887 // check if exterior cells are not contiguous (ECL case)
2888 if (accesses_exterior_dofs)
2889 {
2890 const std::array<unsigned int, n_lanes> &cells = this->get_cell_ids();
2891 const unsigned int n_filled_lanes =
2894 [this->cell];
2895 // we have to check all filled lanes which are active in the mask
2896 for (unsigned int v = 0; v < n_filled_lanes; ++v)
2897 if (mask[v] == true &&
2898 dof_info.index_storage_variants
2900 [cells[v] / n_lanes] <
2902 contiguous)
2903 is_contiguous = false;
2904 } // or if cell/face batch is not contiguous
2905 else if (dof_info.index_storage_variants
2906 [is_face ?
2907 this->dof_access_index :
2908 internal::MatrixFreeFunctions::DoFInfo::dof_access_cell]
2909 [this->cell] < internal::MatrixFreeFunctions::DoFInfo::
2910 IndexStorageVariants::contiguous)
2911 {
2912 is_contiguous = false;
2913 }
2914
2915 if (is_contiguous)
2916 {
2917 read_write_operation_contiguous(operation, src, src_sm, mask);
2918 return;
2919 }
2920 }
2921
2922 // Case 3: standard operation with one index per degree of freedom -> go on
2923 // here
2924 std::array<unsigned int, n_lanes> cells = this->get_cell_ids();
2925
2926 const bool masking_is_active = mask.count() < n_lanes;
2927 if (masking_is_active)
2928 for (unsigned int v = 0; v < n_lanes; ++v)
2929 if (mask[v] == false)
2931
2932 std::bool_constant<internal::is_vectorizable<VectorType, Number>::value>
2933 vector_selector;
2934
2935 const bool use_vectorized_path =
2936 !(masking_is_active || accesses_exterior_dofs);
2937
2938 const std::size_t dofs_per_component = this->data->dofs_per_component_on_cell;
2939
2940 // Whether the n_components copies of a vector-valued quantity live in
2941 // n_components separate vectors, one component per vector, as opposed to
2942 // being interleaved within a single vector belonging to an FESystem. The
2943 // two cases need different index computations and the distinction recurs
2944 // several times below, so evaluate it once here.
2945 const bool separate_vectors =
2946 (n_components == 1 || this->n_fe_components == 1);
2947
2948 if (apply_constraints && this->cell != numbers::invalid_unsigned_int &&
2949 dof_info.index_storage_variants
2950 [is_face ? this->dof_access_index :
2951 internal::MatrixFreeFunctions::DoFInfo::dof_access_cell]
2952 [this->cell] == internal::MatrixFreeFunctions::DoFInfo::
2953 IndexStorageVariants::interleaved &&
2954 use_vectorized_path)
2955 {
2956 const unsigned int *dof_indices =
2957 dof_info.dof_indices_interleaved.data() +
2958 dof_info.row_starts[this->cell * this->n_fe_components * n_lanes]
2959 .first +
2960 this->dof_info
2961 ->component_dof_indices_offset[this->active_fe_index]
2962 [this->first_selected_component] *
2963 n_lanes;
2964
2965 std::array<typename VectorType::value_type *, n_components> src_ptrs;
2966 if (separate_vectors)
2967 for (unsigned int comp = 0; comp < n_components; ++comp)
2968 src_ptrs[comp] =
2969 const_cast<typename VectorType::value_type *>(src[comp]->begin());
2970 else
2971 src_ptrs[0] =
2972 const_cast<typename VectorType::value_type *>(src[0]->begin());
2973
2974 if (separate_vectors)
2975 for (unsigned int i = 0; i < dofs_per_component;
2976 ++i, dof_indices += n_lanes)
2977 for (unsigned int comp = 0; comp < n_components; ++comp)
2978 operation.process_dof_gather(
2979 dof_indices,
2980 *src[comp],
2981 0,
2982 src_ptrs[comp],
2983 this->values_dofs[comp * dofs_per_component + i],
2984 vector_selector);
2985 else
2986 for (unsigned int comp = 0; comp < n_components; ++comp)
2987 for (unsigned int i = 0; i < dofs_per_component;
2988 ++i, dof_indices += n_lanes)
2989 operation.process_dof_gather(
2990 dof_indices,
2991 *src[0],
2992 0,
2993 src_ptrs[0],
2994 this->values_dofs[comp * dofs_per_component + i],
2995 vector_selector);
2996 return;
2997 }
2998
2999 std::array<VectorizedArrayType *, n_components> values_dofs;
3000 for (unsigned int c = 0; c < n_components; ++c)
3001 values_dofs[c] = const_cast<VectorizedArrayType *>(this->values_dofs) +
3002 c * dofs_per_component;
3003
3004 // Allocate pointers, then initialize all of them to nullptrs and
3005 // below overwrite the ones we actually use:
3006 std::array<const unsigned int *, n_lanes> dof_indices;
3007 dof_indices.fill(nullptr);
3008
3009 // Assign the appropriate cell ids for face/cell case and get the pointers
3010 // to the dof indices of the cells on all lanes
3011
3012 bool has_constraints = false;
3013 const unsigned int n_components_read =
3014 this->n_fe_components > 1 ? n_components : 1;
3015
3016 if (is_face)
3017 {
3018 for (unsigned int v = 0; v < n_lanes; ++v)
3019 {
3020 if (cells[v] == numbers::invalid_unsigned_int)
3021 continue;
3022
3023 Assert(cells[v] < dof_info.row_starts.size() - 1, ExcInternalError());
3024 const std::pair<unsigned int, unsigned int> *my_index_start =
3025 &dof_info.row_starts[cells[v] * this->n_fe_components +
3026 this->first_selected_component];
3027
3028 // check whether any of the SIMD lanes has constraints, i.e., the
3029 // constraint indicator which is the second entry of row_starts
3030 // increments on this cell
3031 if (my_index_start[n_components_read].second !=
3032 my_index_start[0].second)
3033 has_constraints = true;
3034
3035 dof_indices[v] =
3036 dof_info.dof_indices.data() + my_index_start[0].first;
3037 }
3038 }
3039 else
3040 {
3041 for (unsigned int v = 0; v < n_lanes; ++v)
3042 {
3043 if (cells[v] == numbers::invalid_unsigned_int)
3044 continue;
3045
3046 const std::pair<unsigned int, unsigned int> *my_index_start =
3047 &dof_info.row_starts[cells[v] * this->n_fe_components +
3048 this->first_selected_component];
3049 if (my_index_start[n_components_read].second !=
3050 my_index_start[0].second)
3051 has_constraints = true;
3052
3053 Assert(my_index_start[n_components_read].first ==
3054 my_index_start[0].first ||
3055 my_index_start[0].first < dof_info.dof_indices.size(),
3056 ExcIndexRange(0,
3057 my_index_start[0].first,
3058 dof_info.dof_indices.size()));
3059 dof_indices[v] =
3060 dof_info.dof_indices.data() + my_index_start[0].first;
3061 }
3062 }
3063
3064 for (unsigned int comp = 0; comp < n_components; ++comp)
3065 for (unsigned int i = 0; i < dofs_per_component; ++i)
3066 operation.process_empty(values_dofs[comp][i]);
3067
3068 // Case where we have no constraints throughout the whole cell: Can go
3069 // through the list of DoFs directly
3070 if (!has_constraints && apply_constraints)
3071 {
3072 if (separate_vectors)
3073 {
3074 for (unsigned int v = 0; v < n_lanes; ++v)
3075 {
3076 if (cells[v] == numbers::invalid_unsigned_int)
3077 continue;
3078
3079 for (unsigned int i = 0; i < dofs_per_component; ++i)
3080 if (dof_indices[v][i] != numbers::invalid_unsigned_int)
3081 for (unsigned int comp = 0; comp < n_components; ++comp)
3082 operation.process_dof(dof_indices[v][i],
3083 *src[comp],
3084 values_dofs[comp][i][v]);
3085 }
3086 }
3087 else
3088 {
3089 for (unsigned int comp = 0; comp < n_components; ++comp)
3090 for (unsigned int v = 0; v < n_lanes; ++v)
3091 {
3092 if (cells[v] == numbers::invalid_unsigned_int)
3093 continue;
3094
3095 for (unsigned int i = 0; i < dofs_per_component; ++i)
3096 if (dof_indices[v][comp * dofs_per_component + i] !=
3098 operation.process_dof(
3099 dof_indices[v][comp * dofs_per_component + i],
3100 *src[0],
3101 values_dofs[comp][i][v]);
3102 }
3103 }
3104 return;
3105 }
3106
3107 // In the case where there are some constraints to be resolved, loop over
3108 // all vector components that are filled and then over local dofs. ind_local
3109 // holds local number on cell, index iterates over the elements of
3110 // index_local_to_global and dof_indices points to the global indices stored
3111 // in index_local_to_global
3112
3113 for (unsigned int v = 0; v < n_lanes; ++v)
3114 {
3115 if (cells[v] == numbers::invalid_unsigned_int)
3116 continue;
3117
3118 const unsigned int cell_index = cells[v];
3119 const unsigned int cell_dof_index =
3120 cell_index * this->n_fe_components + this->first_selected_component;
3121 unsigned int index_indicators =
3122 dof_info.row_starts[cell_dof_index].second;
3123 unsigned int next_index_indicators =
3124 dof_info.row_starts[cell_dof_index + 1].second;
3125
3126 // For read_dof_values_plain, redirect the dof_indices field to the
3127 // unconstrained indices
3128 if (apply_constraints == false &&
3131 {
3132 dof_indices[v] =
3133 dof_info.plain_dof_indices.data() +
3134 this->dof_info
3135 ->component_dof_indices_offset[this->active_fe_index]
3136 [this->first_selected_component] +
3138 next_index_indicators = index_indicators;
3139 }
3140
3141 if (separate_vectors)
3142 {
3143 unsigned int ind_local = 0;
3144 for (; index_indicators != next_index_indicators; ++index_indicators)
3145 {
3146 const std::pair<unsigned short, unsigned short> indicator =
3147 dof_info.constraint_indicator[index_indicators];
3148 // run through values up to next constraint
3149 for (unsigned int j = 0; j < indicator.first; ++j)
3150 if (dof_indices[v][j] != numbers::invalid_unsigned_int)
3151 for (unsigned int comp = 0; comp < n_components; ++comp)
3152 operation.process_dof(dof_indices[v][j],
3153 *src[comp],
3154 values_dofs[comp][ind_local + j][v]);
3155
3156 ind_local += indicator.first;
3157 dof_indices[v] += indicator.first;
3158
3159 // constrained case: build the local value as a linear
3160 // combination of the global value according to constraints
3161 Number value[n_components];
3162 for (unsigned int comp = 0; comp < n_components; ++comp)
3163 operation.pre_constraints(values_dofs[comp][ind_local][v],
3164 value[comp]);
3165
3166 const Number *data_val =
3167 this->matrix_free->constraint_pool_begin(indicator.second);
3168 const Number *end_pool =
3169 this->matrix_free->constraint_pool_end(indicator.second);
3170 for (; data_val != end_pool; ++data_val, ++dof_indices[v])
3171 if (*dof_indices[v] != numbers::invalid_unsigned_int)
3172 for (unsigned int comp = 0; comp < n_components; ++comp)
3173 operation.process_constraint(*dof_indices[v],
3174 *data_val,
3175 *src[comp],
3176 value[comp]);
3177
3178 for (unsigned int comp = 0; comp < n_components; ++comp)
3179 operation.post_constraints(value[comp],
3180 values_dofs[comp][ind_local][v]);
3181 ++ind_local;
3182 }
3183
3184 AssertIndexRange(ind_local, dofs_per_component + 1);
3185
3186 for (; ind_local < dofs_per_component; ++dof_indices[v], ++ind_local)
3187 if (*dof_indices[v] != numbers::invalid_unsigned_int)
3188 for (unsigned int comp = 0; comp < n_components; ++comp)
3189 operation.process_dof(*dof_indices[v],
3190 *src[comp],
3191 values_dofs[comp][ind_local][v]);
3192 }
3193 else
3194 {
3195 // case with vector-valued finite elements where all components are
3196 // included in one single vector. Assumption: first come all entries
3197 // to the first component, then all entries to the second one, and
3198 // so on. This is ensured by the way MatrixFree reads out the
3199 // indices.
3200 for (unsigned int comp = 0; comp < n_components; ++comp)
3201 {
3202 unsigned int ind_local = 0;
3203
3204 // check whether there is any constraint on the current cell
3205 for (; index_indicators != next_index_indicators;
3206 ++index_indicators)
3207 {
3208 const std::pair<unsigned short, unsigned short> indicator =
3209 dof_info.constraint_indicator[index_indicators];
3210
3211 // run through values up to next constraint
3212 for (unsigned int j = 0; j < indicator.first; ++j)
3213 if (dof_indices[v][j] != numbers::invalid_unsigned_int)
3214 operation.process_dof(
3215 dof_indices[v][j],
3216 *src[0],
3217 values_dofs[comp][ind_local + j][v]);
3218 ind_local += indicator.first;
3219 dof_indices[v] += indicator.first;
3220
3221 // constrained case: build the local value as a linear
3222 // combination of the global value according to constraints
3223 Number value;
3224 operation.pre_constraints(values_dofs[comp][ind_local][v],
3225 value);
3226
3227 const Number *data_val =
3228 this->matrix_free->constraint_pool_begin(indicator.second);
3229 const Number *end_pool =
3230 this->matrix_free->constraint_pool_end(indicator.second);
3231
3232 for (; data_val != end_pool; ++data_val, ++dof_indices[v])
3233 if (*dof_indices[v] != numbers::invalid_unsigned_int)
3234 operation.process_constraint(*dof_indices[v],
3235 *data_val,
3236 *src[0],
3237 value);
3238
3239 operation.post_constraints(value,
3240 values_dofs[comp][ind_local][v]);
3241 ++ind_local;
3242 }
3243
3244 AssertIndexRange(ind_local, dofs_per_component + 1);
3245
3246 // get the dof values past the last constraint
3247 for (; ind_local < dofs_per_component;
3248 ++dof_indices[v], ++ind_local)
3249 if (*dof_indices[v] != numbers::invalid_unsigned_int)
3250 {
3251 AssertIndexRange(*dof_indices[v], src[0]->size());
3252 operation.process_dof(*dof_indices[v],
3253 *src[0],
3254 values_dofs[comp][ind_local][v]);
3255 }
3256
3257 if (apply_constraints == true && comp + 1 < n_components)
3258 next_index_indicators =
3259 dof_info.row_starts[cell_dof_index + comp + 2].second;
3260 }
3261 }
3262 }
3263}
3264
3265
3266
3267template <int dim,
3268 int n_components_,
3269 typename Number,
3270 bool is_face,
3271 typename VectorizedArrayType>
3272template <typename VectorType, typename VectorOperation>
3273inline void
3276 const VectorOperation &operation,
3277 const std::array<VectorType *, n_components_> &src) const
3278{
3279 Assert(!local_dof_indices.empty(), ExcNotInitialized());
3280
3281 const std::size_t dofs_per_component = this->data->dofs_per_component_on_cell;
3282 unsigned int index = this->first_selected_component * dofs_per_component;
3283 for (unsigned int comp = 0; comp < n_components; ++comp)
3284 {
3285 for (unsigned int i = 0; i < dofs_per_component; ++i, ++index)
3286 {
3287 operation.process_empty(
3288 this->values_dofs[comp * dofs_per_component + i]);
3289 operation.process_dof_global(
3290 local_dof_indices[this->data->lexicographic_numbering[index]],
3291 *src[0],
3292 this->values_dofs[comp * dofs_per_component + i][0]);
3293 }
3294 }
3295}
3296
3297
3298
3299template <int dim,
3300 int n_components_,
3301 typename Number,
3302 bool is_face,
3303 typename VectorizedArrayType>
3304template <typename VectorType, typename VectorOperation>
3305inline void
3308 const VectorOperation &operation,
3309 const std::array<VectorType *, n_components_> &src,
3310 const std::array<
3312 n_components_> &vectors_sm,
3313 const std::bitset<n_lanes> &mask) const
3314{
3315 // This functions processes the functions read_dof_values,
3316 // distribute_local_to_global, and set_dof_values with the same code for
3317 // contiguous cell indices (DG case). The distinction between these three
3318 // cases is made by the input VectorOperation that either reads values from
3319 // a vector and puts the data into the local data field or write local data
3320 // into the vector. Certain operations are no-ops for the given use case.
3321
3322 std::bool_constant<internal::is_vectorizable<VectorType, Number>::value>
3323 vector_selector;
3325 is_face ? this->dof_access_index :
3327 const unsigned int n_active_lanes = mask.count();
3328
3329 const internal::MatrixFreeFunctions::DoFInfo &dof_info = *this->dof_info;
3330 const std::vector<unsigned int> &dof_indices_cont =
3331 dof_info.dof_indices_contiguous[ind];
3332
3333 const std::size_t dofs_per_component = this->data->dofs_per_component_on_cell;
3334 std::array<VectorizedArrayType *, n_components> values_dofs{{nullptr}};
3335 for (unsigned int c = 0; c < n_components; ++c)
3336 values_dofs[c] = const_cast<VectorizedArrayType *>(this->values_dofs) +
3337 c * dofs_per_component;
3338
3340
3341 const bool accesses_exterior_dofs =
3342 this->dof_access_index ==
3344 this->is_interior_face() == false;
3345
3346 // Whether the n_components copies of a vector-valued quantity live in
3347 // n_components separate (typically scalar) vectors, one component per
3348 // vector -- as opposed to all components being interleaved within a
3349 // single vector that belongs to an FESystem with n_fe_components ==
3350 // n_components. This distinction recurs throughout this function
3351 // because the two cases require different index computations; we
3352 // evaluate it once here rather than at each use.
3353 const bool separate_vectors =
3354 (n_components == 1 || this->n_fe_components == 1);
3355
3356 // Simple case: We have contiguous storage, so we can simply copy out the
3357 // data
3358 if (dof_info.index_storage_variants[ind][this->cell] ==
3360 interleaved_contiguous &&
3361 n_active_lanes == n_lanes && !accesses_exterior_dofs)
3362 {
3363 const unsigned int dof_index =
3364 dof_indices_cont[this->cell * n_lanes] +
3365 this->dof_info
3366 ->component_dof_indices_offset[this->active_fe_index]
3367 [this->first_selected_component] *
3368 n_lanes;
3369 if (separate_vectors)
3370 for (unsigned int comp = 0; comp < n_components; ++comp)
3371 operation.process_dofs_vectorized(dofs_per_component,
3372 dof_index,
3373 *src[comp],
3374 values_dofs[comp],
3375 vector_selector);
3376 else
3377 operation.process_dofs_vectorized(dofs_per_component * n_components,
3378 dof_index,
3379 *src[0],
3380 values_dofs[0],
3381 vector_selector);
3382 return;
3383 }
3384
3385 const std::array<unsigned int, n_lanes> &cells = this->get_cell_or_face_ids();
3386
3387 // More general case: Must go through the components one by one and apply
3388 // some transformations
3389 const unsigned int n_filled_lanes =
3390 dof_info.n_vectorization_lanes_filled[ind][this->cell];
3391
3392 const bool use_vectorized_path = n_filled_lanes == n_lanes &&
3393 n_active_lanes == n_lanes &&
3394 !accesses_exterior_dofs;
3395
3396 if (vectors_sm[0] != nullptr)
3397 {
3398 const auto compute_vector_ptrs = [&](const unsigned int comp) {
3399 std::array<typename VectorType::value_type *, n_lanes> vector_ptrs{
3400 {nullptr}};
3401
3402 const auto upper_bound =
3403 std::min<unsigned int>(n_filled_lanes, n_lanes);
3404 for (unsigned int v = 0; v < upper_bound; ++v)
3405 {
3406 if (mask[v] == false)
3407 {
3408 vector_ptrs[v] = nullptr;
3409 continue;
3410 }
3411
3414 Assert(ind < dof_info.dof_indices_contiguous_sm.size(),
3415 ExcIndexRange(ind,
3416 0,
3417 dof_info.dof_indices_contiguous_sm.size()));
3418 Assert(
3419 cells[v] < dof_info.dof_indices_contiguous_sm[ind].size(),
3420 ExcIndexRange(cells[v],
3421 0,
3422 dof_info.dof_indices_contiguous_sm[ind].size()));
3423
3424 const auto &temp =
3425 dof_info.dof_indices_contiguous_sm[ind][cells[v]];
3426
3427 if (temp.first != numbers::invalid_unsigned_int)
3428 vector_ptrs[v] = const_cast<typename VectorType::value_type *>(
3429 vectors_sm[comp]->operator[](temp.first).data() + temp.second +
3431 [this->active_fe_index][this->first_selected_component]);
3432 else
3433 vector_ptrs[v] = nullptr;
3434 }
3435 for (unsigned int v = n_filled_lanes; v < n_lanes; ++v)
3436 vector_ptrs[v] = nullptr;
3437
3438 return vector_ptrs;
3439 };
3440
3441 if (use_vectorized_path)
3442 {
3443 // If the components live in separate vectors, gather each one
3444 // with its own transposed access. If instead all components
3445 // come from a single FESystem-based vector, their DoFs are
3446 // contiguous per cell in both the source vector and
3447 // values_dofs, so we can process all of them with a single
3448 // bulk transposed access instead -- one loop iteration with a
3449 // correspondingly larger block size.
3450 const unsigned int n_blocks = separate_vectors ? n_components : 1;
3451 const unsigned int block_size = separate_vectors ?
3452 dofs_per_component :
3453 dofs_per_component * n_components;
3454 for (unsigned int comp = 0; comp < n_blocks; ++comp)
3455 {
3456 auto vector_ptrs =
3457 compute_vector_ptrs(separate_vectors ? comp : 0);
3458 operation.process_dofs_vectorized_transpose(block_size,
3459 vector_ptrs,
3460 separate_vectors ?
3461 values_dofs[comp] :
3462 &values_dofs[0][0],
3463 vector_selector);
3464 }
3465 }
3466 else
3467 for (unsigned int comp = 0; comp < n_components; ++comp)
3468 {
3469 auto vector_ptrs = compute_vector_ptrs(separate_vectors ? comp : 0);
3470
3471 for (unsigned int i = 0; i < dofs_per_component; ++i)
3472 operation.process_empty(values_dofs[comp][i]);
3473
3474 // As above: with separate vectors, component comp's DoFs sit
3475 // at the start of vector_ptrs; with a single FESystem-based
3476 // vector, they are offset by the preceding components' DoFs.
3477 const unsigned int comp_offset =
3478 separate_vectors ? 0 : comp * dofs_per_component;
3479 for (unsigned int v = 0; v < n_filled_lanes; ++v)
3480 if (mask[v] == true)
3481 for (unsigned int i = 0; i < dofs_per_component; ++i)
3482 operation.process_dof(vector_ptrs[v][i + comp_offset],
3483 values_dofs[comp][i][v]);
3484 }
3485 return;
3486 }
3487
3488 std::array<unsigned int, n_lanes> dof_indices{
3490 Assert(n_filled_lanes <= n_lanes, ExcInternalError());
3491 for (unsigned int v = 0; v < n_filled_lanes; ++v)
3492 {
3493 Assert(mask[v] == false || cells[v] != numbers::invalid_unsigned_int,
3495 if (mask[v] == true)
3496 dof_indices[v] =
3497 dof_indices_cont[cells[v]] +
3498 this->dof_info
3499 ->component_dof_indices_offset[this->active_fe_index]
3500 [this->first_selected_component] *
3501 dof_info.dof_indices_interleave_strides[ind][cells[v]];
3502 }
3503
3504 // In the case with contiguous cell indices, we know that there are no
3505 // constraints and that the indices within each element are contiguous
3506 if (use_vectorized_path)
3507 {
3508 if (dof_info.index_storage_variants[ind][this->cell] ==
3510 contiguous)
3511 {
3512 if (separate_vectors)
3513 for (unsigned int comp = 0; comp < n_components; ++comp)
3514 operation.process_dofs_vectorized_transpose(dofs_per_component,
3515 dof_indices.data(),
3516 *src[comp],
3517 values_dofs[comp],
3518 vector_selector);
3519 else
3520 operation.process_dofs_vectorized_transpose(dofs_per_component *
3521 n_components,
3522 dof_indices.data(),
3523 *src[0],
3524 &values_dofs[0][0],
3525 vector_selector);
3526 }
3527 else if (dof_info.index_storage_variants[ind][this->cell] ==
3529 interleaved_contiguous_strided)
3530 {
3531 std::array<typename VectorType::value_type *, n_components> src_ptrs{
3532 {nullptr}};
3533 if (separate_vectors)
3534 for (unsigned int comp = 0; comp < n_components; ++comp)
3535 src_ptrs[comp] = const_cast<typename VectorType::value_type *>(
3536 src[comp]->begin());
3537 else
3538 src_ptrs[0] =
3539 const_cast<typename VectorType::value_type *>(src[0]->begin());
3540
3541 if (separate_vectors)
3542 for (unsigned int i = 0; i < dofs_per_component; ++i)
3543 {
3544 for (unsigned int comp = 0; comp < n_components; ++comp)
3545 operation.process_dof_gather(dof_indices.data(),
3546 *src[comp],
3547 i * n_lanes,
3548 src_ptrs[comp] + i * n_lanes,
3549 values_dofs[comp][i],
3550 vector_selector);
3551 }
3552 else
3553 for (unsigned int comp = 0; comp < n_components; ++comp)
3554 for (unsigned int i = 0; i < dofs_per_component; ++i)
3555 {
3556 operation.process_dof_gather(
3557 dof_indices.data(),
3558 *src[0],
3559 (comp * dofs_per_component + i) * n_lanes,
3560 src_ptrs[0] + (comp * dofs_per_component + i) * n_lanes,
3561 values_dofs[comp][i],
3562 vector_selector);
3563 }
3564 }
3565 else
3566 {
3567 Assert(dof_info.index_storage_variants[ind][this->cell] ==
3569 IndexStorageVariants::interleaved_contiguous_mixed_strides,
3571 std::array<typename VectorType::value_type *, n_components> src_ptrs{
3572 {nullptr}};
3573 if (separate_vectors)
3574 for (unsigned int comp = 0; comp < n_components; ++comp)
3575 src_ptrs[comp] = const_cast<typename VectorType::value_type *>(
3576 src[comp]->begin());
3577 else
3578 src_ptrs[0] =
3579 const_cast<typename VectorType::value_type *>(src[0]->begin());
3580
3581 const unsigned int *offsets =
3582 &dof_info.dof_indices_interleave_strides[ind][n_lanes * this->cell];
3583 if (separate_vectors)
3584 for (unsigned int i = 0; i < dofs_per_component; ++i)
3585 {
3586 for (unsigned int comp = 0; comp < n_components; ++comp)
3587 operation.process_dof_gather(dof_indices.data(),
3588 *src[comp],
3589 0,
3590 src_ptrs[comp],
3591 values_dofs[comp][i],
3592 vector_selector);
3594 for (unsigned int v = 0; v < n_lanes; ++v)
3595 dof_indices[v] += offsets[v];
3596 }
3597 else
3598 for (unsigned int comp = 0; comp < n_components; ++comp)
3599 for (unsigned int i = 0; i < dofs_per_component; ++i)
3600 {
3601 operation.process_dof_gather(dof_indices.data(),
3602 *src[0],
3603 0,
3604 src_ptrs[0],
3605 values_dofs[comp][i],
3606 vector_selector);
3608 for (unsigned int v = 0; v < n_lanes; ++v)
3609 dof_indices[v] += offsets[v];
3610 }
3611 }
3612 }
3613 else
3614 for (unsigned int comp = 0; comp < n_components; ++comp)
3615 {
3616 for (unsigned int i = 0; i < dofs_per_component; ++i)
3617 operation.process_empty(values_dofs[comp][i]);
3618 if (accesses_exterior_dofs)
3619 {
3620 for (unsigned int v = 0; v < n_filled_lanes; ++v)
3621 if (mask[v] == true)
3622 {
3623 if (dof_info.index_storage_variants
3624 [ind][cells[v] / VectorizedArrayType::size()] ==
3627 {
3628 if (separate_vectors)
3629 {
3630 for (unsigned int i = 0; i < dofs_per_component; ++i)
3631 operation.process_dof(dof_indices[v] + i,
3632 *src[comp],
3633 values_dofs[comp][i][v]);
3634 }
3635 else
3636 {
3637 for (unsigned int i = 0; i < dofs_per_component; ++i)
3638 operation.process_dof(dof_indices[v] + i +
3639 comp * dofs_per_component,
3640 *src[0],
3641 values_dofs[comp][i][v]);
3642 }
3643 }
3644 else
3645 {
3646 const unsigned int offset =
3647 dof_info.dof_indices_interleave_strides[ind][cells[v]];
3648 AssertIndexRange(offset, VectorizedArrayType::size() + 1);
3649 if (separate_vectors)
3650 {
3651 for (unsigned int i = 0; i < dofs_per_component; ++i)
3652 operation.process_dof(dof_indices[v] + i * offset,
3653 *src[comp],
3654 values_dofs[comp][i][v]);
3655 }
3656 else
3657 {
3658 for (unsigned int i = 0; i < dofs_per_component; ++i)
3659 operation.process_dof(
3660 dof_indices[v] +
3661 (i + comp * dofs_per_component) * offset,
3662 *src[0],
3663 values_dofs[comp][i][v]);
3664 }
3665 }
3666 }
3667 }
3668 else
3669 {
3670 if (dof_info.index_storage_variants[ind][this->cell] ==
3672 contiguous)
3673 {
3674 if (separate_vectors)
3675 {
3676 for (unsigned int v = 0; v < n_filled_lanes; ++v)
3677 if (mask[v] == true)
3678 for (unsigned int i = 0; i < dofs_per_component; ++i)
3679 operation.process_dof(dof_indices[v] + i,
3680 *src[comp],
3681 values_dofs[comp][i][v]);
3682 }
3683 else
3684 {
3685 for (unsigned int v = 0; v < n_filled_lanes; ++v)
3686 if (mask[v] == true)
3687 for (unsigned int i = 0; i < dofs_per_component; ++i)
3688 operation.process_dof(dof_indices[v] + i +
3689 comp * dofs_per_component,
3690 *src[0],
3691 values_dofs[comp][i][v]);
3692 }
3693 }
3694 else
3695 {
3696 const unsigned int *offsets =
3698 [ind][VectorizedArrayType::size() * this->cell];
3699 for (unsigned int v = 0; v < n_filled_lanes; ++v)
3700 AssertIndexRange(offsets[v], VectorizedArrayType::size() + 1);
3701 if (separate_vectors)
3702 for (unsigned int v = 0; v < n_filled_lanes; ++v)
3703 {
3704 if (mask[v] == true)
3705 for (unsigned int i = 0; i < dofs_per_component; ++i)
3706 operation.process_dof(dof_indices[v] + i * offsets[v],
3707 *src[comp],
3708 values_dofs[comp][i][v]);
3709 }
3710 else
3711 {
3712 for (unsigned int v = 0; v < n_filled_lanes; ++v)
3713 if (mask[v] == true)
3714 for (unsigned int i = 0; i < dofs_per_component; ++i)
3715 operation.process_dof(
3716 dof_indices[v] +
3717 (i + comp * dofs_per_component) * offsets[v],
3718 *src[0],
3719 values_dofs[comp][i][v]);
3720 }
3721 }
3722 }
3723 }
3724}
3725
3726namespace internal
3727{
3728 template <
3729 typename Number,
3730 typename VectorType,
3731 std::enable_if_t<!IsBlockVector<VectorType>::value, VectorType> * = nullptr>
3732 decltype(std::declval<VectorType>().begin())
3733 get_beginning(VectorType &vec)
3734 {
3735 return vec.begin();
3736 }
3737
3738 template <
3739 typename Number,
3740 typename VectorType,
3741 std::enable_if_t<IsBlockVector<VectorType>::value, VectorType> * = nullptr>
3742 typename VectorType::value_type *
3743 get_beginning(VectorType &)
3744 {
3745 return nullptr;
3746 }
3747
3748 template <typename VectorType,
3749 std::enable_if_t<has_shared_vector_data<VectorType>, VectorType> * =
3750 nullptr>
3751 const std::vector<ArrayView<const typename VectorType::value_type>> *
3752 get_shared_vector_data(VectorType *vec,
3753 const bool is_valid_mode_for_sm,
3754 const unsigned int active_fe_index,
3756 {
3757 // note: no hp is supported
3758 if (is_valid_mode_for_sm &&
3759 dof_info->dof_indices_contiguous_sm[0 /*any index (<3) should work*/]
3760 .size() > 0 &&
3761 active_fe_index == 0)
3762 return &vec->shared_vector_data();
3763 else
3764 return nullptr;
3765 }
3766
3767 template <typename VectorType,
3768 std::enable_if_t<!has_shared_vector_data<VectorType>, VectorType>
3769 * = nullptr>
3770 const std::vector<ArrayView<const typename VectorType::value_type>> *
3771 get_shared_vector_data(VectorType *,
3772 const bool,
3773 const unsigned int,
3775 {
3776 return nullptr;
3777 }
3778
3779 template <int n_components, typename VectorType>
3780 std::pair<
3781 std::array<typename internal::BlockVectorSelector<
3782 VectorType,
3783 IsBlockVector<VectorType>::value>::BaseVectorType *,
3784 n_components>,
3785 std::array<
3786 const std::vector<ArrayView<const typename internal::BlockVectorSelector<
3787 VectorType,
3788 IsBlockVector<VectorType>::value>::BaseVectorType::value_type>> *,
3789 n_components>>
3790 get_vector_data(VectorType &src,
3791 const unsigned int first_index,
3792 const bool is_valid_mode_for_sm,
3793 const unsigned int active_fe_index,
3795 {
3796 // select between block vectors and non-block vectors. Note that the number
3797 // of components is checked in the internal data
3798 std::pair<
3799 std::array<typename internal::BlockVectorSelector<
3800 VectorType,
3801 IsBlockVector<VectorType>::value>::BaseVectorType *,
3802 n_components>,
3803 std::array<
3804 const std::vector<
3805 ArrayView<const typename internal::BlockVectorSelector<
3806 VectorType,
3807 IsBlockVector<VectorType>::value>::BaseVectorType::value_type>> *,
3808 n_components>>
3809 src_data;
3810
3811 for (unsigned int d = 0; d < n_components; ++d)
3812 src_data.first[d] = internal::BlockVectorSelector<
3813 VectorType,
3814 IsBlockVector<VectorType>::value>::get_vector_component(src,
3815 d +
3816 first_index);
3817
3818 for (unsigned int d = 0; d < n_components; ++d)
3819 src_data.second[d] = get_shared_vector_data(
3820 const_cast<typename internal::BlockVectorSelector<
3821 std::remove_const_t<VectorType>,
3823 *>(src_data.first[d]),
3824 is_valid_mode_for_sm,
3825 active_fe_index,
3826 dof_info);
3827
3828 return src_data;
3829 }
3830} // namespace internal
3831
3832
3833
3834template <int dim,
3835 int n_components_,
3836 typename Number,
3837 bool is_face,
3838 typename VectorizedArrayType>
3839inline void
3842{
3843 if (this->dof_info == nullptr ||
3844 this->dof_info->hanging_node_constraint_masks.empty() ||
3845 this->dof_info->hanging_node_constraint_masks_comp.empty() ||
3846 this->dof_info->hanging_node_constraint_masks_comp
3847 [this->active_fe_index][this->first_selected_component] == false)
3848 return; // nothing to do with faces
3849
3850 std::array<internal::MatrixFreeFunctions::compressed_constraint_kind, n_lanes>
3851 constraint_mask{{internal::MatrixFreeFunctions::
3852 unconstrained_compressed_constraint_kind}};
3853
3854 bool hn_available = false;
3855
3856 const std::array<unsigned int, n_lanes> &cells = this->get_cell_ids();
3857
3858 for (unsigned int v = 0; v < n_lanes; ++v)
3859 {
3860 if (cells[v] == numbers::invalid_unsigned_int)
3861 {
3862 constraint_mask[v] = internal::MatrixFreeFunctions::
3864 continue;
3865 }
3866
3867 const unsigned int cell_index = cells[v];
3868 const auto mask =
3870 constraint_mask[v] = mask;
3871
3872 hn_available |= (mask != internal::MatrixFreeFunctions::
3874 }
3875
3876 if (hn_available == false)
3877 return; // no hanging node on cell batch -> nothing to do
3878
3880 apply(n_components,
3881 this->data->data.front().fe_degree,
3882 this->get_shape_info(),
3883 transpose,
3884 constraint_mask,
3885 this->values_dofs);
3886}
3887
3888
3889
3890template <int dim,
3891 int n_components_,
3892 typename Number,
3893 bool is_face,
3894 typename VectorizedArrayType>
3895inline void
3898 const EvaluationFlags::EvaluationFlags evaluation_flag)
3899{
3900 if (this->data->element_type ==
3902 evaluation_flag & EvaluationFlags::gradients &&
3903 this->cell_type > internal::MatrixFreeFunctions::affine)
3904 std::copy_n(this->values_quad,
3905 n_components * this->n_quadrature_points,
3906 this->values_from_gradients_quad);
3907}
3908
3909
3910
3911template <int dim,
3912 int n_components_,
3913 typename Number,
3914 bool is_face,
3915 typename VectorizedArrayType>
3916template <typename VectorType>
3917inline void
3919 read_dof_values(const VectorType &src,
3920 const unsigned int first_index,
3921 const std::bitset<n_lanes> &mask)
3922{
3923 const auto src_data = internal::get_vector_data<n_components_>(
3924 src,
3925 first_index,
3926 this->dof_info != nullptr &&
3927 this->dof_access_index ==
3929 this->active_fe_index,
3930 this->dof_info);
3931
3933 read_write_operation(reader, src_data.first, src_data.second, mask, true);
3934
3935 apply_hanging_node_constraints(false);
3936
3937 if constexpr (running_in_debug_mode())
3938 {
3939 this->dof_values_initialized = true;
3940 }
3941}
3942
3943
3944
3945template <int dim,
3946 int n_components_,
3947 typename Number,
3948 bool is_face,
3949 typename VectorizedArrayType>
3950template <typename VectorType>
3951inline void
3953 read_dof_values_plain(const VectorType &src,
3954 const unsigned int first_index,
3955 const std::bitset<n_lanes> &mask)
3956{
3957 const auto src_data = internal::get_vector_data<n_components_>(
3958 src,
3959 first_index,
3960 this->dof_info != nullptr &&
3961 this->dof_access_index ==
3963 this->active_fe_index,
3964 this->dof_info);
3965
3967 read_write_operation(reader, src_data.first, src_data.second, mask, false);
3968
3969 if constexpr (running_in_debug_mode())
3970 {
3971 this->dof_values_initialized = true;
3972 }
3973}
3974
3975
3976
3977template <int dim,
3978 int n_components_,
3979 typename Number,
3980 bool is_face,
3981 typename VectorizedArrayType>
3982template <typename VectorType>
3983inline void
3985 distribute_local_to_global(VectorType &dst,
3986 const unsigned int first_index,
3987 const std::bitset<n_lanes> &mask) const
3988{
3989 if constexpr (running_in_debug_mode())
3990 {
3991 Assert(this->dof_values_initialized == true,
3993 }
3994
3995 apply_hanging_node_constraints(true);
3996
3997 const auto dst_data = internal::get_vector_data<n_components_>(
3998 dst,
3999 first_index,
4000 this->dof_info != nullptr &&
4001 this->dof_access_index ==
4003 this->active_fe_index,
4004 this->dof_info);
4005
4007 distributor;
4008 read_write_operation(distributor, dst_data.first, dst_data.second, mask);
4009}
4010
4011
4012
4013template <int dim,
4014 int n_components_,
4015 typename Number,
4016 bool is_face,
4017 typename VectorizedArrayType>
4018template <typename VectorType>
4019inline void
4021 set_dof_values(VectorType &dst,
4022 const unsigned int first_index,
4023 const std::bitset<n_lanes> &mask) const
4024{
4025 if constexpr (running_in_debug_mode())
4026 {
4027 Assert(this->dof_values_initialized == true,
4029 }
4030
4031 const auto dst_data = internal::get_vector_data<n_components_>(
4032 dst,
4033 first_index,
4034 this->dof_info != nullptr &&
4035 this->dof_access_index ==
4037 this->active_fe_index,
4038 this->dof_info);
4039
4041 read_write_operation(setter, dst_data.first, dst_data.second, mask);
4042}
4043
4044
4045
4046template <int dim,
4047 int n_components_,
4048 typename Number,
4049 bool is_face,
4050 typename VectorizedArrayType>
4051template <typename VectorType>
4052inline void
4054 set_dof_values_plain(VectorType &dst,
4055 const unsigned int first_index,
4056 const std::bitset<n_lanes> &mask) const
4057{
4058 if constexpr (running_in_debug_mode())
4059 {
4060 Assert(this->dof_values_initialized == true,
4062 }
4063
4064 const auto dst_data = internal::get_vector_data<n_components_>(
4065 dst,
4066 first_index,
4067 this->dof_access_index ==
4069 this->active_fe_index,
4070 this->dof_info);
4071
4073 read_write_operation(setter, dst_data.first, dst_data.second, mask, false);
4074}
4075
4076
4077
4078/*------------------------------ access to data fields ----------------------*/
4079
4080
4081
4082template <int dim,
4083 int n_components_,
4084 typename Number,
4085 bool is_face,
4086 typename VectorizedArrayType>
4088 typename FEEvaluationBase<dim,
4089 n_components_,
4090 Number,
4091 is_face,
4092 VectorizedArrayType>::value_type
4094 get_dof_value(const unsigned int dof) const
4095{
4096 AssertIndexRange(dof, this->data->dofs_per_component_on_cell);
4097 if constexpr (n_components == 1)
4098 return this->values_dofs[dof];
4099 else
4100 {
4101 const std::size_t dofs = this->data->dofs_per_component_on_cell;
4102 Tensor<1, n_components_, VectorizedArrayType> return_value;
4103 for (unsigned int comp = 0; comp < n_components; ++comp)
4104 return_value[comp] = this->values_dofs[comp * dofs + dof];
4105 return return_value;
4106 }
4107}
4108
4109
4110
4111template <int dim,
4112 int n_components_,
4113 typename Number,
4114 bool is_face,
4115 typename VectorizedArrayType>
4117 typename FEEvaluationBase<dim,
4118 n_components_,
4119 Number,
4120 is_face,
4121 VectorizedArrayType>::value_type
4123 get_value(const unsigned int q_point) const
4124{
4125 if constexpr (running_in_debug_mode())
4126 {
4127 Assert(this->values_quad_initialized == true,
4129 }
4130
4131 AssertIndexRange(q_point, this->n_quadrature_points);
4132 if constexpr (n_components == 1)
4133 return this->values_quad[q_point];
4134 else
4135 {
4136 if (n_components == dim &&
4137 this->data->element_type ==
4139 {
4140 // Piola transform is required
4141 if constexpr (running_in_debug_mode())
4142 {
4143 Assert(this->values_quad_initialized == true,
4145 }
4146
4147 AssertIndexRange(q_point, this->n_quadrature_points);
4148 Assert(this->J_value != nullptr,
4150 "update_values"));
4151 const std::size_t nqp = this->n_quadrature_points;
4153
4154 if (!is_face &&
4156 {
4157 // Cartesian cell
4158 const Tensor<2, dim, VectorizedArrayType> jac = this->jacobian[1];
4159 const VectorizedArrayType inv_det =
4160 (dim == 2) ? this->jacobian[0][0][0] * this->jacobian[0][1][1] :
4161 this->jacobian[0][0][0] * this->jacobian[0][1][1] *
4162 this->jacobian[0][2][2];
4163
4164 // J * u * det(J^-1)
4165 for (unsigned int comp = 0; comp < n_components; ++comp)
4166 value_out[comp] = this->values_quad[comp * nqp + q_point] *
4167 jac[comp][comp] * inv_det;
4168 }
4169 else
4170 {
4171 // Affine or general cell
4172 const Tensor<2, dim, VectorizedArrayType> inv_t_jac =
4173 (this->cell_type > internal::MatrixFreeFunctions::affine) ?
4174 this->jacobian[q_point] :
4175 this->jacobian[0];
4177 (this->cell_type > internal::MatrixFreeFunctions::affine) ?
4178 transpose(invert(inv_t_jac)) :
4179 this->jacobian[1];
4180
4181 // Derivatives are reordered for faces. Need to take this into
4182 // account
4183 const VectorizedArrayType inv_det =
4184 (is_face && dim == 2 && this->get_face_no() < 2) ?
4185 -determinant(inv_t_jac) :
4186 determinant(inv_t_jac);
4187 // J * u * det(J^-1)
4188 for (unsigned int comp = 0; comp < n_components; ++comp)
4189 {
4190 value_out[comp] = this->values_quad[q_point] * jac[comp][0];
4191 for (unsigned int e = 1; e < dim; ++e)
4192 value_out[comp] +=
4193 this->values_quad[e * nqp + q_point] * jac[comp][e];
4194 value_out[comp] *= inv_det;
4195 }
4196 }
4197 return value_out;
4198 }
4199 else if (n_components == dim &&
4200 this->data->element_type ==
4202 {
4203 // Piola transform is required
4204 if constexpr (running_in_debug_mode())
4205 {
4206 Assert(this->values_quad_initialized == true,
4208 }
4209
4210 AssertIndexRange(q_point, this->n_quadrature_points);
4211 Assert(this->J_value != nullptr,
4213 "update_values"));
4214 const std::size_t nqp = this->n_quadrature_points;
4216
4217 if (!is_face &&
4219 {
4220 // Cartesian cell
4221 const Tensor<2, dim, VectorizedArrayType> inv_transp_jac =
4222 this->jacobian[0];
4223
4224
4225 // J^{-T} * u
4226 for (unsigned int comp = 0; comp < n_components; ++comp)
4227 value_out[comp] = this->values_quad[comp * nqp + q_point] *
4228 inv_transp_jac[comp][comp];
4229 }
4230 else
4231 {
4232 // Affine or general cell
4233 const Tensor<2, dim, VectorizedArrayType> inv_t_jac =
4234 (this->cell_type > internal::MatrixFreeFunctions::affine) ?
4235 this->jacobian[q_point] :
4236 this->jacobian[0];
4237
4238 // J^{-T} * u
4239 for (unsigned int comp = 0; comp < n_components; ++comp)
4240 {
4241 value_out[comp] =
4242 this->values_quad[q_point] * inv_t_jac[comp][0];
4243 for (unsigned int e = 1; e < dim; ++e)
4244 value_out[comp] +=
4245 this->values_quad[e * nqp + q_point] * inv_t_jac[comp][e];
4246 }
4247 }
4248 return value_out;
4249 }
4250 else
4251 {
4252 const std::size_t nqp = this->n_quadrature_points;
4254 for (unsigned int comp = 0; comp < n_components; ++comp)
4255 return_value[comp] = this->values_quad[comp * nqp + q_point];
4256 return return_value;
4257 }
4258 }
4259}
4260
4261
4262
4263template <int dim,
4264 int n_components_,
4265 typename Number,
4266 bool is_face,
4267 typename VectorizedArrayType>
4269 typename FEEvaluationBase<dim,
4270 n_components_,
4271 Number,
4272 is_face,
4273 VectorizedArrayType>::gradient_type
4275 get_gradient(const unsigned int q_point) const
4276{
4277 if constexpr (running_in_debug_mode())
4278 {
4279 Assert(this->gradients_quad_initialized == true,
4281 }
4282
4283 AssertIndexRange(q_point, this->n_quadrature_points);
4284 Assert(this->jacobian != nullptr,
4286 "update_gradients"));
4287 const std::size_t nqp = this->n_quadrature_points;
4288
4289 if constexpr (n_components == dim && dim > 1)
4290 {
4291 if (this->data->element_type ==
4293 {
4294 // Piola transform is required
4295 if constexpr (running_in_debug_mode())
4296 {
4297 Assert(this->gradients_quad_initialized == true,
4299 }
4300
4301 AssertIndexRange(q_point, this->n_quadrature_points);
4302 Assert(this->jacobian != nullptr,
4304 "update_gradients"));
4305 const std::size_t nqp = this->n_quadrature_points;
4306 const std::size_t nqp_d = nqp * dim;
4308 const VectorizedArrayType *gradients =
4309 this->gradients_quad + q_point * dim;
4310
4311
4312 if (!is_face &&
4314 {
4315 // Cartesian cell
4316 const Tensor<2, dim, VectorizedArrayType> &inv_t_jac =
4317 this->jacobian[0];
4319 this->jacobian[1];
4320 const VectorizedArrayType inv_det =
4321 (dim == 2) ? this->jacobian[0][0][0] * this->jacobian[0][1][1] :
4322 this->jacobian[0][0][0] * this->jacobian[0][1][1] *
4323 this->jacobian[0][2][2];
4324
4325 // J * grad_quad * J^-1 * det(J^-1)
4326 for (unsigned int d = 0; d < dim; ++d)
4327 for (unsigned int comp = 0; comp < n_components; ++comp)
4328 grad_out[comp][d] = gradients[comp * nqp_d + d] *
4329 inv_t_jac[d][d] *
4330 (jac[comp][comp] * inv_det);
4331 }
4332 else if (this->cell_type <= internal::MatrixFreeFunctions::affine)
4333 {
4334 // Affine cell
4335 const Tensor<2, dim, VectorizedArrayType> &inv_t_jac =
4336 this->jacobian[0];
4338 this->jacobian[1];
4339
4340 // Derivatives are reordered for faces. Need to take this into
4341 // account
4342 const VectorizedArrayType inv_det =
4343 (is_face && dim == 2 && this->get_face_no() < 2) ?
4344 -determinant(inv_t_jac) :
4345 determinant(inv_t_jac);
4346
4347 VectorizedArrayType tmp[dim][dim];
4348 // J * grad_quad * J^-1 * det(J^-1)
4349 for (unsigned int d = 0; d < dim; ++d)
4350 for (unsigned int e = 0; e < dim; ++e)
4351 {
4352 tmp[d][e] = inv_t_jac[d][0] * gradients[e * nqp_d + 0];
4353 for (unsigned int f = 1; f < dim; ++f)
4354 tmp[d][e] += inv_t_jac[d][f] * gradients[e * nqp_d + f];
4355 }
4356 for (unsigned int comp = 0; comp < n_components; ++comp)
4357 for (unsigned int d = 0; d < dim; ++d)
4358 {
4359 VectorizedArrayType res = jac[comp][0] * tmp[d][0];
4360 for (unsigned int f = 1; f < dim; ++f)
4361 res += jac[comp][f] * tmp[d][f];
4362
4363 grad_out[comp][d] = res * inv_det;
4364 }
4365 }
4366 else
4367 {
4368 // General cell
4369
4370 // This assert could be removed if we make sure that this is
4371 // updated even though update_hessians or update_jacobian_grads is
4372 // not passed, i.e make the necessary changes in
4373 // MatrixFreeFunctions::MappingInfoStorage::compute_update_flags
4374 Assert(this->jacobian_gradients_non_inverse != nullptr,
4376 "update_hessians"));
4377
4378 const auto jac_grad =
4379 this->jacobian_gradients_non_inverse[q_point];
4380 const Tensor<2, dim, VectorizedArrayType> inv_t_jac =
4381 this->jacobian[q_point];
4382
4383 // Derivatives are reordered for faces. Need to take this into
4384 // account
4385 const VectorizedArrayType inv_det =
4386 (is_face && dim == 2 && this->get_face_no() < 2) ?
4387 -determinant(inv_t_jac) :
4388 determinant(inv_t_jac);
4390 invert(inv_t_jac);
4391
4392 // (J * grad_quad) * J^-1 * det(J^-1), part in braces
4393 VectorizedArrayType tmp[dim][dim];
4394 for (unsigned int d = 0; d < dim; ++d)
4395 for (unsigned int e = 0; e < dim; ++e)
4396 {
4397 tmp[e][d] = t_jac[0][d] * gradients[0 * nqp_d + e];
4398 for (unsigned int f = 1; f < dim; ++f)
4399 tmp[e][d] += t_jac[f][d] * gradients[f * nqp_d + e];
4400 }
4401
4402 // Add (jac_grad * values) * J^{-1} * det(J^{-1}), combine terms
4403 // outside braces with gradient part from above
4404 for (unsigned int d = 0; d < dim; ++d)
4405 {
4406 for (unsigned int e = 0; e < dim; ++e)
4407 tmp[e][d] +=
4408 jac_grad[e][d] *
4409 this->values_from_gradients_quad[e * nqp + q_point];
4410 for (unsigned int f = 0, r = dim; f < dim; ++f)
4411 for (unsigned int k = f + 1; k < dim; ++k, ++r)
4412 {
4413 tmp[k][d] +=
4414 jac_grad[r][d] *
4415 this->values_from_gradients_quad[f * nqp + q_point];
4416 tmp[f][d] +=
4417 jac_grad[r][d] *
4418 this->values_from_gradients_quad[k * nqp + q_point];
4419 }
4420 }
4421
4422 // Apply J^{-1} appearing in both terms outside braces above
4423 for (unsigned int d = 0; d < dim; ++d)
4424 for (unsigned int e = 0; e < dim; ++e)
4425 {
4426 VectorizedArrayType res = tmp[0][d] * inv_t_jac[e][0];
4427 for (unsigned int f = 1; f < dim; ++f)
4428 res += tmp[f][d] * inv_t_jac[e][f];
4429 grad_out[d][e] = res;
4430 }
4431
4432 // Add -(J^{-T} * jac_grad * J^{-1} * J * values * det(J^{-1})),
4433 // which can be expressed as a rank-1 update tmp[d] * tmp4[e],
4434 // where tmp = J * values and tmp4 = (J^{-T} * jac_grad * J^{-1})
4435 VectorizedArrayType tmp3[dim], tmp4[dim];
4436 for (unsigned int d = 0; d < dim; ++d)
4437 {
4438 tmp3[d] = inv_t_jac[0][d] * jac_grad[d][0];
4439 for (unsigned int e = 1; e < dim; ++e)
4440 tmp3[d] += inv_t_jac[e][d] * jac_grad[d][e];
4441 }
4442 for (unsigned int e = 0, k = dim; e < dim; ++e)
4443 for (unsigned int f = e + 1; f < dim; ++k, ++f)
4444 for (unsigned int d = 0; d < dim; ++d)
4445 {
4446 tmp3[f] += inv_t_jac[d][e] * jac_grad[k][d];
4447 tmp3[e] += inv_t_jac[d][f] * jac_grad[k][d];
4448 }
4449 for (unsigned int d = 0; d < dim; ++d)
4450 {
4451 tmp4[d] = tmp3[0] * inv_t_jac[d][0];
4452 for (unsigned int e = 1; e < dim; ++e)
4453 tmp4[d] += tmp3[e] * inv_t_jac[d][e];
4454 }
4455
4456 VectorizedArrayType tmp2[dim];
4457 for (unsigned int d = 0; d < dim; ++d)
4458 {
4459 tmp2[d] =
4460 t_jac[0][d] * this->values_from_gradients_quad[q_point];
4461 for (unsigned e = 1; e < dim; ++e)
4462 tmp2[d] +=
4463 t_jac[e][d] *
4464 this->values_from_gradients_quad[e * nqp + q_point];
4465 }
4466
4467 for (unsigned int d = 0; d < dim; ++d)
4468 for (unsigned int e = 0; e < dim; ++e)
4469 {
4470 grad_out[d][e] -= tmp4[e] * tmp2[d];
4471
4472 // finally multiply by det(J^{-1}) necessary in all
4473 // contributions above
4474 grad_out[d][e] *= inv_det;
4475 }
4476 }
4477 return grad_out;
4478 }
4479 }
4481
4482 // Cartesian cell
4483 if (!is_face && this->cell_type == internal::MatrixFreeFunctions::cartesian)
4484 {
4485 for (unsigned int comp = 0; comp < n_components; ++comp)
4486 for (unsigned int d = 0; d < dim; ++d)
4487 grad_out[comp][d] =
4488 this->gradients_quad[(comp * nqp + q_point) * dim + d] *
4489 this->jacobian[0][d][d];
4490 }
4491 // cell with general/affine Jacobian
4492 else
4493 {
4495 this->jacobian[this->cell_type > internal::MatrixFreeFunctions::affine ?
4496 q_point :
4497 0];
4498 for (unsigned int comp = 0; comp < n_components; ++comp)
4499 for (unsigned int d = 0; d < dim; ++d)
4500 {
4501 grad_out[comp][d] =
4502 jac[d][0] * this->gradients_quad[(comp * nqp + q_point) * dim];
4503 for (unsigned int e = 1; e < dim; ++e)
4504 grad_out[comp][d] +=
4505 jac[d][e] *
4506 this->gradients_quad[(comp * nqp + q_point) * dim + e];
4507 }
4508 }
4509 if constexpr (n_components == 1)
4510 return grad_out[0];
4511 else
4512 return grad_out;
4513}
4514
4515
4516
4517template <int dim,
4518 int n_components_,
4519 typename Number,
4520 bool is_face,
4521 typename VectorizedArrayType>
4523 typename FEEvaluationBase<dim,
4524 n_components_,
4525 Number,
4526 is_face,
4527 VectorizedArrayType>::value_type
4529 get_normal_derivative(const unsigned int q_point) const
4530{
4531 AssertIndexRange(q_point, this->n_quadrature_points);
4532 if constexpr (running_in_debug_mode())
4533 {
4534 Assert(this->gradients_quad_initialized == true,
4536 }
4537
4538 Assert(this->normal_x_jacobian != nullptr,
4540 "update_gradients"));
4541
4542 const std::size_t nqp = this->n_quadrature_points;
4544
4545 if (this->cell_type == internal::MatrixFreeFunctions::cartesian)
4546 for (unsigned int comp = 0; comp < n_components; ++comp)
4547 grad_out[comp] =
4548 this->gradients_quad[(comp * nqp + q_point) * dim + dim - 1] *
4549 (this->normal_x_jacobian[0][dim - 1]);
4550 else
4551 {
4552 const std::size_t index =
4553 this->cell_type <= internal::MatrixFreeFunctions::affine ? 0 : q_point;
4554 for (unsigned int comp = 0; comp < n_components; ++comp)
4555 {
4556 grad_out[comp] = this->gradients_quad[(comp * nqp + q_point) * dim] *
4557 this->normal_x_jacobian[index][0];
4558 for (unsigned int d = 1; d < dim; ++d)
4559 grad_out[comp] +=
4560 this->gradients_quad[(comp * nqp + q_point) * dim + d] *
4561 this->normal_x_jacobian[index][d];
4562 }
4563 }
4564 if constexpr (n_components == 1)
4565 return grad_out[0];
4566 else
4567 return grad_out;
4568}
4569
4570
4571
4572namespace internal
4573{
4574 // compute tmp = hess_unit(u) * J^T. do this manually because we do not
4575 // store the lower diagonal because of symmetry
4576 template <typename VectorizedArrayType>
4577 inline void
4578 hessian_unit_times_jac(const Tensor<2, 1, VectorizedArrayType> &jac,
4579 const VectorizedArrayType *const hessians,
4580 const unsigned int,
4581 VectorizedArrayType (&tmp)[1][1])
4582 {
4583 tmp[0][0] = jac[0][0] * hessians[0];
4584 }
4585
4586 template <typename VectorizedArrayType>
4587 inline void
4588 hessian_unit_times_jac(const Tensor<2, 2, VectorizedArrayType> &jac,
4589 const VectorizedArrayType *const hessians,
4590 const unsigned int nqp,
4591 VectorizedArrayType (&tmp)[2][2])
4592 {
4593 for (unsigned int d = 0; d < 2; ++d)
4594 {
4595 tmp[0][d] = (jac[d][0] * hessians[0] + jac[d][1] * hessians[2 * nqp]);
4596 tmp[1][d] =
4597 (jac[d][0] * hessians[2 * nqp] + jac[d][1] * hessians[1 * nqp]);
4598 }
4599 }
4600
4601 template <typename VectorizedArrayType>
4602 inline void
4603 hessian_unit_times_jac(const Tensor<2, 3, VectorizedArrayType> &jac,
4604 const VectorizedArrayType *const hessians,
4605 const unsigned int nqp,
4606 VectorizedArrayType (&tmp)[3][3])
4607 {
4608 for (unsigned int d = 0; d < 3; ++d)
4609 {
4610 tmp[0][d] =
4611 (jac[d][0] * hessians[0 * nqp] + jac[d][1] * hessians[3 * nqp] +
4612 jac[d][2] * hessians[4 * nqp]);
4613 tmp[1][d] =
4614 (jac[d][0] * hessians[3 * nqp] + jac[d][1] * hessians[1 * nqp] +
4615 jac[d][2] * hessians[5 * nqp]);
4616 tmp[2][d] =
4617 (jac[d][0] * hessians[4 * nqp] + jac[d][1] * hessians[5 * nqp] +
4618 jac[d][2] * hessians[2 * nqp]);
4619 }
4620 }
4621} // namespace internal
4622
4623
4624
4625template <int dim,
4626 int n_components_,
4627 typename Number,
4628 bool is_face,
4629 typename VectorizedArrayType>
4630inline typename FEEvaluationBase<dim,
4631 n_components_,
4632 Number,
4633 is_face,
4634 VectorizedArrayType>::hessian_type
4636 get_hessian(const unsigned int q_point) const
4637{
4638 if constexpr (running_in_debug_mode())
4639 {
4640 Assert(this->hessians_quad_initialized == true,
4642 }
4643 AssertIndexRange(q_point, this->n_quadrature_points);
4644
4645 Assert(this->jacobian != nullptr,
4647 "update_hessian"));
4649 this->jacobian[this->cell_type <= internal::MatrixFreeFunctions::affine ?
4650 0 :
4651 q_point];
4652
4654
4655 const std::size_t nqp = this->n_quadrature_points;
4656 constexpr unsigned int hdim = (dim * (dim + 1)) / 2;
4657
4658 // Cartesian cell
4659 if (!is_face && this->cell_type == internal::MatrixFreeFunctions::cartesian)
4660 {
4661 for (unsigned int comp = 0; comp < n_components; ++comp)
4662 {
4663 for (unsigned int d = 0; d < dim; ++d)
4664 hessian_out[comp][d][d] =
4665 this->hessians_quad[(comp * hdim + d) * nqp + q_point] *
4666 (jac[d][d] * jac[d][d]);
4667 switch (dim)
4668 {
4669 case 1:
4670 break;
4671 case 2:
4672 hessian_out[comp][0][1] =
4673 this->hessians_quad[(comp * hdim + 2) * nqp + q_point] *
4674 (jac[0][0] * jac[1][1]);
4675 break;
4676 case 3:
4677 hessian_out[comp][0][1] =
4678 this->hessians_quad[(comp * hdim + 3) * nqp + q_point] *
4679 (jac[0][0] * jac[1][1]);
4680 hessian_out[comp][0][2] =
4681 this->hessians_quad[(comp * hdim + 4) * nqp + q_point] *
4682 (jac[0][0] * jac[2][2]);
4683 hessian_out[comp][1][2] =
4684 this->hessians_quad[(comp * hdim + 5) * nqp + q_point] *
4685 (jac[1][1] * jac[2][2]);
4686 break;
4687 default:
4689 }
4690 for (unsigned int d = 0; d < dim; ++d)
4691 for (unsigned int e = d + 1; e < dim; ++e)
4692 hessian_out[comp][e][d] = hessian_out[comp][d][e];
4693 }
4694 }
4695 // cell with general Jacobian, but constant within the cell
4696 else if (this->cell_type <= internal::MatrixFreeFunctions::affine)
4697 {
4698 for (unsigned int comp = 0; comp < n_components; ++comp)
4699 {
4700 VectorizedArrayType tmp[dim][dim];
4701 internal::hessian_unit_times_jac(
4702 jac, this->hessians_quad + comp * hdim * nqp + q_point, nqp, tmp);
4703
4704 // compute first part of hessian, J * tmp = J * hess_unit(u) * J^T
4705 for (unsigned int d = 0; d < dim; ++d)
4706 for (unsigned int e = d; e < dim; ++e)
4707 {
4708 hessian_out[comp][d][e] = jac[d][0] * tmp[0][e];
4709 for (unsigned int f = 1; f < dim; ++f)
4710 hessian_out[comp][d][e] += jac[d][f] * tmp[f][e];
4711 }
4712
4713 // no J' * grad(u) part here because the Jacobian is constant
4714 // throughout the cell and hence, its derivative is zero
4715
4716 // take symmetric part
4717 for (unsigned int d = 0; d < dim; ++d)
4718 for (unsigned int e = d + 1; e < dim; ++e)
4719 hessian_out[comp][e][d] = hessian_out[comp][d][e];
4720 }
4721 }
4722 // cell with general Jacobian
4723 else
4724 {
4725 const auto &jac_grad = this->jacobian_gradients[q_point];
4726 for (unsigned int comp = 0; comp < n_components; ++comp)
4727 {
4728 VectorizedArrayType tmp[dim][dim];
4729 internal::hessian_unit_times_jac(
4730 jac, this->hessians_quad + comp * hdim * nqp + q_point, nqp, tmp);
4731
4732 // compute first part of hessian, J * tmp = J * hess_unit(u) * J^T
4733 for (unsigned int d = 0; d < dim; ++d)
4734 for (unsigned int e = d; e < dim; ++e)
4735 {
4736 hessian_out[comp][d][e] = jac[d][0] * tmp[0][e];
4737 for (unsigned int f = 1; f < dim; ++f)
4738 hessian_out[comp][d][e] += jac[d][f] * tmp[f][e];
4739 }
4740
4741 // add diagonal part of J' * grad(u)
4742 for (unsigned int d = 0; d < dim; ++d)
4743 for (unsigned int e = 0; e < dim; ++e)
4744 hessian_out[comp][d][d] +=
4745 jac_grad[d][e] *
4746 this->gradients_quad[(comp * nqp + q_point) * dim + e];
4747
4748 // add off-diagonal part of J' * grad(u)
4749 for (unsigned int d = 0, count = dim; d < dim; ++d)
4750 for (unsigned int e = d + 1; e < dim; ++e, ++count)
4751 for (unsigned int f = 0; f < dim; ++f)
4752 hessian_out[comp][d][e] +=
4753 jac_grad[count][f] *
4754 this->gradients_quad[(comp * nqp + q_point) * dim + f];
4755
4756 // take symmetric part
4757 for (unsigned int d = 0; d < dim; ++d)
4758 for (unsigned int e = d + 1; e < dim; ++e)
4759 hessian_out[comp][e][d] = hessian_out[comp][d][e];
4760 }
4761 }
4762 if constexpr (n_components == 1)
4763 return hessian_out[0];
4764 else
4765 return hessian_out;
4766}
4767
4768
4769
4770template <int dim,
4771 int n_components_,
4772 typename Number,
4773 bool is_face,
4774 typename VectorizedArrayType>
4775inline typename FEEvaluationBase<dim,
4776 n_components_,
4777 Number,
4778 is_face,
4779 VectorizedArrayType>::gradient_type
4781 get_hessian_diagonal(const unsigned int q_point) const
4782{
4783 Assert(!is_face, ExcNotImplemented());
4784 if constexpr (running_in_debug_mode())
4785 {
4786 Assert(this->hessians_quad_initialized == true,
4788 }
4789 AssertIndexRange(q_point, this->n_quadrature_points);
4790
4791 Assert(this->jacobian != nullptr, ExcNotImplemented());
4793 this->jacobian[this->cell_type <= internal::MatrixFreeFunctions::affine ?
4794 0 :
4795 q_point];
4796
4797 const std::size_t nqp = this->n_quadrature_points;
4798 constexpr unsigned int hdim = (dim * (dim + 1)) / 2;
4800
4801 // Cartesian cell
4802 if (this->cell_type == internal::MatrixFreeFunctions::cartesian)
4803 {
4804 for (unsigned int comp = 0; comp < n_components; ++comp)
4805 for (unsigned int d = 0; d < dim; ++d)
4806 hessian_out[comp][d] =
4807 this->hessians_quad[(comp * hdim + d) * nqp + q_point] *
4808 (jac[d][d] * jac[d][d]);
4809 }
4810 // cell with general Jacobian, but constant within the cell
4811 else if (this->cell_type == internal::MatrixFreeFunctions::affine)
4812 {
4813 for (unsigned int comp = 0; comp < n_components; ++comp)
4814 {
4815 // compute laplacian before the gradient because it needs to access
4816 // unscaled gradient data
4817 VectorizedArrayType tmp[dim][dim];
4818 internal::hessian_unit_times_jac(
4819 jac, this->hessians_quad + comp * hdim * nqp + q_point, nqp, tmp);
4820
4821 // compute only the trace part of hessian, J * tmp = J *
4822 // hess_unit(u) * J^T
4823 for (unsigned int d = 0; d < dim; ++d)
4824 {
4825 hessian_out[comp][d] = jac[d][0] * tmp[0][d];
4826 for (unsigned int f = 1; f < dim; ++f)
4827 hessian_out[comp][d] += jac[d][f] * tmp[f][d];
4828 }
4829 }
4830 }
4831 // cell with general Jacobian
4832 else
4833 {
4834 const auto &jac_grad = this->jacobian_gradients[q_point];
4835 for (unsigned int comp = 0; comp < n_components; ++comp)
4836 {
4837 // compute laplacian before the gradient because it needs to access
4838 // unscaled gradient data
4839 VectorizedArrayType tmp[dim][dim];
4840 internal::hessian_unit_times_jac(
4841 jac, this->hessians_quad + comp * hdim * nqp + q_point, nqp, tmp);
4842
4843 // compute only the trace part of hessian, J * tmp = J *
4844 // hess_unit(u) * J^T
4845 for (unsigned int d = 0; d < dim; ++d)
4846 {
4847 hessian_out[comp][d] = jac[d][0] * tmp[0][d];
4848 for (unsigned int f = 1; f < dim; ++f)
4849 hessian_out[comp][d] += jac[d][f] * tmp[f][d];
4850 }
4851
4852 for (unsigned int d = 0; d < dim; ++d)
4853 for (unsigned int e = 0; e < dim; ++e)
4854 hessian_out[comp][d] +=
4855 jac_grad[d][e] *
4856 this->gradients_quad[(comp * nqp + q_point) * dim + e];
4857 }
4858 }
4859
4860 if constexpr (n_components == 1)
4861 return hessian_out[0];
4862 else
4863 return hessian_out;
4864}
4865
4866
4867
4868template <int dim,
4869 int n_components_,
4870 typename Number,
4871 bool is_face,
4872 typename VectorizedArrayType>
4873inline typename FEEvaluationBase<dim,
4874 n_components_,
4875 Number,
4876 is_face,
4877 VectorizedArrayType>::value_type
4879 get_laplacian(const unsigned int q_point) const
4880{
4881 Assert(is_face == false, ExcNotImplemented());
4882 if constexpr (running_in_debug_mode())
4883 {
4884 Assert(this->hessians_quad_initialized == true,
4886 }
4887 AssertIndexRange(q_point, this->n_quadrature_points);
4888
4889 const gradient_type hess_diag = get_hessian_diagonal(q_point);
4890 if constexpr (n_components == 1)
4891 {
4892 VectorizedArrayType sum = hess_diag[0];
4893 for (unsigned int d = 1; d < dim; ++d)
4894 sum += hess_diag[d];
4895 return sum;
4896 }
4897 else
4898 {
4900 for (unsigned int comp = 0; comp < n_components; ++comp)
4901 {
4902 laplacian_out[comp] = hess_diag[comp][0];
4903 for (unsigned int d = 1; d < dim; ++d)
4904 laplacian_out[comp] += hess_diag[comp][d];
4905 }
4906 return laplacian_out;
4907 }
4908}
4909
4910
4911
4912template <int dim,
4913 int n_components_,
4914 typename Number,
4915 bool is_face,
4916 typename VectorizedArrayType>
4917inline typename FEEvaluationBase<dim,
4918 n_components_,
4919 Number,
4920 is_face,
4921 VectorizedArrayType>::value_type
4923 get_normal_hessian(const unsigned int q_point) const
4924{
4925 if constexpr (running_in_debug_mode())
4926 {
4927 Assert(this->hessians_quad_initialized == true,
4929 }
4930 AssertIndexRange(q_point, this->n_quadrature_points);
4931
4932 Assert(this->normal_x_jacobian != nullptr,
4934 "update_hessians"));
4935
4937
4938 const std::size_t nqp = this->n_quadrature_points;
4939 constexpr unsigned int hdim = (dim * (dim + 1)) / 2;
4940
4941 if (this->cell_type <= internal::MatrixFreeFunctions::affine)
4942 {
4943 const auto nxj = this->normal_x_jacobian[0];
4944
4945 for (unsigned int comp = 0; comp < n_components; ++comp)
4946 {
4947 for (unsigned int d = 0; d < dim; ++d)
4948 hessian_out[comp] +=
4949 this->hessians_quad[(comp * hdim + d) * nqp + q_point] *
4950 (nxj[d]) * (nxj[d]);
4951
4952 switch (dim)
4953 {
4954 case 1:
4955 break;
4956 case 2:
4957 hessian_out[comp] +=
4958 this->hessians_quad[(comp * hdim + 2) * nqp + q_point] *
4959 (nxj[0] * nxj[1]);
4960 break;
4961 case 3:
4962 hessian_out[comp] +=
4963 2. * this->hessians_quad[(comp * hdim + 3) * nqp + q_point] *
4964 (nxj[0] * nxj[1]);
4965 hessian_out[comp] +=
4966 2. * this->hessians_quad[(comp * hdim + 4) * nqp + q_point] *
4967 (nxj[0] * nxj[2]);
4968 hessian_out[comp] +=
4969 2. * this->hessians_quad[(comp * hdim + 5) * nqp + q_point] *
4970 (nxj[1] * nxj[2]);
4971 break;
4972 default:
4974 }
4975 }
4976 }
4977 // cell with general Jacobian
4978 else
4979 {
4980 const auto normal = this->normal_vector(q_point);
4981 const auto hessian = get_hessian(q_point);
4982
4983 if constexpr (n_components == 1)
4984 hessian_out[0] = hessian * normal * normal;
4985 else
4986 for (unsigned int comp = 0; comp < n_components; ++comp)
4987 hessian_out[comp] = hessian[comp] * normal * normal;
4988 }
4989 if constexpr (n_components == 1)
4990 return hessian_out[0];
4991 else
4992 return hessian_out;
4993}
4994
4995
4996
4997template <int dim,
4998 int n_components_,
4999 typename Number,
5000 bool is_face,
5001 typename VectorizedArrayType>
5002inline DEAL_II_ALWAYS_INLINE void
5004 submit_dof_value(const value_type val_in, const unsigned int dof)
5005{
5006 if constexpr (running_in_debug_mode())
5007 {
5008 this->dof_values_initialized = true;
5009 }
5010 const std::size_t dofs = this->data->dofs_per_component_on_cell;
5011 AssertIndexRange(dof, this->data->dofs_per_component_on_cell);
5012 for (unsigned int comp = 0; comp < n_components; ++comp)
5013 if constexpr (n_components == 1)
5014 this->values_dofs[comp * dofs + dof] = val_in;
5015 else
5016 this->values_dofs[comp * dofs + dof] = val_in[comp];
5017}
5018
5019
5020
5021template <int dim,
5022 int n_components_,
5023 typename Number,
5024 bool is_face,
5025 typename VectorizedArrayType>
5026inline DEAL_II_ALWAYS_INLINE void
5028 submit_value(const value_type val_in, const unsigned int q_point)
5029{
5030 if constexpr (running_in_debug_mode())
5031 {
5032 Assert(this->is_reinitialized, ExcNotInitialized());
5033 }
5034 AssertIndexRange(q_point, this->n_quadrature_points);
5035 Assert(this->J_value != nullptr,
5037 "update_values"));
5038 if constexpr (running_in_debug_mode())
5039 {
5040 this->values_quad_submitted = true;
5041 }
5042
5043 const std::size_t nqp = this->n_quadrature_points;
5044 VectorizedArrayType *values = this->values_quad + q_point;
5045
5046 const VectorizedArrayType JxW =
5047 this->cell_type <= internal::MatrixFreeFunctions::affine ?
5048 this->J_value[0] * this->quadrature_weights[q_point] :
5049 this->J_value[q_point];
5050 if constexpr (n_components == 1)
5051 values[0] = val_in * JxW;
5052 else
5053 {
5054 if (n_components == dim &&
5055 this->data->element_type ==
5057 {
5058 // Piola transform is required
5059 AssertIndexRange(q_point, this->n_quadrature_points);
5060 Assert(this->J_value != nullptr,
5062 "update_value"));
5063 if constexpr (running_in_debug_mode())
5064 {
5065 Assert(this->is_reinitialized, ExcNotInitialized());
5066 this->values_quad_submitted = true;
5067 }
5068
5069 VectorizedArrayType *values = this->values_quad + q_point;
5070 const std::size_t nqp = this->n_quadrature_points;
5071
5072 if (!is_face &&
5074 {
5075 const Tensor<2, dim, VectorizedArrayType> jac = this->jacobian[1];
5076 const VectorizedArrayType weight =
5077 this->quadrature_weights[q_point];
5078
5079 for (unsigned int comp = 0; comp < n_components; ++comp)
5080 values[comp * nqp] = val_in[comp] * weight * jac[comp][comp];
5081 }
5082 else
5083 {
5084 // Affine or general cell
5085 const Tensor<2, dim, VectorizedArrayType> inv_t_jac =
5086 (this->cell_type > internal::MatrixFreeFunctions::affine) ?
5087 this->jacobian[q_point] :
5088 this->jacobian[0];
5089
5090 // Derivatives are reordered for faces. Need to take this into
5091 // account and 1/inv_det != J_value for faces
5092 const VectorizedArrayType fac =
5093 (!is_face) ?
5094 this->quadrature_weights[q_point] :
5095 (((this->cell_type > internal::MatrixFreeFunctions::affine) ?
5096 this->J_value[q_point] :
5097 this->J_value[0] * this->quadrature_weights[q_point]) *
5098 ((dim == 2 && this->get_face_no() < 2) ?
5099 -determinant(inv_t_jac) :
5100 determinant(inv_t_jac)));
5102 (this->cell_type > internal::MatrixFreeFunctions::affine) ?
5103 transpose(invert(inv_t_jac)) :
5104 this->jacobian[1];
5105
5106 // J^T * u * factor
5107 for (unsigned int comp = 0; comp < n_components; ++comp)
5108 {
5109 values[comp * nqp] = val_in[0] * jac[0][comp];
5110 for (unsigned int e = 1; e < dim; ++e)
5111 values[comp * nqp] += val_in[e] * jac[e][comp];
5112 values[comp * nqp] *= fac;
5113 }
5114 }
5115 }
5116 else if (n_components == dim &&
5117 this->data->element_type ==
5119 {
5120 // Piola transform is required
5121 AssertIndexRange(q_point, this->n_quadrature_points);
5122 Assert(this->J_value != nullptr,
5124 "update_value"));
5125 if constexpr (running_in_debug_mode())
5126 {
5127 Assert(this->is_reinitialized, ExcNotInitialized());
5128 this->values_quad_submitted = true;
5129 }
5130
5131 VectorizedArrayType *values = this->values_quad + q_point;
5132 const std::size_t nqp = this->n_quadrature_points;
5133
5134 if (!is_face &&
5136 {
5137 const Tensor<2, dim, VectorizedArrayType> inv_t_jac =
5138 this->jacobian[0];
5139 const VectorizedArrayType det_jac =
5140 (dim == 2) ? this->jacobian[1][0][0] * this->jacobian[1][1][1] :
5141 this->jacobian[1][0][0] * this->jacobian[1][1][1] *
5142 this->jacobian[1][2][2];
5143
5144 const VectorizedArrayType weight =
5145 this->quadrature_weights[q_point];
5146
5147 // J^{-1} * u * det(J) * weight
5148 for (unsigned int comp = 0; comp < n_components; ++comp)
5149 values[comp * nqp] =
5150 val_in[comp] * weight * inv_t_jac[comp][comp] * det_jac;
5151 }
5152 else
5153 {
5154 // Affine or general cell
5155 const Tensor<2, dim, VectorizedArrayType> inv_t_jac =
5156 (this->cell_type > internal::MatrixFreeFunctions::affine) ?
5157 this->jacobian[q_point] :
5158 this->jacobian[0];
5159
5160 const VectorizedArrayType fac =
5161 ((this->cell_type > internal::MatrixFreeFunctions::affine) ?
5162 this->J_value[q_point] :
5163 this->J_value[0] * this->quadrature_weights[q_point]);
5164
5165 // J^{-1} * u * factor
5166 for (unsigned int comp = 0; comp < n_components; ++comp)
5167 {
5168 values[comp * nqp] = val_in[0] * inv_t_jac[0][comp];
5169 for (unsigned int e = 1; e < dim; ++e)
5170 values[comp * nqp] += val_in[e] * inv_t_jac[e][comp];
5171 values[comp * nqp] *= fac;
5172 }
5173 }
5174 }
5175 else
5176 for (unsigned int comp = 0; comp < n_components; ++comp)
5177 values[comp * nqp] = val_in[comp] * JxW;
5178 }
5179}
5180
5181
5182
5183template <int dim,
5184 int n_components_,
5185 typename Number,
5186 bool is_face,
5187 typename VectorizedArrayType>
5188template <int, typename>
5189inline DEAL_II_ALWAYS_INLINE void
5192 const unsigned int q_point)
5193{
5194 static_assert(n_components == 1,
5195 "Do not try to modify the default template parameters used for"
5196 " selectively enabling this function via std::enable_if!");
5197 submit_value(val_in[0], q_point);
5198}
5199
5200
5201
5202template <int dim,
5203 int n_components_,
5204 typename Number,
5205 bool is_face,
5206 typename VectorizedArrayType>
5207inline DEAL_II_ALWAYS_INLINE void
5209 submit_gradient(const gradient_type grad_in, const unsigned int q_point)
5210{
5211 if constexpr (running_in_debug_mode())
5212 {
5213 Assert(this->is_reinitialized, ExcNotInitialized());
5214 }
5215 AssertIndexRange(q_point, this->n_quadrature_points);
5216 Assert(this->J_value != nullptr,
5218 "update_gradients"));
5219 Assert(this->jacobian != nullptr,
5221 "update_gradients"));
5222 if constexpr (running_in_debug_mode())
5223 {
5224 this->gradients_quad_submitted = true;
5225 }
5226
5227 if constexpr (dim > 1 && n_components == dim)
5228 {
5229 if (this->data->element_type ==
5231 {
5232 // Piola transform is required
5233
5234 if constexpr (running_in_debug_mode())
5235 {
5236 Assert(this->is_reinitialized, ExcNotInitialized());
5237 }
5238 AssertIndexRange(q_point, this->n_quadrature_points);
5239 Assert(this->J_value != nullptr,
5241 "update_gradients"));
5242 Assert(this->jacobian != nullptr,
5244 "update_gradients"));
5245 if constexpr (running_in_debug_mode())
5246 {
5247 this->gradients_quad_submitted = true;
5248 }
5249
5250 VectorizedArrayType *gradients = this->gradients_quad + q_point * dim;
5251 VectorizedArrayType *values =
5252 this->values_from_gradients_quad + q_point;
5253 const std::size_t nqp = this->n_quadrature_points;
5254 const std::size_t nqp_d = nqp * dim;
5255
5256 if (!is_face &&
5258 {
5259 // Cartesian cell
5260 const Tensor<2, dim, VectorizedArrayType> &inv_t_jac =
5261 this->jacobian[0];
5263 this->jacobian[1];
5264 const VectorizedArrayType weight =
5265 this->quadrature_weights[q_point];
5266 for (unsigned int d = 0; d < dim; ++d)
5267 for (unsigned int comp = 0; comp < n_components; ++comp)
5268 gradients[comp * nqp_d + d] = grad_in[comp][d] *
5269 inv_t_jac[d][d] *
5270 (jac[comp][comp] * weight);
5271 }
5272 else if (this->cell_type <= internal::MatrixFreeFunctions::affine)
5273 {
5274 // Affine cell
5275 const Tensor<2, dim, VectorizedArrayType> &inv_t_jac =
5276 this->jacobian[0];
5278 this->jacobian[1];
5279
5280 // Derivatives are reordered for faces. Need to take this into
5281 // account and 1/inv_det != J_value for faces
5282 const VectorizedArrayType fac =
5283 (!is_face) ?
5284 this->quadrature_weights[q_point] :
5285 this->J_value[0] * this->quadrature_weights[q_point] *
5286 ((dim == 2 && this->get_face_no() < 2) ?
5287 -determinant(inv_t_jac) :
5288 determinant(inv_t_jac));
5289
5290 // J_{j,i} * J^{-1}_{k,m} * grad_in_{j,m} * factor
5291 VectorizedArrayType tmp[dim][dim];
5292 for (unsigned int d = 0; d < dim; ++d)
5293 for (unsigned int e = 0; e < dim; ++e)
5294 {
5295 tmp[d][e] = inv_t_jac[0][d] * grad_in[e][0];
5296 for (unsigned int f = 1; f < dim; ++f)
5297 tmp[d][e] += inv_t_jac[f][d] * grad_in[e][f];
5298 }
5299 for (unsigned int comp = 0; comp < n_components; ++comp)
5300 for (unsigned int d = 0; d < dim; ++d)
5301 {
5302 VectorizedArrayType res = jac[0][comp] * tmp[d][0];
5303 for (unsigned int f = 1; f < dim; ++f)
5304 res += jac[f][comp] * tmp[d][f];
5305
5306 gradients[comp * nqp_d + d] = res * fac;
5307 }
5308 }
5309 else
5310 {
5311 // General cell
5312
5313 const auto jac_grad =
5314 this->jacobian_gradients_non_inverse[q_point];
5315 const Tensor<2, dim, VectorizedArrayType> inv_t_jac =
5316 this->jacobian[q_point];
5317
5318 // Derivatives are reordered for faces. Need to take this into
5319 // account and 1/inv_det != J_value for faces
5320 const VectorizedArrayType fac =
5321 (!is_face) ? this->quadrature_weights[q_point] :
5322 this->J_value[q_point] *
5323 ((dim == 2 && this->get_face_no() < 2) ?
5324 -determinant(inv_t_jac) :
5325 determinant(inv_t_jac));
5327 invert(inv_t_jac);
5328
5329 // Start evaluation for values part below to enable the compiler
5330 // to possibly re-use the same computation in get_gradient()
5331 // without interfering with stores to 'gradients'
5332 VectorizedArrayType tmp3[dim], tmp4[dim];
5333 for (unsigned int d = 0; d < dim; ++d)
5334 {
5335 tmp3[d] = inv_t_jac[0][d] * jac_grad[d][0];
5336 for (unsigned int e = 1; e < dim; ++e)
5337 tmp3[d] += inv_t_jac[e][d] * jac_grad[d][e];
5338 }
5339 for (unsigned int e = 0, k = dim; e < dim; ++e)
5340 for (unsigned int f = e + 1; f < dim; ++k, ++f)
5341 for (unsigned int d = 0; d < dim; ++d)
5342 {
5343 tmp3[f] += inv_t_jac[d][e] * jac_grad[k][d];
5344 tmp3[e] += inv_t_jac[d][f] * jac_grad[k][d];
5345 }
5346 for (unsigned int d = 0; d < dim; ++d)
5347 {
5348 tmp4[d] = tmp3[0] * inv_t_jac[d][0];
5349 for (unsigned int e = 1; e < dim; ++e)
5350 tmp4[d] += tmp3[e] * inv_t_jac[d][e];
5351 }
5352
5353 const Tensor<2, dim, VectorizedArrayType> grad_in_scaled =
5354 fac * grad_in;
5355
5356 VectorizedArrayType tmp[dim][dim];
5357
5358 // J * (J^{-1} * (grad_in * factor))
5359 for (unsigned int d = 0; d < dim; ++d)
5360 for (unsigned int e = 0; e < dim; ++e)
5361 {
5362 tmp[d][e] = inv_t_jac[0][d] * grad_in_scaled[e][0];
5363 for (unsigned int f = 1; f < dim; ++f)
5364 tmp[d][e] += inv_t_jac[f][d] * grad_in_scaled[e][f];
5365 }
5366
5367 for (unsigned int d = 0; d < dim; ++d)
5368 for (unsigned int e = 0; e < dim; ++e)
5369 {
5370 VectorizedArrayType res = t_jac[d][0] * tmp[e][0];
5371 for (unsigned int f = 1; f < dim; ++f)
5372 res += t_jac[d][f] * tmp[e][f];
5373
5374 gradients[d * nqp_d + e] = res;
5375 }
5376
5377 // jac_grad * (J^{-1} * (grad_in * factor)), re-use part in braces
5378 // as 'tmp' from above
5379 VectorizedArrayType value[dim];
5380 for (unsigned int d = 0; d < dim; ++d)
5381 {
5382 value[d] = tmp[d][0] * jac_grad[d][0];
5383 for (unsigned int e = 1; e < dim; ++e)
5384 value[d] += tmp[d][e] * jac_grad[d][e];
5385 }
5386 for (unsigned int e = 0, k = dim; e < dim; ++e)
5387 for (unsigned int f = e + 1; f < dim; ++k, ++f)
5388 for (unsigned int d = 0; d < dim; ++d)
5389 {
5390 value[e] += tmp[f][d] * jac_grad[k][d];
5391 value[f] += tmp[e][d] * jac_grad[k][d];
5392 }
5393
5394 // -(grad_in * factor) * J * (J^{-T} * jac_grad * J^{-1})
5395 // = -(grad_in * factor) * J * ( \------- tmp4 ---------/ )
5396 for (unsigned int d = 0; d < dim; ++d)
5397 {
5398 VectorizedArrayType tmp2 = grad_in_scaled[d][0] * tmp4[0];
5399 for (unsigned int e = 1; e < dim; ++e)
5400 tmp2 += grad_in_scaled[d][e] * tmp4[e];
5401 for (unsigned int e = 0; e < dim; ++e)
5402 value[e] -= t_jac[e][d] * tmp2;
5403 }
5404
5405 for (unsigned int d = 0; d < dim; ++d)
5406 values[d * nqp] = value[d];
5407 }
5408 return;
5409 }
5410 }
5411
5412 const std::size_t nqp_d = this->n_quadrature_points * dim;
5413 VectorizedArrayType *gradients = this->gradients_quad + q_point * dim;
5414
5415 if (!is_face && this->cell_type == internal::MatrixFreeFunctions::cartesian)
5416 {
5417 const VectorizedArrayType JxW =
5418 this->J_value[0] * this->quadrature_weights[q_point];
5419
5420 // Load all entries before starting to write back to make sure the
5421 // compiler sees opportunity of loads in a possibly nearby
5422 // get_gradient() function (i.e., the compiler should not think that
5423 // 'jacobian' could alias with 'gradients').
5424 std::array<VectorizedArrayType, dim> jac;
5425 for (unsigned int d = 0; d < dim; ++d)
5426 jac[d] = this->jacobian[0][d][d];
5427
5428 for (unsigned int d = 0; d < dim; ++d)
5429 {
5430 const VectorizedArrayType factor = this->jacobian[0][d][d] * JxW;
5431 if constexpr (n_components == 1)
5432 gradients[d] = grad_in[d] * factor;
5433 else
5434 for (unsigned int comp = 0; comp < n_components; ++comp)
5435 gradients[comp * nqp_d + d] = grad_in[comp][d] * factor;
5436 }
5437 }
5438 else
5439 {
5441 this->cell_type > internal::MatrixFreeFunctions::affine ?
5442 this->jacobian[q_point] :
5443 this->jacobian[0];
5444 const VectorizedArrayType JxW =
5445 this->cell_type > internal::MatrixFreeFunctions::affine ?
5446 this->J_value[q_point] :
5447 this->J_value[0] * this->quadrature_weights[q_point];
5448 if constexpr (n_components == 1)
5449 for (unsigned int d = 0; d < dim; ++d)
5450 {
5451 VectorizedArrayType new_val = jac[0][d] * grad_in[0];
5452 for (unsigned int e = 1; e < dim; ++e)
5453 new_val += (jac[e][d] * grad_in[e]);
5454 gradients[d] = new_val * JxW;
5455 }
5456 else
5457 for (unsigned int comp = 0; comp < n_components; ++comp)
5458 for (unsigned int d = 0; d < dim; ++d)
5459 {
5460 VectorizedArrayType new_val = jac[0][d] * grad_in[comp][0];
5461 for (unsigned int e = 1; e < dim; ++e)
5462 new_val += (jac[e][d] * grad_in[comp][e]);
5463 gradients[comp * nqp_d + d] = new_val * JxW;
5464 }
5465 }
5466}
5467
5468
5469
5470template <int dim,
5471 int n_components_,
5472 typename Number,
5473 bool is_face,
5474 typename VectorizedArrayType>
5475template <int, typename>
5476inline DEAL_II_ALWAYS_INLINE void
5479 const unsigned int q_point)
5480{
5481 static_assert(n_components == 1 && dim == 1,
5482 "Do not try to modify the default template parameters used for"
5483 " selectively enabling this function via std::enable_if!");
5484 submit_gradient(grad_in[0], q_point);
5485}
5486
5487
5488
5489template <int dim,
5490 int n_components_,
5491 typename Number,
5492 bool is_face,
5493 typename VectorizedArrayType>
5494inline DEAL_II_ALWAYS_INLINE void
5496 submit_normal_derivative(const value_type grad_in, const unsigned int q_point)
5497{
5498 AssertIndexRange(q_point, this->n_quadrature_points);
5499 Assert(this->normal_x_jacobian != nullptr,
5501 "update_gradients"));
5502 if constexpr (running_in_debug_mode())
5503 {
5504 this->gradients_quad_submitted = true;
5505 }
5506
5507 const std::size_t nqp_d = this->n_quadrature_points * dim;
5508 VectorizedArrayType *gradients = this->gradients_quad + q_point * dim;
5509
5510 if (this->cell_type == internal::MatrixFreeFunctions::cartesian)
5511 {
5512 const VectorizedArrayType JxW_jac = this->J_value[0] *
5513 this->quadrature_weights[q_point] *
5514 this->normal_x_jacobian[0][dim - 1];
5515 for (unsigned int comp = 0; comp < n_components; ++comp)
5516 {
5517 for (unsigned int d = 0; d < dim - 1; ++d)
5518 gradients[comp * nqp_d + d] = VectorizedArrayType();
5519 if constexpr (n_components == 1)
5520 gradients[dim - 1] = grad_in * JxW_jac;
5521 else
5522 gradients[comp * nqp_d + dim - 1] = grad_in[comp] * JxW_jac;
5523 }
5524 }
5525 else
5526 {
5527 const unsigned int index =
5528 this->cell_type <= internal::MatrixFreeFunctions::affine ? 0 : q_point;
5530 this->normal_x_jacobian[index];
5531 const VectorizedArrayType JxW =
5532 (this->cell_type <= internal::MatrixFreeFunctions::affine) ?
5533 this->J_value[index] * this->quadrature_weights[q_point] :
5534 this->J_value[index];
5535 for (unsigned int comp = 0; comp < n_components; ++comp)
5536 for (unsigned int d = 0; d < dim; ++d)
5537 if constexpr (n_components == 1)
5538 gradients[d] = (grad_in * JxW) * jac[d];
5539 else
5540 gradients[comp * nqp_d + d] = (grad_in[comp] * JxW) * jac[d];
5541 }
5542}
5543
5544
5545
5546template <int dim,
5547 int n_components_,
5548 typename Number,
5549 bool is_face,
5550 typename VectorizedArrayType>
5551inline DEAL_II_ALWAYS_INLINE void
5553 submit_hessian(const hessian_type hessian_in, const unsigned int q_point)
5554{
5555 if constexpr (running_in_debug_mode())
5556 {
5557 Assert(this->is_reinitialized, ExcNotInitialized());
5558 }
5559 AssertIndexRange(q_point, this->n_quadrature_points);
5560 Assert(this->J_value != nullptr,
5562 "update_hessians"));
5563 Assert(this->jacobian != nullptr,
5565 "update_hessians"));
5566 if constexpr (running_in_debug_mode())
5567 {
5568 this->hessians_quad_submitted = true;
5569 }
5570
5571 // compute hessian_unit = J^T * hessian_in(u) * J
5572 const std::size_t nqp = this->n_quadrature_points;
5573 constexpr unsigned int hdim = (dim * (dim + 1)) / 2;
5574 if (!is_face && this->cell_type == internal::MatrixFreeFunctions::cartesian)
5575 {
5576 const VectorizedArrayType JxW =
5577 this->J_value[0] * this->quadrature_weights[q_point];
5578
5579 // diagonal part
5580 for (unsigned int d = 0; d < dim; ++d)
5581 {
5582 const auto jac_d = this->jacobian[0][d][d];
5583 const VectorizedArrayType factor = jac_d * jac_d * JxW;
5584 for (unsigned int comp = 0; comp < n_components; ++comp)
5585 if constexpr (n_components == 1)
5586 this->hessians_quad[d * nqp + q_point] =
5587 hessian_in[d][d] * factor;
5588 else
5589 this->hessians_quad[(comp * hdim + d) * nqp + q_point] =
5590 hessian_in[comp][d][d] * factor;
5591 }
5592
5593 // off diagonal part
5594 for (unsigned int d = 1, off_dia = dim; d < dim; ++d)
5595 for (unsigned int e = 0; e < d; ++e, ++off_dia)
5596 {
5597 const auto jac_d = this->jacobian[0][d][d];
5598 const auto jac_e = this->jacobian[0][e][e];
5599 const VectorizedArrayType factor = jac_d * jac_e * JxW;
5600 for (unsigned int comp = 0; comp < n_components; ++comp)
5601 if constexpr (n_components == 1)
5602 this->hessians_quad[off_dia * nqp + q_point] =
5603 (hessian_in[d][e] + hessian_in[e][d]) * factor;
5604 else
5605 this->hessians_quad[(comp * hdim + off_dia) * nqp + q_point] =
5606 (hessian_in[comp][d][e] + hessian_in[comp][e][d]) * factor;
5607 }
5608 }
5609 // cell with general Jacobian, but constant within the cell
5610 else if (this->cell_type <= internal::MatrixFreeFunctions::affine)
5611 {
5612 const Tensor<2, dim, VectorizedArrayType> jac = this->jacobian[0];
5613 const VectorizedArrayType JxW =
5614 this->J_value[0] * this->quadrature_weights[q_point];
5615 for (unsigned int comp = 0; comp < n_components; ++comp)
5616 {
5618 if constexpr (n_components == 1)
5619 hessian_c = hessian_in;
5620 else
5621 hessian_c = hessian_in[comp];
5622
5623 // 1. tmp = hessian(u) * J
5624 VectorizedArrayType tmp[dim][dim];
5625 for (unsigned int i = 0; i < dim; ++i)
5626 for (unsigned int j = 0; j < dim; ++j)
5627 {
5628 tmp[i][j] = hessian_c[i][0] * jac[0][j];
5629 for (unsigned int k = 1; k < dim; ++k)
5630 tmp[i][j] += hessian_c[i][k] * jac[k][j];
5631 }
5632
5633 // 2. hessian_unit = J^T * tmp
5634 VectorizedArrayType tmp2[dim][dim];
5635 for (unsigned int i = 0; i < dim; ++i)
5636 for (unsigned int j = 0; j < dim; ++j)
5637 {
5638 tmp2[i][j] = jac[0][i] * tmp[0][j];
5639 for (unsigned int k = 1; k < dim; ++k)
5640 tmp2[i][j] += jac[k][i] * tmp[k][j];
5641 }
5642
5643 // diagonal part
5644 for (unsigned int d = 0; d < dim; ++d)
5645 this->hessians_quad[(comp * hdim + d) * nqp + q_point] =
5646 tmp2[d][d] * JxW;
5647
5648 // off diagonal part
5649 for (unsigned int d = 0, off_diag = dim; d < dim; ++d)
5650 for (unsigned int e = d + 1; e < dim; ++e, ++off_diag)
5651 this->hessians_quad[(comp * hdim + off_diag) * nqp + q_point] =
5652 (tmp2[d][e] + tmp2[e][d]) * JxW;
5653 }
5654 }
5655 else
5656 {
5657 const Tensor<2, dim, VectorizedArrayType> jac = this->jacobian[q_point];
5658 const VectorizedArrayType JxW = this->J_value[q_point];
5659 const auto &jac_grad = this->jacobian_gradients[q_point];
5660 for (unsigned int comp = 0; comp < n_components; ++comp)
5661 {
5663 if constexpr (n_components == 1)
5664 hessian_c = hessian_in;
5665 else
5666 hessian_c = hessian_in[comp];
5667
5668 // 1. tmp = hessian(u) * J
5669 VectorizedArrayType tmp[dim][dim];
5670 for (unsigned int i = 0; i < dim; ++i)
5671 for (unsigned int j = 0; j < dim; ++j)
5672 {
5673 tmp[i][j] = hessian_c[i][0] * jac[0][j];
5674 for (unsigned int k = 1; k < dim; ++k)
5675 tmp[i][j] += hessian_c[i][k] * jac[k][j];
5676 }
5677
5678 // 2. hessian_unit = J^T * tmp
5679 VectorizedArrayType tmp2[dim][dim];
5680 for (unsigned int i = 0; i < dim; ++i)
5681 for (unsigned int j = 0; j < dim; ++j)
5682 {
5683 tmp2[i][j] = jac[0][i] * tmp[0][j];
5684 for (unsigned int k = 1; k < dim; ++k)
5685 tmp2[i][j] += jac[k][i] * tmp[k][j];
5686 }
5687
5688 // diagonal part
5689 for (unsigned int d = 0; d < dim; ++d)
5690 this->hessians_quad[(comp * hdim + d) * nqp + q_point] =
5691 tmp2[d][d] * JxW;
5692
5693 // off diagonal part
5694 for (unsigned int d = 0, off_diag = dim; d < dim; ++d)
5695 for (unsigned int e = d + 1; e < dim; ++e, ++off_diag)
5696 this->hessians_quad[(comp * hdim + off_diag) * nqp + q_point] =
5697 (tmp2[d][e] + tmp2[e][d]) * JxW;
5698
5699 // 3. gradient_unit = J' * hessian
5700 for (unsigned int d = 0; d < dim; ++d)
5701 {
5702 VectorizedArrayType sum = 0;
5703 for (unsigned int e = 0; e < dim; ++e)
5704 sum += hessian_c[e][e] * jac_grad[e][d];
5705 for (unsigned int e = 0, count = dim; e < dim; ++e)
5706 for (unsigned int f = e + 1; f < dim; ++f, ++count)
5707 sum +=
5708 (hessian_c[e][f] + hessian_c[f][e]) * jac_grad[count][d];
5709 this->gradients_from_hessians_quad[(comp * nqp + q_point) * dim +
5710 d] = sum * JxW;
5711 }
5712 }
5713 }
5714}
5715
5716
5717
5718template <int dim,
5719 int n_components_,
5720 typename Number,
5721 bool is_face,
5722 typename VectorizedArrayType>
5723inline DEAL_II_ALWAYS_INLINE void
5725 submit_normal_hessian(const value_type normal_hessian_in,
5726 const unsigned int q_point)
5727{
5728 if constexpr (running_in_debug_mode())
5729 {
5730 Assert(this->is_reinitialized, ExcNotInitialized());
5731 }
5732 AssertIndexRange(q_point, this->n_quadrature_points);
5733 Assert(this->J_value != nullptr,
5735 "update_hessians"));
5736 Assert(this->jacobian != nullptr,
5738 "update_hessians"));
5739 if constexpr (running_in_debug_mode())
5740 {
5741 this->hessians_quad_submitted = true;
5742 }
5743
5744 // compute hessian_unit = J^T * hessian_in(u) * J
5745 const std::size_t nqp = this->n_quadrature_points;
5746 constexpr unsigned int hdim = (dim * (dim + 1)) / 2;
5747 if (this->cell_type <= internal::MatrixFreeFunctions::affine)
5748 {
5749 const VectorizedArrayType JxW =
5750 this->J_value[0] * this->quadrature_weights[q_point];
5751
5752 const auto nxj = this->normal_x_jacobian[0];
5753
5754 // diagonal part
5755 for (unsigned int d = 0; d < dim; ++d)
5756 {
5757 const auto nxj_d = nxj[d];
5758 const VectorizedArrayType factor = nxj_d * nxj_d * JxW;
5759 for (unsigned int comp = 0; comp < n_components; ++comp)
5760 if constexpr (n_components == 1)
5761 this->hessians_quad[d * nqp + q_point] =
5762 normal_hessian_in * factor;
5763 else
5764 this->hessians_quad[(comp * hdim + d) * nqp + q_point] =
5765 normal_hessian_in[comp] * factor;
5766 }
5767
5768 // off diagonal part
5769 for (unsigned int d = 1, off_dia = dim; d < dim; ++d)
5770 for (unsigned int e = 0; e < d; ++e, ++off_dia)
5771 {
5772 const auto jac_d = nxj[d];
5773 const auto jac_e = nxj[e];
5774 const VectorizedArrayType factor = jac_d * jac_e * JxW;
5775 for (unsigned int comp = 0; comp < n_components; ++comp)
5776 if constexpr (n_components == 1)
5777 this->hessians_quad[off_dia * nqp + q_point] =
5778 2. * normal_hessian_in * factor;
5779 else
5780 this->hessians_quad[(comp * hdim + off_dia) * nqp + q_point] =
5781 2. * normal_hessian_in[comp] * factor;
5782 }
5783 }
5784 else
5785 {
5786 const auto normal = this->normal_vector(q_point);
5787 const auto normal_projector = outer_product(normal, normal);
5788 if constexpr (n_components == 1)
5789 submit_hessian(normal_hessian_in * normal_projector, q_point);
5790 else
5791 {
5792 hessian_type tmp;
5793 for (unsigned int comp = 0; comp < n_components; ++comp)
5794 tmp[comp] = normal_hessian_in[comp] * normal_projector;
5795 submit_hessian(tmp, q_point);
5796 }
5797 }
5798}
5799
5800
5801
5802template <int dim,
5803 int n_components_,
5804 typename Number,
5805 bool is_face,
5806 typename VectorizedArrayType>
5807inline typename FEEvaluationBase<dim,
5808 n_components_,
5809 Number,
5810 is_face,
5811 VectorizedArrayType>::value_type
5813 integrate_value() const
5814{
5815 if constexpr (running_in_debug_mode())
5816 {
5817 Assert(this->is_reinitialized, ExcNotInitialized());
5818 Assert(this->values_quad_submitted == true,
5820 }
5821
5823 const std::size_t nqp = this->n_quadrature_points;
5824 for (unsigned int q = 0; q < nqp; ++q)
5825 for (unsigned int comp = 0; comp < n_components; ++comp)
5826 return_value[comp] += this->values_quad[comp * nqp + q];
5827 if constexpr (n_components == 1)
5828 return return_value[0];
5829 else
5830 return return_value;
5831}
5832
5833
5834
5835template <int dim,
5836 int n_components_,
5837 typename Number,
5838 bool is_face,
5839 typename VectorizedArrayType>
5840template <int, typename>
5841inline DEAL_II_ALWAYS_INLINE VectorizedArrayType
5843 get_divergence(const unsigned int q_point) const
5844{
5845 static_assert(n_components == dim,
5846 "Do not try to modify the default template parameters used for"
5847 " selectively enabling this function via std::enable_if!");
5848
5849 if constexpr (running_in_debug_mode())
5850 {
5851 Assert(this->gradients_quad_initialized == true,
5853 }
5854 AssertIndexRange(q_point, this->n_quadrature_points);
5855 Assert(this->jacobian != nullptr,
5857 "update_gradients"));
5858
5859 VectorizedArrayType divergence;
5860 const std::size_t nqp = this->n_quadrature_points;
5861
5862 if (dim > 1 &&
5863 this->data->element_type ==
5865 {
5866 VectorizedArrayType inv_det =
5867 (!is_face &&
5868 this->cell_type == internal::MatrixFreeFunctions::cartesian) ?
5869 this->jacobian[0][0][0] *
5870 ((dim == 2) ? this->jacobian[0][1][1] :
5871 this->jacobian[0][1][1] * this->jacobian[0][2][2]) :
5872 determinant(this->jacobian[this->cell_type >
5873 internal::MatrixFreeFunctions::affine ?
5874 q_point :
5875 0]);
5876
5877 // on faces in 2d, the determinant has the wrong sign due to ordering of
5878 // derivatives
5879 if (is_face && dim == 2 && this->get_face_no() < 2)
5880 inv_det = -inv_det;
5881
5882 // div * det(J^-1)
5883 divergence = this->gradients_quad[q_point * dim];
5884 for (unsigned int d = 1; d < dim; ++d)
5885 divergence += this->gradients_quad[(d * nqp + q_point) * dim + d];
5886 divergence *= inv_det;
5887 }
5888 else
5889 {
5890 if (!is_face &&
5892 {
5893 // Cartesian cell
5894 divergence =
5895 this->gradients_quad[q_point * dim] * this->jacobian[0][0][0];
5896 for (unsigned int d = 1; d < dim; ++d)
5897 divergence += this->gradients_quad[(d * nqp + q_point) * dim + d] *
5898 this->jacobian[0][d][d];
5899 }
5900 else
5901 {
5902 // cell with general/constant Jacobian
5904 this->cell_type == internal::MatrixFreeFunctions::general ?
5905 this->jacobian[q_point] :
5906 this->jacobian[0];
5907 divergence = jac[0][0] * this->gradients_quad[q_point * dim];
5908 for (unsigned int e = 1; e < dim; ++e)
5909 divergence += jac[0][e] * this->gradients_quad[q_point * dim + e];
5910 for (unsigned int d = 1; d < dim; ++d)
5911 for (unsigned int e = 0; e < dim; ++e)
5912 divergence +=
5913 jac[d][e] * this->gradients_quad[(d * nqp + q_point) * dim + e];
5914 }
5915 }
5916 return divergence;
5917}
5918
5919
5920
5921template <int dim,
5922 int n_components_,
5923 typename Number,
5924 bool is_face,
5925 typename VectorizedArrayType>
5926template <int, typename>
5929 get_symmetric_gradient(const unsigned int q_point) const
5930{
5931 static_assert(n_components == dim,
5932 "Do not try to modify the default template parameters used for"
5933 " selectively enabling this function via std::enable_if!");
5934
5935 // copy from generic function into dim-specialization function
5936 const auto grad = get_gradient(q_point);
5937 VectorizedArrayType symmetrized[(dim * dim + dim) / 2];
5938 VectorizedArrayType half = Number(0.5);
5939 for (unsigned int d = 0; d < dim; ++d)
5940 symmetrized[d] = grad[d][d];
5941 switch (dim)
5942 {
5943 case 1:
5944 break;
5945 case 2:
5946 symmetrized[2] = grad[0][1] + grad[1][0];
5947 symmetrized[2] *= half;
5948 break;
5949 case 3:
5950 symmetrized[3] = grad[0][1] + grad[1][0];
5951 symmetrized[3] *= half;
5952 symmetrized[4] = grad[0][2] + grad[2][0];
5953 symmetrized[4] *= half;
5954 symmetrized[5] = grad[1][2] + grad[2][1];
5955 symmetrized[5] *= half;
5956 break;
5957 default:
5959 }
5961}
5962
5963
5964
5965template <int dim,
5966 int n_components_,
5967 typename Number,
5968 bool is_face,
5969 typename VectorizedArrayType>
5970template <int, typename>
5972 typename FEEvaluationBase<dim,
5973 n_components_,
5974 Number,
5975 is_face,
5976 VectorizedArrayType>::curl_type
5978 get_curl(const unsigned int q_point) const
5979{
5980 static_assert(dim > 1 && n_components == dim,
5981 "Do not try to modify the default template parameters used for"
5982 " selectively enabling this function via std::enable_if!");
5983
5984 if (dim > 1 && this->data->element_type ==
5986 {
5987 // Piola transformation required: Since the transformation for Nedelec
5988 // is constructed to give a curl based on a scaled version of the
5989 // reference curl, this function turns out to be particularly simple.
5990 if constexpr (running_in_debug_mode())
5991 {
5992 Assert(this->gradients_quad_initialized == true,
5994 }
5995 AssertIndexRange(q_point, this->n_quadrature_points);
5996 Assert(this->jacobian != nullptr,
5998 "update_gradients"));
5999 curl_type curl;
6000 const std::size_t nqp = this->n_quadrature_points;
6001 const std::size_t nqp_d = nqp * dim;
6002 const VectorizedArrayType *gradients =
6003 this->gradients_quad + q_point * dim;
6004 if constexpr (dim == 2)
6005 curl = gradients[1 * nqp_d + 0] - gradients[0 * nqp_d + 1];
6006 else if constexpr (dim == 3)
6007 {
6008 curl[0] = gradients[2 * nqp_d + 1] - gradients[1 * nqp_d + 2];
6009 curl[1] = gradients[0 * nqp_d + 2] - gradients[2 * nqp_d + 0];
6010 curl[2] = gradients[1 * nqp_d + 0] - gradients[0 * nqp_d + 1];
6011 }
6012 else
6014
6015 if (!is_face &&
6017 {
6018 VectorizedArrayType inv_det =
6019 this->jacobian[0][0][0] *
6020 ((dim == 2) ? this->jacobian[0][1][1] :
6021 this->jacobian[0][1][1] * this->jacobian[0][2][2]);
6022
6023 const Tensor<2, dim, VectorizedArrayType> jac = this->jacobian[1];
6024
6025 // J * curl * det(J^-1)
6026 if constexpr (dim == 2)
6027 curl *= inv_det;
6028 else
6029 for (unsigned int d = 0; d < (dim == 2 ? 1 : dim); ++d)
6030 curl[d] *= jac[d][d] * inv_det;
6031 }
6032 else
6033 {
6034 // Cell with general/constant Jacobian.
6035 const Tensor<2, dim, VectorizedArrayType> inv_t_jac =
6036 (this->cell_type > internal::MatrixFreeFunctions::affine) ?
6037 this->jacobian[q_point] :
6038 this->jacobian[0];
6040 (this->cell_type > internal::MatrixFreeFunctions::affine) ?
6041 transpose(invert(inv_t_jac)) :
6042 this->jacobian[1];
6043
6044 VectorizedArrayType inv_det = determinant(inv_t_jac);
6045
6046 // on faces in 2d, the determinant has the wrong sign due to ordering
6047 // of derivatives
6048 if (is_face && dim == 2 && this->get_face_no() < 2)
6049 inv_det = -inv_det;
6050
6051 // J * curl * det(J^-1)
6052 // In case of 2D its just a scaling with det(J^-1)
6053 if constexpr (dim == 2)
6054 curl *= inv_det;
6055 else
6056 {
6058 for (unsigned int comp = 0; comp < dim; ++comp)
6059 {
6060 curl_temp[comp] = curl[0] * jac[comp][0];
6061 for (unsigned int e = 1; e < dim; ++e)
6062 curl_temp[comp] += jac[comp][e] * curl[e];
6063 }
6064 for (unsigned int comp = 0; comp < dim; ++comp)
6065 curl[comp] = curl_temp[comp] * inv_det;
6066 }
6067 }
6068 return curl;
6069 }
6070
6071 // copy from generic function into dim-specialization function
6072 const Tensor<2, dim, VectorizedArrayType> grad = get_gradient(q_point);
6073 curl_type curl;
6074 if constexpr (dim == 2)
6075 curl = grad[1][0] - grad[0][1];
6076 else if constexpr (dim == 3)
6077 {
6078 curl[0] = grad[2][1] - grad[1][2];
6079 curl[1] = grad[0][2] - grad[2][0];
6080 curl[2] = grad[1][0] - grad[0][1];
6081 }
6082 else
6084
6085 return curl;
6086}
6087
6088
6089
6090template <int dim,
6091 int n_components_,
6092 typename Number,
6093 bool is_face,
6094 typename VectorizedArrayType>
6095template <int, typename>
6096inline DEAL_II_ALWAYS_INLINE void
6098 submit_divergence(const VectorizedArrayType div_in,
6099 const unsigned int q_point)
6100{
6101 static_assert(n_components == dim,
6102 "Do not try to modify the default template parameters used for"
6103 " selectively enabling this function via std::enable_if!");
6104
6105 if constexpr (running_in_debug_mode())
6106 {
6107 Assert(this->is_reinitialized, ExcNotInitialized());
6108 }
6109 AssertIndexRange(q_point, this->n_quadrature_points);
6110 Assert(this->J_value != nullptr,
6112 "update_gradients"));
6113 Assert(this->jacobian != nullptr,
6115 "update_gradients"));
6116 if constexpr (running_in_debug_mode())
6117 {
6118 this->gradients_quad_submitted = true;
6119 }
6120
6121 const std::size_t nqp_d = this->n_quadrature_points * dim;
6122 VectorizedArrayType *gradients = this->gradients_quad + q_point * dim;
6123
6124 if (this->data->element_type ==
6126 {
6127 // General cell
6128
6129 // Derivatives are reordered for faces. Need to take this into account
6130 // and 1/inv_det != J_value for faces
6131 const VectorizedArrayType fac =
6132 (!is_face) ?
6133 this->quadrature_weights[q_point] * div_in :
6134 (this->cell_type > internal::MatrixFreeFunctions::affine ?
6135 this->J_value[q_point] :
6136 this->J_value[0] * this->quadrature_weights[q_point]) *
6137 div_in *
6139 this->jacobian[this->cell_type >
6140 internal::MatrixFreeFunctions::affine ?
6141 q_point :
6142 0]) *
6143 Number((dim == 2 && this->get_face_no() < 2) ? -1 : 1);
6144
6145 for (unsigned int d = 0; d < dim; ++d)
6146 {
6147 for (unsigned int e = 0; e < dim; ++e)
6148 gradients[d * nqp_d + e] = (d == e) ? fac : 0.;
6149 }
6150 this->divergence_is_requested = true;
6151 }
6152 else
6153 {
6154 if (!is_face &&
6156 {
6157 const VectorizedArrayType fac =
6158 this->J_value[0] * this->quadrature_weights[q_point] * div_in;
6159 for (unsigned int d = 0; d < dim; ++d)
6160 {
6161 const VectorizedArrayType jac_dd = this->jacobian[0][d][d];
6162 for (unsigned int e = 0; e < dim; ++e)
6163 gradients[d * nqp_d + e] = (d == e) ? fac * jac_dd : 0.;
6164 }
6165 }
6166 else
6167 {
6169 this->cell_type == internal::MatrixFreeFunctions::general ?
6170 this->jacobian[q_point] :
6171 this->jacobian[0];
6172 const VectorizedArrayType fac =
6173 (this->cell_type == internal::MatrixFreeFunctions::general ?
6174 this->J_value[q_point] :
6175 this->J_value[0] * this->quadrature_weights[q_point]) *
6176 div_in;
6177 for (unsigned int d = 0; d < dim; ++d)
6178 {
6179 for (unsigned int e = 0; e < dim; ++e)
6180 gradients[d * nqp_d + e] = jac[d][e] * fac;
6181 }
6182 }
6183 }
6184}
6185
6186
6187
6188template <int dim,
6189 int n_components_,
6190 typename Number,
6191 bool is_face,
6192 typename VectorizedArrayType>
6193template <int, typename>
6194inline DEAL_II_ALWAYS_INLINE void
6198 const unsigned int q_point)
6199{
6200 static_assert(n_components == dim,
6201 "Do not try to modify the default template parameters used for"
6202 " selectively enabling this function via std::enable_if!");
6203
6205 this->data->element_type !=
6208
6209 // could have used base class operator, but that involves some overhead
6210 // which is inefficient. it is nice to have the symmetric tensor because
6211 // that saves some operations
6212 if constexpr (running_in_debug_mode())
6213 {
6214 Assert(this->is_reinitialized, ExcNotInitialized());
6215 }
6216 AssertIndexRange(q_point, this->n_quadrature_points);
6217 Assert(this->J_value != nullptr,
6219 "update_gradients"));
6220 Assert(this->jacobian != nullptr,
6222 "update_gradients"));
6223 if constexpr (running_in_debug_mode())
6224 {
6225 this->gradients_quad_submitted = true;
6226 }
6227
6228 const std::size_t nqp_d = this->n_quadrature_points * dim;
6229 VectorizedArrayType *gradients = this->gradients_quad + dim * q_point;
6230 if (!is_face && this->cell_type == internal::MatrixFreeFunctions::cartesian)
6231 {
6232 const VectorizedArrayType JxW =
6233 this->J_value[0] * this->quadrature_weights[q_point];
6234 const Tensor<2, dim, VectorizedArrayType> jac = this->jacobian[0];
6235 for (unsigned int d = 0; d < dim; ++d)
6236 gradients[d * nqp_d + d] =
6237 (sym_grad.access_raw_entry(d) * JxW * jac[d][d]);
6238 for (unsigned int e = 0, counter = dim; e < dim; ++e)
6239 for (unsigned int d = e + 1; d < dim; ++d, ++counter)
6240 {
6241 const VectorizedArrayType value =
6242 sym_grad.access_raw_entry(counter) * JxW;
6243 gradients[e * nqp_d + d] = value * jac[d][d];
6244 gradients[d * nqp_d + e] = value * jac[e][e];
6245 }
6246 }
6247 // general/affine cell type
6248 else
6249 {
6250 const VectorizedArrayType JxW =
6251 this->cell_type == internal::MatrixFreeFunctions::general ?
6252 this->J_value[q_point] :
6253 this->J_value[0] * this->quadrature_weights[q_point];
6255 this->cell_type == internal::MatrixFreeFunctions::general ?
6256 this->jacobian[q_point] :
6257 this->jacobian[0];
6258 VectorizedArrayType weighted[dim][dim];
6259 for (unsigned int i = 0; i < dim; ++i)
6260 weighted[i][i] = sym_grad.access_raw_entry(i) * JxW;
6261 for (unsigned int i = 0, counter = dim; i < dim; ++i)
6262 for (unsigned int j = i + 1; j < dim; ++j, ++counter)
6263 {
6264 const VectorizedArrayType value =
6265 sym_grad.access_raw_entry(counter) * JxW;
6266 weighted[i][j] = value;
6267 weighted[j][i] = value;
6268 }
6269 for (unsigned int comp = 0; comp < dim; ++comp)
6270 for (unsigned int d = 0; d < dim; ++d)
6271 {
6272 VectorizedArrayType new_val = jac[0][d] * weighted[comp][0];
6273 for (unsigned int e = 1; e < dim; ++e)
6274 new_val += jac[e][d] * weighted[comp][e];
6275 gradients[comp * nqp_d + d] = new_val;
6276 }
6277 }
6278}
6279
6280
6281
6282template <int dim,
6283 int n_components_,
6284 typename Number,
6285 bool is_face,
6286 typename VectorizedArrayType>
6287template <int, typename>
6288inline DEAL_II_ALWAYS_INLINE void
6291 const typename FEEvaluationBase<dim,
6292 n_components_,
6293 Number,
6294 is_face,
6295 VectorizedArrayType>::curl_type curl,
6296 const unsigned int q_point)
6297{
6298 static_assert(n_components == dim,
6299 "Do not try to modify the default template parameters used for"
6300 " selectively enabling this function via std::enable_if!");
6301
6303
6304 if (this->data->element_type ==
6306 {
6307 curl_type curl_temp;
6308
6309 // Piola transform is required
6310 AssertIndexRange(q_point, this->n_quadrature_points);
6311 Assert(this->J_value != nullptr,
6313 "update_value"));
6314# ifdef DEBUG
6315 Assert(this->is_reinitialized, ExcNotInitialized());
6316 this->gradients_quad_submitted = true;
6317# endif
6318
6319 const std::size_t nqp_d = this->n_quadrature_points * dim;
6320 VectorizedArrayType *gradients = this->gradients_quad + q_point * dim;
6321
6322 if (!is_face &&
6324 {
6325 const Tensor<2, dim, VectorizedArrayType> jac = this->jacobian[1];
6326 const VectorizedArrayType weight = this->quadrature_weights[q_point];
6327
6328 if constexpr (dim == 2)
6329 {
6330 curl_temp = curl * weight;
6331 }
6332 else if constexpr (dim == 3)
6333 {
6334 for (unsigned int comp = 0; comp < dim; ++comp)
6335 {
6336 curl_temp[comp] = curl[comp] * jac[comp][comp] * weight;
6337 }
6338 }
6339 else
6341 }
6342 else
6343 {
6344 // Affine or general cell
6345 const Tensor<2, dim, VectorizedArrayType> inv_t_jac =
6346 (this->cell_type > internal::MatrixFreeFunctions::affine) ?
6347 this->jacobian[q_point] :
6348 this->jacobian[0];
6349
6350 // Derivatives are reordered for faces. Need to take this into
6351 // account and 1/inv_det != J_value for faces
6352 const VectorizedArrayType fac =
6353 (!is_face) ?
6354 this->quadrature_weights[q_point] :
6355 (((this->cell_type > internal::MatrixFreeFunctions::affine) ?
6356 this->J_value[q_point] :
6357 this->J_value[0] * this->quadrature_weights[q_point]) *
6358 ((dim == 2 && this->get_face_no() < 2) ?
6359 -determinant(inv_t_jac) :
6360 determinant(inv_t_jac)));
6362 (this->cell_type > internal::MatrixFreeFunctions::affine) ?
6363 transpose(invert(inv_t_jac)) :
6364 this->jacobian[1];
6365
6366 if constexpr (dim == 2)
6367 {
6368 curl_temp = curl * fac;
6369 }
6370 else if constexpr (dim == 3)
6371 {
6372 // J^T * u * factor
6373 for (unsigned int comp = 0; comp < n_components; ++comp)
6374 {
6375 curl_temp[comp] = curl[0] * jac[0][comp];
6376 for (unsigned int e = 1; e < dim; ++e)
6377 curl_temp[comp] += curl[e] * jac[e][comp];
6378 curl_temp[comp] *= fac;
6379 }
6380 }
6381 else
6383 }
6384 if constexpr (dim == 2)
6385 {
6386 grad[1][0] = curl_temp;
6387 grad[0][1] = -curl_temp;
6388 grad[0][0] = 0;
6389 grad[1][1] = 0;
6390 }
6391 else if constexpr (dim == 3)
6392 {
6393 grad[2][1] = curl_temp[0];
6394 grad[1][2] = -curl_temp[0];
6395 grad[0][2] = curl_temp[1];
6396 grad[2][0] = -curl_temp[1];
6397 grad[1][0] = curl_temp[2];
6398 grad[0][1] = -curl_temp[2];
6399 grad[0][0] = 0;
6400 grad[1][1] = 0;
6401 grad[2][2] = 0;
6402 }
6403 else
6405 for (unsigned int d = 0; d < dim; ++d)
6406 {
6407 for (unsigned int comp = 0; comp < n_components; ++comp)
6408 gradients[comp * nqp_d + d] = grad[comp][d];
6409 }
6410 return;
6411 }
6412
6413 if constexpr (dim == 2)
6414 {
6415 grad[1][0] = curl;
6416 grad[0][1] = -curl;
6417 }
6418 else if constexpr (dim == 3)
6419 {
6420 grad[2][1] = curl[0];
6421 grad[1][2] = -curl[0];
6422 grad[0][2] = curl[1];
6423 grad[2][0] = -curl[1];
6424 grad[1][0] = curl[2];
6425 grad[0][1] = -curl[2];
6426 }
6427 else
6429
6430 submit_gradient(grad, q_point);
6431}
6432
6433
6434
6435/*-------------------------- FEEvaluation -----------------------------------*/
6436
6437
6438template <int dim,
6439 int fe_degree,
6440 int n_q_points_1d,
6441 int n_components_,
6442 typename Number,
6443 typename VectorizedArrayType>
6444inline FEEvaluation<dim,
6445 fe_degree,
6446 n_q_points_1d,
6447 n_components_,
6448 Number,
6449 VectorizedArrayType>::
6450 FEEvaluation(const MatrixFree<dim, Number, VectorizedArrayType> &matrix_free,
6451 const unsigned int fe_no,
6452 const unsigned int quadrature_index,
6453 const unsigned int first_selected_component,
6454 const unsigned int active_fe_index,
6455 const unsigned int active_quad_index)
6456 : BaseClass(matrix_free,
6457 fe_no,
6458 first_selected_component,
6459 quadrature_index,
6460 fe_degree,
6461 static_n_q_points,
6462 true /*note: this is not a face*/,
6463 active_fe_index,
6464 active_quad_index,
6465 numbers::invalid_unsigned_int /*face_type*/)
6466 , dofs_per_component(this->data->dofs_per_component_on_cell)
6467 , dofs_per_cell(this->data->dofs_per_component_on_cell * n_components_)
6468 , n_q_points(this->data->n_q_points)
6469{
6470 check_template_arguments(fe_no, 0);
6471}
6472
6473
6474
6475template <int dim,
6476 int fe_degree,
6477 int n_q_points_1d,
6478 int n_components_,
6479 typename Number,
6480 typename VectorizedArrayType>
6481inline FEEvaluation<dim,
6482 fe_degree,
6483 n_q_points_1d,
6484 n_components_,
6485 Number,
6486 VectorizedArrayType>::
6487 FEEvaluation(const MatrixFree<dim, Number, VectorizedArrayType> &matrix_free,
6488 const std::pair<unsigned int, unsigned int> &range,
6489 const unsigned int dof_handler_index,
6490 const unsigned int quadrature_index,
6491 const unsigned int first_selected_component)
6492 : FEEvaluation(matrix_free,
6493 dof_handler_index,
6494 quadrature_index,
6495 first_selected_component,
6496 matrix_free.get_cell_active_fe_index(range, dof_handler_index))
6497{}
6498
6499
6500
6501template <int dim,
6502 int fe_degree,
6503 int n_q_points_1d,
6504 int n_components_,
6505 typename Number,
6506 typename VectorizedArrayType>
6507inline FEEvaluation<dim,
6508 fe_degree,
6509 n_q_points_1d,
6510 n_components_,
6511 Number,
6512 VectorizedArrayType>::
6513 FEEvaluation(const Mapping<dim> &mapping,
6514 const FiniteElement<dim> &fe,
6515 const Quadrature<1> &quadrature,
6516 const UpdateFlags update_flags,
6517 const unsigned int first_selected_component)
6518 : BaseClass(mapping,
6519 fe,
6520 quadrature,
6521 update_flags,
6522 first_selected_component,
6523 nullptr)
6524 , dofs_per_component(this->data->dofs_per_component_on_cell)
6525 , dofs_per_cell(this->data->dofs_per_component_on_cell * n_components_)
6526 , n_q_points(this->data->n_q_points)
6527{
6528 check_template_arguments(numbers::invalid_unsigned_int, 0);
6529}
6530
6531
6532
6533template <int dim,
6534 int fe_degree,
6535 int n_q_points_1d,
6536 int n_components_,
6537 typename Number,
6538 typename VectorizedArrayType>
6539inline FEEvaluation<dim,
6540 fe_degree,
6541 n_q_points_1d,
6542 n_components_,
6543 Number,
6544 VectorizedArrayType>::
6545 FEEvaluation(const FiniteElement<dim> &fe,
6546 const Quadrature<1> &quadrature,
6547 const UpdateFlags update_flags,
6548 const unsigned int first_selected_component)
6549 : BaseClass(StaticMappingQ1<dim>::mapping,
6550 fe,
6551 quadrature,
6552 update_flags,
6553 first_selected_component,
6554 nullptr)
6555 , dofs_per_component(this->data->dofs_per_component_on_cell)
6556 , dofs_per_cell(this->data->dofs_per_component_on_cell * n_components_)
6557 , n_q_points(this->data->n_q_points)
6558{
6559 check_template_arguments(numbers::invalid_unsigned_int, 0);
6560}
6561
6562
6563
6564template <int dim,
6565 int fe_degree,
6566 int n_q_points_1d,
6567 int n_components_,
6568 typename Number,
6569 typename VectorizedArrayType>
6570inline FEEvaluation<dim,
6571 fe_degree,
6572 n_q_points_1d,
6573 n_components_,
6574 Number,
6575 VectorizedArrayType>::
6576 FEEvaluation(const FiniteElement<dim> &fe,
6578 const unsigned int first_selected_component)
6579 : BaseClass(other.mapped_geometry->get_fe_values().get_mapping(),
6580 fe,
6581 other.mapped_geometry->get_quadrature(),
6582 other.mapped_geometry->get_fe_values().get_update_flags(),
6583 first_selected_component,
6584 &other)
6585 , dofs_per_component(this->data->dofs_per_component_on_cell)
6586 , dofs_per_cell(this->data->dofs_per_component_on_cell * n_components_)
6587 , n_q_points(this->data->n_q_points)
6588{
6589 check_template_arguments(numbers::invalid_unsigned_int, 0);
6590}
6591
6592
6593
6594template <int dim,
6595 int fe_degree,
6596 int n_q_points_1d,
6597 int n_components_,
6598 typename Number,
6599 typename VectorizedArrayType>
6600inline FEEvaluation<dim,
6601 fe_degree,
6602 n_q_points_1d,
6603 n_components_,
6604 Number,
6605 VectorizedArrayType>::FEEvaluation(const FEEvaluation
6606 &other)
6607 : BaseClass(other)
6608 , dofs_per_component(this->data->dofs_per_component_on_cell)
6609 , dofs_per_cell(this->data->dofs_per_component_on_cell * n_components_)
6610 , n_q_points(this->data->n_q_points)
6611{
6612 check_template_arguments(numbers::invalid_unsigned_int, 0);
6613}
6614
6615
6616
6617template <int dim,
6618 int fe_degree,
6619 int n_q_points_1d,
6620 int n_components_,
6621 typename Number,
6622 typename VectorizedArrayType>
6623inline FEEvaluation<dim,
6624 fe_degree,
6625 n_q_points_1d,
6626 n_components_,
6627 Number,
6628 VectorizedArrayType> &
6629FEEvaluation<dim,
6630 fe_degree,
6631 n_q_points_1d,
6632 n_components_,
6633 Number,
6634 VectorizedArrayType>::operator=(const FEEvaluation &other)
6635{
6636 BaseClass::operator=(other);
6637 check_template_arguments(numbers::invalid_unsigned_int, 0);
6638 return *this;
6639}
6640
6641
6642
6643template <int dim,
6644 int fe_degree,
6645 int n_q_points_1d,
6646 int n_components_,
6647 typename Number,
6648 typename VectorizedArrayType>
6649inline void
6650FEEvaluation<dim,
6651 fe_degree,
6652 n_q_points_1d,
6653 n_components_,
6654 Number,
6655 VectorizedArrayType>::
6656 check_template_arguments(const unsigned int dof_handler_index,
6657 const unsigned int first_selected_component)
6658{
6659 (void)dof_handler_index;
6660 (void)first_selected_component;
6661
6662 Assert(
6663 this->data->dofs_per_component_on_cell > 0,
6664 ExcMessage(
6665 "There is nothing useful you can do with an FEEvaluation object with "
6666 "FE_Nothing, i.e., without DoFs! If you have passed to "
6667 "MatrixFree::reinit() a collection of finite elements also containing "
6668 "FE_Nothing, please check - before creating FEEvaluation - the category "
6669 "of the current range by calling either "
6670 "MatrixFree::get_cell_range_category(range) or "
6671 "MatrixFree::get_face_range_category(range). The returned category "
6672 "is the index of the active FE, which you can use to exclude "
6673 "FE_Nothing."));
6674
6675 if constexpr (running_in_debug_mode())
6676 {
6677 // print error message when the dimensions do not match. Propose a
6678 // possible fix
6679 if ((static_cast<unsigned int>(fe_degree) !=
6681 static_cast<unsigned int>(fe_degree) !=
6682 this->data->data.front().fe_degree) ||
6683 n_q_points != this->n_quadrature_points)
6684 {
6685 std::string message =
6686 "-------------------------------------------------------\n";
6687 message +=
6688 "Illegal arguments in constructor/wrong template arguments!\n";
6689 message += " Called --> FEEvaluation<dim,";
6690 message += Utilities::int_to_string(fe_degree) + ",";
6691 message += Utilities::int_to_string(n_q_points_1d);
6692 message += "," + Utilities::int_to_string(n_components);
6693 message += ",Number>(data";
6694 if (first_selected_component != numbers::invalid_unsigned_int)
6695 {
6696 message +=
6697 ", " + Utilities::int_to_string(dof_handler_index) + ", ";
6698 message +=
6699 Utilities::int_to_string(this->quadrature_index) + ", ";
6700 message += Utilities::int_to_string(first_selected_component);
6701 }
6702 message += ")\n";
6703
6704 // check whether some other vector component has the correct number of
6705 // points
6706 unsigned int proposed_dof_comp = numbers::invalid_unsigned_int,
6707 proposed_fe_comp = numbers::invalid_unsigned_int,
6708 proposed_quad_comp = numbers::invalid_unsigned_int;
6709 if (dof_handler_index != numbers::invalid_unsigned_int)
6710 {
6711 if (static_cast<unsigned int>(fe_degree) ==
6712 this->data->data.front().fe_degree)
6713 {
6714 proposed_dof_comp = dof_handler_index;
6715 proposed_fe_comp = first_selected_component;
6716 }
6717 else
6718 for (unsigned int no = 0;
6719 no < this->matrix_free->n_components();
6720 ++no)
6721 for (unsigned int nf = 0;
6722 nf < this->matrix_free->n_base_elements(no);
6723 ++nf)
6724 if (this->matrix_free
6725 ->get_shape_info(no, 0, nf, this->active_fe_index, 0)
6726 .data.front()
6727 .fe_degree == static_cast<unsigned int>(fe_degree))
6728 {
6729 proposed_dof_comp = no;
6730 proposed_fe_comp = nf;
6731 break;
6732 }
6733 if (n_q_points ==
6734 this->mapping_data->descriptor[this->active_quad_index]
6735 .n_q_points)
6736 proposed_quad_comp = this->quadrature_index;
6737 else
6738 for (unsigned int no = 0;
6739 no <
6740 this->matrix_free->get_mapping_info().cell_data.size();
6741 ++no)
6742 if (this->matrix_free->get_mapping_info()
6743 .cell_data[no]
6744 .descriptor[this->active_quad_index]
6745 .n_q_points == n_q_points)
6746 {
6747 proposed_quad_comp = no;
6748 break;
6749 }
6750 }
6751 if (proposed_dof_comp != numbers::invalid_unsigned_int &&
6752 proposed_quad_comp != numbers::invalid_unsigned_int)
6753 {
6754 if (proposed_dof_comp != first_selected_component)
6755 message += "Wrong vector component selection:\n";
6756 else
6757 message += "Wrong quadrature formula selection:\n";
6758 message += " Did you mean FEEvaluation<dim,";
6759 message += Utilities::int_to_string(fe_degree) + ",";
6760 message += Utilities::int_to_string(n_q_points_1d);
6761 message += "," + Utilities::int_to_string(n_components);
6762 message += ",Number>(data";
6763 if (dof_handler_index != numbers::invalid_unsigned_int)
6764 {
6765 message +=
6766 ", " + Utilities::int_to_string(proposed_dof_comp) + ", ";
6767 message +=
6768 Utilities::int_to_string(proposed_quad_comp) + ", ";
6769 message += Utilities::int_to_string(proposed_fe_comp);
6770 }
6771 message += ")?\n";
6772 std::string correct_pos;
6773 if (proposed_dof_comp != dof_handler_index)
6774 correct_pos = " ^ ";
6775 else
6776 correct_pos = " ";
6777 if (proposed_quad_comp != this->quadrature_index)
6778 correct_pos += " ^ ";
6779 else
6780 correct_pos += " ";
6781 if (proposed_fe_comp != first_selected_component)
6782 correct_pos += " ^\n";
6783 else
6784 correct_pos += " \n";
6785 message +=
6786 " " +
6787 correct_pos;
6788 }
6789 // ok, did not find the numbers specified by the template arguments in
6790 // the given list. Suggest correct template arguments
6791 const unsigned int proposed_n_q_points_1d = static_cast<unsigned int>(
6792 std::pow(1.001 * this->n_quadrature_points, 1. / dim));
6793 message += "Wrong template arguments:\n";
6794 message += " Did you mean FEEvaluation<dim,";
6795 message +=
6796 Utilities::int_to_string(this->data->data.front().fe_degree) + ",";
6797 message += Utilities::int_to_string(proposed_n_q_points_1d);
6798 message += "," + Utilities::int_to_string(n_components);
6799 message += ",Number>(data";
6800 if (dof_handler_index != numbers::invalid_unsigned_int)
6801 {
6802 message +=
6803 ", " + Utilities::int_to_string(dof_handler_index) + ", ";
6804 message += Utilities::int_to_string(this->quadrature_index);
6805 message +=
6806 ", " + Utilities::int_to_string(first_selected_component);
6807 }
6808 message += ")?\n";
6809 std::string correct_pos;
6810 if (this->data->data.front().fe_degree !=
6811 static_cast<unsigned int>(fe_degree))
6812 correct_pos = " ^";
6813 else
6814 correct_pos = " ";
6815 if (proposed_n_q_points_1d != n_q_points_1d)
6816 correct_pos += " ^\n";
6817 else
6818 correct_pos += " \n";
6819 message += " " + correct_pos;
6820
6821 Assert(static_cast<unsigned int>(fe_degree) ==
6822 this->data->data.front().fe_degree &&
6823 n_q_points == this->n_quadrature_points,
6824 ExcMessage(message));
6825 }
6826 if (dof_handler_index != numbers::invalid_unsigned_int)
6828 n_q_points,
6829 this->mapping_data->descriptor[this->active_quad_index].n_q_points);
6830 }
6831}
6832
6833
6834
6835template <int dim,
6836 int fe_degree,
6837 int n_q_points_1d,
6838 int n_components_,
6839 typename Number,
6840 typename VectorizedArrayType>
6841inline void
6842FEEvaluation<dim,
6843 fe_degree,
6844 n_q_points_1d,
6845 n_components_,
6846 Number,
6847 VectorizedArrayType>::reinit(const unsigned int cell_index)
6848{
6849 Assert(this->matrix_free != nullptr,
6850 ExcMessage("FEEvaluation was initialized without a matrix-free object."
6851 " Integer indexing is not possible."));
6852
6853 Assert(this->dof_info != nullptr, ExcNotInitialized());
6854 Assert(this->mapping_data != nullptr, ExcNotInitialized());
6855 this->cell = cell_index;
6856 this->cell_type =
6857 this->matrix_free->get_mapping_info().get_cell_type(cell_index);
6858
6859 const unsigned int offsets =
6860 this->mapping_data->data_index_offsets[cell_index];
6861 this->jacobian = &this->mapping_data->jacobians[0][offsets];
6862 this->J_value = &this->mapping_data->JxW_values[offsets];
6863 if (!this->mapping_data->jacobian_gradients[0].empty())
6864 {
6865 this->jacobian_gradients =
6866 this->mapping_data->jacobian_gradients[0].data() + offsets;
6867 this->jacobian_gradients_non_inverse =
6868 this->mapping_data->jacobian_gradients_non_inverse[0].data() + offsets;
6869 }
6870
6871 if (this->matrix_free->n_active_entries_per_cell_batch(this->cell) == n_lanes)
6872 {
6874 for (unsigned int i = 0; i < n_lanes; ++i)
6875 this->cell_ids[i] = cell_index * n_lanes + i;
6876 }
6877 else
6878 {
6879 unsigned int i = 0;
6880 for (; i < this->matrix_free->n_active_entries_per_cell_batch(this->cell);
6881 ++i)
6882 this->cell_ids[i] = cell_index * n_lanes + i;
6883 for (; i < n_lanes; ++i)
6884 this->cell_ids[i] = numbers::invalid_unsigned_int;
6885 }
6886
6887 if (this->mapping_data->quadrature_points.empty() == false)
6888 this->quadrature_points =
6889 &this->mapping_data->quadrature_points
6890 [this->mapping_data->quadrature_point_offsets[this->cell]];
6891
6892 if constexpr (running_in_debug_mode())
6893 {
6894 this->is_reinitialized = true;
6895 this->dof_values_initialized = false;
6896 this->values_quad_initialized = false;
6897 this->gradients_quad_initialized = false;
6898 this->hessians_quad_initialized = false;
6899 }
6900}
6901
6902
6903
6904template <int dim,
6905 int fe_degree,
6906 int n_q_points_1d,
6907 int n_components_,
6908 typename Number,
6909 typename VectorizedArrayType>
6910inline void
6911FEEvaluation<dim,
6912 fe_degree,
6913 n_q_points_1d,
6914 n_components_,
6915 Number,
6916 VectorizedArrayType>::reinit(const std::array<unsigned int,
6917 n_lanes> &cell_ids)
6918{
6919 Assert(this->dof_info != nullptr, ExcNotInitialized());
6920 Assert(this->mapping_data != nullptr, ExcNotInitialized());
6921
6922 this->cell = numbers::invalid_unsigned_int;
6923 this->cell_ids = cell_ids;
6924
6925 // determine type of cell batch
6927
6928 for (unsigned int v = 0; v < n_lanes; ++v)
6929 {
6930 const unsigned int cell_index = cell_ids[v];
6931
6933 continue;
6934
6935 this->cell_type =
6936 std::max(this->cell_type,
6937 this->matrix_free->get_mapping_info().get_cell_type(
6938 cell_index / n_lanes));
6939 }
6940
6941 // allocate memory for internal data storage
6942 if (this->mapped_geometry == nullptr)
6943 this->mapped_geometry =
6944 std::make_shared<internal::MatrixFreeFunctions::
6945 MappingDataOnTheFly<dim, VectorizedArrayType>>();
6946
6947 auto &mapping_storage = this->mapped_geometry->get_data_storage();
6948
6949 auto &this_jacobian_data = mapping_storage.jacobians[0];
6950 auto &this_J_value_data = mapping_storage.JxW_values;
6951 auto &this_jacobian_gradients_data = mapping_storage.jacobian_gradients[0];
6952 auto &this_jacobian_gradients_non_inverse_data =
6953 mapping_storage.jacobian_gradients_non_inverse[0];
6954 auto &this_quadrature_points_data = mapping_storage.quadrature_points;
6955
6957 {
6958 if (this_jacobian_data.size() != 2)
6959 this_jacobian_data.resize_fast(2);
6960
6961 if (this_J_value_data.size() != 1)
6962 this_J_value_data.resize_fast(1);
6963
6964 const auto &update_flags_cells =
6965 this->matrix_free->get_mapping_info().update_flags_cells;
6966
6967 if (update_flags_cells & update_jacobian_grads &&
6968 this_jacobian_gradients_data.size() != 1)
6969 {
6970 this_jacobian_gradients_data.resize_fast(1);
6971 this_jacobian_gradients_non_inverse_data.resize_fast(1);
6972 }
6973
6974 if (update_flags_cells & update_quadrature_points &&
6975 this_quadrature_points_data.size() != 1)
6976 this_quadrature_points_data.resize_fast(1);
6977 }
6978 else
6979 {
6980 if (this_jacobian_data.size() != this->n_quadrature_points)
6981 this_jacobian_data.resize_fast(this->n_quadrature_points);
6982
6983 if (this_J_value_data.size() != this->n_quadrature_points)
6984 this_J_value_data.resize_fast(this->n_quadrature_points);
6985
6986 const auto &update_flags_cells =
6987 this->matrix_free->get_mapping_info().update_flags_cells;
6988
6989 if (update_flags_cells & update_jacobian_grads &&
6990 this_jacobian_gradients_data.size() != this->n_quadrature_points)
6991 {
6992 this_jacobian_gradients_data.resize_fast(this->n_quadrature_points);
6993 this_jacobian_gradients_non_inverse_data.resize_fast(
6994 this->n_quadrature_points);
6995 }
6996
6997 if (update_flags_cells & update_quadrature_points &&
6998 this_quadrature_points_data.size() != this->n_quadrature_points)
6999 this_quadrature_points_data.resize_fast(this->n_quadrature_points);
7000 }
7001
7002 // set pointers to internal data storage
7003 this->jacobian = this_jacobian_data.data();
7004 this->J_value = this_J_value_data.data();
7005 this->jacobian_gradients = this_jacobian_gradients_data.data();
7006 this->jacobian_gradients_non_inverse =
7007 this_jacobian_gradients_non_inverse_data.data();
7008 this->quadrature_points = this_quadrature_points_data.data();
7009
7010 // fill internal data storage lane by lane
7011 for (unsigned int v = 0; v < n_lanes; ++v)
7012 {
7013 const unsigned int cell_index = cell_ids[v];
7014
7016 continue;
7017
7018 const unsigned int cell_batch_index = cell_index / n_lanes;
7019 const unsigned int offsets =
7020 this->mapping_data->data_index_offsets[cell_batch_index];
7021 const unsigned int lane = cell_index % n_lanes;
7022
7023 if (this->cell_type <=
7025 {
7026 // case that all cells are Cartesian or affine
7027 for (unsigned int q = 0; q < 2; ++q)
7028 for (unsigned int i = 0; i < dim; ++i)
7029 for (unsigned int j = 0; j < dim; ++j)
7030 this_jacobian_data[q][i][j][v] =
7031 this->mapping_data->jacobians[0][offsets + q][i][j][lane];
7032
7033 const unsigned int q = 0;
7034
7035 this_J_value_data[q][v] =
7036 this->mapping_data->JxW_values[offsets + q][lane];
7037
7038 const auto &update_flags_cells =
7039 this->matrix_free->get_mapping_info().update_flags_cells;
7040
7041 if (update_flags_cells & update_jacobian_grads)
7042 {
7043 for (unsigned int i = 0; i < dim * (dim + 1) / 2; ++i)
7044 for (unsigned int j = 0; j < dim; ++j)
7045 this_jacobian_gradients_data[q][i][j][v] =
7046 this->mapping_data
7047 ->jacobian_gradients[0][offsets + q][i][j][lane];
7048
7049 for (unsigned int i = 0; i < dim * (dim + 1) / 2; ++i)
7050 for (unsigned int j = 0; j < dim; ++j)
7051 this_jacobian_gradients_non_inverse_data[q][i][j][v] =
7052 this->mapping_data
7053 ->jacobian_gradients_non_inverse[0][offsets + q][i][j]
7054 [lane];
7055 }
7056
7057 if (update_flags_cells & update_quadrature_points)
7058 for (unsigned int i = 0; i < dim; ++i)
7059 this_quadrature_points_data[q][i][v] =
7060 this->mapping_data->quadrature_points
7061 [this->mapping_data
7062 ->quadrature_point_offsets[cell_batch_index] +
7063 q][i][lane];
7064 }
7065 else
7066 {
7067 // general case that at least one cell is not Cartesian or affine
7068 const auto cell_type =
7069 this->matrix_free->get_mapping_info().get_cell_type(
7070 cell_batch_index);
7071
7072 for (unsigned int q = 0; q < this->n_quadrature_points; ++q)
7073 {
7074 const unsigned int q_src =
7075 (cell_type <=
7077 0 :
7078 q;
7079
7080 this_J_value_data[q][v] =
7081 this->mapping_data->JxW_values[offsets + q_src][lane];
7082
7083 for (unsigned int i = 0; i < dim; ++i)
7084 for (unsigned int j = 0; j < dim; ++j)
7085 this_jacobian_data[q][i][j][v] =
7086 this->mapping_data
7087 ->jacobians[0][offsets + q_src][i][j][lane];
7088
7089 const auto &update_flags_cells =
7090 this->matrix_free->get_mapping_info().update_flags_cells;
7091
7092 if (update_flags_cells & update_jacobian_grads)
7093 {
7094 for (unsigned int i = 0; i < dim * (dim + 1) / 2; ++i)
7095 for (unsigned int j = 0; j < dim; ++j)
7096 this_jacobian_gradients_data[q][i][j][v] =
7097 this->mapping_data
7098 ->jacobian_gradients[0][offsets + q_src][i][j][lane];
7099
7100 for (unsigned int i = 0; i < dim * (dim + 1) / 2; ++i)
7101 for (unsigned int j = 0; j < dim; ++j)
7102 this_jacobian_gradients_non_inverse_data[q][i][j][v] =
7103 this->mapping_data
7104 ->jacobian_gradients_non_inverse[0][offsets + q_src]
7105 [i][j][lane];
7106 }
7107
7108 if (update_flags_cells & update_quadrature_points)
7109 {
7110 if (cell_type <=
7112 {
7113 // affine case: quadrature points are not available but
7114 // have to be computed from the corner point and the
7115 // Jacobian
7117 this->mapping_data->quadrature_points
7118 [this->mapping_data
7119 ->quadrature_point_offsets[cell_batch_index] +
7120 0];
7121
7123 this->mapping_data->jacobians[0][offsets + 1];
7125 for (unsigned int d = 0; d < dim; ++d)
7126 point[d] +=
7127 jac[d][d] *
7128 static_cast<Number>(
7129 this->descriptor->quadrature.point(q)[d]);
7130 else
7131 for (unsigned int d = 0; d < dim; ++d)
7132 for (unsigned int e = 0; e < dim; ++e)
7133 point[d] +=
7134 jac[d][e] *
7135 static_cast<Number>(
7136 this->descriptor->quadrature.point(q)[e]);
7137
7138 for (unsigned int i = 0; i < dim; ++i)
7139 this_quadrature_points_data[q][i][v] = point[i][lane];
7140 }
7141 else
7142 {
7143 // general case: quadrature points are available
7144 for (unsigned int i = 0; i < dim; ++i)
7145 this_quadrature_points_data[q][i][v] =
7146 this->mapping_data->quadrature_points
7147 [this->mapping_data
7148 ->quadrature_point_offsets[cell_batch_index] +
7149 q][i][lane];
7150 }
7151 }
7152 }
7153 }
7154 }
7155
7156 if constexpr (running_in_debug_mode())
7157 {
7158 this->is_reinitialized = true;
7159 this->dof_values_initialized = false;
7160 this->values_quad_initialized = false;
7161 this->gradients_quad_initialized = false;
7162 this->hessians_quad_initialized = false;
7163 }
7164}
7165
7166
7167
7168template <int dim,
7169 int fe_degree,
7170 int n_q_points_1d,
7171 int n_components_,
7172 typename Number,
7173 typename VectorizedArrayType>
7174template <bool level_dof_access>
7175inline void
7176FEEvaluation<dim,
7177 fe_degree,
7178 n_q_points_1d,
7179 n_components_,
7180 Number,
7181 VectorizedArrayType>::
7183{
7184 Assert(this->matrix_free == nullptr,
7185 ExcMessage("Cannot use initialization from cell iterator if "
7186 "initialized from MatrixFree object. Use variant for "
7187 "on the fly computation with arguments as for FEValues "
7188 "instead"));
7189 Assert(this->mapped_geometry.get() != nullptr, ExcNotInitialized());
7190 this->mapped_geometry->reinit(
7191 static_cast<typename Triangulation<dim>::cell_iterator>(cell));
7192 this->local_dof_indices.resize(cell->get_fe().n_dofs_per_cell());
7193 if (level_dof_access)
7194 cell->get_mg_dof_indices(this->local_dof_indices);
7195 else
7196 cell->get_dof_indices(this->local_dof_indices);
7197
7198 if constexpr (running_in_debug_mode())
7199 {
7200 this->is_reinitialized = true;
7201 }
7202}
7203
7204
7205
7206template <int dim,
7207 int fe_degree,
7208 int n_q_points_1d,
7209 int n_components_,
7210 typename Number,
7211 typename VectorizedArrayType>
7212inline void
7213FEEvaluation<dim,
7214 fe_degree,
7215 n_q_points_1d,
7216 n_components_,
7217 Number,
7218 VectorizedArrayType>::
7219 reinit(const typename Triangulation<dim>::cell_iterator &cell)
7220{
7221 Assert(this->matrix_free == 0,
7222 ExcMessage("Cannot use initialization from cell iterator if "
7223 "initialized from MatrixFree object. Use variant for "
7224 "on the fly computation with arguments as for FEValues "
7225 "instead"));
7226 Assert(this->mapped_geometry.get() != 0, ExcNotInitialized());
7227 this->mapped_geometry->reinit(cell);
7228
7229 if constexpr (running_in_debug_mode())
7230 {
7231 this->is_reinitialized = true;
7232 }
7233}
7234
7235
7236
7237template <int dim,
7238 int fe_degree,
7239 int n_q_points_1d,
7240 int n_components_,
7241 typename Number,
7242 typename VectorizedArrayType>
7243inline void
7244FEEvaluation<dim,
7245 fe_degree,
7246 n_q_points_1d,
7247 n_components_,
7248 Number,
7249 VectorizedArrayType>::
7250 evaluate(const EvaluationFlags::EvaluationFlags evaluation_flags)
7251{
7252 if constexpr (running_in_debug_mode())
7253 {
7254 Assert(this->dof_values_initialized == true,
7256 }
7257 evaluate(this->values_dofs, evaluation_flags);
7258}
7259
7260
7261
7262template <int dim,
7263 int fe_degree,
7264 int n_q_points_1d,
7265 int n_components_,
7266 typename Number,
7267 typename VectorizedArrayType>
7268inline void
7269FEEvaluation<dim,
7270 fe_degree,
7271 n_q_points_1d,
7272 n_components_,
7273 Number,
7274 VectorizedArrayType>::
7275 evaluate(const VectorizedArrayType *values_array,
7276 const EvaluationFlags::EvaluationFlags evaluation_flag)
7277{
7278 const bool hessians_on_general_cells =
7279 evaluation_flag & EvaluationFlags::hessians &&
7280 (this->cell_type > internal::MatrixFreeFunctions::affine);
7281 EvaluationFlags::EvaluationFlags evaluation_flag_actual = evaluation_flag;
7282 if (hessians_on_general_cells)
7283 evaluation_flag_actual |= EvaluationFlags::gradients;
7284
7285 if (this->data->element_type ==
7287 evaluation_flag & EvaluationFlags::gradients &&
7288 (this->cell_type > internal::MatrixFreeFunctions::affine))
7289 evaluation_flag_actual |= EvaluationFlags::values;
7290
7291 if constexpr (fe_degree > -1)
7292 {
7294 template run<fe_degree, n_q_points_1d>(n_components,
7295 evaluation_flag_actual,
7296 values_array,
7297 *this);
7298 }
7299 else
7300 {
7302 n_components,
7303 evaluation_flag_actual,
7304 const_cast<VectorizedArrayType *>(values_array),
7305 *this);
7306 }
7307
7308 this->store_values_for_gradients(evaluation_flag);
7309
7310 if constexpr (running_in_debug_mode())
7311 {
7312 this->values_quad_initialized =
7313 evaluation_flag_actual & EvaluationFlags::values;
7314 this->gradients_quad_initialized =
7315 evaluation_flag_actual & EvaluationFlags::gradients;
7316 this->hessians_quad_initialized =
7317 evaluation_flag_actual & EvaluationFlags::hessians;
7318 }
7319}
7320
7321
7322namespace internal
7323{
7327 template <typename Number,
7328 typename VectorizedArrayType,
7329 typename VectorType,
7330 typename EvaluatorType,
7331 std::enable_if_t<internal::has_begin<VectorType> &&
7333 VectorType> * = nullptr>
7334 VectorizedArrayType *
7335 check_vector_access_inplace(const EvaluatorType &fe_eval, VectorType &vector)
7336 {
7337 // for user-defined cell batches this functionality is not supported
7338 if (fe_eval.get_current_cell_index() == numbers::invalid_unsigned_int)
7339 return nullptr;
7340
7341 const unsigned int cell = fe_eval.get_cell_or_face_batch_id();
7342 const auto &dof_info = fe_eval.get_dof_info();
7343
7344 // If the index storage is interleaved and contiguous and the vector
7345 // storage has the correct alignment, we can directly pass the pointer
7346 // into the vector to the evaluate() and integrate() calls, without
7347 // reading the vector entries into a separate data field. This saves some
7348 // operations.
7349 if (std::is_same_v<typename VectorType::value_type, Number> &&
7350 dof_info.index_storage_variants
7353 interleaved_contiguous &&
7354 reinterpret_cast<std::size_t>(
7355 vector.begin() +
7356 dof_info.dof_indices_contiguous
7357 [internal::MatrixFreeFunctions::DoFInfo::dof_access_cell]
7358 [cell * VectorizedArrayType::size()]) %
7359 sizeof(VectorizedArrayType) ==
7360 0)
7361 {
7362 return reinterpret_cast<VectorizedArrayType *>(
7363 vector.begin() +
7364 dof_info.dof_indices_contiguous
7366 [cell * VectorizedArrayType::size()] +
7368 [fe_eval.get_active_fe_index()]
7369 [fe_eval.get_first_selected_component()] *
7370 VectorizedArrayType::size());
7371 }
7372 else
7373 return nullptr;
7374 }
7375
7379 template <typename Number,
7380 typename VectorizedArrayType,
7381 typename VectorType,
7382 typename EvaluatorType,
7383 std::enable_if_t<!internal::has_begin<VectorType> ||
7385 VectorType> * = nullptr>
7386 VectorizedArrayType *
7387 check_vector_access_inplace(const EvaluatorType &, VectorType &)
7388 {
7389 return nullptr;
7390 }
7391} // namespace internal
7392
7393
7394
7395template <int dim,
7396 int fe_degree,
7397 int n_q_points_1d,
7398 int n_components_,
7399 typename Number,
7400 typename VectorizedArrayType>
7401template <typename VectorType>
7402inline void
7403FEEvaluation<dim,
7404 fe_degree,
7405 n_q_points_1d,
7406 n_components_,
7407 Number,
7408 VectorizedArrayType>::
7409 gather_evaluate(const VectorType &input_vector,
7410 const EvaluationFlags::EvaluationFlags evaluation_flag)
7411{
7412 const VectorizedArrayType *src_ptr =
7413 internal::check_vector_access_inplace<Number, const VectorizedArrayType>(
7414 *this, input_vector);
7415 if (src_ptr != nullptr)
7416 evaluate(src_ptr, evaluation_flag);
7417 else
7418 {
7419 this->read_dof_values(input_vector);
7420 evaluate(this->begin_dof_values(), evaluation_flag);
7421 }
7422}
7423
7424
7425
7426template <int dim,
7427 int fe_degree,
7428 int n_q_points_1d,
7429 int n_components_,
7430 typename Number,
7431 typename VectorizedArrayType>
7432inline void
7433FEEvaluation<dim,
7434 fe_degree,
7435 n_q_points_1d,
7436 n_components_,
7437 Number,
7438 VectorizedArrayType>::
7439 integrate(const EvaluationFlags::EvaluationFlags integration_flag)
7440{
7441 integrate(integration_flag, this->values_dofs);
7442
7443 if constexpr (running_in_debug_mode())
7444 {
7445 this->dof_values_initialized = true;
7446 }
7447}
7448
7449
7450
7451template <int dim,
7452 int fe_degree,
7453 int n_q_points_1d,
7454 int n_components_,
7455 typename Number,
7456 typename VectorizedArrayType>
7457inline void
7458FEEvaluation<dim,
7459 fe_degree,
7460 n_q_points_1d,
7461 n_components_,
7462 Number,
7463 VectorizedArrayType>::
7464 integrate(const EvaluationFlags::EvaluationFlags integration_flag,
7465 VectorizedArrayType *values_array,
7466 const bool sum_into_values_array)
7467{
7468 if constexpr (running_in_debug_mode())
7469 {
7470 if (integration_flag & EvaluationFlags::values)
7471 Assert(this->values_quad_submitted == true,
7473 if (integration_flag & EvaluationFlags::gradients)
7474 Assert(this->gradients_quad_submitted == true,
7476 if ((integration_flag & EvaluationFlags::hessians) != 0u)
7477 Assert(this->hessians_quad_submitted == true,
7479 }
7480 Assert(this->matrix_free != nullptr ||
7481 this->mapped_geometry->is_initialized(),
7483
7484 Assert(
7485 (integration_flag & ~(EvaluationFlags::values | EvaluationFlags::gradients |
7487 ExcMessage("Only EvaluationFlags::values, EvaluationFlags::gradients, and "
7488 "EvaluationFlags::hessians are supported."));
7489
7490 EvaluationFlags::EvaluationFlags integration_flag_actual = integration_flag;
7491 if (integration_flag & EvaluationFlags::hessians &&
7492 (this->cell_type > internal::MatrixFreeFunctions::affine))
7493 {
7494 unsigned int size = n_components * dim * n_q_points;
7495 if ((integration_flag & EvaluationFlags::gradients) != 0u)
7496 {
7497 for (unsigned int i = 0; i < size; ++i)
7498 this->gradients_quad[i] += this->gradients_from_hessians_quad[i];
7499 }
7500 else
7501 {
7502 for (unsigned int i = 0; i < size; ++i)
7503 this->gradients_quad[i] = this->gradients_from_hessians_quad[i];
7504 integration_flag_actual |= EvaluationFlags::gradients;
7505 }
7506 }
7507
7508 if (n_components == dim &&
7509 this->data->element_type ==
7511 integration_flag & EvaluationFlags::gradients &&
7512 this->cell_type > internal::MatrixFreeFunctions::affine &&
7513 this->divergence_is_requested == false)
7514 {
7515 unsigned int size = n_components * n_q_points;
7516 if ((integration_flag & EvaluationFlags::values) != 0u)
7517 {
7518 for (unsigned int i = 0; i < size; ++i)
7519 this->values_quad[i] += this->values_from_gradients_quad[i];
7520 }
7521 else
7522 {
7523 for (unsigned int i = 0; i < size; ++i)
7524 this->values_quad[i] = this->values_from_gradients_quad[i];
7525 integration_flag_actual |= EvaluationFlags::values;
7526 }
7527 }
7528
7529 if constexpr (fe_degree > -1)
7530 {
7532 template run<fe_degree, n_q_points_1d>(n_components,
7533 integration_flag_actual,
7534 values_array,
7535 *this,
7536 sum_into_values_array);
7537 }
7538 else
7539 {
7541 n_components,
7542 integration_flag_actual,
7543 values_array,
7544 *this,
7545 sum_into_values_array);
7546 }
7547
7548 if constexpr (running_in_debug_mode())
7549 {
7550 this->dof_values_initialized = true;
7551 }
7552}
7553
7554
7555
7556template <int dim,
7557 int fe_degree,
7558 int n_q_points_1d,
7559 int n_components_,
7560 typename Number,
7561 typename VectorizedArrayType>
7562template <typename VectorType>
7563inline void
7564FEEvaluation<dim,
7565 fe_degree,
7566 n_q_points_1d,
7567 n_components_,
7568 Number,
7569 VectorizedArrayType>::
7570 integrate_scatter(const EvaluationFlags::EvaluationFlags integration_flag,
7571 VectorType &destination)
7572{
7573 VectorizedArrayType *dst_ptr =
7574 internal::check_vector_access_inplace<Number, VectorizedArrayType>(
7575 *this, destination);
7576 if (dst_ptr != nullptr)
7577 integrate(integration_flag, dst_ptr, true);
7578 else
7579 {
7580 integrate(integration_flag, this->begin_dof_values());
7581 this->distribute_local_to_global(destination);
7582 }
7583}
7584
7585
7586
7587template <int dim,
7588 int fe_degree,
7589 int n_q_points_1d,
7590 int n_components_,
7591 typename Number,
7592 typename VectorizedArrayType>
7594FEEvaluation<dim,
7595 fe_degree,
7596 n_q_points_1d,
7597 n_components_,
7598 Number,
7599 VectorizedArrayType>::dof_indices() const
7600{
7602 0U, dofs_per_cell);
7603}
7604
7605
7606
7607/*-------------------------- FEFaceEvaluation ---------------------------*/
7608
7609
7610
7611template <int dim,
7612 int fe_degree,
7613 int n_q_points_1d,
7614 int n_components_,
7615 typename Number,
7616 typename VectorizedArrayType>
7617inline FEFaceEvaluation<dim,
7618 fe_degree,
7619 n_q_points_1d,
7620 n_components_,
7621 Number,
7622 VectorizedArrayType>::
7623 FEFaceEvaluation(
7625 const bool is_interior_face,
7626 const unsigned int dof_handler_index,
7627 const unsigned int quadrature_index,
7628 const unsigned int first_selected_component,
7629 const unsigned int active_fe_index,
7630 const unsigned int active_quad_index,
7631 const unsigned int face_type)
7632 : BaseClass(matrix_free,
7633 dof_handler_index,
7634 first_selected_component,
7635 quadrature_index,
7636 fe_degree,
7637 static_n_q_points,
7638 is_interior_face,
7639 active_fe_index,
7640 active_quad_index,
7641 face_type)
7642 , dofs_per_component(this->data->dofs_per_component_on_cell)
7643 , dofs_per_cell(this->data->dofs_per_component_on_cell * n_components_)
7644 , n_q_points(this->n_quadrature_points)
7645{}
7646
7647
7648
7649template <int dim,
7650 int fe_degree,
7651 int n_q_points_1d,
7652 int n_components_,
7653 typename Number,
7654 typename VectorizedArrayType>
7655inline FEFaceEvaluation<dim,
7656 fe_degree,
7657 n_q_points_1d,
7658 n_components_,
7659 Number,
7660 VectorizedArrayType>::
7661 FEFaceEvaluation(
7663 const std::pair<unsigned int, unsigned int> &range,
7664 const bool is_interior_face,
7665 const unsigned int dof_handler_index,
7666 const unsigned int quadrature_index,
7667 const unsigned int first_selected_component)
7668 : FEFaceEvaluation(matrix_free,
7669 is_interior_face,
7670 dof_handler_index,
7671 quadrature_index,
7672 first_selected_component,
7673 matrix_free.get_face_active_fe_index(range,
7674 is_interior_face),
7676 matrix_free.get_face_info(range.first).face_type)
7677{}
7678
7679
7680
7681template <int dim,
7682 int fe_degree,
7683 int n_q_points_1d,
7684 int n_components_,
7685 typename Number,
7686 typename VectorizedArrayType>
7687inline void
7689 fe_degree,
7690 n_q_points_1d,
7691 n_components_,
7692 Number,
7693 VectorizedArrayType>::reinit(const unsigned int face_index)
7694{
7695 Assert(this->mapped_geometry == nullptr,
7696 ExcMessage("FEEvaluation was initialized without a matrix-free object."
7697 " Integer indexing is not possible"));
7698 if (this->mapped_geometry != nullptr)
7699 return;
7700
7701 this->cell = face_index;
7702 this->dof_access_index =
7703 this->is_interior_face() ?
7706 Assert(this->mapping_data != nullptr, ExcNotInitialized());
7707
7708 if (face_index >=
7709 this->matrix_free->get_task_info().face_partition_data.back() &&
7710 face_index <
7711 this->matrix_free->get_task_info().boundary_partition_data.back())
7712 Assert(this->is_interior_face(),
7713 ExcMessage(
7714 "Boundary faces do not have a neighbor. When looping over "
7715 "boundary faces use FEFaceEvaluation with the parameter "
7716 "is_interior_face set to true. "));
7717
7718 this->reinit_face(this->matrix_free->get_face_info(face_index));
7719
7720 unsigned int i = 0;
7721 for (; i < this->matrix_free->n_active_entries_per_face_batch(this->cell);
7722 ++i)
7723 this->face_ids[i] = face_index * n_lanes + i;
7724 for (; i < n_lanes; ++i)
7725 this->face_ids[i] = numbers::invalid_unsigned_int;
7726
7727 this->cell_type = this->matrix_free->get_mapping_info().face_type[face_index];
7728 const unsigned int offsets =
7729 this->mapping_data->data_index_offsets[face_index];
7730 this->J_value = &this->mapping_data->JxW_values[offsets];
7731 this->normal_vectors = &this->mapping_data->normal_vectors[offsets];
7732 this->jacobian =
7733 &this->mapping_data->jacobians[!this->is_interior_face()][offsets];
7734 this->normal_x_jacobian =
7735 &this->mapping_data
7736 ->normals_times_jacobians[!this->is_interior_face()][offsets];
7737 this->jacobian_gradients =
7738 this->mapping_data->jacobian_gradients[!this->is_interior_face()].data() +
7739 offsets;
7740 this->jacobian_gradients_non_inverse =
7741 this->mapping_data
7742 ->jacobian_gradients_non_inverse[!this->is_interior_face()]
7743 .data() +
7744 offsets;
7745
7746 if (this->mapping_data->quadrature_point_offsets.empty() == false)
7747 {
7748 AssertIndexRange(this->cell,
7749 this->mapping_data->quadrature_point_offsets.size());
7750 this->quadrature_points =
7751 this->mapping_data->quadrature_points.data() +
7752 this->mapping_data->quadrature_point_offsets[this->cell];
7753 }
7754
7755 if constexpr (running_in_debug_mode())
7756 {
7757 this->is_reinitialized = true;
7758 this->dof_values_initialized = false;
7759 this->values_quad_initialized = false;
7760 this->gradients_quad_initialized = false;
7761 this->hessians_quad_initialized = false;
7762 }
7763}
7764
7765
7766
7767template <int dim,
7768 int fe_degree,
7769 int n_q_points_1d,
7770 int n_components_,
7771 typename Number,
7772 typename VectorizedArrayType>
7773inline void
7775 fe_degree,
7776 n_q_points_1d,
7777 n_components_,
7778 Number,
7779 VectorizedArrayType>::reinit(const unsigned int cell_index,
7780 const unsigned int face_number)
7781{
7782 Assert(
7783 this->quadrature_index <
7784 this->matrix_free->get_mapping_info().face_data_by_cells.size(),
7785 ExcMessage(
7786 "You must set MatrixFree::AdditionalData::mapping_update_flags_faces_by_cells to use the present reinit method."));
7789 this->matrix_free->get_mapping_info().cell_type.size());
7790 Assert(this->mapped_geometry == nullptr,
7791 ExcMessage("FEEvaluation was initialized without a matrix-free object."
7792 " Integer indexing is not possible"));
7793 if (this->mapped_geometry != nullptr)
7794 return;
7795 Assert(this->matrix_free != nullptr, ExcNotInitialized());
7796
7797 this->cell_type = this->matrix_free->get_mapping_info()
7798 .faces_by_cells_type[cell_index][face_number];
7799 this->cell = cell_index;
7800 this->subface_index = GeometryInfo<dim>::max_children_per_cell;
7801 this->dof_access_index =
7803
7804 if (this->is_interior_face() == false)
7805 {
7806 // for this case, we need to look into the FaceInfo field that collects
7807 // information from both sides of a face once for the global mesh, and
7808 // pick the face id that is not the local one (cell_this).
7809 for (unsigned int i = 0; i < n_lanes; ++i)
7810 {
7811 // compute actual (non vectorized) cell ID
7812 const unsigned int cell_this = cell_index * n_lanes + i;
7813 // compute face ID
7814 unsigned int face_index =
7815 this->matrix_free->get_cell_and_face_to_plain_faces()(cell_index,
7816 face_number,
7817 i);
7818
7819 this->face_ids[i] = face_index;
7820
7821 if (face_index == numbers::invalid_unsigned_int)
7822 {
7823 this->cell_ids[i] = numbers::invalid_unsigned_int;
7824 this->face_numbers[i] = static_cast<std::uint8_t>(-1);
7825 this->face_orientations[i] =
7827 continue; // invalid face ID: no neighbor on boundary
7828 }
7829
7830 const auto &faces =
7831 this->matrix_free->get_face_info(face_index / n_lanes);
7832 // get cell ID on both sides of face
7833 auto cell_m = faces.cells_interior[face_index % n_lanes];
7834 auto cell_p = faces.cells_exterior[face_index % n_lanes];
7835
7836 const bool face_identifies_as_interior = cell_m != cell_this;
7837
7838 Assert(cell_m == cell_this || cell_p == cell_this,
7840
7841 // compare the IDs with the given cell ID
7842 if (face_identifies_as_interior)
7843 {
7844 this->cell_ids[i] = cell_m; // neighbor has the other ID
7845 this->face_numbers[i] = faces.interior_face_no;
7846 }
7847 else
7848 {
7849 this->cell_ids[i] = cell_p;
7850 this->face_numbers[i] = faces.exterior_face_no;
7851 }
7852
7853 const bool orientation_interior_face = faces.face_orientation >= 8;
7854 types::geometric_orientation face_orientation =
7855 faces.face_orientation % 8;
7856 if (face_identifies_as_interior != orientation_interior_face)
7857 {
7858 Assert(this->matrix_free->get_cell_iterator(cell_index, i)
7859 ->reference_cell() ==
7860 ReferenceCells::get_hypercube<dim>(),
7862 face_orientation =
7864 .get_inverse_combined_orientation(face_orientation);
7865 }
7866 this->face_orientations[i] = face_orientation;
7867 }
7868 }
7869 else
7870 {
7871 this->face_orientations[0] = numbers::default_geometric_orientation;
7872 this->face_numbers[0] = face_number;
7873 if (this->matrix_free->n_active_entries_per_cell_batch(this->cell) ==
7874 n_lanes)
7875 {
7877 for (unsigned int i = 0; i < n_lanes; ++i)
7878 this->cell_ids[i] = cell_index * n_lanes + i;
7879 }
7880 else
7881 {
7882 unsigned int i = 0;
7883 for (; i <
7884 this->matrix_free->n_active_entries_per_cell_batch(this->cell);
7885 ++i)
7886 this->cell_ids[i] = cell_index * n_lanes + i;
7887 for (; i < n_lanes; ++i)
7888 this->cell_ids[i] = numbers::invalid_unsigned_int;
7889 }
7890 for (unsigned int i = 0; i < n_lanes; ++i)
7891 this->face_ids[i] =
7892 this->matrix_free->get_cell_and_face_to_plain_faces()(cell_index,
7893 face_number,
7894 i);
7895 }
7896
7897 const unsigned int offsets =
7898 this->matrix_free->get_mapping_info()
7899 .face_data_by_cells[this->quadrature_index]
7900 .data_index_offsets[cell_index * GeometryInfo<dim>::faces_per_cell +
7901 face_number];
7902 AssertIndexRange(offsets,
7903 this->matrix_free->get_mapping_info()
7904 .face_data_by_cells[this->quadrature_index]
7905 .JxW_values.size());
7906 this->J_value = &this->matrix_free->get_mapping_info()
7907 .face_data_by_cells[this->quadrature_index]
7908 .JxW_values[offsets];
7909 this->normal_vectors = &this->matrix_free->get_mapping_info()
7910 .face_data_by_cells[this->quadrature_index]
7911 .normal_vectors[offsets];
7912 this->jacobian = &this->matrix_free->get_mapping_info()
7913 .face_data_by_cells[this->quadrature_index]
7914 .jacobians[!this->is_interior_face()][offsets];
7915 this->normal_x_jacobian =
7916 &this->matrix_free->get_mapping_info()
7917 .face_data_by_cells[this->quadrature_index]
7918 .normals_times_jacobians[!this->is_interior_face()][offsets];
7919 this->jacobian_gradients =
7920 this->mapping_data->jacobian_gradients[!this->is_interior_face()].data() +
7921 offsets;
7922 this->jacobian_gradients_non_inverse =
7923 this->mapping_data
7924 ->jacobian_gradients_non_inverse[!this->is_interior_face()]
7925 .data() +
7926 offsets;
7927
7928 if (this->matrix_free->get_mapping_info()
7929 .face_data_by_cells[this->quadrature_index]
7930 .quadrature_point_offsets.empty() == false)
7931 {
7932 const unsigned int index =
7933 this->cell * GeometryInfo<dim>::faces_per_cell + this->face_numbers[0];
7935 this->matrix_free->get_mapping_info()
7936 .face_data_by_cells[this->quadrature_index]
7937 .quadrature_point_offsets.size());
7938 this->quadrature_points = this->matrix_free->get_mapping_info()
7939 .face_data_by_cells[this->quadrature_index]
7940 .quadrature_points.data() +
7941 this->matrix_free->get_mapping_info()
7942 .face_data_by_cells[this->quadrature_index]
7943 .quadrature_point_offsets[index];
7944 }
7945
7946 if constexpr (running_in_debug_mode())
7947 {
7948 this->is_reinitialized = true;
7949 this->dof_values_initialized = false;
7950 this->values_quad_initialized = false;
7951 this->gradients_quad_initialized = false;
7952 this->hessians_quad_initialized = false;
7953 }
7954}
7955
7956
7957
7958template <int dim,
7959 int fe_degree,
7960 int n_q_points_1d,
7961 int n_components_,
7962 typename Number,
7963 typename VectorizedArrayType>
7964inline void
7966 fe_degree,
7967 n_q_points_1d,
7968 n_components_,
7969 Number,
7970 VectorizedArrayType>::
7971 evaluate(const EvaluationFlags::EvaluationFlags evaluation_flag)
7972{
7973 if constexpr (running_in_debug_mode())
7974 {
7975 Assert(this->dof_values_initialized, ExcNotInitialized());
7976 }
7977
7978 evaluate(this->values_dofs, evaluation_flag);
7979}
7980
7981
7982
7983template <int dim,
7984 int fe_degree,
7985 int n_q_points_1d,
7986 int n_components_,
7987 typename Number,
7988 typename VectorizedArrayType>
7989inline void
7991 fe_degree,
7992 n_q_points_1d,
7993 n_components_,
7994 Number,
7995 VectorizedArrayType>::
7996 evaluate(const VectorizedArrayType *values_array,
7997 const EvaluationFlags::EvaluationFlags evaluation_flag)
7998{
7999 Assert((evaluation_flag &
8002 ExcMessage("Only EvaluationFlags::values, EvaluationFlags::gradients, "
8003 "and EvaluationFlags::hessians are supported."));
8004
8005 const bool hessians_on_general_cells =
8006 evaluation_flag & EvaluationFlags::hessians &&
8007 (this->cell_type > internal::MatrixFreeFunctions::affine);
8008 EvaluationFlags::EvaluationFlags evaluation_flag_actual = evaluation_flag;
8009 if (hessians_on_general_cells)
8010 evaluation_flag_actual |= EvaluationFlags::gradients;
8011
8012 if (this->data->element_type ==
8014 evaluation_flag & EvaluationFlags::gradients &&
8015 (this->cell_type > internal::MatrixFreeFunctions::affine))
8016 evaluation_flag_actual |= EvaluationFlags::values;
8017
8018 if constexpr (fe_degree > -1)
8020 template run<fe_degree, n_q_points_1d>(n_components,
8021 evaluation_flag_actual,
8022 values_array,
8023 *this);
8024 else
8026 n_components, evaluation_flag_actual, values_array, *this);
8027
8028 this->store_values_for_gradients(evaluation_flag);
8029
8030 if constexpr (running_in_debug_mode())
8031 {
8032 this->values_quad_initialized =
8033 evaluation_flag_actual & EvaluationFlags::values;
8034 this->gradients_quad_initialized =
8035 evaluation_flag_actual & EvaluationFlags::gradients;
8036 this->hessians_quad_initialized =
8037 evaluation_flag_actual & EvaluationFlags::hessians;
8038 }
8039}
8040
8041
8042
8043template <int dim,
8044 int fe_degree,
8045 int n_q_points_1d,
8046 int n_components_,
8047 typename Number,
8048 typename VectorizedArrayType>
8049inline void
8051 fe_degree,
8052 n_q_points_1d,
8053 n_components_,
8054 Number,
8055 VectorizedArrayType>::
8056 project_to_face(const EvaluationFlags::EvaluationFlags evaluation_flag)
8057{
8058 if constexpr (running_in_debug_mode())
8059 {
8060 Assert(this->dof_values_initialized, ExcNotInitialized());
8061 }
8062
8063 project_to_face(this->values_dofs, evaluation_flag);
8064}
8065
8066
8067
8068template <int dim,
8069 int fe_degree,
8070 int n_q_points_1d,
8071 int n_components_,
8072 typename Number,
8073 typename VectorizedArrayType>
8074inline void
8076 fe_degree,
8077 n_q_points_1d,
8078 n_components_,
8079 Number,
8080 VectorizedArrayType>::
8081 project_to_face(const VectorizedArrayType *values_array,
8082 const EvaluationFlags::EvaluationFlags evaluation_flag)
8083{
8084 Assert((evaluation_flag &
8087 ExcMessage("Only EvaluationFlags::values, EvaluationFlags::gradients, "
8088 "and EvaluationFlags::hessians are supported."));
8089
8090 const bool hessians_on_general_cells =
8091 evaluation_flag & EvaluationFlags::hessians &&
8092 (this->cell_type > internal::MatrixFreeFunctions::affine);
8093 EvaluationFlags::EvaluationFlags evaluation_flag_actual = evaluation_flag;
8094 if (hessians_on_general_cells)
8095 evaluation_flag_actual |= EvaluationFlags::gradients;
8096
8097 if (this->data->element_type ==
8099 evaluation_flag & EvaluationFlags::gradients &&
8100 (this->cell_type > internal::MatrixFreeFunctions::affine))
8101 evaluation_flag_actual |= EvaluationFlags::values;
8102
8103 if constexpr (fe_degree > -1)
8105 dim,
8106 VectorizedArrayType>::template run<fe_degree>(n_components,
8107 evaluation_flag_actual,
8108 values_array,
8109 *this);
8110 else
8112 project_to_face(n_components,
8113 evaluation_flag_actual,
8114 values_array,
8115 *this);
8116
8117 // face dofs initialized
8118}
8119
8120
8121
8122template <int dim,
8123 int fe_degree,
8124 int n_q_points_1d,
8125 int n_components_,
8126 typename Number,
8127 typename VectorizedArrayType>
8128inline void
8130 fe_degree,
8131 n_q_points_1d,
8132 n_components_,
8133 Number,
8134 VectorizedArrayType>::
8135 evaluate_in_face(const EvaluationFlags::EvaluationFlags evaluation_flag)
8136{
8137 Assert((evaluation_flag &
8140 ExcMessage("Only EvaluationFlags::values, EvaluationFlags::gradients, "
8141 "and EvaluationFlags::hessians are supported."));
8142
8143 const bool hessians_on_general_cells =
8144 evaluation_flag & EvaluationFlags::hessians &&
8145 (this->cell_type > internal::MatrixFreeFunctions::affine);
8146 EvaluationFlags::EvaluationFlags evaluation_flag_actual = evaluation_flag;
8147 if (hessians_on_general_cells)
8148 evaluation_flag_actual |= EvaluationFlags::gradients;
8149
8150 if (this->data->element_type ==
8152 evaluation_flag & EvaluationFlags::gradients &&
8153 (this->cell_type > internal::MatrixFreeFunctions::affine))
8154 evaluation_flag_actual |= EvaluationFlags::values;
8155
8156 if constexpr (fe_degree > -1)
8158 dim,
8159 VectorizedArrayType>::template run<fe_degree>(n_components,
8160 evaluation_flag_actual,
8161 *this);
8162 else
8164 evaluate_in_face(n_components, evaluation_flag_actual, *this);
8165
8166 this->store_values_for_gradients(evaluation_flag);
8167
8168 if constexpr (running_in_debug_mode())
8169 {
8170 this->values_quad_initialized =
8171 evaluation_flag_actual & EvaluationFlags::values;
8172 this->gradients_quad_initialized =
8173 evaluation_flag_actual & EvaluationFlags::gradients;
8174 this->hessians_quad_initialized =
8175 evaluation_flag_actual & EvaluationFlags::hessians;
8176 }
8177}
8178
8179
8180
8181template <int dim,
8182 int fe_degree,
8183 int n_q_points_1d,
8184 int n_components_,
8185 typename Number,
8186 typename VectorizedArrayType>
8187inline void
8189 fe_degree,
8190 n_q_points_1d,
8191 n_components_,
8192 Number,
8193 VectorizedArrayType>::
8194 integrate(const EvaluationFlags::EvaluationFlags integration_flag,
8195 const bool sum_into_values)
8196{
8197 integrate(integration_flag, this->values_dofs, sum_into_values);
8198
8199 if constexpr (running_in_debug_mode())
8200 {
8201 this->dof_values_initialized = true;
8202 }
8203}
8204
8205
8206
8207template <int dim,
8208 int fe_degree,
8209 int n_q_points_1d,
8210 int n_components_,
8211 typename Number,
8212 typename VectorizedArrayType>
8213inline void
8215 fe_degree,
8216 n_q_points_1d,
8217 n_components_,
8218 Number,
8219 VectorizedArrayType>::
8220 integrate(const EvaluationFlags::EvaluationFlags integration_flag,
8221 VectorizedArrayType *values_array,
8222 const bool sum_into_values)
8223{
8224 Assert((integration_flag &
8227 ExcMessage("Only EvaluationFlags::values, EvaluationFlags::gradients, "
8228 "and EvaluationFlags::hessians are supported."));
8229
8230 EvaluationFlags::EvaluationFlags integration_flag_actual = integration_flag;
8231 if (integration_flag & EvaluationFlags::hessians &&
8232 (this->cell_type > internal::MatrixFreeFunctions::affine))
8233 {
8234 unsigned int size = n_components * dim * n_q_points;
8235 if ((integration_flag & EvaluationFlags::gradients) != 0u)
8236 {
8237 for (unsigned int i = 0; i < size; ++i)
8238 this->gradients_quad[i] += this->gradients_from_hessians_quad[i];
8239 }
8240 else
8241 {
8242 for (unsigned int i = 0; i < size; ++i)
8243 this->gradients_quad[i] = this->gradients_from_hessians_quad[i];
8244 integration_flag_actual |= EvaluationFlags::gradients;
8245 }
8246 }
8247
8248 if (this->data->element_type ==
8250 integration_flag & EvaluationFlags::gradients &&
8251 this->cell_type > internal::MatrixFreeFunctions::affine &&
8252 this->divergence_is_requested == false)
8253 {
8254 unsigned int size = n_components * n_q_points;
8255 if ((integration_flag & EvaluationFlags::values) != 0u)
8256 {
8257 for (unsigned int i = 0; i < size; ++i)
8258 this->values_quad[i] += this->values_from_gradients_quad[i];
8259 }
8260 else
8261 {
8262 for (unsigned int i = 0; i < size; ++i)
8263 this->values_quad[i] = this->values_from_gradients_quad[i];
8264 integration_flag_actual |= EvaluationFlags::values;
8265 }
8266 }
8267
8268 if constexpr (fe_degree > -1)
8270 template run<fe_degree, n_q_points_1d>(n_components,
8271 integration_flag_actual,
8272 values_array,
8273 *this,
8274 sum_into_values);
8275 else
8277 n_components,
8278 integration_flag_actual,
8279 values_array,
8280 *this,
8281 sum_into_values);
8282}
8283
8284
8285
8286template <int dim,
8287 int fe_degree,
8288 int n_q_points_1d,
8289 int n_components_,
8290 typename Number,
8291 typename VectorizedArrayType>
8292inline void
8294 fe_degree,
8295 n_q_points_1d,
8296 n_components_,
8297 Number,
8298 VectorizedArrayType>::
8299 integrate_in_face(const EvaluationFlags::EvaluationFlags integration_flag)
8300{
8301 Assert((integration_flag &
8304 ExcMessage("Only EvaluationFlags::values, EvaluationFlags::gradients, "
8305 "and EvaluationFlags::hessians are supported."));
8306
8307 EvaluationFlags::EvaluationFlags integration_flag_actual = integration_flag;
8308 if (integration_flag & EvaluationFlags::hessians &&
8309 (this->cell_type > internal::MatrixFreeFunctions::affine))
8310 {
8311 unsigned int size = n_components * dim * n_q_points;
8312 if ((integration_flag & EvaluationFlags::gradients) != 0u)
8313 {
8314 for (unsigned int i = 0; i < size; ++i)
8315 this->gradients_quad[i] += this->gradients_from_hessians_quad[i];
8316 }
8317 else
8318 {
8319 for (unsigned int i = 0; i < size; ++i)
8320 this->gradients_quad[i] = this->gradients_from_hessians_quad[i];
8321 integration_flag_actual |= EvaluationFlags::gradients;
8322 }
8323 }
8324
8325 if (this->data->element_type ==
8327 integration_flag & EvaluationFlags::gradients &&
8328 this->cell_type > internal::MatrixFreeFunctions::affine &&
8329 this->divergence_is_requested == false)
8330 {
8331 unsigned int size = n_components * n_q_points;
8332 if ((integration_flag & EvaluationFlags::values) != 0u)
8333 {
8334 for (unsigned int i = 0; i < size; ++i)
8335 this->values_quad[i] += this->values_from_gradients_quad[i];
8336 }
8337 else
8338 {
8339 for (unsigned int i = 0; i < size; ++i)
8340 this->values_quad[i] = this->values_from_gradients_quad[i];
8341 integration_flag_actual |= EvaluationFlags::values;
8342 }
8343 }
8344
8345 if constexpr (fe_degree > -1)
8347 dim,
8348 VectorizedArrayType>::template run<fe_degree>(n_components,
8349 integration_flag_actual,
8350 *this);
8351 else
8353 integrate_in_face(n_components, integration_flag_actual, *this);
8354
8355 // face dofs initialized
8356}
8357
8358
8359
8360template <int dim,
8361 int fe_degree,
8362 int n_q_points_1d,
8363 int n_components_,
8364 typename Number,
8365 typename VectorizedArrayType>
8366inline void
8368 fe_degree,
8369 n_q_points_1d,
8370 n_components_,
8371 Number,
8372 VectorizedArrayType>::
8373 collect_from_face(const EvaluationFlags::EvaluationFlags integration_flag,
8374 const bool sum_into_values)
8375{
8376 collect_from_face(integration_flag, this->values_dofs, sum_into_values);
8377
8378 if constexpr (running_in_debug_mode())
8379 {
8380 this->dof_values_initialized = true;
8381 }
8382}
8383
8384
8385
8386template <int dim,
8387 int fe_degree,
8388 int n_q_points_1d,
8389 int n_components_,
8390 typename Number,
8391 typename VectorizedArrayType>
8392inline void
8394 fe_degree,
8395 n_q_points_1d,
8396 n_components_,
8397 Number,
8398 VectorizedArrayType>::
8399 collect_from_face(const EvaluationFlags::EvaluationFlags integration_flag,
8400 VectorizedArrayType *values_array,
8401 const bool sum_into_values)
8402{
8403 Assert((integration_flag &
8406 ExcMessage("Only EvaluationFlags::values, EvaluationFlags::gradients, "
8407 "and EvaluationFlags::hessians are supported."));
8408
8409 EvaluationFlags::EvaluationFlags integration_flag_actual = integration_flag;
8410 if (integration_flag & EvaluationFlags::hessians &&
8411 (this->cell_type > internal::MatrixFreeFunctions::affine))
8412 integration_flag_actual |= EvaluationFlags::gradients;
8413
8414 if (this->data->element_type ==
8416 integration_flag & EvaluationFlags::gradients &&
8417 this->cell_type > internal::MatrixFreeFunctions::affine &&
8418 this->divergence_is_requested == false)
8419 integration_flag_actual |= EvaluationFlags::values;
8420
8421 if constexpr (fe_degree > -1)
8423 dim,
8424 VectorizedArrayType>::template run<fe_degree>(n_components,
8425 integration_flag_actual,
8426 values_array,
8427 *this,
8428 sum_into_values);
8429 else
8431 collect_from_face(n_components,
8432 integration_flag_actual,
8433 values_array,
8434 *this,
8435 sum_into_values);
8436}
8437
8438
8439
8440template <int dim,
8441 int fe_degree,
8442 int n_q_points_1d,
8443 int n_components_,
8444 typename Number,
8445 typename VectorizedArrayType>
8446template <typename VectorType>
8447inline void
8449 fe_degree,
8450 n_q_points_1d,
8451 n_components_,
8452 Number,
8453 VectorizedArrayType>::
8454 gather_evaluate(const VectorType &input_vector,
8455 const EvaluationFlags::EvaluationFlags evaluation_flag)
8456{
8457 Assert((evaluation_flag &
8460 ExcMessage("Only EvaluationFlags::values, EvaluationFlags::gradients, "
8461 "and EvaluationFlags::hessians are supported."));
8462
8463 const auto shared_vector_data = internal::get_shared_vector_data(
8464 &input_vector,
8465 this->dof_access_index ==
8467 this->active_fe_index,
8468 this->dof_info);
8469
8470 if (this->data->data.front().fe_degree > 0 &&
8471 fast_evaluation_supported(this->data->data.front().fe_degree,
8472 this->data->data.front().n_q_points_1d) &&
8474 dim,
8475 typename VectorType::value_type,
8476 VectorizedArrayType>::
8477 supports(evaluation_flag,
8478 *this->data,
8479 internal::get_beginning<typename VectorType::value_type>(
8480 input_vector),
8481 this->dof_info->index_storage_variants[this->dof_access_index]
8482 [this->cell]))
8483 {
8484 if constexpr (fe_degree > -1)
8485 {
8487 dim,
8488 typename VectorType::value_type,
8489 VectorizedArrayType>::template run<fe_degree,
8490 n_q_points_1d>(
8491 n_components,
8492 evaluation_flag,
8493 internal::get_beginning<typename VectorType::value_type>(
8494 input_vector),
8495 shared_vector_data,
8496 *this);
8497 }
8498 else
8499 {
8501 dim,
8502 typename VectorType::value_type,
8503 VectorizedArrayType>::evaluate(n_components,
8504 evaluation_flag,
8505 internal::get_beginning<
8506 typename VectorType::value_type>(
8507 input_vector),
8508 shared_vector_data,
8509 *this);
8510 }
8511 }
8512 else
8513 {
8514 this->read_dof_values(input_vector);
8515 this->evaluate(evaluation_flag);
8516 }
8517
8518 if constexpr (running_in_debug_mode())
8519 {
8520 this->values_quad_initialized = evaluation_flag & EvaluationFlags::values;
8521 this->gradients_quad_initialized =
8522 evaluation_flag & EvaluationFlags::gradients;
8523 this->hessians_quad_initialized =
8524 evaluation_flag & EvaluationFlags::hessians;
8525 }
8526}
8527
8528
8529
8530template <int dim,
8531 int fe_degree,
8532 int n_q_points_1d,
8533 int n_components_,
8534 typename Number,
8535 typename VectorizedArrayType>
8536template <typename VectorType>
8537inline void
8539 dim,
8540 fe_degree,
8541 n_q_points_1d,
8542 n_components_,
8543 Number,
8544 VectorizedArrayType>::integrate_scatter(const bool integrate_values,
8545 const bool integrate_gradients,
8546 VectorType &destination)
8547{
8549 ((integrate_values) ? EvaluationFlags::values : EvaluationFlags::nothing) |
8550 ((integrate_gradients) ? EvaluationFlags::gradients :
8552
8553 integrate_scatter(flag, destination);
8554}
8555
8556
8557
8558template <int dim,
8559 int fe_degree,
8560 int n_q_points_1d,
8561 int n_components_,
8562 typename Number,
8563 typename VectorizedArrayType>
8564template <typename VectorType>
8565inline void
8567 fe_degree,
8568 n_q_points_1d,
8569 n_components_,
8570 Number,
8571 VectorizedArrayType>::
8572 integrate_scatter(const EvaluationFlags::EvaluationFlags integration_flag,
8573 VectorType &destination)
8574{
8575 Assert((this->dof_access_index ==
8577 this->is_interior_face() == false) == false,
8579
8580 const auto shared_vector_data = internal::get_shared_vector_data(
8581 &destination,
8582 this->dof_access_index ==
8584 this->active_fe_index,
8585 this->dof_info);
8586
8587 if (this->data->data.front().fe_degree > 0 &&
8588 fast_evaluation_supported(this->data->data.front().fe_degree,
8589 this->data->data.front().n_q_points_1d) &&
8591 dim,
8592 typename VectorType::value_type,
8593 VectorizedArrayType>::
8594 supports(integration_flag,
8595 *this->data,
8596 internal::get_beginning<typename VectorType::value_type>(
8597 destination),
8598 this->dof_info->index_storage_variants[this->dof_access_index]
8599 [this->cell]))
8600 {
8601 if constexpr (fe_degree > -1)
8602 {
8604 dim,
8605 typename VectorType::value_type,
8606 VectorizedArrayType>::template run<fe_degree,
8607 n_q_points_1d>(
8608 n_components,
8609 integration_flag,
8610 internal::get_beginning<typename VectorType::value_type>(
8611 destination),
8612 shared_vector_data,
8613 *this);
8614 }
8615 else
8616 {
8618 dim,
8619 typename VectorType::value_type,
8620 VectorizedArrayType>::integrate(n_components,
8621 integration_flag,
8622 internal::get_beginning<
8623 typename VectorType::value_type>(
8624 destination),
8625 shared_vector_data,
8626 *this);
8627 }
8628 }
8629 else
8630 {
8631 integrate(integration_flag);
8632 this->distribute_local_to_global(destination);
8633 }
8634}
8635
8636
8637
8638template <int dim,
8639 int fe_degree,
8640 int n_q_points_1d,
8641 int n_components_,
8642 typename Number,
8643 typename VectorizedArrayType>
8646 fe_degree,
8647 n_q_points_1d,
8648 n_components_,
8649 Number,
8650 VectorizedArrayType>::dof_indices() const
8651{
8653 0U, dofs_per_cell);
8654}
8655
8656
8657
8658template <int dim,
8659 int fe_degree,
8660 int n_q_points_1d,
8661 int n_components_,
8662 typename Number,
8663 typename VectorizedArrayType>
8664bool
8665FEEvaluation<dim,
8666 fe_degree,
8667 n_q_points_1d,
8668 n_components_,
8669 Number,
8670 VectorizedArrayType>::
8671 fast_evaluation_supported(const unsigned int given_degree,
8672 const unsigned int given_n_q_points_1d)
8673{
8674 return fe_degree == -1 ?
8676 fast_evaluation_supported(given_degree, given_n_q_points_1d) :
8677 true;
8678}
8679
8680
8681
8682template <int dim,
8683 int fe_degree,
8684 int n_q_points_1d,
8685 int n_components_,
8686 typename Number,
8687 typename VectorizedArrayType>
8688bool
8690 fe_degree,
8691 n_q_points_1d,
8692 n_components_,
8693 Number,
8694 VectorizedArrayType>::
8695 fast_evaluation_supported(const unsigned int given_degree,
8696 const unsigned int given_n_q_points_1d)
8697{
8698 return fe_degree == -1 ?
8700 fast_evaluation_supported(given_degree, given_n_q_points_1d) :
8701 true;
8702}
8703
8704
8705
8706template <int dim,
8707 int fe_degree,
8708 int n_q_points_1d,
8709 int n_components_,
8710 typename Number,
8711 typename VectorizedArrayType>
8712bool
8714 fe_degree,
8715 n_q_points_1d,
8716 n_components_,
8717 Number,
8718 VectorizedArrayType>::at_boundary() const
8719{
8720 Assert(this->dof_access_index !=
8723
8724 if (this->is_interior_face() == false)
8725 return false;
8726 else if (this->cell < this->matrix_free->n_inner_face_batches())
8727 return false;
8728 else if (this->cell < (this->matrix_free->n_inner_face_batches() +
8729 this->matrix_free->n_boundary_face_batches()))
8730 return true;
8731 else
8732 return false;
8733}
8734
8735
8736
8737template <int dim,
8738 int fe_degree,
8739 int n_q_points_1d,
8740 int n_components_,
8741 typename Number,
8742 typename VectorizedArrayType>
8745 fe_degree,
8746 n_q_points_1d,
8747 n_components_,
8748 Number,
8749 VectorizedArrayType>::boundary_id() const
8750{
8751 Assert(this->dof_access_index !=
8754
8755 if (at_boundary())
8756 return this->matrix_free->get_boundary_id(this->cell);
8757 else
8759}
8760
8761
8762
8763template <int dim,
8764 int fe_degree,
8765 int n_q_points_1d,
8766 int n_components_,
8767 typename Number,
8768 typename VectorizedArrayType>
8769unsigned int
8771 dim,
8772 fe_degree,
8773 n_q_points_1d,
8774 n_components_,
8775 Number,
8776 VectorizedArrayType>::get_dofs_per_component_projected_to_face()
8777{
8778 return this->data->dofs_per_component_on_face;
8779}
8780
8781
8782
8783template <int dim,
8784 int fe_degree,
8785 int n_q_points_1d,
8786 int n_components_,
8787 typename Number,
8788 typename VectorizedArrayType>
8789unsigned int
8791 fe_degree,
8792 n_q_points_1d,
8793 n_components_,
8794 Number,
8795 VectorizedArrayType>::get_dofs_projected_to_face()
8796{
8797 return this->data->dofs_per_component_on_face * n_components_;
8798}
8799
8800
8801
8802/*------------------------- end FEFaceEvaluation ------------------------- */
8803
8804
8805#endif // ifndef DOXYGEN
8806
8807
8809
8810#endif
*  *  iterator begin()
value_type get_dof_value(const unsigned int dof) const
void read_write_operation_global(const VectorOperation &operation, const std::array< VectorType *, n_components_ > &vectors) const
value_type get_laplacian(const unsigned int q_point) const
AlignedVector< VectorizedArrayType > * scratch_data_array
gradient_type get_gradient(const unsigned int q_point) const
void submit_gradient(const Tensor< 2, 1, VectorizedArrayType > val_in, const unsigned int q_point)
void submit_normal_hessian(const value_type normal_hessian_in, const unsigned int q_point)
internal::CurlType< dim, VectorizedArrayType > curl_type
static constexpr unsigned int dimension
void read_write_operation(const VectorOperation &operation, const std::array< VectorType *, n_components_ > &vectors, const std::array< const std::vector< ArrayView< const typename VectorType::value_type > > *, n_components_ > &vectors_sm, const std::bitset< n_lanes > &mask, const bool apply_constraints=true) const
void submit_gradient(const gradient_type grad_in, const unsigned int q_point)
void submit_value(const value_type val_in, const unsigned int q_point)
void submit_divergence(const VectorizedArrayType div_in, const unsigned int q_point)
void submit_dof_value(const value_type val_in, const unsigned int dof)
std::vector< types::global_dof_index > local_dof_indices
void store_values_for_gradients(const EvaluationFlags::EvaluationFlags evaluation_flag)
void distribute_local_to_global(VectorType &dst, const unsigned int first_index=0, const std::bitset< n_lanes > &mask=std::bitset< n_lanes >().flip()) const
std::conditional_t< n_components_==1, Tensor< 2, dim, VectorizedArrayType >, std::conditional_t< n_components_==dim, Tensor< 3, dim, VectorizedArrayType >, Tensor< 1, n_components_, Tensor< 2, dim, VectorizedArrayType > > > > hessian_type
std::conditional_t< n_components_==1, Tensor< 1, dim, VectorizedArrayType >, std::conditional_t< n_components_==dim, Tensor< 2, dim, VectorizedArrayType >, Tensor< 1, n_components_, Tensor< 1, dim, VectorizedArrayType > > > > gradient_type
FEEvaluationBase(const MatrixFree< dim, Number, VectorizedArrayType > &matrix_free, const unsigned int dof_handler_index, const unsigned int first_selected_component, const unsigned int quadrature_index, const unsigned int fe_degree, const unsigned int n_q_points, const bool is_interior_face, const unsigned int active_fe_index, const unsigned int active_quad_index, const unsigned int face_type)
void read_dof_values_plain(const VectorType &src, const unsigned int first_index=0, const std::bitset< n_lanes > &mask=std::bitset< n_lanes >().flip())
curl_type get_curl(const unsigned int q_point) const
VectorizedArrayType get_divergence(const unsigned int q_point) const
hessian_type get_hessian(const unsigned int q_point) const
FEEvaluationBase(const Mapping< dim > &mapping, const FiniteElement< dim > &fe, const Quadrature< 1 > &quadrature, const UpdateFlags update_flags, const unsigned int first_selected_component, const FEEvaluationData< dim, VectorizedArrayType, is_face > *other)
void submit_curl(const curl_type curl_in, const unsigned int q_point)
FEEvaluationBase & operator=(const FEEvaluationBase &other)
SymmetricTensor< 2, dim, VectorizedArrayType > get_symmetric_gradient(const unsigned int q_point) const
static constexpr unsigned int n_components
void submit_symmetric_gradient(const SymmetricTensor< 2, dim, VectorizedArrayType > grad_in, const unsigned int q_point)
gradient_type get_hessian_diagonal(const unsigned int q_point) const
void submit_value(const Tensor< 1, 1, VectorizedArrayType > val_in, const unsigned int q_point)
std::conditional_t< n_components_==1, VectorizedArrayType, Tensor< 1, n_components_, VectorizedArrayType > > value_type
const MatrixFree< dim, Number, VectorizedArrayType > & get_matrix_free() const
void apply_hanging_node_constraints(const bool transpose) const
void set_dof_values_plain(VectorType &dst, const unsigned int first_index=0, const std::bitset< n_lanes > &mask=std::bitset< n_lanes >().flip()) const
void submit_normal_derivative(const value_type grad_in, const unsigned int q_point)
void read_write_operation_contiguous(const VectorOperation &operation, const std::array< VectorType *, n_components_ > &vectors, const std::array< const std::vector< ArrayView< const typename VectorType::value_type > > *, n_components_ > &vectors_sm, const std::bitset< n_lanes > &mask) const
value_type integrate_value() const
FEEvaluationBase(const FEEvaluationBase &other)
void submit_hessian(const hessian_type hessian_in, const unsigned int q_point)
void set_dof_values(VectorType &dst, const unsigned int first_index=0, const std::bitset< n_lanes > &mask=std::bitset< n_lanes >().flip()) const
static constexpr unsigned int n_lanes
const MatrixFree< dim, Number, VectorizedArrayType > * matrix_free
value_type get_normal_derivative(const unsigned int q_point) const
value_type get_value(const unsigned int q_point) const
value_type get_normal_hessian(const unsigned int q_point) const
void read_dof_values(const VectorType &src, const unsigned int first_index=0, const std::bitset< n_lanes > &mask=std::bitset< n_lanes >().flip())
const MappingInfoStorageType::QuadratureDescriptor * descriptor
const MappingInfoStorageType * mapping_data
const ShapeInfoType * data
std::shared_ptr< internal::MatrixFreeFunctions::MappingDataOnTheFly< dim, Number > > mapped_geometry
const DoFInfo * dof_info
FEEvaluationData & operator=(const FEEvaluationData &other)
const unsigned int dofs_per_component
std_cxx20::ranges::iota_view< unsigned int, unsigned int > dof_indices() const
FEEvaluation(const Mapping< dim > &mapping, const FiniteElement< dim > &fe, const Quadrature< 1 > &quadrature, const UpdateFlags update_flags, const unsigned int first_selected_component=0)
const unsigned int n_q_points
FEEvaluation(const FiniteElement< dim > &fe, const Quadrature< 1 > &quadrature, const UpdateFlags update_flags, const unsigned int first_selected_component=0)
void reinit(const typename Triangulation< dim >::cell_iterator &cell)
static bool fast_evaluation_supported(const unsigned int given_degree, const unsigned int given_n_q_points_1d)
void integrate_scatter(const EvaluationFlags::EvaluationFlags integration_flag, VectorType &output_vector)
void reinit(const unsigned int cell_batch_index)
void reinit(const std::array< unsigned int, n_lanes > &cell_ids)
FEEvaluation(const FiniteElement< dim > &fe, const FEEvaluationData< dim, VectorizedArrayType, false > &other, const unsigned int first_selected_component=0)
void reinit(const TriaIterator< DoFCellAccessor< dim, dim, level_dof_access > > &cell)
void evaluate(const EvaluationFlags::EvaluationFlags evaluation_flag)
FEEvaluation(const MatrixFree< dim, Number, VectorizedArrayType > &matrix_free, const unsigned int dof_handler_index=0, const unsigned int quadrature_index=0, const unsigned int first_selected_component=0, const unsigned int active_fe_index=numbers::invalid_unsigned_int, const unsigned int active_quad_index=numbers::invalid_unsigned_int)
static constexpr unsigned int tensor_dofs_per_cell
void evaluate(const VectorizedArrayType *values_array, const EvaluationFlags::EvaluationFlags evaluation_flag)
typename BaseClass::gradient_type gradient_type
void integrate(const EvaluationFlags::EvaluationFlags integration_flag, VectorizedArrayType *values_array, const bool sum_into_values=false)
FEEvaluation(const MatrixFree< dim, Number, VectorizedArrayType > &matrix_free, const std::pair< unsigned int, unsigned int > &range, const unsigned int dof_handler_index=0, const unsigned int quadrature_index=0, const unsigned int first_selected_component=0)
static constexpr unsigned int dimension
void gather_evaluate(const VectorType &input_vector, const EvaluationFlags::EvaluationFlags evaluation_flag)
const unsigned int dofs_per_cell
static constexpr unsigned int static_dofs_per_cell
typename BaseClass::value_type value_type
FEEvaluation & operator=(const FEEvaluation &other)
void integrate(const EvaluationFlags::EvaluationFlags integration_flag)
static constexpr unsigned int n_components
static constexpr unsigned int static_n_q_points
static constexpr unsigned int n_lanes
FEEvaluation(const FEEvaluation &other)
void check_template_arguments(const unsigned int fe_no, const unsigned int first_selected_component)
static constexpr unsigned int static_dofs_per_component
typename BaseClass::value_type value_type
std_cxx20::ranges::iota_view< unsigned int, unsigned int > dof_indices() const
void integrate(const EvaluationFlags::EvaluationFlags integration_flag, VectorizedArrayType *values_array, const bool sum_into_values=false)
FEFaceEvaluation(const MatrixFree< dim, Number, VectorizedArrayType > &matrix_free, const std::pair< unsigned int, unsigned int > &range, const bool is_interior_face=true, const unsigned int dof_handler_index=0, const unsigned int quadrature_index=0, const unsigned int first_selected_component=0)
void collect_from_face(const EvaluationFlags::EvaluationFlags integration_flag, VectorizedArrayType *values_array, const bool sum_into_values=false)
bool at_boundary() const
void integrate_scatter(const EvaluationFlags::EvaluationFlags integration_flag, VectorType &output_vector)
static constexpr unsigned int static_n_q_points_cell
void project_to_face(const EvaluationFlags::EvaluationFlags evaluation_flag)
static constexpr unsigned int tensor_dofs_per_cell
unsigned int get_dofs_per_component_projected_to_face()
void project_to_face(const VectorizedArrayType *values_array, const EvaluationFlags::EvaluationFlags evaluation_flag)
const unsigned int dofs_per_component
void reinit(const unsigned int face_batch_number)
const unsigned int n_q_points
void gather_evaluate(const VectorType &input_vector, const EvaluationFlags::EvaluationFlags evaluation_flag)
void reinit(const unsigned int cell_batch_number, const unsigned int face_number)
static bool fast_evaluation_supported(const unsigned int given_degree, const unsigned int given_n_q_points_1d)
void evaluate(const VectorizedArrayType *values_array, const EvaluationFlags::EvaluationFlags evaluation_flag)
const unsigned int dofs_per_cell
static constexpr unsigned int n_components
FEFaceEvaluation(const MatrixFree< dim, Number, VectorizedArrayType > &matrix_free, const bool is_interior_face=true, const unsigned int dof_handler_index=0, const unsigned int quadrature_index=0, const unsigned int first_selected_component=0, const unsigned int active_fe_index=numbers::invalid_unsigned_int, const unsigned int active_quad_index=numbers::invalid_unsigned_int, const unsigned int face_type=numbers::invalid_unsigned_int)
void evaluate(const EvaluationFlags::EvaluationFlags evaluation_flag)
void collect_from_face(const EvaluationFlags::EvaluationFlags integration_flag, const bool sum_into_values=false)
static constexpr unsigned int static_dofs_per_component
static constexpr unsigned int n_lanes
static constexpr unsigned int static_n_q_points
unsigned int get_dofs_projected_to_face()
static constexpr unsigned int dimension
typename BaseClass::gradient_type gradient_type
types::boundary_id boundary_id() const
void integrate(const EvaluationFlags::EvaluationFlags integration_flag, const bool sum_into_values=false)
void evaluate_in_face(const EvaluationFlags::EvaluationFlags evaluation_flag)
void integrate_scatter(const bool integrate_values, const bool integrate_gradients, VectorType &output_vector)
static constexpr unsigned int static_dofs_per_cell
void integrate_in_face(const EvaluationFlags::EvaluationFlags integration_flag)
std::pair< unsigned int, unsigned int > component_to_base_index(const unsigned int component) const
unsigned int element_multiplicity(const unsigned int index) const
Abstract base class for mapping classes.
Definition mapping.h:318
const internal::MatrixFreeFunctions::TaskInfo & get_task_info() const
types::boundary_id get_boundary_id(const unsigned int face_batch_index) const
const Table< 3, unsigned int > & get_cell_and_face_to_plain_faces() const
unsigned int n_inner_face_batches() const
unsigned int n_active_entries_per_cell_batch(const unsigned int cell_batch_index) const
const internal::MatrixFreeFunctions::FaceToCellTopology< VectorizedArrayType::size()> & get_face_info(const unsigned int face_batch_index) const
const internal::MatrixFreeFunctions::DoFInfo & get_dof_info(const unsigned int dof_handler_index_component=0) const
AlignedVector< VectorizedArrayType > * acquire_scratch_data() const
const Number * constraint_pool_begin(const unsigned int pool_index) const
void release_scratch_data(const AlignedVector< VectorizedArrayType > *memory) const
DoFHandler< dim >::cell_iterator get_cell_iterator(const unsigned int cell_batch_index, const unsigned int lane_index, const unsigned int dof_handler_index=0) const
const internal::MatrixFreeFunctions::MappingInfo< dim, Number, VectorizedArrayType > & get_mapping_info() const
bool indices_initialized() const
const Number * constraint_pool_end(const unsigned int pool_index) const
unsigned int n_components() const
unsigned int n_active_entries_per_face_batch(const unsigned int face_batch_index) const
const internal::MatrixFreeFunctions::ShapeInfo< Number > & get_shape_info(const unsigned int dof_handler_index_component=0, const unsigned int quad_index=0, const unsigned int fe_base_element=0, const unsigned int hp_active_fe_index=0, const unsigned int hp_active_quad_index=0) const
unsigned int n_base_elements(const unsigned int dof_handler_index) const
Definition point.h:111
constexpr const Number & access_raw_entry(const unsigned int unrolled_index) const
#define DEAL_II_ALWAYS_INLINE
Definition config.h:166
#define DEAL_II_OPENMP_SIMD_PRAGMA
Definition config.h:214
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:38
constexpr bool running_in_debug_mode()
Definition config.h:76
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
DerivativeForm< 1, spacedim, dim, Number > transpose(const DerivativeForm< 1, dim, spacedim, Number > &DF)
#define DEAL_II_NOT_IMPLEMENTED()
Point< 2 > second
Definition grid_out.cc:4640
Point< 2 > first
Definition grid_out.cc:4639
unsigned int cell_index
static ::ExceptionBase & ExcNotImplemented()
#define Assert(cond, exc)
#define AssertDimension(dim1, dim2)
#define AssertIndexRange(index, range)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcAccessToUninitializedField()
static ::ExceptionBase & ExcIndexRange(std::size_t arg1, std::size_t arg2, std::size_t arg3)
static ::ExceptionBase & ExcNotInitialized()
static ::ExceptionBase & ExcMatrixFreeAccessToUninitializedMappingField(std::string arg1)
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
UpdateFlags
@ update_jacobian_grads
Gradient of volume element.
@ update_quadrature_points
Transformed quadrature points.
std::vector< index_type > data
Definition mpi.cc:734
std::size_t size
Definition mpi.cc:733
The namespace for the EvaluationFlags enum.
EvaluationFlags
The EvaluationFlags enum.
Tpetra::Vector< Number, LO, GO, NodeType< MemorySpace > > VectorType
std::enable_if_t< IsBlockVector< VectorType >::value, unsigned int > n_blocks(const VectorType &vector)
Definition operators.h:47
Point< spacedim > point(const gp_Pnt &p, const double tolerance=1e-10)
Definition utilities.cc:190
void quadrature_points(const Triangulation< dim, spacedim > &triangulation, const Quadrature< dim > &quadrature, const std::vector< std::vector< BoundingBox< spacedim > > > &global_bounding_boxes, ParticleHandler< dim, spacedim > &particle_handler, const Mapping< dim, spacedim > &mapping=(ReferenceCells::get_hypercube< dim >() .template get_default_linear_mapping< spacedim >()), const std::vector< std::vector< double > > &properties={})
SymmetricTensor< 2, dim, Number > e(const Tensor< 2, dim, Number > &F)
SymmetricTensor< 2, dim, Number > d(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
*  *  *  ScaleZFunction< dim, Number, components >::ScaleZFunction *  component(component)
*  *  *  RotationFunction< dim, Number >::RotationFunction Number(dim)
*  *  *  *  *  *  TimeRateUpdateFlags TimeRateRequest< ValueType, dim, Number >  get_update_flags() const
*  *  *  *  std::vector< Number > ThermoPlasticMaterial< dim, ViscoplasticYieldLaw, Number >::get_state_parameters   const
constexpr const ReferenceCell< dim > & get_hypercube()
T sum(const T &t, const MPI_Comm mpi_communicator)
std::string int_to_string(const unsigned int value, const unsigned int digits=numbers::invalid_unsigned_int)
Definition utilities.cc:464
constexpr T pow(const T base, const int iexp)
Definition utilities.h:966
void run(const Iterator &begin, const std_cxx20::type_identity_t< Iterator > &end, Worker worker, Copier copier, const ScratchData &sample_scratch_data, const CopyData &sample_copy_data, const unsigned int queue_length, const unsigned int chunk_size)
constexpr compressed_constraint_kind unconstrained_compressed_constraint_kind
std::conditional_t< dim==3, Tensor< 1, 3, NumberType >, std::conditional_t< dim==2, NumberType, std::monostate > > CurlType
void reinit(MatrixBlock< MatrixType > &v, const BlockSparsityPattern &p)
void check_vector_compatibility(const VectorType &vec, const MatrixFree< dim, Number, VectorizedArrayType > &, const internal::MatrixFreeFunctions::DoFInfo &dof_info)
constexpr types::geometric_orientation invalid_geometric_orientation
Definition types.h:369
constexpr unsigned int invalid_unsigned_int
Definition types.h:228
constexpr types::boundary_id internal_face_boundary_id
Definition types.h:319
constexpr types::geometric_orientation default_geometric_orientation
Definition types.h:342
boost::integer_range< IncrementableType > iota_view
Definition iota_view.h:43
STL namespace.
::VectorizedArray< Number, width > max(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > pow(const ::VectorizedArray< Number, width > &, const Number p)
std::uint8_t geometric_orientation
Definition types.h:38
static bool fast_evaluation_supported(const unsigned int given_degree, const unsigned int n_q_points_1d)
static void evaluate(const unsigned int n_components, const EvaluationFlags::EvaluationFlags evaluation_flag, const Number *values_dofs, FEEvaluationData< dim, Number, false > &fe_eval)
static void integrate(const unsigned int n_components, const EvaluationFlags::EvaluationFlags integration_flag, Number *values_dofs, FEEvaluationData< dim, Number, false > &fe_eval, const bool sum_into_values_array)
static void apply(const unsigned int n_components, const unsigned int fe_degree, const MatrixFreeFunctions::ShapeInfo< Number > &shape_info, const bool transpose, const std::array< MatrixFreeFunctions::compressed_constraint_kind, VectorizedArrayType::size()> &c_mask, VectorizedArrayType *values)
static void integrate(const unsigned int n_components, const EvaluationFlags::EvaluationFlags integration_flag, Number *values_dofs, FEEvaluationData< dim, Number, true > &fe_eval, const bool sum_into_values)
static void evaluate(const unsigned int n_components, const EvaluationFlags::EvaluationFlags evaluation_flag, const Number *values_dofs, FEEvaluationData< dim, Number, true > &fe_eval)
static bool fast_evaluation_supported(const unsigned int given_degree, const unsigned int n_q_points_1d)
static void evaluate_in_face(const unsigned int n_components, const EvaluationFlags::EvaluationFlags evaluation_flag, FEEvaluationData< dim, Number, true > &fe_eval)
static void integrate_in_face(const unsigned int n_components, const EvaluationFlags::EvaluationFlags integration_flag, FEEvaluationData< dim, Number, true > &fe_eval)
static void collect_from_face(const unsigned int n_components, const EvaluationFlags::EvaluationFlags integration_flag, Number *values_dofs, FEEvaluationData< dim, Number, true > &fe_eval, const bool sum_into_values)
static void project_to_face(const unsigned int n_components, const EvaluationFlags::EvaluationFlags evaluation_flag, const Number *values_dofs, FEEvaluationData< dim, Number, true > &fe_eval)
std::vector< std::pair< unsigned short, unsigned short > > constraint_indicator
Definition dof_info.h:536
std::vector< std::pair< unsigned int, unsigned int > > row_starts
Definition dof_info.h:495
std::vector< std::vector< unsigned int > > component_dof_indices_offset
Definition dof_info.h:688
unsigned int fe_index_from_degree(const unsigned int first_selected_component, const unsigned int fe_degree) const
std::vector< unsigned int > dof_indices
Definition dof_info.h:512
std::vector< compressed_constraint_kind > hanging_node_constraint_masks
Definition dof_info.h:524
std::array< std::vector< unsigned int >, 3 > dof_indices_interleave_strides
Definition dof_info.h:572
std::array< std::vector< std::pair< unsigned int, unsigned int > >, 3 > dof_indices_contiguous_sm
Definition dof_info.h:562
std::vector< unsigned int > row_starts_plain_indices
Definition dof_info.h:635
std::vector< unsigned int > component_to_base_index
Definition dof_info.h:675
std::array< std::vector< unsigned int >, 3 > dof_indices_contiguous
Definition dof_info.h:551
std::vector< unsigned int > plain_dof_indices
Definition dof_info.h:645
std::array< std::vector< unsigned char >, 3 > n_vectorization_lanes_filled
Definition dof_info.h:583
std::vector< unsigned int > dof_indices_interleaved
Definition dof_info.h:541
std::array< std::vector< IndexStorageVariants >, 3 > index_storage_variants
Definition dof_info.h:487
unsigned int quad_index_from_n_q_points(const unsigned int n_q_points) const
std::vector< unsigned int > face_partition_data
Definition task_info.h:494
constexpr Number determinant(const SymmetricTensor< 2, dim, Number > &)
constexpr SymmetricTensor< 2, dim, Number > invert(const SymmetricTensor< 2, dim, Number > &)
constexpr SymmetricTensor< 4, dim, Number > outer_product(const SymmetricTensor< 2, dim, Number > &t1, const SymmetricTensor< 2, dim, Number > &t2)