* Number>. In particular, if order == 1 and the derivative is the Jacobian of
* $\mathbf F(\mathbf x)$, then Tensor[i] = $\nabla F_i(\mathbf x)$.
*/
- template <typename Number2>
- operator Tensor<order + 1, dim, Number2>() const;
+ operator Tensor<order + 1, dim, Number>() const;
/**
* Converts a DerivativeForm<1, dim, 1, Number> to Tensor<1, dim, Number>.
*/
- template <typename Number2>
- operator Tensor<1, dim, Number2>() const;
+ operator Tensor<1, dim, Number>() const;
/**
* Return the transpose of a rectangular DerivativeForm,
template <int order, int dim, int spacedim, typename Number>
-template <typename Number2>
inline DerivativeForm<order, dim, spacedim, Number>::
-operator Tensor<1, dim, Number2>() const
+operator Tensor<1, dim, Number>() const
{
Assert((1 == spacedim) && (order == 1),
ExcMessage("Only allowed for spacedim==1."));
template <int order, int dim, int spacedim, typename Number>
-template <typename Number2>
inline DerivativeForm<order, dim, spacedim, Number>::
-operator Tensor<order + 1, dim, Number2>() const
+operator Tensor<order + 1, dim, Number>() const
{
Assert((dim == spacedim), ExcMessage("Only allowed when dim==spacedim."));
- Tensor<order + 1, dim, Number2> t;
+ Tensor<order + 1, dim, Number> t;
if (dim == spacedim)
for (unsigned int j = 0; j < dim; ++j)
+/**
+ * Similar to the previous apply_transformation(), specialized for the case `dim
+ * == spacedim` where we can return a rank-2 tensor instead of the more general
+ * `DerivativeForm`.
+ * Each row of the result corresponds to one of the rows of @p D_X transformed
+ * by @p grad_F, equivalent to $\mathrm{D\_X} \, \mathrm{grad\_F}^T$ in matrix
+ * notation.
+ *
+ * @relatesalso DerivativeForm
+ */
+// rank=2
+template <int dim, typename Number1, typename Number2>
+inline Tensor<2, dim, typename ProductType<Number1, Number2>::type>
+apply_transformation(const DerivativeForm<1, dim, dim, Number1> &grad_F,
+ const Tensor<2, dim, Number2> & D_X)
+{
+ Tensor<2, dim, typename ProductType<Number1, Number2>::type> dest;
+ for (unsigned int i = 0; i < dim; ++i)
+ dest[i] = apply_transformation(grad_F, D_X[i]);
+
+ return dest;
+}
+
+
+
/**
* Similar to the previous apply_transformation().
* Each row of the result corresponds to one of the rows of @p D_X transformed
DEAL_II_CUDA_HOST_DEV Tensor<0, dim, Number> &
Tensor<0, dim, Number>::operator=(const Tensor<0, dim, OtherNumber> &p)
{
- value = internal::NumberType<Number>::value(p);
+ value = internal::NumberType<Number>::value(p.value);
return *this;
}
constexpr DEAL_II_ALWAYS_INLINE Tensor<rank_, dim, Number>::
operator Tensor<1, dim, Tensor<rank_ - 1, dim, OtherNumber>>() const
{
- return Tensor<1, dim, Tensor<rank_ - 1, dim, Number>>(values);
+ return Tensor<1, dim, Tensor<rank_ - 1, dim, OtherNumber>>(values);
}
Number>::set_gradient(val_and_grad.second,
j,
unit_gradients[i + j]);
- gradients[i + j] = static_cast<gradient_type>(
+ gradients[i + j] =
apply_transformation(mapping_info->get_mapping_data()
.inverse_jacobians[i + j]
.transpose(),
- unit_gradients[i + j]));
+ unit_gradients[i + j]);
}
}
}
if (integration_flags & EvaluationFlags::gradients)
for (unsigned int j = 0; j < n_lanes && i + j < n_points; ++j)
{
- gradients[i + j] =
- static_cast<gradient_type>(apply_transformation(
- mapping_info->get_mapping_data().inverse_jacobians[i + j],
- gradients[i + j]));
+ gradients[i + j] = apply_transformation(
+ mapping_info->get_mapping_data().inverse_jacobians[i + j],
+ gradients[i + j]);
internal::FEPointEvaluation::
EvaluatorTypeTraits<dim, n_components, Number>::get_gradient(
gradient, j, gradients[i + j]);
--- /dev/null
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 1998 - 2018 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE.md at
+// the top level directory of deal.II.
+//
+// ---------------------------------------------------------------------
+
+// Test for mixed Number type assignments and casts of nested Tensors.
+
+#include <deal.II/base/tensor.h>
+
+#include <complex>
+
+#include "../tests.h"
+
+
+int
+main()
+{
+ initlog();
+
+ Tensor<1, 1, Tensor<1, 2, float>> nested_f;
+ Tensor<1, 1, Tensor<1, 2, double>> nested_d;
+
+ nested_d = nested_f;
+ nested_f = nested_d;
+
+ nested_d = static_cast<Tensor<1, 1, Tensor<1, 2, double>>>(nested_f);
+ nested_f = static_cast<Tensor<1, 1, Tensor<1, 2, float>>>(nested_d);
+
+ deallog << "OK!" << std::endl;
+}