]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add MGLevelObject::clear() 15792/head
authorPeter Munch <peterrmuench@gmail.com>
Tue, 25 Jul 2023 21:02:00 +0000 (23:02 +0200)
committerPeter Munch <peterrmuench@gmail.com>
Tue, 25 Jul 2023 21:02:00 +0000 (23:02 +0200)
include/deal.II/base/mg_level_object.h
tests/multigrid/mg_level_obj_02.cc [new file with mode: 0644]
tests/multigrid/mg_level_obj_02.output [new file with mode: 0644]

index 20211a730123209360f86f3eea74db58d63262d6..3aec38ea9239dc1ce53c62d586d34939329fbebc 100644 (file)
@@ -131,6 +131,13 @@ public:
   MGLevelObject<Object> &
   operator=(const double d);
 
+  /**
+   * Clear all data fields and brings the class into a condition similar
+   * to after having called the default constructor.
+   */
+  void
+  clear();
+
   /**
    * Call @p clear on all objects stored by this object. This function
    * is only implemented for some @p Object classes, e.g., matrix
@@ -275,6 +282,15 @@ MGLevelObject<Object>::operator=(const double d)
 }
 
 
+template <class Object>
+void
+MGLevelObject<Object>::clear()
+{
+  minlevel = 0;
+  objects.clear();
+}
+
+
 template <class Object>
 void
 MGLevelObject<Object>::clear_elements()
diff --git a/tests/multigrid/mg_level_obj_02.cc b/tests/multigrid/mg_level_obj_02.cc
new file mode 100644 (file)
index 0000000..cecb305
--- /dev/null
@@ -0,0 +1,42 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2023 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.
+//
+// ---------------------------------------------------------------------
+
+
+// check MGLevelObject::clear()
+
+#include <deal.II/base/mg_level_object.h>
+
+#include <algorithm>
+
+#include "../tests.h"
+
+int
+main()
+{
+  initlog();
+
+  MGLevelObject<double> o(2, 4);
+
+  AssertDimension(o.min_level(), 2);
+  AssertDimension(o.max_level(), 4);
+  AssertDimension(o.n_levels(), 3);
+
+  o.clear();
+
+  AssertDimension(o.min_level(), 0);
+  AssertDimension(o.n_levels(), 0);
+
+  deallog << "OK!" << std::endl;
+}
diff --git a/tests/multigrid/mg_level_obj_02.output b/tests/multigrid/mg_level_obj_02.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.