*
* If you want to use this function in a `constexpr` context,
* use symmetrize() instead.
+ *
+ * Because we check for symmetry via a non-constexpr function call, you will
+ * have to use the symmetrize() function in constexpr contexts instead.
*/
template <typename OtherNumber>
explicit SymmetricTensor(const Tensor<2, dim, OtherNumber> &t);
* Internal helper function for unroll.
*/
template <typename OtherNumber>
- DEAL_II_CONSTEXPR void
+ void
unroll_recursion(Vector<OtherNumber> &result,
unsigned int & start_index) const;
template <int dim, typename Number>
-DEAL_II_CONSTEXPR DEAL_II_CUDA_HOST_DEV inline
+DEAL_II_CONSTEXPR DEAL_II_CUDA_HOST_DEV inline DEAL_II_ALWAYS_INLINE
typename Tensor<0, dim, Number>::real_type
Tensor<0, dim, Number>::norm_square() const
{
template <int dim, typename Number>
template <typename OtherNumber>
-inline DEAL_II_CONSTEXPR void
+inline void
Tensor<0, dim, Number>::unroll_recursion(Vector<OtherNumber> &result,
unsigned int & index) const
{
DEAL_II_CONSTEXPR inline DEAL_II_ALWAYS_INLINE Tensor<rank_, dim, Number> &
Tensor<rank_, dim, Number>::operator=(const Tensor<rank_, dim, OtherNumber> &t)
{
- // std::copy is constexpr only from C++20 on.
+ // The following loop could be written more concisely using std::copy, but
+ // that function is only constexpr from C++20 on.
for (unsigned int i = 0; i < dim; ++i)
values[i] = t.values[i];
return *this;
inline unsigned int
mod<0>(const unsigned int x)
{
- // Assert(false, ExcInternalError());
+ Assert(false, ExcInternalError());
return x;
}
* @relatesalso Tensor<0,dim,Number>
*/
template <int dim, typename Number, typename Other>
-constexpr DEAL_II_CUDA_HOST_DEV DEAL_II_ALWAYS_INLINE
+DEAL_II_CONSTEXPR DEAL_II_CUDA_HOST_DEV DEAL_II_ALWAYS_INLINE
typename ProductType<Other, Number>::type
operator*(const Other &object, const Tensor<0, dim, Number> &t)
{
* @relatesalso Tensor<0,dim,Number>
*/
template <int dim, typename Number, typename Other>
-constexpr DEAL_II_CUDA_HOST_DEV DEAL_II_ALWAYS_INLINE
+DEAL_II_CONSTEXPR DEAL_II_CUDA_HOST_DEV DEAL_II_ALWAYS_INLINE
typename ProductType<Number, Other>::type
operator*(const Tensor<0, dim, Number> &t, const Other &object)
{
* @relatesalso Tensor
*/
template <int rank, int dim, typename Number, typename OtherNumber>
-DEAL_II_CUDA_HOST_DEV constexpr DEAL_II_ALWAYS_INLINE
- Tensor<rank,
+DEAL_II_CUDA_HOST_DEV DEAL_II_CONSTEXPR DEAL_II_ALWAYS_INLINE
+ Tensor<rank,
dim,
typename ProductType<typename EnableIfScalar<Number>::type,
OtherNumber>::type>
- operator*(const Number &factor, const Tensor<rank, dim, OtherNumber> &t)
+ operator*(const Number &factor, const Tensor<rank, dim, OtherNumber> &t)
{
// simply forward to the operator above
return t * factor;
deallog << "SymmetricTensor<4,2> = " << B << std::endl;
{
- DEAL_II_CONSTEXPR double a_init[3][3] = {{1., 0., 0.},
- {2., 1., 0.},
- {3., 2., 1.}};
- DEAL_II_CONSTEXPR Tensor<2, 3> dummy_a{a_init};
- DEAL_II_CONSTEXPR SymmetricTensor<2, 3> a = symmetrize(dummy_a);
- std::cout << a << std::endl;
- DEAL_II_CONSTEXPR auto inverted = invert(a);
- std::cout << inverted << std::endl;
- DEAL_II_CONSTEXPR double ref_init[3][3] = {{0., -2., 2.},
- {-2., 5., -2.},
- {2., -2., 0.}};
- DEAL_II_CONSTEXPR Tensor<2, 3> dummy_ref{ref_init};
- DEAL_II_CONSTEXPR SymmetricTensor<2, 3> ref = symmetrize(dummy_ref);
- std::cout << ref << std::endl;
+ constexpr double a_init[3][3] = {{1., 0., 0.}, {2., 1., 0.}, {3., 2., 1.}};
+ constexpr Tensor<2, 3> dummy_a{a_init};
+ DEAL_II_CONSTEXPR const SymmetricTensor<2, 3> a = symmetrize(dummy_a);
+ DEAL_II_CONSTEXPR const auto inverted = invert(a);
+ constexpr double ref_init[3][3] = {{0., -2., 2.},
+ {-2., 5., -2.},
+ {2., -2., 0.}};
+ constexpr Tensor<2, 3> dummy_ref{ref_init};
+ DEAL_II_CONSTEXPR const SymmetricTensor<2, 3> ref = symmetrize(dummy_ref);
Assert(inverted == ref, ExcInternalError());
}
{
- DEAL_II_CONSTEXPR double a_init[3][3] = {{1., 2., 3.},
- {2., 1., 2.},
- {3., 2., 1.}};
- DEAL_II_CONSTEXPR Tensor<2, 3> dummy_a{a_init};
- DEAL_II_CONSTEXPR SymmetricTensor<2, 3> a = symmetrize(dummy_a);
- DEAL_II_CONSTEXPR auto transposed = transpose(a);
+ constexpr double a_init[3][3] = {{1., 2., 3.}, {2., 1., 2.}, {3., 2., 1.}};
+ constexpr Tensor<2, 3> dummy_a{a_init};
+ DEAL_II_CONSTEXPR const SymmetricTensor<2, 3> a = symmetrize(dummy_a);
+ DEAL_II_CONSTEXPR const auto transposed = transpose(a);
Assert(transposed == a, ExcInternalError());
- constexpr auto dummy = scalar_product(a, a);
- constexpr auto dummy_5 = a * a;
- constexpr auto middle = outer_product(a, a);
- constexpr auto dummy_6 = contract3(a, middle, a);
+ DEAL_II_CONSTEXPR const auto dummy = scalar_product(a, a);
+ DEAL_II_CONSTEXPR const auto dummy_5 = a * a;
+ DEAL_II_CONSTEXPR const auto middle = outer_product(a, a);
+ DEAL_II_CONSTEXPR const auto dummy_6 = contract3(a, middle, a);
}
deallog << "OK" << std::endl;
deallog << b << std::endl;
deallog << c << std::endl;
- constexpr auto d = a * 2.;
- constexpr auto e = a / 2.;
- constexpr auto f = d + e;
- constexpr auto g = d - e;
+ DEAL_II_CONSTEXPR const auto d = a * 2.;
+ DEAL_II_CONSTEXPR const auto e = 2. * a;
+ DEAL_II_CONSTEXPR const auto f = a / 2.;
+ DEAL_II_CONSTEXPR const auto g = d + e;
+ DEAL_II_CONSTEXPR const auto h = d - e;
deallog << d << std::endl;
deallog << e << std::endl;
deallog << f << std::endl;
deallog << g << std::endl;
+ deallog << h << std::endl;
}
DEAL_II_CONSTEXPR double
deallog << tensor_rank2_result << std::endl;
{
- DEAL_II_CONSTEXPR double initializer[2] = {1., -1.};
- DEAL_II_CONSTEXPR Tensor<1, 2> c{initializer};
- DEAL_II_CONSTEXPR Tensor<1, 2> c_cross = cross_product_2d(c);
- DEAL_II_CONSTEXPR double initializer_ref[2] = {-1., -1.};
- DEAL_II_CONSTEXPR Tensor<1, 2> ref{initializer_ref};
- DEAL_II_CONSTEXPR bool is_same = (c_cross == ref);
- DEAL_II_CONSTEXPR bool is_not_same = (c_cross != ref);
+ constexpr double initializer[2] = {1., -1.};
+ constexpr Tensor<1, 2> c{initializer};
+ DEAL_II_CONSTEXPR const Tensor<1, 2> c_cross = cross_product_2d(c);
+ constexpr double initializer_ref[2] = {-1., -1.};
+ constexpr Tensor<1, 2> ref{initializer_ref};
+ DEAL_II_CONSTEXPR const bool is_same = (c_cross == ref);
+ DEAL_II_CONSTEXPR const bool is_not_same = (c_cross != ref);
Assert(is_same && !is_not_same, ExcInternalError());
}
{
- DEAL_II_CONSTEXPR double initializer_1[3] = {1., 0., 0.};
- DEAL_II_CONSTEXPR Tensor<1, 3> c_1{initializer_1};
- DEAL_II_CONSTEXPR double initializer_2[3] = {0., 1., 0.};
- DEAL_II_CONSTEXPR Tensor<1, 3> c_2{initializer_2};
-
- DEAL_II_CONSTEXPR auto c_cross = cross_product_3d(c_1, c_2);
- DEAL_II_CONSTEXPR double initializer_ref[3] = {0., 0., 1.};
- DEAL_II_CONSTEXPR Tensor<1, 3> ref{initializer_ref};
- DEAL_II_CONSTEXPR bool is_same = (c_cross == ref);
- DEAL_II_CONSTEXPR bool is_not_same = (c_cross != ref);
+ DEAL_II_CONSTEXPR const double initializer_1[3] = {1., 0., 0.};
+ DEAL_II_CONSTEXPR const Tensor<1, 3> c_1{initializer_1};
+ DEAL_II_CONSTEXPR const double initializer_2[3] = {0., 1., 0.};
+ DEAL_II_CONSTEXPR const Tensor<1, 3> c_2{initializer_2};
+
+ DEAL_II_CONSTEXPR const auto c_cross = cross_product_3d(c_1, c_2);
+ DEAL_II_CONSTEXPR const double initializer_ref[3] = {0., 0., 1.};
+ DEAL_II_CONSTEXPR const Tensor<1, 3> ref{initializer_ref};
+ DEAL_II_CONSTEXPR const bool is_same = (c_cross == ref);
+ DEAL_II_CONSTEXPR const bool is_not_same = (c_cross != ref);
Assert(is_same && !is_not_same, ExcInternalError());
}
- DEAL_II_CONSTEXPR auto table_indices =
+ DEAL_II_CONSTEXPR const auto table_indices =
Tensor<2, 3>::unrolled_to_component_indices(0);
- DEAL_II_CONSTEXPR auto index =
+ DEAL_II_CONSTEXPR const auto index =
Tensor<2, 3>::component_to_unrolled_index(TableIndices<2>{});
Assert(index == 0, ExcInternalError());
- DEAL_II_CONSTEXPR auto used_memory = Tensor<2, 3>::memory_consumption();
+ DEAL_II_CONSTEXPR const auto used_memory = Tensor<2, 3>::memory_consumption();
deallog << "Used memory: " << used_memory << std::endl;
{
- DEAL_II_CONSTEXPR double a_init[3][3] = {{1., 0., 0.},
- {2., 1., 0.},
- {3., 2., 1.}};
- DEAL_II_CONSTEXPR Tensor<2, 3> a{a_init};
- DEAL_II_CONSTEXPR auto inverted = invert(a);
- DEAL_II_CONSTEXPR double ref_init[3][3] = {{1., 0., 0.},
- {-2., 1., 0.},
- {1., -2., 1}};
- DEAL_II_CONSTEXPR Tensor<2, 3> ref{ref_init};
+ DEAL_II_CONSTEXPR const double a_init[3][3] = {{1., 0., 0.},
+ {2., 1., 0.},
+ {3., 2., 1.}};
+ DEAL_II_CONSTEXPR const Tensor<2, 3> a{a_init};
+ DEAL_II_CONSTEXPR const auto inverted = invert(a);
+ DEAL_II_CONSTEXPR const double ref_init[3][3] = {{1., 0., 0.},
+ {-2., 1., 0.},
+ {1., -2., 1}};
+ DEAL_II_CONSTEXPR const Tensor<2, 3> ref{ref_init};
Assert(inverted == ref, ExcInternalError());
}
{
- DEAL_II_CONSTEXPR double a_init[3][3] = {{1., 0., 0.},
- {2., 1., 0.},
- {3., 2., 1.}};
- DEAL_II_CONSTEXPR Tensor<2, 3> a{a_init};
- DEAL_II_CONSTEXPR auto transposed = transpose(a);
- DEAL_II_CONSTEXPR double ref_init[3][3] = {{1., 2., 3.},
- {0., 1., 2.},
- {0., 0., 1}};
- DEAL_II_CONSTEXPR Tensor<2, 3> ref{ref_init};
+ DEAL_II_CONSTEXPR const double a_init[3][3] = {{1., 0., 0.},
+ {2., 1., 0.},
+ {3., 2., 1.}};
+ DEAL_II_CONSTEXPR const Tensor<2, 3> a{a_init};
+ DEAL_II_CONSTEXPR const auto transposed = transpose(a);
+ DEAL_II_CONSTEXPR const double ref_init[3][3] = {{1., 2., 3.},
+ {0., 1., 2.},
+ {0., 0., 1}};
+ DEAL_II_CONSTEXPR const Tensor<2, 3> ref{ref_init};
Assert(transposed == ref, ExcInternalError());
- constexpr auto dummy = scalar_product(a, ref);
- constexpr auto dummy_2 = contract<0, 0>(a, ref);
- constexpr auto dummy_3 = double_contract<0, 0, 1, 1>(a, ref);
- constexpr auto dummy_4 = schur_product(a, ref);
- constexpr auto dummy_5 = a * ref;
- constexpr auto middle = outer_product(a, a);
- constexpr auto dummy_6 = contract3(a, middle, a);
- constexpr auto dummy_7 = adjugate(a);
- constexpr auto dummy_8 = cofactor(a);
- constexpr auto dummy_9 = l1_norm(a);
- constexpr auto dummy_10 = linfty_norm(a);
+ DEAL_II_CONSTEXPR const auto dummy = scalar_product(a, ref);
+ DEAL_II_CONSTEXPR const auto dummy_2 = contract<0, 0>(a, ref);
+ DEAL_II_CONSTEXPR const auto dummy_3 = double_contract<0, 0, 1, 1>(a, ref);
+ DEAL_II_CONSTEXPR const auto dummy_4 = schur_product(a, ref);
+ DEAL_II_CONSTEXPR const auto dummy_5 = a * ref;
+ DEAL_II_CONSTEXPR const auto middle = outer_product(a, a);
+ DEAL_II_CONSTEXPR const auto dummy_6 = contract3(a, middle, a);
+ DEAL_II_CONSTEXPR const auto dummy_7 = adjugate(a);
+ DEAL_II_CONSTEXPR const auto dummy_8 = cofactor(a);
+ DEAL_II_CONSTEXPR const auto dummy_9 = l1_norm(a);
+ DEAL_II_CONSTEXPR const auto dummy_10 = linfty_norm(a);
}
deallog << "OK" << std::endl;
DEAL:float::0.00000
DEAL:float::0.00000
DEAL:float::0.00000
+DEAL:float::0.00000
DEAL:float:: Tensor<0,2>
DEAL:float::0.00000
DEAL:float::0.00000
DEAL:float::0.00000
DEAL:float::0.00000
DEAL:float::0.00000
+DEAL:float::0.00000
DEAL:float:: Tensor<0,3>
DEAL:float::0.00000
DEAL:float::0.00000
DEAL:float::0.00000
DEAL:float::0.00000
DEAL:float::0.00000
+DEAL:float::0.00000
DEAL:float:: Tensor<1,1>
DEAL:float::0.00000
DEAL:float::0.00000
DEAL:float::0.00000
DEAL:float::0.00000
DEAL:float::0.00000
+DEAL:float::0.00000
DEAL:float:: Tensor<1,2>
DEAL:float::0.00000 0.00000
DEAL:float::0.00000 0.00000
DEAL:float::0.00000 0.00000
DEAL:float::0.00000 0.00000
DEAL:float::0.00000 0.00000
+DEAL:float::0.00000 0.00000
DEAL:float:: Tensor<1,3>
DEAL:float::0.00000 0.00000 0.00000
DEAL:float::0.00000 0.00000 0.00000
DEAL:float::0.00000 0.00000 0.00000
DEAL:float::0.00000 0.00000 0.00000
DEAL:float::0.00000 0.00000 0.00000
+DEAL:float::0.00000 0.00000 0.00000
DEAL:float:: Tensor<2,1>
DEAL:float::0.00000
DEAL:float::0.00000
DEAL:float::0.00000
DEAL:float::0.00000
DEAL:float::0.00000
+DEAL:float::0.00000
DEAL:float:: Tensor<2,2>
DEAL:float::0.00000 0.00000 0.00000 0.00000
DEAL:float::0.00000 0.00000 0.00000 0.00000
DEAL:float::0.00000 0.00000 0.00000 0.00000
DEAL:float::0.00000 0.00000 0.00000 0.00000
DEAL:float::0.00000 0.00000 0.00000 0.00000
+DEAL:float::0.00000 0.00000 0.00000 0.00000
DEAL:float:: Tensor<2,3>
DEAL:float::0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000
DEAL:float::0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000
DEAL:float::0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000
DEAL:float::0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000
DEAL:float::0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000
+DEAL:float::0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000
DEAL:double:: Tensor<0,1>
DEAL:double::0.00000
DEAL:double::0.00000
DEAL:double::0.00000
DEAL:double::0.00000
DEAL:double::0.00000
+DEAL:double::0.00000
DEAL:double:: Tensor<0,2>
DEAL:double::0.00000
DEAL:double::0.00000
DEAL:double::0.00000
DEAL:double::0.00000
DEAL:double::0.00000
+DEAL:double::0.00000
DEAL:double:: Tensor<0,3>
DEAL:double::0.00000
DEAL:double::0.00000
DEAL:double::0.00000
DEAL:double::0.00000
DEAL:double::0.00000
+DEAL:double::0.00000
DEAL:double:: Tensor<1,1>
DEAL:double::0.00000
DEAL:double::0.00000
DEAL:double::0.00000
DEAL:double::0.00000
DEAL:double::0.00000
+DEAL:double::0.00000
DEAL:double:: Tensor<1,2>
DEAL:double::0.00000 0.00000
DEAL:double::0.00000 0.00000
DEAL:double::0.00000 0.00000
DEAL:double::0.00000 0.00000
DEAL:double::0.00000 0.00000
+DEAL:double::0.00000 0.00000
DEAL:double:: Tensor<1,3>
DEAL:double::0.00000 0.00000 0.00000
DEAL:double::0.00000 0.00000 0.00000
DEAL:double::0.00000 0.00000 0.00000
DEAL:double::0.00000 0.00000 0.00000
DEAL:double::0.00000 0.00000 0.00000
+DEAL:double::0.00000 0.00000 0.00000
DEAL:double:: Tensor<2,1>
DEAL:double::0.00000
DEAL:double::0.00000
DEAL:double::0.00000
DEAL:double::0.00000
DEAL:double::0.00000
+DEAL:double::0.00000
DEAL:double:: Tensor<2,2>
DEAL:double::0.00000 0.00000 0.00000 0.00000
DEAL:double::0.00000 0.00000 0.00000 0.00000
DEAL:double::0.00000 0.00000 0.00000 0.00000
DEAL:double::0.00000 0.00000 0.00000 0.00000
DEAL:double::0.00000 0.00000 0.00000 0.00000
+DEAL:double::0.00000 0.00000 0.00000 0.00000
DEAL:double:: Tensor<2,3>
DEAL:double::0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000
DEAL:double::0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000
DEAL:double::0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000
DEAL:double::0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000
DEAL:double::0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000
+DEAL:double::0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000
DEAL::Using Tensor within constexpr functions
DEAL::15.2000
DEAL::116.000