- Thank you received: 0
Possible to read data from file into function?
7 years 2 months ago #159
by dajuno
Possible to read data from file into function? was created 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
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
7 years 2 months ago #160
by joachim
Replied by joachim on topic Possible to read data from file into function?
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:
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
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
Time to create page: 0.125 seconds