From 928f0e24a23cdcbc817ea99bec2e2ed419086ac2 Mon Sep 17 00:00:00 2001 From: wolf Date: Sat, 7 Nov 1998 02:13:12 +0000 Subject: [PATCH] More tensor work. git-svn-id: https://svn.dealii.org/trunk@654 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/base/include/base/function.h | 8 ++--- deal.II/base/include/base/tensor.h | 42 +++++++++++++++++++++++++ deal.II/base/include/base/tensor_base.h | 32 ++++++++++++++++++- deal.II/base/source/function.cc | 12 +++---- 4 files changed, 83 insertions(+), 11 deletions(-) diff --git a/deal.II/base/include/base/function.h b/deal.II/base/include/base/function.h index c7a5687917..f992406d9c 100644 --- a/deal.II/base/include/base/function.h +++ b/deal.II/base/include/base/function.h @@ -116,7 +116,7 @@ class Function { * Return the gradient of the function * at the given point. */ - virtual Point gradient (const Point &p) const; + virtual Tensor<1,dim> gradient (const Point &p) const; /** * Set #gradients# to the gradients of @@ -126,7 +126,7 @@ class Function { * the same size as the #points# array. */ virtual void gradient_list (const vector > &points, - vector > &gradients) const; + vector > &gradients) const; /** * Return the value of the time variable/ @@ -203,7 +203,7 @@ class ZeroFunction : public Function { * Return the gradient of the function * at the given point. */ - virtual Point gradient (const Point &p) const; + virtual Tensor<1,dim> gradient (const Point &p) const; /** * Set #gradients# to the gradients of @@ -213,7 +213,7 @@ class ZeroFunction : public Function { * the same size as the #points# array. */ virtual void gradient_list (const vector > &points, - vector > &gradients) const; + vector > &gradients) const; }; diff --git a/deal.II/base/include/base/tensor.h b/deal.II/base/include/base/tensor.h index de90959cdf..ac90f9920b 100644 --- a/deal.II/base/include/base/tensor.h +++ b/deal.II/base/include/base/tensor.h @@ -97,6 +97,20 @@ class Tensor { */ Tensor & operator /= (const double &factor); + /** + * Add two tensors. If possible, use + * #operator +=# instead since this does not + * need to copy a point at least once. + */ + Tensor operator + (const Tensor &) const; + + /** + * Subtract two tensors. If possible, use + * #operator +=# instead since this does not + * need to copy a point at least once. + */ + Tensor operator - (const Tensor &) const; + /** * Reset all values to zero. */ @@ -212,6 +226,34 @@ Tensor & Tensor::operator /= (const double &s) { +template +inline +Tensor +Tensor::operator + (const Tensor &t) const { + Tensor tmp(*this); + + for (unsigned int i=0; i +inline +Tensor +Tensor::operator - (const Tensor &t) const { + Tensor tmp(*this); + + for (unsigned int i=0; i inline void Tensor::clear () { diff --git a/deal.II/base/include/base/tensor_base.h b/deal.II/base/include/base/tensor_base.h index 077c722c53..51f42ee7b0 100644 --- a/deal.II/base/include/base/tensor_base.h +++ b/deal.II/base/include/base/tensor_base.h @@ -126,7 +126,21 @@ class Tensor<1,dim> { /** * Returns the scalar product of two vectors. */ - double operator * (const Tensor<1,dim> &) const; + double operator * (const Tensor<1,dim> &) const; + + /** + * Add two tensors. If possible, use + * #operator +=# instead since this does not + * need to copy a point at least once. + */ + Tensor<1,dim> operator + (const Tensor<1,dim> &) const; + + /** + * Subtract two tensors. If possible, use + * #operator +=# instead since this does not + * need to copy a point at least once. + */ + Tensor<1,dim> operator - (const Tensor<1,dim> &) const; /** * Reset all values to zero. @@ -285,6 +299,22 @@ double Tensor<1,dim>::operator * (const Tensor<1,dim> &p) const { +template +inline +Tensor<1,dim> Tensor<1,dim>::operator + (const Tensor<1,dim> &p) const { + return (Tensor<1,dim>(*this) += p); +}; + + + +template +inline +Tensor<1,dim> Tensor<1,dim>::operator - (const Tensor<1,dim> &p) const { + return (Tensor<1,dim>(*this) -= p); +}; + + + template inline void Tensor<1,dim>::clear () { diff --git a/deal.II/base/source/function.cc b/deal.II/base/source/function.cc index a88413d677..3b7a77494b 100644 --- a/deal.II/base/source/function.cc +++ b/deal.II/base/source/function.cc @@ -38,7 +38,7 @@ void Function::value_list (const vector > &points, template -Point Function::gradient (const Point &) const { +Tensor<1,dim> Function::gradient (const Point &) const { Assert (false, ExcPureFunctionCalled()); return Point(); }; @@ -47,7 +47,7 @@ Point Function::gradient (const Point &) const { template void Function::gradient_list (const vector > &points, - vector > &gradients) const { + vector > &gradients) const { Assert (gradients.size() == points.size(), ExcVectorHasWrongSize(gradients.size(), points.size())); @@ -104,19 +104,19 @@ void ZeroFunction::value_list (const vector > &points, template -Point ZeroFunction::gradient (const Point &) const { - return Point(); +Tensor<1,dim> ZeroFunction::gradient (const Point &) const { + return Tensor<1,dim>(); }; template void ZeroFunction::gradient_list (const vector > &points, - vector > &gradients) const { + vector > &gradients) const { Assert (gradients.size() == points.size(), ExcVectorHasWrongSize(gradients.size(), points.size())); - fill_n (gradients.begin(), points.size(), Point()); + gradients.clear (); }; -- 2.39.5