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