[Gmsh] How to add a Point to a Surface with the gmsh Python API?

Max Orok morok at mevex.com
Tue Aug 20 17:53:40 CEST 2019


Hi Lepy,

I think the embed function is what you're looking for:
https://gitlab.onelab.info/gmsh/gmsh/blob/master/api/gmsh.py#L2319

It's more general than "Point in Surface", because it can do Curves in
Surfaces, etc.
Make sure to call synchronize before trying to embed points.

The modified script is:

import gmsh

gmsh.initialize()

gmsh.option.setNumber("General.Terminal", 1)
gmsh.option.setNumber("Mesh.Algorithm", 6)
gmsh.option.setNumber("Mesh.RecombineAll", 1)

gmsh.model.add("square")
gmsh.model.geo.addPoint(0, 0, 0, 0.6, 1)
gmsh.model.geo.addPoint(1, 0, 0, 0.6, 2)
gmsh.model.geo.addPoint(1, 1, 0, 0.5, 3)
gmsh.model.geo.addPoint(0, 1, 0, 0.4, 4)
gmsh.model.geo.addLine(1, 2, 1)
gmsh.model.geo.addLine(2, 3, 2)
gmsh.model.geo.addLine(3, 4, 3)
line4 = gmsh.model.geo.addLine(4, 1)

gmsh.model.geo.addCurveLoop([1, 2, 3, line4], 1)
gmsh.model.geo.addPlaneSurface([1], 6)

gmsh.model.geo.addPoint(.5, .5, 0, 0.1, 5)

# make sure synchronize before adding point!
gmsh.model.geo.synchronize()

# embed point 5 (dim 0) in surface 6 (dim 2)
gmsh.model.mesh.embed(0, [5], 2, 6)
gmsh.model.mesh.generate(2)

gmsh.write("embedded.msh")

Without embedded point:
[image: image.png]

With embedded point:
[image: image.png]

Sincerely,
Max





On Tue, Aug 20, 2019 at 11:01 AM <lepy at mailbox.org> wrote:

> Hi,
>
> I want to use the Python API from gmsh to mesh a 2D surface with a local
> mesh refinement.
>
> How can I add a point to a surface to get a finer mesh around some inner
> points?
>
> It should be the Python version of
>
> Point{5} In Surface{6};
>
> Thanks
>
> Lepy
>
> gmsh.initialize()
>
> gmsh.option.setNumber("General.Terminal", 1)
> gmsh.option.setNumber("Mesh.Algorithm", 6)
> gmsh.option.setNumber("Mesh.RecombineAll", 1)
>
> gmsh.model.add("square")
> gmsh.model.geo.addPoint(0, 0, 0, 0.6, 1)
> gmsh.model.geo.addPoint(1, 0, 0, 0.6, 2)
> gmsh.model.geo.addPoint(1, 1, 0, 0.5, 3)
> gmsh.model.geo.addPoint(0, 1, 0, 0.4, 4)
> gmsh.model.geo.addLine(1, 2, 1)
> gmsh.model.geo.addLine(2, 3, 2)
> gmsh.model.geo.addLine(3, 4, 3)
> line4 = gmsh.model.geo.addLine(4, 1)
>
> gmsh.model.geo.addCurveLoop([1, 2, 3, line4], 1)
> gmsh.model.geo.addPlaneSurface([1], 6)
>
> gmsh.model.geo.addPoint(.5, .5, 0, 0.1, 5)
>
> ??? gmsh.model.geo.addPoint2Surface(???)
>
> gmsh.model.geo.synchronize()
> gmsh.model.mesh.generate(2)
>
> _______________________________________________
> gmsh mailing list
> gmsh at onelab.info
> http://onelab.info/mailman/listinfo/gmsh
>


-- 
Max Orok
Contractor
www.mevex.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://onelab.info/pipermail/gmsh/attachments/20190820/fe6aedc3/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 24021 bytes
Desc: not available
URL: <http://onelab.info/pipermail/gmsh/attachments/20190820/fe6aedc3/attachment-0002.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 26433 bytes
Desc: not available
URL: <http://onelab.info/pipermail/gmsh/attachments/20190820/fe6aedc3/attachment-0003.png>


More information about the gmsh mailing list