cyclicGAMGInterface.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-2022 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 "cyclicGAMGInterface.H"
28 #include "labelPair.H"
29 #include "HashTable.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35  defineTypeNameAndDebug(cyclicGAMGInterface, 0);
37  (
38  GAMGInterface,
39  cyclicGAMGInterface,
40  lduInterface
41  );
43  (
44  GAMGInterface,
45  cyclicGAMGInterface,
46  Istream
47  );
48 
49  // Add under name cyclicSlip
51  (
52  GAMGInterface,
53  cyclicGAMGInterface,
54  lduInterface,
55  cyclicSlip
56  );
58  (
59  GAMGInterface,
60  cyclicGAMGInterface,
61  Istream,
62  cyclicSlip
63  );
64 
65  // Add under name nonConformalCyclic
67  (
68  GAMGInterface,
69  cyclicGAMGInterface,
70  lduInterface,
71  nonConformalCyclic
72  );
74  (
75  GAMGInterface,
76  cyclicGAMGInterface,
77  Istream,
78  nonConformalCyclic
79  );
80 }
81 
82 
83 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
84 
86 (
87  const label index,
88  const lduInterfacePtrsList& coarseInterfaces,
89  const lduInterface& fineInterface,
90  const labelField& localRestrictAddressing,
91  const labelField& neighbourRestrictAddressing,
92  const label fineLevelIndex,
93  const label coarseComm
94 )
95 :
96  GAMGInterface(index, coarseInterfaces),
97  nbrPatchID_
98  (
99  refCast<const cyclicLduInterface>(fineInterface).nbrPatchID()
100  ),
101  owner_(refCast<const cyclicLduInterface>(fineInterface).owner()),
102  transform_(refCast<const cyclicLduInterface>(fineInterface).transform())
103 {
104  // From coarse face to coarse cell
105  DynamicList<label> dynFaceCells(localRestrictAddressing.size());
106  // From fine face to coarse face
107  DynamicList<label> dynFaceRestrictAddressing
108  (
109  localRestrictAddressing.size()
110  );
111 
112  // From coarse cell pair to coarse face
114  (
115  2*localRestrictAddressing.size()
116  );
117 
118  forAll(localRestrictAddressing, ffi)
119  {
120  labelPair cellPair;
121 
122  // Do switching on master/slave indexes based on the owner/neighbour of
123  // the processor index such that both sides get the same answer.
124  if (owner())
125  {
126  // Master side
127  cellPair = labelPair
128  (
129  localRestrictAddressing[ffi],
130  neighbourRestrictAddressing[ffi]
131  );
132  }
133  else
134  {
135  // Slave side
136  cellPair = labelPair
137  (
138  neighbourRestrictAddressing[ffi],
139  localRestrictAddressing[ffi]
140  );
141  }
142 
143  HashTable<label, labelPair, labelPair::Hash<>>::const_iterator fnd =
144  cellsToCoarseFace.find(cellPair);
145 
146  if (fnd == cellsToCoarseFace.end())
147  {
148  // New coarse face
149  label coarseI = dynFaceCells.size();
150  dynFaceRestrictAddressing.append(coarseI);
151  dynFaceCells.append(localRestrictAddressing[ffi]);
152  cellsToCoarseFace.insert(cellPair, coarseI);
153  }
154  else
155  {
156  // Already have coarse face
157  dynFaceRestrictAddressing.append(fnd());
158  }
159  }
160 
161  faceCells_.transfer(dynFaceCells);
162  faceRestrictAddressing_.transfer(dynFaceRestrictAddressing);
163 }
164 
165 
167 (
168  const label index,
169  const lduInterfacePtrsList& coarseInterfaces,
170  Istream& is
171 )
172 :
173  GAMGInterface(index, coarseInterfaces, is),
174  nbrPatchID_(readLabel(is)),
175  owner_(readBool(is)),
176  transform_(is)
177 {}
178 
179 
180 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
181 
183 {}
184 
185 
186 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
187 
189 (
190  const Pstream::commsTypes,
191  const labelUList& iF
192 ) const
193 {
194  const cyclicGAMGInterface& nbr = nbrPatch();
195  const labelUList& nbrFaceCells = nbr.faceCells();
196 
197  tmp<labelField> tpnf(new labelField(size()));
198  labelField& pnf = tpnf.ref();
199 
200  forAll(pnf, facei)
201  {
202  pnf[facei] = iF[nbrFaceCells[facei]];
203  }
204 
205  return tpnf;
206 }
207 
208 
210 {
212  os << token::SPACE << nbrPatchID_
213  << token::SPACE << owner_
214  << token::SPACE << transform_;
215 }
216 
217 
218 // ************************************************************************* //
Field< label > labelField
Specialisation of Field<T> for label.
Definition: labelField.H:49
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
static iteratorEnd end()
iteratorEnd set to beyond the end of any HashTable
Definition: HashTable.H:112
commsTypes
Types of communications.
Definition: UPstream.H:64
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:181
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
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
virtual tmp< labelField > internalFieldTransfer(const Pstream::commsTypes commsType, const labelUList &iF) const
Transfer and return internal field adjacent to the interface.
bool readBool(Istream &)
Definition: boolIO.C:60
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
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
Definition: DynamicList.H:56
Pair< label > labelPair
Label pair.
Definition: labelPair.H:48
An STL-conforming hash table.
Definition: HashTable.H:61
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:60
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
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
A class for managing temporary objects.
Definition: PtrList.H:53
cyclicGAMGInterface(const label index, const lduInterfacePtrsList &coarseInterfaces, const lduInterface &fineInterface, const labelField &restrictAddressing, const labelField &neighbourRestrictAddressing, const label fineLevelIndex, const label coarseComm)
Construct from fine level interface,.
addNamedToRunTimeSelectionTable(parcelCloud, collidingCloud, viscosity, collidingCloud)
virtual ~cyclicGAMGInterface()
Destructor.
virtual void write(Ostream &) const
Write to stream.
Namespace for OpenFOAM.
GAMG agglomerated cyclic interface.
dimensionSet transform(const dimensionSet &)
Definition: dimensionSet.C:483