Hello,
I generate a 3d mesh by making a boolean_difference
between a box and a sphere as follows
import meshio
import gmsh
import pygmsh
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("resolution")
args = parser.parse_args()
resolution = (float)(args.resolution)
geometry = pygmsh.occ.Geometry()
model = geometry.__enter__()
box = model.add_box([0, 0, 0], [1, 1, 1], mesh_size=resolution)
ball = model.add_ball([0.5, 0.5, 0.5], 0.25, mesh_size=resolution)
box_minus_ball = model.boolean_difference( box, ball )
model.synchronize()
model.add_physical( box_minus_ball, "box_minus_ball" )
geometry.generate_mesh(dim=3)
gmsh.write("solution/mesh.msh")
model.__exit__()
def create_mesh(mesh, cell_type, prune_z=False):
cells = mesh.get_cells_type(cell_type)
cell_data = mesh.get_cell_data("gmsh:physical", cell_type)
out_mesh = meshio.Mesh(points=mesh.points, cells={
cell_type: cells}, cell_data={"name_to_read": [cell_data]})
return out_mesh
mesh_from_file = meshio.read("solution/mesh.msh")
tetrahedron_mesh = create_mesh(mesh_from_file, "tetra", True)
meshio.write("solution/tetrahedron_mesh.xdmf", tetrahedron_mesh)
which runs by taking the mesh resolution as runtime flag
$ rm -r solution; mkdir solution; python3 generate_3dmesh_box_ball.py 0.1
/usr/local/lib/python3.6/dist-packages/pygmsh/occ/geometry.py:222: UserWarning: Specified mesh size for <pygmsh.occ.box.Box object at 0x7ffff7926c50> discarded in Boolean difference operation.
f"Specified mesh size for {s[0]} "
/usr/local/lib/python3.6/dist-packages/pygmsh/occ/geometry.py:222: UserWarning: Specified mesh size for <pygmsh Ball object (OCC), ID 2> discarded in Boolean difference operation.
As said in the warning, my mesh resolution is ignored: For instance, if I set it to 0.1
or to 0.01
, the result is the same:
Do you know how I can increase the mesh resolution in this code ? I looked on google and on this site for the topic, I could not find any solution…
Thank you