From 5832808c7111d4bb40ade21ff0df31a8233766da Mon Sep 17 00:00:00 2001 From: Matthias Maier Date: Mon, 14 Sep 2015 22:14:57 -0500 Subject: [PATCH] tensor.h: Let the cross_product functions return its result All other function signatures also return their result - do the same here and deprecate the old signatures. --- include/deal.II/base/tensor.h | 53 +++++++++++-------- include/deal.II/base/tensor_deprecated.h | 66 ++++++++++++++++++++++++ 2 files changed, 97 insertions(+), 22 deletions(-) create mode 100644 include/deal.II/base/tensor_deprecated.h diff --git a/include/deal.II/base/tensor.h b/include/deal.II/base/tensor.h index 1f75f7a7da..a90dbfd024 100644 --- a/include/deal.II/base/tensor.h +++ b/include/deal.II/base/tensor.h @@ -2167,51 +2167,57 @@ Number determinant (const Tensor<1,1,Number> &t) /** - * Cross-product in 2d. This is just a rotation by 90 degrees clockwise to - * compute the outer normal from a tangential vector. This function is defined - * for all space dimensions to allow for dimension independent programming - * (e.g. within switches over the space dimension), but may only be called if - * the actual dimension of the arguments is two (e.g. from the dim==2 - * case in the switch). + * Returns the cross-product in 2d. This is just a rotation by 90 degrees + * clockwise to compute the outer normal from a tangential vector. This + * function is defined for all space dimensions to allow for dimension + * independent programming (e.g. within switches over the space dimension), + * but may only be called if the actual dimension of the arguments is two + * (e.g. from the dim==2 case in the switch). * * @relates Tensor * @author Guido Kanschat, 2001 */ template inline -void -cross_product (Tensor<1,dim,Number> &dst, - const Tensor<1,dim,Number> &src) +Tensor<1,dim,Number> +cross_product (const Tensor<1,dim,Number> &src) { Assert (dim==2, ExcInternalError()); - dst[0] = src[1]; - dst[1] = -src[0]; + Tensor<1, dim, Number> result; + + result[0] = src[1]; + result[1] = -src[0]; + + return result; } /** - * Cross-product of 2 vectors in 3d. This function is defined for all space - * dimensions to allow for dimension independent programming (e.g. within - * switches over the space dimension), but may only be called if the actual - * dimension of the arguments is three (e.g. from the dim==3 case in - * the switch). + * Returns the cross-product of 2 vectors in 3d. This function is defined + * for all space dimensions to allow for dimension independent programming + * (e.g. within switches over the space dimension), but may only be called + * if the actual dimension of the arguments is three (e.g. from the + * dim==3 case in the switch). * * @relates Tensor * @author Guido Kanschat, 2001 */ template inline -void -cross_product (Tensor<1,dim,Number> &dst, - const Tensor<1,dim,Number> &src1, +Tensor<1,dim,Number> +cross_product (const Tensor<1,dim,Number> &src1, const Tensor<1,dim,Number> &src2) { Assert (dim==3, ExcInternalError()); - 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]; + Tensor<1, dim, Number> result; + + result[0] = src1[1]*src2[2] - src1[2]*src2[1]; + result[1] = src1[2]*src2[0] - src1[0]*src2[2]; + result[2] = src1[0]*src2[1] - src1[1]*src2[0]; + + return result; } @@ -2536,4 +2542,7 @@ linfty_norm (const Tensor<2,dim,Number> &t) DEAL_II_NAMESPACE_CLOSE +// include deprecated non-member functions operating on Tensor +#include + #endif diff --git a/include/deal.II/base/tensor_deprecated.h b/include/deal.II/base/tensor_deprecated.h new file mode 100644 index 0000000000..9bc6663167 --- /dev/null +++ b/include/deal.II/base/tensor_deprecated.h @@ -0,0 +1,66 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 1998 - 2015 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 at +// the top level of the deal.II distribution. +// +// --------------------------------------------------------------------- + +#ifndef dealii__tensor_deprecated_h +#define dealii__tensor_deprecated_h + +#include + + +/* --------- Deprecated non-member functions operating on tensors. ---------- */ + +DEAL_II_NAMESPACE_OPEN + +//@} +/** + * @name Deprecated Tensor operations + */ +//@{ + + +/** + * The cross-product of 2 vectors in 3d. + * + * @deprecated Use the cross_product function that returns the value. + * @relates Tensor + */ +template +inline +void +cross_product (Tensor<1,dim,Number> &dst, + const Tensor<1,dim,Number> &src1, + const Tensor<1,dim,Number> &src2) DEAL_II_DEPRECATED; + + +#ifndef DOXYGEN + + +template +inline +void +cross_product (Tensor<1,dim,Number> &dst, + const Tensor<1,dim,Number> &src1, + const Tensor<1,dim,Number> &src2) +{ + dst = cross_product(src1, src2); +} + +#endif /* DOXYGEN */ + +//@} + +DEAL_II_NAMESPACE_CLOSE + +#endif -- 2.39.5