manualGAMGProcAgglomeration.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) 2013-2015 OpenFOAM Foundation
9  Copyright (C) 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 
31 #include "GAMGAgglomeration.H"
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37  defineTypeNameAndDebug(manualGAMGProcAgglomeration, 0);
38 
40  (
41  GAMGProcAgglomeration,
42  manualGAMGProcAgglomeration,
43  GAMGAgglomeration
44  );
45 }
46 
47 
48 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
49 
51 (
52  GAMGAgglomeration& agglom,
53  const dictionary& controlDict
54 )
55 :
57  procAgglomMaps_(controlDict.lookup("processorAgglomeration"))
58 {}
59 
60 
61 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
62 
64 {}
65 
66 
67 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
68 
70 {
71  if (debug)
72  {
73  Pout<< nl << "Starting mesh overview" << endl;
74  printStats(Pout, agglom_);
75  }
76 
77  if (agglom_.size() >= 1)
78  {
79  forAll(procAgglomMaps_, i)
80  {
81  const label fineLevelIndex = procAgglomMaps_[i].first();
82 
83  if (fineLevelIndex >= agglom_.size())
84  {
86  << "Ignoring specification for level " << fineLevelIndex
87  << " since outside agglomeration." << endl;
88 
89  continue;
90  }
91 
92  if (agglom_.hasMeshLevel(fineLevelIndex))
93  {
94  // Get the fine mesh
95  const lduMesh& levelMesh = agglom_.meshLevel(fineLevelIndex);
96  label nProcs = UPstream::nProcs(levelMesh.comm());
97 
98  if (nProcs > 1)
99  {
100  // My processor id
101  const label myProcID = Pstream::myProcNo(levelMesh.comm());
102 
103  const List<labelList>& clusters =
104  procAgglomMaps_[i].second();
105 
106  // Coarse to fine master processor
107  labelList coarseToMaster(clusters.size());
108 
109  // Fine to coarse map
110  labelList procAgglomMap(nProcs, -1);
111 
112  // Cluster for my processor (with master index first)
113  labelList agglomProcIDs;
114 
115 
116 
117  forAll(clusters, coarseI)
118  {
119  const labelList& cluster = clusters[coarseI];
120  coarseToMaster[coarseI] = cluster[0];
121 
122  forAll(cluster, i)
123  {
124  procAgglomMap[cluster[i]] = coarseI;
125  }
126 
127  const label masterIndex =
128  cluster.find(coarseToMaster[coarseI]);
129 
130  if (masterIndex == -1)
131  {
133  << "At level " << fineLevelIndex
134  << " the master processor "
135  << coarseToMaster[coarseI]
136  << " is not in the cluster "
137  << cluster
138  << exit(FatalError);
139  }
140 
141  if (cluster.found(myProcID))
142  {
143  // This is my cluster. Make sure master index is
144  // first
145  agglomProcIDs = cluster;
146  std::swap
147  (
148  agglomProcIDs[0],
149  agglomProcIDs[masterIndex]
150  );
151  }
152  }
153 
154 
155  // Check that we've done all processors
156  if (procAgglomMap.found(-1))
157  {
159  << "At level " << fineLevelIndex
160  << " processor "
161  << procAgglomMap.find(-1)
162  << " is not in any cluster"
163  << exit(FatalError);
164  }
165 
166 
167  // Communicator for the processor-agglomerated matrix
168  comms_.push_back
169  (
171  (
172  levelMesh.comm(),
173  coarseToMaster
174  )
175  );
176 
177  // Use processor agglomeration maps to do the actual
178  // collecting
179  if (UPstream::myProcNo(levelMesh.comm()) != -1)
180  {
182  (
183  fineLevelIndex,
184  procAgglomMap,
185  coarseToMaster,
186  agglomProcIDs,
187  comms_.back()
188  );
189  }
190  }
191  }
192  }
193 
194  // Print a bit
195  if (debug)
196  {
197  Pout<< nl << "Agglomerated mesh overview" << endl;
198  printStats(Pout, agglom_);
199  }
200  }
201 
202  return true;
203 }
204 
205 
206 // ************************************************************************* //
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
manualGAMGProcAgglomeration(const manualGAMGProcAgglomeration &)=delete
No copy construct.
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:598
virtual bool agglomerate()
Modify agglomeration. Return true if modified.
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
static int myProcNo(const label communicator=worldComm)
Rank of this process in the communicator (starting from masterNo()). Can be negative if the process i...
Definition: UPstream.H:1074
Lookup type of boundary radiation properties.
Definition: lookup.H:57
Macros for easy insertion into run-time selection tables.
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
static label nProcs(const label communicator=worldComm)
Number of ranks in parallel run (for given communicator). It is 1 for serial run. ...
Definition: UPstream.H:1065
runTime controlDict().readEntry("adjustTimeStep"
The central control dictionary, the contents of which are either taken directly from the FOAM_CONTROL...
Definition: debug.C:142
int debug
Static debugging option.
defineTypeNameAndDebug(combustionModel, 0)
virtual bool agglomerate()=0
Modify agglomeration.
#define WarningInFunction
Report a warning using Foam::Warning.
Processor agglomeration of GAMGAgglomerations.
List< label > labelList
A List of labels.
Definition: List.H:62
Geometric agglomerated algebraic multigrid agglomeration class.
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
static label allocateCommunicator(const label parent, const labelRange &subRanks, const bool withComponents=true)
Allocate new communicator with contiguous sub-ranks on the parent communicator.
Definition: UPstream.C:258
Namespace for OpenFOAM.
addToRunTimeSelectionTable(functionObject, pointHistory, dictionary)