How to compute the gradient of a CF function in a BilinearForm?

Hi, I am solving a PDE on a surface, and my main code is as follows:


from netgen.occ import *
from netgen import meshing
from ngsolve import *
from ngsolve.webgui import Draw

sp = Sphere(Pnt(0, 0, 0), 1)
mesh = Mesh(OCCGeometry(sp).GenerateMesh(maxh=0.1, perfstepsend=meshing.MeshingStep.MESHSURFACE))
k = 2
fesV = VectorH1(mesh, order=k)
mesh.Curve(k)

lhs = BilinearForm(fesV)
v = fesV.TrialFunction()
w = fesV.TestFunction()
nsurf = specialcf.normal(3)
lhs += InnerProduct((grad(nsurf * v).Trace()), (grad(nsurf * w).Trace())) * ds

I would like to ask how to generate the following BilinearForm:

lhs += InnerProduct((grad(nsurf * v).Trace()), (grad(nsurf * w).Trace())) * ds

Currently, I am encountering the following error:

NgException: Operator grad not overloaded for CF class ngfem::MultMatVecCoefficientFunction

Could anyone help me with this? Thanks in advance!

What does grad mean to you on a surface? Is it the covariant gradient?

I am considering geometric evolution problems (curvature flow). Here, I need to solve for a velocity field v: Γ_h → R^3 to evolve (deform) the surface Γ_h.
However, I need to decompose the velocity into tangential and normal components and solve them separately. I may need bilinear forms similar to these two:

nsurf = specialcf.normal(3)
lhs_n += InnerProduct((grad(nsurf * v).Trace()), (grad(nsurf * w).Trace())) * ds

and

Ptau = Id(3) - OuterProduct(nsurf, nsurf)
lhs_T += InnerProduct((grad(Ptau * v).Trace()), (grad(Ptau * w).Trace())) * ds

I now understand the differentiation of the product of the vector nsurf and the vector v using the product rule:

Grad(nsurf_now) * v + Grad(v).Trace() * nsurf_now

However, I may also need to compute the matrix grad(Ptau * v).Trace() , where I need to apply the product rule to the multiplication of the matrix Ptau = Id(3) - OuterProduct(nsurf, nsurf) and the vector v.

At this point, Grad(Ptau) might be a third-order tensor. I would like to ask how to correctly apply the product rule in NGSolve to compute grad(Ptau * v).Trace().Currently, my formulation:

Grad(Ptau) * v + Ptau * Grad(v).Trace()

throws an error. I suspect the issue is with the multiplication Grad(Ptau) * v, as the operation involving a third-order tensor may not be correctly handled.

Hi Guangwei,

grad(nsurf) is supported, this gives you the Weingarten tensor.
Here is an example: 11. Computation of Curvature — NGSolve@PDESoft 2024

Have a look into publications by Michael Neunteufel, and also here 9. Shells — NGSolve 24

Joachim

1 Like

Yes, thank you for sharing, Prof. Schöberl. The code for computing Gaussian curvature using Regge finite elements is very helpful to me. I will read it carefully.