mapDistribute.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) 2015-2019 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 "mapDistribute.H"
31 #include "transformField.H"
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37  defineTypeNameAndDebug(mapDistribute, 0);
38 }
39 
40 
41 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
42 
43 template<>
44 void Foam::mapDistribute::transform::operator()
45 (
46  const vectorTensorTransform&,
47  const bool,
49 ) const {}
50 
51 template<>
52 void Foam::mapDistribute::transform::operator()
53 (
54  const coupledPolyPatch&,
56 ) const {}
57 
58 template<>
59 void Foam::mapDistribute::transform::operator()
60 (
61  const coupledPolyPatch&,
62  Map<label>&
63 ) const {}
64 
65 template<>
66 void Foam::mapDistribute::transform::operator()
67 (
68  const coupledPolyPatch&,
70 ) const {}
71 
72 
73 template<>
74 void Foam::mapDistribute::transform::operator()
75 (
76  const vectorTensorTransform&,
77  const bool,
79 ) const {}
80 
81 template<>
82 void Foam::mapDistribute::transform::operator()
83 (
84  const coupledPolyPatch&,
86 ) const {}
87 
88 template<>
89 void Foam::mapDistribute::transform::operator()
90 (
91  const coupledPolyPatch&,
93 ) const {}
94 
95 template<>
96 void Foam::mapDistribute::transform::operator()
97 (
98  const coupledPolyPatch&,
100 ) const {}
101 
102 
103 template<>
104 void Foam::mapDistribute::transform::operator()
105 (
106  const vectorTensorTransform&,
107  const bool,
108  List<bool>&
109 ) const {}
110 
111 template<>
112 void Foam::mapDistribute::transform::operator()
113 (
114  const coupledPolyPatch&,
115  UList<bool>&
116 ) const {}
117 
118 template<>
119 void Foam::mapDistribute::transform::operator()
120 (
121  const coupledPolyPatch&,
122  Map<bool>&
123 ) const {}
124 
125 template<>
126 void Foam::mapDistribute::transform::operator()
127 (
128  const coupledPolyPatch&,
130 ) const {}
131 
132 
134 {
136 
137  forAll(transformElements_, trafoI)
138  {
139  if (transformElements_[trafoI].size() > 0)
140  {
141  os << "transform " << trafoI << ':' << endl
142  << " start : " << transformStart_[trafoI] << endl
143  << " size : " << transformElements_[trafoI].size() << endl;
144  }
145  }
146 }
147 
148 
149 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
150 
152 :
153  mapDistributeBase(comm)
154 {}
155 
156 
158 :
159  mapDistributeBase(map),
160  transformElements_(map.transformElements_),
161  transformStart_(map.transformStart_)
162 {}
163 
164 
166 :
167  mapDistribute()
168 {
169  transfer(map);
170 }
171 
172 
174 (
175  const label constructSize,
176  labelListList&& subMap,
177  labelListList&& constructMap,
178  const bool subHasFlip,
179  const bool constructHasFlip,
180  const label comm
181 )
182 :
184  (
185  constructSize,
186  std::move(subMap),
187  std::move(constructMap),
188  subHasFlip,
189  constructHasFlip,
190  comm
191  )
192 {}
193 
194 
196 (
197  const label constructSize,
198  labelListList&& subMap,
199  labelListList&& constructMap,
200  labelListList&& transformElements,
201  labelList&& transformStart,
202  const bool subHasFlip,
203  const bool constructHasFlip,
204  const label comm
205 )
206 :
208  (
209  constructSize,
210  std::move(subMap),
211  std::move(constructMap),
212  subHasFlip,
213  constructHasFlip,
214  comm
215  ),
216  transformElements_(std::move(transformElements)),
217  transformStart_(std::move(transformStart))
218 {}
219 
220 
222 (
223  const labelUList& sendProcs,
224  const labelUList& recvProcs,
225  const label comm
226 )
227 :
228  mapDistributeBase(sendProcs, recvProcs, comm)
229 {}
230 
231 
233 (
234  const globalIndex& globalNumbering,
235  labelList& elements,
236  List<Map<label>>& compactMap,
237  const int tag,
238  const label comm
239 )
240 :
242  (
243  globalNumbering,
244  elements,
245  compactMap,
246  tag,
247  comm
248  )
249 {}
250 
251 
253 (
254  const globalIndex& globalNumbering,
255  labelListList& cellCells,
256  List<Map<label>>& compactMap,
257  const int tag,
258  const label comm
259 )
260 :
262  (
263  globalNumbering,
264  cellCells,
265  compactMap,
266  tag,
267  comm
268  )
269 {}
270 
271 
273 (
274  const globalIndex& globalNumbering,
275  labelList& elements,
276  const globalIndexAndTransform& globalTransforms,
277  const labelPairList& transformedElements,
278  labelList& transformedIndices,
279  List<Map<label>>& compactMap,
280  const int tag,
281  const label comm
282 )
283 :
284  mapDistributeBase(comm)
285 {
286  const label myRank = Pstream::myProcNo(comm);
287 
288  // Construct per processor compact addressing of the global elements
289  // needed. The ones from the local processor are not included since
290  // these are always all needed.
291  calcCompactAddressing
292  (
293  globalNumbering,
294  elements,
295  compactMap
296  );
297 
298  // Add all (non-local) transformed elements needed.
299  forAll(transformedElements, i)
300  {
301  labelPair elem = transformedElements[i];
302  label proci = globalTransforms.processor(elem);
303  if (proci != myRank)
304  {
305  label index = globalTransforms.index(elem);
306  label nCompact = compactMap[proci].size();
307  compactMap[proci].insert(index, nCompact);
308  }
309  }
310 
311 
312  // Exchange what I need with processor that supplies it. Renumber elements
313  // into compact numbering
314  labelList compactStart;
315  exchangeAddressing
316  (
317  tag,
318  globalNumbering,
319  elements,
320  compactMap,
321  compactStart
322  );
323 
324 
325  // Renumber the transformed elements
326  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
327  // Count per transformIndex
328  label nTrafo = globalTransforms.transformPermutations().size();
329  labelList nPerTransform(nTrafo, Zero);
330  forAll(transformedElements, i)
331  {
332  labelPair elem = transformedElements[i];
333  label trafoI = globalTransforms.transformIndex(elem);
334  nPerTransform[trafoI]++;
335  }
336  // Offset per transformIndex
337  transformStart_.setSize(nTrafo);
338  transformElements_.setSize(nTrafo);
339  forAll(transformStart_, trafoI)
340  {
341  transformStart_[trafoI] = constructSize_;
342  constructSize_ += nPerTransform[trafoI];
343  transformElements_[trafoI].setSize(nPerTransform[trafoI]);
344  }
345 
346  // Sort transformed elements into their new slot.
347  nPerTransform = 0;
348 
349  transformedIndices.setSize(transformedElements.size());
350  forAll(transformedElements, i)
351  {
352  labelPair elem = transformedElements[i];
353  label proci = globalTransforms.processor(elem);
354  label index = globalTransforms.index(elem);
355  label trafoI = globalTransforms.transformIndex(elem);
356 
357  // Get compact index for untransformed element
358  label rawElemI =
359  (
360  proci == myRank
361  ? index
362  : compactMap[proci][index]
363  );
364 
365  label& n = nPerTransform[trafoI];
366  // index of element to transform
367  transformElements_[trafoI][n] = rawElemI;
368  // destination of transformed element
369  transformedIndices[i] = transformStart_[trafoI]+n;
370  n++;
371  }
372 
373  if (debug)
374  {
375  printLayout(Pout);
376  }
377 }
378 
379 
381 (
382  const globalIndex& globalNumbering,
383  labelListList& cellCells,
384  const globalIndexAndTransform& globalTransforms,
385  const List<labelPairList>& transformedElements,
386  labelListList& transformedIndices,
387  List<Map<label>>& compactMap,
388  const int tag,
389  const label comm
390 )
391 :
392  mapDistributeBase(comm)
393 {
394  const label myRank = Pstream::myProcNo(comm_);
395 
396  // Construct per processor compact addressing of the global elements
397  // needed. The ones from the local processor are not included since
398  // these are always all needed.
399  calcCompactAddressing
400  (
401  globalNumbering,
402  cellCells,
403  compactMap
404  );
405 
406  // Add all (non-local) transformed elements needed.
407  forAll(transformedElements, celli)
408  {
409  const labelPairList& elems = transformedElements[celli];
410 
411  forAll(elems, i)
412  {
413  label proci = globalTransforms.processor(elems[i]);
414  if (proci != myRank)
415  {
416  label index = globalTransforms.index(elems[i]);
417  label nCompact = compactMap[proci].size();
418  compactMap[proci].insert(index, nCompact);
419  }
420  }
421  }
422 
423 
424  // Exchange what I need with processor that supplies it. Renumber elements
425  // into compact numbering
426  labelList compactStart;
427  exchangeAddressing
428  (
429  tag,
430  globalNumbering,
431  cellCells,
432  compactMap,
433  compactStart
434  );
435 
436 
437  // Renumber the transformed elements
438  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
439  // Count per transformIndex
440  label nTrafo = globalTransforms.transformPermutations().size();
441  labelList nPerTransform(nTrafo, Zero);
442  forAll(transformedElements, celli)
443  {
444  const labelPairList& elems = transformedElements[celli];
445 
446  forAll(elems, i)
447  {
448  label trafoI = globalTransforms.transformIndex(elems[i]);
449  nPerTransform[trafoI]++;
450  }
451  }
452  // Offset per transformIndex
453  transformStart_.setSize(nTrafo);
454  transformElements_.setSize(nTrafo);
455  forAll(transformStart_, trafoI)
456  {
457  transformStart_[trafoI] = constructSize_;
458  constructSize_ += nPerTransform[trafoI];
459  transformElements_[trafoI].setSize(nPerTransform[trafoI]);
460  }
461 
462  // Sort transformed elements into their new slot.
463  nPerTransform = 0;
464 
465  transformedIndices.setSize(transformedElements.size());
466  forAll(transformedElements, celli)
467  {
468  const labelPairList& elems = transformedElements[celli];
469  transformedIndices[celli].setSize(elems.size());
470 
471  forAll(elems, i)
472  {
473  label proci = globalTransforms.processor(elems[i]);
474  label index = globalTransforms.index(elems[i]);
475  label trafoI = globalTransforms.transformIndex(elems[i]);
476 
477  // Get compact index for untransformed element
478  label rawElemI =
479  (
480  proci == myRank
481  ? index
482  : compactMap[proci][index]
483  );
484 
485  label& n = nPerTransform[trafoI];
486  // index of element to transform
487  transformElements_[trafoI][n] = rawElemI;
488  // destination of transformed element
489  transformedIndices[celli][i] = transformStart_[trafoI]+n;
490  n++;
491  }
492  }
493 
494  if (debug)
495  {
496  printLayout(Pout);
497  }
498 }
499 
500 
502 (
503  labelListList&& subMap,
504  const bool subHasFlip,
505  const bool constructHasFlip,
506  const label comm
507 )
508 :
509  mapDistributeBase(std::move(subMap), subHasFlip, constructHasFlip, comm)
510 {}
511 
512 
514 {
515  is >> *this;
516 }
517 
518 
520 {
521  return autoPtr<mapDistribute>::New(*this);
522 }
523 
524 
525 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
526 
527 Foam::label Foam::mapDistribute::whichTransform(const label index) const
528 {
529  return findLower(transformStart_, index+1);
530 }
531 
532 
534 {
535  if (this == &rhs)
536  {
537  // Self-assignment is a no-op
538  }
539 
541  transformElements_.transfer(rhs.transformElements_);
542  transformStart_.transfer(rhs.transformStart_);
543 }
544 
545 
546 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
547 
549 {
550  if (this == &rhs)
551  {
552  return; // Self-assignment is a no-op
553  }
554 
556  transformElements_ = rhs.transformElements_;
557  transformStart_ = rhs.transformStart_;
558 }
559 
560 
562 {
563  if (this != &rhs)
564  {
565  // Avoid self-assignment
566  transfer(rhs);
567  }
568 }
569 
570 
571 // * * * * * * * * * * * * * * Istream Operator * * * * * * * * * * * * * * //
572 
574 {
576 
577  is >> static_cast<mapDistributeBase&>(map)
578  >> map.transformElements_ >> map.transformStart_;
579 
580  return is;
581 }
582 
583 
584 // * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * * //
585 
587 {
588  os << static_cast<const mapDistributeBase&>(map) << token::NL
589  << map.transformElements_ << token::NL
590  << map.transformStart_;
591 
592  return os;
593 }
594 
595 
596 // ************************************************************************* //
Foam::globalIndexAndTransform::processor
label processor(const labelPair &globalIAndTransform) const
Which processor does this come from?
Definition: globalIndexAndTransformI.H:357
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
Foam::autoPtr::New
static autoPtr< T > New(Args &&... args)
Construct autoPtr of T with forwarding arguments.
Foam::mapDistribute::whichTransform
label whichTransform(const label index) const
Find transform from transformElements.
Definition: mapDistribute.C:527
Foam::mapDistribute::operator=
void operator=(const mapDistribute &rhs)
Copy assignment.
Definition: mapDistribute.C:548
Foam::mapDistributeBase::operator=
void operator=(const mapDistributeBase &rhs)
Copy assignment.
Definition: mapDistributeBase.C:1327
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::globalIndexAndTransform::index
label index(const labelPair &globalIAndTransform) const
Index carried by the object.
Definition: globalIndexAndTransformI.H:348
Foam::globalIndexAndTransform::transformPermutations
const List< vectorTensorTransform > & transformPermutations() const
Return access to the permuted transforms.
Definition: globalIndexAndTransformI.H:388
Foam::IOstream::fatalCheck
bool fatalCheck(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:64
Foam::Map< label >
Foam::operator>>
Istream & operator>>(Istream &, directionInfo &)
Definition: directionInfo.C:230
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::coupledPolyPatch
The coupledPolyPatch is an abstract base class for patches that couple regions of the computational d...
Definition: coupledPolyPatch.H:54
Foam::Pout
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
Foam::mapDistributeBase::transfer
void transfer(mapDistributeBase &rhs)
Transfer the contents of the argument and annul the argument.
Definition: mapDistributeBase.C:883
Foam::mapDistribute::transfer
void transfer(mapDistribute &map)
Transfer the contents of the argument and annul the argument.
Definition: mapDistribute.C:533
transformField.H
Spatial transformation functions for primitive fields.
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
n
label n
Definition: TABSMDCalcMethod2.H:31
Foam::findLower
label findLower(const ListType &input, const T &val, const label start, const ComparePredicate &comp)
Foam::globalIndexAndTransform::transformIndex
label transformIndex(const labelPair &globalIAndTransform) const
Transform carried by the object.
Definition: globalIndexAndTransformI.H:366
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
globalIndexAndTransform.H
Foam::List::setSize
void setSize(const label n)
Alias for resize()
Definition: List.H:222
Foam::mapDistribute
Class containing processor-to-processor mapping information.
Definition: mapDistribute.H:163
Foam::token::NL
Newline [isspace].
Definition: token.H:124
os
OBJstream os(runTime.globalPath()/outputName)
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::globalIndex
Calculates a unique integer (label so might not have enough room - 2G max) for processor + local inde...
Definition: globalIndex.H:68
Foam::mapDistributeBase::printLayout
void printLayout(Ostream &os) const
Debug: print layout. Can only be used on maps with sorted.
Definition: mapDistributeBase.C:221
Foam::autoPtr< Foam::mapDistribute >
Foam::EdgeMap< label >
Foam::UPstream::myProcNo
static int myProcNo(const label communicator=worldComm)
Number of this process (starting from masterNo() = 0)
Definition: UPstream.H:463
Foam::Pair< label >
mapDistribute.H
Foam::List< label >
Foam::vectorTensorTransform
Vector-tensor class used to perform translations and rotations in 3D space.
Definition: vectorTensorTransform.H:63
Foam::UList< label >
Foam::mapDistribute::mapDistribute
mapDistribute(const label comm=UPstream::worldComm)
Construct null.
Definition: mapDistribute.C:151
bool
bool
Definition: EEqn.H:20
FUNCTION_NAME
#define FUNCTION_NAME
Definition: messageStream.H:295
Foam::mapDistributeBase
Class containing processor-to-processor mapping information.
Definition: mapDistributeBase.H:103
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::mapDistribute::clone
autoPtr< mapDistribute > clone() const
Clone.
Definition: mapDistribute.C:519
Foam::mapDistribute::printLayout
void printLayout(Ostream &os) const
Debug: print layout. Can only be used on maps with sorted.
Definition: mapDistribute.C:133
Foam::globalIndexAndTransform
Determination and storage of the possible independent transforms introduced by coupledPolyPatches,...
Definition: globalIndexAndTransform.H:64
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)