Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AffineConstraints: remove the block sparsity constraint function. #14398

Merged
merged 2 commits into from
Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
90 changes: 0 additions & 90 deletions include/deal.II/lac/affine_constraints.h
Original file line number Diff line number Diff line change
Expand Up @@ -1972,30 +1972,6 @@ class AffineConstraints : public Subscriptor
const bool use_inhomogeneities_for_rhs,
const std::integral_constant<bool, true>) const;

/**
* This function actually implements the local_to_global function for
* standard (non-block) sparsity types.
*/
template <typename SparsityPatternType>
void
add_entries_local_to_global(const std::vector<size_type> &local_dof_indices,
SparsityPatternType & sparsity_pattern,
const bool keep_constrained_entries,
const Table<2, bool> &dof_mask,
const std::integral_constant<bool, false>) const;

/**
* This function actually implements the local_to_global function for block
* sparsity types.
*/
template <typename SparsityPatternType>
void
add_entries_local_to_global(const std::vector<size_type> &local_dof_indices,
SparsityPatternType & sparsity_pattern,
const bool keep_constrained_entries,
const Table<2, bool> &dof_mask,
const std::integral_constant<bool, true>) const;

/**
* Internal helper function for distribute_local_to_global function.
*
Expand Down Expand Up @@ -2454,49 +2430,6 @@ namespace internal
template <typename MatrixType>
const bool IsBlockMatrix<MatrixType>::value;


/**
* A class that can be used to determine whether a given type is a block
* sparsity pattern type or not. In this, it matches the IsBlockMatrix
* class.
*
* @see
* @ref GlossBlockLA "Block (linear algebra)"
*/
template <typename MatrixType>
struct IsBlockSparsityPattern
{
private:
/**
* Overload returning true if the class is derived from
* BlockSparsityPatternBase, which is what block sparsity patterns do.
*/
template <typename T>
static std::true_type
check(const BlockSparsityPatternBase<T> *);

/**
* Catch all for all other potential types that are then apparently not
* block sparsity patterns.
*/
static std::false_type
check(...);

public:
/**
* A statically computable value that indicates whether the template
* argument to this class is a block sparsity pattern (in fact whether the
* type is derived from BlockSparsityPatternBase<T>).
*/
static const bool value =
std::is_same<decltype(check(std::declval<MatrixType *>())),
std::true_type>::value;
};

