processorGAMGInterface.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "processorGAMGInterface.H"
28 #include "HashTable.H"
29 #include "labelPair.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
37  (
41  );
43  (
46  Istream
47  );
48 }
49 
50 
51 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
52 
54 (
55  const label index,
56  const lduInterfacePtrsList& coarseInterfaces,
57  const lduInterface& fineInterface,
58  const labelField& localRestrictAddressing,
59  const labelField& neighbourRestrictAddressing,
60  const label fineLevelIndex,
61  const label coarseComm
62 )
63 :
65  (
66  index,
67  coarseInterfaces
68  ),
69  comm_(coarseComm),
70  myProcNo_(refCast<const processorLduInterface>(fineInterface).myProcNo()),
71  neighbProcNo_
72  (
73  refCast<const processorLduInterface>(fineInterface).neighbProcNo()
74  ),
75  transform_
76  (
77  refCast<const processorLduInterface>(fineInterface).transform()
78  ),
79  tag_(refCast<const processorLduInterface>(fineInterface).tag())
80 {
81  // From coarse face to coarse cell
82  DynamicList<label> dynFaceCells(localRestrictAddressing.size());
83  // From fine face to coarse face
84  DynamicList<label> dynFaceRestrictAddressing
85  (
86  localRestrictAddressing.size()
87  );
88 
89  // From coarse cell pair to coarse face
91  (
92  2*localRestrictAddressing.size()
93  );
94 
95  forAll(localRestrictAddressing, ffi)
96  {
97  labelPair cellPair;
98 
99  // Do switching on master/slave indexes based on the owner/neighbour of
100  // the processor index such that both sides get the same answer.
101  if (myProcNo() < neighbProcNo())
102  {
103  // Master side
104  cellPair = labelPair
105  (
106  localRestrictAddressing[ffi],
107  neighbourRestrictAddressing[ffi]
108  );
109  }
110  else
111  {
112  // Slave side
113  cellPair = labelPair
114  (
115  neighbourRestrictAddressing[ffi],
116  localRestrictAddressing[ffi]
117  );
118  }
119 
120  HashTable<label, labelPair, labelPair::Hash<>>::const_iterator fnd =
121  cellsToCoarseFace.find(cellPair);
122 
123  if (fnd == cellsToCoarseFace.end())
124  {
125  // New coarse face
126  label coarseI = dynFaceCells.size();
127  dynFaceRestrictAddressing.append(coarseI);
128  dynFaceCells.append(localRestrictAddressing[ffi]);
129  cellsToCoarseFace.insert(cellPair, coarseI);
130  }
131  else
132  {
133  // Already have coarse face
134  dynFaceRestrictAddressing.append(fnd());
135  }
136  }
137 
138  faceCells_.transfer(dynFaceCells);
139  faceRestrictAddressing_.transfer(dynFaceRestrictAddressing);
140 }
141 
142 
144 (
145  const label index,
146  const lduInterfacePtrsList& coarseInterfaces,
147  const labelUList& faceCells,
148  const labelUList& faceRestrictAddressing,
149  const label coarseComm,
150  const label myProcNo,
151  const label neighbProcNo,
152  const transformer& transform,
153  const int tag
154 )
155 :
157  (
158  index,
159  coarseInterfaces,
160  faceCells,
161  faceRestrictAddressing
162  ),
163  comm_(coarseComm),
164  myProcNo_(myProcNo),
165  neighbProcNo_(neighbProcNo),
166  transform_(transform),
167  tag_(tag)
168 {}
169 
170 
172 (
173  const label index,
174  const lduInterfacePtrsList& coarseInterfaces,
175  Istream& is
176 )
177 :
178  GAMGInterface(index, coarseInterfaces, is),
179  comm_(readLabel(is)),
180  myProcNo_(readLabel(is)),
181  neighbProcNo_(readLabel(is)),
182  transform_(is),
183  tag_(readLabel(is))
184 {}
185 
186 
187 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
188 
190 {}
191 
192 
193 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
194 
196 (
197  const Pstream::commsTypes commsType,
198  const labelUList& iF
199 ) const
200 {
201  send(commsType, interfaceInternalField(iF)());
202 }
203 
204 
206 (
207  const Pstream::commsTypes commsType,
208  const labelUList& iF
209 ) const
210 {
211  tmp<Field<label>> tfld(receive<label>(commsType, this->size()));
212 
213  return tfld;
214 }
215 
216 
218 {
220  os << token::SPACE << comm_
221  << token::SPACE << myProcNo_
222  << token::SPACE << neighbProcNo_
223  << token::SPACE << transform_
224  << token::SPACE << tag_;
225 }
226 
227 
228 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
Macros for easy insertion into run-time selection tables.
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
Definition: DynamicListI.H:296
Abstract base class for GAMG agglomerated interfaces.
Definition: GAMGInterface.H:54
labelList faceRestrictAddressing_
Face restrict addressing.
Definition: GAMGInterface.H:70
labelList faceCells_
Face-cell addressing.
Definition: GAMGInterface.H:67
virtual void write(Ostream &) const =0
Write to stream.
An STL-conforming hash table.
Definition: HashTable.H:127
bool insert(const Key &, const T &newElmt)
Insert a new hashedEntry.
Definition: HashTableI.H:80
iterator find(const Key &)
Find and return an iterator set at the hashedEntry.
Definition: HashTable.C:167
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
void transfer(List< T > &)
Transfer the contents of the argument List into this list.
Definition: List.C:342
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
commsTypes
Types of communications.
Definition: UPstream.H:65
An abstract base class for implicitly-coupled interfaces e.g. processor and cyclic patches.
Definition: lduInterface.H:54
GAMG agglomerated processor interface.
virtual void write(Ostream &) const
Write to stream.
processorGAMGInterface(const label index, const lduInterfacePtrsList &coarseInterfaces, const lduInterface &fineInterface, const labelField &restrictAddressing, const labelField &neighbourRestrictAddressing, const label fineLevelIndex, const label coarseComm)
Construct from fine-level interface,.
virtual int myProcNo() const
Return processor number (rank in communicator)
virtual void initInternalFieldTransfer(const Pstream::commsTypes commsType, const labelUList &iF) const
Initialise neighbour field transfer.
virtual tmp< labelField > internalFieldTransfer(const Pstream::commsTypes commsType, const labelUList &iF) const
Transfer and return internal field adjacent to the interface.
virtual ~processorGAMGInterface()
Destructor.
virtual int neighbProcNo() const
Return neighbour processor number (rank in communicator)
An abstract base class for processor coupled interfaces.
A class for managing temporary objects.
Definition: tmp.H:55
Vector-tensor class used to perform translations, rotations and scaling operations in 3D space.
Definition: transformer.H:84
Namespace for OpenFOAM.
Pair< label > labelPair
Label pair.
Definition: labelPair.H:48
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
addToRunTimeSelectionTable(polyPatch, mergedCyclicPolyPatch, word)
To & refCast(From &r)
Reference type cast template function.
Definition: typeInfo.H:129
dimensionSet transform(const dimensionSet &)
Definition: dimensionSet.C:504
defineTypeNameAndDebug(combustionModel, 0)
label readLabel(Istream &is)
Definition: label.H:64
static iteratorEnd end()
iteratorEnd set to beyond the end of any HashTable
Definition: HashTable.H:112