Mutable FunctionSpaces#5243
Draft
achanbour wants to merge 9 commits into
Draft
Conversation
connorjward
requested changes
Jul 14, 2026
connorjward
left a comment
Contributor
There was a problem hiding this comment.
This doesn't provide any mechanism for migrating functions when the topology changes. Without that something like
vom = VertexOnlyMesh(...)
V = FunctionSpace(vom, ...)
f = Function(V)
vom.migrate(...)
assemble(f*dx) # will be absolute gibberish…o achanbour/mutable-fs-on-vom
connorjward
requested changes
Jul 17, 2026
|
|
||
| self._topology_version = 0 | ||
| if self._topology_is_mutable: | ||
| self._topology_step_sfs = {} |
Contributor
There was a problem hiding this comment.
Probably shouldn't be in this PR unless you end up touching it somewhere.
Contributor
Author
There was a problem hiding this comment.
I left it here for now given that the FS caching mechanism (which is what this PR is about) relies on the versioning of the mesh's topology.
achanbour
force-pushed
the
achanbour/mutable-fs-on-vom
branch
from
July 17, 2026 13:09
55f80cf to
88add8a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR describes my first attempt at making
FunctionSpaces mutable. Note: this currently only works for FS defined on VOMs (the generalisation to arbitrary meshes is TBD).The main idea is that FS need to detect somehow that the VOM, against which they were built, has changed (topologically). We want this is to be done lazily. This is because there are usually a large number of FS laying around and there is no straightforward way of keeping track through all of them: from the mesh's perspective,
FunctionSpaces with the same element, DoF layout etc. share the same_shared_dataobject cached on the mesh - aFunctionSpaceDataobject carrying all topology-derived numerical data.Using this cached attribute allows us to invalidate the FS at the mesh level. At the same time, we want each FS to detect this invalidation and to refresh itself upon on its own first use after the VOM has mutated. Mutating the VOM does the following:
topology._shared_data.clear()topology._topology_version += 1The lazy FS rebuild is implemented here as follows:
_shared_datawhich, upon detecting a topology version mismatch, causes all the attributes to be recomputed (refresh_shared_datacallsget_shared_datawhich returns a newFunctionSpaceDataobject with the updated data)_shared_dataTo trigger the indirect rebuild, cached properties such as
cell_node_list(derived from_shared_data) were turned into version-gated properties (which execute steps 2-4 upon a version mismatch). This required changing these properties from being@cached_propertyto being plain@propertywith their own caching mechanism. All other, non-topology-related properties were kept as@cached_property.Final note: The version gating mechanism described above has only been implemented for
FunctionSpaceand has not been ported yet intoMixedFunctionSpace.