← Back to team overview

dolfin team mailing list archive

Re: [Question #117931]: Transforming mesh coordinates

 

Question #117931 on DOLFIN changed:
https://answers.launchpad.net/dolfin/+question/117931

Andy R Terrel proposed the following answer:
Use numpy.sin and numpy.cos instead of sin and cos, which get imported
from ufl.

-- Andy

2010/7/16 Øystein Sørensen <question117931@xxxxxxxxxxxxxxxxxxxxx>:
> 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.
>
> _______________________________________________
> Mailing list: https://launchpad.net/~dolfin
> Post to     : dolfin@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~dolfin
> More help   : https://help.launchpad.net/ListHelp
>

You received this question notification because you are a member of
DOLFIN Team, which is an answer contact for DOLFIN.