Gravity in FEniCSx

Hi

I am working on the horizontal beam using the linear elastic dynamic equation (mass–stiffness–damping formulation).
I have a question about how to include gravity: should I explicitly apply the gravitational force in FEniCSx, or is it automatically included through the mass matrix?

In other words, does FEniCSx automatically account for the structure’s weight and apply a body force in the negative z-direction (assuming z is vertical), or do I need to add gravity manually?

You would need to add gravity to your variational form, i.e. if you are solving

\int_\Omega \sigma(u): \epsilon(v)~\mathrm{d}x = \int_\Omega \mathrm{g}\cdot v~\mathrm{d}x

where \mathbf{g}=(0,0, -\rho\cdot g) is your graviational force, which would split into the variational form

def epsilon(u):
    return ufl.sym(
        ufl.grad(u)
    )  # Equivalent to 0.5*(ufl.nabla_grad(u) + ufl.nabla_grad(u).T)


def sigma(u):
    return lambda_ * ufl.nabla_div(u) * ufl.Identity(len(u)) + 2 * mu * epsilon(u)


u = ufl.TrialFunction(V)
v = ufl.TestFunction(V)
f = fem.Constant(domain, default_scalar_type((0, 0, -rho * g)))
a = ufl.inner(sigma(u), epsilon(v)) * ufl.dx
L = ufl.dot(f, v) * ufl.dx + ufl.dot(T, v) * ds

as for instance modelled in:

for linear elasticity

1 Like