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

fvMeshDistribute.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 \*----------------------------------------------------------------------------*/
00026 
00027 #include "fvMeshDistribute.H"
00028 #include "ProcessorTopology.H"
00029 #include "commSchedule.H"
00030 #include "PstreamCombineReduceOps.H"
00031 #include "fvMeshAdder.H"
00032 #include "faceCoupleInfo.H"
00033 #include "processorFvPatchField.H"
00034 #include "polyTopoChange.H"
00035 #include "removeCells.H"
00036 #include "polyModifyFace.H"
00037 #include "polyRemovePoint.H"
00038 #include "mergePoints.H"
00039 #include "mapDistributePolyMesh.H"
00040 #include "surfaceFields.H"
00041 
00042 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00043 
00044 defineTypeNameAndDebug(Foam::fvMeshDistribute, 0);
00045 
00046 
00047 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00048 
00049 //Foam::List<Foam::labelPair> Foam::fvMeshDistribute::getSchedule
00050 //(
00051 //    const labelList& distribution
00052 //)
00053 //{
00054 //    labelList nCellsPerProc(countCells(distribution));
00055 //
00056 //    if (debug)
00057 //    {
00058 //        Pout<< "getSchedule : Wanted distribution:" << nCellsPerProc << endl;
00059 //    }
00060 //
00061 //    // Processors I need to send data to
00062 //    labelListList mySendProcs(Pstream::nProcs());
00063 //
00064 //    // Count
00065 //    label nSendProcs = 0;
00066 //    forAll(nCellsPerProc, sendProcI)
00067 //    {
00068 //        if (sendProcI != Pstream::myProcNo() && nCellsPerProc[sendProcI] > 0)
00069 //        {
00070 //            nSendProcs++;
00071 //        }
00072 //    }
00073 //
00074 //    // Fill 
00075 //    mySendProcs[Pstream::myProcNo()].setSize(nSendProcs);
00076 //    nSendProcs = 0;
00077 //    forAll(nCellsPerProc, sendProcI)
00078 //    {
00079 //        if (sendProcI != Pstream::myProcNo() && nCellsPerProc[sendProcI] > 0)
00080 //        {
00081 //            mySendProcs[Pstream::myProcNo()][nSendProcs++] = sendProcI;
00082 //        }
00083 //    }
00084 //
00085 //    // Synchronise
00086 //    Pstream::gatherList(mySendProcs);
00087 //    Pstream::scatterList(mySendProcs);
00088 //
00089 //    // Combine into list (same on all procs) giving sending and receiving
00090 //    // processor
00091 //    label nComms = 0;
00092 //    forAll(mySendProcs, procI)
00093 //    {
00094 //        nComms += mySendProcs[procI].size();
00095 //    }
00096 //
00097 //    List<labelPair> schedule(nComms);
00098 //    nComms = 0;
00099 //
00100 //    forAll(mySendProcs, procI)
00101 //    {
00102 //        const labelList& sendProcs = mySendProcs[procI];
00103 //
00104 //        forAll(sendProcs, i)
00105 //        {
00106 //            schedule[nComms++] = labelPair(procI, sendProcs[i]);
00107 //        }
00108 //    }
00109 //
00110 //    return schedule;
00111 //}
00112 
00113 
00114 Foam::labelList Foam::fvMeshDistribute::select
00115 (
00116     const bool selectEqual,
00117     const labelList& values,
00118     const label value
00119 )
00120 {
00121     label n = 0;
00122 
00123     forAll(values, i)
00124     {
00125         if (selectEqual == (values[i] == value))
00126         {
00127             n++;
00128         }
00129     }
00130 
00131     labelList indices(n);
00132     n = 0;
00133 
00134     forAll(values, i)
00135     {
00136         if (selectEqual == (values[i] == value))
00137         {
00138             indices[n++] = i;
00139         }
00140     }
00141     return indices;
00142 }
00143 
00144 
00145 // Check all procs have same names and in exactly same order.
00146 void Foam::fvMeshDistribute::checkEqualWordList(const wordList& lst)
00147 {
00148     wordList myObjects(lst);
00149 
00150     // Check that all meshes have same objects
00151     Pstream::listCombineGather(myObjects, checkEqualType());
00152     // Below scatter only needed to balance sends and receives.
00153     Pstream::listCombineScatter(myObjects);
00154 }
00155 
00156 
00157 Foam::wordList Foam::fvMeshDistribute::mergeWordList(const wordList& procNames)
00158 {
00159     List<wordList> allNames(Pstream::nProcs());
00160     allNames[Pstream::myProcNo()] = procNames;
00161     Pstream::gatherList(allNames);
00162     Pstream::scatterList(allNames);
00163 
00164     HashSet<word> mergedNames;
00165     forAll(allNames, procI)
00166     {
00167         forAll(allNames[procI], i)
00168         {
00169             mergedNames.insert(allNames[procI][i]);
00170         }
00171     }
00172     return mergedNames.toc();
00173 }
00174 
00175 
00176 // Print some info on mesh.
00177 void Foam::fvMeshDistribute::printMeshInfo(const fvMesh& mesh)
00178 {
00179     Pout<< "Primitives:" << nl
00180         << "    points       :" << mesh.nPoints() << nl
00181         << "    internalFaces:" << mesh.nInternalFaces() << nl
00182         << "    faces        :" << mesh.nFaces() << nl
00183         << "    cells        :" << mesh.nCells() << nl;
00184 
00185     const fvBoundaryMesh& patches = mesh.boundary();
00186 
00187     Pout<< "Patches:" << endl;
00188     forAll(patches, patchI)
00189     {
00190         const polyPatch& pp = patches[patchI].patch();
00191 
00192         Pout<< "    " << patchI << " name:" << pp.name()
00193             << " size:" << pp.size()
00194             << " start:" << pp.start()
00195             << " type:" << pp.type()
00196             << endl;
00197     }
00198 
00199     if (mesh.pointZones().size())
00200     {
00201         Pout<< "PointZones:" << endl;
00202         forAll(mesh.pointZones(), zoneI)
00203         {
00204             const pointZone& pz = mesh.pointZones()[zoneI];
00205             Pout<< "    " << zoneI << " name:" << pz.name()
00206                 << " size:" << pz.size()
00207                 << endl;
00208         }
00209     }
00210     if (mesh.faceZones().size())
00211     {
00212         Pout<< "FaceZones:" << endl;
00213         forAll(mesh.faceZones(), zoneI)
00214         {
00215             const faceZone& fz = mesh.faceZones()[zoneI];
00216             Pout<< "    " << zoneI << " name:" << fz.name()
00217                 << " size:" << fz.size()
00218                 << endl;
00219         }
00220     }
00221     if (mesh.cellZones().size())
00222     {
00223         Pout<< "CellZones:" << endl;
00224         forAll(mesh.cellZones(), zoneI)
00225         {
00226             const cellZone& cz = mesh.cellZones()[zoneI];
00227             Pout<< "    " << zoneI << " name:" << cz.name()
00228                 << " size:" << cz.size()
00229                 << endl;
00230         }
00231     }
00232 }
00233 
00234 
00235 void Foam::fvMeshDistribute::printCoupleInfo
00236 (
00237     const primitiveMesh& mesh,
00238     const labelList& sourceFace,
00239     const labelList& sourceProc,
00240     const labelList& sourceNewProc
00241 )
00242 {
00243     Pout<< nl
00244         << "Current coupling info:"
00245         << endl;
00246 
00247     forAll(sourceFace, bFaceI)
00248     {
00249         label meshFaceI = mesh.nInternalFaces() + bFaceI;
00250 
00251         Pout<< "    meshFace:" << meshFaceI
00252             << " fc:" << mesh.faceCentres()[meshFaceI]
00253             << " connects to proc:" << sourceProc[bFaceI]
00254             << "/face:" << sourceFace[bFaceI]
00255             << " which will move to proc:" << sourceNewProc[bFaceI]
00256             << endl;
00257     }
00258 }
00259 
00260 
00261 // Finds (non-empty) patch that exposed internal and proc faces can be put into.
00262 Foam::label Foam::fvMeshDistribute::findNonEmptyPatch() const
00263 {
00264     const polyBoundaryMesh& patches = mesh_.boundaryMesh();
00265 
00266     label nonEmptyPatchI = -1;
00267 
00268     forAllReverse(patches, patchI)
00269     {
00270         const polyPatch& pp = patches[patchI];
00271 
00272         if (!isA<emptyPolyPatch>(pp) && !pp.coupled())
00273         {
00274             nonEmptyPatchI = patchI;
00275             break;
00276         }
00277     }
00278 
00279     if (nonEmptyPatchI == -1)
00280     {
00281         FatalErrorIn("fvMeshDistribute::findNonEmptyPatch() const")
00282             << "Cannot find a patch which is neither of type empty nor"
00283             << " coupled in patches " << patches.names() << endl
00284             << "There has to be at least one such patch for"
00285             << " distribution to work" << abort(FatalError);
00286     }
00287 
00288     if (debug)
00289     {
00290         Pout<< "findNonEmptyPatch : using patch " << nonEmptyPatchI
00291             << " name:" << patches[nonEmptyPatchI].name()
00292             << " type:" << patches[nonEmptyPatchI].type()
00293             << " to put exposed faces into." << endl;
00294     }
00295 
00296 
00297     // Do additional test for processor patches intermingled with non-proc
00298     // patches.
00299     label procPatchI = -1;
00300 
00301     forAll(patches, patchI)
00302     {
00303         if (isA<processorPolyPatch>(patches[patchI]))
00304         {
00305             procPatchI = patchI;
00306         }
00307         else if (procPatchI != -1)
00308         {
00309             FatalErrorIn("fvMeshDistribute::findNonEmptyPatch() const")
00310                 << "Processor patches should be at end of patch list."
00311                 << endl
00312                 << "Have processor patch " << procPatchI
00313                 << " followed by non-processor patch " << patchI
00314                 << " in patches " << patches.names()
00315                 << abort(FatalError);
00316         }
00317     }
00318 
00319     return nonEmptyPatchI;
00320 }
00321 
00322 
00323 // Appends processorPolyPatch. Returns patchID.
00324 Foam::label Foam::fvMeshDistribute::addProcPatch
00325 (
00326     const word& patchName,
00327     const label nbrProc
00328 )
00329 {
00330     // Clear local fields and e.g. polyMesh globalMeshData.
00331     mesh_.clearOut();
00332 
00333 
00334     polyBoundaryMesh& polyPatches =
00335         const_cast<polyBoundaryMesh&>(mesh_.boundaryMesh());
00336     fvBoundaryMesh& fvPatches = const_cast<fvBoundaryMesh&>(mesh_.boundary());
00337 
00338     if (polyPatches.findPatchID(patchName) != -1)
00339     {
00340         FatalErrorIn("fvMeshDistribute::addProcPatch(const word&, const label)")
00341             << "Cannot create patch " << patchName << " since already exists."
00342             << nl
00343             << "Current patch names:" << polyPatches.names()
00344             << exit(FatalError);
00345     }
00346 
00347 
00348 
00349     // Add the patch
00350     // ~~~~~~~~~~~~~
00351 
00352     label sz = polyPatches.size();
00353 
00354     // Add polyPatch
00355     polyPatches.setSize(sz+1);
00356     polyPatches.set
00357     (
00358         sz,
00359         new processorPolyPatch
00360         (
00361             patchName,
00362             0,              // size
00363             mesh_.nFaces(),
00364             sz,
00365             mesh_.boundaryMesh(),
00366             Pstream::myProcNo(),
00367             nbrProc
00368         )
00369     );
00370     fvPatches.setSize(sz+1);
00371     fvPatches.set
00372     (
00373         sz,
00374         fvPatch::New
00375         (
00376             polyPatches[sz],  // point to newly added polyPatch
00377             mesh_.boundary()
00378         )
00379     );
00380 
00381     return sz;
00382 }
00383 
00384 
00385 // Deletes last patch
00386 void Foam::fvMeshDistribute::deleteTrailingPatch()
00387 {
00388     // Clear local fields and e.g. polyMesh globalMeshData.
00389     mesh_.clearOut();
00390 
00391     polyBoundaryMesh& polyPatches =
00392         const_cast<polyBoundaryMesh&>(mesh_.boundaryMesh());
00393     fvBoundaryMesh& fvPatches = const_cast<fvBoundaryMesh&>(mesh_.boundary());
00394 
00395     if (polyPatches.empty())
00396     {
00397         FatalErrorIn("fvMeshDistribute::deleteTrailingPatch(fvMesh&)")
00398             << "No patches in mesh"
00399             << abort(FatalError);
00400     }
00401 
00402     label sz = polyPatches.size();
00403 
00404     label nFaces = polyPatches[sz-1].size();
00405 
00406     // Remove last polyPatch
00407     if (debug)
00408     {
00409         Pout<< "deleteTrailingPatch : Removing patch " << sz-1
00410             << " : " << polyPatches[sz-1].name() << " size:" << nFaces << endl;
00411     }
00412 
00413     if (nFaces)
00414     {
00415         FatalErrorIn("fvMeshDistribute::deleteTrailingPatch()")
00416             << "There are still " << nFaces << " faces in patch to be deleted "
00417             << sz-1 << ' ' << polyPatches[sz-1].name()
00418             << abort(FatalError);
00419     }
00420 
00421     // Remove actual patch
00422     polyPatches.setSize(sz-1);
00423     fvPatches.setSize(sz-1);
00424 }
00425 
00426 
00427 // Delete all processor patches. Move any processor faces into the last
00428 // non-processor patch.
00429 Foam::autoPtr<Foam::mapPolyMesh> Foam::fvMeshDistribute::deleteProcPatches
00430 (
00431     const label destinationPatch
00432 )
00433 {
00434     // New patchID per boundary faces to be repatched. Is -1 (no change)
00435     // or new patchID
00436     labelList newPatchID(mesh_.nFaces() - mesh_.nInternalFaces(), -1);
00437 
00438     label nProcPatches = 0;
00439 
00440     forAll(mesh_.boundaryMesh(), patchI)
00441     {
00442         const polyPatch& pp = mesh_.boundaryMesh()[patchI];
00443 
00444         if (isA<processorPolyPatch>(pp))
00445         {
00446             if (debug)
00447             {
00448                 Pout<< "Moving all faces of patch " << pp.name()
00449                     << " into patch " << destinationPatch
00450                     << endl;
00451             }
00452 
00453             label offset = pp.start() - mesh_.nInternalFaces();
00454 
00455             forAll(pp, i)
00456             {
00457                 newPatchID[offset+i] = destinationPatch;
00458             }
00459 
00460             nProcPatches++;
00461         }
00462     }
00463 
00464     // Note: order of boundary faces been kept the same since the
00465     // destinationPatch is at the end and we have visited the patches in
00466     // incremental order.
00467     labelListList dummyFaceMaps;
00468     autoPtr<mapPolyMesh> map = repatch(newPatchID, dummyFaceMaps);
00469 
00470 
00471     // Delete (now empty) processor patches.
00472     forAllReverse(mesh_.boundaryMesh(), patchI)
00473     {
00474         const polyPatch& pp = mesh_.boundaryMesh()[patchI];
00475 
00476         if (isA<processorPolyPatch>(pp))
00477         {
00478             deleteTrailingPatch();
00479             deleteTrailingPatchFields<volScalarField>();
00480             deleteTrailingPatchFields<volVectorField>();
00481             deleteTrailingPatchFields<volSphericalTensorField>();
00482             deleteTrailingPatchFields<volSymmTensorField>();
00483             deleteTrailingPatchFields<volTensorField>();
00484 
00485             deleteTrailingPatchFields<surfaceScalarField>();
00486             deleteTrailingPatchFields<surfaceVectorField>();
00487             deleteTrailingPatchFields<surfaceSphericalTensorField>();
00488             deleteTrailingPatchFields<surfaceSymmTensorField>();
00489             deleteTrailingPatchFields<surfaceTensorField>();
00490         }
00491     }
00492 
00493     return map;
00494 }
00495 
00496 
00497 // Repatch the mesh.
00498 Foam::autoPtr<Foam::mapPolyMesh> Foam::fvMeshDistribute::repatch
00499 (
00500     const labelList& newPatchID,         // per boundary face -1 or new patchID
00501     labelListList& constructFaceMap
00502 )
00503 {
00504     polyTopoChange meshMod(mesh_);
00505     
00506     forAll(newPatchID, bFaceI)
00507     {
00508         if (newPatchID[bFaceI] != -1)
00509         {
00510             label faceI = mesh_.nInternalFaces() + bFaceI;
00511 
00512             label zoneID = mesh_.faceZones().whichZone(faceI);
00513             bool zoneFlip = false;
00514 
00515             if (zoneID >= 0)
00516             {
00517                 const faceZone& fZone = mesh_.faceZones()[zoneID];
00518                 zoneFlip = fZone.flipMap()[fZone.whichFace(faceI)];
00519             }
00520 
00521             meshMod.setAction
00522             (
00523                 polyModifyFace
00524                 (
00525                     mesh_.faces()[faceI],       // modified face
00526                     faceI,                      // label of face
00527                     mesh_.faceOwner()[faceI],   // owner
00528                     -1,                         // neighbour
00529                     false,                      // face flip
00530                     newPatchID[bFaceI],         // patch for face
00531                     false,                      // remove from zone
00532                     zoneID,                     // zone for face
00533                     zoneFlip                    // face flip in zone
00534                 )
00535             );
00536         }
00537     }
00538 
00539 
00540     // Do mapping of fields from one patchField to the other ourselves since
00541     // is currently not supported by updateMesh.
00542 
00543     // Store boundary fields (we only do this for surfaceFields)
00544     PtrList<FieldField<fvsPatchField, scalar> > sFlds;
00545     saveBoundaryFields<scalar, surfaceMesh>(sFlds);
00546     PtrList<FieldField<fvsPatchField, vector> > vFlds;
00547     saveBoundaryFields<vector, surfaceMesh>(vFlds);
00548     PtrList<FieldField<fvsPatchField, sphericalTensor> > sptFlds;
00549     saveBoundaryFields<sphericalTensor, surfaceMesh>(sptFlds);
00550     PtrList<FieldField<fvsPatchField, symmTensor> > sytFlds;
00551     saveBoundaryFields<symmTensor, surfaceMesh>(sytFlds);
00552     PtrList<FieldField<fvsPatchField, tensor> > tFlds;
00553     saveBoundaryFields<tensor, surfaceMesh>(tFlds);
00554 
00555     // Change the mesh (no inflation). Note: parallel comms allowed.
00556     autoPtr<mapPolyMesh> map = meshMod.changeMesh(mesh_, false, true);
00557 
00558     // Update fields. No inflation, parallel sync.
00559     mesh_.updateMesh(map);
00560 
00561     // Map patch fields using stored boundary fields. Note: assumes order
00562     // of fields has not changed in object registry!
00563     mapBoundaryFields<scalar, surfaceMesh>(map, sFlds);
00564     mapBoundaryFields<vector, surfaceMesh>(map, vFlds);
00565     mapBoundaryFields<sphericalTensor, surfaceMesh>(map, sptFlds);
00566     mapBoundaryFields<symmTensor, surfaceMesh>(map, sytFlds);
00567     mapBoundaryFields<tensor, surfaceMesh>(map, tFlds);
00568 
00569 
00570     // Move mesh (since morphing does not do this)
00571     if (map().hasMotionPoints())
00572     {
00573         mesh_.movePoints(map().preMotionPoints());
00574     }
00575 
00576     // Adapt constructMaps.
00577 
00578     if (debug)
00579     {
00580         label index = findIndex(map().reverseFaceMap(), -1);
00581 
00582         if (index != -1)
00583         {
00584             FatalErrorIn
00585             (
00586                 "fvMeshDistribute::repatch(const labelList&, labelListList&)"
00587             )   << "reverseFaceMap contains -1 at index:"
00588                 << index << endl
00589                 << "This means that the repatch operation was not just"
00590                 << " a shuffle?" << abort(FatalError);
00591         }
00592     }
00593 
00594     forAll(constructFaceMap, procI)
00595     {
00596         inplaceRenumber(map().reverseFaceMap(), constructFaceMap[procI]);
00597     }
00598 
00599 
00600     return map;
00601 }
00602 
00603 
00604 // Detect shared points. Need processor patches to be present.
00605 // Background: when adding bits of mesh one can get points which
00606 // share the same position but are only detectable to be topologically
00607 // the same point when doing parallel analysis. This routine will
00608 // merge those points.
00609 Foam::autoPtr<Foam::mapPolyMesh> Foam::fvMeshDistribute::mergeSharedPoints
00610 (
00611     labelListList& constructPointMap
00612 )
00613 {
00614     // Find out which sets of points get merged and create a map from
00615     // mesh point to unique point.
00616     Map<label> pointToMaster
00617     (
00618         fvMeshAdder::findSharedPoints
00619         (
00620             mesh_,
00621             mergeTol_
00622         )
00623     );
00624 
00625     if (returnReduce(pointToMaster.size(), sumOp<label>()) == 0)
00626     {
00627         return autoPtr<mapPolyMesh>(NULL);
00628     }
00629 
00630     polyTopoChange meshMod(mesh_);
00631 
00632     fvMeshAdder::mergePoints(mesh_, pointToMaster, meshMod);
00633 
00634     // Change the mesh (no inflation). Note: parallel comms allowed.
00635     autoPtr<mapPolyMesh> map = meshMod.changeMesh(mesh_, false, true);
00636 
00637     // Update fields. No inflation, parallel sync.
00638     mesh_.updateMesh(map);
00639 
00640     // Adapt constructMaps for merged points.
00641     forAll(constructPointMap, procI)
00642     {
00643         labelList& constructMap = constructPointMap[procI];
00644 
00645         forAll(constructMap, i)
00646         {
00647             label oldPointI = constructMap[i];
00648 
00649             label newPointI = map().reversePointMap()[oldPointI];
00650 
00651             if (newPointI < -1)
00652             {
00653                 constructMap[i] = -newPointI-2;
00654             }
00655             else if (newPointI >= 0)
00656             {
00657                 constructMap[i] = newPointI;
00658             }
00659             else
00660             {
00661                 FatalErrorIn("fvMeshDistribute::mergeSharedPoints()")
00662                     << "Problem. oldPointI:" << oldPointI
00663                     << " newPointI:" << newPointI << abort(FatalError);
00664             }
00665         }
00666         //- old: use pointToMaster map.
00667         //forAll(constructMap, i)
00668         //{
00669         //    label oldPointI = constructMap[i];
00670         //
00671         //    // See if merged into other point
00672         //    Map<label>::const_iterator iter = pointToMaster.find(oldPointI);
00673         //
00674         //    if (iter != pointToMaster.end())
00675         //    {
00676         //        oldPointI = iter();
00677         //    }
00678         //
00679         //    constructMap[i] = map().reversePointMap()[oldPointI];
00680         //}
00681     }
00682     return map;
00683 }
00684 
00685 
00686 // Construct the local environment of all boundary faces.
00687 void Foam::fvMeshDistribute::getNeighbourData
00688 (
00689     const labelList& distribution,
00690     labelList& sourceFace,
00691     labelList& sourceProc,
00692     labelList& sourceNewProc
00693 ) const
00694 {
00695     sourceFace.setSize(mesh_.nFaces() - mesh_.nInternalFaces());
00696     sourceProc.setSize(sourceFace.size());
00697     sourceNewProc.setSize(sourceFace.size());
00698 
00699     const polyBoundaryMesh& patches = mesh_.boundaryMesh();
00700 
00701     // Send meshFace labels of processor patches and destination processor.
00702     forAll(patches, patchI)
00703     {
00704         const polyPatch& pp = patches[patchI];
00705 
00706         if (isA<processorPolyPatch>(pp))
00707         {
00708             const processorPolyPatch& procPatch =
00709                 refCast<const processorPolyPatch>(pp);
00710 
00711             // Labels of faces on this side
00712             labelList meshFaceLabels(pp.size());
00713             forAll(meshFaceLabels, i)
00714             {
00715                 meshFaceLabels[i] = pp.start()+i;
00716             }
00717 
00718             // Which processor they will end up on
00719             const labelList newProc
00720             (
00721                 UIndirectList<label>(distribution, pp.faceCells())
00722             );
00723 
00724             OPstream toNeighbour(Pstream::blocking, procPatch.neighbProcNo());
00725 
00726             toNeighbour << meshFaceLabels << newProc;
00727         }
00728     }
00729 
00730     // Receive meshFace labels and destination processors of processor faces.
00731     forAll(patches, patchI)
00732     {
00733         const polyPatch& pp = patches[patchI];
00734 
00735         label offset = pp.start() - mesh_.nInternalFaces();
00736 
00737         if (isA<processorPolyPatch>(pp))
00738         {
00739             const processorPolyPatch& procPatch =
00740                 refCast<const processorPolyPatch>(pp);
00741 
00742             // Receive the data
00743             IPstream fromNeighbour(Pstream::blocking, procPatch.neighbProcNo());
00744             labelList nbrFaces(fromNeighbour);
00745             labelList nbrNewProc(fromNeighbour);
00746 
00747             // Check which of the two faces we store.
00748 
00749             if (Pstream::myProcNo() < procPatch.neighbProcNo())
00750             {
00751                 // Use my local face labels
00752                 forAll(pp, i)
00753                 {
00754                     sourceFace[offset + i] = pp.start()+i;
00755                     sourceProc[offset + i] = Pstream::myProcNo();
00756                     sourceNewProc[offset + i] = nbrNewProc[i];
00757                 }
00758             }
00759             else
00760             {
00761                 // Use my neighbours face labels
00762                 forAll(pp, i)
00763                 {
00764                     sourceFace[offset + i] = nbrFaces[i];
00765                     sourceProc[offset + i] = procPatch.neighbProcNo();
00766                     sourceNewProc[offset + i] = nbrNewProc[i];
00767                 }
00768             }
00769         }
00770         else
00771         {
00772             // Normal (physical) boundary
00773             forAll(pp, i)
00774             {
00775                 sourceFace[offset + i] = patchI;
00776                 sourceProc[offset + i] = -1;
00777                 sourceNewProc[offset + i] = -1;
00778             }
00779         }
00780     }
00781 }
00782 
00783 
00784 // Subset the neighbourCell/neighbourProc fields
00785 void Foam::fvMeshDistribute::subsetBoundaryData
00786 (
00787     const fvMesh& mesh,
00788     const labelList& faceMap,
00789     const labelList& cellMap,
00790 
00791     const labelList& oldDistribution,
00792     const labelList& oldFaceOwner,
00793     const labelList& oldFaceNeighbour,
00794     const label oldInternalFaces,
00795 
00796     const labelList& sourceFace,
00797     const labelList& sourceProc,
00798     const labelList& sourceNewProc,
00799 
00800     labelList& subFace,
00801     labelList& subProc,
00802     labelList& subNewProc
00803 )
00804 {
00805     subFace.setSize(mesh.nFaces() - mesh.nInternalFaces());
00806     subProc.setSize(mesh.nFaces() - mesh.nInternalFaces());
00807     subNewProc.setSize(mesh.nFaces() - mesh.nInternalFaces());
00808 
00809     forAll(subFace, newBFaceI)
00810     {
00811         label newFaceI = newBFaceI + mesh.nInternalFaces();
00812 
00813         label oldFaceI = faceMap[newFaceI];
00814 
00815         // Was oldFaceI internal face? If so which side did we get.
00816         if (oldFaceI < oldInternalFaces)
00817         {
00818             subFace[newBFaceI] = oldFaceI;
00819             subProc[newBFaceI] = Pstream::myProcNo();
00820 
00821             label oldOwn = oldFaceOwner[oldFaceI];
00822             label oldNei = oldFaceNeighbour[oldFaceI];
00823 
00824             if (oldOwn == cellMap[mesh.faceOwner()[newFaceI]])
00825             {
00826                 // We kept the owner side. Where does the neighbour move to?
00827                 subNewProc[newBFaceI] = oldDistribution[oldNei];
00828             }
00829             else
00830             {
00831                 // We kept the neighbour side.
00832                 subNewProc[newBFaceI] = oldDistribution[oldOwn];
00833             }
00834         }
00835         else
00836         {
00837             // Was boundary face. Take over boundary information
00838             label oldBFaceI = oldFaceI - oldInternalFaces;
00839 
00840             subFace[newBFaceI] = sourceFace[oldBFaceI];
00841             subProc[newBFaceI] = sourceProc[oldBFaceI];
00842             subNewProc[newBFaceI] = sourceNewProc[oldBFaceI];
00843         }
00844     }
00845 }
00846 
00847 
00848 // Find cells on mesh whose faceID/procID match the neighbour cell/proc of
00849 // domainMesh. Store the matching face.
00850 void Foam::fvMeshDistribute::findCouples
00851 (
00852     const primitiveMesh& mesh,
00853     const labelList& sourceFace,
00854     const labelList& sourceProc,
00855 
00856     const label domain,
00857     const primitiveMesh& domainMesh,
00858     const labelList& domainFace,
00859     const labelList& domainProc,
00860 
00861     labelList& masterCoupledFaces,
00862     labelList& slaveCoupledFaces
00863 )
00864 {
00865     // Store domain neighbour as map so we can easily look for pair
00866     // with same face+proc.
00867     HashTable<label, labelPair, labelPair::Hash<> > map(domainFace.size());
00868 
00869     forAll(domainFace, bFaceI)
00870     {
00871         map.insert(labelPair(domainFace[bFaceI], domainProc[bFaceI]), bFaceI);
00872     }
00873 
00874 
00875     // Try to match mesh data.
00876 
00877     masterCoupledFaces.setSize(domainFace.size());
00878     slaveCoupledFaces.setSize(domainFace.size());
00879     label coupledI = 0;
00880 
00881     forAll(sourceFace, bFaceI)
00882     {
00883         if (sourceProc[bFaceI] != -1)
00884         {
00885             labelPair myData(sourceFace[bFaceI], sourceProc[bFaceI]);
00886 
00887             HashTable<label, labelPair, labelPair::Hash<> >::const_iterator
00888                 iter = map.find(myData);
00889 
00890             if (iter != map.end())
00891             {
00892                 label nbrBFaceI = iter();
00893 
00894                 masterCoupledFaces[coupledI] = mesh.nInternalFaces() + bFaceI;
00895                 slaveCoupledFaces[coupledI] =
00896                     domainMesh.nInternalFaces()
00897                   + nbrBFaceI;
00898 
00899                 coupledI++;
00900             }
00901         }
00902     }
00903 
00904     masterCoupledFaces.setSize(coupledI);
00905     slaveCoupledFaces.setSize(coupledI);
00906 
00907     if (debug)
00908     {
00909         Pout<< "findCouples : found " << coupledI
00910             << " faces that will be stitched" << nl << endl;
00911     }
00912 }
00913 
00914 
00915 // Map data on boundary faces to new mesh (resulting from adding two meshes)
00916 Foam::labelList Foam::fvMeshDistribute::mapBoundaryData
00917 (
00918     const primitiveMesh& mesh,      // mesh after adding
00919     const mapAddedPolyMesh& map,
00920     const labelList& boundaryData0, // mesh before adding
00921     const label nInternalFaces1,
00922     const labelList& boundaryData1  // added mesh
00923 )
00924 {
00925     labelList newBoundaryData(mesh.nFaces() - mesh.nInternalFaces());
00926 
00927     forAll(boundaryData0, oldBFaceI)
00928     {
00929         label newFaceI = map.oldFaceMap()[oldBFaceI + map.nOldInternalFaces()];
00930 
00931         // Face still exists (is necessary?) and still boundary face
00932         if (newFaceI >= 0 && newFaceI >= mesh.nInternalFaces())
00933         {
00934             newBoundaryData[newFaceI - mesh.nInternalFaces()] =
00935                 boundaryData0[oldBFaceI];
00936         }
00937     }
00938 
00939     forAll(boundaryData1, addedBFaceI)
00940     {
00941         label newFaceI = map.addedFaceMap()[addedBFaceI + nInternalFaces1];
00942 
00943         if (newFaceI >= 0 && newFaceI >= mesh.nInternalFaces())
00944         {
00945             newBoundaryData[newFaceI - mesh.nInternalFaces()] =
00946                 boundaryData1[addedBFaceI];
00947         }
00948     }
00949 
00950     return newBoundaryData;
00951 }
00952 
00953 
00954 // Remove cells. Add all exposed faces to patch oldInternalPatchI
00955 Foam::autoPtr<Foam::mapPolyMesh> Foam::fvMeshDistribute::doRemoveCells
00956 (
00957     const labelList& cellsToRemove,
00958     const label oldInternalPatchI
00959 )
00960 {
00961     // Mesh change engine
00962     polyTopoChange meshMod(mesh_);
00963 
00964     // Cell removal topo engine. Do NOT synchronize parallel since
00965     // we are doing a local cell removal.
00966     removeCells cellRemover(mesh_, false);
00967 
00968     // Get all exposed faces
00969     labelList exposedFaces(cellRemover.getExposedFaces(cellsToRemove));
00970 
00971     // Insert the topo changes
00972     cellRemover.setRefinement
00973     (
00974         cellsToRemove,
00975         exposedFaces,
00976         labelList(exposedFaces.size(), oldInternalPatchI),  // patch for exposed
00977                                                             // faces.
00978         meshMod
00979     );
00980 
00981     // Change the mesh. No inflation. Note: no parallel comms allowed.
00982     autoPtr<mapPolyMesh> map = meshMod.changeMesh(mesh_, false, false);
00983 
00984     // Update fields
00985     mesh_.updateMesh(map);
00986 
00987     // Move mesh (since morphing does not do this)
00988     if (map().hasMotionPoints())
00989     {
00990         mesh_.movePoints(map().preMotionPoints());
00991     }
00992 
00993     return map;
00994 }
00995 
00996 
00997 // Delete and add processor patches. Changes mesh and returns per neighbour proc
00998 // the processor patchID.
00999 void Foam::fvMeshDistribute::addProcPatches
01000 (
01001     const labelList& neighbourNewProc,   // processor that neighbour is on
01002     labelList& procPatchID              
01003 )
01004 {
01005     // Now use the neighbourFace/Proc to repatch the mesh. These two lists
01006     // contain for all current boundary faces the global patchID (for non-proc
01007     // patch) or the processor.
01008 
01009     labelList procPatchSizes(Pstream::nProcs(), 0);
01010 
01011     forAll(neighbourNewProc, bFaceI)
01012     {
01013         if (neighbourNewProc[bFaceI] != -1)
01014         {
01015             procPatchSizes[neighbourNewProc[bFaceI]]++;
01016         }
01017     }
01018 
01019     // Per neighbour processor the label of the processor patch
01020     procPatchID.setSize(Pstream::nProcs());
01021 
01022     forAll(procPatchSizes, procI)
01023     {
01024         if (procPatchSizes[procI] > 0)
01025         {
01026             const word patchName =
01027                 "procBoundary"
01028               + name(Pstream::myProcNo())
01029               + "to"
01030               + name(procI);
01031 
01032 
01033             procPatchID[procI] = addProcPatch(patchName, procI);
01034             addPatchFields<volScalarField>
01035             (
01036                 processorFvPatchField<scalar>::typeName
01037             );
01038             addPatchFields<volVectorField>
01039             (
01040                 processorFvPatchField<vector>::typeName
01041             );
01042             addPatchFields<volSphericalTensorField>
01043             (
01044                 processorFvPatchField<sphericalTensor>::typeName
01045             );
01046             addPatchFields<volSymmTensorField>
01047             (
01048                 processorFvPatchField<symmTensor>::typeName
01049             );
01050             addPatchFields<volTensorField>
01051             (
01052                 processorFvPatchField<tensor>::typeName
01053             );
01054 
01055             addPatchFields<surfaceScalarField>
01056             (
01057                 processorFvPatchField<scalar>::typeName
01058             );
01059             addPatchFields<surfaceVectorField>
01060             (
01061                 processorFvPatchField<vector>::typeName
01062             );
01063             addPatchFields<surfaceSphericalTensorField>
01064             (
01065                 processorFvPatchField<sphericalTensor>::typeName
01066             );
01067             addPatchFields<surfaceSymmTensorField>
01068             (
01069                 processorFvPatchField<symmTensor>::typeName
01070             );
01071             addPatchFields<surfaceTensorField>
01072             (
01073                 processorFvPatchField<tensor>::typeName
01074             );
01075         }
01076         else
01077         {
01078             procPatchID[procI] = -1;
01079         }
01080     }
01081 }
01082 
01083 
01084 // Get boundary faces to be repatched. Is -1 or new patchID
01085 Foam::labelList Foam::fvMeshDistribute::getProcBoundaryPatch
01086 (
01087     const labelList& neighbourNewProc,  // new processor per boundary face
01088     const labelList& procPatchID        // patchID
01089 )
01090 {
01091     labelList patchIDs(neighbourNewProc);
01092 
01093     forAll(neighbourNewProc, bFaceI)
01094     {
01095         if (neighbourNewProc[bFaceI] != -1)
01096         {
01097             label nbrProc = neighbourNewProc[bFaceI];
01098 
01099             patchIDs[bFaceI] = procPatchID[nbrProc];
01100         }
01101         else
01102         {
01103             patchIDs[bFaceI] = -1;
01104         }
01105     }
01106     return patchIDs;
01107 }
01108 
01109 
01110 // Send mesh and coupling data.
01111 void Foam::fvMeshDistribute::sendMesh
01112 (
01113     const label domain,
01114     const fvMesh& mesh,
01115 
01116     const wordList& pointZoneNames,
01117     const wordList& faceZoneNames,
01118     const wordList& cellZoneNames,
01119 
01120     const labelList& sourceFace,
01121     const labelList& sourceProc,
01122     const labelList& sourceNewProc
01123 )
01124 {
01125     if (debug)
01126     {
01127         Pout<< "Sending to domain " << domain << nl
01128             << "    nPoints:" << mesh.nPoints() << nl
01129             << "    nFaces:" << mesh.nFaces() << nl
01130             << "    nCells:" << mesh.nCells() << nl
01131             << "    nPatches:" << mesh.boundaryMesh().size() << nl
01132             << endl;
01133     }
01134 
01135     // Assume sparse point zones. Get contents in merged-zone indices.
01136     labelListList zonePoints(pointZoneNames.size());
01137     {
01138         const pointZoneMesh& pointZones = mesh.pointZones();
01139 
01140         forAll(pointZoneNames, nameI)
01141         {
01142             label myZoneID = pointZones.findZoneID(pointZoneNames[nameI]);
01143 
01144             if (myZoneID != -1)
01145             {
01146                 zonePoints[nameI] = pointZones[myZoneID];
01147             }
01148         }
01149     }
01150 
01151     // Assume sparse face zones
01152     labelListList zoneFaces(faceZoneNames.size());
01153     boolListList zoneFaceFlip(faceZoneNames.size());
01154     {
01155         const faceZoneMesh& faceZones = mesh.faceZones();
01156 
01157         forAll(faceZoneNames, nameI)
01158         {
01159             label myZoneID = faceZones.findZoneID(faceZoneNames[nameI]);
01160 
01161             if (myZoneID != -1)
01162             {
01163                 zoneFaces[nameI] = faceZones[myZoneID];
01164                 zoneFaceFlip[nameI] = faceZones[myZoneID].flipMap();
01165             }
01166         }
01167     }
01168 
01169     // Assume sparse cell zones
01170     labelListList zoneCells(cellZoneNames.size());
01171     {
01172         const cellZoneMesh& cellZones = mesh.cellZones();
01173 
01174         forAll(cellZoneNames, nameI)
01175         {
01176             label myZoneID = cellZones.findZoneID(cellZoneNames[nameI]);
01177 
01178             if (myZoneID != -1)
01179             {
01180                 zoneCells[nameI] = cellZones[myZoneID];
01181             }
01182         }
01183     }
01185     //labelList cellZoneID;
01186     //if (hasCellZones)
01187     //{
01188     //    cellZoneID.setSize(mesh.nCells());
01189     //    cellZoneID = -1;
01190     //
01191     //    const cellZoneMesh& cellZones = mesh.cellZones();
01192     //
01193     //    forAll(cellZones, zoneI)
01194     //    {
01195     //        UIndirectList<label>(cellZoneID, cellZones[zoneI]) = zoneI;
01196     //    }
01197     //}
01198 
01199     // Send
01200     OPstream toDomain(Pstream::blocking, domain);
01201     toDomain
01202         << mesh.points()
01203         << mesh.faces()
01204         << mesh.faceOwner()
01205         << mesh.faceNeighbour()
01206         << mesh.boundaryMesh()
01207 
01208         << zonePoints
01209         << zoneFaces
01210         << zoneFaceFlip
01211         << zoneCells
01212 
01213         << sourceFace
01214         << sourceProc
01215         << sourceNewProc;
01216 }
01217 
01218 
01219 // Receive mesh. Opposite of sendMesh
01220 Foam::autoPtr<Foam::fvMesh> Foam::fvMeshDistribute::receiveMesh
01221 (
01222     const label domain,
01223     const wordList& pointZoneNames,
01224     const wordList& faceZoneNames,
01225     const wordList& cellZoneNames,
01226     const Time& runTime,
01227     labelList& domainSourceFace,
01228     labelList& domainSourceProc,
01229     labelList& domainSourceNewProc
01230 )
01231 {
01232     IPstream fromNbr(Pstream::blocking, domain);
01233 
01234     pointField domainPoints(fromNbr);
01235     faceList domainFaces(fromNbr);
01236     labelList domainAllOwner(fromNbr);
01237     labelList domainAllNeighbour(fromNbr);
01238     PtrList<entry> patchEntries(fromNbr);
01239 
01240     labelListList zonePoints(fromNbr);
01241     labelListList zoneFaces(fromNbr);
01242     boolListList zoneFaceFlip(fromNbr);
01243     labelListList zoneCells(fromNbr);
01244 
01245     fromNbr
01246         >> domainSourceFace
01247         >> domainSourceProc
01248         >> domainSourceNewProc;
01249 
01250     // Construct fvMesh
01251     autoPtr<fvMesh> domainMeshPtr
01252     (
01253         new fvMesh 
01254         (
01255             IOobject
01256             (
01257                 fvMesh::defaultRegion,
01258                 runTime.timeName(),
01259                 runTime,
01260                 IOobject::NO_READ
01261             ),
01262             xferMove(domainPoints),
01263             xferMove(domainFaces),
01264             xferMove(domainAllOwner),
01265             xferMove(domainAllNeighbour),
01266             false                   // no parallel comms
01267         )
01268     );
01269     fvMesh& domainMesh = domainMeshPtr();
01270 
01271     List<polyPatch*> patches(patchEntries.size());
01272 
01273     forAll(patchEntries, patchI)
01274     {
01275         patches[patchI] = polyPatch::New
01276         (
01277             patchEntries[patchI].keyword(),
01278             patchEntries[patchI].dict(),
01279             patchI,
01280             domainMesh.boundaryMesh()
01281         ).ptr();
01282     }
01283     // Add patches; no parallel comms
01284     domainMesh.addFvPatches(patches, false);
01285 
01286     // Construct zones
01287     List<pointZone*> pZonePtrs(pointZoneNames.size());
01288     forAll(pZonePtrs, i)
01289     {
01290         pZonePtrs[i] = new pointZone
01291         (
01292             pointZoneNames[i],
01293             zonePoints[i],
01294             i,
01295             domainMesh.pointZones()
01296         );
01297     }
01298 
01299     List<faceZone*> fZonePtrs(faceZoneNames.size());
01300     forAll(fZonePtrs, i)
01301     {
01302         fZonePtrs[i] = new faceZone
01303         (
01304             faceZoneNames[i],
01305             zoneFaces[i],
01306             zoneFaceFlip[i],
01307             i,
01308             domainMesh.faceZones()
01309         );
01310     }
01311 
01312     List<cellZone*> cZonePtrs(cellZoneNames.size());
01313     forAll(cZonePtrs, i)
01314     {
01315         cZonePtrs[i] = new cellZone
01316         (
01317             cellZoneNames[i],
01318             zoneCells[i],
01319             i,
01320             domainMesh.cellZones()
01321         );
01322     }
01323     domainMesh.addZones(pZonePtrs, fZonePtrs, cZonePtrs);
01324 
01325     return domainMeshPtr;
01326 }
01327 
01328 
01329 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
01330 
01331 // Construct from components
01332 Foam::fvMeshDistribute::fvMeshDistribute(fvMesh& mesh, const scalar mergeTol)
01333 :
01334     mesh_(mesh),
01335     mergeTol_(mergeTol)
01336 {}
01337 
01338 
01339 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
01340 
01341 Foam::labelList Foam::fvMeshDistribute::countCells
01342 (
01343     const labelList& distribution
01344 )
01345 {
01346     labelList nCells(Pstream::nProcs(), 0);
01347     forAll(distribution, cellI)
01348     {
01349         label newProc = distribution[cellI];
01350 
01351         if (newProc < 0 || newProc >= Pstream::nProcs())
01352         {
01353             FatalErrorIn("fvMeshDistribute::distribute(const labelList&)")
01354                 << "Distribution should be in range 0.." << Pstream::nProcs()-1
01355                 << endl
01356                 << "At index " << cellI << " distribution:" << newProc
01357                 << abort(FatalError);
01358         }
01359         nCells[newProc]++;
01360     }
01361     return nCells;
01362 }
01363 
01364 
01365 Foam::autoPtr<Foam::mapDistributePolyMesh> Foam::fvMeshDistribute::distribute
01366 (
01367     const labelList& distribution
01368 )
01369 {
01370     // Some checks on distribution
01371     if (distribution.size() != mesh_.nCells())
01372     {
01373         FatalErrorIn("fvMeshDistribute::distribute(const labelList&)")
01374             << "Size of distribution:"
01375             << distribution.size() << " mesh nCells:" << mesh_.nCells()
01376             << abort(FatalError);
01377     }
01378 
01379 
01380     const polyBoundaryMesh& patches = mesh_.boundaryMesh();
01381 
01382     // Check all processors have same non-proc patches in same order.
01383     if (patches.checkParallelSync(true))
01384     {
01385         FatalErrorIn("fvMeshDistribute::distribute(const labelList&)")
01386             << "This application requires all non-processor patches"
01387             << " to be present in the same order on all patches" << nl
01388             << "followed by the processor patches (which of course are unique)."
01389             << nl
01390             << "Local patches:" << mesh_.boundaryMesh().names()
01391             << abort(FatalError);
01392     }
01393 
01394     // Save some data for mapping later on
01395     const label nOldPoints(mesh_.nPoints());
01396     const label nOldFaces(mesh_.nFaces());
01397     const label nOldCells(mesh_.nCells());
01398     labelList oldPatchStarts(patches.size());
01399     labelList oldPatchNMeshPoints(patches.size());
01400     forAll(patches, patchI)
01401     {
01402         oldPatchStarts[patchI] = patches[patchI].start();
01403         oldPatchNMeshPoints[patchI] = patches[patchI].nPoints();
01404     }
01405 
01406 
01407 
01408     // Short circuit trivial case.
01409     if (!Pstream::parRun())
01410     {
01411         // Collect all maps and return
01412         return autoPtr<mapDistributePolyMesh>
01413         (
01414             new mapDistributePolyMesh
01415             (
01416                 mesh_,
01417 
01418                 nOldPoints,
01419                 nOldFaces,
01420                 nOldCells,
01421                 oldPatchStarts,
01422                 oldPatchNMeshPoints,
01423 
01424                 labelListList(1, identity(mesh_.nPoints())),//subPointMap
01425                 labelListList(1, identity(mesh_.nFaces())), //subFaceMap
01426                 labelListList(1, identity(mesh_.nCells())), //subCellMap
01427                 labelListList(1, identity(patches.size())), //subPatchMap
01428 
01429                 labelListList(1, identity(mesh_.nPoints())),//constructPointMap
01430                 labelListList(1, identity(mesh_.nFaces())), //constructFaceMap
01431                 labelListList(1, identity(mesh_.nCells())), //constructCellMap
01432                 labelListList(1, identity(patches.size()))  //constructPatchMap
01433             )
01434         );
01435     }
01436 
01437 
01438     // Collect any zone names
01439     const wordList pointZoneNames(mergeWordList(mesh_.pointZones().names()));
01440     const wordList faceZoneNames(mergeWordList(mesh_.faceZones().names()));
01441     const wordList cellZoneNames(mergeWordList(mesh_.cellZones().names()));
01442 
01443 
01444     // Local environment of all boundary faces
01445     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
01446 
01447     // A face is uniquely defined by
01448     //  - proc
01449     //  - local face no
01450     //
01451     // To glue the parts of meshes which can get sent from anywhere we
01452     // need to know on boundary faces what the above tuple on both sides is.
01453     // So we need to maintain:
01454     //  - original face
01455     //  - original processor id (= trivial)
01456     // For coupled boundaries (where the faces are 'duplicate') we take the
01457     // lowest numbered processor as the data to store.
01458     //
01459     // Additionally to create the procboundaries we need to know where the owner
01460     // cell on the other side now is: newNeighbourProc.
01461     //
01462 
01463     // physical boundary:
01464     //     sourceProc = -1
01465     //     sourceNewProc = -1
01466     //     sourceFace = patchID
01467     // coupled boundary:
01468     //     sourceProc = proc
01469     //     sourceNewProc = distribution[cell on proc]
01470     //     sourceFace = face
01471     labelList sourceFace;
01472     labelList sourceProc;
01473     labelList sourceNewProc;
01474     getNeighbourData(distribution, sourceFace, sourceProc, sourceNewProc);
01475 
01476 
01477     // Remove meshPhi. Since this would otherwise dissappear anyway
01478     // during topo changes and we have to guarantee that all the fields
01479     // can be sent.
01480     mesh_.clearOut();
01481     mesh_.resetMotion();
01482 
01483     const wordList volScalars(mesh_.names(volScalarField::typeName));
01484     checkEqualWordList(volScalars);
01485     const wordList volVectors(mesh_.names(volVectorField::typeName));
01486     checkEqualWordList(volVectors);
01487     const wordList volSphereTensors
01488     (
01489         mesh_.names(volSphericalTensorField::typeName)
01490     );
01491     checkEqualWordList(volSphereTensors);
01492     const wordList volSymmTensors(mesh_.names(volSymmTensorField::typeName));
01493     checkEqualWordList(volSymmTensors);
01494     const wordList volTensors(mesh_.names(volTensorField::typeName));
01495     checkEqualWordList(volTensors);
01496 
01497     const wordList surfScalars(mesh_.names(surfaceScalarField::typeName));
01498     checkEqualWordList(surfScalars);
01499     const wordList surfVectors(mesh_.names(surfaceVectorField::typeName));
01500     checkEqualWordList(surfVectors);
01501     const wordList surfSphereTensors
01502     (
01503         mesh_.names(surfaceSphericalTensorField::typeName)
01504     );
01505     checkEqualWordList(surfSphereTensors);
01506     const wordList surfSymmTensors
01507     (
01508         mesh_.names(surfaceSymmTensorField::typeName)
01509     );
01510     checkEqualWordList(surfSymmTensors);
01511     const wordList surfTensors(mesh_.names(surfaceTensorField::typeName));
01512     checkEqualWordList(surfTensors);
01513 
01514 
01515     // Find patch to temporarily put exposed and processor faces into.
01516     label oldInternalPatchI = findNonEmptyPatch();
01517 
01518 
01519 
01520     // Delete processor patches, starting from the back. Move all faces into
01521     // oldInternalPatchI.
01522     labelList repatchFaceMap;
01523     {
01524         autoPtr<mapPolyMesh> repatchMap = deleteProcPatches(oldInternalPatchI);
01525 
01526         // Store face map (only face ordering that changed)
01527         repatchFaceMap = repatchMap().faceMap();
01528 
01529         // Reorder all boundary face data (sourceProc, sourceFace etc.)
01530         labelList bFaceMap
01531         (
01532             SubList<label>
01533             (
01534                 repatchMap().reverseFaceMap(),
01535                 mesh_.nFaces() - mesh_.nInternalFaces(),
01536                 mesh_.nInternalFaces()
01537             )
01538           - mesh_.nInternalFaces()
01539         );
01540 
01541         inplaceReorder(bFaceMap, sourceFace);
01542         inplaceReorder(bFaceMap, sourceProc);
01543         inplaceReorder(bFaceMap, sourceNewProc);
01544     }
01545 
01546 
01547 
01548     // Print a bit.
01549     if (debug)
01550     {
01551         Pout<< nl << "MESH WITH PROC PATCHES DELETED:" << endl;
01552         printMeshInfo(mesh_);
01553         printFieldInfo<volScalarField>(mesh_);
01554         printFieldInfo<volVectorField>(mesh_);
01555         printFieldInfo<volSphericalTensorField>(mesh_);
01556         printFieldInfo<volSymmTensorField>(mesh_);
01557         printFieldInfo<volTensorField>(mesh_);
01558         printFieldInfo<surfaceScalarField>(mesh_);
01559         printFieldInfo<surfaceVectorField>(mesh_);
01560         printFieldInfo<surfaceSphericalTensorField>(mesh_);
01561         printFieldInfo<surfaceSymmTensorField>(mesh_);
01562         printFieldInfo<surfaceTensorField>(mesh_);
01563         Pout<< nl << endl;
01564     }
01565 
01566 
01567 
01568     // Maps from subsetted mesh (that is sent) back to original maps
01569     labelListList subCellMap(Pstream::nProcs());
01570     labelListList subFaceMap(Pstream::nProcs());
01571     labelListList subPointMap(Pstream::nProcs());
01572     labelListList subPatchMap(Pstream::nProcs());
01573     // Maps from subsetted mesh to reconstructed mesh
01574     labelListList constructCellMap(Pstream::nProcs());
01575     labelListList constructFaceMap(Pstream::nProcs());
01576     labelListList constructPointMap(Pstream::nProcs());
01577     labelListList constructPatchMap(Pstream::nProcs());
01578 
01579 
01580 
01581 
01582     // Find out schedule
01583     // ~~~~~~~~~~~~~~~~~
01584 
01585     labelListList nSendCells(Pstream::nProcs());
01586     nSendCells[Pstream::myProcNo()] = countCells(distribution);
01587     Pstream::gatherList(nSendCells);
01588     Pstream::scatterList(nSendCells);
01589 
01590 
01591 
01592     // What to send to neighbouring domains
01593     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
01594 
01595     forAll(nSendCells[Pstream::myProcNo()], recvProc)
01596     {
01597         if
01598         (
01599             recvProc != Pstream::myProcNo()
01600          && nSendCells[Pstream::myProcNo()][recvProc] > 0
01601         )
01602         {
01603             // Send to recvProc
01604 
01605             if (debug)
01606             {
01607                 Pout<< nl
01608                     << "SUBSETTING FOR DOMAIN " << recvProc
01609                     << " cells to send:"
01610                     << nSendCells[Pstream::myProcNo()][recvProc]
01611                     << nl << endl;
01612             }
01613 
01614             // Mesh subsetting engine
01615             fvMeshSubset subsetter(mesh_);
01616 
01617             // Subset the cells of the current domain.
01618             subsetter.setLargeCellSubset
01619             (
01620                 distribution,
01621                 recvProc,
01622                 oldInternalPatchI,  // oldInternalFaces patch
01623                 false               // no parallel sync
01624             );
01625 
01626             subCellMap[recvProc] = subsetter.cellMap();
01627             subFaceMap[recvProc] = renumber
01628             (
01629                 repatchFaceMap,
01630                 subsetter.faceMap()
01631             );
01632             subPointMap[recvProc] = subsetter.pointMap();
01633             subPatchMap[recvProc] = subsetter.patchMap();
01634 
01635 
01636             // Subset the boundary fields (owner/neighbour/processor)
01637             labelList procSourceFace;
01638             labelList procSourceProc;
01639             labelList procSourceNewProc;
01640 
01641             subsetBoundaryData
01642             (
01643                 subsetter.subMesh(),
01644                 subsetter.faceMap(),        // from subMesh to mesh
01645                 subsetter.cellMap(),        //      ,,      ,,
01646 
01647                 distribution,               // old mesh distribution
01648                 mesh_.faceOwner(),          // old owner
01649                 mesh_.faceNeighbour(),
01650                 mesh_.nInternalFaces(),
01651 
01652                 sourceFace,
01653                 sourceProc,
01654                 sourceNewProc,
01655 
01656                 procSourceFace,
01657                 procSourceProc,
01658                 procSourceNewProc
01659             );
01660 
01661             // Send to neighbour
01662             sendMesh
01663             (
01664                 recvProc,
01665                 subsetter.subMesh(),
01666 
01667                 pointZoneNames,
01668                 faceZoneNames,
01669                 cellZoneNames,
01670 
01671                 procSourceFace,
01672                 procSourceProc,
01673                 procSourceNewProc
01674             );
01675             sendFields<volScalarField>(recvProc, volScalars, subsetter);
01676             sendFields<volVectorField>(recvProc, volVectors, subsetter);
01677             sendFields<volSphericalTensorField>
01678             (
01679                 recvProc,
01680                 volSphereTensors,
01681                 subsetter
01682             );
01683             sendFields<volSymmTensorField>
01684             (
01685                 recvProc,
01686                 volSymmTensors,
01687                 subsetter
01688             );
01689             sendFields<volTensorField>(recvProc, volTensors, subsetter);
01690 
01691             sendFields<surfaceScalarField>(recvProc, surfScalars, subsetter);
01692             sendFields<surfaceVectorField>(recvProc, surfVectors, subsetter);
01693             sendFields<surfaceSphericalTensorField>
01694             (   
01695                 recvProc,
01696                 surfSphereTensors,
01697                 subsetter
01698             );
01699             sendFields<surfaceSymmTensorField>
01700             (
01701                 recvProc,
01702                 surfSymmTensors,
01703                 subsetter
01704             );
01705             sendFields<surfaceTensorField>(recvProc, surfTensors, subsetter);
01706         }
01707     }
01708 
01709 
01710 
01711     // Subset the part that stays
01712     // ~~~~~~~~~~~~~~~~~~~~~~~~~~
01713 
01714     {
01715         // Save old mesh maps before changing mesh
01716         const labelList oldFaceOwner(mesh_.faceOwner());
01717         const labelList oldFaceNeighbour(mesh_.faceNeighbour());
01718         const label oldInternalFaces = mesh_.nInternalFaces();
01719 
01720         // Remove cells.
01721         autoPtr<mapPolyMesh> subMap
01722         (
01723             doRemoveCells
01724             (
01725                 select(false, distribution, Pstream::myProcNo()),
01726                 oldInternalPatchI
01727             )
01728         );
01729 
01730         // Addressing from subsetted mesh
01731         subCellMap[Pstream::myProcNo()] = subMap().cellMap();
01732         subFaceMap[Pstream::myProcNo()] = renumber
01733         (
01734             repatchFaceMap,
01735             subMap().faceMap()
01736         );
01737         subPointMap[Pstream::myProcNo()] = subMap().pointMap();
01738         subPatchMap[Pstream::myProcNo()] = identity(patches.size());
01739 
01740         // Initialize all addressing into current mesh
01741         constructCellMap[Pstream::myProcNo()] = identity(mesh_.nCells());
01742         constructFaceMap[Pstream::myProcNo()] = identity(mesh_.nFaces());
01743         constructPointMap[Pstream::myProcNo()] = identity(mesh_.nPoints());
01744         constructPatchMap[Pstream::myProcNo()] = identity(patches.size());
01745 
01746         // Subset the mesh data: neighbourCell/neighbourProc
01747         // fields
01748         labelList domainSourceFace;
01749         labelList domainSourceProc;
01750         labelList domainSourceNewProc;
01751 
01752         subsetBoundaryData
01753         (
01754             mesh_,                          // new mesh
01755             subMap().faceMap(),             // from new to original mesh
01756             subMap().cellMap(),
01757 
01758             distribution,                   // distribution before subsetting
01759             oldFaceOwner,                   // owner before subsetting
01760             oldFaceNeighbour,               // neighbour        ,,
01761             oldInternalFaces,               // nInternalFaces   ,,
01762 
01763             sourceFace,
01764             sourceProc,
01765             sourceNewProc,
01766 
01767             domainSourceFace,
01768             domainSourceProc,
01769             domainSourceNewProc
01770         );
01771 
01772         sourceFace.transfer(domainSourceFace);
01773         sourceProc.transfer(domainSourceProc);
01774         sourceNewProc.transfer(domainSourceNewProc);
01775     }
01776 
01777 
01778     // Print a bit.
01779     if (debug)
01780     {
01781         Pout<< nl << "STARTING MESH:" << endl;
01782         printMeshInfo(mesh_);
01783         printFieldInfo<volScalarField>(mesh_);
01784         printFieldInfo<volVectorField>(mesh_);
01785         printFieldInfo<volSphericalTensorField>(mesh_);
01786         printFieldInfo<volSymmTensorField>(mesh_);
01787         printFieldInfo<volTensorField>(mesh_);
01788         printFieldInfo<surfaceScalarField>(mesh_);
01789         printFieldInfo<surfaceVectorField>(mesh_);
01790         printFieldInfo<surfaceSphericalTensorField>(mesh_);
01791         printFieldInfo<surfaceSymmTensorField>(mesh_);
01792         printFieldInfo<surfaceTensorField>(mesh_);
01793         Pout<< nl << endl;
01794     }
01795 
01796 
01797 
01798     // Receive and add what was sent
01799     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
01800 
01801     forAll(nSendCells, sendProc)
01802     {
01803         // Did processor sendProc send anything to me?
01804         if
01805         (
01806             sendProc != Pstream::myProcNo()
01807          && nSendCells[sendProc][Pstream::myProcNo()] > 0
01808         )
01809         {
01810             if (debug)
01811             {
01812                 Pout<< nl
01813                     << "RECEIVING FROM DOMAIN " << sendProc
01814                     << " cells to receive:"
01815                     << nSendCells[sendProc][Pstream::myProcNo()]
01816                     << nl << endl;
01817             }
01818 
01819             // Receive from sendProc
01820             labelList domainSourceFace;
01821             labelList domainSourceProc;
01822             labelList domainSourceNewProc;
01823 
01824             // Opposite of sendMesh
01825             autoPtr<fvMesh> domainMeshPtr = receiveMesh
01826             (
01827                 sendProc,
01828                 pointZoneNames,
01829                 faceZoneNames,
01830                 cellZoneNames,
01831 
01832                 const_cast<Time&>(mesh_.time()),
01833                 domainSourceFace,
01834                 domainSourceProc,
01835                 domainSourceNewProc
01836             );
01837             fvMesh& domainMesh = domainMeshPtr();
01838 
01839             // Receive fields
01840             PtrList<volScalarField> vsf;
01841             receiveFields<volScalarField>
01842             (
01843                 sendProc,
01844                 volScalars,
01845                 domainMesh,
01846                 vsf
01847             );
01848 
01849             PtrList<volVectorField> vvf;
01850             receiveFields<volVectorField>
01851             (
01852                 sendProc,
01853                 volVectors,
01854                 domainMesh,
01855                 vvf
01856             );
01857             PtrList<volSphericalTensorField> vsptf;
01858             receiveFields<volSphericalTensorField>
01859             (
01860                 sendProc,
01861                 volSphereTensors,
01862                 domainMesh,
01863                 vsptf
01864             );
01865             PtrList<volSymmTensorField> vsytf;
01866             receiveFields<volSymmTensorField>
01867             (
01868                 sendProc,
01869                 volSymmTensors,
01870                 domainMesh,
01871                 vsytf
01872             );
01873             PtrList<volTensorField> vtf;
01874             receiveFields<volTensorField>
01875             (
01876                 sendProc,
01877                 volTensors,
01878                 domainMesh,
01879                 vtf
01880             );
01881 
01882             PtrList<surfaceScalarField> ssf;
01883             receiveFields<surfaceScalarField>
01884             (
01885                 sendProc,
01886                 surfScalars,
01887                 domainMesh,
01888                 ssf
01889             );
01890             PtrList<surfaceVectorField> svf;
01891             receiveFields<surfaceVectorField>
01892             (
01893                 sendProc,
01894                 surfVectors,
01895                 domainMesh,
01896                 svf
01897             );
01898             PtrList<surfaceSphericalTensorField> ssptf;
01899             receiveFields<surfaceSphericalTensorField>
01900             (
01901                 sendProc,
01902                 surfSphereTensors,
01903                 domainMesh,
01904                 ssptf
01905             );
01906             PtrList<surfaceSymmTensorField> ssytf;
01907             receiveFields<surfaceSymmTensorField>
01908             (
01909                 sendProc,
01910                 surfSymmTensors,
01911                 domainMesh,
01912                 ssytf
01913             );
01914             PtrList<surfaceTensorField> stf;
01915             receiveFields<surfaceTensorField>
01916             (
01917                 sendProc,
01918                 surfTensors,
01919                 domainMesh,
01920                 stf
01921             );
01922 
01923 
01924             constructCellMap[sendProc] = identity(domainMesh.nCells());
01925             constructFaceMap[sendProc] = identity(domainMesh.nFaces());
01926             constructPointMap[sendProc] = identity(domainMesh.nPoints());
01927             constructPatchMap[sendProc] =
01928                 identity(domainMesh.boundaryMesh().size());
01929 
01930 
01931             // Print a bit.
01932             if (debug)
01933             {
01934                 Pout<< nl << "RECEIVED MESH FROM:" << sendProc << endl;
01935                 printMeshInfo(domainMesh);
01936                 printFieldInfo<volScalarField>(domainMesh);
01937                 printFieldInfo<volVectorField>(domainMesh);
01938                 printFieldInfo<volSphericalTensorField>(domainMesh);
01939                 printFieldInfo<volSymmTensorField>(domainMesh);
01940                 printFieldInfo<volTensorField>(domainMesh);
01941                 printFieldInfo<surfaceScalarField>(domainMesh);
01942                 printFieldInfo<surfaceVectorField>(domainMesh);
01943                 printFieldInfo<surfaceSphericalTensorField>(domainMesh);
01944                 printFieldInfo<surfaceSymmTensorField>(domainMesh);
01945                 printFieldInfo<surfaceTensorField>(domainMesh);
01946             }
01947 
01948 
01949             // Now this mesh we received (from sendProc) needs to be merged
01950             // with the current mesh. On the current mesh we have for all
01951             // boundaryfaces the original face and processor. See if we can
01952             // match these up to the received domainSourceFace and
01953             // domainSourceProc.
01954             labelList masterCoupledFaces;
01955             labelList slaveCoupledFaces;
01956             findCouples
01957             (
01958                 mesh_,
01959 
01960                 sourceFace,
01961                 sourceProc,
01962 
01963                 sendProc,
01964                 domainMesh,
01965                 domainSourceFace,
01966                 domainSourceProc,
01967 
01968                 masterCoupledFaces,
01969                 slaveCoupledFaces
01970             );
01971 
01972             // Generate additional coupling info (points, edges) from
01973             // faces-that-match
01974             faceCoupleInfo couples
01975             (
01976                 mesh_,
01977                 masterCoupledFaces,
01978                 domainMesh,
01979                 slaveCoupledFaces,
01980                 mergeTol_,              // merge tolerance
01981                 true,                   // faces align
01982                 true,                   // couples are ordered already
01983                 false
01984             );
01985 
01986 
01987             // Add domainMesh to mesh
01988             // ~~~~~~~~~~~~~~~~~~~~~~
01989 
01990             autoPtr<mapAddedPolyMesh> map = fvMeshAdder::add
01991             (
01992                 mesh_,
01993                 domainMesh,
01994                 couples,
01995                 false           // no parallel comms
01996             );
01997 
01998             // Update mesh data: sourceFace,sourceProc for added
01999             // mesh.
02000 
02001             sourceFace = 
02002                 mapBoundaryData
02003                 (
02004                     mesh_,
02005                     map(),
02006                     sourceFace,
02007                     domainMesh.nInternalFaces(),
02008                     domainSourceFace
02009                 );
02010             sourceProc = 
02011                 mapBoundaryData
02012                 (
02013                     mesh_,
02014                     map(),
02015                     sourceProc,
02016                     domainMesh.nInternalFaces(),
02017                     domainSourceProc
02018                 );
02019             sourceNewProc = 
02020                 mapBoundaryData
02021                 (
02022                     mesh_,
02023                     map(),
02024                     sourceNewProc,
02025                     domainMesh.nInternalFaces(),
02026                     domainSourceNewProc
02027                 );
02028 
02029             // Update all addressing so xxProcAddressing points to correct item
02030             // in masterMesh.
02031             const labelList& oldCellMap = map().oldCellMap();
02032             const labelList& oldFaceMap = map().oldFaceMap();
02033             const labelList& oldPointMap = map().oldPointMap();
02034             const labelList& oldPatchMap = map().oldPatchMap();
02035 
02036             forAll(constructPatchMap, procI)
02037             {
02038                 if (procI != sendProc && constructPatchMap[procI].size())
02039                 {
02040                     // Processor already in mesh (either myProcNo or received)
02041                     inplaceRenumber(oldCellMap, constructCellMap[procI]);
02042                     inplaceRenumber(oldFaceMap, constructFaceMap[procI]);
02043                     inplaceRenumber(oldPointMap, constructPointMap[procI]);
02044                     inplaceRenumber(oldPatchMap, constructPatchMap[procI]);
02045                 }
02046             }
02047 
02048             // Added processor
02049             inplaceRenumber(map().addedCellMap(), constructCellMap[sendProc]);
02050             inplaceRenumber(map().addedFaceMap(), constructFaceMap[sendProc]);
02051             inplaceRenumber(map().addedPointMap(), constructPointMap[sendProc]);
02052             inplaceRenumber(map().addedPatchMap(), constructPatchMap[sendProc]);
02053 
02054             if (debug)
02055             {
02056                 Pout<< nl << "MERGED MESH FROM:" << sendProc << endl;
02057                 printMeshInfo(mesh_);
02058                 printFieldInfo<volScalarField>(mesh_);
02059                 printFieldInfo<volVectorField>(mesh_);
02060                 printFieldInfo<volSphericalTensorField>(mesh_);
02061                 printFieldInfo<volSymmTensorField>(mesh_);
02062                 printFieldInfo<volTensorField>(mesh_);
02063                 printFieldInfo<surfaceScalarField>(mesh_);
02064                 printFieldInfo<surfaceVectorField>(mesh_);
02065                 printFieldInfo<surfaceSphericalTensorField>(mesh_);
02066                 printFieldInfo<surfaceSymmTensorField>(mesh_);
02067                 printFieldInfo<surfaceTensorField>(mesh_);
02068                 Pout<< nl << endl;
02069             }
02070         }
02071     }
02072 
02073 
02074     // Print a bit.
02075     if (debug)
02076     {
02077         Pout<< nl << "REDISTRIBUTED MESH:" << endl;
02078         printMeshInfo(mesh_);
02079         printFieldInfo<volScalarField>(mesh_);
02080         printFieldInfo<volVectorField>(mesh_);
02081         printFieldInfo<volSphericalTensorField>(mesh_);
02082         printFieldInfo<volSymmTensorField>(mesh_);
02083         printFieldInfo<volTensorField>(mesh_);
02084         printFieldInfo<surfaceScalarField>(mesh_);
02085         printFieldInfo<surfaceVectorField>(mesh_);
02086         printFieldInfo<surfaceSphericalTensorField>(mesh_);
02087         printFieldInfo<surfaceSymmTensorField>(mesh_);
02088         printFieldInfo<surfaceTensorField>(mesh_);
02089         Pout<< nl << endl;
02090     }
02091 
02092 
02093 
02094     // Add processorPatches
02095     // ~~~~~~~~~~~~~~~~~~~~
02096 
02097     // Per neighbour processor the patchID to it (or -1).
02098     labelList procPatchID;
02099 
02100     // Add processor patches.
02101     addProcPatches(sourceNewProc, procPatchID);
02102 
02103     // Put faces into correct patch. Note that we now have proper
02104     // processorPolyPatches again so repatching will take care of coupled face
02105     // ordering.
02106 
02107     // Get boundary faces to be repatched. Is -1 or new patchID
02108     labelList newPatchID
02109     (
02110         getProcBoundaryPatch
02111         (
02112             sourceNewProc,
02113             procPatchID
02114         )
02115     );
02116 
02117     // Change patches. Since this might change ordering of coupled faces
02118     // we also need to adapt our constructMaps.
02119     repatch(newPatchID, constructFaceMap);
02120 
02121     // See if any geometrically shared points need to be merged. Note: does
02122     // parallel comms.
02123     mergeSharedPoints(constructPointMap);
02124 
02125     // Bit of hack: processorFvPatchField does not get reset since created
02126     // from nothing so explicitly reset.
02127     initPatchFields<volScalarField>
02128     (
02129         processorFvPatchField<scalar>::typeName,
02130         pTraits<scalar>::zero
02131     );
02132     initPatchFields<volVectorField>
02133     (
02134         processorFvPatchField<vector>::typeName,
02135         pTraits<vector>::zero
02136     );
02137     initPatchFields<volSphericalTensorField>
02138     (
02139         processorFvPatchField<sphericalTensor>::typeName,
02140         pTraits<sphericalTensor>::zero
02141     );
02142     initPatchFields<volSymmTensorField>
02143     (
02144         processorFvPatchField<symmTensor>::typeName,
02145         pTraits<symmTensor>::zero
02146     );
02147     initPatchFields<volTensorField>
02148     (
02149         processorFvPatchField<tensor>::typeName,
02150         pTraits<tensor>::zero
02151     );
02152     initPatchFields<surfaceScalarField>
02153     (
02154         processorFvPatchField<scalar>::typeName,
02155         pTraits<scalar>::zero
02156     );
02157     initPatchFields<surfaceVectorField>
02158     (
02159         processorFvPatchField<vector>::typeName,
02160         pTraits<vector>::zero
02161     );
02162     initPatchFields<surfaceSphericalTensorField>
02163     (
02164         processorFvPatchField<sphericalTensor>::typeName,
02165         pTraits<sphericalTensor>::zero
02166     );
02167     initPatchFields<surfaceSymmTensorField>
02168     (
02169         processorFvPatchField<symmTensor>::typeName,
02170         pTraits<symmTensor>::zero
02171     );
02172     initPatchFields<surfaceTensorField>
02173     (
02174         processorFvPatchField<tensor>::typeName,
02175         pTraits<tensor>::zero
02176     );
02177 
02178 
02179     mesh_.setInstance(mesh_.time().timeName());
02180 
02181 
02182     // Print a bit
02183     if (debug)
02184     {
02185         Pout<< nl << "FINAL MESH:" << endl;
02186         printMeshInfo(mesh_);
02187         printFieldInfo<volScalarField>(mesh_);
02188         printFieldInfo<volVectorField>(mesh_);
02189         printFieldInfo<volSphericalTensorField>(mesh_);
02190         printFieldInfo<volSymmTensorField>(mesh_);
02191         printFieldInfo<volTensorField>(mesh_);
02192         printFieldInfo<surfaceScalarField>(mesh_);
02193         printFieldInfo<surfaceVectorField>(mesh_);
02194         printFieldInfo<surfaceSphericalTensorField>(mesh_);
02195         printFieldInfo<surfaceSymmTensorField>(mesh_);
02196         printFieldInfo<surfaceTensorField>(mesh_);
02197         Pout<< nl << endl;
02198     }
02199 
02200     // Collect all maps and return
02201     return autoPtr<mapDistributePolyMesh>
02202     (
02203         new mapDistributePolyMesh
02204         (
02205             mesh_,
02206 
02207             nOldPoints,
02208             nOldFaces,
02209             nOldCells,
02210             oldPatchStarts,
02211             oldPatchNMeshPoints,
02212 
02213             subPointMap,
02214             subFaceMap,
02215             subCellMap,
02216             subPatchMap,
02217 
02218             constructPointMap,
02219             constructFaceMap,
02220             constructCellMap,
02221             constructPatchMap,
02222             true                // reuse storage
02223         )
02224     );
02225 }
02226 
02227 
02228 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd