]> https://gitweb.dealii.org/ - dealii.git/commitdiff
DoFTools::extract_constant_modes(): return vectors 17479/head
authorPeter Munch <peterrmuench@gmail.com>
Sat, 10 Aug 2024 17:26:11 +0000 (19:26 +0200)
committerPeter Munch <peterrmuench@gmail.com>
Mon, 26 Aug 2024 11:46:26 +0000 (13:46 +0200)
15 files changed:
examples/step-31/step-31.cc
examples/step-32/step-32.cc
examples/step-42/step-42.cc
examples/step-90/step-90.cc
include/deal.II/dofs/dof_tools.h
source/dofs/dof_tools.cc
source/dofs/dof_tools.inst.in
tests/dofs/extract_dofs_by_component_04.cc
tests/mpi/extract_constant_modes_01.cc
tests/mpi/extract_constant_modes_02.cc
tests/mpi/extract_constant_modes_03.cc
tests/mpi/extract_constant_modes_04.cc
tests/simplex/step-31.cc
tests/trilinos/precondition_amg_dgp_01.cc
tests/trilinos/precondition_muelu_dgp.cc

index 6ee6303a89e4675d3b438725d7989ecbd4aee6ca..3812ddb9a6dbea5c2b59314f551f85334959ba4c 100644 (file)
@@ -1124,12 +1124,10 @@ namespace Step31
 
     Amg_preconditioner = std::make_shared<TrilinosWrappers::PreconditionAMG>();
 
-    std::vector<std::vector<bool>>   constant_modes;
-    const FEValuesExtractors::Vector velocity_components(0);
-    DoFTools::extract_constant_modes(stokes_dof_handler,
-                                     stokes_fe.component_mask(
-                                       velocity_components),
-                                     constant_modes);
+    const FEValuesExtractors::Vector     velocity_components(0);
+    const std::vector<std::vector<bool>> constant_modes =
+      DoFTools::extract_constant_modes(
+        stokes_dof_handler, stokes_fe.component_mask(velocity_components));
     TrilinosWrappers::PreconditionAMG::AdditionalData amg_data;
     amg_data.constant_modes = constant_modes;
 
index 1d536f50fb90e98ec30e344b0a21f7a0f78f78e4..e0db852efb072094b89fffa1161bd3090efde448 100644 (file)
@@ -2160,12 +2160,10 @@ namespace Step32
 
     assemble_stokes_preconditioner();
 
-    std::vector<std::vector<bool>>   constant_modes;
-    const FEValuesExtractors::Vector velocity_components(0);
-    DoFTools::extract_constant_modes(stokes_dof_handler,
-                                     stokes_fe.component_mask(
-                                       velocity_components),
-                                     constant_modes);
+    const FEValuesExtractors::Vector     velocity_components(0);
+    const std::vector<std::vector<bool>> constant_modes =
+      DoFTools::extract_constant_modes(
+        stokes_dof_handler, stokes_fe.component_mask(velocity_components));
 
     Mp_preconditioner =
       std::make_shared<TrilinosWrappers::PreconditionJacobi>();
index f50bad68f2b74cafd68df60cfdb9fedf8d2b071b..c4ef650a1a4a50a66c41dc0c0f9d41a23b7269ef 100644 (file)
@@ -1622,10 +1622,8 @@ namespace Step42
     {
       TimerOutput::Scope t(computing_timer, "Solve: setup preconditioner");
 
-      std::vector<std::vector<bool>> constant_modes;
-      DoFTools::extract_constant_modes(dof_handler,
-                                       ComponentMask(),
-                                       constant_modes);
+      const std::vector<std::vector<bool>> constant_modes =
+        DoFTools::extract_constant_modes(dof_handler, ComponentMask());
 
       TrilinosWrappers::PreconditionAMG::AdditionalData additional_data;
       additional_data.constant_modes        = constant_modes;
index aaee4a21f244d6703aed505c3fd391a2cd04c1a6..c14ae9b33199d2b333a3702221526e1347515bbf 100644 (file)
@@ -946,10 +946,8 @@ namespace Step90
               << std::flush;
         const unsigned int max_iterations = 500;
         SolverControl      solver_control(max_iterations, relative_error);
-        std::vector<std::vector<bool>> constant_modes;
-        DoFTools::extract_constant_modes(dof_handler,
-                                         ComponentMask(),
-                                         constant_modes);
+        const std::vector<std::vector<bool>> constant_modes =
+          DoFTools::extract_constant_modes(dof_handler, ComponentMask());
         TrilinosWrappers::PreconditionAMG preconditioner_stiffness;
         TrilinosWrappers::PreconditionAMG::AdditionalData Amg_data;
         Amg_data.constant_modes        = constant_modes;
index 5ec5922656b7da328ca8378cc28868182c10ec01..0c25937c1d91046e81666633d2e624b116dbb15f 100644 (file)
@@ -1371,20 +1371,44 @@ namespace DoFTools
    * This function is used in step-31, step-32, and step-42, for example.
    */
   template <int dim, int spacedim>
-  void
+  std::vector<std::vector<bool>>
   extract_constant_modes(const DoFHandler<dim, spacedim> &dof_handler,
-                         const ComponentMask             &component_mask,
-                         std::vector<std::vector<bool>>  &constant_modes);
+                         const ComponentMask             &component_mask);
+
+  /**
+   * Same as above.
+   *
+   * @deprecated
+   */
+  template <int dim, int spacedim>
+  DEAL_II_DEPRECATED_EARLY_WITH_COMMENT(
+    "Use the other function that returns the constant modes by value, rather than via an argument.")
+  void extract_constant_modes(const DoFHandler<dim, spacedim> &dof_handler,
+                              const ComponentMask             &component_mask,
+                              std::vector<std::vector<bool>>  &constant_modes);
 
   /**
    * Same as above but for multigrid levels.
    */
   template <int dim, int spacedim>
