]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Further work on the Tensor class. Implement special constructor which allows to copy...
authorwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Sun, 8 Nov 1998 20:34:10 +0000 (20:34 +0000)
committerwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Sun, 8 Nov 1998 20:34:10 +0000 (20:34 +0000)
git-svn-id: https://svn.dealii.org/trunk@656 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/base/include/base/point.h
deal.II/base/include/base/tensor.h
deal.II/base/include/base/tensor_base.h

index c8b1a3e2e10d49b25779c13d3fbbfedb14d6b92d..9ea1ecd648a18720483290b7f87245bc0ca4064a 100644 (file)
@@ -36,13 +36,11 @@ template <int dim>
 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 <int dim>
 inline
-Point<dim>::Point () :
-               Tensor<1,dim>() {};
+Point<dim>::Point (const bool initialize) :
+               Tensor<1,dim>(initialize) {};
 
 
 template <int dim>
index ac90f9920b8a18aab5fb0f5baeab36a8bebb5d2e..13852631c85e8b275f08a70fd7d6974eaeef2a5e 100644 (file)
@@ -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<rank_-1,dim>::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 <int rank_, int dim>
+inline
+Tensor<rank_,dim>::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 <int rank_, int dim>
+inline
+Tensor<rank_,dim>::Tensor (const array_type &initializer) {
+  for (unsigned int i=0; i<dim; ++i)
+    subtensor[i] =  Tensor<rank_-1,dim>(initializer[i]);
+};
+
+      
+
+
 template <int rank_, int dim>
 inline
 Tensor<rank_-1,dim> &
index 51f42ee7b0722bfc9d817222dd250fa512930cd1..5a3d61fa46f8b403e84985e95a956e5caa4ec30e 100644 (file)
@@ -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 <int dim>
 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<dim; ++i)
+      values[i] = 0;
+};
+
+
+
+template <int dim>
+inline
+Tensor<1,dim>::Tensor (const array_type &initializer) {
   for (unsigned int i=0; i<dim; ++i)
-    values[i] = 0;
+    values[i] = initializer[i];
 };
 
 

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.