PABLO  0.1
PArallel Balanced Linear Octree
 All Classes Functions Variables Pages
test17.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;
20  Class_Para_Tree<2> pablo17a;
21  Class_Para_Tree<2> pablo17b;
22 
24  int idx = 0;
25  pablo17a.setBalance(idx,false);
26 
28  for (iter=1; iter<6; iter++){
29  pablo17a.adaptGlobalRefine();
30  pablo17b.adaptGlobalRefine();
31  }
32 
34  double xc, yc;
35  xc = yc = 0.5;
36  double radius = 0.25;
37 
39  uint32_t nocts = pablo17a.getNumOctants();
40  uint32_t nghosts = pablo17a.getNumGhosts();
41  vector<double> oct_data(nocts, 0.0);
42  vector<double> ghost_data(nghosts, 0.0);
43 
45  for (int i=0; i<nocts; i++){
47  vector<double> center = pablo17a.getCenter(i);
48  oct_data[i] = (pow((center[0]-xc),2.0)+pow((center[1]-yc),2.0));
50  vector<vector<double> > nodes = pablo17a.getNodes(i);
51  for (int j=0; j<global2D.nnodes; j++){
52  double x = nodes[j][0];
53  double y = nodes[j][1];
54  if ((pow((x-xc),2.0)+pow((y-yc),2.0) <= pow(radius,2.0))){
55  if (center[0]<=xc){
56 
58  pablo17a.setMarker(i,1);
59  }
60  else{
61 
63  pablo17a.setMarker(i,-1);
64  }
65  }
66  }
67  }
68 
70  iter = 0;
71  pablo17a.updateConnectivity();
72  pablo17b.updateConnectivity();
73  pablo17a.write("Pablo17a_iter"+to_string(static_cast<unsigned long long>(iter)));
74 // pablo7b.write("Pablo7b_iter"+to_string(static_cast<unsigned long long>((iter)));
75 
77  int start = 1;
78  for (iter=start; iter<start+2; iter++){
79  for (int i=0; i<nocts; i++){
81  vector<double> center = pablo17a.getCenter(i);
83  vector<vector<double> > nodes = pablo17a.getNodes(i);
84  for (int j=0; j<global2D.nnodes; j++){
85  double x = nodes[j][0];
86  double y = nodes[j][1];
87  if ((pow((x-xc),2.0)+pow((y-yc),2.0) <= pow(radius,2.0))){
88  if (center[0]<xc){
89 
91  pablo17a.setMarker(i,1);
92  }
93  else{
94 
96  pablo17a.setMarker(i,-1);
97  }
98  }
99  }
100  }
101 
103  vector<double> oct_data_new;
104  vector<uint32_t> mapper;
105  vector<bool> isghost;
106  pablo17a.adapt(true);
107  nocts = pablo17a.getNumOctants();
108  oct_data_new.resize(nocts, 0.0);
109 
113  for (uint32_t i=0; i<nocts; i++){
114  pablo17a.getMapping(i, mapper, isghost);
115  if (pablo17a.getIsNewC(i)){
116  for (int j=0; j<global2D.nchildren; j++){
117  if (isghost[j]){
118  oct_data_new[i] += ghost_data[mapper[j]]/global3D.nchildren;
119  }
120  else{
121  oct_data_new[i] += oct_data[mapper[j]]/global3D.nchildren;
122  }
123  }
124  }
125  else if (pablo17a.getIsNewR(i)){
126  oct_data_new[i] += oct_data[mapper[0]];
127  }
128  else{
129  oct_data_new[i] += oct_data[mapper[0]];
130  }
131  }
132  oct_data = oct_data_new;
133  oct_data_new.clear();
134 
136  pablo17a.updateConnectivity();
137  pablo17a.writeTest("Pablo17a_iter"+to_string(static_cast<unsigned long long>(iter)), oct_data);
138 
139  }
140 
141 #if NOMPI==0
142 
144  User_Data_LB<vector<double> > data_lb(oct_data,ghost_data);
145  pablo17a.loadBalance(data_lb);
146  pablo17b.loadBalance();
147 
149  pablo17a.updateConnectivity();
150  pablo17a.writeTest("Pablo17a_iter"+to_string(static_cast<unsigned long long>(iter)), oct_data);
151 
152 #endif
153 
154 
156  vector<pair<pair<uint32_t,uint32_t>, pair<int, int> > > mapPablo;
157  nocts = pablo17b.getNumOctants();
158  mapPablo = pablo17b.mapPablos(pablo17a);
159  vector<double> oct_data_b(nocts);
160 // /**<Assign data to the new octree : process owner the first octant index in mapPablo.*/
161 // for (int i=0; i<nocts; i++){
162 // oct_data_b[i] = mapPablo[i].second.first;
163 // }
165  for (int i=0; i<nocts; i++){
166  oct_data_b[i] = mapPablo[i].first.first;
167  }
168 
170  pablo17b.updateConnectivity();
171  pablo17b.writeTest("Pablo17b_iter"+to_string(static_cast<unsigned long long>(iter)), oct_data_b);
172 
173 #if NOMPI==0
174  }
175 
176  MPI::Finalize();
177 #endif
178 }
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)
vector< pair< pair< uint32_t, uint32_t >, pair< int, int > > > mapPablos(Class_Para_Tree< 2 > &ptree)
bool getIsNewR(Class_Octant< 2 > *oct)
void write(string filename)
void setBalance(Class_Octant< 2 > *oct, bool balance)
void getCenter(Class_Octant< 2 > *oct, vector< double > &center)