From c95f6b80e42ddaf1149593a13b1aec1e3b85803e Mon Sep 17 00:00:00 2001 From: Martin Kronbichler Date: Wed, 25 Aug 2010 14:08:55 +0000 Subject: [PATCH] Add function add_entries_local_to_global for rectangular matrices. git-svn-id: https://svn.dealii.org/trunk@21704 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/lac/include/lac/constraint_matrix.h | 37 ++++++- .../include/lac/constraint_matrix.templates.h | 98 +++++++++++++++++++ deal.II/lac/source/constraint_matrix.cc | 8 +- 3 files changed, 138 insertions(+), 5 deletions(-) diff --git a/deal.II/lac/include/lac/constraint_matrix.h b/deal.II/lac/include/lac/constraint_matrix.h index b3296ce25c..a175c86a65 100644 --- a/deal.II/lac/include/lac/constraint_matrix.h +++ b/deal.II/lac/include/lac/constraint_matrix.h @@ -1359,9 +1359,9 @@ class ConstraintMatrix : public Subscriptor MatrixType &global_matrix) const; /** - * Does the same as the function above - * but can treat - * non quadratic matrices. + * Does the same as the function + * above but can treat non + * quadratic matrices. */ template void @@ -1474,6 +1474,20 @@ class ConstraintMatrix : public Subscriptor template void add_entries_local_to_global (const std::vector &local_dof_indices, + SparsityType &sparsity_pattern, + const bool keep_constrained_entries = true, + const Table<2,bool> &dof_mask = default_empty_table) const; + + /** + * Similar to the other function, + * but for non-quadratic sparsity + * patterns. + */ + + template + void + add_entries_local_to_global (const std::vector &row_indices, + const std::vector &col_indices, SparsityType &sparsity_pattern, const bool keep_constrained_entries = true, const Table<2,bool> &dof_mask = default_empty_table) const; @@ -1894,12 +1908,27 @@ class ConstraintMatrix : public Subscriptor * function. * * Creates a list of affected - * rows for distribution. + * global rows for distribution, + * including the local rows where + * the entries come from. */ void make_sorted_row_list (const std::vector &local_dof_indices, internals::GlobalRowsFromLocal &global_rows) const; + /** + * Internal helper function for + * add_entries_local_to_global + * function. + * + * Creates a list of affected + * rows for distribution without + * any additional information. + */ + void + make_sorted_row_list (const std::vector &local_dof_indices, + std::vector &active_dofs) const; + /** * Internal helper function for * distribute_local_to_global function. diff --git a/deal.II/lac/include/lac/constraint_matrix.templates.h b/deal.II/lac/include/lac/constraint_matrix.templates.h index 0b6aae5a0a..980933b628 100644 --- a/deal.II/lac/include/lac/constraint_matrix.templates.h +++ b/deal.II/lac/include/lac/constraint_matrix.templates.h @@ -2119,6 +2119,54 @@ make_sorted_row_list (const std::vector &local_dof_indices, +inline +void +ConstraintMatrix:: +make_sorted_row_list (const std::vector &local_dof_indices, + std::vector &active_dofs) const +{ + const unsigned int n_local_dofs = local_dof_indices.size(); + unsigned int added_rows = 0; + for (unsigned int i = 0; i0; --i) + { + const unsigned int local_row = active_dofs.back(); + active_dofs.pop_back(); + const unsigned int global_row = local_dof_indices[local_row]; + const ConstraintLine & position = + lines[lines_cache[calculate_line_index(global_row)]]; + for (unsigned int q=0; q::iterator it = + std::lower_bound(active_dofs.begin(), + active_dofs.end()-i+1, + new_index); + if (*it != new_index) + active_dofs.insert(it, new_index); + } + } + } +} + + + template inline void @@ -2598,6 +2646,56 @@ add_entries_local_to_global (const std::vector &local_dof_indices, +template +void +ConstraintMatrix:: +add_entries_local_to_global (const std::vector &row_indices, + const std::vector &col_indices, + SparsityType &sparsity_pattern, + const bool keep_constrained_entries, + const Table<2,bool> &dof_mask) const +{ + const unsigned int n_local_rows = row_indices.size(); + const unsigned int n_local_cols = col_indices.size(); + bool dof_mask_is_active = false; + Assert (keep_constrained_entries == false, ExcNotImplemented()); + if (dof_mask.n_rows() == n_local_rows && dof_mask.n_cols() == n_local_cols) + dof_mask_is_active = true; + + // if the dof mask is not active, all we + // have to do is to add some indices in a + // matrix format. To do this, we first + // create an array of all the indices + // that are to be added. these indices + // are the local dof indices plus some + // indices that come from constraints. + if (dof_mask_is_active == false) + { + 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); + const unsigned int n_actual_rows = actual_row_indices.size(); + + // now add the indices we collected above + // to the sparsity pattern. Very easy + // here - just add the same array to all + // the rows... + for (unsigned int i=0; i void ConstraintMatrix:: diff --git a/deal.II/lac/source/constraint_matrix.cc b/deal.II/lac/source/constraint_matrix.cc index 040a854e4d..689e63be6c 100644 --- a/deal.II/lac/source/constraint_matrix.cc +++ b/deal.II/lac/source/constraint_matrix.cc @@ -2511,7 +2511,13 @@ BLOCK_MATRIX_VECTOR_FUNCTIONS(TrilinosWrappers::BlockSparseMatrix, TrilinosWrapp SparsityType &, \ const bool, \ const Table<2,bool> &, \ - internal::bool2type) const + internal::bool2type) const; \ + template void ConstraintMatrix::add_entries_local_to_global (\ + const std::vector &, \ + const std::vector &, \ + SparsityType &, \ + const bool, \ + const Table<2,bool> &) const #define BLOCK_SPARSITY_FUNCTIONS(SparsityType) \ template void ConstraintMatrix::add_entries_local_to_global (\ const std::vector &, \ -- 2.39.5