From 2be4e4b02f80f3a34fa2d930a589e9a3e95ce1eb Mon Sep 17 00:00:00 2001 From: Matthias Maier Date: Sun, 27 May 2018 19:25:06 -0500 Subject: [PATCH] MatrixFree: Templatify reinit functions Unfortunately, we have a bit of a clashing ideology here: - The MatrixFree container is motivated by the old ConstraintMatrix object. Meaning it expects constraints to be expressed in double. - AffineConstraints, however, should be matched with the underlying number type. And the rest of the library now assumes that this is the case (in particular project_matrix_free and variants...) In order to facilitate both approaches, we have to slab another "number" template aorund the reinit functions. That's a bit unfortunate but cannot be avoided. :-/ --- include/deal.II/matrix_free/matrix_free.h | 151 +++++++++--------- .../matrix_free/matrix_free.templates.h | 13 +- source/matrix_free/matrix_free.inst.in | 33 ++++ 3 files changed, 118 insertions(+), 79 deletions(-) diff --git a/include/deal.II/matrix_free/matrix_free.h b/include/deal.II/matrix_free/matrix_free.h index 4048a4fbb5..8231d0b11c 100644 --- a/include/deal.II/matrix_free/matrix_free.h +++ b/include/deal.II/matrix_free/matrix_free.h @@ -486,24 +486,24 @@ public: * not allowed. In that case, use the initialization function with * several DoFHandler arguments. */ - template + template void - reinit(const Mapping & mapping, - const DoFHandlerType & dof_handler, - const AffineConstraints &constraint, - const QuadratureType & quad, - const AdditionalData additional_data = AdditionalData()); + reinit(const Mapping & mapping, + const DoFHandlerType & dof_handler, + const AffineConstraints &constraint, + const QuadratureType & quad, + const AdditionalData additional_data = AdditionalData()); /** * Initializes the data structures. Same as above, but using a $Q_1$ * mapping. */ - template + template void - reinit(const DoFHandlerType & dof_handler, - const AffineConstraints &constraint, - const QuadratureType & quad, - const AdditionalData additional_data = AdditionalData()); + reinit(const DoFHandlerType & dof_handler, + const AffineConstraints &constraint, + const QuadratureType & quad, + const AdditionalData additional_data = AdditionalData()); /** * Same as above. @@ -512,14 +512,14 @@ public: * more. Use the reinit function without index set argument to choose the * one provided by DoFHandler::locally_owned_dofs(). */ - template + template DEAL_II_DEPRECATED void - reinit(const Mapping & mapping, - const DoFHandlerType & dof_handler, - const AffineConstraints &constraint, - const IndexSet & locally_owned_dofs, - const QuadratureType & quad, - const AdditionalData additional_data = AdditionalData()); + reinit(const Mapping & mapping, + const DoFHandlerType & dof_handler, + const AffineConstraints &constraint, + const IndexSet & locally_owned_dofs, + const QuadratureType & quad, + const AdditionalData additional_data = AdditionalData()); /** * Extracts the information needed to perform loops over cells. The @@ -541,23 +541,23 @@ public: * can be sets independently from the number of DoFHandlers, when several * elements are always integrated with the same quadrature formula. */ - template + template void - reinit(const Mapping & mapping, - const std::vector & dof_handler, - const std::vector *> &constraint, - const std::vector & quad, + reinit(const Mapping & mapping, + const std::vector & dof_handler, + const std::vector *> &constraint, + const std::vector & quad, const AdditionalData additional_data = AdditionalData()); /** * Initializes the data structures. Same as above, but using a $Q_1$ * mapping. */ - template + template void - reinit(const std::vector & dof_handler, - const std::vector *> &constraint, - const std::vector & quad, + reinit(const std::vector & dof_handler, + const std::vector *> &constraint, + const std::vector & quad, const AdditionalData additional_data = AdditionalData()); /** @@ -567,11 +567,11 @@ public: * more. Use the reinit function without index set argument to choose the * one provided by DoFHandler::locally_owned_dofs(). */ - template + template DEAL_II_DEPRECATED void - reinit(const Mapping & mapping, - const std::vector & dof_handler, - const std::vector *> &constraint, + reinit(const Mapping & mapping, + const std::vector & dof_handler, + const std::vector *> &constraint, const std::vector & locally_owned_set, const std::vector &quad, const AdditionalData additional_data = AdditionalData()); @@ -583,23 +583,23 @@ public: * as might be necessary when several components in a vector-valued problem * are integrated together based on the same quadrature formula. */ - template + template void - reinit(const Mapping & mapping, - const std::vector & dof_handler, - const std::vector *> &constraint, - const QuadratureType & quad, + reinit(const Mapping & mapping, + const std::vector & dof_handler, + const std::vector *> &constraint, + const QuadratureType & quad, const AdditionalData additional_data = AdditionalData()); /** * Initializes the data structures. Same as above, but using a $Q_1$ * mapping. */ - template + template void - reinit(const std::vector & dof_handler, - const std::vector *> &constraint, - const QuadratureType & quad, + reinit(const std::vector & dof_handler, + const std::vector *> &constraint, + const QuadratureType & quad, const AdditionalData additional_data = AdditionalData()); /** @@ -1578,26 +1578,28 @@ private: * This is the actual reinit function that sets up the indices for the * DoFHandler case. */ + template void internal_reinit( - const Mapping & mapping, - const std::vector *> & dof_handler, - const std::vector *> &constraint, - const std::vector & locally_owned_set, - const std::vector> & quad, - const AdditionalData & additional_data); + const Mapping & mapping, + const std::vector *> & dof_handler, + const std::vector *> &constraint, + const std::vector & locally_owned_set, + const std::vector> & quad, + const AdditionalData & additional_data); /** * Same as before but for hp::DoFHandler instead of generic DoFHandler type. */ + template void internal_reinit( - const Mapping & mapping, - const std::vector *> & dof_handler, - const std::vector *> &constraint, - const std::vector & locally_owned_set, - const std::vector> & quad, - const AdditionalData & additional_data); + const Mapping & mapping, + const std::vector *> & dof_handler, + const std::vector *> &constraint, + const std::vector & locally_owned_set, + const std::vector> & quad, + const AdditionalData & additional_data); /** * Initializes the fields in DoFInfo together with the constraint pool that @@ -1605,11 +1607,12 @@ private: * because several DoFInfo classes can have the same weights which * consequently only need to be stored once). */ + template void initialize_indices( - const std::vector *> &constraint, - const std::vector & locally_owned_set, - const AdditionalData & additional_data); + const std::vector *> &constraint, + const std::vector & locally_owned_set, + const AdditionalData & additional_data); /** * Initializes the DoFHandlers based on a DoFHandler argument. @@ -2425,17 +2428,17 @@ namespace internal template -template +template void MatrixFree::reinit( const DoFHandlerType & dof_handler, - const AffineConstraints & constraints_in, + const AffineConstraints & constraints_in, const QuadratureType & quad, const typename MatrixFree::AdditionalData additional_data) { - std::vector dof_handlers; - std::vector *> constraints; - std::vector quads; + std::vector dof_handlers; + std::vector *> constraints; + std::vector quads; dof_handlers.push_back(&dof_handler); constraints.push_back(&constraints_in); @@ -2459,17 +2462,17 @@ MatrixFree::reinit( template -template +template void MatrixFree::reinit( const Mapping & mapping, const DoFHandlerType & dof_handler, - const AffineConstraints & constraints_in, + const AffineConstraints & constraints_in, const QuadratureType & quad, const typename MatrixFree::AdditionalData additional_data) { - std::vector dof_handlers; - std::vector *> constraints; + std::vector dof_handlers; + std::vector *> constraints; dof_handlers.push_back(&dof_handler); constraints.push_back(&constraints_in); @@ -2492,11 +2495,11 @@ MatrixFree::reinit( template -template +template void MatrixFree::reinit( const std::vector & dof_handler, - const std::vector *> & constraint, + const std::vector *> &constraint, const std::vector & quad, const typename MatrixFree::AdditionalData additional_data) { @@ -2517,11 +2520,11 @@ MatrixFree::reinit( template -template +template void MatrixFree::reinit( const std::vector & dof_handler, - const std::vector *> & constraint, + const std::vector *> &constraint, const QuadratureType & quad, const typename MatrixFree::AdditionalData additional_data) { @@ -2541,12 +2544,12 @@ MatrixFree::reinit( template -template +template void MatrixFree::reinit( const Mapping & mapping, const std::vector & dof_handler, - const std::vector *> & constraint, + const std::vector *> &constraint, const QuadratureType & quad, const typename MatrixFree::AdditionalData additional_data) { @@ -2566,12 +2569,12 @@ MatrixFree::reinit( template -template +template void MatrixFree::reinit( const Mapping & mapping, const std::vector & dof_handler, - const std::vector *> & constraint, + const std::vector *> &constraint, const std::vector & quad, const typename MatrixFree::AdditionalData additional_data) { @@ -2592,12 +2595,12 @@ MatrixFree::reinit( template -template +template void MatrixFree::reinit( const Mapping & mapping, const std::vector & dof_handler, - const std::vector *> & constraint, + const std::vector *> &constraint, const std::vector & locally_owned_set, const std::vector & quad, const typename MatrixFree::AdditionalData additional_data) diff --git a/include/deal.II/matrix_free/matrix_free.templates.h b/include/deal.II/matrix_free/matrix_free.templates.h index 8c4074dfab..13cd407850 100644 --- a/include/deal.II/matrix_free/matrix_free.templates.h +++ b/include/deal.II/matrix_free/matrix_free.templates.h @@ -225,11 +225,12 @@ MatrixFree::copy_from(const MatrixFree &v) template +template void MatrixFree::internal_reinit( const Mapping & mapping, const std::vector *> & dof_handler, - const std::vector *> & constraint, + const std::vector *> & constraint, const std::vector & locally_owned_set, const std::vector> & quad, const typename MatrixFree::AdditionalData &additional_data) @@ -384,11 +385,12 @@ MatrixFree::internal_reinit( template +template void MatrixFree::internal_reinit( const Mapping & mapping, const std::vector *> & dof_handler, - const std::vector *> & constraint, + const std::vector *> & constraint, const std::vector & locally_owned_set, const std::vector> & quad, const typename MatrixFree::AdditionalData &additional_data) @@ -737,11 +739,12 @@ MatrixFree::initialize_dof_handlers( template +template void MatrixFree::initialize_indices( - const std::vector *> &constraint, - const std::vector & locally_owned_set, - const AdditionalData & additional_data) + const std::vector *> &constraint, + const std::vector & locally_owned_set, + const AdditionalData & additional_data) { // insert possible ghost cells and construct face topology const bool do_face_integrals = diff --git a/source/matrix_free/matrix_free.inst.in b/source/matrix_free/matrix_free.inst.in index fddb7f18b3..694b7904df 100644 --- a/source/matrix_free/matrix_free.inst.in +++ b/source/matrix_free/matrix_free.inst.in @@ -30,9 +30,42 @@ for (deal_II_dimension : DIMENSIONS) MatrixFree::print_memory_consumption(std::ostream &) const; + template void MatrixFree:: print_memory_consumption(ConditionalOStream &) const; + template void MatrixFree::internal_reinit( + const Mapping &, + const std::vector *> &, + const std::vector *> &, + const std::vector &, + const std::vector> &, + const AdditionalData &); + + template void MatrixFree::internal_reinit( + const Mapping &, + const std::vector *> &, + const std::vector *> &, + const std::vector &, + const std::vector> &, + const AdditionalData &); + + template void MatrixFree::internal_reinit( + const Mapping &, + const std::vector *> &, + const std::vector *> &, + const std::vector &, + const std::vector> &, + const AdditionalData &); + + template void MatrixFree::internal_reinit( + const Mapping &, + const std::vector *> &, + const std::vector *> &, + const std::vector &, + const std::vector> &, + const AdditionalData &); + #ifndef DEAL_II_MSVC template void internal::MatrixFreeFunctions::ShapeInfo::reinit( -- 2.39.5