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
30 \*---------------------------------------------------------------------------*/
32 #include "decompositionMethod.H"
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
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())
62 "decompositionMethod::New"
63 "(const dictionary& decompositionDict)"
64 ) << "Unknown decompositionMethod "
65 << decompositionMethodTypeName << endl << endl
66 << "Valid decompositionMethods are : " << endl
67 << dictionaryConstructorTablePtr_->toc()
71 return autoPtr<decompositionMethod>(cstrIter()(decompositionDict));
75 Foam::autoPtr<Foam::decompositionMethod> Foam::decompositionMethod::New
77 const dictionary& decompositionDict,
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())
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()
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)
121 fineDistribution[i] = coarseDistribution[fineToCoarse[i]];
124 return fineDistribution;
128 void Foam::decompositionMethod::calcCellCells
130 const polyMesh& mesh,
131 const labelList& fineToCoarse,
133 labelListList& cellCells
136 if (fineToCoarse.size() != mesh.nCells())
140 "decompositionMethod::calcCellCells"
141 "(const labelList&, labelListList&) const"
142 ) << "Only valid for mesh agglomeration." << exit(FatalError);
145 List<DynamicList<label> > dynCellCells(nCoarse);
147 forAll(mesh.faceNeighbour(), faceI)
149 label own = fineToCoarse[mesh.faceOwner()[faceI]];
150 label nei = fineToCoarse[mesh.faceNeighbour()[faceI]];
154 if (findIndex(dynCellCells[own], nei) == -1)
156 dynCellCells[own].append(nei);
158 if (findIndex(dynCellCells[nei], own) == -1)
160 dynCellCells[nei].append(own);
165 cellCells.setSize(dynCellCells.size());
166 forAll(dynCellCells, coarseI)
168 cellCells[coarseI].transfer(dynCellCells[coarseI]);
173 // ************************************************************************* //