Smart way to define Neumann boundary conditions for an elasticity-problem

Hello everyone,

I’m a new user of Fenics and I can’t find a simple way to define boundary conditions. I have a linear elasticity problem with pure Neumann boundary conditions. I apply exact expressions of stresses \sigma_{ij} on the external boundary. So, when we talk about the linear term in the weak formulation \int_{ \partial\Omega } (\sigma \cdot n) \cdot v, I’m going to substitute exacte functions for each component of tensor.

The best code would be

n = FacetNormal(mesh)
L = dot( dot( sigma, n ), v )*ds

but I don’t understand how to define a tensor of Expressions. Of cause, I can calculate each term of the final sum, but maybe you know a “smarter” way for this?

In general, we use Expressions to define Dirichlet conditions, for example

u_D = Expression(’1 + x[0]*x[0] + 2*x[1]*x[1]’, degree=2)

but in my case the functions aren’t expressed as polynomials, so there will be a small error after the interpolation in the FE space. I would like to apply exacte values of the functions instead of their FE representations.
How can I do it?

And the third question. Can we use a python (instead of C++) expression of functions in the Expression?

Thank you for your attention!

For applying Neumann BCs, it’s possible to avoid Expressions altogether. You can access the spatial coordinate associated with a given mesh in UFL via

x = SpatialCoordinate(mesh)

This can then be used to define components of a tensor using the as_tensor function, e.g.,

s00 = # Something in terms of `x`
s01 = # ...
s11 = # ...
sigma_BC = as_tensor([[s00,s01],
                      [s01,s11]])

(Or, if you are doing verification starting from an exact displacement solution, you could define the displacement in terms of x, then plug it into the definition of \sigma to get sigma_BC, letting UFL handle all the spatial derivatives.) This is sufficient for a Neumann BC that enters into the variational formulation through a ds integral. The one limitation of this approach is that functions defined this way cannot be interpolated or used to define a DirichletBC.