# tensor operation for elasticity

Hi,
I want to write down the Hook's law in UFL, sigma=C: e, that is, sigma_{i,j}=\sum_{k,l} C_ijkl*e_kl.

Right now, I have C as a four dimensional numpy array. How can I convert C to a rank 4 tensor and write down the UFL expression above? Thanks.

## Question information

Language:
English Edit question
Status:
Solved
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Solved by:
Shiyuan
Solved:
2013-02-06
Last query:
2013-02-06
2013-02-05
 Martin Sandve Alnæs (martinal) said on 2013-02-05: #1

Check out as_tensor.

Martin
Den 5. feb. 2013 01:46 skrev "Shiyuan" <email address hidden>
følgende:

> New question #221062 on DOLFIN:
>
> Hi,
> I want to write down the Hook's law in UFL, sigma=C: e, that is,
> sigma_{i,j}=\sum_{k,l} C_ijkl*e_kl.
>
> Right now, I have C as a four dimensional numpy array. How can I convert C
> to a rank 4 tensor and write down the UFL expression above? Thanks.
>
> --
> You received this question notification because you are a member of
> DOLFIN Team, which is an answer contact for DOLFIN.
>

 Shiyuan (gshy2014) said on 2013-02-05: #2

as_tensor(C) gives a rank-4 tensor. What about the summation:
sigma_{i,j}=\sum_{k,l} C_ijkl*e_kl

It is not a dot(), inner() or outer(). Is there a concise UFL expression for this summation? Thanks.

 Martin Sandve Alnæs (martinal) said on 2013-02-05: #3

One of the main features of UFL is generic tensor notation with implicit
summation, check
out the UFL chapter in the FEniCS book, available for download from the
fenics webpage.

Martin

On 5 February 2013 17:45, Shiyuan <email address hidden>wrote:

> Question #221062 on DOLFIN changed:
>
>
> Shiyuan is still having a problem:
> as_tensor(C) gives a rank-4 tensor. What about the summation:
> sigma_{i,j}=\sum_{k,l} C_ijkl*e_kl
>
> It is not a dot(), inner() or outer(). Is there a concise UFL expression
> for this summation? Thanks.
>
> --
> You received this question notification because you are a member of
> DOLFIN Team, which is an answer contact for DOLFIN.
>

 Shiyuan (gshy2014) said on 2013-02-06: #4

This is my solution:
C_t=as_tensor(C) #this will cast a 4 dimensional numpy array to a rank-4 tensor
stress=C_t[:,:,k,l]*e[k,l] #k, l is a pre-defined index in UFL