PABLO  0.1
PArallel Balanced Linear Octree
 All Classes Functions Variables Pages
test7.cpp
1 #include "preprocessor_defines.dat"
2 #include "Class_Global.hpp"
3 #include "Class_Para_Tree.hpp"
4 
5 using namespace std;
6 
7 // =================================================================================== //
8 
9 int main(int argc, char *argv[]) {
10 
11 #if NOMPI==0
12  MPI::Init(argc, argv);
13 
14  {
15 #endif
16  int iter = 0;
18  Class_Para_Tree<2> pablo7a;
19 
21  int idx = 0;
22  pablo7a.setBalance(idx,false);
23 
25  for (iter=1; iter<6; iter++){
26  pablo7a.adaptGlobalRefine();
27  }
28 
30  Class_Para_Tree<2> pablo7b = pablo7a;
31 
33  double xc, yc;
34  xc = yc = 0.5;
35  double radius = 0.25;
36 
38  uint32_t nocts = pablo7a.getNumOctants();
39  vector<double> oct_data(nocts, 0.0);
40 
42  for (int i=0; i<nocts; i++){
44  vector<double> center = pablo7a.getCenter(i);
45  oct_data[i] = (pow((center[0]-xc),2.0)+pow((center[1]-yc),2.0));
47  vector<vector<double> > nodes = pablo7a.getNodes(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  if (center[0]<=xc){
53 
55  pablo7a.setMarker(i,1);
56  }
57  else{
58 
60  pablo7a.setMarker(i,-1);
61  }
62  }
63  }
64  }
65 
67  iter = 0;
68  pablo7a.updateConnectivity();
69  pablo7b.updateConnectivity();
70  pablo7a.write("Pablo7a_iter"+to_string(static_cast<unsigned long long>(iter)));
71 // pablo7b.write("Pablo7b_iter"+to_string(static_cast<unsigned long long>(iter)));
72 
74  int start = 1;
75  for (iter=start; iter<start+2; iter++){
76  for (int i=0; i<nocts; i++){
78  vector<double> center = pablo7a.getCenter(i);
80  vector<vector<double> > nodes = pablo7a.getNodes(i);
81  for (int j=0; j<global2D.nnodes; j++){
82  double x = nodes[j][0];
83  double y = nodes[j][1];
84  if ((pow((x-xc),2.0)+pow((y-yc),2.0) <= pow(radius,2.0))){
85  if (center[0]<xc){
86 
88  pablo7a.setMarker(i,1);
89  }
90  else{
91 
93  pablo7a.setMarker(i,-1);
94  }
95  }
96  }
97  }
98 
100  vector<double> oct_data_new;
101  vector<uint32_t> mapper;
102  vector<bool> isghost;
103  pablo7a.adapt(true);
104  nocts = pablo7a.getNumOctants();
105  oct_data_new.resize(nocts, 0.0);
106 
110  for (uint32_t i=0; i<nocts; i++){
111  pablo7a.getMapping(i, mapper, isghost);
112  if (pablo7a.getIsNewC(i)){
113  for (int j=0; j<global2D.nchildren; j++){
114  oct_data_new[i] += oct_data[mapper[j]]/global2D.nchildren;
115  }
116  }
117  else if (pablo7a.getIsNewR(i)){
118  oct_data_new[i] += oct_data[mapper[0]];
119  }
120  else{
121  oct_data_new[i] += oct_data[mapper[0]];
122  }
123  }
124  oct_data = oct_data_new;
125  oct_data_new.clear();
126 
128  pablo7a.updateConnectivity();
129  pablo7a.writeTest("Pablo7a_iter"+to_string(static_cast<unsigned long long>(iter)), oct_data);
130 
131  }
132 
133 
135  vector<pair<pair<uint32_t,uint32_t>, pair<int, int> > > mapPablo;
136  nocts = pablo7b.getNumOctants();
137  mapPablo = pablo7b.mapPablos(pablo7a);
138  vector<double> oct_data_b(nocts);
140  for (int i=0; i<nocts; i++){
141  oct_data_b[i] = oct_data[mapPablo[i].first.second];
142  }
143 
145  pablo7b.updateConnectivity();
146  pablo7b.writeTest("Pablo7b_iter"+to_string(static_cast<unsigned long long>(iter)), oct_data_b);
147 
148 #if NOMPI==0
149  }
150 
151  MPI::Finalize();
152 #endif
153 }
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
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)