/**
* Write the sparsity structure of the matrix belonging to the specified @p
* level. The sparsity pattern is not compressed, so before creating the
- * actual matrix you have to compress the matrix yourself, using
- * <tt>SparsityPatternType::compress()</tt>.
+ * actual matrix you have to compress the matrix yourself, either using
+ * SparsityPattern::compress() or by copying to a SparsityPattern.
*
* The optional AffineConstraints argument allows to define constraints of
* the level matrices like Dirichlet boundary conditions. Note that there is
* one level is considered. See DoFTools::make_sparsity_pattern() for more
* details about the arguments.
*/
- template <int dim,
- int spacedim,
- typename SparsityPatternType,
- typename number = double>
+ template <int dim, int spacedim, typename number = double>
void
make_sparsity_pattern(
const DoFHandler<dim, spacedim> &dof_handler,
- SparsityPatternType & sparsity,
+ SparsityPatternBase & sparsity,
const unsigned int level,
const AffineConstraints<number> &constraints = AffineConstraints<number>(),
const bool keep_constrained_dofs = true);
* and
* @ref DoFTools
*/
- template <int dim,
- int spacedim,
- typename SparsityPatternType,
- typename number = double>
+ template <int dim, int spacedim, typename number = double>
void
make_flux_sparsity_pattern(
const DoFHandler<dim, spacedim> &dof_handler,
- SparsityPatternType & sparsity,
+ SparsityPatternBase & sparsity,
const unsigned int level,
const AffineConstraints<number> &constraints = AffineConstraints<number>(),
const bool keep_constrained_dofs = true);
*
* make_flux_sparsity_pattern()
*/
- template <int dim, typename SparsityPatternType, int spacedim>
+ template <int dim, int spacedim>
void
make_flux_sparsity_pattern_edge(const DoFHandler<dim, spacedim> &dof_handler,
- SparsityPatternType & sparsity,
+ SparsityPatternBase & sparsity,
const unsigned int level);
/**
* This function does the same as the other with the same name, but it gets
* There is one matrix for couplings in a cell and one for the couplings
* occurring in fluxes.
*/
- template <int dim, typename SparsityPatternType, int spacedim>
+ template <int dim, int spacedim>
void
make_flux_sparsity_pattern(const DoFHandler<dim, spacedim> & dof,
- SparsityPatternType & sparsity,
+ SparsityPatternBase & sparsity,
const unsigned int level,
const Table<2, DoFTools::Coupling> &int_mask,
const Table<2, DoFTools::Coupling> &flux_mask);
*
* make_flux_sparsity_pattern()
*/
- template <int dim, typename SparsityPatternType, int spacedim>
+ template <int dim, int spacedim>
void
make_flux_sparsity_pattern_edge(
const DoFHandler<dim, spacedim> & dof_handler,
- SparsityPatternType & sparsity,
+ SparsityPatternBase & sparsity,
const unsigned int level,
const Table<2, DoFTools::Coupling> &flux_mask);
* degrees of freedom on a refinement edge to those not on the refinement edge
* of a certain level.
*/
- template <int dim, int spacedim, typename SparsityPatternType>
+ template <int dim, int spacedim>
void
make_interface_sparsity_pattern(const DoFHandler<dim, spacedim> &dof_handler,
const MGConstrainedDoFs &mg_constrained_dofs,
- SparsityPatternType & sparsity,
+ SparsityPatternBase & sparsity,
const unsigned int level);
- template <int dim,
- int spacedim,
- typename SparsityPatternType,
- typename number>
+ template <int dim, int spacedim, typename number>
void
make_sparsity_pattern(const DoFHandler<dim, spacedim> &dof,
- SparsityPatternType & sparsity,
+ SparsityPatternBase & sparsity,
const unsigned int level,
const AffineConstraints<number> &constraints,
const bool keep_constrained_dofs)
- template <int dim,
- int spacedim,
- typename SparsityPatternType,
- typename number>
+ template <int dim, int spacedim, typename number>
void
make_flux_sparsity_pattern(const DoFHandler<dim, spacedim> &dof,
- SparsityPatternType & sparsity,
+ SparsityPatternBase & sparsity,
const unsigned int level,
const AffineConstraints<number> &constraints,
const bool keep_constrained_dofs)
- template <int dim, typename SparsityPatternType, int spacedim>
+ template <int dim, int spacedim>
void
make_flux_sparsity_pattern_edge(const DoFHandler<dim, spacedim> &dof,
- SparsityPatternType & sparsity,
+ SparsityPatternBase & sparsity,
const unsigned int level)
{
Assert((level >= 1) && (level < dof.get_triangulation().n_global_levels()),
cell->neighbor_or_periodic_neighbor(face);
neighbor->get_mg_dof_indices(dofs_on_other_cell);
+ std::sort(dofs_on_this_cell.begin(), dofs_on_this_cell.end());
for (unsigned int i = 0; i < dofs_per_cell; ++i)
- {
- for (unsigned int j = 0; j < dofs_per_cell; ++j)
- {
- sparsity.add(dofs_on_other_cell[i],
- dofs_on_this_cell[j]);
- sparsity.add(dofs_on_other_cell[j],
- dofs_on_this_cell[i]);
- }
- }
+ sparsity.add_row_entries(dofs_on_other_cell[i],
+ make_array_view(dofs_on_this_cell),
+ true);
}
}
}
- template <int dim, typename SparsityPatternType, int spacedim>
+ template <int dim, int spacedim>
void
make_flux_sparsity_pattern(const DoFHandler<dim, spacedim> & dof,
- SparsityPatternType & sparsity,
+ SparsityPatternBase & sparsity,
const unsigned int level,
const Table<2, DoFTools::Coupling> &int_mask,
const Table<2, DoFTools::Coupling> &flux_mask)
const unsigned int total_dofs = fe.n_dofs_per_cell();
std::vector<types::global_dof_index> dofs_on_this_cell(total_dofs);
std::vector<types::global_dof_index> dofs_on_other_cell(total_dofs);
- Table<2, bool> support_on_face(total_dofs,
+ std::vector<std::pair<types::global_dof_index, types::global_dof_index>>
+ cell_entries;
+
+ Table<2, bool> support_on_face(total_dofs,
GeometryInfo<dim>::faces_per_cell);
const Table<2, DoFTools::Coupling>
for (unsigned int i = 0; i < total_dofs; ++i)
for (unsigned int j = 0; j < total_dofs; ++j)
if (int_dof_mask[i][j] != DoFTools::none)
- sparsity.add(dofs_on_this_cell[i], dofs_on_this_cell[j]);
+ cell_entries.emplace_back(dofs_on_this_cell[i],
+ dofs_on_this_cell[j]);
// Loop over all interior neighbors
for (const unsigned int face : GeometryInfo<dim>::face_indices())
const bool j_non_zero_i = support_on_face(j, face);
if (flux_dof_mask(i, j) == DoFTools::always)
- sparsity.add(dofs_on_this_cell[i],
- dofs_on_this_cell[j]);
+ cell_entries.emplace_back(dofs_on_this_cell[i],
+ dofs_on_this_cell[j]);
if (flux_dof_mask(i, j) == DoFTools::nonzero &&
i_non_zero_i && j_non_zero_i)
- sparsity.add(dofs_on_this_cell[i],
- dofs_on_this_cell[j]);
+ cell_entries.emplace_back(dofs_on_this_cell[i],
+ dofs_on_this_cell[j]);
}
}
}
support_on_face(j, neighbor_face);
if (flux_dof_mask(i, j) == DoFTools::always)
{
- sparsity.add(dofs_on_this_cell[i],
- dofs_on_other_cell[j]);
- sparsity.add(dofs_on_other_cell[i],
- dofs_on_this_cell[j]);
- sparsity.add(dofs_on_this_cell[i],
- dofs_on_this_cell[j]);
- sparsity.add(dofs_on_other_cell[i],
- dofs_on_other_cell[j]);
+ cell_entries.emplace_back(dofs_on_this_cell[i],
+ dofs_on_other_cell[j]);
+ cell_entries.emplace_back(dofs_on_other_cell[i],
+ dofs_on_this_cell[j]);
+ cell_entries.emplace_back(dofs_on_this_cell[i],
+ dofs_on_this_cell[j]);
+ cell_entries.emplace_back(dofs_on_other_cell[i],
+ dofs_on_other_cell[j]);
}
if (flux_dof_mask(i, j) == DoFTools::nonzero)
{
if (i_non_zero_i && j_non_zero_e)
- sparsity.add(dofs_on_this_cell[i],
- dofs_on_other_cell[j]);
+ cell_entries.emplace_back(dofs_on_this_cell[i],
+ dofs_on_other_cell[j]);
if (i_non_zero_e && j_non_zero_i)
- sparsity.add(dofs_on_other_cell[i],
- dofs_on_this_cell[j]);
+ cell_entries.emplace_back(dofs_on_other_cell[i],
+ dofs_on_this_cell[j]);
if (i_non_zero_i && j_non_zero_i)
- sparsity.add(dofs_on_this_cell[i],
- dofs_on_this_cell[j]);
+ cell_entries.emplace_back(dofs_on_this_cell[i],
+ dofs_on_this_cell[j]);
if (i_non_zero_e && j_non_zero_e)
- sparsity.add(dofs_on_other_cell[i],
- dofs_on_other_cell[j]);
+ cell_entries.emplace_back(dofs_on_other_cell[i],
+ dofs_on_other_cell[j]);
}
if (flux_dof_mask(j, i) == DoFTools::always)
{
- sparsity.add(dofs_on_this_cell[j],
- dofs_on_other_cell[i]);
- sparsity.add(dofs_on_other_cell[j],
- dofs_on_this_cell[i]);
- sparsity.add(dofs_on_this_cell[j],
- dofs_on_this_cell[i]);
- sparsity.add(dofs_on_other_cell[j],
- dofs_on_other_cell[i]);
+ cell_entries.emplace_back(dofs_on_this_cell[j],
+ dofs_on_other_cell[i]);
+ cell_entries.emplace_back(dofs_on_other_cell[j],
+ dofs_on_this_cell[i]);
+ cell_entries.emplace_back(dofs_on_this_cell[j],
+ dofs_on_this_cell[i]);
+ cell_entries.emplace_back(dofs_on_other_cell[j],
+ dofs_on_other_cell[i]);
}
if (flux_dof_mask(j, i) == DoFTools::nonzero)
{
if (j_non_zero_i && i_non_zero_e)
- sparsity.add(dofs_on_this_cell[j],
- dofs_on_other_cell[i]);
+ cell_entries.emplace_back(dofs_on_this_cell[j],
+ dofs_on_other_cell[i]);
if (j_non_zero_e && i_non_zero_i)
- sparsity.add(dofs_on_other_cell[j],
- dofs_on_this_cell[i]);
+ cell_entries.emplace_back(dofs_on_other_cell[j],
+ dofs_on_this_cell[i]);
if (j_non_zero_i && i_non_zero_i)
- sparsity.add(dofs_on_this_cell[j],
- dofs_on_this_cell[i]);
+ cell_entries.emplace_back(dofs_on_this_cell[j],
+ dofs_on_this_cell[i]);
if (j_non_zero_e && i_non_zero_e)
- sparsity.add(dofs_on_other_cell[j],
- dofs_on_other_cell[i]);
+ cell_entries.emplace_back(dofs_on_other_cell[j],
+ dofs_on_other_cell[i]);
}
}
}
face_touched[neighbor->face(neighbor_face)->index()] = true;
}
}
+ sparsity.add_entries(make_array_view(cell_entries));
+ cell_entries.clear();
}
}
- template <int dim, typename SparsityPatternType, int spacedim>
+ template <int dim, int spacedim>
void
make_flux_sparsity_pattern_edge(const DoFHandler<dim, spacedim> & dof,
- SparsityPatternType & sparsity,
+ SparsityPatternBase & sparsity,
const unsigned int level,
const Table<2, DoFTools::Coupling> &flux_mask)
{
const unsigned int dofs_per_cell = dof.get_fe().n_dofs_per_cell();
std::vector<types::global_dof_index> dofs_on_this_cell(dofs_per_cell);
std::vector<types::global_dof_index> dofs_on_other_cell(dofs_per_cell);
- Table<2, bool> support_on_face(dofs_per_cell,
+ std::vector<std::pair<types::global_dof_index, types::global_dof_index>>
+ cell_entries;
+
+ Table<2, bool> support_on_face(dofs_per_cell,
GeometryInfo<dim>::faces_per_cell);
const Table<2, DoFTools::Coupling> flux_dof_mask =
{
if (flux_dof_mask(i, j) != DoFTools::none)
{
- sparsity.add(dofs_on_other_cell[i],
- dofs_on_this_cell[j]);
- sparsity.add(dofs_on_other_cell[j],
- dofs_on_this_cell[i]);
+ cell_entries.emplace_back(dofs_on_other_cell[i],
+ dofs_on_this_cell[j]);
+ cell_entries.emplace_back(dofs_on_other_cell[j],
+ dofs_on_this_cell[i]);
}
}
}
}
}
+ sparsity.add_entries(make_array_view(cell_entries));
+ cell_entries.clear();
}
}
- template <int dim, int spacedim, typename SparsityPatternType>
+ template <int dim, int spacedim>
void
make_interface_sparsity_pattern(const DoFHandler<dim, spacedim> &dof,
const MGConstrainedDoFs &mg_constrained_dofs,
- SparsityPatternType & sparsity,
+ SparsityPatternBase & sparsity,
const unsigned int level)
{
const types::global_dof_index n_dofs = dof.n_dofs(level);
const unsigned int dofs_per_cell = dof.get_fe().n_dofs_per_cell();
std::vector<types::global_dof_index> dofs_on_this_cell(dofs_per_cell);
+ std::vector<types::global_dof_index> cols;
+ cols.reserve(dofs_per_cell);
+
for (const auto &cell : dof.cell_iterators_on_level(level))
if (cell->is_locally_owned_on_level())
{
cell->get_mg_dof_indices(dofs_on_this_cell);
+ std::sort(dofs_on_this_cell.begin(), dofs_on_this_cell.end());
for (unsigned int i = 0; i < dofs_per_cell; ++i)
- for (unsigned int j = 0; j < dofs_per_cell; ++j)
- if (mg_constrained_dofs.is_interface_matrix_entry(
- level, dofs_on_this_cell[i], dofs_on_this_cell[j]))
- sparsity.add(dofs_on_this_cell[i], dofs_on_this_cell[j]);
+ {
+ for (unsigned int j = 0; j < dofs_per_cell; ++j)
+ if (mg_constrained_dofs.is_interface_matrix_entry(
+ level, dofs_on_this_cell[i], dofs_on_this_cell[j]))
+ cols.push_back(dofs_on_this_cell[j]);
+ sparsity.add_row_entries(dofs_on_this_cell[i],
+ make_array_view(cols),
+ true);
+ cols.clear();
+ }
}
}
-for (PATTERN : SPARSITY_PATTERNS; deal_II_dimension : DIMENSIONS;
- deal_II_space_dimension : SPACE_DIMENSIONS)
+for (deal_II_dimension : DIMENSIONS; deal_II_space_dimension : SPACE_DIMENSIONS)
{
namespace MGTools
\{
#if deal_II_dimension <= deal_II_space_dimension
template void
- make_sparsity_pattern<deal_II_dimension,
- deal_II_space_dimension,
- PATTERN,
- double>(
+ make_sparsity_pattern<deal_II_dimension, deal_II_space_dimension, double>(
const DoFHandler<deal_II_dimension, deal_II_space_dimension> &,
- PATTERN &,
+ SparsityPatternBase &,
const unsigned int,
const AffineConstraints<double> &,
const bool);
template void
- make_sparsity_pattern<deal_II_dimension,
- deal_II_space_dimension,
- PATTERN,
- float>(
+ make_sparsity_pattern<deal_II_dimension, deal_II_space_dimension, float>(
const DoFHandler<deal_II_dimension, deal_II_space_dimension> &,
- PATTERN &,
+ SparsityPatternBase &,
const unsigned int,
const AffineConstraints<float> &,
const bool);
}
-for (PATTERN : SPARSITY_PATTERNS; deal_II_dimension : DIMENSIONS;
- deal_II_space_dimension : SPACE_DIMENSIONS)
+for (deal_II_dimension : DIMENSIONS; deal_II_space_dimension : SPACE_DIMENSIONS)
{
namespace MGTools
\{
#if deal_II_dimension <= deal_II_space_dimension
template void
make_interface_sparsity_pattern<deal_II_dimension,
- deal_II_space_dimension,
- PATTERN>(
+ deal_II_space_dimension>(
const DoFHandler<deal_II_dimension, deal_II_space_dimension> &,
const MGConstrainedDoFs &,
- PATTERN &,
+ SparsityPatternBase &,
const unsigned int);
#endif
template void
make_flux_sparsity_pattern<deal_II_dimension,
deal_II_space_dimension,
- PATTERN,
double>(const DoFHandler<deal_II_dimension> &,
- PATTERN &,
+ SparsityPatternBase &,
const unsigned int,
const AffineConstraints<double> &,
const bool);
template void
make_flux_sparsity_pattern<deal_II_dimension,
deal_II_space_dimension,
- PATTERN,
float>(const DoFHandler<deal_II_dimension> &,
- PATTERN &,
+ SparsityPatternBase &,
const unsigned int,
const AffineConstraints<float> &,
const bool);
template void
make_flux_sparsity_pattern_edge<deal_II_dimension>(
const DoFHandler<deal_II_dimension> &,
- PATTERN &,
+ SparsityPatternBase &,
const unsigned int);
# if deal_II_dimension > 1
template void
make_flux_sparsity_pattern<deal_II_dimension>(
const DoFHandler<deal_II_dimension> &,
- PATTERN &,
+ SparsityPatternBase &,
const unsigned int,
const Table<2, DoFTools::Coupling> &,
const Table<2, DoFTools::Coupling> &);
template void
make_flux_sparsity_pattern_edge<deal_II_dimension>(
const DoFHandler<deal_II_dimension> &,
- PATTERN &,
+ SparsityPatternBase &,
const unsigned int,
const Table<2, DoFTools::Coupling> &);
# endif