NameError: name 'Sphere' is not defined

12 months ago by
Hi guys:

I am new to FeniCs and I am trying to create a program that uses a 3D domain. More specifically I want to create a 'punctured' sphere. I have read some documentation and some online articles and I found this link 

with a nice code that I thought I could modify. 

my attempt to create what I want is this (which is just a variation of the code showed in the above link)

from dolfin import *

# Define 3D geometry
sphere1 = Sphere(Point(0, 0, 0), 1)
sphere2 = Sphere(Point(0,0,0),0.5)

g3d = sphere1 - sphere2

# Test printing
info("\nCompact output of 3D geometry:")
info("\nVerbose output of 3D geometry:")
info(g3d, True)

# Plot geometry

plot(g3d, "3D geometry (surface)")

# Generate and plot mesh
mesh3d = Mesh(g3d, 32)
plot(mesh3d, "3D mesh")


when I compile the program I get this error message

Traceback (most recent call last):
  File "", line 5, in <module>
     sphere1 = Sphere(Point(0, 0, 0), 1)
 NameError: name 'Sphere' is not defined
Abort trap: 6

I don´t understand exactly what it means. Any help or suggestion will be highly appreciated. 

Community: FEniCS Project

1 Answer

12 months ago by


from dolfin import *
from mshr import Sphere, generate_mesh

sphere1 = Sphere(Point(0, 0, 0), 1.0)
sphere2 = Sphere(Point(0, 0, 0), 0.5)

g3d = sphere1 - sphere2

mesh3d = generate_mesh(g3d, 32)
Please login to add an answer/comment or follow this question.

Similar posts:
Search »