Loading...
Searching...
No Matches
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,2023 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"
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
72Foam::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.good())
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 }
144
145 faceCells_.transfer(dynFaceCells);
146 faceRestrictAddressing_.transfer(dynFaceRestrictAddressing);
147}
148
149
150Foam::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
165Foam::cyclicGAMGInterface::cyclicGAMGInterface
166(
167 const label index,
168 const lduInterfacePtrsList& coarseInterfaces,
169 const lduInterface& fineInterface,
170 const labelList& interfaceMap,
171 const labelUList& faceCells,
172 const labelUList& faceRestrictAddresssing,
173 const labelUList& faceOffsets,
174 const lduInterfacePtrsList& allInterfaces
175)
176:
178 (
179 index,
180 coarseInterfaces,
181 faceCells,
182 faceRestrictAddresssing
183 ),
184 neighbPatchID_
185 (
186 interfaceMap.find
187 (
188 refCast<const cyclicLduInterface>(fineInterface).neighbPatchID()
189 )
190 ),
191 owner_(refCast<const cyclicLduInterface>(fineInterface).owner()),
192 forwardT_(refCast<const cyclicLduInterface>(fineInterface).forwardT()),
193 reverseT_(refCast<const cyclicLduInterface>(fineInterface).reverseT())
194{}
195
196
197// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
198
200(
201 const Pstream::commsTypes commsType,
202 const labelUList& iF
203) const
204{
205 const cyclicGAMGInterface& nbr = neighbPatch();
206 const labelUList& nbrFaceCells = nbr.faceCells();
207
208 auto tpnf = tmp<labelField>::New(size());
209 auto& pnf = tpnf.ref();
210
211 forAll(pnf, facei)
212 {
213 pnf[facei] = iF[nbrFaceCells[facei]];
214 }
215
216 return tpnf;
217}
218
219
220void Foam::cyclicGAMGInterface::write(Ostream& os) const
221{
223 os << token::SPACE << neighbPatchID_
224 << token::SPACE << owner_
225 << token::SPACE << forwardT_
226 << token::SPACE << reverseT_;
227}
228
229
230// ************************************************************************* //
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:68
void append(const T &val)
Copy append an element to the end of this list.
Abstract base class for GAMG agglomerated interfaces.
virtual label size() const
Return size.
labelList faceRestrictAddressing_
Face restrict addressing.
virtual label index() const
virtual const lduInterfacePtrsList & coarseInterfaces() const
virtual const labelUList & faceCells() const
Return faceCell addressing.
labelList faceCells_
Face-cell addressing.
GAMGInterface(const GAMGInterface &)=delete
No copy construct.
virtual void write(Ostream &) const =0
Write to stream.
const_iterator cfind(const Key &key) const
Find and return an const_iterator set at the hashed entry.
Definition HashTableI.H:113
bool insert(const Key &key, const T &obj)
Copy insert a new entry, not overwriting existing entries.
Definition HashTableI.H:152
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition Istream.H:60
void transfer(List< T > &list)
Transfer the contents of the argument List into this list and annul the argument list.
Definition List.C:347
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
void size(const label n)
Older name for setAddressableSize.
Definition UList.H:118
commsTypes
Communications types.
Definition UPstream.H:81
GAMG agglomerated cyclic interface.
virtual const tensorField & reverseT() const
Return neighbour-cell transformation tensor.
virtual label neighbPatchID() const
Cyclic interface functions.
virtual void write(Ostream &os) const
Write to stream.
virtual const cyclicGAMGInterface & neighbPatch() const
Return processor number.
virtual tmp< labelField > internalFieldTransfer(const Pstream::commsTypes commsType, const labelUList &iF) const
Transfer and return internal field adjacent to the interface.
virtual const tensorField & forwardT() const
Return face transformation tensor.
An abstract base class for cyclic coupled interfaces.
cyclicLduInterface() noexcept=default
Default construct.
Smooth ATC in cells next to a set of patches supplied by type.
Definition faceCells.H:55
An abstract base class for implicitly-coupled interfaces e.g. processor and cyclic patches.
A class for managing temporary objects.
Definition tmp.H:75
static tmp< T > New(Args &&... args)
Construct tmp with forwarding arguments.
Definition tmp.H:215
@ SPACE
Space [isspace].
Definition token.H:144
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition className.H:142
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.
Type & refCast(U &obj)
A dynamic_cast (for references) to Type reference.
Definition typeInfo.H:172
Pair< label > labelPair
A pair of labels.
Definition Pair.H:54
List< label > labelList
A List of labels.
Definition List.H:62
label readLabel(const char *buf)
Parse entire buffer as a label, skipping leading/trailing whitespace.
Definition label.H:63
UPtrList< const lduInterface > lduInterfacePtrsList
Store lists of lduInterface as a UPtrList.
HashTable< label, labelPair, Foam::Hash< labelPair > > labelPairLookup
This is a Map of a labelPair to a label. Used for e.g. for face1, face2 to shared edge....
Field< label > labelField
Specialisation of Field<T> for label.
Definition labelField.H:48
UList< label > labelUList
A UList of labels.
Definition UList.H:75
bool readBool(Istream &is)
Read bool from stream using Foam::Switch(Istream&).
Definition bool.C:72
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299