]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Pass optional arguments to MGLevelObject 10964/head
authorPeter Munch <peterrmuench@gmail.com>
Thu, 24 Sep 2020 14:19:58 +0000 (16:19 +0200)
committerPeter Munch <peterrmuench@gmail.com>
Thu, 24 Sep 2020 18:53:21 +0000 (20:53 +0200)
include/deal.II/base/mg_level_object.h
tests/multigrid/mg_level_object_args_01.cc [new file with mode: 0644]
tests/multigrid/mg_level_object_args_01.output [new file with mode: 0644]

index cc3e8fbce675477a594e8c13776e743dfb2aaec9..2b57ea888a1165936225c5c929cf6ebad17948fb 100644 (file)
@@ -65,11 +65,15 @@ public:
    *   for level objects.
    * @param[in] maxlevel The highest level for which to provision memory
    *   for level objects.
+   * @param[in] args Optional arguments passed to the constructor of the
+   *   underlying object.
    *
    * @pre minlevel <= maxlevel
    */
+  template <class... Args>
   MGLevelObject(const unsigned int minlevel = 0,
-                const unsigned int maxlevel = 0);
+                const unsigned int maxlevel = 0,
+                Args &&... args);
 
   /**
    * Access object on level @p level.
@@ -92,11 +96,16 @@ public:
    *   for level objects.
    * @param[in] new_maxlevel The highest level for which to provision memory
    *   for level objects.
+   * @param[in] args Optional arguments passed to the constructor of the
+   *   underlying object.
    *
    * @pre minlevel <= maxlevel
    */
+  template <class... Args>
   void
-  resize(const unsigned int new_minlevel, const unsigned int new_maxlevel);
+  resize(const unsigned int new_minlevel,
+         const unsigned int new_maxlevel,
+         Args &&... args);
 
   /**
    * Call <tt>operator = (s)</tt> on all objects stored by this object.
@@ -167,11 +176,13 @@ private:
 
 
 template <class Object>
+template <class... Args>
 MGLevelObject<Object>::MGLevelObject(const unsigned int min,
-                                     const unsigned int max)
+                                     const unsigned int max,
+                                     Args &&... args)
   : minlevel(0)
 {
-  resize(min, max);
+  resize(min, max, std::forward<Args>(args)...);
 }
 
 
@@ -194,9 +205,11 @@ const Object &MGLevelObject<Object>::operator[](const unsigned int i) const
 
 
 template <class Object>
+template <class... Args>
 void
 MGLevelObject<Object>::resize(const unsigned int new_minlevel,
-                              const unsigned int new_maxlevel)
+                              const unsigned int new_maxlevel,
+                              Args &&... args)
 {
   Assert(new_minlevel <= new_maxlevel, ExcInternalError());
   // note that on clear(), the
@@ -207,7 +220,7 @@ MGLevelObject<Object>::resize(const unsigned int new_minlevel,
 
   minlevel = new_minlevel;
   for (unsigned int i = 0; i < new_maxlevel - new_minlevel + 1; ++i)
-    objects.push_back(std::make_shared<Object>());
+    objects.push_back(std::make_shared<Object>(std::forward<Args>(args)...));
 }
 
 
diff --git a/tests/multigrid/mg_level_object_args_01.cc b/tests/multigrid/mg_level_object_args_01.cc
new file mode 100644 (file)
index 0000000..01b15b6
--- /dev/null
@@ -0,0 +1,41 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2019 - 2020 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 optional arguments of MGLevelObject.
+
+#include <deal.II/base/mg_level_object.h>
+
+#include <deal.II/dofs/dof_handler.h>
+
+#include <deal.II/grid/tria.h>
+
+#include "../tests.h"
+
+using namespace dealii;
+
+int
+main()
+{
+  initlog();
+
+  Triangulation<2> tria;
+
+  MGLevelObject<DoFHandler<2>> dof_handlers(0, 3, tria, true);
+
+  dof_handlers.resize(0, 5, tria, true);
+
+  deallog << "OK!" << std::endl;
+}
diff --git a/tests/multigrid/mg_level_object_args_01.output b/tests/multigrid/mg_level_object_args_01.output
new file mode 100644 (file)
index 0000000..5cfb783
--- /dev/null
@@ -0,0 +1,2 @@
+
+DEAL::OK!

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.