Assemble function takes long time after including stabilization method

I try to solve the incompressible flow with Marangoni effect. Following is how I formulate the problem. However, It seems take long time to assemble the matrix after including supg stabilization. Also, the Expression function also take time. Is there any way to improve this?
def dtang_T(T_n,T):
dtang = Expression((‘Tx’, ‘Ty’),Tx=project(T_n.dx(0),T,solver_type=‘cg’, preconditioner_type=‘hypre_amg’),
Ty=project(T_n.dx(1),T,solver_type=‘cg’, preconditioner_type=‘hypre_amg’),degree=2)
return dtang

Res = rho*(1.0/dt)*(u-u0) + rho*dot(u0,grad(u)) - (mu)*div(grad(u)+grad(u).T) + grad(p) 
tau_supg = ((2.0/dt1)**2 + (2.0*sqrt(inner(u0,u0))/h)**2 + 9*(4.0*mu_l/rho_l/(h**2))**2)**(-0.5)
F_supg = (tau_supg*inner(Res,rho*(1.0/dt)*(v-u0)+rho*dot(u0, grad(v))-mu*div(grad(v)+grad(v).T)+ grad(q)) \
        +inner(grad(u),(sqrt(inner(u0,u0))*h)*grad(v)))*dx
F1 = rho*dot((u - u0) / dt, v)*dx + \
     rho*inner(v, dot(grad(u), u0))*dx \
     + (mu)*inner(grad(v), grad(u)+grad(u).T)*dx \
     - inner(div(v), p)*dx +inner(q, div(u))*dx- dot(-0.000083*dtang_T(T_n,T),v)*ds1 \
     +F_supg
a_u1 = lhs(F1)
L_u1 = rhs(F1)

A_u1=assemble(a_u1, tensor=A_u1)
b_u1=assemble(L_u1, tensor=b_u1)
1 Like

One thing that will speed things up is to wrap all floats as constants. And secondly, why do you project t_n and not use it directly in your form?

Thanks for the suggestion. If directly use tangent gradient of T_n in the form like this
F1 = rho*dot((u - u0) / dt, v)dx +
rho
inner(v, dot(grad(u), u0))*dx
+ (mu)*inner(grad(v), grad(u)+grad(u).T)*dx
- inner(div(v), p)*dx +inner(q, div(u))dx- dot(-0.000083T_n.dx,v)*ds1
+F_LS

I got the error “TypeError: unsupported operand type(s) for *: ‘float’ and ‘method’”. Maybe I should put in a different way?

In the text you posted you are not using T.dx(0)