### How to interpolate or project a strain rate tensor into a TensorFunctionSpace?

164

views

0

Hi,

I'm having trouble figuring out how to interpolate or project a strain rate tensor into a TensorFunctionSpace. I thought it would be very straightforward but I'm getting multiple errors with different things.

This gives me an error because as_tensor can only take 2 arguments

I'm having trouble figuring out how to interpolate or project a strain rate tensor into a TensorFunctionSpace. I thought it would be very straightforward but I'm getting multiple errors with different things.

This gives me an error because as_tensor can only take 2 arguments

```
QTS = TensorFunctionSpace(mesh,'CG',3)
dudx, dudy, dudz = gradu[0].dx(0) , gradu[0].dx(1) , gradu[0].dx(2)
dvdx, dvdy, dvdz = gradu[1].dx(0) , gradu[1].dx(1) , gradu[1].dx(2)
dwdx, dwdy, dwdz = gradu[2].dx(0) , gradu[2].dx(1) , gradu[2].dx(2)
sij=project(as_tensor( (dudx,0.5*(dudy+dvdx),0.5*(dudz+dwdx)) , (0.5*(dvdx+dudy),dvdy,0.5*(dvdz+dwdy)) , (0.5*(dwdx+dudz),0.5*(dwdy+dvdz),dwdz) ) ,QTS)
```

And then this:

```
#### TENSORS #####
QTS = TensorFunctionSpace(mesh,'CG',3)
def Sij(u):
return 0.5*(nabla_grad(u)+transpose(nabla_grad(u)))
sij = project(Sij(v0),QTS)
```

gives me this error:

File "HMGTENSOR.py", line 89, in Sij

return 0.5*(nabla_grad(u)+transpose(nabla_grad(u)))

File "/scratch/anaconda2/envs/fenicsproject/lib/python2.7/site-packages/ufl/operators.py", line 119, in transpose

return Transposed(A)

File "/scratch/anaconda2/envs/fenicsproject/lib/python2.7/site-packages/ufl/tensoralgebra.py", line 112, in __init__

error("Transposed is only defined for rank 2 tensors.")

File "/scratch/anaconda2/envs/fenicsproject/lib/python2.7/site-packages/ufl/log.py", line 171, in error

raise self._exception_type(self._format_raw(*message))

ufl.log.UFLException: Transposed is only defined for rank 2 tensors.

Aborted (core dumped)

Community: FEniCS Project

Please login to add an answer/comment or follow this question.

This is what I was trying before but I get an error when I try to project Sij to the TensorFunctionSpace, is there any way around this?

somewhere, you can see the size of your linear systems.

I reduced the orders of all your function spaces to 1, i.e.

and the code runs without errors.

Just for a quick check:

returns 268119.

That's a lot, I guess, since the corresponding mass matrix for projection is of size 268119

^{2}If the results are acceptable with lower order function spaces is up to your judgment, I did not check the results.