]> https://gitweb.dealii.org/ - dealii.git/commitdiff
MatrixCreator: make SparseMatrixType a template parameter 12862/head
authorPeter Munch <peterrmuench@gmail.com>
Fri, 22 Oct 2021 15:46:40 +0000 (17:46 +0200)
committerPeter Munch <peterrmuench@gmail.com>
Wed, 27 Oct 2021 21:29:19 +0000 (23:29 +0200)
include/deal.II/numerics/matrix_creator.templates.h
include/deal.II/numerics/matrix_tools.h
source/numerics/matrix_creator.inst.in
tests/numerics/matrix_creator_01.cc [new file with mode: 0644]
tests/numerics/matrix_creator_01.with_p4est=true.mpirun=1.with_petsc=on.with_trilinos=on.output [new file with mode: 0644]
tests/numerics/matrix_creator_01.with_p4est=true.mpirun=3.with_petsc=on.with_trilinos=on.output [new file with mode: 0644]

index ff9f2fac5c33eaffff762d2f78cc10fd289a9aee..b1a9a8f54f9213692f3b5a2d1ab8cfbdeca03010 100644 (file)
@@ -150,6 +150,7 @@ namespace MatrixCreator
         FullMatrix<number>                   cell_matrix;
         dealii::Vector<number>               cell_rhs;
         const AffineConstraints<number> *    constraints;
+        bool                                 is_locally_owned;
       };
     } // namespace AssemblerData
 
@@ -162,6 +163,10 @@ namespace MatrixCreator
         &                                                       data,
       MatrixCreator::internal::AssemblerData::CopyData<number> &copy_data)
     {
+      copy_data.is_locally_owned = cell->is_locally_owned();
+      if (copy_data.is_locally_owned == false)
+        return;
+
       data.x_fe_values.reinit(cell);
       const FEValues<dim, spacedim> &fe_values =
         data.x_fe_values.get_present_fe_values();
@@ -361,14 +366,18 @@ namespace MatrixCreator
 
 
 
-    template <int dim, int spacedim, typename CellIterator>
+    template <int dim, int spacedim, typename CellIterator, typename Number>
     void
     laplace_assembler(
       const CellIterator &cell,
-      MatrixCreator::internal::AssemblerData::Scratch<dim, spacedim, double>
+      MatrixCreator::internal::AssemblerData::Scratch<dim, spacedim, Number>
         &                                                       data,
-      MatrixCreator::internal::AssemblerData::CopyData<double> &copy_data)
+      MatrixCreator::internal::AssemblerData::CopyData<Number> &copy_data)
     {
+      copy_data.is_locally_owned = cell->is_locally_owned();
+      if (copy_data.is_locally_owned == false)
+        return;
+
       data.x_fe_values.reinit(cell);
       const FEValues<dim, spacedim> &fe_values =
         data.x_fe_values.get_present_fe_values();
@@ -405,7 +414,7 @@ namespace MatrixCreator
           else
             {
               data.rhs_vector_values.resize(
-                n_q_points, dealii::Vector<double>(n_components));
+                n_q_points, dealii::Vector<Number>(n_components));
               data.rhs_function->vector_value_list(
                 fe_values.get_quadrature_points(), data.rhs_vector_values);
             }
@@ -423,7 +432,7 @@ namespace MatrixCreator
           else
             {
               data.coefficient_vector_values.resize(
-                n_q_points, dealii::Vector<double>(n_components));
+                n_q_points, dealii::Vector<Number>(n_components));
               data.coefficient->vector_value_list(
                 fe_values.get_quadrature_points(),
                 data.coefficient_vector_values);
@@ -432,7 +441,7 @@ namespace MatrixCreator
 
 
       const std::vector<double> &JxW = fe_values.get_JxW_values();
