From: Guido Kanschat Date: Thu, 18 Jan 2001 17:29:43 +0000 (+0000) Subject: cross products for Tensor X-Git-Tag: v8.0.0~19810 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=31c08ec90dad39e1af87e2353761205f7eb9454a;p=dealii.git cross products for Tensor git-svn-id: https://svn.dealii.org/trunk@3722 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/base/include/base/tensor.h b/deal.II/base/include/base/tensor.h index af950a21c1..9524befde7 100644 --- a/deal.II/base/include/base/tensor.h +++ b/deal.II/base/include/base/tensor.h @@ -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 diff --git a/tests/base/tensor.cc b/tests/base/tensor.cc index 45ca07a811..61672a7cbb 100644 --- a/tests/base/tensor.cc +++ b/tests/base/tensor.cc @@ -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; }; + }; diff --git a/tests/base/tensor.checked b/tests/base/tensor.checked index 41c95b3ec9..d300eac33f 100644 --- a/tests/base/tensor.checked +++ b/tests/base/tensor.checked @@ -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.