From 4671b78ded2e8f89b96b047d8e0aef26a403f363 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Fri, 24 Mar 2006 19:21:29 +0000 Subject: [PATCH] Allow tensors to be reset to zero by writing t=0 git-svn-id: https://svn.dealii.org/trunk@12672 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/base/include/base/symmetric_tensor.h | 30 +++++++++++++++++- deal.II/base/include/base/tensor.h | 33 ++++++++++++++++++-- deal.II/base/include/base/tensor_base.h | 30 +++++++++++++++++- deal.II/doc/news/changes.html | 7 +++++ 4 files changed, 96 insertions(+), 4 deletions(-) diff --git a/deal.II/base/include/base/symmetric_tensor.h b/deal.II/base/include/base/symmetric_tensor.h index 24369e5953..ad1c2eb7b7 100644 --- a/deal.II/base/include/base/symmetric_tensor.h +++ b/deal.II/base/include/base/symmetric_tensor.h @@ -2,7 +2,7 @@ // $Id$ // Version: $Name$ // -// Copyright (C) 2005 by the deal.II authors +// Copyright (C) 2005, 2006 by the deal.II authors // // This file is subject to QPL and may not be distributed // without copyright and license information. Please refer @@ -656,6 +656,20 @@ class SymmetricTensor */ SymmetricTensor & operator = (const SymmetricTensor &); + /** + * This operator assigns a scalar + * to a tensor. To avoid + * confusion with what exactly it + * means to assign a scalar value + * to a tensor, zero is the only + * value allowed for d, + * allowing the intuitive + * notation t=0 to reset + * all elements of the tensor to + * zero. + */ + SymmetricTensor & operator = (const double d); + /** * Convert the present symmetric tensor * into a full tensor with the same @@ -1020,6 +1034,20 @@ SymmetricTensor::operator = (const SymmetricTensor &t) +template +inline +SymmetricTensor & +SymmetricTensor::operator = (const double d) +{ + Assert (d==0, ExcMessage ("Only assignment with zero is allowed")); + + data = 0; + + return *this; +} + + + template <> inline SymmetricTensor<2,1>:: diff --git a/deal.II/base/include/base/tensor.h b/deal.II/base/include/base/tensor.h index 54888b2b04..d452bfe248 100644 --- a/deal.II/base/include/base/tensor.h +++ b/deal.II/base/include/base/tensor.h @@ -2,7 +2,7 @@ // $Id$ // Version: $Name$ // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 by the deal.II authors +// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 by the deal.II authors // // This file is subject to QPL and may not be distributed // without copyright and license information. Please refer @@ -106,7 +106,21 @@ class Tensor */ Tensor & operator = (const Tensor &); - /** + /** + * This operator assigns a scalar + * to a tensor. To avoid + * confusion with what exactly it + * means to assign a scalar value + * to a tensor, zero is the only + * value allowed for d, + * allowing the intuitive + * notation t=0 to reset + * all elements of the tensor to + * zero. + */ + Tensor & operator = (const double d); + + /** * Test for equality of two tensors. */ bool operator == (const Tensor &) const; @@ -312,6 +326,21 @@ Tensor::operator = (const Tensor &t) } + +template +inline +Tensor & +Tensor::operator = (const double d) +{ + Assert (d==0, ExcMessage ("Only assignment with zero is allowed")); + + for (unsigned int i=0; i inline bool diff --git a/deal.II/base/include/base/tensor_base.h b/deal.II/base/include/base/tensor_base.h index 11d1f269ad..800e41e79f 100644 --- a/deal.II/base/include/base/tensor_base.h +++ b/deal.II/base/include/base/tensor_base.h @@ -2,7 +2,7 @@ // $Id$ // Version: $Name$ // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 by the deal.II authors +// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 by the deal.II authors // // This file is subject to QPL and may not be distributed // without copyright and license information. Please refer @@ -161,6 +161,20 @@ class Tensor<1,dim> */ Tensor<1,dim> & operator = (const Tensor<1,dim> &); + /** + * This operator assigns a scalar + * to a tensor. To avoid + * confusion with what exactly it + * means to assign a scalar value + * to a tensor, zero is the only + * value allowed for d, + * allowing the intuitive + * notation t=0 to reset + * all elements of the tensor to + * zero. + */ + Tensor<1,dim> & operator = (const double d); + /** * Test for equality of two * tensors. @@ -516,6 +530,20 @@ Tensor<1,dim> & Tensor<1,dim>::operator = (const Tensor<1,dim> &p) +template +inline +Tensor<1,dim> & Tensor<1,dim>::operator = (const double d) +{ + Assert (d==0, ExcMessage ("Only assignment with zero is allowed")); + + for (unsigned int i=0; i inline bool Tensor<1,dim>::operator == (const Tensor<1,dim> &p) const diff --git a/deal.II/doc/news/changes.html b/deal.II/doc/news/changes.html index 6333745ddf..07da107116 100644 --- a/deal.II/doc/news/changes.html +++ b/deal.II/doc/news/changes.html @@ -267,6 +267,13 @@ inconvenience this causes.
    +
  1. New: The various tensor classes can now effectively be reset to zero + by simply writing t=0; as has long been allowed for + matrices and vectors. +
    + (WB 2006/03/24) +

    +
  2. New: The new deal_II_numbers::is_finite function can be used to check whether a floating point number is finite, -- 2.39.5