version GIT relicensing-7278-g091132d5eb 2026-12-02 03:10: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
ad_helpers.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) 2018 - 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#ifndef dealii_differentiation_ad_ad_helpers_h
14#define dealii_differentiation_ad_ad_helpers_h
15
16#include <deal.II/base/config.h>
17
18#if defined(DEAL_II_WITH_ADOLC) || defined(DEAL_II_TRILINOS_WITH_SACADO)
19
20# include <deal.II/base/numbers.h>
22# include <deal.II/base/tensor.h>
23
30
32
34# include <deal.II/lac/vector.h>
35
36# include <algorithm>
37# include <iostream>
38# include <iterator>
39# include <numeric>
40
41#endif // defined(DEAL_II_WITH_ADOLC) || defined(DEAL_II_TRILINOS_WITH_SACADO)
42
44
45#if defined(DEAL_II_WITH_ADOLC) || defined(DEAL_II_TRILINOS_WITH_SACADO)
46namespace Differentiation
47{
48 namespace AD
49 {
167 template <enum AD::NumberTypes ADNumberTypeCode,
168 typename ScalarType = double>
170 {
171 public:
178
183 using ad_type =
185
205 HelperBase(const unsigned int n_independent_variables,
206 const unsigned int n_dependent_variables);
207
211 virtual ~HelperBase() = default;
212
224 std::size_t
226
231 std::size_t
232 n_dependent_variables() const;
233
242 void
243 print(std::ostream &stream) const;
244
251 void
252 print_values(std::ostream &stream) const;
253
264 void
265 print_tape_stats(const typename Types<ad_type>::tape_index tape_index,
266 std::ostream &stream) const;
267
293 static void
295 const bool ensure_persistent_setting = true);
296
339 virtual void
340 reset(const unsigned int n_independent_variables =
342 const unsigned int n_dependent_variables =
344 const bool clear_registered_tapes = true);
345
350 bool
351 is_recording() const;
352
358 active_tape_index() const;
359
364 bool
366 const typename Types<ad_type>::tape_index tape_index) const;
367
393 void
395 const typename Types<ad_type>::tape_buffer_sizes obufsize = 64 * 1024 *
396 1024,
397 const typename Types<ad_type>::tape_buffer_sizes lbufsize = 64 * 1024 *
398 1024,
399 const typename Types<ad_type>::tape_buffer_sizes vbufsize = 64 * 1024 *
400 1024,
401 const typename Types<ad_type>::tape_buffer_sizes tbufsize = 64 * 1024 *
402 1024);
403
449 bool
451 const typename Types<ad_type>::tape_index tape_index,
452 const bool overwrite_tape = false,
453 const bool keep_independent_values = true);
454
466 void
467 stop_recording_operations(const bool write_tapes_to_file = false);
468
478 void
480 const typename Types<ad_type>::tape_index tape_index);
481
521 bool
523 const typename Types<ad_type>::tape_index tape_index) const;
524
564 bool
566
574 void
576
579 protected:
592
600
617 void
618 activate_tape(const typename Types<ad_type>::tape_index tape_index,
619 const bool read_mode);
620
635 mutable std::vector<scalar_type> independent_variable_values;
636
645 mutable std::vector<ad_type> independent_variables;
646
652
658
664 void
666
673 void
674 set_sensitivity_value(const unsigned int index, const scalar_type &value);
675
694 void
695 mark_independent_variable(const unsigned int index, ad_type &out) const;
696
707 void
709
719 void
720 initialize_non_sensitive_independent_variable(const unsigned int index,
721 ad_type &out) const;
722
727 unsigned int
729
749 std::vector<ad_type> dependent_variables;
750
755
762 void
763 reset_registered_dependent_variables(const bool flag = false);
764
768 unsigned int
770
782 void
783 register_dependent_variable(const unsigned int index,
784 const ad_type &func);
785
788 }; // class HelperBase
789
790
791
833 template <enum AD::NumberTypes ADNumberTypeCode,
834 typename ScalarType = double>
835 class CellLevelBase : public HelperBase<ADNumberTypeCode, ScalarType>
836 {
837 public:
844
849 using ad_type =
851
871 CellLevelBase(const unsigned int n_independent_variables,
872 const unsigned int n_dependent_variables);
873
877 virtual ~CellLevelBase() = default;
878
903 void
904 register_dof_values(const std::vector<scalar_type> &dof_values);
905
924 template <typename VectorType>
925 void
927 const VectorType &values,
928 const std::vector<::types::global_dof_index> &local_dof_indices);
929
950 const std::vector<ad_type> &
952
979 void
980 set_dof_values(const std::vector<scalar_type> &dof_values);
981
999 template <typename VectorType>
1000 void
1002 const VectorType &values,
1003 const std::vector<::types::global_dof_index> &local_dof_indices);
1004
1026 virtual void
1028
1046 virtual void
1048
1051 }; // class CellLevelBase
1052
1053
1054
1215 template <enum AD::NumberTypes ADNumberTypeCode,
1216 typename ScalarType = double>
1217 class EnergyFunctional : public CellLevelBase<ADNumberTypeCode, ScalarType>
1218 {
1219 public:
1226
1231 using ad_type =
1233
1254 EnergyFunctional(const unsigned int n_independent_variables);
1255
1259 virtual ~EnergyFunctional() = default;
1260
1281 void
1282 register_energy_functional(const ad_type &energy);
1283
1298 compute_energy() const;
1299
1319 void
1320 compute_residual(Vector<scalar_type> &residual) const override;
1321
1342 virtual void
1344 FullMatrix<scalar_type> &linearization) const override;
1345
1348 }; // class EnergyFunctional
1349
1350
1351
1526 template <enum AD::NumberTypes ADNumberTypeCode,
1527 typename ScalarType = double>
1529 : public CellLevelBase<ADNumberTypeCode, ScalarType>
1530 {
1531 public:
1538
1543 using ad_type =
1545
1566 const unsigned int n_dependent_variables);
1567
1571 virtual ~ResidualLinearization() = default;
1572
1593 void
1594 register_residual_vector(const std::vector<ad_type> &residual);
1595
1612 virtual void
1613 compute_residual(Vector<scalar_type> &residual) const override;
1614
1632 virtual void
1634 FullMatrix<scalar_type> &linearization) const override;
1635
1638 }; // class ResidualLinearization
1639
1640
1641
1642 namespace internal
1643 {
1648 template <int dim, typename ExtractorType>
1650
1651
1657 template <int dim>
1658 struct Extractor<dim, FEValuesExtractors::Scalar>
1659 {
1663 static const unsigned int n_components = 1;
1664
1668 static const unsigned int rank = 0;
1669
1673 template <typename NumberType>
1675
1676 static_assert(
1678 "The number of components doesn't match that of the corresponding tensor type.");
1679 static_assert(
1681 "The rank doesn't match that of the corresponding tensor type.");
1682
1686 // Note: FEValuesViews::Scalar::tensor_type is double, so we can't
1687 // use it (FEValuesViews) in this context.
1688 // In fact, sadly, all FEValuesViews objects expect doubles as value
1689 // types.
1690 template <typename NumberType>
1692
1696 template <typename NumberType>
1698
1702 static inline unsigned int
1704 {
1705 return extractor.component;
1706 }
1707
1715 static bool
1716 symmetric_component(const unsigned int unrolled_index)
1717 {
1718 (void)unrolled_index;
1719 return false;
1720 }
1721
1729 template <typename IndexType = unsigned int, int rank_in>
1730 static IndexType
1732 const unsigned int column_offset)
1733 {
1734 Assert(column_offset <= rank_in, ExcInternalError());
1735 (void)table_indices;
1736 (void)column_offset;
1737 return 0;
1738 }
1739 };
1740
1741
1747 template <int dim>
1749 {
1753 static const unsigned int n_components = dim;
1754
1758 static const unsigned int rank = 1;
1759
1763 template <typename NumberType>
1765
1766 static_assert(
1768 "The number of components doesn't match that of the corresponding tensor type.");
1769 static_assert(
1771 "The rank doesn't match that of the corresponding tensor type.");
1772
1776 template <typename NumberType>
1778
1782 template <typename NumberType>
1784
1788 static inline unsigned int
1790 {
1791 return extractor.first_vector_component;
1792 }
1793
1802 static bool
1803 symmetric_component(const unsigned int unrolled_index)
1804 {
1805 (void)unrolled_index;
1806 return false;
1807 }
1808
1813 template <int rank_in>
1814 static TableIndices<rank>
1816 const unsigned int column_offset)
1817 {
1818 Assert(0 + column_offset < rank_in, ExcInternalError());
1819 return TableIndices<rank>(table_indices[column_offset]);
1820 }
1821
1837 template <typename IndexType = unsigned int, int rank_in>
1838 static IndexType
1840 const unsigned int column_offset)
1841 {
1842 static_assert(
1843 rank_in >= rank,
1844 "Cannot extract more table indices than the input table has!");
1845 using TensorType = tensor_type<double>;
1846 return TensorType::component_to_unrolled_index(
1847 table_index_view(table_indices, column_offset));
1848 }
1849 };
1850
1851
1857 template <int dim>
1859 {
1863 static const unsigned int n_components =
1865
1869 static const unsigned int rank = 1;
1870
1874 template <typename NumberType>
1876
1880 template <typename NumberType>
1882
1886 template <typename NumberType>
1888
1892 static inline unsigned int
1894 {
1895 return extractor.first_tensor_component;
1896 }
1897
1905 static bool
1906 symmetric_component(const unsigned int unrolled_index)
1907 {
1908 (void)unrolled_index;
1909 return false;
1910 }
1911
1916 template <int rank_in>
1917 static TableIndices<rank>
1919 const unsigned int column_offset)
1920 {
1921 Assert(column_offset < rank_in, ExcInternalError());
1922 return TableIndices<rank>(table_indices[column_offset]);
1923 }
1924
1940 template <typename IndexType = unsigned int, int rank_in>
1941 static IndexType
1943 const unsigned int column_offset)
1944 {
1945 static_assert(
1946 rank_in >= rank,
1947 "Cannot extract more table indices than the input table has!");
1948 using TensorType = tensor_type<double>;
1949 return TensorType::component_to_unrolled_index(
1950 table_index_view(table_indices, column_offset));
1951 }
1952 };
1953
1954
1960 template <int dim>
1962 {
1966 static const unsigned int n_components =
1968
1972 static const unsigned int rank = Tensor<2, dim>::rank;
1973
1977 template <typename NumberType>
1979
1983 template <typename NumberType>
1985
1989 template <typename NumberType>
1991
1995 static inline unsigned int
1997 {
1998 return extractor.first_tensor_component;
1999 }
2000
2008 static bool
2009 symmetric_component(const unsigned int unrolled_index)
2010 {
2011 (void)unrolled_index;
2012 return false;
2013 }
2014
2019 template <int rank_in>
2020 static TableIndices<rank>
2022 const unsigned int column_offset)
2023 {
2024 Assert(column_offset < rank_in, ExcInternalError());
2025 Assert(column_offset + 1 < rank_in, ExcInternalError());
2026 return TableIndices<rank>(table_indices[column_offset],
2027 table_indices[column_offset + 1]);
2028 }
2029
2045 template <typename IndexType = unsigned int, int rank_in>
2046 static IndexType
2048 const unsigned int column_offset)
2049 {
2050 static_assert(
2051 rank_in >= rank,
2052 "Cannot extract more table indices than the input table has!");
2053 using TensorType = tensor_type<double>;
2054 return TensorType::component_to_unrolled_index(
2055 table_index_view(table_indices, column_offset));
2056 }
2057 };
2058
2059
2065 template <int dim>
2067 {
2071 static const unsigned int n_components =
2073
2077 static const unsigned int rank = SymmetricTensor<2, dim>::rank;
2078
2082 template <typename NumberType>
2084
2088 template <typename NumberType>
2090
2094 template <typename NumberType>
2096
2100 static inline unsigned int
2102 {
2103 return extractor.first_tensor_component;
2104 }
2105
2114 static bool
2115 symmetric_component(const unsigned int unrolled_index)
2116 {
2117 const TableIndices<2> table_indices =
2119 return table_indices[0] != table_indices[1];
2120 }
2121
2126 template <int rank_in>
2127 static TableIndices<rank>
2129 const unsigned int column_offset)
2130 {
2131 Assert(column_offset < rank_in, ExcInternalError());
2132 Assert(column_offset + 1 < rank_in, ExcInternalError());
2133 return TableIndices<rank>(table_indices[column_offset],
2134 table_indices[column_offset + 1]);
2135 }
2136
2152 template <typename IndexType = unsigned int, int rank_in>
2153 static IndexType
2155 const unsigned int column_offset)
2156 {
2157 static_assert(
2158 rank_in >= rank,
2159 "Cannot extract more table indices than the input table has!");
2160 using TensorType = tensor_type<double>;
2161 return TensorType::component_to_unrolled_index(
2162 table_index_view(table_indices, column_offset));
2163 }
2164 };
2165
2166
2172 template <int dim, typename NumberType, typename ExtractorType>
2174 {
2179 using type =
2180 typename Extractor<dim,
2181 ExtractorType>::template tensor_type<NumberType>;
2182 };
2183
2184
2194 template <typename ExtractorType_Row, typename ExtractorType_Col>
2196 {
2208 template <int rank, int dim, typename NumberType>
2210 };
2211
2212
2221 template <>
2224 {
2232 template <int /*rank*/, int dim, typename NumberType>
2233 using type = SymmetricTensor<2 /*rank*/, dim, NumberType>;
2234 };
2235
2236
2245 template <>
2248 {
2257 template <int /*rank*/, int dim, typename NumberType>
2258 using type = SymmetricTensor<2 /*rank*/, dim, NumberType>;
2259 };
2260
2261
2269 template <>
2272 {
2281 template <int /*rank*/, int dim, typename NumberType>
2282 using type = SymmetricTensor<4 /*rank*/, dim, NumberType>;
2283 };
2284
2285
2295 template <int dim,
2296 typename NumberType,
2297 typename ExtractorType_Row,
2298 typename ExtractorType_Col>
2317
2318
2323 template <int dim, typename NumberType, typename ExtractorType_Field>
2326
2327
2337 template <int dim,
2338 typename NumberType,
2339 typename ExtractorType_Field,
2340 typename ExtractorType_Derivative>
2342 NumberType,
2343 ExtractorType_Field,
2344 ExtractorType_Derivative>;
2345
2346
2352 template <int dim,
2353 typename IndexType = unsigned int,
2354 typename ExtractorType>
2355 std::vector<IndexType>
2356 extract_field_component_indices(const ExtractorType &extractor,
2357 const bool ignore_symmetries = true)
2358 {
2359 (void)ignore_symmetries;
2360 const IndexType n_components =
2362 const IndexType comp_first =
2364 std::vector<IndexType> indices(n_components);
2365 std::iota(indices.begin(), indices.end(), comp_first);
2366 return indices;
2367 }
2368
2369
2378 template <int dim, typename IndexType = unsigned int>
2379 std::vector<IndexType>
2381 const FEValuesExtractors::SymmetricTensor<2> &extractor_symm_tensor,
2382 const bool ignore_symmetries = true)
2383 {
2384 using ExtractorType = FEValuesExtractors::SymmetricTensor<2>;
2385 const IndexType n_components =
2387 const IndexType comp_first =
2389 extractor_symm_tensor);
2390
2391 if (ignore_symmetries == true)
2392 {
2393 std::vector<IndexType> indices(n_components);
2394 std::iota(indices.begin(), indices.end(), comp_first);
2395 return indices;
2396 }
2397 else
2398 {
2399 // First get all of the indices of the non-symmetric tensor
2400 const FEValuesExtractors::Tensor<2> extractor_tensor(
2401 extractor_symm_tensor.first_tensor_component);
2402 std::vector<IndexType> indices =
2403 extract_field_component_indices<dim>(extractor_tensor, true);
2404
2405 // Then we overwrite any illegal entries with the equivalent indices
2406 // from the symmetric tensor
2407 for (unsigned int i = 0; i < indices.size(); ++i)
2408 {
2409 // The indices stored in the vector start with the extractor's
2410 // first_component_index. We need to account for this when
2411 // retrieving the tensor (local) index.
2412 const IndexType local_index_i = indices[i] - comp_first;
2413 if (local_index_i >= n_components)
2414 {
2415 const TableIndices<2> ti_tensor =
2417 local_index_i);
2418 const IndexType sti_new_index =
2420 ti_tensor);
2421 indices[i] = comp_first + sti_new_index;
2422 }
2423 }
2424
2425 return indices;
2426 }
2427 }
2428
2429
2434 template <typename TensorType, typename NumberType>
2435 inline void
2436 set_tensor_entry(TensorType &t,
2437 const unsigned int unrolled_index,
2438 const NumberType &value)
2439 {
2440 // Where possible, set values using TableIndices
2441 AssertIndexRange(unrolled_index, t.n_independent_components);
2442 t[TensorType::unrolled_to_component_indices(unrolled_index)] = value;
2443 }
2444
2445
2450 template <int dim, typename NumberType>
2451 inline void
2453 const unsigned int unrolled_index,
2454 const NumberType &value)
2455 {
2456 AssertIndexRange(unrolled_index, 1);
2457 (void)unrolled_index;
2458 t = value;
2459 }
2460
2461
2467 template <typename NumberType>
2468 inline void
2470 const unsigned int unrolled_index,
2471 const NumberType &value)
2472 {
2473 AssertIndexRange(unrolled_index, 1);
2474 (void)unrolled_index;
2475 t = value;
2476 }
2477
2478
2484 template <int dim, typename NumberType>
2485 inline void
2487 const unsigned int unrolled_index_row,
2488 const unsigned int unrolled_index_col,
2489 const NumberType &value)
2490 {
2491 // Fourth order symmetric tensors require a specialized interface
2492 // to extract values.
2493 using SubTensorType = SymmetricTensor<2, dim, NumberType>;
2494 AssertIndexRange(unrolled_index_row,
2495 SubTensorType::n_independent_components);
2496 AssertIndexRange(unrolled_index_col,
2497 SubTensorType::n_independent_components);
2498 const TableIndices<2> indices_row =
2499 SubTensorType::unrolled_to_component_indices(unrolled_index_row);
2500 const TableIndices<2> indices_col =
2501 SubTensorType::unrolled_to_component_indices(unrolled_index_col);
2502 t[indices_row[0]][indices_row[1]][indices_col[0]][indices_col[1]] =
2503 value;
2504 }
2505
2506
2511 template <int rank,
2512 int dim,
2513 typename NumberType,
2514 template <int, int, typename> class TensorType>
2515 inline NumberType
2516 get_tensor_entry(const TensorType<rank, dim, NumberType> &t,
2517 const unsigned int unrolled_index)
2518 {
2519 // Where possible, get values using TableIndices
2520 AssertIndexRange(unrolled_index, t.n_independent_components);
2521 return t[TensorType<rank, dim, NumberType>::
2522 unrolled_to_component_indices(unrolled_index)];
2523 }
2524
2525
2530 template <int dim,
2531 typename NumberType,
2532 template <int, int, typename> class TensorType>
2533 inline NumberType
2534 get_tensor_entry(const TensorType<0, dim, NumberType> &t,
2535 const unsigned int unrolled_index)
2536 {
2537 AssertIndexRange(unrolled_index, 1);
2538 (void)unrolled_index;
2539 return t;
2540 }
2541
2542
2548 template <typename NumberType>
2549 inline const NumberType &
2550 get_tensor_entry(const NumberType &t, const unsigned int unrolled_index)
2551 {
2552 AssertIndexRange(unrolled_index, 1);
2553 (void)unrolled_index;
2554 return t;
2555 }
2556
2557
2562 template <int rank,
2563 int dim,
2564 typename NumberType,
2565 template <int, int, typename> class TensorType>
2566 inline NumberType &
2567 get_tensor_entry(TensorType<rank, dim, NumberType> &t,
2568 const unsigned int unrolled_index)
2569 {
2570 // Where possible, get values using TableIndices
2571 AssertIndexRange(unrolled_index, t.n_independent_components);
2572 return t[TensorType<rank, dim, NumberType>::
2573 unrolled_to_component_indices(unrolled_index)];
2574 }
2575
2576
2581 template <int dim,
2582 typename NumberType,
2583 template <int, int, typename> class TensorType>
2584 NumberType &
2585 get_tensor_entry(TensorType<0, dim, NumberType> &t,
2586 const unsigned int index)
2587 {
2588 AssertIndexRange(index, 1);
2589 (void)index;
2590 return t;
2591 }
2592
2593
2599 template <typename NumberType>
2600 inline NumberType &
2601 get_tensor_entry(NumberType &t, const unsigned int index)
2602 {
2603 AssertIndexRange(index, 1);
2604 (void)index;
2605 return t;
2606 }
2607
2608 } // namespace internal
2609
2610
2611
2633 template <int dim,
2634 enum AD::NumberTypes ADNumberTypeCode,
2635 typename ScalarType = double>
2637 : public HelperBase<ADNumberTypeCode, ScalarType>
2638 {
2639 public:
2644 static constexpr unsigned int dimension = dim;
2645
2652
2657 using ad_type =
2659
2680 const unsigned int n_dependent_variables);
2681
2685 virtual ~PointLevelFunctionsBase() = default;
2686
2729 virtual void
2730 reset(const unsigned int n_independent_variables =
2732 const unsigned int n_dependent_variables =
2734 const bool clear_registered_tapes = true) override;
2735
2751 void
2752 register_independent_variables(const std::vector<scalar_type> &values);
2753
2782 template <typename ValueType, typename ExtractorType>
2783 void
2784 register_independent_variable(const ValueType &value,
2785 const ExtractorType &extractor);
2786
2807 const std::vector<ad_type> &
2809
2810 /*
2811 * Extract a subset of the independent variables as represented by
2812 * auto-differentiable numbers. These are the independent
2813 * variables @f$\mathbf{A} \subset \mathbf{X}@f$ at which the dependent values
2814 * are evaluated and differentiated.
2815 *
2816 * This function indicates to the AD library that implements the
2817 * auto-differentiable number type that operations performed on these
2818 * numbers are to be tracked so they are considered "sensitive"
2819 * variables. This is, therefore, the set of variables with which one
2820 * would then perform computations, and based on which one can then
2821 * extract both the value of the function and its derivatives with the
2822 * member functions below. The values of the components of the returned
2823 * object are initialized to the values set with
2824 * register_independent_variable().
2825 *
2826 * @param[in] extractor An extractor associated with the input field
2827 * variables. This effectively defines which components of the global set
2828 * of independent variables this field is associated with.
2829 * @return An object of auto-differentiable type numbers. The return type is
2830 * based on the input extractor, and will be either a scalar,
2831 * Tensor<1,dim>, Tensor<2,dim>, or SymmetricTensor<2,dim>.
2832 *
2833 * @note For taped AD numbers, this operation is only valid in recording mode.
2834 */
2835 template <typename ExtractorType>
2838 get_sensitive_variables(const ExtractorType &extractor) const;
2839
2864 void
2865 set_independent_variables(const std::vector<scalar_type> &values);
2866
2893 template <typename ValueType, typename ExtractorType>
2894 void
2895 set_independent_variable(const ValueType &value,
2896 const ExtractorType &extractor);
2897
2900 protected:
2916 void
2917 set_sensitivity_value(const unsigned int index,
2918 const bool symmetric_component,
2919 const scalar_type &value);
2920
2926 bool
2927 is_symmetric_independent_variable(const unsigned int index) const;
2928
2933 unsigned int
2935
2938 private:
2949
2952 }; // class PointLevelFunctionsBase
2953
2954
2955
3110 template <int dim,
3111 enum AD::NumberTypes ADNumberTypeCode,
3112 typename ScalarType = double>
3114 : public PointLevelFunctionsBase<dim, ADNumberTypeCode, ScalarType>
3115 {
3116 public:
3123
3128 using ad_type =
3130
3145 ScalarFunction(const unsigned int n_independent_variables);
3146
3150 virtual ~ScalarFunction() = default;
3151
3170 void
3172
3181 compute_value() const;
3182
3195 void
3196 compute_gradient(Vector<scalar_type> &gradient) const;
3197
3212 void
3214
3249 template <typename ExtractorType_Row>
3250 static typename internal::
3251 ScalarFieldGradient<dim, scalar_type, ExtractorType_Row>::type
3253 const ExtractorType_Row &extractor_row);
3254
3293 template <typename ExtractorType_Row, typename ExtractorType_Col>
3294 static typename internal::ScalarFieldHessian<dim,
3296 ExtractorType_Row,
3297 ExtractorType_Col>::type
3299 const ExtractorType_Row &extractor_row,
3300 const ExtractorType_Col &extractor_col);
3301
3317 const FullMatrix<scalar_type> &hessian,
3318 const FEValuesExtractors::Scalar &extractor_row,
3319 const FEValuesExtractors::Scalar &extractor_col);
3320
3334 const FullMatrix<scalar_type> &hessian,
3335 const FEValuesExtractors::SymmetricTensor<2> &extractor_row,
3336 const FEValuesExtractors::SymmetricTensor<2> &extractor_col);
3337
3340 }; // class ScalarFunction
3341
3342
3343
3501 template <int dim,
3502 enum AD::NumberTypes ADNumberTypeCode,
3503 typename ScalarType = double>
3505 : public PointLevelFunctionsBase<dim, ADNumberTypeCode, ScalarType>
3506 {
3507 public:
3514
3519 using ad_type =
3521
3541 VectorFunction(const unsigned int n_independent_variables,
3542 const unsigned int n_dependent_variables);
3543
3547 virtual ~VectorFunction() = default;
3548
3568 void
3569 register_dependent_variables(const std::vector<ad_type> &funcs);
3570
3589 template <typename ValueType, typename ExtractorType>
3590 void
3591 register_dependent_variable(const ValueType &funcs,
3592 const ExtractorType &extractor);
3593
3602 void
3603 compute_values(Vector<scalar_type> &values) const;
3604
3619 void
3621
3622
3635 template <typename ExtractorType_Row>
3636 static typename internal::
3637 VectorFieldValue<dim, scalar_type, ExtractorType_Row>::type
3639 const ExtractorType_Row &extractor_row);
3640
3688 template <typename ExtractorType_Row, typename ExtractorType_Col>
3689 static typename internal::VectorFieldJacobian<dim,
3691 ExtractorType_Row,
3692 ExtractorType_Col>::type
3694 const ExtractorType_Row &extractor_row,
3695 const ExtractorType_Col &extractor_col);
3696
3714 const FullMatrix<scalar_type> &jacobian,
3715 const FEValuesExtractors::Scalar &extractor_row,
3716 const FEValuesExtractors::Scalar &extractor_col);
3717
3733 const FullMatrix<scalar_type> &jacobian,
3734 const FEValuesExtractors::SymmetricTensor<2> &extractor_row,
3735 const FEValuesExtractors::SymmetricTensor<2> &extractor_col);
3736
3739 }; // class VectorFunction
3740
3741
3742 } // namespace AD
3743} // namespace Differentiation
3744
3745
3746/* ----------------- inline and template functions ----------------- */
3747
3748
3749# ifndef DOXYGEN
3750
3751namespace Differentiation
3752{
3753 namespace AD
3754 {
3755 /* ----------------- CellLevelBase ----------------- */
3756
3757
3758
3759 template <enum AD::NumberTypes ADNumberTypeCode, typename ScalarType>
3760 template <typename VectorType>
3761 void
3763 const VectorType &values,
3764 const std::vector<::types::global_dof_index> &local_dof_indices)
3765 {
3766 // This is actually the same thing the set_dof_values() function,
3767 // in the sense that we simply populate our array of independent values
3768 // with a meaningful number. However, in this case we need to double check
3769 // that we're not registering these variables twice
3770 Assert(
3771 local_dof_indices.size() == this->n_independent_variables(),
3772 ExcMessage(
3773 "Degree of freedom index vector size does not match number of independent variables"));
3774 for (unsigned int i = 0; i < this->n_independent_variables(); ++i)
3775 {
3776 Assert(this->registered_independent_variable_values[i] == false,
3777 ExcMessage("Independent variables already registered."));
3778 }
3779 set_dof_values(values, local_dof_indices);
3780 }
3781
3782
3783
3784 template <enum AD::NumberTypes ADNumberTypeCode, typename ScalarType>
3785 template <typename VectorType>
3786 void
3788 const VectorType &values,
3789 const std::vector<::types::global_dof_index> &local_dof_indices)
3790 {
3791 Assert(local_dof_indices.size() == this->n_independent_variables(),
3792 ExcMessage(
3793 "Vector size does not match number of independent variables"));
3794 for (unsigned int i = 0; i < this->n_independent_variables(); ++i)
3796 i, values[local_dof_indices[i]]);
3797 }
3798
3799
3800
3801 /* ----------------- PointLevelFunctionsBase ----------------- */
3802
3803
3804
3805 template <int dim,
3806 enum AD::NumberTypes ADNumberTypeCode,
3807 typename ScalarType>
3808 template <typename ValueType, typename ExtractorType>
3809 void
3811 register_independent_variable(const ValueType &value,
3812 const ExtractorType &extractor)
3813 {
3814 // This is actually the same thing as the set_independent_variable
3815 // function, in the sense that we simply populate our array of independent
3816 // values with a meaningful number. However, in this case we need to
3817 // double check that we're not registering these variables twice
3818 if constexpr (running_in_debug_mode())
3819 {
3820 const std::vector<unsigned int> index_set(
3821 internal::extract_field_component_indices<dim>(extractor));
3822 for (const unsigned int index : index_set)
3823 {
3824 Assert(
3825 this->registered_independent_variable_values[index] == false,
3826 ExcMessage(
3827 "Overlapping indices for independent variables. "
3828 "One or more indices associated with the field that "
3829 "is being registered as an independent variable have "
3830 "already been associated with another field. This suggests "
3831 "that the component offsets used to construct their counterpart "
3832 "extractors are incompatible with one another. Make sure that "
3833 "the first component for each extractor properly takes into "
3834 "account the dimensionality of the preceding fields."));
3835 }
3836 }
3837 set_independent_variable(value, extractor);
3838 }
3839
3840
3841
3842 template <int dim,
3843 enum AD::NumberTypes ADNumberTypeCode,
3844 typename ScalarType>
3845 template <typename ValueType, typename ExtractorType>
3846 void
3848 set_independent_variable(const ValueType &value,
3849 const ExtractorType &extractor)
3850 {
3851 const std::vector<unsigned int> index_set(
3852 internal::extract_field_component_indices<dim>(extractor));
3853 for (unsigned int i = 0; i < index_set.size(); ++i)
3854 {
3855 set_sensitivity_value(
3856 index_set[i],
3857 internal::Extractor<dim, ExtractorType>::symmetric_component(i),
3858 internal::get_tensor_entry(value, i));
3859 }
3860 }
3861
3862
3863
3864 template <int dim,
3865 enum AD::NumberTypes ADNumberTypeCode,
3866 typename ScalarType>
3867 template <typename ExtractorType>
3868 typename internal::Extractor<dim, ExtractorType>::template tensor_type<
3871 get_sensitive_variables(const ExtractorType &extractor) const
3872 {
3873 if (ADNumberTraits<ad_type>::is_taped == true)
3874 {
3875 Assert(this->active_tape_index() !=
3877 ExcMessage("Invalid tape index"));
3878 }
3879
3880 // If necessary, finalize the internally stored vector of
3881 // AD numbers that represents the independent variables
3882 this->finalize_sensitive_independent_variables();
3883 Assert(this->independent_variables.size() ==
3884 this->n_independent_variables(),
3885 ExcDimensionMismatch(this->independent_variables.size(),
3886 this->n_independent_variables()));
3887
3888 const std::vector<unsigned int> index_set(
3889 internal::extract_field_component_indices<dim>(extractor));
3890 typename internal::Extractor<dim,
3891 ExtractorType>::template tensor_type<ad_type>
3892 out;
3893
3894 for (unsigned int i = 0; i < index_set.size(); ++i)
3895 {
3896 const unsigned int index = index_set[i];
3897 Assert(index < this->n_independent_variables(), ExcInternalError());
3898 Assert(this->registered_independent_variable_values[index] == true,
3901 this->independent_variables[index];
3902 }
3903
3904 return out;
3905 }
3906
3907
3908
3909 /* ----------------- ScalarFunction ----------------- */
3910
3911
3912
3913 template <int dim,
3914 enum AD::NumberTypes ADNumberTypeCode,
3915 typename ScalarType>
3916 template <typename ExtractorType_Row>
3917 typename internal::ScalarFieldGradient<
3918 dim,
3920 ExtractorType_Row>::type
3923 const ExtractorType_Row &extractor_row)
3924 {
3925 // NOTE: The order of components must be consistently defined throughout
3926 // this class.
3927 typename internal::
3928 ScalarFieldGradient<dim, scalar_type, ExtractorType_Row>::type out;
3929
3930 // Get indexsets for the subblock from which we wish to extract the
3931 // gradient values
3932 const std::vector<unsigned int> row_index_set(
3933 internal::extract_field_component_indices<dim>(extractor_row));
3934 Assert(out.n_independent_components == row_index_set.size(),
3935 ExcMessage("Not all tensor components have been extracted!"));
3936 for (unsigned int r = 0; r < row_index_set.size(); ++r)
3937 internal::set_tensor_entry(out, r, gradient[row_index_set[r]]);
3938
3939 return out;
3940 }
3941
3942
3943
3944 template <int dim,
3945 enum AD::NumberTypes ADNumberTypeCode,
3946 typename ScalarType>
3947 template <typename ExtractorType_Row, typename ExtractorType_Col>
3948 typename internal::ScalarFieldHessian<
3949 dim,
3951 ExtractorType_Row,
3952 ExtractorType_Col>::type
3955 const ExtractorType_Row &extractor_row,
3956 const ExtractorType_Col &extractor_col)
3957 {
3958 using InternalHessian = internal::ScalarFieldHessian<dim,
3959 scalar_type,
3960 ExtractorType_Row,
3961 ExtractorType_Col>;
3962 using InternalExtractorRow = internal::Extractor<dim, ExtractorType_Row>;
3963 using InternalExtractorCol = internal::Extractor<dim, ExtractorType_Col>;
3964 using HessianType = typename InternalHessian::type;
3965
3966 // NOTE: The order of components must be consistently defined throughout
3967 // this class.
3968 HessianType out;
3969
3970 // Get indexsets for the subblocks from which we wish to extract the
3971 // Hessian values
3972 // NOTE: Here we have to do some clever accounting when the
3973 // one extractor is a symmetric Tensor and the other is not, e.g.
3974 // <SymmTensor,Vector>. In this scenario the return type is a
3975 // non-symmetric Tensor<3,dim> but we have to fetch information from a
3976 // SymmTensor row/column that has too few entries to fill the output
3977 // tensor. So we must duplicate the relevant entries in the row/column
3978 // indexset to fetch off-diagonal components that are otherwise
3979 // non-existent in a SymmTensor.
3980 const std::vector<unsigned int> row_index_set(
3981 internal::extract_field_component_indices<dim>(
3982 extractor_row, false /*ignore_symmetries*/));
3983 const std::vector<unsigned int> col_index_set(
3984 internal::extract_field_component_indices<dim>(
3985 extractor_col, false /*ignore_symmetries*/));
3986
3987 for (unsigned int index = 0;
3988 index < HessianType::n_independent_components;
3989 ++index)
3990 {
3991 const TableIndices<HessianType::rank> ti_out =
3992 HessianType::unrolled_to_component_indices(index);
3993 const unsigned int r =
3994 InternalExtractorRow::local_component(ti_out, 0);
3995 const unsigned int c =
3996 InternalExtractorCol::local_component(ti_out,
3997 InternalExtractorRow::rank);
3998
4000 out, index, hessian[row_index_set[r]][col_index_set[c]]);
4001 }
4002
4003 return out;
4004 }
4005
4006
4007
4008 /* ----------------- VectorFunction ----------------- */
4009
4010
4011
4012 template <int dim,
4013 enum AD::NumberTypes ADNumberTypeCode,
4014 typename ScalarType>
4015 template <typename ValueType, typename ExtractorType>
4016 void
4018 register_dependent_variable(const ValueType &funcs,
4019 const ExtractorType &extractor)
4020 {
4021 const std::vector<unsigned int> index_set(
4022 internal::extract_field_component_indices<dim>(extractor));
4023 for (unsigned int i = 0; i < index_set.size(); ++i)
4024 {
4025 Assert(this->registered_marked_dependent_variables[index_set[i]] ==
4026 false,
4027 ExcMessage("Overlapping indices for dependent variables."));
4029 index_set[i], internal::get_tensor_entry(funcs, i));
4030 }
4031 }
4032
4033
4034
4035 template <int dim,
4036 enum AD::NumberTypes ADNumberTypeCode,
4037 typename ScalarType>
4038 template <typename ExtractorType_Row>
4040 dim,
4042 ExtractorType_Row>::type
4044 const Vector<scalar_type> &values,
4045 const ExtractorType_Row &extractor_row)
4046 {
4047 // NOTE: The order of components must be consistently defined throughout
4048 // this class.
4049 typename internal::VectorFieldValue<dim, scalar_type, ExtractorType_Row>::
4050 type out;
4051
4052 // Get indexsets for the subblock from which we wish to extract the
4053 // gradient values
4054 const std::vector<unsigned int> row_index_set(
4055 internal::extract_field_component_indices<dim>(extractor_row));
4056 Assert(out.n_independent_components == row_index_set.size(),
4057 ExcMessage("Not all tensor components have been extracted!"));
4058 for (unsigned int r = 0; r < row_index_set.size(); ++r)
4059 internal::set_tensor_entry(out, r, values[row_index_set[r]]);
4060
4061 return out;
4062 }
4063
4064
4065
4066 template <int dim,
4067 enum AD::NumberTypes ADNumberTypeCode,
4068 typename ScalarType>
4069 template <typename ExtractorType_Row, typename ExtractorType_Col>
4071 dim,
4073 ExtractorType_Row,
4074 ExtractorType_Col>::type
4077 const ExtractorType_Row &extractor_row,
4078 const ExtractorType_Col &extractor_col)
4079 {
4080 using InternalJacobian = internal::VectorFieldJacobian<dim,
4081 scalar_type,
4082 ExtractorType_Row,
4083 ExtractorType_Col>;
4084 using InternalExtractorRow = internal::Extractor<dim, ExtractorType_Row>;
4085 using InternalExtractorCol = internal::Extractor<dim, ExtractorType_Col>;
4086 using JacobianType = typename InternalJacobian::type;
4087
4088 // NOTE: The order of components must be consistently defined throughout
4089 // this class.
4090 JacobianType out;
4091
4092 // Get indexsets for the subblocks from which we wish to extract the
4093 // Hessian values.
4094 // NOTE: Here we have to do some clever accounting when the
4095 // one extractor is a symmetric Tensor and the other is not, e.g.
4096 // <SymmTensor,Vector>. In this scenario the return type is a
4097 // non-symmetric Tensor<3,dim> but we have to fetch information from a
4098 // SymmTensor row/column that has too few entries to fill the output
4099 // tensor. So we must duplicate the relevant entries in the row/column
4100 // indexset to fetch off-diagonal components that are otherwise
4101 // non-existent in a SymmTensor.
4102 const std::vector<unsigned int> row_index_set(
4103 internal::extract_field_component_indices<dim>(
4104 extractor_row, false /*ignore_symmetries*/));
4105 const std::vector<unsigned int> col_index_set(
4106 internal::extract_field_component_indices<dim>(
4107 extractor_col, false /*ignore_symmetries*/));
4108
4109 for (unsigned int index = 0;
4110 index < JacobianType::n_independent_components;
4111 ++index)
4112 {
4114 JacobianType::unrolled_to_component_indices(index);
4115 const unsigned int r =
4116 InternalExtractorRow::local_component(ti_out, 0);
4117 const unsigned int c =
4118 InternalExtractorCol::local_component(ti_out,
4119 InternalExtractorRow::rank);
4120
4122 out, index, jacobian[row_index_set[r]][col_index_set[c]]);
4123 }
4124
4125 return out;
4126 }
4127
4128
4129 } // namespace AD
4130} // namespace Differentiation
4131
4132
4133# endif // DOXYGEN
4134
4135#endif // defined(DEAL_II_WITH_ADOLC) || defined(DEAL_II_TRILINOS_WITH_SACADO)
4136
4138
4139#endif // dealii_differentiation_ad_ad_helpers_h
void register_dof_values(const VectorType &values, const std::vector<::types::global_dof_index > &local_dof_indices)
const std::vector< ad_type > & get_sensitive_dof_values() const
typename HelperBase< ADNumberTypeCode, ScalarType >::ad_type ad_type
Definition ad_helpers.h:850
void set_dof_values(const std::vector< scalar_type > &dof_values)
virtual void compute_residual(Vector< scalar_type > &residual) const =0
void register_dof_values(const std::vector< scalar_type > &dof_values)
virtual void compute_linearization(FullMatrix< scalar_type > &linearization) const =0
void set_dof_values(const VectorType &values, const std::vector<::types::global_dof_index > &local_dof_indices)
typename HelperBase< ADNumberTypeCode, ScalarType >::scalar_type scalar_type
Definition ad_helpers.h:843
void register_energy_functional(const ad_type &energy)
typename HelperBase< ADNumberTypeCode, ScalarType >::ad_type ad_type
void compute_residual(Vector< scalar_type > &residual) const override
virtual void compute_linearization(FullMatrix< scalar_type > &linearization) const override
typename HelperBase< ADNumberTypeCode, ScalarType >::scalar_type scalar_type
unsigned int n_registered_dependent_variables() const
TapedDrivers< ad_type, scalar_type > taped_driver
Definition ad_helpers.h:591
void stop_recording_operations(const bool write_tapes_to_file=false)
std::vector< bool > registered_marked_independent_variables
Definition ad_helpers.h:657
typename AD::NumberTraits< ScalarType, ADNumberTypeCode >::scalar_type scalar_type
Definition ad_helpers.h:177
std::vector< bool > registered_independent_variable_values
Definition ad_helpers.h:651
Types< ad_type >::tape_index active_tape_index() const
void print_tape_stats(const typename Types< ad_type >::tape_index tape_index, std::ostream &stream) const
std::size_t n_independent_variables() const
bool start_recording_operations(const typename Types< ad_type >::tape_index tape_index, const bool overwrite_tape=false, const bool keep_independent_values=true)
std::vector< scalar_type > independent_variable_values
Definition ad_helpers.h:635
void mark_independent_variable(const unsigned int index, ad_type &out) const
bool is_registered_tape(const typename Types< ad_type >::tape_index tape_index) const
std::vector< bool > registered_marked_dependent_variables
Definition ad_helpers.h:754
void reset_registered_dependent_variables(const bool flag=false)
Definition ad_helpers.cc:96
void activate_tape(const typename Types< ad_type >::tape_index tape_index, const bool read_mode)
void set_tape_buffer_sizes(const typename Types< ad_type >::tape_buffer_sizes obufsize=64 *1024 *1024, const typename Types< ad_type >::tape_buffer_sizes lbufsize=64 *1024 *1024, const typename Types< ad_type >::tape_buffer_sizes vbufsize=64 *1024 *1024, const typename Types< ad_type >::tape_buffer_sizes tbufsize=64 *1024 *1024)
unsigned int n_registered_independent_variables() const
void print(std::ostream &stream) const
void set_sensitivity_value(const unsigned int index, const scalar_type &value)
bool active_tape_requires_retaping() const
std::vector< ad_type > independent_variables
Definition ad_helpers.h:645
virtual void reset(const unsigned int n_independent_variables=::numbers::invalid_unsigned_int, const unsigned int n_dependent_variables=::numbers::invalid_unsigned_int, const bool clear_registered_tapes=true)
TapelessDrivers< ad_type, scalar_type > tapeless_driver
Definition ad_helpers.h:599
bool recorded_tape_requires_retaping(const typename Types< ad_type >::tape_index tape_index) const
std::vector< ad_type > dependent_variables
Definition ad_helpers.h:749
std::size_t n_dependent_variables() const
void print_values(std::ostream &stream) const
void register_dependent_variable(const unsigned int index, const ad_type &func)
void finalize_sensitive_independent_variables() const
static void configure_tapeless_mode(const unsigned int n_independent_variables, const bool ensure_persistent_setting=true)
void initialize_non_sensitive_independent_variable(const unsigned int index, ad_type &out) const
typename AD::NumberTraits< ScalarType, ADNumberTypeCode >::ad_type ad_type
Definition ad_helpers.h:184
void activate_recorded_tape(const typename Types< ad_type >::tape_index tape_index)
void set_independent_variable(const ValueType &value, const ExtractorType &extractor)
bool is_symmetric_independent_variable(const unsigned int index) const
typename HelperBase< ADNumberTypeCode, ScalarType >::ad_type ad_type
static constexpr unsigned int dimension
void set_independent_variables(const std::vector< scalar_type > &values)
typename HelperBase< ADNumberTypeCode, ScalarType >::scalar_type scalar_type
unsigned int n_symmetric_independent_variables() const
void register_independent_variables(const std::vector< scalar_type > &values)
void set_sensitivity_value(const unsigned int index, const bool symmetric_component, const scalar_type &value)
void register_independent_variable(const ValueType &value, const ExtractorType &extractor)
const std::vector< ad_type > & get_sensitive_variables() const
virtual void reset(const unsigned int n_independent_variables=::numbers::invalid_unsigned_int, const unsigned int n_dependent_variables=::numbers::invalid_unsigned_int, const bool clear_registered_tapes=true) override
internal::Extractor< dim, ExtractorType >::template tensor_type< typename HelperBase< ADNumberTypeCode, ScalarType >::ad_type > get_sensitive_variables(const ExtractorType &extractor) const
typename HelperBase< ADNumberTypeCode, ScalarType >::scalar_type scalar_type
virtual void compute_residual(Vector< scalar_type > &residual) const override
virtual void compute_linearization(FullMatrix< scalar_type > &linearization) const override
typename HelperBase< ADNumberTypeCode, ScalarType >::ad_type ad_type
void register_residual_vector(const std::vector< ad_type > &residual)
static internal::ScalarFieldHessian< dim, scalar_type, ExtractorType_Row, ExtractorType_Col >::type extract_hessian_component(const FullMatrix< scalar_type > &hessian, const ExtractorType_Row &extractor_row, const ExtractorType_Col &extractor_col)
typename HelperBase< ADNumberTypeCode, ScalarType >::ad_type ad_type
void register_dependent_variable(const ad_type &func)
static internal::ScalarFieldGradient< dim, scalar_type, ExtractorType_Row >::type extract_gradient_component(const Vector< scalar_type > &gradient, const ExtractorType_Row &extractor_row)
void compute_gradient(Vector< scalar_type > &gradient) const
void compute_hessian(FullMatrix< scalar_type > &hessian) const
typename HelperBase< ADNumberTypeCode, ScalarType >::scalar_type scalar_type
typename HelperBase< ADNumberTypeCode, ScalarType >::ad_type ad_type
void compute_values(Vector< scalar_type > &values) const
void register_dependent_variables(const std::vector< ad_type > &funcs)
void compute_jacobian(FullMatrix< scalar_type > &jacobian) const
typename HelperBase< ADNumberTypeCode, ScalarType >::scalar_type scalar_type
static internal::VectorFieldJacobian< dim, scalar_type, ExtractorType_Row, ExtractorType_Col >::type extract_jacobian_component(const FullMatrix< scalar_type > &jacobian, const ExtractorType_Row &extractor_row, const ExtractorType_Col &extractor_col)
static internal::VectorFieldValue< dim, scalar_type, ExtractorType_Row >::type extract_value_component(const Vector< scalar_type > &values, const ExtractorType_Row &extractor_row)
void register_dependent_variable(const ValueType &funcs, const ExtractorType &extractor)
static constexpr unsigned int component_to_unrolled_index(const TableIndices< rank_ > &indices)
static constexpr TableIndices< rank_ > unrolled_to_component_indices(const unsigned int i)
#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
#define Assert(cond, exc)
#define AssertIndexRange(index, range)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
static ::ExceptionBase & ExcMessage(std::string arg1)
ScalarFieldHessian< dim, NumberType, ExtractorType_Field, ExtractorType_Derivative > VectorFieldJacobian
NumberType get_tensor_entry(const TensorType< rank, dim, NumberType > &t, const unsigned int unrolled_index)
void set_tensor_entry(TensorType &t, const unsigned int unrolled_index, const NumberType &value)
std::vector< IndexType > extract_field_component_indices(const ExtractorType &extractor, const bool ignore_symmetries=true)
ScalarFieldGradient< dim, NumberType, ExtractorType_Field > VectorFieldValue
void set_dof_values(const DoFCellAccessor< dim, spacedim, lda > &cell, const Vector< number > &local_values, OutputVector &values, const bool perform_check)
constexpr unsigned int invalid_unsigned_int
Definition types.h:228
static const Types< ADNumberType >::tape_index invalid_tape_index
Definition ad_drivers.h:119
static unsigned int first_component(const FEValuesExtractors::Scalar &extractor)
static IndexType local_component(const TableIndices< rank_in > &table_indices, const unsigned int column_offset)
static bool symmetric_component(const unsigned int unrolled_index)
static TableIndices< rank > table_index_view(const TableIndices< rank_in > &table_indices, const unsigned int column_offset)
static unsigned int first_component(const FEValuesExtractors::SymmetricTensor< 2 > &extractor)
static IndexType local_component(const TableIndices< rank_in > &table_indices, const unsigned int column_offset)
static TableIndices< rank > table_index_view(const TableIndices< rank_in > &table_indices, const unsigned int column_offset)
static unsigned int first_component(const FEValuesExtractors::Tensor< 1 > &extractor)
static IndexType local_component(const TableIndices< rank_in > &table_indices, const unsigned int column_offset)
static TableIndices< rank > table_index_view(const TableIndices< rank_in > &table_indices, const unsigned int column_offset)
static unsigned int first_component(const FEValuesExtractors::Tensor< 2 > &extractor)
static IndexType local_component(const TableIndices< rank_in > &table_indices, const unsigned int column_offset)
static bool symmetric_component(const unsigned int unrolled_index)
static IndexType local_component(const TableIndices< rank_in > &table_indices, const unsigned int column_offset)
static unsigned int first_component(const FEValuesExtractors::Vector &extractor)
static TableIndices< rank > table_index_view(const TableIndices< rank_in > &table_indices, const unsigned int column_offset)
typename Extractor< dim, ExtractorType >::template tensor_type< NumberType > type
typename HessianType< ExtractorType_Row, ExtractorType_Col >::template type< rank, dim, NumberType > type