Projecting a dolfin dot product onto a scalar function space raises "Bus error"

In the below MWE (full MWE provided at the end), there is a UnitSquareMesh(1, 1). To the dofs of the four vertices, I am attaching the vectors [1.0, 5.0], [7.0, 1.0], [9.0, 10.0], [13.0, 5.0], respectively through a vector function u = Function(V), where V = VectorFunctionSpace(mesh, 'CG', 1), by performing the assignment

v2d = np.array(vertex_to_dof_map(V), dtype = int)

B = np.array([[1.0,5.0],[7.0,1.0],[9.0,10.0],[13.0,5.0]])

for i in range(0,len(v2d)):
  u.vector()[v2d[i]] = B[int(i/2), i%2]

Next, I am calculating the dot product I_4_int = dot(u, Cg_int*u), where Cg_int is a tensor. In order to visualize it in Paraview, I am projecting I_4_int1 = project(I_4_int,W) where W = FunctionSpace(mesh, 'P', 3). This raises the error

Calling FFC just-in-time (JIT) compiler, this may take some time.
Bus error

Complete MWE:

from dolfin import *     
import meshio
import numpy as np
import matplotlib.pyplot as plt
from scipy import linalg as la
#from ufl import * # Uncommenting this line produces the error "W = FunctionSpace(mesh, 'P', 3); TypeError: __init__() takes 3 positional arguments but 4 were given" 
                           

mesh = UnitSquareMesh(1, 1)  
mesh_coords = mesh.coordinates() 
V = VectorFunctionSpace(mesh, 'CG', 1)
W = FunctionSpace(mesh, 'P', 3)

u = Function(V)
u.interpolate(Expression(("3*x[0]", "2*x[1]"), degree=1))

dg = mesh.geometry().dim()
Ig = Identity(dg)             # Identity tensor
Fg = Ig + grad(u)
Cg_int = (Fg).T*(Fg)

v2d = np.array(vertex_to_dof_map(V), dtype = int)
d2v = np.array(dof_to_vertex_map(V), dtype = int)

B = np.array([[1.0,5.0],[7.0,1.0],[9.0,10.0],[13.0,5.0]])

for i in range(0,len(v2d)):
  u.vector()[v2d[i]] = B[int(i/2), i%2]
  print(f"mesh_coords by dof d2v[v2d[int({i}/2)]]: {mesh_coords[d2v[v2d[int(i/2)]]]}, actual mesh coords: {mesh_coords[int(i/2)]}")
  print(f"d2v[v2d[{i}]]: {v2d[d2v[i]]}, {u.vector()[v2d[i]]}: {B[int(i/2), i%2]}")
    
File("uvector.pvd")<<u
  
I_4_int = dot(u, Cg_int*u)

print(I_4_int)

I_4_int1 = project(I_4_int,W)  # Producing "Bus error" here

File("i4int.pvd")<<I_4_int1

I am not sure why it is producing a Bus error and what does it mean in this context.

There is also one more issue. Uncommenting the line from ufl import *, produces the error
W = FunctionSpace(mesh, 'P', 3) TypeError: __init__() takes 3 positional arguments but 4 were given

I have defined scalar function spaces in almost all of my other codes with from ufl import * and that never raised any issues.

Any suggestions would be greatly appreciated.

Thanks.

  1. Running your complete MWE runs with no errors on my computer, so not too sure what leads to the Bus error when you run it. In case it is of any value, I am running Ubuntu linux 20.04 with fenics 2019.1.0 installed using conda.

  2. Since the dolfin package imports the necessary objects from the ufl package, running from dolfin import * is sufficient to use UFL for your PDE code. For instance, the __init__.py file for the dolfin package includes this section relating to imports from ufl:


    Therefore, you shouldn’t run from ufl import * in your code.

2 Likes

Hi @nav ,

Got the second point.
The code runs on every machine except mine. I ran a gdb backtrace and it turns out that the error is stemming from lapack.