masterCoarsestGAMGProcAgglomeration.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-2014 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(masterCoarsestGAMGProcAgglomeration, 0);
37 
39  (
40  GAMGProcAgglomeration,
41  masterCoarsestGAMGProcAgglomeration,
42  GAMGAgglomeration
43  );
44 }
45 
46 
47 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
48 
49 Foam::masterCoarsestGAMGProcAgglomeration::masterCoarsestGAMGProcAgglomeration
50 (
51  GAMGAgglomeration& agglom,
52  const dictionary& controlDict
53 )
54 :
56 {}
57 
58 
59 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
60 
63 {
64  forAllReverse(comms_, i)
65  {
66  if (comms_[i] != -1)
67  {
68  UPstream::freeCommunicator(comms_[i]);
69  }
70  }
71 }
72 
73 
74 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
75 
77 {
78  if (debug)
79  {
80  Pout<< nl << "Starting mesh overview" << endl;
81  printStats(Pout, agglom_);
82  }
83 
84  if (agglom_.size() >= 1)
85  {
86  // Agglomerate one but last level (since also agglomerating
87  // restrictAddressing)
88  label fineLevelIndex = agglom_.size()-1;
89 
90  if (agglom_.hasMeshLevel(fineLevelIndex))
91  {
92  // Get the fine mesh
93  const lduMesh& levelMesh = agglom_.meshLevel(fineLevelIndex);
94  label levelComm = levelMesh.comm();
95  label nProcs = UPstream::nProcs(levelComm);
96 
97  if (nProcs > 1)
98  {
99  // Processor restriction map: per processor the coarse processor
100  labelList procAgglomMap(nProcs, Zero);
101 
102  // Master processor
103  labelList masterProcs;
104  // Local processors that agglomerate. agglomProcIDs[0] is in
105  // masterProc.
106  List<label> agglomProcIDs;
108  (
109  levelComm,
110  procAgglomMap,
111  masterProcs,
112  agglomProcIDs
113  );
114 
115  // Allocate a communicator for the processor-agglomerated matrix
116  comms_.append
117  (
119  (
120  levelComm,
121  masterProcs
122  )
123  );
124 
125  // Use processor agglomeration maps to do the actual collecting.
126  if (Pstream::myProcNo(levelComm) != -1)
127  {
129  (
130  fineLevelIndex,
131  procAgglomMap,
132  masterProcs,
133  agglomProcIDs,
134  comms_.last()
135  );
136  }
137  }
138  }
139  }
140 
141  // Print a bit
142  if (debug)
143  {
144  Pout<< nl << "Agglomerated mesh overview" << endl;
145  printStats(Pout, agglom_);
146  }
147 
148  return true;
149 }
150 
151 
152 // ************************************************************************* //
masterCoarsestGAMGProcAgglomeration.H
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
Foam::masterCoarsestGAMGProcAgglomeration::agglomerate
virtual bool agglomerate()
Modify agglomeration. Return true if modified.
Definition: masterCoarsestGAMGProcAgglomeration.C:76
Foam::GAMGAgglomeration
Geometric agglomerated algebraic multigrid agglomeration class.
Definition: GAMGAgglomeration.H:64
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
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::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::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::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::masterCoarsestGAMGProcAgglomeration::~masterCoarsestGAMGProcAgglomeration
virtual ~masterCoarsestGAMGProcAgglomeration()
Destructor.
Definition: masterCoarsestGAMGProcAgglomeration.C:62
Foam::lduMesh
Abstract base class for meshes which provide LDU addressing for the construction of lduMatrix and LDU...
Definition: lduMesh.H:62