-      double                     add_data;
+      Number                     add_data;
       for (unsigned int i = 0; i < dofs_per_cell; ++i)
         if (fe.is_primitive())
           {
@@ -569,6 +578,9 @@ namespace MatrixCreator
                          MatrixType *                           matrix,
                          VectorType *                           right_hand_side)
     {
+      if (data.is_locally_owned == false)
+        return;
+
       const unsigned int dofs_per_cell = data.dof_indices.size();
       (void)dofs_per_cell;
 
@@ -626,14 +638,16 @@ namespace MatrixCreator
 
 namespace MatrixCreator
 {
-  template <int dim, int spacedim, typename number>
+  template <int dim, int spacedim, typename SparseMatrixType>
   void
-  create_mass_matrix(const Mapping<dim, spacedim> &          mapping,
-                     const DoFHandler<dim, spacedim> &       dof,
-                     const Quadrature<dim> &                 q,
-                     SparseMatrix<number> &                  matrix,
-                     const Function<spacedim, number> *const coefficient,
-                     const AffineConstraints<number> &       constraints)
+  create_mass_matrix(
+    const Mapping<dim, spacedim> &   mapping,
+    const DoFHandler<dim, spacedim> &dof,
+    const Quadrature<dim> &          q,
+    SparseMatrixType &               matrix,
+    const Function<spacedim, typename SparseMatrixType::value_type>
+      *const                                                        coefficient,
+    const AffineConstraints<typename SparseMatrixType::value_type> &constraints)
   {
     Assert(matrix.m() == dof.n_dofs(),
            ExcDimensionMismatch(matrix.m(), dof.n_dofs()));
@@ -643,17 +657,20 @@ namespace MatrixCreator
     const auto &         fe_collection = dof.get_fe_collection();
     hp::QCollection<dim> q_collection(q);
     hp::MappingCollection<dim, spacedim> mapping_collection(mapping);
-    MatrixCreator::internal::AssemblerData::Scratch<dim, spacedim, number>
-      assembler_data(fe_collection,
-                     update_values | update_JxW_values |
-                       (coefficient != nullptr ? update_quadrature_points :
-                                                 UpdateFlags(0)),
-                     coefficient,
-                     /*rhs_function=*/nullptr,
-                     q_collection,
-                     mapping_collection);
-
-    MatrixCreator::internal::AssemblerData::CopyData<number> copy_data;
+    MatrixCreator::internal::AssemblerData::
+      Scratch<dim, spacedim, typename SparseMatrixType::value_type>
+        assembler_data(fe_collection,
+                       update_values | update_JxW_values |
+                         (coefficient != nullptr ? update_quadrature_points :
+                                                   UpdateFlags(0)),
+                       coefficient,
+                       /*rhs_function=*/nullptr,
+                       q_collection,
+                       mapping_collection);
+
+    MatrixCreator::internal::AssemblerData::CopyData<
+      typename SparseMatrixType::value_type>
+      copy_data;
     copy_data.cell_matrix.reinit(
       assembler_data.fe_collection.max_dofs_per_cell(),
       assembler_data.fe_collection.max_dofs_per_cell());
@@ -670,24 +687,32 @@ namespace MatrixCreator
         dim,
         spacedim,
         typename DoFHandler<dim, spacedim>::active_cell_iterator,
-        number>,
-      [&matrix](const internal::AssemblerData::CopyData<number> &data) {
+        typename SparseMatrixType::value_type>,
+      [&matrix](const internal::AssemblerData::CopyData<
+                typename SparseMatrixType::value_type> &data) {
         MatrixCreator::internal::copy_local_to_global(
-          data, &matrix, static_cast<Vector<number> *>(nullptr));
+          data,
+          &matrix,
+          static_cast<Vector<typename SparseMatrixType::value_type> *>(
+            nullptr));
       },
       assembler_data,
       copy_data);
+
+    matrix.compress(VectorOperation::add);
   }
 
 
 
-  template <int dim, int spacedim, typename number>
+  template <int dim, int spacedim, typename SparseMatrixType>
   void
-  create_mass_matrix(const DoFHandler<dim, spacedim> &       dof,
-                     const Quadrature<dim> &                 q,
-                     SparseMatrix<number> &                  matrix,
-                     const Function<spacedim, number> *const coefficient,
-                     const AffineConstraints<number> &       constraints)
+  create_mass_matrix(
+    const DoFHandler<dim, spacedim> &dof,
+    const Quadrature<dim> &          q,
+    SparseMatrixType &               matrix,
+    const Function<spacedim, typename SparseMatrixType::value_type>
+      *const                                                        coefficient,
+    const AffineConstraints<typename SparseMatrixType::value_type> &constraints)
   {
     create_mass_matrix(get_default_linear_mapping(dof.get_triangulation()),
                        dof,
@@ -699,16 +724,18 @@ namespace MatrixCreator
 
 
 
-  template <int dim, int spacedim, typename number>
+  template <int dim, int spacedim, typename SparseMatrixType>
   void
-  create_mass_matrix(const Mapping<dim, spacedim> &          mapping,
-                     const DoFHandler<dim, spacedim> &       dof,
-                     const Quadrature<dim> &                 q,
-                     SparseMatrix<number> &                  matrix,
-                     const Function<spacedim, number> &      rhs,
-                     Vector<number> &                        rhs_vector,
-                     const Function<spacedim, number> *const coefficient,
-                     const AffineConstraints<number> &       constraints)
+  create_mass_matrix(
+    const Mapping<dim, spacedim> &                                   mapping,
+    const DoFHandler<dim, spacedim> &                                dof,
+    const Quadrature<dim> &                                          q,
+    SparseMatrixType &                                               matrix,
+    const Function<spacedim, typename SparseMatrixType::value_type> &rhs,
+    Vector<typename SparseMatrixType::value_type> &                  rhs_vector,
+    const Function<spacedim, typename SparseMatrixType::value_type>
+      *const                                                        coefficient,
+    const AffineConstraints<typename SparseMatrixType::value_type> &constraints)
   {
     Assert(matrix.m() == dof.n_dofs(),
            ExcDimensionMismatch(matrix.m(), dof.n_dofs()));
@@ -718,15 +745,18 @@ namespace MatrixCreator
     const auto &         fe_collection = dof.get_fe_collection();
     hp::QCollection<dim> q_collection(q);
     hp::MappingCollection<dim, spacedim> mapping_collection(mapping);
-    MatrixCreator::internal::AssemblerData::Scratch<dim, spacedim, number>
-      assembler_data(fe_collection,
-                     update_values | update_JxW_values |
-                       update_quadrature_points,
-                     coefficient,
-                     &rhs,
-                     q_collection,
-                     mapping_collection);
-    MatrixCreator::internal::AssemblerData::CopyData<number> copy_data;
+    MatrixCreator::internal::AssemblerData::
+      Scratch<dim, spacedim, typename SparseMatrixType::value_type>
+        assembler_data(fe_collection,
+                       update_values | update_JxW_values |
+                         update_quadrature_points,
+                       coefficient,
+                       &rhs,
+                       q_collection,
+                       mapping_collection);
+    MatrixCreator::internal::AssemblerData::CopyData<
+      typename SparseMatrixType::value_type>
+      copy_data;
     copy_data.cell_matrix.reinit(
       assembler_data.fe_collection.max_dofs_per_cell(),
       assembler_data.fe_collection.max_dofs_per_cell());
@@ -743,28 +773,32 @@ namespace MatrixCreator
         dim,
         spacedim,
         typename DoFHandler<dim, spacedim>::active_cell_iterator,
-        number>,
-      [&matrix,
-       &rhs_vector](const internal::AssemblerData::CopyData<number> &data) {
+        typename SparseMatrixType::value_type>,
+      [&matrix, &rhs_vector](const internal::AssemblerData::CopyData<
+                             typename SparseMatrixType::value_type> &data) {
         MatrixCreator::internal::copy_local_to_global(data,
                                                       &matrix,
                                                       &rhs_vector);
       },
       assembler_data,
       copy_data);
+
+    matrix.compress(VectorOperation::add);
   }
 
 
 
-  template <int dim, int spacedim, typename number>
+  template <int dim, int spacedim, typename SparseMatrixType>
   void
-  create_mass_matrix(const DoFHandler<dim, spacedim> &       dof,
-                     const Quadrature<dim> &                 q,
-                     SparseMatrix<number> &                  matrix,
-                     const Function<spacedim, number> &      rhs,
-                     Vector<number> &                        rhs_vector,
-                     const Function<spacedim, number> *const coefficient,
-                     const AffineConstraints<number> &       constraints)
+  create_mass_matrix(
+    const DoFHandler<dim, spacedim> &                                dof,
+    const Quadrature<dim> &                                          q,
+    SparseMatrixType &                                               matrix,
+    const Function<spacedim, typename SparseMatrixType::value_type> &rhs,
+    Vector<typename SparseMatrixType::value_type> &                  rhs_vector,
+    const Function<spacedim, typename SparseMatrixType::value_type>
+      *const                                                        coefficient,
+    const AffineConstraints<typename SparseMatrixType::value_type> &constraints)
   {
     create_mass_matrix(get_default_linear_mapping(dof.get_triangulation()),
                        dof,
@@ -778,30 +812,35 @@ namespace MatrixCreator
 
 
 
-  template <int dim, int spacedim, typename number>
+  template <int dim, int spacedim, typename SparseMatrixType>
   void
-  create_mass_matrix(const hp::MappingCollection<dim, spacedim> &mapping,
-                     const DoFHandler<dim, spacedim> &           dof,
-                     const hp::QCollection<dim> &                q,
-                     SparseMatrix<number> &                      matrix,
-                     const Function<spacedim, number> *const     coefficient,
-                     const AffineConstraints<number> &           constraints)
+  create_mass_matrix(
+    const hp::MappingCollection<dim, spacedim> &mapping,
+    const DoFHandler<dim, spacedim> &           dof,
+    const hp::QCollection<dim> &                q,
+    SparseMatrixType &                          matrix,
+    const Function<spacedim, typename SparseMatrixType::value_type>
+      *const                                                        coefficient,
+    const AffineConstraints<typename SparseMatrixType::value_type> &constraints)
   {
     Assert(matrix.m() == dof.n_dofs(),
            ExcDimensionMismatch(matrix.m(), dof.n_dofs()));
     Assert(matrix.n() == dof.n_dofs(),
            ExcDimensionMismatch(matrix.n(), dof.n_dofs()));
 
-    MatrixCreator::internal::AssemblerData::Scratch<dim, spacedim, number>
-      assembler_data(dof.get_fe_collection(),
-                     update_values | update_JxW_values |
-                       (coefficient != nullptr ? update_quadrature_points :
-                                                 UpdateFlags(0)),
-                     coefficient,
-                     /*rhs_function=*/nullptr,
-                     q,
-                     mapping);
-    MatrixCreator::internal::AssemblerData::CopyData<number> copy_data;
+    MatrixCreator::internal::AssemblerData::
+      Scratch<dim, spacedim, typename SparseMatrixType::value_type>
+        assembler_data(dof.get_fe_collection(),
+                       update_values | update_JxW_values |
+                         (coefficient != nullptr ? update_quadrature_points :
+                                                   UpdateFlags(0)),
+                       coefficient,
+                       /*rhs_function=*/nullptr,
+                       q,
+                       mapping);
+    MatrixCreator::internal::AssemblerData::CopyData<
+      typename SparseMatrixType::value_type>
+      copy_data;
     copy_data.cell_matrix.reinit(
       assembler_data.fe_collection.max_dofs_per_cell(),
       assembler_data.fe_collection.max_dofs_per_cell());
@@ -818,24 +857,32 @@ namespace MatrixCreator
         dim,
         spacedim,
         typename DoFHandler<dim, spacedim>::active_cell_iterator,
-        number>,
-      [&matrix](const internal::AssemblerData::CopyData<number> &data) {
+        typename SparseMatrixType::value_type>,
+      [&matrix](const internal::AssemblerData::CopyData<
+                typename SparseMatrixType::value_type> &data) {
         MatrixCreator::internal::copy_local_to_global(
-          data, &matrix, static_cast<Vector<number> *>(nullptr));
+          data,
+          &matrix,
+          static_cast<Vector<typename SparseMatrixType::value_type> *>(
+            nullptr));
       },
       assembler_data,
       copy_data);
+
+    matrix.compress(VectorOperation::add);
   }
 
 
 
-  template <int dim, int spacedim, typename number>
+  template <int dim, int spacedim, typename SparseMatrixType>
   void
-  create_mass_matrix(const DoFHandler<dim, spacedim> &       dof,
-                     const hp::QCollection<dim> &            q,
-                     SparseMatrix<number> &                  matrix,
-                     const Function<spacedim, number> *const coefficient,
-                     const AffineConstraints<number> &       constraints)
+  create_mass_matrix(
+    const DoFHandler<dim, spacedim> &dof,
+    const hp::QCollection<dim> &     q,
+    SparseMatrixType &               matrix,
+    const Function<spacedim, typename SparseMatrixType::value_type>
+      *const                                                        coefficient,
+    const AffineConstraints<typename SparseMatrixType::value_type> &constraints)
   {
     create_mass_matrix(hp::StaticMappingQ1<dim, spacedim>::mapping_collection,
                        dof,
@@ -847,31 +894,36 @@ namespace MatrixCreator
 
 
 
-  template <int dim, int spacedim, typename number>
+  template <int dim, int spacedim, typename SparseMatrixType>
   void
-  create_mass_matrix(const hp::MappingCollection<dim, spacedim> &mapping,
-                     const DoFHandler<dim, spacedim> &           dof,
-                     const hp::QCollection<dim> &                q,
-                     SparseMatrix<number> &                      matrix,
-                     const Function<spacedim, number> &          rhs,
-                     Vector<number> &                            rhs_vector,
-                     const Function<spacedim, number> *const     coefficient,
-                     const AffineConstraints<number> &           constraints)
+  create_mass_matrix(
+    const hp::MappingCollection<dim, spacedim> &                     mapping,
+    const DoFHandler<dim, spacedim> &                                dof,
+    const hp::QCollection<dim> &                                     q,
+    SparseMatrixType &                                               matrix,
+    const Function<spacedim, typename SparseMatrixType::value_type> &rhs,
+    Vector<typename SparseMatrixType::value_type> &                  rhs_vector,
+    const Function<spacedim, typename SparseMatrixType::value_type>
+      *const                                                        coefficient,
+    const AffineConstraints<typename SparseMatrixType::value_type> &constraints)
   {
     Assert(matrix.m() == dof.n_dofs(),
            ExcDimensionMismatch(matrix.m(), dof.n_dofs()));
     Assert(matrix.n() == dof.n_dofs(),
            ExcDimensionMismatch(matrix.n(), dof.n_dofs()));
 
-    MatrixCreator::internal::AssemblerData::Scratch<dim, spacedim, number>
-      assembler_data(dof.get_fe_collection(),
-                     update_values | update_JxW_values |
-                       update_quadrature_points,
-                     coefficient,
-                     &rhs,
-                     q,
-                     mapping);
-    MatrixCreator::internal::AssemblerData::CopyData<number> copy_data;
+    MatrixCreator::internal::AssemblerData::
+      Scratch<dim, spacedim, typename SparseMatrixType::value_type>
+        assembler_data(dof.get_fe_collection(),
+                       update_values | update_JxW_values |
+                         update_quadrature_points,
+                       coefficient,
+                       &rhs,
+                       q,
+                       mapping);
+    MatrixCreator::internal::AssemblerData::CopyData<
+      typename SparseMatrixType::value_type>
+      copy_data;
     copy_data.cell_matrix.reinit(
       assembler_data.fe_collection.max_dofs_per_cell(),
       assembler_data.fe_collection.max_dofs_per_cell());
@@ -888,28 +940,32 @@ namespace MatrixCreator
         dim,
         spacedim,
         typename DoFHandler<dim, spacedim>::active_cell_iterator,
-        number>,
-      [&matrix,
-       &rhs_vector](const internal::AssemblerData::CopyData<number> &data) {
+        typename SparseMatrixType::value_type>,
+      [&matrix, &rhs_vector](const internal::AssemblerData::CopyData<
+                             typename SparseMatrixType::value_type> &data) {
         MatrixCreator::internal::copy_local_to_global(data,
                                                       &matrix,
                                                       &rhs_vector);
       },
       assembler_data,
       copy_data);
+
+    matrix.compress(VectorOperation::add);
   }
 
 
 
-  template <int dim, int spacedim, typename number>
+  template <int dim, int spacedim, typename SparseMatrixType>
   void
-  create_mass_matrix(const DoFHandler<dim, spacedim> &       dof,
-                     const hp::QCollection<dim> &            q,
-                     SparseMatrix<number> &                  matrix,
-                     const Function<spacedim, number> &      rhs,
-                     Vector<number> &                        rhs_vector,
-                     const Function<spacedim, number> *const coefficient,
-                     const AffineConstraints<number> &       constraints)
+  create_mass_matrix(
+    const DoFHandler<dim, spacedim> &                                dof,
+    const hp::QCollection<dim> &                                     q,
+    SparseMatrixType &                                               matrix,
+    const Function<spacedim, typename SparseMatrixType::value_type> &rhs,
+    Vector<typename SparseMatrixType::value_type> &                  rhs_vector,
+    const Function<spacedim, typename SparseMatrixType::value_type>
+      *const                                                        coefficient,
+    const AffineConstraints<typename SparseMatrixType::value_type> &constraints)
   {
     create_mass_matrix(hp::StaticMappingQ1<dim, spacedim>::mapping_collection,
                        dof,
@@ -1857,14 +1913,16 @@ namespace MatrixCreator
 
 
 
-  template <int dim, int spacedim>
+  template <int dim, int spacedim, typename SparseMatrixType>
   void
-  create_laplace_matrix(const Mapping<dim, spacedim> &   mapping,
-                        const DoFHandler<dim, spacedim> &dof,
-                        const Quadrature<dim> &          q,
-                        SparseMatrix<double> &           matrix,
-                        const Function<spacedim> *const  coefficient,
-                        const AffineConstraints<double> &constraints)
+  create_laplace_matrix(
+    const Mapping<dim, spacedim> &   mapping,
+    const DoFHandler<dim, spacedim> &dof,
+    const Quadrature<dim> &          q,
+    SparseMatrixType &               matrix,
+    const Function<spacedim, typename SparseMatrixType::value_type>
+      *const                                                        coefficient,
+    const AffineConstraints<typename SparseMatrixType::value_type> &constraints)
   {
     Assert(matrix.m() == dof.n_dofs(),
            ExcDimensionMismatch(matrix.m(), dof.n_dofs()));
@@ -1874,16 +1932,19 @@ namespace MatrixCreator
     const auto &         fe_collection = dof.get_fe_collection();
     hp::QCollection<dim> q_collection(q);
     hp::MappingCollection<dim, spacedim> mapping_collection(mapping);
-    MatrixCreator::internal::AssemblerData::Scratch<dim, spacedim, double>
-      assembler_data(fe_collection,
-                     update_gradients | update_JxW_values |
-                       (coefficient != nullptr ? update_quadrature_points :
-                                                 UpdateFlags(0)),
-                     coefficient,
-                     /*rhs_function=*/nullptr,
-                     q_collection,
-                     mapping_collection);
-    MatrixCreator::internal::AssemblerData::CopyData<double> copy_data;
+    MatrixCreator::internal::AssemblerData::
+      Scratch<dim, spacedim, typename SparseMatrixType::value_type>
+        assembler_data(fe_collection,
+                       update_gradients | update_JxW_values |
+                         (coefficient != nullptr ? update_quadrature_points :
+                                                   UpdateFlags(0)),
+                       coefficient,
+                       /*rhs_function=*/nullptr,
+                       q_collection,
+                       mapping_collection);
+    MatrixCreator::internal::AssemblerData::CopyData<
+      typename SparseMatrixType::value_type>
+      copy_data;
     copy_data.cell_matrix.reinit(
       assembler_data.fe_collection.max_dofs_per_cell(),
       assembler_data.fe_collection.max_dofs_per_cell());
@@ -1899,24 +1960,33 @@ namespace MatrixCreator
       &MatrixCreator::internal::laplace_assembler<
         dim,
         spacedim,
-        typename DoFHandler<dim, spacedim>::active_cell_iterator>,
-      [&matrix](const internal::AssemblerData::CopyData<double> &data) {
+        typename DoFHandler<dim, spacedim>::active_cell_iterator,
+        typename SparseMatrixType::value_type>,
+      [&matrix](const internal::AssemblerData::CopyData<
+                typename SparseMatrixType::value_type> &data) {
         MatrixCreator::internal::copy_local_to_global(
-          data, &matrix, static_cast<Vector<double> *>(nullptr));
+          data,
+          &matrix,
+          static_cast<Vector<typename SparseMatrixType::value_type> *>(
+            nullptr));
       },
       assembler_data,
       copy_data);
+
+    matrix.compress(VectorOperation::add);
   }
 
 
 
-  template <int dim, int spacedim>
+  template <int dim, int spacedim, typename SparseMatrixType>
   void
-  create_laplace_matrix(const DoFHandler<dim, spacedim> &dof,
-                        const Quadrature<dim> &          q,
-                        SparseMatrix<double> &           matrix,
-                        const Function<spacedim> *const  coefficient,
-                        const AffineConstraints<double> &constraints)
+  create_laplace_matrix(
+    const DoFHandler<dim, spacedim> &dof,
+    const Quadrature<dim> &          q,
+    SparseMatrixType &               matrix,
+    const Function<spacedim, typename SparseMatrixType::value_type>
+      *const                                                        coefficient,
+    const AffineConstraints<typename SparseMatrixType::value_type> &constraints)
   {
     create_laplace_matrix(get_default_linear_mapping(dof.get_triangulation()),
                           dof,
@@ -1928,16 +1998,18 @@ namespace MatrixCreator
 
 
 
-  template <int dim, int spacedim>
+  template <int dim, int spacedim, typename SparseMatrixType>
   void
-  create_laplace_matrix(const Mapping<dim, spacedim> &   mapping,
-                        const DoFHandler<dim, spacedim> &dof,
-                        const Quadrature<dim> &          q,
-                        SparseMatrix<double> &           matrix,
-                        const Function<spacedim> &       rhs,
-                        Vector<double> &                 rhs_vector,
-                        const Function<spacedim> *const  coefficient,
-                        const AffineConstraints<double> &constraints)
+  create_laplace_matrix(
+    const Mapping<dim, spacedim> &                                   mapping,
+    const DoFHandler<dim, spacedim> &                                dof,
+    const Quadrature<dim> &                                          q,
+    SparseMatrixType &                                               matrix,
+    const Function<spacedim, typename SparseMatrixType::value_type> &rhs,
+    Vector<typename SparseMatrixType::value_type> &                  rhs_vector,
+    const Function<spacedim, typename SparseMatrixType::value_type>
+      *const                                                        coefficient,
+    const AffineConstraints<typename SparseMatrixType::value_type> &constraints)
   {
     Assert(matrix.m() == dof.n_dofs(),
            ExcDimensionMismatch(matrix.m(), dof.n_dofs()));
@@ -1947,15 +2019,18 @@ namespace MatrixCreator
     const auto &         fe_collection = dof.get_fe_collection();
     hp::QCollection<dim> q_collection(q);
     hp::MappingCollection<dim, spacedim> mapping_collection(mapping);
-    MatrixCreator::internal::AssemblerData::Scratch<dim, spacedim, double>
-      assembler_data(fe_collection,
-                     update_gradients | update_values | update_JxW_values |
-                       update_quadrature_points,
-                     coefficient,
-                     &rhs,
-                     q_collection,
-                     mapping_collection);
-    MatrixCreator::internal::AssemblerData::CopyData<double> copy_data;
+    MatrixCreator::internal::AssemblerData::
+      Scratch<dim, spacedim, typename SparseMatrixType::value_type>
+        assembler_data(fe_collection,
+                       update_gradients | update_values | update_JxW_values |
+                         update_quadrature_points,
+                       coefficient,
+                       &rhs,
+                       q_collection,
+                       mapping_collection);
+    MatrixCreator::internal::AssemblerData::CopyData<
+      typename SparseMatrixType::value_type>
+      copy_data;
     copy_data.cell_matrix.reinit(
       assembler_data.fe_collection.max_dofs_per_cell(),
       assembler_data.fe_collection.max_dofs_per_cell());
@@ -1971,28 +2046,33 @@ namespace MatrixCreator
       &MatrixCreator::internal::laplace_assembler<
         dim,
         spacedim,
-        typename DoFHandler<dim, spacedim>::active_cell_iterator>,
-      [&matrix,
-       &rhs_vector](const internal::AssemblerData::CopyData<double> &data) {
+        typename DoFHandler<dim, spacedim>::active_cell_iterator,
+        typename SparseMatrixType::value_type>,
+      [&matrix, &rhs_vector](const internal::AssemblerData::CopyData<
+                             typename SparseMatrixType::value_type> &data) {
         MatrixCreator::internal::copy_local_to_global(data,
                                                       &matrix,
                                                       &rhs_vector);
       },
       assembler_data,
       copy_data);
+
+    matrix.compress(VectorOperation::add);
   }
 
 
 
-  template <int dim, int spacedim>
+  template <int dim, int spacedim, typename SparseMatrixType>
   void
-  create_laplace_matrix(const DoFHandler<dim, spacedim> &dof,
-                        const Quadrature<dim> &          q,
-                        SparseMatrix<double> &           matrix,
-                        const Function<spacedim> &       rhs,
-                        Vector<double> &                 rhs_vector,
-                        const Function<spacedim> *const  coefficient,
-                        const AffineConstraints<double> &constraints)
+  create_laplace_matrix(
+    const DoFHandler<dim, spacedim> &                                dof,
+    const Quadrature<dim> &                                          q,
+    SparseMatrixType &                                               matrix,
+    const Function<spacedim, typename SparseMatrixType::value_type> &rhs,
+    Vector<typename SparseMatrixType::value_type> &                  rhs_vector,
+    const Function<spacedim, typename SparseMatrixType::value_type>
+      *const                                                        coefficient,
+    const AffineConstraints<typename SparseMatrixType::value_type> &constraints)
   {
     create_laplace_matrix(get_default_linear_mapping(dof.get_triangulation()),
                           dof,
@@ -2006,30 +2086,35 @@ namespace MatrixCreator
 
 
 
-  template <int dim, int spacedim>
+  template <int dim, int spacedim, typename SparseMatrixType>
   void
-  create_laplace_matrix(const hp::MappingCollection<dim, spacedim> &mapping,
-                        const DoFHandler<dim, spacedim> &           dof,
-                        const hp::QCollection<dim> &                q,
-                        SparseMatrix<double> &                      matrix,
-                        const Function<spacedim> *const             coefficient,
-                        const AffineConstraints<double> &           constraints)
+  create_laplace_matrix(
+    const hp::MappingCollection<dim, spacedim> &mapping,
+    const DoFHandler<dim, spacedim> &           dof,
+    const hp::QCollection<dim> &                q,
+    SparseMatrixType &                          matrix,
+    const Function<spacedim, typename SparseMatrixType::value_type>
+      *const                                                        coefficient,
+    const AffineConstraints<typename SparseMatrixType::value_type> &constraints)
   {
     Assert(matrix.m() == dof.n_dofs(),
            ExcDimensionMismatch(matrix.m(), dof.n_dofs()));
     Assert(matrix.n() == dof.n_dofs(),
            ExcDimensionMismatch(matrix.n(), dof.n_dofs()));
 
-    MatrixCreator::internal::AssemblerData::Scratch<dim, spacedim, double>
-      assembler_data(dof.get_fe_collection(),
-                     update_gradients | update_JxW_values |
-                       (coefficient != nullptr ? update_quadrature_points :
-                                                 UpdateFlags(0)),
-                     coefficient,
-                     /*rhs_function=*/nullptr,
-                     q,
-                     mapping);
-    MatrixCreator::internal::AssemblerData::CopyData<double> copy_data;
+    MatrixCreator::internal::AssemblerData::
+      Scratch<dim, spacedim, typename SparseMatrixType::value_type>
+        assembler_data(dof.get_fe_collection(),
+                       update_gradients | update_JxW_values |
+                         (coefficient != nullptr ? update_quadrature_points :
+                                                   UpdateFlags(0)),
+                       coefficient,
+                       /*rhs_function=*/nullptr,
+                       q,
+                       mapping);
+    MatrixCreator::internal::AssemblerData::CopyData<
+      typename SparseMatrixType::value_type>
+      copy_data;
     copy_data.cell_matrix.reinit(
       assembler_data.fe_collection.max_dofs_per_cell(),
       assembler_data.fe_collection.max_dofs_per_cell());
@@ -2045,24 +2130,33 @@ namespace MatrixCreator
       &MatrixCreator::internal::laplace_assembler<
         dim,
         spacedim,
-        typename DoFHandler<dim, spacedim>::active_cell_iterator>,
-      [&matrix](const internal::AssemblerData::CopyData<double> &data) {
+        typename DoFHandler<dim, spacedim>::active_cell_iterator,
+        typename SparseMatrixType::value_type>,
+      [&matrix](const internal::AssemblerData::CopyData<
+                typename SparseMatrixType::value_type> &data) {
         MatrixCreator::internal::copy_local_to_global(
-          data, &matrix, static_cast<Vector<double> *>(nullptr));
+          data,
+          &matrix,
+          static_cast<Vector<typename SparseMatrixType::value_type> *>(
+            nullptr));
       },
       assembler_data,
       copy_data);
+
+    matrix.compress(VectorOperation::add);
   }
 
 
 
-  template <int dim, int spacedim>
+  template <int dim, int spacedim, typename SparseMatrixType>
   void
-  create_laplace_matrix(const DoFHandler<dim, spacedim> &dof,
-                        const hp::QCollection<dim> &     q,
-                        SparseMatrix<double> &           matrix,
-                        const Function<spacedim> *const  coefficient,
-                        const AffineConstraints<double> &constraints)
+  create_laplace_matrix(
+    const DoFHandler<dim, spacedim> &dof,
+    const hp::QCollection<dim> &     q,
+    SparseMatrixType &               matrix,
+    const Function<spacedim, typename SparseMatrixType::value_type>
+      *const                                                        coefficient,
+    const AffineConstraints<typename SparseMatrixType::value_type> &constraints)
   {
     create_laplace_matrix(
       hp::StaticMappingQ1<dim, spacedim>::mapping_collection,
@@ -2075,31 +2169,36 @@ namespace MatrixCreator
 
 
 
-  template <int dim, int spacedim>
+  template <int dim, int spacedim, typename SparseMatrixType>
   void
-  create_laplace_matrix(const hp::MappingCollection<dim, spacedim> &mapping,
-                        const DoFHandler<dim, spacedim> &           dof,
-                        const hp::QCollection<dim> &                q,
-                        SparseMatrix<double> &                      matrix,
-                        const Function<spacedim> &                  rhs,
-                        Vector<double> &                            rhs_vector,
-                        const Function<spacedim> *const             coefficient,
-                        const AffineConstraints<double> &           constraints)
+  create_laplace_matrix(
+    const hp::MappingCollection<dim, spacedim> &                     mapping,
+    const DoFHandler<dim, spacedim> &                                dof,
+    const hp::QCollection<dim> &                                     q,
+    SparseMatrixType &                                               matrix,
+    const Function<spacedim, typename SparseMatrixType::value_type> &rhs,
+    Vector<typename SparseMatrixType::value_type> &                  rhs_vector,
+    const Function<spacedim, typename SparseMatrixType::value_type>
+      *const                                                        coefficient,
+    const AffineConstraints<typename SparseMatrixType::value_type> &constraints)
   {
     Assert(matrix.m() == dof.n_dofs(),
            ExcDimensionMismatch(matrix.m(), dof.n_dofs()));
     Assert(matrix.n() == dof.n_dofs(),
            ExcDimensionMismatch(matrix.n(), dof.n_dofs()));
 
-    MatrixCreator::internal::AssemblerData::Scratch<dim, spacedim, double>
-      assembler_data(dof.get_fe_collection(),
-                     update_gradients | update_values | update_JxW_values |
-                       update_quadrature_points,
-                     coefficient,
-                     &rhs,
-                     q,
-                     mapping);
-    MatrixCreator::internal::AssemblerData::CopyData<double> copy_data;
+    MatrixCreator::internal::AssemblerData::
+      Scratch<dim, spacedim, typename SparseMatrixType::value_type>
+        assembler_data(dof.get_fe_collection(),
+                       update_gradients | update_values | update_JxW_values |
+                         update_quadrature_points,
+                       coefficient,
+                       &rhs,
+                       q,
+                       mapping);
+    MatrixCreator::internal::AssemblerData::CopyData<
+      typename SparseMatrixType::value_type>
+      copy_data;
     copy_data.cell_matrix.reinit(
       assembler_data.fe_collection.max_dofs_per_cell(),
       assembler_data.fe_collection.max_dofs_per_cell());
@@ -2115,28 +2214,33 @@ namespace MatrixCreator
       &MatrixCreator::internal::laplace_assembler<
         dim,
         spacedim,
-        typename DoFHandler<dim, spacedim>::active_cell_iterator>,
-      [&matrix,
-       &rhs_vector](const internal::AssemblerData::CopyData<double> &data) {
+        typename DoFHandler<dim, spacedim>::active_cell_iterator,
+        typename SparseMatrixType::value_type>,
+      [&matrix, &rhs_vector](const internal::AssemblerData::CopyData<
+                             typename SparseMatrixType::value_type> &data) {
         MatrixCreator::internal::copy_local_to_global(data,
                                                       &matrix,
                                                       &rhs_vector);
       },
       assembler_data,
       copy_data);
+
+    matrix.compress(VectorOperation::add);
   }
 
 
 
-  template <int dim, int spacedim>
+  template <int dim, int spacedim, typename SparseMatrixType>
   void
-  create_laplace_matrix(const DoFHandler<dim, spacedim> &dof,
-                        const hp::QCollection<dim> &     q,
-                        SparseMatrix<double> &           matrix,
-                        const Function<spacedim> &       rhs,
-                        Vector<double> &                 rhs_vector,
-                        const Function<spacedim> *const  coefficient,
-                        const AffineConstraints<double> &constraints)
+  create_laplace_matrix(
+    const DoFHandler<dim, spacedim> &                                dof,
+    const hp::QCollection<dim> &                                     q,
+    SparseMatrixType &                                               matrix,
+    const Function<spacedim, typename SparseMatrixType::value_type> &rhs,
+    Vector<typename SparseMatrixType::value_type> &                  rhs_vector,
+    const Function<spacedim, typename SparseMatrixType::value_type>
+      *const                                                        coefficient,
+    const AffineConstraints<typename SparseMatrixType::value_type> &constraints)
   {
     create_laplace_matrix(
       hp::StaticMappingQ1<dim, spacedim>::mapping_collection,
index 21a0c2d25cf501f95e797bc713e89b558dd254e6..745c5cc4ac561c90e712e882c3cf2a61b8b23339 100644 (file)
@@ -246,28 +246,32 @@ namespace MatrixCreator
    *
    * See the general documentation of this namespace for more information.
    */
-  template <int dim, int spacedim, typename number>
+  template <int dim, int spacedim, typename SparseMatrixType>
   void
   create_mass_matrix(
-    const Mapping<dim, spacedim> &          mapping,
-    const DoFHandler<dim, spacedim> &       dof,
-    const Quadrature<dim> &                 q,
-    SparseMatrix<number> &                  matrix,
-    const Function<spacedim, number> *const a    = nullptr,
-    const AffineConstraints<number> &constraints = AffineConstraints<number>());
+    const Mapping<dim, spacedim> &   mapping,
+    const DoFHandler<dim, spacedim> &dof,
+    const Quadrature<dim> &          q,
+    SparseMatrixType &               matrix,
+    const Function<spacedim, typename SparseMatrixType::value_type> *const a =
+      nullptr,
+    const AffineConstraints<typename SparseMatrixType::value_type> &
+      constraints = AffineConstraints<typename SparseMatrixType::value_type>());
 
   /**
    * Call the create_mass_matrix() function, see above, with
    * <tt>mapping=MappingQ@<dim@>(1)</tt>.
    */
-  template <int dim, int spacedim, typename number>
+  template <int dim, int spacedim, typename SparseMatrixType>
   void
   create_mass_matrix(
-    const DoFHandler<dim, spacedim> &       dof,
-    const Quadrature<dim> &                 q,
-    SparseMatrix<number> &                  matrix,
-    const Function<spacedim, number> *const a    = nullptr,
-    const AffineConstraints<number> &constraints = AffineConstraints<number>());
+    const DoFHandler<dim, spacedim> &dof,
+    const Quadrature<dim> &          q,
+    SparseMatrixType &               matrix,
+    const Function<spacedim, typename SparseMatrixType::value_type> *const a =
+      nullptr,
+    const AffineConstraints<typename SparseMatrixType::value_type> &
+      constraints = AffineConstraints<typename SparseMatrixType::value_type>());
 
   /**
    * Assemble the mass matrix and a right hand side vector. If no coefficient
@@ -288,86 +292,98 @@ namespace MatrixCreator
    *
    * See the general documentation of this namespace for more information.
    */
-  template <int dim, int spacedim, typename number>
+  template <int dim, int spacedim, typename SparseMatrixType>
   void
   create_mass_matrix(
-    const Mapping<dim, spacedim> &          mapping,
-    const DoFHandler<dim, spacedim> &       dof,
-    const Quadrature<dim> &                 q,
-    SparseMatrix<number> &                  matrix,
-    const Function<spacedim, number> &      rhs,
-    Vector<number> &                        rhs_vector,
-    const Function<spacedim, number> *const a    = nullptr,
-    const AffineConstraints<number> &constraints = AffineConstraints<number>());
+    const Mapping<dim, spacedim> &                                   mapping,
+    const DoFHandler<dim, spacedim> &                                dof,
+    const Quadrature<dim> &                                          q,
+    SparseMatrixType &                                               matrix,
+    const Function<spacedim, typename SparseMatrixType::value_type> &rhs,
+    Vector<typename SparseMatrixType::value_type> &                  rhs_vector,
+    const Function<spacedim, typename SparseMatrixType::value_type> *const a =
+      nullptr,
+    const AffineConstraints<typename SparseMatrixType::value_type> &
+      constraints = AffineConstraints<typename SparseMatrixType::value_type>());
 
   /**
    * Call the create_mass_matrix() function, see above, with
    * <tt>mapping=MappingQ@<dim@>(1)</tt>.
    */
-  template <int dim, int spacedim, typename number>
+  template <int dim, int spacedim, typename SparseMatrixType>
   void
   create_mass_matrix(
-    const DoFHandler<dim, spacedim> &       dof,
-    const Quadrature<dim> &                 q,
-    SparseMatrix<number> &                  matrix,
-    const Function<spacedim, number> &      rhs,
-    Vector<number> &                        rhs_vector,
-    const Function<spacedim, number> *const a    = nullptr,
-    const AffineConstraints<number> &constraints = AffineConstraints<number>());
+    const DoFHandler<dim, spacedim> &                                dof,
+    const Quadrature<dim> &                                          q,
+    SparseMatrixType &                                               matrix,
+    const Function<spacedim, typename SparseMatrixType::value_type> &rhs,
+    Vector<typename SparseMatrixType::value_type> &                  rhs_vector,
+    const Function<spacedim, typename SparseMatrixType::value_type> *const a =
+      nullptr,
+    const AffineConstraints<typename SparseMatrixType::value_type> &
+      constraints = AffineConstraints<typename SparseMatrixType::value_type>());
 
   /**
    * Same function as above, but for hp-objects.
    */
-  template <int dim, int spacedim, typename number>
+  template <int dim, int spacedim, typename SparseMatrixType>
   void
   create_mass_matrix(
     const hp::MappingCollection<dim, spacedim> &mapping,
     const DoFHandler<dim, spacedim> &           dof,
     const hp::QCollection<dim> &                q,
-    SparseMatrix<number> &                      matrix,
-    const Function<spacedim, number> *const     a = nullptr,
-    const AffineConstraints<number> &constraints = AffineConstraints<number>());
+    SparseMatrixType &                          matrix,
+    const Function<spacedim, typename SparseMatrixType::value_type> *const a =
+      nullptr,
+    const AffineConstraints<typename SparseMatrixType::value_type> &
+      constraints = AffineConstraints<typename SparseMatrixType::value_type>());
 
   /**
    * Same function as above, but for hp-objects.
    */
-  template <int dim, int spacedim, typename number>
+  template <int dim, int spacedim, typename SparseMatrixType>
   void
   create_mass_matrix(
-    const DoFHandler<dim, spacedim> &       dof,
-    const hp::QCollection<dim> &            q,
-    SparseMatrix<number> &                  matrix,
-    const Function<spacedim, number> *const a    = nullptr,
-    const AffineConstraints<number> &constraints = AffineConstraints<number>());
+    const DoFHandler<dim, spacedim> &dof,
+    const hp::QCollection<dim> &     q,
+    SparseMatrixType &               matrix,
+    const Function<spacedim, typename SparseMatrixType::value_type> *const a =
+      nullptr,
+    const AffineConstraints<typename SparseMatrixType::value_type> &
+      constraints = AffineConstraints<typename SparseMatrixType::value_type>());
 
   /**
    * Same function as above, but for hp-objects.
    */
-  template <int dim, int spacedim, typename number>
+  template <int dim, int spacedim, typename SparseMatrixType>
   void
   create_mass_matrix(
-    const hp::MappingCollection<dim, spacedim> &mapping,
-    const DoFHandler<dim, spacedim> &           dof,
-    const hp::QCollection<dim> &                q,
-    SparseMatrix<number> &                      matrix,
-    const Function<spacedim, number> &          rhs,
-    Vector<number> &                            rhs_vector,
-    const Function<spacedim, number> *const     a = nullptr,
-    const AffineConstraints<number> &constraints = AffineConstraints<number>());
+    const hp::MappingCollection<dim, spacedim> &                     mapping,
+    const DoFHandler<dim, spacedim> &                                dof,
+    const hp::QCollection<dim> &                                     q,
+    SparseMatrixType &                                               matrix,
+    const Function<spacedim, typename SparseMatrixType::value_type> &rhs,
+    Vector<typename SparseMatrixType::value_type> &                  rhs_vector,
+    const Function<spacedim, typename SparseMatrixType::value_type> *const a =
+      nullptr,
+    const AffineConstraints<typename SparseMatrixType::value_type> &
+      constraints = AffineConstraints<typename SparseMatrixType::value_type>());
 
   /**
    * Same function as above, but for hp-objects.
    */
-  template <int dim, int spacedim, typename number>
+  template <int dim, int spacedim, typename SparseMatrixType>
   void
   create_mass_matrix(
-    const DoFHandler<dim, spacedim> &       dof,
-    const hp::QCollection<dim> &            q,
-    SparseMatrix<number> &                  matrix,
-    const Function<spacedim, number> &      rhs,
-    Vector<number> &                        rhs_vector,
-    const Function<spacedim, number> *const a    = nullptr,
-    const AffineConstraints<number> &constraints = AffineConstraints<number>());
+    const DoFHandler<dim, spacedim> &                                dof,
+    const hp::QCollection<dim> &                                     q,
+    SparseMatrixType &                                               matrix,
+    const Function<spacedim, typename SparseMatrixType::value_type> &rhs,
+    Vector<typename SparseMatrixType::value_type> &                  rhs_vector,
+    const Function<spacedim, typename SparseMatrixType::value_type> *const a =
+      nullptr,
+    const AffineConstraints<typename SparseMatrixType::value_type> &
+      constraints = AffineConstraints<typename SparseMatrixType::value_type>());
 
 
   /**
@@ -479,28 +495,32 @@ namespace MatrixCreator
    *
    * See the general documentation of this namespace for more information.
    */
-  template <int dim, int spacedim>
+  template <int dim, int spacedim, typename SparseMatrixType>
   void
   create_laplace_matrix(
     const Mapping<dim, spacedim> &   mapping,
     const DoFHandler<dim, spacedim> &dof,
     const Quadrature<dim> &          q,
-    SparseMatrix<double> &           matrix,
-    const Function<spacedim> *const  a           = nullptr,
-    const AffineConstraints<double> &constraints = AffineConstraints<double>());
+    SparseMatrixType &               matrix,
+    const Function<spacedim, typename SparseMatrixType::value_type> *const a =
+      nullptr,
+    const AffineConstraints<typename SparseMatrixType::value_type> &
+      constraints = AffineConstraints<typename SparseMatrixType::value_type>());
 
   /**
    * Call the create_laplace_matrix() function, see above, with
    * <tt>mapping=MappingQ@<dim@>(1)</tt>.
    */
-  template <int dim, int spacedim>
+  template <int dim, int spacedim, typename SparseMatrixType>
   void
   create_laplace_matrix(
     const DoFHandler<dim, spacedim> &dof,
     const Quadrature<dim> &          q,
-    SparseMatrix<double> &           matrix,
-    const Function<spacedim> *const  a           = nullptr,
-    const AffineConstraints<double> &constraints = AffineConstraints<double>());
+    SparseMatrixType &               matrix,
+    const Function<spacedim, typename SparseMatrixType::value_type> *const a =
+      nullptr,
+    const AffineConstraints<typename SparseMatrixType::value_type> &
+      constraints = AffineConstraints<typename SparseMatrixType::value_type>());
 
   /**
    * Assemble the Laplace matrix and a right hand side vector. If no
@@ -520,86 +540,98 @@ namespace MatrixCreator
    *
    * See the general documentation of this namespace for more information.
    */
-  template <int dim, int spacedim>
+  template <int dim, int spacedim, typename SparseMatrixType>
   void
   create_laplace_matrix(
-    const Mapping<dim, spacedim> &   mapping,
-    const DoFHandler<dim, spacedim> &dof,
-    const Quadrature<dim> &          q,
-    SparseMatrix<double> &           matrix,
-    const Function<spacedim> &       rhs,
-    Vector<double> &                 rhs_vector,
-    const Function<spacedim> *const  a           = nullptr,
-    const AffineConstraints<double> &constraints = AffineConstraints<double>());
+    const Mapping<dim, spacedim> &                                   mapping,
+    const DoFHandler<dim, spacedim> &                                dof,
+    const Quadrature<dim> &                                          q,
+    SparseMatrixType &                                               matrix,
+    const Function<spacedim, typename SparseMatrixType::value_type> &rhs,
+    Vector<typename SparseMatrixType::value_type> &                  rhs_vector,
+    const Function<spacedim, typename SparseMatrixType::value_type> *const a =
+      nullptr,
+    const AffineConstraints<typename SparseMatrixType::value_type> &
+      constraints = AffineConstraints<typename SparseMatrixType::value_type>());
 
   /**
    * Call the create_laplace_matrix() function, see above, with
    * <tt>mapping=MappingQ@<dim@>(1)</tt>.
    */
-  template <int dim, int spacedim>
+  template <int dim, int spacedim, typename SparseMatrixType>
   void
   create_laplace_matrix(
-    const DoFHandler<dim, spacedim> &dof,
-    const Quadrature<dim> &          q,
-    SparseMatrix<double> &           matrix,
-    const Function<spacedim> &       rhs,
-    Vector<double> &                 rhs_vector,
-    const Function<spacedim> *const  a           = nullptr,
-    const AffineConstraints<double> &constraints = AffineConstraints<double>());
+    const DoFHandler<dim, spacedim> &                                dof,
+    const Quadrature<dim> &                                          q,
+    SparseMatrixType &                                               matrix,
+    const Function<spacedim, typename SparseMatrixType::value_type> &rhs,
+    Vector<typename SparseMatrixType::value_type> &                  rhs_vector,
+    const Function<spacedim, typename SparseMatrixType::value_type> *const a =
+      nullptr,
+    const AffineConstraints<typename SparseMatrixType::value_type> &
+      constraints = AffineConstraints<typename SparseMatrixType::value_type>());
 
   /**
    * Like the functions above, but for hp-objects.
    */
-  template <int dim, int spacedim>
+  template <int dim, int spacedim, typename SparseMatrixType>
   void
   create_laplace_matrix(
     const hp::MappingCollection<dim, spacedim> &mapping,
     const DoFHandler<dim, spacedim> &           dof,
     const hp::QCollection<dim> &                q,
-    SparseMatrix<double> &                      matrix,
-    const Function<spacedim> *const             a = nullptr,
-    const AffineConstraints<double> &constraints = AffineConstraints<double>());
+    SparseMatrixType &                          matrix,
+    const Function<spacedim, typename SparseMatrixType::value_type> *const a =
+      nullptr,
+    const AffineConstraints<typename SparseMatrixType::value_type> &
+      constraints = AffineConstraints<typename SparseMatrixType::value_type>());
 
   /**
    * Like the functions above, but for hp-objects.
    */
-  template <int dim, int spacedim>
+  template <int dim, int spacedim, typename SparseMatrixType>
   void
   create_laplace_matrix(
     const DoFHandler<dim, spacedim> &dof,
     const hp::QCollection<dim> &     q,
-    SparseMatrix<double> &           matrix,
-    const Function<spacedim> *const  a           = nullptr,
-    const AffineConstraints<double> &constraints = AffineConstraints<double>());
+    SparseMatrixType &               matrix,
+    const Function<spacedim, typename SparseMatrixType::value_type> *const a =
+      nullptr,
+    const AffineConstraints<typename SparseMatrixType::value_type> &
+      constraints = AffineConstraints<typename SparseMatrixType::value_type>());
 
   /**
    * Like the functions above, but for hp-objects.
    */
