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 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
30 #include "GAMGAgglomeration.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36  defineTypeNameAndDebug(manualGAMGProcAgglomeration, 0);
37 
39  (
40  GAMGProcAgglomeration,
41  manualGAMGProcAgglomeration,
42  GAMGAgglomeration
43  );
44 }
45 
46 
47 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
48 
49 Foam::manualGAMGProcAgglomeration::manualGAMGProcAgglomeration
50 (
51  GAMGAgglomeration& agglom,
52  const dictionary& controlDict
53 )
54 :
56  procAgglomMaps_(controlDict.lookup("processorAgglomeration"))
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  forAll(procAgglomMaps_, i)
88  {
89  const label fineLevelIndex = procAgglomMaps_[i].first();
90 
91  if (fineLevelIndex >= agglom_.size())
92  {
94  << "Ignoring specification for level " << fineLevelIndex
95  << " since outside agglomeration." << endl;
96 
97  continue;
98  }
99 
100  if (agglom_.hasMeshLevel(fineLevelIndex))
101  {
102  // Get the fine mesh
103  const lduMesh& levelMesh = agglom_.meshLevel(fineLevelIndex);
104  label nProcs = UPstream::nProcs(levelMesh.comm());
105 
106  if (nProcs > 1)
107  {
108  // My processor id
109  const label myProcID = Pstream::myProcNo(levelMesh.comm());
110 
111  const List<labelList>& clusters =
112  procAgglomMaps_[i].second();
113 
114  // Coarse to fine master processor
115  labelList coarseToMaster(clusters.size());
116 
117  // Fine to coarse map
118  labelList procAgglomMap(nProcs, -1);
119 
120  // Cluster for my processor (with master index first)
121  labelList agglomProcIDs;
122 
123 
124 
125  forAll(clusters, coarseI)
126  {
127  const labelList& cluster = clusters[coarseI];
128  coarseToMaster[coarseI] = cluster[0];
129 
130  forAll(cluster, i)
131  {
132  procAgglomMap[cluster[i]] = coarseI;
133  }
134 
135  const label masterIndex =
136  cluster.find(coarseToMaster[coarseI]);
137 
138  if (masterIndex == -1)
139  {
141  << "At level " << fineLevelIndex
142  << " the master processor "
143  << coarseToMaster[coarseI]
144  << " is not in the cluster "
145  << cluster
146  << exit(FatalError);
147  }
148 
149  if (cluster.found(myProcID))
150  {
151  // This is my cluster. Make sure master index is
152  // first
153  agglomProcIDs = cluster;
154  Swap(agglomProcIDs[0], agglomProcIDs[masterIndex]);
155  }
156  }
157 
158 
159  // Check that we've done all processors
160  if (procAgglomMap.found(-1))
161  {
163  << "At level " << fineLevelIndex
164  << " processor "
165  << procAgglomMap.find(-1)
166  << " is not in any cluster"
167  << exit(FatalError);
168  }
169 
170 
171  // Allocate a communicator for the processor-agglomerated
172  // matrix
173  comms_.append
174  (
176  (
177  levelMesh.comm(),
178  coarseToMaster
179  )
180  );
181 
182  // Use processor agglomeration maps to do the actual
183  // collecting
184  if (Pstream::myProcNo(levelMesh.comm()) != -1)
185  {
187  (
188  fineLevelIndex,
189  procAgglomMap,
190  coarseToMaster,
191  agglomProcIDs,
192  comms_.last()
193  );
194  }
195  }
196  }
197  }
198 
199  // Print a bit
200  if (debug)
201  {
202  Pout<< nl << "Agglomerated mesh overview" << endl;
203  printStats(Pout, agglom_);
204  }
205  }
206 
207  return true;
208 }
209 
210 
211 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
Foam::Swap
void Swap(DynamicList< T, SizeMinA > &a, DynamicList< T, SizeMinB > &b)
Definition: DynamicList.H:429
Foam::GAMGAgglomeration
Geometric agglomerated algebraic multigrid agglomeration class.
Definition: GAMGAgglomeration.H:64
GAMGAgglomeration.H
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::Pout
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
Foam::manualGAMGProcAgglomeration::~manualGAMGProcAgglomeration
virtual ~manualGAMGProcAgglomeration()
Destructor.
Definition: manualGAMGProcAgglomeration.C:63
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::manualGAMGProcAgglomeration::agglomerate
virtual bool agglomerate()
Modify agglomeration. Return true if modified.
Definition: manualGAMGProcAgglomeration.C:77
Foam::UPstream::allocateCommunicator
static label allocateCommunicator(const label parent, const labelList &subRanks, const bool doPstream=true)
Allocate a new communicator.
Definition: UPstream.C:108
Foam::GAMGProcAgglomeration::agglomerate
virtual bool agglomerate()=0
Modify agglomeration. Return true if modified.
controlDict
runTime controlDict().readEntry("adjustTimeStep"
Definition: debug.C:143
Foam::UPstream::freeCommunicator
static void freeCommunicator(const label communicator, const bool doPstream=true)
Free a previously allocated communicator.
Definition: UPstream.C:174
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::UPstream::myProcNo
static int myProcNo(const label communicator=worldComm)
Number of this process (starting from masterNo() = 0)
Definition: UPstream.H:463
Foam::nl
constexpr char nl
Definition: Ostream.H:404
manualGAMGProcAgglomeration.H
Foam::List< labelList >
Foam::lduMesh::comm
virtual label comm() const =0
Return communicator used for parallel communication.
forAllReverse
#define forAllReverse(list, i)
Reverse loop across all elements in list.
Definition: stdFoam.H:309
Foam::GAMGProcAgglomeration
Processor agglomeration of GAMGAgglomerations.
Definition: GAMGProcAgglomeration.H:54
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:328
Foam::UPstream::nProcs
static label nProcs(const label communicator=worldComm)
Number of processes in parallel run, and 1 for serial run.
Definition: UPstream.H:445
Foam::lduMesh
Abstract base class for meshes which provide LDU addressing for the construction of lduMatrix and LDU...
Definition: lduMesh.H:62