BAMresearch / fenics-constitutive

Complex constitutive models beyond the FEniCS UFL.
https://bamresearch.github.io/fenics-constitutive
MIT License
13 stars 2 forks source link

Usage of `fem.Expression` compared to `fem.Function.interpolate` #50

Open pdiercks opened 3 months ago

pdiercks commented 3 months ago

Hi @srosenbu

I just noticed that something like

q = fem.Function(Q) # Q is the scalar quadrature space
q.interpolate(lambda x: x[0], cells=cells)

will fill the entries according to cells in q and leave other entries being zero.

Using fem.Expression on the other hand, only the nonzero values would be returned or the user would need to provide an array of the correct size to store the result.

That being said, I don't think using interpolate for _del_grad_u (see code) will work. What's more, the cell indices are also global indices, so the function on the subspace would probably complain if it encounters indices out of range, and you would evaluate the wrong cells.

We could, however, use strain.interpolate with strain as global function and call interpolate with cells for each material (so $n$ times if there are $n$ different materials). But, then we would need to slice strain.x.array when passing the values to the different material routines.

Best, Philipp

srosenbu commented 2 months ago

Sorry, I missed this message,

I think using interpolate will really come in handy once this PR https://github.com/FEniCS/dolfinx/pull/3114 gets merged in dolfinx. Then, we can just evaluate the expression defined on the whole mesh on the submeshes without handling cell indices ourselves.

pdiercks commented 2 months ago

It was after 5pm when I wrote that message ... I think if we want to work with functions on submeshes, then we do not need to pass cells at all and simply call

self._del_grad_u[k].interpolate(strain_expr) # cells=None

But, in any case, we should re-evaluate the whole design once the new features are available (interpolation from to submeshes, and also assembly of forms that contain quantities defined on different meshes).