// instantiation of the static member
template <typename MatrixType>
const bool IsBlockSparsityPattern<MatrixType>::value;

} // namespace AffineConstraints
} // namespace internal
#endif
Expand Down Expand Up @@ -2570,29 +2503,6 @@ AffineConstraints<number>::distribute_local_to_global(



template <typename number>
template <typename SparsityPatternType>
inline void
AffineConstraints<number>::add_entries_local_to_global(
const std::vector<size_type> &local_dof_indices,
SparsityPatternType & sparsity_pattern,
const bool keep_constrained_entries,
const Table<2, bool> & dof_mask) const
{
// enter the internal function with the respective block information set,
// the actual implementation follows in the cm.templates.h file.
add_entries_local_to_global(
local_dof_indices,
sparsity_pattern,
keep_constrained_entries,
dof_mask,
std::integral_constant<bool,
internal::AffineConstraints::IsBlockSparsityPattern<
SparsityPatternType>::value>());
}



template <typename number>
inline AffineConstraints<number>::ConstraintLine::ConstraintLine(
const size_type & index,
Expand Down
137 changes: 1 addition & 136 deletions include/deal.II/lac/affine_constraints.templates.h
Original file line number Diff line number Diff line change
Expand Up @@ -4281,8 +4281,7 @@ AffineConstraints<number>::add_entries_local_to_global(
const std::vector<size_type> &local_dof_indices,
SparsityPatternType & sparsity_pattern,
const bool keep_constrained_entries,
const Table<2, bool> & dof_mask,
const std::integral_constant<bool, false>) const
const Table<2, bool> & dof_mask) const
{
Assert(sparsity_pattern.n_rows() == sparsity_pattern.n_cols(),
ExcNotQuadratic());
Expand Down Expand Up @@ -4448,140 +4447,6 @@ AffineConstraints<number>::add_entries_local_to_global(
dof_mask);
}



template <typename number>
template <typename SparsityPatternType>
void
AffineConstraints<number>::add_entries_local_to_global(
const std::vector<size_type> &local_dof_indices,
SparsityPatternType & sparsity_pattern,
const bool keep_constrained_entries,
const Table<2, bool> & dof_mask,
const std::integral_constant<bool, true>) const
{
// just as the other add_entries_local_to_global function, but now
// specialized for block matrices.
Assert(sparsity_pattern.n_rows() == sparsity_pattern.n_cols(),
ExcNotQuadratic());
Assert(sparsity_pattern.n_block_rows() == sparsity_pattern.n_block_cols(),
ExcNotQuadratic());

const size_type n_local_dofs = local_dof_indices.size();
const size_type num_blocks = sparsity_pattern.n_block_rows();

typename internal::AffineConstraints::ScratchDataAccessor<number>
scratch_data(this->scratch_data);

const bool dof_mask_is_active = (dof_mask.n_rows() == n_local_dofs);
if (dof_mask_is_active == true)
{
AssertDimension(dof_mask.n_cols(), n_local_dofs);
}
else
{
std::vector<size_type> &actual_dof_indices = scratch_data->columns;
actual_dof_indices.resize(n_local_dofs);
make_sorted_row_list(local_dof_indices, actual_dof_indices);
const size_type n_actual_dofs = actual_dof_indices.size();
(void)n_actual_dofs;

// additional construct that also takes care of block indices.
std::vector<size_type> &block_starts = scratch_data->block_starts;
block_starts.resize(num_blocks + 1);
internal::AffineConstraints::make_block_starts(sparsity_pattern,
actual_dof_indices,
block_starts);

for (size_type block = 0; block < num_blocks; ++block)
{
const size_type next_block = block_starts[block + 1];
for (size_type i = block_starts[block]; i < next_block; ++i)
{
Assert(i < n_actual_dofs, ExcInternalError());
const size_type row = actual_dof_indices[i];
Assert(row < sparsity_pattern.block(block, 0).n_rows(),
ExcInternalError());
std::vector<size_type>::iterator index_it =
actual_dof_indices.begin();
for (size_type block_col = 0; block_col < num_blocks; ++block_col)
{
const size_type next_block_col = block_starts[block_col + 1];
sparsity_pattern.block(block, block_col)
.add_entries(row,
index_it,
actual_dof_indices.begin() + next_block_col,
true);
index_it = actual_dof_indices.begin() + next_block_col;
}
}
}

for (size_type i = 0; i < n_local_dofs; ++i)
if (is_constrained(local_dof_indices[i]))
{
if (keep_constrained_entries == true)
for (size_type j = 0; j < n_local_dofs; ++j)
{
sparsity_pattern.add(local_dof_indices[i],
local_dof_indices[j]);
sparsity_pattern.add(local_dof_indices[j],
local_dof_indices[i]);
}
else
sparsity_pattern.add(local_dof_indices[i], local_dof_indices[i]);
}

return;
}

// difficult case with dof_mask, similar to the distribute_local_to_global
// function for block matrices
internal::AffineConstraints::GlobalRowsFromLocal<number> &global_rows =
scratch_data->global_rows;
global_rows.reinit(n_local_dofs);
make_sorted_row_list(local_dof_indices, global_rows);
const size_type n_actual_dofs = global_rows.size();

// additional construct that also takes care of block indices.
std::vector<size_type> &block_starts = scratch_data->block_starts;
block_starts.resize(num_blocks + 1);
internal::AffineConstraints::make_block_starts(sparsity_pattern,
global_rows,
block_starts);

std::vector<size_type> &cols = scratch_data->columns;
cols.resize(n_actual_dofs);

// the basic difference to the non-block variant from now onwards is that we
// go through the blocks of the matrix separately.
for (size_type block = 0; block < num_blocks; ++block)
{
const size_type next_block = block_starts[block + 1];
for (size_type i = block_starts[block]; i < next_block; ++i)
{
const size_type row = global_rows.global_row(i);
for (size_type block_col = 0; block_col < num_blocks; ++block_col)
{
const size_type begin_block = block_starts[block_col],
end_block = block_starts[block_col + 1];
std::vector<size_type>::iterator col_ptr = cols.begin();
internal::AffineConstraints::resolve_matrix_row(
global_rows, i, begin_block, end_block, dof_mask, col_ptr);

sparsity_pattern.block(block, block_col)
.add_entries(row, cols.begin(), col_ptr, true);
}
}
}

internal::AffineConstraints::set_sparsity_diagonals(global_rows,
local_dof_indices,
dof_mask,
keep_constrained_entries,
sparsity_pattern);
}

DEAL_II_NAMESPACE_CLOSE

#endif