From: wolf Date: Wed, 6 Feb 2002 09:03:47 +0000 (+0000) Subject: Add functions copy_from(FullMatrix) to sparsity pattern and sparse matrix. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0fa09f25e156e9283f701a060cb4e0b88f53d8bc;p=dealii-svn.git Add functions copy_from(FullMatrix) to sparsity pattern and sparse matrix. git-svn-id: https://svn.dealii.org/trunk@5473 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/doc/news/2002/c-3-3.html b/deal.II/doc/news/2002/c-3-3.html index 082d134a6c..3798092656 100644 --- a/deal.II/doc/news/2002/c-3-3.html +++ b/deal.II/doc/news/2002/c-3-3.html @@ -42,6 +42,13 @@ documentation, etc.

lac

    +
  1. New: Functions SparsityPattern::copy_from and SparseMatrix::copy_from allow to copy a + full matrix into a sparse matrix. +
    + (WB 2002/02/06) +

diff --git a/deal.II/lac/include/lac/sparse_matrix.2.templates b/deal.II/lac/include/lac/sparse_matrix.2.templates index 4608417283..f2f37dfb7f 100644 --- a/deal.II/lac/include/lac/sparse_matrix.2.templates +++ b/deal.II/lac/include/lac/sparse_matrix.2.templates @@ -20,6 +20,9 @@ template SparseMatrix & SparseMatrix::copy_from (const SparseMatrix &); +template +void SparseMatrix::copy_from (const FullMatrix &); + template void SparseMatrix::add_scaled (const TYPEMAT, const SparseMatrix &); diff --git a/deal.II/lac/include/lac/sparse_matrix.h b/deal.II/lac/include/lac/sparse_matrix.h index 5eeacc57d5..ac6980f0af 100644 --- a/deal.II/lac/include/lac/sparse_matrix.h +++ b/deal.II/lac/include/lac/sparse_matrix.h @@ -21,6 +21,7 @@ #include template class Vector; +template class FullMatrix; /** * Sparse matrix. @@ -344,6 +345,19 @@ class SparseMatrix : public Subscriptor template void copy_from (const ForwardIterator begin, const ForwardIterator end); + + /** + * Copy the nonzero entries of a + * full matrix into this + * object. Previous content is + * deleted. Note that the + * underlying sparsity pattern + * must be appropriate to hold + * the nonzero entries of the + * full matrix. + */ + template + void copy_from (const FullMatrix &matrix); /** * Add @p{matrix} scaled by diff --git a/deal.II/lac/include/lac/sparse_matrix.templates.h b/deal.II/lac/include/lac/sparse_matrix.templates.h index 7998fb8c5d..12fcc7e0ff 100644 --- a/deal.II/lac/include/lac/sparse_matrix.templates.h +++ b/deal.II/lac/include/lac/sparse_matrix.templates.h @@ -16,6 +16,7 @@ #include #include +#include // we only need output streams, but older compilers did not provide @@ -237,6 +238,24 @@ SparseMatrix::copy_from (const SparseMatrix &matrix) }; + +template +template +void +SparseMatrix::copy_from (const FullMatrix &matrix) +{ + // first delete previous content + clear (); + + // then copy old matrix + for (unsigned int row=0; row template void diff --git a/deal.II/lac/include/lac/sparsity_pattern.h b/deal.II/lac/include/lac/sparsity_pattern.h index ba81481fd8..0155c938e5 100644 --- a/deal.II/lac/include/lac/sparsity_pattern.h +++ b/deal.II/lac/include/lac/sparsity_pattern.h @@ -21,6 +21,7 @@ #include +template class FullMatrix; template class SparseMatrix; class CompressedSparsityPattern; @@ -467,11 +468,27 @@ class SparsityPattern : public Subscriptor /** * Copy data from an object of * type - * @ref{CompressedSparsityPattern}. Previous - * content of this object is - * lost. + * @ref{CompressedSparsityPattern}. + * Previous content of this + * object is lost, and the + * sparsity pattern is in + * compressed mode afterwards. */ void copy_from (const CompressedSparsityPattern &csp); + + /** + * Take a full matrix and use its + * nonzero entries to generate a + * sparse matrix entry pattern + * for this object. + * + * Previous content of this + * object is lost, and the + * sparsity pattern is in + * compressed mode afterwards. + */ + template + void copy_from (const FullMatrix &matrix); /** * Return whether the object is empty. It diff --git a/deal.II/lac/source/sparsity_pattern.cc b/deal.II/lac/source/sparsity_pattern.cc index 2e7e608c3c..0d26610f40 100644 --- a/deal.II/lac/source/sparsity_pattern.cc +++ b/deal.II/lac/source/sparsity_pattern.cc @@ -13,6 +13,7 @@ #include +#include #include #include @@ -495,6 +496,29 @@ SparsityPattern::copy_from (const CompressedSparsityPattern &csp) }; +template +void SparsityPattern::copy_from (const FullMatrix &matrix) +{ + // first init with the number of + // entries per row + std::vector entries_per_row (matrix.m(), 0); + for (unsigned int row=0; row &); +template void SparsityPattern::copy_from (const FullMatrix &);