calculatedProcessorGAMGInterface.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) 2019 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26\*---------------------------------------------------------------------------*/
27
30#include "labelPairHashes.H"
31
32// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33
34namespace Foam
35{
38 (
42 );
44 (
48 );
49}
50
51
52// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
53
55(
56 const label index,
57 const lduInterfacePtrsList& coarseInterfaces,
58 const lduInterface& fineInterface,
59 const labelField& localRestrictAddressing,
60 const labelField& neighbourRestrictAddressing,
61 const label fineLevelIndex,
62 const label coarseComm
63)
64:
66 (
67 index,
68 coarseInterfaces
69 ),
70 comm_(coarseComm),
71 myProcNo_(refCast<const processorLduInterface>(fineInterface).myProcNo()),
72 neighbProcNo_
73 (
74 refCast<const processorLduInterface>(fineInterface).neighbProcNo()
75 ),
76 forwardT_(refCast<const processorLduInterface>(fineInterface).forwardT()),
77 tag_(refCast<const processorLduInterface>(fineInterface).tag())
78{
79 // From coarse face to coarse cell
80 DynamicList<label> dynFaceCells(localRestrictAddressing.size());
81 // From fine face to coarse face
82 DynamicList<label> dynFaceRestrictAddressing
83 (
84 localRestrictAddressing.size()
85 );
86
87 // From coarse cell pair to coarse face
88 labelPairLookup cellsToCoarseFace(2*localRestrictAddressing.size());
89
90 forAll(localRestrictAddressing, ffi)
91 {
92 labelPair cellPair;
93
94 // Do switching on master/slave indexes based on the owner/neighbour of
95 // the processor index such that both sides get the same answer.
96 if (myProcNo() < neighbProcNo())
97 {
98 // Master side
99 cellPair = labelPair
100 (
101 localRestrictAddressing[ffi],
102 neighbourRestrictAddressing[ffi]
103 );
104 }
105 else
106 {
107 // Slave side
108 cellPair = labelPair
109 (
110 neighbourRestrictAddressing[ffi],
111 localRestrictAddressing[ffi]
112 );
113 }
114
115 const auto fnd = cellsToCoarseFace.cfind(cellPair);
116
117 if (fnd.found())
118 {
119 // Already have coarse face
120 dynFaceRestrictAddressing.append(fnd.val());
121 }
122 else
123 {
124 // New coarse face
125 label coarseI = dynFaceCells.size();
126 dynFaceRestrictAddressing.append(coarseI);
127 dynFaceCells.append(localRestrictAddressing[ffi]);
128 cellsToCoarseFace.insert(cellPair, coarseI);
129 }
130 }
131
132 faceCells_.transfer(dynFaceCells);
133 faceRestrictAddressing_.transfer(dynFaceRestrictAddressing);
134}
135
136
138(
139 const label index,
140 const lduInterfacePtrsList& coarseInterfaces,
141 const labelUList& faceCells,
142 const labelUList& faceRestrictAddresssing,
143 const label coarseComm,
144 const label myProcNo,
145 const label neighbProcNo,
146 const tensorField& forwardT,
147 const int tag
148)
149:
151 (
152 index,
153 coarseInterfaces,
154 faceCells,
155 faceRestrictAddresssing
156 ),
157 comm_(coarseComm),
158 myProcNo_(myProcNo),
159 neighbProcNo_(neighbProcNo),
160 forwardT_(forwardT),
161 tag_(tag)
162{}
163
164
166(
167 const label index,
168 const lduInterfacePtrsList& coarseInterfaces,
169 Istream& is
170)
171:
172 GAMGInterface(index, coarseInterfaces, is),
173 comm_(readLabel(is)),
174 myProcNo_(readLabel(is)),
175 neighbProcNo_(readLabel(is)),
176 forwardT_(is),
177 tag_(readLabel(is))
178{}
179
180
181// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
182
184(
185 const Pstream::commsTypes commsType,
186 const labelUList& iF
187) const
188{
189 send(commsType, interfaceInternalField(iF)());
190}
191
192
195(
196 const Pstream::commsTypes commsType,
197 const labelUList& iF
198) const
199{
200 tmp<labelField> tfld(receive<label>(commsType, this->size()));
201
202 return tfld;
203}
204
205
208(
209 const Pstream::commsTypes commsType,
210 const labelUList& iF,
211 const labelUList& faceCells
212) const
213{
215
216 return tmp<labelField>::New(this->size(), Zero);
217}
218
219
221{
223 os << token::SPACE << comm_
224 << token::SPACE << myProcNo_
225 << token::SPACE << neighbProcNo_
226 << token::SPACE << forwardT_
227 << token::SPACE << tag_;
228}
229
230
231// ************************************************************************* //
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
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
Definition: Time.C:717
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
commsTypes
Types of communications.
Definition: UPstream.H:67
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)
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
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
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:517
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
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333