]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Fix using mesh_loop with DG and periodic boundary conditions 14810/head
authorDaniel Arndt <arndtd@ornl.gov>
Fri, 17 Feb 2023 15:15:19 +0000 (10:15 -0500)
committerDaniel Arndt <arndtd@ornl.gov>
Fri, 17 Feb 2023 16:17:43 +0000 (11:17 -0500)
include/deal.II/meshworker/mesh_loop.h
tests/meshworker/mesh_loop_pbc_01.cc [new file with mode: 0644]
tests/meshworker/mesh_loop_pbc_01.output [new file with mode: 0644]

index f46c737c2a2e613372965ad990b23200be71f48c..699264551e52ae21ca0714e4784c1698affa4bda 100644 (file)
@@ -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 (file)
index 0000000..1fb3997
--- /dev/null
@@ -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 <deal.II/fe/fe_dgq.h>
+
+#include <deal.II/grid/grid_generator.h>
+#include <deal.II/grid/grid_tools.h>
+
+#include <deal.II/meshworker/mesh_loop.h>
+
+#include "../tests.h"
+
+template <int dim>
+struct ScratchData
+{};
+
+struct CopyData
+{};
+
+template <int dim>
+void
+test()
+{
+  Triangulation<dim> triangulation;
+
+  const FE_DGQ<dim> fe(1);
+  DoFHandler<dim>   dof_handler(triangulation);
+
+  GridGenerator::hyper_cube(triangulation, 0., 1., true);
+  std::vector<
+    GridTools::PeriodicFacePair<typename Triangulation<dim>::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<dim>::active_cell_iterator;
+
+  const auto cell_worker = [&](const Iterator & /*cell*/,
+                               ScratchData<dim> & /*scratch_data*/,
+                               CopyData & /*copy_data*/) {};
+
+  const auto boundary_worker = [&](const Iterator & /*cell*/,
+                                   const unsigned int & /*face_no*/,
+                                   ScratchData<dim> & /*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<dim> & /*scratch_data*/,
+                               CopyData & /*copy_data*/) {};
+
+  const auto copier = [&](const CopyData & /*c*/) {};
+
+  ScratchData<dim> 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 (file)
index 0000000..8b13789
--- /dev/null
@@ -0,0 +1 @@
+

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.