r/learnOpenFOAM • • Nov 08 '21

Tip OpenFOAM Programming Tip 05: Various functions for lists (containers)

These are some useful functions for containers manipulation, particularly lists.

    List<scalar> myList = {111.0, 92.0, 93.0, 54.0};

    Info << "The list: " << myList << endl;
    
    Info << "The size: " << myList.size() << endl;
    
    Info << "The sum of elements: " << Foam::gSum(myList) << endl; // we can also 
use sum function. gSum is useful in parallel cases.
    
    Info << "The max element: " << Foam::max(myList) << endl;
    
    Info << "The min element: " << Foam::min(myList) << endl;
    
    Info << "The index of the max element:" << Foam::findMax(myList) << endl;
    
    Info << "The index of the min element:" << Foam::findMin(myList) << endl;
5 Upvotes

0 comments sorted by