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 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 
50 Foam::eagerGAMGProcAgglomeration::eagerGAMGProcAgglomeration
51 (
52  GAMGAgglomeration& agglom,
53  const dictionary& controlDict
54 )
55 :
57  mergeLevels_(controlDict.getOrDefault<label>("mergeLevels", 1))
58 {}
59 
60 
61 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
62 
65 {
66  forAllReverse(comms_, i)
67  {
68  if (comms_[i] != -1)
69  {
70  UPstream::freeCommunicator(comms_[i]);
71  }
72  }
73 }
74 
75 
76 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
77 
79 {
80  if (debug)
81  {
82  Pout<< nl << "Starting mesh overview" << endl;
83  printStats(Pout, agglom_);
84  }
85 
86  if (agglom_.size() >= 1)
87  {
88  // Agglomerate one but last level (since also agglomerating
89  // restrictAddressing)
90  for
91  (
92  label fineLevelIndex = 2;
93  fineLevelIndex < agglom_.size();
94  fineLevelIndex++
95  )
96  {
97  if (agglom_.hasMeshLevel(fineLevelIndex))
98  {
99  // Get the fine mesh
100  const lduMesh& levelMesh = agglom_.meshLevel(fineLevelIndex);
101  label levelComm = levelMesh.comm();
102  label nProcs = UPstream::nProcs(levelComm);
103 
104  if (nProcs > 1)
105  {
106  // Processor restriction map: per processor the coarse
107  // processor
108  labelList procAgglomMap(nProcs);
109 
110  forAll(procAgglomMap, proci)
111  {
112  procAgglomMap[proci] = proci/(1<<mergeLevels_);
113  }
114 
115  // Master processor
116  labelList masterProcs;
117  // Local processors that agglomerate. agglomProcIDs[0]
118  // is in masterProc.
119  List<label> agglomProcIDs;
121  (
122  levelComm,
123  procAgglomMap,
124  masterProcs,
125  agglomProcIDs
126  );
127 
128  // Allocate a communicator for the processor-agglomerated
129  // matrix
130  comms_.append
131  (
133  (
134  levelComm,
135  masterProcs
136  )
137  );
138 
139  // Use processor agglomeration maps to do the actual
140  // collecting.
141  if (Pstream::myProcNo(levelComm) != -1)
142  {
144  (
145  fineLevelIndex,
146  procAgglomMap,
147  masterProcs,
148  agglomProcIDs,
149  comms_.last()
150  );
151  }
152  }
153  }
154  }
155  }
156 
157  // Print a bit
158  if (debug)
159  {
160  Pout<< nl << "Agglomerated mesh overview" << endl;
161  printStats(Pout, agglom_);
162  }
163 
164  return true;
165 }
166 
167 
168 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
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.
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::GAMGAgglomeration::calculateRegionMaster
static void calculateRegionMaster(const label comm, const labelList &procAgglomMap, labelList &masterProcs, List< label > &agglomProcIDs)
Given fine to coarse processor map determine:
Definition: GAMGAgglomerateLduAddressing.C:737
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::eagerGAMGProcAgglomeration::agglomerate
virtual bool agglomerate()
Modify agglomeration. Return true if modified.
Definition: eagerGAMGProcAgglomeration.C:78
eagerGAMGProcAgglomeration.H
Foam::UPstream::freeCommunicator
static void freeCommunicator(const label communicator, const bool doPstream=true)
Free a previously allocated communicator.
Definition: UPstream.C:174
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::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
Foam::eagerGAMGProcAgglomeration::~eagerGAMGProcAgglomeration
virtual ~eagerGAMGProcAgglomeration()
Destructor.
Definition: eagerGAMGProcAgglomeration.C:64
Foam::List< label >
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)
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