RuntimeError: Invalid parameter: form_compiler

Hello Everyone,

I am new to Fenics, I installed the Fenics it was working for me a day before. However, I am getting this run time error (attached image) which was not there for the same code.

The used code for this test is the following

from fenics import *             #to import FEniCS library
from mshr import *               #to import library for meshing
import matplotlib.pyplot as plt  #to import matlab plotting library  
from ufl import nabla_div        #to import library for the calculation of nabla divergence


# Define Data
E = 210000.0
nu = 0.3
lambda_1 = (E*nu)/((1+nu)*(1-2*nu))
mu_1 = E/(2*(1+nu))


#Define and plot mesh
domain = Rectangle(Point(0.0, 0.0), Point(100.0, 100.0))
mesh = generate_mesh(domain, 32)
print(mesh.num_cells())
plot(mesh)
plt.show()

# Define function space
V = VectorFunctionSpace(mesh, 'P', 1)


# Define Boundary Conditions
# Dirichlet BC

tol = 1E-14

# finding nodes on bottom edge
def boundary_D_y(x, on_boundary):
    return on_boundary and near(x[1], 0, tol)

# finding node of bottom left cornor
def boundary_D_x(x, on_boundary):
    return near(x[1], 0, tol) and near(x[0], 0, tol)
   
bc_y = DirichletBC(V.sub(1), Constant(0), boundary_D_y)
bc_x = DirichletBC(V, Constant((0, 0)), boundary_D_x, method='pointwise')

#print ('here',bc_x.get_boundary_values())
#print ('here_',bc_y.get_boundary_values())
bcs = [bc_y, bc_x]


# Neumann BC
# finding nodes on top edge
class boundary_N_y(SubDomain):
    def inside(self, x, on_boundary):
        return on_boundary and near(x[1], 100, tol)

# Definition changes in the ds for Neuman BC
boundary_markers = MeshFunction("size_t", mesh, mesh.topology().dim()-1, 0)
B_N_Y = boundary_N_y()
B_N_Y.mark(boundary_markers, 1)

ds = Measure('ds', domain=mesh, subdomain_data=boundary_markers)


# Define stress and strain relations with displacement
def epsilon(u):
    return 0.5*(nabla_grad(u) + nabla_grad(u).T)
   
def sigma(u):
    return lambda_1*nabla_div(u)*Identity(d) + 2*mu_1*epsilon(u)
   

# Solution definition and
u = TrialFunction(V)
d = u.geometric_dimension()
v = TestFunction(V)
T = Constant((0, 100))     # Applied load
a = inner(sigma(u), epsilon(v))*dx
L = dot(T, v)*ds(1)

u = Function(V)
solve(a == L, u, bcs)

I have checked recent updates in my system and the following one is the recent and seems to me that its linked with the Fenics

2024-03-04 16:40:40 install libdolfin2019.2gcc13:amd64 <none> 2019.2.0~legacy20240219.1c52e83-2~ppa1~jammy1

Thank you
Roshan

See Announcement: ufl_legacy and legacy dolfin

To start, the line

from ufl import nabla_div        #to import library for the calculation of nabla divergence

is wrong. You must use ufl_legacy.

Thank you for your response
I checked the link and try to follow the instructions to upgrade ufl with ufl_legacy

The repository 'https://ppa.launchpadcontent.net/libadjoint/ppa/ubuntu jammy Release' does not have a Release file.

Please help me to upgrade ufl with ufl_legacy

Thank you
Roshan

Not sure why you would want to use that ppa. libadjoint : “libadjoint developers” team says the latest build was 352 weeks ago, which is surely before jammy’s release.

I am facing the same problem. I checked the provided code with ufl_legacy but it is throwing the same error.
Please help me to fix the issue.
Code used:

from fenics import *             #to import FEniCS library
from mshr import *               #to import library for meshing 
import matplotlib.pyplot as plt  #to import matlab plotting library  
from ufl_legacy import nabla_div        #to import library for the calculation of nabla divergence


