-
-
Notifications
You must be signed in to change notification settings - Fork 80
Add arity property to form
#470
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
base: main
Are you sure you want to change the base?
Changes from 10 commits
bafefcd
20a08b8
8b443ba
37e430e
d2632ae
7f7ad3b
d2ece42
e516988
0a92da5
4f2993b
73547e4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -340,6 +340,37 @@ def empty(self): | |
| """Returns whether the form has no integrals.""" | ||
| return len(self.integrals()) == 0 | ||
|
|
||
| @property | ||
| def arity(self) -> int | None: | ||
| """Arity of the form. | ||
|
|
||
| Note: | ||
| Mixed function spaces are supported if the parts are not mixed in a single integral. | ||
|
|
||
| Returns: | ||
| Number of arguments if all integrals share the argument count, otherwise None. | ||
| """ | ||
| if not self._integrals: | ||
| return 0 | ||
|
|
||
| from ufl.algorithms.analysis import extract_terminals_with_domain | ||
|
|
||
| arity = None | ||
| for integral in self._integrals: | ||
| args, _, _ = extract_terminals_with_domain(integral.integrand()) | ||
|
schnellerhase marked this conversation as resolved.
Outdated
|
||
|
|
||
| if len(set(arg.part() for arg in args)) > 1: | ||
| raise RuntimeError("Arity does not support mixed arguments in an integral.") | ||
|
Comment on lines
+362
to
+363
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What case does this cover?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Works around the problems arising from having mixed arguments present in the form https://github.com/FEniCS/ufl/pull/470/changes#diff-40318d7ac6b526c958053e25f90768d68e58d7c26e6479fe580f7420f53de86fR146-R159. Probably this is too restrictive. But I am not quite sure what the right checks should be here instead. |
||
|
|
||
| _arity = max((arg.number() + 1 for arg in args), default=0) | ||
|
|
||
| if arity is None: | ||
| arity = _arity | ||
| elif arity != _arity: | ||
| return None | ||
|
|
||
| return arity | ||
|
|
||
| def ufl_domains(self): | ||
| """Return the geometric integration domains occuring in the form. | ||
|
|
||
|
|
||
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.
Do we need this here to avoid circular imports?
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.
Yes exactly. Also used in other parts of
form.pyin the same manner.