AMR-Solver  1.0
Block-based Octree AMR grid flow solver
octreegrid.cpp
Go to the documentation of this file.
1 #include "octree.h"
2 #include "vtk.h"
3 #include "boundary.h"
4 #include <iostream>
5 #include "direction.h"
6 #include "ghost.h"
7 
9 
10 namespace myOctree {
11 
12 extern int max_level;
13 
14 std::list<Octree*> nodes;
15 std::list<Octree*> leaf_nodes;
16 std::list<Octree*> root_nodes;
17 std::list<Octree*> level_nodes[20];
18 
19 
22 
23  leaf_nodes.clear();
24 
25  for (std::list<Octree*>::iterator i = nodes.begin(), end = nodes.end(); i != end; ++i) {
26  if((*i)->isLeafNode())
27  leaf_nodes.push_back(*i);
28  }
29 }
30 
33 
34  root_nodes.clear();
35 
36  for (std::list<Octree*>::iterator i = nodes.begin(), end = nodes.end(); i != end; ++i) {
37  if((*i)->isRootNode())
38  root_nodes.push_back(*i);
39  }
40 }
41 
44 
45  //clearing all lists
46  for (unsigned level=0; level <= max_level; level++) {
47  level_nodes[level].clear();
48  }
49 
50 
51  //pushing nodes to respective lists
52  for (std::list<Octree*>::iterator j = nodes.begin(), end = nodes.end(); j != end; ++j) {
53  int level = (*j)->get_level();
54  level_nodes[level].push_back(*j);
55  }
56 
57 }
58 
60 void create_node(int blocknumber, double xmin, double xmax, double ymin, double ymax, double zmin, double zmax, int level, NodeBc **bc) {
61 
62  //memory allocation to new node
63  Octree r(xmin,xmax,ymin,ymax,zmin,zmax,level);
64  nodes.pop_back();
65  Octree* root = new Octree(r);
66 
67  //boundaries are assigned to this root node
68 // root->east_bc = east_bc;
69 // root->west_bc = west_bc;
70 // root->north_bc = north_bc;
71 // root->south_bc = south_bc;
72 // root->top_bc = top_bc;
73 // root->bottom_bc = bottom_bc;
74 
75  for(int i=0;i<3;i++) {
76  for(int j=0;j<2;j++) {
77  root->bc[i][j] = bc[i][j];
78  }
79  }
80 
81  root->number = blocknumber;
82 
83 }
84 
91 
92  for (unsigned level=0; level <= max_level; level++) {
93 
94 
95  for (std::list<Octree*>::iterator iter = level_nodes[level].begin(), end = level_nodes[level].end(); iter != end; ++iter) {
96  //if it is not leaf node
97  if(!((*iter)->isLeafNode())) {
98 
99  //setting neighbours to children
100  for(int k=0; k<2; k++) {
101  for(int j=0; j<2; j++) {
102  for(int i=0; i<2; i++) {
103 
104  // if(i==0) {
105  // if((*iter)->west != NULL) (*iter)->get_child_at(i, j, k)->west = (*iter)->west->get_child_at(i+1, j, k);
106  // }
107  // if(j==0) {
108  // if((*iter)->south != NULL) (*iter)->get_child_at(i, j, k)->south = (*iter)->south->get_child_at(i, j+1, k);
109  // }
110  // if(k==0) {
111  // if((*iter)->bottom != NULL) (*iter)->get_child_at(i, j, k)->bottom = (*iter)->bottom->get_child_at(i, j, k+1);
112  // }
113  // if(i==1) {
114  // if((*iter)->east != NULL) (*iter)->get_child_at(i, j, k)->east = (*iter)->east->get_child_at(i-1, j, k);
115  // }
116  // if(j==1) {
117  // if((*iter)->north != NULL) (*iter)->get_child_at(i, j, k)->north = (*iter)->north->get_child_at(i, j-1, k);
118  // }
119  // if(k==1) {
120  // if((*iter)->top != NULL) (*iter)->get_child_at(i, j, k)->top = (*iter)->top->get_child_at(i, j, k-1);
121  // }
122  if(i==0) {
123  if((*iter)->neighbour[XDIR][LEFT] != NULL) (*iter)->get_child_at(i, j, k)->neighbour[XDIR][LEFT] = (*iter)->neighbour[XDIR][LEFT]->get_child_at(i+1, j, k);
124  }
125  if(j==0) {
126  if((*iter)->neighbour[YDIR][LEFT] != NULL) (*iter)->get_child_at(i, j, k)->neighbour[YDIR][LEFT] = (*iter)->neighbour[YDIR][LEFT]->get_child_at(i, j+1, k);
127  }
128  if(k==0) {
129  if((*iter)->neighbour[ZDIR][LEFT] != NULL) (*iter)->get_child_at(i, j, k)->neighbour[ZDIR][LEFT] = (*iter)->neighbour[ZDIR][LEFT]->get_child_at(i, j, k+1);
130  }
131  if(i==1) {
132  if((*iter)->neighbour[XDIR][RIGHT] != NULL) (*iter)->get_child_at(i, j, k)->neighbour[XDIR][RIGHT] = (*iter)->neighbour[XDIR][RIGHT]->get_child_at(i-1, j, k);
133  }
134  if(j==1) {
135  if((*iter)->neighbour[YDIR][RIGHT] != NULL) (*iter)->get_child_at(i, j, k)->neighbour[YDIR][RIGHT] = (*iter)->neighbour[YDIR][RIGHT]->get_child_at(i, j-1, k);
136  }
137  if(k==1) {
138  if((*iter)->neighbour[ZDIR][RIGHT] != NULL) (*iter)->get_child_at(i, j, k)->neighbour[ZDIR][RIGHT] = (*iter)->neighbour[ZDIR][RIGHT]->get_child_at(i, j, k-1);
139  }
140  }
141  }
142  }
143  }
144  }
145  }
146 }
147 
150 
152 
153  for (std::list<Octree*>::iterator i = root_nodes.begin(), end = root_nodes.end(); i != end; ++i) {
154 
155  double xmax = (*i)->x_max;
156  double ymax = (*i)->y_max;
157  double zmax = (*i)->z_max;
158  double xmin = (*i)->x_min;
159  double ymin = (*i)->y_min;
160  double zmin = (*i)->z_min;
161 
162  for (std::list<Octree*>::iterator j = root_nodes.begin(), end = root_nodes.end(); j != end; ++j) {
163  /*change it to xmax_nbr*/
164  double x_max = (*j)->x_max;
165  double y_max = (*j)->y_max;
166  double z_max = (*j)->z_max;
167  double x_min = (*j)->x_min;
168  double y_min = (*j)->y_min;
169  double z_min = (*j)->z_min;
170 
171  // if(xmax==x_min&&ymax==y_max&&zmax==z_max)
172  // (*i)->east = (*j);
173 
174  // if(xmin==x_max&&ymax==y_max&&zmax==z_max)
175  // (*i)->west = (*j);
176  //
177  // if(xmax==x_max&&ymax==y_min&&zmax==z_max)
178  // (*i)->north = (*j);
179  //
180  // if(xmax==x_max&&ymin==y_max&&zmax==z_max)
181  // (*i)->south = (*j);
182  //
183  // if(xmax==x_max&&ymax==y_max&&zmax==z_min)
184  // (*i)->top = (*j);
185  //
186  // if(xmax==x_max&&ymax==y_max&&zmin==z_max)
187  // (*i)->bottom = (*j);
188  if(xmax==x_min&&ymax==y_max&&zmax==z_max)
189  (*i)->neighbour[XDIR][RIGHT] = (*j);
190 
191  if(xmin==x_max&&ymax==y_max&&zmax==z_max)
192  (*i)->neighbour[XDIR][LEFT] = (*j);
193 
194  if(xmax==x_max&&ymax==y_min&&zmax==z_max)
195  (*i)->neighbour[YDIR][RIGHT] = (*j);
196 
197  if(xmax==x_max&&ymin==y_max&&zmax==z_max)
198  (*i)->neighbour[YDIR][LEFT] = (*j);
199 
200  if(xmax==x_max&&ymax==y_max&&zmax==z_min)
201  (*i)->neighbour[ZDIR][RIGHT] = (*j);
202 
203  if(xmax==x_max&&ymax==y_max&&zmin==z_max)
204  (*i)->neighbour[ZDIR][LEFT] = (*j);
205 
206 
207  }
208  }
209 }
210 
215 void print_neighbour_information(std::list<Octree*>& nodes) {
216 
217  for (std::list<Octree*>::iterator i = nodes.begin(), end = nodes.end(); i != end; ++i) {
218 
219  printf("I am at %g %g %g\n",(*i)->x_centre,(*i)->y_centre,(*i)->z_centre);
220  // if((*i)->east!=NULL) printf("East neighbour at %g %g %g\n",(*i)->east->x_centre,(*i)->east->y_centre,(*i)->east->z_centre);
221  // if((*i)->west!=NULL) printf("West neighbour at %g %g %g\n",(*i)->west->x_centre,(*i)->west->y_centre,(*i)->west->z_centre);
222  // if((*i)->north!=NULL) printf("North neighbour at %g %g %g\n",(*i)->north->x_centre,(*i)->north->y_centre,(*i)->north->z_centre);
223  // if((*i)->south!=NULL) printf("South neighbour at %g %g %g\n",(*i)->south->x_centre,(*i)->south->y_centre,(*i)->south->z_centre);
224  // if((*i)->top!=NULL) printf("Top neighbour at %g %g %g\n",(*i)->top->x_centre,(*i)->top->y_centre,(*i)->top->z_centre);
225  // if((*i)->bottom!=NULL) printf("Bottom neighbour at %g %g %g\n",(*i)->bottom->x_centre,(*i)->bottom->y_centre,(*i)->bottom->z_centre);
226  if((*i)->neighbour[XDIR][RIGHT]!=NULL) printf("East neighbour at %g %g %g\n",(*i)->neighbour[XDIR][RIGHT]->x_centre,(*i)->neighbour[XDIR][RIGHT]->y_centre,(*i)->neighbour[XDIR][RIGHT]->z_centre);
227  if((*i)->neighbour[XDIR][LEFT]!=NULL) printf("West neighbour at %g %g %g\n",(*i)->neighbour[XDIR][LEFT]->x_centre,(*i)->neighbour[XDIR][LEFT]->y_centre,(*i)->neighbour[XDIR][LEFT]->z_centre);
228  if((*i)->neighbour[YDIR][RIGHT]!=NULL) printf("North neighbour at %g %g %g\n",(*i)->neighbour[YDIR][RIGHT]->x_centre,(*i)->neighbour[YDIR][RIGHT]->y_centre,(*i)->neighbour[YDIR][RIGHT]->z_centre);
229  if((*i)->neighbour[YDIR][LEFT]!=NULL) printf("South neighbour at %g %g %g\n",(*i)->neighbour[YDIR][LEFT]->x_centre,(*i)->neighbour[YDIR][LEFT]->y_centre,(*i)->neighbour[YDIR][LEFT]->z_centre);
230  if((*i)->neighbour[ZDIR][RIGHT]!=NULL) printf("Top neighbour at %g %g %g\n",(*i)->neighbour[ZDIR][RIGHT]->x_centre,(*i)->neighbour[ZDIR][RIGHT]->y_centre,(*i)->neighbour[ZDIR][RIGHT]->z_centre);
231  if((*i)->neighbour[ZDIR][LEFT]!=NULL) printf("Bottom neighbour at %g %g %g\n",(*i)->neighbour[ZDIR][LEFT]->x_centre,(*i)->neighbour[ZDIR][LEFT]->y_centre,(*i)->neighbour[ZDIR][LEFT]->z_centre);
232 
233  }
234 
235 }
236 
239 
240  for(int l = 0; l<scalar_fields.size() ; l++) {
242  }
243 
244  for(int l = 0; l<vector_fields.size() ; l++) {
246  }
247 
248 }
249 
251 void OctreeGrid() {
252 
253  std::cerr << "\n" <<"Setting up grid" << std::endl;
254 
256 
257  //This is to be done after neighbours are set at that particular level
259 
260  //prints neighbours information
261  //print_neighbour_information(nodes);
262 
263 }
264 
265 }
std::vector< std::string > scalar_fields
Definition: block.cpp:8
std::list< Octree * > leaf_nodes
Definition: octreegrid.cpp:15
void create_list_of_root_nodes()
Definition: octreegrid.cpp:32
void set_root_neighbours()
Definition: octreegrid.cpp:149
int max_level
Definition: adapt.cpp:8
NodeBc bc[3][2]
Definition: octree.h:84
std::list< Octree * > level_nodes[20]
Definition: octreegrid.cpp:17
std::list< Octree * > root_nodes
Definition: octreegrid.cpp:16
void OctreeGrid()
Definition: octreegrid.cpp:251
std::vector< std::string > vector_fields
Definition: block.cpp:9
void exchange_ghost_val(int level, std::string name)
Definition: ghost.cpp:10
void reassign_neighbours()
Definition: octreegrid.cpp:90
void create_list_of_leaf_nodes()
Definition: octreegrid.cpp:21
void print_neighbour_information(std::list< Octree * > &nodes)
Definition: octreegrid.cpp:215
Class to store octree datastructure as nodes of the tree.
Definition: octree.h:26
AMR grid stuff.
Definition: adapt.cpp:6
std::list< Octree * > nodes
Definition: octreegrid.cpp:14
node_boundary_flags
Definition: boundary.h:7
void create_node(int blocknumber, double xmin, double xmax, double ymin, double ymax, double zmin, double zmax, int level, NodeBc **bc)
Definition: octreegrid.cpp:60
void create_lists_of_level_nodes()
Definition: octreegrid.cpp:43
void exchange_ghost_values_of_level(int level)
Definition: octreegrid.cpp:238