Loading...
Searching...
No Matches
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 Copyright (C) 2023 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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"
33// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34
35namespace Foam
36{
38
40 (
44 );
45}
46
47
48// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
49
51(
52 GAMGAgglomeration& agglom,
54)
55:
57 procAgglomMaps_(controlDict.lookup("processorAgglomeration"))
58{}
59
60
61// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
64{}
65
66
67// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
68
70{
71 if (debug)
72 {
73 Pout<< nl << "Starting mesh overview" << endl;
74 printStats(Pout, agglom_);
75 }
76
77 if (agglom_.size() >= 1)
78 {
79 forAll(procAgglomMaps_, i)
80 {
81 const label fineLevelIndex = procAgglomMaps_[i].first();
82
83 if (fineLevelIndex >= agglom_.size())
84 {
86 << "Ignoring specification for level " << fineLevelIndex
87 << " since outside agglomeration." << endl;
88
89 continue;
90 }
91
92 if (agglom_.hasMeshLevel(fineLevelIndex))
93 {
94 // Get the fine mesh
95 const lduMesh& levelMesh = agglom_.meshLevel(fineLevelIndex);
96 label nProcs = UPstream::nProcs(levelMesh.comm());
97
98 if (nProcs > 1)
99 {
100 // My processor id
101 const label myProcID = Pstream::myProcNo(levelMesh.comm());
102
103 const List<labelList>& clusters =
104 procAgglomMaps_[i].second();
105
106 // Coarse to fine master processor
107 labelList coarseToMaster(clusters.size());
108
109 // Fine to coarse map
110 labelList procAgglomMap(nProcs, -1);
111
112 // Cluster for my processor (with master index first)
113 labelList agglomProcIDs;
114
115
116
117 forAll(clusters, coarseI)
118 {
119 const labelList& cluster = clusters[coarseI];
120 coarseToMaster[coarseI] = cluster[0];
121
122 forAll(cluster, i)
123 {
124 procAgglomMap[cluster[i]] = coarseI;
125 }
126
127 const label masterIndex =
128 cluster.find(coarseToMaster[coarseI]);
129
130 if (masterIndex == -1)
131 {
133 << "At level " << fineLevelIndex
134 << " the master processor "
135 << coarseToMaster[coarseI]
136 << " is not in the cluster "
137 << cluster
138 << exit(FatalError);
139 }
140
141 if (cluster.found(myProcID))
142 {
143 // This is my cluster. Make sure master index is
144 // first
145 agglomProcIDs = cluster;
146 std::swap
147 (
148 agglomProcIDs[0],
149 agglomProcIDs[masterIndex]
150 );
151 }
152 }
153
154
155 // Check that we've done all processors
156 if (procAgglomMap.found(-1))
157 {
159 << "At level " << fineLevelIndex
160 << " processor "
161 << procAgglomMap.find(-1)
162 << " is not in any cluster"
163 << exit(FatalError);
164 }
165
166
167 // Communicator for the processor-agglomerated matrix
168 comms_.push_back
169 (
171 (
172 levelMesh.comm(),
173 coarseToMaster
174 )
175 );
176
177 // Use processor agglomeration maps to do the actual
178 // collecting
179 if (UPstream::myProcNo(levelMesh.comm()) != -1)
180 {
182 (
183 fineLevelIndex,
184 procAgglomMap,
185 coarseToMaster,
186 agglomProcIDs,
187 comms_.back()
188 );
189 }
190 }
191 }
192 }
193
194 // Print a bit
195 if (debug)
196 {
197 Pout<< nl << "Agglomerated mesh overview" << endl;
198 printStats(Pout, agglom_);
199 }
200 }
201
202 return true;
203}
204
205
206// ************************************************************************* //
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.
GAMGAgglomeration & agglom_
Reference to agglomeration.
void printStats(Ostream &os, GAMGAgglomeration &agglom) const
Debug: write agglomeration info.
DynamicList< label > comms_
Allocated communicators.
GAMGProcAgglomeration(const GAMGProcAgglomeration &)=delete
No copy construct.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition List.H:72
bool found(const T &val, label pos=0) const
Same as contains().
Definition UList.H:983
void size(const label n)
Older name for setAddressableSize.
Definition UList.H:118
label find(const T &val) const
Find index of the first occurrence of the value.
Definition UList.C:160
static int myProcNo(const label communicator=worldComm)
Rank of this process in the communicator (starting from masterNo()). Negative if the process is not a...
Definition UPstream.H:1706
static label nProcs(const label communicator=worldComm)
Number of ranks in parallel run (for given communicator). It is 1 for serial run.
Definition UPstream.H:1697
static label newCommunicator(const label parent, const labelRange &subRanks, const bool withComponents=true)
Create new communicator with sub-ranks on the parent communicator.
Definition UPstream.C:272
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
Abstract base class for meshes which provide LDU addressing for the construction of lduMatrix and LDU...
Definition lduMesh.H:54
virtual label comm() const =0
Return communicator used for parallel communication.
Manual processor agglomeration of GAMGAgglomerations.
manualGAMGProcAgglomeration(const manualGAMGProcAgglomeration &)=delete
No copy construct.
virtual bool agglomerate()
Modify agglomeration. Return true if modified.
Lookup type of boundary radiation properties.
Definition lookup.H:60
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition className.H:142
runTime controlDict().readEntry("adjustTimeStep"
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition error.H:600
#define WarningInFunction
Report a warning using Foam::Warning.
Namespace for handling debugging switches.
Definition debug.C:45
Namespace for OpenFOAM.
List< label > labelList
A List of labels.
Definition List.H:62
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition errorManip.H:125
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299