PABLO  0.1
PArallel Balanced Linear Octree
 All Classes Functions Variables Pages
test15.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<2> pablo15;
22 
24  int idx = 0;
25  pablo15.setBalance(idx,false);
26 
28  for (iter=1; iter<6; iter++){
29  pablo15.adaptGlobalRefine();
30  }
31 
33  double xc, yc;
34  xc = yc = 0.5;
35  double radius = 0.25;
36 
38  uint32_t nocts = pablo15.getNumOctants();
39  uint32_t nghosts = pablo15.getNumGhosts();
40  vector<double> oct_data(nocts, 0.0), ghost_data(nghosts, 0.0);
41 
43  for (int i=0; i<nocts; i++){
45  vector<vector<double> > nodes = pablo15.getNodes(i);
47  vector<double> center = pablo15.getCenter(i);
48  for (int j=0; j<global2D.nnodes; j++){
49  double x = nodes[j][0];
50  double y = nodes[j][1];
51  if ((pow((x-xc),2.0)+pow((y-yc),2.0) <= pow(radius,2.0))){
52  oct_data[i] = (pow((center[0]-xc),2.0)+pow((center[1]-yc),2.0));
53  }
54  }
55  }
56 
58  iter = 0;
59  pablo15.updateConnectivity();
60  pablo15.writeTest("Pablo15_iter"+to_string(static_cast<unsigned long long>(iter)), oct_data);
61 
63  int start = 1;
65  vector<double> weight(nocts, 1.0),weightGhost;
66  for (iter=start; iter<start+2; iter++){
67  for (int i=0; i<nocts; i++){
69  vector<vector<double> > nodes = pablo15.getNodes(i);
71  vector<double> center = pablo15.getCenter(i);
72  for (int j=0; j<global2D.nnodes; j++){
73  weight[i] = 2.0;
74  double x = nodes[j][0];
75  double y = nodes[j][1];
76  if ((pow((x-xc),2.0)+pow((y-yc),2.0) <= pow(radius,2.0))){
77  if (center[0]<=xc){
78 
80  pablo15.setMarker(i,1);
81  weight[i] = 1.0;
82  }
83  else{
84 
86  pablo15.setMarker(i,-1);
87  weight[i] = 100.0;
88  }
89  }
90  }
91  }
92 
94  vector<double> oct_data_new;
95  vector<double> weight_new;
96  vector<uint32_t> mapper;
97  vector<bool> isghost;
98  pablo15.adapt(true);
99  nocts = pablo15.getNumOctants();
100  oct_data_new.resize(nocts, 0.0);
101  weight_new.resize(nocts,0.0);
102 
106  for (uint32_t i=0; i<nocts; i++){
107  pablo15.getMapping(i, mapper, isghost);
108  if (pablo15.getIsNewC(i)){
109  for (int j=0; j<global2D.nchildren; j++){
110  oct_data_new[i] += oct_data[mapper[j]]/global2D.nchildren;
111  weight_new[i] += weight[mapper[j]];
112  }
113  }
114  else if (pablo15.getIsNewR(i)){
115  oct_data_new[i] += oct_data[mapper[0]];
116  weight_new[i] += weight[mapper[0]];
117  }
118  else{
119  oct_data_new[i] += oct_data[mapper[0]];
120  weight_new[i] += weight[mapper[0]];
121  }
122  }
123 
125  pablo15.updateConnectivity();
126  pablo15.writeTest("Pablo15_iter"+to_string(static_cast<unsigned long long>(iter)), oct_data_new);
127 
128  oct_data = oct_data_new;
129  weight = weight_new;
130  }
131 
132 #if NOMPI==0
133 
134 // User_Data_LB<vector<double> > data_lb(oct_data);
135  User_Data_LB<vector<double> > data_lb(weight,weightGhost);
136  pablo15.loadBalance(data_lb, &weight);
137 #endif
138 
139  double tot = 0.0;
140  for (int i=0; i<weight.size(); i++){
141  tot += weight[i];
142  }
143  cout << pablo15.rank << " weight : " << tot << endl;
144  cout << pablo15.rank << " size : " << weight.size() << endl;
145 
147  pablo15.updateConnectivity();
148 // pablo15.writeTest("Pablo15_iter"+to_string(static_cast<unsigned long long>(iter)), oct_data);
149  pablo15.writeTest("Pablo15_iter"+to_string(static_cast<unsigned long long>(iter)), weight);
150 
151 #if NOMPI==0
152  }
153 
154  MPI::Finalize();
155 #endif
156 }
157 
158 
159 
void writeTest(string filename, vector< double > data)
Parallel Octree Manager Class - 2D specialization.
void setMarker(Class_Octant< 2 > *oct, int8_t marker)
bool getIsNewC(Class_Octant< 2 > *oct)
void getNodes(Class_Octant< 2 > *oct, dvector2D &nodes)
uint32_t getNumOctants() const
uint32_t getNumGhosts() const
void getMapping(uint32_t &idx, u32vector &mapper, vector< bool > &isghost)
bool getIsNewR(Class_Octant< 2 > *oct)
void setBalance(Class_Octant< 2 > *oct, bool balance)
void getCenter(Class_Octant< 2 > *oct, vector< double > &center)