eagerGAMGProcAgglomeration.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-2016 OpenFOAM Foundation
9  Copyright (C) 2020-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(eagerGAMGProcAgglomeration, 0);
38 
40  (
41  GAMGProcAgglomeration,
42  eagerGAMGProcAgglomeration,
43  GAMGAgglomeration
44  );
45 }
46 
47 
48 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
49 
51 (
52  GAMGAgglomeration& agglom,
53  const dictionary& controlDict
54 )
55 :
57  mergeLevels_(controlDict.getOrDefault<label>("mergeLevels", 1))
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  // Agglomerate one but last level (since also agglomerating
80  // restrictAddressing)
81  for
82  (
83  label fineLevelIndex = 2;
84  fineLevelIndex < agglom_.size();
85  fineLevelIndex++
86  )
87  {
88  if (agglom_.hasMeshLevel(fineLevelIndex))
89  {
90  // Get the fine mesh
91  const lduMesh& levelMesh = agglom_.meshLevel(fineLevelIndex);
92  label levelComm = levelMesh.comm();
93  label nProcs = UPstream::nProcs(levelComm);
94 
95  if (nProcs > 1)
96  {
97  // Processor restriction map: per processor the coarse
98  // processor
99  labelList procAgglomMap(nProcs);
100 
101  forAll(procAgglomMap, proci)
102  {
103  procAgglomMap[proci] = proci/(1<<mergeLevels_);
104  }
105 
106  // Master processor
107  labelList masterProcs;
108  // Local processors that agglomerate. agglomProcIDs[0]
109  // is in masterProc.
110  List<label> agglomProcIDs;
112  (
113  levelComm,
114  procAgglomMap,
115  masterProcs,
116  agglomProcIDs
117  );
118 
119  // Communicator for the processor-agglomerated matrix
120  comms_.push_back
121  (
123  (
124  levelComm,
125  masterProcs
126  )
127  );
128 
129  // Use processor agglomeration maps to do the actual
130  // collecting.
131  if (UPstream::myProcNo(levelComm) != -1)
132  {
134  (
135  fineLevelIndex,
136  procAgglomMap,
137  masterProcs,
138  agglomProcIDs,
139  comms_.back()
140  );
141  }
142  }
143  }
144  }
145  }
146 
147  // Print a bit
148  if (debug)
149  {
150  Pout<< nl << "Agglomerated mesh overview" << endl;
151  printStats(Pout, agglom_);
152  }
153 
154  return true;
155 }
156 
157 
158 // ************************************************************************* //
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
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
virtual bool agglomerate()
Modify agglomeration. Return true if modified.
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
eagerGAMGProcAgglomeration(const eagerGAMGProcAgglomeration &)=delete
No copy construct.
int debug
Static debugging option.
defineTypeNameAndDebug(combustionModel, 0)
virtual bool agglomerate()=0
Modify agglomeration.
Processor agglomeration of GAMGAgglomerations.
List< label > labelList
A List of labels.
Definition: List.H:62
Geometric agglomerated algebraic multigrid agglomeration class.
static void calculateRegionMaster(const label comm, const labelList &procAgglomMap, labelList &masterProcs, List< label > &agglomProcIDs)
Given fine to coarse processor map determine:
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)