This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

Can anyone provide an updated code for the hollow cylinder example in section 1.4.2 of the fenics book?

0 votes

Hello,

I am trying to run the example in section 1.4.2 of the fenics book to create a hollow cylinder. Here is the code:

Theta = pi/2
a, b = 1, 5.0
nr = 10 # divisions in r direction
nt = 20 # divisions in theta direction
mesh = Rectangle(a, 0, b, 1, nr, nt, "crossed")

x = mesh.coordinates()[:,0]
y = mesh.coordinates()[:,1]
s = 1.3

def denser(x, y):
return [a + (b-a)*((x-a)/(b-a))**s, y]

x_bar, y_bar = denser(x, y)
xy_bar_coor = numpy.array([x_bar, y_bar]).transpose()
mesh.coordinates()[:] = xy_bar_coor
plot(mesh, title="stretched mesh")

def cylinder(r, s):
return [rnumpy.cos(Thetas), rnumpy.sin(Thetas)]

x_hat, y_hat = cylinder(x_bar, y_bar)
xy_hat_coor = numpy.array([x_hat, y_hat]).transpose()
mesh.coordinates()[:] = xy_hat_coor
plot(mesh, title="hollow cylinder")
interactive()

I have already realized that 'Rectangle' needs to be changed to 'RectangleMesh'. However, I can't figure out what to do with the next error I get when I run the code:

Traceback (most recent call last):
File "/home/sophia/Documents/fenics_files/cylinder.py", line 17, in
xy_bar_coor = numpy.array([x_bar, y_bar]).transpose()
NameError: name 'numpy' is not defined

Does anyone have a version of this code that works for fenics 1.2.0?

Thank you,
Sophia

asked Aug 17, 2013 by sophia FEniCS Novice (150 points)

Use code environment, please. The provided code is unreadable.

Did you

import numpy

?

Thank you, Jan, that was the problem. For some reason I thought numpy was included in the dolfin package.

Yeah, DOLFIN also sometimes imports numpy but does not put anything of it into dolfin module namespace.

2 Answers

+2 votes
 
Best answer

Add

import numpy

somewhere above a line you're referencing numpy on.

answered Aug 20, 2013 by Jan Blechta FEniCS Expert (51,420 points)
0 votes

Didi you install the numpy package yet? it seems that problem.

answered Aug 18, 2013 by jying FEniCS User (2,020 points)
...