Create mesh from OCCG with individual mesh sizes

Hey guys!

I am currently trying to generate a mesh, that consists of two geometries previously imported from two STEP-files. Both of these files are attached.

After importing, I cut out a hole of both geometries seperately and I name their surfaces.

The question now is, wether it is possible to generate a mesh, containig both geometries(they should fit together perfectly) with individual mesh sizes?

Gleitlager_D48mm_w17mm_gap.step (13.6 KB)
Gleitlager_D48mm_w17mm_top.step (18.6 KB)

Here is my code:

from netgen.occ import *
from ngsolve import *
import pyngcore as ngcore

D = 48 * 10**-3
R = D / 2
d = 46 * 10**-3
r = d / 2
w = 17.5 * 10**-3
epsilon = 0.5
e = epsilon * (R - r)

max_mesh_gap = 500 * 10**-6
max_mesh_top = 1000 * 10**-6
scale = 10**3

# Import geometry
step_geo_top = OCCGeometry(str(file_step_top))
step_geo_gap = OCCGeometry(str(file_step_gap))

# Get geometry as shape
# The imported STEP-file is in meters, therefore some downscaling needs to be done.
shape_top = step_geo_top.shape
shape_top = shape_top.Scale(Pnt(0, 0, 0), 10**-3 / scale)
shape_gap = step_geo_gap.shape
shape_gap = shape_gap.Scale(Pnt(0, 0, 0), 10**-3 / scale)

# Fuse the geometries
# shape = shape_top + shape_gap

# Define position and direction of shaft
start_point_shaft = Pnt(0, -e, w/2)
direction_shaft = Vec(0, 0, -1)

# Create shaft
shaft = Cylinder(gp_Ax2(start_point_shaft, direction_shaft), r, w)
shaft.faces[0].name = 'inside'

# Create bearing geometry
# bearing = shape - shaft
lub_top = shape_top - shaft
lub_gap = shape_gap - shaft

# Create final geometry
geo_top = OCCGeometry(lub_top)
geo_gap = OCCGeometry(lub_gap)

# Give names to surfaces
geo_top.shape.faces.Max(Z).name = 'front'
geo_top.shape.faces.Min(Z).name = 'back'
geo_gap.shape.faces.Max(Z).name = 'front'
geo_gap.shape.faces.Min(Z).name = 'back'

for face in geo_top.shape.faces:
    if face.name == 'front' or face.name == 'back':
        face.col = (1, 0, 0)
    elif face.name == 'inside':
        face.col = (0, 0, 1)
    else:
        face.name = 'outside'
        face.col = (0, 1, 1)
    # print(face.name)

for face in geo_gap.shape.faces:
    if face.name == 'front' or face.name == 'back':
        face.col = (1, 0, 0)
    elif face.name == 'inside':
        face.col = (0, 0, 1)
    else:
        face.name = 'outside'
        face.col = (0, 1, 1)
    # print(face.name)

# Visaulize geometry
Draw(geo_top)
print('\nGeometry finished\n')

# Generate meshes
ngcore.SetNumThreads(numProc)
with ngcore.TaskManager():
    mesh_top = Mesh(geo_top.GenerateMesh(maxh=max_mesh_top))

ngcore.SetNumThreads(numProc)
with ngcore.TaskManager():
    mesh_gap = Mesh(geo_gap.GenerateMesh(maxh=max_mesh_gap))

# Visualize mesh
Draw(mesh_gap)
print('\nMesh finished\n')

print('\nSuccess! Finished Executing!\n')

Thank you very much for your help!
Best Boindil

I think you want to do this:

geo_top.shape.solids.maxh = max_mesh_top
geo_gap.shape.solids.maxh = max_mesh_gap
geo_both = OCCGeometry(Glue([geo_top.shape, geo_gap.shape]))
mesh_both = Mesh(geo_both.GenerateMesh())

best
Christopher

Hey Christopher!
Thank you, for your reply! That’s exactly what I was looking for!

Nevertheless, this creates another question:
When glueing the parts together, the faces between them are still there. Is there an easy way to name them? Because the way my code works, there will be problems with the boundary conditions.

I attached a picture. There you can see white faces. I want them to get a name like “fluid” or something like that, where the angle of the gap should not be important. It shuld work like this (90°) but also with e.g. 270°.

Thank you for your help!

(shape.solids[0].faces * shape.solids[1].faces).name = "interface"

if you use the + operator instead of glue you fuse them together, but I think you do not want that since you want to set different maxh, so I think naming the interface and then setting boundary conditions on ~mesh.Boundaries("interface") should work. (~ operator inverts the bitarray of the region → all regions except “interface”)

Thank you so much!

Works great :smiley: