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 -------------------------------------------------------------------------------
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(eagerGAMGProcAgglomeration, 0);
37 
39  (
40  GAMGProcAgglomeration,
41  eagerGAMGProcAgglomeration,
42  GAMGAgglomeration
43  );
44 }
45 
46 
47 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
48 
49 Foam::eagerGAMGProcAgglomeration::eagerGAMGProcAgglomeration
50 (
51  GAMGAgglomeration& agglom,
52  const dictionary& controlDict
53 )
54 :
56  mergeLevels_(controlDict.lookupOrDefault<label>("mergeLevels", 1))
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  for
90  (
91  label fineLevelIndex = 2;
92  fineLevelIndex < agglom_.size();
93  fineLevelIndex++
94  )
95  {
96  if (agglom_.hasMeshLevel(fineLevelIndex))
97  {
98  // Get the fine mesh
99  const lduMesh& levelMesh = agglom_.meshLevel(fineLevelIndex);
100  label levelComm = levelMesh.comm();
101  label nProcs = UPstream::nProcs(levelComm);
102 
103  if (nProcs > 1)
104  {
105  // Processor restriction map: per processor the coarse
106  // processor
107  labelList procAgglomMap(nProcs);
108 
109  forAll(procAgglomMap, proci)
110  {
111  procAgglomMap[proci] = proci/(1<<mergeLevels_);
112  }
113 
114  // Master processor
115  labelList masterProcs;
116  // Local processors that agglomerate. agglomProcIDs[0]
117  // is in masterProc.
118  List<label> agglomProcIDs;
120  (
121  levelComm,
122  procAgglomMap,
123  masterProcs,
124  agglomProcIDs
125  );
126 
127  // Allocate a communicator for the processor-agglomerated
128  // matrix
129  comms_.append
130  (
132  (
133  levelComm,
134  masterProcs
135  )
136  );
137 
138  // Use processor agglomeration maps to do the actual
139  // collecting.
140  if (Pstream::myProcNo(levelComm) != -1)
141  {
143  (
144  fineLevelIndex,
145  procAgglomMap,
146  masterProcs,
147  agglomProcIDs,
148  comms_.last()
149  );
150  }
151  }
152  }
153  }
154  }
155 
156  // Print a bit
157  if (debug)
158  {
159  Pout<< nl << "Agglomerated mesh overview" << endl;
160  printStats(Pout, agglom_);
161  }
162 
163  return true;
164 }
165 
166 
167 // ************************************************************************* //
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
Foam::UPstream::nProcs
static label nProcs(const label communicator=0)
Number of processes in parallel run.
Definition: UPstream.H:426
GAMGAgglomeration.H
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:337
Foam::Pout
prefixOSstream Pout
An Ostream wrapper for parallel output to std::cout.
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:290
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:674
Foam::UPstream::allocateCommunicator
static label allocateCommunicator(const label parent, const labelList &subRanks, const bool doPstream=true)
Allocate a new communicator.
Definition: UPstream.C:100
Foam::label
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:62
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:77
eagerGAMGProcAgglomeration.H
Foam::UPstream::freeCommunicator
static void freeCommunicator(const label communicator, const bool doPstream=true)
Free a previously allocated communicator.
Definition: UPstream.C:166
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
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=0)
Number of this process (starting from masterNo() = 0)
Definition: UPstream.H:444
Foam::nl
constexpr char nl
Definition: Ostream.H:372
Foam::eagerGAMGProcAgglomeration::~eagerGAMGProcAgglomeration
virtual ~eagerGAMGProcAgglomeration()
Destructor.
Definition: eagerGAMGProcAgglomeration.C:63
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:303
Foam::GAMGProcAgglomeration
Processor agglomeration of GAMGAgglomerations.
Definition: GAMGProcAgglomeration.H:54
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::lduMesh
Abstract base class for meshes which provide LDU addressing for the construction of lduMatrix and LDU...
Definition: lduMesh.H:62