### Is there anyway to use mixed element and split functions with rank 3 ?

175
views
0
6 months ago by
Hi,

Trying to create mixed elements with the following python code :
****************
V = VectorFunctionSpace(mesh, "CG", 2) #u_i
VV = TensorFunctionSpace(mesh,'CG',2)  #eps_ij
VVV = TensorFunctionSpace(mesh,'CG',2,shape=(2,2,2)) #chi_ijk
W = MixedFunctionSpace([V,VV,VVV])
(u,u_chi2,u_chi3) = TrialFunctions(W)
(w,w_chi2,w_chi3) = TestFunctions(W)
******************
I got the following error :
***
Don't know how to split functions with sub functions of rank 3 (yet).
Traceback (most recent call last):
File "test.py", line 35, in <module>
(u,u_chi2,u_chi3) = TrialFunctions(W)at_raw(*message))
....
ufl.log.UFLException: Don't know how to split functions with sub functions of rank 3 (yet).
***

( Note I also have a warning : 'MixedFunctionSpace' has been deprecated in FEniCS version 2016.1. )

Should I split 'by hand' my tensor function (so that I could note use tensor operations to define my variational form) ?

Any suggestions or ideas are welcome

Community: FEniCS Project

3
6 months ago by
For MixedFunctionSpace, the new way to do this is to create a MixedElement, then create a FunctionSpace from the MixedElement.  As for splitting, I get the same error in 2017.2.  However, you can always just put tensors together yourself as a fall-back, using the as_tensor() function, as follows:

from dolfin import *

mesh = UnitSquareMesh(10,10)

VE = FiniteElement('CG',mesh.ufl_cell(),2)
WE = MixedElement([VE,VE,VE])
W = FunctionSpace(mesh,WE)

w = Function(W)

e11,e22,e12 = w.split()

e = as_tensor([[e11,e12],
[e12,e22]])
​

This also demonstrates the use of MixedElement.  There is an analogous as_vector() function as well.

ok, I use your suggestion and implement this :
*****************************************************
VVV1 = TensorFunctionSpace(mesh,'CG',2)
VVV2 = TensorFunctionSpace(mesh,'CG',2)
W = MixedFunctionSpace([V,VV,VVV1,VVV2])

(u,u_chi2,u_chi3_1,u_chi3_2) = TrialFunctions(W)
(w,w_chi2,w_chi3_1,w_chi3_2) = TestFunctions(W)

def fonctionChi3(chi3_1,chi3_2):
return as_tensor( [ [ [chi3_1[0,0],chi3_1[0,1] ] , [chi3_1[1,0],chi3_1[1,1] ] ] ,
[ [chi3_2[0,0],chi3_2[0,1] ] ,       [chi3_2[1,0],chi3_2[1,1] ]] ] )
*************************************************

It seems to work (I have to validate the solution now ...)

Thanks !!!
written 6 months ago by arnaudl
0
6 months ago by
I don't know if this works for your tensor functions but I guess you should try to generate the space like this:

V = VectorElement("CG", mesh.ufl_cell(), 2)
VV = TensorElement("CG", mesh.ufl_cell(), 2)
VVV = TensorElement("CG", mesh.ufl_cell(), 2)
ME = FunctionSpace(mesh, MixedElement([V,VV,VVV]))

In fact I want
V to deal with vector
VV to deal with tensor of rank 2
VVV to deal with tensor of rank 3 ( note the "shape=(2,2,2)" in the code).
By doing
VVV = TensorElement("CG", mesh.ufl_cell(), 2)
don't you, by default, use tensor of rank 2 ?
written 6 months ago by arnaudl

V = VectorElement("CG", mesh.ufl_cell(), 2)
VV = TensorElement("CG", mesh.ufl_cell(), 2)
VVV = TensorElement("CG", mesh.ufl_cell(), 2,shape=(2,2,2))
ME = FunctionSpace(mesh, MixedElement([V,VV,VVV]))

?
written 6 months ago by Lukas O.
With this code it returns the same errror  :
*******************************
Don't know how to split functions with sub functions of rank 3 (yet)
****************************
written 6 months ago by arnaudl