cyclicGAMGInterface.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-2016 OpenFOAM Foundation
9  Copyright (C) 2019,2023 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 "cyclicGAMGInterface.H"
31 #include "labelPairHashes.H"
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37  defineTypeNameAndDebug(cyclicGAMGInterface, 0);
39  (
40  GAMGInterface,
41  cyclicGAMGInterface,
42  lduInterface
43  );
45  (
46  GAMGInterface,
47  cyclicGAMGInterface,
48  Istream
49  );
50 
51 
52  // Add under name cyclicSlip
54  (
55  GAMGInterface,
56  cyclicGAMGInterface,
57  lduInterface,
58  cyclicSlip
59  );
61  (
62  GAMGInterface,
63  cyclicGAMGInterface,
64  Istream,
65  cyclicSlip
66  );
67 }
68 
69 
70 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
71 
72 Foam::cyclicGAMGInterface::cyclicGAMGInterface
73 (
74  const label index,
75  const lduInterfacePtrsList& coarseInterfaces,
76  const lduInterface& fineInterface,
77  const labelField& localRestrictAddressing,
78  const labelField& neighbourRestrictAddressing,
79  const label fineLevelIndex,
80  const label coarseComm
81 )
82 :
83  GAMGInterface(index, coarseInterfaces),
84  neighbPatchID_
85  (
86  refCast<const cyclicLduInterface>(fineInterface).neighbPatchID()
87  ),
88  owner_(refCast<const cyclicLduInterface>(fineInterface).owner()),
89  forwardT_(refCast<const cyclicLduInterface>(fineInterface).forwardT()),
90  reverseT_(refCast<const cyclicLduInterface>(fineInterface).reverseT())
91 {
92  // From coarse face to coarse cell
93  DynamicList<label> dynFaceCells(localRestrictAddressing.size());
94  // From fine face to coarse face
95  DynamicList<label> dynFaceRestrictAddressing
96  (
97  localRestrictAddressing.size()
98  );
99 
100  // From coarse cell pair to coarse face
101  labelPairLookup cellsToCoarseFace(2*localRestrictAddressing.size());
102 
103  forAll(localRestrictAddressing, ffi)
104  {
105  labelPair cellPair;
106 
107  // Do switching on master/slave indexes based on the owner/neighbour of
108  // the processor index such that both sides get the same answer.
109  if (owner())
110  {
111  // Master side
112  cellPair = labelPair
113  (
114  localRestrictAddressing[ffi],
115  neighbourRestrictAddressing[ffi]
116  );
117  }
118  else
119  {
120  // Slave side
121  cellPair = labelPair
122  (
123  neighbourRestrictAddressing[ffi],
124  localRestrictAddressing[ffi]
125  );
126  }
127 
128  const auto fnd = cellsToCoarseFace.cfind(cellPair);
129 
130  if (fnd.good())
131  {
132  // Already have coarse face
133  dynFaceRestrictAddressing.append(fnd.val());
134  }
135  else
136  {
137  // New coarse face
138  label coarseI = dynFaceCells.size();
139  dynFaceRestrictAddressing.append(coarseI);
140  dynFaceCells.append(localRestrictAddressing[ffi]);
141  cellsToCoarseFace.insert(cellPair, coarseI);
142  }
143  }
145  faceCells_.transfer(dynFaceCells);
146  faceRestrictAddressing_.transfer(dynFaceRestrictAddressing);
147 }
148 
149 
150 Foam::cyclicGAMGInterface::cyclicGAMGInterface
151 (
152  const label index,
153  const lduInterfacePtrsList& coarseInterfaces,
154  Istream& is
155 )
156 :
157  GAMGInterface(index, coarseInterfaces, is),
158  neighbPatchID_(readLabel(is)),
159  owner_(readBool(is)),
160  forwardT_(is),
161  reverseT_(is)
162 {}
163 
164 
165 Foam::cyclicGAMGInterface::cyclicGAMGInterface
166 (
167  const label index,
168  const lduInterfacePtrsList& coarseInterfaces,
169  const lduInterface& fineInterface,
170  const labelList& interfaceMap,
171  const labelUList& faceCells,
172  const labelUList& faceRestrictAddresssing,
173  const labelUList& faceOffsets,
174  const lduInterfacePtrsList& allInterfaces
175 )
176 :
178  (
179  index,
180  coarseInterfaces,
181  faceCells,
182  faceRestrictAddresssing
183  ),
184  neighbPatchID_
185  (
186  interfaceMap.find
187  (
188  refCast<const cyclicLduInterface>(fineInterface).neighbPatchID()
189  )
190  ),
191  owner_(refCast<const cyclicLduInterface>(fineInterface).owner()),
192  forwardT_(refCast<const cyclicLduInterface>(fineInterface).forwardT()),
193  reverseT_(refCast<const cyclicLduInterface>(fineInterface).reverseT())
194 {}
195 
196 
197 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
198 
200 (
201  const Pstream::commsTypes commsType,
202  const labelUList& iF
203 ) const
204 {
205  const cyclicGAMGInterface& nbr = neighbPatch();
206  const labelUList& nbrFaceCells = nbr.faceCells();
207 
208  auto tpnf = tmp<labelField>::New(size());
209  auto& pnf = tpnf.ref();
210 
211  forAll(pnf, facei)
212  {
213  pnf[facei] = iF[nbrFaceCells[facei]];
214  }
215 
216  return tpnf;
217 }
218 
219 
220 void Foam::cyclicGAMGInterface::write(Ostream& os) const
221 {
223  os << token::SPACE << neighbPatchID_
224  << token::SPACE << owner_
225  << token::SPACE << forwardT_
226  << token::SPACE << reverseT_;
227 }
228 
229 
230 // ************************************************************************* //
label find(const ListType &input, const UnaryPredicate &pred, const label start=0)
Same as ListOps::find_if.
Definition: ListOps.H:795
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
commsTypes
Communications types.
Definition: UPstream.H:72
void transfer(List< T > &list)
Transfer the contents of the argument List into this list and annul the argument list.
Definition: List.C:326
virtual const labelUList & faceCells() const
Return faceCell addressing.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
Type & refCast(U &obj)
A dynamic_cast (for references). Generates a FatalError on failed casts and uses the virtual type() m...
Definition: typeInfo.H:159
virtual tmp< labelField > internalFieldTransfer(const Pstream::commsTypes commsType, const labelUList &iF) const
Transfer and return internal field adjacent to the interface.
An abstract base class for cyclic coupled interfaces.
label readLabel(const char *buf)
Parse entire buffer as a label, skipping leading/trailing whitespace.
Definition: label.H:63
labelList faceRestrictAddressing_
Face restrict addressing.
Definition: GAMGInterface.H:76
Smooth ATC in cells next to a set of patches supplied by type.
Definition: faceCells.H:52
Macros for easy insertion into run-time selection tables.
addNamedToRunTimeSelectionTable(topoSetCellSource, badQualityToCell, word, badQuality)
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
Space [isspace].
Definition: token.H:131
virtual void write(Ostream &os) const
Write to stream.
static tmp< T > New(Args &&... args)
Construct tmp with forwarding arguments.
Definition: tmp.H:206
A HashTable to objects of type <T> with a labelPair key. The hashing is based on labelPair (FixedList...
Pair< label > labelPair
A pair of labels.
Definition: Pair.H:51
OBJstream os(runTime.globalPath()/outputName)
defineTypeNameAndDebug(combustionModel, 0)
Abstract base class for GAMG agglomerated interfaces.
Definition: GAMGInterface.H:50
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
labelList faceCells_
Face-cell addressing.
Definition: GAMGInterface.H:71
A class for managing temporary objects.
Definition: HashPtrTable.H:50
virtual bool owner() const
bool readBool(Istream &is)
Read bool from stream using Foam::Switch(Istream&)
Definition: bool.C:62
Namespace for OpenFOAM.
GAMG agglomerated cyclic interface.
addToRunTimeSelectionTable(functionObject, pointHistory, dictionary)