BUG: UListIO: byteSize overflowing on really big faceLists
[OpenFOAM-2.0.x.git] / applications / utilities / mesh / manipulation / topoSet / topoSet.C
blobd097b457e86144004b2f147e91680b51a4fe4cee
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
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
13     the Free Software Foundation, either version 3 of the License, or
14     (at your 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, see <http://www.gnu.org/licenses/>.
24 Description
25     Operates on cellSets/faceSets/pointSets through a dictionary.
27 \*---------------------------------------------------------------------------*/
29 #include "argList.H"
30 #include "Time.H"
31 #include "polyMesh.H"
32 #include "topoSetSource.H"
33 #include "cellSet.H"
34 #include "faceSet.H"
35 #include "pointSet.H"
37 using namespace Foam;
39 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41 // Main program:
43 int main(int argc, char *argv[])
45     argList::addOption
46     (
47         "dict",
48         "file",
49         "specify an alternative dictionary for the topoSet dictionary"
50     );
51 #   include "addRegionOption.H"
52     argList::addBoolOption
53     (
54         "noSync",
55         "do not synchronise selection across coupled patches"
56     );
58 #   include "setRootCase.H"
59 #   include "createTime.H"
60 #   include "createNamedPolyMesh.H"
62     const bool noSync = args.optionFound("noSync");
64     const word dictName("topoSetDict");
66     fileName dictPath = dictName;
67     if (args.optionFound("dict"))
68     {
69         dictPath = args["dict"];
70         if (isDir(dictPath))
71         {
72             dictPath = dictPath / dictName;
73         }
74     }
76     Info<< "Reading " << dictName << "\n" << endl;
78     IOdictionary topoSetDict
79     (
80         (
81             args.optionFound("dict")
82           ? IOobject
83             (
84                 dictPath,
85                 mesh,
86                 IOobject::MUST_READ_IF_MODIFIED,
87                 IOobject::NO_WRITE
88             )
89           : IOobject
90             (
91                 dictName,
92                 runTime.system(),
93                 mesh,
94                 IOobject::MUST_READ_IF_MODIFIED,
95                 IOobject::NO_WRITE
96             )
97         ) 
98     );
101     // Read set construct info from dictionary
102     PtrList<dictionary> patchSources(topoSetDict.lookup("actions"));
104     forAll(patchSources, i)
105     {
106         const dictionary& dict = patchSources[i];
108         const word setName(dict.lookup("name"));
109         const word actionName(dict.lookup("action"));
110         const word setType(dict.lookup("type"));
113         topoSetSource::setAction action = topoSetSource::toAction(actionName);
115         autoPtr<topoSet> currentSet;
116         if
117         (
118             (action == topoSetSource::NEW)
119          || (action == topoSetSource::CLEAR)
120         )
121         {
122             currentSet = topoSet::New(setType, mesh, setName, 10000);
123             Info<< "Created set " << setName << endl;
124         }
125         else if (action == topoSetSource::REMOVE)
126         {
127             //?
128         }
129         else
130         {
131             currentSet = topoSet::New
132             (
133                 setType,
134                 mesh,
135                 setName,
136                 IOobject::MUST_READ
137             );
138             Info<< "Read set " << setName << " with size "
139                 << currentSet().size() << endl;
140         }
144         // Handle special actions (clear, invert) locally, rest through sources.
145         switch (action)
146         {
147             case topoSetSource::NEW:
148             case topoSetSource::ADD:
149             case topoSetSource::DELETE:
150             {
151                 Info<< "    Applying source " << word(dict.lookup("source"))
152                     << endl;
153                 autoPtr<topoSetSource> source = topoSetSource::New
154                 (
155                     dict.lookup("source"),
156                     mesh,
157                     dict.subDict("sourceInfo")
158                 );
160                 source().applyToSet(action, currentSet());
161                 // Synchronize for coupled patches.
162                 if (!noSync) currentSet().sync(mesh);
163                 currentSet().write();
164             }
165             break;
167             case topoSetSource::SUBSET:
168             {
169                 Info<< "    Applying source " << word(dict.lookup("source"))
170                     << endl;
171                 autoPtr<topoSetSource> source = topoSetSource::New
172                 (
173                     dict.lookup("source"),
174                     mesh,
175                     dict.subDict("sourceInfo")
176                 );
178                 // Backup current set.
179                 autoPtr<topoSet> oldSet
180                 (
181                     topoSet::New
182                     (
183                         setType,
184                         mesh,
185                         currentSet().name() + "_old2",
186                         currentSet()
187                     )
188                 );
190                 currentSet().clear();
191                 source().applyToSet(topoSetSource::NEW, currentSet());
193                 // Combine new value of currentSet with old one.
194                 currentSet().subset(oldSet());
195                 // Synchronize for coupled patches.
196                 if (!noSync) currentSet().sync(mesh);
197                 currentSet().write();
198             }
199             break;
201             case topoSetSource::CLEAR:
202                 Info<< "    Clearing set" << endl;
203                 currentSet().clear();
204                 currentSet().write();
205             break;
207             case topoSetSource::INVERT:
208                 Info<< "    Inverting set" << endl;
209                 currentSet().invert(currentSet().maxSize(mesh));
210                 currentSet().write();
211             break;
213             default:
214                 WarningIn(args.executable())
215                     << "Unhandled action " << action << endl;
216             break;
217         }
219         if (currentSet.valid())
220         {
221             Info<< "    Set " << currentSet().name()
222                 << " now size " << currentSet().size()
223                 << endl;
224         }
225     }
227     Info<< "\nEnd\n" << endl;
229     return 0;
233 // ************************************************************************* //