[Dune-devel] Random-Access Iterators

Oliver Sander sander at igpm.rwth-aachen.de
Wed Oct 1 11:02:50 CEST 2014


> I can easily see the use case for something like this to implement FD
> type schemes on structured grids
> and have occasionally thought about options for doing this.
> Of course this wouldn't have required full random access iterators but
> just some +operator....
>

If FD on structured grids is the use case then I am not convinced.
For FD, random access iterators seem like a strange compromise for me.
What you would really want in that case would be some sort of i,j,k
integer coordinate access.
Cheers,
Oliver


> Is there some other usage of this feature you have in mind?
> 
> Greetings
> Andreas
> 
> On 01/10/14 07:58, Oliver Sander wrote:
>> Hi Jö,
>> thanks for the work.  As usual, it seems very well thought-out.
>> However, mainly to satisfy my curiosity, here a two questions:
>> - was this discussed in Berlin?  I can't find it in the meeting minutes,
>> - what is the use-case for random access iterators?
>> Again, this is not to say that I object to the feature.
>> Cheers,
>> Oliver
>>
>> Am 30.09.2014 um 23:17 schrieb Jö Fahlke:
>>> Hi!
>>>
>>> The random-access entity iterators are now ready for general review.
>>> https://cgit.dune-project.org/repositories/dune-grid/log/?h=feature/random-access-entity-iterators
>>>
>>> @Carsten: are you willing to include this in 2.4, provided noone finds any
>>>           serious issues?
>>>
>>> A grid declares that certain entity iterators are random-access by doing
>>>
>>>   typedef std::random_access_iterator_tag iterator_category;
>>>
>>> in the iterator implementation class.  The facade class Dune::EntityIterator
>>> notices this and defines the additional methods needed for random access
>>> iterators in terms of the member functions advance(n) and distanceTo(otherIt)
>>> of the iterator implementation class.  If your grids entity iterators do
>>>
>>>   typedef std::forward_iterator_tag iterator_category;
>>>
>>> or omit the member type completely, the EntityIterator will be a forward
>>> interator, as before.
>>>
>>> To do this, Dune::EntityIterator no longer implements the iterator methods
>>> itself, but derives from Dune::EntityIteratorBase, which has a template
>>> parameter category to select which type of iterator to implement.  Previously
>>> the ancestry looked like
>>>
>>>   EntityPointer
>>>   EntityIterator
>>>
>>> now it looks like (for forward iterators)
>>>
>>>   EntityPointer
>>>   EntityIteratorBase<..., std::forward_iterator_tag>
>>>   EntityIterator
>>>
>>> or (for random access iterators)
>>>
>>>   EntityPointer
>>>   EntityIteratorBase<..., std::forward_iterator_tag>
>>>   EntityIteratorBase<..., std::random_access_iterator_tag>
>>>   EntityIterator
>>>
>>> The template argument list of EntityIterator is completely the same as before.
>>>
>>> There is one function that has been omitted from random access iterators for
>>> the time being, namely operator[].  There are three possibilities for the
>>> return type of operator[]: Either return the entity by value -- but that needs
>>> copyable entities, which are not ready yet.  Or return a reference to the
>>> entity -- not possible, since we have nothing that stores that entity.  Or
>>> return a proxy object -- but I'm too lazy to implement that, since we will
>>> have copyable entities soon.  Note that instead of the (currently) invalid
>>> expression "it[n]" you can write "*(it+n)": The + creates a temporary
>>> iterator that holds the entity.
>>>
>>> I also omitted implementing bidirectional iterators, since I could not come up
>>> with a use case for iterating backwards through the grid.  If a grid declares
>>> an iterator implementation as bidirectional, the resulting EntityIterator will
>>> nevertheless just be a forward iterator.  It should be easy to add
>>> bidirectional iterators, should the need arise.
>>>
>>> Regards,
>>> Jö.
>>>
>>>
>>>
>>> _______________________________________________
>>> Dune-devel mailing list
>>> Dune-devel at dune-project.org
>>> http://lists.dune-project.org/mailman/listinfo/dune-devel
>>>
>>
>>
>>
>> _______________________________________________
>> Dune-devel mailing list
>> Dune-devel at dune-project.org
>> http://lists.dune-project.org/mailman/listinfo/dune-devel
> 
> 
> 
> 
> _______________________________________________
> Dune-devel mailing list
> Dune-devel at dune-project.org
> http://lists.dune-project.org/mailman/listinfo/dune-devel
> 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: OpenPGP digital signature
URL: <https://lists.dune-project.org/pipermail/dune-devel/attachments/20141001/d6921f82/attachment.sig>


More information about the Dune-devel mailing list