Trying to simulate with 2 differents subdomains leads to bus errors

Hello people,
I’m quite a new user to Fenics and try to run some FEM on a complex mesh made of two materials. I started from an existing basis which works fine.
I installed fenics from the ubuntu repository.
I’m reading a 3d xdmf file, and defined two subdomains subdomains = MeshFunction('size_t', mesh, 3)
Somewhere the energy density is defined for a standard NeoHookean material:

du = TrialFunction(V)
v  = TestFunction(V)
u  = Function(V)
B  = Constant((0.0, 0.0, 0.0))
I = Identity(3)
E, nu = 10.0, 0.27
mu, lmbda = Constant(E/(2*(1 + nu))), Constant(E*nu/((1 + nu)*(1 - 2*nu)))
F = I + grad(u)             # Deformation gradient
C = F.T*F                   # Right Cauchy-Green tensor
Finv=inv(F)
Ic = tr(C)
J  = det(F)
n = J*Finv.T*N
# Stored strain energy density (compressible neo-Hookean model)
psi = (mu/2)*(Ic - 3) - mu*ln(J) + (lmbda/2)*(ln(J))**2
Pi = psi*dx - dot(B, u)*dx
F = derivative(Pi, u, v)
J = derivative(F, u, du)
# Solve variational problem
solve(F == 0, u, bcs, J=J)

This works. Now, first problem, if I multiply Pi: Pi = 10*psi*dx - dot(B, u)*dx or Pi = Constant(10)*psi*dx - dot(B, u)*dx, I get a bus error. (i.e. runtime error)
I don’t understand why.
Also if I try to split the domain:

dx_ = Measure('dx', subdomain_data=subdomains)
Pi = psi*dx_(0) +psi*dx_(1) - dot(B, u)*dx

This also raise a bus error.
What I am doing wrong ?

Can you reproduce this error with a built in mesh (say a cube)?

Yes, I still get bus error with a simple BoxMesh

Could you please make your MWE reproducable? I cannot reproduce it as Im missing several key definitions, i.e.:

from dolfin import *
mesh = UnitCubeMesh(5,5,5)
V = VectorFunctionSpace(mesh, "CG", 1)


du = TrialFunction(V)
v  = TestFunction(V)
u  = Function(V)
B  = Constant((0.0, 0.0, 0.0))
I = Identity(3)
E, nu = 10.0, 0.27
mu, lmbda = Constant(E/(2*(1 + nu))), Constant(E*nu/((1 + nu)*(1 - 2*nu)))
F = I + grad(u)             # Deformation gradient
C = F.T*F                   # Right Cauchy-Green tensor
Finv=inv(F)
Ic = tr(C)
J  = det(F)
n = J*Finv.T*N

bcs = [DirichletBC(V, (0,0,0), "on_boundary")]
# Stored strain energy density (compressible neo-Hookean model)
psi = (mu/2)*(Ic - 3) - mu*ln(J) + (lmbda/2)*(ln(J))**2
Pi = psi*dx - dot(B, u)*dx
F = derivative(Pi, u, v)
J = derivative(F, u, du)
# Solve variational problem
solve(F == 0, u, bcs, J=J)

returns

  File "bus_error.py", line 18, in <module>
    n = J*Finv.T*N
NameError: name 'N' is not defined

Yes, sure, here is a whole file:

from dolfin import *
import numpy as np 

# Optimization options for the form compiler
parameters["form_compiler"]["cpp_optimize"] = True
ffc_options = {"optimize": True, \
               "eliminate_zeros": True, \
               "precompute_basis_const": True, \
               "precompute_ip_const": True}


mesh=BoxMesh(Point(0.0, 0.0, 0.0),Point(1.0, 1.0, 1.0),20,20,20)
V = VectorFunctionSpace(mesh, "Lagrange", 1)
N = FacetNormal(mesh)

# Mark boundary subdomians
boundxmin=mesh.coordinates()[:,0].min()
boundxmax=mesh.coordinates()[:,0].max()
boundymin=mesh.coordinates()[:,1].min()
boundymax=mesh.coordinates()[:,1].max()
boundzmin=mesh.coordinates()[:,2].min()
boundzmax=mesh.coordinates()[:,2].max()

left =  CompiledSubDomain("near(x[0], side) && abs(x[2])< diam&& on_boundary", side = boundxmax, diam=0.1*(boundzmax-boundzmin)/2)
c = Expression(("0.0", "0.0", "0.0"),degree=3)
bcl = DirichletBC(V, c, left)
bcs = [bcl]

class myAirChamber(SubDomain):
        def inside(self,x,on_boundary):
          return on_boundary and \
              not(near(x[0],boundxmin)) and not(near(x[0],boundxmax)) and \
                  not(near(x[1],boundymin)) and not(near(x[1],boundymax)) and \
                      not(near(x[2],boundzmin)) and not(near(x[2],boundzmax))
          

