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 #include <OpenFOAM/syncTools.H>
00069 #include <OpenFOAM/argList.H>
00070 #include <OpenFOAM/Time.H>
00071 #include <meshTools/faceSet.H>
00072 #include <dynamicMesh/polyTopoChange.H>
00073 #include <dynamicMesh/polyModifyFace.H>
00074 #include <dynamicMesh/polyAddFace.H>
00075 #include <OpenFOAM/ReadFields.H>
00076 #include <finiteVolume/volFields.H>
00077 #include <finiteVolume/surfaceFields.H>
00078 #include <OpenFOAM/ZoneIDs.H>
00079
00080 using namespace Foam;
00081
00082
00083
00084 void modifyOrAddFace
00085 (
00086 polyTopoChange& meshMod,
00087 const face& f,
00088 const label faceI,
00089 const label own,
00090 const bool flipFaceFlux,
00091 const label newPatchI,
00092 const label zoneID,
00093 const bool zoneFlip,
00094
00095 PackedBoolList& modifiedFace
00096 )
00097 {
00098 if (!modifiedFace[faceI])
00099 {
00100
00101 meshMod.setAction
00102 (
00103 polyModifyFace
00104 (
00105 f,
00106 faceI,
00107 own,
00108 -1,
00109 flipFaceFlux,
00110 newPatchI,
00111 false,
00112 zoneID,
00113 zoneFlip
00114 )
00115 );
00116 modifiedFace[faceI] = 1;
00117 }
00118 else
00119 {
00120
00121 meshMod.setAction
00122 (
00123 polyAddFace
00124 (
00125 f,
00126 own,
00127 -1,
00128 -1,
00129 -1,
00130 faceI,
00131 flipFaceFlux,
00132 newPatchI,
00133 zoneID,
00134 zoneFlip
00135 )
00136 );
00137 }
00138 }
00139
00140
00141 label findPatchID(const polyMesh& mesh, const word& name)
00142 {
00143 label patchI = mesh.boundaryMesh().findPatchID(name);
00144
00145 if (patchI == -1)
00146 {
00147 FatalErrorIn("findPatchID(const polyMesh&, const word&)")
00148 << "Cannot find patch " << name << endl
00149 << "Valid patches are " << mesh.boundaryMesh().names()
00150 << exit(FatalError);
00151 }
00152 return patchI;
00153 }
00154
00155
00156
00157
00158 int main(int argc, char *argv[])
00159 {
00160 # include <OpenFOAM/addRegionOption.H>
00161 argList::validArgs.append("faceZone");
00162 argList::validArgs.append("patch");
00163 argList::validOptions.insert("additionalPatches", "(patch2 .. patchN)");
00164 argList::validOptions.insert("internalFacesOnly", "");
00165 argList::validOptions.insert("overwrite", "");
00166
00167 # include <OpenFOAM/setRootCase.H>
00168 # include <OpenFOAM/createTime.H>
00169 runTime.functionObjects().off();
00170 # include <OpenFOAM/createNamedMesh.H>
00171 const word oldInstance = mesh.pointsInstance();
00172
00173 const polyBoundaryMesh& patches = mesh.boundaryMesh();
00174 const faceZoneMesh& faceZones = mesh.faceZones();
00175
00176
00177 faceZoneID zoneID(args.additionalArgs()[0], faceZones);
00178
00179 Info<< "Converting faces on zone " << zoneID.name()
00180 << " into baffles." << nl << endl;
00181
00182 if (zoneID.index() == -1)
00183 {
00184 FatalErrorIn(args.executable()) << "Cannot find faceZone "
00185 << zoneID.name() << endl
00186 << "Valid zones are " << faceZones.names()
00187 << exit(FatalError);
00188 }
00189
00190 const faceZone& fZone = faceZones[zoneID.index()];
00191
00192 Info<< "Found " << returnReduce(fZone.size(), sumOp<label>())
00193 << " faces on zone " << zoneID.name() << nl << endl;
00194
00195
00196 patches.checkParallelSync(true);
00197 fZone.checkParallelSync(true);
00198
00199
00200 DynamicList<label> newPatches(1);
00201
00202 word patchName(args.additionalArgs()[1]);
00203 newPatches.append(findPatchID(mesh, patchName));
00204 Info<< "Using patch " << patchName
00205 << " at index " << newPatches[0] << endl;
00206
00207
00208
00209 if (args.optionFound("additionalPatches"))
00210 {
00211 const wordList patchNames
00212 (
00213 args.optionLookup("additionalPatches")()
00214 );
00215
00216 newPatches.reserve(patchNames.size() + 1);
00217 forAll(patchNames, i)
00218 {
00219 newPatches.append(findPatchID(mesh, patchNames[i]));
00220 Info<< "Using additional patch " << patchNames[i]
00221 << " at index " << newPatches[newPatches.size()-1] << endl;
00222 }
00223 }
00224
00225
00226 bool overwrite = args.optionFound("overwrite");
00227
00228 bool internalFacesOnly = args.optionFound("internalFacesOnly");
00229
00230 if (internalFacesOnly)
00231 {
00232 Info<< "Not converting faces on non-coupled patches." << nl << endl;
00233 }
00234
00235
00236
00237 IOobjectList objects(mesh, runTime.timeName());
00238
00239
00240
00241 PtrList<volScalarField> vsFlds;
00242 ReadFields(mesh, objects, vsFlds);
00243
00244 PtrList<volVectorField> vvFlds;
00245 ReadFields(mesh, objects, vvFlds);
00246
00247 PtrList<volSphericalTensorField> vstFlds;
00248 ReadFields(mesh, objects, vstFlds);
00249
00250 PtrList<volSymmTensorField> vsymtFlds;
00251 ReadFields(mesh, objects, vsymtFlds);
00252
00253 PtrList<volTensorField> vtFlds;
00254 ReadFields(mesh, objects, vtFlds);
00255
00256
00257
00258 PtrList<surfaceScalarField> ssFlds;
00259 ReadFields(mesh, objects, ssFlds);
00260
00261 PtrList<surfaceVectorField> svFlds;
00262 ReadFields(mesh, objects, svFlds);
00263
00264 PtrList<surfaceSphericalTensorField> sstFlds;
00265 ReadFields(mesh, objects, sstFlds);
00266
00267 PtrList<surfaceSymmTensorField> ssymtFlds;
00268 ReadFields(mesh, objects, ssymtFlds);
00269
00270 PtrList<surfaceTensorField> stFlds;
00271 ReadFields(mesh, objects, stFlds);
00272
00273
00274
00275 polyTopoChange meshMod(mesh);
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286 PackedBoolList modifiedFace(mesh.nFaces());
00287
00288 forAll(patches, patchI)
00289 {
00290 const polyPatch& pp = patches[patchI];
00291 if (pp.coupled())
00292 {
00293 forAll(pp, i)
00294 {
00295 modifiedFace[pp.start()+i] = 1;
00296 }
00297 }
00298 }
00299 label nModified = 0;
00300
00301 forAll(newPatches, i)
00302 {
00303 label newPatchI = newPatches[i];
00304
00305
00306
00307
00308 for (label faceI = 0; faceI < mesh.nInternalFaces(); faceI++)
00309 {
00310 label zoneFaceI = fZone.whichFace(faceI);
00311
00312 if (zoneFaceI != -1)
00313 {
00314 if (!fZone.flipMap()[zoneFaceI])
00315 {
00316
00317 modifyOrAddFace
00318 (
00319 meshMod,
00320 mesh.faces()[faceI],
00321 faceI,
00322 mesh.faceOwner()[faceI],
00323 false,
00324 newPatchI,
00325 zoneID.index(),
00326 false,
00327 modifiedFace
00328 );
00329 }
00330 else
00331 {
00332
00333 modifyOrAddFace
00334 (
00335 meshMod,
00336 mesh.faces()[faceI].reverseFace(),
00337 faceI,
00338 mesh.faceNeighbour()[faceI],
00339 true,
00340 newPatchI,
00341 zoneID.index(),
00342 true,
00343 modifiedFace
00344 );
00345 }
00346
00347 nModified++;
00348 }
00349 }
00350
00351
00352
00353
00354
00355 for (label faceI = 0; faceI < mesh.nInternalFaces(); faceI++)
00356 {
00357 label zoneFaceI = fZone.whichFace(faceI);
00358
00359 if (zoneFaceI != -1)
00360 {
00361 if (!fZone.flipMap()[zoneFaceI])
00362 {
00363
00364 modifyOrAddFace
00365 (
00366 meshMod,
00367 mesh.faces()[faceI].reverseFace(),
00368 faceI,
00369 mesh.faceNeighbour()[faceI],
00370 true,
00371 newPatchI,
00372 zoneID.index(),
00373 true,
00374 modifiedFace
00375 );
00376 }
00377 else
00378 {
00379
00380 modifyOrAddFace
00381 (
00382 meshMod,
00383 mesh.faces()[faceI],
00384 faceI,
00385 mesh.faceOwner()[faceI],
00386 false,
00387 newPatchI,
00388 zoneID.index(),
00389 false,
00390 modifiedFace
00391 );
00392 }
00393 }
00394 }
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409 labelHashSet patchWarned;
00410
00411 forAll(patches, patchI)
00412 {
00413 const polyPatch& pp = patches[patchI];
00414
00415 if (pp.coupled() && patches[newPatchI].coupled())
00416 {
00417
00418
00419 }
00420 else if (pp.coupled() || !internalFacesOnly)
00421 {
00422 forAll(pp, i)
00423 {
00424 label faceI = pp.start()+i;
00425
00426 label zoneFaceI = fZone.whichFace(faceI);
00427
00428 if (zoneFaceI != -1)
00429 {
00430 if (patchWarned.insert(patchI))
00431 {
00432 WarningIn(args.executable())
00433 << "Found boundary face (in patch " << pp.name()
00434 << ") in faceZone " << fZone.name()
00435 << " to convert to baffle patch "
00436 << patches[newPatchI].name()
00437 << endl
00438 << " Run with -internalFacesOnly option"
00439 << " if you don't wish to convert"
00440 << " boundary faces." << endl;
00441 }
00442
00443 modifyOrAddFace
00444 (
00445 meshMod,
00446 mesh.faces()[faceI],
00447 faceI,
00448 mesh.faceOwner()[faceI],
00449 false,
00450 newPatchI,
00451 zoneID.index(),
00452 fZone.flipMap()[zoneFaceI],
00453 modifiedFace
00454 );
00455 nModified++;
00456 }
00457 }
00458 }
00459 }
00460 }
00461
00462
00463 Info<< "Converted " << returnReduce(nModified, sumOp<label>())
00464 << " faces into boundary faces on patch " << patchName << nl << endl;
00465
00466 if (!overwrite)
00467 {
00468 runTime++;
00469 }
00470
00471
00472 autoPtr<mapPolyMesh> map = meshMod.changeMesh(mesh, false);
00473
00474
00475 mesh.updateMesh(map);
00476
00477
00478 if (map().hasMotionPoints())
00479 {
00480 mesh.movePoints(map().preMotionPoints());
00481 }
00482
00483 if (overwrite)
00484 {
00485 mesh.setInstance(oldInstance);
00486 }
00487 Info<< "Writing mesh to " << runTime.timeName() << endl;
00488
00489 mesh.write();
00490
00491 Info<< "End\n" << endl;
00492
00493 return 0;
00494 }
00495
00496
00497