Implement support for new representation of spatial derivatives of functions after UFL has applied differentiation algorithm
UFL has since before the summer had an alternative way to represent spatial derivatives of functions after the differentiation algorithm has been applied. This cannot be enabled by default in UFL because it will break existing form compilers. Supporting this in FFC will probably improve scalability for complicated forms right away, and is a prerequisite for the work-in-progress algorithms from uflacs to work properly.
The issue is the representation of spatial derivatives of functions (Coefficient/
been applied. In the current vs new implementation, they are represented as e.g.
SpatialDerivati
vs
Indexed(
or
ComponentTensor
vs
Grad(Coefficien
So basically, the difference is that you will not encounter SpatialDerivative in an expression after expand_derivatives has been applied, but you will encounter Grad. Other derivatives like div and curl are represented in terms of Grad instead of SpatialDerivative.
The important property of the new representation is that indexing operations are distinct from operations introducing new actual values into an expression, which makes it a lot easier to identify common subexpressions involving Grad(f).
To enable this behaviour change in ufl, you need to do this before anything else:
import ufl.algorithms.ad
ufl.
I don't feel up to the task of implementing this without risking breaking lots of stuff, but I'll be happy to review changes and answer any further questions!
Blueprint information
- Status:
- Complete
- Approver:
- None
- Priority:
- High
- Drafter:
- None
- Direction:
- Approved
- Assignee:
- None
- Definition:
- Approved
- Series goal:
- None
- Implementation:
- Implemented
- Milestone target:
- None
- Started by
- Martin Sandve Alnæs
- Completed by
- Martin Sandve Alnæs
Related branches
Related bugs
Whiteboard
This blueprint supersedes https:/
msa: I took the liberty to set priority to high, as this is highly important for memory and performance with complicated forms.
I have attempted to implement this change in the linked branches, without any validation, but looking at the ffc demo references the resulting code seems to get a much higher operation count. Kristian has agreed to take a look at it next week.
kbo: Did something change in the estimate_
Optimisations also appears to be working.
msa: the ufl degree estimation didn't have a rule for grad, so derivatives did not subtract for the degree when spatial_derivative was replaced by grad. Now it works fine. Note that ffc spends 10-15% more time in compiler stage 2 after this change, but this is a necessary change so I guess it just has to get worse before it gets better.