From 7a1722b0099e9718932b1dff0c04fec089628f04 Mon Sep 17 00:00:00 2001 From: Matthias Maier Date: Fri, 4 Sep 2015 02:24:08 -0500 Subject: [PATCH] Bugfix: Allow creation and handling of Tensor Such objects only store a zero (which doesn't make much sense to work with them). But for certain situations in the library we need to be able to create such objects. --- include/deal.II/base/tensor_base.h | 50 ++++++++++-------------------- 1 file changed, 16 insertions(+), 34 deletions(-) diff --git a/include/deal.II/base/tensor_base.h b/include/deal.II/base/tensor_base.h index e9a263450e..98c60b24e1 100644 --- a/include/deal.II/base/tensor_base.h +++ b/include/deal.II/base/tensor_base.h @@ -258,17 +258,6 @@ public: template void serialize(Archive &ar, const unsigned int version); - /** - * Only tensors with a positive dimension are implemented. This exception is - * thrown by the constructor if the template argument dim is zero - * or less. - * - * @ingroup Exceptions - */ - DeclException1 (ExcDimTooSmall, - int, - << "dim must be positive, but was " << arg1); - private: /** * Internal type declaration that is used to specialize the return type @@ -586,17 +575,6 @@ public: << arg1 << ", but this is not possible for tensors of the current type."); - /** - * Only tensors with a positive dimension are implemented. This exception is - * thrown by the constructor if the template argument dim is zero - * or less. - * - * @ingroup Exceptions - */ - DeclException1 (ExcDimTooSmall, - int, - << "dim must be positive, but was " << arg1); - private: /** * Internal type declaration that is used to specialize the return type @@ -637,8 +615,6 @@ template inline Tensor<0,dim,Number>::Tensor () { - Assert (dim>0, ExcDimTooSmall(dim)); - value = value_type(); } @@ -647,8 +623,8 @@ template inline Tensor<0,dim,Number>::Tensor (const Tensor<0,dim,Number> &p) { - Assert (dim>0, ExcDimTooSmall(dim)); - + Assert(dim != 0 || p.value == Number(), + ExcMessage("Creation of a Tensor<0,0,Number> object with a non-zero scalar requested.")); value = p.value; } @@ -658,8 +634,8 @@ template inline Tensor<0,dim,Number>::Tensor (const OtherNumber initializer) { - Assert (dim>0, ExcDimTooSmall(dim)); - + Assert(dim != 0 || initializer == OtherNumber(), + ExcMessage("Creation of a Tensor<0,0,Number> object with a non-zero scalar requested.")); value = initializer; } @@ -669,8 +645,8 @@ template inline Tensor<0,dim,Number>::Tensor (const Tensor<0,dim,OtherNumber> &p) { - Assert (dim>0, ExcDimTooSmall(dim)); - + Assert(dim != 0 || p.value == OtherNumber(), + ExcMessage("Cannot return a non-zero scalar from a Tensor<0,0,Number> object.")); value = p.value; } @@ -679,6 +655,8 @@ template inline Tensor<0,dim,Number>::operator Number &() { + Assert(dim != 0 || value == Number(), + ExcMessage("Cannot return a non-zero scalar from a Tensor<0,0,Number> object.")); return value; } @@ -687,6 +665,8 @@ template inline Tensor<0,dim,Number>::operator const Number &() const { + Assert(dim != 0 || value == Number(), + ExcMessage("Cannot assign a non-zero scalar to a Tensor<0,0,Number> object.")); return value; } @@ -695,6 +675,8 @@ template inline Tensor<0,dim,Number> &Tensor<0,dim,Number>::operator = (const Tensor<0,dim,Number> &p) { + Assert(dim != 0 || p.value == Number(), + ExcMessage("Cannot assign a non-zero scalar to a Tensor<0,0,Number> object.")); value = p.value; return *this; } @@ -705,6 +687,8 @@ template inline Tensor<0,dim,Number> &Tensor<0,dim,Number>::operator = (const Tensor<0,dim,OtherNumber> &p) { + Assert(dim != 0 || p.value == OtherNumber(), + ExcMessage("Cannot assign a non-zero scalar to a Tensor<0,0,Number> object.")); value = p.value; return *this; } @@ -715,6 +699,8 @@ template inline Tensor<0,dim,Number> &Tensor<0,dim,Number>::operator = (const OtherNumber d) { + Assert(dim != 0 || d == OtherNumber(), + ExcMessage("Cannot assign a non-zero scalar to a Tensor<0,0,Number> object.")); value = d; return *this; } @@ -886,8 +872,6 @@ template inline Tensor::Tensor (const Tensor &initializer) { - Assert (dim>0, ExcDimTooSmall(dim)); - for (unsigned int i=0; i inline Tensor::Tensor (const array_type &initializer) { - Assert (dim>0, ExcDimTooSmall(dim)); - for (unsigned int i=0; i