-
-
Notifications
You must be signed in to change notification settings - Fork 182
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
Add functionalities to cache data when interpolating on nonmatching meshes #2414
Add functionalities to cache data when interpolating on nonmatching meshes #2414
Conversation
Would it be possible to implement this not using a class? For example, the interpolate method could return a map containing the cache which could then be passed as an optional argument. |
Another (perhaps better) option would be to bring the expensive call to |
There's also opportunity of improvement in eval, which is quite expensive (evaluating basis at interpolation points). |
@jhale I guess it is possible to avoid using a class. Out of |
@massimiliano-leoni A core design principles in DOLFINx is to avoid implicit state (as much as possible) and to prefer functional approaches as much as possible. I think what you want to achieve could be more straightforwardly achieved by making the expensive call to |
@jhale I understand that it's a design decision, but I was wondering for my own knowledge what the reason behind the decision is! |
Avoiding, where possible, objects with (mutable) state leads to simpler code (not need to check state), avoids inconsistent state, avoids hidden memory 'leaks' (not technically leaks, but objects that might hold a lot of memory and which isn't obvious to the user), and thread safety. This is why we prefer explicit approaches first. Sometimes it might then be appropriate to build a convenience class/function on top of the low-level implementation. For this particular case, it seems simplest to me that the user calls |
@garth-wells Thanks for the explanation. I implemented it the way you and @jhale suggested. Is it better now? |
Pretty much I think, just a few style things I left in the review. Another thing we do is try to make expensive calls explicit, so I don't think we would include a code path where the data is not pre-computed in this low-level interface. |
…imiliano-leoni/dolfinx into mleoni/cache-repeated-interpolation
I think this is close. How does it all look from the Python interface? |
I think I updated it accordingly. At least, the CI is satisfied. I suggest someone quickly goes through my additions because I'm not very familiar with pybind11 and writing Python wrappers so I might have overlooked something. |
After merging #2245 dolfinx can interpolate discrete functions defined on different meshes. This is, however, quite costly.
This PR adds a class that performs this interpolation caching as much data as possible so that interpolating again between the same two functions, when their meshes haven't moved, is much cheaper.
Some timings for the same example as in the discussion of #2245 [mesh with 750'000 cells]