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 | Copyright (C) 2011-2014 OpenFOAM Foundation
6  \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
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 "mapDistribute.H"
28 #include "transformField.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 defineTypeNameAndDebug(mapDistribute, 0);
35 }
36 
37 
38 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
39 
40 template<>
41 void Foam::mapDistribute::transform::operator()
42 (
43  const vectorTensorTransform&,
44  const bool,
46 ) const
47 {}
48 template<>
49 void Foam::mapDistribute::transform::operator()
50 (
51  const coupledPolyPatch&,
53 ) const
54 {}
55 template<>
56 void Foam::mapDistribute::transform::operator()
57 (
58  const coupledPolyPatch&,
59  Map<label>&
60 ) const
61 {}
62 template<>
63 void Foam::mapDistribute::transform::operator()
64 (
65  const coupledPolyPatch&,
67 ) const
68 {}
69 
70 
71 template<>
72 void Foam::mapDistribute::transform::operator()
73 (
74  const vectorTensorTransform&,
75  const bool,
77 ) const
78 {}
79 template<>
80 void Foam::mapDistribute::transform::operator()
81 (
82  const coupledPolyPatch&,
84 ) const
85 {}
86 template<>
87 void Foam::mapDistribute::transform::operator()
88 (
89  const coupledPolyPatch&,
91 ) const
92 {}
93 template<>
94 void Foam::mapDistribute::transform::operator()
95 (
96  const coupledPolyPatch&,
98 ) const
99 {}
100 
101 
102 template<>
103 void Foam::mapDistribute::transform::operator()
104 (
105  const vectorTensorTransform&,
106  const bool,
107  List<bool>&
108 ) const
109 {}
110 template<>
111 void Foam::mapDistribute::transform::operator()
112 (
113  const coupledPolyPatch&,
114  UList<bool>&
115 ) const
116 {}
117 template<>
118 void Foam::mapDistribute::transform::operator()
119 (
120  const coupledPolyPatch&,
121  Map<bool>&
122 ) const
123 {}
124 template<>
125 void Foam::mapDistribute::transform::operator()
126 (
127  const coupledPolyPatch&,
129 ) const
130 {}
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 
151 //- Construct null
153 :
155 {}
156 
157 
158 //- Construct from components
160 (
161  const label constructSize,
162  const Xfer<labelListList>& subMap,
163  const Xfer<labelListList>& constructMap,
164  const bool subHasFlip,
165  const bool constructHasFlip
166 )
167 :
169  (
170  constructSize,
171  subMap,
172  constructMap,
173  subHasFlip,
174  constructHasFlip
175  )
176 {}
177 
178 
179 //- Construct from components
181 (
182  const label constructSize,
183  const Xfer<labelListList>& subMap,
184  const Xfer<labelListList>& constructMap,
185  const Xfer<labelListList>& transformElements,
186  const Xfer<labelList>& transformStart,
187  const bool subHasFlip,
188  const bool constructHasFlip
189 )
190 :
192  (
193  constructSize,
194  subMap,
195  constructMap,
196  subHasFlip,
197  constructHasFlip
198  ),
199  transformElements_(transformElements),
200  transformStart_(transformStart)
201 {}
202 
203 
205 (
206  const labelList& sendProcs,
207  const labelList& recvProcs
208 )
209 :
210  mapDistributeBase(sendProcs, recvProcs)
211 {}
212 
213 
215 (
216  const globalIndex& globalNumbering,
217  labelList& elements,
218  List<Map<label> >& compactMap,
219  const int tag
220 )
221 :
223  (
224  globalNumbering,
225  elements,
226  compactMap,
227  tag
228  )
229 {}
230 
231 
233 (
234  const globalIndex& globalNumbering,
235  labelListList& cellCells,
236  List<Map<label> >& compactMap,
237  const int tag
238 )
239 :
241  (
242  globalNumbering,
243  cellCells,
244  compactMap,
245  tag
246  )
247 {}
248 
249 
251 (
252  const globalIndex& globalNumbering,
253  labelList& elements,
254  const globalIndexAndTransform& globalTransforms,
255  const labelPairList& transformedElements,
256  labelList& transformedIndices,
257  List<Map<label> >& compactMap,
258  const int tag
259 )
260 :
262 {
263  // Construct per processor compact addressing of the global elements
264  // needed. The ones from the local processor are not included since
265  // these are always all needed.
266  calcCompactAddressing
267  (
268  globalNumbering,
269  elements,
270  compactMap
271  );
272 
273  // Add all (non-local) transformed elements needed.
274  forAll(transformedElements, i)
275  {
276  labelPair elem = transformedElements[i];
278  if (procI != Pstream::myProcNo())
279  {
281  label nCompact = compactMap[procI].size();
282  compactMap[procI].insert(index, nCompact);
283  }
284  }
285 
286 
287  // Exchange what I need with processor that supplies it. Renumber elements
288  // into compact numbering
289  labelList compactStart;
290  exchangeAddressing
291  (
292  tag,
293  globalNumbering,
294  elements,
295  compactMap,
296  compactStart
297  );
298 
299 
300  // Renumber the transformed elements
301  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
302  // Count per transformIndex
303  label nTrafo = globalTransforms.transformPermutations().size();
304  labelList nPerTransform(nTrafo, 0);
305  forAll(transformedElements, i)
306  {
307  labelPair elem = transformedElements[i];
309  nPerTransform[trafoI]++;
310  }
311  // Offset per transformIndex
312  transformStart_.setSize(nTrafo);
313  transformElements_.setSize(nTrafo);
314  forAll(transformStart_, trafoI)
315  {
316  transformStart_[trafoI] = constructSize_;
317  constructSize_ += nPerTransform[trafoI];
318  transformElements_[trafoI].setSize(nPerTransform[trafoI]);
319  }
320 
321  // Sort transformed elements into their new slot.
322  nPerTransform = 0;
323 
324  transformedIndices.setSize(transformedElements.size());
325  forAll(transformedElements, i)
326  {
327  labelPair elem = transformedElements[i];
331 
332  // Get compact index for untransformed element
333  label rawElemI =
334  (
335  procI == Pstream::myProcNo()
336  ? index
337  : compactMap[procI][index]
338  );
339 
340  label& n = nPerTransform[trafoI];
341  // index of element to transform
342  transformElements_[trafoI][n] = rawElemI;
343  // destination of transformed element
344  transformedIndices[i] = transformStart_[trafoI]+n;
345  n++;
346  }
347 
348  if (debug)
349  {
350  printLayout(Pout);
351  }
352 }
353 
354 
356 (
357  const globalIndex& globalNumbering,
358  labelListList& cellCells,
359  const globalIndexAndTransform& globalTransforms,
360  const List<labelPairList>& transformedElements,
361  labelListList& transformedIndices,
362  List<Map<label> >& compactMap,
363  const int tag
364 )
365 :
367 {
368  // Construct per processor compact addressing of the global elements
369  // needed. The ones from the local processor are not included since
370  // these are always all needed.
371  calcCompactAddressing
372  (
373  globalNumbering,
374  cellCells,
375  compactMap
376  );
377 
378  // Add all (non-local) transformed elements needed.
379  forAll(transformedElements, cellI)
380  {
381  const labelPairList& elems = transformedElements[cellI];
382 
383  forAll(elems, i)
384  {
385  label procI = globalIndexAndTransform::processor(elems[i]);
386  if (procI != Pstream::myProcNo())
387  {
388  label index = globalIndexAndTransform::index(elems[i]);
389  label nCompact = compactMap[procI].size();
390  compactMap[procI].insert(index, nCompact);
391  }
392  }
393  }
394 
395 
396  // Exchange what I need with processor that supplies it. Renumber elements
397  // into compact numbering
398  labelList compactStart;
399  exchangeAddressing
400  (
401  tag,
402  globalNumbering,
403  cellCells,
404  compactMap,
405  compactStart
406  );
407 
408 
409  // Renumber the transformed elements
410  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
411  // Count per transformIndex
412  label nTrafo = globalTransforms.transformPermutations().size();
413  labelList nPerTransform(nTrafo, 0);
414  forAll(transformedElements, cellI)
415  {
416  const labelPairList& elems = transformedElements[cellI];
417 
418  forAll(elems, i)
419  {
421  nPerTransform[trafoI]++;
422  }
423  }
424  // Offset per transformIndex
425  transformStart_.setSize(nTrafo);
426  transformElements_.setSize(nTrafo);
427  forAll(transformStart_, trafoI)
428  {
429  transformStart_[trafoI] = constructSize_;
430  constructSize_ += nPerTransform[trafoI];
431  transformElements_[trafoI].setSize(nPerTransform[trafoI]);
432  }
433 
434  // Sort transformed elements into their new slot.
435  nPerTransform = 0;
436 
437  transformedIndices.setSize(transformedElements.size());
438  forAll(transformedElements, cellI)
439  {
440  const labelPairList& elems = transformedElements[cellI];
441  transformedIndices[cellI].setSize(elems.size());
442 
443  forAll(elems, i)
444  {
445  label procI = globalIndexAndTransform::processor(elems[i]);
446  label index = globalIndexAndTransform::index(elems[i]);
448 
449  // Get compact index for untransformed element
450  label rawElemI =
451  (
452  procI == Pstream::myProcNo()
453  ? index
454  : compactMap[procI][index]
455  );
456 
457  label& n = nPerTransform[trafoI];
458  // index of element to transform
459  transformElements_[trafoI][n] = rawElemI;
460  // destination of transformed element
461  transformedIndices[cellI][i] = transformStart_[trafoI]+n;
462  n++;
463  }
464  }
465 
466  if (debug)
467  {
468  printLayout(Pout);
469  }
470 }
471 
472 
474 (
475  const mapDistribute& map
476 )
477 :
478  mapDistributeBase(map),
479  transformElements_(map.transformElements_),
480  transformStart_(map.transformStart_)
481 {}
482 
483 
485 (
486  const Xfer<mapDistribute>& map
487 )
488 :
490  (
491  map().constructSize_,
492  map().subMap_.xfer(),
493  map().constructMap_.xfer(),
494  map().subHasFlip(),
495  map().constructHasFlip()
496  ),
497  transformElements_(map().transformElements_.xfer()),
498  transformStart_(map().transformStart_.xfer())
499 {}
500 
501 
503 {
504  is >> *this;
505 }
506 
507 
509 {
510  return autoPtr<mapDistribute>(new mapDistribute(*this));
511 }
512 
513 
514 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
515 
517 const
518 {
519  return findLower(transformStart_, index+1);
520 }
521 
522 
524 {
526  transformElements_.transfer(rhs.transformElements_);
527  transformStart_.transfer(rhs.transformStart_);
528 }
529 
530 
532 {
533  return xferMove(*this);
534 }
535 
536 
537 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
538 
540 {
541  // Check for assignment to self
542  if (this == &rhs)
543  {
545  << "Attempted assignment to self"
546  << abort(FatalError);
547  }
549  transformElements_ = rhs.transformElements_;
550  transformStart_ = rhs.transformStart_;
551 }
552 
553 
554 // * * * * * * * * * * * * * * Istream Operator * * * * * * * * * * * * * * //
555 
557 {
558  is.fatalCheck("operator>>(Istream&, mapDistribute&)");
559 
560  is >> static_cast<mapDistributeBase&>(map)
561  >> map.transformElements_ >> map.transformStart_;
562 
563  return is;
564 }
565 
566 
567 // * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * * //
568 
569 Foam::Ostream& Foam::operator<<(Ostream& os, const mapDistribute& map)
570 {
571  os << static_cast<const mapDistributeBase&>(map) << token::NL
572  << map.transformElements_ << token::NL
573  << map.transformStart_;
574 
575  return os;
576 }
577 
578 
579 // ************************************************************************* //
Foam::mapDistribute::whichTransform
label whichTransform(const label index) const
Find transform from transformElements.
Definition: mapDistribute.C:516
Foam::IOstream::fatalCheck
void fatalCheck(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:105
Foam::mapDistributeBase::operator=
void operator=(const mapDistributeBase &)
Definition: mapDistributeBase.C:1232
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::globalIndexAndTransform::transformPermutations
const List< vectorTensorTransform > & transformPermutations() const
Return access to the permuted transforms.
Definition: globalIndexAndTransformI.H:423
Foam::Map< label >
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::coupledPolyPatch
The coupledPolyPatch is an abstract base class for patches that couple regions of the computational d...
Definition: coupledPolyPatch.H:51
Foam::token::NL
@ NL
Definition: token.H:97
Foam::Xfer
A simple container for copying or transferring objects of type <T>.
Definition: Xfer.H:85
transformField.H
Spatial transformation functions for primitive fields.
Foam::mapDistribute::transfer
void transfer(mapDistribute &)
Transfer the contents of the argument and annul the argument.
Definition: mapDistribute.C:523
n
label n
Definition: TABSMDCalcMethod2.H:31
Foam::label
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
Foam::globalIndexAndTransform::transformIndex
static label transformIndex(const labelPair &globalIAndTransform)
Transform carried by the object.
Definition: globalIndexAndTransformI.H:401
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:57
globalIndexAndTransform.H
Foam::mapDistribute
Class containing processor-to-processor mapping information.
Definition: mapDistribute.H:152
Foam::globalIndexAndTransform::index
static label index(const labelPair &globalIAndTransform)
Index carried by the object.
Definition: globalIndexAndTransformI.H:383
Foam::findLower
label findLower(const ListType &, typename ListType::const_reference, const label start, const BinaryOp &bop)
Find last element < given value in sorted list and return index,.
Foam::operator<<
Ostream & operator<<(Ostream &, const edgeMesh &)
Definition: edgeMeshIO.C:130
Foam::FatalError
error FatalError
Foam::mapDistributeBase::transfer
void transfer(mapDistributeBase &)
Transfer the contents of the argument and annul the argument.
Definition: mapDistributeBase.C:807
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:131
Foam::globalIndex
Calculates a unique integer (label so might not have enough room - 2G max) for processor + local inde...
Definition: globalIndex.H:63
Foam::mapDistribute::transformElements_
labelListList transformElements_
For every globalIndexAndTransform::transformPermutations.
Definition: mapDistribute.H:160
Foam::UPstream::myProcNo
static int myProcNo(const label communicator=0)
Number of this process (starting from masterNo() = 0)
Definition: UPstream.H:405
Foam::mapDistributeBase::printLayout
void printLayout(Ostream &os) const
Debug: print layout. Can only be used on maps with sorted.
Definition: mapDistributeBase.C:202
Foam::List::setSize
void setSize(const label)
Reset size of List.
Foam::autoPtr< Foam::mapDistribute >
Foam::EdgeMap< label >
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
Foam::globalIndexAndTransform::processor
static label processor(const labelPair &globalIAndTransform)
Which processor does this come from?
Definition: globalIndexAndTransformI.H:392
Foam::xferMove
Xfer< T > xferMove(T &)
Construct by transferring the contents of the arg.
Foam::Pair
An ordered pair of two objects of type <T> with first() and second() elements.
Definition: contiguous.H:49
Foam::Pout
prefixOSstream Pout(cout, "Pout")
Definition: IOstreams.H:53
mapDistribute.H
Foam::List< label >
Foam::vectorTensorTransform
Vector-tensor class used to perform translations and rotations in 3D space.
Definition: vectorTensorTransform.H:61
Foam::UList
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
Foam::operator>>
Istream & operator>>(Istream &, edgeMesh &)
Definition: edgeMeshIO.C:141
Foam::mapDistributeBase
Class containing processor-to-processor mapping information.
Definition: mapDistributeBase.H:91
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
Foam::mapDistribute::clone
autoPtr< mapDistribute > clone() const
Clone.
Definition: mapDistribute.C:508
Foam::mapDistribute::printLayout
void printLayout(Ostream &os) const
Debug: print layout. Can only be used on maps with sorted.
Definition: mapDistribute.C:133
Foam::mapDistribute::xfer
Xfer< mapDistribute > xfer()
Transfer contents to the Xfer container.
Definition: mapDistribute.C:531
Foam::globalIndexAndTransform
Determination and storage of the possible independent transforms introduced by coupledPolyPatches,...
Definition: globalIndexAndTransform.H:60
Foam::mapDistribute::operator=
void operator=(const mapDistribute &)
Definition: mapDistribute.C:539
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::mapDistribute::mapDistribute
mapDistribute()
Construct null.
Definition: mapDistribute.C:152
Foam::mapDistribute::transformStart_
labelList transformStart_
Destination in constructMap for transformed elements.
Definition: mapDistribute.H:163