Hi,
I just added python fields (they will be available in the next nightly
build).
There is no embedded python interpreter in Gmsh, we rather provide
python bindings for the Gmsh library. This is still work in progress, in
particular there is no documentation nor stable API, we just bind most
of Gmsh internal functions to python.
Gmsh Library and python bindings can be downloaded with the gmsh dynamic
library from Gmsh website :
http://geuz.org/gmsh/bin/Linux/gmsh-svn-Linux64-dynamic.tgz
http://geuz.org/gmsh/bin/MacOSX/gmsh-svn-MacOSX-dynamic.tgz
http://geuz.org/gmsh/bin/Windows/gmsh-svn-Windows64-dynamic.zip
On linux and OSX, to build the python bindings, go to the "gmshpy"
sub-directory the run the python script "setup.py" (e.g. python setup.py
build; python setup.py install). On windows, I'm not sure if it works ...
An example of python field is attached, the python script imports the
gmsh python bindings then loads a geo file and adds some python fields
and at the end, the GUI is started.
regards,
Jonathan
On 11/07/13 11:49, Nico Schlömer wrote:
I'd be very much interested in a hands-on example of Gmsh + Python as
well.
--Nico
On Thu, Jul 11, 2013 at 10:06 AM, Christophe Geuzaine
<[email protected] <mailto:[email protected]>> wrote:
On 11 Jul 2013, at 09:07, moritz braun <[email protected]
<mailto:[email protected]>> wrote:
> Dear All
>
> I am using gmsh in the moment to
> create 3D grids with background field to control the
characteristic length.
> Writing functions as .F attribute of an Field variable is
rather restrictive
> it would be nice if gmsh could be extended by embedding the
python interpreter for
> such functions.
> How difficult whould that be?
>
I think you can already define fields in the Gmsh Python interface
(CC'ing Jon on this one: Jon, could you send a small example?). If
this is the case, then your python script could simply import the
Gmsh module, merge your current .geo definitions, then define the
fields directly in Python.
> regards
>
> Moritz
>
> --
> Prof M Braun Tel.:27-12-4298006/8027
> Physics Department Fax.: 27-12-4293643
> University of South Africa (UNISA)
> [email protected] <mailto:[email protected]>
> P.O. Box 392
> 0003
> UNISA
> South Africa
> http://moritz-braun.blogspot.com
> _______________________________________________
> gmsh mailing list
> [email protected] <mailto:[email protected]>
> http://www.geuz.org/mailman/listinfo/gmsh
--
Prof. Christophe Geuzaine
University of Liege, Electrical Engineering and Computer Science
http://www.montefiore.ulg.ac.be/~geuzaine
<http://www.montefiore.ulg.ac.be/%7Egeuzaine>
_______________________________________________
gmsh mailing list
[email protected] <mailto:[email protected]>
http://www.geuz.org/mailman/listinfo/gmsh
#import gmsh python module
from gmshpy import *
#load the mesh into a GModel
m = GModel.current()
m.load("square.geo")
#simplest way to add a python field
def fieldFunction(x, y, z, entity) :
return y
f0id = m.getFields().addPythonField(fieldFunction)
#f0id is the id of the new field
#the id of the field can be specified as an optional argument
f1id = m.getFields().addPythonField(fieldFunction, 10)
# f1id == 10
#the callback can be a member function
class fieldClass :
def op(self, x, y, z, entity) :
return self.tagFactor * entity.tag() + x
def __init__ (self):
self.tagFactor = 1000;
f = fieldClass()
f2id = m.getFields().addPythonField(f.op)
#launch the GUI
FlGui.instance().run()
#instead of starting the GUI, we could generate the mesh and save it
#m.mesh(2) # 2 is the dimension
#m.save("square.msh")
_______________________________________________
gmsh mailing list
[email protected]
http://www.geuz.org/mailman/listinfo/gmsh