Skip to content

Commit

Permalink
Merge pull request #15792 from peterrum/mg_level_object_clear
Browse files Browse the repository at this point in the history
Add MGLevelObject::clear()
  • Loading branch information
bangerth committed Jul 26, 2023
2 parents 736540c + 5f7b76b commit 93dd980
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
16 changes: 16 additions & 0 deletions include/deal.II/base/mg_level_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,13 @@ class MGLevelObject : public Subscriptor
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
Expand Down Expand Up @@ -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()
Expand Down
42 changes: 42 additions & 0 deletions tests/multigrid/mg_level_obj_02.cc
Original file line number Diff line number Diff line change
@@ -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;
}
2 changes: 2 additions & 0 deletions tests/multigrid/mg_level_obj_02.output
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

DEAL::OK!

0 comments on commit 93dd980

Please sign in to comment.