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-------------------------------------------------------------------------------
10License
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
34namespace Foam
35{
37
39 (
43 );
44}
45
46
47// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
48
50(
51 GAMGAgglomeration& agglom,
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 {
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// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
Geometric agglomerated algebraic multigrid agglomeration class.
Processor agglomeration of GAMGAgglomerations.
virtual bool agglomerate()=0
Modify agglomeration. Return true if modified.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:77
label nProcs() const noexcept
Number of ranks associated with PstreamBuffers.
bool found(const T &val, label pos=0) const
True if the value if found in the list.
Definition: UListI.H:265
label find(const T &val, label pos=0) const
Find index of the first occurrence of the value.
Definition: UList.C:212
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
T & last()
Return the last element of the list.
Definition: UListI.H:216
static void freeCommunicator(const label communicator, const bool doPstream=true)
Free a previously allocated communicator.
Definition: UPstream.C:174
static label allocateCommunicator(const label parent, const labelList &subRanks, const bool doPstream=true)
Allocate a new communicator.
Definition: UPstream.C:108
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
Abstract base class for meshes which provide LDU addressing for the construction of lduMatrix and LDU...
Definition: lduMesh.H:63
virtual label comm() const =0
Return communicator used for parallel communication.
Manual processor agglomeration of GAMGAgglomerations.
virtual bool agglomerate()
Modify agglomeration. Return true if modified.
int myProcNo() const noexcept
Return processor number.
Lookup type of boundary radiation properties.
Definition: lookup.H:66
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
runTime controlDict().readEntry("adjustTimeStep"
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
#define WarningInFunction
Report a warning using Foam::Warning.
Namespace for OpenFOAM.
void Swap(DynamicList< T, SizeMinA > &a, DynamicList< T, SizeMinB > &b)
Definition: DynamicList.H:408
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
error FatalError
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333
#define forAllReverse(list, i)
Reverse loop across all elements in list.
Definition: stdFoam.H:346