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

cellZoneSet.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 "cellZoneSet.H"
00027 #include <OpenFOAM/mapPolyMesh.H>
00028 #include <OpenFOAM/polyMesh.H>
00029 #include <OpenFOAM/processorPolyPatch.H>
00030 #include <OpenFOAM/cyclicPolyPatch.H>
00031 
00032 #include <OpenFOAM/addToRunTimeSelectionTable.H>
00033 
00034 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00035 
00036 namespace Foam
00037 {
00038 
00039 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00040 
00041 defineTypeNameAndDebug(cellZoneSet, 0);
00042 
00043 addToRunTimeSelectionTable(topoSet, cellZoneSet, word);
00044 addToRunTimeSelectionTable(topoSet, cellZoneSet, size);
00045 addToRunTimeSelectionTable(topoSet, cellZoneSet, set);
00046 
00047 
00048 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00049 
00050 void cellZoneSet::updateSet()
00051 {
00052     labelList order;
00053     sortedOrder(addressing_, order);
00054     inplaceReorder(order, addressing_);
00055 
00056     cellSet::clearStorage();
00057     cellSet::resize(2*addressing_.size());
00058     forAll(addressing_, i)
00059     {
00060         cellSet::insert(addressing_[i]);
00061     }
00062 }
00063 
00064 
00065 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00066 
00067 cellZoneSet::cellZoneSet
00068 (
00069     const polyMesh& mesh,
00070     const word& name,
00071     readOption r,
00072     writeOption w
00073 )
00074 :
00075     cellSet(mesh, name, 1000),  // do not read cellSet
00076     mesh_(mesh),
00077     addressing_(0)
00078 {
00079     const cellZoneMesh& cellZones = mesh.cellZones();
00080     label zoneID = cellZones.findZoneID(name);
00081 
00082     if
00083     (
00084         (r == IOobject::MUST_READ)
00085      || (r == IOobject::READ_IF_PRESENT && zoneID != -1)
00086     )
00087     {
00088         const cellZone& fz = cellZones[zoneID];
00089         addressing_ = fz;
00090     }
00091 
00092     updateSet();
00093 
00094     check(mesh.nCells());
00095 }
00096 
00097 
00098 cellZoneSet::cellZoneSet
00099 (
00100     const polyMesh& mesh,
00101     const word& name,
00102     const label size,
00103     writeOption w
00104 )
00105 :
00106     cellSet(mesh, name, size, w),
00107     mesh_(mesh),
00108     addressing_(0)
00109 {
00110     updateSet();
00111 }
00112 
00113 
00114 cellZoneSet::cellZoneSet
00115 (
00116     const polyMesh& mesh,
00117     const word& name,
00118     const topoSet& set,
00119     writeOption w
00120 )
00121 :
00122     cellSet(mesh, name, set.size(), w),
00123     mesh_(mesh),
00124     addressing_(refCast<const cellZoneSet>(set).addressing())
00125 {
00126     updateSet();
00127 }
00128 
00129 
00130 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00131 
00132 cellZoneSet::~cellZoneSet()
00133 {}
00134 
00135 
00136 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00137 
00138 void cellZoneSet::invert(const label maxLen)
00139 {
00140     label n = 0;
00141 
00142     for (label cellI = 0; cellI < maxLen; cellI++)
00143     {
00144         if (!found(cellI))
00145         {
00146             addressing_[n] = cellI;
00147             n++;
00148         }
00149     }
00150     addressing_.setSize(n);
00151     updateSet();
00152 }
00153 
00154 
00155 void cellZoneSet::subset(const topoSet& set)
00156 {
00157     DynamicList<label> newAddressing(addressing_.size());
00158 
00159     const cellZoneSet& fSet = refCast<const cellZoneSet>(set);
00160 
00161     forAll(fSet.addressing(), i)
00162     {
00163         label cellI = fSet.addressing()[i];
00164 
00165         if (found(cellI))
00166         {
00167             newAddressing.append(cellI);
00168         }
00169     }
00170 
00171     addressing_.transfer(newAddressing);
00172     updateSet();
00173 }
00174 
00175 
00176 void cellZoneSet::addSet(const topoSet& set)
00177 {
00178     DynamicList<label> newAddressing(addressing_);
00179 
00180     const cellZoneSet& fSet = refCast<const cellZoneSet>(set);
00181 
00182     forAll(fSet.addressing(), i)
00183     {
00184         label cellI = fSet.addressing()[i];
00185 
00186         if (!found(cellI))
00187         {
00188             newAddressing.append(cellI);
00189         }
00190     }
00191 
00192     addressing_.transfer(newAddressing);
00193     updateSet();
00194 }
00195 
00196 
00197 void cellZoneSet::deleteSet(const topoSet& set)
00198 {
00199     DynamicList<label> newAddressing(addressing_.size());
00200 
00201     const cellZoneSet& fSet = refCast<const cellZoneSet>(set);
00202 
00203     forAll(addressing_, i)
00204     {
00205         label cellI = addressing_[i];
00206 
00207         if (!fSet.found(cellI))
00208         {
00209             // Not found in fSet so add
00210             newAddressing.append(cellI);
00211         }
00212     }
00213 
00214     addressing_.transfer(newAddressing);
00215     updateSet();
00216 }
00217 
00218 
00219 void cellZoneSet::sync(const polyMesh& mesh)
00220 {}
00221 
00222 
00223 label cellZoneSet::maxSize(const polyMesh& mesh) const
00224 {
00225     return mesh.nCells();
00226 }
00227 
00228 
00229 //- Write using given format, version and compression
00230 bool cellZoneSet::writeObject
00231 (
00232     IOstream::streamFormat s,
00233     IOstream::versionNumber v,
00234     IOstream::compressionType c
00235 ) const
00236 {
00237     // Write shadow cellSet
00238     word oldTypeName = typeName;
00239     const_cast<word&>(type()) = cellSet::typeName;
00240     bool ok = cellSet::writeObject(s, v, c);
00241     const_cast<word&>(type()) = oldTypeName;
00242 
00243     // Modify cellZone
00244     cellZoneMesh& cellZones = const_cast<polyMesh&>(mesh_).cellZones();
00245     label zoneID = cellZones.findZoneID(name());
00246 
00247     if (zoneID == -1)
00248     {
00249         zoneID = cellZones.size();
00250 
00251         cellZones.setSize(zoneID+1);
00252         cellZones.set
00253         (
00254             zoneID,
00255             new cellZone
00256             (
00257                 name(),
00258                 addressing_,
00259                 zoneID,
00260                 cellZones
00261             )
00262         );
00263     }
00264     else
00265     {
00266         cellZones[zoneID] = addressing_;
00267     }
00268     cellZones.clearAddressing();
00269 
00270     return ok && cellZones.write();
00271 }
00272 
00273 
00274 void cellZoneSet::updateMesh(const mapPolyMesh& morphMap)
00275 {
00276     // cellZone
00277     labelList newAddressing(addressing_.size());
00278 
00279     label n = 0;
00280     forAll(addressing_, i)
00281     {
00282         label cellI = addressing_[i];
00283         label newCellI = morphMap.reverseCellMap()[cellI];
00284         if (newCellI >= 0)
00285         {
00286             newAddressing[n] = newCellI;
00287             n++;
00288         }
00289     }
00290     newAddressing.setSize(n);
00291 
00292     addressing_.transfer(newAddressing);
00293 
00294     updateSet();
00295 }
00296 
00297 
00298 void cellZoneSet::writeDebug
00299 (
00300     Ostream& os,
00301     const primitiveMesh& mesh,
00302     const label maxLen
00303 ) const
00304 {
00305     cellSet::writeDebug(os, mesh, maxLen);
00306 }
00307 
00308 
00309 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00310 
00311 } // End namespace Foam
00312 
00313 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines