Possible to read data from file into function?

More
7 years 2 months ago #159 by dajuno
Hello,
I am interested in using NGSolve for a project. Before getting started, I'd like to know if it's possible to read data from a file (e.g. VTK or HDF5) and to store it in a NGSolve function, that can be evaluated and used in the right hand side of the variational problem.

Also, is it possible to use externally generated meshes, for instance GMSH?

Thanks in advance!

Kind regards,
David
More
7 years 2 months ago #160 by joachim
Hi David,

we do not have many exchange formats implemented, but we rely on Python which allows to convert data relatively easy.

I had it on the list for a while, and your post was a trigger to write a Gmsh reader this afternoon.
Have a look at github, and find it in the nightly release.
github.com/NGSolve/netgen/blob/master/python/read_gmsh.py
Improvements from Gmsh experts are welcome!

You can use it like this:
Code:
from netgen.read_gmsh import ReadGmsh # import the Gmsh file to a Netgen mesh object mesh = ReadGmsh("sphere.msh") # wrap it into an NGSolve mesh from ngsolve import * mesh = Mesh(mesh) Draw(mesh) print ("num vol elements:", mesh.GetNE(VOL)) print ("num bnd elements:", mesh.GetNE(BND))


How do we exchange data, in particular for higher order finite elements ?
* You can use a piece-wise constant GridFunction, i.e. you provide one value per element.
* You can use voxel data on a uniform brick (with linear interpolation) as coefficient function
* We can exchange data in integration points. For that, we dump our integration points, and you provide function values in these points.

Best,
Joachim
More
7 years 2 months ago #164 by dajuno
Hi Joachim,
great, thank you for the Gmsh module and for the information. I'll give it a try.
Best wishes,
David
Time to create page: 0.125 seconds