This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

How to merge, concatenate, add meshed in one mesh

0 votes

Hi guys,

I try to merge 2 mesh in a unique mesh

# Import libraries
from dolfin import *
from mshr import *
# Meshs
mesh_1 = BoxMesh(Point(0.0, 0.0, 0.0), Point(1.0, 1.0, 1.0),1,1,1)
mesh_2 = BoxMesh(Point(1.0, 1.0, 1.0), Point(2.0, 0.0, 0.0),1,1,1)

Then, I would like something like.

mesh_total = mesh_1 + mesh_2 
plot(mesh_total , title='Total mesh', interactive=True)

I do no work on complex geometries, only with cube connected by at least a face.

I have try the following methods, unsuccessfully :

mesh_tot = mesh_1 + mesh_2
mesh_tot = generate_mesh (mesh_tot, 32)

Or

mesh_tot = MultiMesh()
mesh_tot.add(mesh_1)
mesh_tot.add(mesh_2)
mesh_tot.build()

I have seen the function CSGUnion but i dont understand how it works

I know I can use the MeshEditor, but i would like really to avoid this method ( i have thousands of cell to merge... so if i can avoid the connectiviy calculations, that would be great).

asked Sep 27, 2016 by fussegli FEniCS Novice (700 points)

1 Answer

0 votes

Try it with https://bitbucket.org/fenics-project/mshr/wiki/API/Box

box_1 = Box(Point(0.0, 0.0, 0.0), Point(1.0, 1.0, 1.0))
box_2 = Box(Point(1.0, 1.0, 1.0), Point(2.0, 0.0, 0.0)) 
box_tot = box_1 + box_2
mesh_tot = generate_mesh (box_tot, 32)

Since CSGUnion uses CSG geometry and not meshes! So first create 2 geometries (the boxes) and then create a mesh from the union. Should work.

/Edit:Corrected mistake in Box(..)

answered Sep 27, 2016 by Alawvahr FEniCS Novice (170 points)
edited Sep 27, 2016 by Alawvahr

Thanks a lot, it works.
However, i may have to use the mesh editor: generate_mesh create much more cells that i need, even by decreasing the argument '32'.

Merging mesh with BoxMesh.
...