masterCoarsestGAMGProcAgglomeration.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2013-2019 OpenFOAM Foundation
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 \*---------------------------------------------------------------------------*/
25 
28 #include "GAMGAgglomeration.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34  defineTypeNameAndDebug(masterCoarsestGAMGProcAgglomeration, 0);
35 
37  (
38  GAMGProcAgglomeration,
39  masterCoarsestGAMGProcAgglomeration,
40  GAMGAgglomeration
41  );
42 }
43 
44 
45 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
46 
47 
48 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
49 
51 (
52  GAMGAgglomeration& agglom,
53  const dictionary& controlDict
54 )
55 :
56  GAMGProcAgglomeration(agglom, controlDict)
57 {}
58 
59 
60 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
61 
64 {
65  forAllReverse(comms_, i)
66  {
67  if (comms_[i] != -1)
68  {
69  UPstream::freeCommunicator(comms_[i]);
70  }
71  }
72 }
73 
74 
75 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
76 
78 {
79  if (debug)
80  {
81  Pout<< nl << "Starting mesh overview" << endl;
82  printStats(Pout, agglom_);
83  }
84 
85  if (agglom_.size() >= 1)
86  {
87  // Agglomerate one but last level (since also agglomerating
88  // restrictAddressing)
89  label fineLevelIndex = agglom_.size()-1;
90 
91  if (agglom_.hasMeshLevel(fineLevelIndex))
92  {
93  // Get the fine mesh
94  const lduMesh& levelMesh = agglom_.meshLevel(fineLevelIndex);
95  label levelComm = levelMesh.comm();
96  label nProcs = UPstream::nProcs(levelComm);
97 
98  if (nProcs > 1)
99  {
100  // Processor restriction map: per processor the coarse processor
101  labelList procAgglomMap(nProcs, 0);
102 
103  // Master processor
104  labelList masterProcs;
105  // Local processors that agglomerate. agglomProcIDs[0] is in
106  // masterProc.
107  List<label> agglomProcIDs;
109  (
110  levelComm,
111  procAgglomMap,
112  masterProcs,
113  agglomProcIDs
114  );
115 
116  // Allocate a communicator for the processor-agglomerated matrix
117  comms_.append
118  (
120  (
121  levelComm,
122  masterProcs
123  )
124  );
125 
126  // Use processor agglomeration maps to do the actual collecting.
127  if (Pstream::myProcNo(levelComm) != -1)
128  {
130  (
131  fineLevelIndex,
132  procAgglomMap,
133  masterProcs,
134  agglomProcIDs,
135  comms_.last()
136  );
137  }
138  }
139  }
140  }
141 
142  // Print a bit
143  if (debug)
144  {
145  Pout<< nl << "Agglomerated mesh overview" << endl;
146  printStats(Pout, agglom_);
147  }
148 
149  return true;
150 }
151 
152 
153 // ************************************************************************* //
virtual bool agglomerate()
Modify agglomeration. Return true if modified.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
static int myProcNo(const label communicator=0)
Number of this process (starting from masterNo() = 0)
Definition: UPstream.H:429
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Abstract base class for meshes which provide LDU addressing for the construction of lduMatrix and LDU...
Definition: lduMesh.H:59
#define forAllReverse(list, i)
Reverse loop across all elements in list.
Definition: UList.H:446
virtual label comm() const =0
Return communicator used for parallel communication.
Macros for easy insertion into run-time selection tables.
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
static const char nl
Definition: Ostream.H:260
defineTypeNameAndDebug(combustionModel, 0)
masterCoarsestGAMGProcAgglomeration(GAMGAgglomeration &agglom, const dictionary &controlDict)
Construct given agglomerator and controls.
virtual bool agglomerate()=0
Modify agglomeration. Return true if modified.
static label nProcs(const label communicator=0)
Number of processes in parallel run.
Definition: UPstream.H:411
prefixOSstream Pout(cout, "Pout")
Definition: IOstreams.H:53
Processor agglomeration of GAMGAgglomerations.
static label allocateCommunicator(const label parent, const labelList &subRanks, const bool doPstream=true)
Allocate a new communicator.
Definition: UPstream.C:248
T & last()
Return the last element of the list.
Definition: UListI.H:128
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:
static void freeCommunicator(const label communicator, const bool doPstream=true)
Free a previously allocated communicator.
Definition: UPstream.C:314
Namespace for OpenFOAM.