CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   multiphaseEulerFoam: Method forAllIter(...) within solve() (https://www.cfd-online.com/Forums/openfoam-programming-development/127762-multiphaseeulerfoam-method-foralliter-within-solve.html)

maybee December 19, 2013 16:59

multiphaseEulerFoam: Method forAllIter(...) within solve()
 
hi,

within method solve() of multiphaseEulerFoam is found:

Code:

void Foam::multiphaseSystem::solve()
{
forAllIter(PtrDictionary<phaseModel>, phases_, iter) //PtrDictionary<phaseModel>
    { 
        iter().correct();     
    }
.
.
.

where forAllIter(...) is defined as

Code:

forAllIter (...) is defined as

for                                                                        \
    (                                                                          \
        Container::iterator iter = (container).begin();                        \
        iter != (container).end();                                            \
        ++iter                                                                \
    )
Iterate across all elements in the container object of type Container.
Usage
forAll(ContainerType, container, iter)
{
    statements;
}

My question is about the command "iter().correct();" in the first codesnippet. I guess "iter" is here the variable "Container::iterator iter" of the second codesnippet.
Where can I find the class (or struct?) "Container::iterator" , because I need to know what the operator () is doing when called on "iter" ?

greetings
maybee

GerhardHolzinger December 20, 2013 06:41

I don't know if this answers your Question, but here is some code of the file $FOAM_SRC/OpenFOAM/containers/PtrListI.H

I assume that phases_ is a pointer list or is based on a pointer list.


So my guess is that phases_ is a dynamic data structure and iter() returns the actual element of this list. So iter().correct() calls the correct() method of the phase class.


Code:

template<class T>
inline T& Foam::PtrList<T>::iterator::operator*()
{
    return **ptr_;
}


template<class T>
inline T& Foam::PtrList<T>::iterator::operator()()
{
    return operator*();
}


maybee December 21, 2013 05:01

hi,
first of all thx for the help, but I am not really sure if the operators you have listed are the right ones, because when I look in class multiphaseSystem (multiphaseSystem.H) I find
for phases_ :

Code:

PtrDictionary<phaseModel> phases_; //in multiphaseSystem.H
Neither in class PtrDictionary, nor in class phaseModel I can find an operator ().
However, when looking at the methods you' ve posted I think they could be the right ones since iterator iter is some kind of pointer and phases_ is a pointer dictionary -> the double dereferenziation therefore seems logical.

How could you find these operators and how can I be sure that these are the right ones, since even when I look in class PtrList<T> I can't find them?

greetings
maybee

GerhardHolzinger January 6, 2014 12:56

The answer to your question is inhertitance and polymorphism. Both are concepts in computer science and C++ implements them.

phases_ is of the type PtrDictionary<T>

The T means any data type that is compatible with all the operations performed on T.

If the class PtrDictionary does not define an operator (), then this class must have inherited this operator, otherwise the compiler would throw an error when compiling OpenFOAM.

Take a look from which class PtrDictionary is derived and then check this class. Note: C++ allows multiple inhertitance, i.e. class X can be derived from the classes A and B.
Somewhere up the family tree you will find a definition for the operator or function you are interested in.

maybee January 7, 2014 04:35

Quote:

If the class PtrDictionary does not define an operator (), then this class must have inherited this operator, otherwise the compiler would throw an error when compiling OpenFOAM.
In the PtrDictionary class reference also the inherited methods should be shown. Furthermore I have looked up the classes PtrDictionary is derived from. See:

http://foam.sourceforge.net/docs/cpp...ce.html#l00055

Also here I canīt find the operator (). See:

http://foam.sourceforge.net/docs/cpp...ce.html#l00055

and

http://foam.sourceforge.net/docs/cpp/a06384_source.html


All times are GMT -4. The time now is 21:19.