Open rmsc opened 2 years ago
I could also use this; it looks like the main concern is what assumptions gmsh makes internally. The API really seems like it wants you to work on only one model at a time and using a context manager helps to guarantee that. If multiple initialization / destruction is a concern, gmsh has a function is_initialized
that could help avoid anything too awful from happening, but there might be other concerns as well.
I'd be happy to take a crack at this but it would be good to get some feedback from @nschloe first.
As far as I can tell, all tests and examples use the following structure:
In my case I want to store the geometry inside a class, like so:
Common sense says this should work just as fine, but it doesn't. I just get an error on each operation:
Looking at the source code, in
src/pygmsh/common/geometry.py
it is clear that some crucialgmsh
operations are done in__enter__()
and__exit__()
.I could manually call
gmsh.initialize()
and such, but it seems awful for an abstraction API. I could also call__enter__()
and__exit__()
manually, but that's even uglier.A good compromise might be to just move the enter/exit code to proper
initialize()
andfinalize()
methods, calling them from__enter()__
and__exit()__
.As an alternative, the enter/exit code could perhaps be moved to the constructor/destructor.