OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

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