### How to build a tensor in a mesh projecting a matrix (2x2)

182
views
0
5 months ago by
Hi guys I am working on a project and I need to build a tensor in a mesh by projecting a (2x2) matrix, is this possible to do in FENICS? how would I project the matrix? Thank you in advance for your time.
Community: FEniCS Project

5
5 months ago by
You can define a tensor Expression and then project it on a TensorFunctionSpace. Consider something like this:

 ​from dolfin import *

# Mesh and function space
mesh = UnitSquareMesh(5, 5)
V = TensorFunctionSpace(mesh, "CG", 1, shape=(2,2), symmetry=True)  # symmetry parameter is optional

# Projection
exp = Expression((('x[0]', 'sin(x[1])'),('sin(x[1])', 'x[1]')), degree=1)
T = project(exp, V)

Also you can project a tensor defined as an ufl object of the ListTensor class using the as_tensor function:

# Projection
exp1 = Expression('x[0]', degree=1)
exp2 = Expression('x[1]', degree=1)
T = project(as_tensor([[exp1, 0.0],[0.0, exp2]]), V)