Hey,
i have been trying to implement a PDE for Fiber Orientation. The output should be a 3x3 Tensor so i defined a TensorFunctionSpace with shape 3x3 both for Orientation o and velocity u.
Nevertheless, when solving the nabla_grad(u).T FEniCs recognizes o as a higher rank tensor (above 2).
Why is that? Did i accidentally specified it somewhere?
Here is my code:
from __future__ import print_function
from fenics import *
from mshr import *
import numpy as np
T = 5.0 # final time
num_steps = 100 # number of time steps
dt = T / num_steps # time step size
eps = 0.01 # diffusion coefficient
# Read mesh from file
mesh = UnitSquareMesh(8, 8, "left/right") #creating 3x3 tensor on 2d mesh
# Define function space for velocity
W = TensorFunctionSpace(mesh, 'P', 1, shape = (3,3))
V = TensorFunctionSpace(mesh, "Lagrange", 2, shape = (3,3))
#Define boundaries
inflow = 'near(x[0], 0)'
walls = 'near(x[1], 0) || near(x[1], 1)'
#Define boundary conditions
u_D = Expression('1 + x[0]*x[0] + 2*x[1]*x[1]', degree=2)
o_D = np.zeros([3,3])
bco_inflow = DirichletBC(W, o_D, inflow)
bco_noslip = DirichletBC(W, o_D, walls) Constant((0,0,0))
bco = [bco_noslip]
#Define Test-function
v = TestFunction(W)
# Define functions for velocity and orientations
u = TrialFunction(W) #velocity
o = TrialFunction(V) #orientation
o_n = Function(V) #orientatin at next time step
#Define source terms
def symepsilon(u):
return 0.5*(nabla_grad(u) + nabla_grad(u).T) #symmetric part of gradient of velocity
def asymepsilon(u):
return 0.5*(nabla_grad(u) - nabla_grad(u).T) #antisymmetric part of gradient of velocity
def fourth(o):
return inner(o, o)
#Define expressions used in variational form
Lamba = Constant(0.5) #assume Lenght to Thickness ratio is between 0 an 1
#eps = Constant(eps) #for symmetric and antisymmetric part of velocity
D = Constant(0.003) #tendency of fibers to adopt an isotropic orientation state
delta = Identity(dim = 2)
#Define variational Problem
F = ((-0.5*v*(inner(asymepsilon(u), skew(o))- inner(skew(o), asymepsilon(u)))) + \
(0.5*v*Lambda*(inner(symepsilon(u), sym(o)) + inner(sym(o), symepsilon(u)) - 2*inner(symepsilon(u), fourth(o)))) + \
(2*D*v*(delta - 3*(o))))
I get the error message:
Transposed is only defined for rank 2 tensors.
---------------------------------------------------------------------------
UFLException Traceback (most recent call last)
<ipython-input-6-ee03bdbfc5bd> in <module>
69
70 F = ((-0.5*v*(inner(asymepsilon(u), skew(o))- inner(skew(o), asymepsilon(u)))) + \
---> 71 (0.5*v*Lambda*(inner(symepsilon(u), sym(o)) + inner(sym(o), symepsilon(u)) - 2*inner(symepsilon(u), fourth(o)))) + \
72 (2*D*v*(delta - 3*(o))))
73 #Weak form first without impulse bilance; stress tensor
<ipython-input-6-ee03bdbfc5bd> in asymepsilon(u)
53
54 def asymepsilon(u):
---> 55 return 0.5*(nabla_grad(u) - nabla_grad(u).T) #antisymmetric part of gradient of velocity
56
57 def fourth(o):
~/anaconda3/envs/fenicsproject/lib/python3.6/site-packages/ufl/exproperators.py in _transpose(self)
350 """Transpose a rank-2 tensor expression. For more general transpose
351 operations of higher order tensor expressions, use indexing and Tensor."""
--> 352 return Transposed(self)
I know this will probably be a pretty simple question but i am new to FEniCs and struggling a bit with the math.
Thanks in advance