-  template <int dim, int spacedim>
+  template <int dim, int spacedim, typename SparseMatrixType>
   void
   create_laplace_matrix(
-    const hp::MappingCollection<dim, spacedim> &mapping,
-    const DoFHandler<dim, spacedim> &           dof,
-    const hp::QCollection<dim> &                q,
-    SparseMatrix<double> &                      matrix,
-    const Function<spacedim> &                  rhs,
-    Vector<double> &                            rhs_vector,
-    const Function<spacedim> *const             a = nullptr,
-    const AffineConstraints<double> &constraints = AffineConstraints<double>());
+    const hp::MappingCollection<dim, spacedim> &                     mapping,
+    const DoFHandler<dim, spacedim> &                                dof,
+    const hp::QCollection<dim> &                                     q,
+    SparseMatrixType &                                               matrix,
+    const Function<spacedim, typename SparseMatrixType::value_type> &rhs,
+    Vector<typename SparseMatrixType::value_type> &                  rhs_vector,
+    const Function<spacedim, typename SparseMatrixType::value_type> *const a =
+      nullptr,
+    const AffineConstraints<typename SparseMatrixType::value_type> &
+      constraints = AffineConstraints<typename SparseMatrixType::value_type>());
 
   /**
    * Like the functions above, but for hp-objects.
    */
