Linear elasticity with spatially-varying force

I am trying to solve a modified problem of the linear elastic equations, similar to the linear elastic tutorial.

Instead of applying a constant force f=(0,0,-\rho*g) like in the tutorial, my force f = \lambda \nabla N is spatially varying. I am solving the equation \nabla \cdot \sigma - \lambda \nabla N = 0, where \lambda is a known constant and N(x,y,z) is the (known) 3D spatially-varying data.

Having very little FE/FEniCS experience, I’m not sure how to pass this data to the solver. First of all, is it possible to approximate the function \nabla N from N (which is just data, without an analytical expression) in FEniCS? I have previously been doing this in MATLAB using finite differences. Secondly, any pointers on how to implement the equation \nabla \cdot \sigma - \lambda \nabla N = 0 in FEniCS would be much appreciated.

Hi,
are the values N known on the nodes defining your mesh ? If so, you could define N to be a Function on a CG1 FunctionSpace and assign the corresponding values to the array of dofs.
Then, just replace the constant f of the tutorial with the UFL expression f=-lamb*grad(N) (note that the corresponding force is actually f=-\lambda\nabla N with a minus sign since in elasticity we solve for \nabla \dot \sigma + f=0. You don’t need to change anything else in the tutorial to solve for this equation

1 Like

Thanks for your answer, that’s really helpful!
The values of N are known on the mesh nodes, however I’m not sure how to do this:

because I just have one value at each node, not one value per dof? I have tried:

V = fem.VectorFunctionSpace(domain, ("CG", 1))
N = fem.Function(V)
N.vector()[:] = N

where the right-hand-side N is an ndarray, but this gives the following error:
err

Hi rosecollet,

I think the correct command to assign an array is

f.x.array[:]=f1

Best,
Carrot

1 Like

So it is, thank you!