algebraicPairGAMGAgglomeration.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2016,2023 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
30 #include "lduMatrix.H"
32 //#include "cyclicAMILduInterface.H"
33 //#include "cyclicACMILduInterface.H"
34 
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 
37 namespace Foam
38 {
39  defineTypeNameAndDebug(algebraicPairGAMGAgglomeration, 0);
40 
42  (
43  GAMGAgglomeration,
44  algebraicPairGAMGAgglomeration,
45  lduMatrix
46  );
47 }
48 
49 
50 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
51 
53 (
54  const lduMatrix& matrix,
55  const dictionary& controlDict
56 )
57 :
59 {
60  if (matrix.hasLower())
61  {
63  (
65  0,
66  max(mag(matrix.upper()), mag(matrix.lower())),
67  true
68  );
69  }
70  else
71  {
73  }
74 }
75 
76 
77 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
78 
80 {
81  const bool ok = pairGAMGAgglomeration::movePoints();
82 
83  if (!requireUpdate_)
84  {
85  // TBD. For now commented out since cyclicAMI not known in this library.
86 
87 /*
88  // movePoints lower down did not trigger update. Update in case of
89  // cyclicAMI since contains addressing across patches and patches
90  // have moved.
91 
92  bool hasCyclicAMI = false;
93  if (!processorAgglomerate())
94  {
95  const auto& fineInterfaces = interfaceLevel(0);
96  forAll(fineInterfaces, inti)
97  {
98  if (fineInterfaces.set(inti))
99  {
100  const auto& intf = fineInterfaces[inti];
101  if
102  (
103  isA<cyclicAMILduInterface>(intf)
104  || isA<cyclicACMILduInterface>(intf)
105  )
106  {
107  hasCyclicAMI = true;
108 
109  DebugPoutInFunction
110  << "Detected cyclicA(C)MI at interface " << inti
111  << ".Redoing patch agglomeration" << endl;
112 
113  break;
114  }
115  }
116  }
117  }
118 
119 
120  if (hasCyclicAMI)
121  {
122  // Redo the interface agglomeration
123  for
124  (
125  label fineLevelIndex = 0;
126  fineLevelIndex < size();
127  fineLevelIndex++
128  )
129  {
130  // Near complete copy of boundary handling in
131  // GAMGAgglomeration::agglomerateLduAddressing
132 
133  const auto& fineMesh = meshLevel(fineLevelIndex);
134  const auto& fineInterfaces = interfaceLevel(fineLevelIndex);
135  const lduAddressing& fineMeshAddr = fineMesh.lduAddr();
136 
137  // Get restriction map for current level
138  const labelField& restrictMap =
139  restrictAddressing(fineLevelIndex);
140 
141  const label startOfRequests = UPstream::nRequests();
142  forAll(fineInterfaces, inti)
143  {
144  if (fineInterfaces.set(inti))
145  {
146  const auto& intf = fineInterfaces[inti];
147 
148  if
149  (
150  isA<cyclicAMILduInterface>(intf)
151  || isA<cyclicACMILduInterface>(intf)
152  )
153  {
154  if (fineLevelIndex == 0)
155  {
156  intf.initInternalFieldTransfer
157  (
158  Pstream::commsTypes::nonBlocking,
159  restrictMap,
160  fineMeshAddr.patchAddr(inti)
161  );
162  }
163  else
164  {
165  intf.initInternalFieldTransfer
166  (
167  Pstream::commsTypes::nonBlocking,
168  restrictMap
169  );
170  }
171  }
172  }
173  }
174 
175  // Wait for comms to finised
176  UPstream::waitRequests(startOfRequests);
177 
178  // New coarse-level interfaces
179  //lduInterfacePtrsList coarseInterfaces(fineInterfaces.size());
180 
181  forAll(fineInterfaces, inti)
182  {
183  if (fineInterfaces.set(inti))
184  {
185  const auto& intf = fineInterfaces[inti];
186 
187  if
188  (
189  isA<cyclicAMILduInterface>(intf)
190  || isA<cyclicACMILduInterface>(intf)
191  )
192  {
193  tmp<labelField> restrictMapInternalField;
194 
195  // The finest mesh uses patchAddr from the
196  // original lduAdressing.
197  // the coarser levels create thei own adressing for
198  // faceCells
199  if (fineLevelIndex == 0)
200  {
201  restrictMapInternalField =
202  intf.interfaceInternalField
203  (
204  restrictMap,
205  fineMeshAddr.patchAddr(inti)
206  );
207  }
208  else
209  {
210  restrictMapInternalField =
211  intf.interfaceInternalField
212  (
213  restrictMap
214  );
215  }
216 
217  tmp<labelField> nbrRestrictMapInternalField =
218  intf.internalFieldTransfer
219  (
220  Pstream::commsTypes::nonBlocking,
221  restrictMap
222  );
223 
224  lduPrimitiveMesh& coarseMesh =
225  meshLevels_[fineLevelIndex];
226 
227  autoPtr<GAMGInterface> coarseIntf
228  (
229  GAMGInterface::New
230  (
231  inti,
232  coarseMesh.rawInterfaces(),
233  intf,
234  restrictMapInternalField(),
235  nbrRestrictMapInternalField(),
236  fineLevelIndex,
237  fineMesh.comm()
238  )
239  );
240 
241  //coarseInterfaces.set(inti, coarseIntf.ptr());
242  coarseMesh.interfaces().set
243  (
244  inti,
245  coarseIntf.ptr()
246  );
247  coarseMesh.primitiveInterfaces().set
248  (
249  inti,
250  &coarseMesh.interfaces()[inti]
251  );
252  }
253  }
254  }
255 
256  //meshLevels_[fineLevelIndex].addInterfaces
257  //(
258  // coarseInterfaces,
259  // lduPrimitiveMesh::nonBlockingSchedule
260  // <
261  // processorGAMGInterface
262  // >
263  // (
264  // coarseInterfaces
265  // )
266  //);
267  }
268  }
269 
270  if (debug)
271  {
272  printLevels();
273  }
274 */
275  }
276 
277  return ok;
278 }
279 
280 
281 // ************************************************************************* //
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
Agglomerate using the pair algorithm.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:40
Macros for easy insertion into run-time selection tables.
static tmp< labelField > agglomerate(label &nCoarseCells, const lduAddressing &fineMatrixAddressing, const scalarField &faceWeights)
Calculate and return agglomeration.
virtual bool movePoints()
Update when the mesh moves.
dynamicFvMesh & mesh
const scalarField & lower() const
Definition: lduMatrix.C:306
runTime controlDict().readEntry("adjustTimeStep"
The central control dictionary, the contents of which are either taken directly from the FOAM_CONTROL...
Definition: debug.C:142
algebraicPairGAMGAgglomeration(const lduMatrix &matrix, const dictionary &controlDict)
Construct given mesh and controls.
defineTypeNameAndDebug(combustionModel, 0)
lduMatrix is a general matrix class in which the coefficients are stored as three arrays...
Definition: lduMatrix.H:80
const scalarField & upper() const
Definition: lduMatrix.C:235
bool hasLower() const noexcept
Definition: lduMatrix.H:829
virtual bool movePoints()
Update when the mesh moves.
label nCellsInCoarsestLevel_
Number of cells in coarsest level.
Namespace for OpenFOAM.
addToRunTimeSelectionTable(functionObject, pointHistory, dictionary)