processorGAMGInterface.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  Copyright (C) 2019 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "processorGAMGInterface.H"
31 #include "labelPairHashes.H"
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37  defineTypeNameAndDebug(processorGAMGInterface, 0);
39  (
40  GAMGInterface,
41  processorGAMGInterface,
42  lduInterface
43  );
45  (
46  GAMGInterface,
47  processorGAMGInterface,
48  Istream
49  );
50 }
51 
52 
53 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
54 
55 Foam::processorGAMGInterface::processorGAMGInterface
56 (
57  const label index,
58  const lduInterfacePtrsList& coarseInterfaces,
59  const lduInterface& fineInterface,
60  const labelField& localRestrictAddressing,
61  const labelField& neighbourRestrictAddressing,
62  const label fineLevelIndex,
63  const label coarseComm
64 )
65 :
67  (
68  index,
69  coarseInterfaces
70  ),
71  comm_(coarseComm),
72  myProcNo_(refCast<const processorLduInterface>(fineInterface).myProcNo()),
73  neighbProcNo_
74  (
75  refCast<const processorLduInterface>(fineInterface).neighbProcNo()
76  ),
77  forwardT_(refCast<const processorLduInterface>(fineInterface).forwardT()),
78  tag_(refCast<const processorLduInterface>(fineInterface).tag())
79 {
80  // From coarse face to coarse cell
81  DynamicList<label> dynFaceCells(localRestrictAddressing.size());
82  // From fine face to coarse face
83  DynamicList<label> dynFaceRestrictAddressing
84  (
85  localRestrictAddressing.size()
86  );
87 
88  // From coarse cell pair to coarse face
89  labelPairLookup cellsToCoarseFace(2*localRestrictAddressing.size());
90 
91  forAll(localRestrictAddressing, ffi)
92  {
93  labelPair cellPair;
94 
95  // Do switching on master/slave indexes based on the owner/neighbour of
96  // the processor index such that both sides get the same answer.
97  if (myProcNo() < neighbProcNo())
98  {
99  // Master side
100  cellPair = labelPair
101  (
102  localRestrictAddressing[ffi],
103  neighbourRestrictAddressing[ffi]
104  );
105  }
106  else
107  {
108  // Slave side
109  cellPair = labelPair
110  (
111  neighbourRestrictAddressing[ffi],
112  localRestrictAddressing[ffi]
113  );
114  }
115 
116  const auto fnd = cellsToCoarseFace.cfind(cellPair);
117 
118  if (fnd.found())
119  {
120  // Already have coarse face
121  dynFaceRestrictAddressing.append(fnd.val());
122  }
123  else
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  }
132 
133  faceCells_.transfer(dynFaceCells);
134  faceRestrictAddressing_.transfer(dynFaceRestrictAddressing);
135 }
136 
137 
138 Foam::processorGAMGInterface::processorGAMGInterface
139 (
140  const label index,
141  const lduInterfacePtrsList& coarseInterfaces,
142  const labelUList& faceCells,
143  const labelUList& faceRestrictAddresssing,
144  const label coarseComm,
145  const label myProcNo,
146  const label neighbProcNo,
147  const tensorField& forwardT,
148  const int tag
149 )
150 :
152  (
153  index,
154  coarseInterfaces,
155  faceCells,
156  faceRestrictAddresssing
157  ),
158  comm_(coarseComm),
159  myProcNo_(myProcNo),
160  neighbProcNo_(neighbProcNo),
161  forwardT_(forwardT),
162  tag_(tag)
163 {}
164 
165 
166 Foam::processorGAMGInterface::processorGAMGInterface
167 (
168  const label index,
169  const lduInterfacePtrsList& coarseInterfaces,
170  Istream& is
171 )
172 :
173  GAMGInterface(index, coarseInterfaces, is),
174  comm_(readLabel(is)),
175  myProcNo_(readLabel(is)),
176  neighbProcNo_(readLabel(is)),
177  forwardT_(is),
178  tag_(readLabel(is))
179 {}
180 
181 
182 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
183 
185 (
186  const Pstream::commsTypes commsType,
187  const labelUList& iF
188 ) const
189 {
190  send(commsType, interfaceInternalField(iF)());
191 }
192 
193 
195 (
196  const Pstream::commsTypes commsType,
197  const labelUList& iF,
198  const labelUList& faceCells
199 ) const
200 {
201  send(commsType, interfaceInternalField(iF, faceCells)());
202 }
203 
204 
206 (
207  const Pstream::commsTypes commsType,
208  const labelUList& iF
209 ) const
210 {
211  tmp<labelField> 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 << forwardT_
224  << token::SPACE << tag_;
225 }
226 
227 
228 // ************************************************************************* //
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
Foam::GAMGInterface::write
virtual void write(Ostream &) const =0
Write to stream.
Definition: GAMGInterface.C:125
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::processorGAMGInterface::write
virtual void write(Ostream &os) const
Write to stream.
Definition: processorGAMGInterface.C:217
Foam::DynamicList< label >
Foam::lduInterface
An abstract base class for implicitly-coupled interfaces e.g. processor and cyclic patches.
Definition: lduInterface.H:54
Foam::processorGAMGInterface::internalFieldTransfer
virtual tmp< labelField > internalFieldTransfer(const Pstream::commsTypes commsType, const labelUList &iF) const
Transfer and return internal field adjacent to the interface.
Definition: processorGAMGInterface.C:206
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::labelPair
Pair< label > labelPair
A pair of labels.
Definition: Pair.H:54
labelPairHashes.H
A HashTable to objects of type <T> with a labelPair key. The hashing is based on labelPair (FixedList...
Foam::Field< label >
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::GAMGInterface
Abstract base class for GAMG agglomerated interfaces.
Definition: GAMGInterface.H:54
Foam::UPtrList< const lduInterface >
os
OBJstream os(runTime.globalPath()/outputName)
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
processorGAMGInterface.H
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::processorGAMGInterface::initInternalFieldTransfer
virtual void initInternalFieldTransfer(const Pstream::commsTypes commsType, const labelUList &iF) const
Initialise neighbour field transfer.
Definition: processorGAMGInterface.C:185
Foam::HashTable< label, labelPair, Foam::Hash< labelPair > >
Foam::UPstream::commsTypes
commsTypes
Types of communications.
Definition: UPstream.H:69
Foam::Pair< label >
Foam::readLabel
label readLabel(const char *buf)
Parse entire buffer as a label, skipping leading/trailing whitespace.
Definition: label.H:66
Foam::token::SPACE
Space [isspace].
Definition: token.H:125
Foam::UList< label >
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::faceCells
Smooth ATC in cells next to a set of patches supplied by type.
Definition: faceCells.H:56