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

ListOps.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 InNamspace
00025     Foam
00026 
00027 Description
00028     Various functions to operate on Lists.
00029 
00030 SourceFiles
00031     ListOps.C
00032     ListOpsTemplates.C
00033 
00034 \*---------------------------------------------------------------------------*/
00035 
00036 #ifndef ListOps_H
00037 #define ListOps_H
00038 
00039 #include <OpenFOAM/labelList.H>
00040 
00041 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00042 
00043 namespace Foam
00044 {
00045 
00046 //- Renumber the values (not the indices) of a list.
00047 //  Negative ListType elements are left as is.
00048 template<class ListType>
00049 ListType renumber(const UList<label>& oldToNew, const ListType&);
00050 
00051 //- Inplace renumber the values of a list.
00052 //  Negative ListType elements are left as is.
00053 template<class ListType>
00054 void inplaceRenumber(const UList<label>& oldToNew, ListType&);
00055 
00056 
00057 //- Reorder the elements (indices, not values) of a list.
00058 //  Negative ListType elements are left as is.
00059 template<class ListType>
00060 ListType reorder(const UList<label>& oldToNew, const ListType&);
00061 
00062 //- Inplace reorder the elements of a list.
00063 //  Negative ListType elements are left as is.
00064 template<class ListType>
00065 void inplaceReorder(const UList<label>& oldToNew, ListType&);
00066 
00067 
00068 // Variants to work with iterators and sparse tables.
00069 // Need to have iterators and insert()
00070 
00071 //- Map values. Do not map negative values.
00072 template<class Container>
00073 void inplaceMapValue(const UList<label>& oldToNew, Container&);
00074 
00075 //- Recreate with mapped keys. Do not map elements with negative key.
00076 template<class Container>
00077 void inplaceMapKey(const UList<label>& oldToNew, Container&);
00078 
00079 
00080 //- Generate the (stable) sort order for the list
00081 template<class T>
00082 void sortedOrder(const UList<T>&, labelList& order);
00083 
00084 //- Generate (sorted) indices corresponding to duplicate list values
00085 template<class T>
00086 void duplicateOrder(const UList<T>&, labelList& order);
00087 
00088 //- Generate (sorted) indices corresponding to unique list values
00089 template<class T>
00090 void uniqueOrder(const UList<T>&, labelList& order);
00091 
00092 //- Extract elements of List when select is a certain value.
00093 //  eg, to extract all selected elements:
00094 //    subset<bool, labelList>(selectedElems, true, lst);
00095 template<class T, class ListType>
00096 ListType subset(const UList<T>& select, const T& value, const ListType&);
00097 
00098 //- Inplace extract elements of List when select is a certain value.
00099 //  eg, to extract all selected elements:
00100 //    inplaceSubset<bool, labelList>(selectedElems, true, lst);
00101 template<class T, class ListType>
00102 void inplaceSubset(const UList<T>& select, const T& value, ListType&);
00103 
00104 //- Extract elements of List when select is true
00105 //  eg, to extract all selected elements:
00106 //    subset<boolList, labelList>(selectedElems, lst);
00107 //  Note a labelHashSet could also be used for the bool-list
00108 template<class BoolListType, class ListType>
00109 ListType subset(const BoolListType& select, const ListType&);
00110 
00111 //- Inplace extract elements of List when select is true
00112 //  eg, to extract all selected elements:
00113 //    inplaceSubset<boolList, labelList>(selectedElems, lst);
00114 //  Note a labelHashSet could also be used for the bool-list
00115 template<class BoolListType, class ListType>
00116 void inplaceSubset(const BoolListType& select, ListType&);
00117 
00118 //- Invert one-to-one map. Unmapped elements will be -1.
00119 labelList invert(const label len, const UList<label>&);
00120 
00121 //- Invert one-to-many map. Unmapped elements will be size 0.
00122 labelListList invertOneToMany(const label len, const UList<label>&);
00123 
00124 //- Invert many-to-many.
00125 //  Input and output types need to be inherited from List.
00126 //  eg, faces to pointFaces.
00127 template<class InList, class OutList>
00128 void invertManyToMany(const label len, const UList<InList>&, List<OutList>&);
00129 
00130 template<class InList, class OutList>
00131 List<OutList> invertManyToMany(const label len, const UList<InList>& in)
00132 {
00133     List<OutList> out;
00134     invertManyToMany<InList,OutList>(len, in, out);
00135     return out;
00136 }
00137 
00138 //- Create identity map (map[i] == i) of given length
00139 labelList identity(const label len);
00140 
00141 //- Find first occurence of given element and return index,
00142 //  return -1 if not found. Linear search.
00143 template<class ListType>
00144 label findIndex
00145 (
00146     const ListType&,
00147     typename ListType::const_reference,
00148     const label start=0
00149 );
00150 
00151 //- Find all occurences of given element. Linear search.
00152 template<class ListType>
00153 labelList findIndices
00154 (
00155     const ListType&,
00156     typename ListType::const_reference,
00157     const label start=0
00158 );
00159 
00160 //- Opposite of findIndices: set values at indices to given value
00161 template<class ListType>
00162 void setValues
00163 (
00164     ListType&,
00165     const UList<label>& indices,
00166     typename ListType::const_reference
00167 );
00168 
00169 //- Opposite of findIndices: set values at indices to given value
00170 template<class ListType>
00171 ListType createWithValues
00172 (
00173     const label sz,
00174     typename ListType::const_reference initValue,
00175     const UList<label>& indices,
00176     typename ListType::const_reference setValue
00177 );
00178 
00179 //- Find index of max element (and larger than given element).
00180 //  return -1 if not found. Linear search.
00181 template<class ListType>
00182 label findMax(const ListType&, const label start=0);
00183 
00184 
00185 //- Find index of min element (and less than given element).
00186 //  return -1 if not found. Linear search.
00187 template<class ListType>
00188 label findMin(const ListType&, const label start=0);
00189 
00190 
00191 //- Find first occurence of given element in sorted list and return index,
00192 //  return -1 if not found. Binary search.
00193 template<class ListType>
00194 label findSortedIndex
00195 (
00196     const ListType&,
00197     typename ListType::const_reference,
00198     const label start=0
00199 );
00200 
00201 
00202 //- Find last element < given value in sorted list and return index,
00203 //  return -1 if not found. Binary search.
00204 template<class ListType>
00205 label findLower
00206 (
00207     const ListType&,
00208     typename ListType::const_reference,
00209     const label start=0
00210 );
00211 
00212 
00213 //- To construct a List from a C array. Has extra Container type
00214 //  to initialise e.g. wordList from arrays of char*.
00215 template<class Container, class T, int nRows>
00216 List<Container> initList(const T[nRows]);
00217 
00218 
00219 //- To construct a (square) ListList from a C array. Has extra Container type
00220 //  to initialise e.g. faceList from arrays of labels.
00221 template<class Container, class T, int nRows, int nColumns>
00222 List<Container> initListList(const T[nRows][nColumns]);
00223 
00224 
00225 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00226 
00227 } // End namespace Foam
00228 
00229 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00230 
00231 #ifdef NoRepository
00232 #   include "ListOpsTemplates.C"
00233 #endif
00234 
00235 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00236 
00237 #endif
00238 
00239 // ************************ vim: set sw=4 sts=4 et: ************************ //
00240 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines