regionCoupledBaseGAMGInterface.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-2014 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"
29 #include "Map.H"
30 #include "polyMesh.H"
31 
32 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
33 
34 Foam::regionCoupledBaseGAMGInterface::regionCoupledBaseGAMGInterface
35 (
36  const label index,
37  const lduInterfacePtrsList& coarseInterfaces,
38  const lduInterface& fineInterface,
39  const labelField& localRestrictAddressing,
40  const labelField& neighbourRestrictAddressing,
41  const label fineLevelIndex,
42  const label coarseComm
43 )
44 :
46  (
47  index,
48  coarseInterfaces
49  ),
50  fineRegionCoupledLduInterface_
51  (
52  refCast<const regionCoupledLduInterface>(fineInterface)
53  )
54 {
55  // Construct face agglomeration from cell agglomeration
56  {
57  // From coarse face to cell
58  DynamicList<label> dynFaceCells(localRestrictAddressing.size());
59 
60  // From face to coarse face
61  DynamicList<label> dynFaceRestrictAddressing
62  (
63  localRestrictAddressing.size()
64  );
65 
66  Map<label> masterToCoarseFace(localRestrictAddressing.size());
67 
68  forAll(localRestrictAddressing, ffi)
69  {
70  label curMaster = localRestrictAddressing[ffi];
71 
72  Map<label>::const_iterator fnd = masterToCoarseFace.find
73  (
74  curMaster
75  );
76 
77  if (fnd == masterToCoarseFace.end())
78  {
79  // New coarse face
80  label coarseI = dynFaceCells.size();
81  dynFaceRestrictAddressing.append(coarseI);
82  dynFaceCells.append(curMaster);
83  masterToCoarseFace.insert(curMaster, coarseI);
84  }
85  else
86  {
87  // Already have coarse face
88  dynFaceRestrictAddressing.append(fnd());
89  }
90  }
91 
92  faceCells_.transfer(dynFaceCells);
93  faceRestrictAddressing_.transfer(dynFaceRestrictAddressing);
94  }
95 
96  /*
97  // On the owner side construct the AMI
98  if (fineRegionCoupledLduInterface_.owner())
99  {
100  const polyMesh& nbrMesh =
101  fineRegionCoupledLduInterface_.nbrMesh();
102 
103  if
104  (
105  nbrMesh.foundObject<GAMGAgglomeration>(GAMGAgglomeration::typeName)
106  )
107  {
108  const GAMGAgglomeration& nbrAgg = nbrMesh.thisDb().lookupObject
109  <
110  GAMGAgglomeration
111  >
112  (
113  GAMGAgglomeration::typeName
114  );
115 
116  label nbrLevel(-1);
117  if (nbrAgg.size() > fineLevelIndex)
118  {
119  nbrLevel = fineLevelIndex;
120  }
121  else
122  {
123  nbrLevel = nbrAgg.size() - 1;
124  }
125 
126  const labelField& nbrRestrictMap =
127  nbrAgg.restrictAddressing(nbrLevel);
128 
129  const labelUList& nbrFaceCells =
130  nbrLduInterface
131  (
132  nbrLevel,
133  neighbPatchID()
134  ).faceCells();
135 
136 
137  const IndirectList<label> nbrPatchRestrictMap
138  (
139  nbrRestrictMap,
140  nbrFaceCells
141  );
142 
143  labelList nbrFaceRestrictAddressing;
144  {
145  // From face to coarse face
146  DynamicList<label> dynNbrFaceRestrictAddressing
147  (
148  nbrPatchRestrictMap.size()
149  );
150 
151  Map<label> masterToCoarseFace(nbrPatchRestrictMap.size());
152 
153  forAll(nbrPatchRestrictMap, ffi)
154  {
155  label curMaster = nbrPatchRestrictMap[ffi];
156 
157  Map<label>::const_iterator fnd = masterToCoarseFace.find
158  (
159  curMaster
160  );
161 
162  if (fnd == masterToCoarseFace.end())
163  {
164  // New coarse face
165  label coarseI = masterToCoarseFace.size();
166  dynNbrFaceRestrictAddressing.append(coarseI);
167  masterToCoarseFace.insert(curMaster, coarseI);
168  }
169  else
170  {
171  // Already have coarse face
172  dynNbrFaceRestrictAddressing.append(fnd());
173  }
174  }
175 
176  nbrFaceRestrictAddressing.transfer
177  (
178  dynNbrFaceRestrictAddressing
179  );
180  }
181 
182  amiPtr_.reset
183  (
184  new AMIPatchToPatchInterpolation
185  (
186  fineRegionCoupledLduInterface_.AMI(),
187  faceRestrictAddressing_,
188  nbrFaceRestrictAddressing
189  )
190  );
191  }
192  else
193  {
194  FatalErrorIn
195  (
196  "regionCoupledBaseGAMGInterface::"
197  "regionCoupledBaseGAMGInterface"
198  "("
199  "const label index,"
200  "const lduInterfacePtrsList& coarseInterfaces,"
201  "const lduInterface& fineInterface,"
202  "const labelField& localRestrictAddressing,"
203  "const labelField& neighbourRestrictAddressing,"
204  "const label fineLevelIndex"
205  ")"
206  ) << " GAMGAgglomeration was not found in the nbr mesh. "
207  << " Check on the cacheAgglomeration flag in fvSolution"
208  << exit(FatalError);
209  }
210  }
211  */
212 
213 }
214 
215 
216 // * * * * * * * * * * * * * * * * Desstructor * * * * * * * * * * * * * * * //
217 
219 {}
220 
221 
222 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
223 
226 (
227  const Pstream::commsTypes,
228  const labelUList& iF
229 ) const
230 {
231 // WarningIn
232 // (
233 // "regionCoupledBaseGAMGInterface::internalFieldTransfer"
234 // "( const Pstream::commsTypes, const labelUList&)"
235 // " the internal field can not be transfered "
236 // " as the neighbFvPatch are in different meshes "
237 // );
238  /*
239  //const labelUList& nbrFaceCells = neighbPatch().faceCells();
240 
241  const labelUList& nbrFaceCells = nbrLduInterface().faceCells();
242 
243  tmp<labelField> tpnf(new labelField(nbrFaceCells.size()));
244  labelField& pnf = tpnf();
245 
246  forAll(pnf, facei)
247  {
248  pnf[facei] = iF[nbrFaceCells[facei]];
249  }
250  */
251  tmp<labelField> tpnf(new labelField(iF));
252 
253  return tpnf;
254 }
255 
256 
257 // ************************************************************************* //
virtual tmp< labelField > internalFieldTransfer(const Pstream::commsTypes commsType, const labelUList &iF) const
Transfer and return internal field adjacent to the 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
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
#define forAll(list, i)
Definition: UList.H:421
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
A class for managing temporary objects.
Definition: PtrList.H:118