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

ListListOps.C

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 \*---------------------------------------------------------------------------*/
00025 
00026 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00027 
00028 namespace Foam
00029 {
00030 
00031 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00032 
00033 template <class AccessType, class T, class AccessOp>
00034 AccessType ListListOps::combine(const List<T>& lst, AccessOp aop)
00035 {
00036     label sum = 0;
00037 
00038     forAll(lst, lstI)
00039     {
00040         sum += aop(lst[lstI]).size();
00041     }
00042 
00043     AccessType result(sum);
00044 
00045     label globalElemI = 0;
00046 
00047     forAll(lst, lstI)
00048     {
00049         const T& sub = lst[lstI];
00050 
00051         forAll(aop(sub), elemI)
00052         {
00053             result[globalElemI++] = aop(sub)[elemI];
00054         }
00055     }
00056     return result;
00057 }
00058 
00059 
00060 template <class T, class AccessOp>
00061 labelList ListListOps::subSizes(const List<T>& lst, AccessOp aop)
00062 {
00063     labelList sizes(lst.size());
00064 
00065     forAll(lst, lstI)
00066     {
00067         sizes[lstI] = aop(lst[lstI]).size();
00068     }
00069     return sizes;
00070 }
00071 
00072 
00073 template <class AccessType, class T, class AccessOp, class OffsetOp>
00074 AccessType ListListOps::combineOffset
00075 (
00076     const List<T>& lst,
00077     const labelList& sizes,
00078     AccessOp aop,
00079     OffsetOp oop
00080 )
00081 {
00082     label sum = 0;
00083 
00084     forAll(lst, lstI)
00085     {
00086         sum += aop(lst[lstI]).size();
00087     }
00088 
00089     AccessType result(sum);
00090 
00091     label globalElemI = 0;
00092 
00093     label offset = 0;
00094 
00095     forAll(lst, lstI)
00096     {
00097         const T& sub = lst[lstI];
00098 
00099         forAll(aop(sub), elemI)
00100         {
00101             result[globalElemI++] = oop(aop(sub)[elemI], offset);
00102         }
00103 
00104         offset += sizes[lstI];
00105     }
00106     return result;
00107 }
00108 
00109 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00110 
00111 } // End namespace Foam
00112 
00113 
00114 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines