Material properties from discrete data


Hi all,

I’m trying to set a material property based on experimental data. Let’s say we have a temperature dependent thermal conductivity.

I’d like to do the following :

from fenics import *
from scipy.interpolate import interp1d

interpcond = interp1d([300, 400, 500, 600], [1000, 1000, 1500, 3000])
def cond(T):
    c = interpcond(T)
    return c
mesh = UnitSquareMesh(8, 8)
V = FunctionSpace(mesh, 'P', 1)
T = Function(V)
v = TestFunction(V)
F = cond(T)*dot(grad(T), grad(v))*dx

The above doesn’t work but I wondered if anyone had an idea.

Thanks in advance,


Take a look at the responses in this thread:

The one I suggested should work nicely if your lookup tables only have a few entries, as in your MWE (although you might want to add exit() after the print call, now that I look at it again). @freya’s solution would be more efficient for assembly, although you’d have to linearize manually for a nonlinear residual like the one shown in your MWE. You could also try to extend my idea to implement a binary search recursively in UFL, although that may be more trouble than it’s worth.


Hi @kamensky! Thanks for your help.
Using @freya’s solution, in case of a nonlinear problem I think I’d have to reassemble the function at each time step and at each iteration, which is maybe a bit too much a trouble. I looked at your solution but it may indeed be very slow for some datasets, plus I don’t know if it’d work on a nonlinear problem.

To be honest I was hoping for an easy implementation that I wasn’t aware of but apparently there isn’t one - yet. I can always work with polynomial fitting for now.

Thanks !!