PABLO  0.1
PArallel Balanced Linear Octree
 All Classes Functions Variables Pages
testBubbles.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[2];
15  double r;
16 };
17 
18 
19 int main(int argc, char *argv[]) {
20 
21 #if NOMPI==0
22  MPI::Init(argc, argv);
23 
24  {
25 #endif
26  int iter = 0;
27 
29  Class_Para_Tree<2> pabloBB;
30 
32  pabloBB.setBalanceCodimension(1);
33  int idx = 0;
34  pabloBB.setBalance(idx,true);
35 
37  for (iter=1; iter<7; iter++){
38  pabloBB.adaptGlobalRefine();
39  }
40 
41 #if NOMPI==0
42 
43  pabloBB.loadBalance();
44 #endif
45 
47  uint32_t nocts = pabloBB.getNumOctants();
48 
50  time_t Time = time(NULL);
51  srand(Time);
52  if(pabloBB.rank == 0)
53  cout << "the seed = " << Time << endl;
54 
55 #if NOMPI==0
56  int nb = 100;
57 #else
58  int nb = 10;
59 #endif
60  vector<bubble> BB;
61  vector<bubble> BB0;
62  vector<double> DY;
63  vector<double> OM;
64  vector<double> AA;
65 
66  for (int i=0; i<nb; i++){
67  double randc[2];
68  randc[0] = 0.8 * (double) (rand()) / RAND_MAX + 0.1;
69  randc[1] = (double) (rand()) / RAND_MAX - 0.5;
70  double randr = 0.05 * (double) (rand()) / RAND_MAX + 0.02;
71  double dy = 0.005 + 0.05 * (double) (rand()) / RAND_MAX;
72  double omega = 0.5 * (double) (rand()) / RAND_MAX;
73  double aa = 0.15 * (double) (rand()) / RAND_MAX;
74  bubble bb;
75  bb.c[0] = randc[0];
76  bb.c[1] = randc[1];
77  bb.r = randr;
78  BB.push_back(bb);
79  BB0.push_back(bb);
80  DY.push_back(dy);
81  OM.push_back(omega);
82  AA.push_back(aa);
83  }
85  double t0 = 0;
86  double t = t0;
87  double Dt = 0.5;
88 
90  int itstart = 1;
91  int itend = 200;
92 
94  int nrefperiter = 4;
95 
97  for (iter=itstart; iter<itend; iter++){
98  if(pabloBB.rank==0) cout << "iter " << iter << endl;
99  t += Dt;
100 
102  for (int i=0; i<nb; i++){
103  BB[i].c[0] = BB0[i].c[0] + AA[i]*cos(OM[i]*t);
104  BB[i].c[1] = BB[i].c[1]+ Dt*DY[i];
105  }
106 
108  for (int iref=0; iref<nrefperiter; iref++){
109 
110  for (int i=0; i<nocts; i++){
111  bool inside = false;
113  vector<vector<double> > nodes = pabloBB.getNodes(i);
115  vector<double> center = pabloBB.getCenter(i);
116  int ib = 0;
117  while (!inside && ib<nb){
118  double xc = BB[ib].c[0];
119  double yc = BB[ib].c[1];
120  double radius = BB[ib].r;
122  for (int j=0; j<global2D.nnodes; j++){
123  double x = nodes[j][0];
124  double y = nodes[j][1];
125  if ( ((!inside) &&
126  (pow((x-xc),2.0)+pow((y-yc),2.0) <= 1.15*pow(radius,2.0) &&
127  pow((x-xc),2.0)+pow((y-yc),2.0) >= 0.85*pow(radius,2.0)))
128  || ((!inside) && (pow((center[0]-xc),2.0)+pow((center[1]-yc),2.0) <= 1.15*pow(radius,2.0) &&
129  pow((center[0]-xc),2.0)+pow((center[1]-yc),2.0) >= 0.85*pow(radius,2.0)))){
130  if (pabloBB.getLevel(i) < 9){
132  pabloBB.setMarker(i,1);
133  }
134  else{
135  pabloBB.setMarker(i,0);
136  }
137  inside = true;
138  }
139  }
140  ib++;
141  }
142  if (pabloBB.getLevel(i) > 6 && !inside){
144  pabloBB.setMarker(i,-1);
145  }
146  }
147 
149  bool adapt = pabloBB.adapt();
150 
151 #if NOMPI==0
152 
153  pabloBB.loadBalance();
154 #endif
155 
157  nocts = pabloBB.getNumOctants();
158 
159  }
160 
162  pabloBB.updateConnectivity();
163  pabloBB.write("PabloBubble_iter"+to_string(static_cast<unsigned long long>(iter)));
164  }
165 #if NOMPI==0
166  }
167 
168  MPI::Finalize();
169 #endif
170 }
uint8_t getLevel(Class_Octant< 2 > *oct)
Parallel Octree Manager Class - 2D specialization.
void setMarker(Class_Octant< 2 > *oct, int8_t marker)
void getNodes(Class_Octant< 2 > *oct, dvector2D &nodes)
uint32_t getNumOctants() const
void setBalanceCodimension(uint8_t b21codim)
void write(string filename)
void setBalance(Class_Octant< 2 > *oct, bool balance)
void getCenter(Class_Octant< 2 > *oct, vector< double > &center)