AttributeError: 'dolfin.cpp.mesh.Mesh' object has no attribute 'create_block_variable'

Hi I’m new to FeniCS and DOLFIN-adjoint. I’m currently trying to load a 2D mesh (for flow pass cylinder) from h5 file

# Load mesh with markers
mesh_file = 'turek_2d.h5'
mesh = Mesh()
comm = mesh.mpi_comm()
h5 = HDF5File(comm, mesh_file, 'r')

h5.read(mesh, 'mesh', False)

# File("mesh/mesh_cylinder.xml") << mesh

surfaces = MeshFunction('size_t', mesh, mesh.topology().dim()-1)
h5.read(surfaces, 'facet')

This file is generated from here: Cylinder2DFlowControlGeneral/generate_msh.py at master · thw1021/Cylinder2DFlowControlGeneral · GitHub

which is and old version of fenics.

I’m trying to use FEniCS version 2019.1.0 load it because it works well with adjoint-dolfin but got the following error

File "/scratch365/xliu24/cylinder-control/flow_jetsSur.py", line 45, in __init__ h5.read(mesh, 'mesh', False) File "/afs/crc.nd.edu/user/x/xliu24/anaconda3/envs/fenicsproject/lib/python3.9/site-packages/fenics_adjoint/types/io.py", line 14, in HDF5File_read func.create_block_variable() AttributeError: 'dolfin.cpp.mesh.Mesh' object has no attribute 'create_block_variable'

Can anyone help me with this problem? Thanks very much!

You are missing the import statements from the code above. The order of them us crucial, as They should be:

from dolfin import *
from dolfin_adjoint import *

Thanks for your reply. I have these two lines

from fenics import *

from fenics_adjoint import *

But it still doesn’t work.