3D vectors, tensors on 2D mesh

Hello everyone,

I am just trying to evolve my 3D code to 2D without imposing any mathematical formulation. For example, I have 3D hyperelasticity code and I want to use it also in 2D plane stress problem. I want to use 2D rectangular mesh but I want to define my deformation gradient with (3,3) by equating the F(3,3)=1.0. So at the end I will have 3 dimensional vector for displacement with Uz=0. Is it possible to do that in fenics ?

By the way I tried such a thing

mesh = RectangleMesh(Point(0., 0.), Point(10, 10), 10, 10, "crossed")
V = VectorFunctionSpace(mesh, "Lagrange", 1,dim=3)

it creates 3 dimensional displacement but when I try grad(u) it gives (3,2) matrix.

Thanks.

You can use the as_matrix function to construct entry-by-entry matrices symbolically in UFL. See, e.g.,

from dolfin import *
mesh = RectangleMesh(Point(0., 0.), Point(10, 10), 10, 10, "crossed")
V = VectorFunctionSpace(mesh, "Lagrange", 1,dim=3)

u = Function(V)
gradu = grad(u)

# Manually add extra column and add identity for 3x3 F:
F = as_matrix([[gradu[0,0]+1.0, gradu[0,1]    , 0.0],
               [gradu[1,0]    , gradu[1,1]+1.0, 0.0],
               [gradu[2,0]    , gradu[2,1]    , 1.0]])

# Alternte using indices:
#F = as_matrix([[gradu[i,j]+float(i==j) for j in range(0,2)]+[float(i==2),]
#               for i in range(0,3)])

from ufl import shape
print(shape(F))

That’s right kamensky ! Thank you, I will use as_tensor definition.