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-2020 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 
50  // Add under name cyclicSlip
52  (
53  GAMGInterface,
54  cyclicGAMGInterface,
55  lduInterface,
56  cyclicSlip
57  );
59  (
60  GAMGInterface,
61  cyclicGAMGInterface,
62  Istream,
63  cyclicSlip
64  );
65 }
66 
67 
68 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
69 
71 (
72  const label index,
73  const lduInterfacePtrsList& coarseInterfaces,
74  const lduInterface& fineInterface,
75  const labelField& localRestrictAddressing,
76  const labelField& neighbourRestrictAddressing,
77  const label fineLevelIndex,
78  const label coarseComm
79 )
80 :
81  GAMGInterface(index, coarseInterfaces),
82  nbrPatchID_
83  (
84  refCast<const cyclicLduInterface>(fineInterface).nbrPatchID()
85  ),
86  owner_(refCast<const cyclicLduInterface>(fineInterface).owner()),
87  transform_(refCast<const cyclicLduInterface>(fineInterface).transform())
88 {
89  // From coarse face to coarse cell
90  DynamicList<label> dynFaceCells(localRestrictAddressing.size());
91  // From fine face to coarse face
92  DynamicList<label> dynFaceRestrictAddressing
93  (
94  localRestrictAddressing.size()
95  );
96 
97  // From coarse cell pair to coarse face
99  (
100  2*localRestrictAddressing.size()
101  );
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  HashTable<label, labelPair, labelPair::Hash<>>::const_iterator fnd =
129  cellsToCoarseFace.find(cellPair);
130 
131  if (fnd == cellsToCoarseFace.end())
132  {
133  // New coarse face
134  label coarseI = dynFaceCells.size();
135  dynFaceRestrictAddressing.append(coarseI);
136  dynFaceCells.append(localRestrictAddressing[ffi]);
137  cellsToCoarseFace.insert(cellPair, coarseI);
138  }
139  else
140  {
141  // Already have coarse face
142  dynFaceRestrictAddressing.append(fnd());
143  }
144  }
145 
146  faceCells_.transfer(dynFaceCells);
147  faceRestrictAddressing_.transfer(dynFaceRestrictAddressing);
148 }
149 
150 
152 (
153  const label index,
154  const lduInterfacePtrsList& coarseInterfaces,
155  Istream& is
156 )
157 :
158  GAMGInterface(index, coarseInterfaces, is),
159  nbrPatchID_(readLabel(is)),
160  owner_(readBool(is)),
161  transform_(is)
162 {}
163 
164 
165 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
166 
168 {}
169 
170 
171 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
172 
174 (
175  const Pstream::commsTypes,
176  const labelUList& iF
177 ) const
178 {
179  const cyclicGAMGInterface& nbr = nbrPatch();
180  const labelUList& nbrFaceCells = nbr.faceCells();
181 
182  tmp<labelField> tpnf(new labelField(size()));
183  labelField& pnf = tpnf.ref();
184 
185  forAll(pnf, facei)
186  {
187  pnf[facei] = iF[nbrFaceCells[facei]];
188  }
189 
190  return tpnf;
191 }
192 
193 
195 {
197  os << token::SPACE << nbrPatchID_
198  << token::SPACE << owner_
199  << token::SPACE << transform_;
200 }
201 
202 
203 // ************************************************************************* //
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
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
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:174
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
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)
addNamedToRunTimeSelectionTable(GAMGProcAgglomeration, noneGAMGProcAgglomeration, GAMGAgglomeration, none)
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,.
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:477