faFieldDecomposer.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) 2016-2017 Wikki Ltd
9  Copyright (C) 2021 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
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 "faFieldDecomposer.H"
30 
31 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
32 
34 (
35  const label sizeBeforeMapping,
36  const labelUList& addressingSlice,
37  const label addressingOffset
38 )
39 :
40  sizeBeforeMapping_(sizeBeforeMapping),
41  directAddressing_(addressingSlice)
42 {
43  forAll(directAddressing_, i)
44  {
45  // Subtract one to align addressing.
46  // directAddressing_[i] -= addressingOffset + 1;
47  // ZT, 12/Nov/2010
48  directAddressing_[i] -= addressingOffset;
49  }
50 }
51 
52 
55 (
56  const label nTotalFaces,
57  const labelUList& owner, // == mesh.edgeOwner()
58  const labelUList& neigh, // == mesh.edgeNeighbour()
59  const labelUList& addressingSlice,
60  const scalarField& weights
61 )
62 :
63  sizeBeforeMapping_(nTotalFaces),
64  addressing_(addressingSlice.size()),
65  weights_(addressingSlice.size())
66 {
67  forAll(addressing_, i)
68  {
69  // Subtract one to align addressing.
70  label ai = addressingSlice[i];
71 // label ai = mag(addressingSlice[i]) - 1;
72 
73  if (ai < neigh.size())
74  {
75  // This is a regular edge. it has been an internal edge
76  // of the original mesh and now it has become a edge
77  // on the parallel boundary
78  addressing_[i].resize(2);
79  weights_[i].resize(2);
80 
81  addressing_[i][0] = owner[ai];
82  addressing_[i][1] = neigh[ai];
83 
84  if (ai < weights.size())
85  {
86  // Edge weights exist/are usable
87  weights_[i][0] = weights[ai];
88  weights_[i][1] = 1.0 - weights[ai];
89  }
90  else
91  {
92  // No edge weights. use equal weighting
93  weights_[i][0] = 0.5;
94  weights_[i][1] = 0.5;
95  }
96  }
97  else
98  {
99  // This is a edge that used to be on a cyclic boundary
100  // but has now become a parallel patch edge. I cannot
101  // do the interpolation properly (I would need to look
102  // up the different (edge) list of data), so I will
103  // just grab the value from the owner face
104 
105  addressing_[i].resize(1);
106  weights_[i].resize(1);
107 
108  addressing_[i][0] = owner[ai];
109 
110  weights_[i][0] = 1.0;
111  }
112  }
113 }
114 
115 
118 (
119  const faMesh& mesh,
120  const labelUList& addressingSlice
121 )
122 :
124  (
125  mesh.nFaces(),
126  mesh.edgeOwner(),
127  mesh.edgeNeighbour(),
128  addressingSlice,
129  mesh.weights().internalField()
130  )
131 {}
132 
133 
136 (
137  label sizeBeforeMapping,
138  const labelUList& addressingSlice
139 )
140 :
141  sizeBeforeMapping_(sizeBeforeMapping),
142  addressing_(addressingSlice.size()),
143  weights_(addressingSlice.size())
144 {
145  forAll(addressing_, i)
146  {
147  addressing_[i].resize(1);
148  weights_[i].resize(1);
149 
150  addressing_[i][0] = mag(addressingSlice[i]) - 1;
151  weights_[i][0] = sign(addressingSlice[i]);
152  }
153 }
154 
155 
156 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
157 
158 Foam::faFieldDecomposer::faFieldDecomposer
159 (
160  const Foam::zero,
161  const faMesh& procMesh,
162  const labelList& edgeAddressing,
163  const labelList& faceAddressing,
164  const labelList& boundaryAddressing
165 )
166 :
167  procMesh_(procMesh),
168  edgeAddressing_(edgeAddressing),
169  faceAddressing_(faceAddressing),
170  boundaryAddressing_(boundaryAddressing),
171  // Mappers
172  patchFieldDecomposerPtrs_(),
173  processorAreaPatchFieldDecomposerPtrs_(),
174  processorEdgePatchFieldDecomposerPtrs_()
175 {}
176 
177 
178 Foam::faFieldDecomposer::faFieldDecomposer
179 (
180  const faMesh& completeMesh,
181  const faMesh& procMesh,
182  const labelList& edgeAddressing,
183  const labelList& faceAddressing,
184  const labelList& boundaryAddressing
185 )
186 :
188  (
189  zero{},
190  procMesh,
191  edgeAddressing,
192  faceAddressing,
193  boundaryAddressing
194  )
195 {
196  reset(completeMesh);
197 }
198 
199 
200 Foam::faFieldDecomposer::faFieldDecomposer
201 (
202  const label nTotalFaces,
203  const List<labelRange>& boundaryRanges,
204  const labelUList& edgeOwner,
205  const labelUList& edgeNeigbour,
206 
207  const faMesh& procMesh,
208  const labelList& edgeAddressing,
209  const labelList& faceAddressing,
210  const labelList& boundaryAddressing
211 )
212 :
214  (
215  zero{},
216  procMesh,
217  edgeAddressing,
218  faceAddressing,
219  boundaryAddressing
220  )
221 {
222  reset(nTotalFaces, boundaryRanges, edgeOwner, edgeNeigbour);
223 }
224 
225 
226 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
227 
229 {
230  return patchFieldDecomposerPtrs_.empty();
231 }
232 
233 
235 {
236  patchFieldDecomposerPtrs_.clear();
237  processorAreaPatchFieldDecomposerPtrs_.clear();
238  processorEdgePatchFieldDecomposerPtrs_.clear();
239 }
240 
241 
243 (
244  const label nTotalFaces,
245  const List<labelRange>& boundaryRanges,
246  const labelUList& edgeOwner,
247  const labelUList& edgeNeigbour
248 )
249 {
250  clear();
251  const label nMappers = procMesh_.boundary().size();
252 
253  patchFieldDecomposerPtrs_.resize(nMappers);
254  processorAreaPatchFieldDecomposerPtrs_.resize(nMappers);
255  processorEdgePatchFieldDecomposerPtrs_.resize(nMappers);
256 
257  forAll(boundaryAddressing_, patchi)
258  {
259  const label oldPatchi = boundaryAddressing_[patchi];
260  const faPatch& fap = procMesh_.boundary()[patchi];
261  const labelSubList localPatchSlice(fap.patchSlice(edgeAddressing_));
262 
263  if (oldPatchi >= 0)
264  {
265  patchFieldDecomposerPtrs_.set
266  (
267  patchi,
269  (
270  boundaryRanges[oldPatchi].size(),
271  localPatchSlice,
272  boundaryRanges[oldPatchi].start()
273  )
274  );
275  }
276  else
277  {
278  processorAreaPatchFieldDecomposerPtrs_.set
279  (
280  patchi,
282  (
283  nTotalFaces,
284  edgeOwner,
285  edgeNeigbour,
286  localPatchSlice
287  )
288  );
289 
290  processorEdgePatchFieldDecomposerPtrs_.set
291  (
292  patchi,
294  (
295  procMesh_.boundary()[patchi].size(),
296  localPatchSlice
297  )
298  );
299  }
300  }
301 }
302 
303 
304 void Foam::faFieldDecomposer::reset(const faMesh& completeMesh)
305 {
306  clear();
307  const label nMappers = procMesh_.boundary().size();
308  patchFieldDecomposerPtrs_.resize(nMappers);
309  processorAreaPatchFieldDecomposerPtrs_.resize(nMappers);
310  processorEdgePatchFieldDecomposerPtrs_.resize(nMappers);
311 
312  // Create weightings now - needed for proper parallel synchronization
313  (void)completeMesh.weights();
314 
315  // faPatches don't have their own start() - so these are invariant
316  const labelList completePatchStarts
317  (
318  completeMesh.boundary().patchStarts()
319  );
320 
321  forAll(boundaryAddressing_, patchi)
322  {
323  const label oldPatchi = boundaryAddressing_[patchi];
324  const faPatch& fap = procMesh_.boundary()[patchi];
325  const labelSubList localPatchSlice(fap.patchSlice(edgeAddressing_));
326 
327  if (oldPatchi >= 0)
328  {
329  patchFieldDecomposerPtrs_.set
330  (
331  patchi,
333  (
334  completeMesh.boundary()[oldPatchi].size(),
335  localPatchSlice,
336  completePatchStarts[oldPatchi]
337  )
338  );
339  }
340  else
341  {
342  processorAreaPatchFieldDecomposerPtrs_.set
343  (
344  patchi,
346  (
347  completeMesh,
348  localPatchSlice
349  )
350  );
351 
352  processorEdgePatchFieldDecomposerPtrs_.set
353  (
354  patchi,
356  (
357  procMesh_.boundary()[patchi].size(),
358  localPatchSlice
359  )
360  );
361  }
362  }
363 }
364 
365 
366 // ************************************************************************* //
Foam::faFieldDecomposer::processorAreaPatchFieldDecomposer
Processor patch field decomposer class.
Definition: faFieldDecomposer.H:118
Foam::faFieldDecomposer::empty
bool empty() const
True if no mappers have been allocated.
Definition: faFieldDecomposer.C:228
Foam::faFieldDecomposer
Finite Area area and edge field decomposer.
Definition: faFieldDecomposer.H:61
Foam::SubList
A List obtained as a section of another List.
Definition: SubList.H:54
Foam::faFieldDecomposer::clear
void clear()
Remove all mappers.
Definition: faFieldDecomposer.C:234
Foam::sign
dimensionedScalar sign(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:166
Foam::faFieldDecomposer::patchFieldDecomposer::patchFieldDecomposer
patchFieldDecomposer(const label sizeBeforeMapping, const labelUList &addressingSlice, const label addressingOffset)
Construct given addressing.
Definition: faFieldDecomposer.C:34
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::Field< scalar >
Foam::faFieldDecomposer::processorEdgePatchFieldDecomposer
Processor patch field decomposer class.
Definition: faFieldDecomposer.H:183
Foam::faFieldDecomposer::processorEdgePatchFieldDecomposer::processorEdgePatchFieldDecomposer
processorEdgePatchFieldDecomposer(label sizeBeforeMapping, const labelUList &addressingSlice)
Construct given addressing.
Definition: faFieldDecomposer.C:136
Foam::faPatch::patchSlice
List< T >::subList patchSlice(const List< T > &l) const
Slice list to patch.
Definition: faPatch.H:277
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::faMesh::boundary
const faBoundaryMesh & boundary() const noexcept
Return constant reference to boundary mesh.
Definition: faMeshI.H:38
Foam::edgeInterpolation::weights
const edgeScalarField & weights() const
Return reference to weighting factors array.
Definition: edgeInterpolation.C:90
reset
meshPtr reset(new Foam::fvMesh(Foam::IOobject(regionName, runTime.timeName(), runTime, Foam::IOobject::MUST_READ), false))
Foam::faFieldDecomposer::reset
void reset(const faMesh &completeMesh)
Reset mappers using information from the complete mesh.
Definition: faFieldDecomposer.C:304
clear
patchWriters clear()
Foam::faFieldDecomposer::patchFieldDecomposer
Patch field decomposer class.
Definition: faFieldDecomposer.H:66
Foam::List< label >
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Foam::UList< label >
Foam::faMesh
Finite area mesh. Used for 2-D non-Euclidian finite area method.
Definition: faMesh.H:82
Foam::UList::size
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
Foam::faPatch
Finite area patch class. Used for 2-D non-Euclidian finite area method.
Definition: faPatch.H:69
Foam::faBoundaryMesh::patchStarts
labelList patchStarts() const
Return a list of patch start indices.
Definition: faBoundaryMesh.C:220
Foam::zero
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:62
Foam::faFieldDecomposer::processorAreaPatchFieldDecomposer::processorAreaPatchFieldDecomposer
processorAreaPatchFieldDecomposer(const label nTotalFaces, const labelUList &edgeOwner, const labelUList &edgeNeigbour, const labelUList &addressingSlice, const scalarField &edgeWeights=scalarField::null())
Construct addressing from details.
Definition: faFieldDecomposer.C:55
faFieldDecomposer.H