Need help in defining exact solution in polar coordinates

Hello

I want to define the exact solution in polar coordinates attached in the below screenshot:

I try to define it as

    lamda = Constant(0.54448373678246)
    w = Constant(3 * np.pi / 2)
    r = Expression("sqrt(x[0]*x[0] + x[1]*x[1])", degree=3)
    theta = Expression("atan2(x[1], x[0])", degree=3)
    phi = Expression( "sin((1+lamda)*theta)*cos(lamda*w)*(1/(1+lamda)) - cos((1+lamda)*theta) - sin((1-lamda)*theta)*cos(lamda*w)*(1/(1-lamda)) + cos((1-lamda)*theta)", lamda=lamda, w=w, theta=theta, degree=3)
    phi_1 = Expression( "cos((1+lamda)*theta)*cos(lamda*w) + (1+lamda)*sin((1+lamda)*theta)- cos((1-lamda)*theta)*cos(lamda*w) - (1-lamda)*sin((1-lamda)*theta)", lamda=lamda, w=w, theta=theta, degree=3)
    phi_3 = Expression("-(1+lamda)*(1+lamda)*cos((1+lamda)*theta)*cos(lamda*w) - (1+lamda)*(1+lamda)*(1+lamda)*sin((1+lamda)*theta) + (1-lamda)*(1-lamda)*cos((1-lamda)*theta)*cos(lamda*w) + (1-lamda)*(1-lamda)*(1-lamda)*sin((1-lamda)*theta)", lamda=lamda, w=w, theta=theta, degree=3)

    u_exac = Expression(("pow(r, lamda) * ((1 + lamda) * sin(theta) * phi + cos(theta) * phi_1)", "pow(r, lamda) * (sin(theta) * phi_1 - (1 + lamda) * cos(theta) * phi)"), r=r, theta=theta, phi=phi, phi_1=phi_1, lamda=lamda, domain=mesh, degree=3)
    p_exac = Expression("pow(r, lamda-1) * ((1 + lamda)*(1+lamda) * phi_1 + phi_3) / (1 - lamda)",  r=r, phi_1=phi_1, phi_3=phi_3, lamda=lamda, domain=mesh, degree=3)
    
    ```
Output 
===================================================================
 hh  & e(pl2) &  r(pl2)  &  e(ul2)  &  r(ul2)  &  e(uh1)  & r(uh1) 
===================================================================
0.1177 &      nan &  0.000 &      nan &  0.000 &      nan &  0.000 
0.0643 &      nan &    nan &      nan &    nan &      nan &    nan 
====================================================================

If I use exact solution other than this then I get correct results. It means there is some mistake in defining this solution. Please help me in this regard. 

Thanks

Hi Ashini,

The code you have provided is not a minimal working example (please see Read before posting: How do I get my questions answered?.) It would also be of great help if you commented the code, either line-by-line or by explaining what the different variables of your code are.

Notwithstanding the above: are phi_1 and phi_3 the first and third derivatives of the expression \Psi with respect to \varphi? If so, at a first glance it seems to me that at least phi_1 is not the correct expression for the first derivative \Psi'(\varphi). This might be the problem. An alternative is to perform the differentiation of phi directly in the code (searching this forum for e.g. “how to differentiate symbolic expressions in dolfin” probably yields some helpful results.)

Best,
Halvor

1 Like