Remove boundary cells from mesh

I am using libmesh to simulate a PDE on a planar mesh. My code adds a layer of additional cells around the original mesh to impose boundary conditions.

For visualization of the PDE solution, is there a way in paraview to remove the boundary cells?

To be more specific, I attached an example square mesh, where I would like to keep the highlighted bulk cells and remove the gray boundary cells.

mesh file: mesh.vtu (186.8 KB)

Even though they are not intended for that, ghost cells should do the trick in your case.

You can label your cells as ghost : https://vtk.org/doc/nightly/html/classvtkDataSet.html#a1872a27b12dc8a3177e5ae0a6a6a7d8c

I agree with @mwestphal that the best solution for this problem is to have your code identify which cells are part of the additional boundary cells and which are supposed to be the original mesh.

To elaborate a bit, this idea of having 1 or more layers of boundary cells is very common in parallel simulations and visualizations so that you can get information about data in cells in neighboring MPI processes without having to do lots of communication. These “boundary” cells are called ghost cells (or sometimes halo cells) because although you represent them as part of your mesh, they are not actually part of your mesh. When rendering the visualization, you want these ghost cells to be removed, which is the same situation you have.

Ghost cells are identified using a cell field. All cells part of the actual mesh would have a value of 0. All cells part of the boundary layer would have a value of 1. If you are writing out your data into a VTK file format (like .vtu), I think you just need to name this field vtkGhostType and ParaView will pick it up as the ghost cells and automatically remove the boundary cells.

Even if you can’t get ParaView to pick up your cell field as the ghost levels, once you have it you can easily remove the boundary layer using the Threshold filter.

Like I said, I think this is the best solution to your problem. It is a common solution for a great many solvers, and if you can modify your simulation code to write one out, your problem will be solved. If, however, it is not practical for you to make this change in the simulation code, here are some less great solutions.

I note that your data has a field named libmesh_elem_id, which appears to give a unique identifier for each cell. (You can actually create an equivalent cell field with the Generate Ids filter.) I further note that all the cells in the boundary layer have a higher id than those in the actual mesh. For example, in the data you posted I note that the cells of the actual mesh have libmesh_elem_id values from 0 to 2767 and that all the cells on the boundary have values from 2768 to 3097. Thus, you can use the Threshold filter to pull out all cells with libmesh_elem_id between 0 and 2767.

Of course, this will break down if the number of cells in your mesh changes. You would have to adjust the threshold values, so not a great solution.

I also note that the actual cells in your mesh fit in the physical space between -50 and 50 in the X and Y direction. Assuming your mesh is always within this physical range, you can use the Extract Cells By Region filter to pull out only the cells in the physical region. To do this, make sure you Intersect With a Box. Then set the box to be a little outside this boundary.

Once again, this approach will break down if your mesh changes. If your mesh moves out of this physical space, then you will no longer be extracting the exact right cells. So again, not a great solution.

2 Likes

Hi guys - sorry to resurrect an old thread but I am having a similar issue when reading a 3D Rectilinear Mesh with a plugin I am writing for an in-house file format. In these files I have several sub domains within the mesh, each of which have ghosts - some of duplicated ghosts which are needed to ensure that contours match but some are simply external as in this case.

If I label the external ghosts as vtkDataSetAttributes::EXTERIORCELL, they still appear in the final image and must be manually removed via e.g. a Threshold filter, as mentioned above.

If I label them as vtkDataSetAttributes::HIDDENCELL, then they do not appear in the render, but I run into other issues (namely, if I try and use the Clip filter after labelling the cells as hidden, then I do not get a “Clip” - I get a 2d Surface analogous to a slice instead, which makes me suspicious that there are other issues under the hood here).

If I label them as vtkDataSetAttributes::DUPLICATECELL, then nothing is rendered at all in Paraview - I just get a grey screen.

Any advice on how to handle these? I don’t want to just throw away all of the external cells, however I don’t really know what else to do at this point. Is there a way to apply a Threshold Filter from within the plugin so that the ghosts are automatically removed on read/render?