# Define Data
E = 210000.0
nu = 0.3
lambda_1 = (E*nu)/((1+nu)*(1-2*nu))
mu_1 = E/(2*(1+nu))


#Define and plot mesh
domain = Rectangle(Point(0.0, 0.0), Point(100.0, 100.0))
mesh = generate_mesh(domain, 32)


# Define function space 
V = VectorFunctionSpace(mesh, 'P', 1)


# Define Boundary Conditions
# Dirichlet BC

tol = 1E-14

# finding nodes on bottom edge
def boundary_D_y(x, on_boundary):
    return on_boundary and near(x[1], 0, tol)

# finding node of bottom left cornor
def boundary_D_x(x, on_boundary):
    return near(x[1], 0, tol) and near(x[0], 0, tol)
    
bc_y = DirichletBC(V.sub(1), Constant(0), boundary_D_y)
bc_x = DirichletBC(V, Constant((0, 0)), boundary_D_x, method='pointwise')

#print ('here',bc_x.get_boundary_values())
#print ('here_',bc_y.get_boundary_values())
bcs = [bc_y, bc_x]


# Neumann BC
# finding nodes on top edge
class boundary_N_y(SubDomain):
    def inside(self, x, on_boundary):
        return on_boundary and near(x[1], 100, tol)

# Definition changes in the ds for Neuman BC
boundary_markers = MeshFunction("size_t", mesh, mesh.topology().dim()-1, 0)
B_N_Y = boundary_N_y()
B_N_Y.mark(boundary_markers, 1)

ds = Measure('ds', domain=mesh, subdomain_data=boundary_markers)


# Define stress and strain relations with displacement
def epsilon(u):
    return 0.5*(nabla_grad(u) + nabla_grad(u).T)
    
def sigma(u):
    return lambda_1*nabla_div(u)*Identity(d) + 2*mu_1*epsilon(u)
    

# Solution definition and 
u = TrialFunction(V)
d = u.geometric_dimension()
v = TestFunction(V)
T = Constant((0, 100))     # Applied load
a = inner(sigma(u), epsilon(v))*dx
L = dot(T, v)*ds(1)

u = Function(V)
solve(a == L, u, bcs)

Error:

Thank you,
Manish

How did you install DOLFIN? And what platform are you running on?

In general @dparsons might be able to comment as he might have seen this before.

I am using Ubuntu 20.04 and used the following way to install Fenics.
As mentioned on the Fenics website

https://fenicsproject.org/download/archive/

sudo apt-get install software-properties-common
sudo add-apt-repository ppa:fenics-packages/fenics
sudo apt-get update
sudo apt-get install fenics

Thank you,
Manish

I have also followed the same approach.

I don’t specifically know what the problem is, but it looks like the kind of problem you might get if the libraries have lost their chain of linking. meaning they might need to be rebuilt. I’ll test on a fresh installation when I get time later.

In the meantime I strongly recommend upgrading your installation if possible. Ubuntu 20.04 is now quite old, and it is increasingly difficult to maintain packages for it. You will likely have no such error with the latest Ubuntu LTS release.

l am getting same error with Ubuntu 22.04 LTS

I can reproduce the error in a fresh installation of Ubuntu 20.04. Thanks for letting us know Ubuntu 22.04 is also affected. Will investigate further.

1 Like

I can’t identify anything obviously wrong with your script. You’re implementing an elasticity calculation. I suggest comparing against the elasticity demos, which use a slightly different implementation (they are also found in /usr/share/dolfin/demo-python/documented/).

I understood you’re just starting with fenics. I recommend proceeding with the latest version of fenics (fenicsx, dolfinx) rather than legacy fenics unless you specifically need the mixed domain functionality which was recently released in legacy dolfin.

Thank you for your kind reply
The suggested elasticity demos are working perfectly fine with my installation.
However, my code using ufl library is still showing the same error.
Due to unavoidable circumstances, I cannot use (fenicsx, dolfinx).

You simply can’t use ufl, you must use ufl_legacy. If the code that imports ufl is not your own, a simple grep and/or search and replace may help in you in identifying which parts of the code still have the wrong import. Even better, report to the developers of the library you are using about ufl vs ufl_legacy.

