cyclicAMIGAMGInterface.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 "AMIInterpolation.H"
32#include "Map.H"
33
34// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35
36namespace Foam
37{
40 (
44 );
45}
46
47
48// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
49
51(
52 const label index,
53 const lduInterfacePtrsList& coarseInterfaces,
54 const lduInterface& fineInterface,
55 const labelField& localRestrictAddressing,
56 const labelField& neighbourRestrictAddressing,
57 const label fineLevelIndex,
58 const label coarseComm
59)
60:
62 (
63 index,
64 coarseInterfaces
65 ),
66 fineCyclicAMIInterface_
67 (
68 refCast<const cyclicAMILduInterface>(fineInterface)
69 )
70{
71 // Construct face agglomeration from cell agglomeration
72 {
73 // From coarse face to cell
74 DynamicList<label> dynFaceCells(localRestrictAddressing.size());
75
76 // From face to coarse face
77 DynamicList<label> dynFaceRestrictAddressing
78 (
79 localRestrictAddressing.size()
80 );
81
82 Map<label> masterToCoarseFace(localRestrictAddressing.size());
83
84 for (const label curMaster : localRestrictAddressing)
85 {
86 const auto iter = masterToCoarseFace.cfind(curMaster);
87
88 if (iter.found())
89 {
90 // Already have coarse face
91 dynFaceRestrictAddressing.append(iter.val());
92 }
93 else
94 {
95 // New coarse face
96 const label coarseI = dynFaceCells.size();
97 dynFaceRestrictAddressing.append(coarseI);
98 dynFaceCells.append(curMaster);
99 masterToCoarseFace.insert(curMaster, coarseI);
100 }
101 }
102
103 faceCells_.transfer(dynFaceCells);
104 faceRestrictAddressing_.transfer(dynFaceRestrictAddressing);
105 }
106
107
108 // On the owner side construct the AMI
109
110 if (fineCyclicAMIInterface_.owner())
111 {
112 // Construct the neighbour side agglomeration (as the neighbour would
113 // do it so it the exact loop above using neighbourRestrictAddressing
114 // instead of localRestrictAddressing)
115
116 labelList nbrFaceRestrictAddressing;
117 {
118 // From face to coarse face
119 DynamicList<label> dynNbrFaceRestrictAddressing
120 (
121 neighbourRestrictAddressing.size()
122 );
123
124 Map<label> masterToCoarseFace(neighbourRestrictAddressing.size());
125
126 for (const label curMaster : neighbourRestrictAddressing)
127 {
128 const auto iter = masterToCoarseFace.cfind(curMaster);
129
130 if (iter.found())
131 {
132 // Already have coarse face
133 dynNbrFaceRestrictAddressing.append(iter.val());
134 }
135 else
136 {
137 // New coarse face
138 const label coarseI = masterToCoarseFace.size();
139 dynNbrFaceRestrictAddressing.append(coarseI);
140 masterToCoarseFace.insert(curMaster, coarseI);
141 }
142 }
143
144 nbrFaceRestrictAddressing.transfer(dynNbrFaceRestrictAddressing);
145 }
146
147 amiPtr_.reset
148 (
150 (
151 fineCyclicAMIInterface_.AMI(),
153 nbrFaceRestrictAddressing
154 )
155 );
156 }
157}
158
159
160// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
161
163{}
164
165
166// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
167
169(
170 const Pstream::commsTypes commsType,
171 const labelUList& iF
172) const
173{
174 const cyclicAMIGAMGInterface& nbr =
175 dynamic_cast<const cyclicAMIGAMGInterface&>(neighbPatch());
176 const labelUList& nbrFaceCells = nbr.faceCells();
177
178 tmp<labelField> tpnf(new labelField(nbrFaceCells.size()));
179 labelField& pnf = tpnf.ref();
180
181 forAll(pnf, facei)
182 {
183 pnf[facei] = iF[nbrFaceCells[facei]];
184 }
185
186 return tpnf;
187}
188
189// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
Interpolation class dealing with transfer of data between two primitive patches with an arbitrary mes...
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
label size() const noexcept
The number of elements in table.
Definition: HashTableI.H:52
void transfer(List< T > &list)
Definition: List.C:447
A HashTable to objects of type <T> with a label key.
Definition: Map.H:60
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
commsTypes
Types of communications.
Definition: UPstream.H:67
GAMG agglomerated cyclic AMI interface.
virtual ~cyclicAMIGAMGInterface()
Destructor.
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 AMI coupled interfaces.
virtual const AMIPatchToPatchInterpolation & AMI() const =0
virtual bool owner() const =0
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
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
Namespace for OpenFOAM.
To & refCast(From &r)
Reference type cast template function.
Definition: typeInfo.H:131
Field< label > labelField
Specialisation of Field<T> for label.
Definition: labelField.H:52
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333