1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
7 -------------------------------------------------------------------------------
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
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/>.
25 Operates on cellSets/faceSets/pointSets through a dictionary.
27 \*---------------------------------------------------------------------------*/
32 #include "topoSetSource.H"
39 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 int main(int argc, char *argv[])
49 "specify an alternative dictionary for the topoSet dictionary"
51 # include "addRegionOption.H"
52 argList::addBoolOption
55 "do not synchronise selection across coupled patches"
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"))
69 dictPath = args["dict"];
72 dictPath = dictPath / dictName;
76 Info<< "Reading " << dictName << "\n" << endl;
78 IOdictionary topoSetDict
81 args.optionFound("dict")
86 IOobject::MUST_READ_IF_MODIFIED,
94 IOobject::MUST_READ_IF_MODIFIED,
101 // Read set construct info from dictionary
102 PtrList<dictionary> patchSources(topoSetDict.lookup("actions"));
104 forAll(patchSources, i)
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;
118 (action == topoSetSource::NEW)
119 || (action == topoSetSource::CLEAR)
122 currentSet = topoSet::New(setType, mesh, setName, 10000);
123 Info<< "Created set " << setName << endl;
125 else if (action == topoSetSource::REMOVE)
131 currentSet = topoSet::New
138 Info<< "Read set " << setName << " with size "
139 << currentSet().size() << endl;
144 // Handle special actions (clear, invert) locally, rest through sources.
147 case topoSetSource::NEW:
148 case topoSetSource::ADD:
149 case topoSetSource::DELETE:
151 Info<< " Applying source " << word(dict.lookup("source"))
153 autoPtr<topoSetSource> source = topoSetSource::New
155 dict.lookup("source"),
157 dict.subDict("sourceInfo")
160 source().applyToSet(action, currentSet());
161 // Synchronize for coupled patches.
162 if (!noSync) currentSet().sync(mesh);
163 currentSet().write();
167 case topoSetSource::SUBSET:
169 Info<< " Applying source " << word(dict.lookup("source"))
171 autoPtr<topoSetSource> source = topoSetSource::New
173 dict.lookup("source"),
175 dict.subDict("sourceInfo")
178 // Backup current set.
179 autoPtr<topoSet> oldSet
185 currentSet().name() + "_old2",
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();
201 case topoSetSource::CLEAR:
202 Info<< " Clearing set" << endl;
203 currentSet().clear();
204 currentSet().write();
207 case topoSetSource::INVERT:
208 Info<< " Inverting set" << endl;
209 currentSet().invert(currentSet().maxSize(mesh));
210 currentSet().write();
214 WarningIn(args.executable())
215 << "Unhandled action " << action << endl;
219 if (currentSet.valid())
221 Info<< " Set " << currentSet().name()
222 << " now size " << currentSet().size()
227 Info<< "\nEnd\n" << endl;
233 // ************************************************************************* //