The offending line (in dolfin) would be Bitbucket

 p.update(dict(parameters["form_compiler"]))

where parameters is l.12

from dolfin.cpp.parameter import parameters

that is, Bitbucket wrapping Bitbucket
form_compiler is supposed to be defined in ffc_default_parameters(). Apparently it got removed for some reason. It looks as if dolfin.cpp.parameter.parameters is bypassing dolfin.parameter.__init__. And yet these files in dolfin haven’t changed since 2018.

I wasn’t able to test the current debian build earlier. Testing now, the test script runs without error. The report error appears to be isolated to the Ubuntu 20.04 (and 22.04) builds. It might be that the PPA packages need to be rebuilt.

I have implemented the suggestions of using ufl_legacy instead of ufl. But it was showing the same problem. Then, I removed the mshr library and used the mesh option of dolfin RectangleMesh, and it working now. The code is also working with the imported mesh using with Mesh(...).

Thus, I think there is an issue in the linking of the mshr library.
The following modifications were made in the code, and the working code is given below.

Line 2 mshr library not imported
Line 4 replaced ufl with ufl_legacy
Line 15 used RectangleMesh to create the mesh.
Line 16 and 17 commented the previous method of creating mesh.

Working code:

from fenics import *             #to import FEniCS library
#from mshr import *               #to import library for meshing
import matplotlib.pyplot as plt  #to import matlab plotting library  
from ufl_legacy import nabla_div        #to import library for the calculation of nabla divergence


# Define Data
E = 210000.0
nu = 0.3
lambda_1 = (E*nu)/((1+nu)*(1-2*nu))
mu_1 = E/(2*(1+nu))


#Define and plot mesh
mesh = RectangleMesh(Point(0.0, 0.0), Point(100.0, 100.0),10,10)
#domain = Rectangle(Point(0.0, 0.0), Point(100.0, 100.0))
#mesh = generate_mesh(domain, 32)
#print(mesh.num_cells())
#plot(mesh)
#plt.show()


# Define function space
V = VectorFunctionSpace(mesh, 'P', 1)

# Define Boundary Conditions
# Dirichlet BC

tol = 1E-14

# finding nodes on bottom edge

def boundary_D_y(x, on_boundary):
    return on_boundary and near(x[1], 0, tol)

# finding node of bottom left cornor
def boundary_D_x(x, on_boundary):
    return near(x[1], 0, tol) and near(x[0], 0, tol)
  
bc_y = DirichletBC(V.sub(1), Constant(0), boundary_D_y)
bc_x = DirichletBC(V, Constant((0, 0)), boundary_D_x, method='pointwise')

#print ('here',bc_x.get_boundary_values())
#print ('here_',bc_y.get_boundary_values())
bcs = [bc_y, bc_x]


# Neumann BC
# finding nodes on top edge
class boundary_N_y(SubDomain):
    def inside(self, x, on_boundary):
        return on_boundary and near(x[1], 100, tol)

# Definition changes in the ds for Neuman BC
boundary_markers = MeshFunction("size_t", mesh, mesh.topology().dim()-1, 0)
B_N_Y = boundary_N_y()
B_N_Y.mark(boundary_markers, 1)

ds = Measure('ds', domain=mesh, subdomain_data=boundary_markers)

# Define stress and strain relations with displacement
def epsilon(u):
   return 0.5*(nabla_grad(u) + nabla_grad(u).T)

def sigma(u):
    return lambda_1*nabla_div(u)*Identity(d) + 2*mu_1*epsilon(u)

# Solution definition and
u = TrialFunction(V)
d = u.geometric_dimension()
v = TestFunction(V)
T = Constant((0, 100))     # Applied load

a = inner(sigma(u), epsilon(v))*dx
L = dot(T, v)*ds(1)

u = Function(V)
solve(a == L, u, bcs)

That’s a good analysis. It’s probably a good idea to avoid using mshr if you don’t really need it, since it’s not really supported anymore. Nevertheless I’ve uploaded mshr for rebuild. You should find your scripts work now.