From ce85f9a650b07eb0ae76978a837d469cf4e8dbf3 Mon Sep 17 00:00:00 2001 From: Guido Kanschat Date: Wed, 26 Aug 2009 18:09:32 +0000 Subject: [PATCH] add initializers with BlockIndices git-svn-id: https://svn.dealii.org/trunk@19347 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/doc/news/changes.h | 18 ++++ .../lac/include/lac/block_sparsity_pattern.h | 48 +++++++++- deal.II/lac/include/lac/block_vector.h | 24 +++++ .../lac/include/lac/block_vector.templates.h | 23 ++++- deal.II/lac/source/block_sparsity_pattern.cc | 90 ++++++++++++++----- 5 files changed, 175 insertions(+), 28 deletions(-) diff --git a/deal.II/doc/news/changes.h b/deal.II/doc/news/changes.h index f12740255a..ef8290ba35 100644 --- a/deal.II/doc/news/changes.h +++ b/deal.II/doc/news/changes.h @@ -296,6 +296,16 @@ inconvenience this causes.

lac

    + +
  1. Improved: BlockVector and several of the block sparsity + patterns can now be initialized with BlockIndices + objects. Therefore, if an application needs such an object, it does + not have to store a vector of block sizes separately. +
    + (GK 2009/08/26) +

    +
  2. +
  3. Fixed: Crash or strange behaviour (wrong matrix entries written) in @@ -390,6 +400,14 @@ inconvenience this causes.

    deal.II

      + +
    1. FETools::compute_block_renumbering() can nor return block sizes instead of + start indices. +
      + (GK 2009/08/26) +

      +
    2. +
    3. New: The function GridGenerator::truncated_cone() and the class ConeBoundary diff --git a/deal.II/lac/include/lac/block_sparsity_pattern.h b/deal.II/lac/include/lac/block_sparsity_pattern.h index 6cf9e4f17e..abb365c913 100644 --- a/deal.II/lac/include/lac/block_sparsity_pattern.h +++ b/deal.II/lac/include/lac/block_sparsity_pattern.h @@ -2,7 +2,7 @@ // $Id$ // Version: $Name$ // -// Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 by the deal.II authors +// Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 by the deal.II authors // // This file is subject to QPL and may not be distributed // without copyright and license information. Please refer @@ -679,6 +679,15 @@ class BlockCompressedSparsityPattern : public BlockSparsityPatternBase& row_block_sizes, const std::vector& col_block_sizes); + /** + * Initialize the pattern with + * two BlockIndices for the block + * structures of matrix rows and + * columns. + */ + BlockCompressedSparsityPattern (const BlockIndices& row_indices, + const BlockIndices& col_indices); + /** * Resize the matrix to a tensor * product of matrices with @@ -697,6 +706,18 @@ class BlockCompressedSparsityPattern : public BlockSparsityPatternBase &row_block_sizes, const std::vector< unsigned int > &col_block_sizes); + /** + * Resize the matrix to a tensor + * product of matrices with + * dimensions defined by the + * arguments. The two + * BlockIndices objects must be + * initialized and the sparsity + * pattern will have the + * same block structure afterwards. + */ + void reinit (const BlockIndices& row_indices, const BlockIndices& col_indices); + /** * Allow the use of the reinit * functions of the base class as @@ -759,7 +780,7 @@ class BlockCompressedSetSparsityPattern : public BlockSparsityPatternBase& row_block_sizes, - const std::vector& col_block_sizes); + const std::vector& col_block_sizes); + + /** + * Initialize the pattern with + * two BlockIndices for the block + * structures of matrix rows and + * columns. + */ + BlockCompressedSetSparsityPattern (const BlockIndices& row_indices, + const BlockIndices& col_indices); /** * Resize the matrix to a tensor @@ -793,6 +823,18 @@ class BlockCompressedSetSparsityPattern : public BlockSparsityPatternBase &row_block_sizes, const std::vector< unsigned int > &col_block_sizes); + /** + * Resize the matrix to a tensor + * product of matrices with + * dimensions defined by the + * arguments. The two + * BlockIndices objects must be + * initialized and the sparsity + * pattern will have the + * same block structure afterwards. + */ + void reinit (const BlockIndices& row_indices, const BlockIndices& col_indices); + /** * Allow the use of the reinit * functions of the base class as diff --git a/deal.II/lac/include/lac/block_vector.h b/deal.II/lac/include/lac/block_vector.h index 0d65b7607d..0448ca1913 100644 --- a/deal.II/lac/include/lac/block_vector.h +++ b/deal.II/lac/include/lac/block_vector.h @@ -160,6 +160,13 @@ class BlockVector : public BlockVectorBase > */ BlockVector (const std::vector &block_sizes); + /** + * Constructor. Initialize vector + * to the structure found in the + * BlockIndices argument. + */ + BlockVector (const BlockIndices& block_indices); + /** * Constructor. Set the number of * blocks to @@ -285,6 +292,23 @@ class BlockVector : public BlockVectorBase > */ void reinit (const std::vector &N, const bool fast=false); + + /** + * Reinitialize the BlockVector + * to reflect the structure found + * in BlockIndices. + * + * If the number of blocks is the + * same as before this function + * was called, all vectors remain + * the same and reinit() is + * called for each vector. + * + * If fast==false, the vector + * is filled with zeros. + */ + void reinit (const BlockIndices& block_indices, + const bool fast=false); /** * Change the dimension to that diff --git a/deal.II/lac/include/lac/block_vector.templates.h b/deal.II/lac/include/lac/block_vector.templates.h index c5c7ae89c6..91aa68ba59 100644 --- a/deal.II/lac/include/lac/block_vector.templates.h +++ b/deal.II/lac/include/lac/block_vector.templates.h @@ -2,7 +2,7 @@ // $Id$ // Version: $Name$ // -// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 by the deal.II authors +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2009 by the deal.II authors // // This file is subject to QPL and may not be distributed // without copyright and license information. Please refer @@ -38,6 +38,13 @@ BlockVector::BlockVector (const std::vector &n) } +template +BlockVector::BlockVector (const BlockIndices& n) +{ + reinit (n, false); +} + + template BlockVector::BlockVector (const BlockVector& v) : @@ -104,6 +111,20 @@ void BlockVector::reinit (const std::vector &n, } +template +void BlockVector::reinit ( + const BlockIndices& n, + const bool fast) +{ + this->block_indices = n; + if (this->components.size() != this->n_blocks()) + this->components.resize(this->n_blocks()); + + for (unsigned int i=0; in_blocks(); ++i) + this->components[i].reinit(n.block_size(i), fast); +} + + template template void BlockVector::reinit (const BlockVector& v, diff --git a/deal.II/lac/source/block_sparsity_pattern.cc b/deal.II/lac/source/block_sparsity_pattern.cc index 67e84d312c..4ab9c469e7 100644 --- a/deal.II/lac/source/block_sparsity_pattern.cc +++ b/deal.II/lac/source/block_sparsity_pattern.cc @@ -2,7 +2,7 @@ // $Id$ // Version: $Name$ // -// Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 by the deal.II authors +// Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009 by the deal.II authors // // This file is subject to QPL and may not be distributed // without copyright and license information. Please refer @@ -441,8 +441,9 @@ BlockCompressedSparsityPattern::BlockCompressedSparsityPattern () BlockCompressedSparsityPattern:: -BlockCompressedSparsityPattern (const unsigned int n_rows, - const unsigned int n_columns) +BlockCompressedSparsityPattern ( + const unsigned int n_rows, + const unsigned int n_columns) : BlockSparsityPatternBase(n_rows, n_columns) @@ -450,16 +451,20 @@ BlockCompressedSparsityPattern (const unsigned int n_rows, BlockCompressedSparsityPattern:: -BlockCompressedSparsityPattern (const std::vector& row_indices, - const std::vector& col_indices) - : - BlockSparsityPatternBase(row_indices.size(), - col_indices.size()) +BlockCompressedSparsityPattern ( + const std::vector& row_indices, + const std::vector& col_indices) { - for (unsigned int i=0;iblock(i,j).reinit(row_indices[i],col_indices[j]); - this->collect_sizes(); + reinit(row_indices, col_indices); +} + + +BlockCompressedSparsityPattern:: +BlockCompressedSparsityPattern ( + const BlockIndices& row_indices, + const BlockIndices& col_indices) +{ + reinit(row_indices, col_indices); } @@ -477,31 +482,52 @@ BlockCompressedSparsityPattern::reinit ( +void +BlockCompressedSparsityPattern::reinit ( + const BlockIndices& row_indices, + const BlockIndices& col_indices) +{ + BlockSparsityPatternBase::reinit(row_indices.size(), + col_indices.size()); + for (unsigned int i=0;iblock(i,j).reinit(row_indices.block_size(i), + col_indices.block_size(j)); + this->collect_sizes(); +} + + + BlockCompressedSetSparsityPattern::BlockCompressedSetSparsityPattern () {} BlockCompressedSetSparsityPattern:: -BlockCompressedSetSparsityPattern (const unsigned int n_rows, - const unsigned int n_columns) +BlockCompressedSetSparsityPattern ( + const unsigned int n_rows, + const unsigned int n_columns) : BlockSparsityPatternBase(n_rows, - n_columns) + n_columns) {} BlockCompressedSetSparsityPattern:: -BlockCompressedSetSparsityPattern (const std::vector& row_indices, - const std::vector& col_indices) - : - BlockSparsityPatternBase(row_indices.size(), - col_indices.size()) +BlockCompressedSetSparsityPattern ( + const std::vector& row_indices, + const std::vector& col_indices) { - for (unsigned int i=0;iblock(i,j).reinit(row_indices[i],col_indices[j]); - this->collect_sizes(); + reinit(row_indices, col_indices); +} + + +BlockCompressedSetSparsityPattern:: +BlockCompressedSetSparsityPattern ( + const BlockIndices& row_indices, + const BlockIndices& col_indices) +{ + reinit(row_indices, col_indices); } @@ -519,6 +545,22 @@ BlockCompressedSetSparsityPattern::reinit ( +void +BlockCompressedSetSparsityPattern::reinit ( + const BlockIndices& row_indices, + const BlockIndices& col_indices) +{ + BlockSparsityPatternBase::reinit(row_indices.size(), + col_indices.size()); + for (unsigned int i=0;iblock(i,j).reinit(row_indices.block_size(i), + col_indices.block_size(j)); + this->collect_sizes(); +} + + + BlockCompressedSimpleSparsityPattern::BlockCompressedSimpleSparsityPattern () {} -- 2.39.5