initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / matrices / lduMatrix / solvers / GAMG / GAMGAgglomerations / GAMGAgglomeration / GAMGAgglomeration.C
blob633b8e2f37adbe55e66975642a62db9ee80e61cd
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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 "GAMGAgglomeration.H"
28 #include "lduMesh.H"
29 #include "lduMatrix.H"
30 #include "Time.H"
31 #include "dlLibraryTable.H"
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 namespace Foam
37     defineTypeNameAndDebug(GAMGAgglomeration, 0);
38     defineRunTimeSelectionTable(GAMGAgglomeration, lduMesh);
39     defineRunTimeSelectionTable(GAMGAgglomeration, lduMatrix);
43 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
45 void Foam::GAMGAgglomeration::compactLevels(const label nCreatedLevels)
47     nCells_.setSize(nCreatedLevels);
48     restrictAddressing_.setSize(nCreatedLevels);
49     meshLevels_.setSize(nCreatedLevels);
50     interfaceLevels_.setSize(nCreatedLevels + 1);
54 bool Foam::GAMGAgglomeration::continueAgglomerating
56     const label nCoarseCells
57 ) const
59     // Check the need for further agglomeration on all processors
60     bool contAgg = nCoarseCells >= nCellsInCoarsestLevel_;
61     reduce(contAgg, andOp<bool>());
62     return contAgg;
66 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
68 Foam::GAMGAgglomeration::GAMGAgglomeration
70     const lduMesh& mesh,
71     const dictionary& controlDict
74     MeshObject<lduMesh, GAMGAgglomeration>(mesh),
76     maxLevels_(50),
78     nCellsInCoarsestLevel_
79     (
80         readLabel(controlDict.lookup("nCellsInCoarsestLevel"))
81     ),
83     nCells_(maxLevels_),
84     restrictAddressing_(maxLevels_),
85     faceRestrictAddressing_(maxLevels_),
87     meshLevels_(maxLevels_),
88     interfaceLevels_(maxLevels_ + 1)
92 const Foam::GAMGAgglomeration& Foam::GAMGAgglomeration::New
94     const lduMesh& mesh,
95     const dictionary& controlDict
98     if
99     (
100         !mesh.thisDb().foundObject<GAMGAgglomeration>
101         (
102             GAMGAgglomeration::typeName
103         )
104     )
105     {
106         word agglomeratorType(controlDict.lookup("agglomerator"));
108         dlLibraryTable::open
109         (
110             controlDict,
111             "geometricGAMGAgglomerationLibs",
112             lduMeshConstructorTablePtr_
113         );
115         lduMeshConstructorTable::iterator cstrIter =
116             lduMeshConstructorTablePtr_->find(agglomeratorType);
118         if (cstrIter == lduMeshConstructorTablePtr_->end())
119         {
120             FatalErrorIn
121             (
122                 "GAMGAgglomeration::New"
123                 "(const lduMesh& mesh, const dictionary& controlDict)"
124             )   << "Unknown GAMGAgglomeration type "
125                 << agglomeratorType << ".\n"
126                 << "Valid algebraic GAMGAgglomeration types are :"
127                 << lduMatrixConstructorTablePtr_->toc() << endl
128                 << "Valid algebraic GAMGAgglomeration types are :"
129                 << lduMeshConstructorTablePtr_->toc()
130                 << exit(FatalError);
131         }
133         return store(cstrIter()(mesh, controlDict).ptr());
134     }
135     else
136     {
137         return mesh.thisDb().lookupObject<GAMGAgglomeration>
138         (
139             GAMGAgglomeration::typeName
140         );
141     }
145 const Foam::GAMGAgglomeration& Foam::GAMGAgglomeration::New
147     const lduMatrix& matrix,
148     const dictionary& controlDict
151     const lduMesh& mesh = matrix.mesh();
153     if
154     (
155         !mesh.thisDb().foundObject<GAMGAgglomeration>
156         (
157             GAMGAgglomeration::typeName
158         )
159     )
160     {
161         word agglomeratorType(controlDict.lookup("agglomerator"));
163         dlLibraryTable::open
164         (
165             controlDict,
166             "algebraicGAMGAgglomerationLibs",
167             lduMatrixConstructorTablePtr_
168         );
170         if
171         (
172             !lduMatrixConstructorTablePtr_
173          || !lduMatrixConstructorTablePtr_->found(agglomeratorType)
174         )
175         {
176             return New(mesh, controlDict);
177         }
178         else
179         {
180             lduMatrixConstructorTable::iterator cstrIter =
181                 lduMatrixConstructorTablePtr_->find(agglomeratorType);
183             return store(cstrIter()(matrix, controlDict).ptr());
184         }
185     }
186     else
187     {
188         return mesh.thisDb().lookupObject<GAMGAgglomeration>
189         (
190             GAMGAgglomeration::typeName
191         );
192     }
196 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
198 Foam::GAMGAgglomeration::~GAMGAgglomeration()
200     // Clear the interface storage by hand.
201     // It is a list of ptrs not a PtrList for consistency of the interface
202     for (label leveli=1; leveli<interfaceLevels_.size(); leveli++)
203     {
204         lduInterfacePtrsList& curLevel = interfaceLevels_[leveli];
206         forAll (curLevel, i)
207         {
208             if (curLevel.set(i))
209             {
210                 delete curLevel(i);
211             }
212         }
213     }
217 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
219 const Foam::lduMesh& Foam::GAMGAgglomeration::meshLevel
221     const label i
222 ) const
224     if (i == 0)
225     {
226         return mesh_;
227     }
228     else
229     {
230         return meshLevels_[i - 1];
231     }
235 const Foam::lduInterfacePtrsList& Foam::GAMGAgglomeration::interfaceLevel
237     const label i
238 ) const
240     return interfaceLevels_[i];
244 // ************************************************************************* //