From 976c599bb052743e17a43e556b232fd1a3588c7a Mon Sep 17 00:00:00 2001 From: wolf Date: Thu, 8 Apr 1999 16:09:39 +0000 Subject: [PATCH] Allow copying of sparse matrices and their sparsity patterns, but only if they represent empty objects. git-svn-id: https://svn.dealii.org/trunk@1103 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/lac/include/lac/sparse_matrix.h | 63 +++++++++++++++---- .../lac/include/lac/sparse_matrix.templates.h | 16 ++++- deal.II/lac/source/sparse_matrix.cc | 19 +++++- 3 files changed, 83 insertions(+), 15 deletions(-) diff --git a/deal.II/lac/include/lac/sparse_matrix.h b/deal.II/lac/include/lac/sparse_matrix.h index 5e71572cad..a8d02d5a5e 100644 --- a/deal.II/lac/include/lac/sparse_matrix.h +++ b/deal.II/lac/include/lac/sparse_matrix.h @@ -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; diff --git a/deal.II/lac/include/lac/sparse_matrix.templates.h b/deal.II/lac/include/lac/sparse_matrix.templates.h index c0e942f38c..de6d70658c 100644 --- a/deal.II/lac/include/lac/sparse_matrix.templates.h +++ b/deal.II/lac/include/lac/sparse_matrix.templates.h @@ -21,7 +21,21 @@ template SparseMatrix::SparseMatrix () : cols(0), val(0), - max_len(0) {}; + max_len(0) +{}; + + + +template +SparseMatrix::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()); +}; diff --git a/deal.II/lac/source/sparse_matrix.cc b/deal.II/lac/source/sparse_matrix.cc index ecf30fd250..5e16cd89c9 100644 --- a/deal.II/lac/source/sparse_matrix.cc +++ b/deal.II/lac/source/sparse_matrix.cc @@ -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)); -- 2.39.5