1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
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 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
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
26 Add pointZones/faceZones/cellZones to the mesh from similar named
27 pointSets/faceSets/cellSets.
29 There is one catch: for faceZones you also need to specify a flip
30 condition which basically denotes the side of the face. In this app
31 it reads a cellSet (xxxCells if 'xxx' is the name of the faceSet) which
32 is the masterCells of the zone.
33 There are lots of situations in which this will go wrong but it is the
34 best I can think of for now.
36 If one is not interested in sideNess specify the -noFlipMap
39 \*---------------------------------------------------------------------------*/
44 #include "IStringStream.H"
50 #include "IOobjectList.H"
51 #include "SortableList.H"
55 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
59 int main(int argc, char *argv[])
61 argList::validOptions.insert("noFlipMap", "");
63 # include "addTimeOptions.H"
64 # include "setRootCase.H"
65 # include "createTime.H"
67 bool noFlipMap = args.optionFound("noFlipMap");
70 instantList Times = runTime.times();
72 label startTime = Times.size()-1;
73 label endTime = Times.size();
75 // check -time and -latestTime options
76 # include "checkTimeOption.H"
78 runTime.setTime(Times[startTime], startTime);
80 # include "createPolyMesh.H"
82 // Search for list of objects for the time of the mesh
86 mesh.pointsInstance(),
87 polyMesh::meshSubDir/"sets"
90 Info<< "Searched : " << mesh.pointsInstance()/polyMesh::meshSubDir/"sets"
92 << "Found : " << objects.names() << nl
96 IOobjectList pointObjects(objects.lookupClass(pointSet::typeName));
98 //Pout<< "pointSets:" << pointObjects.names() << endl;
102 IOobjectList::const_iterator iter = pointObjects.begin();
103 iter != pointObjects.end();
107 // Not in memory. Load it.
108 pointSet set(*iter());
109 SortableList<label> pointLabels(set.toc());
111 label zoneID = mesh.pointZones().findZoneID(set.name());
114 Info<< "Adding set " << set.name() << " as a pointZone." << endl;
115 label sz = mesh.pointZones().size();
116 mesh.pointZones().setSize(sz+1);
117 mesh.pointZones().set
123 pointLabels, //addressing
125 mesh.pointZones() //pointZoneMesh
128 mesh.pointZones().writeOpt() = IOobject::AUTO_WRITE;
129 mesh.pointZones().instance() = mesh.facesInstance();
133 Info<< "Overwriting contents of existing pointZone " << zoneID
134 << " with that of set " << set.name() << "." << endl;
135 mesh.pointZones()[zoneID] = pointLabels;
136 mesh.pointZones().writeOpt() = IOobject::AUTO_WRITE;
137 mesh.pointZones().instance() = mesh.facesInstance();
143 IOobjectList faceObjects(objects.lookupClass(faceSet::typeName));
145 HashSet<word> slaveCellSets;
147 //Pout<< "faceSets:" << faceObjects.names() << endl;
151 IOobjectList::const_iterator iter = faceObjects.begin();
152 iter != faceObjects.end();
156 // Not in memory. Load it.
157 faceSet set(*iter());
158 SortableList<label> faceLabels(set.toc());
160 DynamicList<label> addressing(set.size());
161 DynamicList<bool> flipMap(set.size());
165 word setName(set.name() + "SlaveCells");
167 Info<< "Trying to load cellSet " << setName
168 << " to find out the slave side of the zone." << nl
169 << "If you do not care about the flipMap"
170 << " (i.e. do not use the sideness)" << nl
171 << "use the -noFlipMap command line option."
174 // Load corresponding cells
175 cellSet cells(mesh, setName);
177 // Store setName to exclude from cellZones further on
178 slaveCellSets.insert(setName);
180 forAll(faceLabels, i)
182 label faceI = faceLabels[i];
186 if (mesh.isInternalFace(faceI))
190 cells.found(mesh.faceOwner()[faceI])
191 && !cells.found(mesh.faceNeighbour()[faceI])
198 !cells.found(mesh.faceOwner()[faceI])
199 && cells.found(mesh.faceNeighbour()[faceI])
206 FatalErrorIn(args.executable())
207 << "One of owner or neighbour of internal face "
208 << faceI << " should be in cellSet " << cells.name()
209 << " to be able to determine orientation." << endl
211 << " own:" << mesh.faceOwner()[faceI]
213 << cells.found(mesh.faceOwner()[faceI])
214 << " nei:" << mesh.faceNeighbour()[faceI]
216 << cells.found(mesh.faceNeighbour()[faceI])
217 << abort(FatalError);
222 if (cells.found(mesh.faceOwner()[faceI]))
232 addressing.append(faceI);
233 flipMap.append(flip);
239 forAll(faceLabels, i)
241 label faceI = faceLabels[i];
242 addressing.append(faceI);
243 flipMap.append(false);
247 label zoneID = mesh.faceZones().findZoneID(set.name());
250 Info<< "Adding set " << set.name() << " as a faceZone." << endl;
251 label sz = mesh.faceZones().size();
252 mesh.faceZones().setSize(sz+1);
259 addressing.shrink(), //addressing
260 flipMap.shrink(), //flipmap
262 mesh.faceZones() //pointZoneMesh
265 mesh.faceZones().writeOpt() = IOobject::AUTO_WRITE;
266 mesh.faceZones().instance() = mesh.facesInstance();
270 Info<< "Overwriting contents of existing faceZone " << zoneID
271 << " with that of set " << set.name() << "." << endl;
272 mesh.faceZones()[zoneID].resetAddressing
277 mesh.faceZones().writeOpt() = IOobject::AUTO_WRITE;
278 mesh.faceZones().instance() = mesh.facesInstance();
284 IOobjectList cellObjects(objects.lookupClass(cellSet::typeName));
286 //Pout<< "cellSets:" << cellObjects.names() << endl;
290 IOobjectList::const_iterator iter = cellObjects.begin();
291 iter != cellObjects.end();
295 if (!slaveCellSets.found(iter.key()))
297 // Not in memory. Load it.
298 cellSet set(*iter());
299 SortableList<label> cellLabels(set.toc());
301 label zoneID = mesh.cellZones().findZoneID(set.name());
304 Info<< "Adding set " << set.name() << " as a cellZone." << endl;
305 label sz = mesh.cellZones().size();
306 mesh.cellZones().setSize(sz+1);
313 cellLabels, //addressing
315 mesh.cellZones() //pointZoneMesh
318 mesh.cellZones().writeOpt() = IOobject::AUTO_WRITE;
319 mesh.cellZones().instance() = mesh.facesInstance();
323 Info<< "Overwriting contents of existing cellZone " << zoneID
324 << " with that of set " << set.name() << "." << endl;
325 mesh.cellZones()[zoneID] = cellLabels;
326 mesh.cellZones().writeOpt() = IOobject::AUTO_WRITE;
327 mesh.cellZones().instance() = mesh.facesInstance();
334 Info<< "Writing mesh." << endl;
338 FatalErrorIn(args.executable())
339 << "Failed writing polyMesh."
343 Info<< nl << "End" << endl;
349 // ************************************************************************* //