Error: Invalid boundary mesh (overlapping facets)
Hello, I'm trying to generate microstructure.
There are some particles outside boundary (Cube).
I want to generate microstructure within the cube, with truncated particles.
I know the every geometrical data for ellipsoids, but I got the error like shown.
I want to know how to fix this error. For your information, I attached the code and text files for the geometrical data.
Can you give me some tips for this issue?
Thank you.
# The Python API is entirely defined in the `gmsh.py' module (which contains the
# full documentation of all the functions in the API):
import numpy as np
import gmsh
import math
import os
import sys
import time
t0_start = time.time()
# Read Coordinates_XYZ, AxisLength_abc, and Euler Angles from *.txt files.
Coordinates_XYZ = np.loadtxt("outputs/PackingAlgorithm/Centroid_XYZ.txt")
AxisLength_abc = np.loadtxt("outputs/PackingAlgorithm/AxisLength_Manual_abc_141p.txt")
# Read *.txt file including modified Coordinates_XYZ and Type of Periodicity.
Periodicity = np.loadtxt("outputs/PackingAlgorithm/Periodicity_141p.txt")
t0_end = time.time()
print("Reading geometrical data --- %s seconds ---" % (t0_end - t0_start))
# Before using any functions in the Python API, Gmsh must be initialized:
gmsh.initialize()
# Next we add a new model named "test" (if gmsh.model.add() is not called a new
# unnamed model will be created on the fly, if necessary):
gmsh.model.add("test")
# We start with a cube and some spheres:
Box=gmsh.model.occ.addBox(0, 0, 0, 64, 64, 64, 10)
t1_start = time.time()
def make_ellipsoid(cx, cy, cz, ax, ay, az):
ellipsoid = gmsh.model.occ.addSphere(cx, cy, cz, 1)
gmsh.model.occ.dilate([(3, ellipsoid)], cx, cy, cz, ax, ay, az)
return ellipsoid
Ellipsoids = [0] * 100
for i in range(0,60):
Ellipsoids[i]=make_ellipsoid(Coordinates_XYZ[i,0], Coordinates_XYZ[i,1], Coordinates_XYZ[i,2],
AxisLength_abc[i,0], AxisLength_abc[i,1], AxisLength_abc[i,2])
for j in range(0,40):
Ellipsoids[j+60]=make_ellipsoid(Periodicity[j,0], Periodicity[j,1], Periodicity[j,2],
AxisLength_abc[int(Periodicity[j,3]),0], AxisLength_abc[int(Periodicity[j,3]),1], AxisLength_abc[int(Periodicity[j,3]),2])
# We first fragment all the volumes, which will leave parts of spheres
# protruding outside the cube:
out, _ = gmsh.model.occ.fragment([(3, Box)], [(3, Ellipsoids[i]) for i in range(0, len(Ellipsoids))])
# out, _ = gmsh.model.occ.fragment([(3, Box)], [(3, Ellipsoids[i]) for i in range(0, 100)])
t1_end1 = time.time()
print("Geometry fragment --- %s seconds ---" % (t1_end1 - t1_start))
"""
Before they can be meshed (and, more generally, before they can be used by API
functions outside of the built-in CAD kernel functions), the CAD entities must
be synchronized with the Gmsh model, which will create the relevant Gmsh data
structures. This is achieved by the gmsh.model.geo.synchronize() API call for
the built-in CAD kernel. Synchronizations can be called at any time, but they
involve a non trivial amount of processing; so while you could synchronize the
internal CAD data after every CAD command, it is usually better to minimize
the number of synchronization points.
"""
gmsh.model.occ.synchronize()
t1_end2 = time.time()
print("Geometry synchronized --- %s seconds ---" % (t1_end2 - t1_end1))
# Ask OpenCASCADE to compute more accurate bounding boxes of entities using
# the STL mesh:
gmsh.option.setNumber("Geometry.OCCBoundsUseStl", 1)
# We then retrieve all the volumes in the bounding box of the original cube,
# and delete all the parts outside it:
eps = 1e-3
vin = gmsh.model.getEntitiesInBoundingBox(-eps, -eps, -eps,
64+eps, 64+eps, 64+eps, 3)
for v in vin:
out.remove(v)
gmsh.model.removeEntities(out, True) # Delete outside parts recursively
# We now set a non-uniform mesh size constraint (again to check results
# visually):
p = gmsh.model.getBoundary(vin, False, False, True) # Get all points
gmsh.model.mesh.setSize(p, 10)
p = gmsh.model.getEntitiesInBoundingBox(-eps, -eps, -eps,
eps, 64+eps, 64+eps,
0)
gmsh.model.mesh.setSize(p, 10)
"""
At this level, Gmsh knows everything to display the rectangular surface 1 and
to mesh it. An optional step is needed if we want to group elementary
geometrical entities into more meaningful groups, e.g. to define some
mathematical ("domain", "boundary"), functional ("left wing", "fuselage") or
material ("steel", "carbon") properties.
Such groups are called "Physical Groups" in Gmsh. By default, if physical
groups are defined, Gmsh will export in output files only mesh elements that
belong to at least one physical group. (To force Gmsh to save all elements,
whether they belong to physical groups or not, set the `Mesh.SaveAll' option
to 1.) Physical groups are also identified by tags, i.e. stricly positive
integers, that should be unique per dimension (0D, 1D, 2D or 3D). Physical
groups can also be given names.
"""
# We can then generate a 3D mesh...
t2_start = time.time()
gmsh.model.mesh.generate(3)
t2_end =time.time()
print("Mesh generation --- %s seconds ---" % (t2_end - t2_start))
# Launch the GUI to see the results:
if '-nopopup' not in sys.argv:
gmsh.fltk.run()
gmsh.finalize()