Hi everyone, how to evaluate function at a given point in dolfinx?

See: https://github.com/FEniCS/dolfinx/blob/master/python/test/unit/function/test_function.py#L169

**Updated link**

Dear dokken, according to your suggestion, I wrote the code like this:

x0 = [-1.117, 0, 0]

tree = geometry.BoundingBoxTree(mesh, 3)

cells = geometry.compute_first_entity_collision(tree, mesh, x0)

u.eval(x0, cells)

The error “RuntimeError: Dimension must be a number between 1 and 2” arouse at the BoundingBoxTree place.

So I guess you are using a 2D mesh? As the error suggests, the last argument in boundingboxtree should be either 1 or 2. You should just use mesh.geometry.dim as the last argument of the boundingboxtree.

mesh.geometry.dim outputs 3. I create the the 2d geometry in x,y plane using gmsh, it has 3d coordiantes although the z coordinates are always 0.

You Need to prune the z-coordinate from the Gmsh mesh, see Converting simple 2D mesh from gmsh to dolfin

Thank you. I’ll try.

dokken, I still have no idea how to generate 2d mesh. I found an option prude_z_0 in generate_mesh in pygmsh, but it seems not work. Could you give me an example? Thank you.

it should work when using the following args in `generate_mesh(geo, prune_z_0=True, verbose=True, geo_filename="mesh.geo")`

. I can’t really help you any more with a minimal example of the mesh and the code you are calling in dolfinx.

dokken, generate_mesh has no problem. Thank you.