From: Peter Munch Date: Fri, 22 Dec 2023 08:59:29 +0000 (+0100) Subject: Add class template X-Git-Tag: relicensing~118^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F16339%2Fhead;p=dealii.git Add class template --- diff --git a/include/deal.II/matrix_free/constraint_info.h b/include/deal.II/matrix_free/constraint_info.h index 184587c5a6..0fceab7b3d 100644 --- a/include/deal.II/matrix_free/constraint_info.h +++ b/include/deal.II/matrix_free/constraint_info.h @@ -81,7 +81,7 @@ namespace internal * user code. It combines constraint related functionalities from * MatrixFree and FEEvaluation. */ - template + template class ConstraintInfo { public: @@ -101,13 +101,11 @@ namespace internal * Version 1: indices are extracted from DoFCellAccessor and * constraints are resolved with the help of AffineConstraints. */ - template void reinit(const DoFHandler &dof_handler, const unsigned int n_cells, const bool use_fast_hanging_node_algorithm = true); - template void read_dof_indices( const unsigned int cell_no, @@ -120,22 +118,18 @@ namespace internal /** * Version 2: no constraints, indices are user-provided. */ - template void reinit(const unsigned int n_cells); - template void read_dof_indices( const unsigned int cell_no, const std::vector &dof_indices, const std::shared_ptr &partitioner); - template void finalize(); - template std::shared_ptr finalize(const MPI_Comm comm); @@ -167,16 +161,16 @@ namespace internal ConstraintValues constraint_values; std::vector> dof_indices_per_cell; std::vector> plain_dof_indices_per_cell; - std::vector> - dof_indices_per_cell_long; - std::vector> - plain_dof_indices_per_cell_long; std::vector>> constraint_indicator_per_cell; std::unique_ptr> hanging_nodes; std::vector> lexicographic_numbering; + std::vector local_dof_indices; + std::vector local_dof_indices_lex; + std::vector mask; + IndexSet locally_owned_indices; std::pair local_range; @@ -204,35 +198,6 @@ namespace internal inline const typename Number::value_type * constraint_pool_end(const unsigned int row) const; - - // TODO - std::vector local_dof_indices; - std::vector local_dof_indices_lex; - std::vector mask; - - template - std::vector> & - get_dof_indices_per_cell() - { - if constexpr (std::is_same_v) - return dof_indices_per_cell; - else if constexpr (std::is_same_v) - return dof_indices_per_cell_long; - else - return {}; - } - - template - std::vector> & - get_plain_dof_indices_per_cell() - { - if constexpr (std::is_same_v) - return plain_dof_indices_per_cell; - else if constexpr (std::is_same_v) - return plain_dof_indices_per_cell_long; - else - return {}; - } }; @@ -305,16 +270,16 @@ namespace internal - template - ConstraintInfo::ConstraintInfo() + template + ConstraintInfo::ConstraintInfo() : local_range({0, 0}) {} - template + template void - ConstraintInfo::set_locally_owned_indices( + ConstraintInfo::set_locally_owned_indices( const IndexSet &locally_owned_indices) { this->locally_owned_indices = locally_owned_indices; @@ -329,16 +294,15 @@ namespace internal - template - template + template inline void - ConstraintInfo::reinit( + ConstraintInfo::reinit( const DoFHandler &dof_handler, const unsigned int n_cells, const bool use_fast_hanging_node_algorithm) { - this->template get_dof_indices_per_cell().resize(n_cells); - this->template get_plain_dof_indices_per_cell().resize(n_cells); + this->dof_indices_per_cell.resize(n_cells); + this->plain_dof_indices_per_cell.resize(n_cells); this->constraint_indicator_per_cell.resize(n_cells); // note: has_hanging_nodes() is a global operatrion @@ -380,22 +344,20 @@ namespace internal - template - template + template inline void - ConstraintInfo::reinit(const unsigned int n_cells) + ConstraintInfo::reinit(const unsigned int n_cells) { - this->template get_dof_indices_per_cell().resize(n_cells); - this->template get_plain_dof_indices_per_cell().resize(0); + this->dof_indices_per_cell.resize(n_cells); + this->plain_dof_indices_per_cell.resize(0); this->constraint_indicator_per_cell.resize(n_cells); } - template - template + template inline void - ConstraintInfo::read_dof_indices( + ConstraintInfo::read_dof_indices( const unsigned int cell_no, const unsigned int mg_level, const TriaIterator> &cell, @@ -427,24 +389,19 @@ namespace internal std::pair constraint_iterator(0, 0); AssertIndexRange(cell_no, this->constraint_indicator_per_cell.size()); - AssertIndexRange(cell_no, - this->template get_dof_indices_per_cell().size()); - AssertIndexRange( - cell_no, this->template get_plain_dof_indices_per_cell().size()); + AssertIndexRange(cell_no, this->dof_indices_per_cell.size()); + AssertIndexRange(cell_no, this->plain_dof_indices_per_cell.size()); auto &constraint_indicator = this->constraint_indicator_per_cell[cell_no]; - auto &dof_indices = this->template get_dof_indices_per_cell()[cell_no]; - auto &plain_dof_indices = - this->template get_plain_dof_indices_per_cell()[cell_no]; + auto &dof_indices = this->dof_indices_per_cell[cell_no]; + auto &plain_dof_indices = this->plain_dof_indices_per_cell[cell_no]; AssertDimension(constraint_indicator_per_cell[cell_no].size(), 0); - AssertDimension( - this->template get_dof_indices_per_cell()[cell_no].size(), 0); - AssertDimension( - this->template get_plain_dof_indices_per_cell()[cell_no].size(), 0); + AssertDimension(this->dof_indices_per_cell[cell_no].size(), 0); + AssertDimension(this->plain_dof_indices_per_cell[cell_no].size(), 0); const auto global_to_local = - [&](const types::global_dof_index global_index) -> T { + [&](const types::global_dof_index global_index) -> IndexType { if (partitioner) return partitioner->global_to_local(global_index); else @@ -530,16 +487,15 @@ namespace internal - template - template + template inline void - ConstraintInfo::read_dof_indices( + ConstraintInfo::read_dof_indices( const unsigned int cell_no, const std::vector &local_dof_indices_lex, const std::shared_ptr &partitioner) { const auto global_to_local = - [&](const types::global_dof_index global_index) -> T { + [&](const types::global_dof_index global_index) -> IndexType { if (partitioner) return partitioner->global_to_local(global_index); else @@ -555,7 +511,7 @@ namespace internal std::pair constraint_iterator(0, 0); auto &constraint_indicator = this->constraint_indicator_per_cell[cell_no]; - auto &dof_indices = this->template get_dof_indices_per_cell()[cell_no]; + auto &dof_indices = this->dof_indices_per_cell[cell_no]; for (const auto current_dof : local_dof_indices_lex) { @@ -588,10 +544,9 @@ namespace internal - template - template + template inline void - ConstraintInfo::finalize() + ConstraintInfo::finalize() { Assert((local_range == std::pair{0, @@ -605,20 +560,17 @@ namespace internal this->row_starts = {}; this->row_starts.emplace_back(0, 0); - if (this->template get_plain_dof_indices_per_cell().empty() == false) + if (this->plain_dof_indices_per_cell.empty() == false) { this->row_starts_plain_indices = {}; this->row_starts_plain_indices.emplace_back(0); } - for (unsigned int i = 0; - i < this->template get_dof_indices_per_cell().size(); - ++i) + for (unsigned int i = 0; i < this->dof_indices_per_cell.size(); ++i) { - this->dof_indices.insert( - this->dof_indices.end(), - this->template get_dof_indices_per_cell()[i].begin(), - this->template get_dof_indices_per_cell()[i].end()); + this->dof_indices.insert(this->dof_indices.end(), + this->dof_indices_per_cell[i].begin(), + this->dof_indices_per_cell[i].end()); this->constraint_indicator.insert( this->constraint_indicator.end(), constraint_indicator_per_cell[i].begin(), @@ -627,13 +579,12 @@ namespace internal this->row_starts.emplace_back(this->dof_indices.size(), this->constraint_indicator.size()); - if (this->template get_plain_dof_indices_per_cell().empty() == - false) + if (this->plain_dof_indices_per_cell.empty() == false) { this->plain_dof_indices.insert( this->plain_dof_indices.end(), - this->template get_plain_dof_indices_per_cell()[i].begin(), - this->template get_plain_dof_indices_per_cell()[i].end()); + this->plain_dof_indices_per_cell[i].begin(), + this->plain_dof_indices_per_cell[i].end()); this->row_starts_plain_indices.emplace_back( this->plain_dof_indices.size()); @@ -667,7 +618,7 @@ namespace internal AssertDimension(constraint_pool_data.size(), length); - this->template get_dof_indices_per_cell().clear(); + this->dof_indices_per_cell.clear(); constraint_indicator_per_cell.clear(); if (hanging_nodes && @@ -680,51 +631,43 @@ namespace internal } - template - template + template inline std::shared_ptr - ConstraintInfo::finalize(const MPI_Comm comm) + ConstraintInfo::finalize(const MPI_Comm comm) { this->dof_indices.clear(); this->plain_dof_indices.clear(); this->constraint_indicator.clear(); this->row_starts.clear(); - this->row_starts.reserve( - this->template get_dof_indices_per_cell().size()); + this->row_starts.reserve(this->dof_indices_per_cell.size()); this->row_starts.emplace_back(0, 0); - if (this->template get_plain_dof_indices_per_cell().empty() == false) + if (this->plain_dof_indices_per_cell.empty() == false) { this->row_starts_plain_indices.clear(); this->row_starts_plain_indices.reserve( - this->template get_dof_indices_per_cell().size()); + this->dof_indices_per_cell.size()); this->row_starts_plain_indices.emplace_back(0); } std::vector ghost_dofs; std::pair counts = {0, 0}; - for (unsigned int i = 0; - i < this->template get_dof_indices_per_cell().size(); - ++i) + for (unsigned int i = 0; i < this->dof_indices_per_cell.size(); ++i) { - counts.first += - this->template get_dof_indices_per_cell()[i].size(); + counts.first += this->dof_indices_per_cell[i].size(); - for (const auto &j : this->template get_dof_indices_per_cell()[i]) + for (const auto &j : this->dof_indices_per_cell[i]) if (j >= (local_range.second - local_range.first)) ghost_dofs.push_back(j - (local_range.second - local_range.first)); - if (this->template get_plain_dof_indices_per_cell().empty() == - false) + if (this->plain_dof_indices_per_cell.empty() == false) { - counts.second += - this->template get_plain_dof_indices_per_cell()[i].size(); + counts.second += this->plain_dof_indices_per_cell[i].size(); - for (const auto &j : - this->template get_plain_dof_indices_per_cell()[i]) + for (const auto &j : this->plain_dof_indices_per_cell[i]) if (j >= (local_range.second - local_range.first)) ghost_dofs.push_back( j - (local_range.second - local_range.first)); @@ -746,11 +689,9 @@ namespace internal this->dof_indices.reserve(counts.first); this->plain_dof_indices.reserve(counts.second); - for (unsigned int i = 0; - i < this->template get_dof_indices_per_cell().size(); - ++i) + for (unsigned int i = 0; i < this->dof_indices_per_cell.size(); ++i) { - for (const auto &j : this->template get_dof_indices_per_cell()[i]) + for (const auto &j : this->dof_indices_per_cell[i]) if (j < (local_range.second - local_range.first)) this->dof_indices.push_back(j); else @@ -765,11 +706,9 @@ namespace internal this->row_starts.emplace_back(this->dof_indices.size(), this->constraint_indicator.size()); - if (this->template get_plain_dof_indices_per_cell().empty() == - false) + if (this->plain_dof_indices_per_cell.empty() == false) { - for (const auto &j : - this->template get_plain_dof_indices_per_cell()[i]) + for (const auto &j : this->plain_dof_indices_per_cell[i]) if (j < (local_range.second - local_range.first)) this->plain_dof_indices.push_back(j); else @@ -809,7 +748,7 @@ namespace internal AssertDimension(constraint_pool_data.size(), length); - this->template get_dof_indices_per_cell().clear(); + this->dof_indices_per_cell.clear(); constraint_indicator_per_cell.clear(); if (hanging_nodes && @@ -825,10 +764,10 @@ namespace internal - template + template template inline void - ConstraintInfo::read_write_operation( + ConstraintInfo::read_write_operation( const T &operation, VectorType &global_vector, Number *local_vector, @@ -910,9 +849,9 @@ namespace internal - template + template inline void - ConstraintInfo::apply_hanging_node_constraints( + ConstraintInfo::apply_hanging_node_constraints( const unsigned int first_cell, const unsigned int n_lanes_filled, const bool transpose, @@ -961,9 +900,9 @@ namespace internal - template + template inline const typename Number::value_type * - ConstraintInfo::constraint_pool_begin( + ConstraintInfo::constraint_pool_begin( const unsigned int row) const { AssertIndexRange(row, constraint_pool_row_index.size() - 1); @@ -974,9 +913,9 @@ namespace internal - template + template inline const typename Number::value_type * - ConstraintInfo::constraint_pool_end( + ConstraintInfo::constraint_pool_end( const unsigned int row) const { AssertIndexRange(row, constraint_pool_row_index.size() - 1); @@ -987,18 +926,15 @@ namespace internal - template + template inline std::size_t - ConstraintInfo::memory_consumption() const + ConstraintInfo::memory_consumption() const { std::size_t size = 0; size += MemoryConsumption::memory_consumption(constraint_values); size += MemoryConsumption::memory_consumption(dof_indices_per_cell); size += MemoryConsumption::memory_consumption(plain_dof_indices_per_cell); - size += MemoryConsumption::memory_consumption(dof_indices_per_cell_long); - size += - MemoryConsumption::memory_consumption(plain_dof_indices_per_cell_long); size += MemoryConsumption::memory_consumption(constraint_indicator_per_cell); diff --git a/include/deal.II/multigrid/mg_transfer_global_coarsening.h b/include/deal.II/multigrid/mg_transfer_global_coarsening.h index 4dd0407ccf..13b0919991 100644 --- a/include/deal.II/multigrid/mg_transfer_global_coarsening.h +++ b/include/deal.II/multigrid/mg_transfer_global_coarsening.h @@ -357,17 +357,17 @@ protected: * Enable inplace vector operations if external and internal vectors * are compatible. */ - template + template void internal_enable_inplace_operations_if_possible( const std::shared_ptr &partitioner_coarse, const std::shared_ptr &partitioner_fine, bool &vec_fine_needs_ghost_update, - internal::MatrixFreeFunctions::ConstraintInfo< - dim, - VectorizedArray> &constraint_info_coarse, - std::vector &dof_indices_fine); + internal::MatrixFreeFunctions:: + ConstraintInfo, IndexType> + &constraint_info_coarse, + std::vector &dof_indices_fine); /** * Flag if the finite elements on the fine cells are continuous. If yes, @@ -684,14 +684,16 @@ private: * Helper class for reading from and writing to global coarse vectors and for * applying constraints. */ - internal::MatrixFreeFunctions::ConstraintInfo - constraint_info_coarse; + internal::MatrixFreeFunctions:: + ConstraintInfo + constraint_info_coarse; /** * Helper class for reading from and writing to global fine vectors. */ - internal::MatrixFreeFunctions::ConstraintInfo - constraint_info_fine; + internal::MatrixFreeFunctions:: + ConstraintInfo + constraint_info_fine; /** * Weights for continuous elements. @@ -959,8 +961,9 @@ private: * Helper class for reading from and writing to global vectors and for * applying constraints. */ - internal::MatrixFreeFunctions::ConstraintInfo - constraint_info; + internal::MatrixFreeFunctions:: + ConstraintInfo + constraint_info; /** * Finite element of the coarse DoFHandler passed to reinit(). diff --git a/include/deal.II/multigrid/mg_transfer_global_coarsening.templates.h b/include/deal.II/multigrid/mg_transfer_global_coarsening.templates.h index 776cc66593..4793542ce9 100644 --- a/include/deal.II/multigrid/mg_transfer_global_coarsening.templates.h +++ b/include/deal.II/multigrid/mg_transfer_global_coarsening.templates.h @@ -1781,20 +1781,19 @@ namespace internal unsigned int cell_no_0 = 0; unsigned int cell_no_1 = transfer.schemes[0].n_coarse_cells; - transfer.constraint_info_coarse - .template reinit( - dof_handler_coarse, - transfer.schemes[0].n_coarse_cells + - transfer.schemes[1].n_coarse_cells, - constraints_coarse.n_constraints() > 0 && - use_fast_hanging_node_algorithm(dof_handler_coarse, - mg_level_coarse)); + transfer.constraint_info_coarse.reinit( + dof_handler_coarse, + transfer.schemes[0].n_coarse_cells + + transfer.schemes[1].n_coarse_cells, + constraints_coarse.n_constraints() > 0 && + use_fast_hanging_node_algorithm(dof_handler_coarse, + mg_level_coarse)); transfer.constraint_info_coarse.set_locally_owned_indices( (mg_level_coarse == numbers::invalid_unsigned_int) ? dof_handler_coarse.locally_owned_dofs() : dof_handler_coarse.locally_owned_mg_dofs(mg_level_coarse)); - transfer.constraint_info_fine.template reinit( + transfer.constraint_info_fine.reinit( transfer.schemes[0].n_coarse_cells + transfer.schemes[1].n_coarse_cells); transfer.constraint_info_fine.set_locally_owned_indices( @@ -1806,13 +1805,12 @@ namespace internal [&](const auto &cell_coarse, const auto &cell_fine) { // parent { - transfer.constraint_info_coarse - .template read_dof_indices( - cell_no_0, - mg_level_coarse, - cell_coarse, - constraints_coarse, - {}); + transfer.constraint_info_coarse.read_dof_indices( + cell_no_0, + mg_level_coarse, + cell_coarse, + constraints_coarse, + {}); } // child @@ -1824,9 +1822,8 @@ namespace internal level_dof_indices_fine_0[i] = local_dof_indices[lexicographic_numbering_fine[i]]; - transfer.constraint_info_fine - .template read_dof_indices( - cell_no_0, level_dof_indices_fine_0, {}); + transfer.constraint_info_fine.read_dof_indices( + cell_no_0, level_dof_indices_fine_0, {}); } // move pointers @@ -1838,13 +1835,12 @@ namespace internal // parent (only once at the beginning) if (c == 0) { - transfer.constraint_info_coarse - .template read_dof_indices( - cell_no_1, - mg_level_coarse, - cell_coarse, - constraints_coarse, - {}); + transfer.constraint_info_coarse.read_dof_indices( + cell_no_1, + mg_level_coarse, + cell_coarse, + constraints_coarse, + {}); level_dof_indices_fine_1.assign(level_dof_indices_fine_1.size(), numbers::invalid_dof_index); @@ -1875,9 +1871,8 @@ namespace internal // move pointers (only once at the end) if (c + 1 == GeometryInfo::max_children_per_cell) { - transfer.constraint_info_fine - .template read_dof_indices( - cell_no_1, level_dof_indices_fine_1, {}); + transfer.constraint_info_fine.read_dof_indices( + cell_no_1, level_dof_indices_fine_1, {}); cell_no_1++; } @@ -1885,16 +1880,12 @@ namespace internal } { - transfer.partitioner_coarse = - transfer.constraint_info_coarse - .template finalize( - dof_handler_coarse.get_communicator()); + transfer.partitioner_coarse = transfer.constraint_info_coarse.finalize( + dof_handler_coarse.get_communicator()); transfer.vec_coarse.reinit(transfer.partitioner_coarse); - transfer.partitioner_fine = - transfer.constraint_info_fine - .template finalize( - dof_handler_fine.get_communicator()); + transfer.partitioner_fine = transfer.constraint_info_fine.finalize( + dof_handler_fine.get_communicator()); transfer.vec_fine.reinit(transfer.partitioner_fine); } @@ -2286,13 +2277,12 @@ namespace internal // parent { - transfer.constraint_info_coarse - .template read_dof_indices( - cell_no[fe_pair_no], - mg_level_coarse, - cell_coarse, - constraints_coarse, - {}); + transfer.constraint_info_coarse.read_dof_indices( + cell_no[fe_pair_no], + mg_level_coarse, + cell_coarse, + constraints_coarse, + {}); } // child @@ -2305,11 +2295,8 @@ namespace internal local_dof_indices_fine_lex[fe_pair_no][i] = local_dof_indices_fine [fe_pair_no][lexicographic_numbering_fine[fe_pair_no][i]]; - transfer.constraint_info_fine - .template read_dof_indices( - cell_no[fe_pair_no], - local_dof_indices_fine_lex[fe_pair_no], - {}); + transfer.constraint_info_fine.read_dof_indices( + cell_no[fe_pair_no], local_dof_indices_fine_lex[fe_pair_no], {}); } // move pointers @@ -2320,16 +2307,12 @@ namespace internal } { - transfer.partitioner_coarse = - transfer.constraint_info_coarse - .template finalize( - dof_handler_coarse.get_communicator()); + transfer.partitioner_coarse = transfer.constraint_info_coarse.finalize( + dof_handler_coarse.get_communicator()); transfer.vec_coarse.reinit(transfer.partitioner_coarse); - transfer.partitioner_fine = - transfer.constraint_info_fine - .template finalize( - dof_handler_fine.get_communicator()); + transfer.partitioner_fine = transfer.constraint_info_fine.finalize( + dof_handler_fine.get_communicator()); transfer.vec_fine.reinit(transfer.partitioner_fine); } @@ -3406,7 +3389,7 @@ namespace internal } // namespace internal template -template +template void MGTwoLevelTransferBase>:: internal_enable_inplace_operations_if_possible( @@ -3415,10 +3398,10 @@ MGTwoLevelTransferBase>:: const std::shared_ptr &external_partitioner_fine, bool &vec_fine_needs_ghost_update, - internal::MatrixFreeFunctions::ConstraintInfo< - dim, - VectorizedArray> &constraint_info_coarse, - std::vector &dof_indices_fine) + internal::MatrixFreeFunctions:: + ConstraintInfo, IndexType> + &constraint_info_coarse, + std::vector &dof_indices_fine) { if (this->partitioner_coarse->is_globally_compatible( *external_partitioner_coarse))