range-based loop over cells

56 views
Skip to first unread message

Niklas Fehn

unread,
Mar 24, 2022, 8:21:42 AM3/24/22
to deal.II User Group
Dear dealii,

when writing

for(auto cell : triangulation){}

which type of cell iterator is used (cell_iterators(), active_cell_iterators())? and where do I find this information in the documentation?

Many thanks and

Best
Niklas

Bruno Turcksin

unread,
Mar 24, 2022, 8:35:41 AM3/24/22
to deal.II User Group
Niklas,

If you want cell_iterators, you write for(auto cell : triangulation.cell_iterators ()) If you want active_cell_iterators, you write for(auto cell : triangulation.active_cell_iterators ()) The documentation is here.

Best,

Bruno

Niklas Fehn

unread,
Mar 24, 2022, 8:57:29 AM3/24/22
to deal.II User Group
thanks. I think it is nevertheless possible to write "cell : triangulation", and I wondered what this means exactly?

simon...@gmail.com

unread,
Mar 24, 2022, 9:10:39 AM3/24/22
to deal.II User Group
You will iterate from begin() to end() on the object after the colon. On Triangulation this is the cells on level 0.

Best,
Simon

simon...@gmail.com

unread,
Mar 24, 2022, 9:21:13 AM3/24/22
to deal.II User Group
No, sorry... All cells. Just starting at level 0. Got confused by this line:

Triangulation< dim, spacedim >::cell_iterator Triangulation< dim, spacedim >::begin
( const unsigned int  level = 0) const

/Simon

Niklas Fehn

unread,
Mar 25, 2022, 8:21:41 AM3/25/22
to deal.II User Group
so this is common C++ knowledge, it is not documented in deal.II?

Bruno Turcksin

unread,
Mar 25, 2022, 9:07:23 AM3/25/22
to dea...@googlegroups.com
Niklas,

You can take a look here but basically if a class defines the begin() and end() iterators, you can do a range-based loop. That's just the C++11 standard.

Best,

Bruno

--
The deal.II project is located at http://www.dealii.org/
For mailing list/forum options, see https://groups.google.com/d/forum/dealii?hl=en
---
You received this message because you are subscribed to a topic in the Google Groups "deal.II User Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/dealii/JZNFZV8FhrU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to dealii+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dealii/1a4343be-c68f-49ee-9105-3351d53a5e8en%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages