processorGAMGInterface.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-2017 OpenFOAM Foundation
9 Copyright (C) 2019 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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
31#include "labelPairHashes.H"
32
33// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34
35namespace Foam
36{
39 (
43 );
45 (
49 );
50}
51
52
53// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
54
56(
57 const label index,
58 const lduInterfacePtrsList& coarseInterfaces,
59 const lduInterface& fineInterface,
60 const labelField& localRestrictAddressing,
61 const labelField& neighbourRestrictAddressing,
62 const label fineLevelIndex,
63 const label coarseComm
64)
65:
67 (
68 index,
69 coarseInterfaces
70 ),
71 comm_(coarseComm),
72 myProcNo_(refCast<const processorLduInterface>(fineInterface).myProcNo()),
73 neighbProcNo_
74 (
75 refCast<const processorLduInterface>(fineInterface).neighbProcNo()
76 ),
77 forwardT_(refCast<const processorLduInterface>(fineInterface).forwardT()),
78 tag_(refCast<const processorLduInterface>(fineInterface).tag())
79{
80 // From coarse face to coarse cell
81 DynamicList<label> dynFaceCells(localRestrictAddressing.size());
82 // From fine face to coarse face
83 DynamicList<label> dynFaceRestrictAddressing
84 (
85 localRestrictAddressing.size()
86 );
87
88 // From coarse cell pair to coarse face
89 labelPairLookup cellsToCoarseFace(2*localRestrictAddressing.size());
90
91 forAll(localRestrictAddressing, ffi)
92 {
93 labelPair cellPair;
94
95 // Do switching on master/slave indexes based on the owner/neighbour of
96 // the processor index such that both sides get the same answer.
97 if (myProcNo() < neighbProcNo())
98 {
99 // Master side
100 cellPair = labelPair
101 (
102 localRestrictAddressing[ffi],
103 neighbourRestrictAddressing[ffi]
104 );
105 }
106 else
107 {
108 // Slave side
109 cellPair = labelPair
110 (
111 neighbourRestrictAddressing[ffi],
112 localRestrictAddressing[ffi]
113 );
114 }
115
116 const auto fnd = cellsToCoarseFace.cfind(cellPair);
117
118 if (fnd.found())
119 {
120 // Already have coarse face
121 dynFaceRestrictAddressing.append(fnd.val());
122 }
123 else
124 {
125 // New coarse face
126 label coarseI = dynFaceCells.size();
127 dynFaceRestrictAddressing.append(coarseI);
128 dynFaceCells.append(localRestrictAddressing[ffi]);
129 cellsToCoarseFace.insert(cellPair, coarseI);
130 }
131 }
132
133 faceCells_.transfer(dynFaceCells);
134 faceRestrictAddressing_.transfer(dynFaceRestrictAddressing);
135}
136
137
139(
140 const label index,
141 const lduInterfacePtrsList& coarseInterfaces,
142 const labelUList& faceCells,
143 const labelUList& faceRestrictAddresssing,
144 const label coarseComm,
145 const label myProcNo,
146 const label neighbProcNo,
147 const tensorField& forwardT,
148 const int tag
149)
150:
152 (
153 index,
154 coarseInterfaces,
155 faceCells,
156 faceRestrictAddresssing
157 ),
158 comm_(coarseComm),
159 myProcNo_(myProcNo),
160 neighbProcNo_(neighbProcNo),
161 forwardT_(forwardT),
162 tag_(tag)
163{}
164
165
167(
168 const label index,
169 const lduInterfacePtrsList& coarseInterfaces,
170 Istream& is
171)
172:
173 GAMGInterface(index, coarseInterfaces, is),
174 comm_(readLabel(is)),
175 myProcNo_(readLabel(is)),
176 neighbProcNo_(readLabel(is)),
177 forwardT_(is),
178 tag_(readLabel(is))
179{}
180
181
182// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
183
185(
186 const Pstream::commsTypes commsType,
187 const labelUList& iF
188) const
189{
190 send(commsType, interfaceInternalField(iF)());
191}
192
193
195(
196 const Pstream::commsTypes commsType,
197 const labelUList& iF,
198 const labelUList& faceCells
199) const
200{
201 send(commsType, interfaceInternalField(iF, faceCells)());
202}
203
204
206(
207 const Pstream::commsTypes commsType,
208 const labelUList& iF
209) const
210{
211 tmp<labelField> tfld(receive<label>(commsType, this->size()));
212
213 return tfld;
214}
215
216
218{
220 os << token::SPACE << comm_
221 << token::SPACE << myProcNo_
222 << token::SPACE << neighbProcNo_
223 << token::SPACE << forwardT_
224 << token::SPACE << tag_;
225}
226
227
228// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:72
void append(const T &val)
Copy append an element to the end of this list.
Definition: DynamicListI.H:503
Abstract base class for GAMG agglomerated interfaces.
Definition: GAMGInterface.H:57
labelList faceRestrictAddressing_
Face restrict addressing.
Definition: GAMGInterface.H:72
labelList faceCells_
Face-cell addressing.
Definition: GAMGInterface.H:69
const_iterator cfind(const Key &key) const
Find and return an const_iterator set at the hashed entry.
Definition: HashTableI.H:141
bool insert(const Key &key, const T &obj)
Copy insert a new entry, not overwriting existing entries.
Definition: HashTableI.H:180
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
void transfer(List< T > &list)
Definition: List.C:447
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
commsTypes
Types of communications.
Definition: UPstream.H:67
Smooth ATC in cells next to a set of patches supplied by type.
Definition: faceCells.H:59
virtual bool write()
Write the output fields.
An abstract base class for implicitly-coupled interfaces e.g. processor and cyclic patches.
Definition: lduInterface.H:58
GAMG agglomerated processor interface.
virtual int myProcNo() const
Return processor number (rank in communicator)
virtual void initInternalFieldTransfer(const Pstream::commsTypes commsType, const labelUList &iF) const
Initialise neighbour field transfer.
virtual tmp< labelField > internalFieldTransfer(const Pstream::commsTypes commsType, const labelUList &iF) const
Transfer and return internal field adjacent to the interface.
virtual int neighbProcNo() const
Return neighbour processor number (rank in communicator)
An abstract base class for processor coupled interfaces.
A class for managing temporary objects.
Definition: tmp.H:65
@ SPACE
Space [isspace].
Definition: token.H:125
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
OBJstream os(runTime.globalPath()/outputName)
A HashTable to objects of type <T> with a labelPair key. The hashing is based on labelPair (FixedList...
Namespace for OpenFOAM.
Pair< label > labelPair
A pair of labels.
Definition: Pair.H:57
To & refCast(From &r)
Reference type cast template function.
Definition: typeInfo.H:131
label readLabel(const char *buf)
Parse entire buffer as a label, skipping leading/trailing whitespace.
Definition: label.H:66
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333