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 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.found())
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  }
144 
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 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
166 
168 (
169  const Pstream::commsTypes commsType,
170  const labelUList& iF
171 ) const
172 {
173  const cyclicGAMGInterface& nbr = neighbPatch();
174  const labelUList& nbrFaceCells = nbr.faceCells();
175 
176  tmp<labelField> tpnf(new labelField(size()));
177  labelField& pnf = tpnf.ref();
178 
179  forAll(pnf, facei)
180  {
181  pnf[facei] = iF[nbrFaceCells[facei]];
182  }
183 
184  return tpnf;
185 }
186 
187 
189 {
191  os << token::SPACE << neighbPatchID_
192  << token::SPACE << owner_
193  << token::SPACE << forwardT_
194  << token::SPACE << reverseT_;
195 }
196 
197 
198 // ************************************************************************* //
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
Foam::GAMGInterface::write
virtual void write(Ostream &) const =0
Write to stream.
Definition: GAMGInterface.C:125
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::DynamicList< label >
Foam::lduInterface
An abstract base class for implicitly-coupled interfaces e.g. processor and cyclic patches.
Definition: lduInterface.H:54
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::labelPair
Pair< label > labelPair
A pair of labels.
Definition: Pair.H:54
labelPairHashes.H
A HashTable to objects of type <T> with a labelPair key. The hashing is based on labelPair (FixedList...
Foam::tmp::ref
T & ref() const
Definition: tmpI.H:227
Foam::Field< label >
Foam::labelField
Field< label > labelField
Specialisation of Field<T> for label.
Definition: labelField.H:52
Foam::GAMGInterface::faceCells
virtual const labelUList & faceCells() const
Return faceCell addressing.
Definition: GAMGInterface.H:221
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::cyclicGAMGInterface::write
virtual void write(Ostream &os) const
Write to stream.
Definition: cyclicGAMGInterface.C:188
Foam::readBool
bool readBool(Istream &is)
Read bool from stream using Foam::Switch(Istream&)
Definition: bool.C:75
Foam::GAMGInterface
Abstract base class for GAMG agglomerated interfaces.
Definition: GAMGInterface.H:54
Foam::addNamedToRunTimeSelectionTable
addNamedToRunTimeSelectionTable(topoSetCellSource, badQualityToCell, word, badQuality)
cyclicGAMGInterface.H
Foam::UPtrList< const lduInterface >
os
OBJstream os(runTime.globalPath()/outputName)
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::HashTable< label, labelPair, Foam::Hash< labelPair > >
Foam::UPstream::commsTypes
commsTypes
Types of communications.
Definition: UPstream.H:69
Foam::cyclicGAMGInterface::internalFieldTransfer
virtual tmp< labelField > internalFieldTransfer(const Pstream::commsTypes commsType, const labelUList &iF) const
Transfer and return internal field adjacent to the interface.
Definition: cyclicGAMGInterface.C:168
Foam::Pair< label >
Foam::readLabel
label readLabel(const char *buf)
Parse entire buffer as a label, skipping leading/trailing whitespace.
Definition: label.H:66
Foam::token::SPACE
Space [isspace].
Definition: token.H:125
Foam::UList< label >
Foam::cyclicGAMGInterface
GAMG agglomerated cyclic interface.
Definition: cyclicGAMGInterface.H:52
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)