[Gmsh] python and gmsh

Magnus Hagdorn Magnus.Hagdorn at OHMsurveys.com
Tue Mar 20 21:09:25 CET 2007


On Tue, 2007-03-20 at 17:58 +0000, Daniel Wheeler wrote:
> 
> On Mar 20, 2007, at 2:59 PM, Magnus Hagdorn wrote:
> 
> > On Tue, 2007-03-20 at 14:51 +0000, Daniel Wheeler wrote:
> > > 
> > > 
> > > Hi,
> > > 
> > > 
> > > 
> > > 
> > > I was wondering if anyone had thought about exposing some of the
> > > gmsh
> > > functionality
> > > to python. We develop a finite volume code in python
> > > <http://www.ctcms.nist.gov/fipy> and
> > > use gmsh externally to create meshes and then read them in. It
> > > would
> > > be desirable to have closer
> > > coupling with gmsh from within python, especially for adaptive
> > > meshing
> > > and multigrid solutions.
> > > I am not sure if this is even a good idea or a project worth
> > > undertaking, but I'd like to hear peoples
> > > thoughts on the matter.
> > > 
> > > 
> > I have written some code which will start gmsh in a second thread
> > from
> > python. The only thing python does is monitor the progress of gmsh.
> > After it finishes you can read the generated mesh file.
> > Cheers
> > magnus
> 
> 
> We do something similar in that we read from a file and have bits of
> code that launch gmsh
> with system() commands, your stuff sounds a little more sophisticated.
> Here is the code
> that we use to do this:
>   
> 
>  <http://matdl-osi.org/fipy/browser/trunk/fipy/meshes/numMesh/gmshImport.py>
> 
> 
> It is fairly crude in that we write the gmsh file and then use our
> GmshImporter object to read it.
> GmshImporter is subclassed from our base Mesh classes. Ideally, we'd
> like to query gmsh directly for
> things like cell centers, face areas and the like and have these
> returned as numpy arrays rather than computing
> all of this in python, which can be slow and use a lot of memory.
> 
> 
> How do you query gmsh in order monitor its progress? Are you actually
> hooking into to gmsh with a python call?
> 
> 
Hi Daniel,
I just use the python thread support and start one thread which runs gms
with some command line options and another thread which monitors the
output to stdout. I'll ask my boss if I can pass the code on. I would
love to be able to contribute something slightly useful to gmsh which is
really excellent.
Cheers
magi