# [Gmsh] Ensuring conformal meshing when using geomtry from Freecad

Juan Sanchez juan.e.sanchez at gmail.com
Thu Apr 5 17:22:53 CEST 2018

```Hello Benedikt,

I am using the OpenCascade factory to do the Boolean Operations in
gmsh.  This is using the pygmsh python module to help automate the
process:

https://github.com/nschloe/pygmsh/tree/master/pygmsh

The boolean operations can then be performed using code like this:
https://github.com/nschloe/pygmsh/issues/164

import pygmsh
characteristic_length_min=0.1,
characteristic_length_max=0.1,
)

def create_vol_volume(geom, h, w, l, x, z, cr, lcar=100):
f = 0.5*w
y = [-f,-f+cr, +f-cr, +f]
z = [z, z + (h-cr), z + h]
f = 0.5 * cr
points = []
points.append(geom.add_point((x, y, z), lcar=lcar))
points.append(geom.add_point((x, y, z), lcar=lcar))
points.append(geom.add_point((x, y, z), lcar=lcar))
points.append(geom.add_point((x, y, z), lcar=lcar))
points.append(geom.add_point((x, y, z), lcar=lcar))
points.append(geom.add_point((x, y, z), lcar=lcar))
points.append(geom.add_point((x, y, z), lcar=lcar))
points.append(geom.add_point((x, y, z), lcar=lcar))

lines = []

vol = geom.extrude(surface, translation_axis=[l, 0, 0])
return vol

h_top=40

z_vol=0
h_vol=25
w_vol=10
l_vol=100
x_vol=-0.5*l_vol
vol=create_vol_volume(geom, h=h_vol, w=w_vol, l=l_vol, x=x_vol,

z_vol2=0
l_vol2=50
t_vol2=1
w_vol2=w_vol+2*t_vol2
h_vol2=h_vol+t_vol2
x_vol2=x_vol + 0.5*(l_vol-l_vol2)
vol2=create_vol_volume(geom, h=h_vol2, w=w_vol2, l=l_vol2, x=x_vol2,
vol2=geom.boolean_difference([vol2], [vol], delete_first=True,
delete_other=False)
geom.boolean_fragments([vol2, vol], [], delete_first=True, delete_other=False)
print(geom.get_code())

And then you can label the volumes as physical volumes and mesh the
resulting geo file.

Regards,

Juan

On Thu, Apr 5, 2018 at 5:53 AM, Benedikt Oswald
<benedikt.oswald at lspr.swiss> wrote:
> Dear gmsh developers
>
> I recently tried to mesh a geometry (made in Freecad) which consists of
> two volumes where a smaller volume was
>
> subtracted in Freecad from the larger one. When I mesh the two volumes I
> would need tetrahedra
>
> and that are conformal between the two volumes. Would you have a
> suggestion on how
>
> to achieve this ? At the moment, gmsh does not really produce a
> conformal mesh.
>
> I attach the files in question.
>
> Thanks a lot in advance and greetings, Benedikt
>
>
>
> ----------------------------------------------------------------------------------------------------------------------
> Dr. sc. techn. Benedikt Oswald - first engineer - LSPR AG - phone +41 43 366 90 74
> Grubenstrasse 9, CH-8045 Zürich, benedikt.oswald at lspr.swiss
> ----------------------------------------------------------------------------------------------------------------------
>
>
> _______________________________________________
> gmsh mailing list
> gmsh at onelab.info
> http://onelab.info/mailman/listinfo/gmsh
>

```