This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

How to calculate a tensor at each quadrature point?

+1 vote

Dear all,

I'm trying to calculate a tensor that depends on the values of another system's solution e.g.,

C = C ( d (x))

where d(x) is the solution from another system. I want to use this C tensor later in a generic inner product for a bilinear form.
I'm doing something like:

def C(d):
M11 = (1.0-d)(math.pow(2.0d+1.0,0.5))
M12 = 0.5(1.0-d)(2.0*d+1.0)
D = np.zeros((2,2,2,2))
D[0][0][0][0] = M11
D[1][1][1][1] = M11
D[0][1][0][1] = M12
D[0][1][1][0] = M12
D[1][0][0][1] = M12
D[1][0][1][0] = M12
return as_tensor(D)

I was wondering if anyone has an idea on how to do this?

Best,
Navid

asked Jul 16, 2014 by Navid Mozaffari FEniCS Novice (510 points)

1 Answer

+1 vote

In the .ufl code you can to do something like this:

FE = FiniteElement('CG', cell, 1,)
TE = TensorElement('CG', cell, 1, shape=(2,2,2,2))    

d = Coefficient(FE)
D = Coefficient(TE)

def C(d):
  M11 = (1.0 - d)*(pow(2.0*d + 1.0, 0.5))
  M12 = 0.5*(1.0 - d)*(2.0*d + 1.0)
  D[0, 0, 0, 0] = M11 
  D[1, 1, 1, 1] = M11
  D[0, 1, 0, 1] = M12
  D[0, 1, 1, 0] = M12
  D[1, 0, 0, 1] = M12
  D[1, 0, 1, 0] = M12
   return D

regards.

answered Sep 29, 2015 by hernan_mella FEniCS Expert (19,460 points)

I just realized of the date of your question :P

Many thanks, learning new things is always good no matter when it happens.

...