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
Initialise neighbour field transfer.
Definition: calculatedProcessorGAMGInterface.C:184
Foam::GAMGInterface::write
virtual void write(Ostream &) const =0
Write to stream.
Definition: GAMGInterface.C:125
Foam::calculatedProcessorGAMGInterface::write
virtual void write(Ostream &os) const
Write to stream.
Definition: calculatedProcessorGAMGInterface.C:220
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::DynamicList< label >
Foam::lduInterface
An abstract base class for implicitly-coupled interfaces e.g. processor and cyclic patches.
Definition: lduInterface.H:54
calculatedProcessorGAMGInterface.H
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
NotImplemented
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:517
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.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::HashTable< label, labelPair, Foam::Hash< labelPair > >
Foam::New
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
Definition: DimensionedFieldReuseFunctions.H:105
Foam::UPstream::commsTypes
commsTypes
Types of communications.
Definition: UPstream.H:69
Foam::calculatedProcessorGAMGInterface::internalFieldTransfer
virtual tmp< labelField > internalFieldTransfer(const Pstream::commsTypes commsType, const labelUList &iF) const
Transfer and return internal field adjacent to the interface.
Definition: calculatedProcessorGAMGInterface.C:195
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