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 | Copyright (C) 2011-2013 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 {
68  // Construct face agglomeration from cell agglomeration
69  {
70  // From coarse face to cell
71  DynamicList<label> dynFaceCells(localRestrictAddressing.size());
72 
73  // From face to coarse face
74  DynamicList<label> dynFaceRestrictAddressing
75  (
76  localRestrictAddressing.size()
77  );
78 
79  Map<label> masterToCoarseFace(localRestrictAddressing.size());
80 
81  forAll(localRestrictAddressing, ffi)
82  {
83  label curMaster = localRestrictAddressing[ffi];
84 
85  Map<label>::const_iterator fnd = masterToCoarseFace.find
86  (
87  curMaster
88  );
89 
90  if (fnd == masterToCoarseFace.end())
91  {
92  // New coarse face
93  label coarseI = dynFaceCells.size();
94  dynFaceRestrictAddressing.append(coarseI);
95  dynFaceCells.append(curMaster);
96  masterToCoarseFace.insert(curMaster, coarseI);
97  }
98  else
99  {
100  // Already have coarse face
101  dynFaceRestrictAddressing.append(fnd());
102  }
103  }
104 
105  faceCells_.transfer(dynFaceCells);
106  faceRestrictAddressing_.transfer(dynFaceRestrictAddressing);
107  }
108 
109 
110  // On the owner side construct the AMI
111 
112  if (fineCyclicAMIInterface_.owner())
113  {
114  // Construct the neighbour side agglomeration (as the neighbour would
115  // do it so it the exact loop above using neighbourRestrictAddressing
116  // instead of localRestrictAddressing)
117 
118  labelList nbrFaceRestrictAddressing;
119  {
120  // From face to coarse face
121  DynamicList<label> dynNbrFaceRestrictAddressing
122  (
123  neighbourRestrictAddressing.size()
124  );
125 
126  Map<label> masterToCoarseFace(neighbourRestrictAddressing.size());
127 
128  forAll(neighbourRestrictAddressing, ffi)
129  {
130  label curMaster = neighbourRestrictAddressing[ffi];
131 
132  Map<label>::const_iterator fnd = masterToCoarseFace.find
133  (
134  curMaster
135  );
136 
137  if (fnd == masterToCoarseFace.end())
138  {
139  // New coarse face
140  label coarseI = masterToCoarseFace.size();
141  dynNbrFaceRestrictAddressing.append(coarseI);
142  masterToCoarseFace.insert(curMaster, coarseI);
143  }
144  else
145  {
146  // Already have coarse face
147  dynNbrFaceRestrictAddressing.append(fnd());
148  }
149  }
150 
151  nbrFaceRestrictAddressing.transfer(dynNbrFaceRestrictAddressing);
152  }
153 
154  amiPtr_.reset
155  (
157  (
158  fineCyclicAMIInterface_.AMI(),
159  faceRestrictAddressing_,
160  nbrFaceRestrictAddressing
161  )
162  );
163  }
164 }
165 
166 
167 // * * * * * * * * * * * * * * * * Desstructor * * * * * * * * * * * * * * * //
168 
170 {}
171 
172 
173 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
174 
176 (
177  const Pstream::commsTypes,
178  const labelUList& iF
179 ) const
180 {
181  const cyclicAMIGAMGInterface& nbr =
182  dynamic_cast<const cyclicAMIGAMGInterface&>(neighbPatch());
183  const labelUList& nbrFaceCells = nbr.faceCells();
184 
185  tmp<labelField> tpnf(new labelField(nbrFaceCells.size()));
186  labelField& pnf = tpnf();
187 
188  forAll(pnf, facei)
189  {
190  pnf[facei] = iF[nbrFaceCells[facei]];
191  }
192 
193  return tpnf;
194 }
195 
196 
197 // ************************************************************************* //
virtual tmp< labelField > internalFieldTransfer(const Pstream::commsTypes commsType, const labelUList &iF) const
Transfer and return internal field adjacent to the interface.
void transfer(List< T > &)
Transfer the contents of the argument List into this list.
Definition: List.C:390
GAMG agglomerated cyclic AMI interface.
Field< label > labelField
Specialisation of Field<T> for label.
Definition: labelField.H:49
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
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
Namespace for OpenFOAM.
virtual const labelUList & faceCells() const
Return faceCell addressing.
virtual ~cyclicAMIGAMGInterface()
Destructor.
An abstract base class for implicitly-coupled interfaces e.g. processor and cyclic patches...
Definition: lduInterface.H:53
commsTypes
Types of communications.
Definition: UPstream.H:64
Interpolation class dealing with transfer of data between two primitive patches with an arbitrary mes...
#define forAll(list, i)
Definition: UList.H:421
label size() const
Return the number of elements in the UList.
Definition: UListI.H:299
Macros for easy insertion into run-time selection tables.
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:60
static iteratorEnd end()
iteratorEnd set to beyond the end of any HashTable
Definition: HashTable.H:106
Abstract base class for GAMG agglomerated interfaces.
Definition: GAMGInterface.H:51
iterator find(const Key &)
Find and return an iterator set at the hashedEntry.
Definition: HashTable.C:139
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
A class for managing temporary objects.
Definition: PtrList.H:118
defineTypeNameAndDebug(combustionModel, 0)