Hello,
As the title say, calling this compiler take some time. Actually, I have to perform it thousand times in my code due to the projection on my FE space. I was wondering if there were a way to make it quicker ? Because what I understood was that it is a “preprocessor” that generates a C++ files containing the variationnal form, and then dolfin read this file to assemble the matrix; isn’t there a way to assemble the matrices directly ?
Thank’s,
Eloi.
You can directly manipulate matrices through the petsc4py
API, but, in most use cases, repeated recompilation of forms can be avoided. In particular, you can prevent recompilation after changing the values of numerical constants by wrapping them as Constant
s. For example:
from dolfin import *
mesh = UnitIntervalMesh(1)
# Compiles every time (if you start with a clean cache):
print("Not using a Constant.")
for i in range(11,17):
print(assemble(i*dx(domain=mesh)))
c = Constant(0)
# Compiles only the first time:
print("Using a Constant.")
f = c*dx(domain=mesh)
for i in range(11,17):
c.assign(i)
print(assemble(f))
Actually I have a density function that changes at each iteration, not constants. Is it Possible to accelerate that ?
Let add more precision. The compiler is called when I need to project on my FE space the following function:
\Nabla mu = \frac{ |\Nabla u|^2 - \mu u^2}{\int_\Omega \rho u^2}
with the functions u, rho and the constant \mu changing at each step, where I perform:
u_func = Function(V)
u_func.vector().set_local(u)
rho_func = Function(VD)
rho_func.vector().set_local(rho)
dMu = Function(VD)
dMu = (dot(grad(u_func), grad(u_func)) - mu*u_func*u_func)/assemble(rho_func*u_func*u_func*dx)
dMu = project(dMu, VD)
How do I allow this to assemble the form just once ?
Thank’s !
Hello,
can you try by defining before entering the loop
u_func = Function(VD)
rho_func = Function(VD)
dMu = Function(VD)
c = Constant(1)
and then inside the loop do
u_func.vector().set_local(u)
rho_func.vector().set_local(rho)
c.assign(Constant(assemble(rho_func*u_func*u_func*dx)))
dmu = (dot(grad(u_func), grad(u_func)) - mu*u_func*u_func)/c
dMu.assign(project(dmu, VD)
also if mu is changing, define it as a Constant and assign it its new value inside the loop
Holy s*** that works ! Thanks a lot !
Do you know where is explained the way the JIT compiler works ?