From a8e36389420623c94bae2a8a7bd2ccc697b0769d Mon Sep 17 00:00:00 2001 From: Luca Heltai Date: Wed, 8 Jul 2020 16:46:37 +0200 Subject: [PATCH] Fixed mesh_loop in one dimension. --- doc/news/changes/minor/20200708LucaHeltai | 3 + include/deal.II/meshworker/mesh_loop.h | 36 +++++++ tests/meshworker/mesh_loop_08.cc | 109 ++++++++++++++++++++++ tests/meshworker/mesh_loop_08.output | 13 +++ 4 files changed, 161 insertions(+) create mode 100644 doc/news/changes/minor/20200708LucaHeltai create mode 100644 tests/meshworker/mesh_loop_08.cc create mode 100644 tests/meshworker/mesh_loop_08.output diff --git a/doc/news/changes/minor/20200708LucaHeltai b/doc/news/changes/minor/20200708LucaHeltai new file mode 100644 index 0000000000..b2e72391b9 --- /dev/null +++ b/doc/news/changes/minor/20200708LucaHeltai @@ -0,0 +1,3 @@ +Fixed: MeshWorker::mesh_loop() did not work on 1d with refined grids. This is now fixed. +
+(Luca Heltai, 2020/07/08) diff --git a/include/deal.II/meshworker/mesh_loop.h b/include/deal.II/meshworker/mesh_loop.h index 79445a8ef9..2c2267de1c 100644 --- a/include/deal.II/meshworker/mesh_loop.h +++ b/include/deal.II/meshworker/mesh_loop.h @@ -435,6 +435,42 @@ namespace MeshWorker copy); } } + else if (CellIteratorType::AccessorType::dimension == 1 && + cell->level() > neighbor->level()) + { + // In one dimension, there is no other check to do + const unsigned int neighbor_face_no = + periodic_neighbor ? + cell->periodic_neighbor_face_no(face_no) : + cell->neighbor_face_no(face_no); + Assert(periodic_neighbor || + neighbor->face(neighbor_face_no) == + cell->face(face_no), + ExcInternalError()); + + face_worker(cell, + face_no, + numbers::invalid_unsigned_int, + neighbor, + neighbor_face_no, + numbers::invalid_unsigned_int, + scratch, + copy); + + if (flags & assemble_own_interior_faces_both) + { + // If own faces are to be assembled from both sides, + // call the faceworker again with swapped arguments. + face_worker(neighbor, + neighbor_face_no, + numbers::invalid_unsigned_int, + cell, + face_no, + numbers::invalid_unsigned_int, + scratch, + copy); + } + } else { // If iterator is active and neighbor is refined, skip diff --git a/tests/meshworker/mesh_loop_08.cc b/tests/meshworker/mesh_loop_08.cc new file mode 100644 index 0000000000..035ea561ec --- /dev/null +++ b/tests/meshworker/mesh_loop_08.cc @@ -0,0 +1,109 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2007 - 2018 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 mesh_loop on 1d meshes with local refinement + +#include + +#include +#include +#include + +#include +#include + +#include + +#include "../tests.h" + +struct ScratchData +{}; +struct CopyData +{}; + +using namespace MeshWorker; + +template +void +test() +{ + Triangulation tria; + GridGenerator::hyper_cube(tria); + tria.refine_global(1); + tria.begin_active()->set_refine_flag(); + tria.execute_coarsening_and_refinement(); + + ScratchData scratch; + CopyData copy; + + auto cell = tria.begin_active(); + auto endc = tria.end(); + + typedef decltype(cell) Iterator; + + + + auto cell_worker = [](const Iterator &cell, ScratchData &s, CopyData &c) { + deallog << "Cell worker on : " << cell << std::endl; + }; + + auto boundary_worker = + [](const Iterator &cell, const unsigned int &f, ScratchData &, CopyData &) { + deallog << "Boundary worker on : " << cell << ", Face : " << f + << std::endl; + }; + + auto face_worker = [](const Iterator & cell, + const unsigned int &f, + const unsigned int &sf, + const Iterator & ncell, + const unsigned int &nf, + const unsigned int &nsf, + ScratchData & s, + CopyData & c) { + deallog << "Face worker on : " << cell << ", Neighbor cell : " << ncell + << ", Face : " << f << ", Neighbor Face : " << nf + << ", Subface: " << sf << ", Neighbor Subface: " << nsf + << std::endl; + }; + + auto copier = [](const CopyData &) { deallog << "copier" << std::endl; }; + + deallog << "ONE DIMENSION" << std::endl << std::endl; + + mesh_loop(cell, + endc, + cell_worker, + copier, + scratch, + copy, + MeshWorker::assemble_own_cells | + MeshWorker::assemble_own_interior_faces_once | + MeshWorker::assemble_boundary_faces, + boundary_worker, + face_worker); +} + + +int +main() +{ + initlog(); + MultithreadInfo::set_thread_limit(1); // to make output deterministic + + test<1, 1>(); +} diff --git a/tests/meshworker/mesh_loop_08.output b/tests/meshworker/mesh_loop_08.output new file mode 100644 index 0000000000..6ef1634131 --- /dev/null +++ b/tests/meshworker/mesh_loop_08.output @@ -0,0 +1,13 @@ + +DEAL::ONE DIMENSION +DEAL:: +DEAL::Cell worker on : 1.1 +DEAL::Boundary worker on : 1.1, Face : 1 +DEAL::copier +DEAL::Cell worker on : 2.0 +DEAL::Boundary worker on : 2.0, Face : 0 +DEAL::Face worker on : 2.0, Neighbor cell : 2.1, Face : 1, Neighbor Face : 0, Subface: 4294967295, Neighbor Subface: 4294967295 +DEAL::copier +DEAL::Cell worker on : 2.1 +DEAL::Face worker on : 2.1, Neighbor cell : 1.1, Face : 1, Neighbor Face : 0, Subface: 4294967295, Neighbor Subface: 4294967295 +DEAL::copier -- 2.39.5