Skip to content

BUG: One wrong coordinate when building an extruded mesh with variable layers and in parallel #4571

@enricofacca

Description

@enricofacca

Describe the bug
I am trying to create an extruded mesh from a 2d-mesh using the variable layer options with multiple processors.

The 2d-mesh is built using the plex_from_cell_list() functions (I loaded only topol and coord array used, but I can provide the whole alogorithm). The 2d mesh seems fine, for both in parallel and serial.

However, in parallel, the extruded 3d mesh has origin (0,0,0) among the coordinates, that it not supposed to be there. Also the pvd files shown this error.

I noticed that the node numbering in the vtu file is different from the one uses in the topol and coords array, even if I pass the reorder=False flag.

Steps to Reproduce
Unzip the data.zip file (the error occurs only withe certain data) and run:
mpiexec -n 2 mwe_extruded_masj.py
where the MWE is:

data.zip

from firedrake import *
import numpy as np

# load topology, and coordinates from text file
cells = np.loadtxt("topol.txt", dtype=int)
coords = np.loadtxt("xy_coords.txt", dtype=np.float64)

# load partition from text file
size_partitions = np.loadtxt("size_partitions.txt", dtype=np.int32)
flat_partions = np.loadtxt("flat_partitions.txt", dtype=np.int32)

comm = COMM_WORLD
if comm.size == 1 :
    distribution_parameters = None
    variable_layers = np.loadtxt("variable_layers.txt")
elif comm.size == 2:
    if comm.rank == 0:
        partitions = (size_partitions, flat_partions)#, list(range(ncells)))
    else:
        partitions = (None, None)  
    distribution_parameters = {
        "partition": partitions,
        "overlap_type": (DistributedMeshOverlapType.VERTEX, 1)
        #"overlap_type": (DistributedMeshOverlapType.NONE, 0)
        }

    # load variable from text file
    file = f"variable_layers_{comm.rank}.txt"
    variable_layers = np.loadtxt(file)
else:
    raise ValueError("This test is designed to run with 1 (works fine) or 2 (bug appears) MPI processes")





# create mesh
plex = mesh.plex_from_cell_list(
        2, cells, coords, comm, mesh._generate_default_mesh_topology_name(mesh.DEFAULT_MESH_NAME)
    )

mesh2d = mesh.Mesh(
    plex,
    reorder=False,
    distribution_parameters=distribution_parameters,
    name=mesh.DEFAULT_MESH_NAME,
    distribution_name=None,
    permutation_name=None,
    comm=comm,
)
VTKFile("mesh2d.pvd").write(mesh2d)

# extrude mesh
mesh3d = ExtrudedMesh(mesh2d, layers=variable_layers, layer_height=1.0)
VTKFile("mesh3d.pvd").write(mesh3d)


for rank in range(comm.size):
    comm.Barrier()
    if rank == comm.rank:
        print("coord check zero", rank)
        #print(selected_mesh3d.coordinates.dat.data)
        for i,c in enumerate(mesh2d.coordinates.dat.data):
            if np.linalg.norm(c) < 1e-10:
                print(c," index ", i)
        
        print("coord check zero", rank)
        #print(selected_mesh3d.coordinates.dat.data)
        for i,c in enumerate(mesh3d.coordinates.dat.data):
            if np.linalg.norm(c) < 1e-10:
                print(c," index ", i)

Expected behavior
There should be no point with coordinates (0,0,0)

Error message
Add error message with full backtrace, or log.
Please add these as text using three backticks (`) for highlighting.
Please do not add screenshots unless the bug is purely graphical.

Environment:
`

  • OS: Ubuntu 24.2
  • Python version: [eg: 3.12]
  • Output of pip list
    Package Version Editable project location

cachetools 5.5.2
certifi 2025.1.31
cgen 2020.1
charset-normalizer 3.4.1
checkpoint_schedules 1.0.4
codepy 2023.1
colorama 0.4.6
connected-components-3d 3.23.0
constantdict 2025.1.1
contourpy 1.3.1
cycler 0.12.1
decorator 4.4.2
edt 3.0.0
fenics-fiat 2024.0.0
fenics-ufl 2024.3.0.dev0
firedrake 0.14.dev0
fonttools 4.56.0
genpy 2022.1
h5py 3.13.0
idna 3.10
imageio 2.37.0
immutabledict 4.2.1
iniconfig 2.0.0
islpy 2025.1.2
kiwisolver 1.4.8
lazy_loader 0.4
libsupermesh 2025.3.0
localthickness 0.1.3
loopy 2024.1
Mako 1.3.9
MarkupSafe 3.0.2
matplotlib 3.10.1
memory-profiler 0.61.0
mpi-pytest 2025.2.0
mpi4py 4.0.3
mpmath 1.3.0
networkx 3.5
nibabel 5.3.2
niot 0.1 /home/ubuntu/niot
numpy 2.2.3
packaging 24.2
petsc4py 3.22.3
pillow 11.1.0
pip 24.0
pkgconfig 1.5.5
platformdirs 4.3.6
pluggy 1.5.0
progress 1.6
psutil 7.0.0
pyadjoint-ad 2023.0.0
pycparser 2.22
pyevtk 1.6.0
pymbolic 2024.2.2
pymetis 2025.2.1
pyparsing 3.2.1
pytest 8.3.5
python-dateutil 2.9.0.post0
pytools 2025.1.1
recursivenodes 0.2.0
requests 2.32.3
rtree 1.4.0
scikit-image 0.25.2
scipy 1.15.2
siphash24 1.7
six 1.17.0
symengine 0.14.0
sympy 1.13.3
tifffile 2025.6.11
typing_extensions 4.12.2
urllib3 2.3.0
vtk 9.5.2
`

  • Any relevant environment variables or modifications [eg: PYOP2_DEBUG=1]

Additional Info
What I am trying to create is a 3d mesh starting from a 3d-numpy mask.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions