RecursionError: maximum recursion depth exceeded in the ft11_magnetostatics.py example of the "Solving PDEs in Python - The FEniCS tutorial Part 1"

The tutorial is out of date. Change your Permeability class to the following:

class Permeability(UserExpression): # UserExpression instead of Expression
    def __init__(self, markers, **kwargs):
        super().__init__(**kwargs) # This part is new!
        self.markers = markers
    def eval_cell(self, values, x, cell):
        if self.markers[cell.index] == 0:
            values[0] = 4*pi*1e-7 # vacuum
        elif self.markers[cell.index] == 1:
            values[0] = 1e-5      # iron (should really be 6.3e-3)
        else:
            values[0] = 1.26e-6   # copper
11 Likes