PABLO  0.1
PArallel Balanced Linear Octree
 All Classes Functions Variables Pages
testBubbles3D.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 
12 class bubble{
13 public:
14  double c[3];
15  double r;
16 
17 
18 };
19 
20 
21 int main(int argc, char *argv[]) {
22 
23 #if NOMPI==0
24  MPI::Init(argc, argv);
25 
26  {
27 #endif
28  int iter = 0;
29 
31  Class_Para_Tree<3> pabloBB;
32 
34  pabloBB.setBalanceCodimension(1);
35  int idx = 0;
36  pabloBB.setBalance(idx,true);
37 
39  for (iter=1; iter<5; iter++){
40  pabloBB.adaptGlobalRefine();
41  }
42 
43 #if NOMPI==0
44 
45  pabloBB.loadBalance();
46 #endif
47 
49  uint32_t nocts = pabloBB.getNumOctants();
50 
52  srand(time(NULL));
53 
54 #if NOMPI==0
55  int nb = 100;
56 #else
57  int nb = 10;
58 #endif
59  vector<bubble> BB;
60  vector<bubble> BB0;
61  vector<double> DZ;
62  vector<double> OM;
63  vector<double> AA;
64 
65  for (int i=0; i<nb; i++){
66  double randc[3];
67  randc[0] = 0.8 * (double) (rand()) / RAND_MAX + 0.1;
68  randc[1] = 0.8 * (double) (rand()) / RAND_MAX + 0.1;
69  randc[2] = (double) (rand()) / RAND_MAX - 0.5;
70  double randr = (0.05 * (double) (rand()) / RAND_MAX + 0.04);
71  //double randr = 0.005 * (double) (rand()) / RAND_MAX + 0.002;
72  double dz = 0.005 + 0.05 * (double) (rand()) / RAND_MAX;
73  double omega = 0.5 * (double) (rand()) / RAND_MAX;
74  double aa = 0.15 * (double) (rand()) / RAND_MAX;
75  bubble bb;
76  bb.c[0] = randc[0];
77  bb.c[1] = randc[1];
78  bb.c[2] = randc[2];
79  bb.r = randr;
80  BB.push_back(bb);
81  BB0.push_back(bb);
82  DZ.push_back(dz);
83  OM.push_back(omega);
84  AA.push_back(aa);
85  }
87  double t0 = 0;
88  double t = t0;
89  double Dt = 0.5;
90 
92  vector<double> oct_data(nocts, 0.0),oct_data_ghost;
93  vector<double> oct_data_new(nocts, 0.0);
94 
96  int itstart = 1;
97  int itend = 200;
98 
100  int nrefperiter = 3;
101 
103  for (iter=itstart; iter<itend; iter++){
104  if(pabloBB.rank==0) cout << "iter " << iter << endl;
105  t += Dt;
106 
108  for (int i=0; i<nb; i++){
109  BB[i].c[0] = BB0[i].c[0];// + AA[i]*cos(OM[i]*t);
110  BB[i].c[1] = BB0[i].c[1];// + AA[i]*cos(OM[i]*t);
111  BB[i].c[2] = BB[i].c[2]+ Dt*DZ[i];
112  }
113 
115  for (int iref=0; iref<nrefperiter; iref++){
116 
117  for (int i=0; i<nocts; i++){
118  bool inside = false;
120  vector<vector<double> > nodes = pabloBB.getNodes(i);
122  vector<double> center = pabloBB.getCenter(i);
123  int ib = 0;
124  while (!inside && ib<nb){
125  double xc = BB[ib].c[0];
126  double yc = BB[ib].c[1];
127  double zc = BB[ib].c[2];
128  double radius = BB[ib].r;
129 // oct_data[i] = 0.0;
131  for (int j=0; j<global3D.nnodes; j++){
132  double x = nodes[j][0];
133  double y = nodes[j][1];
134  double z = nodes[j][2];
135  if (((!inside) && (pow((x-xc),2.0)+pow((y-yc),2.0)+pow((z-zc),2.0) <= 1.15*pow(radius,2.0) &&
136  pow((x-xc),2.0)+pow((y-yc),2.0)+pow((z-zc),2.0) >= 0.85*pow(radius,2.0))) ||
137  ((!inside) && (pow((center[0]-xc),2.0)+pow((center[1]-yc),2.0)+pow((center[2]-zc),2.0) <= 1.15*pow(radius,2.0) &&
138  pow((center[0]-xc),2.0)+pow((center[1]-yc),2.0)+pow((center[2]-zc),2.0) >= 0.85*pow(radius,2.0)))){
139  if (pabloBB.getLevel(i) < 7){
141  pabloBB.setMarker(i,1);
142  oct_data[i] = 1.0;
143  }
144  else{
145  pabloBB.setMarker(i,0);
146  oct_data[i] = 1.0;
147  }
148  inside = true;
149  }
150  }
151  ib++;
152  }
153  if (pabloBB.getLevel(i) > 4 && !inside){
155  pabloBB.setMarker(i,-1);
156  oct_data[i] = 0.0;
157  }
158  }
159 
161  vector<uint32_t> mapidx;
162  vector<bool> isghost;
163  bool adapt = pabloBB.adapt(true);
164 
166  nocts = pabloBB.getNumOctants();
167 
169  oct_data_new.resize(nocts, 0);
170  for (uint32_t i=0; i<nocts; i++){
171  pabloBB.getMapping(i, mapidx, isghost);
172  oct_data_new[i] = oct_data[mapidx[i]];
173  }
174  oct_data = oct_data_new;
175  vector<double>().swap(oct_data_new);
176 
177  }
178 
179 #if NOMPI==0
180 
182  User_Data_LB<vector<double> > data_lb(oct_data,oct_data_ghost);
183  pabloBB.loadBalance(data_lb);
185  nocts = pabloBB.getNumOctants();
186 #endif
187 
189  pabloBB.updateConnectivity();
190  pabloBB.writeTest("PabloBubble3D_iter"+to_string(static_cast<unsigned long long>(iter)), oct_data);
191  }
192 
193 #if NOMPI==0
194  }
195 
196  MPI::Finalize();
197 #endif
198 }
Parallel Octree Manager Class - 3D specialization.
uint8_t getLevel(Class_Octant< 3 > *oct)
void setBalanceCodimension(uint8_t b21codim)
void getCenter(Class_Octant< 3 > *oct, dvector &center)
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)
void setBalance(Class_Octant< 3 > *oct, bool balance)