setsToZones.C
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #include "argList.H"
00042 #include "Time.H"
00043 #include "polyMesh.H"
00044 #include "IStringStream.H"
00045 #include "cellSet.H"
00046 #include "faceSet.H"
00047 #include "pointSet.H"
00048 #include "OFstream.H"
00049 #include "IFstream.H"
00050 #include "IOobjectList.H"
00051 #include "SortableList.H"
00052
00053 using namespace Foam;
00054
00055
00056
00057
00058
00059 int main(int argc, char *argv[])
00060 {
00061 argList::validOptions.insert("noFlipMap", "");
00062
00063 # include "addTimeOptions.H"
00064 # include "setRootCase.H"
00065 # include "createTime.H"
00066
00067 bool noFlipMap = args.optionFound("noFlipMap");
00068
00069
00070 instantList Times = runTime.times();
00071
00072 label startTime = Times.size()-1;
00073 label endTime = Times.size();
00074
00075
00076 # include "checkTimeOption.H"
00077
00078 runTime.setTime(Times[startTime], startTime);
00079
00080 # include "createPolyMesh.H"
00081
00082
00083 IOobjectList objects
00084 (
00085 mesh,
00086 mesh.pointsInstance(),
00087 polyMesh::meshSubDir/"sets"
00088 );
00089
00090 Info<< "Searched : " << mesh.pointsInstance()/polyMesh::meshSubDir/"sets"
00091 << nl
00092 << "Found : " << objects.names() << nl
00093 << endl;
00094
00095
00096 IOobjectList pointObjects(objects.lookupClass(pointSet::typeName));
00097
00098
00099
00100 for
00101 (
00102 IOobjectList::const_iterator iter = pointObjects.begin();
00103 iter != pointObjects.end();
00104 ++iter
00105 )
00106 {
00107
00108 pointSet set(*iter());
00109 SortableList<label> pointLabels(set.toc());
00110
00111 label zoneID = mesh.pointZones().findZoneID(set.name());
00112 if (zoneID == -1)
00113 {
00114 Info<< "Adding set " << set.name() << " as a pointZone." << endl;
00115 label sz = mesh.pointZones().size();
00116 mesh.pointZones().setSize(sz+1);
00117 mesh.pointZones().set
00118 (
00119 sz,
00120 new pointZone
00121 (
00122 set.name(),
00123 pointLabels,
00124 sz,
00125 mesh.pointZones()
00126 )
00127 );
00128 mesh.pointZones().writeOpt() = IOobject::AUTO_WRITE;
00129 mesh.pointZones().instance() = mesh.facesInstance();
00130 }
00131 else
00132 {
00133 Info<< "Overwriting contents of existing pointZone " << zoneID
00134 << " with that of set " << set.name() << "." << endl;
00135 mesh.pointZones()[zoneID] = pointLabels;
00136 mesh.pointZones().writeOpt() = IOobject::AUTO_WRITE;
00137 mesh.pointZones().instance() = mesh.facesInstance();
00138 }
00139 }
00140
00141
00142
00143 IOobjectList faceObjects(objects.lookupClass(faceSet::typeName));
00144
00145 HashSet<word> slaveCellSets;
00146
00147
00148
00149 for
00150 (
00151 IOobjectList::const_iterator iter = faceObjects.begin();
00152 iter != faceObjects.end();
00153 ++iter
00154 )
00155 {
00156
00157 faceSet set(*iter());
00158 SortableList<label> faceLabels(set.toc());
00159
00160 DynamicList<label> addressing(set.size());
00161 DynamicList<bool> flipMap(set.size());
00162
00163 if (!noFlipMap)
00164 {
00165 word setName(set.name() + "SlaveCells");
00166
00167 Info<< "Trying to load cellSet " << setName
00168 << " to find out the slave side of the zone." << nl
00169 << "If you do not care about the flipMap"
00170 << " (i.e. do not use the sideness)" << nl
00171 << "use the -noFlipMap command line option."
00172 << endl;
00173
00174
00175 cellSet cells(mesh, setName);
00176
00177
00178 slaveCellSets.insert(setName);
00179
00180 forAll(faceLabels, i)
00181 {
00182 label faceI = faceLabels[i];
00183
00184 bool flip = false;
00185
00186 if (mesh.isInternalFace(faceI))
00187 {
00188 if
00189 (
00190 cells.found(mesh.faceOwner()[faceI])
00191 && !cells.found(mesh.faceNeighbour()[faceI])
00192 )
00193 {
00194 flip = false;
00195 }
00196 else if
00197 (
00198 !cells.found(mesh.faceOwner()[faceI])
00199 && cells.found(mesh.faceNeighbour()[faceI])
00200 )
00201 {
00202 flip = true;
00203 }
00204 else
00205 {
00206 FatalErrorIn(args.executable())
00207 << "One of owner or neighbour of internal face "
00208 << faceI << " should be in cellSet " << cells.name()
00209 << " to be able to determine orientation." << endl
00210 << "Face:" << faceI
00211 << " own:" << mesh.faceOwner()[faceI]
00212 << " OwnInCellSet:"
00213 << cells.found(mesh.faceOwner()[faceI])
00214 << " nei:" << mesh.faceNeighbour()[faceI]
00215 << " NeiInCellSet:"
00216 << cells.found(mesh.faceNeighbour()[faceI])
00217 << abort(FatalError);
00218 }
00219 }
00220 else
00221 {
00222 if (cells.found(mesh.faceOwner()[faceI]))
00223 {
00224 flip = false;
00225 }
00226 else
00227 {
00228 flip = true;
00229 }
00230 }
00231
00232 addressing.append(faceI);
00233 flipMap.append(flip);
00234 }
00235 }
00236 else
00237 {
00238
00239 forAll(faceLabels, i)
00240 {
00241 label faceI = faceLabels[i];
00242 addressing.append(faceI);
00243 flipMap.append(false);
00244 }
00245 }
00246
00247 label zoneID = mesh.faceZones().findZoneID(set.name());
00248 if (zoneID == -1)
00249 {
00250 Info<< "Adding set " << set.name() << " as a faceZone." << endl;
00251 label sz = mesh.faceZones().size();
00252 mesh.faceZones().setSize(sz+1);
00253 mesh.faceZones().set
00254 (
00255 sz,
00256 new faceZone
00257 (
00258 set.name(),
00259 addressing.shrink(),
00260 flipMap.shrink(),
00261 sz,
00262 mesh.faceZones()
00263 )
00264 );
00265 mesh.faceZones().writeOpt() = IOobject::AUTO_WRITE;
00266 mesh.faceZones().instance() = mesh.facesInstance();
00267 }
00268 else
00269 {
00270 Info<< "Overwriting contents of existing faceZone " << zoneID
00271 << " with that of set " << set.name() << "." << endl;
00272 mesh.faceZones()[zoneID].resetAddressing
00273 (
00274 addressing.shrink(),
00275 flipMap.shrink()
00276 );
00277 mesh.faceZones().writeOpt() = IOobject::AUTO_WRITE;
00278 mesh.faceZones().instance() = mesh.facesInstance();
00279 }
00280 }
00281
00282
00283
00284 IOobjectList cellObjects(objects.lookupClass(cellSet::typeName));
00285
00286
00287
00288 for
00289 (
00290 IOobjectList::const_iterator iter = cellObjects.begin();
00291 iter != cellObjects.end();
00292 ++iter
00293 )
00294 {
00295 if (!slaveCellSets.found(iter.key()))
00296 {
00297
00298 cellSet set(*iter());
00299 SortableList<label> cellLabels(set.toc());
00300
00301 label zoneID = mesh.cellZones().findZoneID(set.name());
00302 if (zoneID == -1)
00303 {
00304 Info<< "Adding set " << set.name() << " as a cellZone." << endl;
00305 label sz = mesh.cellZones().size();
00306 mesh.cellZones().setSize(sz+1);
00307 mesh.cellZones().set
00308 (
00309 sz,
00310 new cellZone
00311 (
00312 set.name(),
00313 cellLabels,
00314 sz,
00315 mesh.cellZones()
00316 )
00317 );
00318 mesh.cellZones().writeOpt() = IOobject::AUTO_WRITE;
00319 mesh.cellZones().instance() = mesh.facesInstance();
00320 }
00321 else
00322 {
00323 Info<< "Overwriting contents of existing cellZone " << zoneID
00324 << " with that of set " << set.name() << "." << endl;
00325 mesh.cellZones()[zoneID] = cellLabels;
00326 mesh.cellZones().writeOpt() = IOobject::AUTO_WRITE;
00327 mesh.cellZones().instance() = mesh.facesInstance();
00328 }
00329 }
00330 }
00331
00332
00333
00334 Info<< "Writing mesh." << endl;
00335
00336 if (!mesh.write())
00337 {
00338 FatalErrorIn(args.executable())
00339 << "Failed writing polyMesh."
00340 << exit(FatalError);
00341 }
00342
00343 Info<< nl << "End" << endl;
00344
00345 return 0;
00346 }
00347
00348
00349
Copyright © 2000-2009 OpenCFD Ltd