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 Add pointZones/faceZones/cellZones to the mesh from similar named
26 pointSets/faceSets/cellSets.
28 There is one catch: for faceZones you also need to specify a flip
29 condition which basically denotes the side of the face. In this app
30 it reads a cellSet (xxxCells if 'xxx' is the name of the faceSet) which
31 is the masterCells of the zone.
32 There are lots of situations in which this will go wrong but it is the
33 best I can think of for now.
35 If one is not interested in sideNess specify the -noFlipMap
38 \*---------------------------------------------------------------------------*/
43 #include "IStringStream.H"
49 #include "IOobjectList.H"
50 #include "SortableList.H"
54 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
58 int main(int argc, char *argv[])
62 "add point/face/cell Zones from similar named point/face/cell Sets"
65 argList::addBoolOption
68 "ignore orientation of faceSet"
71 #include "addRegionOption.H"
72 #include "addTimeOptions.H"
73 #include "setRootCase.H"
74 #include "createTime.H"
76 const bool noFlipMap = args.optionFound("noFlipMap");
79 instantList Times = runTime.times();
81 label startTime = Times.size()-1;
82 label endTime = Times.size();
84 // check -time and -latestTime options
85 #include "checkTimeOption.H"
87 runTime.setTime(Times[startTime], startTime);
89 #include "createNamedPolyMesh.H"
91 // Search for list of objects for the time of the mesh
92 word setsInstance = runTime.findInstance
94 polyMesh::meshSubDir/"sets",
100 IOobjectList objects(mesh, setsInstance, polyMesh::meshSubDir/"sets");
102 Info<< "Searched : " << setsInstance/polyMesh::meshSubDir/"sets"
104 << "Found : " << objects.names() << nl
108 IOobjectList pointObjects(objects.lookupClass(pointSet::typeName));
110 //Pout<< "pointSets:" << pointObjects.names() << endl;
112 forAllConstIter(IOobjectList, pointObjects, iter)
114 // Not in memory. Load it.
115 pointSet set(*iter());
116 SortableList<label> pointLabels(set.toc());
118 label zoneID = mesh.pointZones().findZoneID(set.name());
121 Info<< "Adding set " << set.name() << " as a pointZone." << endl;
122 label sz = mesh.pointZones().size();
123 mesh.pointZones().setSize(sz+1);
124 mesh.pointZones().set
130 pointLabels, //addressing
132 mesh.pointZones() //pointZoneMesh
135 mesh.pointZones().writeOpt() = IOobject::AUTO_WRITE;
136 mesh.pointZones().instance() = mesh.facesInstance();
140 Info<< "Overwriting contents of existing pointZone " << zoneID
141 << " with that of set " << set.name() << "." << endl;
142 mesh.pointZones()[zoneID] = pointLabels;
143 mesh.pointZones().writeOpt() = IOobject::AUTO_WRITE;
144 mesh.pointZones().instance() = mesh.facesInstance();
150 IOobjectList faceObjects(objects.lookupClass(faceSet::typeName));
152 HashSet<word> slaveCellSets;
154 //Pout<< "faceSets:" << faceObjects.names() << endl;
156 forAllConstIter(IOobjectList, faceObjects, iter)
158 // Not in memory. Load it.
159 faceSet set(*iter());
160 SortableList<label> faceLabels(set.toc());
162 DynamicList<label> addressing(set.size());
163 DynamicList<bool> flipMap(set.size());
168 forAll(faceLabels, i)
170 label faceI = faceLabels[i];
171 addressing.append(faceI);
172 flipMap.append(false);
177 const word setName(set.name() + "SlaveCells");
179 Info<< "Trying to load cellSet " << setName
180 << " to find out the slave side of the zone." << nl
181 << "If you do not care about the flipMap"
182 << " (i.e. do not use the sideness)" << nl
183 << "use the -noFlipMap command line option."
186 // Load corresponding cells
187 cellSet cells(mesh, setName);
189 // Store setName to exclude from cellZones further on
190 slaveCellSets.insert(setName);
192 forAll(faceLabels, i)
194 label faceI = faceLabels[i];
198 if (mesh.isInternalFace(faceI))
202 cells.found(mesh.faceOwner()[faceI])
203 && !cells.found(mesh.faceNeighbour()[faceI])
210 !cells.found(mesh.faceOwner()[faceI])
211 && cells.found(mesh.faceNeighbour()[faceI])
218 FatalErrorIn(args.executable())
219 << "One of owner or neighbour of internal face "
220 << faceI << " should be in cellSet " << cells.name()
221 << " to be able to determine orientation." << endl
223 << " own:" << mesh.faceOwner()[faceI]
225 << cells.found(mesh.faceOwner()[faceI])
226 << " nei:" << mesh.faceNeighbour()[faceI]
228 << cells.found(mesh.faceNeighbour()[faceI])
229 << abort(FatalError);
234 if (cells.found(mesh.faceOwner()[faceI]))
244 addressing.append(faceI);
245 flipMap.append(flip);
249 label zoneID = mesh.faceZones().findZoneID(set.name());
252 Info<< "Adding set " << set.name() << " as a faceZone." << endl;
253 label sz = mesh.faceZones().size();
254 mesh.faceZones().setSize(sz+1);
261 addressing.shrink(), //addressing
262 flipMap.shrink(), //flipmap
264 mesh.faceZones() //pointZoneMesh
267 mesh.faceZones().writeOpt() = IOobject::AUTO_WRITE;
268 mesh.faceZones().instance() = mesh.facesInstance();
272 Info<< "Overwriting contents of existing faceZone " << zoneID
273 << " with that of set " << set.name() << "." << endl;
274 mesh.faceZones()[zoneID].resetAddressing
279 mesh.faceZones().writeOpt() = IOobject::AUTO_WRITE;
280 mesh.faceZones().instance() = mesh.facesInstance();
286 IOobjectList cellObjects(objects.lookupClass(cellSet::typeName));
288 //Pout<< "cellSets:" << cellObjects.names() << endl;
290 forAllConstIter(IOobjectList, cellObjects, iter)
292 if (!slaveCellSets.found(iter.key()))
294 // Not in memory. Load it.
295 cellSet set(*iter());
296 SortableList<label> cellLabels(set.toc());
298 label zoneID = mesh.cellZones().findZoneID(set.name());
301 Info<< "Adding set " << set.name() << " as a cellZone." << endl;
302 label sz = mesh.cellZones().size();
303 mesh.cellZones().setSize(sz+1);
310 cellLabels, //addressing
312 mesh.cellZones() //pointZoneMesh
315 mesh.cellZones().writeOpt() = IOobject::AUTO_WRITE;
316 mesh.cellZones().instance() = mesh.facesInstance();
320 Info<< "Overwriting contents of existing cellZone " << zoneID
321 << " with that of set " << set.name() << "." << endl;
322 mesh.cellZones()[zoneID] = cellLabels;
323 mesh.cellZones().writeOpt() = IOobject::AUTO_WRITE;
324 mesh.cellZones().instance() = mesh.facesInstance();
331 Info<< "Writing mesh." << endl;
335 FatalErrorIn(args.executable())
336 << "Failed writing polyMesh."
340 Info<< "\nEnd\n" << endl;
346 // ************************************************************************* //