Gmsh mesh with dolphin adjoint

Hello,
I want to use a mesh created on GMSH (2d rectangle but separated into several rectangles containing a different number of meshes depending on x) in my topological toptimization via dolphin adjoint. However I encounter this error: ‘dolfin.cpp.mesh.mesh’ object has no attribute ‘_ad_will_add_as_dependency’ when I perform “vol_7 = assemble(Constant(1.0) * dx(7))”.

Here’s how I load the mesh:

mesh, boundaries_mf_imported, association_table = import_mesh(prefix=“Mesh/mesh”, dim=2),
which is a function from GitHub - floiseau/msh2xdmf: Converter from MSH mesh format to XDMF mesh format

My code works fine if I don’t import dolphin_adjoint, but I need it for optimization.
Thank you !!!

You need to wrap the mesh with the dolfin_adjoint mesh class, i.e.

mesh = dolfin_adjoint.Mesh(mesh)

See for instance: Dolfin-adjoint overloaded solve fails but regular dolfin solve succeeds? - #2 by dokken

Well, that was obvious… Thank you very much !