class OmegaSheet(SubDomain):
        def inside(self,x,on_boundary):
          return x[1]<=0.5
                  
class OmegaNet(SubDomain):
        def inside(self,x,on_boundary):
          return x[1]>=0.5
subdomains = MeshFunction('size_t', mesh, 3)
# Mark subdomains with numbers 0 and 1
subdomainSheet = OmegaSheet()
subdomainSheet.mark(subdomains, 0)
subdomainNet = OmegaNet()
subdomainNet.mark(subdomains, 1)

# Define functions
du = TrialFunction(V)            # Incremental displacement
v  = TestFunction(V)             # Test function
u  = Function(V)                 # Displacement from previous iteration
B  = Constant((0.0, 0.0, 0.0))  # Body force per unit volume
T  = Constant((0.0,  0.0, 0.0))  # Traction force on the boundary

# Kinematics
d = u.geometric_dimension()
I = Identity(d)             # Identity tensor

# Elasticity parameters
E, nu = 10.0, 0.27
mu, lmbda = Constant(E/(2*(1 + nu))), Constant(E*nu/((1 + nu)*(1 - 2*nu)))


p=0.01
print()
print('pressure: ',p)
#T  = Constant((0.0, p, 0.0))  # Body force per unit volume
F = I + grad(u)             # Deformation gradient
C = F.T*F                   # Right Cauchy-Green tensor
Finv=inv(F)

# Invariants of deformation tensors
Ic = tr(C)
J  = det(F)
n = J*Finv.T*N

# Stored strain energy density (compressible neo-Hookean model)
psi = (mu/2)*(Ic - 3) - mu*ln(J) + (lmbda/2)*(ln(J))**2
pr=Constant((p))

boundaries = MeshFunction("size_t", mesh,mesh.topology().dim()-1, 0)
boundaries.set_all(0)
bottom_bound=myAirChamber()
bottom_bound.mark(boundaries, 1)
ds_region = Measure('ds')[boundaries]
dx_ = Measure('dx', subdomain_data=subdomains)

##Let's try this
Pi = psi*dx_(0) +psi*dx_(1) - dot(B, u)*dx - dot(u,-pr*n)*ds_region(1)#use inverse normal

# Compute first variation of Pi (directional derivative about u in the direction of v)
F = derivative(Pi, u, v)
# Compute Jacobian of F
J = derivative(F, u, du)
# Solve variational problem
solve(F == 0, u, bcs, J=J,
            form_compiler_parameters=ffc_options,
               solver_parameters={
                "newton_solver":{\
                  "relaxation_parameter":0.5,
                  "relative_tolerance":1e-6 ,
                  "maximum_iterations":100, 
                } })

I cannot reproduce your error with the stable Docker image.

I also cant reproduce it with any of the docker images (stable:latest or dev:latest)

That’s annoying. Probably means that some libraries are incompatibles.
After running gdb, it turns out error is thrown in lapack. Here is the stack

#0  0x00007ffff36383d0 in dsymv_U_HASWELL () from /lib/x86_64-linux-gnu/liblapack.so.3
#1  0x00007fffdc5ca663 in DOUBLE_solve1 () from /home/rcharron/.local/lib/python3.8/site-packages/numpy/linalg/_umath_linalg.cpython-38-x86_64-linux-gnu.so
#2  0x00007fffdf08eb85 in generic_wrapped_legacy_loop () from /home/rcharron/.local/lib/python3.8/site-packages/numpy/core/_multiarray_umath.cpython-38-x86_64-linux-gnu.so
#3  0x00007fffdf09a414 in ufunc_generic_fastcall () from /home/rcharron/.local/lib/python3.8/site-packages/numpy/core/_multiarray_umath.cpython-38-x86_64-linux-gnu.so
#4  0x000000000056c5d1 in _PyEval_EvalFrameDefault ()
#5  0x00000000005f6226 in _PyFunction_Vectorcall ()
#6  0x00000000005f55f2 in PyObject_Call ()
#7  0x00007fffdee0f564 in array_implement_array_function () from /home/rcharron/.local/lib/python3.8/site-packages/numpy/core/_multiarray_umath.cpython-38-x86_64-linux-gnu.so

I guess a solution would be to use docker

Which lapack are you using?

ls -l /lib/x86_64-linux-gnu/liblapack.so.3
ls -l /etc/alternatives/liblapack.so.3-x86_64-linux-gnu

Might be worth trying a different lapack.

Notice also you’re using a local installation of numpy. That can cause havoc with your ubuntu installation.

Thanks for your answers, I cannot access the same machine right now, but on another machine with the docker image, it works. So maybe I should report this as a bug somewhere.