Collect all cells of a mesh with C++


171
views
0
9 months ago by
pf4d  
Hello,

I need to collect all the cells of a mesh into a single std::vector such that I can query the vector for the cell by the index, something like this :

std::vector<std::unique_ptr<Cell>>   cells;
cells.resize(mesh->num_cells());

for (CellIterator c(*mesh); !c.end(); ++c)
{
  Cell cell(*mesh, c.index());
  cells[c.index()] = cell;
}​

However, I cannot call c.index() because it is private :

dolfin/mesh/MeshEntityIteratorBase.h:189:25: error: ‘const unsigned int* dolfin::MeshEntityIteratorBase<dolfin::Cell>::index’ is private
     const unsigned int* index;
                         ^
​


Does anyone know how I might create a vector of cells?

Thanks in advance,

Evan

Community: FEniCS Project

1 Answer


0
9 months ago by
pf4d  
Oh, since each cell is intexed from 0 to mesh.num_cells(),

std::vector<Cell> cells;
cells.resize(mesh->num_cells());

for (unsigned int i = 0; i < mesh->num_cells(); i++)
{
  Cell cell(*mesh, i);
  cells[i] = cell;
}
​
Please login to add an answer/comment or follow this question.

Similar posts:
Search »