3D matrix-valued GridFunction on 2D mesh

I have a 2D mesh on which i want to define a 3D GridFunction by interpolating a CF. This works for vector-valued functions, but for matrix-valued functions I get the error
netgen.libngpy._meshing.NgException: Dimensions do not match., despite the CF and GF having the same dimensions.

from ngsolve import *

mesh = Mesh(unit_square.GenerateMesh())

f = CF((0,0,0))
F = Id(3)

fes_Vector = L2(mesh)**3
fes_Matrix = (L2(mesh)**3)**3

f_pp = GridFunction(fes_Vector)
F_pp = GridFunction(fes_Matrix)

f_pp.Interpolate(f) # -> works
F_pp.Interpolate(F) # -> netgen.libngpy._meshing.NgException: Dimensions do not match.

Thank you in advance.

I am new in NGSolve too, but you could try with

fes_Matrix = (L2(mesh, dim=3))**3
fes_Matrix = MatrixValued(L2(mesh), dim=3)

then you can give also symmetric=True

2 Likes

Thanks a lot Joachim, this worked

1 Like