]> https://gitweb.dealii.org/ - dealii.git/commitdiff
cross products for Tensor
authorGuido Kanschat <dr.guido.kanschat@gmail.com>
Thu, 18 Jan 2001 17:29:43 +0000 (17:29 +0000)
committerGuido Kanschat <dr.guido.kanschat@gmail.com>
Thu, 18 Jan 2001 17:29:43 +0000 (17:29 +0000)
git-svn-id: https://svn.dealii.org/trunk@3722 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/base/include/base/tensor.h
tests/base/tensor.cc
tests/base/tensor.checked

index af950a21c13480da8ca1c358ac168422c4873fb7..9524befde72fe3d1917edbf180a00a709e58ec05 100644 (file)
@@ -759,7 +759,42 @@ void outer_product (Tensor<1,dim>       &dst,
 };
 
 
-      
+
+/**
+ * Cross-product in 2d. This is just a rotation by 90 degrees
+ * clockwise to compute the outer normal from a tangential vector.
+ *
+ * @author Guido Kanschat, 2001
+ */
+inline
+void
+cross_product (Tensor<1,2>& dst,
+              const Tensor<1,2>& src)
+{
+  dst[0] = src[1];
+  dst[1] = -src[0];
+}
+
+
+
+/**
+ * Cross-product of 2 vectors in 3d.
+ *
+ * @author Guido Kanschat, 2001
+ */
+inline
+void
+cross_product (Tensor<1,3>& dst,
+              const Tensor<1,3>& src1,
+              const Tensor<1,3>& src2)
+{
+  dst[0] = src1[1]*src2[2] - src1[2]*src2[1];
+  dst[1] = src1[2]*src2[0] - src1[0]*src2[2];
+  dst[2] = src1[0]*src2[1] - src1[1]*src2[0];
+}
+
+
+
 /**
  * Compute the determinant of a tensor of arbitrary rank and dimension
  * one. Since this is a number, the return value is, of course, the
index 45ca07a8119f1aa90f553f35d5c113c158b857d2..61672a7cbba8ce64c2c78c447243ac451fe4f02c 100644 (file)
@@ -61,14 +61,41 @@ int main ()
     };
   deallog << endl;
 
+  if (true)
+    {
+      deallog.push("Cross product");
+      Tensor<1,3> e1;
+      Tensor<1,3> e2;
+      Tensor<1,3> e3;
+      e1[0] = 1.;
+      e2[1] = 1.;
+      e3[2] = 1.;
+      Tensor<1,3> result;
+      cross_product(result,e1,e2);
+      deallog << '\t' << result[0]
+             << '\t' << result[1]
+             << '\t' << result[2] << endl;
+      
+      cross_product(result,e2,e3);
+      deallog << '\t' << result[0]
+             << '\t' << result[1] << '\t'
+             << result[2] << endl;
+      
+      cross_product(result,e3,e1);
+      deallog << '\t' << result[0]
+             << '\t' << result[1]
+             << '\t' << result[2] << endl;
+      
+       deallog.pop();
+    }
+
   if (tt==result)
     {
       deallog << "Result OK." << endl;
-      return 0;
     }
   else
     {
       deallog << "Result WRONG!" << endl;
-      return 1;
     };
+
 };
index 41c95b3ec99987a49d60edce301314cfc6612925..d300eac33f96f4de03ba2e5f9b75bff154536966 100644 (file)
@@ -10,4 +10,7 @@ DEAL::25.0 31.0 37.0
 DEAL::45.0 57.0 69.0 
 DEAL::75.0 96.0 117. 
 
+DEAL:Cross product::   0.00    0.00    1.00
+DEAL:Cross product::   1.00    0.00    0.00
+DEAL:Cross product::   0.00    1.00    0.00
 DEAL::Result OK.

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.