From 3de9e98b915228153979592b7a9e2ab1739440a0 Mon Sep 17 00:00:00 2001 From: bangerth Date: Thu, 17 Nov 2011 23:06:48 +0000 Subject: [PATCH] Make copy constructor work if the matrix is empty. git-svn-id: https://svn.dealii.org/trunk@24753 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/doc/news/changes.h | 18 +++-- .../deal.II/lac/sparse_matrix_ez.templates.h | 68 ++++++++++--------- 2 files changed, 47 insertions(+), 39 deletions(-) diff --git a/deal.II/doc/news/changes.h b/deal.II/doc/news/changes.h index 09a6e01a97..5a8a6d7646 100644 --- a/deal.II/doc/news/changes.h +++ b/deal.II/doc/news/changes.h @@ -34,11 +34,6 @@ inconvenience this causes.

General

    -
  1. New: The DoFTools::count_dofs_per_block function now also works -for objects of type hp::DoFHandler. -
    -(Jason Sheldon, 2011/11/13) -
  2. Fixed: The Intel compiler complains that it can't copy Trilinos vector reference objects, preventing the compiling of step-32. This is now fixed.
    @@ -78,11 +73,22 @@ enabled due to a missing include file in file

    Specific improvements

      +
    1. New: The copy constructor of the SparseMatrixEZ function now works +(rather than throwing an exception) if the copied matrix has size zero. +This is in accordance to the other matrix classes. +
      +(Wolfgang Bangerth, 2011/11/15) +
    2. New: The class ScalarFunctionFromFunctionObject provides a quick way to convert an arbitrary function into a function object that can be passed to part of the library that require the Function@ interface.
      -(Wolfgang Bangerth, 2011/10/30) +(Wolfgang Bangerth, 2011/11/15) + +
    3. New: The DoFTools::count_dofs_per_block function now also works +for objects of type hp::DoFHandler. +
      +(Jason Sheldon, 2011/11/13)
    4. New: FETools::get_fe_from_name() can now return objects of type FE_Nothing.
      diff --git a/deal.II/include/deal.II/lac/sparse_matrix_ez.templates.h b/deal.II/include/deal.II/lac/sparse_matrix_ez.templates.h index fb03815a79..16b06ba2e0 100644 --- a/deal.II/include/deal.II/lac/sparse_matrix_ez.templates.h +++ b/deal.II/include/deal.II/lac/sparse_matrix_ez.templates.h @@ -35,9 +35,11 @@ SparseMatrixEZ::SparseMatrixEZ() template SparseMatrixEZ::SparseMatrixEZ(const SparseMatrixEZ &m) : - Subscriptor (m) + Subscriptor (m), + n_columns (0) { - Assert(false, ExcNotImplemented()); + Assert(m.n() == 0, ExcNotImplemented()); + Assert(m.m() == 0, ExcNotImplemented()); } @@ -73,12 +75,12 @@ SparseMatrixEZ::operator = (const double d) typename std::vector::iterator e = data.begin(); const typename std::vector::iterator end = data.end(); - + while (e != end) { (e++)->value = 0.; } - + return *this; } @@ -95,7 +97,7 @@ SparseMatrixEZ::reinit(const unsigned int n_rows, clear(); increment = default_increment; - + n_columns = n_cols; row_info.resize(n_rows); if (reserve != 0) @@ -248,7 +250,7 @@ SparseMatrixEZ::precondition_Jacobi (Vector &dst, const somenumber *src_ptr = src.begin(); typename std::vector::const_iterator ri = row_info.begin(); const typename std::vector::const_iterator end = row_info.end(); - + for (; ri != end; ++dst_ptr, ++src_ptr, ++ri) { Assert (ri->diagonal != RowInfo::invalid_diagonal, ExcNoDiagonal()); @@ -273,7 +275,7 @@ SparseMatrixEZ::precondition_SOR (Vector &dst, const somenumber *src_ptr = src.begin(); typename std::vector::const_iterator ri = row_info.begin(); const typename std::vector::const_iterator end = row_info.end(); - + for (; ri != end; ++dst_ptr, ++src_ptr, ++ri) { Assert (ri->diagonal != RowInfo::invalid_diagonal, ExcNoDiagonal()); @@ -281,7 +283,7 @@ SparseMatrixEZ::precondition_SOR (Vector &dst, const unsigned int end_row = ri->start + ri->diagonal; for (unsigned int i=ri->start;istart + ri->diagonal].value; } } @@ -305,7 +307,7 @@ SparseMatrixEZ::precondition_TSOR (Vector &dst, ri = row_info.rbegin(); const typename std::vector::const_reverse_iterator end = row_info.rend(); - + for (; ri != end; --dst_ptr, --src_ptr, ++ri) { Assert (ri->diagonal != RowInfo::invalid_diagonal, ExcNoDiagonal()); @@ -313,7 +315,7 @@ SparseMatrixEZ::precondition_TSOR (Vector &dst, const unsigned int end_row = ri->start + ri->length; for (unsigned int i=ri->start+ri->diagonal+1;istart + ri->diagonal].value; } } @@ -345,7 +347,7 @@ SparseMatrixEZ::precondition_SSOR (Vector &dst, const unsigned int end_row = ri->start + ri->diagonal; for (unsigned int i=ri->start;istart + ri->diagonal].value; } @@ -431,18 +433,18 @@ SparseMatrixEZ::compute_statistics( if (max_length < row->length) max_length = row->length; } - + // Number of entries allocated is // position of last entry used --row; allocated = row->start + row->length; reserved = data.capacity(); - - + + if (full) { used_by_line.resize(max_length+1); - + for (row = row_info.begin() ; row != endrow; ++row) { ++used_by_line[row->length]; @@ -453,7 +455,7 @@ SparseMatrixEZ::compute_statistics( template void -SparseMatrixEZ::print (std::ostream &out) const +SparseMatrixEZ::print (std::ostream &out) const { AssertThrow (out, ExcIO()); @@ -470,7 +472,7 @@ SparseMatrixEZ::print (std::ostream &out) const template -void +void SparseMatrixEZ::print_formatted ( std::ostream &out, const unsigned int precision, const bool scientific, @@ -483,7 +485,7 @@ SparseMatrixEZ::print_formatted ( std::ostream &out, Assert (n() != 0, ExcNotInitialized()); unsigned int width = width_; - + std::ios::fmtflags old_flags = out.flags(); unsigned int old_precision = out.precision (precision); @@ -512,7 +514,7 @@ SparseMatrixEZ::print_formatted ( std::ostream &out, } out << std::endl; }; - + // reset output format out.precision(old_precision); out.flags (old_flags); @@ -521,10 +523,10 @@ SparseMatrixEZ::print_formatted ( std::ostream &out, template void -SparseMatrixEZ::block_write (std::ostream &out) const +SparseMatrixEZ::block_write (std::ostream &out) const { AssertThrow (out, ExcIO()); - + // first the simple objects, // bracketed in [...] out << '[' << row_info.size() << "][" @@ -536,9 +538,9 @@ SparseMatrixEZ::block_write (std::ostream &out) const out.write(reinterpret_cast(&*r), sizeof(RowInfo) * row_info.size()); -// Just in case that vector entries are not stored consecutively +// Just in case that vector entries are not stored consecutively // const typename std::vector::const_iterator re = row_info.end(); - + // while (r != re) // { // out.write(reinterpret_cast(&*r), @@ -547,12 +549,12 @@ SparseMatrixEZ::block_write (std::ostream &out) const // } out << "]["; - + typename std::vector::const_iterator d = data.begin(); out.write(reinterpret_cast(&*d), sizeof(Entry) * data.size()); -// Just in case that vector entries are not stored consecutively +// Just in case that vector entries are not stored consecutively // const typename std::vector::const_iterator de = data.end(); // while (d != de) @@ -561,9 +563,9 @@ SparseMatrixEZ::block_write (std::ostream &out) const // sizeof(Entry)); // ++d; // } - + out << ']'; - + AssertThrow (out, ExcIO()); } @@ -584,16 +586,16 @@ SparseMatrixEZ::block_read (std::istream &in) DEAL_II_CHECK_INPUT(in,'[',c); in >> n; row_info.resize(n); - + DEAL_II_CHECK_INPUT(in,']',c); DEAL_II_CHECK_INPUT(in,'[',c); in >> n_columns; - + DEAL_II_CHECK_INPUT(in,']',c); DEAL_II_CHECK_INPUT(in,'[',c); in >> n; data.resize(n); - + DEAL_II_CHECK_INPUT(in,']',c); DEAL_II_CHECK_INPUT(in,'[',c); in >> increment; @@ -604,13 +606,13 @@ SparseMatrixEZ::block_read (std::istream &in) // then read data in.read(reinterpret_cast(&row_info[0]), sizeof(RowInfo) * row_info.size()); - + DEAL_II_CHECK_INPUT(in,']',c); DEAL_II_CHECK_INPUT(in,'[',c); - + in.read(reinterpret_cast(&data[0]), sizeof(Entry) * data.size()); - + DEAL_II_CHECK_INPUT(in,']',c); } -- 2.39.5