How to extract solution at a given point

Hello everyone,

I’m currently working with GetFEM in Python to solve a nonlinear mechanical problem on a large mesh. I would like to extract the value of a variable (e.g., displacement u) at a given point in space — for instance, at coordinates (x, y, z) — either during the simulation.

The approach I’m currently using is:

point = [[x], [y], [z]]  # coordinates of the point (column-wise)
val = md1.interpolation("u", point, md1.mesh())

This works correctly, especially when enabling extrapolation near the boundary if needed.

However, I would like to know:

Is there any other recommended or more efficient method** in GetFEM to access the value of a variable at a specific point?
For example:

  • A way that avoids the overhead of symbolic interpolation?
  • Something more direct or optimized for multiple points?
  • A lower-level access based on nearby DOFs or mesh structure?

Any suggestions or best practices would be highly appreciated.

Thank you in advance!

Best regards,

Hello Djoumessi,

I have generally used md.variable('variable you need') to get an array of all the variables values versus point id in the simulation. Then, mf.eval('each coordinate') can be used to get the coordinate values of each point id. This effectively gives a table of the variable values in the final solution versus the coordinate points. I usually use this for plotting, but it should be possible to find the specific point needed.

I do not believe this method uses extrapolation, but instead extracts data directly from the model.

Here is an example I am using to extract the density f of my plasma flow versus the six dimensions of my problem:

    # extracted solution
    density         = md.variable('f')
    
    x               = mf.eval("x")
    y               = mf.eval("y")
    z               = mf.eval("z")
    u               = mf.eval("u")
    v               = mf.eval("v")
    w               = mf.eval("w")

Note that I am using md as the Model, and mf as my MeshFem in the above codes.

Sincerely,
Eric Comstock

Dear Eric,

Thank you very much for your detailed answer — I really appreciate it.

As you pointed out, this method works perfectly for retrieving values at mesh nodes, and I find it particularly useful for post-processing and visualization tasks.

I was also thinking that if one needs the solution at an arbitrary point (not necessarily a mesh node), then some interpolation may be required. For now, your method provides a great foundation, and I’ll build on that as needed.

Thanks again for your help!

Best regards,
Djoumessi

1 Like

this is the recommended way of doing it. Not mf.eval().

The function md1.interpolation("u", points, mesh) supports also multiple points. There is no symbolic interpolation. The cost of the evaluation is negligible. The main cost is in the inversion of the points from real to reference element. This inversion is quite optimized in the code. However, if you do the same operation often, you might want to cache the inversion, so that you will not be repeating the same costly operation. The recommended syntax for this is

sl_tracked = gf.Slice("points", mesh, points)
gf.compute_interpolate_on(mf, U, sl_tracked) #  U is a vector with nodal values on mf

do not use mf.eval(). Consider it is an obsolete function.

1 Like

another one of the “good” functions is the asm_interpolation_matrix

It will give you an interpolation matrix, so that any further interpolation will be just a matrix-vector product.

1 Like

Dear Poulios,

Thank you for your reply, it works perfectly

Best.