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

faceSet.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 Description
00026     Selects a face set through a dictionary.
00027 
00028 \*---------------------------------------------------------------------------*/
00029 
00030 #include "argList.H"
00031 #include "Time.H"
00032 #include "polyMesh.H"
00033 #include "topoSetSource.H"
00034 #include "faceSet.H"
00035 
00036 using namespace Foam;
00037 
00038 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00039 
00040 // Copy set
00041 void backup
00042 (
00043     const polyMesh& mesh,
00044     const word& fromName,
00045     const topoSet& fromSet,
00046     const word& toName
00047 )
00048 {
00049     Info<< "Backing up " << fromName << " into " << toName << endl;
00050 
00051     topoSet backupSet(mesh, toName, fromSet);
00052 
00053     backupSet.write();
00054 }
00055 
00056 
00057 // Read and copy set
00058 void backup
00059 (
00060     const polyMesh& mesh,
00061     const word& fromName,
00062     const word& toName
00063 )
00064 {
00065     topoSet fromSet(mesh, fromName, IOobject::READ_IF_PRESENT);
00066 
00067     backup(mesh, fromName, fromSet, toName);
00068 }
00069 
00070 
00071 // Main program:
00072 
00073 int main(int argc, char *argv[])
00074 {
00075 #   include "setRootCase.H"
00076 #   include "createTime.H"
00077 #   include "createPolyMesh.H"
00078 
00079     Info<< "Reading faceSetDict\n" << endl;
00080 
00081     IOdictionary faceSetDict
00082     (
00083         IOobject
00084         (
00085             "faceSetDict",
00086             runTime.system(),
00087             mesh,
00088             IOobject::MUST_READ,
00089             IOobject::NO_WRITE
00090         )
00091     );
00092 
00093 
00094     word setName(faceSetDict.lookup("name"));
00095 
00096     word actionName(faceSetDict.lookup("action"));
00097 
00098     topoSetSource::setAction action = topoSetSource::toAction(actionName);
00099 
00100 
00101     // Create topoSetSources
00102     PtrList<topoSetSource> topoSetSources
00103     (
00104         faceSetDict.lookup("topoSetSources"),
00105         topoSetSource::iNew(mesh)
00106     );
00107 
00108 
00109     // Load set to work
00110     autoPtr<topoSet> currentSetPtr(NULL);
00111     IOobject::readOption r;
00112 
00113     if ((action == topoSetSource::NEW) || (action == topoSetSource::CLEAR))
00114     {
00115         r = IOobject::NO_READ;
00116 
00117         backup(mesh, setName, setName + "_old");
00118 
00119         currentSetPtr.reset
00120         (
00121             new faceSet
00122             (
00123                 mesh,
00124                 setName,
00125                 mesh.nFaces()/10+1  // Reasonable size estimate.
00126             )
00127         );
00128     }
00129     else
00130     {
00131         r = IOobject::MUST_READ;
00132 
00133         currentSetPtr.reset
00134         (
00135             new faceSet
00136             (
00137                 mesh,
00138                 setName,
00139                 r
00140             )
00141         );
00142     }
00143 
00144     topoSet& currentSet = currentSetPtr();
00145 
00146     Info<< "Set:" << currentSet.name()
00147         << "  Size:" << currentSet.size()
00148         << "  Action:" << actionName
00149         << endl;
00150 
00151     if ((r == IOobject::MUST_READ) && (action != topoSetSource::LIST))
00152     {
00153         // currentSet has been read so can make copy.
00154         backup(mesh, setName, currentSet, setName + "_old");
00155     }
00156 
00157     if (action == topoSetSource::CLEAR)
00158     {
00159         // Already handled above by not reading
00160     }
00161     else if (action == topoSetSource::INVERT)
00162     {
00163         currentSet.invert(currentSet.maxSize(mesh));
00164     }
00165     else if (action == topoSetSource::LIST)
00166     {
00167         currentSet.writeDebug(Info, mesh, 100);
00168         Info<< endl;
00169     }
00170     else if (action == topoSetSource::SUBSET)
00171     {
00172         // Apply topoSetSources to it to handle new/add/delete
00173         forAll(topoSetSources, topoSetSourceI)
00174         {
00175             // Backup current set.
00176             topoSet oldSet(mesh, currentSet.name() + "_old2", currentSet);
00177 
00178             currentSet.clear();
00179 
00180             topoSetSources[topoSetSourceI].applyToSet
00181             (
00182                 topoSetSource::NEW,
00183                 currentSet
00184             );
00185 
00186             // Combine new value of currentSet with old one.
00187             currentSet.subset(oldSet);
00188         }
00189     }
00190     else
00191     {
00192         // Apply topoSetSources to it to handle new/add/delete
00193         forAll(topoSetSources, topoSetSourceI)
00194         {
00195             topoSetSources[topoSetSourceI].applyToSet(action, currentSet);
00196         }
00197     }
00198 
00199 
00200     if (action != topoSetSource::LIST)
00201     {
00202         // Set has changed.
00203 
00204         // Sync across coupled patches.
00205         currentSet.sync(mesh);
00206 
00207         Info<< "Writing " << currentSet.name()
00208             << " (size " << currentSet.size() << ") to "
00209             << currentSet.instance()/currentSet.local()
00210                /currentSet.name()
00211             << endl << endl;
00212 
00213         currentSet.write();
00214     }
00215 
00216     Info << nl << "End" << endl;
00217 
00218     return 0;
00219 }
00220 
00221 
00222 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd