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 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 private:
49 IntMat tg[2];
50 const GridType& grid;
51
57 int getStripDirection (int nel1, int nel2, int nel3, int parts)
58 {
59 int s1 = nel1 / parts;
60 int s2 = nel2 / parts;
61 int s3 = nel3 / parts;
62 int r1 = nel1 - s1*parts;
63 int r2 = nel2 - s2*parts;
64 int r3 = nel3 - s3*parts;
65
66 if (r1*nel2*nel3 < nel1*r2*nel3 && r1*nel2*nel3 < nel1*nel2*r3)
67 return 0; // strips along x axis
68 else if (nel1*r2*nel3 < r1*nel2*nel3 && nel1*r2*nel3 < nel1*nel2*r3)
69 return 1; // strips along y axis
70 else if (nel1*nel2*r3 < r1*nel2*nel3 && nel1*nel2*r3 < nel1*r2*nel3)
71 return 2; // strips along z axis
72
73 // The number of left-over elements is not smallest in one direction only
74 if (r1*nel2*nel3 > nel1*r2*nel3)
75 return nel2 > nel3 ? 1 : 2;
76 else if (nel1*r2*nel3 > nel1*nel2*r3)
77 return nel1 > nel3 ? 0 : 2;
78 else if (nel1*nel2*r3 > r1*nel2*nel3)
79 return nel1 > nel2 ? 0 : 1;
80
81 // The number of left-over elements is the same in all three directions
82 if (nel1 >= nel2 && nel1 >= nel3)
83 return 0;
84 else if (nel2 >= nel1 && nel2 >= nel3)
85 return 1;
86 else
87 return 2;
88 }
89};
90
91#endif
Generate a coloring of a mesh suitable for threaded assembly. The mesh is assumed structured,...
Definition: meshcolorizer.hpp:26
void calcGroups()
Calculate the coloring.
MeshColorizer(const GridType &grid_)
Default constructor.
Definition: meshcolorizer.hpp:33
const IntMat & operator[](unsigned int i)
Return a color group.
Definition: meshcolorizer.hpp:41