### heterogeneous / position-dependent problems

125
views
0
3 months ago by
I'm trying to solve a nonlinear elasticity problem where I would like the energy density to depend on spatial position.  The nonlinearity is not relevant for this question; one could think of a linear problem with the coefficients being a function of spatial coordinate.

Here is the code snippet for my homogeneous problem:
def W(y):
E, nu = 10.0, 0.3
mu, lmbda = Constant(E/(2*(1 + nu))), Constant(E*nu/((1 + nu)*(1 - 2*nu)))
psi = (mu/2)*(tr(F.T*F) - 3) - mu*ln(det(F)) + (lmbda/2)*(ln(det(F)))**2
return psi

Pi = W(y)*dx ​

I tried simply using "def W(x,y):" and "Pi=W(x,y)*dx", but this gives me the error NameError: name 'x' is not definedNameError: name 'x' is not defined at "Pi=W(x,y)*dx".

The only example of a spatially-varying problem that I could find was here:
but this is for the special case of 2 materials where you pick one or the other.  I also looked at the UFL manual but did not find anything that helped me.

I suppose that I could hard-code the form of $W(x,y)$ into $Pi$ rather than using a separate function, but I use $W$ elsewhere in my code so I prefer to have it defined in a single place.

Thanks for any suggestions.
Community: FEniCS Project

3
3 months ago by
may be this will help: define x like this
x = SpatialCoordinate(mesh)​

Thanks!  This works perfectly for my setting.
written 3 months ago by K D
3
3 months ago by
Hello,
if your modulus has a known analytical expression with respect to the position x you can use an Expression to define it such as :
E = Expression("10+2*x[0]+3*x[1]", degree=1)​
Otherwise, if it comes from a previous FE computation you can define it as a Function
Check also this tutorial
Thanks!  The tutorial is particularly useful for my future plan.
written 3 months ago by K D