From 15ba8301329286dd3b9d6941ff943482db0174fd Mon Sep 17 00:00:00 2001 From: wolf Date: Wed, 13 Feb 2002 09:27:49 +0000 Subject: [PATCH] SparsityPattern::matrix_position git-svn-id: https://svn.dealii.org/trunk@5513 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/doc/news/2002/c-3-3.html | 121 ++++++++++++--------- deal.II/lac/include/lac/sparsity_pattern.h | 48 ++++++-- deal.II/lac/source/sparsity_pattern.cc | 32 ++++++ tests/lac/sparsity_pattern.cc | 25 +++++ 4 files changed, 165 insertions(+), 61 deletions(-) diff --git a/deal.II/doc/news/2002/c-3-3.html b/deal.II/doc/news/2002/c-3-3.html index 0ca59afb35..ae2c8335c9 100644 --- a/deal.II/doc/news/2002/c-3-3.html +++ b/deal.II/doc/news/2002/c-3-3.html @@ -26,51 +26,57 @@ documentation, etc.

General

    -
  1. Changed: The build system was entirely revised. Object - files in debug more now have the suffix .g.o instead of - .go. All object files from the subdirectories are now - placed into the /lib top-level directory, rather than - in library directories in the individual subdirs. -
    - (WB 2002/02/11) -

    +
  2. + Changed: The build system was entirely revised. Object + files in debug more now have the suffix .g.o + instead of .go. All object files from the + subdirectories are now placed into the /lib + top-level directory, rather than in library directories in the + individual subdirs. +
    + (WB 2002/02/11) +

base

