opm-upscaling
meshcolorizer.hpp
Go to the documentation of this file.
1 //==============================================================================
11 //==============================================================================
12 
13 #ifndef MESHCOLORIZER_HPP_
14 #define MESHCOLORIZER_HPP_
15 
16 #include <vector>
17 
25  template<class GridType>
27  typedef std::vector<int> IntVec;
28  typedef std::vector<IntVec> IntMat;
29 
30  public:
33  explicit MeshColorizer(const GridType& grid_) :
34  grid(grid_)
35  {
36  calcGroups();
37  }
38 
41  const IntMat& operator[](unsigned int i)
42  {
43  return tg[i];
44  }
45 
47  void calcGroups()
48  {
49  tg[0].resize(1);
50  tg[0].reserve(grid.size(0));
51  for (int i = 0; i < grid.size(0); ++i) {
52  tg[0][0].push_back(i);
53  }
54  tg[1].clear();
55  }
56 
57  private:
58  IntMat tg[2];
59  const GridType& grid;
60 
66  int getStripDirection (int nel1, int nel2, int nel3, int parts)
67  {
68  int s1 = nel1 / parts;
69  int s2 = nel2 / parts;
70  int s3 = nel3 / parts;
71  int r1 = nel1 - s1*parts;
72  int r2 = nel2 - s2*parts;
73  int r3 = nel3 - s3*parts;
74 
75  if (r1*nel2*nel3 < nel1*r2*nel3 && r1*nel2*nel3 < nel1*nel2*r3)
76  return 0; // strips along x axis
77  else if (nel1*r2*nel3 < r1*nel2*nel3 && nel1*r2*nel3 < nel1*nel2*r3)
78  return 1; // strips along y axis
79  else if (nel1*nel2*r3 < r1*nel2*nel3 && nel1*nel2*r3 < nel1*r2*nel3)
80  return 2; // strips along z axis
81 
82  // The number of left-over elements is not smallest in one direction only
83  if (r1*nel2*nel3 > nel1*r2*nel3)
84  return nel2 > nel3 ? 1 : 2;
85  else if (nel1*r2*nel3 > nel1*nel2*r3)
86  return nel1 > nel3 ? 0 : 2;
87  else if (nel1*nel2*r3 > r1*nel2*nel3)
88  return nel1 > nel2 ? 0 : 1;
89 
90  // The number of left-over elements is the same in all three directions
91  if (nel1 >= nel2 && nel1 >= nel3)
92  return 0;
93  else if (nel2 >= nel1 && nel2 >= nel3)
94  return 1;
95  else
96  return 2;
97  }
98 };
99 
100 #endif
const IntMat & operator[](unsigned int i)
Return a color group.
Definition: meshcolorizer.hpp:41
Generate a coloring of a mesh suitable for threaded assembly.
Definition: meshcolorizer.hpp:26
MeshColorizer(const GridType &grid_)
Default constructor.
Definition: meshcolorizer.hpp:33
void calcGroups()
Calculate the coloring.
Definition: meshcolorizer.hpp:47