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

Spatial coordinates in a weak formulation

0 votes

I want to use spatial coordinates in a weak formulation.

x = SpatialCoordinate(mesh)
u_exact = (sin(x[2]))**lamb*sin(lamb*x[1]) 
f = lamb*(lamb + 1.)*(sin(x[2]))**lamb*sin(lamb*x[1])
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)*Dx(v,2) )*dx
l = f*v*dx
A = assemble(a)
L = assemble(l)

But I get an error:

TypeError: nb_float should return float object

I would be so happy if there is any suggestion for this error. Moreover, if I try it on other function;

x = SpatialCoordinate(mesh)
u1 = ( expm1( 1./(62.6975 - (x[0]**2 + x[1]**2 + x[2]**2)) ) + 1.)*v*dx
U1 = assemble(u1)
u2 = ( x[0]**2 + x[1]**2 + x[2]**2 )**.5*v*dx
U2 = assemble(u2)

U2 works fine but U1 gives the same type of error. I am not able to get what is wrong. Thanks in advance.

asked Jul 7, 2016 by masur FEniCS Novice (320 points)

Hello, can you post a comple (and minimal) code that reproduces the error? In particular, what is mesh, lamb, ...? Also, what is your FEniCS version?

I have a spherical surface mesh which is converted in spherical coordinates (r,phi,theta). The mesh in this link mesh_spherical.xml and the simple code is:

from dolfin import *
from math import *
mesh = Mesh('mesh_spherical.xml')    

V = FunctionSpace(mesh, "CG", 1)
u = TrialFunction(V)
v = TestFunction(V)

lamb = .6
x = SpatialCoordinate(mesh)
f = lamb*(lamb + 1.)*(sin(x[2]))**lamb*sin(lamb*x[1])
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)*Dx(v,2) )*dx
l = f*v*dx
A = assemble(a)
L = assemble(l)

I have the latest version of FEniCS. Thanks a lot.

1 Answer

+1 vote

Hello, remove from math import * import which brings in among others sin function that hides the desired one from UFL.

answered Jul 8, 2016 by MiroK FEniCS Expert (80,920 points)
...