fenics-tutorial
fenics-tutorial copied to clipboard
Update ft11_magnetostatics.py
Expression needs Cpp code to be provided use UserExpression instead
UserExpression throws an error:
AttributeError: 'Permeability' object has no attribute '_ufl_shape'
Any ideas on a fix?
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).