Forum Message

 

 

We have moved the forum to https://forum.ngsolve.org . This is an archived version of the topics until 05/05/23. All the topics were moved to the new forum and conversations can be continued there. This forum is just kept as legacy to not invalidate old links. If you want to continue a conversation just look for the topic in the new forum.

Notice

The forum is in read only mode.

Automatic differentiation unexpected behavior

More
3 years 11 months ago #2627 by Gotya
Hi all,

When I make a CoefficientFunction(x) then Diff(x) returns the expected result of 1.
However, when I make a CoefficientFunction from a GridFunction and then call Diff(x) it returns 0. Is this expected behavior?

Is there a function which I can call that returns the derivative with respect to x of a CoefficientFunction that consists of a GridFunction? Or is the only way to manually specify the derivative using Grad of the GridFunction?

In the attachments there is a small example.

Best,
Gotya
More
3 years 11 months ago #2628 by christopher
Symbolic diff uses pointer comparision and diff rules. So when you for example build a coefficientfunction cf = x*x then cf.Diff(x) = (Product rule) x*x.Diff(x) + x.Diff(x) * x = (Pointer comparison) x*1 + 1*x.
The gridfunction doesn't "know" anything about the cf x.
You can build the derivative you want by using the chain rule, for example:
Code:
func = sin(gf) dfunc = func.Diff(gf) * grad(gf)
Best
The following user(s) said Thank You: Gotya
Time to create page: 0.102 seconds