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  Swap(agglomProcIDs[0], agglomProcIDs[masterIndex]);
147  }
148  }
149 
150 
151  // Check that we've done all processors
152  if (procAgglomMap.found(-1))
153  {
155  << "At level " << fineLevelIndex
156  << " processor "
157  << procAgglomMap.find(-1)
158  << " is not in any cluster"
159  << exit(FatalError);
160  }
161 
162 
163  // Communicator for the processor-agglomerated matrix
164  comms_.push_back
165  (
167  (
168  levelMesh.comm(),
169  coarseToMaster
170  )
171  );
172 
173  // Use processor agglomeration maps to do the actual
174  // collecting
175  if (UPstream::myProcNo(levelMesh.comm()) != -1)
176  {
178  (
179  fineLevelIndex,
180  procAgglomMap,
181  coarseToMaster,
182  agglomProcIDs,
183  comms_.back()
184  );
185  }
186  }
187  }
188  }
189 
190  // Print a bit
191  if (debug)
192  {
193  Pout<< nl << "Agglomerated mesh overview" << endl;
194  printStats(Pout, agglom_);
195  }
196  }
197 
198  return true;
199 }
200 
201 
202 // ************************************************************************* //
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:120
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:578
virtual bool agglomerate()
Modify agglomeration. Return true if modified.
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:49
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:487
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:1029
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:414
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:1020
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)
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
virtual bool agglomerate()=0
Modify agglomeration.
#define WarningInFunction
Report a warning using Foam::Warning.
Processor agglomeration of GAMGAgglomerations.
void Swap(DynamicList< T, SizeMinA > &a, DynamicList< T, SizeMinB > &b)
Definition: DynamicList.H:659
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.