|
[Sponsors] |
February 17, 2014, 16:16 |
position of iterator?
|
#1 | |
Senior Member
Join Date: Jan 2012
Posts: 166
Rep Power: 14 |
hi,
when using something like Code:
forAllIter(PtrDictionary<phaseModel>, phases_, iter) { phaseModel& phase = iter(); . . . } Quote:
greetings maybee Last edited by maybee; February 19, 2014 at 05:38. |
||
February 25, 2014, 02:17 |
|
#2 |
Member
Christian Butcher
Join Date: Jul 2013
Location: Japan
Posts: 85
Rep Power: 12 |
In the case of the position/index of the iterator, what do you want your output to be? Like, 1,2,3 or phase1, phase2, phase3?
Because I think something like Code:
Pout<< *iter << endl; |
|
February 25, 2014, 05:04 |
|
#3 | |
Senior Member
Join Date: Jan 2012
Posts: 166
Rep Power: 14 |
hi chris,
I want to get the position of the iterator as a number like 0,1,2,3.... But I guess Quote:
|
||
February 25, 2014, 05:28 |
|
#4 |
Member
Christian Butcher
Join Date: Jul 2013
Location: Japan
Posts: 85
Rep Power: 12 |
So in the documentation, it turns out that iter() just returns the dereferencing of the iterator:
Code:
template<class T> 220 inline T& Foam::PtrList<T>::iterator::operator*() 221 { 222 return **ptr_; 223 } template<class T> 227 inline T& Foam::PtrList<T>::iterator::operator()() 228 { 229 return operator*(); 230 } I'm afraid I don't have OF on this computer, and have left my workplace, so can't quickly check different permutations to get what you want. I guess try different things and see what a) compiles, and then b) gives you the result you want? |
|
February 25, 2014, 20:50 |
|
#5 |
Member
Christian Butcher
Join Date: Jul 2013
Location: Japan
Posts: 85
Rep Power: 12 |
So I'm afraid I can't find anything that will give the integer position (although that is almost certainly due to my lack of imagination, rather than any inherent limitation in the OF framework).
You can however call iter.key() to get the phase. I know that was in fact the opposite of what you wanted, but maybe it will be helpful? |
|
February 28, 2014, 09:36 |
|
#6 |
Senior Member
Join Date: Jan 2012
Posts: 166
Rep Power: 14 |
@chris: Thx for your help, but unfortunately to get the phase does not help me at all.
Update: I tried now something like Code:
forAllIter(PtrDictionary<phaseModel>, fluid.phases(), iter) { PtrDictionary<phaseModel>& PtrDict = fluid.phases(); int IteratorPosition = std::distance(PtrDict.cbegin(), iter); } Code:
error: no matching function for call to ‘distance(Foam::DLListBase::const_iterator, Foam::LPtrList<Foam::DLListBase, Foam::phaseModel>::iterator&) |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[OpenFOAM] an error in Calculator's equation | immortality | ParaView | 12 | June 29, 2021 00:10 |
Force dependent on particle position | jranita | OpenFOAM Programming & Development | 1 | August 23, 2011 19:44 |
how to read in a position file | jiejie | OpenFOAM | 0 | May 23, 2011 04:38 |
DPM UDF particle position using the macro P_POS(p)[i] | dm2747 | FLUENT | 0 | April 17, 2009 01:29 |
Combustion Convergence problems | Art Stretton | Phoenics | 5 | April 2, 2002 05:59 |