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 | Copyright (C) 2011-2016 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 
70 Foam::cyclicGAMGInterface::cyclicGAMGInterface
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  neighbPatchID_
83  (
84  refCast<const cyclicLduInterface>(fineInterface).neighbPatchID()
85  ),
86  owner_(refCast<const cyclicLduInterface>(fineInterface).owner()),
87  forwardT_(refCast<const cyclicLduInterface>(fineInterface).forwardT()),
88  reverseT_(refCast<const cyclicLduInterface>(fineInterface).reverseT())
89 {
90  // From coarse face to coarse cell
91  DynamicList<label> dynFaceCells(localRestrictAddressing.size());
92  // From fine face to coarse face
93  DynamicList<label> dynFaceRestrictAddressing
94  (
95  localRestrictAddressing.size()
96  );
97 
98  // From coarse cell pair to coarse face
100  (
101  2*localRestrictAddressing.size()
102  );
103 
104  forAll(localRestrictAddressing, ffi)
105  {
106  labelPair cellPair;
107 
108  // Do switching on master/slave indexes based on the owner/neighbour of
109  // the processor index such that both sides get the same answer.
110  if (owner())
111  {
112  // Master side
113  cellPair = labelPair
114  (
115  localRestrictAddressing[ffi],
116  neighbourRestrictAddressing[ffi]
117  );
118  }
119  else
120  {
121  // Slave side
122  cellPair = labelPair
123  (
124  neighbourRestrictAddressing[ffi],
125  localRestrictAddressing[ffi]
126  );
127  }
128 
129  HashTable<label, labelPair, labelPair::Hash<>>::const_iterator fnd =
130  cellsToCoarseFace.find(cellPair);
131 
132  if (fnd == cellsToCoarseFace.end())
133  {
134  // New coarse face
135  label coarseI = dynFaceCells.size();
136  dynFaceRestrictAddressing.append(coarseI);
137  dynFaceCells.append(localRestrictAddressing[ffi]);
138  cellsToCoarseFace.insert(cellPair, coarseI);
139  }
140  else
141  {
142  // Already have coarse face
143  dynFaceRestrictAddressing.append(fnd());
144  }
145  }
146 
147  faceCells_.transfer(dynFaceCells);
148  faceRestrictAddressing_.transfer(dynFaceRestrictAddressing);
149 }
150 
151 
152 Foam::cyclicGAMGInterface::cyclicGAMGInterface
153 (
154  const label index,
155  const lduInterfacePtrsList& coarseInterfaces,
156  Istream& is
157 )
158 :
159  GAMGInterface(index, coarseInterfaces, is),
160  neighbPatchID_(readLabel(is)),
161  owner_(readBool(is)),
162  forwardT_(is),
163  reverseT_(is)
164 {}
165 
166 
167 // * * * * * * * * * * * * * * * * Desstructor * * * * * * * * * * * * * * * //
168 
170 {}
171 
172 
173 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
174 
176 (
177  const Pstream::commsTypes,
178  const labelUList& iF
179 ) const
180 {
181  const cyclicGAMGInterface& nbr = neighbPatch();
182  const labelUList& nbrFaceCells = nbr.faceCells();
183 
184  tmp<labelField> tpnf(new labelField(size()));
185  labelField& pnf = tpnf.ref();
186 
187  forAll(pnf, facei)
188  {
189  pnf[facei] = iF[nbrFaceCells[facei]];
190  }
191 
192  return tpnf;
193 }
194 
195 
197 {
199  os << token::SPACE << neighbPatchID_
200  << token::SPACE << owner_
201  << token::SPACE << forwardT_
202  << token::SPACE << reverseT_;
203 }
204 
205 
206 // ************************************************************************* //
Field< label > labelField
Specialisation of Field<T> for label.
Definition: labelField.H:49
virtual tmp< labelField > internalFieldTransfer(const Pstream::commsTypes commsType, const labelUList &iF) const
Transfer and return internal field adjacent to the interface.
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
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:106
commsTypes
Types of communications.
Definition: UPstream.H:64
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:76
virtual void write(Ostream &) const
Write to stream.
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:138
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:53
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:54
virtual const labelUList & faceCells() const
Return faceCell addressing.
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:174
virtual ~cyclicGAMGInterface()
Destructor.
Namespace for OpenFOAM.
GAMG agglomerated cyclic interface.