From 6fe243d706e71e857065e188719203445f1dced2 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Sat, 30 May 2020 11:00:19 -0600 Subject: [PATCH] Move implementations out of structure declarations. --- .../lac/affine_constraints.templates.h | 203 +++++++++++------- 1 file changed, 128 insertions(+), 75 deletions(-) diff --git a/include/deal.II/lac/affine_constraints.templates.h b/include/deal.II/lac/affine_constraints.templates.h index db36143180..c123426194 100644 --- a/include/deal.II/lac/affine_constraints.templates.h +++ b/include/deal.II/lac/affine_constraints.templates.h @@ -2331,28 +2331,33 @@ namespace internal { using size_type = types::global_dof_index; - // this struct contains all the information we need to store about each of - // the global entries (global_row): are they obtained directly by some local - // entry (local_row) or some constraints (constraint_position). This is not - // directly used in the user code, but accessed via the GlobalRowsFromLocal. - // - // The actions performed here correspond to reshaping the constraint - // information from global degrees of freedom to local ones (i.e., - // cell-related DoFs), and also transforming the constraint information from - // compressed row storage (each local dof that is constrained has a list of - // constraint entries associated to it) into compressed column storage based - // on the cell-related DoFs (we have a list of global degrees of freedom, - // and to each we have a list of local rows where the entries come from). To - // increase the speed, we additionally store whether an entry is generated - // directly from the local degrees of freedom or whether it comes from a - // constraint. + /** + * This struct contains all the information we need to store about each of + * the global entries (global_row): are they obtained directly by some local + * entry (local_row) or some constraints (constraint_position). This is not + * directly used in the user code, but accessed via the GlobalRowsFromLocal. + * + * The actions performed here correspond to reshaping the constraint + * information from global degrees of freedom to local ones (i.e., + * cell-related DoFs), and also transforming the constraint information from + * compressed row storage (each local dof that is constrained has a list of + * constraint entries associated to it) into compressed column storage based + * on the cell-related DoFs (we have a list of global degrees of freedom, + * and to each we have a list of local rows where the entries come from). To + * increase the speed, we additionally store whether an entry is generated + * directly from the local degrees of freedom or whether it comes from a + * constraint. + */ struct Distributing { Distributing(const size_type global_row = numbers::invalid_size_type, const size_type local_row = numbers::invalid_size_type); + Distributing(const Distributing &in); + Distributing & operator=(const Distributing &in); + bool operator<(const Distributing &in) const { @@ -2364,6 +2369,8 @@ namespace internal mutable size_type constraint_position; }; + + inline Distributing::Distributing(const size_type global_row, const size_type local_row) : global_row(global_row) @@ -2371,12 +2378,16 @@ namespace internal , constraint_position(numbers::invalid_size_type) {} + + inline Distributing::Distributing(const Distributing &in) : constraint_position(numbers::invalid_size_type) { *this = (in); } + + inline Distributing & Distributing::operator=(const Distributing &in) { @@ -2394,80 +2405,39 @@ namespace internal return *this; } - // this is a cache for constraints that are encountered on a local level. - // The functionality is similar to - // std::vector > >, but tuned so that - // frequent memory allocation for each entry is avoided. The data is put - // into a std::vector > and the row length is kept - // fixed at row_length. Both the number of rows and the row length can - // change is this structure is filled. In that case, the data is - // rearranged. This is not directly used in the user code, but accessed - // via the GlobalRowsFromLocal. + + + /** + * This class represents a cache for constraints that are encountered on a + * local level. The functionality is similar to + * std::vector > >, but tuned so that + * frequent memory allocation for each entry is avoided. The data is put + * into a std::vector > and the row length is kept + * fixed at row_length. Both the number of rows and the row length can + * change is this structure is filled. In that case, the data is + * rearranged. This is not directly used in the user code, but accessed + * via the GlobalRowsFromLocal. + */ template struct DataCache { - DataCache() - : row_length(8) - {} + DataCache(); void - reinit() - { - individual_size.resize(0); - data.resize(0); - } + reinit(); size_type - insert_new_index(const std::pair &pair) - { - Assert(row_length > 0, ExcInternalError()); - const unsigned int index = individual_size.size(); - individual_size.push_back(1); - data.resize(individual_size.size() * row_length); - data[index * row_length] = pair; - individual_size[index] = 1; - return index; - } + insert_new_index(const std::pair &pair); void append_index(const size_type index, - const std::pair &pair) - { - AssertIndexRange(index, individual_size.size()); - const size_type my_length = individual_size[index]; - if (my_length == row_length) - { - AssertDimension(data.size(), individual_size.size() * row_length); - // no space left in this row, need to double row_length and - // rearrange the data items. Move all items to the right except the - // first one, starting at the back. Since individual_size contains - // at least one element when we get here, subtracting 1 works fine. - data.resize(2 * data.size()); - for (size_type i = individual_size.size() - 1; i > 0; --i) - { - const auto ptr = data.data(); - std::move_backward(ptr + i * row_length, - ptr + i * row_length + individual_size[i], - ptr + i * 2 * row_length + - individual_size[i]); - } - row_length *= 2; - } - data[index * row_length + my_length] = pair; - individual_size[index] = my_length + 1; - } + const std::pair &pair); size_type - get_size(const size_type index) const - { - return individual_size[index]; - } + get_size(const size_type index) const; const std::pair * - get_entry(const size_type index) const - { - return &data[index * row_length]; - } + get_entry(const size_type index) const; size_type row_length; @@ -2476,6 +2446,89 @@ namespace internal std::vector individual_size; }; + + + template + DataCache::DataCache() + : row_length(8) + {} + + + + template + void + DataCache::reinit() + { + individual_size.resize(0); + data.resize(0); + } + + + + template + size_type + DataCache::insert_new_index( + const std::pair &pair) + { + Assert(row_length > 0, ExcInternalError()); + const unsigned int index = individual_size.size(); + individual_size.push_back(1); + data.resize(individual_size.size() * row_length); + data[index * row_length] = pair; + individual_size[index] = 1; + return index; + } + + + + template + void + DataCache::append_index(const size_type index, + const std::pair &pair) + { + AssertIndexRange(index, individual_size.size()); + const size_type my_length = individual_size[index]; + if (my_length == row_length) + { + AssertDimension(data.size(), individual_size.size() * row_length); + // no space left in this row, need to double row_length and + // rearrange the data items. Move all items to the right except the + // first one, starting at the back. Since individual_size contains + // at least one element when we get here, subtracting 1 works fine. + data.resize(2 * data.size()); + for (size_type i = individual_size.size() - 1; i > 0; --i) + { + const auto ptr = data.data(); + std::move_backward(ptr + i * row_length, + ptr + i * row_length + individual_size[i], + ptr + i * 2 * row_length + individual_size[i]); + } + row_length *= 2; + } + data[index * row_length + my_length] = pair; + individual_size[index] = my_length + 1; + } + + + + template + size_type + DataCache::get_size(const size_type index) const + { + return individual_size[index]; + } + + + + template + const std::pair * + DataCache::get_entry(const size_type index) const + { + return &data[index * row_length]; + } + + + /** * A data structure that collects all the global rows from a local * contribution (cell) and their origin (direct/constraint). This -- 2.39.5