FreeFOAM The Cross-Platform CFD Toolkit
decompositionMethod.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
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.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 InClass
25  decompositionMethod
26 
27 \*---------------------------------------------------------------------------*/
28 
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35  defineTypeNameAndDebug(decompositionMethod, 0);
36  defineRunTimeSelectionTable(decompositionMethod, dictionary);
37  defineRunTimeSelectionTable(decompositionMethod, dictionaryMesh);
38 }
39 
40 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
41 
43 (
44  const dictionary& decompositionDict
45 )
46 {
47  word decompositionMethodTypeName(decompositionDict.lookup("method"));
48 
49  Info<< "Selecting decompositionMethod "
50  << decompositionMethodTypeName << endl;
51 
52  dictionaryConstructorTable::iterator cstrIter =
53  dictionaryConstructorTablePtr_->find(decompositionMethodTypeName);
54 
55  if (cstrIter == dictionaryConstructorTablePtr_->end())
56  {
58  (
59  "decompositionMethod::New"
60  "(const dictionary& decompositionDict)"
61  ) << "Unknown decompositionMethod "
62  << decompositionMethodTypeName << endl << endl
63  << "Valid decompositionMethods are : " << endl
64  << dictionaryConstructorTablePtr_->toc()
65  << exit(FatalError);
66  }
67 
68  return autoPtr<decompositionMethod>(cstrIter()(decompositionDict));
69 }
70 
71 
73 (
74  const dictionary& decompositionDict,
75  const polyMesh& mesh
76 )
77 {
78  word decompositionMethodTypeName(decompositionDict.lookup("method"));
79 
80  Info<< "Selecting decompositionMethod "
81  << decompositionMethodTypeName << endl;
82 
83  dictionaryMeshConstructorTable::iterator cstrIter =
84  dictionaryMeshConstructorTablePtr_->find(decompositionMethodTypeName);
85 
86  if (cstrIter == dictionaryMeshConstructorTablePtr_->end())
87  {
89  (
90  "decompositionMethod::New"
91  "(const dictionary& decompositionDict, "
92  "const polyMesh& mesh)"
93  ) << "Unknown decompositionMethod "
94  << decompositionMethodTypeName << endl << endl
95  << "Valid decompositionMethods are : " << endl
96  << dictionaryMeshConstructorTablePtr_->toc()
97  << exit(FatalError);
98  }
99 
100  return autoPtr<decompositionMethod>(cstrIter()(decompositionDict, mesh));
101 }
102 
103 
105 (
106  const pointField& points
107 )
108 {
109  scalarField weights(0);
110 
111  return decompose(points, weights);
112 }
113 
114 
116 (
117  const labelList& fineToCoarse,
118  const pointField& coarsePoints,
119  const scalarField& coarseWeights
120 )
121 {
122  // Decompose based on agglomerated points
123  labelList coarseDistribution(decompose(coarsePoints, coarseWeights));
124 
125  // Rework back into decomposition for original mesh_
126  labelList fineDistribution(fineToCoarse.size());
127 
128  forAll(fineDistribution, i)
129  {
130  fineDistribution[i] = coarseDistribution[fineToCoarse[i]];
131  }
132 
133  return fineDistribution;
134 }
135 
136 
138 (
139  const labelList& fineToCoarse,
140  const pointField& coarsePoints
141 )
142 {
143  // Decompose based on agglomerated points
144  labelList coarseDistribution(decompose(coarsePoints));
145 
146  // Rework back into decomposition for original mesh_
147  labelList fineDistribution(fineToCoarse.size());
148 
149  forAll(fineDistribution, i)
150  {
151  fineDistribution[i] = coarseDistribution[fineToCoarse[i]];
152  }
153 
154  return fineDistribution;
155 }
156 
157 
159 (
160  const polyMesh& mesh,
161  const labelList& fineToCoarse,
162  const label nCoarse,
163  labelListList& cellCells
164 )
165 {
166  if (fineToCoarse.size() != mesh.nCells())
167  {
169  (
170  "decompositionMethod::calcCellCells"
171  "(const labelList&, labelListList&) const"
172  ) << "Only valid for mesh agglomeration." << exit(FatalError);
173  }
174 
175  List<DynamicList<label> > dynCellCells(nCoarse);
176 
177  forAll(mesh.faceNeighbour(), faceI)
178  {
179  label own = fineToCoarse[mesh.faceOwner()[faceI]];
180  label nei = fineToCoarse[mesh.faceNeighbour()[faceI]];
181 
182  if (own != nei)
183  {
184  if (findIndex(dynCellCells[own], nei) == -1)
185  {
186  dynCellCells[own].append(nei);
187  }
188  if (findIndex(dynCellCells[nei], own) == -1)
189  {
190  dynCellCells[nei].append(own);
191  }
192  }
193  }
194 
195  cellCells.setSize(dynCellCells.size());
196  forAll(dynCellCells, coarseI)
197  {
198  cellCells[coarseI].transfer(dynCellCells[coarseI]);
199  }
200 }
201 
202 
204 (
205  const labelListList& globalCellCells,
206  const pointField& cc
207 )
208 {
209  scalarField cWeights(0);
210 
211  return decompose(globalCellCells, cc, cWeights);
212 }
213 
214 
215 // ************************ vim: set sw=4 sts=4 et: ************************ //