From d3f6501bf6607baf487eee1bab924546da1debe6 Mon Sep 17 00:00:00 2001 From: Luca Heltai Date: Fri, 18 Feb 2022 08:47:30 +0000 Subject: [PATCH] Another rectangular version of add_entries_local_to_global() --- doc/news/changes/minor/20220218LucaHeltai | 4 ++ include/deal.II/lac/affine_constraints.h | 14 ++++ .../lac/affine_constraints.templates.h | 36 ++++++++-- source/lac/affine_constraints.inst.in | 8 +++ ...raints_add_entries_local_to_global_rect.cc | 65 +++++++++++++++++++ ...ts_add_entries_local_to_global_rect.output | 11 ++++ 6 files changed, 131 insertions(+), 7 deletions(-) create mode 100644 doc/news/changes/minor/20220218LucaHeltai create mode 100644 tests/lac/constraints_add_entries_local_to_global_rect.cc create mode 100644 tests/lac/constraints_add_entries_local_to_global_rect.output diff --git a/doc/news/changes/minor/20220218LucaHeltai b/doc/news/changes/minor/20220218LucaHeltai new file mode 100644 index 0000000000..68975e01a5 --- /dev/null +++ b/doc/news/changes/minor/20220218LucaHeltai @@ -0,0 +1,4 @@ +New: AffineConstraints::add_entries_local_to_global() now supports also the case +where columns don't use the same constraints as rows. +
+(Luca Heltai, 2022/02/18) diff --git a/include/deal.II/lac/affine_constraints.h b/include/deal.II/lac/affine_constraints.h index eaa2d95da8..2a1ecec635 100644 --- a/include/deal.II/lac/affine_constraints.h +++ b/include/deal.II/lac/affine_constraints.h @@ -1525,6 +1525,20 @@ public: const bool keep_constrained_entries = true, const Table<2, bool> & dof_mask = Table<2, bool>()) const; + /** + * Similar to the other function, but for non-quadratic sparsity patterns, and + * for different constraints in the column space. + */ + template + void + add_entries_local_to_global( + const std::vector & row_indices, + const AffineConstraints &col_constraints, + const std::vector & col_indices, + SparsityPatternType & sparsity_pattern, + const bool keep_constrained_entries = true, + const Table<2, bool> & dof_mask = Table<2, bool>()) const; + /** * This function imports values from a global vector (@p global_vector) by * applying the constraints to a vector of local values, expressed in diff --git a/include/deal.II/lac/affine_constraints.templates.h b/include/deal.II/lac/affine_constraints.templates.h index 76c6d8e68a..489624c50c 100644 --- a/include/deal.II/lac/affine_constraints.templates.h +++ b/include/deal.II/lac/affine_constraints.templates.h @@ -4356,11 +4356,12 @@ template template void AffineConstraints::add_entries_local_to_global( - const std::vector &row_indices, - const std::vector &col_indices, - SparsityPatternType & sparsity_pattern, - const bool keep_constrained_entries, - const Table<2, bool> & dof_mask) const + const std::vector & row_indices, + const AffineConstraints &col_constraints, + const std::vector & col_indices, + SparsityPatternType & sparsity_pattern, + const bool keep_constrained_entries, + const Table<2, bool> & dof_mask) const { const size_type n_local_rows = row_indices.size(); const size_type n_local_cols = col_indices.size(); @@ -4374,7 +4375,7 @@ AffineConstraints::add_entries_local_to_global( for (const size_type col_index : col_indices) sparsity_pattern.add(row_index, col_index); for (const size_type col_index : col_indices) - if (is_constrained(col_index)) + if (col_constraints.is_constrained(col_index)) for (const size_type row_index : row_indices) sparsity_pattern.add(row_index, col_index); } @@ -4390,7 +4391,7 @@ AffineConstraints::add_entries_local_to_global( std::vector actual_row_indices(n_local_rows); std::vector actual_col_indices(n_local_cols); make_sorted_row_list(row_indices, actual_row_indices); - make_sorted_row_list(col_indices, actual_col_indices); + col_constraints.make_sorted_row_list(col_indices, actual_col_indices); const size_type n_actual_rows = actual_row_indices.size(); // now add the indices we collected above to the sparsity pattern. Very @@ -4409,6 +4410,27 @@ AffineConstraints::add_entries_local_to_global( +template +template +void +AffineConstraints::add_entries_local_to_global( + const std::vector &row_indices, + const std::vector &col_indices, + SparsityPatternType & sparsity_pattern, + const bool keep_constrained_entries, + const Table<2, bool> & dof_mask) const +{ + // Call the function with the same name that takes a column constraint as well + add_entries_local_to_global(row_indices, + *this, + col_indices, + sparsity_pattern, + keep_constrained_entries, + dof_mask); +} + + + template template void diff --git a/source/lac/affine_constraints.inst.in b/source/lac/affine_constraints.inst.in index 4fcb197a8a..100236c270 100644 --- a/source/lac/affine_constraints.inst.in +++ b/source/lac/affine_constraints.inst.in @@ -272,6 +272,14 @@ for (S : REAL_AND_COMPLEX_SCALARS; SP : AFFINE_CONSTRAINTS_SP) SP &, const bool, const Table<2, bool> &) const; + + template void AffineConstraints::add_entries_local_to_global( + const std::vector::size_type> &, + const AffineConstraints &, + const std::vector::size_type> &, + SP &, + const bool, + const Table<2, bool> &) const; } for (S : REAL_AND_COMPLEX_SCALARS; SP : AFFINE_CONSTRAINTS_SP_BLOCK) diff --git a/tests/lac/constraints_add_entries_local_to_global_rect.cc b/tests/lac/constraints_add_entries_local_to_global_rect.cc new file mode 100644 index 0000000000..78bb9d249b --- /dev/null +++ b/tests/lac/constraints_add_entries_local_to_global_rect.cc @@ -0,0 +1,65 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2017 - 2018 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.md at +// the top level directory of deal.II. +// +// --------------------------------------------------------------------- + + + +// this function tests the correctness of the implementation of +// AffineConstraints::add_entries_local_to_global for row and column +// indices with different constraints on the rows and columns. + +#include + +#include +#include + +#include + +#include "../tests.h" + +void +test() +{ + DynamicSparsityPattern dsp1(4, 6), dsp2(4, 6); + AffineConstraints cm1, cm2; + cm1.add_line(2); + cm1.add_entry(2, 1, 0.5); + cm1.add_entry(2, 3, 0.5); + cm1.close(); + cm2.add_line(4); + cm2.add_entry(4, 2, 0.3); + cm2.add_entry(4, 5, 0.7); + cm2.close(); + + std::vector indices1(2), indices2(2); + indices1[0] = 1; + indices1[1] = 2; + indices2[0] = 4; + indices2[1] = 5; + cm1.add_entries_local_to_global(indices1, indices2, dsp1); + deallog << "Same constraints: " << std::endl; + dsp1.print(deallog.get_file_stream()); + cm1.add_entries_local_to_global(indices1, cm2, indices2, dsp2); + deallog << "Different constraints: " << std::endl; + dsp2.print(deallog.get_file_stream()); +} + + +int +main() +{ + initlog(); + + test(); +} diff --git a/tests/lac/constraints_add_entries_local_to_global_rect.output b/tests/lac/constraints_add_entries_local_to_global_rect.output new file mode 100644 index 0000000000..c9cf61dc54 --- /dev/null +++ b/tests/lac/constraints_add_entries_local_to_global_rect.output @@ -0,0 +1,11 @@ + +DEAL::Same constraints: +[0] +[1,4,5] +[2,4,5] +[3,4,5] +DEAL::Different constraints: +[0] +[1,2,4,5] +[2,4,5] +[3,2,5] -- 2.39.5