summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIlhan Özgen Xian <iozgen@lbl.gov>2021-04-14 16:48:14 -0700
committerIlhan Özgen Xian <iozgen@lbl.gov>2021-04-14 16:48:14 -0700
commit89c3e93111b112a2412cd3862a41583894717ebb (patch)
treec8479e5e2584db70356d9dde07b383efb51e9a57
parentf9b794965d97ff37c99b898e499068e5e7eb9493 (diff)
fix bug
-rw-r--r--agent.cpp80
-rw-r--r--main.cpp11
2 files changed, 39 insertions, 52 deletions
diff --git a/agent.cpp b/agent.cpp
index 5b1c37e..11fdcfe 100644
--- a/agent.cpp
+++ b/agent.cpp
@@ -35,8 +35,16 @@ int HydroAgent::advance(Mesh *mesh, size_t step)
if (domain[step-1] == SURFACE_FLAG) {
flag = advance_surface(mesh, step);
- } else if (domain[step] == SUBSURFACE_FLAG) {
+ } else if (domain[step-1] == SUBSURFACE_FLAG) {
flag = advance_subsurface(mesh, step);
+ } else if (domain[step-1] == OUTOFBOUNDS_FLAG) {
+ flag = 1;
+ x[step] = x[step-1];
+ y[step] = y[step-1];
+ set_domain(OUTOFBOUNDS_FLAG, step);
+ #if VERBOSE
+ printf("[ok] agent is out of bounds. do not advect.\n");
+ #endif
}
return flag;
@@ -47,61 +55,51 @@ int HydroAgent::advance_surface(Mesh *mesh, size_t step)
double vx = location->get_v(0);
double vy = location->get_v(1);
-
- if (get_domain(step-1) == OUTOFBOUNDS_FLAG) {
-
- x[step] = x[step-1];
- y[step] = y[step-1];
- set_domain(OUTOFBOUNDS_FLAG, step);
-
- } else {
- double x_agent = x[step-1] + DT_SURFACE * vx;
- double y_agent = y[step-1] + DT_SURFACE * vy;
+ double x_agent = x[step-1] + DT_SURFACE * vx;
+ double y_agent = y[step-1] + DT_SURFACE * vy;
- x[step] = x_agent;
- y[step] = y_agent;
+ x[step] = x_agent;
+ y[step] = y_agent;
- double x_centroid = location->get_x();
- double y_centroid = location->get_y();
+ double x_centroid = location->get_x();
+ double y_centroid = location->get_y();
- double dx = x_centroid - x_agent;
- double dy = y_centroid - y_agent;
+ double dx = x_centroid - x_agent;
+ double dy = y_centroid - y_agent;
- double distance = sqrt(dx * dx + dy * dy);
+ double distance = sqrt(dx * dx + dy * dy);
- int cell_index = -1;
+ int cell_index = -1;
- for (int n = 0; n < N_EDGES; n ++) {
+ for (int n = 0; n < N_EDGES; n ++) {
- hsize_t neighbor_index = location->get_neighbor(n);
+ hsize_t neighbor_index = location->get_neighbor(n);
- double x_neighbor = mesh->get_cells()[neighbor_index].get_x();
- double y_neighbor = mesh->get_cells()[neighbor_index].get_y();
-
- dx = x_neighbor - x_agent;
- dy = y_neighbor - y_agent;
+ double x_neighbor = mesh->get_cells()[neighbor_index].get_x();
+ double y_neighbor = mesh->get_cells()[neighbor_index].get_y();
- double _distance = sqrt(dx * dx + dy * dy);
+ dx = x_neighbor - x_agent;
+ dy = y_neighbor - y_agent;
- if (distance > _distance) {
- cell_index = n;
- distance = _distance;
- }
-
- }
+ double _distance = sqrt(dx * dx + dy * dy);
- if (cell_index >= 0) {
- location = &(mesh->get_cells()[location->get_neighbor(cell_index)]);
+ if (distance > _distance) {
+ cell_index = n;
+ distance = _distance;
}
+
+ }
- if ((x_agent > mesh->get_xmax()) || (x_agent < mesh->get_xmin()) ||
- (y_agent > mesh->get_ymax()) || (y_agent < mesh->get_ymin())) {
- set_domain(OUTOFBOUNDS_FLAG, step);
- } else {
- set_domain(SURFACE_FLAG, step);
- }
+ if (cell_index >= 0) {
+ location = &(mesh->get_cells()[location->get_neighbor(cell_index)]);
+ }
+ if ((x_agent > mesh->get_xmax()) || (x_agent < mesh->get_xmin()) ||
+ (y_agent > mesh->get_ymax()) || (y_agent < mesh->get_ymin())) {
+ domain[step] = OUTOFBOUNDS_FLAG;
+ } else {
+ domain[step] = SURFACE_FLAG;
}
return 1;
diff --git a/main.cpp b/main.cpp
index b2fdfc1..7628088 100644
--- a/main.cpp
+++ b/main.cpp
@@ -10,18 +10,8 @@ int main(void)
printf(" o--o =================\n");
printf("\n\n");
-
printf("[OK] # of agents: %d, # of iterations: %d\n[OK] size of surface time step: %f s\n[OK] size of subsurface time step: %f s\n\n", N_AGENT, N_ITERATION, DT_SURFACE, DT_SUBSURFACE);
- #if TESTING
- // small test to see if cell is initialized correctly
- double coords[3] = { 20.0, 1.0, 2.0 };
- Cell test = Cell(coords);
- printf("[OK] test cell coordinates:\n");
- printf("[OK] x: %f, y: %f, z: %f\n\n", test.get_x(), test.get_y(), test.get_z());
- // end of test
- #endif
-
H5::H5File fp = H5::H5File(MESH_FILE_NAME, H5F_ACC_RDONLY);
Mesh mesh = Mesh();
@@ -77,7 +67,6 @@ int main(void)
#endif
agents[i].advance(&mesh, step);
- agents[i].set_domain(SURFACE_FLAG, step);
}