Using continious funstions to define conductivity tensor

Hi all,

I am following one of the fenics examples for the tensor-weighted-poisson. In there, they use the MeshFunction objects to represent elements of the conductivity tensor, i.e., the conductivity is constant actors a single mesh cell. I was wondering if there is a way to modify this example so that the conductivity tensor elements would vary across a single cell, e.g., by using Function objects instead. My hope is that I can set up a continious interpolated function across the simulation domain, instead of splitting things into cells.

Yes, there are various ways of doing this.
See for instance Define two materials C tensor - #7 by dokken

Thank you for the response, but I think I am still quite confused about the solution that you mentioned. In that example, the tensor C is evaluated to be constant across each cell and the only spacial dependence of the tensor comes from two subdomains. What I was hoping to do is to construct a tensor C that would depend on the spatial coordinates (x[0] and x[1]) and that can go into the typical fenics PDE solution scheme for tensor-weighted equations:

a = inner(C*grad(u), grad(v))*dx
L = f*v*dx
solve(a == L, u, bc)

The elements of C are defined as functions and can vary across each cell, e.g.:
\begin{pmatrix} C_{00}\left ( x, y \right ) & C_{01}\left ( x, y \right ) \\ C_{01}\left ( x, y \right ) & C_{11}\left ( x, y \right ) \end{pmatrix}=\begin{pmatrix} x^2+y^2 & x \\ x & x^2+y^2 \end{pmatrix}
Note standard notaion that x is x[0] and y is x[1].

Thoughts/ideas?

Simply use

x =dolfin.SpatialCoordinate(mesh)
r2 = x[0]**2+x[1]**2
D = dolfin.as_tensor(((r2,x[0]),(x[0], r2 )))

@dokken Thank you. I didn’t realize that expressions can be just simply used as values in the tensor.