GAMGAgglomerationTemplates.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) 2011-2017 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
28#include "GAMGAgglomeration.H"
29#include "mapDistribute.H"
30#include "globalIndex.H"
31
32// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33
34template<class Type>
36(
37 Field<Type>& cf,
38 const Field<Type>& ff,
39 const labelList& fineToCoarse
40) const
41{
42 cf = Zero;
43
44 forAll(ff, i)
45 {
46 cf[fineToCoarse[i]] += ff[i];
47 }
48}
49
50
51template<class Type>
53(
54 Field<Type>& cf,
55 const Field<Type>& ff,
56 const label fineLevelIndex,
57 const bool procAgglom
58) const
59{
60 const labelList& fineToCoarse = restrictAddressing_[fineLevelIndex];
61
62 if (!procAgglom && ff.size() != fineToCoarse.size())
63 {
65 << "field does not correspond to level " << fineLevelIndex
66 << " sizes: field = " << ff.size()
67 << " level = " << fineToCoarse.size()
68 << abort(FatalError);
69 }
70
71 restrictField(cf, ff, fineToCoarse);
72
73 const label coarseLevelIndex = fineLevelIndex+1;
74
75 if (procAgglom && hasProcMesh(coarseLevelIndex))
76 {
77 const label coarseComm =
78 UPstream::parent(procCommunicator_[coarseLevelIndex]);
79
80 const List<label>& procIDs = agglomProcIDs(coarseLevelIndex);
81 const labelList& offsets = cellOffsets(coarseLevelIndex);
82
84 (
85 offsets,
86 coarseComm,
87 procIDs,
88 cf,
90 Pstream::commsTypes::nonBlocking //Pstream::commsTypes::scheduled
91 );
92 }
93}
94
95
96template<class Type>
98(
99 Field<Type>& cf,
100 const Field<Type>& ff,
101 const label fineLevelIndex
102) const
103{
104 const labelList& fineToCoarse = faceRestrictAddressing_[fineLevelIndex];
105
106 if (ff.size() != fineToCoarse.size())
107 {
109 << "field does not correspond to level " << fineLevelIndex
110 << " sizes: field = " << ff.size()
111 << " level = " << fineToCoarse.size()
112 << abort(FatalError);
113 }
114
115 cf = Zero;
116
117 forAll(fineToCoarse, ffacei)
118 {
119 label cFace = fineToCoarse[ffacei];
120
121 if (cFace >= 0)
122 {
123 cf[cFace] += ff[ffacei];
124 }
125 }
126}
127
128
129template<class Type>
131(
132 Field<Type>& ff,
133 const Field<Type>& cf,
134 const label levelIndex,
135 const bool procAgglom
136) const
137{
138 const labelList& fineToCoarse = restrictAddressing_[levelIndex];
139
140 const label coarseLevelIndex = levelIndex+1;
141
142 if (procAgglom && hasProcMesh(coarseLevelIndex))
143 {
144 const label coarseComm =
145 UPstream::parent(procCommunicator_[coarseLevelIndex]);
146
147 const List<label>& procIDs = agglomProcIDs(coarseLevelIndex);
148 const labelList& offsets = cellOffsets(coarseLevelIndex);
149
150 const label localSize = nCells_[levelIndex];
151
152 Field<Type> allCf(localSize);
154 (
155 offsets,
156 coarseComm,
157 procIDs,
158 cf,
159 allCf,
161 Pstream::commsTypes::nonBlocking //Pstream::commsTypes::scheduled
162 );
163
164 forAll(fineToCoarse, i)
165 {
166 ff[i] = allCf[fineToCoarse[i]];
167 }
168 }
169 else
170 {
171 forAll(fineToCoarse, i)
172 {
173 ff[i] = cf[fineToCoarse[i]];
174 }
175 }
176}
177
178
179// ************************************************************************* //
Generic templated field type.
Definition: Field.H:82
void restrictField(Field< Type > &cf, const Field< Type > &ff, const label fineLevelIndex, const bool procAgglom) const
Restrict (integrate by summation) cell field.
void prolongField(Field< Type > &ff, const Field< Type > &cf, const label coarseLevelIndex, const bool procAgglom) const
Prolong (interpolate by injection) cell field.
void restrictFaceField(Field< Type > &cf, const Field< Type > &ff, const label fineLevelIndex) const
Restrict (integrate by summation) face field.
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
@ nonBlocking
"nonBlocking"
static int & msgType() noexcept
Message tag of standard messages.
Definition: UPstream.H:556
static void gather(const labelUList &offsets, const label comm, const ProcIDsContainer &procIDs, const UList< Type > &fld, List< Type > &allFld, const int tag=UPstream::msgType(), const UPstream::commsTypes=UPstream::commsTypes::nonBlocking)
Collect data in processor order on master (== procIDs[0]).
static void scatter(const labelUList &offsets, const label comm, const ProcIDsContainer &procIDs, const UList< Type > &allFld, UList< Type > &fld, const int tag=UPstream::msgType(), const UPstream::commsTypes=UPstream::commsTypes::nonBlocking)
Distribute data in processor order.
splitCell * parent() const
Definition: splitCell.H:103
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
errorManip< error > abort(error &err)
Definition: errorManip.H:144
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
error FatalError
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333