mapDistributeBase.H
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) 2015-2017 OpenFOAM Foundation
9  Copyright (C) 2015-2022 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 Class
28  Foam::mapDistributeBase
29 
30 Description
31  Class containing processor-to-processor mapping information.
32 
33  We store mapping from the bits-to-send to the complete starting list
34  (subXXXMap) and from the received bits to their location in the new
35  list (constructXXXMap).
36 
37 Note:
38  Schedule is a list of processor pairs (one send, one receive. One of
39  them will be myself) which forms a scheduled (i.e. non-buffered) exchange.
40  See distribute on how to use it.
41  Note2: number of items sent on one processor have to equal the number
42  of items received on the other processor.
43 
44  To aid constructing these maps there are the constructors from global
45  numbering, either with or without transforms.
46 
47  Constructors using compact numbering: layout is
48  - all my own elements first (whether used or not)
49  - followed by used-only remote elements sorted by remote processor.
50  So e.g 4 procs and on proc 1 the compact
51  table will first have all globalIndex.localSize() elements from proc1
52  followed by used-only elements of proc0, proc2, proc3.
53  The constructed mapDistributeBase sends the local elements from and
54  receives the remote elements into their compact position.
55  compactMap[proci] is the position of elements from proci in the compact
56  map. compactMap[myProcNo()] is empty since trivial addressing.
57 
58  It rewrites the input global indices into indices into the constructed
59  data.
60 
61  When constructing from components optionally a 'flip' on
62  the maps can be specified. This will interpret the map
63  values as index+flip, similar to e.g. faceProcAddressing. The flip
64  will only be applied to fieldTypes (scalar, vector, .. triad)
65 
66 
67 SourceFiles
68  mapDistributeBase.C
69  mapDistributeBaseIO.C
70  mapDistributeBaseTemplates.C
71 
72 \*---------------------------------------------------------------------------*/
73 
74 #ifndef Foam_mapDistributeBase_H
75 #define Foam_mapDistributeBase_H
76 
77 #include "boolList.H"
78 #include "labelList.H"
79 #include "labelPair.H"
80 #include "Pstream.H"
81 #include "Map.H"
82 #include "InfoProxy.H"
83 
84 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
85 
86 namespace Foam
87 {
88 
89 // Forward Declarations
90 
91 class bitSet;
92 class dictionary;
93 class globalIndex;
94 class PstreamBuffers;
95 class mapPolyMesh;
96 class mapDistributeBase;
97 
98 Istream& operator>>(Istream&, mapDistributeBase&);
99 Ostream& operator<<(Ostream&, const mapDistributeBase&);
100 
102 /*---------------------------------------------------------------------------*\
103  Class mapDistributeBase Declaration
104 \*---------------------------------------------------------------------------*/
105 
106 class mapDistributeBase
107 {
108  // Private Data
109 
110  //- Size of reconstructed data
111  label constructSize_;
112 
113  //- Maps from subsetted data back to original data
114  labelListList subMap_;
115 
116  //- Maps from subsetted data to new reconstructed data
117  labelListList constructMap_;
118 
119  //- Whether subMap includes flip or not
120  bool subHasFlip_;
121 
122  //- Whether constructMap includes flip or not
123  bool constructHasFlip_;
124 
125  //- Communicator to use for parallel operations
126  label comm_;
127 
128  //- Schedule
129  mutable autoPtr<List<labelPair>> schedulePtr_;
130 
131 
132 protected:
133 
134  // Protected Member Functions
135 
136  //- Fatal if expected and received size are not equal
137  static void checkReceivedSize
138  (
139  const label proci,
140  const label expectedSize,
141  const label receivedSize
142  );
143 
144  //- Scan the maps for the max addressed index.
145  //
146  // \param maps The maps to scan
147  // \param hasFlip True if maps has flip addressing
148  // \return max-size needed for addressing (eg, constructSize)
149  static label getMappedSize
150  (
151  const labelListList& maps,
152  const bool hasFlip
153  );
154 
155  //- Construct per processor compact addressing of the global elements
156  // needed. The ones from the local processor are not included since
157  // these are always all needed.
159  (
160  const globalIndex& globalNumbering,
161  const labelUList& elements,
162  List<Map<label>>& compactMap
163  ) const;
164 
166  (
167  const globalIndex& globalNumbering,
168  const labelListList& elements,
169  List<Map<label>>& compactMap
170  ) const;
171 
172  void exchangeAddressing
173  (
174  const int tag,
175  const globalIndex& globalNumbering,
176  labelList& elements,
177  List<Map<label>>& compactMap,
178  labelList& compactStart
179  );
180  void exchangeAddressing
181  (
182  const int tag,
183  const globalIndex& globalNumbering,
184  labelListList& elements,
185  List<Map<label>>& compactMap,
186  labelList& compactStart
187  );
188 
189  //- Synchronize send/recv mask buffers as a 'copy' operation.
190  // Somewhat similar to Pstream::exchangeContainer
191  //
192  // The masks must be properly sized by the caller, which avoids
193  // a needless all-to-all for the sizes and the sizing is already
194  // given by the maps.
195  static void exchangeMasks
196  (
197  const UList<bitSet>& sendMasks,
198  UList<bitSet>& recvMasks,
199  const int tag,
200  const label comm
201  );
202 
203  //- Bi-direction sync of send/recv buffers using bitwise '&='
204  //- combine operation.
205  //
206  // The masks must be properly sized by the caller, which avoids
207  // a needless all-to-all for the sizes and the sizing is already
208  // given by the maps.
209  static void unionCombineMasks
210  (
211  UList<bitSet>& sendMasks,
212  UList<bitSet>& recvMasks,
213  const int tag,
214  const label comm
215  );
216 
217 
218  template<class T, class CombineOp, class NegateOp>
219  static void flipAndCombine
220  (
221  const labelUList& map,
222  const bool hasFlip,
223  const UList<T>& rhs,
224  const CombineOp& cop,
225  const NegateOp& negOp,
226  List<T>& lhs
227  );
228 
229  //- Lookup a field value at specified index and return its value
230  //- after any flip negation operations
231  template<class T, class NegateOp>
232  static T accessAndFlip
233  (
234  const UList<T>& values,
235  const label index,
236  const bool hasFlip,
237  const NegateOp& negOp
238  );
239 
240  //- Lookup field values at specified indices and return
241  //- after any flip negation operations
242  template<class T, class NegateOp>
243  static List<T> accessAndFlip
244  (
245  const UList<T>& values,
246  const labelUList& indices,
247  const bool hasFlip,
248  const NegateOp& negOp
249  );
250 
251 
252 private:
253 
254  // Private Member Functions
255 
256  //- Helper for compactData (private: filescope only!)
257  // Establishes the exact send/recv elements used after masking.
258  //
259  // \param allowedLocalElems Permissible local mapped elements
260  // (true/false). Can be longer/shorter than actual number
261  // of mapped elements.
262  // \param allowedRemoteElems Permissible remote mapped elements
263  // (true/false). Can be longer/shorter than actual number
264  // of mapped elements.
265  // \param[out] sendMasks Mask of local elements sent to procs.
266  // \param[out] recvMasks Mask of remote elements received
267  // from procs
268  // \param tag The message tag
269  void calcCompactDataRequirements
270  (
271  const bitSet& allowedLocalElems,
272  const bitSet& allowedRemoteElems,
273  List<bitSet>& sendMasks, // [out]
274  List<bitSet>& recvMasks, // [out]
275  const int tag
276  );
277 
278  //- Helper for compactLocalData (private: filescope only!)
279  // Establishes the exact send/recv elements used after masking.
280  //
281  // \param allowedLocalElems Permissible local mapped elements
282  // (true/false). Can be longer/shorter than actual number
283  // of mapped elements.
284  // \param[out] sendMasks Mask of local elements sent to procs.
285  // \param[out] recvMasks Mask of remote elements received by proc.
286  // from procs
287  // \param tag The message tag
288  void calcCompactLocalDataRequirements
289  (
290  const bitSet& allowedLocalElems,
291  List<bitSet>& sendMasks, // [out]
292  List<bitSet>& recvMasks, // [out]
293  const int tag
294  );
295 
296  //- Helper for compactRemoteData (private: filescope only!)
297  // Establishes the exact send/recv elements used after masking.
298  //
299  // \param allowedRemoteElems Permissible remote mapped elements
300  // (true/false). Can be longer/shorter than actual number
301  // of mapped elements.
302  // \param[out] sendMasks Mask of local elements sent to procs.
303  // \param[out] recvMasks Mask of remote elements received by proc.
304  // \param tag The message tag
305  void calcCompactRemoteDataRequirements
306  (
307  const bitSet& allowedRemoteElems,
308  List<bitSet>& sendMasks, // [out]
309  List<bitSet>& recvMasks, // [out]
310  const int tag
311  );
312 
313  //- Implementation for compact{Local,Remote}Data (private).
314  // Also renumbers the subMap/constructMap if oldToNew maps
315  // are notNull().
316  //
317  // No communication
318  void compactData
319  (
320  const UList<bitSet>& sendMasks,
321  const UList<bitSet>& recvMasks,
322  labelList& oldToNewSub,
323  labelList& oldToNewConstruct,
324  const label localSize = -1
325  );
326 
327  //- Wrapper for compactData (private) that supplies oldToNew
328  //- maps for renumbering if doRenumber is true.
329  // No communication
330  void compactDataImpl
331  (
332  const UList<bitSet>& sendMasks,
333  const UList<bitSet>& recvMasks,
334  const bool doRenumber
335  );
336 
337 
338  //- Helper for renumbering compacted map elements and updating the
339  //- supplied old-to-new mapping to account for the visit order of
340  //- the original elements
341  //
342  // \param origElements The original elements visited (eg, meshPoints)
343  // \param[in,out] oldToNew The old-to-new mapping
344  // \param[in,out] mapElements The map to be renumbered
345  // \param hasFlip True if map has flip addressing
346  static void renumberVisitOrder
347  (
348  const labelUList& origElements,
349  labelList& oldToNew,
350  labelListList& maps,
351  const bool hasFlip
352  );
353 
354 
355 public:
356 
357  // Declare name of the class and its debug switch
358  ClassName("mapDistributeBase");
359 
360 
361  // Constructors
362 
363  //- Default construct (uses worldComm)
365 
366  //- Default construct with specified communicator
367  explicit mapDistributeBase(const label comm);
368 
369  //- Copy construct
371 
372  //- Move construct
374 
375  //- Read construct from dictionary
376  explicit mapDistributeBase
377  (
378  const dictionary& dict,
379  const label comm = UPstream::worldComm
380  );
381 
382  //- Move construct from components
384  (
385  const label constructSize,
388  const bool subHasFlip = false,
389  const bool constructHasFlip = false,
390  const label comm = UPstream::worldComm
391  );
392 
393  //- Construct from reverse addressing: per data item the send
394  //- processor and the receive processor.
395  //
396  // \note data is not sorted per processor - cannot use printLayout!
398  (
399  const labelUList& sendProcs,
400  const labelUList& recvProcs,
401  const label comm = UPstream::worldComm
402  );
403 
404  //- Construct from list of (possibly) remote elements in globalIndex
405  //- numbering (or -1).
406  //
407  // Determines compact numbering (see above) and distribute map
408  // to get data into this ordering and renumbers the elements to
409  // be in compact numbering.
411  (
412  const globalIndex&,
413  labelList& elements,
414  List<Map<label>>& compactMap,
415  const int tag = UPstream::msgType(),
416  const label comm = UPstream::worldComm
417  );
418 
419  //- Special variant that works with the info sorted into bins
420  //- according to local indices.
421  //
422  // E.g. think cellCells where
423  // cellCells[localCellI] is a list of global cells
425  (
426  const globalIndex&,
427  labelListList& cellCells,
428  List<Map<label>>& compactMap,
429  const int tag = UPstream::msgType(),
430  const label comm = UPstream::worldComm
431  );
432 
433  //- Construct from my elements to send.
434  // Assumes layout is my elements first followed by elements
435  // from all other processors in consecutive order.
436  explicit mapDistributeBase
437  (
439  const bool subHasFlip = false,
440  const bool constructHasFlip = false,
441  const label comm = UPstream::worldComm
442  );
443 
444  //- Construct from Istream
445  explicit mapDistributeBase(Istream& is);
446 
447 
448  // Static Functions
449 
450  //- Test for flip addressing, where flips are encoded as negative
451  //- indices and non-flips are encoded as positive non-zero indices.
452  //
453  // Exits early on the first detected zero or negative, which
454  // makes this more efficient than testing min(map) < 0.
455  //
456  // \note may return a false negative (ie, no flips detected)
457  // even when flip addressing is used, but the local map does not
458  // contain any flipped elements
459  static bool hasFlipAddressing(const labelUList& map);
460 
461  //- Test for flip addressing, where flips are encoded as negative
462  //- indices and non-flips are encoded as positive non-zero indices.
463  //
464  // See notes above.
465  static bool hasFlipAddressing(const labelListList& maps);
466 
467  //- Count the number of unmapped elements.
468  //
469  // \param elements The elements that are expected to be mapped
470  // \param maps The maps to scan
471  // \param hasFlip True if maps has flip addressing
472  // \return number of unmapped elements
473  static label countUnmapped
474  (
475  const labelUList& elements,
476  const labelListList& maps,
477  const bool hasFlip
478  );
479 
480 
481  // Member Functions
482 
483  // Access
484 
485  //- Constructed data size
486  label constructSize() const noexcept
487  {
488  return constructSize_;
489  }
490 
491  //- Constructed data size
492  label& constructSize() noexcept
493  {
494  return constructSize_;
495  }
496 
497  //- From subsetted data back to original data
498  const labelListList& subMap() const noexcept
499  {
500  return subMap_;
501  }
502 
503  //- From subsetted data back to original data
505  {
506  return subMap_;
507  }
508 
509  //- From subsetted data to new reconstructed data
510  const labelListList& constructMap() const noexcept
511  {
512  return constructMap_;
513  }
514 
515  //- From subsetted data to new reconstructed data
517  {
518  return constructMap_;
519  }
520 
521  //- Does subMap include a sign
522  bool subHasFlip() const noexcept
523  {
524  return subHasFlip_;
525  }
526 
527  //- Does subMap include a sign
528  bool& subHasFlip() noexcept
529  {
530  return subHasFlip_;
531  }
532 
533  //- Does constructMap include a sign
534  bool constructHasFlip() const noexcept
535  {
536  return constructHasFlip_;
537  }
538 
539  //- Does constructMap include a sign
540  bool& constructHasFlip() noexcept
541  {
542  return constructHasFlip_;
543  }
544 
545  //- The communicator used
546  label comm() const noexcept
547  {
548  return comm_;
549  }
550 
551  //- The number of sub-lists within the maps
552  label nMaps() const noexcept
553  {
554  return constructMap_.size();
555  }
556 
557  //- The sizes of the subMap lists
558  labelList subMapSizes() const;
559 
560  //- The sizes of the constructMap lists
562 
563 
564  // Schedule
565 
566  //- Calculate a communication schedule. See above.
568  (
569  const labelListList& subMap,
571  const int tag, // Message tag: msgType()
572  const label comm = UPstream::worldComm
573  );
574 
575  //- Return a schedule. Demand driven. See above.
576  const List<labelPair>& schedule() const;
577 
578  //- Return real or dummy schedule depending on the
579  //- communication type
581  (
582  const UPstream::commsTypes commsType
583  ) const;
585 
586  // Other
587 
588  //- Reset to zero size, only retaining communicator
589  void clear();
590 
591  //- Transfer the contents of the argument and annul the argument.
593 
594  //- Helper for construct from globalIndex. Renumbers element
595  // (in globalIndex numbering) into compact indices.
596  static label renumber
597  (
598  const globalIndex&,
599  const List<Map<label>>& compactMap,
600  const label globalElement
601  );
602 
603  //- Helper for renumbering the (compacted) map elements
604  //- using the supplied old-to-new mapping.
605  // Only compacts the maps, does not change the local layout.
606  //
607  // \param[in,out] mapElements The map to be renumbered
608  // \param oldToNew The old-to-new mapping
609  // \param hasFlip True if map has flip addressing
610  //
611  // \return max-size needed for new addressing (eg, constructSize)
612  static label renumberMap
613  (
614  labelListList& mapElements,
615  const labelUList& oldToNew,
616  const bool hasFlip
617  );
618 
619 
620  // Compaction
621 
622  //- Compact send/receive maps based on selection of
623  //- originating local (send) elements.
624  // Determines and removes the correspondingly unneeded elements
625  // in the send/receive maps.
626  // Only compacts the maps, does not change the local layout.
627  //
628  // \param allowedLocalElems Permissible local mapped elements
629  // (true/false). Can be longer/shorter than actual number
630  // of mapped elements.
631  // \param tag The message tag
632  // \param doRenumber Apply oldToNew internally to renumber
633  // entries (uses renumberMap) and adjust the constructSize
634  //
635  // \note generally preferable to compact based on remote data
636  // (ie, the actual receiver)
637  void compactLocalData
638  (
639  const bitSet& allowedLocalElems,
640  const int tag = UPstream::msgType(),
641  const bool doRenumber = false
642  );
643 
644  //- Compact send/receive maps based on selection of
645  //- remote (receive) elements.
646  // Determines and removes the correspondingly unneeded elements
647  // in the send/receive maps.
648  // Only compacts the maps, does not change the local layout.
649  //
650  // \param allowedRemoteElems Permissible remote mapped elements
651  // (true/false). Can be longer/shorter than actual number
652  // of mapped elements.
653  // \param tag The message tag
654  // \param doRenumber Apply oldToNew internally to renumber
655  // entries (uses renumberMap) and adjust the constructSize
657  (
658  const bitSet& allowedRemoteElems,
659  const int tag = UPstream::msgType(),
660  const bool doRenumber = false
661  );
662 
663 
664  //- Compact send/receive maps based on selection of
665  //- originating local (send) elements.
666  //- Returns compaction mappings for subMap and constructMap.
667  //
668  // \param allowedLocalElems Permissible local mapped elements
669  // (true/false). Can be longer/shorter than actual number
670  // of mapped elements.
671  // \param[out] oldToNewSub Old-to-new mapping: subMap
672  // Disabled if labelList::null(),
673  // \param[out] oldToNewConstruct Old-to-new mapping: constructMap
674  // Disabled if labelList::null(),
675  // \param localSize The max index for subMap (-1: auto-detect)
676  // \param tag The message tag
677  //
678  // \note Applies oldToNew to renumber entries
679  // (uses renumberMap) and adjust constructSize
680  //
681  // \note generally preferable to compact based on remote data
682  // (ie, the actual receiver)
683  void compactLocalData
684  (
685  const bitSet& allowedLocalElems,
686  labelList& oldToNewSub,
687  labelList& oldToNewConstruct,
688  const label localSize = -1,
689  const int tag = UPstream::msgType()
690  );
691 
692  //- Compact send/receive maps based on selection of
693  //- remote (receive) elements.
694  //- Returns compaction mappings for subMap and constructMap.
695  //
696  // \param allowedRemoteElems Permissible remote mapped elements
697  // (true/false). Can be longer/shorter than actual number
698  // of mapped elements.
699  // \param[out] oldToNewSub Old-to-new mapping: subMap
700  // Disabled if labelList::null(),
701  // \param[out] oldToNewConstruct Old-to-new mapping: constructMap
702  // Disabled if labelList::null(),
703  // \param localSize The max index for subMap (-1: auto-detect)
704  // \param tag The message tag
705  //
706  // \note Applies oldToNew to renumber entries
707  // (uses renumberMap) and adjust constructSize
708  void compactRemoteData
709  (
710  const bitSet& allowedRemoteElems,
711  labelList& oldToNewSub,
712  labelList& oldToNewConstruct,
713  const label localSize = -1,
714  const int tag = UPstream::msgType()
715  );
716 
717 
718  //- Compact send/receive maps based on selection of
719  //- originating local (send) and remote (receive) elements.
720  //
721  // The resulting compact numbering:
722  // - \c subMap (and \c oldToNewSub) :
723  // will follow the original ordering of \c localElements.
724  // - \c constructMap (and \c oldToNewConstruct) :
725  // will follow the original ordering of \c remoteElements.
726  // .
727  // \warning ill-defined behaviour if \c localElements
728  // or \c remoteElements contains duplicates.
729  void compactData
730  (
731  const labelUList& localElements,
732  const labelUList& remoteElements,
733  labelList& oldToNewSub,
734  labelList& oldToNewConstruct,
735  const label localSize = -1,
736  const int tag = UPstream::msgType()
737  );
738 
739  //- Compact send/receive maps based on selection of
740  //- originating local (send) elements.
741  //
742  // The resulting compact numbering:
743  // - \c subMap (and \c oldToNewSub) :
744  // will follow the original ordering of \c localElements.
745  // - \c constructMap (and \c oldToNewConstruct) :
746  // numbered in simple ascending order.
747  // .
748  // \warning ill-defined behaviour if \c localElements
749  // contains duplicates.
750  //
751  // \note generally preferable to compact based on remote data
752  // (ie, the actual receiver)
753  void compactLocalData
754  (
755  const labelUList& localElements,
756  labelList& oldToNewSub,
757  labelList& oldToNewConstruct,
758  const label localSize = -1,
759  const int tag = UPstream::msgType()
760  );
761 
762  //- Compact send/receive maps based on selection of
763  //- remote (receive) elements.
764  //
765  // The resulting compact numbering:
766  // - \c subMap (and \c oldToNewSub) :
767  // numbered in simple ascending order.
768  // - \c constructMap (and \c oldToNewConstruct) :
769  // will follow the original ordering of \c remoteElements.
770  // .
771  // \warning ill-defined behaviour if \c remoteElements
772  // contains duplicates.
773  void compactRemoteData
774  (
775  const labelUList& remoteElements,
776  labelList& oldToNewSub,
777  labelList& oldToNewConstruct,
778  const label localSize = -1,
779  const int tag = UPstream::msgType()
780  );
781 
782 
783  // Distribute
784 
785  //- Distribute data with specified negate operator (for flips).
786  //
787  // \note schedule currently only used for
788  // Pstream::commsTypes::scheduled, all others just use
789  // send-to-all, receive-from-all.
790  template<class T, class NegateOp>
791  static void distribute
792  (
793  const Pstream::commsTypes commsType,
794  const List<labelPair>& schedule,
795  const label constructSize,
796  const labelListList& subMap,
797  const bool subHasFlip,
799  const bool constructHasFlip,
800  List<T>& field,
801  const NegateOp& negOp,
802  const int tag = UPstream::msgType(),
803  const label comm = UPstream::worldComm
804  );
805 
806  //- Distribute data with specified combine operation
807  //
808  // If multiple processors writing to same
809  // position adds contributions using cop.
810  template<class T, class CombineOp, class NegateOp>
811  static void distribute
812  (
813  const Pstream::commsTypes commsType,
814  const List<labelPair>& schedule,
815  const label constructSize,
816  const labelListList& subMap,
817  const bool subHasFlip,
819  const bool constructHasFlip,
820  List<T>& field,
821  const T& nullValue,
822  const CombineOp& cop,
823  const NegateOp& negOp,
824  const int tag = UPstream::msgType(),
825  const label comm = UPstream::worldComm
826  );
827 
828 
829  //- Distribute data using default commsType
830  //- and the default flip/negate operator.
831  template<class T>
832  void distribute
833  (
834  List<T>& values,
835  const int tag = UPstream::msgType()
836  ) const;
837 
838  //- Distribute data using default commsType
839  //- and the default flip/negate operator.
840  template<class T>
841  void distribute
842  (
844  const int tag = UPstream::msgType()
845  ) const;
846 
847  //- Distribute data using default commsType
848  //- and the specified negate operator (for flips).
849  template<class T, class NegateOp>
850  void distribute
851  (
852  List<T>& values,
853  const NegateOp& negOp,
854  const int tag = UPstream::msgType()
855  ) const;
856 
857  //- Distribute data using specified commsType
858  //- and the specified negate operator (for flips).
859  // Accepts a nullValue to initialize unmapped elements
860  // (ie, when the constructSize is larger than the number of
861  // mapped elements).
862  template<class T, class NegateOp>
863  void distribute
864  (
865  const Pstream::commsTypes commsType,
866  List<T>& values,
867  const NegateOp& negOp,
868  const int tag = UPstream::msgType()
869  ) const;
870 
871  //- Distribute data using specified commsType
872  //- and the specified negate operator (for flips).
873  // Accepts a nullValue to initialize unmapped elements
874  // (ie, when the constructSize is larger than the number of
875  // mapped elements).
876  template<class T, class NegateOp>
877  void distribute
878  (
879  const Pstream::commsTypes commsType,
880  const T& nullValue,
881  List<T>& values,
882  const NegateOp& negOp,
883  const int tag = UPstream::msgType()
884  ) const;
885 
886 
887  //- Reverse distribute data using default commsType
888  //- and the default flip/negate operator
889  template<class T>
890  void reverseDistribute
891  (
892  const label constructSize,
893  List<T>& values,
894  const int tag = UPstream::msgType()
895  ) const;
896 
897  //- Reverse distribute data using default commsType
898  //- and the default flip/negate operator.
899  // Accepts a nullValue to initialize unmapped elements
900  // (ie, when the constructSize is larger than the subMap).
901  template<class T>
902  void reverseDistribute
903  (
904  const label constructSize,
905  const T& nullValue,
906  List<T>& values,
907  const int tag = UPstream::msgType()
908  ) const;
909 
910  //- Reverse distribute data using specified commsType
911  //- and the default flip/negate operator
912  template<class T>
913  void reverseDistribute
914  (
915  const Pstream::commsTypes commsType,
916  const label constructSize,
917  List<T>& values,
918  const int tag = UPstream::msgType()
919  ) const;
920 
921  //- Reverse distribute data using specified commsType
922  //- and the specified flip/negate operator.
923  template<class T, class NegateOp>
924  void reverseDistribute
925  (
926  const Pstream::commsTypes commsType,
927  const label constructSize,
928  List<T>& values,
929  const NegateOp& negOp,
930  const int tag = UPstream::msgType()
931  ) const;
932 
933  //- Reverse distribute data using specified commsType
934  //- and the default flip/negate operator.
935  // Accepts a nullValue to initialize unmapped elements
936  // (ie, when the constructSize is larger than the subMap).
937  template<class T>
938  void reverseDistribute
939  (
940  const Pstream::commsTypes commsType,
941  const label constructSize,
942  const T& nullValue,
943  List<T>& values,
944  const int tag = UPstream::msgType()
945  ) const;
946 
947 
948  //- Do all sends using PstreamBuffers
949  template<class T>
950  void send(PstreamBuffers& pBufs, const List<T>& field) const;
951 
952  //- Do all receives using PstreamBuffers
953  template<class T>
954  void receive(PstreamBuffers& pBufs, List<T>& field) const;
955 
956 
957  //- Debug: print layout. Can only be used on maps with sorted
958  // storage (local data first, then non-local data)
959  void printLayout(Ostream& os) const;
960 
961 
962  // Member Operators
963 
964  //- Copy assignment
965  void operator=(const mapDistributeBase& rhs);
966 
967  //- Move assignment
968  void operator=(mapDistributeBase&& rhs);
969 
970 
971  // IOstream Operators
972 
973  //- Info proxy to print summary information to a stream
975  {
976  return *this;
977  }
978 
979  //- Read entries from dictionary format
980  void readDict(const dictionary& dict);
981 
982  //- Write entries in dictionary format
983  void writeEntries(Ostream& os) const;
984 
985  //- Read plain content (not dictionary) from Istream
987 
988  //- Write plain content (not dictionary) to Ostream
989  friend Ostream& operator<<(Ostream&, const mapDistributeBase&);
990 
991 
992  // Housekeeping
993 
994  //- No correction for topo change
995  void updateMesh(const mapPolyMesh&)
996  {
998  }
999 
1000  //- OpenFOAM-v2112 and earlier naming for compactRemoteData()
1001  //- using boolList.
1002  void compact
1003  (
1004  const boolList& remoteElemUsed,
1005  const int tag = UPstream::msgType()
1006  );
1007 
1008  //- OpenFOAM-v2112 and earlier naming for compactRemoteData().
1009  //- using boolList.
1010  void compact
1011  (
1012  const boolList& remoteElemUsed,
1013  const label localSize,
1014  labelList& oldToNewSub,
1015  labelList& oldToNewConstruct,
1016  const int tag = UPstream::msgType()
1017  );
1018 };
1019 
1020 
1021 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
1022 
1023 template<>
1024 Ostream& operator<<(Ostream& os, const InfoProxy<mapDistributeBase>& ip);
1025 
1026 
1027 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
1028 
1029 } // End namespace Foam
1030 
1031 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
1032 
1033 #ifdef NoRepository
1034  #include "mapDistributeBaseTemplates.C"
1035 #endif
1036 
1037 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
1038 
1039 #endif
1040 
1041 // ************************************************************************* //
void calcCompactAddressing(const globalIndex &globalNumbering, const labelUList &elements, List< Map< label >> &compactMap) const
Construct per processor compact addressing of the global elements.
dictionary dict
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:118
static label countUnmapped(const labelUList &elements, const labelListList &maps, const bool hasFlip)
Count the number of unmapped elements.
void compactLocalData(const bitSet &allowedLocalElems, const int tag=UPstream::msgType(), const bool doRenumber=false)
Compact send/receive maps based on selection of originating local (send) elements.
rDeltaTY field()
static label renumber(const globalIndex &, const List< Map< label >> &compactMap, const label globalElement)
Helper for construct from globalIndex. Renumbers element.
commsTypes
Types of communications.
Definition: UPstream.H:66
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:120
const List< labelPair > & schedule() const
Return a schedule. Demand driven. See above.
InfoProxy< mapDistributeBase > info() const
Info proxy to print summary information to a stream.
void send(PstreamBuffers &pBufs, const List< T > &field) const
Do all sends using PstreamBuffers.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
friend Ostream & operator<<(Ostream &, const mapDistributeBase &)
Write plain content (not dictionary) to Ostream.
label constructSize() const noexcept
Constructed data size.
label comm() const noexcept
The communicator used.
void compactRemoteData(const bitSet &allowedRemoteElems, const int tag=UPstream::msgType(), const bool doRenumber=false)
Compact send/receive maps based on selection of remote (receive) elements.
label nMaps() const noexcept
The number of sub-lists within the maps.
static int & msgType() noexcept
Message tag of standard messages.
Definition: UPstream.H:806
static label worldComm
Default world communicator (all processors). May differ from globalComm if local worlds are in use...
Definition: UPstream.H:361
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:157
mapDistributeBase()
Default construct (uses worldComm)
static void flipAndCombine(const labelUList &map, const bool hasFlip, const UList< T > &rhs, const CombineOp &cop, const NegateOp &negOp, List< T > &lhs)
friend Istream & operator>>(Istream &, mapDistributeBase &)
Read plain content (not dictionary) from Istream.
bool subHasFlip() const noexcept
Does subMap include a sign.
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
Definition: HashOps.H:164
Calculates a unique integer (label so might not have enough room - 2G max) for processor + local inde...
Definition: globalIndex.H:63
static T accessAndFlip(const UList< T > &values, const label index, const bool hasFlip, const NegateOp &negOp)
Lookup a field value at specified index and return its value after any flip negation operations...
const List< labelPair > & whichSchedule(const UPstream::commsTypes commsType) const
Return real or dummy schedule depending on the communication type.
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
Definition: DynamicList.H:51
static bool hasFlipAddressing(const labelUList &map)
Test for flip addressing, where flips are encoded as negative indices and non-flips are encoded as po...
void readDict(const dictionary &dict)
Read entries from dictionary format.
static void exchangeMasks(const UList< bitSet > &sendMasks, UList< bitSet > &recvMasks, const int tag, const label comm)
Synchronize send/recv mask buffers as a &#39;copy&#39; operation.
void compact(const boolList &remoteElemUsed, const int tag=UPstream::msgType())
OpenFOAM-v2112 and earlier naming for compactRemoteData() using boolList.
Istream & operator>>(Istream &, directionInfo &)
void printLayout(Ostream &os) const
Debug: print layout. Can only be used on maps with sorted.
void reverseDistribute(const label constructSize, List< T > &values, const int tag=UPstream::msgType()) const
Reverse distribute data using default commsType and the default flip/negate operator.
void transfer(mapDistributeBase &rhs)
Transfer the contents of the argument and annul the argument.
void updateMesh(const mapPolyMesh &)
No correction for topo change.
void operator=(const mapDistributeBase &rhs)
Copy assignment.
Class containing processor-to-processor mapping information.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:55
const direction noexcept
Definition: Scalar.H:258
bool constructHasFlip() const noexcept
Does constructMap include a sign.
OBJstream os(runTime.globalPath()/outputName)
Buffers for inter-processor communications streams (UOPstream, UIPstream).
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
void receive(PstreamBuffers &pBufs, List< T > &field) const
Do all receives using PstreamBuffers.
static void unionCombineMasks(UList< bitSet > &sendMasks, UList< bitSet > &recvMasks, const int tag, const label comm)
Bi-direction sync of send/recv buffers using bitwise &#39;&=&#39; combine operation.
const labelListList & constructMap() const noexcept
From subsetted data to new reconstructed data.
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:76
A helper class for outputting values to Ostream.
Definition: ensightCells.H:43
void exchangeAddressing(const int tag, const globalIndex &globalNumbering, labelList &elements, List< Map< label >> &compactMap, labelList &compactStart)
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:59
labelList subMapSizes() const
The sizes of the subMap lists.
static void distribute(const Pstream::commsTypes commsType, const List< labelPair > &schedule, const label constructSize, const labelListList &subMap, const bool subHasFlip, const labelListList &constructMap, const bool constructHasFlip, List< T > &field, const NegateOp &negOp, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Distribute data with specified negate operator (for flips).
void clear()
Reset to zero size, only retaining communicator.
ClassName("mapDistributeBase")
static void checkReceivedSize(const label proci, const label expectedSize, const label receivedSize)
Fatal if expected and received size are not equal.
static label getMappedSize(const labelListList &maps, const bool hasFlip)
Scan the maps for the max addressed index.
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
List< label > labelList
A List of labels.
Definition: List.H:62
const labelListList & subMap() const noexcept
From subsetted data back to original data.
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:666
List< bool > boolList
A List of bools.
Definition: List.H:60
labelList constructMapSizes() const
The sizes of the constructMap lists.
void writeEntries(Ostream &os) const
Write entries in dictionary format.
Namespace for OpenFOAM.
static label renumberMap(labelListList &mapElements, const labelUList &oldToNew, const bool hasFlip)
Helper for renumbering the (compacted) map elements using the supplied old-to-new mapping...