]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Allow copying of sparse matrices and their sparsity patterns, but only if they repres...
authorwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Thu, 8 Apr 1999 16:09:39 +0000 (16:09 +0000)
committerwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Thu, 8 Apr 1999 16:09:39 +0000 (16:09 +0000)
git-svn-id: https://svn.dealii.org/trunk@1103 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/lac/include/lac/sparse_matrix.h
deal.II/lac/include/lac/sparse_matrix.templates.h
deal.II/lac/source/sparse_matrix.cc

index 5e71572cad0371db5aea97b0748c46543186ebfd..a8d02d5a5e49e1a6a9a243d9000858a2ab8e665c 100644 (file)
@@ -29,19 +29,6 @@ class ostream;
    */
 class SparseMatrixStruct
 {
-  private:
-                                    /**
-                                     * Copy constructor, made private in order to
-                                     * prevent copying such an object which does
-                                     * not make much sense because you can use
-                                     * a structure like this for more than one
-                                     * matrix.
-                                     *
-                                     * Because it is not needed, this function
-                                     * is not implemented.
-                                     */
-    SparseMatrixStruct (const SparseMatrixStruct &);
-    
   public:
                                     /**
                                      * Initialize the matrix empty, i.e. with
@@ -53,6 +40,33 @@ class SparseMatrixStruct
                                      */
     SparseMatrixStruct ();
     
+                                    /**
+                                     * Copy constructor. This constructor is
+                                     * only allowed to be called if the matrix
+                                     * structure to be copied is empty. This is
+                                     * so in order to prevent involuntary
+                                     * copies of objects for temporaries, which
+                                     * can use large amounts of computing time.
+                                     * However, copy constructors are needed
+                                     * if yo want to use the STL data types
+                                     * on classes like this, e.g. to write
+                                     * such statements like
+                                     * #v.push_back (SparseMatrixStruct());#,
+                                     * with #v# a vector of #SparseMatrixStruct#
+                                     * objects.
+                                     *
+                                     * Usually, it is sufficient to use the
+                                     * explicit keyword to disallow unwanted
+                                     * temporaries, but for the STL vectors,
+                                     * this does not work. Since copying a
+                                     * structure like this is not useful
+                                     * anyway because multiple matrices can
+                                     * use the same sparsity structure, copies
+                                     * are only allowed for empty objects, as
+                                     * described above.
+                                     */
+    SparseMatrixStruct (const SparseMatrixStruct &);
+
                                     /**
                                      * Initialize a rectangular matrix with
                                      * #m# rows and #n# columns,
@@ -334,6 +348,10 @@ class SparseMatrixStruct
                                      * Exception
                                      */
     DeclException0 (ExcIO);
+                                    /**
+                                     * Exception
+                                     */
+    DeclException0 (ExcInvalidConstructorCall);
 
   private:
     unsigned int max_dim;
@@ -382,6 +400,21 @@ class SparseMatrix
                                      * #reinit(SparseMatrixStruct)#.
                                      */
     SparseMatrix ();
+
+                                    /**
+                                     * Copy constructor. This constructor is
+                                     * only allowed to be called if the matrix
+                                     * to be copied is empty. This is for the
+                                     * same reason as for the
+                                     * #SparseMatrixStruct#, see there for the
+                                     * details.
+                                     *
+                                     * If you really want to copy a whole
+                                     * matrix, you can do so by using the
+                                     * #copy_from# function.
+                                     */
+    SparseMatrix (const SparseMatrix &);
+    
     
                                     /**
                                      * Constructor. Takes the given matrix
@@ -781,6 +814,10 @@ class SparseMatrix
                                      * Exception
                                      */
     DeclException0 (ExcIO);
+                                    /**
+                                     * Exception
+                                     */
+    DeclException0 (ExcInvalidConstructorCall);
     
   private:
     const SparseMatrixStruct * cols;
index c0e942f38c689ec14c139425e801904e3e7c8ed2..de6d70658c3b46106bfed9bd1f944111b1fb0864 100644 (file)
@@ -21,7 +21,21 @@ template <typename number>
 SparseMatrix<number>::SparseMatrix () :
                cols(0),
                val(0),
-               max_len(0) {};
+               max_len(0)
+{};
+
+
+
+template <typename number>
+SparseMatrix<number>::SparseMatrix (const SparseMatrix &m) :
+               cols(0),
+               val(0),
+               max_len(0)
+{
+  Assert (m.cols==0, ExcInvalidConstructorCall());
+  Assert (m.val==0, ExcInvalidConstructorCall());
+  Assert (m.max_len==0, ExcInvalidConstructorCall());
+};
 
 
 
index ecf30fd250aec2143da0fd00d3d2b700e7b74f09..5e16cd89c9548fc3f43bd7f5e2c2f5b1d74471bf 100644 (file)
@@ -28,6 +28,22 @@ SparseMatrixStruct::SparseMatrixStruct () :
 
 
 
+SparseMatrixStruct::SparseMatrixStruct (const SparseMatrixStruct &s) :
+               max_dim(0),
+               max_vec_len(0),
+               rowstart(0),
+               colnums(0)
+{
+  Assert (s.rowstart == 0, ExcInvalidConstructorCall());
+  Assert (s.colnums == 0, ExcInvalidConstructorCall());
+  Assert (s.rows == 0, ExcInvalidConstructorCall());
+  Assert (s.cols == 0, ExcInvalidConstructorCall());
+  
+  reinit (0,0,0);
+};
+
+
+
 SparseMatrixStruct::SparseMatrixStruct (const unsigned int m, const unsigned int n,
                                        const unsigned int max_per_row) 
                : max_dim(0),
@@ -62,7 +78,8 @@ SparseMatrixStruct::~SparseMatrixStruct ()
 
 
 void
-SparseMatrixStruct::reinit (const unsigned int m, const unsigned int n,
+SparseMatrixStruct::reinit (const unsigned int m,
+                           const unsigned int n,
                            const unsigned int max_per_row)
 {
   Assert ((max_per_row>0) || ((m==0) && (n==0)), ExcInvalidNumber(max_per_row));

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.