1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 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, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "MGridGenGAMGAgglomeration.H"
29 #include "addToRunTimeSelectionTable.H"
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 defineTypeNameAndDebug(MGridGenGAMGAgglomeration, 0);
37 addToRunTimeSelectionTable
40 MGridGenGAMGAgglomeration,
46 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
48 Foam::MGridGenGAMGAgglomeration::MGridGenGAMGAgglomeration
51 const dictionary& controlDict
54 GAMGAgglomeration(mesh, controlDict),
55 fvMesh_(refCast<const fvMesh>(mesh))
57 // Min, max size of agglomerated cells
58 label minSize(readLabel(controlDict.lookup("minSize")));
59 label maxSize(readLabel(controlDict.lookup("maxSize")));
62 // Get the finest-level interfaces from the mesh
66 new lduInterfacePtrsList(fvMesh_.boundary().interfaces())
69 // Start geometric agglomeration from the cell volumes and areas of the mesh
70 scalarField* VPtr = const_cast<scalarField*>(&fvMesh_.cellVolumes());
71 vectorField* SfPtr = const_cast<vectorField*>(&fvMesh_.faceAreas());
73 // Create the boundary area cell field
74 scalarField* SbPtr(new scalarField(fvMesh_.nCells(), 0));
77 scalarField& Sb = *SbPtr;
79 const labelList& own = fvMesh_.faceOwner();
80 const vectorField& Sf = fvMesh_.faceAreas();
84 if (!fvMesh_.isInternalFace(facei))
86 Sb[own[facei]] += mag(Sf[facei]);
92 // Agglomerate until the required number of cells in the coarsest level
95 label nCreatedLevels = 0;
97 while (nCreatedLevels < maxLevels_ - 1)
99 label nCoarseCells = -1;
101 tmp<labelField> finalAgglomPtr = agglomerate
106 meshLevel(nCreatedLevels).lduAddr(),
112 if (continueAgglomerating(nCoarseCells))
114 nCells_[nCreatedLevels] = nCoarseCells;
115 restrictAddressing_.set(nCreatedLevels, finalAgglomPtr);
122 agglomerateLduAddressing(nCreatedLevels);
124 // Agglomerate the cell volumes field for the next level
128 new scalarField(meshLevels_[nCreatedLevels].size())
131 restrictField(*aggVPtr, *VPtr, nCreatedLevels);
141 // Agglomerate the face areas field for the next level
143 vectorField* aggSfPtr
147 meshLevels_[nCreatedLevels].upperAddr().size(),
152 restrictFaceField(*aggSfPtr, *SfPtr, nCreatedLevels);
162 // Agglomerate the cell boundary areas field for the next level
164 scalarField* aggSbPtr
166 new scalarField(meshLevels_[nCreatedLevels].size())
169 restrictField(*aggSbPtr, *SbPtr, nCreatedLevels);
178 // Shrink the storage of the levels to those created
179 compactLevels(nCreatedLevels);
181 // Delete temporary geometry storage
191 // ************************************************************************* //