# Declaration of ghost cells for rectilinear grid

**URL:** https://discourse.paraview.org/t/declaration-of-ghost-cells-for-rectilinear-grid/1585
**Category:** In Situ Support
**Created:** [April 2, 2019, 3:22pm UTC](https://discourse.paraview.org/t/declaration-of-ghost-cells-for-rectilinear-grid/1585 "2019-04-02T15:22:11Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![bastian](https://discourse.paraview.org/user_avatar/discourse.paraview.org/bastian/32/7513_2.png) [@bastian](https://discourse.paraview.org/u/bastian)
#### Post date: [April 2, 2019, 3:22pm UTC](https://discourse.paraview.org/t/declaration-of-ghost-cells-for-rectilinear-grid/1585/1 "2019-04-02T15:22:11Z")

</div>

I looked at just about any Catalyst example I could find that demonstrates the handling of ghost cells for (though I couldn’t find any for rectilinear grids), and still I can’t get it to function.

Could anyone help me out here, I just can’t see what I am doing wrong.

I have a Fortran code where `call createcpdata(gis,gie,gjs,gje,gks,gke,nxb,nyb,nzb,xgrid,ygrid,zgrid)` inside [FEFortranAdaptor.F90](https://discourse.paraview.org/uploads/default/original/2X/f/fe721aa47a8d5e684cf454acb4a56d4695e01a4a.F90) (1.8 KB)  
has the grid defined.

`createcpdata` is defined in [FECxx.cxx](https://discourse.paraview.org/uploads/default/original/2X/7/725d0fedf24a974c632b304ec8c4f37c56fabded.cxx) (4.3 KB).  
This function contains a section where ghost cells are marked:

```auto
    // Mark ghost cells
    vtkNew<vtkUnsignedCharArray> ghostCells;
    ghostCells->SetNumberOfTuples(grid->GetNumberOfCells());
    ghostCells->SetName(vtkDataSetAttributes::GhostArrayName());
    ghostCells->Fill(0);
    grid->GetCellData()->AddArray(ghostCells);
    
    vtkIdType cellId = 0;
    for (int k = *ks; k < *ke+1; k++)
    {
      bool zGhosts = ((k == *ks) || (k == *ke)) && (k > 0) && (k < *nz-1);
      for (int j = *js; j < *je+1; j++)
      {
        bool yGhosts = ((j == *js) || (j == *je)) && (j > 0) && (j < *ny-1);
        for (int i = *is; i < *ie+1; i++)
        {
          bool xGhosts = ((i == *is) || (i == *ie)) && (i > 0) && (i < *nx-1);
          if (xGhosts || yGhosts || zGhosts)
          {
            cout << "ghost: (" << i << ", " << j << ", " << k << ")\n";
            ghostCells->SetValue(cellId, ghostCells->GetValue(cellId) | vtkDataSetAttributes::DUPLICATECELL); 
          }
          cellId++;
        } 
      }   
    }

```

When **running in serial** , there are no ghost cells and the line `ghostCells->SetValue(...)` is never reached.  
I can do live visualization and have the coprocessor script write `.pvtr`/`.vtr` files which I can load in Paraview without any issue.

When **running in parallel** cells are marked as ghostcells in the above section. I verified that the right cells are marked. (Subdomains overlap by two layers of cells due to one layer of ghost cells.)  
When doing live visualization Paraview crashes due to a _Segmentation fault_.  
I can still have a set of `.pvtr`/`.vtr` files written and load the `.pvtr` file in Paraview. However, when slicing the field data I am confronted with a gap shown in the screenshot on the left. One _x_-normal layer of data is not displayed.  
When loading the two `.vtr` files individually, this gap is not present (right).

 ![Screenshot%20from%202019-04-02%2017-08-34](https://discourse.paraview.org/uploads/default/original/2X/a/a9c0ca18eb01ae3c27fd9f528d1d8f2766684be6.png) ![Screenshot%20from%202019-04-02%2017-09-13](https://discourse.paraview.org/uploads/default/original/2X/5/50ad7735f2de440eed9816f38a63ae1f9eb2c9e2.png)

**Another mystery** :  
Ghost cells are no longer declared as such in any succeeding time step, i.e. where the `.pvtr` file read

```auto
    <PCellData>
      <PDataArray type="UInt8" Name="vtkGhostType"/>
      <PDataArray type="Float64" Name="pressure"/>
    </PCellData>

```

the very first time it was produced, it then reads

```auto
    <PCellData>
      <PDataArray type="Float64" Name="pressure"/>
    </PCellData>

```

in all the succeeding time steps.

---

<div class="post-metadata">

### Author: ![bastian](https://discourse.paraview.org/user_avatar/discourse.paraview.org/bastian/32/7513_2.png) [@bastian](https://discourse.paraview.org/u/bastian)
#### Post date: [April 26, 2019, 4:21pm UTC](https://discourse.paraview.org/t/declaration-of-ghost-cells-for-rectilinear-grid/1585/3 "2019-04-26T16:21:20Z")

</div>

As I wrote above, I declare ghost cells in the function `createcpdata_`. This information is taken into account the very **first time** that `coprocess()` is called. Accordingly, when loading the `vtr` files that I have my coprocessing script generate into paraview, ghost cells are hidden (left), however and to my surprise the `pvtr` file (right) is not represented correctly:  
 ![Slices of both .vtr files](https://discourse.paraview.org/uploads/default/original/2X/1/1f64970577a76289ee270a05bcb1dd195a526635.png) ![Slice of .pvtr file](https://discourse.paraview.org/uploads/default/original/2X/8/8e0d294d976e04f5b82ab2e49df7c060e49d5d54.png)

When calling the coprocessor In **any later time step** , ghost cells appear to be ignored entirely. This becomes clear when loading the individual `vtr` files (left), but that does not appear to bother paraview when loading the corresponding `pvtr` file (right):  
 ![Slices of both .vtr files](https://discourse.paraview.org/uploads/default/original/2X/8/848748e8135abd27e0d55d9d7bb525286e247ef4.png) ![Slices of both .vtr files](https://discourse.paraview.org/uploads/default/original/2X/1/1caeb31e80aa373e3d5f2788e658366c1bfb0b55.png)

When doing **live visualization** I generally have the second situation past the first time step and here the Paraview GUI always crashes, stating that subdomains cannot be merged.

If it _is_ possible to have rectilinear grids with ghost cells in Catalyst please let me know.

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [April 29, 2019, 9:51am UTC](https://discourse.paraview.org/t/declaration-of-ghost-cells-for-rectilinear-grid/1585/4 "2019-04-29T09:51:26Z")

</div>

Have you tried reproducing this issue without catalyst in a parallel paraview ?

---

<div class="post-metadata">

### Author: ![bastian](https://discourse.paraview.org/user_avatar/discourse.paraview.org/bastian/32/7513_2.png) [@bastian](https://discourse.paraview.org/u/bastian)
#### Post date: [April 29, 2019, 11:44am UTC](https://discourse.paraview.org/t/declaration-of-ghost-cells-for-rectilinear-grid/1585/5 "2019-04-29T11:44:42Z")

</div>

When running a pvserver on two cores and connecting my local paraview-GUI, I get the same output as in my post above.

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [April 29, 2019, 1:04pm UTC](https://discourse.paraview.org/t/declaration-of-ghost-cells-for-rectilinear-grid/1585/6 "2019-04-29T13:04:10Z")

</div>

Could you share a statefile and associated dataset to reproduce ?

---

<div class="post-metadata">

### Author: ![bastian](https://discourse.paraview.org/user_avatar/discourse.paraview.org/bastian/32/7513_2.png) [@bastian](https://discourse.paraview.org/u/bastian)
#### Post date: [April 29, 2019, 2:58pm UTC](https://discourse.paraview.org/t/declaration-of-ghost-cells-for-rectilinear-grid/1585/7 "2019-04-29T14:58:50Z")

</div>

Here is an archive containing a Paraview 5.5.2 state file and `(p)vtr` files produced in the first and second time step. The state file produces the representation included in my posts above.

[demo\_catalyst\_output.zip](https://discourse.paraview.org/uploads/default/original/2X/5/58c074c819f74441903e60c0fe6f06637ca15169.zip) (21.5 KB)

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [May 15, 2019, 3:12pm UTC](https://discourse.paraview.org/t/declaration-of-ghost-cells-for-rectilinear-grid/1585/8 "2019-05-15T15:12:02Z")

</div>

Hi Bastian.

Sorry it took me so long to look into this.  
This is caused by a [bug](https://gitlab.kitware.com/vtk/vtk/issues/17601) in the vtkXMLRectilinearGridReader.

The reader actually repartition your data and do not keep the data the way it was partitioned. However it keep the vtkGhostType array the way it was, resulting in the issue.

This bug should be fixed, but, you actually do not need to provide the ghost cells, as they are computed on the fly when ParaView need them !

So my advice would be to just not generate GhostCells at all !

---

<div class="post-metadata">

### Author: ![bastian](https://discourse.paraview.org/user_avatar/discourse.paraview.org/bastian/32/7513_2.png) [@bastian](https://discourse.paraview.org/u/bastian)
#### Post date: [June 21, 2019, 4:23pm UTC](https://discourse.paraview.org/t/declaration-of-ghost-cells-for-rectilinear-grid/1585/9 "2019-06-21T16:23:36Z")

</div>

Dear Mathieu,

> [@mwestphal](#):
>
> So my advice would be to just not generate GhostCells at all !

Unfortunately this does not work. The Paraview client that is connected to Catalyst then crashes and Catalyst issues the following Warnings/Error messages:

```
Generic Warning: In /dev/shm/easybuild-build/ParaView/5.5.2/intel-2018a-mpi/ParaView-v5.5.2/ParaViewCore/VTKExtensions/Core/vtkMultiProcessControllerHelper.cxx, line 171
vtkRectilinearGrid cannot be merged

ERROR: In /dev/shm/easybuild-build/ParaView/5.5.2/intel-2018a-mpi/ParaView-v5.5.2/VTK/Parallel/Core/vtkSocketCommunicator.cxx, line 808
vtkSocketCommunicator (0x56199a0): Could not receive tag. 1

ERROR: In /dev/shm/easybuild-build/ParaView/5.5.2/intel-2018a-mpi/ParaView-v5.5.2/VTK/Parallel/Core/vtkMultiProcessController.cxx, line 666
vtkSocketController (0x561a570): Could not receive RMI trigger message.

```

At the same time Catalyst does not mind writing `.pvtr` that can indeed be viewed in Paraview and that look fine, but again, Live Visualization is not possible.

---

<div class="post-metadata">

### Author: ![bastian](https://discourse.paraview.org/user_avatar/discourse.paraview.org/bastian/32/7513_2.png) [@bastian](https://discourse.paraview.org/u/bastian)
#### Post date: [June 26, 2019, 5:27pm UTC](https://discourse.paraview.org/t/declaration-of-ghost-cells-for-rectilinear-grid/1585/10 "2019-06-26T17:27:28Z")

</div>

Since there appears to be a bug in the _vtkRectilinearGrid_ that prohibits the use of ghost cells, I would instead just use another grid class then.

The Catalyst examples folder is loaded with `FEAdaptor.cxx` files that use _vtkUnstructuredGrid_ but none that use _vtkStructuredGrid_. **Before going through the trouble of figuring out how to implement coprocessing with _vtkStructuredGrid_ could anyone confirm that this class supports ghost cells?**  
Are there any sample files out there?

I am reluctant to use _vtkUnstructuredGrid_ before ruling out _vtkStructuredGrid_.

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [May 15, 2020, 1:40am UTC](https://discourse.paraview.org/t/declaration-of-ghost-cells-for-rectilinear-grid/1585/11 "2020-05-15T01:40:06Z")

</div>

For reference, here is the issue : [https://gitlab.kitware.com/paraview/paraview/-/issues/18911](https://gitlab.kitware.com/paraview/paraview/-/issues/18911)
