1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation, either version 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
25 Agglomerate one level using the MGridGen algorithm.
27 \*---------------------------------------------------------------------------*/
29 #include "MGridGenGAMGAgglomeration.H"
31 #include "syncTools.H"
35 # include "mgridgen.h"
44 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
46 void Foam::MGridGenGAMGAgglomeration::
47 makeCompactCellFaceAddressingAndFaceWeights
49 const lduAddressing& fineAddressing,
51 labelList& cellCellOffsets,
52 const vectorField& Si,
53 List<scalar>& faceWeights
56 const label nFineCells = fineAddressing.size();
57 const label nFineFaces = fineAddressing.upperAddr().size();
59 const unallocLabelList& upperAddr = fineAddressing.upperAddr();
60 const unallocLabelList& lowerAddr = fineAddressing.lowerAddr();
62 // Number of neighbours for each cell
63 labelList nNbrs(nFineCells, 0);
65 forAll (upperAddr, facei)
67 nNbrs[upperAddr[facei]]++;
70 forAll (lowerAddr, facei)
72 nNbrs[lowerAddr[facei]]++;
75 // Set the sizes of the addressing and faceWeights arrays
76 cellCellOffsets.setSize(nFineCells + 1);
77 cellCells.setSize(2*nFineFaces);
78 faceWeights.setSize(2*nFineFaces);
81 cellCellOffsets[0] = 0;
84 cellCellOffsets[celli+1] = cellCellOffsets[celli] + nNbrs[celli];
87 // reset the whole list to use as counter
90 forAll (upperAddr, facei)
92 label own = upperAddr[facei];
93 label nei = lowerAddr[facei];
95 label l1 = cellCellOffsets[own] + nNbrs[own]++;
96 label l2 = cellCellOffsets[nei] + nNbrs[nei]++;
101 faceWeights[l1] = mag(Si[facei]);
102 faceWeights[l2] = mag(Si[facei]);
107 Foam::tmp<Foam::labelField> Foam::MGridGenGAMGAgglomeration::agglomerate
112 const lduAddressing& fineAddressing,
113 const scalarField& V,
114 const vectorField& Sf,
115 const scalarField& Sb
118 const label nFineCells = fineAddressing.size();
120 // Compact addressing for cellCells
122 labelList cellCellOffsets;
124 // Face weights = face areas of the internal faces
125 List<scalar> faceWeights;
127 // Create the compact addressing for cellCells and faceWeights
128 makeCompactCellFaceAddressingAndFaceWeights
137 // MGridGen agglomeration options.
138 labelList options(4, 0);
139 options[0] = 4; // globular agglom
140 options[1] = 6; // objective F3 and F2
141 options[2] = 128; // debugging output level
142 options[3] = fvMesh_.nGeometricD(); // Dimensionality of the grid
145 // output: cell -> processor addressing
146 List<int> finalAgglom(nFineCells);
154 cellCellOffsets.begin(),
155 const_cast<scalar*>(V.begin()),
156 const_cast<scalar*>(Sb.begin()),
169 // Conversion of type for MGridGen interface
171 Field<realtype> dblVols(V.size());
177 Field<realtype> dblAreas(Sb.size());
183 Field<realtype> dblFaceWeights(faceWeights.size());
184 forAll (dblFaceWeights, i)
186 dblFaceWeights[i] = faceWeights[i];
192 cellCellOffsets.begin(),
196 dblFaceWeights.begin(),
207 return tmp<labelField>(new labelField(finalAgglom));
211 // ************************************************************************* //