Loading...
Searching...
No Matches
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
31
32// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33
34namespace Foam
35{
38 (
42 );
44 (
48 );
49}
50
51
52// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
53
54Foam::calculatedProcessorGAMGInterface::calculatedProcessorGAMGInterface
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.good())
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 }
131
132 faceCells_.transfer(dynFaceCells);
133 faceRestrictAddressing_.transfer(dynFaceRestrictAddressing);
134}
135
136
137Foam::calculatedProcessorGAMGInterface::calculatedProcessorGAMGInterface
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:
150 GAMGInterface
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
165Foam::calculatedProcessorGAMGInterface::calculatedProcessorGAMGInterface
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
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
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: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.
tmp< Field< Type > > interfaceInternalField(const UList< Type > &internalData) const
Return the interface internal field of the given field.
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
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 void write(Ostream &os) const
Write to stream.
virtual int tag() const
Return message tag used for sending.
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).
virtual const tensorField & forwardT() const
Return face transformation tensor.
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.
An abstract base class for processor coupled interfaces.
processorLduInterface() noexcept=default
Default construct.
void receive(const UPstream::commsTypes commsType, UList< Type > &f) const
Raw receive function.
void send(const UPstream::commsTypes commsType, const UList< Type > &f) const
Raw send function.
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
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition error.H:688
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
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
static constexpr const zero Zero
Global zero (0).
Definition zero.H:127
Field< tensor > tensorField
Specialisation of Field<T> for tensor.
UList< label > labelUList
A UList of labels.
Definition UList.H:75
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299