summaryrefslogtreecommitdiff
path: root/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'main.cpp')
-rw-r--r--main.cpp112
1 files changed, 86 insertions, 26 deletions
diff --git a/main.cpp b/main.cpp
index 1e45aac..cfa59ca 100644
--- a/main.cpp
+++ b/main.cpp
@@ -2,6 +2,7 @@
#include "mesh.hpp"
#include "agent.hpp"
+#include "parser.hpp"
int main(int argc, char* argv[])
{
@@ -13,25 +14,74 @@ int main(int argc, char* argv[])
MPI_Comm_size(MPI_COMM_WORLD, &size);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
- Mesh mesh = Mesh();
-
- H5::H5File fp_subsurface = H5::H5File(SUBSURFACE_MESH_FILE, H5F_ACC_RDONLY);
- H5::H5File dp_subsurface = H5::H5File(SUBSURFACE_DATA_FILE, H5F_ACC_RDONLY);
- H5::H5File fp_surface = H5::H5File(SURFACE_MESH_FILE, H5F_ACC_RDONLY);
- H5::H5File dp_surface = H5::H5File(SURFACE_DATA_FILE, H5F_ACC_RDONLY);
+ if (rank == 0) {
+
+ std::cout << std::endl;
+ std::cout << " / /^ agent provocateur" << std::endl;
+ std::cout << " o--o =================" << std::endl;
+ std::cout << std::endl;
+
+ std::cout << "[~>] Read in input data" << std::endl;
+
+ }
- if (rank == 0)
+ Parser parser;
+ parser.read_options("input/options.input");
+
+ if (rank == 0) {
+
+ std::cout << "[~~>] Number of agents: " << parser.n_agent << std::endl;
+ std::cout << "[~~>] Number of iterations: " << parser.n_iteration << std::endl;
+ std::cout << "[~~>] Random seed: " << parser.seed << std::endl;
+ std::cout << "[~~>] Geometric fuzz: " << parser.fuzz << std::endl;
+
+ std::cout << "[~~>] Surface mesh file: " << parser.surface_mesh_file << std::endl;
+ std::cout << "[~~>] Surface data file: " << parser.surface_data_file << std::endl;
+ std::cout << "[~~>] Surface time: ";
+ for (uint i = 0; i < parser.surface_time.size(); i ++)
+ std::cout << parser.surface_time[i] << " ";
+ std::cout <<std::endl;
+ std::cout << "[~~>] Surface group: ";
+ for (uint i = 0; i < parser.surface_data_group.size(); i ++)
+ std::cout << parser.surface_data_group[i] << " ";
+ std::cout <<std::endl;
+
+ std::cout << "[~~>] Subsurface mesh file: " << parser.subsurface_mesh_file << std::endl;
+ std::cout << "[~~>] Subsurface data file: " << parser.subsurface_data_file << std::endl;
+ std::cout << "[~~>] Subsurface time: ";
+ for (uint i = 0; i < parser.subsurface_time.size(); i ++)
+ std::cout << parser.subsurface_time[i] << " ";
+ std::cout <<std::endl;
+ std::cout << "[~~>] Subsurface group: ";
+ for (uint i = 0; i < parser.subsurface_data_group.size(); i ++)
+ std::cout << parser.subsurface_data_group[i] << " ";
+ std::cout << std::endl;
+ std::cout << std::endl;
+
std::cout << "[~>] Building the subsurface mesh" << std::endl;
+
+ }
+ Mesh mesh = Mesh();
+
+ mesh.set_fuzz(parser.fuzz);
+
+ H5::H5File fp_subsurface = H5::H5File(parser.subsurface_mesh_file.c_str(), H5F_ACC_RDONLY);
+ H5::H5File dp_subsurface = H5::H5File(parser.subsurface_data_file.c_str(), H5F_ACC_RDONLY);
+ H5::H5File fp_surface = H5::H5File(parser.surface_mesh_file.c_str(), H5F_ACC_RDONLY);
+ H5::H5File dp_surface = H5::H5File(parser.surface_data_file.c_str(), H5F_ACC_RDONLY);
+
mesh.build_subsurface_mesh(fp_subsurface);
fp_subsurface.close();
if (rank == 0) {
std::cout << "[~~>] Number of cells: " << mesh.get_n_cells(SUBSURFACE_FLAG) << std::endl;
+ std::cout << std::endl;
+
std::cout << "[~>] Building the surface mesh (includes coupling with subsurface and may take a while)" << std::endl;
}
- mesh.build_surface_mesh(fp_surface, dp_surface);
+ mesh.build_surface_mesh(fp_surface, dp_surface, parser.surface_data_group[0]);
fp_surface.close();
if (rank == 0) {
@@ -39,18 +89,18 @@ int main(int argc, char* argv[])
int len_surf = mesh.get_n_cells(SURFACE_FLAG);
std::cout << "[~~>] Number of cells: " << len_surf << std::endl;
+ std::cout << std::endl;
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 < len_surf; n ++) {
- c = mesh.get_cell(n, SURFACE_FLAG);
- fprintf(mesh_fp, "%f, %f, %f, %d\n",
- c->get_coordinate(0),
- c->get_coordinate(1),
- c->get_coordinate(2), n);
+ c = mesh.get_cell(n, SURFACE_FLAG);
+ fprintf(mesh_fp, "%f, %f, %f, %d\n",
+ c->get_coordinate(0),
+ c->get_coordinate(1),
+ c->get_coordinate(2), n);
}
fclose(mesh_fp);
@@ -59,30 +109,36 @@ int main(int argc, char* argv[])
}
- mesh.build_environment(dp_subsurface, SUBSURFACE_FLAG);
+ mesh.build_environment(dp_subsurface, parser.subsurface_data_group[0], SUBSURFACE_FLAG);
dp_subsurface.close();
- mesh.build_environment(dp_surface, SURFACE_FLAG);
- dp_subsurface.close();
+ if (rank == 0) {
+ std::cout << "[~>] Reading the surface environment" << std::endl;
+ std::cout << std::endl;
+ }
+
+ mesh.build_environment(dp_surface, parser.surface_data_group[0], SURFACE_FLAG);
+ dp_surface.close();
// Place agents in the domain and advance N_ITERATION steps
// Bootstrap
- srand(SEED + rank);
+ srand(parser.seed + rank);
int len = mesh.get_n_cells(SUBSURFACE_FLAG);
int index;
- std::cout << "[~>] Releasing " << N_AGENT << " agents" << std::endl;
+ std::cout << "[~>] Releasing " << parser.n_agent << " agents" << std::endl;
- size_t partition = N_AGENT / size;
+ size_t partition = parser.n_agent / size;
size_t low_bound = rank * partition;
size_t high_bound = (rank + 1) * partition;
if (rank == size - 1) // top processor picks up extras
- high_bound = N_AGENT;
+ high_bound = parser.n_agent;
for (size_t i = low_bound; i < high_bound; i ++) {
Agent agent;
+ agent.init(parser.n_iteration);
index = rand()%len;
agent.set_cell_index(index);
@@ -97,16 +153,20 @@ int main(int argc, char* argv[])
mesh.get_cell(index, SUBSURFACE_FLAG)->get_coordinate(1),
mesh.get_cell(index, SUBSURFACE_FLAG)->get_coordinate(2), 1);
- size_t step;
+ int 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 = " << agent.get_timestepsize() << " s" << std::endl;
+ for (step = 1; step < parser.n_iteration; step ++) {
+ if (step % (parser.n_iteration / 5) == 0 && i % (parser.n_agent / 5) == 0) {
+ std::cout << "[~~>] agent[" << i << "] step = " << step << " dt = " << agent.get_timestepsize() << " s" << std::endl;
}
+
agent.advance(&mesh, step);
+
+ // update environment if necessary
+
}
// write out results
@@ -114,7 +174,7 @@ int main(int argc, char* argv[])
FILE *result_fp = fopen(output_fname, "w");
fprintf(result_fp, "time (s), x (m), y (m), z (m), domain\n");
- for (step = 0; step < N_ITERATION; step ++) {
+ for (step = 0; step < parser.n_iteration; step ++) {
fprintf(result_fp, "%f, %f, %f, %f, %d\n",
agent.get_time(step),
agent.get_path(step, 0),