-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
reducing mesh elements on a flat surface #37
Comments
shimwell
changed the title
try mesh.MeshSizeFactor for flat faces
reducing mesh elements on a flat surface
Jun 27, 2023
Example script takes the elements down from 683 to 330 by including the MeshSizeExtendFromBoundary line
|
Working a bit on this recently as the above method was not working well import gmsh
import sys
def create_geometry():
# Initialize gmsh
gmsh.initialize(sys.argv)
# Create a new model
gmsh.model.add("sphere_and_box_union")
# Create sphere (radius = 1.0)
sphere = gmsh.model.occ.addSphere(0, 0, 0, 1.0)
# Create box with less overlap
# Move it to just slightly overlap with the sphere
box = gmsh.model.occ.addBox(0.7, -1, -1, 2, 2, 2)
# Create the union of the two shapes
union = gmsh.model.occ.fuse([(3, sphere)], [(3, box)])
# Synchronize the geometry
gmsh.model.occ.synchronize()
# Get all surfaces
surfaces = gmsh.model.getEntities(dim=2)
# Define mesh sizes with more contrast
fine_size = 0.08 # Even finer for curved surfaces
coarse_size = 80 # Coarser for flat surfaces
# Function to check if a surface is planar
def is_planar_surface(surface_tag):
surface_type = gmsh.model.getType(2, surface_tag)
return surface_type == "Plane"
# Set mesh sizes with stronger enforcement
for surface in surfaces:
surface_tag = surface[1]
points = gmsh.model.getBoundary([surface], recursive=True)
for point in points:
if point[0] == 0: # Only process points (dim=0)
if is_planar_surface(surface_tag):
gmsh.model.mesh.setSize([point], coarse_size)
else:
gmsh.model.mesh.setSize([point], fine_size)
# Force mesh sizes to be respected more strictly
gmsh.option.setNumber("Mesh.CharacteristicLengthFactor", 1)
gmsh.option.setNumber("Mesh.CharacteristicLengthMin", fine_size)
gmsh.option.setNumber("Mesh.CharacteristicLengthMax", coarse_size)
gmsh.option.setNumber("Mesh.MinimumCirclePoints", 20) # More points on curved surfaces
# Less aggressive smoothing to maintain size differences
gmsh.option.setNumber("Mesh.Smoothing", 100)
# Generate 2D mesh
gmsh.model.mesh.generate(2)
# Save the mesh
gmsh.write("sphere_and_box_union.msh")
# Launch the GUI
gmsh.fltk.run()
# Cleanup
gmsh.finalize()
if __name__ == "__main__":
create_geometry() Perhaps this is the way to mesh a big flat shape with few elements while having lots of elements on curved surfaces. Needs testing in transport and all that but could just replaced the meshing approach with this and see how it goes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Looks like we can reduce the mesh element count by setting mesh.MeshSizeFactor to a large number.
The text was updated successfully, but these errors were encountered: