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
83
84
85
86
87
88
89
90
91
92
93
94
|
// -*- mode: c++ -*-
#include "mesh.hpp"
#include "agent.hpp"
int main(int argc, char* argv[])
{
Mesh mesh = Mesh();
H5::H5File fp_subsurface = H5::H5File(SUBSURFACE_MESH_FILE, H5F_ACC_RDONLY);
mesh.build_subsurface_mesh(fp_subsurface);
fp_subsurface.close();
H5::H5File fp_surface = H5::H5File(SURFACE_MESH_FILE, H5F_ACC_RDONLY);
mesh.build_surface_mesh(fp_surface);
fp_surface.close();
// FILE *mesh_fp = fopen("mesh.csv", "w");
// fprintf(mesh_fp, "x (m), y (m), z (m), index\n");
// Cell *c;
// for (int n = 0; n < mesh.get_n_cells(); n ++) {
// c = mesh.get_cell(n);
// fprintf(mesh_fp, "%f, %f, %f, %d\n", c->get_coordinate(0),
// c->get_coordinate(1), c->get_coordinate(2), n);
// }
// fclose(mesh_fp);
H5::H5File dp_subsurface = H5::H5File(SUBSURFACE_DATA_FILE, H5F_ACC_RDONLY);
mesh.build_environment(dp_subsurface, SUBSURFACE_FLAG);
dp_subsurface.close();
H5::H5File dp_surface = H5::H5File(SURFACE_DATA_FILE, H5F_ACC_RDONLY);
mesh.build_environment(dp_surface, SURFACE_FLAG);
dp_subsurface.close();
// Place agents in the domain and advance N_ITERATION steps
std::vector<Agent> agents(N_AGENT);
// Bootstrap
srand(SEED);
int len = mesh.get_n_cells(SUBSURFACE_FLAG);
int index;
std::cout << "[~>] Releasing " << N_AGENT << " agents" << std::endl;
for (size_t i = 0; i < N_AGENT; i ++) {
index = rand()%len;
agents[i].set_cell_index(index);
agents[i].set_path(mesh.get_cell(index, SUBSURFACE_FLAG)->get_coordinate(0),
mesh.get_cell(index, SUBSURFACE_FLAG)->get_coordinate(1),
mesh.get_cell(index, SUBSURFACE_FLAG)->get_coordinate(2), 0);
agents[i].set_domain(SUBSURFACE_FLAG, 0);
agents[i].set_domain(SUBSURFACE_FLAG, 1);
agents[i].set_path(mesh.get_cell(index, SUBSURFACE_FLAG)->get_coordinate(0),
mesh.get_cell(index, SUBSURFACE_FLAG)->get_coordinate(1),
mesh.get_cell(index, SUBSURFACE_FLAG)->get_coordinate(2), 1);
size_t step;
char output_fname[1024];
// move agent
for (step = 1; step < N_ITERATION; step ++) {
if (step % (N_ITERATION / 5) == 0 && i % (N_AGENT / 5) == 0) {
std::cout << "[~~~>] agent[" << i << "] step = " << step << " dt = " << agents[i].get_timestepsize() << " s" << std::endl;
}
agents[i].advance(&mesh, step);
}
// write out results
sprintf(output_fname, "results/agent-%06lu.csv", i);
FILE *result_fp = fopen(output_fname, "w");
fprintf(result_fp, "time (s), x (m), y (m), z (m)\n");
for (step = 0; step < N_ITERATION; step ++) {
fprintf(result_fp, "%f, %f, %f, %f\n",
agents[i].get_time(step),
agents[i].get_path(step, 0),
agents[i].get_path(step, 1),
agents[i].get_path(step, 2));
}
fclose(result_fp);
}
return EXIT_SUCCESS;
}
|