From: Daniel Arndt Date: Fri, 17 Feb 2023 15:15:19 +0000 (-0500) Subject: Fix using mesh_loop with DG and periodic boundary conditions X-Git-Tag: v9.5.0-rc1~541^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F14810%2Fhead;p=dealii.git Fix using mesh_loop with DG and periodic boundary conditions --- diff --git a/include/deal.II/meshworker/mesh_loop.h b/include/deal.II/meshworker/mesh_loop.h index f46c737c2a..699264551e 100644 --- a/include/deal.II/meshworker/mesh_loop.h +++ b/include/deal.II/meshworker/mesh_loop.h @@ -570,7 +570,10 @@ namespace MeshWorker // Now neighbor is on the same refinement level. // Double check. - Assert(!cell->neighbor_is_coarser(face_no), + Assert((!periodic_neighbor && + !cell->neighbor_is_coarser(face_no)) || + (periodic_neighbor && + !cell->periodic_neighbor_is_coarser(face_no)), ExcInternalError()); // If we own both cells only do faces from one side (unless diff --git a/tests/meshworker/mesh_loop_pbc_01.cc b/tests/meshworker/mesh_loop_pbc_01.cc new file mode 100644 index 0000000000..1fb39975e0 --- /dev/null +++ b/tests/meshworker/mesh_loop_pbc_01.cc @@ -0,0 +1,100 @@ +// --------------------------------------------------------------------- +// +// 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. +// +// --------------------------------------------------------------------- + +// test that we can use mesh_loop with DG and periodic boundary conditions + +#include + +#include +#include + +#include + +#include "../tests.h" + +template +struct ScratchData +{}; + +struct CopyData +{}; + +template +void +test() +{ + Triangulation triangulation; + + const FE_DGQ fe(1); + DoFHandler dof_handler(triangulation); + + GridGenerator::hyper_cube(triangulation, 0., 1., true); + std::vector< + GridTools::PeriodicFacePair::cell_iterator>> + periodicity_vector; + GridTools::collect_periodic_faces(triangulation, 0, 1, 0, periodicity_vector); + triangulation.add_periodicity(periodicity_vector); + + triangulation.refine_global(4); + dof_handler.distribute_dofs(fe); + using Iterator = typename DoFHandler::active_cell_iterator; + + const auto cell_worker = [&](const Iterator & /*cell*/, + ScratchData & /*scratch_data*/, + CopyData & /*copy_data*/) {}; + + const auto boundary_worker = [&](const Iterator & /*cell*/, + const unsigned int & /*face_no*/, + ScratchData & /*scratch_data*/, + CopyData & /*copy_data*/) {}; + + const 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 & /*scratch_data*/, + CopyData & /*copy_data*/) {}; + + const auto copier = [&](const CopyData & /*c*/) {}; + + ScratchData scratch_data; + CopyData copy_data; + + MeshWorker::mesh_loop(dof_handler.begin_active(), + dof_handler.end(), + cell_worker, + copier, + scratch_data, + copy_data, + MeshWorker::assemble_own_cells | + MeshWorker::assemble_boundary_faces | + MeshWorker::assemble_own_interior_faces_once, + boundary_worker, + face_worker); +} + + +int +main() +{ + initlog(); + + test<1>(); + test<2>(); + test<3>(); + return 0; +} diff --git a/tests/meshworker/mesh_loop_pbc_01.output b/tests/meshworker/mesh_loop_pbc_01.output new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/tests/meshworker/mesh_loop_pbc_01.output @@ -0,0 +1 @@ +