Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Painfully slow mapping with volumetric coupling #151

Closed
boris-martin opened this issue May 13, 2022 · 1 comment
Closed

Painfully slow mapping with volumetric coupling #151

boris-martin opened this issue May 13, 2022 · 1 comment

Comments

@boris-martin
Copy link
Contributor

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:

  • Are there drawbacks to this approach? Does projecting reduce accuracy, or is that accuracy lost anyway when evaluating the expression ? Should we recommend it by default anytime the read data is not a Dirichlet BC?
  • Could this be implemented in the adapter (output a function instead of an expression directly) in a way such that performances increase ?
  • Would it be possible to completely skip the RBF part ? I assume this is trickier than it looks (see Compute CouplingExpression from point data via Minimization on P0DG function space #119 ), especially if we want it to work for weird element types (I'm using 1st order triangles so a direct mapping from preCICE to a function looks obvious, but making it general would be harder)

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
Copy link
Member

As far as I understand we can close this issue due to #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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants