Initial commit for version 2.0.x patch release
[OpenFOAM-2.0.x.git] / src / parallel / decompose / decompositionMethods / structuredDecomp / structuredDecomp.C
blobb43876a2a023c2b76425559ae034974b7c2744c6
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2010-2011 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software: you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by
13     the Free Software Foundation, either version 3 of the License, or
14     (at your option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "structuredDecomp.H"
27 #include "addToRunTimeSelectionTable.H"
28 #include "FaceCellWave.H"
29 #include "topoDistanceData.H"
30 #include "fvMeshSubset.H"
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34 namespace Foam
36     defineTypeNameAndDebug(structuredDecomp, 0);
38     addToRunTimeSelectionTable
39     (
40         decompositionMethod,
41         structuredDecomp,
42         dictionary
43     );
47 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
49 Foam::structuredDecomp::structuredDecomp(const dictionary& decompositionDict)
51     decompositionMethod(decompositionDict),
52     methodDict_(decompositionDict_.subDict(typeName + "Coeffs"))
54     methodDict_.set("numberOfSubdomains", nDomains());
55     method_ = decompositionMethod::New(methodDict_);
56     patches_ = wordList(methodDict_.lookup("patches"));
60 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
62 bool Foam::structuredDecomp::parallelAware() const
64     return method_().parallelAware();
68 Foam::labelList Foam::structuredDecomp::decompose
70     const polyMesh& mesh,
71     const pointField& cc,
72     const scalarField& cWeights
75     labelList patchIDs(patches_.size());
76     const polyBoundaryMesh& pbm = mesh.boundaryMesh();
78     label nFaces = 0;
79     forAll(patches_, i)
80     {
81         patchIDs[i] = pbm.findPatchID(patches_[i]);
83         if (patchIDs[i] == -1)
84         {
85             FatalErrorIn("structuredDecomp::decompose(..)")
86                 << "Cannot find patch " << patches_[i] << endl
87                 << "Valid patches are " << pbm.names()
88                 << exit(FatalError);
89         }
90         nFaces += pbm[patchIDs[i]].size();
91     }
93     // Extract a submesh.
94     labelHashSet patchCells(2*nFaces);
95     forAll(patchIDs, i)
96     {
97         const labelUList& fc = pbm[patchIDs[i]].faceCells();
98         forAll(fc, i)
99         {
100             patchCells.insert(fc[i]);
101         }
102     }
104     // Subset the layer of cells next to the patch
105     fvMeshSubset subsetter(dynamic_cast<const fvMesh&>(mesh));
106     subsetter.setLargeCellSubset(patchCells);
107     const fvMesh& subMesh = subsetter.subMesh();
108     pointField subCc(cc, subsetter.cellMap());
109     scalarField subWeights(cWeights, subsetter.cellMap());
111     // Decompose the layer of cells
112     labelList subDecomp(method_().decompose(subMesh, subCc, subWeights));
115     // Transfer to final decomposition
116     labelList finalDecomp(cc.size(), -1);
117     forAll(subDecomp, i)
118     {
119         finalDecomp[subsetter.cellMap()[i]] = subDecomp[i];
120     }
122     // Field on cells and faces.
123     List<topoDistanceData> cellData(mesh.nCells());
124     List<topoDistanceData> faceData(mesh.nFaces());
126     // Start of changes
127     labelList patchFaces(nFaces);
128     List<topoDistanceData> patchData(nFaces);
129     nFaces = 0;
130     forAll(patchIDs, i)
131     {
132         const polyPatch& pp = pbm[patchIDs[i]];
133         const labelUList& fc = pp.faceCells();
134         forAll(fc, i)
135         {
136             patchFaces[nFaces] = pp.start()+i;
137             patchData[nFaces] = topoDistanceData(finalDecomp[fc[i]], 0);
138             nFaces++;
139         }
140     }
142     // Propagate information inwards
143     FaceCellWave<topoDistanceData> deltaCalc
144     (
145         mesh,
146         patchFaces,
147         patchData,
148         faceData,
149         cellData,
150         mesh.globalData().nTotalCells()+1
151     );
153     // And extract
154     bool haveWarned = false;
155     forAll(finalDecomp, cellI)
156     {
157         if (!cellData[cellI].valid(deltaCalc.data()))
158         {
159             if (!haveWarned)
160             {
161                 WarningIn("structuredDecomp::decompose(..)")
162                     << "Did not visit some cells, e.g. cell " << cellI
163                     << " at " << mesh.cellCentres()[cellI] << endl
164                     << "Assigning  these cells to domain 0." << endl;
165                 haveWarned = true;
166             }
167             finalDecomp[cellI] = 0;
168         }
169         else
170         {
171             finalDecomp[cellI] = cellData[cellI].data();
172         }
173     }
175     return finalDecomp;
179 Foam::labelList Foam::structuredDecomp::decompose
181     const labelListList& globalPointPoints,
182     const pointField& points,
183     const scalarField& pointWeights
186     notImplemented
187     (
188         "structuredDecomp::decompose\n"
189         "(\n"
190         "    const labelListList&,\n"
191         "    const pointField&,\n"
192         "    const scalarField&\n"
193         ")\n"
194     );
196     return labelList::null();
200 // ************************************************************************* //