jorgensd / dolfinx-tutorial

A reimplementation of the Springer book: https://github.com/hplgit/fenics-tutorial/, covering new topics as well as transitioning from dolfin to dolfinx
https://jorgensd.github.io/dolfinx-tutorial/
103 stars 60 forks source link

Working With GMSH #121

Closed slavakung closed 1 year ago

slavakung commented 1 year ago

I am not sure what is causing this error:

from mpi4py import MPI from dolfinx import mesh from dolfinx import fem from dolfinx.io import XDMFFile, gmshio

from dolfinx.fem import FunctionSpace import numpy as np import ufl import gmsh from petsc4py.PETSc import ScalarType

gmsh.initialize()

gmsh.model.add("L3D")

boxout = gmsh.model.occ.addBox(0, 0, 0, 1, 1, 1, 1) boxin = gmsh.model.occ.addBox(0, 0, 0, 0.5, 0.5, 0.5, 2) Lshape = gmsh.model.occ.cut([(3, 1)], [(3, 2)], 3)

gmsh.model.occ.synchronize() model = gmsh.model()

model.add_physical_group(dim=3, tags=[Lshape])

gmsh.model.mesh.generate(dim=3)

msh, cell_markers, facet_markers = gmshio.model_to_mesh(model, MPI.COMM_SELF, 0)

Traceback (most recent call last): File "", line 1, in File "/home/slava2/anaconda3/envs/fenicsx-env/lib/python3.10/site-packages/dolfinx/io/gmshio.py", line 205, in model_to_mesh cell_id = cell_information[perm_sort[-1]]["id"] IndexError: index -1 is out of bounds for axis 0 with size 0

jorgensd commented 1 year ago
from mpi4py import MPI
from dolfinx import mesh
from dolfinx import fem
from dolfinx.io import XDMFFile, gmshio
from IPython import embed
from dolfinx.fem import FunctionSpace
import numpy as np
import ufl
import gmsh
from petsc4py.PETSc import ScalarType

gmsh.initialize()

gmsh.model.add("L3D")

boxout = gmsh.model.occ.addBox(0, 0, 0, 1, 1, 1, 1)
boxin = gmsh.model.occ.addBox(0, 0, 0, 0.5, 0.5, 0.5, 2)
Lshape_tags, _ = gmsh.model.occ.cut([(3, 1)], [(3, 2)], 3)
tags = [tag[1] for tag in Lshape_tags]
gmsh.model.occ.synchronize()
model = gmsh.model()
model.add_physical_group(dim=3, tags=tags)

gmsh.model.mesh.generate(dim=3)

msh, cell_markers, facet_markers = gmshio.model_to_mesh(
    model, MPI.COMM_SELF, 0)