1 #ifndef PARALLELMERGEMESH_HPP
2 #define PARALLELMERGEMESH_HPP
3 
4 #include "moab/Types.hpp"
5 #include <vector>
6 #include "moab/Range.hpp"
7 #include "moab/ParallelComm.hpp"
8 
9 #include "moab/TupleList.hpp"
10 #include "moab/gs.hpp"
11 
12 /*
13   Class to merge meshes in parallel
14   Requires a ParallelComm and tolerance epsilon
15   Currently uses a 1 dimensional partition of the global box
16 */
17 
18 namespace moab {
19 
20   class ParallelComm;
21   class TupleList;
22 
23   class ParallelMergeMesh {
24   public:
25     ParallelMergeMesh(ParallelComm *pc,
26 		      const double epsilon);
27 
28     //Public Function to identify shared elements
29     ErrorCode merge(EntityHandle levelset=0, bool skip_local_merge=false);
30 
31   private:
32     ParallelComm *myPcomm;
33     Interface *myMB;
34     std::vector<Range> mySkinEnts;
35     double myEps;
36     TupleList myTup, myMatches;
37     gs_data::crystal_data myCD;
38 
39     //Wrapper of merge() that performs the merge
40     ErrorCode PerformMerge(EntityHandle levelset=0, bool skip_local_merge=false);
41     //Determine the local skin entities (fills mySkinEnts)
42     ErrorCode PopulateMySkinEnts(const EntityHandle meshset,int dim, bool skip_local_merge=false);
43     //Get the global bounding box
44     ErrorCode GetGlobalBox(double *gbox);
45     //Fill out the local myTup before the first gather-scatter
46     ErrorCode PopulateMyTup(double * gbox);
47     //Once myTup is filled and gather scattered, figure out the matches
48     ErrorCode PopulateMyMatches();
49     //Sort the matching tuples
50     ErrorCode SortMyMatches();
51     //Tag the shared elements once the myMatches has been filled
52     ErrorCode TagSharedElements(int dim);
53     //Cleanup any data allocated by class members
54     void CleanUp();
55     //Partition the global box by the number of procs
56     //Returns results in lengths and parts, which needs to be of length 3
57     ErrorCode PartitionGlobalBox(double *gbox, double *lengths, int *parts);
58     //A function for determining how many parts a side should be split into
59     static int PartitionSide(double sideLeng, double restLen, unsigned numProcs, bool altRatio);
60 
61     //Swap 2 tuples
62     static void SwapTuples(TupleList &tup,
63 			   unsigned long a,
64 			   unsigned long b);
65 
66     //Sort a tuple list by its real values
67     static void SortTuplesByReal(TupleList &tup,
68 				 double eps2=0);
69 
70     //The recursive sorting function
71     static void PerformRealSort(TupleList &tup,
72 				unsigned long left,
73 				unsigned long right,
74 				double eps2,
75 				uint tup_mr);
76 
77     //Determines whether tuple i is greater than tuple j
78     static bool TupleGreaterThan(TupleList &tup,
79 				 unsigned long vrI,
80 				 unsigned long vrJ,
81 				 double eps2,
82 				 uint tup_mr);
83   };
84 
85 } // namespace moab
86 
87 #endif
88