On Thu, Aug 21, 2014 at 10:05 AM, Miguel Angel Salazar de Troya
<salazardetr...@gmail.com> wrote:
> Thanks for your response. Could you please answer my first email?
>
> Do the elements have id's from 0 to the number of elements? And when we
> refine the mesh, the new elements will take subsequent id numbers?
> Basically what I want to do is to have an array of numbers of size equal to
> the number of elements and assign each number to each element. If I refined
> the mesh, I would resize this array to accommodate the new elements. Is
> there a more efficient way to do this in libmesh rather than just creating
> a vector and accessing it with an index equal to the element's id? Thanks
> in advance.
>
> I realized the element id's are not from 0 to the number of elements.
> Because I need to have id's of elements from 0 to number of active
> elements, I have thought of building a vector with size equal to the
> max_elem_id(), iterate through the elements and assign a counter to the
> index corresponding to the element_id. Something like,

With adaptivity it's guaranteed that the active elements will *not* be
numbered starting from 0.

Relying on element numberings in libmesh is always a bad idea, because
they get renumbered all the time during adaptivity.


> std::vector<unsigned int> indexer;
> indexer.resize (mesh.max_elem_id());
> unsigned int counter = 0
>
> Now iterate through the elements and for each one:
>
> indexer[elem.id()] = counter++
>
> Is there a better way to do this? Probably I will rebuild this indexer
> every time I refine the mesh.

If you have non-contiguous numbering, consider using a std::map.

-- 
John

------------------------------------------------------------------------------
Slashdot TV.  
Video for Nerds.  Stuff that matters.
http://tv.slashdot.org/
_______________________________________________
Libmesh-users mailing list
Libmesh-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libmesh-users

Reply via email to