-  template <int dim, int spacedim>
+  template <int dim, int spacedim, typename SparseMatrixType>
   void
   create_laplace_matrix(
-    const DoFHandler<dim, spacedim> &dof,
-    const hp::QCollection<dim> &     q,
-    SparseMatrix<double> &           matrix,
-    const Function<spacedim> &       rhs,
-    Vector<double> &                 rhs_vector,
-    const Function<spacedim> *const  a           = nullptr,
-    const AffineConstraints<double> &constraints = AffineConstraints<double>());
+    const DoFHandler<dim, spacedim> &                                dof,
+    const hp::QCollection<dim> &                                     q,
+    SparseMatrixType &                                               matrix,
+    const Function<spacedim, typename SparseMatrixType::value_type> &rhs,
+    Vector<typename SparseMatrixType::value_type> &                  rhs_vector,
+    const Function<spacedim, typename SparseMatrixType::value_type> *const a =
+      nullptr,
+    const AffineConstraints<typename SparseMatrixType::value_type> &
+      constraints = AffineConstraints<typename SparseMatrixType::value_type>());
 
   /**
    * Exception
index 0eb54b53898fc0a31ccfa46d2ab5509a18b81f66..a13918d1a44b3739904e73010e852d70900485b5 100644 (file)
 
 // MatrixCreator::create_mass_matrix for the matrix only --> only real-valued
 // scalars
-for (scalar : REAL_SCALARS; deal_II_dimension : DIMENSIONS;
+for (deal_II_sparse_matrix_type : SPARSE_MATRICES;
+     deal_II_dimension : DIMENSIONS;
      deal_II_space_dimension : SPACE_DIMENSIONS)
   {
 #if deal_II_dimension <= deal_II_space_dimension
     // non-hp-version of create_mass_matrix
-    template void MatrixCreator::
-      create_mass_matrix<deal_II_dimension, deal_II_space_dimension, scalar>(
-        const Mapping<deal_II_dimension, deal_II_space_dimension> &   mapping,
-        const DoFHandler<deal_II_dimension, deal_II_space_dimension> &dof,
-        const Quadrature<deal_II_dimension> &                         q,
-        SparseMatrix<scalar> &                                        matrix,
-        const Function<deal_II_space_dimension, scalar> *const coefficient,
-        const AffineConstraints<scalar> &                      constraints);
-    template void MatrixCreator::
-      create_mass_matrix<deal_II_dimension, deal_II_space_dimension, scalar>(
-        const DoFHandler<deal_II_dimension, deal_II_space_dimension> &dof,
-        const Quadrature<deal_II_dimension> &                         q,
-        SparseMatrix<scalar> &                                        matrix,
-        const Function<deal_II_space_dimension, scalar> *const coefficient,
-        const AffineConstraints<scalar> &                      constraints);
+    template void MatrixCreator::create_mass_matrix<deal_II_dimension,
+                                                    deal_II_space_dimension,
+                                                    deal_II_sparse_matrix_type>(
+      const Mapping<deal_II_dimension, deal_II_space_dimension> &   mapping,
+      const DoFHandler<deal_II_dimension, deal_II_space_dimension> &dof,
+      const Quadrature<deal_II_dimension> &                         q,
+      deal_II_sparse_matrix_type &                                  matrix,
+      const Function<deal_II_space_dimension,
+                     typename deal_II_sparse_matrix_type::value_type>
+        *const coefficient,
+      const AffineConstraints<typename deal_II_sparse_matrix_type::value_type>
+        &constraints);
+    template void MatrixCreator::create_mass_matrix<deal_II_dimension,
+                                                    deal_II_space_dimension,
+                                                    deal_II_sparse_matrix_type>(
+      const DoFHandler<deal_II_dimension, deal_II_space_dimension> &dof,
+      const Quadrature<deal_II_dimension> &                         q,
+      deal_II_sparse_matrix_type &                                  matrix,
+      const Function<deal_II_space_dimension,
+                     typename deal_II_sparse_matrix_type::value_type>
+        *const coefficient,
+      const AffineConstraints<typename deal_II_sparse_matrix_type::value_type>
+        &constraints);
 
     // hp-versions of functions
-    template void MatrixCreator::
-      create_mass_matrix<deal_II_dimension, deal_II_space_dimension, scalar>(
-        const hp::MappingCollection<deal_II_dimension, deal_II_space_dimension>
-          &                                                           mapping,
-        const DoFHandler<deal_II_dimension, deal_II_space_dimension> &dof,
-        const hp::QCollection<deal_II_dimension> &                    q,
-        SparseMatrix<scalar> &                                        matrix,
-        const Function<deal_II_space_dimension, scalar> *const coefficient,
-        const AffineConstraints<scalar> &                      constraints);
+    template void MatrixCreator::create_mass_matrix<deal_II_dimension,
+                                                    deal_II_space_dimension,
+                                                    deal_II_sparse_matrix_type>(
+      const hp::MappingCollection<deal_II_dimension, deal_II_space_dimension>
+        &                                                           mapping,
+      const DoFHandler<deal_II_dimension, deal_II_space_dimension> &dof,
+      const hp::QCollection<deal_II_dimension> &                    q,
+      deal_II_sparse_matrix_type &                                  matrix,
+      const Function<deal_II_space_dimension,
+                     typename deal_II_sparse_matrix_type::value_type>
+        *const coefficient,
+      const AffineConstraints<typename deal_II_sparse_matrix_type::value_type>
+        &constraints);
 
-    template void MatrixCreator::
-      create_mass_matrix<deal_II_dimension, deal_II_space_dimension, scalar>(
-        const DoFHandler<deal_II_dimension, deal_II_space_dimension> &dof,
-        const hp::QCollection<deal_II_dimension> &                    q,
-        SparseMatrix<scalar> &                                        matrix,
-        const Function<deal_II_space_dimension, scalar> *const coefficient,
-        const AffineConstraints<scalar> &                      constraints);
+    template void MatrixCreator::create_mass_matrix<deal_II_dimension,
+                                                    deal_II_space_dimension,
+                                                    deal_II_sparse_matrix_type>(
+      const DoFHandler<deal_II_dimension, deal_II_space_dimension> &dof,
+      const hp::QCollection<deal_II_dimension> &                    q,
+      deal_II_sparse_matrix_type &                                  matrix,
+      const Function<deal_II_space_dimension,
+                     typename deal_II_sparse_matrix_type::value_type>
+        *const coefficient,
+      const AffineConstraints<typename deal_II_sparse_matrix_type::value_type>
+        &constraints);
 #endif
   }
 
@@ -67,48 +84,52 @@ for (scalar : REAL_AND_COMPLEX_SCALARS; deal_II_dimension : DIMENSIONS;
   {
 #if deal_II_dimension <= deal_II_space_dimension
     // non-hp-version of create_mass_matrix
-    template void MatrixCreator::
-      create_mass_matrix<deal_II_dimension, deal_II_space_dimension, scalar>(
-        const Mapping<deal_II_dimension, deal_II_space_dimension> &   mapping,
-        const DoFHandler<deal_II_dimension, deal_II_space_dimension> &dof,
-        const Quadrature<deal_II_dimension> &                         q,
-        SparseMatrix<scalar> &                                        matrix,
-        const Function<deal_II_space_dimension, scalar> &             rhs,
-        Vector<scalar> &                                       rhs_vector,
-        const Function<deal_II_space_dimension, scalar> *const coefficient,
-        const AffineConstraints<scalar> &                      constraints);
-    template void MatrixCreator::
-      create_mass_matrix<deal_II_dimension, deal_II_space_dimension, scalar>(
-        const DoFHandler<deal_II_dimension, deal_II_space_dimension> &dof,
-        const Quadrature<deal_II_dimension> &                         q,
-        SparseMatrix<scalar> &                                        matrix,
-        const Function<deal_II_space_dimension, scalar> &             rhs,
-        Vector<scalar> &                                       rhs_vector,
-        const Function<deal_II_space_dimension, scalar> *const coefficient,
-        const AffineConstraints<scalar> &                      constraints);
+    template void MatrixCreator::create_mass_matrix<deal_II_dimension,
+                                                    deal_II_space_dimension,
+                                                    SparseMatrix<scalar>>(
+      const Mapping<deal_II_dimension, deal_II_space_dimension> &   mapping,
+      const DoFHandler<deal_II_dimension, deal_II_space_dimension> &dof,
+      const Quadrature<deal_II_dimension> &                         q,
+      SparseMatrix<scalar> &                                        matrix,
+      const Function<deal_II_space_dimension, scalar> &             rhs,
+      Vector<scalar> &                                              rhs_vector,
+      const Function<deal_II_space_dimension, scalar> *const        coefficient,
+      const AffineConstraints<scalar> &constraints);
+    template void MatrixCreator::create_mass_matrix<deal_II_dimension,
+                                                    deal_II_space_dimension,
+                                                    SparseMatrix<scalar>>(
+      const DoFHandler<deal_II_dimension, deal_II_space_dimension> &dof,
+      const Quadrature<deal_II_dimension> &                         q,
+      SparseMatrix<scalar> &                                        matrix,
+      const Function<deal_II_space_dimension, scalar> &             rhs,
+      Vector<scalar> &                                              rhs_vector,
+      const Function<deal_II_space_dimension, scalar> *const        coefficient,
+      const AffineConstraints<scalar> &constraints);
 
     // hp-version
-    template void MatrixCreator::
-      create_mass_matrix<deal_II_dimension, deal_II_space_dimension, scalar>(
-        const hp::MappingCollection<deal_II_dimension, deal_II_space_dimension>
-          &                                                           mapping,
-        const DoFHandler<deal_II_dimension, deal_II_space_dimension> &dof,
-        const hp::QCollection<deal_II_dimension> &                    q,
-        SparseMatrix<scalar> &                                        matrix,
-        const Function<deal_II_space_dimension, scalar> &             rhs,
-        Vector<scalar> &                                       rhs_vector,
-        const Function<deal_II_space_dimension, scalar> *const coefficient,
-        const AffineConstraints<scalar> &                      constraints);
+    template void MatrixCreator::create_mass_matrix<deal_II_dimension,
+                                                    deal_II_space_dimension,
+                                                    SparseMatrix<scalar>>(
+      const hp::MappingCollection<deal_II_dimension, deal_II_space_dimension>
+        &                                                           mapping,
+      const DoFHandler<deal_II_dimension, deal_II_space_dimension> &dof,
+      const hp::QCollection<deal_II_dimension> &                    q,
+      SparseMatrix<scalar> &                                        matrix,
+      const Function<deal_II_space_dimension, scalar> &             rhs,
+      Vector<scalar> &                                              rhs_vector,
+      const Function<deal_II_space_dimension, scalar> *const        coefficient,
+      const AffineConstraints<scalar> &constraints);
 
-    template void MatrixCreator::
-      create_mass_matrix<deal_II_dimension, deal_II_space_dimension, scalar>(
-        const DoFHandler<deal_II_dimension, deal_II_space_dimension> &dof,
-        const hp::QCollection<deal_II_dimension> &                    q,
-        SparseMatrix<scalar> &                                        matrix,
-        const Function<deal_II_space_dimension, scalar> &             rhs,
-        Vector<scalar> &                                       rhs_vector,
-        const Function<deal_II_space_dimension, scalar> *const coefficient,
-        const AffineConstraints<scalar> &                      constraints);
+    template void MatrixCreator::create_mass_matrix<deal_II_dimension,
+                                                    deal_II_space_dimension,
+                                                    SparseMatrix<scalar>>(
+      const DoFHandler<deal_II_dimension, deal_II_space_dimension> &dof,
+      const hp::QCollection<deal_II_dimension> &                    q,
+      SparseMatrix<scalar> &                                        matrix,
+      const Function<deal_II_space_dimension, scalar> &             rhs,
+      Vector<scalar> &                                              rhs_vector,
+      const Function<deal_II_space_dimension, scalar> *const        coefficient,
+      const AffineConstraints<scalar> &constraints);
 #endif
   }
 
@@ -179,114 +200,192 @@ for (scalar : REAL_AND_COMPLEX_SCALARS; deal_II_dimension : DIMENSIONS;
 
 
 
-for (deal_II_dimension : DIMENSIONS; deal_II_space_dimension : SPACE_DIMENSIONS)
+for (deal_II_sparse_matrix_type : SPARSE_MATRICES;
+     deal_II_dimension : DIMENSIONS;
+     deal_II_space_dimension : SPACE_DIMENSIONS)
   {
 #if deal_II_dimension == deal_II_space_dimension
 
     // non-hp-versions of create_laplace_matrix
-    template void MatrixCreator::create_laplace_matrix<deal_II_dimension>(
-      const DoFHandler<deal_II_dimension> &    dof,
-      const Quadrature<deal_II_dimension> &    q,
-      SparseMatrix<double> &                   matrix,
-      const Function<deal_II_dimension> *const coefficient,
-      const AffineConstraints<double> &        constraints);
-    template void MatrixCreator::create_laplace_matrix<deal_II_dimension>(
-      const Mapping<deal_II_dimension> &       mapping,
-      const DoFHandler<deal_II_dimension> &    dof,
-      const Quadrature<deal_II_dimension> &    q,
-      SparseMatrix<double> &                   matrix,
-      const Function<deal_II_dimension> *const coefficient,
-      const AffineConstraints<double> &        constraints);
-    template void MatrixCreator::create_laplace_matrix<deal_II_dimension>(
-      const Mapping<deal_II_dimension> &       mapping,
-      const DoFHandler<deal_II_dimension> &    dof,
-      const Quadrature<deal_II_dimension> &    q,
-      SparseMatrix<double> &                   matrix,
-      const Function<deal_II_dimension> &      rhs,
-      Vector<double> &                         rhs_vector,
-      const Function<deal_II_dimension> *const coefficient,
-      const AffineConstraints<double> &        constraints);
-    template void MatrixCreator::create_laplace_matrix<deal_II_dimension>(
-      const DoFHandler<deal_II_dimension> &    dof,
-      const Quadrature<deal_II_dimension> &    q,
-      SparseMatrix<double> &                   matrix,
-      const Function<deal_II_dimension> &      rhs,
-      Vector<double> &                         rhs_vector,
-      const Function<deal_II_dimension> *const coefficient,
-      const AffineConstraints<double> &        constraints);
+    template void
+    MatrixCreator::create_laplace_matrix<deal_II_dimension,
+                                         deal_II_space_dimension,
+                                         deal_II_sparse_matrix_type>(
+      const DoFHandler<deal_II_dimension> &dof,
+      const Quadrature<deal_II_dimension> &q,
+      deal_II_sparse_matrix_type &         matrix,
+      const Function<deal_II_dimension,
+                     typename deal_II_sparse_matrix_type::value_type>
+        *const coefficient,
+      const AffineConstraints<typename deal_II_sparse_matrix_type::value_type>
+        &constraints);
+    template void
+    MatrixCreator::create_laplace_matrix<deal_II_dimension,
+                                         deal_II_space_dimension,
+                                         deal_II_sparse_matrix_type>(
+      const Mapping<deal_II_dimension> &   mapping,
+      const DoFHandler<deal_II_dimension> &dof,
+      const Quadrature<deal_II_dimension> &q,
+      deal_II_sparse_matrix_type &         matrix,
+      const Function<deal_II_dimension,
+                     typename deal_II_sparse_matrix_type::value_type>
+        *const coefficient,
+      const AffineConstraints<typename deal_II_sparse_matrix_type::value_type>
+        &constraints);
+    template void
+    MatrixCreator::create_laplace_matrix<deal_II_dimension,
+                                         deal_II_space_dimension,
+                                         deal_II_sparse_matrix_type>(
+      const Mapping<deal_II_dimension> &                               mapping,
+      const DoFHandler<deal_II_dimension> &                            dof,
+      const Quadrature<deal_II_dimension> &                            q,
+      deal_II_sparse_matrix_type &                                     matrix,
+      const Function<deal_II_dimension,
+                     typename deal_II_sparse_matrix_type::value_type> &rhs,
+      Vector<typename deal_II_sparse_matrix_type::value_type> &rhs_vector,
+      const Function<deal_II_dimension,
+                     typename deal_II_sparse_matrix_type::value_type>
+        *const coefficient,
+      const AffineConstraints<typename deal_II_sparse_matrix_type::value_type>
+        &constraints);
+    template void
+    MatrixCreator::create_laplace_matrix<deal_II_dimension,
+                                         deal_II_space_dimension,
+                                         deal_II_sparse_matrix_type>(
+      const DoFHandler<deal_II_dimension> &                            dof,
+      const Quadrature<deal_II_dimension> &                            q,
+      deal_II_sparse_matrix_type &                                     matrix,
+      const Function<deal_II_dimension,
+                     typename deal_II_sparse_matrix_type::value_type> &rhs,
+      Vector<typename deal_II_sparse_matrix_type::value_type> &rhs_vector,
+      const Function<deal_II_dimension,
+                     typename deal_II_sparse_matrix_type::value_type>
+        *const coefficient,
+      const AffineConstraints<typename deal_II_sparse_matrix_type::value_type>
+        &constraints);
 
     // hp-versions of create_laplace_matrix
-    template void MatrixCreator::create_laplace_matrix<deal_II_dimension>(
+    template void
+    MatrixCreator::create_laplace_matrix<deal_II_dimension,
+                                         deal_II_space_dimension,
+                                         deal_II_sparse_matrix_type>(
       const DoFHandler<deal_II_dimension> &     dof,
       const hp::QCollection<deal_II_dimension> &q,
-      SparseMatrix<double> &                    matrix,
-      const Function<deal_II_dimension> *const  coefficient,
-      const AffineConstraints<double> &         constraints);
-    template void MatrixCreator::create_laplace_matrix<deal_II_dimension>(
-      const hp::MappingCollection<deal_II_dimension> &mapping,
-      const DoFHandler<deal_II_dimension> &           dof,
-      const hp::QCollection<deal_II_dimension> &      q,
-      SparseMatrix<double> &                          matrix,
-      const Function<deal_II_dimension> *const        coefficient,
-      const AffineConstraints<double> &               constraints);
-    template void MatrixCreator::create_laplace_matrix<deal_II_dimension>(
+      deal_II_sparse_matrix_type &              matrix,
+      const Function<deal_II_dimension,
+                     typename deal_II_sparse_matrix_type::value_type>
+        *const coefficient,
+      const AffineConstraints<typename deal_II_sparse_matrix_type::value_type>
+        &constraints);
+    template void
+    MatrixCreator::create_laplace_matrix<deal_II_dimension,
+                                         deal_II_space_dimension,
+                                         deal_II_sparse_matrix_type>(
       const hp::MappingCollection<deal_II_dimension> &mapping,
       const DoFHandler<deal_II_dimension> &           dof,
       const hp::QCollection<deal_II_dimension> &      q,
-      SparseMatrix<double> &                          matrix,
-      const Function<deal_II_dimension> &             rhs,
-      Vector<double> &                                rhs_vector,
-      const Function<deal_II_dimension> *const        coefficient,
-      const AffineConstraints<double> &               constraints);
-    template void MatrixCreator::create_laplace_matrix<deal_II_dimension>(
-      const DoFHandler<deal_II_dimension> &     dof,
-      const hp::QCollection<deal_II_dimension> &q,
-      SparseMatrix<double> &                    matrix,
-      const Function<deal_II_dimension> &       rhs,
-      Vector<double> &                          rhs_vector,
-      const Function<deal_II_dimension> *const  coefficient,
-      const AffineConstraints<double> &         constraints);
+      deal_II_sparse_matrix_type &                    matrix,
+      const Function<deal_II_dimension,
+                     typename deal_II_sparse_matrix_type::value_type>
+        *const coefficient,
+      const AffineConstraints<typename deal_II_sparse_matrix_type::value_type>
+        &constraints);
+    template void
+    MatrixCreator::create_laplace_matrix<deal_II_dimension,
+                                         deal_II_space_dimension,
+                                         deal_II_sparse_matrix_type>(
+      const hp::MappingCollection<deal_II_dimension> &                 mapping,
+      const DoFHandler<deal_II_dimension> &                            dof,
+      const hp::QCollection<deal_II_dimension> &                       q,
+      deal_II_sparse_matrix_type &                                     matrix,
+      const Function<deal_II_dimension,
+                     typename deal_II_sparse_matrix_type::value_type> &rhs,
+      Vector<typename deal_II_sparse_matrix_type::value_type> &rhs_vector,
+      const Function<deal_II_dimension,
+                     typename deal_II_sparse_matrix_type::value_type>
+        *const coefficient,
+      const AffineConstraints<typename deal_II_sparse_matrix_type::value_type>
+        &constraints);
+    template void
+    MatrixCreator::create_laplace_matrix<deal_II_dimension,
+                                         deal_II_space_dimension,
+                                         deal_II_sparse_matrix_type>(
+      const DoFHandler<deal_II_dimension> &                            dof,
+      const hp::QCollection<deal_II_dimension> &                       q,
+      deal_II_sparse_matrix_type &                                     matrix,
+      const Function<deal_II_dimension,
+                     typename deal_II_sparse_matrix_type::value_type> &rhs,
+      Vector<typename deal_II_sparse_matrix_type::value_type> &rhs_vector,
+      const Function<deal_II_dimension,
+                     typename deal_II_sparse_matrix_type::value_type>
+        *const coefficient,
+      const AffineConstraints<typename deal_II_sparse_matrix_type::value_type>
+        &constraints);
 
 #endif
   }
 
-for (deal_II_dimension : DIMENSIONS; deal_II_space_dimension : SPACE_DIMENSIONS)
+for (deal_II_sparse_matrix_type : SPARSE_MATRICES;
+     deal_II_dimension : DIMENSIONS;
+     deal_II_space_dimension : SPACE_DIMENSIONS)
   {
 #if deal_II_dimension < deal_II_space_dimension
     // non-hp-version of create_laplace_matrix
-    template void MatrixCreator::create_laplace_matrix<deal_II_dimension,
-                                                       deal_II_space_dimension>(
-      const Mapping<deal_II_dimension, deal_II_space_dimension> &   mapping,
-      const DoFHandler<deal_II_dimension, deal_II_space_dimension> &dof,
-      const Quadrature<deal_II_dimension> &                         q,
-      SparseMatrix<double> &                                        matrix,
-      const Function<deal_II_space_dimension, double> *const        coefficient,
-      const AffineConstraints<double> &constraints);
-    template void MatrixCreator::create_laplace_matrix<deal_II_dimension,
-                                                       deal_II_space_dimension>(
-      const DoFHandler<deal_II_dimension, deal_II_space_dimension> &dof,
-      const Quadrature<deal_II_dimension> &                         q,
-      SparseMatrix<double> &                                        matrix,
-      const Function<deal_II_space_dimension, double> *const        coefficient,
-      const AffineConstraints<double> &constraints);
-    template void MatrixCreator::create_laplace_matrix<deal_II_dimension,
-                                                       deal_II_space_dimension>(
+    template void
+    MatrixCreator::create_laplace_matrix<deal_II_dimension,
+                                         deal_II_space_dimension,
+                                         deal_II_sparse_matrix_type>(
       const Mapping<deal_II_dimension, deal_II_space_dimension> &   mapping,
       const DoFHandler<deal_II_dimension, deal_II_space_dimension> &dof,
       const Quadrature<deal_II_dimension> &                         q,
-      SparseMatrix<double> &                                        matrix,
-      const Function<deal_II_space_dimension, double> &             rhs,
-      Vector<double> &                                              rhs_vector,
-      const Function<deal_II_space_dimension, double> *const        coefficient,
-      const AffineConstraints<double> &constraints);
-    template void MatrixCreator::create_laplace_matrix<deal_II_dimension,
-                                                       deal_II_space_dimension>(
+      deal_II_sparse_matrix_type &                                  matrix,
+      const Function<deal_II_space_dimension,
+                     typename deal_II_sparse_matrix_type::value_type>
+        *const coefficient,
+      const AffineConstraints<typename deal_II_sparse_matrix_type::value_type>
+        &constraints);
+    template void
+    MatrixCreator::create_laplace_matrix<deal_II_dimension,
+                                         deal_II_space_dimension,
+                                         deal_II_sparse_matrix_type>(
       const DoFHandler<deal_II_dimension, deal_II_space_dimension> &dof,
       const Quadrature<deal_II_dimension> &                         q,
-      SparseMatrix<double> &                                        matrix,
-      const Function<deal_II_space_dimension, double> &             rhs,
-      Vector<double> &                                              rhs_vector,
-      const Function<deal_II_space_dimension, double> *const        coefficient,
-      const AffineConstraints<double> &constraints);
+      deal_II_sparse_matrix_type &                                  matrix,
+      const Function<deal_II_space_dimension,
+                     typename deal_II_sparse_matrix_type::value_type>
+        *const coefficient,
+      const AffineConstraints<typename deal_II_sparse_matrix_type::value_type>
+        &constraints);
+    template void
+    MatrixCreator::create_laplace_matrix<deal_II_dimension,
+                                         deal_II_space_dimension,
+                                         deal_II_sparse_matrix_type>(
+      const Mapping<deal_II_dimension, deal_II_space_dimension> &      mapping,
+      const DoFHandler<deal_II_dimension, deal_II_space_dimension> &   dof,
+      const Quadrature<deal_II_dimension> &                            q,
+      deal_II_sparse_matrix_type &                                     matrix,
+      const Function<deal_II_space_dimension,
+                     typename deal_II_sparse_matrix_type::value_type> &rhs,
+      Vector<typename deal_II_sparse_matrix_type::value_type> &rhs_vector,
+      const Function<deal_II_space_dimension,
+                     typename deal_II_sparse_matrix_type::value_type>
+        *const coefficient,
+      const AffineConstraints<typename deal_II_sparse_matrix_type::value_type>
+        &constraints);
+    template void
+    MatrixCreator::create_laplace_matrix<deal_II_dimension,
+                                         deal_II_space_dimension,
+                                         deal_II_sparse_matrix_type>(
+      const DoFHandler<deal_II_dimension, deal_II_space_dimension> &   dof,
+      const Quadrature<deal_II_dimension> &                            q,
+      deal_II_sparse_matrix_type &                                     matrix,
+      const Function<deal_II_space_dimension,
+                     typename deal_II_sparse_matrix_type::value_type> &rhs,
+      Vector<typename deal_II_sparse_matrix_type::value_type> &rhs_vector,
+      const Function<deal_II_space_dimension,
+                     typename deal_II_sparse_matrix_type::value_type>
+        *const coefficient,
+      const AffineConstraints<typename deal_II_sparse_matrix_type::value_type>
+        &constraints);
 #endif
   }
diff --git a/tests/numerics/matrix_creator_01.cc b/tests/numerics/matrix_creator_01.cc
new file mode 100644 (file)
index 0000000..07f893c
--- /dev/null
@@ -0,0 +1,97 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2021 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.
+//
+// ---------------------------------------------------------------------
+
+
+// Test MatrixCreator::create_mass_matrix() and
+// MatrixCreator::create_laplace_matrix() for Trilinos and PETSc matrices in
+// parallel.
+
+#include <deal.II/base/mpi.h>
+#include <deal.II/base/quadrature_lib.h>
+
+#include <deal.II/distributed/tria.h>
+
+#include <deal.II/dofs/dof_tools.h>
+
+#include <deal.II/fe/fe_q.h>
+
+#include <deal.II/grid/grid_generator.h>
+
+#include <deal.II/lac/generic_linear_algebra.h>
+#include <deal.II/lac/sparsity_tools.h>
+
+#include <deal.II/numerics/matrix_tools.h>
+
+#include "../tests.h"
+
+using namespace dealii;
+
+template <int dim, typename MatrixType>
+void
+test()
+{
+  parallel::distributed::Triangulation<dim> tria(MPI_COMM_WORLD);
+  GridGenerator::hyper_cube(tria);
+  tria.refine_global(2);
+
+  FE_Q<dim>   fe(2);
+  QGauss<dim> quad(3);
+
+  DoFHandler<dim> dof_handler(tria);
+  dof_handler.distribute_dofs(fe);
+
+  const auto      mpi_comm   = dof_handler.get_communicator();
+  const IndexSet &owned_dofs = dof_handler.locally_owned_dofs();
+
+  IndexSet relevant_dofs;
+  DoFTools::extract_locally_relevant_dofs(dof_handler, relevant_dofs);
+
+  AffineConstraints<typename MatrixType::value_type> constraints;
+
+  DynamicSparsityPattern sparsity_pattern(relevant_dofs);
+  DoFTools::make_sparsity_pattern(dof_handler, sparsity_pattern, constraints);
+  SparsityTools::distribute_sparsity_pattern(sparsity_pattern,
+                                             owned_dofs,
+                                             mpi_comm,
+                                             relevant_dofs);
+
+  MatrixType matrix;
+  matrix.reinit(owned_dofs, owned_dofs, sparsity_pattern, mpi_comm);
+
+  MatrixCreator::create_laplace_matrix(dof_handler, quad, matrix);
+  deallog << "Laplace matrix: " << matrix.frobenius_norm() << std::endl;
+
+  matrix = 0.0;
+  MatrixCreator::create_mass_matrix(dof_handler, quad, matrix);
+  deallog << "Mass matrix:    " << matrix.frobenius_norm() << std::endl;
+}
+
+int
+main(int argc, char *argv[])
+{
+  Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1);
+  mpi_initlog();
+
+  {
+    deallog.push("Trilinos");
+    test<2, TrilinosWrappers::SparseMatrix>();
+    deallog.pop();
+  }
+  {
+    deallog.push("PETSc");
+    test<2, PETScWrappers::MPI::SparseMatrix>();
+    deallog.pop();
+  }
+}
diff --git a/tests/numerics/matrix_creator_01.with_p4est=true.mpirun=1.with_petsc=on.with_trilinos=on.output b/tests/numerics/matrix_creator_01.with_p4est=true.mpirun=1.with_petsc=on.with_trilinos=on.output
new file mode 100644 (file)
index 0000000..b78c103
--- /dev/null
@@ -0,0 +1,5 @@
+
+DEAL:Trilinos::Laplace matrix: 34.9481
+DEAL:Trilinos::Mass matrix:    0.0916667
+DEAL:PETSc::Laplace matrix: 34.9481
+DEAL:PETSc::Mass matrix:    0.0916667
diff --git a/tests/numerics/matrix_creator_01.with_p4est=true.mpirun=3.with_petsc=on.with_trilinos=on.output b/tests/numerics/matrix_creator_01.with_p4est=true.mpirun=3.with_petsc=on.with_trilinos=on.output
new file mode 100644 (file)
index 0000000..b78c103
--- /dev/null
@@ -0,0 +1,5 @@
+
+DEAL:Trilinos::Laplace matrix: 34.9481
+DEAL:Trilinos::Mass matrix:    0.0916667
+DEAL:PETSc::Laplace matrix: 34.9481
+DEAL:PETSc::Mass matrix:    0.0916667

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.