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 -------------------------------------------------------------------------------
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 
28 #include "GAMGAgglomeration.H"
29 #include "mapDistribute.H"
30 #include "globalIndex.H"
31 
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 
34 template<class Type>
36 (
37  const label comm,
38  const labelList& procIDs,
39  const Type& myVal,
40  List<Type>& allVals,
41  const int tag
42 )
43 {
44  if (Pstream::myProcNo(comm) == procIDs[0])
45  {
46  allVals.setSize(procIDs.size());
47 
48  allVals[0] = myVal;
49  for (label i=1; i<procIDs.size(); i++)
50  {
51  IPstream fromSlave
52  (
53  Pstream::commsTypes::scheduled,
54  procIDs[i],
55  0,
56  tag,
57  comm
58  );
59 
60  fromSlave >> allVals[i];
61  }
62  }
63  else
64  {
65  OPstream toMaster
66  (
67  Pstream::commsTypes::scheduled,
68  procIDs[0],
69  0,
70  tag,
71  comm
72  );
73  toMaster << myVal;
74  }
75 }
76 
77 
78 template<class Type>
80 (
81  Field<Type>& cf,
82  const Field<Type>& ff,
83  const labelList& fineToCoarse
84 ) const
85 {
86  cf = Zero;
87 
88  forAll(ff, i)
89  {
90  cf[fineToCoarse[i]] += ff[i];
91  }
92 }
93 
94 
95 template<class Type>
97 (
98  Field<Type>& cf,
99  const Field<Type>& ff,
100  const label fineLevelIndex,
101  const bool procAgglom
102 ) const
103 {
104  const labelList& fineToCoarse = restrictAddressing_[fineLevelIndex];
105 
106  if (!procAgglom && 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  restrictField(cf, ff, fineToCoarse);
116 
117  label coarseLevelIndex = fineLevelIndex+1;
118 
119  if (procAgglom && hasProcMesh(coarseLevelIndex))
120  {
121  label fineComm = UPstream::parent(procCommunicator_[coarseLevelIndex]);
122 
123  const List<label>& procIDs = agglomProcIDs(coarseLevelIndex);
124  const labelList& offsets = cellOffsets(coarseLevelIndex);
125 
126  globalIndex::gather
127  (
128  offsets,
129  fineComm,
130  procIDs,
131  cf,
132  UPstream::msgType(),
133  Pstream::commsTypes::nonBlocking //Pstream::commsTypes::scheduled
134  );
135  }
136 }
137 
138 
139 template<class Type>
141 (
142  Field<Type>& cf,
143  const Field<Type>& ff,
144  const label fineLevelIndex
145 ) const
146 {
147  const labelList& fineToCoarse = faceRestrictAddressing_[fineLevelIndex];
148 
149  if (ff.size() != fineToCoarse.size())
150  {
152  << "field does not correspond to level " << fineLevelIndex
153  << " sizes: field = " << ff.size()
154  << " level = " << fineToCoarse.size()
155  << abort(FatalError);
156  }
157 
158  cf = Zero;
159 
160  forAll(fineToCoarse, ffacei)
161  {
162  label cFace = fineToCoarse[ffacei];
163 
164  if (cFace >= 0)
165  {
166  cf[cFace] += ff[ffacei];
167  }
168  }
169 }
170 
171 
172 template<class Type>
174 (
175  Field<Type>& ff,
176  const Field<Type>& cf,
177  const label levelIndex,
178  const bool procAgglom
179 ) const
180 {
181  const labelList& fineToCoarse = restrictAddressing_[levelIndex];
182 
183  label coarseLevelIndex = levelIndex+1;
184 
185  if (procAgglom && hasProcMesh(coarseLevelIndex))
186  {
187  label coarseComm = UPstream::parent
188  (
189  procCommunicator_[coarseLevelIndex]
190  );
191 
192  const List<label>& procIDs = agglomProcIDs(coarseLevelIndex);
193  const labelList& offsets = cellOffsets(coarseLevelIndex);
194 
195  label localSize = nCells_[levelIndex];
196 
197  Field<Type> allCf(localSize);
198  globalIndex::scatter
199  (
200  offsets,
201  coarseComm,
202  procIDs,
203  cf,
204  allCf,
205  UPstream::msgType(),
206  Pstream::commsTypes::nonBlocking //Pstream::commsTypes::scheduled
207  );
208 
209  forAll(fineToCoarse, i)
210  {
211  ff[i] = allCf[fineToCoarse[i]];
212  }
213  }
214  else
215  {
216  forAll(fineToCoarse, i)
217  {
218  ff[i] = cf[fineToCoarse[i]];
219  }
220  }
221 }
222 
223 
224 // ************************************************************************* //
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::OPstream
Output inter-processor communications stream.
Definition: OPstream.H:53
globalIndex.H
GAMGAgglomeration.H
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::Field
Generic templated field type.
Definition: Field.H:63
Foam::GAMGAgglomeration::restrictFaceField
void restrictFaceField(Field< Type > &cf, const Field< Type > &ff, const label fineLevelIndex) const
Restrict (integrate by summation) face field.
Definition: GAMGAgglomerationTemplates.C:141
Foam::List::setSize
void setSize(const label n)
Alias for resize()
Definition: List.H:222
Foam::GAMGAgglomeration::gatherList
static void gatherList(const label comm, const labelList &procIDs, const Type &myVal, List< Type > &allVals, const int tag=Pstream::msgType())
Gather value from all procIDs onto procIDs[0].
Definition: GAMGAgglomerationTemplates.C:36
Foam::FatalError
error FatalError
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:144
Foam::fv::ff
const FieldField< fvPatchField, Type > & ff(const FieldField< fvPatchField, Type > &bf)
Definition: CrankNicolsonDdtScheme.C:275
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
mapDistribute.H
Foam::GAMGAgglomeration::restrictField
void restrictField(Field< Type > &cf, const Field< Type > &ff, const label fineLevelIndex, const bool procAgglom) const
Restrict (integrate by summation) cell field.
Definition: GAMGAgglomerationTemplates.C:97
Foam::List< label >
Foam::GAMGAgglomeration::prolongField
void prolongField(Field< Type > &ff, const Field< Type > &cf, const label coarseLevelIndex, const bool procAgglom) const
Prolong (interpolate by injection) cell field.
Definition: GAMGAgglomerationTemplates.C:174
Foam::IPstream
Input inter-processor communications stream.
Definition: IPstream.H:53