1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software; you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
29 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
34 const labelList& oldToNew,
39 List newLst(lst.size());
45 newLst[elemI] = oldToNew[lst[elemI]];
54 void Foam::inplaceRenumber
56 const labelList& oldToNew,
64 lst[elemI] = oldToNew[lst[elemI]];
73 const labelList& oldToNew,
78 List newLst(lst.size());
82 if (oldToNew[elemI] >= 0)
84 newLst[oldToNew[elemI]] = lst[elemI];
88 newLst[elemI] = lst[elemI];
96 void Foam::inplaceReorder
98 const labelList& oldToNew,
103 List newLst(lst.size());
107 if (oldToNew[elemI] >= 0)
109 newLst[oldToNew[elemI]] = lst[elemI];
113 newLst[elemI] = lst[elemI];
117 lst.transfer(newLst);
121 template<class Container>
122 void Foam::inplaceMapValue
124 const labelList& oldToNew,
130 typename Container::iterator iter = lst.begin();
137 iter() = oldToNew[iter()];
143 template<class Container>
144 void Foam::inplaceMapKey
146 const labelList& oldToNew,
150 Container newLst(lst);
154 typename Container::iterator iter = lst.begin();
161 newLst.insert(oldToNew[iter.key()], iter());
165 lst.transfer(newLst);
169 template<class T, class List>
170 List Foam::subset(const UList<T>& regions, const T& region, const List& lst)
172 if (regions.size() < lst.size())
174 FatalErrorIn("subset(const UList<T>&, const T&, const List&)")
175 << "Regions is of size " << regions.size()
176 << "; list it is supposed to index is of size " << lst.size()
177 << abort(FatalError);
180 List newLst(lst.size());
185 if (regions[elemI] == region)
187 newLst[nElem++] = lst[elemI];
190 newLst.setSize(nElem);
196 template<class T, class List>
197 void Foam::inplaceSubset(const UList<T>& regions, const T& region, List& lst)
199 if (regions.size() < lst.size())
201 FatalErrorIn("inplaceSubset(const UList<T>&, const T&, List&)")
202 << "Regions is of size " << regions.size()
203 << "; list it is supposed to index is of size " << lst.size()
204 << abort(FatalError);
210 if (regions[elemI] == region)
214 lst[nElem] = lst[elemI];
224 // As clarification coded as inversion from pointEdges to edges but completely
226 template<class InList, class OutList>
227 void Foam::invertManyToMany
230 const UList<InList>& pointEdges,
234 // Number of points per edge
235 labelList nPointsPerEdge(nEdges, 0);
237 forAll(pointEdges, pointI)
239 const InList& pEdges = pointEdges[pointI];
243 nPointsPerEdge[pEdges[j]]++;
248 edges.setSize(nEdges);
250 forAll(nPointsPerEdge, edgeI)
252 edges[edgeI].setSize(nPointsPerEdge[edgeI]);
257 forAll(pointEdges, pointI)
259 const InList& pEdges = pointEdges[pointI];
263 label edgeI = pEdges[j];
265 edges[edgeI][nPointsPerEdge[edgeI]++] = pointI;
272 Foam::label Foam::findIndex
275 typename List::const_reference t,
281 for (label i = start; i < l.size(); i++)
295 Foam::labelList Foam::findIndices
298 typename List::const_reference t,
305 for (label i = start; i < l.size(); i++)
314 labelList indices(n);
317 for (label i = start; i < l.size(); i++)
333 const labelList& indices,
334 typename List::const_reference t
345 List Foam::createWithValues
348 const typename List::const_reference initValue,
349 const labelList& indices,
350 typename List::const_reference setValue
353 List l(sz, initValue);
354 setValues(l, indices, setValue);
360 Foam::label Foam::findMax(const List& l, const label start)
362 if (start >= l.size())
369 for (label i = start+1; i < l.size(); i++)
382 Foam::label Foam::findMin(const List& l, const label start)
384 if (start >= l.size())
391 for (label i = start+1; i < l.size(); i++)
404 Foam::label Foam::findSortedIndex
407 typename List::const_reference t,
411 if (start >= l.size())
417 label high = l.size() - 1;
421 label mid = (low + high)/2;
442 Foam::label Foam::findLower
445 typename List::const_reference t,
449 if (start >= l.size())
455 label high = l.size() - 1;
457 while ((high - low) > 1)
459 label mid = (low + high)/2;
489 template<class Container, class T, int nRows>
490 Foam::List<Container> Foam::initList(const T elems[nRows])
492 List<Container> faces(nRows);
496 faces[faceI] = Container(elems[faceI]);
502 template<class Container, class T, int nRows, int nColumns>
503 Foam::List<Container> Foam::initListList(const T elems[nRows][nColumns])
505 List<Container> faces(nRows);
507 Container f(nColumns);
512 f[i] = elems[faceI][i];
520 // ************************************************************************* //