NameError: name 'CellFunction' is not defined

I wanted to solve the Maxwell’s equations for electrostatics .However I always get this error NameError: name 'CellFunction' is not defined. I have attached relevant part of my code.Can somebody please point out a solution.

from fenics import *
from mshr import *
from math import *
from matplotlib import *
from dolfin import *

Create Geometry

Rair = 5
cyltot = Cylinder(Point(0,0,10),Point(0,0,0),Rair,Rair)
mesh_tot = generate_mesh(cyltot,64)
vtkfile = File(‘Mesh.pvd’)
vtkfile << mesh_tot
V = FunctionSpace(mesh,‘P’,1)

Finding Subdomains

rho = Expression(‘sqrt(x[0]*x[0] + x[1]*x[1] + x[2]*x[2])’,degree=2)

tol = 1E-14
class Copper(SubDomain):
def inside(self, x, on_boundary):
return rho <= 1 + tol

class Air(SubDomain):
def inside(self, x, on_boundary):
return rho >= 1 - tol

materials = CellFunction(‘size_t’,mesh_tot,0)
Subdom_cu = Copper()
Subdom_air = Air()
Subdom_cu.mark(materials,1)
Subdom_air.mark(materials,0)
plot(materials,interactive=True)

Following the changelog, this function is deprecated, and the new usage should be:
materials = MeshFunction("size_t", mesh, mesh.topology().dim(), 0).
Note that there are several other changes, especially wrt. plotting. I would for instance use

import matplotlib.pyplot as plt
plot(materials)
plt.show()
3 Likes