1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2010 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/>.
25 Agglomerate one level using the MGridGen algorithm.
27 \*---------------------------------------------------------------------------*/
29 #include "MGridGenGAMGAgglomeration.H"
30 #include <finiteVolume/fvMesh.H>
31 #include <OpenFOAM/syncTools.H>
35 //# include <mgridgen.h>
38 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
40 void Foam::MGridGenGAMGAgglomeration::
41 makeCompactCellFaceAddressingAndFaceWeights
43 const lduAddressing& fineAddressing,
44 List<idxtype>& cellCells,
45 List<idxtype>& cellCellOffsets,
46 const vectorField& Si,
47 List<scalar>& faceWeights
50 const label nFineCells = fineAddressing.size();
51 const label nFineFaces = fineAddressing.upperAddr().size();
53 const unallocLabelList& upperAddr = fineAddressing.upperAddr();
54 const unallocLabelList& lowerAddr = fineAddressing.lowerAddr();
56 // Number of neighbours for each cell
57 labelList nNbrs(nFineCells, 0);
59 forAll (upperAddr, facei)
61 nNbrs[upperAddr[facei]]++;
64 forAll (lowerAddr, facei)
66 nNbrs[lowerAddr[facei]]++;
69 // Set the sizes of the addressing and faceWeights arrays
70 cellCellOffsets.setSize(nFineCells + 1);
71 cellCells.setSize(2*nFineFaces);
72 faceWeights.setSize(2*nFineFaces);
75 cellCellOffsets[0] = 0;
78 cellCellOffsets[celli+1] = cellCellOffsets[celli] + nNbrs[celli];
81 // reset the whole list to use as counter
84 forAll (upperAddr, facei)
86 label own = upperAddr[facei];
87 label nei = lowerAddr[facei];
89 label l1 = cellCellOffsets[own] + nNbrs[own]++;
90 label l2 = cellCellOffsets[nei] + nNbrs[nei]++;
95 faceWeights[l1] = mag(Si[facei]);
96 faceWeights[l2] = mag(Si[facei]);
101 Foam::tmp<Foam::labelField> Foam::MGridGenGAMGAgglomeration::agglomerate
106 const lduAddressing& fineAddressing,
107 const scalarField& V,
108 const vectorField& Sf,
109 const scalarField& Sb
112 const label nFineCells = fineAddressing.size();
114 // Compact addressing for cellCells
115 List<idxtype> cellCells;
116 List<idxtype> cellCellOffsets;
118 // Face weights = face areas of the internal faces
119 List<scalar> faceWeights;
121 // Create the compact addressing for cellCells and faceWeights
122 makeCompactCellFaceAddressingAndFaceWeights
131 // agglomeration options.
132 List<int> options(4, 0);
133 options[0] = 4; // globular agglom
134 options[1] = 6; // objective F3 and F2
135 options[2] = 128; // debugging output level
136 options[3] = fvMesh_.nGeometricD(); // Dimensionality of the grid
139 // output: cell -> processor addressing
140 List<int> finalAgglom(nFineCells);
146 cellCellOffsets.begin(),
147 const_cast<scalar*>(V.begin()),
148 const_cast<scalar*>(Sb.begin()),
159 return tmp<labelField>(new labelField(finalAgglom));
163 // ************************ vim: set sw=4 sts=4 et: ************************ //