Possible to read data from file into function?

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,

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.

Improvements from Gmsh experts are welcome!

You can use it like this:

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)

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.


Hi Joachim,
great, thank you for the Gmsh module and for the information. I’ll give it a try.
Best wishes,