1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2010-2011 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
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
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 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
36 defineTypeNameAndDebug(structuredDecomp, 0);
38 addToRunTimeSelectionTable
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
72 const scalarField& cWeights
75 labelList patchIDs(patches_.size());
76 const polyBoundaryMesh& pbm = mesh.boundaryMesh();
81 patchIDs[i] = pbm.findPatchID(patches_[i]);
83 if (patchIDs[i] == -1)
85 FatalErrorIn("structuredDecomp::decompose(..)")
86 << "Cannot find patch " << patches_[i] << endl
87 << "Valid patches are " << pbm.names()
90 nFaces += pbm[patchIDs[i]].size();
94 labelHashSet patchCells(2*nFaces);
97 const labelUList& fc = pbm[patchIDs[i]].faceCells();
100 patchCells.insert(fc[i]);
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);
119 finalDecomp[subsetter.cellMap()[i]] = subDecomp[i];
122 // Field on cells and faces.
123 List<topoDistanceData> cellData(mesh.nCells());
124 List<topoDistanceData> faceData(mesh.nFaces());
127 labelList patchFaces(nFaces);
128 List<topoDistanceData> patchData(nFaces);
132 const polyPatch& pp = pbm[patchIDs[i]];
133 const labelUList& fc = pp.faceCells();
136 patchFaces[nFaces] = pp.start()+i;
137 patchData[nFaces] = topoDistanceData(finalDecomp[fc[i]], 0);
142 // Propagate information inwards
143 FaceCellWave<topoDistanceData> deltaCalc
150 mesh.globalData().nTotalCells()+1
154 bool haveWarned = false;
155 forAll(finalDecomp, cellI)
157 if (!cellData[cellI].valid(deltaCalc.data()))
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;
167 finalDecomp[cellI] = 0;
171 finalDecomp[cellI] = cellData[cellI].data();
179 Foam::labelList Foam::structuredDecomp::decompose
181 const labelListList& globalPointPoints,
182 const pointField& points,
183 const scalarField& pointWeights
188 "structuredDecomp::decompose\n"
190 " const labelListList&,\n"
191 " const pointField&,\n"
192 " const scalarField&\n"
196 return labelList::null();
200 // ************************************************************************* //