firedrakeproject / firedrake

Firedrake is an automated system for the portable solution of partial differential equations using the finite element method (FEM)
https://firedrakeproject.org
Other
482 stars 157 forks source link

Compute norm of assembled derivative #3651

Closed LeeLizuoLiu closed 1 day ago

LeeLizuoLiu commented 3 days ago

I may want to know, whether there is a way to compute the norm of the assembled derivative? I tried norm(assemble(derivative(inner(grad(v), grad(v))*dx, w)), it doesn't work.

         > OK here's a significantly more minimal case. This extracts the failing operation from the adjoint, so we're now down to a failing assemble with no adjoint aspect.
from firedrake import *

n = 4
mesh = UnitSquareMesh(n,n)
V = VectorFunctionSpace(mesh, 'CG', 1)
R = FunctionSpace(mesh, 'R', 0)
# R = FunctionSpace(mesh, 'CG', 1)  - works if you use a "normal" function space
W = V*R
w = Function(W)
v, lamb0 = split(w)
assemble(derivative(inner(grad(v), grad(v))*dx, w))

Originally posted by @LeeLizuoLiu in https://github.com/firedrakeproject/firedrake/issues/2830#issuecomment-2187540974

connorjward commented 3 days ago

My suspicion is that it is something to do with the fact that the input to norm(...) here is a Cofunction instead of a Function and hence there may be mathematical reasons why this doesn't work.

@colinjcotter @pbrubeck do either of you know?

colinjcotter commented 2 days ago

Yes, the derivative is a cofunction not a function. Cofunctions have norms, obtained by Riesz map to function and then taking norm of the corresponding function.


From: Connor Ward @.> Sent: 26 June 2024 10:07 To: firedrakeproject/firedrake @.> Cc: Cotter, Colin J @.>; Mention @.> Subject: Re: [firedrakeproject/firedrake] Compute norm of assembled derivative (Issue #3651)

My suspicion is that it is something to do with the fact that the input to norm(...) here is a Cofunction instead of a Function and hence there may be mathematical reasons why this doesn't work.

@colinjcotterhttps://github.com/colinjcotter @pbrubeckhttps://github.com/pbrubeck do either of you know?

— Reply to this email directly, view it on GitHubhttps://github.com/firedrakeproject/firedrake/issues/3651#issuecomment-2191195429, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABOSV4XR35EIC77NPCK23E3ZJKAFNAVCNFSM6AAAAABJ4K4DGWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCOJRGE4TKNBSHE. You are receiving this because you were mentioned.Message ID: @.***>

LeeLizuoLiu commented 2 days ago

Thanks, do I need to derive the Riesz map manually?

colinjcotter commented 2 days ago

No, it is a method of Cofunction

On 26 Jun 2024, at 17:04, Lizuo Liu @.***> wrote:



Thanks, do I need to derive the Riesz map manually?

— Reply to this email directly, view it on GitHubhttps://github.com/firedrakeproject/firedrake/issues/3651#issuecomment-2192072562, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABOSV4R765JAQ77FCQSQWNDZJLRBNAVCNFSM6AAAAABJ4K4DGWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCOJSGA3TENJWGI. You are receiving this because you were mentioned.Message ID: @.***>

LeeLizuoLiu commented 1 day ago

Great, thanks! I successfully implemented it.