From: Peter Munch Date: Wed, 25 Aug 2021 17:42:46 +0000 (+0200) Subject: Introduce CellAccessor::is_artificial_on_level() X-Git-Tag: v9.4.0-rc1~1030^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F12709%2Fhead;p=dealii.git Introduce CellAccessor::is_artificial_on_level() --- diff --git a/include/deal.II/grid/tria_accessor.h b/include/deal.II/grid/tria_accessor.h index c1e11bb7ac..2dbd027010 100644 --- a/include/deal.II/grid/tria_accessor.h +++ b/include/deal.II/grid/tria_accessor.h @@ -3750,6 +3750,15 @@ public: bool is_artificial() const; + /** + * Similar to is_artificial() but checking the conditions on the levels. + * + * @post The returned value is equal to !is_ghost_on_level() && + * !is_locally_owned_on_level(). + */ + bool + is_artificial_on_level() const; + /** * Test whether the point @p p is inside this cell. Points on the boundary * are counted as being inside the cell. diff --git a/include/deal.II/grid/tria_accessor.templates.h b/include/deal.II/grid/tria_accessor.templates.h index 6558059da9..b656d517c5 100644 --- a/include/deal.II/grid/tria_accessor.templates.h +++ b/include/deal.II/grid/tria_accessor.templates.h @@ -3783,6 +3783,19 @@ CellAccessor::is_artificial() const +template +inline bool +CellAccessor::is_artificial_on_level() const +{ +#ifndef DEAL_II_WITH_MPI + return false; +#else + return (is_locally_owned_on_level() || is_ghost_on_level()) == false; +#endif +} + + + template inline types::subdomain_id CellAccessor::subdomain_id() const diff --git a/tests/grid/is_artificial_on_level.cc b/tests/grid/is_artificial_on_level.cc new file mode 100644 index 0000000000..a28d0d686e --- /dev/null +++ b/tests/grid/is_artificial_on_level.cc @@ -0,0 +1,77 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2021 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 CellAccessor::is_artificial_on_level() on a subdivided hypercube. + +#include + +#include + +#include + +#include "../tests.h" + +using namespace dealii; + +int +main(int argc, char *argv[]) +{ + Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1); + MPILogInitAll all; + + + parallel::distributed::Triangulation<2> tria( + MPI_COMM_WORLD, + dealii::Triangulation<2>::none, + parallel::distributed::Triangulation<2>::construct_multigrid_hierarchy); + GridGenerator::subdivided_hyper_cube(tria, 4); + + AssertDimension(Utilities::MPI::n_mpi_processes(MPI_COMM_WORLD), 2); + + const auto rank = Utilities::MPI::this_mpi_process(MPI_COMM_WORLD); + + for (const auto &cell : tria.active_cell_iterators()) + { + if (rank == 0) + { + if (cell->center()[1] > 0.75) + { + Assert(cell->is_artificial_on_level(), ExcInternalError()); + } + else + { + Assert(!cell->is_artificial_on_level(), ExcInternalError()); + } + } + else if (rank == 1) + { + if (cell->center()[1] < 0.25) + { + Assert(cell->is_artificial_on_level(), ExcInternalError()); + } + else + { + Assert(!cell->is_artificial_on_level(), ExcInternalError()); + } + } + else + { + Assert(false, ExcInternalError()); + } + } + + deallog << "OK!" << std::endl; +} diff --git a/tests/grid/is_artificial_on_level.with_p4est=true.mpirun=2.output b/tests/grid/is_artificial_on_level.with_p4est=true.mpirun=2.output new file mode 100644 index 0000000000..c5e23046f1 --- /dev/null +++ b/tests/grid/is_artificial_on_level.with_p4est=true.mpirun=2.output @@ -0,0 +1,5 @@ + +DEAL:0::OK! + +DEAL:1::OK! +