From: wolf Date: Sun, 8 Nov 1998 20:34:10 +0000 (+0000) Subject: Further work on the Tensor class. Implement special constructor which allows to copy... X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5647661d6697d98921ca99c581e101c8e05f1573;p=dealii-svn.git Further work on the Tensor class. Implement special constructor which allows to copy construct from a C-style array. git-svn-id: https://svn.dealii.org/trunk@656 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/base/include/base/point.h b/deal.II/base/include/base/point.h index c8b1a3e2e1..9ea1ecd648 100644 --- a/deal.II/base/include/base/point.h +++ b/deal.II/base/include/base/point.h @@ -36,13 +36,11 @@ template class Point : public Tensor<1,dim> { public: /** - * Default constructor. - */ - /** * Constructor. Initialize all entries - * to zero. + * to zero if #initialize==true#; this + * is the default behaviour. */ - explicit Point (); + explicit Point (const bool initialize = true); /** * Convert a tensor to a point. Since no @@ -156,8 +154,8 @@ class Point : public Tensor<1,dim> { template inline -Point::Point () : - Tensor<1,dim>() {}; +Point::Point (const bool initialize) : + Tensor<1,dim>(initialize) {}; template diff --git a/deal.II/base/include/base/tensor.h b/deal.II/base/include/base/tensor.h index ac90f9920b..13852631c8 100644 --- a/deal.II/base/include/base/tensor.h +++ b/deal.II/base/include/base/tensor.h @@ -50,6 +50,25 @@ class Tensor { */ static const unsigned int rank = rank_; + /** + * Declare an array type which can + * be used to initialize statically + * an object of this type. + */ + typedef typename Tensor::array_type array_type[dim]; + + /** + * Constructor. Initialize all entries + * to zero. + */ + Tensor (); + + /** + * Copy constructor, where the data is + * copied from a C-style array. + */ + Tensor (const array_type &initializer); + /** * Read-Write access operator. */ @@ -136,6 +155,27 @@ class Tensor { /*--------------------------- Inline functions -----------------------------*/ + +template +inline +Tensor::Tensor () { +// default constructor. not specifying an initializer list calls +// the default constructor of the subobjects, which initialize them +// selves. therefore, the tensor is set to zero this way +}; + + + +template +inline +Tensor::Tensor (const array_type &initializer) { + for (unsigned int i=0; i(initializer[i]); +}; + + + + template inline Tensor & diff --git a/deal.II/base/include/base/tensor_base.h b/deal.II/base/include/base/tensor_base.h index 51f42ee7b0..5a3d61fa46 100644 --- a/deal.II/base/include/base/tensor_base.h +++ b/deal.II/base/include/base/tensor_base.h @@ -57,11 +57,25 @@ class Tensor<1,dim> { */ static const unsigned int rank = 1; + /** + * Declare an array type which can + * be used to initialize statically + * an object of this type. + */ + typedef double array_type[dim]; + /** * Constructor. Initialize all entries - * to zero. + * to zero if #initialize==true#; this + * is the default behaviour. */ - explicit Tensor (); + explicit Tensor (const bool initialize = true); + + /** + * Copy constructor, where the data is + * copied from a C-style array. + */ + Tensor (const array_type &initializer); /** * Copy constructor. @@ -184,11 +198,21 @@ ostream & operator << (ostream &out, const Tensor<1,dim> &p); template inline -Tensor<1,dim>::Tensor () { +Tensor<1,dim>::Tensor (const bool initialize) { Assert (dim>0, ExcDimTooSmall(dim)); + if (initialize) + for (unsigned int i=0; i +inline +Tensor<1,dim>::Tensor (const array_type &initializer) { for (unsigned int i=0; i