-  void
+  std::vector<std::vector<bool>>
   extract_level_constant_modes(const unsigned int               level,
                                const DoFHandler<dim, spacedim> &dof_handler,
-                               const ComponentMask             &component_mask,
-                               std::vector<std::vector<bool>>  &constant_modes);
+                               const ComponentMask             &component_mask);
+
+  /**
+   * Same as above.
+   *
+   * @deprecated
+   */
+  template <int dim, int spacedim>
+  DEAL_II_DEPRECATED_EARLY_WITH_COMMENT(
+    "Use the other function that returns the constant modes by value, rather than via an argument.")
+  void extract_level_constant_modes(
+    const unsigned int               level,
+    const DoFHandler<dim, spacedim> &dof_handler,
+    const ComponentMask             &component_mask,
+    std::vector<std::vector<bool>>  &constant_modes);
 
   /**
    * Same as the above but additional to the translational modes also
index 3c344a445983f974be45f9646ef13eb1df2359a1..497dc3bcc8dbf0d598eb1faf2853bcd26f0c2128 100644 (file)
@@ -1269,12 +1269,13 @@ namespace DoFTools
   namespace internal
   {
     template <int dim, int spacedim>
-    void
+    std::vector<std::vector<bool>>
     extract_constant_modes(const DoFHandler<dim, spacedim> &dof_handler,
                            const ComponentMask             &component_mask,
-                           const unsigned int               mg_level,
-                           std::vector<std::vector<bool>>  &constant_modes)
+                           const unsigned int               mg_level)
     {
+      std::vector<std::vector<bool>> constant_modes;
+
       const auto &locally_owned_dofs =
         (mg_level == numbers::invalid_unsigned_int) ?
           dof_handler.locally_owned_dofs() :
@@ -1284,8 +1285,7 @@ namespace DoFTools
       // constant_modes object:
       if (locally_owned_dofs.n_elements() == 0)
         {
-          constant_modes = std::vector<std::vector<bool>>(0);
-          return;
+          return std::vector<std::vector<bool>>(0);
         }
 
       const unsigned int n_components = dof_handler.get_fe(0).n_components();
@@ -1408,6 +1408,8 @@ namespace DoFTools
                       indices.second, i);
             }
       });
+
+      return constant_modes;
     }
 
 
@@ -1538,16 +1540,40 @@ namespace DoFTools
 
 
 
+  template <int dim, int spacedim>
+  std::vector<std::vector<bool>>
+  extract_constant_modes(const DoFHandler<dim, spacedim> &dof_handler,
+                         const ComponentMask             &component_mask)
+  {
+    return internal::extract_constant_modes(dof_handler,
+                                            component_mask,
+                                            numbers::invalid_unsigned_int);
+  }
+
+
+
   template <int dim, int spacedim>
   void
   extract_constant_modes(const DoFHandler<dim, spacedim> &dof_handler,
                          const ComponentMask             &component_mask,
                          std::vector<std::vector<bool>>  &constant_modes)
   {
-    internal::extract_constant_modes(dof_handler,
-                                     component_mask,
-                                     numbers::invalid_unsigned_int,
-                                     constant_modes);
+    const auto temp =
+      internal::extract_constant_modes(dof_handler,
+                                       component_mask,
+                                       numbers::invalid_unsigned_int);
+    constant_modes = temp;
+  }
+
+
+
+  template <int dim, int spacedim>
+  std::vector<std::vector<bool>>
+  extract_level_constant_modes(const unsigned int               level,
+                               const DoFHandler<dim, spacedim> &dof_handler,
+                               const ComponentMask             &component_mask)
+  {
+    return internal::extract_constant_modes(dof_handler, component_mask, level);
   }
 
 
@@ -1559,10 +1585,9 @@ namespace DoFTools
                                const ComponentMask             &component_mask,
                                std::vector<std::vector<bool>>  &constant_modes)
   {
-    internal::extract_constant_modes(dof_handler,
-                                     component_mask,
-                                     level,
-                                     constant_modes);
+    const auto temp =
+      internal::extract_constant_modes(dof_handler, component_mask, level);
+    constant_modes = temp;
   }
 
 
index d371037eb6f834a6398abebe150a4632394782d6..901e203c6690521d5c86d3bbedb05f378a4691ec 100644 (file)
@@ -188,11 +188,21 @@ for (deal_II_dimension : DIMENSIONS)
       const types::subdomain_id            subdomain_id,
       std::vector<bool>                   &selected_dofs);
 
+    template std::vector<std::vector<bool>> DoFTools::extract_constant_modes<
+      deal_II_dimension>(const DoFHandler<deal_II_dimension> &dof_handler,
+                         const ComponentMask &selected_components);
+
     template void DoFTools::extract_constant_modes<deal_II_dimension>(
       const DoFHandler<deal_II_dimension> &dof_handler,
       const ComponentMask                 &selected_components,
       std::vector<std::vector<bool>>      &constant_modes);
 
+    template std::vector<std::vector<bool>>
+    DoFTools::extract_level_constant_modes<deal_II_dimension>(
+      const unsigned int                   level,
+      const DoFHandler<deal_II_dimension> &dof_handler,
+      const ComponentMask                 &selected_components);
+
     template void DoFTools::extract_level_constant_modes<deal_II_dimension>(
       const unsigned int                   level,
       const DoFHandler<deal_II_dimension> &dof_handler,
index 3ce1b9f06eda658f54a2e8de4f14efbb65f6b257..d4c3ba790377b16560fe43e4e338b57ea1a663ab 100644 (file)
@@ -67,8 +67,8 @@ check()
       for (unsigned int c = 0; c < element.n_components(); ++c)
         component_mask.set(c, (int_mask & (1 << c)));
 
-      std::vector<std::vector<bool>> constant_modes;
-      DoFTools::extract_constant_modes(dof, component_mask, constant_modes);
+      const auto constant_modes =
+        DoFTools::extract_constant_modes(dof, component_mask);
 
       for (unsigned int d = 0; d < constant_modes.size(); ++d)
         {
index eea5ec9b2e7f5b16e6c0a40aa66a4b4f92042877..fbaa96204d42116dcd624a04677902272d5dfdf7 100644 (file)
@@ -68,8 +68,8 @@ test()
         ComponentMask mask(fe.n_components(), false);
         mask.set(c, true);
 
-        std::vector<std::vector<bool>> constant_modes;
-        DoFTools::extract_constant_modes(dofh, mask, constant_modes);
+        const auto constant_modes =
+          DoFTools::extract_constant_modes(dofh, mask);
 
         for (unsigned int i = 0; i < constant_modes.size(); ++i)
           {
@@ -87,8 +87,8 @@ test()
         ComponentMask mask(fe.n_components(), false);
         mask.set(c, true);
 
-        std::vector<std::vector<bool>> constant_modes;
-        DoFTools::extract_constant_modes(dofh, mask, constant_modes);
+        const auto constant_modes =
+          DoFTools::extract_constant_modes(dofh, mask);
 
         for (unsigned int i = 0; i < constant_modes.size(); ++i)
           {
index d115ac54d0633d954e74d5d09df06b1fb5830ea7..703e1772ccbb12c7cc86a03f98f8fb0f1a817f89 100644 (file)
@@ -64,8 +64,7 @@ test()
     {
       ComponentMask mask(fe.n_components(), true);
 
-      std::vector<std::vector<bool>> constant_modes;
-      DoFTools::extract_constant_modes(dofh, mask, constant_modes);
+      const auto constant_modes = DoFTools::extract_constant_modes(dofh, mask);
 
       for (unsigned int i = 0; i < constant_modes.size(); ++i)
         {
index 432fe34c41e82e5fb311cc9579a1e9eef3d29647..538905f08cc0da9233da64f12baa91e35bbb6612 100644 (file)
@@ -82,8 +82,7 @@ test(unsigned int fe_nothing_index)
     {
       ComponentMask mask(1, true);
 
-      std::vector<std::vector<bool>> constant_modes;
-      DoFTools::extract_constant_modes(dofh, mask, constant_modes);
+      const auto constant_modes = DoFTools::extract_constant_modes(dofh, mask);
 
       for (unsigned int i = 0; i < constant_modes.size(); ++i)
         {
index 80fdd790ee16fd889e1db502789e5bf514808a21..ac419578eeee7cbd6c90476da3c9a571c75b2c9f 100644 (file)
@@ -73,8 +73,8 @@ test()
         ComponentMask mask(fe.n_components(), false);
         mask.set(c, true);
 
-        std::vector<std::vector<bool>> constant_modes;
-        DoFTools::extract_level_constant_modes(0, dofh, mask, constant_modes);
+        const auto constant_modes =
+          DoFTools::extract_level_constant_modes(0, dofh, mask);
 
         for (unsigned int i = 0; i < constant_modes.size(); ++i)
           {
@@ -92,8 +92,8 @@ test()
         ComponentMask mask(fe.n_components(), false);
         mask.set(c, true);
 
-        std::vector<std::vector<bool>> constant_modes;
-        DoFTools::extract_level_constant_modes(0, dofh, mask, constant_modes);
+        const auto constant_modes =
+          DoFTools::extract_level_constant_modes(0, dofh, mask);
 
         for (unsigned int i = 0; i < constant_modes.size(); ++i)
           {
index fc37345f138511434ed273fa982a74d203701af7..465cb37b48ac98a5b0884613a23e881c8f654453 100644 (file)
@@ -600,12 +600,9 @@ namespace Step31
     deallog << "   Rebuilding Stokes preconditioner..." << std::flush;
     assemble_stokes_preconditioner();
     Amg_preconditioner = std::make_shared<TrilinosWrappers::PreconditionAMG>();
-    std::vector<std::vector<bool>>   constant_modes;
     const FEValuesExtractors::Vector velocity_components(0);
-    DoFTools::extract_constant_modes(stokes_dof_handler,
-                                     stokes_fe.component_mask(
-                                       velocity_components),
-                                     constant_modes);
+    const auto constant_modes = DoFTools::extract_constant_modes(
+      stokes_dof_handler, stokes_fe.component_mask(velocity_components));
 
     std::vector<std::vector<double>> constant_modes_values(
       constant_modes.size());
index 060de40a6a02cafc80f01874a5f06bf07b6a98a9..717e469b1e3597dfc78b0d8f22f13c1fe810669a 100644 (file)
@@ -197,9 +197,8 @@ Step4<dim>::solve()
   deallog.push(Utilities::int_to_string(dof_handler.n_dofs(), 5));
   TrilinosWrappers::PreconditionAMG                 preconditioner;
   TrilinosWrappers::PreconditionAMG::AdditionalData data;
-  DoFTools::extract_constant_modes(dof_handler,
-                                   ComponentMask(1, true),
-                                   data.constant_modes);
+  data.constant_modes =
+    DoFTools::extract_constant_modes(dof_handler, ComponentMask(1, true));
   data.smoother_sweeps = 2;
   {
     solution = 0;
index 549e88ef61b9e79533db5a6573006f0fc8dfb980..59a4c45eda46eccdc954ad47fbf623ae491909db 100644 (file)
@@ -197,9 +197,8 @@ Step4<dim>::solve()
   deallog.push(Utilities::int_to_string(dof_handler.n_dofs(), 5));
   TrilinosWrappers::PreconditionAMGMueLu                 preconditioner;
   TrilinosWrappers::PreconditionAMGMueLu::AdditionalData data;
-  DoFTools::extract_constant_modes(dof_handler,
-                                   std::vector<bool>(1, true),
-                                   data.constant_modes);
+  data.constant_modes =
+    DoFTools::extract_constant_modes(dof_handler, std::vector<bool>(1, true));
   data.smoother_sweeps = 2;
   {
     solution = 0;

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.