FFC

Comment 1 for bug 897372

Revision history for this message
Kristian B. Ølgaard (k.b.oelgaard) wrote : Re: [Bug 897372] [NEW] FFC is extremely slow compared to SFC for this Fung-type material law

On 28 November 2011 20:47, Anders E. Johansen <email address hidden> wrote:
> Public bug reported:
>
> FFC uses a considerable amount of time (> 1h) compiling the following
> program. The generated .h-file exceeds 90MB. Running, it uses hours
> assembling a matrix. Using the SFC compiler, compiling is done in no
> more than ten minutes, and then the program finishes in about ten
> seconds.

Thank you for the bug report.
I don't have time at the moment to fix this, there is no simple
solution other than serious profiling and I foresee a lot of code to
be rewritten to get around this.

Are you using any GCC optimisations?
'-O2 -funroll-loops' usually gives good performance with quadrature code.
With a 90MB header file you might be stressing your hardware though.

You could also try to switch on FFC optimisations, I expect it will add to
the FFC compile time, if at all possible.
Use '-O -fprecompute_basis_const -feliminate_zeros' as I doubt
'-O' will work, it is quite memory intense.

I'm not surprised that SFC outperformes FFC, as it was designed with these
hyper elastic models in mind.
Are there any particular reasons you want to use FFC instead of SFC?

> I have similar problems with FFC and this Fung-type material law in
> other cases, eg computing the second Piola-Kirchhoff stress tensor.
> Then, the SFC compiled code is about 22000 times faster than FFC.

Could you add an example of such a case, it's good to have a more
forms for testing these things.
Slightly less complex forms are also appreciated, waiting hours
between each debug cycle is rather inefficient.

> Anders
>
>
> from dolfin import *
>
> mesh = UnitCube(2, 2, 2)
> V = VectorFunctionSpace(mesh, "CG", 1)
> bcl = DirichletBC(V, (0.0, 0.0, 0.0), "near(x[0], 0.0) && on_boundary")
> bcr = DirichletBC(V, (0.1, 0.0, 0.0), "near(x[0], 1.0) && on_boundary")
> bcs = [bcl, bcr]
>
> v  = TestFunction(V)
> u  = Function(V)
> du = TrialFunction(V)
>
> K   = Constant(0.876)
> C   = Constant(10.0)
> bff = Constant(18.48)
> bxx = Constant(3.58)
> bfx = Constant(2.8)
>
> I = Identity(3)
> F = I + grad(u)
>
> a = Expression(("x[0]*DOLFIN_PI/8"))
> R = as_matrix([[cos(a), 0, -sin(a)], [0, 1, 0], [sin(a), 0, cos(a)]])
>
> F = variable(R.T*F*R)
> E = 0.5*(F.T*F - I)
> J = det(F)
>
> f=0; s=1; n=2
> W = (bff*E[f,f]**2
>     + bxx*(E[n,n]**2 + E[s,s]**2 + E[n,s]**2)
>     + bfx*(E[f,n]**2 + E[n,f]**2 + E[f,s]**2 + E[s,f]**2))
> psi = 0.5*K*(exp(W) - 1) + C*(J*ln(J) - J + 1)
>
> P = diff(psi, F)
> P = R*P*R.T
>
> L = inner(P, grad(v))*dx
> a = derivative(L, u, du)
> solve(L==0, u, bcs, J=a)
> plot(u, mode="displacement", interactive=True)
>
> ** Affects: ffc
>     Importance: Undecided
>         Status: New
>
> --
> You received this bug notification because you are a member of FFC Core
> Team, which is subscribed to FFC.
> https://bugs.launchpad.net/bugs/897372
>
> Title:
>  FFC is extremely slow compared to SFC for this Fung-type material law
>
> Status in FEniCS Form Compiler:
>  New
>
> Bug description:
>  FFC uses a considerable amount of time (> 1h) compiling the following
>  program. The generated .h-file exceeds 90MB. Running, it uses hours
>  assembling a matrix. Using the SFC compiler, compiling is done in no
>  more than ten minutes, and then the program finishes in about ten
>  seconds.
>
>  I have similar problems with FFC and this Fung-type material law in
>  other cases, eg computing the second Piola-Kirchhoff stress tensor.
>  Then, the SFC compiled code is about 22000 times faster than FFC.
>
>  Anders
>
>
>  from dolfin import *
>
>  mesh = UnitCube(2, 2, 2)
>  V = VectorFunctionSpace(mesh, "CG", 1)
>  bcl = DirichletBC(V, (0.0, 0.0, 0.0), "near(x[0], 0.0) && on_boundary")
>  bcr = DirichletBC(V, (0.1, 0.0, 0.0), "near(x[0], 1.0) && on_boundary")
>  bcs = [bcl, bcr]
>
>  v  = TestFunction(V)
>  u  = Function(V)
>  du = TrialFunction(V)
>
>  K   = Constant(0.876)
>  C   = Constant(10.0)
>  bff = Constant(18.48)
>  bxx = Constant(3.58)
>  bfx = Constant(2.8)
>
>  I = Identity(3)
>  F = I + grad(u)
>
>  a = Expression(("x[0]*DOLFIN_PI/8"))
>  R = as_matrix([[cos(a), 0, -sin(a)], [0, 1, 0], [sin(a), 0, cos(a)]])
>
>  F = variable(R.T*F*R)
>  E = 0.5*(F.T*F - I)
>  J = det(F)
>
>  f=0; s=1; n=2
>  W = (bff*E[f,f]**2
>       + bxx*(E[n,n]**2 + E[s,s]**2 + E[n,s]**2)
>       + bfx*(E[f,n]**2 + E[n,f]**2 + E[f,s]**2 + E[s,f]**2))
>  psi = 0.5*K*(exp(W) - 1) + C*(J*ln(J) - J + 1)
>
>  P = diff(psi, F)
>  P = R*P*R.T
>
>  L = inner(P, grad(v))*dx
>  a = derivative(L, u, du)
>  solve(L==0, u, bcs, J=a)
>  plot(u, mode="displacement", interactive=True)
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/ffc/+bug/897372/+subscriptions
>