dolfin team mailing list archive
-
dolfin team
-
Mailing list archive
-
Message #18724
[Question #117931]: Transforming mesh coordinates
New question #117931 on DOLFIN:
https://answers.launchpad.net/dolfin/+question/117931
I am trying out the script in section 5.2 of the FEniCS tutorial, with the code:
----------------------------------
from dolfin import *
import numpy
Theta = pi/2
a, b = 1, 5.0
nr = 10 # divisions in the r direction
nt = 20 # divisions in the theta direction
mesh = Rectangle(a, 0, b, 1, nr, nt, 'crossed')
# First make a denser mesh towards r = a
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 [r*cos(Theta*s), r*sin(Theta*s)]
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()
----------------------------------
The goal is to create a part of a hollow cylinder of Theta degrees, with inner radius a and outer radius b. The first part stretches the rectangular coordinates, and this works well, i.e. the function 'denser'.
In the next step, the function 'cylinder' is supposed to transform the rectangle into the semi-circle, but now I get the error message:
Invalid type conversion: <type 'numpy.ndarray'> can not be converted to any UFL type.
The traceback shows that the error occurs when calling the 'cylinder' function.
If I remove the sin and cos, e.g. by writing
def cylinder(r, s):
return [r*s, r*s**2]
then everything works well. It seems to me like there is something with the cos and sine functions that messes it up.
Any ideas?
--
You received this question notification because you are a member of
DOLFIN Team, which is an answer contact for DOLFIN.
Follow ups