OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

createBaffles.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Description
00026     Makes internal faces into boundary faces. Does not duplicate points, unlike
00027     mergeOrSplitBaffles.
00028 
00029     Note: if any coupled patch face is selected for baffling the opposite
00030     member has to be selected for baffling as well. Note that this
00031     is the same as repatching. This was added only for convenience so
00032     you don't have to filter coupled boundary out of your set.
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         // First usage of face. Modify.
00069         meshMod.setAction
00070         (
00071             polyModifyFace
00072             (
00073                 f,                          // modified face
00074                 faceI,                      // label of face
00075                 own,                        // owner
00076                 -1,                         // neighbour
00077                 flipFaceFlux,               // face flip
00078                 newPatchI,                  // patch for face
00079                 false,                      // remove from zone
00080                 zoneID,                     // zone for face
00081                 zoneFlip                    // face flip in zone
00082             )
00083         );
00084         modifiedFace[faceI] = 1;
00085     }
00086     else
00087     {
00088         // Second or more usage of face. Add.
00089         meshMod.setAction
00090         (
00091             polyAddFace
00092             (
00093                 f,                          // modified face
00094                 own,                        // owner
00095                 -1,                         // neighbour
00096                 -1,                         // master point
00097                 -1,                         // master edge
00098                 faceI,                      // master face
00099                 flipFaceFlux,               // face flip
00100                 newPatchI,                  // patch for face
00101                 zoneID,                     // zone for face
00102                 zoneFlip                    // face flip in zone
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 // Main program:
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     // Faces to baffle
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     // Make sure patches and zoneFaces are synchronised across couples
00155     patches.checkParallelSync(true);
00156     fZone.checkParallelSync(true);
00157 
00158     // Patches to put baffles into
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     // Additional patches
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     // Read objects in time directory
00196     IOobjectList objects(mesh, runTime.timeName());
00197 
00198     // Read vol fields.
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     // Read surface fields.
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     // Mesh change container
00234     polyTopoChange meshMod(mesh);
00235 
00236 
00237     // Do the actual changes. Note:
00238     // - loop in incrementing face order (not necessary if faceZone ordered).
00239     //   Preserves any existing ordering on patch faces.
00240     // - two passes, do non-flip faces first and flip faces second. This
00241     //   guarantees that when e.g. creating a cyclic all faces from one
00242     //   side come first and faces from the other side next.
00243 
00244     // Whether first use of face (modify) or consecutive (add)
00245     PackedBoolList modifiedFace(mesh.nFaces());
00246     // Never modify coupled faces
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         // Pass 1. Do selected side of zone
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                     // Use owner side of face
00276                     modifyOrAddFace
00277                     (
00278                         meshMod,
00279                         mesh.faces()[faceI],    // modified face
00280                         faceI,                  // label of face
00281                         mesh.faceOwner()[faceI],// owner
00282                         false,                  // face flip
00283                         newPatchI,              // patch for face
00284                         zoneID.index(),         // zone for face
00285                         false,                  // face flip in zone
00286                         modifiedFace            // modify or add status
00287                     );
00288                 }
00289                 else
00290                 {
00291                     // Use neighbour side of face
00292                     modifyOrAddFace
00293                     (
00294                         meshMod,
00295                         mesh.faces()[faceI].reverseFace(),  // modified face
00296                         faceI,                      // label of face
00297                         mesh.faceNeighbour()[faceI],// owner
00298                         true,                       // face flip
00299                         newPatchI,                  // patch for face
00300                         zoneID.index(),             // zone for face
00301                         true,                       // face flip in zone
00302                         modifiedFace                // modify or add status
00303                     );
00304                 }
00305 
00306                 nModified++;
00307             }
00308         }
00309 
00310 
00311         // Pass 2. Do other side of zone
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                     // Use neighbour side of face
00323                     modifyOrAddFace
00324                     (
00325                         meshMod,
00326                         mesh.faces()[faceI].reverseFace(),  // modified face
00327                         faceI,                              // label of face
00328                         mesh.faceNeighbour()[faceI],        // owner
00329                         true,                               // face flip
00330                         newPatchI,                          // patch for face
00331                         zoneID.index(),                     // zone for face
00332                         true,                               // face flip in zone
00333                         modifiedFace                        // modify or add
00334                     );
00335                 }
00336                 else
00337                 {
00338                     // Use owner side of face
00339                     modifyOrAddFace
00340                     (
00341                         meshMod,
00342                         mesh.faces()[faceI],    // modified face
00343                         faceI,                  // label of face
00344                         mesh.faceOwner()[faceI],// owner
00345                         false,                  // face flip
00346                         newPatchI,              // patch for face
00347                         zoneID.index(),         // zone for face
00348                         false,                  // face flip in zone
00349                         modifiedFace            // modify or add status
00350                     );
00351                 }
00352             }
00353         }
00354 
00355 
00356         // Modify any boundary faces
00357         // ~~~~~~~~~~~~~~~~~~~~~~~~~
00358 
00359         // Normal boundary:
00360         // - move to new patch. Might already be back-to-back baffle
00361         // you want to add cyclic to. Do warn though.
00362         //
00363         // Processor boundary:
00364         // - do not move to cyclic
00365         // - add normal patches though.
00366 
00367         // For warning once per patch.
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                 // Do not allow coupled faces to be moved to different coupled
00377                 // patches.
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],        // modified face
00406                             faceI,                      // label of face
00407                             mesh.faceOwner()[faceI],    // owner
00408                             false,                      // face flip
00409                             newPatchI,                  // patch for face
00410                             zoneID.index(),             // zone for face
00411                             fZone.flipMap()[zoneFaceI], // face flip in zone
00412                             modifiedFace                // modify or add status
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     // Change the mesh. Change points directly (no inflation).
00431     autoPtr<mapPolyMesh> map = meshMod.changeMesh(mesh, false);
00432 
00433     // Update fields
00434     mesh.updateMesh(map);
00435 
00436     // Move mesh (since morphing might not do this)
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 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd