initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / decompositionMethods / decompositionMethods / decompositionMethod / decompositionMethod.C
blobb526f391ef3d595e93679097f98173a1cdff023a
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 InClass
26     decompositionMethod
28 Description
30 \*---------------------------------------------------------------------------*/
32 #include "decompositionMethod.H"
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 namespace Foam
38     defineTypeNameAndDebug(decompositionMethod, 0);
39     defineRunTimeSelectionTable(decompositionMethod, dictionary);
40     defineRunTimeSelectionTable(decompositionMethod, dictionaryMesh);
43 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
45 Foam::autoPtr<Foam::decompositionMethod> Foam::decompositionMethod::New
47     const dictionary& decompositionDict
50     word decompositionMethodTypeName(decompositionDict.lookup("method"));
52     Info<< "Selecting decompositionMethod "
53         << decompositionMethodTypeName << endl;
55     dictionaryConstructorTable::iterator cstrIter =
56         dictionaryConstructorTablePtr_->find(decompositionMethodTypeName);
58     if (cstrIter == dictionaryConstructorTablePtr_->end())
59     {
60         FatalErrorIn
61         (
62             "decompositionMethod::New"
63             "(const dictionary& decompositionDict)"
64         )   << "Unknown decompositionMethod "
65             << decompositionMethodTypeName << endl << endl
66             << "Valid decompositionMethods are : " << endl
67             << dictionaryConstructorTablePtr_->toc()
68             << exit(FatalError);
69     }
71     return autoPtr<decompositionMethod>(cstrIter()(decompositionDict));
75 Foam::autoPtr<Foam::decompositionMethod> Foam::decompositionMethod::New
77     const dictionary& decompositionDict,
78     const polyMesh& mesh
81     word decompositionMethodTypeName(decompositionDict.lookup("method"));
83     Info<< "Selecting decompositionMethod "
84         << decompositionMethodTypeName << endl;
86     dictionaryMeshConstructorTable::iterator cstrIter =
87         dictionaryMeshConstructorTablePtr_->find(decompositionMethodTypeName);
89     if (cstrIter == dictionaryMeshConstructorTablePtr_->end())
90     {
91         FatalErrorIn
92         (
93             "decompositionMethod::New"
94             "(const dictionary& decompositionDict, "
95             "const polyMesh& mesh)"
96         )   << "Unknown decompositionMethod "
97             << decompositionMethodTypeName << endl << endl
98             << "Valid decompositionMethods are : " << endl
99             << dictionaryMeshConstructorTablePtr_->toc()
100             << exit(FatalError);
101     }
103     return autoPtr<decompositionMethod>(cstrIter()(decompositionDict, mesh));
107 Foam::labelList Foam::decompositionMethod::decompose
109     const labelList& fineToCoarse,
110     const pointField& coarsePoints
113     // Decompose based on agglomerated points
114     labelList coarseDistribution(decompose(coarsePoints));
116     // Rework back into decomposition for original mesh_
117     labelList fineDistribution(fineToCoarse.size());
119     forAll(fineDistribution, i)
120     {
121         fineDistribution[i] = coarseDistribution[fineToCoarse[i]];
122     }
124     return fineDistribution;
128 void Foam::decompositionMethod::calcCellCells
130     const polyMesh& mesh,
131     const labelList& fineToCoarse,
132     const label nCoarse,
133     labelListList& cellCells
136     if (fineToCoarse.size() != mesh.nCells())
137     {
138         FatalErrorIn
139         (
140             "decompositionMethod::calcCellCells"
141             "(const labelList&, labelListList&) const"
142         )   << "Only valid for mesh agglomeration." << exit(FatalError);
143     }
145     List<DynamicList<label> > dynCellCells(nCoarse);
147     forAll(mesh.faceNeighbour(), faceI)
148     {
149         label own = fineToCoarse[mesh.faceOwner()[faceI]];
150         label nei = fineToCoarse[mesh.faceNeighbour()[faceI]];
152         if (own != nei)
153         {
154             if (findIndex(dynCellCells[own], nei) == -1)
155             {
156                 dynCellCells[own].append(nei);
157             }
158             if (findIndex(dynCellCells[nei], own) == -1)
159             {
160                 dynCellCells[nei].append(own);
161             }
162         }
163     }
165     cellCells.setSize(dynCellCells.size());
166     forAll(dynCellCells, coarseI)
167     {
168         cellCells[coarseI].transfer(dynCellCells[coarseI]);
169     }
173 // ************************************************************************* //