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

distributeCells.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 "domainDecomposition.H"
00028 #include "decompositionMethod.H"
00029 #include "cpuTime.H"
00030 #include "cyclicPolyPatch.H"
00031 #include "cellSet.H"
00032 #include "regionSplit.H"
00033 
00034 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00035 
00036 void domainDecomposition::distributeCells()
00037 {
00038     Info<< "\nCalculating distribution of cells" << endl;
00039 
00040     cpuTime decompositionTime;
00041 
00042 
00043     // See if any faces need to have owner and neighbour on same processor
00044     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00045 
00046     labelHashSet sameProcFaces;
00047 
00048     if (decompositionDict_.found("preserveFaceZones"))
00049     {
00050         wordList zNames(decompositionDict_.lookup("preserveFaceZones"));
00051 
00052         Info<< "Keeping owner and neighbour of faces in zones " << zNames
00053             << " on same processor" << endl;
00054 
00055         const faceZoneMesh& fZones = faceZones();
00056 
00057         forAll(zNames, i)
00058         {
00059             label zoneI = fZones.findZoneID(zNames[i]);
00060 
00061             if (zoneI == -1)
00062             {
00063                 FatalErrorIn("domainDecomposition::distributeCells()")
00064                     << "Unknown preserveFaceZone " << zNames[i]
00065                     << endl << "Valid faceZones are " << fZones.names()
00066                     << exit(FatalError);
00067             }
00068 
00069             const faceZone& fz = fZones[zoneI];
00070 
00071             forAll(fz, i)
00072             {
00073                 sameProcFaces.insert(fz[i]);
00074             }
00075         }
00076     }
00077 
00078 
00079     // Construct decomposition method and either do decomposition on
00080     // cell centres or on agglomeration
00081 
00082 
00083     autoPtr<decompositionMethod> decomposePtr = decompositionMethod::New
00084     (
00085         decompositionDict_,
00086         *this
00087     );
00088 
00089     if (sameProcFaces.empty())
00090     {
00091         cellToProc_ = decomposePtr().decompose(cellCentres());
00092     }
00093     else
00094     {
00095         Info<< "Selected " << sameProcFaces.size()
00096             << " faces whose owner and neighbour cell should be kept on the"
00097             << " same processor" << endl;
00098 
00099         // Faces where owner and neighbour are not 'connected' (= all except
00100         // sameProcFaces)
00101         boolList blockedFace(nFaces(), true);
00102 
00103         forAllConstIter(labelHashSet, sameProcFaces, iter)
00104         {
00105             blockedFace[iter.key()] = false;
00106         }
00107 
00108         // Connect coupled boundary faces
00109         const polyBoundaryMesh& patches =  boundaryMesh();
00110 
00111         forAll(patches, patchI)
00112         {
00113             const polyPatch& pp = patches[patchI];
00114 
00115             if (pp.coupled())
00116             {
00117                 forAll(pp, i)
00118                 {
00119                     blockedFace[pp.start()+i] = false;
00120                 }
00121             }
00122         }
00123 
00124         // Determine global regions, separated by blockedFaces
00125         regionSplit globalRegion(*this, blockedFace);
00126 
00127 
00128         // Determine region cell centres
00129         // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00130 
00131         // This just takes the first cell in the region. Otherwise the problem
00132         // is with cyclics - if we'd average the region centre might be
00133         // somewhere in the middle of the domain which might not be anywhere
00134         // near any of the cells.
00135 
00136         const point greatPoint(GREAT, GREAT, GREAT);
00137 
00138         pointField regionCentres(globalRegion.nRegions(), greatPoint);
00139 
00140         forAll(globalRegion, cellI)
00141         {
00142             label regionI = globalRegion[cellI];
00143 
00144             if (regionCentres[regionI] == greatPoint)
00145             {
00146                 regionCentres[regionI] = cellCentres()[cellI];
00147             }
00148         }
00149 
00150         // Do decomposition on agglomeration
00151         // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00152         cellToProc_ = decomposePtr().decompose(globalRegion, regionCentres);
00153     }
00154 
00155     Info<< "\nFinished decomposition in "
00156         << decompositionTime.elapsedCpuTime()
00157         << " s" << endl;
00158 }
00159 
00160 
00161 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd