Speeding up time-dependent diffusion equation

You can make a tensor with ufl.as_tensor that is a mixture of ufl.SpatialCoordinate and constants (say for time)`
For instance you could do something like

x = ufl.SpatialCoordinate(domain)
a = dolfinx.fem.Constant(domain, 0.)
t = dolfinx.fem.Constant(domain, 0.1)
D = ufl.as_tensor(((a*x[0]-t, 0),(x[1], t)))

and update a and t in your time loop.

1 Like