Formatting
[foam-extend-3.2.git] / src / fvAgglomerationMethods / MGridGenGamgAgglomeration / MGridGenGAMGAgglomeration.C
blobeb0ad207d2cce6447c89c6b9d9cb83cb3d8b5589
1 /*---------------------------------------------------------------------------*\
2   =========                 |
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 -------------------------------------------------------------------------------
8 License
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/>.
24 \*---------------------------------------------------------------------------*/
26 #include "MGridGenGAMGAgglomeration.H"
27 #include "fvMesh.H"
28 #include "addToRunTimeSelectionTable.H"
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 namespace Foam
34     defineTypeNameAndDebug(MGridGenGAMGAgglomeration, 0);
36     addToRunTimeSelectionTable
37     (
38         GAMGAgglomeration,
39         MGridGenGAMGAgglomeration,
40         lduMesh
41     );
45 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
47 Foam::MGridGenGAMGAgglomeration::MGridGenGAMGAgglomeration
49     const lduMesh& mesh,
50     const dictionary& dict
53     GAMGAgglomeration(mesh, dict),
54     fvMesh_(refCast<const fvMesh>(mesh))
56     // Min, max size of agglomerated cells
57     label minSize(readLabel(dict.lookup("minSize")));
58     label maxSize(readLabel(dict.lookup("maxSize")));
61     // Get the finest-level interfaces from the mesh
62     interfaceLevels_.set
63     (
64         0,
65         new lduInterfacePtrsList(fvMesh_.boundary().interfaces())
66     );
68     // Start geometric agglomeration from the cell volumes and areas of the mesh
69     scalarField* VPtr = const_cast<scalarField*>(&fvMesh_.cellVolumes());
70     vectorField* SfPtr = const_cast<vectorField*>(&fvMesh_.faceAreas());
72     // Create the boundary area cell field
73     scalarField* SbPtr(new scalarField(fvMesh_.nCells(), 0));
75     {
76         scalarField& Sb = *SbPtr;
78         const labelList& own = fvMesh_.faceOwner();
79         const vectorField& Sf = fvMesh_.faceAreas();
81         forAll(Sf, facei)
82         {
83             if (!fvMesh_.isInternalFace(facei))
84             {
85                 Sb[own[facei]] += mag(Sf[facei]);
86             }
87         }
88     }
91     // Agglomerate until the required number of cells in the coarsest level
92     // is reached
94     label nCreatedLevels = 0;
96     while (nCreatedLevels < maxLevels_ - 1)
97     {
98         label nCoarseCells = -1;
100         tmp<labelField> finalAgglomPtr = agglomerate
101         (
102             nCoarseCells,
103             minSize,
104             maxSize,
105             meshLevel(nCreatedLevels).lduAddr(),
106             *VPtr,
107             *SfPtr,
108             *SbPtr
109         );
111         if (continueAgglomerating(nCoarseCells))
112         {
113             nCells_[nCreatedLevels] = nCoarseCells;
114             restrictAddressing_.set(nCreatedLevels, finalAgglomPtr);
115         }
116         else
117         {
118             break;
119         }
121         agglomerateLduAddressing(nCreatedLevels);
123         // Agglomerate the cell volumes field for the next level
124         {
125             scalarField* aggVPtr
126             (
127                 new scalarField(meshLevels_[nCreatedLevels].size())
128             );
130             restrictField(*aggVPtr, *VPtr, nCreatedLevels);
132             if (nCreatedLevels)
133             {
134                 delete VPtr;
135             }
137             VPtr = aggVPtr;
138         }
140         // Agglomerate the face areas field for the next level
141         {
142             vectorField* aggSfPtr
143             (
144                 new vectorField
145                 (
146                     meshLevels_[nCreatedLevels].upperAddr().size(),
147                     vector::zero
148                 )
149             );
151             restrictFaceField(*aggSfPtr, *SfPtr, nCreatedLevels);
153             if (nCreatedLevels)
154             {
155                 delete SfPtr;
156             }
158             SfPtr = aggSfPtr;
159         }
161         // Agglomerate the cell boundary areas field for the next level
162         {
163             scalarField* aggSbPtr
164             (
165                 new scalarField(meshLevels_[nCreatedLevels].size())
166             );
168             restrictField(*aggSbPtr, *SbPtr, nCreatedLevels);
170             delete SbPtr;
171             SbPtr = aggSbPtr;
172         }
174         nCreatedLevels++;
175     }
177     // Shrink the storage of the levels to those created
178     compactLevels(nCreatedLevels);
180     // Delete temporary geometry storage
181     if (nCreatedLevels)
182     {
183         delete VPtr;
184         delete SfPtr;
185     }
186     delete SbPtr;
190 // ************************************************************************* //