PABLO  0.1
PArallel Balanced Linear Octree
 All Classes Functions Variables Pages
test116.cpp
1 #include "preprocessor_defines.dat"
2 #include "Class_Global.hpp"
3 #include "Class_Para_Tree.hpp"
4 #include "User_Data_Comm.hpp"
5 #include "User_Data_LB.hpp"
6 
7 using namespace std;
8 
9 // =================================================================================== //
10 
11 int main(int argc, char *argv[]) {
12 
13 #if NOMPI==0
14  MPI::Init(argc, argv);
15 
16  {
17 #endif
18  int iter = 0;
19 
21  Class_Para_Tree<3> pablo116;
22 
24  int idx = 0;
25  pablo116.setBalance(idx,false);
26 
28  for (iter=1; iter<6; iter++){
29  pablo116.adaptGlobalRefine();
30  }
31 
32 #if NOMPI==0
33 
34  pablo116.loadBalance();
35 #endif
36 
38  double xc, yc;
39  xc = yc = 0.5;
40  double radius = 0.25;
41 
43  uint32_t nocts = pablo116.getNumOctants();
44  uint32_t nghosts = pablo116.getNumGhosts();
45  vector<double> oct_data(nocts, 0.0), ghost_data(nghosts, 0.0);
46 
48  for (int i=0; i<nocts; i++){
50  vector<vector<double> > nodes = pablo116.getNodes(i);
52  vector<double> center = pablo116.getCenter(i);
53  for (int j=0; j<global3D.nnodes; j++){
54  double x = nodes[j][0];
55  double y = nodes[j][1];
56  if ((pow((x-xc),2.0)+pow((y-yc),2.0) <= pow(radius,2.0))){
57  oct_data[i] = (pow((center[0]-xc),2.0)+pow((center[1]-yc),2.0));
58  }
59  }
60  }
61 
63  iter = 0;
64  pablo116.updateConnectivity();
65  pablo116.writeTest("Pablo116_iter"+to_string(static_cast<unsigned long long>(iter)), oct_data);
66 
68  int start = 1;
69  for (iter=start; iter<start+2; iter++){
70  for (int i=0; i<nocts; i++){
72  vector<vector<double> > nodes = pablo116.getNodes(i);
74  vector<double> center = pablo116.getCenter(i);
75  for (int j=0; j<global3D.nnodes; j++){
76  double x = nodes[j][0];
77  double y = nodes[j][1];
78  if ((pow((x-xc),2.0)+pow((y-yc),2.0) <= pow(radius,2.0))){
79  if (center[0]<=xc){
80 
82  pablo116.setMarker(i,1);
83  }
84  else{
85 
87  pablo116.setMarker(i,-1);
88  }
89  }
90  }
91  }
92 
94  vector<double> oct_data_new;
95  vector<uint32_t> mapper;
96  vector<bool> isghost;
97  pablo116.adapt(true);
98  nocts = pablo116.getNumOctants();
99  oct_data_new.resize(nocts, 0.0);
100 
104  for (uint32_t i=0; i<nocts; i++){
105  pablo116.getMapping(i, mapper, isghost);
106  if (pablo116.getIsNewC(i)){
107  for (int j=0; j<global3D.nchildren; j++){
108  if (isghost[j]){
109  oct_data_new[i] += ghost_data[mapper[j]]/global3D.nchildren;
110  }
111  else{
112  oct_data_new[i] += oct_data[mapper[j]]/global3D.nchildren;
113  }
114  }
115  }
116  else if (pablo116.getIsNewR(i)){
117  oct_data_new[i] += oct_data[mapper[0]];
118  }
119  else{
120  oct_data_new[i] += oct_data[mapper[0]];
121  }
122  }
123 
125  pablo116.updateConnectivity();
126  pablo116.writeTest("Pablo116_iter"+to_string(static_cast<unsigned long long>(iter)), oct_data_new);
127 
128  oct_data = oct_data_new;
129  }
130 
131 #if NOMPI==0
132 
134  uint8_t levels = 4;
135  User_Data_LB<vector<double> > data_lb(oct_data,ghost_data);
136  pablo116.loadBalance(data_lb, levels);
137 #endif
138 
140  pablo116.updateConnectivity();
141  pablo116.writeTest("Pablo116_iter"+to_string(static_cast<unsigned long long>(iter)), oct_data);
142 
143 #if NOMPI==0
144  }
145 
146  MPI::Finalize();
147 #endif
148 }
Parallel Octree Manager Class - 3D specialization.
void getCenter(Class_Octant< 3 > *oct, dvector &center)
bool getIsNewC(Class_Octant< 3 > *oct)
void getNodes(Class_Octant< 3 > *oct, dvector2D &nodes)
uint32_t getNumOctants() const
void setMarker(Class_Octant< 3 > *oct, int8_t marker)
void getMapping(uint32_t &idx, u32vector &mapper, vector< bool > &isghost)
void writeTest(string filename, vector< double > data)
bool getIsNewR(Class_Octant< 3 > *oct)
void setBalance(Class_Octant< 3 > *oct, bool balance)
uint32_t getNumGhosts() const