- -
  • Changed: The quite logorrhoeic function name TensorProductPolynomials::n_tensor_product_polynomials was changed to - n to be compliant wth the new class PolynomialSpace. -
    - (GK 2002/02/11) -

    - -
  • New: The class PolynomialSpace - implements the space of polynomials at most a certain degree in - arbitrary space dimensions. -
    - (GK 2002/02/11) -

    - -
  • New: The function DataOutBase:: - write_tecplot_binary has been added. This - function will write Tecplot binary files if the Tecplot API is detected - by ./configure. To use this feature be sure that the environment - variable TECHOME points to a valid Tecplot installation and that the files - $TECHOME/include/TECIO.h and $TECHOME/lib/tecio.a exist. The name of the - file to be written is specified through the DataOutBase - ::TecplotFlags. - tecplot_binary_file_name variable. If the API is not - available this code simply calls the existing ASCII output function. -
    - (BK 2002/02/11) -

    - +
  • + Changed: The quite logorrhoeic function name TensorProductPolynomials::n_tensor_product_polynomials was changed to + n to be compliant wth the new class PolynomialSpace. +
    + (GK 2002/02/11) +

    + +
  • + New: The class PolynomialSpace + implements the space of polynomials at most a certain degree in + arbitrary space dimensions. +
    + (GK 2002/02/11) +

    + +
  • + New: The function DataOutBase:: + write_tecplot_binary has been + added. This function will write Tecplot binary files if the + Tecplot API is detected by ./configure. To use this feature be + sure that the environment variable TECHOME points to a valid + Tecplot installation and that the files + $TECHOME/include/TECIO.h and $TECHOME/lib/tecio.a exist. The + name of the file to be written is specified through the DataOutBase ::TecplotFlags. tecplot_binary_file_name variable. If the + API is not available this code simply calls the existing ASCII + output function. +
    + (BK 2002/02/11) +

    @@ -80,26 +86,35 @@ 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) -

      +
    2. + New: Function SparsityPattern::matrix_position is the + inverse function for SparsityPattern::operator(). +
      + (WB 2002/02/13) +

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

    deal.II

    - -
  • New: Finite element family with complete polynomial spaces - for discontinuous Galerkin: FE_DGP -
    - (GK 2002/02/11) -

    - +
  • + New: Finite element family with complete polynomial spaces + for discontinuous Galerkin: FE_DGP +
    + (GK 2002/02/11) +

    diff --git a/deal.II/lac/include/lac/sparsity_pattern.h b/deal.II/lac/include/lac/sparsity_pattern.h index 0155c938e5..f917b9ca7e 100644 --- a/deal.II/lac/include/lac/sparsity_pattern.h +++ b/deal.II/lac/include/lac/sparsity_pattern.h @@ -256,10 +256,12 @@ class SparsityPattern : public Subscriptor ~SparsityPattern (); /** - * Copy operator. For this the same holds - * as for the copy constructor: it is - * declared, defined and fine to be called, - * but the latter only for empty objects. + * Copy operator. For this the + * same holds as for the copy + * constructor: it is declared, + * defined and fine to be called, + * but the latter only for empty + * objects. */ SparsityPattern & operator = (const SparsityPattern &); @@ -510,10 +512,11 @@ class SparsityPattern : public Subscriptor /** * Return the index of the matrix - * element with row number @p{i} and - * column number @p{j}. If the matrix - * element is not a nonzero one, - * return @p{SparsityPattern::invalid_entry}. + * element with row number @p{i} + * and column number @p{j}. If + * the matrix element is not a + * nonzero one, return + * @p{SparsityPattern::invalid_entry}. * * This function is usually called * by the @p{operator()} of the @@ -525,10 +528,39 @@ class SparsityPattern : public Subscriptor * with a binary sort algorithm * because the column numbers are * sorted. + * + * If @p{m} is the number of + * entries in @p{row}, then the + * complexity of this function is + * @p{log(m)} if the sparsity + * pattern is compressed. */ unsigned int operator() (const unsigned int i, const unsigned int j) const; + /** + * This is the inverse operation + * to @p{operator()}: given a + * global index, find out row and + * column of the matrix entry to + * which it belongs. The returned + * value is the pair composed of + * row and column index. + * + * This function may only be + * called if the sparsity pattern + * is closed. The global index + * must then be between zero and + * @p{n_nonzero_elements}. + * + * If @p{N} is the number of + * rows of this matrix, then the + * complexity of this function is + * @p{log(N)}. + */ + std::pair + matrix_position (const unsigned int global_index) const; + /** * Add a nonzero entry to the matrix. * This function may only be called diff --git a/deal.II/lac/source/sparsity_pattern.cc b/deal.II/lac/source/sparsity_pattern.cc index 0d26610f40..5edda62920 100644 --- a/deal.II/lac/source/sparsity_pattern.cc +++ b/deal.II/lac/source/sparsity_pattern.cc @@ -661,6 +661,38 @@ SparsityPattern::exists (const unsigned int i, } + +std::pair +SparsityPattern::matrix_position (const unsigned int global_index) const +{ + Assert (compressed == true, ExcNotCompressed()); + Assert (global_index < n_nonzero_elements(), + ExcIndexRange (global_index, 0, n_nonzero_elements())); + + // first find the row in which the + // entry is located. for this note + // that the rowstart array indexes + // the global indices at which each + // row starts. since it is sorted, + // and since there is an element + // for the one-past-last row, we + // can simply use a bisection + // search on it + const unsigned int row + = (std::upper_bound (&rowstart[0], &rowstart[rows], global_index) + - &rowstart[0] - 1); + + // now, the column index is simple + // since that is what the colnums + // array stores: + const unsigned int col = colnums[global_index]; + + // so return the respective pair + return std::make_pair (row,col); +}; + + + void SparsityPattern::symmetrize () { diff --git a/tests/lac/sparsity_pattern.cc b/tests/lac/sparsity_pattern.cc index 023540907b..0de153d679 100644 --- a/tests/lac/sparsity_pattern.cc +++ b/tests/lac/sparsity_pattern.cc @@ -96,6 +96,31 @@ main () for (; sp3_p != sp3.get_column_numbers()+sp3.get_rowstart_indices()[row+1]; ++sp3_p, ++sp4_p) Assert (*sp3_p == *sp4_p, ExcInternalError()); }; + + + // check the matrix_position + // function with sparsity patterns + // sp1 through sp4. the checked + // function should be the inverse + // of operator() + // + // check inverseness property first + // forward, then backward + for (unsigned int loop=1; loop<=4; ++loop) + { + const SparsityPattern & + sp = (loop==1 ? sp1 : (loop==2 ? sp2 : (loop==3 ? sp3 : sp4))); + for (unsigned int i=0; i