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

Erase cell from mesh by index

0 votes

Dear all,

I would like to know if there a method/command to erase a cell by index.

I would like to remove a group of cell that failed in my stress criteria for example and run this model again without these elements.

Is anyone has any idea?

Best Regards

asked May 8, 2016 by RDOLL FEniCS User (2,230 points)

1 Answer

+1 vote

I don't exactly understand what you try to achieve but one way to remove a cell is to create a new mesh based on the old one without the cell you want to remove. Here is a 1D example:

from dolfin import * 
import numpy as np

mesh = UnitIntervalMesh(5)

old_cells = mesh.cells()
old_coors = mesh.coordinates()

new_coors = np.delete(old_coors, (3), axis=0)
new_cells = np.delete(old_cells, (-1), axis = 0)

new_mesh = Mesh() 
editor = MeshEditor() 
editor.open(new_mesh, 1, 1)
editor.init_vertices(len(new_coors))
editor.init_cells(len(new_cells))

vert_id = 0
for vert in new_coors:
    editor.add_vertex(vert_id, vert)
    vert_id += 1

cell_id = 0
for c in range(len(new_cells)): 
    editor.add_cell(cell_id, new_cells[c][0], new_cells[c][1])
    cell_id += 1 

editor.close()

plot(new_mesh, interactive=True)
answered May 8, 2016 by Tristan FEniCS Novice (680 points)

Thank you for your answer, but I am looking for easier command, for example:

I have four cells:

cell_ids = [ 0, 1, 2, 3, 4 ]

and I would like to delete the cell ids 1 and 2 from mesh object.

I am looking for a command like this for example:

mesh.delete_cells([1,2])

and then I will run the model again.

...