Skip to content

Commit

Permalink
Update gmshio: FEniCS/dolfinx#3547 (#139)
Browse files Browse the repository at this point in the history
* Update gmshio

* Update mesh extaction

* Update last demo
  • Loading branch information
jorgensd authored Dec 14, 2024
1 parent 66e5dcd commit 9ea0364
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 21 deletions.
19 changes: 12 additions & 7 deletions python/demos/create_and_export_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,10 @@ def generate_tet_boxes(
gmsh.option.setNumber("Mesh.MaxNumThreads3D", MPI.COMM_WORLD.size)
gmsh.model.mesh.generate(3)
gmsh.model.mesh.setOrder(1)
mesh, _, ft = gmshio.model_to_mesh(gmsh.model, MPI.COMM_WORLD, 0)
mesh_data = gmshio.model_to_mesh(gmsh.model, MPI.COMM_WORLD, 0)
gmsh.finalize()
return mesh, ft
assert mesh_data.facet_tags is not None
return mesh_data.mesh, mesh_data.facet_tags


def generate_hex_boxes(
Expand Down Expand Up @@ -266,11 +267,12 @@ def generate_hex_boxes(
gmsh.option.setNumber("Mesh.MaxNumThreads3D", MPI.COMM_WORLD.size)
gmsh.model.mesh.generate(3)
gmsh.model.mesh.setOrder(1)
mesh, _, ft = gmshio.model_to_mesh(gmsh.model, MPI.COMM_WORLD, 0)
MPI.COMM_WORLD.barrier()
mesh_data = gmshio.model_to_mesh(gmsh.model, MPI.COMM_WORLD, 0)
gmsh.clear()
gmsh.finalize()
MPI.COMM_WORLD.barrier()
return mesh, ft
assert mesh_data.facet_tags is not None
return mesh_data.mesh, mesh_data.facet_tags


def gmsh_2D_stacked(celltype: str, theta: float, verbose: bool = False) -> Tuple[_mesh.Mesh, _mesh.MeshTags]:
Expand Down Expand Up @@ -381,15 +383,18 @@ def gmsh_2D_stacked(celltype: str, theta: float, verbose: bool = False) -> Tuple
gmsh.option.setNumber("Mesh.MaxNumThreads3D", MPI.COMM_WORLD.size)
gmsh.model.mesh.generate(2)
gmsh.model.mesh.setOrder(1)
mesh, _, ft = gmshio.model_to_mesh(gmsh.model, MPI.COMM_WORLD, 0, gdim=2)
MPI.COMM_WORLD.Barrier()
mesh_data = gmshio.model_to_mesh(gmsh.model, MPI.COMM_WORLD, 0, gdim=2)
r_matrix = _utils.rotation_matrix([0, 0, 1], theta)

# NOTE: Hex mesh must be rotated after generation due to gmsh API
mesh = mesh_data.mesh
assert mesh_data.facet_tags is not None
mesh.geometry.x[:] = np.dot(r_matrix, mesh.geometry.x.T).T
gmsh.clear()
gmsh.finalize()
MPI.COMM_WORLD.barrier()
return mesh, ft
return mesh, mesh_data.facet_tags


def mesh_2D_dolfin(celltype: str, theta: float = 0, outdir: Union[str, Path] = Path("meshes")):
Expand Down
10 changes: 7 additions & 3 deletions python/demos/demo_elasticity_disconnect.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,16 @@
gmsh.model.mesh.optimize("Netgen")
gmsh.model.mesh.setOrder(2)


mesh, ct, ft = gmshio.model_to_mesh(gmsh.model, MPI.COMM_WORLD, 0, gdim=3)
MPI.COMM_WORLD.barrier()
mesh_data = gmshio.model_to_mesh(gmsh.model, MPI.COMM_WORLD, 0, gdim=3)
mesh = mesh_data.mesh
assert mesh_data.cell_tags is not None
ct = mesh_data.cell_tags
assert mesh_data.facet_tags is not None
ft = mesh_data.facet_tags

gmsh.clear()
gmsh.finalize()
MPI.COMM_WORLD.barrier()

V = functionspace(mesh, ("Lagrange", 1, (mesh.geometry.dim,)))

Expand Down
9 changes: 5 additions & 4 deletions python/demos/demo_elasticity_disconnect_2D.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,14 @@
# gmsh.option.setNumber("General.Terminal", 1)
gmsh.model.mesh.optimize("Netgen")

mesh, ct, _ = gmshio.model_to_mesh(gmsh.model, MPI.COMM_WORLD, 0, gdim=2)
MPI.COMM_WORLD.barrier()
mesh_data = gmshio.model_to_mesh(gmsh.model, MPI.COMM_WORLD, 0, gdim=2)
gmsh.clear()
gmsh.finalize()
MPI.COMM_WORLD.barrier()
mesh = mesh_data.mesh
assert mesh_data.cell_tags is not None
ct = mesh_data.cell_tags

with XDMFFile(mesh.comm, "test.xdmf", "w") as xdmf:
xdmf.write_mesh(mesh)
V = functionspace(mesh, ("Lagrange", 1, (mesh.geometry.dim,)))
tdim = mesh.topology.dim
fdim = tdim - 1
Expand Down
5 changes: 3 additions & 2 deletions python/demos/demo_stokes.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,10 @@ def create_mesh_gmsh(
# Generate mesh
gmsh.model.mesh.generate(2)
# Convert gmsh model to DOLFINx Mesh and meshtags
mesh, _, ft = gmshio.model_to_mesh(gmsh.model, MPI.COMM_WORLD, 0, gdim=2)
mesh_data = gmshio.model_to_mesh(gmsh.model, MPI.COMM_WORLD, 0, gdim=2)
gmsh.finalize()
return mesh, ft
assert mesh_data.facet_tags is not None
return mesh_data.mesh, mesh_data.facet_tags


mesh, mt = create_mesh_gmsh(res=0.1)
Expand Down
6 changes: 4 additions & 2 deletions python/demos/demo_stokes_nest.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,11 @@ def create_mesh_gmsh(
# Generate mesh
gmsh.model.mesh.generate(2)
# Convert gmsh model to DOLFINx Mesh and meshtags
mesh, _, ft = gmshio.model_to_mesh(gmsh.model, MPI.COMM_WORLD, 0, gdim=2)
mesh_data = gmshio.model_to_mesh(gmsh.model, MPI.COMM_WORLD, 0, gdim=2)
assert mesh_data.cell_tags is not None
ft = mesh_data.facet_tags
gmsh.finalize()
return mesh, ft
return mesh_data.mesh, ft


# ------------------- Mesh and function space creation ------------------------
Expand Down
8 changes: 5 additions & 3 deletions python/tests/test_cube_contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,14 @@ def generate_hex_boxes():
gmsh.option.setNumber("Mesh.MaxNumThreads3D", MPI.COMM_WORLD.size)
gmsh.model.mesh.generate(3)
gmsh.model.mesh.setOrder(1)
mesh, _, ft = gmshio.model_to_mesh(gmsh.model, MPI.COMM_WORLD, 0)
MPI.COMM_WORLD.barrier()
mesh_data = gmshio.model_to_mesh(gmsh.model, MPI.COMM_WORLD, 0)
gmsh.clear()
gmsh.finalize()
# NOTE: Hex mesh must be rotated after generation due to gmsh API
mesh.geometry.x[:] = np.dot(r_matrix, mesh.geometry.x.T).T
return (mesh, ft)
mesh_data.mesh.geometry.x[:] = np.dot(r_matrix, mesh_data.mesh.geometry.x.T).T
assert mesh_data.facet_tags is not None
return (mesh_data.mesh, mesh_data.facet_tags)


@pytest.mark.parametrize("get_assemblers", ["C++", "numba"], indirect=True)
Expand Down

0 comments on commit 9ea0364

Please sign in to comment.