calculatedProcessorGAMGInterface.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) 2019 OpenCFD Ltd.
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 
30 #include "labelPairHashes.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36  defineTypeNameAndDebug(calculatedProcessorGAMGInterface, 0);
38  (
39  GAMGInterface,
40  calculatedProcessorGAMGInterface,
41  lduInterface
42  );
44  (
45  GAMGInterface,
46  calculatedProcessorGAMGInterface,
47  Istream
48  );
49 }
50 
51 
52 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
53 
54 Foam::calculatedProcessorGAMGInterface::calculatedProcessorGAMGInterface
55 (
56  const label index,
57  const lduInterfacePtrsList& coarseInterfaces,
58  const lduInterface& fineInterface,
59  const labelField& localRestrictAddressing,
60  const labelField& neighbourRestrictAddressing,
61  const label fineLevelIndex,
62  const label coarseComm
63 )
64 :
66  (
67  index,
68  coarseInterfaces
69  ),
70  comm_(coarseComm),
71  myProcNo_(refCast<const processorLduInterface>(fineInterface).myProcNo()),
72  neighbProcNo_
73  (
74  refCast<const processorLduInterface>(fineInterface).neighbProcNo()
75  ),
76  forwardT_(refCast<const processorLduInterface>(fineInterface).forwardT()),
77  tag_(refCast<const processorLduInterface>(fineInterface).tag())
78 {
79  // From coarse face to coarse cell
80  DynamicList<label> dynFaceCells(localRestrictAddressing.size());
81  // From fine face to coarse face
82  DynamicList<label> dynFaceRestrictAddressing
83  (
84  localRestrictAddressing.size()
85  );
86 
87  // From coarse cell pair to coarse face
88  labelPairLookup cellsToCoarseFace(2*localRestrictAddressing.size());
89 
90  forAll(localRestrictAddressing, ffi)
91  {
92  labelPair cellPair;
93 
94  // Do switching on master/slave indexes based on the owner/neighbour of
95  // the processor index such that both sides get the same answer.
96  if (myProcNo() < neighbProcNo())
97  {
98  // Master side
99  cellPair = labelPair
100  (
101  localRestrictAddressing[ffi],
102  neighbourRestrictAddressing[ffi]
103  );
104  }
105  else
106  {
107  // Slave side
108  cellPair = labelPair
109  (
110  neighbourRestrictAddressing[ffi],
111  localRestrictAddressing[ffi]
112  );
113  }
114 
115  const auto fnd = cellsToCoarseFace.cfind(cellPair);
116 
117  if (fnd.found())
118  {
119  // Already have coarse face
120  dynFaceRestrictAddressing.append(fnd.val());
121  }
122  else
123  {
124  // New coarse face
125  label coarseI = dynFaceCells.size();
126  dynFaceRestrictAddressing.append(coarseI);
127  dynFaceCells.append(localRestrictAddressing[ffi]);
128  cellsToCoarseFace.insert(cellPair, coarseI);
129  }
130  }
131 
132  faceCells_.transfer(dynFaceCells);
133  faceRestrictAddressing_.transfer(dynFaceRestrictAddressing);
134 }
135 
136 
137 Foam::calculatedProcessorGAMGInterface::calculatedProcessorGAMGInterface
138 (
139  const label index,
140  const lduInterfacePtrsList& coarseInterfaces,
141  const labelUList& faceCells,
142  const labelUList& faceRestrictAddresssing,
143  const label coarseComm,
144  const label myProcNo,
145  const label neighbProcNo,
146  const tensorField& forwardT,
147  const int tag
148 )
149 :
151  (
152  index,
153  coarseInterfaces,
154  faceCells,
155  faceRestrictAddresssing
156  ),
157  comm_(coarseComm),
158  myProcNo_(myProcNo),
159  neighbProcNo_(neighbProcNo),
160  forwardT_(forwardT),
161  tag_(tag)
162 {}
163 
164 
165 Foam::calculatedProcessorGAMGInterface::calculatedProcessorGAMGInterface
166 (
167  const label index,
168  const lduInterfacePtrsList& coarseInterfaces,
169  Istream& is
170 )
171 :
172  GAMGInterface(index, coarseInterfaces, is),
173  comm_(readLabel(is)),
174  myProcNo_(readLabel(is)),
175  neighbProcNo_(readLabel(is)),
176  forwardT_(is),
177  tag_(readLabel(is))
178 {}
179 
180 
181 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
182 
184 (
185  const Pstream::commsTypes commsType,
186  const labelUList& iF
187 ) const
188 {
189  send(commsType, interfaceInternalField(iF)());
190 }
191 
192 
195 (
196  const Pstream::commsTypes commsType,
197  const labelUList& iF
198 ) const
199 {
200  tmp<labelField> tfld(receive<label>(commsType, this->size()));
201 
202  return tfld;
203 }
204 
205 
208 (
209  const Pstream::commsTypes commsType,
210  const labelUList& iF,
211  const labelUList& faceCells
212 ) const
213 {
215 
216  return tmp<labelField>::New(this->size(), Zero);
217 }
218 
219 
221 {
223  os << token::SPACE << comm_
224  << token::SPACE << myProcNo_
225  << token::SPACE << neighbProcNo_
226  << token::SPACE << forwardT_
227  << token::SPACE << tag_;
228 }
229 
230 
231 // ************************************************************************* //
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
Foam::calculatedProcessorGAMGInterface::initInternalFieldTransfer
virtual void initInternalFieldTransfer(const Pstream::commsTypes commsType, const labelUList &iF) const
Definition: calculatedProcessorGAMGInterface.C:177
Foam::GAMGInterface::write
virtual void write(Ostream &) const =0
Definition: GAMGInterface.C:118
Foam::calculatedProcessorGAMGInterface::write
virtual void write(Ostream &os) const
Definition: calculatedProcessorGAMGInterface.C:213
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:57
Foam::Zero
static constexpr const zero Zero
Definition: zero.H:131
Foam::DynamicList< label >
Foam::GAMGInterface::faceRestrictAddressing_
labelList faceRestrictAddressing_
Definition: GAMGInterface.H:68
Foam::lduInterface
An abstract base class for implicitly-coupled interfaces e.g. processor and cyclic patches.
Definition: lduInterface.H:50
Foam::processorLduInterface
An abstract base class for processor coupled interfaces.
Definition: processorLduInterface.H:49
calculatedProcessorGAMGInterface.H
Foam::HashTable::insert
bool insert(const Key &key, const T &obj)
Definition: HashTableI.H:173
forAll
#define forAll(list, i)
Definition: stdFoam.H:349
Foam::GAMGInterface::faceCells_
labelList faceCells_
Definition: GAMGInterface.H:65
Foam::labelPair
Pair< label > labelPair
A pair of labels.
Definition: Pair.H:50
NotImplemented
#define NotImplemented
Definition: error.H:553
labelPairHashes.H
A HashTable to objects of type <T> with a labelPair key. The hashing is based on labelPair (FixedList...
Foam::Field
Generic templated field type.
Definition: Field.H:59
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:57
Foam::GAMGInterface
Abstract base class for GAMG agglomerated interfaces.
Definition: GAMGInterface.H:50
Foam::DynamicList::append
DynamicList< T, SizeMin > & append(const T &val)
Definition: DynamicListI.H:504
Foam::calculatedProcessorGAMGInterface::myProcNo
virtual int myProcNo() const
Definition: calculatedProcessorGAMGInterface.H:167
Foam::List::transfer
void transfer(List< T > &list)
Foam::UPtrList
A list of pointers to objects of type <T>, without allocation/deallocation management of the pointers...
Definition: UPtrList.H:58
os
OBJstream os(runTime.globalPath()/outputName)
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Definition: atmBoundaryLayer.C:26
Foam::refCast
To & refCast(From &r)
Definition: typeInfo.H:136
Foam::HashTable< label, labelPair, Foam::Hash< labelPair > >
Foam::calculatedProcessorGAMGInterface::neighbProcNo
virtual int neighbProcNo() const
Definition: calculatedProcessorGAMGInterface.H:173
Foam::New
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Definition: DimensionedFieldReuseFunctions.H:100
Foam::UPstream::commsTypes
commsTypes
Definition: UPstream.H:65
Foam::HashTable::cfind
const_iterator cfind(const Key &key) const
Definition: HashTableI.H:134
Foam::calculatedProcessorGAMGInterface::internalFieldTransfer
virtual tmp< labelField > internalFieldTransfer(const Pstream::commsTypes commsType, const labelUList &iF) const
Definition: calculatedProcessorGAMGInterface.C:188
Foam::Pair
An ordered pair of two objects of type <T> with first() and second() elements.
Definition: Pair.H:50
Foam::readLabel
label readLabel(const char *buf)
Definition: label.H:63
Foam::token::SPACE
@ SPACE
Space [isspace].
Definition: token.H:121
Foam::UList
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:99
Foam::tmp::New
static tmp< T > New(Args &&... args)
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:52
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::faceCells
Smooth ATC in cells next to a set of patches supplied by type.
Definition: faceCells.H:52