]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Fix Tensor::invert() for auto-differentiable numbers
authorJean-Paul Pelteret <jppelteret@gmail.com>
Thu, 12 Apr 2018 13:33:20 +0000 (15:33 +0200)
committerJean-Paul Pelteret <jppelteret@gmail.com>
Thu, 12 Apr 2018 21:16:51 +0000 (23:16 +0200)
doc/news/changes/minor/20180412Jean-PaulPelteret-1 [new file with mode: 0644]
include/deal.II/base/tensor.h

diff --git a/doc/news/changes/minor/20180412Jean-PaulPelteret-1 b/doc/news/changes/minor/20180412Jean-PaulPelteret-1
new file mode 100644 (file)
index 0000000..0eadf9b
--- /dev/null
@@ -0,0 +1,4 @@
+Fixed: The Tensor::invert() function would previously not work with some Sacado
+number types. This has now been fixed.
+<br>
+(Jean-Paul Pelteret, 2018/04/12)
index 6819b023f309364e1c618d5dc030c59bce36c776..2aa612b6dc915f4652d1c22c06ca68828cd39007 100644 (file)
@@ -2065,7 +2065,7 @@ invert (const Tensor<2,1,Number> &t)
 {
   Number return_tensor [1][1];
 
-  return_tensor[0][0] = 1.0/t[0][0];
+  return_tensor[0][0] = internal::NumberType<Number>::value(1.0/t[0][0]);
 
   return Tensor<2,1,Number>(return_tensor);
 }
@@ -2080,7 +2080,7 @@ invert (const Tensor<2,2,Number> &t)
 
   // this is Maple output,
   // thus a bit unstructured
-  const Number inv_det_t = 1.0/(t[0][0]*t[1][1]-t[1][0]*t[0][1]);
+  const Number inv_det_t = internal::NumberType<Number>::value(1.0/(t[0][0]*t[1][1]-t[1][0]*t[0][1]));
   return_tensor[0][0] = t[1][1];
   return_tensor[0][1] = -t[0][1];
   return_tensor[1][0] = -t[1][0];
@@ -2098,23 +2098,24 @@ invert (const Tensor<2,3,Number> &t)
 {
   Tensor<2,3,Number> return_tensor;
 
-  const Number t4 = t[0][0]*t[1][1],
-               t6 = t[0][0]*t[1][2],
-               t8 = t[0][1]*t[1][0],
-               t00 = t[0][2]*t[1][0],
-               t01 = t[0][1]*t[2][0],
-               t04 = t[0][2]*t[2][0],
-               inv_det_t = 1.0/(t4*t[2][2]-t6*t[2][1]-t8*t[2][2]+
-                                t00*t[2][1]+t01*t[1][2]-t04*t[1][1]);
-  return_tensor[0][0] = t[1][1]*t[2][2]-t[1][2]*t[2][1];
-  return_tensor[0][1] = t[0][2]*t[2][1]-t[0][1]*t[2][2];
-  return_tensor[0][2] = t[0][1]*t[1][2]-t[0][2]*t[1][1];
-  return_tensor[1][0] = t[1][2]*t[2][0]-t[1][0]*t[2][2];
-  return_tensor[1][1] = t[0][0]*t[2][2]-t04;
+  const Number t4 = internal::NumberType<Number>::value(t[0][0]*t[1][1]),
+               t6 = internal::NumberType<Number>::value(t[0][0]*t[1][2]),
+               t8 = internal::NumberType<Number>::value(t[0][1]*t[1][0]),
+               t00 = internal::NumberType<Number>::value(t[0][2]*t[1][0]),
+               t01 = internal::NumberType<Number>::value(t[0][1]*t[2][0]),
+               t04 = internal::NumberType<Number>::value(t[0][2]*t[2][0]),
+               inv_det_t = internal::NumberType<Number>::value(
+                             1.0/(t4*t[2][2]-t6*t[2][1]-t8*t[2][2]+
+                                  t00*t[2][1]+t01*t[1][2]-t04*t[1][1]));
+  return_tensor[0][0] = internal::NumberType<Number>::value(t[1][1]*t[2][2])-internal::NumberType<Number>::value(t[1][2]*t[2][1]);
+  return_tensor[0][1] = internal::NumberType<Number>::value(t[0][2]*t[2][1])-internal::NumberType<Number>::value(t[0][1]*t[2][2]);
+  return_tensor[0][2] = internal::NumberType<Number>::value(t[0][1]*t[1][2])-internal::NumberType<Number>::value(t[0][2]*t[1][1]);
+  return_tensor[1][0] = internal::NumberType<Number>::value(t[1][2]*t[2][0])-internal::NumberType<Number>::value(t[1][0]*t[2][2]);
+  return_tensor[1][1] = internal::NumberType<Number>::value(t[0][0]*t[2][2])-t04;
   return_tensor[1][2] = t00-t6;
-  return_tensor[2][0] = t[1][0]*t[2][1]-t[1][1]*t[2][0];
-  return_tensor[2][1] = t01-t[0][0]*t[2][1];
-  return_tensor[2][2] = t4-t8;
+  return_tensor[2][0] = internal::NumberType<Number>::value(t[1][0]*t[2][1])-internal::NumberType<Number>::value(t[1][1]*t[2][0]);
+  return_tensor[2][1] = t01-internal::NumberType<Number>::value(t[0][0]*t[2][1]);
+  return_tensor[2][2] = internal::NumberType<Number>::value(t4-t8);
   return_tensor *= inv_det_t;
 
   return return_tensor;

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.