PABLO  0.1
PArallel Balanced Linear Octree
 All Classes Functions Variables Pages
test_temp.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> pablo;
22 
24  int idx = 0;
25  pablo.setBalance(idx,false);
26 
28  for (iter=1; iter<6; iter++){
29  pablo.adaptGlobalRefine();
30  }
31 
32 #if NOMPI==0
33 
34  // User_Data_LB<vector<double> > data_lb(oct_data);
35  pablo.loadBalance();
36 #endif
37 
38 
40  double xc, yc;
41  xc = yc = 0.5;
42  double radius = 0.25;
43 
45  uint32_t nocts = pablo.getNumOctants();
46  uint32_t nghosts = pablo.getNumGhosts();
47  vector<double> oct_data(nocts, 0.0), ghost_data(nghosts, 0.0);
48 
50  for (int i=0; i<nocts; i++){
52  vector<vector<double> > nodes = pablo.getNodes(i);
54  vector<double> center = pablo.getCenter(i);
55  for (int j=0; j<global2D.nnodes; j++){
56  double x = nodes[j][0];
57  double y = nodes[j][1];
58  if ((pow((x-xc),2.0)+pow((y-yc),2.0) <= pow(radius,2.0))){
59  oct_data[i] = (pow((center[0]-xc),2.0)+pow((center[1]-yc),2.0));
60  }
61  }
62  }
63 
64  {
65 #if NOMPI==0
66 
67  User_Data_Comm<vector<double> > data_comm(oct_data, ghost_data);
68  pablo.communicate(data_comm);
69 #endif
70  }
71 
73  iter = 0;
74  pablo.updateConnectivity();
75  pablo.writeTest("Pablo_iter"+to_string(static_cast<unsigned long long>(iter)), oct_data);
76 
78  int start = 1;
79  for (iter=start; iter<start+2; iter++){
80  for (int i=0; i<nocts; i++){
82  vector<vector<double> > nodes = pablo.getNodes(i);
84  vector<double> center = pablo.getCenter(i);
85  for (int j=0; j<global2D.nnodes; j++){
86  double x = nodes[j][0];
87  double y = nodes[j][1];
88  if ((pow((x-xc),2.0)+pow((y-yc),2.0) <= pow(radius,2.0))){
89  if (center[0]<=xc){
90 
92  pablo.setMarker(i,1);
93  }
94  else{
95 
97  pablo.setMarker(i,-1);
98  }
99  }
100  }
101  }
102 
104  vector<double> oct_data_new, ghost_data_new;
105  vector<uint32_t> mapper;
106  vector<bool> isghost;
107  pablo.adapt(true);
108  nocts = pablo.getNumOctants();
109  nghosts = pablo.getNumGhosts();
110  oct_data_new.resize(nocts, 0.0);
111  ghost_data_new.resize(nghosts, 0.0);
112 
116  cout << "iter " << iter << endl;
117  for (uint32_t i=0; i<nocts; i++){
118  pablo.getMapping(i, mapper, isghost);
119  if (pablo.getIsNewC(i)){
120  for (int j=0; j<global2D.nchildren; j++){
121  if (isghost[j]){
122  cout << pablo.rank << " using ghost for idx " << i << endl;
123  oct_data_new[i] += ghost_data[mapper[j]]/global2D.nchildren;
124  }
125  else{
126  oct_data_new[i] += oct_data[mapper[j]]/global2D.nchildren;
127  }
128  }
129  }
130  else if (pablo.getIsNewR(i)){
131  oct_data_new[i] += oct_data[mapper[0]];
132  }
133  else{
134  oct_data_new[i] += oct_data[mapper[0]];
135  }
136  }
137 
138  oct_data = oct_data_new;
139  ghost_data = ghost_data_new;
140 
141 #if NOMPI==0
142 
143  User_Data_LB<vector<double> > data_lb(oct_data,ghost_data);
144  pablo.loadBalance(data_lb);
145 #endif
146 
147  nocts = pablo.getNumOctants();
148  nghosts = pablo.getNumGhosts();
149  ghost_data_new.resize(nghosts, 0.0);
150  ghost_data = ghost_data_new;
151 
152 
153 #if NOMPI==0
154 
155  User_Data_Comm<vector<double> > data_comm(oct_data, ghost_data);
156  pablo.communicate(data_comm);
157 #endif
158 
159  cout << " Out comm " << endl;
160 
162  pablo.updateConnectivity();
163  pablo.writeTest("Pablo_iter"+to_string(static_cast<unsigned long long>(iter)), oct_data);
164 
165  }
166 
167 
169  pablo.updateConnectivity();
170  pablo.writeTest("Pablo_iter"+to_string(static_cast<unsigned long long>(iter)), oct_data);
171 
172 
173 
174 
175 
176 
177 #if NOMPI==0
178  }
179 
180  MPI::Finalize();
181 #endif
182 }
183 
184 
185 
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)
void communicate(Class_Data_Comm_Interface< Impl > &userData)
bool getIsNewR(Class_Octant< 2 > *oct)
void setBalance(Class_Octant< 2 > *oct, bool balance)
void getCenter(Class_Octant< 2 > *oct, vector< double > &center)