Correct syntax to use BoxMesh to create hexahedron mesh?


386
views
0
7 months ago by
I'd like to use BoxMesh to make a hexahedron mesh in 2017.2, but am encountering errors. Perhaps I have a wrong syntax?

BoxMesh(Point(-1,-1,-1),Point(1,1,1),10,10,10)
#Generares Tet mesh


BoxMesh(Point(-1,-1,-1),Point(1,1,1),10,10,10, CellType.Type_hexahedron)
# Fails, type error

UnitCubeMesh.create(10,10,10, CellType.Type_hexahedron)
# Works, creates a cubic hex mesh

BoxMesh.create(Point(-1,-1,-1),Point(1,1,1),10,10,10, CellType.Type_hexahedron)
#Fails: 
# Traceback (most recent call last):
#  File "<stdin>", line 1, in <module>
#  File "/usr/lib/python2.7/dist-packages/dolfin/cpp/mesh.py", line 6814, in create
#    return _mesh.BoxMesh_create(*args)
#NotImplementedError: Wrong number or type of arguments for overloaded function #'BoxMesh_create'.
#  Possible C/C++ prototypes are:
#    dolfin::BoxMesh::create(std::array< dolfin::Point,2 > const &,std::array< #std::size_t,3 >,dolfin::CellType::Type)
#    dolfin::BoxMesh::create(MPI_Comm,std::array< dolfin::Point,2 > const &,std::array< #std::size_t,3 >,dolfin::CellType::Type)

​

It looks like the cpp function is expecting a list of points and resolution but I've been unable to run it from python.
Thanks
Community: FEniCS Project

1 Answer


2
7 months ago by
I think it should be something like:

mesh = BoxMesh.create([Point(-1,-1,-1), Point(1,1,1)], [10, 10, 10], CellType.Type.hexahedron)
No such luck:
>>> mesh = BoxMesh.create([Point(-1,-1,-1), Point(1,1,1)], [10, 10, 10], CellType.Type.hexahedron)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: type object 'CellType' has no attribute 'Type'
​
written 7 months ago by Mike Welland  
Changed to CellType.Type_hexahedron (to match other examples), still fails:

>>> mesh = BoxMesh.create([Point(-1,-1,-1), Point(1,1,1)], [10, 10, 10], CellType.Type_hexahedron)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/dist-packages/dolfin/cpp/mesh.py", line 6814, in create
    return _mesh.BoxMesh_create(*args)
TypeError: in method 'BoxMesh_create', argument 1 of type 'std::array< dolfin::Point,2 > const &'
​
written 7 months ago by Mike Welland  
OK, maybe without the .create bit then. It is all a bit messed up in the Python layer to retain backwards compatibility.
written 7 months ago by Chris Richardson  
This works for me in master:

mesh = BoxMesh.create(MPI.comm_world, [Point(0,0,0), Point(1,1,1)], [2,3,4], CellType.Type.hexahedron)
written 7 months ago by Chris Richardson  

Fails:

>>> mesh = BoxMesh([Point(-1,-1,-1), Point(1,1,1)], [10, 10, 10], CellType.Type_hexahedron)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/dist-packages/dolfin/cpp/mesh.py", line 6839, in __init__
    _mesh.BoxMesh_swiginit(self, _mesh.new_BoxMesh(*args))
NotImplementedError: Wrong number or type of arguments for overloaded function 'new_BoxMesh'.
  Possible C/C++ prototypes are:
    dolfin::BoxMesh::BoxMesh(dolfin::Point const &,dolfin::Point const &,std::size_t,std::size_t,std::size_t)
    dolfin::BoxMesh::BoxMesh(MPI_Comm,dolfin::Point const &,dolfin::Point const &,std::size_t,std::size_t,std::size_t)

If I remove the square brackets and the mention of the hexahedron cell type it works (the first example above).

written 7 months ago by Mike Welland  
Seems like it is a problem with SWIG. I guess it cannot translate a Python list to std::array, without some extra help. So, your options are: either try the pybind11 interface (which will be the future), or just use UnitCubeMesh and rescale the coordinates.
written 7 months ago by Chris Richardson  
Thanks for the help and info. that's what i am doing now as a workaround.
written 7 months ago by Mike Welland  
Please login to add an answer/comment or follow this question.

Similar posts:
Search »