15#ifndef dealii_tensor_h
16#define dealii_tensor_h
27#ifdef DEAL_II_WITH_ADOLC
28# include <adolc/adouble.h>
33#include <boost/version.hpp>
34#if BOOST_VERSION >= 106400
35# include <boost/serialization/array_wrapper.hpp>
37# include <boost/serialization/array.hpp>
50template <
typename ElementType,
typename MemorySpace>
53template <
int dim,
typename Number>
57template <
int rank_,
int dim, typename Number =
double>
59template <typename Number>
61template <typename number>
102template <
int dim,
typename Number>
106 static_assert(dim >= 0,
107 "Tensors must have a dimension greater than or equal to one.");
122 static constexpr unsigned int rank = 0;
167 template <
typename OtherNumber>
176 template <
typename OtherNumber>
180#ifdef DEAL_II_DELETED_MOVE_CONSTRUCTOR_BUG
223 template <
typename OtherNumber>
227#if defined(__INTEL_COMPILER) || defined(DEAL_II_DELETED_MOVE_CONSTRUCTOR_BUG)
240#ifdef DEAL_II_DELETED_MOVE_CONSTRUCTOR_BUG
254 template <
typename OtherNumber>
263 template <
typename OtherNumber>
270 template <
typename OtherNumber>
277 template <
typename OtherNumber>
286 template <
typename OtherNumber>
295 template <
typename OtherNumber>
304 template <
typename OtherNumber>
313 template <
typename OtherNumber>
364 template <
class Iterator>
366 unroll(
const Iterator begin,
const Iterator end)
const;
373 template <
class Archive>
390 template <
int,
int,
typename>
469template <
int rank_,
int dim,
typename Number>
473 static_assert(rank_ >= 1,
474 "Tensors must have a rank greater than or equal to one.");
475 static_assert(dim >= 0,
476 "Tensors must have a dimension greater than or equal to zero.");
490 static constexpr unsigned int rank = rank_;
515 std::conditional_t<rank_ == 1, Number,
Tensor<rank_ - 1, dim, Number>>;
530 Number[(dim != 0) ? dim : 1],
560 template <
typename ElementType,
typename MemorySpace>
571 template <
typename OtherNumber>
578 template <
typename OtherNumber>
585 template <
typename OtherNumber>
589#ifdef DEAL_II_DELETED_MOVE_CONSTRUCTOR_BUG
620 constexpr const Number &
664 template <
typename OtherNumber>
685#ifdef DEAL_II_DELETED_MOVE_CONSTRUCTOR_BUG
702 template <
typename OtherNumber>
709 template <
typename OtherNumber>
718 template <
typename OtherNumber>
727 template <
typename OtherNumber>
737 template <
typename OtherNumber>
746 template <
typename OtherNumber>
804 template <
class Iterator>
806 unroll(
const Iterator begin,
const Iterator end)
const;
827 static constexpr std::size_t
835 template <
class Archive>
851 std::conditional_t<rank_ == 1,
852 std::array<Number, dim>,
853 std::array<
Tensor<rank_ - 1, dim, Number>, dim>>
862 template <
typename ArrayLike, std::size_t... Indices>
864 Tensor(
const ArrayLike &initializer, std::index_sequence<Indices...>);
867 template <
int,
int,
typename>
872 friend class Point<dim, Number>;
883 template <
int rank,
int dim,
typename T,
typename U>
884 struct ProductTypeImpl<
Tensor<rank, dim, T>,
std::complex<U>>
890 template <
int rank,
int dim,
typename T,
typename U>
891 struct ProductTypeImpl<
Tensor<rank, dim,
std::complex<T>>, std::complex<U>>
897 template <
typename T,
int rank,
int dim,
typename U>
898 struct ProductTypeImpl<
std::complex<T>,
Tensor<rank, dim, U>>
904 template <
int rank,
int dim,
typename T,
typename U>
905 struct ProductTypeImpl<
std::complex<T>,
Tensor<rank, dim, std::complex<U>>>
916 template <
int rank,
int dim,
typename T>
917 struct NumberType<
Tensor<rank, dim, T>>
940template <
int dim,
typename Number>
950template <
int dim,
typename Number>
951template <
typename OtherNumber>
959template <
int dim,
typename Number>
960template <
typename OtherNumber>
967# ifdef DEAL_II_DELETED_MOVE_CONSTRUCTOR_BUG
968template <
int dim,
typename Number>
976template <
int dim,
typename Number>
979 :
value{std::move(other.value)}
985template <
int dim,
typename Number>
990 ExcMessage(
"Cannot access an object of type Tensor<0,0,Number>"));
995template <
int dim,
typename Number>
1000 ExcMessage(
"Cannot access an object of type Tensor<0,0,Number>"));
1006template <
int dim,
typename Number>
1007template <
typename OtherNumber>
1016# if defined(__INTEL_COMPILER) || defined(DEAL_II_DELETED_MOVE_CONSTRUCTOR_BUG)
1017template <
int dim,
typename Number>
1026# ifdef DEAL_II_DELETED_MOVE_CONSTRUCTOR_BUG
1027template <
int dim,
typename Number>
1031 value = std::move(other.value);
1038template <
int dim,
typename Number>
1039template <
typename OtherNumber>
1048template <
int dim,
typename Number>
1049template <
typename OtherNumber>
1050constexpr inline bool
1053# ifdef DEAL_II_ADOLC_WITH_ADVANCED_BRANCHING
1054 Assert(!(std::is_same_v<Number, adouble> ||
1055 std::is_same_v<OtherNumber, adouble>),
1057 "The Tensor equality operator for ADOL-C taped numbers has not yet "
1058 "been extended to support advanced branching."));
1065template <
int dim,
typename Number>
1066template <
typename OtherNumber>
1070 return !((*this) == p);
1074template <
int dim,
typename Number>
1075template <
typename OtherNumber>
1084template <
int dim,
typename Number>
1085template <
typename OtherNumber>
1097 namespace ComplexWorkaround
1099 template <
typename Number,
typename OtherNumber>
1101 multiply_assign_scalar(Number &val,
const OtherNumber &s)
1106 template <
typename Number,
typename OtherNumber>
1108 multiply_assign_scalar(std::complex<Number> &val,
const OtherNumber &s)
1110# if KOKKOS_VERSION >= 30600
1111 KOKKOS_IF_ON_HOST((val *= s;))
1112 KOKKOS_IF_ON_DEVICE(({
1116 "This function is not implemented for std::complex<Number>!\n");
1119# ifdef KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST
1125 "This function is not implemented for std::complex<Number>!\n");
1133template <
int dim,
typename Number>
1134template <
typename OtherNumber>
1138 internal::ComplexWorkaround::multiply_assign_scalar(value, s);
1144template <
int dim,
typename Number>
1145template <
typename OtherNumber>
1154template <
int dim,
typename Number>
1162template <
int dim,
typename Number>
1167 ExcMessage(
"Cannot access an object of type Tensor<0,0,Number>"));
1172template <
int dim,
typename Number>
1178 ExcMessage(
"Cannot access an object of type Tensor<0,0,Number>"));
1184template <
int dim,
typename Number>
1185constexpr inline void
1195template <
int dim,
typename Number>
1196template <
class Iterator>
1203 ExcMessage(
"Cannot unroll an object of type Tensor<0,0,Number>"));
1204 Assert(std::distance(begin, end) >= 1,
1205 ExcMessage(
"The provided iterator range must contain at least one "
1212template <
int dim,
typename Number>
1213template <
class Archive>
1221template <
int dim,
typename Number>
1227template <
int rank_,
int dim,
typename Number>
1228template <
typename ArrayLike, std::size_t... indices>
1231 std::index_sequence<indices...>)
1248 if constexpr (rank_ == 1)
1254 static_assert(
sizeof...(indices) == dim,
1255 "dim should match the number of indices");
1259# ifdef DEAL_II_HAVE_CXX20
1261template <
int rank_,
int dim,
typename Number>
1296 []<
std::size_t... I>(
1297 const
std::index_sequence<I...> &) constexpr -> decltype(
values) {
1298 if constexpr (rank_ == 1)
1300 auto get_zero_and_ignore_argument = [](
int) {
1303 return {{(get_zero_and_ignore_argument(I))...}};
1307 auto get_zero_and_ignore_argument = [](
int) {
1308 return Tensor<rank_ - 1, dim, Number>();
1310 return {{(get_zero_and_ignore_argument(I))...}};
1312 }(std::make_index_sequence<dim>()))
1328 namespace TensorInitialization
1330 template <
int rank,
int dim,
typename Number, std::size_t... I>
1331 constexpr std::array<typename Tensor<rank, dim, Number>::value_type, dim>
1332 make_zero_array(
const std::index_sequence<I...> &)
1334 static_assert(
sizeof...(I) == dim,
"This is bad.");
1340 if constexpr (dim == 0)
1344 else if constexpr (rank == 1)
1346 auto get_zero_and_ignore_argument = [](
int) {
1349 return {{(get_zero_and_ignore_argument(I))...}};
1353 auto get_zero_and_ignore_argument = [](
int) {
1354 return Tensor<rank - 1, dim, Number>();
1356 return {{(get_zero_and_ignore_argument(I))...}};
1363template <
int rank_,
int dim,
typename Number>
1366 :
values(
internal::TensorInitialization::make_zero_array<rank_, dim, Number>(
1367 std::make_index_sequence<dim>()))
1374template <
int rank_,
int dim,
typename Number>
1377 :
Tensor(initializer,
std::make_index_sequence<dim>{})
1382template <
int rank_,
int dim,
typename Number>
1383template <
typename ElementType,
typename MemorySpace>
1389 const int my_n_independent_components = n_independent_components;
1392 for (
unsigned int i = 0; i < my_n_independent_components; ++i)
1393 (*
this)[unrolled_to_component_indices(i)] = initializer[i];
1398template <
int rank_,
int dim,
typename Number>
1399template <
typename OtherNumber>
1403 :
Tensor(initializer,
std::make_index_sequence<dim>{})
1408template <
int rank_,
int dim,
typename Number>
1409template <
typename OtherNumber>
1413 :
Tensor(initializer,
std::make_index_sequence<dim>{})
1418template <
int rank_,
int dim,
typename Number>
1419template <
typename OtherNumber>
1421operator
Tensor<1, dim,
Tensor<rank_ - 1, dim, OtherNumber>>()
const
1424 std::copy(
values.begin(),
values.end(), x.values.begin());
1429# ifdef DEAL_II_DELETED_MOVE_CONSTRUCTOR_BUG
1430template <
int rank_,
int dim,
typename Number>
1438template <
int rank_,
int dim,
typename Number>
1441 :
values(std::move(other.values))
1447template <
int rank_,
int dim,
typename Number>
1453 ExcMessage(
"Cannot access an object of type Tensor<rank_,0,Number>"));
1461template <
int rank_,
int dim,
typename Number>
1467 ExcMessage(
"Cannot access an object of type Tensor<rank_,0,Number>"));
1475template <
int rank_,
int dim,
typename Number>
1480 ExcMessage(
"Cannot access an object of type Tensor<rank_,0,Number>"));
1482 return TensorAccessors::extract<rank_>(*
this, indices);
1487template <
int rank_,
int dim,
typename Number>
1492 ExcMessage(
"Cannot access an object of type Tensor<rank_,0,Number>"));
1494 return TensorAccessors::extract<rank_>(*
this, indices);
1499template <
int rank_,
int dim,
typename Number>
1503 static_assert(rank_ == 1,
1504 "This function is only available for rank-1 tensors "
1505 "because higher-rank tensors may not store their elements "
1506 "in a contiguous array.");
1508 return std::addressof(
1509 this->
operator[](this->unrolled_to_component_indices(0)));
1514template <
int rank_,
int dim,
typename Number>
1515inline const Number *
1518 static_assert(rank_ == 1,
1519 "This function is only available for rank-1 tensors "
1520 "because higher-rank tensors may not store their elements "
1521 "in a contiguous array.");
1523 return std::addressof(
1524 this->
operator[](this->unrolled_to_component_indices(0)));
1529template <
int rank_,
int dim,
typename Number>
1533 static_assert(rank_ == 1,
1534 "This function is only available for rank-1 tensors "
1535 "because higher-rank tensors may not store their elements "
1536 "in a contiguous array.");
1538 return begin_raw() + n_independent_components;
1543template <
int rank_,
int dim,
typename Number>
1544inline const Number *
1547 static_assert(rank_ == 1,
1548 "This function is only available for rank-1 tensors "
1549 "because higher-rank tensors may not store their elements "
1550 "in a contiguous array.");
1552 return begin_raw() + n_independent_components;
1557template <
int rank_,
int dim,
typename Number>
1558template <
typename OtherNumber>
1564 for (
unsigned int i = 0; i < dim; ++i)
1571template <
int rank_,
int dim,
typename Number>
1579 for (
unsigned int i = 0; i < dim; ++i)
1585# ifdef DEAL_II_DELETED_MOVE_CONSTRUCTOR_BUG
1586template <
int rank_,
int dim,
typename Number>
1590 for (
unsigned int i = 0; i < dim; ++i)
1591 values[i] = other.
values[i];
1597template <
int rank_,
int dim,
typename Number>
1602 for (
unsigned int i = 0; i < dim; ++i)
1603 values[i] = other.
values[i];
1609template <
int rank_,
int dim,
typename Number>
1610template <
typename OtherNumber>
1611constexpr inline bool
1615# ifdef DEAL_II_ADOLC_WITH_ADVANCED_BRANCHING
1616 Assert(!(std::is_same_v<Number, adouble> ||
1617 std::is_same_v<OtherNumber, adouble>),
1619 "The Tensor equality operator for ADOL-C taped numbers has not yet "
1620 "been extended to support advanced branching."));
1623 for (
unsigned int i = 0; i < dim; ++i)
1637constexpr inline bool
1644template <
int rank_,
int dim,
typename Number>
1645template <
typename OtherNumber>
1650 return !((*this) == p);
1654template <
int rank_,
int dim,
typename Number>
1655template <
typename OtherNumber>
1661 for (
unsigned int i = 0; i < dim; ++i)
1662 values[i] += p.
values[i];
1667template <
int rank_,
int dim,
typename Number>
1668template <
typename OtherNumber>
1674 for (
unsigned int i = 0; i < dim; ++i)
1675 values[i] -= p.
values[i];
1680template <
int rank_,
int dim,
typename Number>
1681template <
typename OtherNumber>
1686 for (
unsigned int i = 0; i < dim; ++i)
1693template <
int rank_,
int dim,
typename Number>
1694template <
typename OtherNumber>
1699 if constexpr (std::is_integral<
1701 std::is_same_v<Number, Differentiation::SD::Expression>)
1704 for (
unsigned int d = 0;
d < dim; ++
d)
1711 const Number inverse_factor = Number(1.) / s;
1712 for (
unsigned int d = 0;
d < dim; ++
d)
1713 values[d] *= inverse_factor;
1720template <
int rank_,
int dim,
typename Number>
1727 for (
unsigned int i = 0; i < dim; ++i)
1728 tmp.
values[i] = -values[i];
1734template <
int rank_,
int dim,
typename Number>
1740 if constexpr ((rank_ == 1) && (dim == 1) && std::is_arithmetic_v<Number>)
1744 else if constexpr ((rank_ == 2) && (dim == 1) && std::is_arithmetic_v<Number>)
1757 return sqrt(norm_square());
1762template <
int rank_,
int dim,
typename Number>
1767 if constexpr (dim == 0)
1770 else if constexpr (rank_ == 1)
1776 for (
unsigned int i = 1; i < dim; ++i)
1787 for (
unsigned int i = 1; i < dim; ++i)
1788 s += values[i].norm_square();
1796template <
int rank_,
int dim,
typename Number>
1797template <
class Iterator>
1800 const Iterator end)
const
1802 if constexpr (rank_ > 1)
1805 Iterator next =
begin;
1806 for (
unsigned int i = 0; i < dim; ++i)
1808 values[i].unroll(next, end);
1818 Assert(std::distance(begin, end) >= dim,
1820 "The provided iterator range must contain at least 'dim' "
1822 std::copy(std::begin(values), std::end(values), begin);
1828template <
int rank_,
int dim,
typename Number>
1829constexpr inline unsigned int
1833 unsigned int index = 0;
1834 for (
int r = 0; r < rank_; ++r)
1835 index = index * dim + indices[r];
1842template <
int rank_,
int dim,
typename Number>
1847 unsigned int dummy = n_independent_components;
1851 if constexpr (dim == 0)
1855 "A tensor with dimension 0 does not store any elements. "
1856 "There is no indexing that can address its elements."));
1863 unsigned int remainder = i;
1864 for (
int r = rank_ - 1; r >= 0; --r)
1866 indices[r] = remainder % dim;
1867 remainder = remainder / dim;
1876template <
int rank_,
int dim,
typename Number>
1877constexpr inline void
1880 for (
unsigned int i = 0; i < dim; ++i)
1885template <
int rank_,
int dim,
typename Number>
1886constexpr std::size_t
1893template <
int rank_,
int dim,
typename Number>
1894template <
class Archive>
1898 if constexpr (rank_ > 1)
1901 ar &boost::serialization::make_array(&values[0], dim);
1905template <
int rank_,
int dim,
typename Number>
1924template <
int rank_,
int dim,
typename Number>
1925inline std::ostream &
1928 for (
unsigned int i = 0; i < dim; ++i)
1932 for (
unsigned int j = 0; j < rank_; ++j)
1946template <
int dim,
typename Number>
1947inline std::ostream &
1950 out << static_cast<const Number &>(p);
1973template <
int dim,
typename Number,
typename Other>
1978 return object *
static_cast<const Number &
>(t);
1993template <
int dim,
typename Number,
typename Other>
1998 return static_cast<const Number &
>(t) *
object;
2013template <
int dim,
typename Number,
typename OtherNumber>
2019 return static_cast<const Number &
>(src1) *
2020 static_cast<const OtherNumber &
>(src2);
2031template <
int dim,
typename Number,
typename OtherNumber>
2039 return static_cast<const Number &
>(t) / factor;
2050template <
int dim,
typename Number,
typename OtherNumber>
2056 return static_cast<const Number &
>(p) +
static_cast<const OtherNumber &
>(q);
2067template <
int dim,
typename Number,
typename OtherNumber>
2073 return static_cast<const Number &
>(p) -
static_cast<const OtherNumber &
>(q);
2089template <
int rank,
int dim,
typename Number,
typename OtherNumber>
2115template <
int rank,
int dim,
typename Number,
typename OtherNumber>
2138template <
int rank,
int dim,
typename Number,
typename OtherNumber>
2161template <
int rank,
int dim,
typename Number,
typename OtherNumber>
2182template <
int rank,
int dim,
typename Number,
typename OtherNumber>
2199template <
int dim,
typename Number,
typename OtherNumber>
2228template <
int rank,
int dim,
typename Number,
typename OtherNumber>
2236 for (
unsigned int i = 0; i < dim; ++i)
2287template <
int rank_1,
2291 typename OtherNumber,
2292 typename = std::enable_if_t<rank_1 >= 1 && rank_2 >= 1>>
2294 typename Tensor<rank_1 + rank_2 - 2,
2306 if constexpr ((rank_1 == 1) && (rank_2 == 1))
2310 static_assert(dim > 0,
"Tensors cannot have dimension zero.");
2312 for (
unsigned int i = 1; i < dim; ++i)
2313 sum += src1[i] * src2[i];
2317 else if constexpr ((rank_1 == 2) && (rank_2 == 1))
2323 rank_1 + rank_2 - 2,
2326 for (
unsigned int i = 0; i < dim; ++i)
2327 result[i] += src1[i] * src2;
2336 rank_1 + rank_2 - 2,
2340 TensorAccessors::internal::
2341 ReorderedIndexView<0, rank_2, const Tensor<rank_2, dim, OtherNumber>>
2342 reordered = TensorAccessors::reordered_index_view<0, rank_2>(src2);
2343 TensorAccessors::contract<1, rank_1, rank_2, dim>(result,
2380template <
int index_1,
2386 typename OtherNumber>
2388 typename Tensor<rank_1 + rank_2 - 2,
2394 Assert(0 <= index_1 && index_1 < rank_1,
2396 "The specified index_1 must lie within the range [0,rank_1)"));
2397 Assert(0 <= index_2 && index_2 < rank_2,
2399 "The specified index_2 must lie within the range [0,rank_2)"));
2406 reord_01 = reordered_index_view<index_1, rank_1>(src1);
2412 reord_02 = reordered_index_view<index_2, rank_2>(src2);
2414 typename Tensor<rank_1 + rank_2 - 2,
2418 TensorAccessors::contract<1, rank_1, rank_2, dim>(result, reord_01, reord_02);
2453template <
int index_1,
2461 typename OtherNumber>
2463 typename Tensor<rank_1 + rank_2 - 4,
2469 Assert(0 <= index_1 && index_1 < rank_1,
2471 "The specified index_1 must lie within the range [0,rank_1)"));
2472 Assert(0 <= index_3 && index_3 < rank_1,
2474 "The specified index_3 must lie within the range [0,rank_1)"));
2475 Assert(index_1 != index_3,
2476 ExcMessage(
"index_1 and index_3 must not be the same"));
2477 Assert(0 <= index_2 && index_2 < rank_2,
2479 "The specified index_2 must lie within the range [0,rank_2)"));
2480 Assert(0 <= index_4 && index_4 < rank_2,
2482 "The specified index_4 must lie within the range [0,rank_2)"));
2483 Assert(index_2 != index_4,
2484 ExcMessage(
"index_2 and index_4 must not be the same"));
2491 reord_1 = TensorAccessors::reordered_index_view<index_1, rank_1>(src1);
2495 reord_2 = TensorAccessors::reordered_index_view<index_2, rank_2>(src2);
2501 (index_3 < index_1 ? index_3 : index_3 - 1),
2513 (index_4 < index_2 ? index_4 : index_4 - 1),
2521 typename Tensor<rank_1 + rank_2 - 4,
2525 TensorAccessors::contract<2, rank_1, rank_2, dim>(result, reord_3, reord_4);
2542template <
int rank,
int dim,
typename Number,
typename OtherNumber>
2549 TensorAccessors::contract<rank, rank, rank, dim>(result, left, right);
2571template <
template <
int,
int,
typename>
class TensorT1,
2572 template <
int,
int,
typename>
2574 template <
int,
int,
typename>
2584 contract3(
const TensorT1<rank_1, dim, T1> &left,
2585 const TensorT2<rank_1 + rank_2, dim, T2> &middle,
2586 const TensorT3<rank_2, dim, T3> &right)
2590 return TensorAccessors::contract3<rank_1, rank_2, dim, return_type>(left,
2606template <
int rank_1,
2610 typename OtherNumber>
2616 typename Tensor<rank_1 + rank_2,
2620 TensorAccessors::contract<0, rank_1, rank_2, dim>(result, src1, src2);
2643template <
int dim,
typename Number>
2652 result[1] = -src[0];
2667template <
int dim,
typename Number1,
typename Number2>
2678 constexpr int s0 = 0 % dim;
2679 constexpr int s1 = 1 % dim;
2680 constexpr int s2 = 2 % dim;
2682 result[s0] = src1[s1] * src2[s2] - src1[s2] * src2[s1];
2683 result[s1] = src1[s2] * src2[s0] - src1[s0] * src2[s2];
2684 result[s2] = src1[s0] * src2[s1] - src1[s1] * src2[s0];
2703template <
int dim,
typename Number>
2711 for (
unsigned int k = 0; k < dim; ++k)
2713 Tensor<2, dim - 1, Number> minor;
2714 for (
unsigned int i = 0; i < dim - 1; ++i)
2715 for (
unsigned int j = 0; j < dim - 1; ++j)
2716 minor[i][j] = t[i][j < k ? j : j + 1];
2718 const Number cofactor = ((k % 2 == 0) ? -1. : 1.) *
determinant(minor);
2720 det += t[dim - 1][k] * cofactor;
2723 return ((dim % 2 == 0) ? 1. : -1.) * det;
2731template <
typename Number>
2743template <
typename Number>
2748 return t[0][0] * t[1][1] - t[1][0] * t[0][1];
2756template <
typename Number>
2767 return t[0][0] * C0 + t[0][1] * C1 + t[0][2] * C2;
2777template <
int dim,
typename Number>
2782 for (
unsigned int i = 1; i < dim; ++i)
2796template <
int dim,
typename Number>
2800 Number return_tensor[dim][dim];
2813template <
typename Number>
2821 return return_tensor;
2825template <
typename Number>
2832 1.0 / (t[0][0] * t[1][1] - t[1][0] * t[0][1]));
2833 return_tensor[0][0] = t[1][1];
2834 return_tensor[0][1] = -t[0][1];
2835 return_tensor[1][0] = -t[1][0];
2836 return_tensor[1][1] = t[0][0];
2837 return_tensor *= inv_det_t;
2839 return return_tensor;
2842template <
typename Number>
2848 const auto value = [](
const auto &t) {
2852 return_tensor[0][0] =
value(t[1][1] * t[2][2]) -
value(t[1][2] * t[2][1]);
2853 return_tensor[0][1] =
value(t[0][2] * t[2][1]) -
value(t[0][1] * t[2][2]);
2854 return_tensor[0][2] =
value(t[0][1] * t[1][2]) -
value(t[0][2] * t[1][1]);
2855 return_tensor[1][0] =
value(t[1][2] * t[2][0]) -
value(t[1][0] * t[2][2]);
2856 return_tensor[1][1] =
value(t[0][0] * t[2][2]) -
value(t[0][2] * t[2][0]);
2857 return_tensor[1][2] =
value(t[0][2] * t[1][0]) -
value(t[0][0] * t[1][2]);
2858 return_tensor[2][0] =
value(t[1][0] * t[2][1]) -
value(t[1][1] * t[2][0]);
2859 return_tensor[2][1] =
value(t[0][1] * t[2][0]) -
value(t[0][0] * t[2][1]);
2860 return_tensor[2][2] =
value(t[0][0] * t[1][1]) -
value(t[0][1] * t[1][0]);
2862 const Number inv_det_t =
2863 value(1.0 / (t[0][0] * return_tensor[0][0] + t[0][1] * return_tensor[1][0] +
2864 t[0][2] * return_tensor[2][0]));
2865 return_tensor *= inv_det_t;
2867 return return_tensor;
2878template <
int dim,
typename Number>
2883 for (
unsigned int i = 0; i < dim; ++i)
2886 for (
unsigned int j = i + 1; j < dim; ++j)
2909template <
int dim,
typename Number>
2930template <
int dim,
typename Number>
3001template <
int dim,
typename Number>
3013template <
int dim,
typename Number>
3018 for (
unsigned int j = 0; j < dim; ++j)
3021 for (
unsigned int i = 0; i < dim; ++i)
3039template <
int dim,
typename Number>
3044 for (
unsigned int i = 0; i < dim; ++i)
3047 for (
unsigned int j = 0; j < dim; ++j)
3065# ifdef DEAL_II_ADOLC_WITH_ADVANCED_BRANCHING
3074 for (
unsigned int j = 0; j < dim; ++j)
3077 for (
unsigned int i = 0; i < dim; ++i)
3078 sum += fabs(t[i][j]);
3080 condassign(max, (sum > max), sum, max);
3092 for (
unsigned int i = 0; i < dim; ++i)
3095 for (
unsigned int j = 0; j < dim; ++j)
3096 sum +=
fabs(t[i][j]);
3098 condassign(max, (sum > max), sum, max);
constexpr Tensor & operator*=(const OtherNumber &factor)
constexpr Tensor & operator=(const OtherNumber &d) &&=delete
void serialize(Archive &ar, const unsigned int version)
constexpr Tensor & operator/=(const OtherNumber &factor)
constexpr Tensor & operator-=(const Tensor< 0, dim, OtherNumber > &rhs)
constexpr Tensor(const Tensor< 0, dim, OtherNumber > &initializer)
constexpr Tensor(const OtherNumber &initializer)
constexpr real_type norm_square() const
constexpr bool operator!=(const Tensor< 0, dim, OtherNumber > &rhs) const
constexpr Tensor & operator=(const Tensor< 0, dim, OtherNumber > &rhs)
constexpr Tensor & operator+=(const Tensor< 0, dim, OtherNumber > &rhs)
void unroll(const Iterator begin, const Iterator end) const
constexpr bool operator==(const Tensor< 0, dim, OtherNumber > &rhs) const
typename numbers::NumberTraits< Number >::real_type real_type
constexpr Tensor & operator=(const OtherNumber &d) &
constexpr Tensor operator-() const
constexpr Tensor & operator/=(const OtherNumber &factor)
constexpr Tensor(const ArrayView< ElementType, MemorySpace > &initializer)
constexpr bool operator==(const Tensor< rank_, dim, OtherNumber > &) const
constexpr Tensor< rank, dim, typename ProductType< Number, typename EnableIfScalar< OtherNumber >::type >::type > operator/(const Tensor< rank, dim, Number > &t, const OtherNumber &factor)
constexpr Tensor(const Tensor< 1, dim, Tensor< rank_ - 1, dim, OtherNumber > > &initializer)
constexpr const Number & operator[](const TableIndices< rank_ > &indices) const
constexpr Tensor< 0, dim, typename ProductType< Number, typename EnableIfScalar< OtherNumber >::type >::type > operator/(const Tensor< 0, dim, Number > &t, const OtherNumber &factor)
static constexpr unsigned int rank
constexpr Tensor(const Tensor< rank_, dim, OtherNumber > &initializer)
std::conditional_t< rank_==1, Number, Tensor< rank_ - 1, dim, Number > > value_type
numbers::NumberTraits< Number >::real_type norm() const
constexpr Tensor & operator-=(const Tensor< rank_, dim, OtherNumber > &)
void unroll(const Iterator begin, const Iterator end) const
static constexpr unsigned int component_to_unrolled_index(const TableIndices< rank_ > &indices)
constexpr ProductType< Number, OtherNumber >::type operator*(const Tensor< 0, dim, Number > &src1, const Tensor< 0, dim, OtherNumber > &src2)
const Number * begin_raw() const
std::conditional_t< rank_==1, Number[(dim !=0) ? dim :1], typename Tensor< rank_ - 1, dim, Number >::array_type[(dim !=0) ? dim :1]> array_type
constexpr bool operator!=(const Tensor< rank_, dim, OtherNumber > &) const
constexpr Tensor< 0, dim, typename ProductType< Number, OtherNumber >::type > schur_product(const Tensor< 0, dim, Number > &src1, const Tensor< 0, dim, OtherNumber > &src2)
constexpr value_type & operator[](const unsigned int i)
constexpr DEAL_II_HOST_DEVICE_ALWAYS_INLINE Tensor< 0, dim, typename ProductType< Number, OtherNumber >::type > operator-(const Tensor< 0, dim, Number > &p, const Tensor< 0, dim, OtherNumber > &q)
constexpr Tensor< rank, dim, typename ProductType< Number, OtherNumber >::type > operator+(const Tensor< rank, dim, Number > &p, const Tensor< rank, dim, OtherNumber > &q)
Number linfty_norm(const Tensor< 2, dim, Number > &t)
constexpr ProductType< Other, Number >::type operator*(const Other &object, const Tensor< 0, dim, Number > &t)
constexpr DEAL_II_HOST_DEVICE_ALWAYS_INLINE Tensor()
Number l1_norm(const Tensor< 2, dim, Number > &t)
static constexpr unsigned int dimension
static constexpr TableIndices< rank_ > unrolled_to_component_indices(const unsigned int i)
constexpr Tensor & operator=(const Number &d) &&=delete
constexpr Tensor< rank, dim, typename ProductType< typename EnableIfScalar< Number >::type, OtherNumber >::type > operator*(const Number &factor, const Tensor< rank, dim, OtherNumber > &t)
static constexpr std::size_t memory_consumption()
constexpr Tensor & operator=(const Number &d) &
std::conditional_t< rank_==1, std::array< Number, dim >, std::array< Tensor< rank_ - 1, dim, Number >, dim > > values
constexpr Tensor & operator+=(const Tensor< rank_, dim, OtherNumber > &)
constexpr DEAL_II_HOST_DEVICE_ALWAYS_INLINE Tensor< 0, dim, typename ProductType< Number, OtherNumber >::type > operator+(const Tensor< 0, dim, Number > &p, const Tensor< 0, dim, OtherNumber > &q)
const Number * end_raw() const
constexpr Number & operator[](const TableIndices< rank_ > &indices)
constexpr Tensor< rank, dim, typename ProductType< Number, OtherNumber >::type > schur_product(const Tensor< rank, dim, Number > &src1, const Tensor< rank, dim, OtherNumber > &src2)
constexpr numbers::NumberTraits< Number >::real_type norm_square() const
constexpr Tensor< rank, dim, typename ProductType< Number, OtherNumber >::type > operator-(const Tensor< rank, dim, Number > &p, const Tensor< rank, dim, OtherNumber > &q)
constexpr ProductType< Number, Other >::type operator*(const Tensor< 0, dim, Number > &t, const Other &object)
constexpr Tensor(const ArrayLike &initializer, std::index_sequence< Indices... >)
constexpr Tensor< rank, dim, typename ProductType< Number, typename EnableIfScalar< OtherNumber >::type >::type > operator*(const Tensor< rank, dim, Number > &t, const OtherNumber &factor)
void serialize(Archive &ar, const unsigned int version)
constexpr Tensor & operator*=(const OtherNumber &factor)
constexpr const value_type & operator[](const unsigned int i) const
constexpr Tensor(const array_type &initializer)
static constexpr unsigned int n_independent_components
constexpr Tensor operator-() const
constexpr Tensor & operator=(const Tensor< rank_, dim, OtherNumber > &rhs)
#define DEAL_II_ALWAYS_INLINE
#define DEAL_II_DEPRECATED
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_CXX20_REQUIRES(condition)
#define DEAL_II_CXX23_ASSUME(expr)
#define DEAL_II_NAMESPACE_CLOSE
static ::ExceptionBase & ExcNotImplemented()
static ::ExceptionBase & ExcScalarAssignmentOnlyForZeroValue()
#define Assert(cond, exc)
#define AssertDimension(dim1, dim2)
#define AssertIndexRange(index, range)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
Expression fabs(const Expression &x)
SymmetricTensor< 2, dim, Number > d(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
constexpr internal::ReorderedIndexView< index, rank, T > reordered_index_view(T &t)
constexpr void contract(T1 &result, const T2 &left, const T3 &right)
constexpr T1 contract3(const T2 &left, const T3 &middle, const T4 &right)
VectorType::value_type * begin(VectorType &V)
T sum(const T &t, const MPI_Comm mpi_communicator)
constexpr bool values_are_not_equal(const Number1 &value_1, const Number2 &value_2)
constexpr bool value_is_zero(const Number &value)
constexpr bool values_are_equal(const Number1 &value_1, const Number2 &value_2)
::VectorizedArray< Number, width > sqrt(const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > abs(const ::VectorizedArray< Number, width > &)
#define DEAL_II_HOST_DEVICE
#define DEAL_II_HOST_DEVICE_ALWAYS_INLINE
typename internal::ProductTypeImpl< std::decay_t< T >, std::decay_t< U > >::type type
static constexpr DEAL_II_HOST_DEVICE_ALWAYS_INLINE const T & value(const T &t)
decltype(std::declval< T >() *std::declval< U >()) type
static real_type abs(const number &x)
static constexpr real_type abs_square(const number &x)
DEAL_II_HOST constexpr Number determinant(const SymmetricTensor< 2, dim, Number > &)
DEAL_II_HOST constexpr SymmetricTensor< 2, dim, Number > invert(const SymmetricTensor< 2, dim, Number > &)
DEAL_II_HOST constexpr SymmetricTensor< 4, dim, Number > outer_product(const SymmetricTensor< 2, dim, Number > &t1, const SymmetricTensor< 2, dim, Number > &t2)
DEAL_II_HOST constexpr Number trace(const SymmetricTensor< 2, dim2, Number > &)
Tensor< 2, dim, Number > project_onto_orthogonal_tensors(const Tensor< 2, dim, Number > &A)
std::ostream & operator<<(std::ostream &out, const Tensor< rank_, dim, Number > &p)
constexpr Tensor< 0, dim, typename ProductType< Number, OtherNumber >::type > schur_product(const Tensor< 0, dim, Number > &src1, const Tensor< 0, dim, OtherNumber > &src2)
Number linfty_norm(const Tensor< 2, dim, Number > &t)
constexpr ProductType< Other, Number >::type operator*(const Other &object, const Tensor< 0, dim, Number > &t)
Number l1_norm(const Tensor< 2, dim, Number > &t)