precice / fenics-adapter

preCICE-adapter for the open source computing platform FEniCS
GNU Lesser General Public License v3.0
29 stars 15 forks source link

Painfully slow mapping with volumetric coupling #151

Closed boris-martin closed 9 months ago

boris-martin commented 2 years ago

Context

I'm doing a volume coupled simulation (with a f * dx term where f is read from preCICE) but the mapping makes the simulation extremely slow. I use nearest neighbor on a matching grid on the preCICE side, but the way FEniCS processes the mapping seems problematic. I assume the RBF interpolation takes a while, but it seems using the expression is slow too: the simulation solves a non-linear problem (with implicit time step) and each iteration is much slower than without preCICE, although the source term is unchanged.

Quickfix

I realized interpolating the coupling expression on a Function object reduces the overhead significantly (but not enough to my liking) So instead of doing just

read_data = precice.read_data()
precice.update_coupling_expression(flow_expr, read_data)

# Solve a problem with flow_expr * dx in the formulation

I use So instead of doing just

flow = Function(V)

read_data = precice.read_data()
precice.update_coupling_expression(flow_expr, read_data)

flow.interpolate(flow_expr)
# Solve a problem with flow * dx in the formulation

and get a significant speedup. Open questions:

Reproduce

fenics_case_slow.tar.gz

Run a simulation with 2 participants: flow-precice.py and either chemistry-precice.py or chemistry-precice-slow.py. A monolithic case chemistry.py without preCICE is given as reference.

The "slow" version with preCICE uses the custom expression in the variational problem, whereas the "fast" version interpolates the expression on a Function, which is used in the variational problem. As the name implies, it is much faster (the whole simulation is about 3-4 times faster on my computer!), although both are much slower than the monolithic code.

BenjaminRodenberg commented 9 months ago

As far as I understand we can close this issue due to https://github.com/precice/fenics-adapter/pull/152. This issue is probably somehow also related to #162. But I would treat this as a follow-up task.

I'm closing this issue @boris-martin or @IshaanDesai: Please comment, if you disagree and we can always reopen this issue.