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

How to use a Function to fill a tensor field in another problem...

0 votes

I am trying to use the result of a poisson equation (normalised electrostatic field n - unit vectors parallel to the electric field) to fill the tensorial permittivity eps_r for a second simulation.

$ \vec n = \vec E / \sqrt{ \left| \vec E \right|^2 } $

The tensor is given by:
$\varepsilon = \varepsilon_1 \vec I + \Delta\varepsilon \left( \vec n \otimes \vec n \right)$

I used an Expression for this purpose. I get how to make it return a tensor. But now I'm trying to read the values of $\vec n$ to fill the tensor.

How do you do that?

asked May 13, 2016 by cweickhmann FEniCS Novice (550 points)

1 Answer

+2 votes
 
Best answer

You can project into a suitable TensorFunctionSpace. Consider the following example.

mesh = UnitSquareMesh(16,16)

V = VectorFunctionSpace(mesh, "CG", 1)
T = TensorFunctionSpace(mesh, "CG", 2)

E = Function(V)

e1 = Constant(1.0)
delta_e = Constant(1.0)


epsilon = project(e1 * Identity(2) + delta_e * outer(E, E), T)
answered May 16, 2016 by Magne Nordaas FEniCS Expert (13,820 points)
selected May 23, 2016 by johannr

Thanks a lot! I thought of this way, but since I found neither Identity nor outer in the documentation, I went the hard and slow way using the Expression...
Am I looking in the wrong spot for functions like that? http://fenicsproject.org/documentation/dolfin/1.6.0/python/genindex.html

For defining forms you need to look at the UFL documentation (this is probably not too clear, but when importing dolfin in Python you are actually importing dolfin and ufl together). This page defines both Identity and outer (as well as other useful functions).

...