Contenu principal

mergeCells

Merge geometry cells

Since R2023b

Description

h = mergeCells(g,cellIDs) merges the cells identified by cellIDs for the 3-D geometry g by removing their shared faces. mergeCells renumbers cells, faces, edges, and vertices in the resulting geometry. The cell IDs of the resulting geometry start with 1 and end with the number of cells after merging. Because the function removes shared faces, it also removes edges and vertices belonging only to these faces, and decreases the IDs of all subsequent faces, edges, and vertices.

example

In R2026a: h = mergeCells(g) merges all cells of the 3-D geometry g by removing their shared faces.

example

Examples

collapse all

Merge two cells in a nested cylinder consisting of three cells.

Create a nested cylinder.

gm = multicylinder([1 2 3],3);

Plot the cylinder with cell labels.

pdegplot(gm,CellLabels="on",FaceAlpha=0.2);

Figure contains an axes object. The axes object contains 6 objects of type quiver, text, patch, line.

Merge the two inner cells.

newgm = mergeCells(gm,[1 2]);

Plot the resulting geometry. Although mergeCells removes shared faces, it does not merge faces of the merged cells. So, cell 1 has two top faces and two bottom faces.

pdegplot(newgm,CellLabels="on",FaceAlpha=0.2);

Figure contains an axes object. The axes object contains 6 objects of type quiver, text, patch, line.

You also can merge all geometry cells into one.

newgm = mergeCells(gm);
pdegplot(newgm,CellLabels="on",FaceAlpha=0.2);

Figure contains an axes object. The axes object contains 6 objects of type quiver, text, patch, line.

Since R2026a

Reduce the number of cells to two cells in a nested cuboid geometry consisting of five cells.

Create a nested cuboid.

gm = multicuboid(1:5,1:5,2);

Plot the cuboid with cell labels.

pdegplot(gm,CellLabels="on",FaceAlpha=0.2)

Figure contains an axes object. The axes object contains 6 objects of type quiver, text, patch, line.

Merge the three smallest cells into one cell and the remaining two cells into another cell.

gm_merge = mergeCells(gm,{1:3,4:5});

Plot the resulting geometry. Although mergeCells removes shared faces, it does not merge faces of the merged cells. So, the resulting nested cuboid has extraneous top and bottom faces.

pdegplot(gm_merge,CellLabels="on",FaceAlpha=0.2)

Figure contains an axes object. The axes object contains 6 objects of type quiver, text, patch, line.

Input Arguments

collapse all

Original multicell geometry, specified as an fegeometry object or a DiscreteGeometry object.

IDs of the cells to merge, specified as a vector of positive integers or a cell array of vectors of positive integers. The function merges the cells specified by each vector. For example, mergeCells(g,[1 2 3]) merges the cells with IDs 1, 2, and 3 into one cell. mergeCells(g,{[1 2 3],[7 9]}) merges the cells with IDs 1, 2, and 3 into one cell, and merges cells 7 and 9 into another cell.

When you merge two cells, they must share at least one face. When you merge three or more cells, all cells must be connected through shared faces, so that the resulting cell forms a solid without gaps. If any of the specified groups of cells do not form a connected set through shared faces, mergeCells issues an error and does not merge any cells.

Output Arguments

collapse all

Modified geometry, returned as an fegeometry object or a handle to a DiscreteGeometry object.

  • If the original geometry g is an fegeometry object, then h is a new fegeometry object representing the modified geometry. The original geometry g remains unchanged. To replace the original geometry with the modified geometry, use the original geometry name as the output argument, for example, g = mergeCells(g,[1 2]).

  • If the original geometry g is a DiscreteGeometry object, then h is a handle to the modified DiscreteGeometry object g.

Tips

  • Although mergeCells removes shared faces of the merged cells, it does not merge faces of the merged cell. So, the resulting geometry can have extraneous faces. For example, if you merge two stacked cubes, mergeCells removes the face between the cubes, but each side of the merged cell consists of two faces, not one face, for a total of 10 faces in the merged geometry.

  • Merging modifies a geometry, but it does not modify the mesh. After merging cells, call generateMesh for a correct mesh association with the new geometry.

Version History

Introduced in R2023b

expand all