From b75910e71711011f9ef438ab18b291962d2e52da Mon Sep 17 00:00:00 2001 From: kanschat Date: Sun, 20 Jun 2010 17:53:33 +0000 Subject: [PATCH] use CompressedSparsityPattern git-svn-id: https://svn.dealii.org/trunk@21235 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/examples/step-3/step-3.cc | 24 ++++++++---------------- deal.II/examples/step-4/step-4.cc | 15 +++++++-------- deal.II/examples/step-5/step-5.cc | 15 +++++++-------- deal.II/examples/step-6/step-6.cc | 27 ++++++++++++++++----------- 4 files changed, 38 insertions(+), 43 deletions(-) diff --git a/deal.II/examples/step-3/step-3.cc b/deal.II/examples/step-3/step-3.cc index 3a3f92a8be..de0da46ba6 100644 --- a/deal.II/examples/step-3/step-3.cc +++ b/deal.II/examples/step-3/step-3.cc @@ -80,6 +80,7 @@ #include #include #include +#include #include #include @@ -259,25 +260,16 @@ void LaplaceProblem::make_grid_and_dofs () // As we have seen in the previous example, // we set up a sparsity pattern for the // system matrix and tag those entries that - // might be nonzero. Compared to what we - // did in step-2, the only change is that - // instead of giving a magically obtained - // maximal number of nonzero entries per - // row, we now use a function in the - // DoFHandler class that can compute - // this number for us: - sparsity_pattern.reinit (dof_handler.n_dofs(), - dof_handler.n_dofs(), - dof_handler.max_couplings_between_dofs()); - DoFTools::make_sparsity_pattern (dof_handler, sparsity_pattern); - sparsity_pattern.compress(); + // might be nonzero. + CompressedSparsityPattern c_sparsity(dof_handler.n_dofs()); + DoFTools::make_sparsity_pattern (dof_handler, c_sparsity); + sparsity_pattern.copy_from(c_sparsity); // Now the sparsity pattern is - // built and fixed (after - // `compress' has been called, you + // built, you // can't add nonzero entries - // anymore; the sparsity pattern is - // `sealed', so to say), we can + // anymore. The sparsity pattern is + // `sealed', so to say, and we can // initialize the matrix itself // with it. Note that the // SparsityPattern object does diff --git a/deal.II/examples/step-4/step-4.cc b/deal.II/examples/step-4/step-4.cc index 680c59bb4c..8c49529ef2 100644 --- a/deal.II/examples/step-4/step-4.cc +++ b/deal.II/examples/step-4/step-4.cc @@ -3,7 +3,7 @@ /* $Id$ */ /* */ -/* Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 by the deal.II authors */ +/* Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 by the deal.II authors */ /* */ /* This file is subject to QPL and may not be distributed */ /* without copyright and license information. Please refer */ @@ -33,6 +33,7 @@ #include #include #include +#include #include #include @@ -344,14 +345,12 @@ void LaplaceProblem::make_grid_and_dofs () << dof_handler.n_dofs() << std::endl; - sparsity_pattern.reinit (dof_handler.n_dofs(), - dof_handler.n_dofs(), - dof_handler.max_couplings_between_dofs()); - DoFTools::make_sparsity_pattern (dof_handler, sparsity_pattern); - sparsity_pattern.compress(); - + CompressedSparsityPattern c_sparsity(dof_handler.n_dofs()); + DoFTools::make_sparsity_pattern (dof_handler, c_sparsity); + sparsity_pattern.copy_from(c_sparsity); + system_matrix.reinit (sparsity_pattern); - + solution.reinit (dof_handler.n_dofs()); system_rhs.reinit (dof_handler.n_dofs()); } diff --git a/deal.II/examples/step-5/step-5.cc b/deal.II/examples/step-5/step-5.cc index 86d3b720c5..d140d0a654 100644 --- a/deal.II/examples/step-5/step-5.cc +++ b/deal.II/examples/step-5/step-5.cc @@ -3,7 +3,7 @@ /* $Id$ */ /* */ -/* Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2006, 2007, 2008 by the deal.II authors */ +/* Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2006, 2007, 2008, 2010 by the deal.II authors */ /* */ /* This file is subject to QPL and may not be distributed */ /* without copyright and license information. Please refer */ @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -382,14 +383,12 @@ void LaplaceProblem::setup_system () << dof_handler.n_dofs() << std::endl; - sparsity_pattern.reinit (dof_handler.n_dofs(), - dof_handler.n_dofs(), - dof_handler.max_couplings_between_dofs()); - DoFTools::make_sparsity_pattern (dof_handler, sparsity_pattern); - sparsity_pattern.compress(); - + CompressedSparsityPattern c_sparsity(dof_handler.n_dofs()); + DoFTools::make_sparsity_pattern (dof_handler, c_sparsity); + sparsity_pattern.copy_from(c_sparsity); + system_matrix.reinit (sparsity_pattern); - + solution.reinit (dof_handler.n_dofs()); system_rhs.reinit (dof_handler.n_dofs()); } diff --git a/deal.II/examples/step-6/step-6.cc b/deal.II/examples/step-6/step-6.cc index b6d3ae2729..0050d8507b 100644 --- a/deal.II/examples/step-6/step-6.cc +++ b/deal.II/examples/step-6/step-6.cc @@ -3,7 +3,7 @@ /* $Id$ */ /* */ -/* Copyright (C) 2000, 2001, 2002, 2003, 2004, 2006, 2007, 2008 by the deal.II authors */ +/* Copyright (C) 2000, 2001, 2002, 2003, 2004, 2006, 2007, 2008, 2010 by the deal.II authors */ /* */ /* This file is subject to QPL and may not be distributed */ /* without copyright and license information. Please refer */ @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -409,11 +410,6 @@ void LaplaceProblem::setup_system () { dof_handler.distribute_dofs (fe); - sparsity_pattern.reinit (dof_handler.n_dofs(), - dof_handler.n_dofs(), - dof_handler.max_couplings_between_dofs()); - DoFTools::make_sparsity_pattern (dof_handler, sparsity_pattern); - solution.reinit (dof_handler.n_dofs()); system_rhs.reinit (dof_handler.n_dofs()); @@ -467,6 +463,15 @@ void LaplaceProblem::setup_system () // added any more: hanging_node_constraints.close (); + // Now we first build our + // compressed sparsity pattern like + // we did in the previous + // examples. Nevertheless, we do + // not copy it to the final + // sparsity pattern immediately. + CompressedSparsityPattern c_sparsity(dof_handler.n_dofs()); + DoFTools::make_sparsity_pattern (dof_handler, c_sparsity); + // The constrained hanging nodes // will later be eliminated from // the linear system of @@ -483,17 +488,17 @@ void LaplaceProblem::setup_system () // the system matrix and right hand // side, as well as for the // sparsity pattern. - hanging_node_constraints.condense (sparsity_pattern); + hanging_node_constraints.condense (c_sparsity); // Now all non-zero entries of the // matrix are known (i.e. those // from regularly assembling the // matrix and those that were // introduced by eliminating - // constraints). We can thus close - // the sparsity pattern and remove - // unneeded space: - sparsity_pattern.compress(); + // constraints). We can thus copy + // our intermediate object to + // the sparsity pattern: + sparsity_pattern.copy_from(c_sparsity); // Finally, the so-constructed // sparsity pattern serves as the -- 2.39.5