Dear NGSolve community,
I experienced some unexpected behaviour during the differentiation of a domain-wise coefficient function. For example, computing the second derivative of a hyperelastic strain-energy function (to obtain some stiffness value) in two different ways seems to give equivalent results, but very different computing times. The two options:
(1) Differentiating the domain-wise energy coefficient function (twice).
(2) Differentiating the energy per domain (twice) and defining a domain-wise coefficient function for the stiffness.
Option (1) is significantly slower than (2), also visible in the very different number of entries in the expression trees for the compiled functions ((1) more than (2)). See also the attached minimal example. This is a bit confusing to me, since I thought that option (1) is what happens “under the hood” during operations like AssembleLinearization in case of domain-wise defined energy functions used in the bilinear forms.
The difference in the computing times is not only cosmetic, but becomes crucial for larger problems and more sophisticated energy functions than a simple Neo-Hooke. Interpolating the stiffness values via the set-command for post-processing becomes almost infeasible with option (1).
Is this intended behaviour or am I overlooking some significant differences in the two options?
Thank you!
test_diff2_set.py (1.8 KB)