Measure triggers recompile with subdomain data

Hello,

I just stumbled across something (for me) unexpected in 2019.2.0.dev0 (so I don’t know if it is still relevant in DolfinX).

I have a domain with a lot of subdomains defined via a mesh function. Integrating over each of these subdomains always triggers an ffc recompile while I would not expect that. More specifically I define my measure as below and with that I can integrate over a subdomain with id subdomain_id via

ds = df.Measure("ds")(subdomain_data=mesh_function, domain=mesh)
df.assemble(df.Constant(1) * ds(subdomain_id))

but this will trigger a new compiliation for each new subdomain_id as the ID goes into the form signature as can be seen here in the UFL source code.

As a workaround I now create a subdomain mask mesh function that is 1 inside the subdomain and 0 outside which triggers the jit only once as the ID doesn’t change anymore. This creates some overhead but is fast enough for me.

I found an older related question here. I would however expect that the jit does not run again just because the ID changed. Is there a reason it is like that or is there a better way as a work around?

Many thanks,
Jo

I’ve fixed this in; Group integrals with common integrand in IntegralData by jorgensd · Pull Request #92 · FEniCS/ufl · GitHub
However, we are waiting for firedrake to propagate this change through their code.

It is not likely that this will be fixed for legacy DOLFIN, but hopefully it will be fixed in DOLFINx soon.

1 Like

Nice. Thanks a lot for the confirmation. I don’t expect a back port of this and I’m looking forward to adopt DOLFINx in the future!