-
Notifications
You must be signed in to change notification settings - Fork 160
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
Constant and derivative #3261
Constant and derivative #3261
Conversation
firedrake/constant.py
Outdated
def _unicode_format_firedrake_constant(self, o): | ||
"""Format a Firedrake constant.""" | ||
i = o.count() | ||
var = "💩" | ||
if len(o.ufl_shape) == 1: | ||
var += UC.combining_right_arrow_above | ||
elif len(o.ufl_shape) > 1 and self.colorama_bold: | ||
var = f"{colorama.Style.BRIGHT}{var}{colorama.Style.RESET_ALL}" | ||
return f"{var}{subscript_number(i)}" | ||
|
||
|
||
# This monkey patches ufl2unicode support for Firedrake constants | ||
Expression2UnicodeHandler.firedrake_constant = _unicode_format_firedrake_constant |
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.
I don't think that's the right place to add ufl2unicode
support for constants, see my comment here.
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.
I agree, this code is disgusting. I envision my code as being a temporary workaround current issues whilst someone with more UFL skills fixes this upstream.
7b83329
to
852e8ed
Compare
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.
I think this is basically fine, but a better mathematician than me should really take a look at this.
I think eventually we might want to consider dropping support for differentiating wrt constants. Downstream users that rely on this functionality (hopefully not many!) could do the replacement themselves.
Co-authored-by: Connor Ward <c.ward20@imperial.ac.uk>
Description
Improvements to some oversights with the changes I previously made to
Constant
.derivative
now substitutes the symbolic constant back into the form after taking the derivative. This allows the user to perform solves with the resultant form, which was not the case before.ufl2unicode
support forConstant
via various hackery.