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

The weak formulation of spherical coordinates

+1 vote

I am trying to solve Laplace equation on spherical surface using spherical coordinates. First, the mesh coordinates are converted into spherical coordinates and then I have built the functions space and functions on this mesh. But I have failed to write the grad in the weak formulation. The code is

V = FunctionSpace(spherical_mesh, "CG", 1)
u = TrialFunction(V) 
v = TestFunctions(V)
w = Function(V)      
lamb = .6       
f = Expression("lamb*(lamb + 1)*(sin(x[2]))**lamb*sin(lamb*x[1])", lamb = lamb)
a = ( Dx(u,0)*Dx(v,0) + 1/x[0]**2*Dx(u,1)*Dx(v,1) + 1/(x[0]*sin(x[1]))**2*Dx(u,2)*Dy(v,2) )*dx
L = inner(f,v)*dx
solve(a == L, w)

I get an error message in compile.log file as 'Manually-specified variables were not used by the project'.

I have checked the code in Support use of coordinates in forms but it is hard to see why the mesh is not used.

Is there any suggestion for me how to write the weak formulation?

asked Jun 23, 2016 by masur FEniCS Novice (320 points)

1 Answer

+1 vote
 
Best answer

Why not simply using the Expression class?

r = Expression("x[0]", degree=1)
theta = Expression("x[1]", degree=1)
a = ( Dx(u,0)*Dx(v,0) + (Constant(1.)/r)**2*Dx(u,1)*Dx(v,1) + Constant(1.)/(r*sin(theta))**2*Dx(u,2)*Dx(v,2) )*dx
answered Jun 24, 2016 by umberto FEniCS User (6,440 points)
selected Jun 25, 2016 by masur

Thanks a lot, however, I still have the same error. Do you have any other suggestion? As far as I see, now in f function I have the error.

r = Expression("x[0]", degree=1)
phi = Expression("x[1]", degree=1)
theta = Expression("x[2]", degree=1)
f = Expression("lamb*(lamb + 1)*(sin(x[2]))**lamb*sin(lamb*x[1])", lamb=lamb)  
a = ( Dx(u,0)*Dx(v,0) + (Constant(1.)/r)**2*Dx(u,1)*Dx(v,1) +     Constant(1.)/(r*sin(phi))**2*Dx(u,2)*Dx(v,2) )*dx
L = inner(f,v)*dx

I think you have a typo in the definition of the test function:

v = TestFunctions(V)

should be

v = TestFunction(V)

Yes, you are right, I have corrected it and I took f out of expression. Now, it works. Thanks a lot.

You can also use SpatialCoordinate instead of Expression. For example,

r, phi, theta = SpatialCoordinate(mesh)
x = r * sin(theta) * cos(phi)
...