Unable to compile C++ code with dijitso

Hi All,
Hope you are great. I am a little bit confused about writing my formulation in polar coordinates with C++. I am trying to write the following expressions in my code as essential boundary conditions for displacement:
u_{1} = \frac{K_{I}}{2\mu} \times \sqrt{\frac{2\times r}{\pi}} \times \cos(\frac{\theta}{2}) \times (1-2\nu + \sin^{2}(\frac{\theta}{2}))
u_{2} = \frac{K_{II}}{2\mu} \times \sqrt{\frac{2\times r}{\pi}} \times \sin(\frac{\theta}{2}) \times (2-2\nu - \cos^{2}(\frac{\theta}{2}))
The way that I tried to write it (only u_{1}) is given as below:

x = SpatialCoordinate(mesh)
r = Expression('sqrt(x[0]*x[0]+x[1]*x[1])', degree = 2)
thetta = Expression('atan2(x[1],x[0])', degree = 2)
BoundaryU1 = Expression('K1/(2*mu)*sqrt((2*r/pi)*cos(thetta/2)*(1-2*nu+sin(thetta/2)**2))', r = r, thetta = thetta, degree = 2)

Running the code gave the following error:

File "/usr/lib/petsc/lib/python3/dist-packages/dolfin/function/expression.py", line 400, in __init__
    self._cpp_object = jit.compile_expression(cpp_code, params)
  File "/usr/lib/petsc/lib/python3/dist-packages/dolfin/function/jit.py", line 158, in compile_expression
    expression = compile_class(cpp_data, mpi_comm=mpi_comm)
  File "/usr/lib/petsc/lib/python3/dist-packages/dolfin/jit/jit.py", line 173, in compile_class
    raise RuntimeError("Unable to compile C++ code with dijitso")
RuntimeError: Unable to compile C++ code with dijitso

Any help regarding this would be highly appreciated.

Thanks,
Ben

Hi
You should supply your values/expressions for K1, mu and nu. Also, either use the pow function or do the product explicitly in sin(thetta/2)**2

K1 = 1.0
nu = 0.3
mu = 1.0
BoundaryU1 = Expression('K1/(2*mu)*sqrt((2*r/pi)*cos(thetta/2)*(1-2*nu+sin(thetta/2) * sin(thetta/2) ))', r = r, thetta = thetta, degree = 2, nu=nu, K1=K1, mu=mu)

Thanks for your help. My expressions for the corresponding parameters are:

KC = sqrt(2*mu*G/(1-nu))
K1 = 2.4*KC
K2 = sqrt(1.5-K1**2)/K1
kappa = (3.0-nu)/(1.0+nu)
E = 3*k0*(1-2*nu)
x = SpatialCoordinate(mesh)
r = Expression('sqrt(x[0]*x[0]+x[1]*x[1])', degree = 2)
thetta = Expression('atan2(x[1],x[0])', degree = 2)
BoundaryU = Expression('K1/(2*mu)*(r/(2*pi))**0.5', r = r, degree = 2)

Even for this simple line, I got the same error.
Thanks for your help.

I think you missed my point about using the pow function when trying to raise expressions to (non-integer) powers inside your Expression. ** is not C++ syntax. Try

BoundaryU = Expression('K1/(2*mu)*sqrt(r/(2*pi))', r = r, degree = 2, K1=K1, mu=mu)

By the way, in your snippet you haven’t declared mu, nu, G etc. I am assuming that you are copy-pasting part of your code and you have indeed declared these otherwise.

Thanks buddy, the solution worked. My bad!!