cyclicAMIGAMGInterface.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "AMIInterpolation.H"
27 #include "cyclicAMIGAMGInterface.H"
29 #include "Map.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35  defineTypeNameAndDebug(cyclicAMIGAMGInterface, 0);
37  (
38  GAMGInterface,
39  cyclicAMIGAMGInterface,
40  lduInterface
41  );
42 }
43 
44 
45 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
46 
47 Foam::cyclicAMIGAMGInterface::cyclicAMIGAMGInterface
48 (
49  const label index,
50  const lduInterfacePtrsList& coarseInterfaces,
51  const lduInterface& fineInterface,
52  const labelField& localRestrictAddressing,
53  const labelField& neighbourRestrictAddressing,
54  const label fineLevelIndex,
55  const label coarseComm
56 )
57 :
59  (
60  index,
61  coarseInterfaces
62  ),
63  fineCyclicAMIInterface_
64  (
65  refCast<const cyclicAMILduInterface>(fineInterface)
66  ),
67  AMIs_(),
68  AMITransforms_()
69 {
70  // Construct face agglomeration from cell agglomeration
71  {
72  // From coarse face to cell
73  DynamicList<label> dynFaceCells(localRestrictAddressing.size());
74 
75  // From face to coarse face
76  DynamicList<label> dynFaceRestrictAddressing
77  (
78  localRestrictAddressing.size()
79  );
80 
81  Map<label> masterToCoarseFace(localRestrictAddressing.size());
82 
83  forAll(localRestrictAddressing, ffi)
84  {
85  label curMaster = localRestrictAddressing[ffi];
86 
87  Map<label>::const_iterator fnd = masterToCoarseFace.find
88  (
89  curMaster
90  );
91 
92  if (fnd == masterToCoarseFace.end())
93  {
94  // New coarse face
95  label coarseI = dynFaceCells.size();
96  dynFaceRestrictAddressing.append(coarseI);
97  dynFaceCells.append(curMaster);
98  masterToCoarseFace.insert(curMaster, coarseI);
99  }
100  else
101  {
102  // Already have coarse face
103  dynFaceRestrictAddressing.append(fnd());
104  }
105  }
106 
107  faceCells_.transfer(dynFaceCells);
108  faceRestrictAddressing_.transfer(dynFaceRestrictAddressing);
109  }
110 
111 
112  // On the owner side construct the AMI
113 
114  if (fineCyclicAMIInterface_.owner())
115  {
116  // Construct the neighbour side agglomeration (as the neighbour would
117  // do it so it the exact loop above using neighbourRestrictAddressing
118  // instead of localRestrictAddressing)
119 
120  labelList nbrFaceRestrictAddressing;
121  {
122  // From face to coarse face
123  DynamicList<label> dynNbrFaceRestrictAddressing
124  (
125  neighbourRestrictAddressing.size()
126  );
127 
128  Map<label> masterToCoarseFace(neighbourRestrictAddressing.size());
129 
130  forAll(neighbourRestrictAddressing, ffi)
131  {
132  label curMaster = neighbourRestrictAddressing[ffi];
133 
134  Map<label>::const_iterator fnd = masterToCoarseFace.find
135  (
136  curMaster
137  );
138 
139  if (fnd == masterToCoarseFace.end())
140  {
141  // New coarse face
142  label coarseI = masterToCoarseFace.size();
143  dynNbrFaceRestrictAddressing.append(coarseI);
144  masterToCoarseFace.insert(curMaster, coarseI);
145  }
146  else
147  {
148  // Already have coarse face
149  dynNbrFaceRestrictAddressing.append(fnd());
150  }
151  }
152 
153  nbrFaceRestrictAddressing.transfer(dynNbrFaceRestrictAddressing);
154  }
155 
156  AMIs_.resize(fineCyclicAMIInterface_.AMIs().size());
157  AMITransforms_.resize(fineCyclicAMIInterface_.AMITransforms().size());
158 
159  forAll(AMIs(), i)
160  {
161  AMIs_.set
162  (
163  i,
165  (
166  fineCyclicAMIInterface_.AMIs()[i],
167  faceRestrictAddressing_,
168  nbrFaceRestrictAddressing
169  )
170  );
171 
172  AMITransforms_[i] = fineCyclicAMIInterface_.AMITransforms()[i];
173  }
174  }
175 }
176 
177 
178 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
179 
181 {}
182 
183 
184 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
185 
187 (
188  const Pstream::commsTypes,
189  const labelUList& iF
190 ) const
191 {
192  const cyclicAMIGAMGInterface& nbr =
193  dynamic_cast<const cyclicAMIGAMGInterface&>(neighbPatch());
194 
195  const labelUList& nbrFaceCells = nbr.faceCells();
196 
197  tmp<labelField> tpnf(new labelField(nbrFaceCells.size()));
198  labelField& pnf = tpnf.ref();
199 
200  forAll(pnf, facei)
201  {
202  pnf[facei] = iF[nbrFaceCells[facei]];
203  }
204 
205  return tpnf;
206 }
207 
208 
209 // ************************************************************************* //
Field< label > labelField
Specialisation of Field<T> for label.
Definition: labelField.H:49
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
GAMG agglomerated cyclic AMI interface.
static iteratorEnd end()
iteratorEnd set to beyond the end of any HashTable
Definition: HashTable.H:110
virtual tmp< labelField > internalFieldTransfer(const Pstream::commsTypes commsType, const labelUList &iF) const
Transfer and return internal field adjacent to the interface.
commsTypes
Types of communications.
Definition: UPstream.H:64
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:174
virtual const labelUList & faceCells() const
Return faceCell addressing.
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:163
Macros for easy insertion into run-time selection tables.
iterator find(const Key &)
Find and return an iterator set at the hashedEntry.
Definition: HashTable.C:142
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:61
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
defineTypeNameAndDebug(combustionModel, 0)
Abstract base class for GAMG agglomerated interfaces.
Definition: GAMGInterface.H:51
Interpolation class dealing with transfer of data between two primitive patches with an arbitrary mes...
An abstract base class for implicitly-coupled interfaces e.g. processor and cyclic patches...
Definition: lduInterface.H:53
A class for managing temporary objects.
Definition: PtrList.H:53
label size() const
Return the number of elements in the UList.
Definition: UListI.H:299
virtual ~cyclicAMIGAMGInterface()
Destructor.
void transfer(List< T > &)
Transfer the contents of the argument List into this list.
Definition: List.C:342
Namespace for OpenFOAM.