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 {
35  defineTypeNameAndDebug(processorGAMGInterface, 0);
37  (
38  GAMGInterface,
39  processorGAMGInterface,
40  lduInterface
41  );
43  (
44  GAMGInterface,
45  processorGAMGInterface,
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
virtual ~processorGAMGInterface()
Destructor.
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
Vector-tensor class used to perform translations, rotations and scaling operations in 3D space...
Definition: transformer.H:83
static iteratorEnd end()
iteratorEnd set to beyond the end of any HashTable
Definition: HashTable.H:112
commsTypes
Types of communications.
Definition: UPstream.H:64
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,.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
virtual void write(Ostream &) const
Write to stream.
Macros for easy insertion into run-time selection tables.
iterator find(const Key &)
Find and return an iterator set at the hashedEntry.
Definition: HashTable.C:142
An ordered pair of two objects of type <T> with first() and second() elements.
Definition: contiguous.H:49
Pair< label > labelPair
Label pair.
Definition: labelPair.H:48
An STL-conforming hash table.
Definition: HashTable.H:61
label readLabel(Istream &is)
Definition: label.H:64
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:60
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
defineTypeNameAndDebug(combustionModel, 0)
Abstract base class for GAMG agglomerated interfaces.
Definition: GAMGInterface.H:51
virtual void write(Ostream &) const =0
Write to stream.
An abstract base class for implicitly-coupled interfaces e.g. processor and cyclic patches...
Definition: lduInterface.H:53
virtual tmp< labelField > internalFieldTransfer(const Pstream::commsTypes commsType, const labelUList &iF) const
Transfer and return internal field adjacent to the interface.
A class for managing temporary objects.
Definition: PtrList.H:53
virtual void initInternalFieldTransfer(const Pstream::commsTypes commsType, const labelUList &iF) const
Initialise neighbour field transfer.
Namespace for OpenFOAM.
dimensionSet transform(const dimensionSet &)
Definition: dimensionSet.C:477