Integrating over the domain

I am implementing a hyperelastic model in fenics. I define:

dx = Measure(‘dx’,domain=mesh, subdomain_data=matdomain)

My strain energy formula is simply:

psi = 1/2mu( inner(F,F) - 3 - 2ln(det(F)) ) + 1/2lmbda*(1/2*(det(F)**2 - 1) - ln(det(F)))

After running the solver, I want to compute the total strain energy. Is this the appropriate method:

psi_total = assemble(psi*dx)

The results look reasonable, this is more of a sanity check. Apologies if this question is addressed elsewhere I am new to the forum.

1 Like

Looks right to me, assuming F is defined in terms of the unknown displacement Function that ends up with the solution to the nonlinear problem.

P.S. You can format code nicely here by enclosing it in backticks; look up “Markdown” for detailed formatting information.

Thanks! And thanks for the tip :slight_smile: F is defined as:

d = len(u)
I = Identity(d)             # Identity tensor
F = I + grad(u)             # Deformation gradient
F = variable(F)

where

W = FunctionSpace(mesh, TH)
u = Function(W)