]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Bugfix: Provide missing operator+ and operator- variants
authorMatthias Maier <tamiko@43-1.org>
Thu, 29 Oct 2015 03:47:29 +0000 (22:47 -0500)
committerMatthias Maier <tamiko@43-1.org>
Thu, 29 Oct 2015 03:47:29 +0000 (22:47 -0500)
Unfortunately, it is not possible any more to exploit an implicit
conversion from SymmetricTensor to Tensor due to the heavily templated
operator variants for Tensor.

Thus, provide mixed operator types. (And clean up symmetric_tensor.h
later).

include/deal.II/base/symmetric_tensor.h

index e1de217faf533f5f5b419aae1bd42e470477c797..fc31e576ad5a943ece595588e6f2f0e390320c06 100644 (file)
@@ -1994,6 +1994,72 @@ SymmetricTensor<rank,dim,Number>::serialize(Archive &ar, const unsigned int)
 
 /* ----------------- Non-member functions operating on tensors. ------------ */
 
+
+/**
+ * Addition of a SymmetricTensor and a general Tensor of equal rank. The
+ * result is a general Tensor.
+ *
+ * @relates SymmetricTensor
+ */
+template <int rank, int dim, typename Number, typename OtherNumber>
+inline
+Tensor<rank, dim, typename ProductType<Number, OtherNumber>::type>
+operator+(const SymmetricTensor<rank, dim, Number> &left,
+          const Tensor<rank, dim, OtherNumber> &right)
+{
+  return Tensor<rank, dim, Number>(left) + right;
+}
+
+
+/**
+ * Addition of a general Tensor with a SymmetricTensor of equal rank. The
+ * result is a general Tensor.
+ *
+ * @relates SymmetricTensor
+ */
+template <int rank, int dim, typename Number, typename OtherNumber>
+inline
+Tensor<rank, dim, typename ProductType<Number, OtherNumber>::type>
+operator+(const Tensor<rank, dim, Number> &left,
+          const SymmetricTensor<rank, dim, OtherNumber> &right)
+{
+  return left + Tensor<rank, dim, OtherNumber>(right);
+}
+
+
+/**
+ * Subtraction of a SymmetricTensor and a general Tensor of equal rank. The
+ * result is a general Tensor.
+ *
+ * @relates SymmetricTensor
+ */
+template <int rank, int dim, typename Number, typename OtherNumber>
+inline
+Tensor<rank, dim, typename ProductType<Number, OtherNumber>::type>
+operator-(const SymmetricTensor<rank, dim, Number> &left,
+          const Tensor<rank, dim, OtherNumber> &right)
+{
+  return Tensor<rank, dim, Number>(left) - right;
+}
+
+
+/**
+ * Subtraction of a general Tensor with a SymmetricTensor of equal rank.
+ * The result is a general Tensor.
+ *
+ * @relates SymmetricTensor
+ */
+template <int rank, int dim, typename Number, typename OtherNumber>
+inline
+Tensor<rank, dim, typename ProductType<Number, OtherNumber>::type>
+operator-(const Tensor<rank, dim, Number> &left,
+          const SymmetricTensor<rank, dim, OtherNumber> &right)
+{
+  return left - Tensor<rank, dim, OtherNumber>(right);
+}
+
+
+
 /**
  * Compute the determinant of a tensor or rank 2. The determinant is also
  * commonly referred to as the third invariant of rank-2 tensors.

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.