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

Polar coordinates

0 votes

Hi folks
I'm solving the wave equation on a circular domain that I made in gmsh.
I want the initial conditions to be defined by a function I came up with using polar coordinates.
However, I have trouble implementing it in fenics.
As far as I know, the symbol "x" in fenics refers to a vector containing spatial variables, i.e. x[1] = x, x[1] = y and so on.
I've tried converting my initial conditions to cartesian coordinates but I don't get what I expect, so therefore I ask if it's possible to re-define x in fenics so as to contain polar coordinates?
I need something like: x[0] = r and x[1] = theta

asked May 20, 2016 by Fenics4ever FEniCS Novice (210 points)

Hi, what is the expression for your initial condition?

I think my change of variables when converting from polar to cartesian was wrong... by a lot.
Anyway here it is (I'll denote theta with t):

f(r,t) = r^2 * (2-r) * sin(t/2)^2 * cos(t/2) * cos(r^3)

I think my problem is that I can't just simply substitute t = arctan(y/x) , at least that's what I can tell from reading about changing functions in polar coordinates to functions in cartesian coordinates.

1 Answer

+1 vote

Does

r = Expression("sqrt(x[0]*x[0]+x[1]*x[1])")
theta = Expression("atan2(x[1],x[0])")
u_init = Expression("r*r*(2-r)*sin(t/2)*sin(t/2)*cos(t/2)*cos(r*r*r)",r=r,t=theta)

not work?

answered May 23, 2016 by KristianE FEniCS Expert (12,900 points)
...