Meshes with subdomains - broken tutorial

I am trying to run the tutorial Generating meshes with subdomains. In Fenics 2018 I get a RecursionError, as was already remarked in Cannot create domain-dependent expression
Apperently one should replace Expression with UserExpression in the tutorial. But then I get the Error: ‘Permeability’ object has no attribute ‘_ufl_shape’.

What are the appropiate modifications in the tutorial to make it run with fenics 2018?

Thank You!

2 Likes

It runs for me if I change the Expression definition to

# Define magnetic permeability
#class Permeability(Expression):
class Permeability(UserExpression):
    def __init__(self, markers, **kwargs):
        ####### ADDED ##########
        super(Permeability, self).__init__(**kwargs)
        ########################
        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

and also modify the plotting at the end to be

# Hold plot
#interactive()
from matplotlib import pyplot as plt
plt.show()
3 Likes

Hi @Thomas
Consider using the new vtkplotter. E.g.:

# Plot solution
from vtkplotter.dolfin import plot
plot(A_z, at=0, N=2, # draw on the first of 2 renderers
     lw=0,           # no linewidth of mesh
     bg='white',
     isolines={'n':20, 'lw':1.5, 'c':'black'})
plot(B, at=1)        # draw on the second renderer


which also allows to draw isolines (in the plot above are hardly visible). Choosing R=2.5:

1 Like

Hi @marcomusy,
Please can you tell me how to install the vtkplotter. I am installing using

pip install vtkplotter

But it is getting installed in conjunction with python3.6 . I am using the fenics using python2.7 version. And I can’t run the fenics using python3.6. I wish to link the vtkplotter with python2.7 . Your suggestions would be helpful.

Thanks & Regards,
Peter

Hi @Peter_James
you may try with:
python -m pip install vtkplotter
or:
pip2.7 install vtkplotter

or you can manually install it with these commands:

git clone https://github.com/marcomusy/vtkplotter.git
cd vtkplotter
pip install .

I have not tested the dolfin module on older versions of python/dolfin, so I hope it will work, if not please let me know.
Cheers
Marco

vtk plotter works with the docker installation of FENICS?

it should, but I never tried myself, I not familiar with docker.