Loading...
Searching...
No Matches
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-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 mergeLevels_(controlDict.getOrDefault<label>("mergeLevels", 1))
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 // Agglomerate one but last level (since also agglomerating
80 // restrictAddressing)
81 for
82 (
83 label fineLevelIndex = 2;
84 fineLevelIndex < agglom_.size();
85 fineLevelIndex++
86 )
87 {
88 if (agglom_.hasMeshLevel(fineLevelIndex))
89 {
90 // Get the fine mesh
91 const lduMesh& levelMesh = agglom_.meshLevel(fineLevelIndex);
92 label levelComm = levelMesh.comm();
93 label nProcs = UPstream::nProcs(levelComm);
94
95 if (nProcs > 1)
96 {
97 // Processor restriction map: per processor the coarse
98 // processor
99 labelList procAgglomMap(nProcs);
100
101 forAll(procAgglomMap, proci)
102 {
103 procAgglomMap[proci] = proci/(1<<mergeLevels_);
104 }
105
106 // Master processor
107 labelList masterProcs;
108 // Local processors that agglomerate. agglomProcIDs[0]
109 // is in masterProc.
110 List<label> agglomProcIDs;
112 (
113 levelComm,
114 procAgglomMap,
115 masterProcs,
116 agglomProcIDs
117 );
118
119 // Communicator for the processor-agglomerated matrix
120 comms_.push_back
121 (
123 (
124 levelComm,
125 masterProcs
126 )
127 );
128
129 // Use processor agglomeration maps to do the actual
130 // collecting.
131 if (UPstream::myProcNo(levelComm) != -1)
132 {
134 (
135 fineLevelIndex,
136 procAgglomMap,
137 masterProcs,
138 agglomProcIDs,
139 comms_.back()
140 );
141 }
142 }
143 }
144 }
145 }
146
147 // Print a bit
148 if (debug)
149 {
150 Pout<< nl << "Agglomerated mesh overview" << endl;
151 printStats(Pout, agglom_);
152 }
153
154 return true;
155}
156
157
158// ************************************************************************* //
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.
static void calculateRegionMaster(const label comm, const labelList &procAgglomMap, labelList &masterProcs, List< label > &agglomProcIDs)
Given fine to coarse processor map determine:
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
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
'Eager' processor agglomeration of GAMGAgglomerations: at every level agglomerates 'mergeLevels' numb...
eagerGAMGProcAgglomeration(const eagerGAMGProcAgglomeration &)=delete
No copy construct.
virtual bool agglomerate()
Modify agglomeration. Return true if modified.
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.
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition className.H:142
runTime controlDict().readEntry("adjustTimeStep"
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
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
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