-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
90 lines (68 loc) · 3.09 KB
/
main.cpp
File metadata and controls
90 lines (68 loc) · 3.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// C++ standard libraries
#include <iostream>
#include <random>
#include <iomanip>
// Local AMR included files
#include "include/AMR_Tree.h"
#include "include/Static_Mesh_Tree.h"
#include "include/Adaptive_Mesh_Tree.h"
#include "include/Point.h"
int main() {
/// Set up Adaptive/Static Mesh Tree parameters:
// Define the number of dimensions.
int dimensions = 3;
// Define upper bounds, lower bounds defaulted at 0.
double upper_bounds [3] = {10, 10, 10};
// Define depth of levels for Static tree (will produce (2^(dimensions))^(depth+1) - 1 Nodes).
int depth = 8;
/// Set up objects to add into the Tree, in this case a simple Point particle class (Point.cpp/Point.h):
// Number of test points to add to the system.
int number_points = 500;
// Initialize an a vector of Points.
vector <Point *> points;
points.reserve(number_points);
/// Create random coordinates within the region (0,0,0) to upper_bounds for each Point object.
// Initialize uniform_real_distribution object for creating random coordinates for each Point.
std::uniform_real_distribution<double> unif(0, upper_bounds[0]);
std::default_random_engine rand_eng;
// Create random coordinates for each Point in each dimension.
for (int dim = 0; dim < number_points; dim++){
// Initialize mass.
int mass = dim;
// Random coordinates.
double rand_coords[dimensions];
for (int i = 0; i < dimensions; i++){
rand_coords[i] = unif(rand_eng);
}
// Create new Point object and add it to vector.
points.push_back(new Point(mass, dimensions, rand_coords));
}
std::cout << number_points << " Points created." << std::endl;
/// Initialize Static and Adaptive Mesh Trees for this example:
// Initialize a Static Mesh Tree and an Adaptive Mesh Tree.
Static_Mesh_Tree<Point> staticTree(depth, dimensions, upper_bounds);
Adaptive_Mesh_Tree<Point> adaptTree(dimensions, upper_bounds);
/// Use Static Mesh Tree:
std::cout << "*** TESTING STATIC MESH TREE ***" << std::endl;
// Insert points into Static Tree.
staticTree.insert(points);
std::cout << number_points << " Points inserted into AMR Tree." << std::endl;
// Update tree - tree should be restructured after every coordinate update.
staticTree.updateTree();
std::cout << "Tree has been restructured" << std::endl;
// Print out leftmost depth.
std::cout << "Left-most depth = " << staticTree.get_depth() << std::endl;
std::cout << std::endl;
/// Use Adaptive Mesh Tree:
std::cout << "*** TESTING ADAPTIVE MESH TREE ***" << std::endl;
// Insert points into Adaptive Tree.
adaptTree.insert(points);
std::cout << number_points << " Points inserted into AMR Tree." << std::endl;
// Update tree - tree should be restructured after every coordinate update.
adaptTree.updateTree();
std::cout << "Tree has been restructured" << std::endl;
// Print out leftmost depth.
std::cout << "Left-most depth = " << adaptTree.get_depth() << std::endl;
std::cout << std::endl;
return 0;
}