Hello,
Before asking my main question, I’m sorry to write mathematics formula and code in the following way, I didn’t find any option to write in the appropriate format.
I want to define the following function, that is in polar coordinates, in cartesian coordinates and then consider its gradient and Hessian.
u_exact (r,θ):= r^(5/3) * (1-r)^(5/2) * (sin(2θ/3))^(5/2) if 0 < θ < 3π/2,
and otherwise its value is zero.
My attempt is as following
from fenics import *
from mshr import *
from math import atan2
domain = Circle(Point(0.,0.),1.0)
mesh = generate_mesh(domain, 5, “cgal”)
x = SpatialCoordinate(mesh)
V = FunctionSpace(mesh, “CG”, 2)
class u_exact(Expression):
def eval(self, values, x):
values[0] =(pow(pow(x[0],2) + pow(x[1],2),5./6) * pow(1 - sqrt(pow(x[0],2) + pow(x[1],2)),5./2) * pow(sin(2./3*atan2(x[1],x[0])),5./2) if \
-pi <= atan2(x[1],x[0]) <= -pi/2 || 0 <= atan2(x[1],x[0])<= pi else 0.0 )
return
u1_exact = u_exact(degree=2)
uu_exact = project(u1_exact, V)
g_exact = grad(uu_exact)
H_exact = grad(g_exact)
But I got an error. For some reason, I need to consider cartesian coordinates.
Any help would be greatly appreciated.