Skip to content
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

Product rule for derivative of a FormSum #45

Closed
wants to merge 3 commits into from

Conversation

pbrubeck
Copy link

@pbrubeck pbrubeck commented Nov 7, 2023

Adding the product rule for FormSum (although I know that so far we only support constant weights).

In addition, we eagerly cancel terms that are zero by checking if they depend on the variable with respect to which we are differentiating.

Also this fixes Firedrake issue #3206, as we do not return a FormSum when the variational term is the only one that depends on the differentiation variable.

if coefficient in component.coefficients()]
args += [(component * derivative(weight, coefficient, argument, coefficient_derivatives), 1)
for component, weight in zip(components, weights)
if hasattr(weight, "coefficients") and coefficient in weight.coefficients()]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if hasattr(weight, "coefficients") and coefficient in weight.coefficients()]
if isinstance(weight, BaseForm)]

# Distribute derivative over FormSum components
return FormSum(*[(derivative(component, coefficient, argument, coefficient_derivatives), 1)
for component in form.components()])
# Distribute derivative over FormSum components and weights that depend on coefficient

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't do anything if you don't also make sure the DAG visitor is aware that it needs to visit the weights during differentiation, see

nonzero_components = [(component, w) for component, w in zip(mapped_components, form.weights())
. There is a couple of things to change to support weights that are non constant, see my comment in #44.

@pbrubeck pbrubeck closed this May 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: Failing to compute the Jacobian of a FormSum
2 participants