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-2018 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 
53 Foam::processorGAMGInterface::processorGAMGInterface
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  forwardT_(refCast<const processorLduInterface>(fineInterface).forwardT()),
76  tag_(refCast<const processorLduInterface>(fineInterface).tag())
77 {
78  // From coarse face to coarse cell
79  DynamicList<label> dynFaceCells(localRestrictAddressing.size());
80  // From fine face to coarse face
81  DynamicList<label> dynFaceRestrictAddressing
82  (
83  localRestrictAddressing.size()
84  );
85 
86  // From coarse cell pair to coarse face
88  (
89  2*localRestrictAddressing.size()
90  );
91 
92  forAll(localRestrictAddressing, ffi)
93  {
94  labelPair cellPair;
95 
96  // Do switching on master/slave indexes based on the owner/neighbour of
97  // the processor index such that both sides get the same answer.
98  if (myProcNo() < neighbProcNo())
99  {
100  // Master side
101  cellPair = labelPair
102  (
103  localRestrictAddressing[ffi],
104  neighbourRestrictAddressing[ffi]
105  );
106  }
107  else
108  {
109  // Slave side
110  cellPair = labelPair
111  (
112  neighbourRestrictAddressing[ffi],
113  localRestrictAddressing[ffi]
114  );
115  }
116 
117  HashTable<label, labelPair, labelPair::Hash<>>::const_iterator fnd =
118  cellsToCoarseFace.find(cellPair);
119 
120  if (fnd == cellsToCoarseFace.end())
121  {
122  // New coarse face
123  label coarseI = dynFaceCells.size();
124  dynFaceRestrictAddressing.append(coarseI);
125  dynFaceCells.append(localRestrictAddressing[ffi]);
126  cellsToCoarseFace.insert(cellPair, coarseI);
127  }
128  else
129  {
130  // Already have coarse face
131  dynFaceRestrictAddressing.append(fnd());
132  }
133  }
134 
135  faceCells_.transfer(dynFaceCells);
136  faceRestrictAddressing_.transfer(dynFaceRestrictAddressing);
137 }
138 
139 
140 Foam::processorGAMGInterface::processorGAMGInterface
141 (
142  const label index,
143  const lduInterfacePtrsList& coarseInterfaces,
144  const labelUList& faceCells,
145  const labelUList& faceRestrictAddresssing,
146  const label coarseComm,
147  const label myProcNo,
148  const label neighbProcNo,
149  const tensorField& forwardT,
150  const int tag
151 )
152 :
154  (
155  index,
156  coarseInterfaces,
157  faceCells,
158  faceRestrictAddresssing
159  ),
160  comm_(coarseComm),
161  myProcNo_(myProcNo),
162  neighbProcNo_(neighbProcNo),
163  forwardT_(forwardT),
164  tag_(tag)
165 {}
166 
167 
168 Foam::processorGAMGInterface::processorGAMGInterface
169 (
170  const label index,
171  const lduInterfacePtrsList& coarseInterfaces,
172  Istream& is
173 )
174 :
175  GAMGInterface(index, coarseInterfaces, is),
176  comm_(readLabel(is)),
177  myProcNo_(readLabel(is)),
178  neighbProcNo_(readLabel(is)),
179  forwardT_(is),
180  tag_(readLabel(is))
181 {}
182 
183 
184 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
185 
187 {}
188 
189 
190 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
191 
193 (
194  const Pstream::commsTypes commsType,
195  const labelUList& iF
196 ) const
197 {
198  send(commsType, interfaceInternalField(iF)());
199 }
200 
201 
203 (
204  const Pstream::commsTypes commsType,
205  const labelUList& iF
206 ) const
207 {
208  tmp<Field<label>> tfld(receive<label>(commsType, this->size()));
209 
210  return tfld;
211 }
212 
213 
215 {
217  os << token::SPACE << comm_
218  << token::SPACE << myProcNo_
219  << token::SPACE << neighbProcNo_
220  << token::SPACE << forwardT_
221  << token::SPACE << tag_;
222 }
223 
224 
225 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
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
static iteratorEnd end()
iteratorEnd set to beyond the end of any HashTable
Definition: HashTable.H:110
commsTypes
Types of communications.
Definition: UPstream.H:64
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:163
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:62
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:61
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
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.