Hi,

I am quite new to Fenics and dolfin-adjoint, and I’ve been trying to solve a 3D- heat transfer topology optimization problem.

When defining an assembly for minimization, I get an error:

`DijitsoError: Dijitso JIT compilation failed, see '/..../box/jitfailure-ffc_form_26b5aad55790b45b60fe7a7a80201fa4da1014b6' for details`

bellow is a minimum working example:

```
from fenics import *
from fenics_adjoint import *
import numpy as np
from mpi4py import MPI
rank = MPI.COMM_WORLD.rank
P1 = Point(0, 0, 0)
P2 = Point(10, 10, 10)
mesh = BoxMesh(P1, P2, 10, 10, 10)
V = Constant(0.4) # volume bound on the control
p = Constant(5) # power used in the solid isotropic material
eps = Constant(1.0e-3) # epsilon used in the solid isotropic material
alpha = Constant(1.0e-8) # regularisation coefficient in functional
A = FunctionSpace(mesh, "CG", 1) # function space for control
P = FunctionSpace(mesh, "CG", 1) # function space for solution
# SIMP rule
def k(rho):
return eps + (1 - eps) * rho **p
# Mark subdomains (baseplate, heatplate, and design space in between)
subdomains = MeshFunction("size_t", mesh, mesh.topology().dim())
subdomains.set_all(0)
class BasePlate(SubDomain):
def inside(self, x, on_boundary):
return x[2] < 2
class HeaterPlate(SubDomain):
def inside(self, x, on_boundary):
return x[2] > 8
BasePlate().mark(subdomains, 1) # baseplate mark
HeaterPlate().mark(subdomains, 2) # heater mark
#File('subdomains.pvd') << subdomains
submesh = SubMesh(mesh, subdomains, 0)
# Define a measure for optimization subdomain
dx = Measure('dx', domain=mesh, subdomain_data= subdomains)
Asub = FunctionSpace(submesh, "CG", 1)
rhosub = interpolate(Constant(1.0), Asub)
# Boundary condition at baseplate
class BPBottom(SubDomain):
def inside(self, x, on_boundary):
return x[2] < DOLFIN_EPS and on_boundary
bc = [DirichletBC(P, 20, BPBottom())]
f = interpolate(Constant(1.0e-2), P) # the volume source term for the PDE
def forward(rho,rho_sub):
"""Solve the forward problem for a given material distribution rho(x)."""
T = Function(P, name="Temperature")
v = TestFunction(P)
F = (
inner(grad(v), k(rho_sub) * grad(T)) * dx(0) # design domain
+inner(grad(v), k(rho) * grad(T)) * dx(1) # baseplate
+inner(grad(v), k(rho) * grad(T)) * dx(2) # heater
- f * v * dx(2) # heater source term
)
solve(F == 0, T, bc, solver_parameters={"newton_solver": {"absolute_tolerance": 1.0e-7,
"maximum_iterations": 20}})
return T
rho_sub = interpolate(Constant(0.4), Asub)
rho = interpolate(V,A)
T = forward(rho,rho_sub)
file = File("solution.pvd")
file << T
## error happens here!!
J = assemble(f * T * dx(2) + alpha * inner(grad(rho_sub), grad(rho_sub)) * dx(0))
m = Control(rhosub)
Jhat = ReducedFunctional(J, m, eval_cb_post=eval_cb)
```

I’ve tried including all subdomains in the equation but with no luck.

Perhaps someone could also suggest a better way to define control on a subdomain?

Installed on Ubuntu 20.04.2 LTS with:

pip3 install git+https://github.com/dolfin-adjoint/pyadjoint.git@2019.1.0

inside a conda enviroment.

Thanks in advance!