+namespace internal
+{
+ namespace PointImplementation
+ {
+ template <int dim,
+ typename Number,
+ typename OtherNumber,
+ typename std::enable_if<
+ !std::is_integral<
+ typename ProductType<Number, OtherNumber>::type>::value,
+ int>::type = 0>
+ inline DEAL_II_CUDA_HOST_DEV
+ Point<dim, typename ProductType<Number, OtherNumber>::type>
+ division_operator(const Point<dim, Number> &p, const OtherNumber factor)
+ {
+ using common_type = typename ProductType<Number, OtherNumber>::type;
+ Point<dim, common_type> tmp;
+ const auto inverse_factor =
+ static_cast<common_type>(1.) / static_cast<common_type>(factor);
+ for (unsigned int i = 0; i < dim; ++i)
+ tmp[i] = p[i] * inverse_factor;
+ return tmp;
+ }
+
+ template <int dim,
+ typename Number,
+ typename OtherNumber,
+ typename std::enable_if<
+ std::is_integral<
+ typename ProductType<Number, OtherNumber>::type>::value,
+ int>::type = 0>
+ inline DEAL_II_CUDA_HOST_DEV
+ Point<dim, typename ProductType<Number, OtherNumber>::type>
+ division_operator(const Point<dim, Number> &p, const OtherNumber factor)
+ {
+ Point<dim, typename ProductType<Number, OtherNumber>::type> tmp;
+ for (unsigned int i = 0; i < dim; ++i)
+ tmp[i] = p[i] / factor;
+ return tmp;
+ }
+ } // namespace PointImplementation
+} // namespace internal
+
+
template <int dim, typename Number>
template <typename OtherNumber>
inline DEAL_II_CUDA_HOST_DEV
typename EnableIfScalar<OtherNumber>::type>::type>
Point<dim, Number>::operator/(const OtherNumber factor) const
{
- Point<dim, typename ProductType<Number, OtherNumber>::type> tmp;
- for (unsigned int i = 0; i < dim; ++i)
- tmp[i] = this->operator[](i) / factor;
- return tmp;
+ return internal::PointImplementation::division_operator(*this, factor);
}
}
+namespace internal
+{
+ namespace TensorImplementation
+ {
+ template <int rank,
+ int dim,
+ typename Number,
+ typename OtherNumber,
+ typename std::enable_if<
+ !std::is_integral<
+ typename ProductType<Number, OtherNumber>::type>::value,
+ int>::type = 0>
+ DEAL_II_CONSTEXPR DEAL_II_CUDA_HOST_DEV inline DEAL_II_ALWAYS_INLINE void
+ division_operator(Tensor<rank, dim, Number> (&t)[dim],
+ const OtherNumber &factor)
+ {
+ const Number inverse_factor = Number(1.) / factor;
+ // recurse over the base objects
+ for (unsigned int d = 0; d < dim; ++d)
+ t[d] *= inverse_factor;
+ }
+
+
+ template <int rank,
+ int dim,
+ typename Number,
+ typename OtherNumber,
+ typename std::enable_if<
+ std::is_integral<
+ typename ProductType<Number, OtherNumber>::type>::value,
+ int>::type = 0>
+ DEAL_II_CONSTEXPR DEAL_II_CUDA_HOST_DEV inline DEAL_II_ALWAYS_INLINE void
+ division_operator(dealii::Tensor<rank, dim, Number> (&t)[dim],
+ const OtherNumber &factor)
+ {
+ // recurse over the base objects
+ for (unsigned int d = 0; d < dim; ++d)
+ t[d] /= factor;
+ }
+ } // namespace TensorImplementation
+} // namespace internal
+
+
template <int rank_, int dim, typename Number>
template <typename OtherNumber>
DEAL_II_CONSTEXPR inline DEAL_II_ALWAYS_INLINE
DEAL_II_CUDA_HOST_DEV Tensor<rank_, dim, Number> &
Tensor<rank_, dim, Number>::operator/=(const OtherNumber &s)
{
- for (unsigned int i = 0; i < dim; ++i)
- values[i] /= s;
+ internal::TensorImplementation::division_operator(values, s);
return *this;
}
}
+namespace internal
+{
+ namespace TensorImplementation
+ {
+ template <int rank,
+ int dim,
+ typename Number,
+ typename OtherNumber,
+ typename std::enable_if<
+ !std::is_integral<
+ typename ProductType<Number, OtherNumber>::type>::value,
+ int>::type = 0>
+ DEAL_II_CONSTEXPR DEAL_II_CUDA_HOST_DEV inline DEAL_II_ALWAYS_INLINE
+ Tensor<rank, dim, typename ProductType<Number, OtherNumber>::type>
+ division_operator(const Tensor<rank, dim, Number> &t,
+ const OtherNumber & factor)
+ {
+ Tensor<rank, dim, typename ProductType<Number, OtherNumber>::type> tt;
+ const Number inverse_factor = Number(1.) / factor;
+ // recurse over the base objects
+ for (unsigned int d = 0; d < dim; ++d)
+ tt[d] = t[d] * inverse_factor;
+ return tt;
+ }
+
+
+ template <int rank,
+ int dim,
+ typename Number,
+ typename OtherNumber,
+ typename std::enable_if<
+ std::is_integral<
+ typename ProductType<Number, OtherNumber>::type>::value,
+ int>::type = 0>
+ DEAL_II_CONSTEXPR DEAL_II_CUDA_HOST_DEV inline DEAL_II_ALWAYS_INLINE
+ Tensor<rank, dim, typename ProductType<Number, OtherNumber>::type>
+ division_operator(const Tensor<rank, dim, Number> &t,
+ const OtherNumber & factor)
+ {
+ Tensor<rank, dim, typename ProductType<Number, OtherNumber>::type> tt;
+ // recurse over the base objects
+ for (unsigned int d = 0; d < dim; ++d)
+ tt[d] = t[d] / factor;
+ return tt;
+ }
+ } // namespace TensorImplementation
+} // namespace internal
+
+
/**
* Division of a tensor of general rank with a scalar number. See the
* discussion on operator*() above for more information about template
typename EnableIfScalar<OtherNumber>::type>::type>
operator/(const Tensor<rank, dim, Number> &t, const OtherNumber &factor)
{
- // recurse over the base objects
- Tensor<rank, dim, typename ProductType<Number, OtherNumber>::type> tt;
- for (unsigned int d = 0; d < dim; ++d)
- tt[d] = t[d] / factor;
- return tt;
+ return internal::TensorImplementation::division_operator(t, factor);
}
AssertIsFinite(factor);
Assert(factor != 0., ExcDivideByZero());
+ const value_type inverse_factor = value_type(1.) / factor;
+
for (size_type i = 0; i < n_blocks(); ++i)
- components[i] /= factor;
+ components[i] *= inverse_factor;
return *this;
}
<Piece NumberOfPoints="384" NumberOfCells="24" >
<Points>
<DataArray type="Float32" NumberOfComponents="3" format="binary">
-AQAAAAASAAAAEgAARQUAAA==eNqdV01onFUUnVo0lApCkxbaZhFqJqigrbQFW5jv2VJFsCBYZqVWurFoN+LCjVJCK2jFFES6K9JIsnCykKIFBb97AxHEhcQisdCfhdRVIVBcCFER733fve+debOamc1733yXyTkv59x3T6s1G1r2ObX7/XBz9elK999dfDtcm/wq7m98/ZrWxLql3lupfufO0+HD//bEmrVzr4Z/PrgS9/sOvxiWevfivtvtpvrrO14OB5+ciN/ff/eFcHT907i/sPxM6HbXqqbq2VR/YaIT7r7yYP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H5YvasMzIkCUJMiaV2rDMSJAlCTLmBm1YZiTIkgQZk4bhi9gssxNk+brM+IjNMjtBlq/LjI/YLLMTZPm6zPj/A1hg9+k=
</DataArray>
</Points>
--- /dev/null
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2019 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.
+//
+// ---------------------------------------------------------------------
+
+
+// check Tensor::operator/=(int) and Tensor::operator/(int)
+
+#include <deal.II/base/tensor.h>
+
+#include "../tests.h"
+
+template <typename Number>
+void
+test()
+{
+ Number a[3][3] = {{1, 2, 3}, {3, 4, 5}, {6, 7, 8}};
+
+ const unsigned int dim = 3;
+ Tensor<2, dim, Number> t(a);
+
+ deallog << "Before: " << t << std::endl;
+ Tensor<2, dim, Number> u = t / 2;
+ deallog << "operator/: " << u << std::endl;
+ t /= 2;
+ deallog << "operator/=: " << t << std::endl;
+}
+
+int
+main()
+{
+ initlog();
+ deallog.push("Test double");
+ test<double>();
+ deallog.pop();
+ deallog.push("Test int");
+ test<int>();
+ deallog.pop();
+}
--- /dev/null
+
+DEAL:Test double::Before: 1.00000 2.00000 3.00000 3.00000 4.00000 5.00000 6.00000 7.00000 8.00000
+DEAL:Test double::operator/: 0.500000 1.00000 1.50000 1.50000 2.00000 2.50000 3.00000 3.50000 4.00000
+DEAL:Test double::operator/=: 0.500000 1.00000 1.50000 1.50000 2.00000 2.50000 3.00000 3.50000 4.00000
+DEAL:Test int::Before: 1 2 3 3 4 5 6 7 8
+DEAL:Test int::operator/: 0 1 1 1 2 2 3 3 4
+DEAL:Test int::operator/=: 0 1 1 1 2 2 3 3 4