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-------------------------------------------------------------------------------
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
29#include "cyclicGAMGInterface.H"
31#include "labelPairHashes.H"
32
33// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34
35namespace Foam
36{
39 (
43 );
45 (
49 );
50
51
52 // Add under name cyclicSlip
54 (
58 cyclicSlip
59 );
61 (
64 Istream,
65 cyclicSlip
66 );
67}
68
69
70// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
71
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
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// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
#define addNamedToRunTimeSelectionTable(baseType, thisType, argNames, lookupName)
Add to construction table with 'lookupName' as the key.
#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
virtual const labelUList & faceCells() const
Return faceCell addressing.
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
GAMG agglomerated cyclic interface.
virtual bool owner() const
virtual tmp< labelField > internalFieldTransfer(const Pstream::commsTypes commsType, const labelUList &iF) const
Transfer and return internal field adjacent to the interface.
An abstract base class for cyclic coupled interfaces.
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
A class for managing temporary objects.
Definition: tmp.H:65
T & ref() const
Definition: tmpI.H:227
@ 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
Field< label > labelField
Specialisation of Field<T> for label.
Definition: labelField.H:52
bool readBool(Istream &is)
Read bool from stream using Foam::Switch(Istream&)
Definition: bool.C:69
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333