From 8df2f86cb20a27c68cf142ca50037528994e5278 Mon Sep 17 00:00:00 2001 From: Peter Munch Date: Thu, 24 Sep 2020 16:19:58 +0200 Subject: [PATCH] Pass optional arguments to MGLevelObject --- include/deal.II/base/mg_level_object.h | 25 ++++++++--- tests/multigrid/mg_level_object_args_01.cc | 41 +++++++++++++++++++ .../multigrid/mg_level_object_args_01.output | 2 + 3 files changed, 62 insertions(+), 6 deletions(-) create mode 100644 tests/multigrid/mg_level_object_args_01.cc create mode 100644 tests/multigrid/mg_level_object_args_01.output diff --git a/include/deal.II/base/mg_level_object.h b/include/deal.II/base/mg_level_object.h index cc3e8fbce6..2b57ea888a 100644 --- a/include/deal.II/base/mg_level_object.h +++ b/include/deal.II/base/mg_level_object.h @@ -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 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 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 operator = (s) on all objects stored by this object. @@ -167,11 +176,13 @@ private: template +template MGLevelObject::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)...); } @@ -194,9 +205,11 @@ const Object &MGLevelObject::operator[](const unsigned int i) const template +template void MGLevelObject::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::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()); + objects.push_back(std::make_shared(std::forward(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 index 0000000000..01b15b6ae8 --- /dev/null +++ b/tests/multigrid/mg_level_object_args_01.cc @@ -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 + +#include + +#include + +#include "../tests.h" + +using namespace dealii; + +int +main() +{ + initlog(); + + Triangulation<2> tria; + + MGLevelObject> 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 index 0000000000..5cfb783b8f --- /dev/null +++ b/tests/multigrid/mg_level_object_args_01.output @@ -0,0 +1,2 @@ + +DEAL::OK! -- 2.39.5