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.
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
FiniteElement
python wrapper #3542base: main
Are you sure you want to change the base?
Add
FiniteElement
python wrapper #3542Changes from 15 commits
5406935
00fe740
d5b32f9
3a3a565
891f9ab
ccdae0f
7790a9e
625cd62
de6ba0a
ddbcc17
22aa1cf
05f850e
c186199
765110b
b7cea4b
df6f9ce
b2cb0d0
a7239ba
4686468
a0798b1
02d03f2
f77dd43
6f35a39
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This creates a new
FiniteElement
wrapper each time. Would it be better to wrap the element in the initialiser?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would require an additional state variable of the wrapper class
FunctionSpace
keeping track of theFiniteElement
, which contradicts it being a wrapper to provide access only to thecpp_object
, as we would then have twofinite_element
's around to manage.Also the
FiniteElement
object itself is only a wrapper, it performs no computations or produces additional states, so it's fine to be created whenever we expose aFiniteElement
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps this is naive, but could https://docs.python.org/3/library/functools.html#functools.cached_property be used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems to add exactly what we would need here - however I am not convinced we satisfy the
part of it. Calling the constructor of
FiniteElement
is very lightweight and would then compete with the cached lookup.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With non-cached approach calling the constructor each time, won't this break expected outcome of
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another aspect to consider regarding
cached_property
:In the current implementation, what is the lifespan of all these instantiated
FiniteElement
s?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I look through the Python layer, this situation/question crops up a lot. Perhaps this can be addressed in a future PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good, will file an issue when this gets merged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In
dolfinx.mesh.Mesh
, we store the Python-wrappers: https://github.com/FEniCS/dolfinx/blob/main/python/dolfinx/mesh.py#L275-L278I guess we need to decide on a unified structure for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Returning, possibly many, different instances that wrap the same C++
FiniteElement
is clumsy.cached_property
looks like a neat way to deal with it.The issue should be fixed in this PR, not later.