Slow Assembling of linear and bilinear forms using Assemble()

Hello everyone,

i am currently facing major problems (w.r.t. computational speed) when dealing with the assembling of complex linear and bilinear forms that occur in computational homogenization, for more complex (dissipative) systems etc.

In some cases Assemble() of linear and bilinear forms is not even possible.

I have prepared a MWE that illustrates the problem by solving a nonlinear hyperelastic problem

  1. using AssembleLinearization and

  2. Linearization of the problem via autodiff and assembling linear and bilinear forms via Assemble().

MWE_Linearization.ipynb (6.7 KB)

For the simple problem at hand Variant I is about >3 times faster.

For more complex problems this is far more extreme.

Is there a workaround or a solution to speed up Assemble() (in combination with autodiff)?

Thanks in advance and best regards.

Best

Philipp

to see what’s going on, you can print and analyze the CoefficientFunctions:

print (cf)
print (cf.Compile())
print (cf.Diff().Compile())

The costs for matrix assembling is the sum of all steps of the compiled CF.
If you call AssembleLinearization, the first and second order derivatives are evaluated by automatic differentiation in forward mode. Here, the number of steps are exactly the same as for function evaluation, we just evaluate the steps using C++ AutoDiff classes.

However, the Diff manipulates the expression tree by symbolic differentiation. There are implemented formulas for differentiating matrix inverses, determinants, etc., and plenty of heuristic for tree optimizations. It is easily possible that some more optimizations could be applied. If you find some missed optimizations we could possible add them.

A good compromise could be symbolic differentiation for the first derivative, and AssembleLinearization for the second one.

Joachim

Thank you for the clarification and the heads up, Joachim.

I will have a closer look at it in the coming week and hope to find something to optimize and improve the speed.

Since this poses some major trouble when e.g. trying to assemble the “algorithmic” part of the tangent for more complex rate-independent dissipative systems.