Is it possible to do symbolic differentiation of a vector-valued CoefficientFunction? For example, I would like to compute the gradient of the vector-valued
u_exact = CoefficientFunction((sin(2*pi*x)*cos(2*pi*y) , -cos(2*pi*x)*sin(2*pi*y) ))
and obtain a tensor-valued CoefficientFunction.
Best regards
Gonzalo
You can differentiate a tensor wrt another tensor. Make a CF
coords for the vector (x,y). The MakeVariable
ensures that the coords
object is not optimized out.
coords = CF( (x,y) ).MakeVariable()
x_, y_ = coords
u_exact = CF((sin(2*pi*x_)*cos(2*pi*y_) , -cos(2*pi*x_)*sin(2*pi*y_) ))
print (u_exact.Diff(coords).shape)
outputs
(2, 2)
1 Like
Thank you, Joachim. This is quite useful!