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-2023 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 {
37  (
41  );
43  (
46  Istream
47  );
48 
49  // Add under name cyclicSlip
51  (
55  cyclicSlip
56  );
58  (
61  Istream,
62  cyclicSlip
63  );
64 
65  // Add under name nonConformalCyclic
67  (
71  nonConformalCyclic
72  );
74  (
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  nbrPatchIndex_
98  (
99  refCast<const cyclicLduInterface>(fineInterface).nbrPatchIndex()
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  nbrPatchIndex_(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 << nbrPatchIndex_
213  << token::SPACE << owner_
214  << token::SPACE << transform_;
215 }
216 
217 
218 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
Macros for easy insertion into run-time selection tables.
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
Definition: DynamicListI.H:296
Abstract base class for GAMG agglomerated interfaces.
Definition: GAMGInterface.H:54
labelList faceRestrictAddressing_
Face restrict addressing.
Definition: GAMGInterface.H:70
labelList faceCells_
Face-cell addressing.
Definition: GAMGInterface.H:67
virtual const labelUList & faceCells() const
Return faceCell addressing.
virtual void write(Ostream &) const =0
Write to stream.
An STL-conforming hash table.
Definition: HashTable.H:127
bool insert(const Key &, const T &newElmt)
Insert a new hashedEntry.
Definition: HashTableI.H:80
iterator find(const Key &)
Find and return an iterator set at the hashedEntry.
Definition: HashTable.C:167
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
void transfer(List< T > &)
Transfer the contents of the argument List into this list.
Definition: List.C:342
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
commsTypes
Types of communications.
Definition: UPstream.H:65
GAMG agglomerated cyclic interface.
virtual void write(Ostream &) const
Write to stream.
virtual bool owner() const
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,.
virtual ~cyclicGAMGInterface()
Destructor.
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.
An abstract base class for implicitly-coupled interfaces e.g. processor and cyclic patches.
Definition: lduInterface.H:54
A class for managing temporary objects.
Definition: tmp.H:55
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:181
Namespace for OpenFOAM.
Pair< label > labelPair
Label pair.
Definition: labelPair.H:48
bool readBool(Istream &)
Definition: boolIO.C:66
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
addToRunTimeSelectionTable(polyPatch, mergedCyclicPolyPatch, word)
To & refCast(From &r)
Reference type cast template function.
Definition: typeInfo.H:129
addNamedToRunTimeSelectionTable(parcelCloud, collidingCloud, viscosity, collidingCloud)
dimensionSet transform(const dimensionSet &)
Definition: dimensionSet.C:504
defineTypeNameAndDebug(combustionModel, 0)
Field< label > labelField
Specialisation of Field<T> for label.
Definition: labelField.H:49
label readLabel(Istream &is)
Definition: label.H:64
static iteratorEnd end()
iteratorEnd set to beyond the end of any HashTable
Definition: HashTable.H:112