Efficient parameter interpolation using VoxelCoefficient

Hello everyone,

I am currently working on a nonlinear material model in NGSolve where the material parameters (e.g., Young’s modulus) depend on internal strain quantities that were identified from a previous experiment. The relationship between the strain and material parameters is not given in a closed analytical form, but only as discrete values on a regular parameter grid.

For 1D dependencies, I previously used BSpline interpolation in combination with scipy, which worked very well. However, I now need to handle 2D parameter dependencies in a 3D finite element simulation, which is why I started using VoxelCoefficient.

The function is promising, since it allows bilinear interpolation of regular grids inside NGSolve via:

paramCF = VoxelCoefficient(
    start=(x_min, y_min),
    end=(x_max, y_max),
    values=f_values_grid,     # shape: (ny, nx)
    linear=True,
    trafocf=(cf_x, cf_y)      # 2D coefficient function for evaluation
).Compile()

This works quite well for now. In my actual code, I need 21 “VoxelCoefficient” functions with a fine grid, which can significantly affect performance.

Is there a way to increase computational performance or reduce the overhead of using many VoxelCoefficient functions?

In the appendix there is an example with minimal code for one parameter.

Any insights or best practices would be highly appreciated!

Best regards,
Leonhard
Bilinear_interpolation_2D_param_space.py (4.7 KB)