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

MeshedSurfaceZones.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 #include "MeshedSurface.H"
00027 
00028 // * * * * * * * * * * * * Protected Member Functions  * * * * * * * * * * * //
00029 
00030 template<class Face>
00031 void Foam::MeshedSurface<Face>::checkZones()
00032 {
00033     // extra safety, ensure we have at some zones
00034     // and they cover all the faces - fix start silently
00035     surfZoneList& zones = this->storedZones();
00036     if (zones.size())
00037     {
00038         label count = 0;
00039         forAll(zones, zoneI)
00040         {
00041             zones[zoneI].start() = count;
00042             count += zones[zoneI].size();
00043         }
00044 
00045         if (count < this->size())
00046         {
00047             WarningIn
00048             (
00049                 "MeshedSurface::checkZones()\n"
00050             )
00051                 << "more faces " << this->size() << " than zones " << count
00052                 << " ... extending final zone"
00053                 << endl;
00054 
00055             zones[zones.size()-1].size() += count - this->size();
00056         }
00057         else if (count > this->size())
00058         {
00059             FatalErrorIn
00060             (
00061                 "MeshedSurface::checkZones()\n"
00062             )
00063                 << "more zones " << count << " than faces " << this->size()
00064                 << exit(FatalError);
00065         }
00066     }
00067 }
00068 
00069 
00070 template<class Face>
00071 void Foam::MeshedSurface<Face>::sortFacesAndStore
00072 (
00073     const Xfer< List<Face> >& unsortedFaces,
00074     const Xfer< List<label> >& zoneIds,
00075     const bool sorted
00076 )
00077 {
00078     List<Face>  oldFaces(unsortedFaces);
00079     List<label> zones(zoneIds);
00080 
00081     if (sorted)
00082     {
00083         // already sorted - simply transfer faces
00084         this->storedFaces().transfer(oldFaces);
00085     }
00086     else
00087     {
00088         // unsorted - determine the sorted order:
00089         // avoid SortableList since we discard the main list anyhow
00090         List<label> faceMap;
00091         sortedOrder(zones, faceMap);
00092         zones.clear();
00093 
00094         // sorted faces
00095         List<Face> newFaces(faceMap.size());
00096         forAll(faceMap, faceI)
00097         {
00098             // use transfer to recover memory where possible
00099             newFaces[faceI].transfer(oldFaces[faceMap[faceI]]);
00100         }
00101         this->storedFaces().transfer(newFaces);
00102     }
00103     zones.clear();
00104 }
00105 
00106 
00107 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00108 
00109 template<class Face>
00110 void Foam::MeshedSurface<Face>::addZones
00111 (
00112     const UList<surfZone>& srfZones,
00113     const bool cullEmpty
00114 )
00115 {
00116     label nZone = 0;
00117 
00118     surfZoneList& zones = this->storedZones();
00119     zones.setSize(zones.size());
00120     forAll(zones, zoneI)
00121     {
00122         if (srfZones[zoneI].size() || !cullEmpty)
00123         {
00124             zones[nZone] = surfZone(srfZones[zoneI], nZone);
00125             nZone++;
00126         }
00127     }
00128     zones.setSize(nZone);
00129 }
00130 
00131 
00132 template<class Face>
00133 void Foam::MeshedSurface<Face>::addZones
00134 (
00135     const UList<label>& sizes,
00136     const UList<word>& names,
00137     const bool cullEmpty
00138 )
00139 {
00140     label start   = 0;
00141     label nZone = 0;
00142 
00143     surfZoneList& zones = this->storedZones();
00144     zones.setSize(sizes.size());
00145     forAll(zones, zoneI)
00146     {
00147         if (sizes[zoneI] || !cullEmpty)
00148         {
00149             zones[nZone] = surfZone
00150             (
00151                 names[zoneI],
00152                 sizes[zoneI],
00153                 start,
00154                 nZone
00155             );
00156             start += sizes[zoneI];
00157             nZone++;
00158         }
00159     }
00160     zones.setSize(nZone);
00161 }
00162 
00163 
00164 template<class Face>
00165 void Foam::MeshedSurface<Face>::addZones
00166 (
00167     const UList<label>& sizes,
00168     const bool cullEmpty
00169 )
00170 {
00171     label start   = 0;
00172     label nZone = 0;
00173 
00174     surfZoneList& zones = this->storedZones();
00175     zones.setSize(sizes.size());
00176     forAll(zones, zoneI)
00177     {
00178         if (sizes[zoneI] || !cullEmpty)
00179         {
00180             zones[nZone] = surfZone
00181             (
00182                 word("zone") + ::Foam::name(nZone),
00183                 sizes[zoneI],
00184                 start,
00185                 nZone
00186             );
00187             start += sizes[zoneI];
00188             nZone++;
00189         }
00190     }
00191     zones.setSize(nZone);
00192 }
00193 
00194 
00195 template<class Face>
00196 void Foam::MeshedSurface<Face>::removeZones()
00197 {
00198     this->storedZones().clear();
00199 }
00200 
00201 
00202 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines