I want to implement an example of left ventricle in the paper, here is the constitutive law.
I have the displacement of the structure and I want to calculate the feedback force. Here is my code.
from fenics import *
def first_PK_stress(u): # input the displacement
# Parameters
C = Constant(10.0) # C = 10kPa
bf = Constant(1.0)
bt = Constant(1.0)
bfs = Constant(1.0)
I = Identity(len(u))
F = I + grad(u) # nabla_grad is used someplaces. I think grad is correct.
E = 0.5*(F.T*F - I)
e1 = as_vector([ 1.0, 0.0, 0.0 ])
e2 = as_vector([ 0.0, 1.0, 0.0 ])
e3 = as_vector([ 0.0, 0.0, 1.0 ])
E11, E12, E13 = inner(E*e1, e1), inner(E*e1, e2), inner(E*e1, e3)
E21, E22, E23 = inner(E*e2, e1), inner(E*e2, e2), inner(E*e2, e3)
E31, E32, E33 = inner(E*e3, e1), inner(E*e3, e2), inner(E*e3, e3)
Q = bf*E11**2 + bt*(E22**2 + E33**2 + E23**2 + E32**2) \
+ bfs*(E12**2 + E21**2 + E13**2 + E31**2)
Wpassive = C/2.0 * (exp(Q) - 1)
FF = variable(F)
# CC = variable(F.T*F)
# S = 2*diff(Wpassive,CC) # calculate the second PK stress tensor
return diff(Wpassive, FF) # Calculate the first PK stress tensor
mesh = UnitCubeMesh(10,10,10)
V = VectorFunctionSpace(mesh,"P",2)
u = TrialFunction(V)
v = TestFunction(V)
disp = Function(V)
# Define the constutive law for the left ventricle
F = inner(first_PK_stress(disp), grad(v))*dx + inner(u, v)*dx
a = lhs(F)
L = rhs(F)
A = assemble(a)
b = assemble(L)
The information is :
Traceback (most recent call last):
File "test_force.py", line 45, in <module>
b = assemble(L)
File "/usr/lib/python3/dist-packages/dolfin/fem/assembling.py", line 198, in assemble
dolfin_form = _create_dolfin_form(form, form_compiler_parameters)
File "/usr/lib/python3/dist-packages/dolfin/fem/assembling.py", line 58, in _create_dolfin_form
function_spaces=function_spaces)
File "/usr/lib/python3/dist-packages/dolfin/fem/form.py", line 23, in __init__
self.subdomains, = list(sd.values()) # Assuming single domain
ValueError: not enough values to unpack (expected 1, got 0)
I think the reason is the variational formulation generate an empty form L
: Form([])
, but I don’t know why.