Runtime Error: Unable to compile C++ code with dijitso

Hi everyone,

I am currently trying to run a piece of code in Fenics, but I keep getting an error message reading

Traceback (most recent call last):
  File "target2.py", line 36, in <module>
    Laser = Expression('2*A*Pmax/(pi*w*w)*exp(-2*pow((x[0] - 4), 2)/(w*w)-2*pow((x[1]-4), 2)/(w*w)-2*pow((x[2]-z1), 2)/(w2*w2) )',degree=2, A=0.1, Pmax=500,w=1, w2= 0.1) #power (w2 localises the z-coordinates)
  File "/usr/local/lib/python3.6/dist-packages/dolfin/function/expression.py", line 400, in __init__
    self._cpp_object = jit.compile_expression(cpp_code, params)
  File "/usr/local/lib/python3.6/dist-packages/dolfin/function/jit.py", line 158, in compile_expression
    expression = compile_class(cpp_data, mpi_comm=mpi_comm)
  File "/usr/local/lib/python3.6/dist-packages/dolfin/jit/jit.py", line 170, in compile_class
    raise RuntimeError("Unable to compile C++ code with dijitso")
RuntimeError: Unable to compile C++ code with dijitso

The error seems to be arising from my equation for a 3D guassian used in the code:

Laser = Expression('2*A*Pmax/(pi*w*w)*exp(-2*pow((x[0] - 4), 2)/(w*w)-2*pow((x[1]-4), 2)/(w*w)-2*pow((x[2]-z1), 2)/(w2*w2) )',degree=2, A=0.1, Pmax=500,w=1, w2= 0.1)

I have also tried updating pkgconfig using:

$ pip3 install -U pkgconfig

But this has not resolved the problem. Does anyone have any suggestions?

The full code is below

from __future__ import print_function
from fenics import *
import numpy as np
import matplotlib.pyplot as plt
from dolfin import *
from mshr import *
import math
# THIS IS A TEST TO SEE IF A STEADY STATE, TIME INDEPENDENT SOLUTION IS POSSIBLE IN FENICS
parameters["allow_extrapolation"] = True
parameters["form_compiler"]["cpp_optimize"] = True
set_log_level(20)

# SOLVE THE HEAT TRANSFER PROBLEM FOR A 3D TARGET

#--Dimensions in mm----
x0 = 0 
y0 = 0
z0 = 0
x1 = 8
y1 = 8
z1 = 8
#----------------
t_start = 0.0
t_end = 900
nstep = 450
dtime = (t_start - t_end)/ nstep
#-----------------
#Configure for dimensions of system

pi = 3.141592653589793
T_am = 0.0 #ambient vacuum temperature
T_a4 = T_am**4
epsilon = 0.05  # material emissivity
sigma = 5.67E-14 # W/(m2.K4)
es = epsilon*sigma
Laser = Expression('2*A*Pmax/(pi*w*w)*exp(-2*pow((x[0] - 4), 2)/(w*w)-2*pow((x[1]-4), 2)/(w*w)-2*pow((x[2]-z1), 2)/(w2*w2) )',degree=2, A=0.1, Pmax=500,w=1, w2= 0.1) #power (w2 localises the z-coordinates)
#----------THERMAL--PROPERTIES--[W]--------
kappa = 0.174         #conductivity [W/mm K] 
c = 0.132         #Specific Heat Capacity [J/gK]
rho = 0.019            #Density [g/mm^3]
const = kappa /(c * rho)
tau_T = 0.0 #Temperature Gradient Lag
tau_q = 0.0 #Heat Flux Lag
#---------------------------------------

mesh = BoxMesh( Point(x0,y0,z0), Point(x1,y1,z1), 80,80,80)
Space = FunctionSpace(mesh, 'P', 1)
VectorSpace = VectorFunctionSpace(mesh, 'P', 1)
cells = CellFunction('size_t', mesh)
facets = FacetFunction('size_t', mesh)
da = Measure('ds', domain=mesh, subdomain_data = facets)
dv = Measure('dx', domain=mesh, subdomain_data = cells)

initial_T = Expression("Tini", Tini=T_am)
T0 = interpolate(initial_T, Space)
T = Function(Space)
V = TestFunction(Space)
dT = TrialFunction(Space)
q0 = Function(VectorSpace)
G = as_tensor(T.dx(i), (i,))
G0 = as_tensor(T0.dx(i), (i,))
q = as_tensor(dt/(dt + tau_q) * (tau_q/dt*q0[i] - kappa*(1+tau_T/dt)*G[i] + kappa*tau_T/dt*G0[i]),(i,))

F = (rho*c/dt*(T-T0)*V - q[i]*V.dx(i) - rho*Laser*V ) * dv + es*(T**4 - T_a4)*V*da
Gain = derivative(Form, T, dT)

file_T = File('target3D/solution.pvd')
for t in np.arange(t_start,t_end,dtime):
   print( "Time", t)
   solve(F==0, T, [], J = Gain, solver_parameters={"newton_solver":{"linear_solver": "mumps", "relative_tolerance": 1e-3} }, form_compiler_parameters={"cpp_optimize": True, "representation": "quadrature","quadrature_degree": 2} )
   file_T << (T,t)
   q0 = project(q, VectorSpace)
   T0.assign(T)

Hi,
You forgot to add z1=z1 in your expression.

Ah right, thanks a lot!

hi, im facing the same issue and do not manage to resolve it
can you pls assist? im using the code that was posted by fenics for hyperelastic material

c = Expression((“0.0”, “0.0”, “0.0”,degree==2))
r = Expression((“scale0.0",
"scale
(y0 + (x[1] - y0)*cos(theta) - (x[2] - z0)sin(theta) - x[1])",
"scale
(z0 + (x[1] - y0)*sin(theta) + (x[2] - z0)*cos(theta) - x[2])”),degree==2,
scale = 0.5, y0 = 0.5, z0 = 0.5,theta = pi/3)

Please provide a minimal reproducible example with 3x` formatting, i.e.

```python
#add code that reproduces your error here
```