CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

position of iterator?

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 17, 2014, 16:16
Default position of iterator?
  #1
Senior Member
 
Join Date: Jan 2012
Posts: 166
Rep Power: 14
maybee is on a distinguished road
hi,

when using something like

Code:
forAllIter(PtrDictionary<phaseModel>, phases_, iter)  
{ 
phaseModel& phase = iter();
.
.
.
}
is it possible to get the actual position/index of iterator "iter" (which pointer is the iterator refering to at the moment)?

Quote:
Additionally:

If I define a dictionary like

Code:
const dictionary& subDict_Droplets;
subDict_Droplets = properties.subDict("currentValue");
can I create an iterator for the dictionary, set this iterator to a specific position of the dictionary (the position I would get from the first iterator if possible -> see code snippet 1) and get the content of the dictionary at that position?
-> Ok, I guess I solved the second part more efficiently by using the datatype "list<dimensionedScalar>" instead of "dictionary". The elements of datatype "list<dimensionedScalar>" should be accessable like a vector (->array) right?


greetings
maybee

Last edited by maybee; February 19, 2014 at 05:38.
maybee is offline   Reply With Quote

Old   February 25, 2014, 02:17
Default
  #2
Member
 
Christian Butcher
Join Date: Jul 2013
Location: Japan
Posts: 85
Rep Power: 12
chrisb2244 is on a distinguished road
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;
will give you the value in terms of the position, like 0, 1, 2, 3 etc.
chrisb2244 is offline   Reply With Quote

Old   February 25, 2014, 05:04
Default
  #3
Senior Member
 
Join Date: Jan 2012
Posts: 166
Rep Power: 14
maybee is on a distinguished road
hi chris,

I want to get the position of the iterator as a number like 0,1,2,3....

But I guess

Quote:
*iter
will give me the content "iter is pointing to" , since an iterator is some kind of pointer and the operator * generally should dereference a pointer.
maybee is offline   Reply With Quote

Old   February 25, 2014, 05:28
Default
  #4
Member
 
Christian Butcher
Join Date: Jul 2013
Location: Japan
Posts: 85
Rep Power: 12
chrisb2244 is on a distinguished road
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 }
http://foam.sourceforge.net/docs/cpp/a01178.html might be vaguely helpful.
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?
chrisb2244 is offline   Reply With Quote

Old   February 25, 2014, 20:50
Default
  #5
Member
 
Christian Butcher
Join Date: Jul 2013
Location: Japan
Posts: 85
Rep Power: 12
chrisb2244 is on a distinguished road
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?
chrisb2244 is offline   Reply With Quote

Old   February 28, 2014, 09:36
Default
  #6
Senior Member
 
Join Date: Jan 2012
Posts: 166
Rep Power: 14
maybee is on a distinguished road
@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);

}
, but I get the error:

Code:
error: no matching function for call to ‘distance(Foam::DLListBase::const_iterator, Foam::LPtrList<Foam::DLListBase, Foam::phaseModel>::iterator&)
Perhaps someone knows to solve this problem?
maybee is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


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


All times are GMT -4. The time now is 02:23.