### NameError: name 'Sphere' is not defined

195
views
0
4 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

https://fenicsproject.org/olddocs/dolfin/1.4.0/python/demo/documented/csg-3D/python/documentation.html

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(g3d)
info("\nVerbose output of 3D geometry:")
info(g3d, True)

# Plot geometry

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

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

interactive()

when I compile the program I get this error message

Traceback (most recent call last):
File "sphericalshell.py", 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.

Best
Community: FEniCS Project

3
4 months ago by

Use

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)