From 0169d2e366bafa240637c08b5d558a1376ac5946 Mon Sep 17 00:00:00 2001 From: Maien Hamed Date: Wed, 19 Aug 2015 16:29:23 +0200 Subject: [PATCH] Generalized conversions between DerivativeForm and Tensor to general ranks. --- doc/news/changes.h | 7 +++++ include/deal.II/base/derivative_form.h | 39 +++++++++++++------------- 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/doc/news/changes.h b/doc/news/changes.h index 73000a826a..2f59813705 100644 --- a/doc/news/changes.h +++ b/doc/news/changes.h @@ -134,6 +134,13 @@ inconvenience this causes.
    +
  1. Improved: Generalized conversion between Tensor and + DerivativeForm to general order using converting constructor + and assignment operator. +
    + (Maien Hamed, 2015/08/01-2015/08/09) +
  2. +
  3. Changed: The function Vector::add() that adds a scalar number to all elements of a vector has been deprecated. The same is true for the Vector::ratio() function, and for the corresponding functions in other diff --git a/include/deal.II/base/derivative_form.h b/include/deal.II/base/derivative_form.h index 961e900ef1..a93c843630 100644 --- a/include/deal.II/base/derivative_form.h +++ b/include/deal.II/base/derivative_form.h @@ -63,9 +63,9 @@ public: DerivativeForm (); /** - * Constructor from a second order tensor. + * Constructor from a tensor. */ - DerivativeForm (const Tensor<2,dim,Number> &); + DerivativeForm (const Tensor &); /** * Read-Write access operator. @@ -86,7 +86,7 @@ public: /** * Assignment operator. */ - DerivativeForm &operator = (const Tensor<2,dim, Number> &); + DerivativeForm &operator = (const Tensor &); /** * Assignment operator. @@ -94,10 +94,11 @@ public: DerivativeForm &operator = (const Tensor<1,dim, Number> &); /** - * Converts a DerivativeForm <1,dim, dim> to Tensor<2,dim,Number>. If the - * derivative is the Jacobian of F, then Tensor[i] = grad(F^i). + * Converts a DerivativeForm to Tensor. + * In particular, if order==1 and the derivative is the Jacobian of F, then + * Tensor[i] = grad(F^i). */ - operator Tensor<2,dim,Number>() const; + operator Tensor() const; /** * Converts a DerivativeForm <1, dim, 1> to Tensor<1,dim,Number>. @@ -180,11 +181,11 @@ DerivativeForm::DerivativeForm () template inline -DerivativeForm::DerivativeForm(const Tensor<2,dim,Number> &T) +DerivativeForm::DerivativeForm(const Tensor &T) { - Assert( (dim == spacedim) && (order==1), - ExcMessage("Only allowed for square tensors.")); - if ((dim == spacedim) && (order==1)) + Assert( (dim == spacedim), + ExcMessage("Only allowed for forms with dim==spacedim.")); + if (dim == spacedim) for (unsigned int j=0; j &ta) template inline DerivativeForm &DerivativeForm:: -operator = (const Tensor<2,dim,Number> &ta) +operator = (const Tensor &ta) { - Assert( (dim == spacedim) && (order==1), - ExcMessage("Only allowed for square tensors.")); + Assert( (dim == spacedim), + ExcMessage("Only allowed when dim==spacedim.")); - if ((dim == spacedim) && (order==1)) + if (dim == spacedim) for (unsigned int j=0; j::operator Tensor<1,dim,Number>() co template inline -DerivativeForm::operator Tensor<2,dim,Number>() const +DerivativeForm::operator Tensor() const { - Assert( (dim == spacedim) && (order==1), - ExcMessage("Only allowed for square tensors.")); + Assert( (dim == spacedim), + ExcMessage("Only allowed when dim==spacedim.")); - Tensor<2,dim,Number> t; + Tensor t; - if ((dim == spacedim) && (order==1)) + if (dim == spacedim) for (unsigned int j=0; j