"Interpolating" a function to a higher order space without an explicit expression

I would like to create a GridFunction (e.g. a higher order Lagrange finite element function), but the “expression” is not explicitly given. I can only evaluate the “expression” at discrete points (with arbitrary coordinates).

For example, I would like to compute the closest point (in an array) to a given “grid point”. In principle, I would just find the coordinates of all the DoFs in my GridFunction, and evaluate my “expression” at those points.

However, as has been pointed out in many other posts, NGSolve uses hierarchical basis, so the explicit coordinates of those DoFs is not available. So how can I interpolate my expression into a higher order FE space?

In another post, Joachim said this:

“We can exchange data in integration points. For that, we dump our integration points, and you provide function values in these points.”

So, do I just get the integration points for my GridFunction, and evaluate my “expression” with those? If so, then how do I get the values of my “expression” back into the GridFunction?

-Shawn

you can do L_2-like projection:

\int u * v = \int_{mypoints} u_{my} * v \qquad \forall v

If the points are defined on the reference element, you can use the integration rule for the right hand side. If these are completely independen points, then you have to use the point evaluation functional for the rhs.

You may also want to add a regularization term to the matrix, like \int h^2 \nabla u \nabla v

Joachim

Thanks for this. I found a least squares code you had posted that does this.

If I have enough points on each element, I shouldn’t need the regularization term, right?

-Shawn

right, I think so - but as we know you, you love a 4th order HHJ-regularization term,
Joachim

sigh Actually this has nothing to do with HHJ!

-Shawn

@walker_tr9 could you share the code snippet, or the link to Joachim’s previous post? I have tried to find it, but the forum is already to large :smiley:

This is what I had found:

Look at the least_squares.py file.

-Shawn