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