FEFaceValuesBase<deal_II_dimension> }
SPARSITY_PATTERNS := { SparsityPattern;
- CompressedSparsityPattern;
- CompressedSetSparsityPattern;
- CompressedSimpleSparsityPattern;
+ DynamicSparsityPattern;
@DEAL_II_EXPAND_TRILINOS_SPARSITY_PATTERN@;
BlockSparsityPattern;
- BlockCompressedSparsityPattern;
- BlockCompressedSetSparsityPattern;
- BlockCompressedSimpleSparsityPattern;
+ BlockDynamicSparsityPattern;
@DEAL_II_EXPAND_TRILINOS_BLOCK_SPARSITY_PATTERN@; }
DIMENSIONS := { 1; 2; 3 }
// ---------------------------------------------------------------------
//
-// Copyright (C) 2006 - 2014 by the deal.II authors
+// Copyright (C) 2006 - 2015 by the deal.II authors
//
// This file is part of the deal.II library.
//
// ---------------------------------------------------------------------
-// See documentation of BlockCompressedSparsityPattern for documentation of this example
+// See documentation of BlockDynamicSparsityPattern for documentation of this example
#include <deal.II/lac/block_sparsity_pattern.h>
#include <deal.II/lac/constraint_matrix.h>
std::vector<unsigned int> dofs_per_block(fe.n_blocks());
DoFTools::count_dofs_per_block(dof, dofs_per_block);
- BlockCompressedSparsityPattern c_sparsity(fe.n_blocks(), fe.n_blocks());
+ BlockDynamicSparsityPattern c_sparsity(fe.n_blocks(), fe.n_blocks());
for (unsigned int i=0; i<fe.n_blocks(); ++i)
for (unsigned int j=0; j<fe.n_blocks(); ++j)
c_sparsity.block(i,j).reinit(dofs_per_block[i],dofs_per_block[j]);
#include <deal.II/numerics/matrix_tools.h>
// Just this one is new: it declares a class
-// <code>CompressedSparsityPattern</code>, which we will use and explain
+// <code>DynamicSparsityPattern</code>, which we will use and explain
// further down below.
-#include <deal.II/lac/compressed_sparsity_pattern.h>
+#include <deal.II/lac/dynamic_sparsity_pattern.h>
// We will make use of the std::find algorithm of the C++ standard library, so
// we have to include the following file for its declaration:
//
// Since this can be so difficult that no reasonable answer can be given
// that allows allocation of only a reasonable amount of memory, there is
- // a class <code>CompressedSparsityPattern</code>, that can help us out
+ // a class <code>DynamicSparsityPattern</code>, that can help us out
// here. It does not require that we know in advance how many entries rows
// could have, but allows just about any length. It is thus significantly
// more flexible in case you do not have good estimates of row lengths,
// pattern due to the differential operator, then condense it with the
// constraints object which adds those positions in the sparsity pattern
// that are required for the elimination of the constraint.
- CompressedSparsityPattern csp (dof_handler.n_dofs(),
- dof_handler.n_dofs());
+ DynamicSparsityPattern csp (dof_handler.n_dofs(),
+ dof_handler.n_dofs());
DoFTools::make_sparsity_pattern (dof_handler, csp);
mean_value_constraints.condense (csp);
// Finally, once we have the full pattern, we can initialize an object of
// type <code>SparsityPattern</code> from it and in turn initialize the
// matrix with it. Note that this is actually necessary, since the
- // <code>CompressedSparsityPattern</code> is so inefficient compared to
+ // <code>DynamicSparsityPattern</code> is so inefficient compared to
// the <code>SparsityPattern</code> class due to the more flexible data
// structures it has to use, that we can impossibly base the sparse matrix
// class on it, but rather need an object of type
#include <deal.II/base/quadrature_lib.h>
#include <deal.II/base/function.h>
#include <deal.II/lac/vector.h>
-#include <deal.II/lac/compressed_sparsity_pattern.h>
+#include <deal.II/lac/dynamic_sparsity_pattern.h>
#include <deal.II/lac/sparse_matrix.h>
#include <deal.II/grid/tria.h>
#include <deal.II/grid/grid_generator.h>
dof_handler.distribute_dofs (fe);
// We start by generating the sparsity pattern. To this end, we first fill
- // an intermediate object of type CompressedSparsityPattern with the
+ // an intermediate object of type DynamicSparsityPattern with the
// couplings appearing in the system. After building the pattern, this
// object is copied to <code>sparsity_pattern</code> and can be discarded.
// To build the sparsity pattern for DG discretizations, we can call the
// function analogue to DoFTools::make_sparsity_pattern, which is called
// DoFTools::make_flux_sparsity_pattern:
- CompressedSparsityPattern c_sparsity(dof_handler.n_dofs());
+ DynamicSparsityPattern c_sparsity(dof_handler.n_dofs());
DoFTools::make_flux_sparsity_pattern (dof_handler, c_sparsity);
sparsity_pattern.copy_from(c_sparsity);
#include <deal.II/lac/vector.h>
#include <deal.II/lac/full_matrix.h>
#include <deal.II/lac/sparse_matrix.h>
+#include <deal.II/lac/dynamic_sparsity_pattern.h>
#include <deal.II/lac/solver_cg.h>
#include <deal.II/lac/precondition.h>
#include <deal.II/lac/constraint_matrix.h>
Threads::Task<> side_task(std_cxx11::bind(mhnc_p,std_cxx11::cref(dof_handler),
std_cxx11::ref(hanging_node_constraints)));
- 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);
+ DynamicSparsityPattern csp(dof_handler.n_dofs(), dof_handler.n_dofs());
+ DoFTools::make_sparsity_pattern (dof_handler, csp);
+
+
// Wait for the side task to be done before going further
side_task.join();
hanging_node_constraints.close ();
- hanging_node_constraints.condense (sparsity_pattern);
+ hanging_node_constraints.condense (csp);
+ sparsity_pattern.copy_from(csp);
+
- // Finally, close the sparsity pattern, initialize the matrix, and set
- // the right hand side vector to the right size.
- sparsity_pattern.compress();
+ // Finally initialize the matrix and right hand side vector
matrix.reinit (sparsity_pattern);
rhs.reinit (dof_handler.n_dofs());
}
#include <deal.II/lac/vector.h>
#include <deal.II/lac/full_matrix.h>
#include <deal.II/lac/sparse_matrix.h>
+#include <deal.II/lac/dynamic_sparsity_pattern.h>
#include <deal.II/lac/solver_cg.h>
#include <deal.II/lac/precondition.h>
#include <deal.II/lac/constraint_matrix.h>
ConstraintMatrix &)
= &DoFTools::make_hanging_node_constraints;
- Threads::Task<> side_task
- = Threads::new_task (mhnc_p,
- dof_handler,
- hanging_node_constraints);
+ // Start a side task then continue on the main thread
+ Threads::Task<> side_task(std_cxx11::bind(mhnc_p,std_cxx11::cref(dof_handler),
+ std_cxx11::ref(hanging_node_constraints)));
- 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);
+ DynamicSparsityPattern csp(dof_handler.n_dofs(), dof_handler.n_dofs());
+ DoFTools::make_sparsity_pattern (dof_handler, csp);
+
+
+ // Wait for the side task to be done before going further
side_task.join();
hanging_node_constraints.close ();
- hanging_node_constraints.condense (sparsity_pattern);
+ hanging_node_constraints.condense (csp);
+ sparsity_pattern.copy_from(csp);
- sparsity_pattern.compress();
matrix.reinit (sparsity_pattern);
rhs.reinit (dof_handler.n_dofs());
}
#include <deal.II/lac/vector.h>
#include <deal.II/lac/full_matrix.h>
#include <deal.II/lac/sparse_matrix.h>
-#include <deal.II/lac/compressed_sparsity_pattern.h>
+#include <deal.II/lac/dynamic_sparsity_pattern.h>
#include <deal.II/lac/solver_cg.h>
#include <deal.II/lac/precondition.h>
#include <deal.II/lac/constraint_matrix.h>
newton_update.reinit (dof_handler.n_dofs());
system_rhs.reinit (dof_handler.n_dofs());
- CompressedSparsityPattern c_sparsity(dof_handler.n_dofs());
+ DynamicSparsityPattern c_sparsity(dof_handler.n_dofs());
DoFTools::make_sparsity_pattern (dof_handler, c_sparsity);
hanging_node_constraints.condense (c_sparsity);
? ")" : ", ");
deallog << 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);
+ DynamicSparsityPattern csp(dof_handler.n_dofs(), dof_handler.n_dofs());
+ DoFTools::make_sparsity_pattern (dof_handler, csp);
solution.reinit (dof_handler.n_dofs());
system_rhs.reinit (dof_handler.n_dofs());
constraints);
constraints.close ();
hanging_node_constraints.close ();
- constraints.condense (sparsity_pattern);
- sparsity_pattern.compress();
+ constraints.condense (csp);
+ sparsity_pattern.copy_from (csp);
system_matrix.reinit (sparsity_pattern);
// The multigrid constraints have to be initialized. They need to know
// matrices.
for (unsigned int level=0; level<n_levels; ++level)
{
- CompressedSparsityPattern csp;
- csp.reinit(dof_handler.n_dofs(level),
- dof_handler.n_dofs(level));
+ DynamicSparsityPattern csp (dof_handler.n_dofs(level),
+ dof_handler.n_dofs(level));
MGTools::make_sparsity_pattern(dof_handler, csp, level);
mg_sparsity_patterns[level].copy_from (csp);
#include <deal.II/base/utilities.h>
#include <deal.II/lac/vector.h>
#include <deal.II/lac/full_matrix.h>
-#include <deal.II/lac/compressed_sparsity_pattern.h>
+#include <deal.II/lac/dynamic_sparsity_pattern.h>
#include <deal.II/lac/petsc_vector.h>
#include <deal.II/lac/petsc_parallel_vector.h>
#include <deal.II/lac/petsc_parallel_sparse_matrix.h>
// going to work with, and make sure that the condensation of hanging node
// constraints add the necessary additional entries in the sparsity
// pattern:
- CompressedSparsityPattern sparsity_pattern (dof_handler.n_dofs(),
- dof_handler.n_dofs());
+ DynamicSparsityPattern sparsity_pattern (dof_handler.n_dofs(),
+ dof_handler.n_dofs());
DoFTools::make_sparsity_pattern (dof_handler, sparsity_pattern);
hanging_node_constraints.condense (sparsity_pattern);
- // Note that we have used the <code>CompressedSparsityPattern</code> class
+ // Note that we have used the <code>DynamicSparsityPattern</code> class
// here that was already introduced in step-11, rather than the
// <code>SparsityPattern</code> class that we have used in all other
// cases. The reason for this is that for the latter class to work we have
// too much memory can lead to out-of-memory situations.
//
// In order to avoid this, we resort to the
- // <code>CompressedSparsityPattern</code> class that is slower but does
+ // <code>DynamicSparsityPattern</code> class that is slower but does
// not require any up-front estimate on the number of nonzero entries per
// row. It therefore only ever allocates as much memory as it needs at any
// given time, and we can build it even for large 3d problems.
#include <deal.II/lac/sparse_matrix.h>
// We will also need to use an intermediate sparsity pattern structure, which
// is found in this file:
-#include <deal.II/lac/compressed_sparsity_pattern.h>
+#include <deal.II/lac/dynamic_sparsity_pattern.h>
// We will want to use a special algorithm to renumber degrees of freedom. It
// is declared here:
// number, leading to a lot of wasted memory, sometimes too much for the
// machine used, even if the unused memory can be released immediately after
// computing the sparsity pattern. In order to avoid this, we use an
- // intermediate object of type CompressedSparsityPattern that uses a
+ // intermediate object of type DynamicSparsityPattern that uses a
// different %internal data structure and that we can later copy into the
// SparsityPattern object without much overhead. (Some more information on
// these data structures can be found in the @ref Sparsity module.) In order
// to initialize this intermediate data structure, we have to give it the
// size of the matrix, which in our case will be square with as many rows
// and columns as there are degrees of freedom on the grid:
- CompressedSparsityPattern compressed_sparsity_pattern(dof_handler.n_dofs(),
- dof_handler.n_dofs());
+ DynamicSparsityPattern compressed_sparsity_pattern(dof_handler.n_dofs(),
+ dof_handler.n_dofs());
// We then fill this object with the places where nonzero elements will be
// located given the present numbering of degrees of freedom:
// Now we are ready to create the actual sparsity pattern that we could
// later use for our matrix. It will just contain the data already assembled
- // in the CompressedSparsityPattern.
+ // in the DynamicSparsityPattern.
SparsityPattern sparsity_pattern;
sparsity_pattern.copy_from (compressed_sparsity_pattern);
{
DoFRenumbering::Cuthill_McKee (dof_handler);
- CompressedSparsityPattern compressed_sparsity_pattern(dof_handler.n_dofs(),
- dof_handler.n_dofs());
+ DynamicSparsityPattern compressed_sparsity_pattern(dof_handler.n_dofs(),
+ dof_handler.n_dofs());
DoFTools::make_sparsity_pattern (dof_handler, compressed_sparsity_pattern);
SparsityPattern sparsity_pattern;
// The next task is to allocate a sparsity pattern for the matrix that we
// will create. We use a compressed sparsity pattern like in the previous
// steps, but as <code>system_matrix</code> is a block matrix we use the
- // class <code>BlockCompressedSparsityPattern</code> instead of just
- // <code>CompressedSparsityPattern</code>. This block sparsity pattern has
+ // class <code>BlockDynamicSparsityPattern</code> instead of just
+ // <code>DynamicSparsityPattern</code>. This block sparsity pattern has
// four blocks in a $2 \times 2$ pattern. The blocks' sizes depend on
// <code>n_u</code> and <code>n_p</code>, which hold the number of velocity
// and pressure variables. In the second step we have to instruct the block
// system to update its knowledge about the sizes of the blocks it manages;
// this happens with the <code>c_sparsity.collect_sizes ()</code> call.
- BlockCompressedSparsityPattern c_sparsity(2, 2);
+ BlockDynamicSparsityPattern c_sparsity(2, 2);
c_sparsity.block(0, 0).reinit (n_u, n_u);
c_sparsity.block(1, 0).reinit (n_p, n_u);
c_sparsity.block(0, 1).reinit (n_u, n_p);
// BlockSparsityPattern. This is entirely analogous to what we already did
// in step-11 and step-18.
//
- // There is one snag again here, though: it turns out that using the
- // CompressedSparsityPattern (or the block version
- // BlockCompressedSparsityPattern we would use here) has a bottleneck that
- // makes the algorithm to build the sparsity pattern be quadratic in the
- // number of degrees of freedom. This doesn't become noticeable until we
- // get well into the range of several 100,000 degrees of freedom, but
- // eventually dominates the setup of the linear system when we get to more
- // than a million degrees of freedom. This is due to the data structures
- // used in the CompressedSparsityPattern class, nothing that can easily be
- // changed. Fortunately, there is an easy solution: the
- // CompressedSimpleSparsityPattern class (and its block variant
- // BlockCompressedSimpleSparsityPattern) has exactly the same interface,
- // uses a different %internal data structure and is linear in the number
- // of degrees of freedom and therefore much more efficient for large
- // problems. As another alternative, we could also have chosen the class
- // BlockCompressedSetSparsityPattern that uses yet another strategy for
- // %internal memory management. Though, that class turns out to be more
- // memory-demanding than BlockCompressedSimpleSparsityPattern for this
- // example.
- //
- // Consequently, this is the class that we will use for our intermediate
- // sparsity representation. All this is done inside a new scope, which
+ // All this is done inside a new scope, which
// means that the memory of <code>csp</code> will be released once the
// information has been copied to <code>sparsity_pattern</code>.
{
- BlockCompressedSimpleSparsityPattern csp (2,2);
+ BlockDynamicSparsityPattern csp (2,2);
csp.block(0,0).reinit (n_u, n_u);
csp.block(1,0).reinit (n_p, n_u);
#include <deal.II/lac/vector.h>
#include <deal.II/lac/full_matrix.h>
#include <deal.II/lac/sparse_matrix.h>
+#include <deal.II/lac/dynamic_sparsity_pattern.h>
#include <deal.II/lac/solver_cg.h>
#include <deal.II/lac/precondition.h>
#include <deal.II/lac/constraint_matrix.h>
<< std::endl
<< 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();
+ DynamicSparsityPattern csp(dof_handler.n_dofs(), dof_handler.n_dofs());
+ DoFTools::make_sparsity_pattern (dof_handler, csp);
+ sparsity_pattern.copy_from (csp);
// Then comes a block where we have to initialize the 3 matrices we need
// in the course of the program: the mass matrix, the Laplace matrix, and
#include <deal.II/lac/vector.h>
#include <deal.II/lac/full_matrix.h>
#include <deal.II/lac/sparse_matrix.h>
+#include <deal.II/lac/dynamic_sparsity_pattern.h>
#include <deal.II/lac/solver_cg.h>
#include <deal.II/lac/precondition.h>
#include <deal.II/lac/constraint_matrix.h>
<< std::endl
<< 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();
+ DynamicSparsityPattern csp(dof_handler.n_dofs(), dof_handler.n_dofs());
+ DoFTools::make_sparsity_pattern (dof_handler, csp);
+ sparsity_pattern.copy_from (csp);
system_matrix.reinit (sparsity_pattern);
mass_matrix.reinit (sparsity_pattern);
#include <deal.II/lac/vector.h>
#include <deal.II/lac/full_matrix.h>
#include <deal.II/lac/sparse_matrix.h>
+#include <deal.II/lac/dynamic_sparsity_pattern.h>
#include <deal.II/lac/solver_cg.h>
#include <deal.II/lac/precondition.h>
#include <deal.II/lac/constraint_matrix.h>
<< 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 ();
+ DynamicSparsityPattern csp(dof_handler.n_dofs(), dof_handler.n_dofs());
+ DoFTools::make_sparsity_pattern (dof_handler, csp);
+ sparsity_pattern.copy_from (csp);
system_matrix.reinit (sparsity_pattern);
mass_matrix.reinit (sparsity_pattern);
#include <deal.II/base/logstream.h>
#include <deal.II/lac/vector.h>
#include <deal.II/lac/full_matrix.h>
-#include <deal.II/lac/compressed_sparsity_pattern.h>
+#include <deal.II/lac/dynamic_sparsity_pattern.h>
#include <deal.II/lac/sparse_matrix.h>
#include <deal.II/lac/solver_cg.h>
#include <deal.II/lac/precondition.h>
constraints);
constraints.close();
- CompressedSparsityPattern c_sparsity(dof_handler.n_dofs());
+ DynamicSparsityPattern c_sparsity(dof_handler.n_dofs());
DoFTools::make_sparsity_pattern(dof_handler,
c_sparsity,
constraints,
#include <deal.II/numerics/error_estimator.h>
// These are the new files we need. The first one provides an alternative to
-// the usual SparsityPattern class and the CompressedSparsityPattern class
+// the usual SparsityPattern class and the DynamicSparsityPattern class
// already discussed in step-11 and step-18. The last two provide <i>hp</i>
// versions of the DoFHandler and FEValues classes as described in the
// introduction of this program.
-#include <deal.II/lac/compressed_set_sparsity_pattern.h>
+#include <deal.II/lac/dynamic_sparsity_pattern.h>
#include <deal.II/hp/dof_handler.h>
#include <deal.II/hp/fe_values.h>
constraints);
constraints.close ();
- CompressedSetSparsityPattern csp (dof_handler.n_dofs(),
- dof_handler.n_dofs());
+ DynamicSparsityPattern csp (dof_handler.n_dofs(),
+ dof_handler.n_dofs());
DoFTools::make_sparsity_pattern (dof_handler, csp, constraints, false);
sparsity_pattern.copy_from (csp);
#include <deal.II/lac/vector.h>
#include <deal.II/lac/full_matrix.h>
#include <deal.II/lac/sparsity_pattern.h>
+#include <deal.II/lac/dynamic_sparsity_pattern.h>
#include <deal.II/lac/sparse_matrix.h>
#include <deal.II/lac/solver_cg.h>
#include <deal.II/lac/precondition.h>
system_matrix.clear ();
- sparsity_pattern.reinit (n_dofs, n_dofs,
- dof_handler.max_couplings_between_dofs());
- DoFTools::make_sparsity_pattern (dof_handler, sparsity_pattern);
- hanging_node_constraints.condense (sparsity_pattern);
- sparsity_pattern.compress ();
+ DynamicSparsityPattern csp(n_dofs, n_dofs);
+ DoFTools::make_sparsity_pattern (dof_handler, csp);
+ hanging_node_constraints.condense (csp);
+ sparsity_pattern.copy_from (csp);
system_matrix.reinit (sparsity_pattern);
#include <deal.II/lac/vector.h>
#include <deal.II/lac/full_matrix.h>
#include <deal.II/lac/sparse_matrix.h>
+#include <deal.II/lac/dynamic_sparsity_pattern.h>
#include <deal.II/grid/tria.h>
#include <deal.II/grid/grid_generator.h>
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);
- sparsity_pattern.compress();
+ DynamicSparsityPattern csp(dof_handler.n_dofs(), dof_handler.n_dofs());
+ DoFTools::make_sparsity_pattern (dof_handler, csp);
+ sparsity_pattern.copy_from (csp);
system_matrix.reinit (sparsity_pattern);
system_rhs.reinit (dof_handler.n_dofs());
#include <deal.II/lac/vector.h>
#include <deal.II/lac/full_matrix.h>
#include <deal.II/lac/sparse_matrix.h>
-#include <deal.II/lac/compressed_sparsity_pattern.h>
+#include <deal.II/lac/dynamic_sparsity_pattern.h>
#include <deal.II/lac/solver_cg.h>
#include <deal.II/lac/precondition.h>
// first creating a temporary structure, tagging those entries that might be
// nonzero, and then copying the data over to the SparsityPattern object
// that can then be used by the system matrix.
- CompressedSparsityPattern c_sparsity(dof_handler.n_dofs());
+ DynamicSparsityPattern c_sparsity(dof_handler.n_dofs());
DoFTools::make_sparsity_pattern (dof_handler, c_sparsity);
sparsity_pattern.copy_from(c_sparsity);
// The next step is to create the sparsity pattern for the Stokes and
// temperature system matrices as well as the preconditioner matrix from
// which we build the Stokes preconditioner. As in step-22, we choose to
- // create the pattern not as in the first few tutorial programs, but by
- // using the blocked version of CompressedSimpleSparsityPattern. The
- // reason for doing this is mainly memory, that is, the SparsityPattern
- // class would consume too much memory when used in three spatial
- // dimensions as we intend to do for this program.
+ // create the pattern by
+ // using the blocked version of DynamicSparsityPattern.
//
// So, we first release the memory stored in the matrices, then set up an
- // object of type BlockCompressedSimpleSparsityPattern consisting of
+ // object of type BlockDynamicSparsityPattern consisting of
// $2\times 2$ blocks (for the Stokes system matrix and preconditioner) or
- // CompressedSimpleSparsityPattern (for the temperature part). We then
+ // DynamicSparsityPattern (for the temperature part). We then
// fill these objects with the nonzero pattern, taking into account that
// for the Stokes system matrix, there are no entries in the
// pressure-pressure block (but all velocity vector components couple with
{
stokes_matrix.clear ();
- BlockCompressedSimpleSparsityPattern csp (2,2);
+ BlockDynamicSparsityPattern csp (2,2);
csp.block(0,0).reinit (n_u, n_u);
csp.block(0,1).reinit (n_u, n_p);
Mp_preconditioner.reset ();
stokes_preconditioner_matrix.clear ();
- BlockCompressedSimpleSparsityPattern csp (2,2);
+ BlockDynamicSparsityPattern csp (2,2);
csp.block(0,0).reinit (n_u, n_u);
csp.block(0,1).reinit (n_u, n_p);
temperature_stiffness_matrix.clear ();
temperature_matrix.clear ();
- CompressedSimpleSparsityPattern csp (n_T, n_T);
+ DynamicSparsityPattern csp (n_T, n_T);
DoFTools::make_sparsity_pattern (temperature_dof_handler, csp,
temperature_constraints, false);
// is that the matrices we want to set up are distributed across multiple
// processors. Since we still want to build up the sparsity pattern first
// for efficiency reasons, we could continue to build the <i>entire</i>
- // sparsity pattern as a BlockCompressedSimpleSparsityPattern, as we did in
+ // sparsity pattern as a BlockDynamicSparsityPattern, as we did in
// step-31. However, that would be inefficient: every processor would build
// the same sparsity pattern, but only initialize a small part of the matrix
// using it. It also violates the principle that every processor should only
#include <deal.II/base/std_cxx11/array.h>
#include <deal.II/lac/vector.h>
-#include <deal.II/lac/compressed_sparsity_pattern.h>
+#include <deal.II/lac/dynamic_sparsity_pattern.h>
#include <deal.II/grid/tria.h>
#include <deal.II/grid/grid_generator.h>
template <int dim>
void ConservationLaw<dim>::setup_system ()
{
- CompressedSparsityPattern sparsity_pattern (dof_handler.n_dofs(),
- dof_handler.n_dofs());
+ DynamicSparsityPattern sparsity_pattern (dof_handler.n_dofs(),
+ dof_handler.n_dofs());
DoFTools::make_sparsity_pattern (dof_handler, sparsity_pattern);
system_matrix.reinit (sparsity_pattern);
#include <deal.II/lac/vector.h>
#include <deal.II/lac/sparse_matrix.h>
+#include <deal.II/lac/dynamic_sparsity_pattern.h>
#include <deal.II/lac/solver_cg.h>
#include <deal.II/lac/precondition.h>
#include <deal.II/lac/solver_gmres.h>
void
NavierStokesProjection<dim>::initialize_velocity_matrices()
{
- sparsity_pattern_velocity.reinit (dof_handler_velocity.n_dofs(),
- dof_handler_velocity.n_dofs(),
- dof_handler_velocity.max_couplings_between_dofs());
- DoFTools::make_sparsity_pattern (dof_handler_velocity,
- sparsity_pattern_velocity);
- sparsity_pattern_velocity.compress();
-
+ {
+ DynamicSparsityPattern csp(dof_handler_velocity.n_dofs(), dof_handler_velocity.n_dofs());
+ DoFTools::make_sparsity_pattern (dof_handler_velocity, csp);
+ sparsity_pattern_velocity.copy_from (csp);
+ }
vel_Laplace_plus_Mass.reinit (sparsity_pattern_velocity);
for (unsigned int d=0; d<dim; ++d)
vel_it_matrix[d].reinit (sparsity_pattern_velocity);
void
NavierStokesProjection<dim>::initialize_pressure_matrices()
{
- sparsity_pattern_pressure.reinit (dof_handler_pressure.n_dofs(), dof_handler_pressure.n_dofs(),
- dof_handler_pressure.max_couplings_between_dofs());
- DoFTools::make_sparsity_pattern (dof_handler_pressure, sparsity_pattern_pressure);
-
- sparsity_pattern_pressure.compress();
+ {
+ DynamicSparsityPattern csp(dof_handler_pressure.n_dofs(), dof_handler_pressure.n_dofs());
+ DoFTools::make_sparsity_pattern (dof_handler_pressure, csp);
+ sparsity_pattern_pressure.copy_from (csp);
+ }
pres_Laplace.reinit (sparsity_pattern_pressure);
pres_iterative.reinit (sparsity_pattern_pressure);
void
NavierStokesProjection<dim>::initialize_gradient_operator()
{
- sparsity_pattern_pres_vel.reinit (dof_handler_velocity.n_dofs(),
- dof_handler_pressure.n_dofs(),
- dof_handler_velocity.max_couplings_between_dofs());
- DoFTools::make_sparsity_pattern (dof_handler_velocity,
- dof_handler_pressure,
- sparsity_pattern_pres_vel);
- sparsity_pattern_pres_vel.compress();
+ {
+ DynamicSparsityPattern csp(dof_handler_velocity.n_dofs(), dof_handler_pressure.n_dofs());
+ DoFTools::make_sparsity_pattern (dof_handler_velocity, dof_handler_pressure, csp);
+ sparsity_pattern_pres_vel.copy_from (csp);
+ }
InitGradPerTaskData per_task_data (0, fe_velocity.dofs_per_cell,
fe_pressure.dofs_per_cell);
// sure that we do not need to re-allocate memory and free the one used
// previously. One way to do that would be to use code like this:
// @code
- // CompressedSimpleSparsityPattern
+ // DynamicSparsityPattern
// csp (dof_handler.n_dofs(),
// dof_handler.n_dofs());
// DoFTools::make_sparsity_pattern (dof_handler, csp);
#include <deal.II/lac/solver_cg.h>
#include <deal.II/lac/precondition.h>
#include <deal.II/lac/sparse_matrix.h>
-#include <deal.II/lac/compressed_sparsity_pattern.h>
+#include <deal.II/lac/dynamic_sparsity_pattern.h>
#include <deal.II/dofs/dof_handler.h>
#include <deal.II/dofs/dof_accessor.h>
#include <deal.II/dofs/dof_tools.h>
<< " degrees of freedom."
<< std::endl;
- CompressedSparsityPattern csp (dof_handler.n_dofs(), dof_handler.n_dofs());
+ DynamicSparsityPattern csp (dof_handler.n_dofs(), dof_handler.n_dofs());
DoFTools::make_sparsity_pattern (dof_handler, csp);
sparsity_pattern.copy_from (csp);
// turn will include the necessary files for SparsityPattern and Vector
// classes.
#include <deal.II/lac/sparse_matrix.h>
-#include <deal.II/lac/compressed_sparsity_pattern.h>
+#include <deal.II/lac/dynamic_sparsity_pattern.h>
#include <deal.II/lac/solver_cg.h>
#include <deal.II/lac/precondition.h>
#include <deal.II/lac/precondition_block.h>
// Next, we set up the sparsity pattern for the global matrix. Since we do
// not know the row sizes in advance, we first fill a temporary
- // CompressedSparsityPattern object and copy it to the regular
+ // DynamicSparsityPattern object and copy it to the regular
// SparsityPattern once it is complete.
- CompressedSparsityPattern c_sparsity(n_dofs);
+ DynamicSparsityPattern c_sparsity(n_dofs);
DoFTools::make_flux_sparsity_pattern(dof_handler, c_sparsity);
sparsity.copy_from(c_sparsity);
matrix.reinit(sparsity);
{
// These are roughly the same lines as above for the global matrix,
// now for each level.
- CompressedSparsityPattern c_sparsity(dof_handler.n_dofs(level));
+ DynamicSparsityPattern c_sparsity(dof_handler.n_dofs(level));
MGTools::make_flux_sparsity_pattern(dof_handler, c_sparsity, level);
mg_sparsity[level].copy_from(c_sparsity);
mg_matrix[level].reinit(mg_sparsity[level]);
// object on level 0.
if (level>0)
{
- CompressedSparsityPattern ci_sparsity;
+ DynamicSparsityPattern ci_sparsity;
ci_sparsity.reinit(dof_handler.n_dofs(level-1), dof_handler.n_dofs(level));
MGTools::make_flux_sparsity_pattern_edge(dof_handler, ci_sparsity, level);
mg_sparsity_dg_interface[level].copy_from(ci_sparsity);
#include <deal.II/lac/vector.h>
#include <deal.II/lac/full_matrix.h>
#include <deal.II/lac/sparse_matrix.h>
-#include <deal.II/lac/compressed_sparsity_pattern.h>
+#include <deal.II/lac/dynamic_sparsity_pattern.h>
#include <deal.II/lac/solver_cg.h>
#include <deal.II/lac/precondition.h>
<< dof_handler.n_dofs()
<< std::endl;
- CompressedSparsityPattern c_sparsity(dof_handler.n_dofs());
+ DynamicSparsityPattern c_sparsity(dof_handler.n_dofs());
DoFTools::make_sparsity_pattern (dof_handler, c_sparsity);
sparsity_pattern.copy_from(c_sparsity);
#include <deal.II/lac/full_matrix.h>
#include <deal.II/lac/solver_cg.h>
#include <deal.II/lac/constraint_matrix.h>
-#include <deal.II/lac/compressed_simple_sparsity_pattern.h>
+#include <deal.II/lac/dynamic_sparsity_pattern.h>
#include <deal.II/lac/petsc_parallel_sparse_matrix.h>
#include <deal.II/lac/petsc_parallel_vector.h>
// The last part of this function deals with initializing the matrix with
// accompanying sparsity pattern. As in previous tutorial programs, we use
- // the CompressedSimpleSparsityPattern as an intermediate with which we
+ // the DynamicSparsityPattern as an intermediate with which we
// then initialize the PETSc matrix. To do so we have to tell the sparsity
// pattern its size but as above there is no way the resulting object will
// be able to store even a single pointer for each global degree of
// entries that will exist in that part of the finite element matrix that
// it will own. The final step is to initialize the matrix with the
// sparsity pattern.
- CompressedSimpleSparsityPattern csp (locally_relevant_dofs);
+ DynamicSparsityPattern csp (locally_relevant_dofs);
DoFTools::make_sparsity_pattern (dof_handler, csp,
constraints, false);
#include <deal.II/lac/vector.h>
#include <deal.II/lac/full_matrix.h>
-#include <deal.II/lac/compressed_sparsity_pattern.h>
+#include <deal.II/lac/dynamic_sparsity_pattern.h>
#include <deal.II/lac/solver_cg.h>
#include <deal.II/lac/trilinos_sparse_matrix.h>
#include <deal.II/lac/trilinos_vector.h>
constraints);
constraints.close ();
- CompressedSparsityPattern c_sparsity(dof_handler.n_dofs());
+ DynamicSparsityPattern c_sparsity(dof_handler.n_dofs());
DoFTools::make_sparsity_pattern (dof_handler,
c_sparsity,
constraints,
// various blocks. This information is then used to create the sparsity
// pattern for the Darcy and saturation system matrices as well as the
// preconditioner matrix from which we build the Darcy preconditioner. As in
- // step-31, we choose to create the pattern not as in the first few tutorial
- // programs, but by using the blocked version of
- // CompressedSimpleSparsityPattern. The reason for doing this is mainly
- // memory, that is, the SparsityPattern class would consume too much memory
- // when used in three spatial dimensions as we intend to do for this
- // program. So, for this, we follow the same way as step-31 did and we don't
- // have to repeat descriptions again for the rest of the member function.
+ // step-31, we choose to create the pattern using the blocked version of
+ // DynamicSparsityPattern. So, for this, we follow the same way as step-31
+ // did and we don't have to repeat descriptions again for the rest of the
+ // member function.
template <int dim>
void TwoPhaseFlowProblem<dim>::setup_dofs ()
{
{
darcy_matrix.clear ();
- BlockCompressedSimpleSparsityPattern csp (2,2);
+ BlockDynamicSparsityPattern csp (2,2);
csp.block(0,0).reinit (n_u, n_u);
csp.block(0,1).reinit (n_u, n_p);
Mp_preconditioner.reset ();
darcy_preconditioner_matrix.clear ();
- BlockCompressedSimpleSparsityPattern csp (2,2);
+ BlockDynamicSparsityPattern csp (2,2);
csp.block(0,0).reinit (n_u, n_u);
csp.block(0,1).reinit (n_u, n_p);
{
saturation_matrix.clear ();
- CompressedSimpleSparsityPattern csp (n_s, n_s);
+ DynamicSparsityPattern csp (n_s, n_s);
DoFTools::make_sparsity_pattern (saturation_dof_handler, csp,
saturation_constraints, false);
#include <deal.II/lac/block_sparse_matrix.h>
#include <deal.II/lac/block_vector.h>
-#include <deal.II/lac/compressed_sparsity_pattern.h>
+#include <deal.II/lac/dynamic_sparsity_pattern.h>
#include <deal.II/lac/full_matrix.h>
#include <deal.II/lac/precondition_selector.h>
#include <deal.II/lac/solver_cg.h>
const types::global_dof_index n_dofs_p = dofs_per_block[p_dof];
const types::global_dof_index n_dofs_J = dofs_per_block[J_dof];
- BlockCompressedSimpleSparsityPattern csp(n_blocks, n_blocks);
+ BlockDynamicSparsityPattern csp(n_blocks, n_blocks);
csp.block(u_dof, u_dof).reinit(n_dofs_u, n_dofs_u);
csp.block(u_dof, p_dof).reinit(n_dofs_u, n_dofs_p);
#include <deal.II/lac/solver_control.h>
#include <deal.II/lac/sparse_matrix.h>
#include <deal.II/lac/sparsity_pattern.h>
-#include <deal.II/lac/compressed_sparsity_pattern.h>
+#include <deal.II/lac/dynamic_sparsity_pattern.h>
#include <deal.II/grid/grid_generator.h>
#include <deal.II/grid/tria.h>
// Then we create the sparsity pattern and the system matrix and
// initialize the solution and right-hand side vectors. This is again as
// in step-3 or step-6, for example:
- CompressedSparsityPattern c_sparsity_pattern (dof_handler.n_dofs(),
- dof_handler.n_dofs());
+ DynamicSparsityPattern c_sparsity_pattern (dof_handler.n_dofs(),
+ dof_handler.n_dofs());
DoFTools::make_sparsity_pattern (dof_handler,
c_sparsity_pattern,
constraints,
// extensively in the introduction, and use it to initialize the matrix;
// then also set vectors to their correct sizes:
{
- CompressedSimpleSparsityPattern csp (dof_handler.n_dofs(),
- dof_handler.n_dofs());
+ DynamicSparsityPattern csp (dof_handler.n_dofs(),
+ dof_handler.n_dofs());
Table<2,DoFTools::Coupling> cell_coupling (fe_collection.n_components(),
fe_collection.n_components());
#include <deal.II/lac/vector.h>
#include <deal.II/lac/full_matrix.h>
#include <deal.II/lac/sparse_matrix.h>
-#include <deal.II/lac/compressed_sparsity_pattern.h>
+#include <deal.II/lac/dynamic_sparsity_pattern.h>
#include <deal.II/lac/solver_cg.h>
#include <deal.II/lac/precondition.h>
#include <deal.II/grid/tria.h>
constraints.close();
- CompressedSparsityPattern c_sparsity(dof_handler.n_dofs());
+ DynamicSparsityPattern c_sparsity(dof_handler.n_dofs());
DoFTools::make_sparsity_pattern (dof_handler, c_sparsity);
constraints.condense (c_sparsity);
#include <deal.II/lac/vector.h>
#include <deal.II/lac/full_matrix.h>
#include <deal.II/lac/sparse_matrix.h>
-#include <deal.II/lac/compressed_sparsity_pattern.h>
+#include <deal.II/lac/dynamic_sparsity_pattern.h>
#include <deal.II/lac/solver_cg.h>
#include <deal.II/lac/precondition.h>
#include <deal.II/grid/tria.h>
<< dof_handler.n_dofs()
<< std::endl;
- CompressedSparsityPattern c_sparsity(dof_handler.n_dofs());
+ DynamicSparsityPattern c_sparsity(dof_handler.n_dofs());
DoFTools::make_sparsity_pattern (dof_handler, c_sparsity);
sparsity_pattern.copy_from(c_sparsity);
constraints.close ();
hanging_node_constraints.close ();
- CompressedSimpleSparsityPattern csp(mg_dof_handler.n_dofs(), mg_dof_handler.n_dofs());
+ DynamicSparsityPattern csp(mg_dof_handler.n_dofs(), mg_dof_handler.n_dofs());
DoFTools::make_sparsity_pattern (mg_dof_handler, csp, constraints);
system_matrix.reinit (mg_dof_handler.locally_owned_dofs(), csp, MPI_COMM_WORLD, true);
// matrices.
for (unsigned int level=0; level<n_levels; ++level)
{
- CompressedSparsityPattern csp;
- csp.reinit(mg_dof_handler.n_dofs(level),
- mg_dof_handler.n_dofs(level));
+ DynamicSparsityPattern csp(mg_dof_handler.n_dofs(level),
+ mg_dof_handler.n_dofs(level));
MGTools::make_sparsity_pattern(mg_dof_handler, csp, level);
mg_matrices[level].reinit(mg_dof_handler.locally_owned_mg_dofs(level),
#include <deal.II/base/convergence_table.h>
#include <deal.II/lac/vector.h>
#include <deal.II/lac/full_matrix.h>
-#include <deal.II/lac/compressed_simple_sparsity_pattern.h>
+#include <deal.II/lac/dynamic_sparsity_pattern.h>
#include <deal.II/lac/solver_bicgstab.h>
#include <deal.II/lac/precondition.h>
#include <deal.II/grid/tria.h>
// to the number of dofs on a face, when copying this into the final
// sparsity pattern.
{
- CompressedSimpleSparsityPattern csp (dof_handler.n_dofs());
+ DynamicSparsityPattern csp (dof_handler.n_dofs());
DoFTools::make_sparsity_pattern (dof_handler, csp,
constraints, false);
sparsity_pattern.copy_from(csp, fe.dofs_per_face);
VectorTools::interpolate_boundary_values(dof_handler,1,ZeroFunction<2>(),constraint_matrix);
constraint_matrix.close();
- CompressedSparsityPattern c_sparsity(dof_handler.n_dofs());
+ DynamicSparsityPattern c_sparsity(dof_handler.n_dofs());
DoFTools::make_sparsity_pattern(dof_handler,c_sparsity,constraint_matrix);
sparsity_pattern.copy_from(c_sparsity);
#include <deal.II/lac/vector.h>
#include <deal.II/lac/full_matrix.h>
#include <deal.II/lac/sparse_matrix.h>
-#include <deal.II/lac/compressed_sparsity_pattern.h>
+#include <deal.II/lac/dynamic_sparsity_pattern.h>
#include <deal.II/lac/solver_cg.h>
#include <deal.II/lac/precondition.h>
#include <deal.II/grid/tria.h>
// sparsity pattern, and initializing the solution and right hand side
// vectors. Note that the sparsity pattern will have significantly more
// entries per row now, since there are now 9 degrees of freedom per cell, not
-// only four, that can couple with each other. The
-// <code>dof_Handler.max_couplings_between_dofs()</code> call will take care
-// of this, however:
+// only four, that can couple with each other.
template <int dim>
void Step6<dim>::setup_system ()
{
// constraints after assembling, we would have to pass <code>true</code>
// instead because then we would first write into these locations only to
// later set them to zero again during condensation.
- CompressedSparsityPattern c_sparsity(dof_handler.n_dofs());
+ DynamicSparsityPattern c_sparsity(dof_handler.n_dofs());
DoFTools::make_sparsity_pattern(dof_handler,
c_sparsity,
constraints,
#include <deal.II/lac/vector.h>
#include <deal.II/lac/full_matrix.h>
#include <deal.II/lac/sparse_matrix.h>
+#include <deal.II/lac/dynamic_sparsity_pattern.h>
#include <deal.II/lac/solver_cg.h>
#include <deal.II/lac/precondition.h>
#include <deal.II/lac/constraint_matrix.h>
hanging_node_constraints);
hanging_node_constraints.close ();
- 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);
- hanging_node_constraints.condense (sparsity_pattern);
- sparsity_pattern.compress();
+ DynamicSparsityPattern csp (dof_handler.n_dofs(), dof_handler.n_dofs());
+ DoFTools::make_sparsity_pattern (dof_handler, csp);
+ hanging_node_constraints.condense (csp);
+ sparsity_pattern.copy_from (csp);
system_matrix.reinit (sparsity_pattern);
#include <deal.II/lac/vector.h>
#include <deal.II/lac/full_matrix.h>
#include <deal.II/lac/sparse_matrix.h>
+#include <deal.II/lac/dynamic_sparsity_pattern.h>
#include <deal.II/lac/solver_cg.h>
#include <deal.II/lac/precondition.h>
#include <deal.II/lac/constraint_matrix.h>
DoFTools::make_hanging_node_constraints (dof_handler,
hanging_node_constraints);
hanging_node_constraints.close ();
- 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);
- hanging_node_constraints.condense (sparsity_pattern);
-
- sparsity_pattern.compress();
+ DynamicSparsityPattern csp(dof_handler.n_dofs(), dof_handler.n_dofs());
+ DoFTools::make_sparsity_pattern(dof_handler,
+ csp,
+ hanging_node_constraints,
+ /*keep_constrained_dofs = */ true);
+ sparsity_pattern.copy_from (csp);
system_matrix.reinit (sparsity_pattern);
#include <deal.II/lac/vector.h>
#include <deal.II/lac/full_matrix.h>
#include <deal.II/lac/sparse_matrix.h>
+#include <deal.II/lac/dynamic_sparsity_pattern.h>
#include <deal.II/lac/solver_bicgstab.h>
#include <deal.II/lac/precondition.h>
#include <deal.II/lac/constraint_matrix.h>
void AdvectionProblem<dim>::setup_system ()
{
dof_handler.distribute_dofs (fe);
-
hanging_node_constraints.clear ();
DoFTools::make_hanging_node_constraints (dof_handler,
hanging_node_constraints);
hanging_node_constraints.close ();
- 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);
-
- hanging_node_constraints.condense (sparsity_pattern);
-
- sparsity_pattern.compress();
+ DynamicSparsityPattern csp(dof_handler.n_dofs(), dof_handler.n_dofs());
+ DoFTools::make_sparsity_pattern(dof_handler,
+ csp,
+ hanging_node_constraints,
+ /*keep_constrained_dofs = */ true);
+ sparsity_pattern.copy_from (csp);
system_matrix.reinit (sparsity_pattern);
template <typename number> class BlockSparseMatrix;
class BlockSparsityPattern;
-class BlockCompressedSparsityPattern;
-class BlockCompressedSimpleSparsityPattern;
-class BlockCompressedSetSparsityPattern;
+class BlockDynamicSparsityPattern;
#ifdef DEAL_II_WITH_TRILINOS
namespace TrilinosWrappers
{
std::size_t memory_consumption () const;
/**
- * Copy data from an object of type BlockCompressedSparsityPattern, i.e.
+ * Copy data from an object of type BlockDynamicSparsityPattern, i.e.
* resize this object to the size of the given argument, and copy over the
* contents of each of the subobjects. Previous content of this object is
* lost.
*/
- void copy_from (const BlockCompressedSparsityPattern &csp);
-
- /**
- * Copy data from an object of type BlockCompressedSetSparsityPattern, i.e.
- * resize this object to the size of the given argument, and copy over the
- * contents of each of the subobjects. Previous content of this object is
- * lost.
- */
- void copy_from (const BlockCompressedSetSparsityPattern &csp);
-
- /**
- * Copy data from an object of type BlockCompressedSimpleSparsityPattern,
- * i.e. resize this object to the size of the given argument, and copy over
- * the contents of each of the subobjects. Previous content of this object
- * is lost.
- */
- void copy_from (const BlockCompressedSimpleSparsityPattern &csp);
-
-
-
+ void copy_from (const BlockDynamicSparsityPattern &csp);
};
* This class is an example of the "dynamic" type of
* @ref Sparsity.
*
- * <b>Note:</b> There are several, exchangeable variations of this class, see
- * @ref Sparsity,
- * section 'Dynamic block sparsity patterns' for more information.
- *
- *
* <h3>Example</h3>
*
- * Usage of this class is very similar to CompressedSparsityPattern, but since
+ * Usage of this class is very similar to DynamicSparsityPattern, but since
* the use of block indices causes some additional complications, we give a
* short example.
*
*
* @skipline dofs_per_block @until count
*
- * Now, we are ready to set up the BlockCompressedSparsityPattern.
+ * Now, we are ready to set up the BlockDynamicSparsityPattern.
*
* @until collect
*
*
* @author Wolfgang Bangerth, 2000, 2001, Guido Kanschat, 2006, 2007
*/
-class BlockCompressedSparsityPattern : public BlockSparsityPatternBase<CompressedSparsityPattern>
-{
-public:
-
- /**
- * Initialize the matrix empty, that is with no memory allocated. This is
- * useful if you want such objects as member variables in other classes. You
- * can make the structure usable by calling the reinit() function.
- */
- BlockCompressedSparsityPattern ();
- /**
- * Initialize the matrix with the given number of block rows and columns.
- * The blocks themselves are still empty, and you have to call
- * collect_sizes() after you assign them sizes.
- */
- BlockCompressedSparsityPattern (const size_type n_rows,
- const size_type n_columns);
-
- /**
- * Initialize the pattern with two BlockIndices for the block structures of
- * matrix rows and columns. This function is equivalent to calling the
- * previous constructor with the length of the two index vector and then
- * entering the index values.
- */
- BlockCompressedSparsityPattern (const std::vector<size_type> &row_block_sizes,
- const std::vector<size_type> &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 dimensions defined
- * by the arguments.
- *
- * The matrix will have as many block rows and columns as there are entries
- * in the two arguments. The block at position (<i>i,j</i>) will have the
- * dimensions <tt>row_block_sizes[i]</tt> times <tt>col_block_sizes[j]</tt>.
- */
- void reinit (const std::vector<size_type> &row_block_sizes,
- const std::vector<size_type> &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 well.
- */
- using BlockSparsityPatternBase<CompressedSparsityPattern>::reinit;
-};
-
-
-
-/**
- * This class extends the base class to implement an array of compressed
- * sparsity patterns that can be used to initialize objects of type
- * BlockSparsityPattern. It is used in the same way as the
- * BlockCompressedSparsityPattern except that it builds upon the
- * CompressedSetSparsityPattern instead of the CompressedSparsityPattern. See
- * the documentation of the BlockCompressedSparsityPattern for examples.
- *
- * This class is an example of the "dynamic" type of
- * @ref Sparsity.
- *
- * @note There are several, exchangeable variations of this class, see
- * @ref Sparsity,
- * section 'Dynamic block sparsity patterns' for more information.
- *
- * @author Wolfgang Bangerth, 2007
- */
-class BlockCompressedSetSparsityPattern : public BlockSparsityPatternBase<CompressedSetSparsityPattern>
+class BlockDynamicSparsityPattern : public BlockSparsityPatternBase<DynamicSparsityPattern>
{
public:
* useful if you want such objects as member variables in other classes. You
* can make the structure usable by calling the reinit() function.
*/
- BlockCompressedSetSparsityPattern ();
+ BlockDynamicSparsityPattern ();
/**
* Initialize the matrix with the given number of block rows and columns.
* The blocks themselves are still empty, and you have to call
* collect_sizes() after you assign them sizes.
*/
- BlockCompressedSetSparsityPattern (const size_type n_rows,
- const size_type n_columns);
+ BlockDynamicSparsityPattern (const size_type n_rows,
+ const size_type n_columns);
/**
* Initialize the pattern with two BlockIndices for the block structures of
* previous constructor with the length of the two index vector and then
* entering the index values.
*/
- BlockCompressedSetSparsityPattern (const std::vector<size_type> &row_block_sizes,
- const std::vector<size_type> &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 product of matrices with dimensions defined
- * by the arguments.
- *
- * The matrix will have as many block rows and columns as there are entries
- * in the two arguments. The block at position (<i>i,j</i>) will have the
- * dimensions <tt>row_block_sizes[i]</tt> times <tt>col_block_sizes[j]</tt>.
- */
- void reinit (const std::vector<size_type> &row_block_sizes,
- const std::vector<size_type> &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 well.
- */
- using BlockSparsityPatternBase<CompressedSetSparsityPattern>::reinit;
-};
-
-
-
-
-
-/**
- * This class extends the base class to implement an array of compressed
- * sparsity patterns that can be used to initialize objects of type
- * BlockSparsityPattern. It is used in the same way as the
- * BlockCompressedSparsityPattern except that it builds upon the
- * CompressedSimpleSparsityPattern instead of the CompressedSparsityPattern.
- * See the documentation of the BlockCompressedSparsityPattern for examples.
- *
- * This class is an example of the "dynamic" type of
- * @ref Sparsity.
- *
- * @note There are several, exchangeable variations of this class, see
- * @ref Sparsity,
- * section 'Dynamic block sparsity patterns' for more information.
- *
- * This class is used in step-22 and step-31.
- *
- * @author Timo Heister, 2008
- */
-class BlockCompressedSimpleSparsityPattern : public BlockSparsityPatternBase<CompressedSimpleSparsityPattern>
-{
-public:
-
- /**
- * Initialize the matrix empty, that is with no memory allocated. This is
- * useful if you want such objects as member variables in other classes. You
- * can make the structure usable by calling the reinit() function.
- */
- BlockCompressedSimpleSparsityPattern ();
-
- /**
- * Initialize the matrix with the given number of block rows and columns.
- * The blocks themselves are still empty, and you have to call
- * collect_sizes() after you assign them sizes.
- */
- BlockCompressedSimpleSparsityPattern (const size_type n_rows,
- const size_type n_columns);
-
- /**
- * Initialize the pattern with two BlockIndices for the block structures of
- * matrix rows and columns. This function is equivalent to calling the
- * previous constructor with the length of the two index vector and then
- * entering the index values.
- */
- BlockCompressedSimpleSparsityPattern (const std::vector<size_type> &row_block_sizes,
- const std::vector<size_type> &col_block_sizes);
+ BlockDynamicSparsityPattern (const std::vector<size_type> &row_block_sizes,
+ const std::vector<size_type> &col_block_sizes);
/**
* Initialize the pattern with symmetric blocks. The number of IndexSets in
* which is useful for distributed memory parallel computations and usually
* corresponds to the locally owned DoFs.
*/
- BlockCompressedSimpleSparsityPattern (const std::vector<IndexSet> &partitioning);
+ BlockDynamicSparsityPattern (const std::vector<IndexSet> &partitioning);
/**
* Resize the pattern to a tensor product of matrices with dimensions
/**
* Allow the use of the reinit functions of the base class as well.
*/
- using BlockSparsityPatternBase<CompressedSimpleSparsityPattern>::reinit;
+ using BlockSparsityPatternBase<DynamicSparsityPattern>::reinit;
};
+/**
+ * @deprecated Use BlockDynamicSparsityPattern instead.
+ */
+typedef BlockDynamicSparsityPattern BlockCompressedSparsityPattern DEAL_II_DEPRECATED;
+
+/**
+ * @deprecated Use BlockDynamicSparsityPattern instead.
+ */
+typedef BlockDynamicSparsityPattern BlockCompressedSetSparsityPattern DEAL_II_DEPRECATED;
+
+/**
+ * @deprecated Use BlockDynamicSparsityPattern instead.
+ */
+typedef BlockDynamicSparsityPattern BlockCompressedSimpleSparsityPattern DEAL_II_DEPRECATED;
+
inline
-BlockCompressedSimpleSparsityPattern::size_type
-BlockCompressedSimpleSparsityPattern::column_number (const size_type row,
- const unsigned int index) const
+BlockDynamicSparsityPattern::size_type
+BlockDynamicSparsityPattern::column_number (const size_type row,
+ const unsigned int index) const
{
// .first= ith block, .second = jth row in that block
const std::pair<size_type ,size_type >
// ---------------------------------------------------------------------
//
-// Copyright (C) 2001 - 2014 by the deal.II authors
+// Copyright (C) 2001 - 2015 by the deal.II authors
//
// This file is part of the deal.II library.
//
#include <deal.II/base/config.h>
-#include <deal.II/base/subscriptor.h>
-#include <deal.II/lac/exceptions.h>
-
-#include <vector>
-#include <algorithm>
-#include <set>
+#include <deal.II/lac/dynamic_sparsity_pattern.h>
DEAL_II_NAMESPACE_OPEN
-template <typename number> class SparseMatrix;
-
/*! @addtogroup Sparsity
*@{
*/
-
/**
- * This class acts as an intermediate form of the SparsityPattern class. From
- * the interface it mostly represents a SparsityPattern object that is kept
- * compressed at all times. However, since the final sparsity pattern is not
- * known while constructing it, keeping the pattern compressed at all times
- * can only be achieved at the expense of either increased memory or run time
- * consumption upon use. The main purpose of this class is to avoid some
- * memory bottlenecks, so we chose to implement it memory conservative, but
- * the chosen data format is too unsuited to be used for actual matrices. It
- * is therefore necessary to first copy the data of this object over to an
- * object of type SparsityPattern before using it in actual matrices.
- *
- * Another viewpoint is that this class does not need up front allocation of a
- * certain amount of memory, but grows as necessary. An extensive description
- * of sparsity patterns can be found in the documentation of the
- * @ref Sparsity
- * module.
- *
- * This class is an example of the "dynamic" type of
- * @ref Sparsity.
- * It is discussed in the step-27 and
- * @ref step_22 "step-22"
- * tutorial programs.
- *
- * <h3>Interface</h3>
- *
- * Since this class is intended as an intermediate replacement of the
- * SparsityPattern class, it has mostly the same interface, with small changes
- * where necessary. In particular, the add() function, and the functions
- * inquiring properties of the sparsity pattern are the same.
- *
- *
- * <h3>Usage</h3>
- *
- * Use this class as follows:
- * @code
- * CompressedSetSparsityPattern compressed_pattern (dof_handler.n_dofs());
- * DoFTools::make_sparsity_pattern (dof_handler,
- * compressed_pattern);
- * constraints.condense (compressed_pattern);
- *
- * SparsityPattern sp;
- * sp.copy_from (compressed_pattern);
- * @endcode
- *
- * See also step-11 and step-18 for usage patterns of the related
- * CompressedSparsityPattern class, and step-27 of the current class.
- *
- * <h3>Notes</h3>
- *
- * There are several, exchangeable variations of this class, see
- * @ref Sparsity,
- * section '"Dynamic" or "compressed" sparsity patterns' for more information.
- *
- * This class is a variation of the CompressedSparsityPattern class. Instead
- * of using sorted vectors together with a caching algorithm for storing the
- * column indices of nonzero entries, the std::set container is used. This
- * solution might not be the fastest in all situations, but seems to work much
- * better than the CompressedSparsityPattern in the context of hp-adaptivity
- * (see for example step-27), or generally when there are many nonzero entries
- * in each row of a matrix (see
- * @ref step_22 "step-22").
- * On the other hand, a benchmark where nonzero entries were randomly inserted
- * into the sparsity pattern revealed that this class is slower by a factor
- * 4-6 in this situation. Hence, currently the suggestion is to carefully
- * analyze which of the CompressedSparsityPattern classes works best in a
- * certain setting. An algorithm which performs equally well in all situations
- * still has to be found.
- *
- *
- * @author Oliver Kayser-Herold, 2007
+ * @deprecated Use DynamicSparsityPattern instead.
*/
-class CompressedSetSparsityPattern : public Subscriptor
-{
-public:
- /**
- * Declare the type for container size.
- */
- typedef types::global_dof_index size_type;
-
- /**
- * An iterator that can be used to iterate over the elements of a single
- * row. The result of dereferencing such an iterator is a column index.
- */
- typedef std::set<size_type>::const_iterator row_iterator;
-
-
- /**
- * Initialize the matrix empty, that is with no memory allocated. This is
- * useful if you want such objects as member variables in other classes. You
- * can make the structure usable by calling the reinit() function.
- */
- CompressedSetSparsityPattern ();
-
- /**
- * Copy constructor. This constructor is only allowed to be called if the
- * matrix structure to be copied is empty. This is so in order to prevent
- * involuntary copies of objects for temporaries, which can use large
- * amounts of computing time. However, copy constructors are needed if yo
- * want to use the STL data types on classes like this, e.g. to write such
- * statements like <tt>v.push_back (CompressedSetSparsityPattern());</tt>,
- * with @p v a vector of @p CompressedSetSparsityPattern objects.
- */
- CompressedSetSparsityPattern (const CompressedSetSparsityPattern &);
-
- /**
- * Initialize a rectangular matrix with @p m rows and @p n columns.
- */
- CompressedSetSparsityPattern (const size_type m,
- const size_type n);
-
- /**
- * Initialize a square matrix of dimension @p n.
- */
- CompressedSetSparsityPattern (const size_type n);
-
- /**
- * 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.
- */
- CompressedSetSparsityPattern &operator = (const CompressedSetSparsityPattern &);
-
- /**
- * Reallocate memory and set up data structures for a new matrix with @p m
- * rows and @p n columns, with at most max_entries_per_row() nonzero entries
- * per row.
- */
- void reinit (const size_type m,
- const size_type n);
-
- /**
- * Since this object is kept compressed at all times anway, this function
- * does nothing, but is declared to make the interface of this class as much
- * alike as that of the SparsityPattern class.
- */
- void compress ();
-
- /**
- * Return whether the object is empty. It is empty if no memory is
- * allocated, which is the same as that both dimensions are zero.
- */
- bool empty () const;
-
- /**
- * Return the maximum number of entries per row. Note that this number may
- * change as entries are added.
- */
- size_type max_entries_per_row () const;
-
- /**
- * Add a nonzero entry to the matrix. If the entry already exists, nothing
- * bad happens.
- */
- void add (const size_type i,
- const size_type j);
-
- /**
- * Add several nonzero entries to the specified row of the matrix. If the
- * entries already exist, nothing bad happens.
- */
- template <typename ForwardIterator>
- void add_entries (const size_type row,
- ForwardIterator begin,
- ForwardIterator end,
- const bool indices_are_sorted = false);
-
- /**
- * Check if a value at a certain position may be non-zero.
- */
- bool exists (const size_type i,
- const size_type j) const;
-
- /**
- * Make the sparsity pattern symmetric by adding the sparsity pattern of the
- * transpose object.
- *
- * This function throws an exception if the sparsity pattern does not
- * represent a square matrix.
- */
- void symmetrize ();
-
- /**
- * Print the sparsity of the matrix. The output consists of one line per row
- * of the format <tt>[i,j1,j2,j3,...]</tt>. <i>i</i> is the row number and
- * <i>jn</i> are the allocated columns in this row.
- */
- void print (std::ostream &out) const;
-
- /**
- * Print the sparsity of the matrix in a format that @p gnuplot understands
- * and which can be used to plot the sparsity pattern in a graphical way.
- * The format consists of pairs <tt>i j</tt> of nonzero elements, each
- * representing one entry of this matrix, one per line of the output file.
- * Indices are counted from zero on, as usual. Since sparsity patterns are
- * printed in the same way as matrices are displayed, we print the negative
- * of the column index, which means that the <tt>(0,0)</tt> element is in
- * the top left rather than in the bottom left corner.
- *
- * Print the sparsity pattern in gnuplot by setting the data style to dots
- * or points and use the @p plot command.
- */
- void print_gnuplot (std::ostream &out) const;
-
- /**
- * Return number of rows of this matrix, which equals the dimension of the
- * image space.
- */
- size_type n_rows () const;
-
- /**
- * Return number of columns of this matrix, which equals the dimension of
- * the range space.
- */
- size_type n_cols () const;
-
- /**
- * Number of entries in a specific row.
- */
- size_type row_length (const size_type row) const;
-
- /**
- * Return an iterator that can loop over all entries in the given row.
- * Dereferencing the iterator yields a column index.
- */
- row_iterator row_begin (const size_type row) const;
-
- /**
- * End iterator for the given row.
- */
- row_iterator row_end (const size_type row) const;
-
-
- /**
- * Compute the bandwidth of the matrix represented by this structure. The
- * bandwidth is the maximum of $|i-j|$ for which the index pair $(i,j)$
- * represents a nonzero entry of the matrix.
- */
- size_type bandwidth () const;
-
- /**
- * Return the number of nonzero elements allocated through this sparsity
- * pattern.
- */
- size_type n_nonzero_elements () const;
-
- /**
- * Return whether this object stores only those entries that have been added
- * explicitly, or if the sparsity pattern contains elements that have been
- * added through other means (implicitly) while building it. For the current
- * class, the result is always true.
- *
- * This function mainly serves the purpose of describing the current class
- * in cases where several kinds of sparsity patterns can be passed as
- * template arguments.
- */
- static
- bool stores_only_added_elements ();
-
-private:
- /**
- * Number of rows that this sparsity structure shall represent.
- */
- size_type rows;
-
- /**
- * Number of columns that this sparsity structure shall represent.
- */
- size_type cols;
-
- /**
- * For each row of the matrix, store the allocated non-zero entries as a
- * std::set of column indices. For a discussion of storage schemes see the
- * CompressedSparsityPattern::Line class.
- */
- struct Line
- {
- std::set<size_type> entries;
-
- /**
- * Constructor.
- */
- Line ();
-
- /**
- * Add the given column number to this line.
- */
- void add (const size_type col_num);
-
- /**
- * Add the columns specified by the iterator range to this line.
- */
- template <typename ForwardIterator>
- void add_entries (ForwardIterator begin,
- ForwardIterator end);
- };
-
-
- /**
- * Actual data: store for each row the set of nonzero entries.
- */
- std::vector<Line> lines;
-};
+typedef DynamicSparsityPattern CompressedSetSparsityPattern DEAL_II_DEPRECATED;
/*@}*/
-/*---------------------- Inline functions -----------------------------------*/
-
-
-inline
-CompressedSetSparsityPattern::Line::Line ()
-{}
-
-
-
-inline
-void
-CompressedSetSparsityPattern::Line::add (const size_type j)
-{
- entries.insert (j);
-}
-
-
-
-template <typename ForwardIterator>
-inline
-void
-CompressedSetSparsityPattern::Line::add_entries (ForwardIterator begin,
- ForwardIterator end)
-{
- entries.insert (begin, end);
-}
-
-
-
-inline
-CompressedSetSparsityPattern::size_type
-CompressedSetSparsityPattern::n_rows () const
-{
- return rows;
-}
-
-
-
-inline
-CompressedSetSparsityPattern::size_type
-CompressedSetSparsityPattern::n_cols () const
-{
- return cols;
-}
-
-
-
-inline
-void
-CompressedSetSparsityPattern::add (const size_type i,
- const size_type j)
-{
- Assert (i<rows, ExcIndexRangeType<size_type>(i, 0, rows));
- Assert (j<cols, ExcIndexRangeType<size_type>(j, 0, cols));
-
- lines[i].add (j);
-}
-
-
-
-template <typename ForwardIterator>
-inline
-void
-CompressedSetSparsityPattern::add_entries (const size_type row,
- ForwardIterator begin,
- ForwardIterator end,
- const bool /*indices_are_sorted*/)
-{
- Assert (row < rows, ExcIndexRangeType<size_type> (row, 0, rows));
-
- lines[row].add_entries (begin, end);
-}
-
-
-
-inline
-CompressedSetSparsityPattern::size_type
-CompressedSetSparsityPattern::row_length (const size_type row) const
-{
- Assert (row < n_rows(), ExcIndexRangeType<size_type> (row, 0, n_rows()));
-
- return lines[row].entries.size();
-}
-
-
-
-inline
-CompressedSetSparsityPattern::row_iterator
-CompressedSetSparsityPattern::row_begin (const size_type row) const
-{
- return (lines[row].entries.begin ());
-}
-
-
-
-inline
-CompressedSetSparsityPattern::row_iterator
-CompressedSetSparsityPattern::row_end (const size_type row) const
-{
- return (lines[row].entries.end ());
-}
-
-
-
-inline
-bool
-CompressedSetSparsityPattern::stores_only_added_elements ()
-{
- return true;
-}
-
DEAL_II_NAMESPACE_CLOSE
// ---------------------------------------------------------------------
//
-// Copyright (C) 2001 - 2014 by the deal.II authors
+// Copyright (C) 2001 - 2015 by the deal.II authors
//
// This file is part of the deal.II library.
//
#include <deal.II/lac/exceptions.h>
#include <deal.II/base/index_set.h>
+#include <deal.II/lac/dynamic_sparsity_pattern.h>
+
#include <vector>
#include <algorithm>
#include <iostream>
*@{
*/
-
/**
- * This class acts as an intermediate form of the SparsityPattern class. From
- * the interface it mostly represents a SparsityPattern object that is kept
- * compressed at all times. However, since the final sparsity pattern is not
- * known while constructing it, keeping the pattern compressed at all times
- * can only be achieved at the expense of either increased memory or run time
- * consumption upon use. The main purpose of this class is to avoid some
- * memory bottlenecks, so we chose to implement it memory conservative. The
- * chosen data format is too unsuited to be used for actual matrices, though.
- * It is therefore necessary to first copy the data of this object over to an
- * object of type SparsityPattern before using it in actual matrices.
- *
- * Another viewpoint is that this class does not need up front allocation of a
- * certain amount of memory, but grows as necessary. An extensive description
- * of sparsity patterns can be found in the documentation of the
- * @ref Sparsity
- * module.
- *
- * This class is an example of the "dynamic" type of
- * @ref Sparsity.
- *
- * <h3>Interface</h3>
- *
- * Since this class is intended as an intermediate replacement of the
- * SparsityPattern class, it has mostly the same interface, with small changes
- * where necessary. In particular, the add() function, and the functions
- * inquiring properties of the sparsity pattern are the same.
- *
- *
- * <h3>Usage</h3>
- *
- * Use this class as follows:
- * @code
- * CompressedSimpleSparsityPattern compressed_pattern (dof_handler.n_dofs());
- * DoFTools::make_sparsity_pattern (dof_handler,
- * compressed_pattern);
- * constraints.condense (compressed_pattern);
- *
- * SparsityPattern sp;
- * sp.copy_from (compressed_pattern);
- * @endcode
- *
- *
- * <h3>Notes</h3>
- *
- * There are several, exchangeable variations of this class, see
- * @ref Sparsity,
- * section '"Dynamic" or "compressed" sparsity patterns' for more information.
- *
- * @author Timo Heister, 2008
+ * @deprecated Use DynamicSparsityPattern instead.
*/
-class CompressedSimpleSparsityPattern : public Subscriptor
-{
-public:
- /**
- * Declare the type for container size.
- */
- typedef types::global_dof_index size_type;
-
- /**
- * An iterator that can be used to iterate over the elements of a single
- * row. The result of dereferencing such an iterator is a column index.
- */
- typedef std::vector<size_type>::const_iterator row_iterator;
-
- /**
- * Initialize the matrix empty, that is with no memory allocated. This is
- * useful if you want such objects as member variables in other classes. You
- * can make the structure usable by calling the reinit() function.
- */
- CompressedSimpleSparsityPattern ();
-
- /**
- * Copy constructor. This constructor is only allowed to be called if the
- * matrix structure to be copied is empty. This is so in order to prevent
- * involuntary copies of objects for temporaries, which can use large
- * amounts of computing time. However, copy constructors are needed if you
- * want to use the STL data types on classes like this, e.g. to write such
- * statements like <tt>v.push_back (CompressedSparsityPattern());</tt>, with
- * @p v a vector of @p CompressedSparsityPattern objects.
- */
- CompressedSimpleSparsityPattern (const CompressedSimpleSparsityPattern &);
-
- /**
- * Initialize a rectangular matrix with @p m rows and @p n columns. The @p
- * rowset restricts the storage to elements in rows of this set. Adding
- * elements outside of this set has no effect. The default argument keeps
- * all entries.
- */
- CompressedSimpleSparsityPattern (const size_type m,
- const size_type n,
- const IndexSet &rowset = IndexSet());
-
- /**
- * Create a square SparsityPattern using the index set.
- */
- CompressedSimpleSparsityPattern (const IndexSet &indexset);
-
- /**
- * Initialize a square matrix of dimension @p n.
- */
- CompressedSimpleSparsityPattern (const size_type n);
-
- /**
- * 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.
- */
- CompressedSimpleSparsityPattern &operator = (const CompressedSimpleSparsityPattern &);
-
- /**
- * Reallocate memory and set up data structures for a new matrix with @p m
- * rows and @p n columns, with at most max_entries_per_row() nonzero entries
- * per row. The @p rowset restricts the storage to elements in rows of this
- * set. Adding elements outside of this set has no effect. The default
- * argument keeps all entries.
- */
- void reinit (const size_type m,
- const size_type n,
- const IndexSet &rowset = IndexSet());
-
- /**
- * Since this object is kept compressed at all times anway, this function
- * does nothing, but is declared to make the interface of this class as much
- * alike as that of the SparsityPattern class.
- */
- void compress ();
-
- /**
- * Return whether the object is empty. It is empty if no memory is
- * allocated, which is the same as that both dimensions are zero.
- */
- bool empty () const;
-
- /**
- * Return the maximum number of entries per row. Note that this number may
- * change as entries are added.
- */
- size_type max_entries_per_row () const;
-
- /**
- * Add a nonzero entry to the matrix. If the entry already exists, nothing
- * bad happens.
- */
- void add (const size_type i,
- const size_type j);
-
- /**
- * Add several nonzero entries to the specified row of the matrix. If the
- * entries already exist, nothing bad happens.
- */
- template <typename ForwardIterator>
- void add_entries (const size_type row,
- ForwardIterator begin,
- ForwardIterator end,
- const bool indices_are_unique_and_sorted = false);
-
- /**
- * Check if a value at a certain position may be non-zero.
- */
- bool exists (const size_type i,
- const size_type j) const;
-
- /**
- * Make the sparsity pattern symmetric by adding the sparsity pattern of the
- * transpose object.
- *
- * This function throws an exception if the sparsity pattern does not
- * represent a square matrix.
- */
- void symmetrize ();
-
- /**
- * Print the sparsity of the matrix. The output consists of one line per row
- * of the format <tt>[i,j1,j2,j3,...]</tt>. <i>i</i> is the row number and
- * <i>jn</i> are the allocated columns in this row.
- */
- void print (std::ostream &out) const;
-
- /**
- * Print the sparsity of the matrix in a format that @p gnuplot understands
- * and which can be used to plot the sparsity pattern in a graphical way.
- * The format consists of pairs <tt>i j</tt> of nonzero elements, each
- * representing one entry of this matrix, one per line of the output file.
- * Indices are counted from zero on, as usual. Since sparsity patterns are
- * printed in the same way as matrices are displayed, we print the negative
- * of the column index, which means that the <tt>(0,0)</tt> element is in
- * the top left rather than in the bottom left corner.
- *
- * Print the sparsity pattern in gnuplot by setting the data style to dots
- * or points and use the @p plot command.
- */
- void print_gnuplot (std::ostream &out) const;
-
- /**
- * Return number of rows of this matrix, which equals the dimension of the
- * image space.
- */
- size_type n_rows () const;
-
- /**
- * Return number of columns of this matrix, which equals the dimension of
- * the range space.
- */
- size_type n_cols () const;
-
- /**
- * Number of entries in a specific row. This function can only be called if
- * the given row is a member of the index set of rows that we want to store.
- */
- size_type row_length (const size_type row) const;
-
- /**
- * Access to column number field. Return the column number of the @p
- * indexth entry in @p row.
- */
- size_type column_number (const size_type row,
- const size_type index) const;
-
- /**
- * Return an iterator that can loop over all entries in the given row.
- * Dereferencing the iterator yields a column index.
- */
- row_iterator row_begin (const size_type row) const;
-
- /**
- * Returns the end of the current row.
- */
- row_iterator row_end (const size_type row) const;
- /**
- * Compute the bandwidth of the matrix represented by this structure. The
- * bandwidth is the maximum of $|i-j|$ for which the index pair $(i,j)$
- * represents a nonzero entry of the matrix.
- */
- size_type bandwidth () const;
-
- /**
- * Return the number of nonzero elements allocated through this sparsity
- * pattern.
- */
- size_type n_nonzero_elements () const;
-
- /**
- * Return the IndexSet that sets which rows are active on the current
- * processor. It corresponds to the IndexSet given to this class in the
- * constructor or in the reinit function.
- */
- const IndexSet &row_index_set () const;
-
- /**
- * return whether this object stores only those entries that have been added
- * explicitly, or if the sparsity pattern contains elements that have been
- * added through other means (implicitly) while building it. For the current
- * class, the result is always true.
- *
- * This function mainly serves the purpose of describing the current class
- * in cases where several kinds of sparsity patterns can be passed as
- * template arguments.
- */
- static
- bool stores_only_added_elements ();
-
- /**
- * Determine an estimate for the memory consumption (in bytes) of this
- * object.
- */
- size_type memory_consumption () const;
-
-private:
- /**
- * Number of rows that this sparsity structure shall represent.
- */
- size_type rows;
-
- /**
- * Number of columns that this sparsity structure shall represent.
- */
- size_type cols;
-
- /**
- * A set that contains the valid rows.
- */
-
- IndexSet rowset;
-
-
- /**
- * Store some data for each row describing which entries of this row are
- * nonzero. Data is stored sorted in the @p entries std::vector. The vector
- * per row is dynamically growing upon insertion doubling its memory each
- * time.
- */
- struct Line
- {
- public:
- /**
- * Storage for the column indices of this row. This array is always kept
- * sorted.
- */
- std::vector<size_type> entries;
-
- /**
- * Constructor.
- */
- Line ();
-
- /**
- * Add the given column number to this line.
- */
- void add (const size_type col_num);
-
- /**
- * Add the columns specified by the iterator range to this line.
- */
- template <typename ForwardIterator>
- void add_entries (ForwardIterator begin,
- ForwardIterator end,
- const bool indices_are_sorted);
-
- /**
- * estimates memory consumption.
- */
- size_type memory_consumption () const;
- };
-
-
- /**
- * Actual data: store for each row the set of nonzero entries.
- */
- std::vector<Line> lines;
-};
+typedef DynamicSparsityPattern CompressedSimpleSparsityPattern DEAL_II_DEPRECATED;
/*@}*/
-/*---------------------- Inline functions -----------------------------------*/
-
-
-inline
-void
-CompressedSimpleSparsityPattern::Line::add (const size_type j)
-{
- // first check the last element (or if line is still empty)
- if ( (entries.size()==0) || ( entries.back() < j) )
- {
- entries.push_back(j);
- return;
- }
-
- // do a binary search to find the place where to insert:
- std::vector<size_type>::iterator
- it = Utilities::lower_bound(entries.begin(),
- entries.end(),
- j);
-
- // If this entry is a duplicate, exit immediately
- if (*it == j)
- return;
-
- // Insert at the right place in the vector. Vector grows automatically to
- // fit elements. Always doubles its size.
- entries.insert(it, j);
-}
-
-
-
-inline
-CompressedSimpleSparsityPattern::size_type
-CompressedSimpleSparsityPattern::n_rows () const
-{
- return rows;
-}
-
-
-
-inline
-types::global_dof_index
-CompressedSimpleSparsityPattern::n_cols () const
-{
- return cols;
-}
-
-
-
-inline
-void
-CompressedSimpleSparsityPattern::add (const size_type i,
- const size_type j)
-{
- Assert (i<rows, ExcIndexRangeType<size_type>(i, 0, rows));
- Assert (j<cols, ExcIndexRangeType<size_type>(j, 0, cols));
-
- if (rowset.size() > 0 && !rowset.is_element(i))
- return;
-
- const size_type rowindex =
- rowset.size()==0 ? i : rowset.index_within_set(i);
- lines[rowindex].add (j);
-}
-
-
-
-template <typename ForwardIterator>
-inline
-void
-CompressedSimpleSparsityPattern::add_entries (const size_type row,
- ForwardIterator begin,
- ForwardIterator end,
- const bool indices_are_sorted)
-{
- Assert (row < rows, ExcIndexRangeType<size_type> (row, 0, rows));
-
- if (rowset.size() > 0 && !rowset.is_element(row))
- return;
-
- const size_type rowindex =
- rowset.size()==0 ? row : rowset.index_within_set(row);
- lines[rowindex].add_entries (begin, end, indices_are_sorted);
-}
-
-
-
-inline
-CompressedSimpleSparsityPattern::Line::Line ()
-{}
-
-
-
-inline
-types::global_dof_index
-CompressedSimpleSparsityPattern::row_length (const size_type row) const
-{
- Assert (row < n_rows(), ExcIndexRangeType<size_type> (row, 0, n_rows()));
- if (rowset.size() > 0 && !rowset.is_element(row))
- return 0;
-
- const size_type rowindex =
- rowset.size()==0 ? row : rowset.index_within_set(row);
- return lines[rowindex].entries.size();
-}
-
-
-
-inline
-types::global_dof_index
-CompressedSimpleSparsityPattern::column_number (const size_type row,
- const size_type index) const
-{
- Assert (row < n_rows(), ExcIndexRangeType<size_type> (row, 0, n_rows()));
- Assert( rowset.size() == 0 || rowset.is_element(row), ExcInternalError());
-
- const size_type local_row = rowset.size() ? rowset.index_within_set(row) : row;
- Assert (index < lines[local_row].entries.size(),
- ExcIndexRangeType<size_type> (index, 0, lines[local_row].entries.size()));
- return lines[local_row].entries[index];
-}
-
-
-
-inline
-CompressedSimpleSparsityPattern::row_iterator
-CompressedSimpleSparsityPattern::row_begin (const size_type row) const
-{
- Assert (row < n_rows(), ExcIndexRangeType<size_type> (row, 0, n_rows()));
- const size_type local_row = rowset.size() ? rowset.index_within_set(row) : row;
- return lines[local_row].entries.begin();
-}
-
-
-
-inline
-CompressedSimpleSparsityPattern::row_iterator
-CompressedSimpleSparsityPattern::row_end (const size_type row) const
-{
- Assert (row < n_rows(), ExcIndexRangeType<size_type> (row, 0, n_rows()));
- const size_type local_row = rowset.size() ? rowset.index_within_set(row) : row;
- return lines[local_row].entries.end();
-}
-
-
-
-inline
-const IndexSet &
-CompressedSimpleSparsityPattern::row_index_set () const
-{
- return rowset;
-}
-
-
-
-inline
-bool
-CompressedSimpleSparsityPattern::stores_only_added_elements ()
-{
- return true;
-}
DEAL_II_NAMESPACE_CLOSE
// ---------------------------------------------------------------------
//
-// Copyright (C) 2001 - 2014 by the deal.II authors
+// Copyright (C) 2001 - 2015 by the deal.II authors
//
// This file is part of the deal.II library.
//
#include <deal.II/base/config.h>
-#include <deal.II/base/subscriptor.h>
-#include <deal.II/lac/exceptions.h>
-
-#include <vector>
-#include <algorithm>
+#include <deal.II/lac/dynamic_sparsity_pattern.h>
DEAL_II_NAMESPACE_OPEN
-template <typename number> class SparseMatrix;
-
-
-// TODO[WB]: Unify implementation with the CompressedSetSparsityPattern
-// since really all that's different is the Line structure in the two
-// classes. We should have a templatized base class that simply gets the
-// particular Line structure from a derived class.
-
/*! @addtogroup Sparsity
*@{
*/
-
/**
- * This class acts as an intermediate form of the SparsityPattern class. From
- * the interface it mostly represents a SparsityPattern object that is kept
- * compressed at all times. However, since the final sparsity pattern is not
- * known while constructing it, keeping the pattern compressed at all times
- * can only be achieved at the expense of either increased memory or run time
- * consumption upon use. The main purpose of this class is to avoid some
- * memory bottlenecks, so we chose to implement it memory conservative, but
- * the chosen data format is too unsuited to be used for actual matrices. It
- * is therefore necessary to first copy the data of this object over to an
- * object of type SparsityPattern before using it in actual matrices.
- *
- * Another viewpoint is that this class does not need up front allocation of a
- * certain amount of memory, but grows as necessary. An extensive description
- * of sparsity patterns can be found in the documentation of the
- * @ref Sparsity
- * module.
- *
- * This class is an example of the "dynamic" type of
- * @ref Sparsity.
- *
- * <h3>Interface</h3>
- *
- * Since this class is intended as an intermediate replacement of the
- * SparsityPattern class, it has mostly the same interface, with small changes
- * where necessary. In particular, the add() function, and the functions
- * inquiring properties of the sparsity pattern are the same.
- *
- *
- * <h3>Usage</h3>
- *
- * Use this class as follows:
- * @code
- * CompressedSparsityPattern compressed_pattern (dof_handler.n_dofs());
- * DoFTools::make_sparsity_pattern (dof_handler,
- * compressed_pattern);
- * constraints.condense (compressed_pattern);
- *
- * SparsityPattern sp;
- * sp.copy_from (compressed_pattern);
- * @endcode
- *
- * See also step-11 and step-18 for usage patterns.
- *
- * <h3>Notes</h3>
- *
- * There are several, exchangeable variations of this class, see
- * @ref Sparsity,
- * section '"Dynamic" or "compressed" sparsity patterns' for more information.
- *
- * @author Wolfgang Bangerth, 2001
+ * @deprecated Use DynamicSparsityPattern instead.
*/
-class CompressedSparsityPattern : public Subscriptor
-{
-public:
- /**
- * Declare the type for container size.
- */
- typedef types::global_dof_index size_type;
-
- /**
- * An iterator that can be used to iterate over the elements of a single
- * row. The result of dereferencing such an iterator is a column index.
- */
- typedef std::vector<size_type>::const_iterator row_iterator;
-
- /**
- * Initialize the matrix empty, that is with no memory allocated. This is
- * useful if you want such objects as member variables in other classes. You
- * can make the structure usable by calling the reinit() function.
- */
- CompressedSparsityPattern ();
-
- /**
- * Copy constructor. This constructor is only allowed to be called if the
- * matrix structure to be copied is empty. This is so in order to prevent
- * involuntary copies of objects for temporaries, which can use large
- * amounts of computing time. However, copy constructors are needed if yo
- * want to use the STL data types on classes like this, e.g. to write such
- * statements like <tt>v.push_back (CompressedSparsityPattern());</tt>, with
- * @p v a vector of @p CompressedSparsityPattern objects.
- */
- CompressedSparsityPattern (const CompressedSparsityPattern &);
-
- /**
- * Initialize a rectangular matrix with @p m rows and @p n columns.
- */
- CompressedSparsityPattern (const size_type m,
- const size_type n);
-
- /**
- * Initialize a square matrix of dimension @p n.
- */
- CompressedSparsityPattern (const size_type n);
-
- /**
- * 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.
- */
- CompressedSparsityPattern &operator = (const CompressedSparsityPattern &);
-
- /**
- * Reallocate memory and set up data structures for a new matrix with @p m
- * rows and @p n columns, with at most max_entries_per_row() nonzero entries
- * per row.
- */
- void reinit (const size_type m,
- const size_type n);
-
- /**
- * Since this object is kept compressed at all times anway, this function
- * does nothing, but is declared to make the interface of this class as much
- * alike as that of the SparsityPattern class.
- */
- void compress ();
-
- /**
- * Return whether the object is empty. It is empty if no memory is
- * allocated, which is the same as that both dimensions are zero.
- */
- bool empty () const;
-
- /**
- * Return the maximum number of entries per row. Note that this number may
- * change as entries are added.
- */
- size_type max_entries_per_row () const;
-
- /**
- * Add a nonzero entry to the matrix. If the entry already exists, nothing
- * bad happens.
- */
- void add (const size_type i,
- const size_type j);
-
- /**
- * Add several nonzero entries to the specified row of the matrix. If the
- * entries already exist, nothing bad happens.
- */
- template <typename ForwardIterator>
- void add_entries (const size_type row,
- ForwardIterator begin,
- ForwardIterator end,
- const bool indices_are_unique_and_sorted = false);
-
- /**
- * Check if a value at a certain position may be non-zero.
- */
- bool exists (const size_type i,
- const size_type j) const;
-
- /**
- * Make the sparsity pattern symmetric by adding the sparsity pattern of the
- * transpose object.
- *
- * This function throws an exception if the sparsity pattern does not
- * represent a square matrix.
- */
- void symmetrize ();
-
- /**
- * Print the sparsity of the matrix. The output consists of one line per row
- * of the format <tt>[i,j1,j2,j3,...]</tt>. <i>i</i> is the row number and
- * <i>jn</i> are the allocated columns in this row.
- */
- void print (std::ostream &out) const;
-
- /**
- * Print the sparsity of the matrix in a format that @p gnuplot understands
- * and which can be used to plot the sparsity pattern in a graphical way.
- * The format consists of pairs <tt>i j</tt> of nonzero elements, each
- * representing one entry of this matrix, one per line of the output file.
- * Indices are counted from zero on, as usual. Since sparsity patterns are
- * printed in the same way as matrices are displayed, we print the negative
- * of the column index, which means that the <tt>(0,0)</tt> element is in
- * the top left rather than in the bottom left corner.
- *
- * Print the sparsity pattern in gnuplot by setting the data style to dots
- * or points and use the @p plot command.
- */
- void print_gnuplot (std::ostream &out) const;
-
- /**
- * Return number of rows of this matrix, which equals the dimension of the
- * image space.
- */
- size_type n_rows () const;
-
- /**
- * Return number of columns of this matrix, which equals the dimension of
- * the range space.
- */
- size_type n_cols () const;
-
- /**
- * Number of entries in a specific row.
- */
- size_type row_length (const size_type row) const;
-
- /**
- * Access to column number field. Return the column number of the @p indexth
- * entry in @p row.
- */
- size_type column_number (const size_type row,
- const size_type index) const;
-
- /**
- * Return an iterator that can loop over all entries in the given row.
- * Dereferencing the iterator yields a column index.
- */
- row_iterator row_begin (const size_type row) const;
-
- /**
- * Returns the end of the current row.
- */
- row_iterator row_end (const size_type row) const;
-
- /**
- * Compute the bandwidth of the matrix represented by this structure. The
- * bandwidth is the maximum of $|i-j|$ for which the index pair $(i,j)$
- * represents a nonzero entry of the matrix.
- */
- size_type bandwidth () const;
-
- /**
- * Return the number of nonzero elements allocated through this sparsity
- * pattern.
- */
- size_type n_nonzero_elements () const;
-
- /**
- * Return whether this object stores only those entries that have been added
- * explicitly, or if the sparsity pattern contains elements that have been
- * added through other means (implicitly) while building it. For the current
- * class, the result is always true.
- *
- * This function mainly serves the purpose of describing the current class
- * in cases where several kinds of sparsity patterns can be passed as
- * template arguments.
- */
- static
- bool stores_only_added_elements ();
-
-private:
- /**
- * Number of rows that this sparsity structure shall represent.
- */
- size_type rows;
-
- /**
- * Number of columns that this sparsity structure shall represent.
- */
- size_type cols;
-
- /**
- * Store some data for each row describing which entries of this row are
- * nonzero. Data is organized as follows: if an entry is added to a row, it
- * is first added to the #cache variable, irrespective of whether an entry
- * with same column number has already been added. Only if the cache is full
- * do we flush it by removing duplicates, removing entries that are already
- * stored in the @p entries array, sorting everything, and merging the two
- * arrays.
- *
- * The reasoning behind this scheme is that memory allocation is expensive,
- * and we only want to do it when really necessary. Previously (in deal.II
- * versions up to 5.0), we used to store the column indices inside a
- * std::set, but this would allocate 20 bytes each time we added an entry.
- * (A std::set based class has later been revived in form of the
- * CompressedSetSparsityPattern class, as this turned out to be more
- * efficient for hp finite element programs such as step-27). Using the
- * present scheme, we only need to allocate memory once for every 8 added
- * entries, and we waste a lot less memory by not using a balanced tree for
- * storing column indices.
- *
- * Since some functions that are @p const need to access the data of this
- * object, but need to flush caches before, the flush_cache() function is
- * marked const, and the data members are marked @p mutable.
- *
- * A small testseries about the size of the cache showed that the run time
- * of a small program just testing the compressed sparsity pattern element
- * insertion routine ran for 3.6 seconds with a cache size of 8, and 4.2
- * seconds with a cache size of 16. We deem even smaller cache sizes
- * undesirable, since they lead to more memory allocations, while larger
- * cache sizes lead to waste of memory. The original version of this class,
- * with one std::set per row took 8.2 seconds on the same program.
- */
- struct Line
- {
- private:
- /**
- * Size of the cache.
- */
- static const unsigned int cache_size = 8;
-
- public:
- /**
- * Storage for the column indices of this row, unless they are still in
- * the cache. This array is always kept sorted.
- */
- mutable std::vector<size_type> entries;
-
- /**
- * Cache of entries that have not yet been written to #entries;
- */
- mutable size_type cache[cache_size];
-
- /**
- * Number of entries in the cache.
- */
- mutable unsigned int cache_entries;
-
- /**
- * Constructor.
- */
- Line ();
-
- /**
- * Add the given column number to this line.
- */
- void add (const size_type col_num);
-
- /**
- * Add the columns specified by the iterator range to this line.
- */
- template <typename ForwardIterator>
- void add_entries (ForwardIterator begin,
- ForwardIterator end,
- const bool indices_are_sorted);
-
- /**
- * Flush the cache my merging it with the #entries array.
- */
- void flush_cache () const;
- };
-
-
- /**
- * Actual data: store for each row the set of nonzero entries.
- */
- std::vector<Line> lines;
-};
+typedef DynamicSparsityPattern CompressedSparsityPattern DEAL_II_DEPRECATED;
/*@}*/
-/*---------------------- Inline functions -----------------------------------*/
-
-
-inline
-void
-CompressedSparsityPattern::Line::add (const size_type j)
-{
- // first check whether this entry is
- // already in the cache. if so, we can
- // safely return
- for (unsigned int i=0; i<cache_entries; ++i)
- if (cache[i] == j)
- return;
-
- // if not, see whether there is still some
- // space in the cache. if not, then flush
- // the cache first
- if (cache_entries == cache_size && cache_entries != 0)
- flush_cache ();
-
- cache[cache_entries] = j;
- ++cache_entries;
-}
-
-
-
-inline
-types::global_dof_index
-CompressedSparsityPattern::n_rows () const
-{
- return rows;
-}
-
-
-
-inline
-types::global_dof_index
-CompressedSparsityPattern::n_cols () const
-{
- return cols;
-}
-
-
-
-inline
-void
-CompressedSparsityPattern::add (const size_type i,
- const size_type j)
-{
- Assert (i<rows, ExcIndexRangeType<size_type>(i, 0, rows));
- Assert (j<cols, ExcIndexRangeType<size_type>(j, 0, cols));
-
- lines[i].add (j);
-}
-
-
-
-template <typename ForwardIterator>
-inline
-void
-CompressedSparsityPattern::add_entries (const size_type row,
- ForwardIterator begin,
- ForwardIterator end,
- const bool indices_are_sorted)
-{
- Assert (row < rows, ExcIndexRange (row, 0, rows));
-
- lines[row].add_entries (begin, end, indices_are_sorted);
-}
-
-
-
-inline
-CompressedSparsityPattern::Line::Line ()
- :
- cache_entries (0)
-{}
-
-
-
-inline
-types::global_dof_index
-CompressedSparsityPattern::row_length (const size_type row) const
-{
- Assert (row < n_rows(), ExcIndexRangeType<size_type> (row, 0, n_rows()));
-
- if (lines[row].cache_entries != 0)
- lines[row].flush_cache ();
- return lines[row].entries.size();
-}
-
-
-
-inline
-types::global_dof_index
-CompressedSparsityPattern::column_number (const size_type row,
- const size_type index) const
-{
- Assert (row < n_rows(), ExcIndexRangeType<size_type> (row, 0, n_rows()));
- Assert (index < lines[row].entries.size(),
- ExcIndexRangeType<size_type> (index, 0, lines[row].entries.size()));
-
- if (lines[row].cache_entries != 0)
- lines[row].flush_cache ();
- return lines[row].entries[index];
-}
-
-
-
-inline
-CompressedSparsityPattern::row_iterator
-CompressedSparsityPattern::row_begin (const size_type row) const
-{
- Assert (row < n_rows(), ExcIndexRangeType<size_type> (row, 0, n_rows()));
-
- if (lines[row].cache_entries != 0)
- lines[row].flush_cache ();
- return lines[row].entries.begin();
-}
-
-
-
-inline
-CompressedSparsityPattern::row_iterator
-CompressedSparsityPattern::row_end (const size_type row) const
-{
- Assert (row < n_rows(), ExcIndexRangeType<size_type> (row, 0, n_rows()));
- return lines[row].entries.end();
-}
-
-
-
-inline
-bool
-CompressedSparsityPattern::stores_only_added_elements ()
-{
- return true;
-}
-
-
-
DEAL_II_NAMESPACE_CLOSE
template<int dim, class T> class Table;
template <typename> class FullMatrix;
class SparsityPattern;
-class CompressedSparsityPattern;
-class CompressedSetSparsityPattern;
-class CompressedSimpleSparsityPattern;
+class DynamicSparsityPattern;
class BlockSparsityPattern;
-class BlockCompressedSparsityPattern;
-class BlockCompressedSetSparsityPattern;
-class BlockCompressedSimpleSparsityPattern;
+class BlockDynamicSparsityPattern;
template <typename number> class SparseMatrix;
template <typename number> class BlockSparseMatrix;
class BlockIndices;
*/
void condense (BlockSparsityPattern &sparsity) const;
- /**
- * Same function as above, but condenses square compressed sparsity
- * patterns.
- *
- * Given the data structure used by CompressedSparsityPattern, this function
- * becomes quadratic in the number of degrees of freedom for large problems
- * and can dominate setting up linear systems when several hundred thousand
- * or millions of unknowns are involved and for problems with many nonzero
- * elements per row (for example for vector-valued problems or hp finite
- * elements). In this case, it is advisable to use the
- * CompressedSetSparsityPattern class instead, see for example
- * @ref step_27 "step-27",
- * or to use the CompressedSimpleSparsityPattern class, see for example
- * @ref step_31 "step-31".
- */
- void condense (CompressedSparsityPattern &sparsity) const;
-
- /**
- * Same function as above, but condenses compressed sparsity patterns, which
- * are based on the std::set container.
- */
- void condense (CompressedSetSparsityPattern &sparsity) const;
-
- /**
- * Same function as above, but condenses compressed sparsity patterns, which
- * are based on the ''simple'' aproach.
- */
- void condense (CompressedSimpleSparsityPattern &sparsity) const;
-
- /**
- * Same function as above, but condenses square compressed sparsity
- * patterns.
- *
- * Given the data structure used by BlockCompressedSparsityPattern, this
- * function becomes quadratic in the number of degrees of freedom for large
- * problems and can dominate setting up linear systems when several hundred
- * thousand or millions of unknowns are involved and for problems with many
- * nonzero elements per row (for example for vector-valued problems or hp
- * finite elements). In this case, it is advisable to use the
- * BlockCompressedSetSparsityPattern class instead, see for example
- * @ref step_27 "step-27"
- * and
- * @ref step_31 "step-31".
- */
- void condense (BlockCompressedSparsityPattern &sparsity) const;
-
/**
* Same function as above, but condenses square compressed sparsity
* patterns.
*/
- void condense (BlockCompressedSetSparsityPattern &sparsity) const;
+ void condense (DynamicSparsityPattern &sparsity) const;
/**
* Same function as above, but condenses square compressed sparsity
* patterns.
*/
- void condense (BlockCompressedSimpleSparsityPattern &sparsity) const;
+ void condense (BlockDynamicSparsityPattern &sparsity) const;
/**
* Condense a given matrix, i.e., eliminate the rows and columns of the
--- /dev/null
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2011 - 2015 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE at
+// the top level of the deal.II distribution.
+//
+// ---------------------------------------------------------------------
+
+#ifndef __deal2__dynamic_sparsity_pattern_h
+#define __deal2__dynamic_sparsity_pattern_h
+
+
+#include <deal.II/base/config.h>
+#include <deal.II/base/subscriptor.h>
+#include <deal.II/base/utilities.h>
+#include <deal.II/lac/exceptions.h>
+#include <deal.II/base/index_set.h>
+
+#include <vector>
+#include <algorithm>
+#include <iostream>
+
+DEAL_II_NAMESPACE_OPEN
+
+template <typename number> class SparseMatrix;
+
+
+/*! @addtogroup Sparsity
+ *@{
+ */
+
+
+/**
+ * This class acts as an intermediate form of the SparsityPattern class. From
+ * the interface it mostly represents a SparsityPattern object that is kept
+ * compressed at all times. However, since the final sparsity pattern is not
+ * known while constructing it, keeping the pattern compressed at all times
+ * can only be achieved at the expense of either increased memory or run time
+ * consumption upon use. The main purpose of this class is to avoid some
+ * memory bottlenecks, so we chose to implement it memory conservative. The
+ * chosen data format is too unsuited to be used for actual matrices, though.
+ * It is therefore necessary to first copy the data of this object over to an
+ * object of type SparsityPattern before using it in actual matrices.
+ *
+ * Another viewpoint is that this class does not need up front allocation of a
+ * certain amount of memory, but grows as necessary. An extensive description
+ * of sparsity patterns can be found in the documentation of the
+ * @ref Sparsity
+ * module.
+ *
+ * This class is an example of the "dynamic" type of
+ * @ref Sparsity.
+ *
+ * <h3>Interface</h3>
+ *
+ * Since this class is intended as an intermediate replacement of the
+ * SparsityPattern class, it has mostly the same interface, with small changes
+ * where necessary. In particular, the add() function, and the functions
+ * inquiring properties of the sparsity pattern are the same.
+ *
+ *
+ * <h3>Usage</h3>
+ *
+ * Use this class as follows:
+ * @code
+ * DynamicSparsityPattern compressed_pattern (dof_handler.n_dofs());
+ * DoFTools::make_sparsity_pattern (dof_handler,
+ * compressed_pattern);
+ * constraints.condense (compressed_pattern);
+ *
+ * SparsityPattern sp;
+ * sp.copy_from (compressed_pattern);
+ * @endcode
+ *
+ * @author Timo Heister, 2008
+ */
+class DynamicSparsityPattern : public Subscriptor
+{
+public:
+ /**
+ * Declare the type for container size.
+ */
+ typedef types::global_dof_index size_type;
+
+ /**
+ * An iterator that can be used to iterate over the elements of a single
+ * row. The result of dereferencing such an iterator is a column index.
+ */
+ typedef std::vector<size_type>::const_iterator row_iterator;
+
+ /**
+ * Initialize as an empty object. This is
+ * useful if you want such objects as member variables in other classes. You
+ * can make the structure usable by calling the reinit() function.
+ */
+ DynamicSparsityPattern ();
+
+ /**
+ * Copy constructor. This constructor is only allowed to be called if the
+ * sparsity structure to be copied is empty. This is so in order to prevent
+ * involuntary copies of objects for temporaries, which can use large
+ * amounts of computing time. However, copy constructors are needed if you
+ * want to use the STL data types on classes like this, e.g. to write such
+ * statements like <tt>v.push_back (DynamicSparsityPattern());</tt>, with
+ * @p v a vector of @p DynamicSparsityPattern objects.
+ */
+ DynamicSparsityPattern (const DynamicSparsityPattern &);
+
+ /**
+ * Initialize a rectangular sparsity pattern with @p m rows and @p n columns. The @p
+ * rowset restricts the storage to elements in rows of this set. Adding
+ * elements outside of this set has no effect. The default argument keeps
+ * all entries.
+ */
+ DynamicSparsityPattern (const size_type m,
+ const size_type n,
+ const IndexSet &rowset = IndexSet());
+
+ /**
+ * Create a square SparsityPattern using the index set.
+ */
+ DynamicSparsityPattern (const IndexSet &indexset);
+
+ /**
+ * Initialize a square pattern of dimension @p n.
+ */
+ DynamicSparsityPattern (const size_type n);
+
+ /**
+ * 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.
+ */
+ DynamicSparsityPattern &operator = (const DynamicSparsityPattern &);
+
+ /**
+ * Reallocate memory and set up data structures for a new sparsity pattern with @p m
+ * rows and @p n columns. The @p rowset restricts the storage to elements in rows of this
+ * set. Adding elements outside of this set has no effect. The default
+ * argument keeps all entries.
+ */
+ void reinit (const size_type m,
+ const size_type n,
+ const IndexSet &rowset = IndexSet());
+
+ /**
+ * Since this object is kept compressed at all times anyway, this function
+ * does nothing, but is declared to make the interface of this class as much
+ * alike as that of the SparsityPattern class.
+ */
+ void compress ();
+
+ /**
+ * Return whether the object is empty. It is empty if no memory is
+ * allocated, which is the same as that both dimensions are zero.
+ */
+ bool empty () const;
+
+ /**
+ * Return the maximum number of entries per row. Note that this number may
+ * change as entries are added.
+ */
+ size_type max_entries_per_row () const;
+
+ /**
+ * Add a nonzero entry. If the entry already exists, this call does nothing.
+ */
+ void add (const size_type i,
+ const size_type j);
+
+ /**
+ * Add several nonzero entries to the specified row. Already existing entries are ignored.
+ */
+ template <typename ForwardIterator>
+ void add_entries (const size_type row,
+ ForwardIterator begin,
+ ForwardIterator end,
+ const bool indices_are_unique_and_sorted = false);
+
+ /**
+ * Check if a value at a certain position may be non-zero.
+ */
+ bool exists (const size_type i,
+ const size_type j) const;
+
+ /**
+ * Make the sparsity pattern symmetric by adding the sparsity pattern of the
+ * transpose object.
+ *
+ * This function throws an exception if the sparsity pattern does not
+ * represent a square matrix.
+ */
+ void symmetrize ();
+
+ /**
+ * Print the sparsity pattern. The output consists of one line per row
+ * of the format <tt>[i,j1,j2,j3,...]</tt>. <i>i</i> is the row number and
+ * <i>jn</i> are the allocated columns in this row.
+ */
+ void print (std::ostream &out) const;
+
+ /**
+ * Print the sparsity pattern in a format that @p gnuplot understands
+ * and which can be used to plot the sparsity pattern in a graphical way.
+ * The format consists of pairs <tt>i j</tt> of nonzero elements, each
+ * representing one entry, one per line of the output file.
+ * Indices are counted from zero on, as usual. Since sparsity patterns are
+ * printed in the same way as matrices are displayed, we print the negative
+ * of the column index, which means that the <tt>(0,0)</tt> element is in
+ * the top left rather than in the bottom left corner.
+ *
+ * Print the sparsity pattern in gnuplot by setting the data style to dots
+ * or points and use the @p plot command.
+ */
+ void print_gnuplot (std::ostream &out) const;
+
+ /**
+ * Return the number of rows, which equals the dimension of the
+ * image space.
+ */
+ size_type n_rows () const;
+
+ /**
+ * Return the number of columns, which equals the dimension of
+ * the range space.
+ */
+ size_type n_cols () const;
+
+ /**
+ * Number of entries in a specific row. This function can only be called if
+ * the given row is a member of the index set of rows that we want to store.
+ */
+ size_type row_length (const size_type row) const;
+
+ /**
+ * Access to column number field. Return the column number of the @p
+ * indexth entry in @p row.
+ */
+ size_type column_number (const size_type row,
+ const size_type index) const;
+
+ /**
+ * Return an iterator that can loop over all entries in the given row.
+ * Dereferencing the iterator yields a column index.
+ */
+ row_iterator row_begin (const size_type row) const;
+
+ /**
+ * Returns the end of the current row.
+ */
+ row_iterator row_end (const size_type row) const;
+ /**
+ * Compute the bandwidth of the matrix represented by this structure. The
+ * bandwidth is the maximum of $|i-j|$ for which the index pair $(i,j)$
+ * represents a nonzero entry of the matrix.
+ */
+ size_type bandwidth () const;
+
+ /**
+ * Return the number of nonzero elements allocated through this sparsity
+ * pattern.
+ */
+ size_type n_nonzero_elements () const;
+
+ /**
+ * Return the IndexSet that sets which rows are active on the current
+ * processor. It corresponds to the IndexSet given to this class in the
+ * constructor or in the reinit function.
+ */
+ const IndexSet &row_index_set () const;
+
+ /**
+ * return whether this object stores only those entries that have been added
+ * explicitly, or if the sparsity pattern contains elements that have been
+ * added through other means (implicitly) while building it. For the current
+ * class, the result is always true.
+ *
+ * This function mainly serves the purpose of describing the current class
+ * in cases where several kinds of sparsity patterns can be passed as
+ * template arguments.
+ */
+ static
+ bool stores_only_added_elements ();
+
+ /**
+ * Determine an estimate for the memory consumption (in bytes) of this
+ * object.
+ */
+ size_type memory_consumption () const;
+
+private:
+ /**
+ * Number of rows that this sparsity structure shall represent.
+ */
+ size_type rows;
+
+ /**
+ * Number of columns that this sparsity structure shall represent.
+ */
+ size_type cols;
+
+ /**
+ * A set that contains the valid rows.
+ */
+
+ IndexSet rowset;
+
+
+ /**
+ * Store some data for each row describing which entries of this row are
+ * nonzero. Data is stored sorted in the @p entries std::vector. The vector
+ * per row is dynamically growing upon insertion doubling its memory each
+ * time.
+ */
+ struct Line
+ {
+ public:
+ /**
+ * Storage for the column indices of this row. This array is always kept
+ * sorted.
+ */
+ std::vector<size_type> entries;
+
+ /**
+ * Constructor.
+ */
+ Line ();
+
+ /**
+ * Add the given column number to this line.
+ */
+ void add (const size_type col_num);
+
+ /**
+ * Add the columns specified by the iterator range to this line.
+ */
+ template <typename ForwardIterator>
+ void add_entries (ForwardIterator begin,
+ ForwardIterator end,
+ const bool indices_are_sorted);
+
+ /**
+ * estimates memory consumption.
+ */
+ size_type memory_consumption () const;
+ };
+
+
+ /**
+ * Actual data: store for each row the set of nonzero entries.
+ */
+ std::vector<Line> lines;
+};
+
+/*@}*/
+/*---------------------- Inline functions -----------------------------------*/
+
+
+inline
+void
+DynamicSparsityPattern::Line::add (const size_type j)
+{
+ // first check the last element (or if line is still empty)
+ if ( (entries.size()==0) || ( entries.back() < j) )
+ {
+ entries.push_back(j);
+ return;
+ }
+
+ // do a binary search to find the place where to insert:
+ std::vector<size_type>::iterator
+ it = Utilities::lower_bound(entries.begin(),
+ entries.end(),
+ j);
+
+ // If this entry is a duplicate, exit immediately
+ if (*it == j)
+ return;
+
+ // Insert at the right place in the vector. Vector grows automatically to
+ // fit elements. Always doubles its size.
+ entries.insert(it, j);
+}
+
+
+
+inline
+DynamicSparsityPattern::size_type
+DynamicSparsityPattern::n_rows () const
+{
+ return rows;
+}
+
+
+
+inline
+types::global_dof_index
+DynamicSparsityPattern::n_cols () const
+{
+ return cols;
+}
+
+
+
+inline
+void
+DynamicSparsityPattern::add (const size_type i,
+ const size_type j)
+{
+ Assert (i<rows, ExcIndexRangeType<size_type>(i, 0, rows));
+ Assert (j<cols, ExcIndexRangeType<size_type>(j, 0, cols));
+
+ if (rowset.size() > 0 && !rowset.is_element(i))
+ return;
+
+ const size_type rowindex =
+ rowset.size()==0 ? i : rowset.index_within_set(i);
+ lines[rowindex].add (j);
+}
+
+
+
+template <typename ForwardIterator>
+inline
+void
+DynamicSparsityPattern::add_entries (const size_type row,
+ ForwardIterator begin,
+ ForwardIterator end,
+ const bool indices_are_sorted)
+{
+ Assert (row < rows, ExcIndexRangeType<size_type> (row, 0, rows));
+
+ if (rowset.size() > 0 && !rowset.is_element(row))
+ return;
+
+ const size_type rowindex =
+ rowset.size()==0 ? row : rowset.index_within_set(row);
+ lines[rowindex].add_entries (begin, end, indices_are_sorted);
+}
+
+
+
+inline
+DynamicSparsityPattern::Line::Line ()
+{}
+
+
+
+inline
+types::global_dof_index
+DynamicSparsityPattern::row_length (const size_type row) const
+{
+ Assert (row < n_rows(), ExcIndexRangeType<size_type> (row, 0, n_rows()));
+ if (rowset.size() > 0 && !rowset.is_element(row))
+ return 0;
+
+ const size_type rowindex =
+ rowset.size()==0 ? row : rowset.index_within_set(row);
+ return lines[rowindex].entries.size();
+}
+
+
+
+inline
+types::global_dof_index
+DynamicSparsityPattern::column_number (const size_type row,
+ const size_type index) const
+{
+ Assert (row < n_rows(), ExcIndexRangeType<size_type> (row, 0, n_rows()));
+ Assert( rowset.size() == 0 || rowset.is_element(row), ExcInternalError());
+
+ const size_type local_row = rowset.size() ? rowset.index_within_set(row) : row;
+ Assert (index < lines[local_row].entries.size(),
+ ExcIndexRangeType<size_type> (index, 0, lines[local_row].entries.size()));
+ return lines[local_row].entries[index];
+}
+
+
+
+inline
+DynamicSparsityPattern::row_iterator
+DynamicSparsityPattern::row_begin (const size_type row) const
+{
+ Assert (row < n_rows(), ExcIndexRangeType<size_type> (row, 0, n_rows()));
+ const size_type local_row = rowset.size() ? rowset.index_within_set(row) : row;
+ return lines[local_row].entries.begin();
+}
+
+
+
+inline
+DynamicSparsityPattern::row_iterator
+DynamicSparsityPattern::row_end (const size_type row) const
+{
+ Assert (row < n_rows(), ExcIndexRangeType<size_type> (row, 0, n_rows()));
+ const size_type local_row = rowset.size() ? rowset.index_within_set(row) : row;
+ return lines[local_row].entries.end();
+}
+
+
+
+inline
+const IndexSet &
+DynamicSparsityPattern::row_index_set () const
+{
+ return rowset;
+}
+
+
+
+inline
+bool
+DynamicSparsityPattern::stores_only_added_elements ()
+{
+ return true;
+}
+
+
+DEAL_II_NAMESPACE_CLOSE
+
+#endif
*/
typedef PETScWrappers::MPI::BlockSparseMatrix BlockSparseMatrix;
- typedef dealii::BlockCompressedSimpleSparsityPattern BlockCompressedSparsityPattern;
+ typedef dealii::BlockDynamicSparsityPattern BlockCompressedSparsityPattern;
/**
* Typedef for the AMG preconditioner type.
*/
void reinit(const std::vector<IndexSet> &rows,
const std::vector<IndexSet> &cols,
- const BlockCompressedSimpleSparsityPattern &bcsp,
+ const BlockDynamicSparsityPattern &bcsp,
const MPI_Comm &com);
* Same as above but for a symmetric structure only.
*/
void reinit(const std::vector<IndexSet> &sizes,
- const BlockCompressedSimpleSparsityPattern &bcsp,
+ const BlockDynamicSparsityPattern &bcsp,
const MPI_Comm &com);
template <typename number> class SparseILU;
template <class VECTOR> class VectorSlice;
-class CompressedSparsityPattern;
-class CompressedSetSparsityPattern;
-class CompressedSimpleSparsityPattern;
-
-
namespace ChunkSparsityPatternIterators
{
class Accessor;
// forward declarations
class BlockSparsityPattern;
-class BlockCompressedSparsityPattern;
-class BlockCompressedSetSparsityPattern;
-class BlockCompressedSimpleSparsityPattern;
template <typename number> class BlockSparseMatrix;
// forward declarations
class SparsityPattern;
-class CompressedSparsityPattern;
-class CompressedSetSparsityPattern;
-class CompressedSimpleSparsityPattern;
+class DynamicSparsityPattern;
namespace TrilinosWrappers
{
#include <deal.II/base/vectorization.h>
#include <deal.II/base/partitioner.h>
#include <deal.II/lac/constraint_matrix.h>
+#include <deal.II/lac/dynamic_sparsity_pattern.h>
#include <deal.II/dofs/dof_handler.h>
#include <deal.II/matrix_free/helper_functions.h>
const std::vector<unsigned int> &renumbering,
const std::vector<unsigned int> &irregular_cells,
const bool do_blocking,
- CompressedSimpleSparsityPattern &connectivity) const;
+ DynamicSparsityPattern &connectivity) const;
/**
* Renumbers the degrees of freedom to give good access for this class.
#include <deal.II/base/memory_consumption.h>
#include <deal.II/base/multithread_info.h>
-#include <deal.II/lac/compressed_simple_sparsity_pattern.h>
+#include <deal.II/lac/dynamic_sparsity_pattern.h>
#include <deal.II/lac/sparsity_pattern.h>
#include <deal.II/matrix_free/dof_info.h>
#include <deal.II/matrix_free/helper_functions.h>
(task_info.block_size*(task_info.n_blocks-1));
// create the connectivity graph with internal blocking
- CompressedSimpleSparsityPattern connectivity;
+ DynamicSparsityPattern connectivity;
make_connectivity_graph (size_info, task_info, renumbering,irregular_cells,
true, connectivity);
{
Assert(cell_partition[neighbor_list[j]]==partition-1,
ExcInternalError());
- CompressedSimpleSparsityPattern::row_iterator neighbor =
+ DynamicSparsityPattern::row_iterator neighbor =
connectivity.row_begin(neighbor_list[j]),
end = connectivity.row_end(neighbor_list[j]);
for (; neighbor!=end ; ++neighbor)
color_finder.resize(n_neighbors+1);
for (unsigned int j=0; j<=n_neighbors; ++j)
color_finder[j]=true;
- CompressedSimpleSparsityPattern::row_iterator
+ DynamicSparsityPattern::row_iterator
neighbor = connectivity.row_begin(cell),
end = connectivity.row_end(cell);
for (; neighbor!=end ; ++neighbor)
unsigned int cluster_size = task_info.block_size*vectorization_length;
// create the connectivity graph without internal blocking
- CompressedSimpleSparsityPattern connectivity;
+ DynamicSparsityPattern connectivity;
make_connectivity_graph (size_info, task_info, renumbering,irregular_cells,
false, connectivity);
}
index--;
unsigned int additional = neighbor_list[index];
- CompressedSimpleSparsityPattern::row_iterator neighbor =
+ DynamicSparsityPattern::row_iterator neighbor =
connectivity.row_begin(additional),
end = connectivity.row_end(additional);
for (; neighbor!=end ; ++neighbor)
{
Assert(cell_partition[neighbor_list[j]]==partition-1,
ExcInternalError());
- CompressedSimpleSparsityPattern::row_iterator neighbor =
+ DynamicSparsityPattern::row_iterator neighbor =
connectivity.row_begin(neighbor_list[j]),
end = connectivity.row_end(neighbor_list[j]);
for (; neighbor!=end ; ++neighbor)
}
index--;
unsigned int additional = neighbor_neighbor_list[index];
- CompressedSimpleSparsityPattern::row_iterator neighbor =
+ DynamicSparsityPattern::row_iterator neighbor =
connectivity.row_begin(additional),
end = connectivity.row_end(additional);
for (; neighbor!=end ; ++neighbor)
ExcInternalError());
Assert(cell_partition_l2[neighbor_list[j]]==partition_l2-1,
ExcInternalError());
- CompressedSimpleSparsityPattern::row_iterator neighbor =
+ DynamicSparsityPattern::row_iterator neighbor =
connectivity.row_begin(neighbor_list[j]),
end = connectivity.row_end(neighbor_list[j]);
for (; neighbor!=end ; ++neighbor)
// go through the neighbors of the last cell in the
// current partition and check if we find some to
// fill up with.
- CompressedSimpleSparsityPattern::row_iterator
+ DynamicSparsityPattern::row_iterator
neighbor =
connectivity.row_begin(additional),
end = connectivity.row_end(additional);
const std::vector<unsigned int> &renumbering,
const std::vector<unsigned int> &irregular_cells,
const bool do_blocking,
- CompressedSimpleSparsityPattern &connectivity) const
+ DynamicSparsityPattern &connectivity) const
{
AssertDimension (row_starts.size()-1, size_info.n_active_cells);
const unsigned int n_rows =
block_vector.cc
chunk_sparse_matrix.cc
chunk_sparsity_pattern.cc
- compressed_set_sparsity_pattern.cc
- compressed_simple_sparsity_pattern.cc
- compressed_sparsity_pattern.cc
+ dynamic_sparsity_pattern.cc
constraint_matrix.cc
full_matrix.cc
lapack_full_matrix.cc
template <>
void
-BlockSparsityPatternBase<CompressedSimpleSparsityPattern>::print(std::ostream &out) const
+BlockSparsityPatternBase<DynamicSparsityPattern>::print(std::ostream &out) const
{
size_type k=0;
for (size_type ib=0; ib<n_block_rows(); ++ib)
size_type l=0;
for (size_type jb=0; jb<n_block_cols(); ++jb)
{
- const CompressedSimpleSparsityPattern &b = block(ib,jb);
+ const DynamicSparsityPattern &b = block(ib,jb);
if (b.row_index_set().size()==0 || b.row_index_set().is_element(i))
for (size_type j=0; j<b.n_cols(); ++j)
if (b.exists(i,j))
template class BlockSparsityPatternBase<SparsityPattern>;
-template class BlockSparsityPatternBase<CompressedSparsityPattern>;
-template class BlockSparsityPatternBase<CompressedSimpleSparsityPattern>;
-template class BlockSparsityPatternBase<CompressedSetSparsityPattern>;
+template class BlockSparsityPatternBase<DynamicSparsityPattern>;
#ifdef DEAL_II_WITH_TRILINOS
template class BlockSparsityPatternBase<TrilinosWrappers::SparsityPattern>;
#endif
void
-BlockSparsityPattern::copy_from (const BlockCompressedSparsityPattern &csp)
+BlockSparsityPattern::copy_from (const BlockDynamicSparsityPattern &csp)
{
// delete old content, set block
// sizes anew
collect_sizes();
}
-void
-BlockSparsityPattern::copy_from (const BlockCompressedSimpleSparsityPattern &csp)
-{
- // delete old content, set block
- // sizes anew
- reinit (csp.n_block_rows(), csp.n_block_cols());
-
- // copy over blocks
- for (size_type i=0; i<rows; ++i)
- for (size_type j=0; j<rows; ++j)
- block(i,j).copy_from (csp.block(i,j));
-
- // and finally enquire their new
- // sizes
- collect_sizes();
-}
-
-void
-BlockSparsityPattern::copy_from (const BlockCompressedSetSparsityPattern &csp)
-{
- // delete old content, set block
- // sizes anew
- reinit (csp.n_block_rows(), csp.n_block_cols());
-
- // copy over blocks
- for (size_type i=0; i<rows; ++i)
- for (size_type j=0; j<rows; ++j)
- block(i,j).copy_from (csp.block(i,j));
-
- // and finally enquire their new
- // sizes
- collect_sizes();
-}
-
-
-
-BlockCompressedSparsityPattern::BlockCompressedSparsityPattern ()
-{}
-
-
-
-BlockCompressedSparsityPattern::
-BlockCompressedSparsityPattern (
- const size_type n_rows,
- const size_type n_columns)
- :
- BlockSparsityPatternBase<CompressedSparsityPattern>(n_rows,
- n_columns)
-{}
-
-
-BlockCompressedSparsityPattern::
-BlockCompressedSparsityPattern (
- const std::vector<size_type> &row_indices,
- const std::vector<size_type> &col_indices)
-{
- reinit(row_indices, col_indices);
-}
-
-
-BlockCompressedSparsityPattern::
-BlockCompressedSparsityPattern (
- const BlockIndices &row_indices,
- const BlockIndices &col_indices)
-{
- reinit(row_indices, col_indices);
-}
-
-
-void
-BlockCompressedSparsityPattern::reinit (
- const std::vector<size_type> &row_block_sizes,
- const std::vector<size_type> &col_block_sizes)
-{
- BlockSparsityPatternBase<CompressedSparsityPattern>::reinit(row_block_sizes.size(), col_block_sizes.size());
- for (size_type i=0; i<row_block_sizes.size(); ++i)
- for (size_type j=0; j<col_block_sizes.size(); ++j)
- this->block(i,j).reinit(row_block_sizes[i],col_block_sizes[j]);
- this->collect_sizes();
-}
-
-
-
-void
-BlockCompressedSparsityPattern::reinit (
- const BlockIndices &row_indices,
- const BlockIndices &col_indices)
-{
- BlockSparsityPatternBase<CompressedSparsityPattern>::reinit(row_indices.size(),
- col_indices.size());
- for (size_type i=0; i<row_indices.size(); ++i)
- for (size_type j=0; j<col_indices.size(); ++j)
- this->block(i,j).reinit(row_indices.block_size(i),
- col_indices.block_size(j));
- this->collect_sizes();
-}
-
-
-
-BlockCompressedSetSparsityPattern::BlockCompressedSetSparsityPattern ()
-{}
-
-
-
-BlockCompressedSetSparsityPattern::
-BlockCompressedSetSparsityPattern (
- const size_type n_rows,
- const size_type n_columns)
- :
- BlockSparsityPatternBase<CompressedSetSparsityPattern>(n_rows,
- n_columns)
-{}
-
-
-BlockCompressedSetSparsityPattern::
-BlockCompressedSetSparsityPattern (
- const std::vector<size_type> &row_indices,
- const std::vector<size_type> &col_indices)
-{
- reinit(row_indices, col_indices);
-}
-
-
-BlockCompressedSetSparsityPattern::
-BlockCompressedSetSparsityPattern (
- const BlockIndices &row_indices,
- const BlockIndices &col_indices)
-{
- reinit(row_indices, col_indices);
-}
-
-
-void
-BlockCompressedSetSparsityPattern::reinit (
- const std::vector<size_type> &row_block_sizes,
- const std::vector<size_type> &col_block_sizes)
-{
- BlockSparsityPatternBase<CompressedSetSparsityPattern>::reinit(row_block_sizes.size(), col_block_sizes.size());
- for (size_type i=0; i<row_block_sizes.size(); ++i)
- for (size_type j=0; j<col_block_sizes.size(); ++j)
- this->block(i,j).reinit(row_block_sizes[i],col_block_sizes[j]);
- this->collect_sizes();
-}
-
-
-
-void
-BlockCompressedSetSparsityPattern::reinit (
- const BlockIndices &row_indices,
- const BlockIndices &col_indices)
-{
- BlockSparsityPatternBase<CompressedSetSparsityPattern>::reinit(row_indices.size(),
- col_indices.size());
- for (size_type i=0; i<row_indices.size(); ++i)
- for (size_type j=0; j<col_indices.size(); ++j)
- this->block(i,j).reinit(row_indices.block_size(i),
- col_indices.block_size(j));
- this->collect_sizes();
-}
-BlockCompressedSimpleSparsityPattern::BlockCompressedSimpleSparsityPattern ()
+BlockDynamicSparsityPattern::BlockDynamicSparsityPattern ()
{}
-BlockCompressedSimpleSparsityPattern::
-BlockCompressedSimpleSparsityPattern (const size_type n_rows,
- const size_type n_columns)
+BlockDynamicSparsityPattern::
+BlockDynamicSparsityPattern (const size_type n_rows,
+ const size_type n_columns)
:
- BlockSparsityPatternBase<CompressedSimpleSparsityPattern>(n_rows,
- n_columns)
+ BlockSparsityPatternBase<DynamicSparsityPattern>(n_rows,
+ n_columns)
{}
-BlockCompressedSimpleSparsityPattern::
-BlockCompressedSimpleSparsityPattern (const std::vector<size_type> &row_indices,
- const std::vector<size_type> &col_indices)
+BlockDynamicSparsityPattern::
+BlockDynamicSparsityPattern (const std::vector<size_type> &row_indices,
+ const std::vector<size_type> &col_indices)
:
- BlockSparsityPatternBase<CompressedSimpleSparsityPattern>(row_indices.size(),
- col_indices.size())
+ BlockSparsityPatternBase<DynamicSparsityPattern>(row_indices.size(),
+ col_indices.size())
{
for (size_type i=0; i<row_indices.size(); ++i)
for (size_type j=0; j<col_indices.size(); ++j)
}
-BlockCompressedSimpleSparsityPattern::
-BlockCompressedSimpleSparsityPattern (const std::vector<IndexSet> &partitioning)
+BlockDynamicSparsityPattern::
+BlockDynamicSparsityPattern (const std::vector<IndexSet> &partitioning)
:
- BlockSparsityPatternBase<CompressedSimpleSparsityPattern>(partitioning.size(),
- partitioning.size())
+ BlockSparsityPatternBase<DynamicSparsityPattern>(partitioning.size(),
+ partitioning.size())
{
for (size_type i=0; i<partitioning.size(); ++i)
for (size_type j=0; j<partitioning.size(); ++j)
void
-BlockCompressedSimpleSparsityPattern::reinit (
+BlockDynamicSparsityPattern::reinit (
const std::vector<size_type> &row_block_sizes,
const std::vector<size_type> &col_block_sizes)
{
- BlockSparsityPatternBase<CompressedSimpleSparsityPattern>::
+ BlockSparsityPatternBase<DynamicSparsityPattern>::
reinit(row_block_sizes.size(), col_block_sizes.size());
for (size_type i=0; i<row_block_sizes.size(); ++i)
for (size_type j=0; j<col_block_sizes.size(); ++j)
}
void
-BlockCompressedSimpleSparsityPattern::reinit (
+BlockDynamicSparsityPattern::reinit (
const std::vector< IndexSet > &partitioning)
{
- BlockSparsityPatternBase<CompressedSimpleSparsityPattern>::
+ BlockSparsityPatternBase<DynamicSparsityPattern>::
reinit(partitioning.size(), partitioning.size());
for (size_type i=0; i<partitioning.size(); ++i)
for (size_type j=0; j<partitioning.size(); ++j)
// sparsity pattern
const size_type m_chunks = (csp.n_rows()+chunk_size-1) / chunk_size,
n_chunks = (csp.n_cols()+chunk_size-1) / chunk_size;
- CompressedSimpleSparsityPattern temporary_sp(m_chunks, n_chunks);
+ DynamicSparsityPattern temporary_sp(m_chunks, n_chunks);
for (size_type row = 0; row<csp.n_rows(); ++row)
{
// explicit instantiations
template
-void ChunkSparsityPattern::copy_from<CompressedSparsityPattern> (const CompressedSparsityPattern &,
- const size_type);
-template
-void ChunkSparsityPattern::copy_from<CompressedSetSparsityPattern> (const CompressedSetSparsityPattern &,
- const size_type);
-template
-void ChunkSparsityPattern::copy_from<CompressedSimpleSparsityPattern> (const CompressedSimpleSparsityPattern &,
+void ChunkSparsityPattern::copy_from<DynamicSparsityPattern> (const DynamicSparsityPattern &,
const size_type);
template
void ChunkSparsityPattern::create_from<SparsityPattern>
const unsigned int,
const bool);
template
-void ChunkSparsityPattern::create_from<CompressedSparsityPattern>
+void ChunkSparsityPattern::create_from<DynamicSparsityPattern>
(const unsigned int,
const unsigned int,
const CompressedSparsityPattern &,
const unsigned int,
const bool);
template
-void ChunkSparsityPattern::create_from<CompressedSetSparsityPattern>
-(const unsigned int,
- const unsigned int,
- const CompressedSetSparsityPattern &,
- const unsigned int,
- const bool);
-template
-void ChunkSparsityPattern::create_from<CompressedSimpleSparsityPattern>
-(const unsigned int,
- const unsigned int,
- const CompressedSimpleSparsityPattern &,
- const unsigned int,
- const bool);
-template
void ChunkSparsityPattern::copy_from<float> (const FullMatrix<float> &,
const size_type);
template
+++ /dev/null
-// ---------------------------------------------------------------------
-//
-// Copyright (C) 2001 - 2014 by the deal.II authors
-//
-// This file is part of the deal.II library.
-//
-// The deal.II library is free software; you can use it, redistribute
-// it, and/or modify it under the terms of the GNU Lesser General
-// Public License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-// The full text of the license can be found in the file LICENSE at
-// the top level of the deal.II distribution.
-//
-// ---------------------------------------------------------------------
-
-#include <deal.II/lac/compressed_set_sparsity_pattern.h>
-
-#include <iostream>
-#include <iomanip>
-#include <algorithm>
-#include <cmath>
-#include <numeric>
-#include <functional>
-
-DEAL_II_NAMESPACE_OPEN
-
-
-
-CompressedSetSparsityPattern::CompressedSetSparsityPattern ()
- :
- rows(0),
- cols(0)
-{}
-
-
-
-CompressedSetSparsityPattern::
-CompressedSetSparsityPattern (const CompressedSetSparsityPattern &s)
- :
- Subscriptor(),
- rows(0),
- cols(0)
-{
- Assert (s.rows == 0, ExcInvalidConstructorCall());
- Assert (s.cols == 0, ExcInvalidConstructorCall());
-}
-
-
-
-CompressedSetSparsityPattern::CompressedSetSparsityPattern (const size_type m,
- const size_type n)
- :
- rows(0),
- cols(0)
-{
- reinit (m,n);
-}
-
-
-
-CompressedSetSparsityPattern::CompressedSetSparsityPattern (const size_type n)
- :
- rows(0),
- cols(0)
-{
- reinit (n,n);
-}
-
-
-
-CompressedSetSparsityPattern &
-CompressedSetSparsityPattern::operator = (const CompressedSetSparsityPattern &s)
-{
- Assert (s.rows == 0, ExcInvalidConstructorCall());
- Assert (s.cols == 0, ExcInvalidConstructorCall());
-
- Assert (rows == 0, ExcInvalidConstructorCall());
- Assert (cols == 0, ExcInvalidConstructorCall());
-
- return *this;
-}
-
-
-
-void
-CompressedSetSparsityPattern::reinit (const size_type m,
- const size_type n)
-{
- rows = m;
- cols = n;
-
- std::vector<Line> new_lines (rows);
- lines.swap (new_lines);
-}
-
-
-
-void
-CompressedSetSparsityPattern::compress ()
-{}
-
-
-
-bool
-CompressedSetSparsityPattern::empty () const
-{
- return ((rows==0) && (cols==0));
-}
-
-
-
-CompressedSetSparsityPattern::size_type
-CompressedSetSparsityPattern::max_entries_per_row () const
-{
- size_type m = 0;
- for (size_type i=0; i<rows; ++i)
- {
- m = std::max (m, static_cast<size_type>(lines[i].entries.size()));
- }
-
- return m;
-}
-
-
-
-bool
-CompressedSetSparsityPattern::exists (const size_type i,
- const size_type j) const
-{
- Assert (i<rows, ExcIndexRange(i, 0, rows));
- Assert (j<cols, ExcIndexRange(j, 0, cols));
-
- return (lines[i].entries.find (j) != lines[i].entries.end ());
-}
-
-
-
-void
-CompressedSetSparsityPattern::symmetrize ()
-{
- Assert (rows==cols, ExcNotQuadratic());
-
- // loop over all elements presently
- // in the sparsity pattern and add
- // the transpose element. note:
- //
- // 1. that the sparsity pattern
- // changes which we work on, but
- // not the present row
- //
- // 2. that the @p{add} function can
- // be called on elements that
- // already exist without any harm
- for (size_type row=0; row<rows; ++row)
- {
- for (std::set<size_type>::const_iterator
- j=lines[row].entries.begin();
- j != lines[row].entries.end();
- ++j)
- // add the transpose entry if
- // this is not the diagonal
- if (row != *j)
- add (*j, row);
- }
-}
-
-
-
-void
-CompressedSetSparsityPattern::print (std::ostream &out) const
-{
- AssertThrow (out, ExcIO());
-
- for (size_type row=0; row<rows; ++row)
- {
- out << '[' << row;
-
- for (std::set<size_type >::const_iterator
- j=lines[row].entries.begin();
- j != lines[row].entries.end(); ++j)
- out << ',' << *j;
-
- out << ']' << std::endl;
- }
-
- AssertThrow (out, ExcIO());
-}
-
-
-
-void
-CompressedSetSparsityPattern::print_gnuplot (std::ostream &out) const
-{
- AssertThrow (out, ExcIO());
-
- for (size_type row=0; row<rows; ++row)
- {
- for (std::set<size_type>::const_iterator
- j=lines[row].entries.begin();
- j != lines[row].entries.end(); ++j)
- // while matrix entries are usually
- // written (i,j), with i vertical and
- // j horizontal, gnuplot output is
- // x-y, that is we have to exchange
- // the order of output
- out << *j << " " << -static_cast<signed int>(row) << std::endl;
- }
-
-
- AssertThrow (out, ExcIO());
-}
-
-
-
-CompressedSetSparsityPattern::size_type
-CompressedSetSparsityPattern::bandwidth () const
-{
- size_type b=0;
- for (size_type row=0; row<rows; ++row)
- {
- for (std::set<size_type>::const_iterator
- j=lines[row].entries.begin();
- j != lines[row].entries.end(); ++j)
- if (static_cast<size_type>(std::abs(static_cast<int>(row-*j))) > b)
- b = std::abs(static_cast<signed int>(row-*j));
- }
-
- return b;
-}
-
-
-
-CompressedSetSparsityPattern::size_type
-CompressedSetSparsityPattern::n_nonzero_elements () const
-{
- size_type n=0;
- for (size_type i=0; i<rows; ++i)
- {
- n += lines[i].entries.size();
- }
-
- return n;
-}
-
-DEAL_II_NAMESPACE_CLOSE
+++ /dev/null
-// ---------------------------------------------------------------------
-//
-// Copyright (C) 2001 - 2014 by the deal.II authors
-//
-// This file is part of the deal.II library.
-//
-// The deal.II library is free software; you can use it, redistribute
-// it, and/or modify it under the terms of the GNU Lesser General
-// Public License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-// The full text of the license can be found in the file LICENSE at
-// the top level of the deal.II distribution.
-//
-// ---------------------------------------------------------------------
-
-#include <deal.II/lac/compressed_sparsity_pattern.h>
-
-#include <iostream>
-#include <iomanip>
-#include <algorithm>
-#include <cmath>
-#include <numeric>
-#include <functional>
-
-DEAL_II_NAMESPACE_OPEN
-
-
-#ifdef DEAL_II_MSVC
-__declspec(selectany) // weak external binding because of multiple link error
-#endif
-const unsigned int CompressedSparsityPattern::Line::cache_size;
-
-
-
-// This function was originally inlined, because it was called very
-// often without any need, because cache_entries==0. On the other
-// hand, it is very long and causes linker warnings on certain
-// systems.
-
-// Therefore, we require now, that the caller checks if this function
-// is necessary and only calls it, if it is actually used. Since it is
-// called less often, it is removed from the inlined section.
-void
-CompressedSparsityPattern::Line::flush_cache () const
-{
- // Make sure the caller checked
- // necessity of this function.
- Assert(cache_entries != 0, ExcInternalError());
-
- // first sort the entries in the cache, so
- // that it is easier to merge it with the
- // main array. note that due to the way
- // add() inserts elements, there can be no
- // duplicates in the cache
- //
- // do the sorting in a way that is fast for
- // the small cache sizes we have
- // here. basically, use bubble sort
- switch (cache_entries)
- {
- case 1:
- {
- break;
- }
-
- case 2:
- {
- if (cache[1] < cache[0])
- std::swap (cache[0], cache[1]);
- break;
- }
-
- case 3:
- {
- if (cache[1] < cache[0])
- std::swap (cache[0], cache[1]);
- if (cache[2] < cache[1])
- std::swap (cache[1], cache[2]);
- if (cache[1] < cache[0])
- std::swap (cache[0], cache[1]);
- break;
- }
-
- case 4:
- case 5:
- case 6:
- case 7:
- {
- for (unsigned int i=0; i<cache_entries; ++i)
- for (unsigned int j=i+1; j<cache_entries; ++j)
- if (cache[j] < cache[i])
- std::swap (cache[i], cache[j]);
- break;
- }
-
- default:
- {
- std::sort (&cache[0], &cache[cache_entries]);
- break;
- }
- }
-
- // TODO: could use the add_entries
- // function of the constraint line for
- // doing this, but that one is
- // non-const. Still need to figure out
- // how to do that.
-
- // next job is to merge the two
- // arrays. special case the case that the
- // original array is empty.
- if (entries.size() == 0)
- {
- entries.resize (cache_entries);
- for (unsigned int i=0; i<cache_entries; ++i)
- entries[i] = cache[i];
- }
- else
- {
- // first count how many of the cache
- // entries are already in the main
- // array, so that we can efficiently
- // allocate memory
- unsigned int n_new_entries = 0;
- {
- unsigned int cache_position = 0;
- unsigned int entry_position = 0;
- while ((entry_position<entries.size()) &&
- (cache_position<cache_entries))
- {
- ++n_new_entries;
- if (entries[entry_position] < cache[cache_position])
- ++entry_position;
- else if (entries[entry_position] == cache[cache_position])
- {
- ++entry_position;
- ++cache_position;
- }
- else
- ++cache_position;
- }
-
- // scoop up leftovers in arrays
- n_new_entries += (entries.size() - entry_position) +
- (cache_entries - cache_position);
- }
-
- // then allocate new memory and merge
- // arrays, if there are any entries at
- // all that need to be merged
- Assert (n_new_entries >= entries.size(),
- ExcInternalError());
- if (n_new_entries > entries.size())
- {
- std::vector<types::global_dof_index> new_entries;
- new_entries.reserve (n_new_entries);
- unsigned int cache_position = 0;
- unsigned int entry_position = 0;
- while ((entry_position<entries.size()) &&
- (cache_position<cache_entries))
- if (entries[entry_position] < cache[cache_position])
- {
- new_entries.push_back (entries[entry_position]);
- ++entry_position;
- }
- else if (entries[entry_position] == cache[cache_position])
- {
- new_entries.push_back (entries[entry_position]);
- ++entry_position;
- ++cache_position;
- }
- else
- {
- new_entries.push_back (cache[cache_position]);
- ++cache_position;
- }
-
- // copy remaining elements from the
- // array that we haven't
- // finished. note that at most one
- // of the following loops will run
- // at all
- for (; entry_position < entries.size(); ++entry_position)
- new_entries.push_back (entries[entry_position]);
- for (; cache_position < cache_entries; ++cache_position)
- new_entries.push_back (cache[cache_position]);
-
- Assert (new_entries.size() == n_new_entries,
- ExcInternalError());
-
- // finally swap old and new array,
- // and set cache size to zero
- new_entries.swap (entries);
- }
- }
-
- cache_entries = 0;
-}
-
-
-
-template <typename ForwardIterator>
-void
-CompressedSparsityPattern::Line::add_entries (ForwardIterator begin,
- ForwardIterator end,
- const bool indices_are_sorted)
-{
- // use the same code as when flushing the
- // cache in case we have many (more than
- // three) entries in a sorted
- // list. Otherwise, go on to the single
- // add() function.
- const int n_elements = end - begin;
- if (n_elements <= 0)
- return;
-
- const unsigned int n_cols = static_cast<unsigned int>(n_elements);
-
- if (indices_are_sorted == true)
- {
-
- // next job is to merge the two
- // arrays. special case the case that the
- // original array is empty.
- if (entries.size() == 0)
- {
- entries.resize (n_cols);
- ForwardIterator my_it = begin;
- for (unsigned int i=0; i<n_cols; ++i)
- entries[i] = *my_it++;
- }
- else
- {
- // first count how many of the cache
- // entries are already in the main
- // array, so that we can efficiently
- // allocate memory
- unsigned int n_new_entries = 0;
- {
- unsigned int entry_position = 0;
- ForwardIterator my_it = begin;
- while ((entry_position<entries.size()) &&
- (my_it != end))
- {
- ++n_new_entries;
- if (entries[entry_position] < *my_it)
- ++entry_position;
- else if (entries[entry_position] == *my_it)
- {
- ++entry_position;
- ++my_it;
- }
- else
- ++my_it;
- }
-
- // scoop up leftovers in arrays
- n_new_entries += (entries.size() - entry_position) +
- (end - my_it);
- }
-
- // then allocate new memory and merge
- // arrays, if there are any entries at
- // all that need to be merged
- Assert (n_new_entries >= entries.size(),
- ExcInternalError());
- if (n_new_entries > entries.size())
- {
- std::vector<types::global_dof_index> new_entries;
- new_entries.reserve (n_new_entries);
- ForwardIterator my_it = begin;
- unsigned int entry_position = 0;
- while ((entry_position<entries.size()) &&
- (my_it != end))
- if (entries[entry_position] < *my_it)
- {
- new_entries.push_back (entries[entry_position]);
- ++entry_position;
- }
- else if (entries[entry_position] == *my_it)
- {
- new_entries.push_back (entries[entry_position]);
- ++entry_position;
- ++my_it;
- }
- else
- {
- new_entries.push_back (*my_it);
- ++my_it;
- }
-
- // copy remaining elements from the
- // array that we haven't
- // finished. note that at most one
- // of the following loops will run
- // at all
- for (; entry_position < entries.size(); ++entry_position)
- new_entries.push_back (entries[entry_position]);
- for (; my_it != end; ++my_it)
- new_entries.push_back (*my_it);
-
- Assert (new_entries.size() == n_new_entries,
- ExcInternalError());
-
- // finally swap old and new array,
- // and set cache size to zero
- new_entries.swap (entries);
- }
- }
- return;
- }
-
- // otherwise, insert the indices one
- // after each other
- for (ForwardIterator it = begin; it != end; ++it)
- add (*it);
-}
-
-
-
-CompressedSparsityPattern::CompressedSparsityPattern ()
- :
- rows(0),
- cols(0)
-{}
-
-
-
-CompressedSparsityPattern::
-CompressedSparsityPattern (const CompressedSparsityPattern &s)
- :
- Subscriptor(),
- rows(0),
- cols(0)
-{
- Assert (s.rows == 0, ExcInvalidConstructorCall());
- Assert (s.cols == 0, ExcInvalidConstructorCall());
-}
-
-
-
-CompressedSparsityPattern::CompressedSparsityPattern (const size_type m,
- const size_type n)
- :
- rows(0),
- cols(0)
-{
- reinit (m,n);
-}
-
-
-
-CompressedSparsityPattern::CompressedSparsityPattern (const size_type n)
- :
- rows(0),
- cols(0)
-{
- reinit (n,n);
-}
-
-
-
-CompressedSparsityPattern &
-CompressedSparsityPattern::operator = (const CompressedSparsityPattern &s)
-{
- Assert (s.rows == 0, ExcInvalidConstructorCall());
- Assert (s.cols == 0, ExcInvalidConstructorCall());
-
- Assert (rows == 0, ExcInvalidConstructorCall());
- Assert (cols == 0, ExcInvalidConstructorCall());
-
- return *this;
-}
-
-
-
-void
-CompressedSparsityPattern::reinit (const size_type m,
- const size_type n)
-{
- rows = m;
- cols = n;
-
- std::vector<Line> new_lines (rows);
- lines.swap (new_lines);
-}
-
-
-
-void
-CompressedSparsityPattern::compress ()
-{}
-
-
-
-bool
-CompressedSparsityPattern::empty () const
-{
- return ((rows==0) && (cols==0));
-}
-
-
-
-CompressedSparsityPattern::size_type
-CompressedSparsityPattern::max_entries_per_row () const
-{
- size_type m = 0;
- for (size_type i=0; i<rows; ++i)
- {
- if (lines[i].cache_entries != 0)
- lines[i].flush_cache ();
- m = std::max (m, static_cast<size_type>(lines[i].entries.size()));
- }
-
- return m;
-}
-
-
-
-bool
-CompressedSparsityPattern::exists (const size_type i,
- const size_type j) const
-{
- Assert (i<rows, ExcIndexRange(i, 0, rows));
- Assert (j<cols, ExcIndexRange(j, 0, cols));
-
- if (lines[i].cache_entries != 0)
- lines[i].flush_cache();
- return std::binary_search (lines[i].entries.begin(),
- lines[i].entries.end(),
- j);
-}
-
-
-
-void
-CompressedSparsityPattern::symmetrize ()
-{
- Assert (rows==cols, ExcNotQuadratic());
-
- // loop over all elements presently
- // in the sparsity pattern and add
- // the transpose element. note:
- //
- // 1. that the sparsity pattern
- // changes which we work on, but
- // not the present row
- //
- // 2. that the @p{add} function can
- // be called on elements that
- // already exist without any harm
- for (size_type row=0; row<rows; ++row)
- {
- if (lines[row].cache_entries != 0)
- lines[row].flush_cache ();
- for (std::vector<size_type>::const_iterator
- j=lines[row].entries.begin();
- j != lines[row].entries.end();
- ++j)
- // add the transpose entry if
- // this is not the diagonal
- if (row != *j)
- add (*j, row);
- }
-}
-
-
-
-void
-CompressedSparsityPattern::print (std::ostream &out) const
-{
- for (size_type row=0; row<rows; ++row)
- {
- if (lines[row].cache_entries != 0)
- lines[row].flush_cache ();
-
- out << '[' << row;
-
- for (std::vector<size_type>::const_iterator
- j=lines[row].entries.begin();
- j != lines[row].entries.end(); ++j)
- out << ',' << *j;
-
- out << ']' << std::endl;
- }
-
- AssertThrow (out, ExcIO());
-}
-
-
-
-void
-CompressedSparsityPattern::print_gnuplot (std::ostream &out) const
-{
- for (size_type row=0; row<rows; ++row)
- {
- if (lines[row].cache_entries != 0)
- lines[row].flush_cache ();
- for (std::vector<size_type>::const_iterator
- j=lines[row].entries.begin();
- j != lines[row].entries.end(); ++j)
- // while matrix entries are usually
- // written (i,j), with i vertical and
- // j horizontal, gnuplot output is
- // x-y, that is we have to exchange
- // the order of output
- out << *j << " " << -static_cast<signed int>(row) << std::endl;
- }
-
- AssertThrow (out, ExcIO());
-}
-
-
-
-CompressedSparsityPattern::size_type
-CompressedSparsityPattern::bandwidth () const
-{
- size_type b=0;
- for (size_type row=0; row<rows; ++row)
- {
- if (lines[row].cache_entries != 0)
- lines[row].flush_cache ();
-
- for (std::vector<size_type>::const_iterator
- j=lines[row].entries.begin();
- j != lines[row].entries.end(); ++j)
- if (static_cast<size_type>(std::abs(static_cast<int>(row-*j))) > b)
- b = std::abs(static_cast<signed int>(row-*j));
- }
-
- return b;
-}
-
-
-
-CompressedSparsityPattern::size_type
-CompressedSparsityPattern::n_nonzero_elements () const
-{
- size_type n=0;
- for (size_type i=0; i<rows; ++i)
- {
- if (lines[i].cache_entries != 0)
- lines[i].flush_cache ();
- n += lines[i].entries.size();
- }
-
- return n;
-}
-
-
-// explicit instantiations
-template void CompressedSparsityPattern::Line::add_entries(size_type *,
- size_type *,
- const bool);
-template void CompressedSparsityPattern::Line::add_entries(const size_type *,
- const size_type *,
- const bool);
-#ifndef DEAL_II_VECTOR_ITERATOR_IS_POINTER
-template void CompressedSparsityPattern::Line::
-add_entries(std::vector<size_type>::iterator,
- std::vector<size_type>::iterator,
- const bool);
-#endif
-
-DEAL_II_NAMESPACE_CLOSE
#include <deal.II/lac/constraint_matrix.templates.h>
#include <deal.II/base/memory_consumption.h>
-#include <deal.II/lac/compressed_sparsity_pattern.h>
-#include <deal.II/lac/compressed_set_sparsity_pattern.h>
-#include <deal.II/lac/compressed_simple_sparsity_pattern.h>
+#include <deal.II/lac/dynamic_sparsity_pattern.h>
#include <deal.II/lac/block_vector.h>
#include <deal.II/lac/block_sparse_matrix.h>
#include <deal.II/lac/sparse_matrix_ez.h>
-void ConstraintMatrix::condense (CompressedSparsityPattern &sparsity) const
-{
- Assert (sorted == true, ExcMatrixNotClosed());
- Assert (sparsity.n_rows() == sparsity.n_cols(),
- ExcNotQuadratic());
-
- // store for each index whether it must be distributed or not. If entry
- // is numbers::invalid_unsigned_int, no distribution is necessary.
- // otherwise, the number states which line in the constraint matrix
- // handles this index
- std::vector<size_type> distribute(sparsity.n_rows(),
- numbers::invalid_size_type);
-
- for (size_type c=0; c<lines.size(); ++c)
- distribute[lines[c].line] = c;
-
- const size_type n_rows = sparsity.n_rows();
- for (size_type row=0; row<n_rows; ++row)
- {
- if (distribute[row] == numbers::invalid_size_type)
- // regular line. loop over cols. note that as we proceed to
- // distribute cols, the loop may get longer
- for (size_type j=0; j<sparsity.row_length(row); ++j)
- {
- const size_type column = sparsity.column_number(row,j);
-
- if (distribute[column] != numbers::invalid_size_type)
- {
- // distribute entry at regular row @p{row} and irregular
- // column column. note that this changes the line we are
- // presently working on: we add additional entries. if we
- // add another entry at a column behind the present one, we
- // will encounter it later on (but since it can't be
- // further constrained, won't have to do anything about
- // it). if we add it up front of the present column, we
- // will find the present column later on again as it was
- // shifted back (again nothing happens, in particular no
- // endless loop, as when we encounter it the second time we
- // won't be able to add more entries as they all already
- // exist, but we do the same work more often than
- // necessary, and the loop gets longer), so move the cursor
- // one to the right in the case that we add an entry up
- // front that did not exist before. check whether it
- // existed before by tracking the length of this row
- size_type old_rowlength = sparsity.row_length(row);
- for (size_type q=0;
- q!=lines[distribute[column]].entries.size();
- ++q)
- {
- const size_type
- new_col = lines[distribute[column]].entries[q].first;
-
- sparsity.add (row, new_col);
- const size_type new_rowlength = sparsity.row_length(row);
- if ((new_col < column) && (old_rowlength != new_rowlength))
- ++j;
- old_rowlength = new_rowlength;
- };
- };
- }
- else
- // row must be distributed
- for (size_type j=0; j<sparsity.row_length(row); ++j)
- {
- const size_type column = sparsity.column_number(row,j);
-
- if (distribute[column] == numbers::invalid_size_type)
- // distribute entry at irregular row @p{row} and regular
- // column sparsity.colnums[j]
- for (size_type q=0;
- q!=lines[distribute[row]].entries.size(); ++q)
- sparsity.add (lines[distribute[row]].entries[q].first,
- column);
- else
- // distribute entry at irregular row @p{row} and irregular
- // column sparsity.get_column_numbers()[j]
- for (size_type p=0; p!=lines[distribute[row]].entries.size(); ++p)
- for (size_type q=0;
- q!=lines[distribute[sparsity.column_number(row,j)]]
- .entries.size(); ++q)
- sparsity.add (lines[distribute[row]].entries[p].first,
- lines[distribute[sparsity.column_number(row,j)]]
- .entries[q].first);
- };
- };
-}
-
-
-
-void ConstraintMatrix::condense (CompressedSetSparsityPattern &sparsity) const
-{
- Assert (sorted == true, ExcMatrixNotClosed());
- Assert (sparsity.n_rows() == sparsity.n_cols(),
- ExcNotQuadratic());
-
- // store for each index whether it must be distributed or not. If entry
- // is numbers::invalid_unsigned_int, no distribution is necessary.
- // otherwise, the number states which line in the constraint matrix
- // handles this index
- std::vector<size_type> distribute(sparsity.n_rows(),
- numbers::invalid_size_type);
-
- for (size_type c=0; c<lines.size(); ++c)
- distribute[lines[c].line] = c;
-
- const size_type n_rows = sparsity.n_rows();
- for (size_type row=0; row<n_rows; ++row)
- {
- if (distribute[row] == numbers::invalid_size_type)
- {
- // regular line. loop over cols. note that as we proceed to
- // distribute cols, the loop may get longer
- CompressedSetSparsityPattern::row_iterator col_num = sparsity.row_begin (row);
-
- for (; col_num != sparsity.row_end (row); ++col_num)
- {
- const size_type column = *col_num;
-
- if (distribute[column] != numbers::invalid_size_type)
- {
- // row
- for (size_type q=0;
- q!=lines[distribute[column]].entries.size();
- ++q)
- {
- const size_type
- new_col = lines[distribute[column]].entries[q].first;
-
- sparsity.add (row, new_col);
- }
- }
- }
- }
- else
- // row must be distributed
- {
- CompressedSetSparsityPattern::row_iterator col_num = sparsity.row_begin (row);
-
- for (; col_num != sparsity.row_end (row); ++col_num)
- {
- const size_type column = *col_num;
-
- if (distribute[column] == numbers::invalid_size_type)
- // distribute entry at irregular row @p{row} and regular
- // column sparsity.colnums[j]
- for (size_type q=0;
- q!=lines[distribute[row]].entries.size(); ++q)
- sparsity.add (lines[distribute[row]].entries[q].first,
- column);
- else
- // distribute entry at irregular row @p{row} and irregular
- // column sparsity.get_column_numbers()[j]
- for (size_type p=0; p!=lines[distribute[row]].entries.size(); ++p)
- for (size_type q=0;
- q!=lines[distribute[column]]
- .entries.size(); ++q)
- sparsity.add (lines[distribute[row]].entries[p].first,
- lines[distribute[column]]
- .entries[q].first);
- };
- }
- };
-}
-
-
-
-void ConstraintMatrix::condense (CompressedSimpleSparsityPattern &sparsity) const
+void ConstraintMatrix::condense (DynamicSparsityPattern &sparsity) const
{
Assert (sorted == true, ExcMatrixNotClosed());
Assert (sparsity.n_rows() == sparsity.n_cols(),
-void ConstraintMatrix::condense (BlockCompressedSparsityPattern &sparsity) const
-{
- Assert (sorted == true, ExcMatrixNotClosed());
- Assert (sparsity.n_rows() == sparsity.n_cols(),
- ExcNotQuadratic());
- Assert (sparsity.n_block_rows() == sparsity.n_block_cols(),
- ExcNotQuadratic());
- Assert (sparsity.get_column_indices() == sparsity.get_row_indices(),
- ExcNotQuadratic());
-
- const BlockIndices &
- index_mapping = sparsity.get_column_indices();
-
- const size_type n_blocks = sparsity.n_block_rows();
-
- // store for each index whether it must be distributed or not. If entry
- // is numbers::invalid_unsigned_int, no distribution is necessary.
- // otherwise, the number states which line in the constraint matrix
- // handles this index
- std::vector<size_type> distribute (sparsity.n_rows(),
- numbers::invalid_size_type);
-
- for (size_type c=0; c<lines.size(); ++c)
- distribute[lines[c].line] = static_cast<signed int>(c);
-
- const size_type n_rows = sparsity.n_rows();
- for (size_type row=0; row<n_rows; ++row)
- {
- // get index of this row within the blocks
- const std::pair<size_type,size_type>
- block_index = index_mapping.global_to_local(row);
- const size_type block_row = block_index.first;
- const size_type local_row = block_index.second;
-
- if (distribute[row] == numbers::invalid_size_type)
- // regular line. loop over all columns and see whether this column
- // must be distributed. note that as we proceed to distribute cols,
- // the loop over cols may get longer.
- //
- // don't try to be clever here as in the algorithm for the
- // CompressedSparsityPattern, as that would be much more
- // complicated here. after all, we know that compressed patterns
- // are inefficient...
- {
-
- // to loop over all entries in this row, we have to loop over all
- // blocks in this blockrow and the corresponding row therein
- for (size_type block_col=0; block_col<n_blocks; ++block_col)
- {
- const CompressedSparsityPattern &
- block_sparsity = sparsity.block(block_row, block_col);
-
- for (size_type j=0; j<block_sparsity.row_length(local_row); ++j)
- {
- const size_type global_col
- = index_mapping.local_to_global(block_col,
- block_sparsity.column_number(local_row,j));
-
- if (distribute[global_col] != numbers::invalid_size_type)
- // distribute entry at regular row @p{row} and
- // irregular column global_col
- {
- for (size_type q=0;
- q!=lines[distribute[global_col]]
- .entries.size(); ++q)
- sparsity.add (row,
- lines[distribute[global_col]].entries[q].first);
- };
- };
- };
- }
- else
- {
- // row must be distributed. split the whole row into the chunks
- // defined by the blocks
- for (size_type block_col=0; block_col<n_blocks; ++block_col)
- {
- const CompressedSparsityPattern &
- block_sparsity = sparsity.block(block_row,block_col);
-
- for (size_type j=0; j<block_sparsity.row_length(local_row); ++j)
- {
- const size_type global_col
- = index_mapping.local_to_global (block_col,
- block_sparsity.column_number(local_row,j));
-
- if (distribute[global_col] == numbers::invalid_size_type)
- // distribute entry at irregular row @p{row} and
- // regular column global_col.
- {
- for (size_type q=0; q!=lines[distribute[row]].entries.size(); ++q)
- sparsity.add (lines[distribute[row]].entries[q].first,
- global_col);
- }
- else
- // distribute entry at irregular row @p{row} and
- // irregular column @p{global_col}
- {
- for (size_type p=0; p!=lines[distribute[row]].entries.size(); ++p)
- for (size_type q=0; q!=lines[distribute[global_col]].entries.size(); ++q)
- sparsity.add (lines[distribute[row]].entries[p].first,
- lines[distribute[global_col]].entries[q].first);
- };
- };
- };
- };
- };
-}
-
-
-
-void ConstraintMatrix::condense (BlockCompressedSetSparsityPattern &sparsity) const
-{
- Assert (sorted == true, ExcMatrixNotClosed());
- Assert (sparsity.n_rows() == sparsity.n_cols(),
- ExcNotQuadratic());
- Assert (sparsity.n_block_rows() == sparsity.n_block_cols(),
- ExcNotQuadratic());
- Assert (sparsity.get_column_indices() == sparsity.get_row_indices(),
- ExcNotQuadratic());
-
- const BlockIndices &
- index_mapping = sparsity.get_column_indices();
-
- const size_type n_blocks = sparsity.n_block_rows();
-
- // store for each index whether it must be distributed or not. If entry
- // is numbers::invalid_unsigned_int, no distribution is necessary.
- // otherwise, the number states which line in the constraint matrix
- // handles this index
- std::vector<size_type> distribute (sparsity.n_rows(),
- numbers::invalid_size_type);
-
- for (size_type c=0; c<lines.size(); ++c)
- distribute[lines[c].line] = static_cast<signed int>(c);
-
- const size_type n_rows = sparsity.n_rows();
- for (size_type row=0; row<n_rows; ++row)
- {
- // get index of this row within the blocks
- const std::pair<size_type,size_type>
- block_index = index_mapping.global_to_local(row);
- const size_type block_row = block_index.first;
- const size_type local_row = block_index.second;
-
- if (distribute[row] == numbers::invalid_size_type)
- // regular line. loop over all columns and see whether this column
- // must be distributed. note that as we proceed to distribute cols,
- // the loop over cols may get longer.
- //
- // don't try to be clever here as in the algorithm for the
- // CompressedSparsityPattern, as that would be much more
- // complicated here. after all, we know that compressed patterns
- // are inefficient...
- {
-
- // to loop over all entries in this row, we have to loop over all
- // blocks in this blockrow and the corresponding row therein
- for (size_type block_col=0; block_col<n_blocks; ++block_col)
- {
- const CompressedSetSparsityPattern &
- block_sparsity = sparsity.block(block_row, block_col);
-
- for (CompressedSetSparsityPattern::row_iterator
- j = block_sparsity.row_begin(local_row);
- j != block_sparsity.row_end(local_row); ++j)
- {
- const size_type global_col
- = index_mapping.local_to_global(block_col, *j);
-
- if (distribute[global_col] != numbers::invalid_size_type)
- // distribute entry at regular row @p{row} and
- // irregular column global_col
- {
- for (size_type q=0;
- q!=lines[distribute[global_col]]
- .entries.size(); ++q)
- sparsity.add (row,
- lines[distribute[global_col]].entries[q].first);
- };
- };
- };
- }
- else
- {
- // row must be distributed. split the whole row into the chunks
- // defined by the blocks
- for (size_type block_col=0; block_col<n_blocks; ++block_col)
- {
- const CompressedSetSparsityPattern &
- block_sparsity = sparsity.block(block_row,block_col);
-
- for (CompressedSetSparsityPattern::row_iterator
- j = block_sparsity.row_begin(local_row);
- j != block_sparsity.row_end(local_row); ++j)
- {
- const size_type global_col
- = index_mapping.local_to_global (block_col, *j);
-
- if (distribute[global_col] == numbers::invalid_size_type)
- // distribute entry at irregular row @p{row} and
- // regular column global_col.
- {
- for (size_type q=0; q!=lines[distribute[row]].entries.size(); ++q)
- sparsity.add (lines[distribute[row]].entries[q].first,
- global_col);
- }
- else
- // distribute entry at irregular row @p{row} and
- // irregular column @p{global_col}
- {
- for (size_type p=0; p!=lines[distribute[row]].entries.size(); ++p)
- for (size_type q=0; q!=lines[distribute[global_col]].entries.size(); ++q)
- sparsity.add (lines[distribute[row]].entries[p].first,
- lines[distribute[global_col]].entries[q].first);
- };
- };
- };
- };
- };
-}
-
-
-void ConstraintMatrix::condense (BlockCompressedSimpleSparsityPattern &sparsity) const
+void ConstraintMatrix::condense (BlockDynamicSparsityPattern &sparsity) const
{
Assert (sorted == true, ExcMatrixNotClosed());
Assert (sparsity.n_rows() == sparsity.n_cols(),
// blocks in this blockrow and the corresponding row therein
for (size_type block_col=0; block_col<n_blocks; ++block_col)
{
- const CompressedSimpleSparsityPattern &
+ const DynamicSparsityPattern &
block_sparsity = sparsity.block(block_row, block_col);
for (size_type j=0; j<block_sparsity.row_length(local_row); ++j)
// defined by the blocks
for (size_type block_col=0; block_col<n_blocks; ++block_col)
{
- const CompressedSimpleSparsityPattern &
+ const DynamicSparsityPattern &
block_sparsity = sparsity.block(block_row,block_col);
for (size_type j=0; j<block_sparsity.row_length(local_row); ++j)
const Table<2,bool> &) const
SPARSITY_FUNCTIONS(SparsityPattern);
-SPARSITY_FUNCTIONS(CompressedSparsityPattern);
-SPARSITY_FUNCTIONS(CompressedSetSparsityPattern);
-SPARSITY_FUNCTIONS(CompressedSimpleSparsityPattern);
+SPARSITY_FUNCTIONS(DynamicSparsityPattern);
BLOCK_SPARSITY_FUNCTIONS(BlockSparsityPattern);
-BLOCK_SPARSITY_FUNCTIONS(BlockCompressedSparsityPattern);
-BLOCK_SPARSITY_FUNCTIONS(BlockCompressedSetSparsityPattern);
-BLOCK_SPARSITY_FUNCTIONS(BlockCompressedSimpleSparsityPattern);
+BLOCK_SPARSITY_FUNCTIONS(BlockDynamicSparsityPattern);
#ifdef DEAL_II_WITH_TRILINOS
SPARSITY_FUNCTIONS(TrilinosWrappers::SparsityPattern);
// ---------------------------------------------------------------------
//
-// Copyright (C) 2008 - 2014 by the deal.II authors
+// Copyright (C) 2008 - 2015 by the deal.II authors
//
// This file is part of the deal.II library.
//
//
// ---------------------------------------------------------------------
-#include <deal.II/lac/compressed_simple_sparsity_pattern.h>
+#include <deal.II/lac/dynamic_sparsity_pattern.h>
#include <deal.II/base/memory_consumption.h>
#include <algorithm>
template <typename ForwardIterator>
void
-CompressedSimpleSparsityPattern::Line::add_entries (ForwardIterator begin,
- ForwardIterator end,
- const bool indices_are_sorted)
+DynamicSparsityPattern::Line::add_entries (ForwardIterator begin,
+ ForwardIterator end,
+ const bool indices_are_sorted)
{
const int n_elements = end - begin;
if (n_elements <= 0)
}
-CompressedSimpleSparsityPattern::size_type
-CompressedSimpleSparsityPattern::Line::memory_consumption () const
+DynamicSparsityPattern::size_type
+DynamicSparsityPattern::Line::memory_consumption () const
{
return entries.capacity()*sizeof(size_type)+sizeof(Line);
}
-CompressedSimpleSparsityPattern::CompressedSimpleSparsityPattern ()
+DynamicSparsityPattern::DynamicSparsityPattern ()
:
rows(0),
cols(0),
-CompressedSimpleSparsityPattern::
-CompressedSimpleSparsityPattern (const CompressedSimpleSparsityPattern &s)
+DynamicSparsityPattern::
+DynamicSparsityPattern (const DynamicSparsityPattern &s)
:
Subscriptor(),
rows(0),
-CompressedSimpleSparsityPattern::CompressedSimpleSparsityPattern (const size_type m,
- const size_type n,
- const IndexSet &rowset_
- )
+DynamicSparsityPattern::DynamicSparsityPattern (const size_type m,
+ const size_type n,
+ const IndexSet &rowset_
+ )
:
rows(0),
cols(0),
}
-CompressedSimpleSparsityPattern::CompressedSimpleSparsityPattern (const IndexSet &rowset_)
+DynamicSparsityPattern::DynamicSparsityPattern (const IndexSet &rowset_)
:
rows(0),
cols(0),
}
-CompressedSimpleSparsityPattern::CompressedSimpleSparsityPattern (const size_type n)
+DynamicSparsityPattern::DynamicSparsityPattern (const size_type n)
:
rows(0),
cols(0),
-CompressedSimpleSparsityPattern &
-CompressedSimpleSparsityPattern::operator = (const CompressedSimpleSparsityPattern &s)
+DynamicSparsityPattern &
+DynamicSparsityPattern::operator = (const DynamicSparsityPattern &s)
{
Assert (s.rows == 0, ExcInvalidConstructorCall());
Assert (s.cols == 0, ExcInvalidConstructorCall());
void
-CompressedSimpleSparsityPattern::reinit (const size_type m,
- const size_type n,
- const IndexSet &rowset_)
+DynamicSparsityPattern::reinit (const size_type m,
+ const size_type n,
+ const IndexSet &rowset_)
{
rows = m;
cols = n;
void
-CompressedSimpleSparsityPattern::compress ()
+DynamicSparsityPattern::compress ()
{}
bool
-CompressedSimpleSparsityPattern::empty () const
+DynamicSparsityPattern::empty () const
{
return ((rows==0) && (cols==0));
}
-CompressedSimpleSparsityPattern::size_type
-CompressedSimpleSparsityPattern::max_entries_per_row () const
+DynamicSparsityPattern::size_type
+DynamicSparsityPattern::max_entries_per_row () const
{
size_type m = 0;
for (size_type i=0; i<lines.size(); ++i)
bool
-CompressedSimpleSparsityPattern::exists (const size_type i,
- const size_type j) const
+DynamicSparsityPattern::exists (const size_type i,
+ const size_type j) const
{
Assert (i<rows, ExcIndexRange(i, 0, rows));
Assert (j<cols, ExcIndexRange(j, 0, cols));
void
-CompressedSimpleSparsityPattern::symmetrize ()
+DynamicSparsityPattern::symmetrize ()
{
Assert (rows==cols, ExcNotQuadratic());
void
-CompressedSimpleSparsityPattern::print (std::ostream &out) const
+DynamicSparsityPattern::print (std::ostream &out) const
{
for (size_type row=0; row<lines.size(); ++row)
{
void
-CompressedSimpleSparsityPattern::print_gnuplot (std::ostream &out) const
+DynamicSparsityPattern::print_gnuplot (std::ostream &out) const
{
for (size_type row=0; row<lines.size(); ++row)
{
-CompressedSimpleSparsityPattern::size_type
-CompressedSimpleSparsityPattern::bandwidth () const
+DynamicSparsityPattern::size_type
+DynamicSparsityPattern::bandwidth () const
{
size_type b=0;
for (size_type row=0; row<lines.size(); ++row)
-CompressedSimpleSparsityPattern::size_type
-CompressedSimpleSparsityPattern::n_nonzero_elements () const
+DynamicSparsityPattern::size_type
+DynamicSparsityPattern::n_nonzero_elements () const
{
size_type n=0;
for (size_type i=0; i<lines.size(); ++i)
}
-CompressedSimpleSparsityPattern::size_type
-CompressedSimpleSparsityPattern::memory_consumption () const
+DynamicSparsityPattern::size_type
+DynamicSparsityPattern::memory_consumption () const
{
//TODO: IndexSet...
- size_type mem = sizeof(CompressedSimpleSparsityPattern);
+ size_type mem = sizeof(DynamicSparsityPattern);
for (size_type i=0; i<lines.size(); ++i)
mem += MemoryConsumption::memory_consumption (lines[i]);
// explicit instantiations
-template void CompressedSimpleSparsityPattern::Line::add_entries(size_type *,
- size_type *,
- const bool);
-template void CompressedSimpleSparsityPattern::Line::add_entries(const size_type *,
- const size_type *,
- const bool);
+template void DynamicSparsityPattern::Line::add_entries(size_type *,
+ size_type *,
+ const bool);
+template void DynamicSparsityPattern::Line::add_entries(const size_type *,
+ const size_type *,
+ const bool);
#ifndef DEAL_II_VECTOR_ITERATOR_IS_POINTER
-template void CompressedSimpleSparsityPattern::Line::
+template void DynamicSparsityPattern::Line::
add_entries(std::vector<size_type>::iterator,
std::vector<size_type>::iterator,
const bool);
BlockSparseMatrix::
reinit(const std::vector<IndexSet> &rows,
const std::vector<IndexSet> &cols,
- const BlockCompressedSimpleSparsityPattern &bcsp,
+ const BlockDynamicSparsityPattern &bcsp,
const MPI_Comm &com)
{
Assert(rows.size() == bcsp.n_block_rows(), ExcMessage("invalid size"));
void
BlockSparseMatrix::
reinit(const std::vector<IndexSet> &sizes,
- const BlockCompressedSimpleSparsityPattern &bcsp,
+ const BlockDynamicSparsityPattern &bcsp,
const MPI_Comm &com)
{
reinit(sizes, sizes, bcsp, com);
# include <deal.II/lac/petsc_vector.h>
# include <deal.II/lac/sparsity_pattern.h>
-# include <deal.II/lac/compressed_sparsity_pattern.h>
-# include <deal.II/lac/compressed_simple_sparsity_pattern.h>
+# include <deal.II/lac/dynamic_sparsity_pattern.h>
DEAL_II_NAMESPACE_OPEN
const bool);
template
SparseMatrix::SparseMatrix (const MPI_Comm &,
- const CompressedSparsityPattern &,
- const std::vector<size_type> &,
- const std::vector<size_type> &,
- const unsigned int,
- const bool);
- template
- SparseMatrix::SparseMatrix (const MPI_Comm &,
- const CompressedSimpleSparsityPattern &,
+ const DynamicSparsityPattern &,
const std::vector<size_type> &,
const std::vector<size_type> &,
const unsigned int,
const bool);
template void
SparseMatrix::reinit (const MPI_Comm &,
- const CompressedSparsityPattern &,
- const std::vector<size_type> &,
- const std::vector<size_type> &,
- const unsigned int,
- const bool);
- template void
- SparseMatrix::reinit (const MPI_Comm &,
- const CompressedSimpleSparsityPattern &,
+ const DynamicSparsityPattern &,
const std::vector<size_type> &,
const std::vector<size_type> &,
const unsigned int,
SparseMatrix::
reinit (const IndexSet &,
const IndexSet &,
- const CompressedSimpleSparsityPattern &,
+ const DynamicSparsityPattern &,
const MPI_Comm &);
template void
const unsigned int ,
const bool);
template void
- SparseMatrix::do_reinit (const CompressedSparsityPattern &,
- const std::vector<size_type> &,
- const std::vector<size_type> &,
- const unsigned int ,
- const bool);
- template void
- SparseMatrix::do_reinit (const CompressedSimpleSparsityPattern &,
+ SparseMatrix::do_reinit (const DynamicSparsityPattern &,
const std::vector<size_type> &,
const std::vector<size_type> &,
const unsigned int ,
SparseMatrix::
do_reinit (const IndexSet &,
const IndexSet &,
- const CompressedSimpleSparsityPattern &);
+ const DynamicSparsityPattern &);
PetscScalar
# include <deal.II/lac/petsc_vector.h>
# include <deal.II/lac/sparsity_pattern.h>
-# include <deal.II/lac/compressed_sparsity_pattern.h>
-# include <deal.II/lac/compressed_simple_sparsity_pattern.h>
+# include <deal.II/lac/dynamic_sparsity_pattern.h>
DEAL_II_NAMESPACE_OPEN
SparseMatrix::SparseMatrix (const SparsityPattern &,
const bool);
template
- SparseMatrix::SparseMatrix (const CompressedSparsityPattern &,
- const bool);
- template
- SparseMatrix::SparseMatrix (const CompressedSimpleSparsityPattern &,
+ SparseMatrix::SparseMatrix (const DynamicSparsityPattern &,
const bool);
template void
SparseMatrix::reinit (const SparsityPattern &,
const bool);
template void
- SparseMatrix::reinit (const CompressedSparsityPattern &,
- const bool);
- template void
- SparseMatrix::reinit (const CompressedSimpleSparsityPattern &,
+ SparseMatrix::reinit (const DynamicSparsityPattern &,
const bool);
template void
SparseMatrix::do_reinit (const SparsityPattern &,
const bool);
template void
- SparseMatrix::do_reinit (const CompressedSparsityPattern &,
- const bool);
- template void
- SparseMatrix::do_reinit (const CompressedSimpleSparsityPattern &,
+ SparseMatrix::do_reinit (const DynamicSparsityPattern &,
const bool);
PetscScalar
#include <deal.II/lac/sparsity_pattern.h>
#include <deal.II/lac/sparsity_tools.h>
#include <deal.II/lac/full_matrix.h>
-#include <deal.II/lac/compressed_sparsity_pattern.h>
-#include <deal.II/lac/compressed_set_sparsity_pattern.h>
-#include <deal.II/lac/compressed_simple_sparsity_pattern.h>
+#include <deal.II/lac/dynamic_sparsity_pattern.h>
#include <iostream>
#include <iomanip>
// explicit instantiations
template void SparsityPattern::copy_from<SparsityPattern> (const SparsityPattern &);
-template void SparsityPattern::copy_from<CompressedSparsityPattern> (const CompressedSparsityPattern &);
-template void SparsityPattern::copy_from<CompressedSetSparsityPattern> (const CompressedSetSparsityPattern &);
-template void SparsityPattern::copy_from<CompressedSimpleSparsityPattern> (const CompressedSimpleSparsityPattern &);
+template void SparsityPattern::copy_from<DynamicSparsityPattern> (const DynamicSparsityPattern &);
template void SparsityPattern::copy_from<float> (const FullMatrix<float> &);
template void SparsityPattern::copy_from<double> (const FullMatrix<double> &);
#ifdef DEAL_II_WITH_MPI
#include <deal.II/base/utilities.h>
-#include <deal.II/lac/compressed_sparsity_pattern.h>
-#include <deal.II/lac/compressed_set_sparsity_pattern.h>
-#include <deal.II/lac/compressed_simple_sparsity_pattern.h>
+#include <deal.II/lac/dynamic_sparsity_pattern.h>
#include <deal.II/lac/block_sparsity_pattern.h>
#endif
const IndexSet & myrange)
#ifdef DEAL_II_WITH_MPI
-SPARSITY_FUNCTIONS(CompressedSparsityPattern);
-SPARSITY_FUNCTIONS(CompressedSimpleSparsityPattern);
+SPARSITY_FUNCTIONS(DynamicSparsityPattern);
template void SparsityTools::distribute_sparsity_pattern
<BlockCompressedSimpleSparsityPattern>
template void
BlockSparseMatrix::reinit (const dealii::BlockSparsityPattern &);
template void
- BlockSparseMatrix::reinit (const dealii::BlockCompressedSparsityPattern &);
- template void
- BlockSparseMatrix::reinit (const dealii::BlockCompressedSetSparsityPattern &);
- template void
- BlockSparseMatrix::reinit (const dealii::BlockCompressedSimpleSparsityPattern &);
-
+ BlockSparseMatrix::reinit (const dealii::BlockDynamicSparsityPattern &);
template void
BlockSparseMatrix::reinit (const std::vector<Epetra_Map> &,
const bool);
template void
BlockSparseMatrix::reinit (const std::vector<Epetra_Map> &,
- const dealii::BlockCompressedSparsityPattern &,
- const bool);
- template void
- BlockSparseMatrix::reinit (const std::vector<Epetra_Map> &,
- const dealii::BlockCompressedSetSparsityPattern &,
- const bool);
- template void
- BlockSparseMatrix::reinit (const std::vector<Epetra_Map> &,
- const dealii::BlockCompressedSimpleSparsityPattern &,
+ const dealii::BlockDynamicSparsityPattern &,
const bool);
template void
BlockSparseMatrix::reinit (const std::vector<IndexSet> &,
- const dealii::BlockCompressedSimpleSparsityPattern &,
+ const dealii::BlockDynamicSparsityPattern &,
const MPI_Comm &,
const bool);
# include <deal.II/lac/sparse_matrix.h>
# include <deal.II/lac/trilinos_sparsity_pattern.h>
# include <deal.II/lac/sparsity_pattern.h>
-# include <deal.II/lac/compressed_sparsity_pattern.h>
-# include <deal.II/lac/compressed_set_sparsity_pattern.h>
-# include <deal.II/lac/compressed_simple_sparsity_pattern.h>
+# include <deal.II/lac/dynamic_sparsity_pattern.h>
# include <deal.II/lac/sparsity_tools.h>
# include <Epetra_Export.h>
void
SparseMatrix::reinit (const Epetra_Map &input_row_map,
const Epetra_Map &input_col_map,
- const CompressedSimpleSparsityPattern &sparsity_pattern,
+ const DynamicSparsityPattern &sparsity_pattern,
const bool exchange_data)
{
matrix.reset();
{
template void
SparseMatrix::reinit (const dealii::SparsityPattern &);
+
template void
- SparseMatrix::reinit (const CompressedSparsityPattern &);
- template void
- SparseMatrix::reinit (const CompressedSetSparsityPattern &);
- template void
- SparseMatrix::reinit (const CompressedSimpleSparsityPattern &);
+ SparseMatrix::reinit (const DynamicSparsityPattern &);
template void
SparseMatrix::reinit (const Epetra_Map &,
const bool);
template void
SparseMatrix::reinit (const Epetra_Map &,
- const CompressedSparsityPattern &,
- const bool);
- template void
- SparseMatrix::reinit (const Epetra_Map &,
- const CompressedSetSparsityPattern &,
- const bool);
- template void
- SparseMatrix::reinit (const Epetra_Map &,
- const CompressedSimpleSparsityPattern &,
+ const DynamicSparsityPattern &,
const bool);
const Epetra_Map &,
const dealii::SparsityPattern &,
const bool);
+
template void
SparseMatrix::reinit (const Epetra_Map &,
const Epetra_Map &,
- const CompressedSparsityPattern &,
- const bool);
- template void
- SparseMatrix::reinit (const Epetra_Map &,
- const Epetra_Map &,
- const CompressedSetSparsityPattern &,
+ const DynamicSparsityPattern &,
const bool);
}
# include <deal.II/base/utilities.h>
# include <deal.II/lac/sparsity_pattern.h>
-# include <deal.II/lac/compressed_sparsity_pattern.h>
-# include <deal.II/lac/compressed_set_sparsity_pattern.h>
-# include <deal.II/lac/compressed_simple_sparsity_pattern.h>
+# include <deal.II/lac/dynamic_sparsity_pattern.h>
# include <Epetra_Export.h>
template void
SparsityPattern::copy_from (const dealii::SparsityPattern &);
template void
- SparsityPattern::copy_from (const dealii::CompressedSparsityPattern &);
- template void
- SparsityPattern::copy_from (const dealii::CompressedSetSparsityPattern &);
- template void
- SparsityPattern::copy_from (const dealii::CompressedSimpleSparsityPattern &);
+ SparsityPattern::copy_from (const dealii::DynamicSparsityPattern &);
template void
bool);
template void
SparsityPattern::reinit (const Epetra_Map &,
- const dealii::CompressedSparsityPattern &,
- bool);
- template void
- SparsityPattern::reinit (const Epetra_Map &,
- const dealii::CompressedSetSparsityPattern &,
+ const dealii::DynamicSparsityPattern &,
bool);
- template void
- SparsityPattern::reinit (const Epetra_Map &,
- const dealii::CompressedSimpleSparsityPattern &,
- bool);
-
template void
SparsityPattern::reinit (const Epetra_Map &,
template void
SparsityPattern::reinit (const Epetra_Map &,
const Epetra_Map &,
- const dealii::CompressedSparsityPattern &,
+ const dealii::DynamicSparsityPattern &,
bool);
- template void
- SparsityPattern::reinit (const Epetra_Map &,
- const Epetra_Map &,
- const dealii::CompressedSetSparsityPattern &,
- bool);
- template void
- SparsityPattern::reinit (const Epetra_Map &,
- const Epetra_Map &,
- const dealii::CompressedSimpleSparsityPattern &,
- bool);
-
template void
bool);
template void
SparsityPattern::reinit (const IndexSet &,
- const dealii::CompressedSparsityPattern &,
- const MPI_Comm &,
- bool);
- template void
- SparsityPattern::reinit (const IndexSet &,
- const dealii::CompressedSetSparsityPattern &,
- const MPI_Comm &,
- bool);
- template void
- SparsityPattern::reinit (const IndexSet &,
- const dealii::CompressedSimpleSparsityPattern &,
+ const dealii::DynamicSparsityPattern &,
const MPI_Comm &,
bool);
template void
SparsityPattern::reinit (const IndexSet &,
const IndexSet &,
- const dealii::CompressedSparsityPattern &,
- const MPI_Comm &,
- bool);
- template void
- SparsityPattern::reinit (const IndexSet &,
- const IndexSet &,
- const dealii::CompressedSetSparsityPattern &,
- const MPI_Comm &,
- bool);
- template void
- SparsityPattern::reinit (const IndexSet &,
- const IndexSet &,
- const dealii::CompressedSimpleSparsityPattern &,
+ const dealii::DynamicSparsityPattern &,
const MPI_Comm &,
bool);
#include <deal.II/base/logstream.h>
#include <deal.II/base/index_set.h>
#include <deal.II/lac/sparsity_pattern.h>
+#include <deal.II/lac/dynamic_sparsity_pattern.h>
#include <deal.II/lac/compressed_sparsity_pattern.h>
#include <deal.II/lac/compressed_simple_sparsity_pattern.h>
#include <deal.II/lac/compressed_set_sparsity_pattern.h>
}
-void do_reinit (CompressedSparsityPattern &sp)
-{
- sp.reinit((N-1)*(N-1), (N-1)*(N-1));
-}
void do_reinit (CompressedSimpleSparsityPattern &sp,
const IndexSet &index_set = IndexSet())
sp.reinit((N-1)*(N-1), (N-1)*(N-1), index_set);
}
-void do_reinit (CompressedSetSparsityPattern &sp)
-{
- sp.reinit((N-1)*(N-1), (N-1)*(N-1));
-}
template <>
-void copy_with_offdiagonals_1<CompressedSparsityPattern> ()
+void copy_with_offdiagonals_1<DynamicSparsityPattern> ()
{
// this sparsity pattern doesn't have this
// function
deallog << "OK" << std::endl;
}
-template <>
-void copy_with_offdiagonals_1<CompressedSimpleSparsityPattern> ()
-{
- // this sparsity pattern doesn't have this
- // function
- deallog << "OK" << std::endl;
-}
-
-template <>
-void copy_with_offdiagonals_1<CompressedSetSparsityPattern> ()
-{
- // this sparsity pattern doesn't have this
- // function
- deallog << "OK" << std::endl;
-}
template <>
-void copy_with_offdiagonals_2<CompressedSparsityPattern> ()
+void copy_with_offdiagonals_2<DynamicSparsityPattern> ()
{
// this sparsity pattern doesn't have this
// function
-template <>
-void copy_with_offdiagonals_2<CompressedSimpleSparsityPattern> ()
-{
- // this sparsity pattern doesn't have this
- // function
- deallog << "OK" << std::endl;
-}
-
-
-
-template <>
-void copy_with_offdiagonals_2<CompressedSetSparsityPattern> ()
-{
- // this sparsity pattern doesn't have this
- // function
- deallog << "OK" << std::endl;
-}
-
-
void
do_copy_from (const std::list<std::set<unsigned int,std::greater<unsigned int> > > &sparsity,
}
-template <typename SP>
-void
-do_copy_from (const CompressedSparsityPattern &sparsity,
- SP &sp4)
-{
- std::list<std::set<unsigned int,std::greater<unsigned int> > > sparsity_x;
- for (unsigned int i=0; i<sparsity.n_rows(); ++i)
- {
- sparsity_x.push_back
- (std::set<unsigned int,std::greater<unsigned int> >());
-
- for (unsigned int j=0; j<sparsity.n_cols(); ++j)
- if (sparsity.exists(i,j))
- sparsity_x.back().insert (j);
- }
-
- do_copy_from (sparsity_x, sp4);
-}
template <typename SP>
void
-do_copy_from (const CompressedSimpleSparsityPattern &sparsity,
- SP &sp4)
-{
- std::list<std::set<unsigned int,std::greater<unsigned int> > > sparsity_x;
- for (unsigned int i=0; i<sparsity.n_rows(); ++i)
- {
- sparsity_x.push_back
- (std::set<unsigned int,std::greater<unsigned int> >());
-
- for (unsigned int j=0; j<sparsity.n_cols(); ++j)
- if (sparsity.exists(i,j))
- sparsity_x.back().insert (j);
- }
-
- do_copy_from (sparsity_x, sp4);
-}
-
-
-template <typename SP>
-void
-do_copy_from (const CompressedSetSparsityPattern &sparsity,
+do_copy_from (const DynamicSparsityPattern &sparsity,
SP &sp4)
{
std::list<std::set<unsigned int,std::greater<unsigned int> > > sparsity_x;
template <>
-void matrix_position<CompressedSparsityPattern> ()
-{
- // this class doesn't have that function
- deallog << "OK" << std::endl;
-}
-
-
-
-template <>
-void matrix_position<CompressedSimpleSparsityPattern> ()
+void matrix_position<DynamicSparsityPattern> ()
{
// this class doesn't have that function
deallog << "OK" << std::endl;
-template <>
-void matrix_position<CompressedSetSparsityPattern> ()
-{
- // this class doesn't have that function
- deallog << "OK" << std::endl;
-}
-
template <typename SP>
template <>
-void block_read_write<CompressedSparsityPattern> ()
+void block_read_write<DynamicSparsityPattern> ()
{
// not implemented for this sparsity
// pattern
-template <>
-void block_read_write<CompressedSimpleSparsityPattern> ()
-{
- // not implemented for this sparsity
- // pattern
- deallog << "OK" << std::endl;
-}
-
-
-
-template <>
-void block_read_write<CompressedSetSparsityPattern> ()
-{
- // not implemented for this sparsity
- // pattern
- deallog << "OK" << std::endl;
-}
-
-
template <typename SP>
void test_index_set (const bool contiguous)