Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid cell connection generated between child cells #15685

Closed
bangerth opened this issue Jul 8, 2023 · 5 comments · Fixed by #15687
Closed

Invalid cell connection generated between child cells #15685

bangerth opened this issue Jul 8, 2023 · 5 comments · Fixed by #15687
Labels
Milestone

Comments

@bangerth
Copy link
Member

bangerth commented Jul 8, 2023

This little code, extracted from something @cedrict and @danieldouglas92 are working on, is clearly not doing things:

#include <deal.II/grid/tria.h>
#include <deal.II/grid/grid_generator.h>
#include <deal.II/grid/grid_out.h>
#include <fstream>

using namespace dealii;

int main()
{
  Triangulation<2> coarse_grid;
      
  std::vector<Point<2>> vertices = {
        {+0, 1}, {+0, 0}, {1, 0}, {2, 0}, //
        {1, 1}, {2, 1}}; //

  const std::vector<std::array<int, 4>>
    cell_vertices = {
        {{0, 1, 4, 2}},
        {{2, 3, 4, 5}},
  };

  const unsigned int n_cells = cell_vertices.size();

  std::vector<CellData<2>> cells(n_cells);
  for (unsigned int i = 0; i < n_cells; ++i)
    {
      for (unsigned int j = 0; j < cell_vertices[i].size(); ++j)
        cells[i].vertices[j] = cell_vertices[i][j];
      cells[i].material_id = 0;
    }
  coarse_grid.create_triangulation(vertices, cells, {});

  coarse_grid.refine_global(2);

  GridOut go;
  std::ofstream o("coarse_mesh.gnuplot");
  go.write_gnuplot (coarse_grid, o);  
}

It yields the following mesh:
image

If I reverse the order of the two cells in the cell_vertices array, I get the following:
image

What I imagine happens is that during the first global refinement, we do not correctly connect the child cells to their proper neighbors. During the second refinement, we then end up creating homunculus children. If this hypothesis is correct, it's fascinating that we've never run into this in 20+ years of allowing these kinds of meshes.

@bangerth bangerth added the Bug label Jul 8, 2023
@bangerth bangerth added this to the Release 9.6 milestone Jul 8, 2023
@bangerth
Copy link
Member Author

bangerth commented Jul 8, 2023

It turns out that all that is missing is a call to GridTools::consistently_order_cells(). I'm going to see whether I can write a few assertions that lets us catch these sorts of things.

@bangerth
Copy link
Member Author

bangerth commented Jul 8, 2023

Separately, the code was originally copied from step-14, which did not call GridTools::consistently_order_cells(). I'll write a patch to fix this.

@tamiko
Copy link
Member

tamiko commented Jul 8, 2023

@bangerth How much would it hurt to simply call GridTools::consistently_order_cells() whenever we are about to create a mesh?

@bangerth
Copy link
Member Author

bangerth commented Jul 8, 2023

It would lead to different vertex numbers :-( I plan on doing this anyway for #15044 but I think I can generate a decent error message already now.

@tamiko
Copy link
Member

tamiko commented Jul 8, 2023

@bangerth Fair point. Let's add the quality of life feature (automatic reordering for consistency) when we do the reordering anyway :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants