Maximum recursion depth exceeded

Hello, I am trying to simulate 3D cantilever beam using UFL form and Mixed function space, but when I am trying to enforce clamped boundary conditions, i received that error,

Here is my code:

from dolfin import *
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
from matplotlib.patches import Rectangle
import numpy as np
from ufl import *
from ufl.classes import *
from ufl.algorithms import *
# Problem definition
L = 5;
W = 0.2;
t=0.2;
mesh = BoxMesh(Point(0, 0, 0), Point(L, W, W), 10, 3, 3)
V = FiniteElement("CG", mesh.ufl_cell(), 2) # displacements
VV = FiniteElement("CG", mesh.ufl_cell(), 1)  # relaxed strains
VVV=FiniteElement("DG", mesh.ufl_cell(), 0)  # Lagrange multipliers
MX = FunctionSpace(mesh, MixedElement(V,VV,VVV))
# Define boundary condition
tol = 1E-14
left  = CompiledSubDomain("near(x[0], 0) && on_boundary")
null= Constant((0.0,0.0,0.0))
bc1=DirichletBC(MX,null,left)
RecursionError: maximum recursion depth exceeded

Your issue is that you are using wildcard import on both ufl and dolfin (+ ufl.classes and ufl.algorithms). Rule of thumb is that you should never use more than one wildcard import.
By removing from ufl import * and from ufl.classes import * your code compiles.

1 Like

Hi, thank you dear Dokken for your advice, another problem is when I remove ufl import * in my code, I can’t define indices in order to compute strain and stresses and other tensor calculations!

Import ufl without wildcard import, i.e. import ufl and use ufl.functionname(input)

1 Like