FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

ParSortableList.H

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2010 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software: you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
00023 
00024 Class
00025     Foam::ParSortableList
00026 
00027 Description
00028     Implementation of PSRS parallel sorting routine.
00029 
00030     From "On the Versatility of Parallel Sorting by Regular Sampling"
00031     Xiaobo Li et. all.
00032 
00033     Construct from list of things to sort (uses SortableList, 'thing' should
00034     implement >, ==).
00035 
00036     Will contain sorted data and in
00037         - indices() the original indices
00038         - procs() the original processor id.
00039 
00040     Can also be constructed from size, filled at ease and then sort()'ed.
00041 
00042 SourceFiles
00043     ParSortableList.C
00044 
00045 \*---------------------------------------------------------------------------*/
00046 
00047 #ifndef ParSortableList_H
00048 #define ParSortableList_H
00049 
00050 #include <OpenFOAM/labelList.H>
00051 
00052 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00053 
00054 namespace Foam
00055 {
00056 
00057 
00058 /*---------------------------------------------------------------------------*\
00059                         Class ParSortableListName Declaration
00060 \*---------------------------------------------------------------------------*/
00061 
00062 TemplateName(ParSortableList);
00063 
00064 
00065 /*---------------------------------------------------------------------------*\
00066                            Class ParSortableList Declaration
00067 \*---------------------------------------------------------------------------*/
00068 
00069 template <class Type>
00070 class ParSortableList
00071 :
00072     public ParSortableListName,
00073     public List<Type>
00074 {
00075     // Private data
00076 
00077         //- Original indices
00078         labelList indices_;
00079 
00080         //- Processor numbers
00081         labelList procs_;
00082 
00083 
00084     // Private class
00085 
00086         //- Private class for sorting. Sorts on value_.
00087         class taggedValue
00088         {
00089             // Private data
00090 
00091                 //- Value
00092                 Type value_;
00093 
00094                 //- Index
00095                 label index_;
00096 
00097                 //- Proc
00098                 label procID_;
00099 
00100 
00101         public:
00102 
00103             // Constructors
00104 
00105                 taggedValue()
00106                 {}
00107 
00108             // Member Functions
00109 
00110                 const Type& value() const
00111                 {
00112                     return value_;
00113                 }
00114 
00115                 Type& value()
00116                 {
00117                     return value_;
00118                 }
00119 
00120                 label index() const
00121                 {
00122                     return index_;
00123                 }
00124 
00125                 label& index()
00126                 {
00127                     return index_;
00128                 }
00129 
00130                 label procID() const
00131                 {
00132                     return procID_;
00133                 }
00134 
00135                 label& procID()
00136                 {
00137                     return procID_;
00138                 }
00139         };
00140 
00141 
00142     // Private Member Functions
00143 
00144         //- Write for debugging
00145         void write(const List<Type>& elems, Ostream& os) const;
00146 
00147         //- Copy into dest, setting indices and processor no.
00148         void copyInto
00149         (
00150             const List<Type>& values,
00151             const labelList& indices,
00152             const label fromProcNo,
00153             label& destI,
00154             List<taggedValue>& dest
00155         ) const;
00156 
00157         //- Calculate pivots.
00158         void getPivots(const List<Type>& elems, List<Type>& pivots) const;
00159 
00160         //- If destProc != myProcNo send & clear values and indices
00161         void checkAndSend
00162         (
00163             List<Type>& values,
00164             labelList& indices,
00165             const label bufSize,
00166             const label destProcI
00167         ) const;
00168 
00169 
00170 public:
00171 
00172     // Constructors
00173 
00174         //- Construct from List, sorting the elements.
00175         ParSortableList(const UList<Type>&);
00176 
00177         //- Construct given size. Sort later on.
00178         ParSortableList(const label size);
00179 
00180 
00181     // Member Functions
00182 
00183         //- (stable) sort the list (if changed after construction time)
00184         void sort();
00185 
00186         //- Return the list of sorted point indices
00187         const labelList& indices() const
00188         {
00189             return indices_;
00190         }
00191 
00192         //- Return the list of processor number
00193         const labelList& procs() const
00194         {
00195             return procs_;
00196         }
00197 };
00198 
00199 
00200 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00201 
00202 } // End namespace Foam
00203 
00204 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00205 
00206 #ifdef NoRepository
00207 #   include <OpenFOAM/ParSortableList.C>
00208 #endif
00209 
00210 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00211 
00212 #endif
00213 
00214 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines