initial commit for version 1.5.x patch release
[OpenFOAM-1.5.x.git] / applications / utilities / mesh / manipulation / faceSet / faceSet.C
blob26d206e5cfca648c6a27713b596c2b1c565a61b5
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software; you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 Description
26     Selects a face set through a dictionary.
28 \*---------------------------------------------------------------------------*/
30 #include "argList.H"
31 #include "Time.H"
32 #include "polyMesh.H"
33 #include "topoSetSource.H"
34 #include "faceSet.H"
36 using namespace Foam;
38 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
40 // Copy set
41 void backup
43     const polyMesh& mesh,
44     const word& fromName,
45     const topoSet& fromSet,
46     const word& toName
49     Info<< "Backing up " << fromName << " into " << toName << endl;
51     topoSet backupSet(mesh, toName, fromSet);
53     backupSet.write();
57 // Read and copy set
58 void backup
60     const polyMesh& mesh,
61     const word& fromName,
62     const word& toName
65     topoSet fromSet(mesh, fromName, IOobject::READ_IF_PRESENT);
67     backup(mesh, fromName, fromSet, toName);
71 // Main program:
73 int main(int argc, char *argv[])
75 #   include "setRootCase.H"
76 #   include "createTime.H"
78     Info<< "Reading mesh for time = " << runTime.value() << endl;
80     Info<< "Create mesh\n" << endl;
81     polyMesh mesh
82     (
83         IOobject
84         (
85             polyMesh::defaultRegion,
86             runTime.timeName(),
87             runTime
88         )
89     );
91     Info<< "Reading faceSetDict\n" << endl;
93     IOdictionary faceSetDict
94     (
95         IOobject
96         (
97             "faceSetDict",
98             runTime.system(),
99             mesh,
100             IOobject::MUST_READ,
101             IOobject::NO_WRITE
102         )
103     );
106     word setName(faceSetDict.lookup("name"));
108     word actionName(faceSetDict.lookup("action"));
110     topoSetSource::setAction action = topoSetSource::toAction(actionName);
113     // Create topoSetSources
114     PtrList<topoSetSource> topoSetSources
115     (
116         faceSetDict.lookup("topoSetSources"),
117         topoSetSource::iNew(mesh)
118     );
121     // Load set to work
122     autoPtr<topoSet> currentSetPtr(NULL);
123     IOobject::readOption r;
125     if ((action == topoSetSource::NEW) || (action == topoSetSource::CLEAR))
126     {
127         r = IOobject::NO_READ;
129         backup(mesh, setName, setName + "_old");
131         currentSetPtr.reset
132         (
133             new faceSet
134             (
135                 mesh,
136                 setName,
137                 mesh.nFaces()/10+1  // Reasonable size estimate.
138             )
139         );
140     }
141     else
142     {
143         r = IOobject::MUST_READ;
145         currentSetPtr.reset
146         (
147             new faceSet
148             (
149                 mesh,
150                 setName,
151                 r
152             )
153         );
154     }
156     topoSet& currentSet = currentSetPtr();
158     Info<< "Set:" << currentSet.name()
159         << "  Size:" << currentSet.size()
160         << "  Action:" << actionName
161         << endl;
163     if ((r == IOobject::MUST_READ) && (action != topoSetSource::LIST))
164     {
165         // currentSet has been read so can make copy.
166         backup(mesh, setName, currentSet, setName + "_old");
167     }
169     if (action == topoSetSource::CLEAR)
170     {
171         // Already handled above by not reading
172     }
173     else if (action == topoSetSource::INVERT)
174     {
175         currentSet.invert(currentSet.maxSize(mesh));
176     }
177     else if (action == topoSetSource::LIST)
178     {
179         currentSet.writeDebug(Info, mesh, 100);
180         Info<< endl;
181     }
182     else if (action == topoSetSource::SUBSET)
183     {
184         // Apply topoSetSources to it to handle new/add/delete
185         forAll(topoSetSources, topoSetSourceI)
186         {
187             // Backup current set.
188             topoSet oldSet(mesh, currentSet.name() + "_old2", currentSet);
190             currentSet.clear();
192             topoSetSources[topoSetSourceI].applyToSet
193             (
194                 topoSetSource::NEW,
195                 currentSet
196             );
198             // Combine new value of currentSet with old one.
199             currentSet.subset(oldSet);
200         }
201     }
202     else
203     {
204         // Apply topoSetSources to it to handle new/add/delete
205         forAll(topoSetSources, topoSetSourceI)
206         {
207             topoSetSources[topoSetSourceI].applyToSet(action, currentSet);
208         }
209     }
212     if (action != topoSetSource::LIST)
213     {
214         // Set has changed.
216         // Sync across coupled patches.
217         currentSet.sync(mesh);
219         Info<< "Writing " << currentSet.name()
220             << " (size " << currentSet.size() << ") to "
221             << currentSet.instance()/currentSet.local()
222                /currentSet.name()
223             << endl << endl;
225         currentSet.write();
226     }
228     Info << nl << "End" << endl;
230     return 0;
234 // ************************************************************************* //