fenics-tutorial icon indicating copy to clipboard operation
fenics-tutorial copied to clipboard

Update ft11_magnetostatics.py

Open benjaminknebusch opened this issue 6 years ago • 2 comments

Expression needs Cpp code to be provided use UserExpression instead

benjaminknebusch avatar Apr 05 '19 12:04 benjaminknebusch

UserExpression throws an error:

AttributeError: 'Permeability' object has no attribute '_ufl_shape'

Any ideas on a fix?

smartalecH avatar Sep 09 '19 16:09 smartalecH

It looks like in addition to changing Expression to UserExpression, you need to initialize the superclass. The child class definition should look like this:

class Permeability(UserExpression):
    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

Finally, to get the script to run with 2019.1.0, you also need to remove Interactive() and rely on pyplot (as mentioned in other PRs).

smartalecH avatar Sep 09 '19 19:09 smartalecH