Discussion:
[Gmsh] Gmsh Python API
Christophe Geuzaine
2018-05-21 06:36:00 UTC
Permalink
It works fine over here: are you sure you are editing/examining the correct input/output files?

Add

gmsh.fltk.run()

before gmsh.finalize() - it will launch the GUI so that you can inspect the model interactively.
Dear List,
I have been trying to use the Python API but my meshing does not respond to the mesh size that I set when adding the points. I reproduced my problem in the following example. So no matter what value I set on ‘lc’, the surface always happens to have only four triangles.
Hope you can help me figure it out and be able to control the meshing. I am also attaching the resulting 'MyTest.msh’ file.
import gmsh
gmsh.initialize()
gmsh.option.setNumber("General.Terminal", 1)
gmsh.model.add("MyTest")
lc = 1e-4
gmsh.model.geo.addPoint(0, 0, 0, lc, 1)
gmsh.model.geo.addPoint(.1, 0, 0, lc, 2)
gmsh.model.geo.addPoint(.1, .3, 0, lc, 3)
gmsh.model.geo.addPoint(0, .3, 0, lc, 4)
gmsh.model.geo.addLine(1, 2, 1)
gmsh.model.geo.addLine(3, 2, 2)
gmsh.model.geo.addLine(3, 4, 3)
gmsh.model.geo.addLine(4, 1, 4)
gmsh.model.geo.addCurveLoop([4, 1, -2, 3], 1)
gmsh.model.geo.addPlaneSurface([1], 1)
gmsh.model.addPhysicalGroup(2, [1], 1)
gmsh.model.setPhysicalName(2, 1, "My surface")
gmsh.model.geo.synchronize()
gmsh.model.mesh.generate(2)
gmsh.write("MyTest.msh")
gmsh.finalize()
Thanks,
Alejandro
<MyTest.msh>_______________________________________________
gmsh mailing list
http://onelab.info/mailman/listinfo/gmsh
Alejandro Pina
2018-05-21 16:54:16 UTC
Permalink
Thanks Christophe for replying. I have attached a picture after adding the
line you suggested.
In the picture you can also see the API version I am using and built number.
The size of triangles does not respond to any value set on Œlc¹.
Best,
Alejandro

From: Christophe Geuzaine <***@gmail.com>
Date: Monday, May 21, 2018 at 7:36 AM
To: Alejandro Pina <***@gmail.com>
Cc: <***@onelab.info>
Subject: Re: [Gmsh] Gmsh Python API


It works fine over here: are you sure you are editing/examining the correct
input/output files?

Add

gmsh.fltk.run()

before gmsh.finalize() - it will launch the GUI so that you can inspect the
model interactively.
Dear List,
I have been trying to use the Python API but my meshing does not respond to
the mesh size that I set when adding the points. I reproduced my problem in
the following example. So no matter what value I set on Œlc¹, the surface
always happens to have only four triangles.
Hope you can help me figure it out and be able to control the meshing. I am
also attaching the resulting 'MyTest.msh¹ file.
import gmsh
gmsh.initialize()
gmsh.option.setNumber("General.Terminal", 1)
gmsh.model.add("MyTest")
lc = 1e-4
gmsh.model.geo.addPoint(0, 0, 0, lc, 1)
gmsh.model.geo.addPoint(.1, 0, 0, lc, 2)
gmsh.model.geo.addPoint(.1, .3, 0, lc, 3)
gmsh.model.geo.addPoint(0, .3, 0, lc, 4)
gmsh.model.geo.addLine(1, 2, 1)
gmsh.model.geo.addLine(3, 2, 2)
gmsh.model.geo.addLine(3, 4, 3)
gmsh.model.geo.addLine(4, 1, 4)
gmsh.model.geo.addCurveLoop([4, 1, -2, 3], 1)
gmsh.model.geo.addPlaneSurface([1], 1)
gmsh.model.addPhysicalGroup(2, [1], 1)
gmsh.model.setPhysicalName(2, 1, "My surface")
gmsh.model.geo.synchronize()
gmsh.model.mesh.generate(2)
gmsh.write("MyTest.msh")
gmsh.finalize()
Thanks,
Alejandro
<MyTest.msh>_______________________________________________
gmsh mailing list
http://onelab.info/mailman/listinfo/gmsh
Alejandro Pina
2018-05-21 17:23:23 UTC
Permalink
Thanks!! You are absolutely right. I added the following lines and it
perfectly works.

gmsh.initialize('',False)
gmsh.option.setNumber("Mesh.Algorithm", 5)

Best,
Alejandro

From: Christophe Geuzaine <***@gmail.com>
Date: Monday, May 21, 2018 at 6:04 PM
To: Alejandro Pina <***@gmail.com>
Cc: gmsh <***@onelab.info>
Subject: Re: [Gmsh] Gmsh Python API
Post by Alejandro Pina
Thanks Christophe for replying. I have attached a picture after adding the
line you suggested.
In the picture you can also see the API version I am using and built number.
The size of triangles does not respond to any value set on Œlc¹.
By default gmsh.intialize() reads the Gmsh configuration files it finds on
your system; my guess is that you have some options set in .gmshrc or
.gmsh-options to change the default meshing algorithm (your log shows that
you're using Frontal, which is not the default) and the mesh size.

Try

gmsh.initialize('', False)

which will disable reading of the config files.
Post by Alejandro Pina
Best,
Alejandro
Date: Monday, May 21, 2018 at 7:36 AM
Subject: Re: [Gmsh] Gmsh Python API
It works fine over here: are you sure you are editing/examining the correct
input/output files?
Add
gmsh.fltk.run()
before gmsh.finalize() - it will launch the GUI so that you can inspect the
model interactively.
Dear List,
I have been trying to use the Python API but my meshing does not respond to
the mesh size that I set when adding the points. I reproduced my problem in
the following example. So no matter what value I set on Œlc¹, the surface
always happens to have only four triangles.
Hope you can help me figure it out and be able to control the meshing. I am
also attaching the resulting 'MyTest.msh¹ file.
import gmsh
gmsh.initialize()
gmsh.option.setNumber("General.Terminal", 1)
gmsh.model.add("MyTest")
lc = 1e-4
gmsh.model.geo.addPoint(0, 0, 0, lc, 1)
gmsh.model.geo.addPoint(.1, 0, 0, lc, 2)
gmsh.model.geo.addPoint(.1, .3, 0, lc, 3)
gmsh.model.geo.addPoint(0, .3, 0, lc, 4)
gmsh.model.geo.addLine(1, 2, 1)
gmsh.model.geo.addLine(3, 2, 2)
gmsh.model.geo.addLine(3, 4, 3)
gmsh.model.geo.addLine(4, 1, 4)
gmsh.model.geo.addCurveLoop([4, 1, -2, 3], 1)
gmsh.model.geo.addPlaneSurface([1], 1)
gmsh.model.addPhysicalGroup(2, [1], 1)
gmsh.model.setPhysicalName(2, 1, "My surface")
gmsh.model.geo.synchronize()
gmsh.model.mesh.generate(2)
gmsh.write("MyTest.msh")
gmsh.finalize()
Thanks,
Alejandro
<MyTest.msh>_______________________________________________
gmsh mailing list
http://onelab.info/mailman/listinfo/gmsh
<Screen Shot 2018-05-21 at 5.47.04 PM.png>
Loading...