From 5e42eaa935595e845c73a6b25a69147a3b86756e Mon Sep 17 00:00:00 2001 From: JonathanGorard Date: Thu, 13 Jun 2024 17:08:22 -0400 Subject: [PATCH 01/32] Began prototyping singly- and doubly-nested AMR infrastructure, now hooked up and working with the 2D Euler equations. Added both singly- and doubly-nested versions of the 2D axisymmetric Sod-type shock test, the 2D Euler Riemann problem, and the 2D Euler shock bubble test. --- amr/amr_block.c | 207 ++++- amr/amr_core_euler.c | 738 +++++++++++++++++- amr/gkyl_amr_block_priv.h | 23 +- amr/gkyl_amr_core.h | 45 ++ ....c => rt_amr_euler_cart_axi_sodshock_l1.c} | 0 .../rt_amr_euler_cart_axi_sodshock_l2.c | 197 +++++ ...er_riem_2d.c => rt_amr_euler_riem_2d_l1.c} | 0 regression/rt_amr_euler_riem_2d_l2.c | 253 ++++++ ...ubble.c => rt_amr_euler_shock_bubble_l1.c} | 0 regression/rt_amr_euler_shock_bubble_l2.c | 213 +++++ 10 files changed, 1673 insertions(+), 3 deletions(-) rename regression/{rt_amr_euler_cart_axi_sodshock.c => rt_amr_euler_cart_axi_sodshock_l1.c} (100%) create mode 100644 regression/rt_amr_euler_cart_axi_sodshock_l2.c rename regression/{rt_amr_euler_riem_2d.c => rt_amr_euler_riem_2d_l1.c} (100%) create mode 100644 regression/rt_amr_euler_riem_2d_l2.c rename regression/{rt_amr_euler_shock_bubble.c => rt_amr_euler_shock_bubble_l1.c} (100%) create mode 100644 regression/rt_amr_euler_shock_bubble_l2.c diff --git a/amr/amr_block.c b/amr/amr_block.c index 9cb2eef5e..fde03156f 100644 --- a/amr/amr_block.c +++ b/amr/amr_block.c @@ -63,6 +63,42 @@ euler_block_bc_updaters_init(struct euler_block_data* bdata, const struct gkyl_b bdata->bc_buffer = gkyl_array_new(GKYL_DOUBLE, 5, buff_sz); } +void +euler_nested_block_bc_updaters_init(struct euler_block_data* bdata, const struct gkyl_block_connections* conn) +{ + int nghost[25]; + for (int i = 0; i < 25; i++) { + nghost[i] = 2; + } + + for (int d = 0; d < 2; d++) { + bdata->lower_bc[d] = bdata->upper_bc[d] = 0; + + if (conn->connections[d][0].edge == GKYL_PHYSICAL) { + bdata->lower_bc[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler, bdata->geom, d, GKYL_LOWER_EDGE, nghost, + euler_transmissive_bc, 0); + } + + if (conn->connections[d][1].edge == GKYL_PHYSICAL) { + bdata->upper_bc[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler, bdata->geom, d, GKYL_UPPER_EDGE, nghost, + euler_transmissive_bc, 0); + } + } + + skin_ghost_ranges_init_block(&bdata->skin_ghost, &bdata->ext_range, nghost); + long buff_sz = 0; + + for (int d = 0; d < 2; d++) { + long vol = bdata->skin_ghost.lower_skin[d].volume; + + if (buff_sz <= vol) { + buff_sz = vol; + } + } + + bdata->bc_buffer = gkyl_array_new(GKYL_DOUBLE, 5, buff_sz); +} + void gr_euler_block_bc_updaters_init(struct euler_block_data* bdata, const struct gkyl_block_connections* conn) { @@ -99,6 +135,42 @@ gr_euler_block_bc_updaters_init(struct euler_block_data* bdata, const struct gky bdata->bc_buffer = gkyl_array_new(GKYL_DOUBLE, 29, buff_sz); } +void +gr_euler_nested_block_bc_updaters_init(struct euler_block_data* bdata, const struct gkyl_block_connections* conn) +{ + int nghost[25]; + for (int i = 0; i < 25; i++) { + nghost[i] = 2; + } + + for (int d = 0; d < 2; d++) { + bdata->lower_bc[d] = bdata->upper_bc[d] = 0; + + if (conn->connections[d][0].edge == GKYL_PHYSICAL) { + bdata->lower_bc[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler, bdata->geom, d, GKYL_LOWER_EDGE, nghost, + gr_euler_transmissive_bc, 0); + } + + if (conn->connections[d][1].edge == GKYL_PHYSICAL) { + bdata->upper_bc[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler, bdata->geom, d, GKYL_UPPER_EDGE, nghost, + gr_euler_transmissive_bc, 0); + } + } + + skin_ghost_ranges_init_block(&bdata->skin_ghost, &bdata->ext_range, nghost); + long buff_sz = 0; + + for (int d = 0; d < 2; d++) { + long vol = bdata->skin_ghost.lower_skin[d].volume; + + if (buff_sz <= vol) { + buff_sz = vol; + } + } + + bdata->bc_buffer = gkyl_array_new(GKYL_DOUBLE, 29, buff_sz); +} + void euler_block_bc_updaters_release(struct euler_block_data* bdata) { @@ -659,7 +731,7 @@ create_block_topo() btopo->conn[6] = (struct gkyl_block_connections) { .connections[0] = { { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL }, { .bid = 7, .dir = 0, .edge = GKYL_LOWER_POSITIVE } }, - .connections[1] = { { .bid = 6, .dir = 1, .edge = GKYL_PHYSICAL }, { .bid = 4, .dir = 1, .edge = GKYL_LOWER_POSITIVE } }, + .connections[1] = { { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL }, { .bid = 4, .dir = 1, .edge = GKYL_LOWER_POSITIVE } }, }; btopo->conn[7] = (struct gkyl_block_connections) { @@ -672,5 +744,138 @@ create_block_topo() .connections[1] = { { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL }, { .bid = 5, .dir = 1, .edge = GKYL_LOWER_POSITIVE } }, }; + return btopo; +} + +struct gkyl_block_topo* +create_nested_block_topo() +{ + struct gkyl_block_topo *btopo = gkyl_block_topo_new(2, 25); + + btopo->conn[0] = (struct gkyl_block_connections) { + .connections[0] = { { .bid = 4, .dir = 0, .edge = GKYL_UPPER_POSITIVE }, { .bid = 5, .dir = 0, .edge = GKYL_LOWER_POSITIVE } }, + .connections[1] = { { .bid = 7, .dir = 1, .edge = GKYL_UPPER_POSITIVE }, { .bid = 2, .dir = 1, .edge = GKYL_LOWER_POSITIVE } }, + }; + + btopo->conn[1] = (struct gkyl_block_connections) { + .connections[0] = { { .bid = 14, .dir = 0, .edge = GKYL_UPPER_POSITIVE }, { .bid = 2, .dir = 0, .edge = GKYL_LOWER_POSITIVE } }, + .connections[1] = { { .bid = 4, .dir = 1, .edge = GKYL_UPPER_POSITIVE }, { .bid = 10, .dir = 1, .edge = GKYL_LOWER_POSITIVE } }, + }; + + btopo->conn[2] = (struct gkyl_block_connections) { + .connections[0] = { { .bid = 1, .dir = 0, .edge = GKYL_UPPER_POSITIVE }, { .bid = 3, .dir = 0, .edge = GKYL_LOWER_POSITIVE } }, + .connections[1] = { { .bid = 0, .dir = 1, .edge = GKYL_UPPER_POSITIVE }, { .bid = 11, .dir = 1, .edge = GKYL_LOWER_POSITIVE } }, + }; + + btopo->conn[3] = (struct gkyl_block_connections) { + .connections[0] = { { .bid = 2, .dir = 0, .edge = GKYL_UPPER_POSITIVE }, { .bid = 15, .dir = 0, .edge = GKYL_LOWER_POSITIVE } }, + .connections[1] = { { .bid = 5, .dir = 1, .edge = GKYL_UPPER_POSITIVE }, { .bid = 12, .dir = 1, .edge = GKYL_LOWER_POSITIVE } }, + }; + + btopo->conn[4] = (struct gkyl_block_connections) { + .connections[0] = { { .bid = 16, .dir = 0, .edge = GKYL_UPPER_POSITIVE }, { .bid = 0, .dir = 0, .edge = GKYL_LOWER_POSITIVE } }, + .connections[1] = { { .bid = 6, .dir = 1, .edge = GKYL_UPPER_POSITIVE }, { .bid = 1, .dir = 1, .edge = GKYL_LOWER_POSITIVE } }, + }; + + btopo->conn[5] = (struct gkyl_block_connections) { + .connections[0] = { { .bid = 0, .dir = 0, .edge = GKYL_UPPER_POSITIVE }, { .bid = 17, .dir = 0, .edge = GKYL_LOWER_POSITIVE } }, + .connections[1] = { { .bid = 8, .dir = 1, .edge = GKYL_UPPER_POSITIVE }, { .bid = 3, .dir = 1, .edge = GKYL_LOWER_POSITIVE } }, + }; + + btopo->conn[6] = (struct gkyl_block_connections) { + .connections[0] = { { .bid = 18, .dir = 0, .edge = GKYL_UPPER_POSITIVE }, { .bid = 7, .dir = 0, .edge = GKYL_LOWER_POSITIVE } }, + .connections[1] = { { .bid = 21, .dir = 1, .edge = GKYL_UPPER_POSITIVE }, { .bid = 4, .dir = 1, .edge = GKYL_LOWER_POSITIVE } }, + }; + + btopo->conn[7] = (struct gkyl_block_connections) { + .connections[0] = { { .bid = 6, .dir = 0, .edge = GKYL_UPPER_POSITIVE }, { .bid = 8, .dir = 0, .edge = GKYL_LOWER_POSITIVE } }, + .connections[1] = { { .bid = 22, .dir = 1, .edge = GKYL_UPPER_POSITIVE }, { .bid = 0, .dir = 1, .edge = GKYL_LOWER_POSITIVE } }, + }; + + btopo->conn[8] = (struct gkyl_block_connections) { + .connections[0] = { { .bid = 7, .dir = 0, .edge = GKYL_UPPER_POSITIVE }, { .bid = 19, .dir = 0, .edge = GKYL_LOWER_POSITIVE } }, + .connections[1] = { { .bid = 23, .dir = 1, .edge = GKYL_UPPER_POSITIVE }, { .bid = 5, .dir = 1, .edge = GKYL_LOWER_POSITIVE } }, + }; + + btopo->conn[9] = (struct gkyl_block_connections) { + .connections[0] = { { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL }, { .bid = 10, .dir = 0, .edge = GKYL_LOWER_POSITIVE } }, + .connections[1] = { { .bid = 14, .dir = 1, .edge = GKYL_UPPER_POSITIVE }, { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL } }, + }; + + btopo->conn[10] = (struct gkyl_block_connections) { + .connections[0] = { { .bid = 9, .dir = 0, .edge = GKYL_UPPER_POSITIVE }, { .bid = 11, .dir = 0, .edge = GKYL_LOWER_POSITIVE } }, + .connections[1] = { { .bid = 1, .dir = 1, .edge = GKYL_UPPER_POSITIVE }, { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL } }, + }; + + btopo->conn[11] = (struct gkyl_block_connections) { + .connections[0] = { { .bid = 10, .dir = 0, .edge = GKYL_UPPER_POSITIVE }, { .bid = 12, .dir = 0, .edge = GKYL_LOWER_POSITIVE } }, + .connections[1] = { { .bid = 2, .dir = 1, .edge = GKYL_UPPER_POSITIVE }, { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL } }, + }; + + btopo->conn[12] = (struct gkyl_block_connections) { + .connections[0] = { { .bid = 11, .dir = 0, .edge = GKYL_UPPER_POSITIVE }, { .bid = 13, .dir = 0, .edge = GKYL_LOWER_POSITIVE } }, + .connections[1] = { { .bid = 3, .dir = 1, .edge = GKYL_UPPER_POSITIVE }, { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL } }, + }; + + btopo->conn[13] = (struct gkyl_block_connections) { + .connections[0] = { { .bid = 12, .dir = 0, .edge = GKYL_UPPER_POSITIVE }, { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL } }, + .connections[1] = { { .bid = 15, .dir = 1, .edge = GKYL_UPPER_POSITIVE }, { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL } }, + }; + + btopo->conn[14] = (struct gkyl_block_connections) { + .connections[0] = { { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL }, { .bid = 1, .dir = 0, .edge = GKYL_LOWER_POSITIVE } }, + .connections[1] = { { .bid = 16, .dir = 1, .edge = GKYL_UPPER_POSITIVE }, { .bid = 9, .dir = 1, .edge = GKYL_LOWER_POSITIVE } }, + }; + + btopo->conn[15] = (struct gkyl_block_connections) { + .connections[0] = { { .bid = 3, .dir = 0, .edge = GKYL_UPPER_POSITIVE }, { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL } }, + .connections[1] = { { .bid = 17, .dir = 1, .edge = GKYL_UPPER_POSITIVE }, { .bid = 13, .dir = 1, .edge = GKYL_LOWER_POSITIVE } }, + }; + + btopo->conn[16] = (struct gkyl_block_connections) { + .connections[0] = { { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL }, { .bid = 4, .dir = 0, .edge = GKYL_LOWER_POSITIVE } }, + .connections[1] = { { .bid = 18, .dir = 1, .edge = GKYL_UPPER_POSITIVE }, { .bid = 14, .dir = 1, .edge = GKYL_LOWER_POSITIVE } }, + }; + + btopo->conn[17] = (struct gkyl_block_connections) { + .connections[0] = { { .bid = 5, .dir = 0, .edge = GKYL_UPPER_POSITIVE }, { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL } }, + .connections[1] = { { .bid = 19, .dir = 1, .edge = GKYL_UPPER_POSITIVE }, { .bid = 15, .dir = 1, .edge = GKYL_LOWER_POSITIVE } }, + }; + + btopo->conn[18] = (struct gkyl_block_connections) { + .connections[0] = { { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL }, { .bid = 6, .dir = 0, .edge = GKYL_LOWER_POSITIVE } }, + .connections[1] = { { .bid = 20, .dir = 1, .edge = GKYL_UPPER_POSITIVE }, { .bid = 16, .dir = 1, .edge = GKYL_LOWER_POSITIVE } }, + }; + + btopo->conn[19] = (struct gkyl_block_connections) { + .connections[0] = { { .bid = 8, .dir = 0, .edge = GKYL_UPPER_POSITIVE }, { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL } }, + .connections[1] = { { .bid = 24, .dir = 1, .edge = GKYL_UPPER_POSITIVE }, { .bid = 17, .dir = 1, .edge = GKYL_LOWER_POSITIVE } }, + }; + + btopo->conn[20] = (struct gkyl_block_connections) { + .connections[0] = { { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL }, { .bid = 21, .dir = 0, .edge = GKYL_LOWER_POSITIVE } }, + .connections[1] = { { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL }, { .bid = 18, .dir = 1, .edge = GKYL_LOWER_POSITIVE } }, + }; + + btopo->conn[21] = (struct gkyl_block_connections) { + .connections[0] = { { .bid = 20, .dir = 0, .edge = GKYL_UPPER_POSITIVE }, { .bid = 22, .dir = 0, .edge = GKYL_LOWER_POSITIVE } }, + .connections[1] = { { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL }, { .bid = 6, .dir = 1, .edge = GKYL_LOWER_POSITIVE } }, + }; + + btopo->conn[22] = (struct gkyl_block_connections) { + .connections[0] = { { .bid = 21, .dir = 0, .edge = GKYL_UPPER_POSITIVE }, { .bid = 23, .dir = 0, .edge = GKYL_LOWER_POSITIVE } }, + .connections[1] = { { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL }, { .bid = 7, .dir = 1, .edge = GKYL_LOWER_POSITIVE } }, + }; + + btopo->conn[23] = (struct gkyl_block_connections) { + .connections[0] = { { .bid = 22, .dir = 0, .edge = GKYL_UPPER_POSITIVE }, { .bid = 24, .dir = 0, .edge = GKYL_LOWER_POSITIVE } }, + .connections[1] = { { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL }, { .bid = 8, .dir = 1, .edge = GKYL_LOWER_POSITIVE } }, + }; + + btopo->conn[24] = (struct gkyl_block_connections) { + .connections[0] = { { .bid = 23, .dir = 0, .edge = GKYL_UPPER_POSITIVE }, { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL } }, + .connections[1] = { { .bid = 0, .dir = 1, .edge = GKYL_PHYSICAL }, { .bid = 19, .dir = 1, .edge = GKYL_LOWER_POSITIVE } }, + }; + return btopo; } \ No newline at end of file diff --git a/amr/amr_core_euler.c b/amr/amr_core_euler.c index 13d6b9a98..844754d1c 100644 --- a/amr/amr_core_euler.c +++ b/amr/amr_core_euler.c @@ -333,7 +333,7 @@ euler1d_run_single(int argc, char **argv, struct euler1d_single_init* init) else { num_failures = 0; } - + coarse_step += 1; } @@ -878,4 +878,740 @@ euler2d_run_single(int argc, char **argv, struct euler2d_single_init* init) #ifdef AMR_DEBUG gkyl_job_pool_release(fine_job_pool); #endif +} + +void +euler2d_run_double(int argc, char **argv, struct euler2d_double_init* init) +{ + struct gkyl_app_args app_args = parse_app_args(argc, argv); + + if (app_args.trace_mem) { + gkyl_cu_dev_mem_debug_set(true); + gkyl_mem_debug_set(true); + } + + int base_Nx = init->base_Nx; + int base_Ny = init->base_Ny; + int ref_factor1 = init->ref_factor1; + int ref_factor2 = init->ref_factor2; + + double coarse_x1 = init->coarse_x1; + double coarse_y1 = init->coarse_y1; + double coarse_x2 = init->coarse_x2; + double coarse_y2 = init->coarse_y2; + + double intermediate_x1 = init->intermediate_x1; + double intermediate_y1 = init->intermediate_y1; + double intermediate_x2 = init->intermediate_x2; + double intermediate_y2 = init->intermediate_y2; + + double refined_x1 = init->refined_x1; + double refined_y1 = init->refined_y1; + double refined_x2 = init->refined_x2; + double refined_y2 = init->refined_y2; + + evalf_t eval = init->eval; + double gas_gamma = init->gas_gamma; + + char euler_output[32]; + strcpy(euler_output, init->euler_output); + + bool low_order_flux = init->low_order_flux; + int num_frames = init->num_frames; + + double cfl_frac = init->cfl_frac; + double t_end = init->t_end; + double dt_failure_tol = init->dt_failure_tol; + int num_failures_max = init->num_failures_max; + + int ndim = 2; + int num_blocks = 25; + int Nx = base_Nx; + int Ny = base_Ny; + + struct euler_block_data coarse_bdata[num_blocks]; + struct gkyl_job_pool *coarse_job_pool = gkyl_thread_pool_new(app_args.num_threads); + +#ifdef AMR_DEBUG + gkyl_rect_grid_init(&coarse_bdata[0].grid, 2, (double []) { refined_x1, refined_y1 }, (double []) { refined_x2, refined_y2 }, + (int []) { Nx, Ny }); + + gkyl_rect_grid_init(&coarse_bdata[1].grid, 2, (double []) { intermediate_x1, refined_y2 }, (double []) { refined_x1, intermediate_y2 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[2].grid, 2, (double []) { refined_x1, refined_y2 }, (double []) { refined_x2, intermediate_y2 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[3].grid, 2, (double []) { refined_x2, refined_y2 }, (double []) { intermediate_x2, intermediate_y2 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[4].grid, 2, (double []) { intermediate_x1, refined_y1 }, (double []) { refined_x1, refined_y2 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[5].grid, 2, (double []) { refined_x2, refined_y1 }, (double []) { intermediate_x2, refined_y2 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[6].grid, 2, (double []) { intermediate_x1, intermediate_y1 }, (double []) { refined_x1, refined_y1 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[7].grid, 2, (double []) { refined_x1, intermediate_y1 }, (double []) { refined_x2, refined_y1 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[8].grid, 2, (double []) { refined_x2, intermediate_y1 }, (double []) { intermediate_x2, refined_y1 }, + (int []) { Nx, Ny }); +#else + gkyl_rect_grid_init(&coarse_bdata[0].grid, 2, (double []) { refined_x1, refined_y1 }, (double []) { refined_x2, refined_y2 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + + gkyl_rect_grid_init(&coarse_bdata[1].grid, 2, (double []) { intermediate_x1, refined_y2 }, (double []) { refined_x1, intermediate_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&coarse_bdata[2].grid, 2, (double []) { refined_x1, refined_y2 }, (double []) { refined_x2, intermediate_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&coarse_bdata[3].grid, 2, (double []) { refined_x2, refined_y2 }, (double []) { intermediate_x2, intermediate_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&coarse_bdata[4].grid, 2, (double []) { intermediate_x1, refined_y1 }, (double []) { refined_x1, refined_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&coarse_bdata[5].grid, 2, (double []) { refined_x2, refined_y1 }, (double []) { intermediate_x2, refined_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&coarse_bdata[6].grid, 2, (double []) { intermediate_x1, intermediate_y1 }, (double []) { refined_x1, refined_y1 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&coarse_bdata[7].grid, 2, (double []) { refined_x1, intermediate_y1 }, (double []) { refined_x2, refined_y1 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&coarse_bdata[8].grid, 2, (double []) { refined_x2, intermediate_y1 }, (double []) { intermediate_x2, refined_y1 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); +#endif + + gkyl_rect_grid_init(&coarse_bdata[9].grid, 2, (double []) { coarse_x1, intermediate_y2 }, (double []) { intermediate_x1, coarse_y2 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[10].grid, 2, (double []) { intermediate_x1, intermediate_y2 }, (double []) { refined_x1, coarse_y2 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[11].grid, 2, (double []) { refined_x1, intermediate_y2 }, (double []) { refined_x2, coarse_y2 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[12].grid, 2, (double []) { refined_x2, intermediate_y2 }, (double []) { intermediate_x2, coarse_y2 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[13].grid, 2, (double []) { intermediate_x2, intermediate_y2 }, (double []) { coarse_x2, coarse_y2 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[14].grid, 2, (double []) { coarse_x1, refined_y2 }, (double []) { intermediate_x1, intermediate_y2 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[15].grid, 2, (double []) { intermediate_x2, refined_y2 }, (double []) { coarse_x2, intermediate_y2 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[16].grid, 2, (double []) { coarse_x1, refined_y1 }, (double []) { intermediate_x1, refined_y2 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[17].grid, 2, (double []) { intermediate_x2, refined_y1 }, (double []) { coarse_x2, refined_y2 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[18].grid, 2, (double []) { coarse_x1, intermediate_y1 }, (double []) { intermediate_x1, refined_y1 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[19].grid, 2, (double []) { intermediate_x2, intermediate_y1 }, (double []) { coarse_x2, refined_y1 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[20].grid, 2, (double []) { coarse_x1, coarse_y1 }, (double []) { intermediate_x1, intermediate_y1 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[21].grid, 2, (double []) { intermediate_x1, coarse_y1 }, (double []) { refined_x1, intermediate_y1 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[22].grid, 2, (double []) { refined_x1, coarse_y1 }, (double []) { refined_x2, intermediate_y1 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[23].grid, 2, (double []) { refined_x2, coarse_y1 }, (double []) { intermediate_x2, intermediate_y1 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[24].grid, 2, (double []) { intermediate_x2, coarse_y1 }, (double []) { coarse_x2, intermediate_y1 }, + (int []) { Nx, Ny }); + +#ifdef AMR_DEBUG + struct euler_block_data intermediate_bdata[num_blocks]; + struct gkyl_job_pool *intermediate_job_pool = gkyl_thread_pool_new(app_args.num_threads); + + gkyl_rect_grid_init(&intermediate_bdata[0].grid, 2, (double []) { refined_x1, refined_y1 }, (double []) { refined_x2, refined_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + + gkyl_rect_grid_init(&intermediate_bdata[1].grid, 2, (double []) { coarse_x1, refined_y2 }, (double []) { refined_x1, coarse_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[2].grid, 2, (double []) { refined_x1, refined_y2 }, (double []) { refined_x2, coarse_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[3].grid, 2, (double []) { refined_x2, refined_y2 }, (double []) { coarse_x2, coarse_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[4].grid, 2, (double []) { coarse_x1, refined_y1 }, (double []) { refined_x1, refined_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[5].grid, 2, (double []) { refined_x2, refined_y1 }, (double []) { coarse_x2, refined_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[6].grid, 2, (double []) { coarse_x1, coarse_y1 }, (double []) { refined_x1, refined_y1 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[7].grid, 2, (double []) { refined_x1, coarse_y1 }, (double []) { refined_x2, refined_y1 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[8].grid, 2, (double []) { refined_x2, coarse_y1 }, (double []) { coarse_x2, refined_y1 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + + gkyl_rect_grid_init(&intermediate_bdata[9].grid, 2, (double []) { coarse_x1, intermediate_y2 }, (double []) { intermediate_x1, coarse_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[10].grid, 2, (double []) { intermediate_x1, intermediate_y2 }, (double []) { refined_x1, coarse_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[11].grid, 2, (double []) { refined_x1, intermediate_y2 }, (double []) { refined_x2, coarse_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[12].grid, 2, (double []) { refined_x2, intermediate_y2 }, (double []) { intermediate_x2, coarse_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[13].grid, 2, (double []) { intermediate_x2, intermediate_y2 }, (double []) { coarse_x2, coarse_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[14].grid, 2, (double []) { coarse_x1, refined_y2 }, (double []) { intermediate_x1, intermediate_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[15].grid, 2, (double []) { intermediate_x2, refined_y2 }, (double []) { coarse_x2, intermediate_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[16].grid, 2, (double []) { coarse_x1, refined_y1 }, (double []) { intermediate_x1, refined_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[17].grid, 2, (double []) { intermediate_x2, refined_y1 }, (double []) { coarse_x2, refined_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[18].grid, 2, (double []) { coarse_x1, intermediate_y1 }, (double []) { intermediate_x1, refined_y1 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[19].grid, 2, (double []) { intermediate_x2, intermediate_y1 }, (double []) { coarse_x2, refined_y1 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[20].grid, 2, (double []) { coarse_x1, coarse_y1 }, (double []) { intermediate_x1, intermediate_y1 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[21].grid, 2, (double []) { intermediate_x1, coarse_y1 }, (double []) { refined_x1, intermediate_y1 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[22].grid, 2, (double []) { refined_x1, coarse_y1 }, (double []) { refined_x2, intermediate_y1 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[23].grid, 2, (double []) { refined_x2, coarse_y1 }, (double []) { intermediate_x2, intermediate_y1 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[24].grid, 2, (double []) { intermediate_x2, coarse_y1 }, (double []) { coarse_x2, intermediate_y1 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + + struct euler_block_data fine_bdata[num_blocks]; + struct gkyl_job_pool *fine_job_pool = gkyl_thread_pool_new(app_args.num_threads); + + gkyl_rect_grid_init(&fine_bdata[0].grid, 2, (double []) { refined_x1, refined_y1 }, (double []) { refined_x2, refined_y2 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + + gkyl_rect_grid_init(&fine_bdata[1].grid, 2, (double []) { coarse_x1, refined_y2 }, (double []) { refined_x1, coarse_y2 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[2].grid, 2, (double []) { refined_x1, refined_y2 }, (double []) { refined_x2, coarse_y2 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[3].grid, 2, (double []) { refined_x2, refined_y2 }, (double []) { coarse_x2, coarse_y2 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[4].grid, 2, (double []) { coarse_x1, refined_y1 }, (double []) { refined_x1, refined_y2 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[5].grid, 2, (double []) { refined_x2, refined_y1 }, (double []) { coarse_x2, refined_y2 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[6].grid, 2, (double []) { coarse_x1, coarse_y1 }, (double []) { refined_x1, refined_y1 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[7].grid, 2, (double []) { refined_x1, coarse_y1 }, (double []) { refined_x2, refined_y1 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[8].grid, 2, (double []) { refined_x2, coarse_y1 }, (double []) { coarse_x2, refined_y1 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + + gkyl_rect_grid_init(&fine_bdata[9].grid, 2, (double []) { coarse_x1, intermediate_y2 }, (double []) { intermediate_x1, coarse_y2 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[10].grid, 2, (double []) { intermediate_x1, intermediate_y2 }, (double []) { refined_x1, coarse_y2 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[11].grid, 2, (double []) { refined_x1, intermediate_y2 }, (double []) { refined_x2, coarse_y2 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[12].grid, 2, (double []) { refined_x2, intermediate_y2 }, (double []) { intermediate_x2, coarse_y2 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[13].grid, 2, (double []) { intermediate_x2, intermediate_y2 }, (double []) { coarse_x2, coarse_y2 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[14].grid, 2, (double []) { coarse_x1, refined_y2 }, (double []) { intermediate_x1, intermediate_y2 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[15].grid, 2, (double []) { intermediate_x2, refined_y2 }, (double []) { coarse_x2, intermediate_y2 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[16].grid, 2, (double []) { coarse_x1, refined_y1 }, (double []) { intermediate_x1, refined_y2 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[17].grid, 2, (double []) { intermediate_x2, refined_y1 }, (double []) { coarse_x2, refined_y2 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[18].grid, 2, (double []) { coarse_x1, intermediate_y1 }, (double []) { intermediate_x1, refined_y1 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[19].grid, 2, (double []) { intermediate_x2, intermediate_y1 }, (double []) { coarse_x2, refined_y1 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[20].grid, 2, (double []) { coarse_x1, coarse_y1 }, (double []) { intermediate_x1, intermediate_y1 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[21].grid, 2, (double []) { intermediate_x1, coarse_y1 }, (double []) { refined_x1, intermediate_y1 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[22].grid, 2, (double []) { refined_x1, coarse_y1 }, (double []) { refined_x2, intermediate_y1 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[23].grid, 2, (double []) { refined_x2, coarse_y1 }, (double []) { intermediate_x2, intermediate_y1 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[24].grid, 2, (double []) { intermediate_x2, coarse_y1 }, (double []) { coarse_x2, intermediate_y1 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); +#endif + + for (int i = 0; i < num_blocks; i++) { + coarse_bdata[i].fv_proj = gkyl_fv_proj_new(&coarse_bdata[i].grid, 2, 5, eval, 0); + +#ifdef AMR_DEBUG + intermediate_bdata[i].fv_proj = gkyl_fv_proj_new(&intermediate_bdata[i].grid, 2, 5, eval, 0); + fine_bdata[i].fv_proj = gkyl_fv_proj_new(&fine_bdata[i].grid, 2, 5, eval, 0); +#endif + } + + for (int i = 0; i < num_blocks; i++) { + gkyl_create_grid_ranges(&coarse_bdata[i].grid, (int []) { 2, 2 }, &coarse_bdata[i].ext_range, &coarse_bdata[i].range); + coarse_bdata[i].geom = gkyl_wave_geom_new(&coarse_bdata[i].grid, &coarse_bdata[i].ext_range, 0, 0, false); + +#ifdef AMR_DEBUG + gkyl_create_grid_ranges(&intermediate_bdata[i].grid, (int []) { 2, 2 }, &intermediate_bdata[i].ext_range, &intermediate_bdata[i].range); + intermediate_bdata[i].geom = gkyl_wave_geom_new(&intermediate_bdata[i].grid, &intermediate_bdata[i].ext_range, 0, 0, false); + + gkyl_create_grid_ranges(&fine_bdata[i].grid, (int []) { 2, 2 }, &fine_bdata[i].ext_range, &fine_bdata[i].range); + fine_bdata[i].geom = gkyl_wave_geom_new(&fine_bdata[i].grid, &fine_bdata[i].ext_range, 0, 0, false); +#endif + } + + for (int i = 0; i < num_blocks; i++) { + if (low_order_flux) { + struct gkyl_wv_euler_inp inp = { + .gas_gamma = gas_gamma, + .rp_type = WV_EULER_RP_HLL, + .use_gpu = app_args.use_gpu, + }; + coarse_bdata[i].euler = gkyl_wv_euler_inew(&inp); + } + else { + coarse_bdata[i].euler = gkyl_wv_euler_new(gas_gamma, app_args.use_gpu); + } + + for (int d = 0; d < ndim; d++) { + coarse_bdata[i].slvr[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { + .grid = &coarse_bdata[i].grid, + .equation = coarse_bdata[i].euler, + .limiter = GKYL_MONOTONIZED_CENTERED, + .num_up_dirs = 1, + .update_dirs = { d }, + .cfl = cfl_frac, + .geom = coarse_bdata[i].geom, + } + ); + } + +#ifdef AMR_DEBUG + if (low_order_flux) { + struct gkyl_wv_euler_inp inp = { + .gas_gamma = gas_gamma, + .rp_type = WV_EULER_RP_HLL, + .use_gpu = app_args.use_gpu, + }; + intermediate_bdata[i].euler = gkyl_wv_euler_inew(&inp); + fine_bdata[i].euler = gkyl_wv_euler_inew(&inp); + } + else { + intermediate_bdata[i].euler = gkyl_wv_euler_new(gas_gamma, app_args.use_gpu); + fine_bdata[i].euler = gkyl_wv_euler_new(gas_gamma, app_args.use_gpu); + } + + for (int d = 0; d < ndim; d++) { + intermediate_bdata[i].slvr[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { + .grid = &intermediate_bdata[i].grid, + .equation = intermediate_bdata[i].euler, + .limiter = GKYL_MONOTONIZED_CENTERED, + .num_up_dirs = 1, + .update_dirs = { d }, + .cfl = cfl_frac, + .geom = intermediate_bdata[i].geom, + } + ); + + fine_bdata[i].slvr[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { + .grid = &fine_bdata[i].grid, + .equation = fine_bdata[i].euler, + .limiter = GKYL_MONOTONIZED_CENTERED, + .num_up_dirs = 1, + .update_dirs = { d }, + .cfl = cfl_frac, + .geom = fine_bdata[i].geom, + } + ); + } +#endif + } + + struct gkyl_block_topo *btopo = create_nested_block_topo(); + + for (int i = 0; i < num_blocks; i++) { + euler_nested_block_bc_updaters_init(&coarse_bdata[i], &btopo->conn[i]); + +#ifdef AMR_DEBUG + euler_nested_block_bc_updaters_init(&intermediate_bdata[i], &btopo->conn[i]); + euler_nested_block_bc_updaters_init(&fine_bdata[i], &btopo->conn[i]); +#endif + } + + for (int i = 0; i < num_blocks; i++) { + coarse_bdata[i].fdup = gkyl_array_new(GKYL_DOUBLE, 5, coarse_bdata[i].ext_range.volume); + + for (int d = 0; d < ndim + 1; d++) { + coarse_bdata[i].f[d] = gkyl_array_new(GKYL_DOUBLE, 5, coarse_bdata[i].ext_range.volume); + } + +#ifdef AMR_DEBUG + intermediate_bdata[i].fdup = gkyl_array_new(GKYL_DOUBLE, 5, intermediate_bdata[i].ext_range.volume); + fine_bdata[i].fdup = gkyl_array_new(GKYL_DOUBLE, 5, fine_bdata[i].ext_range.volume); + + for (int d = 0; d < ndim + 1; d++) { + intermediate_bdata[i].f[d] = gkyl_array_new(GKYL_DOUBLE, 5, intermediate_bdata[i].ext_range.volume); + fine_bdata[i].f[d] = gkyl_array_new(GKYL_DOUBLE, 5, fine_bdata[i].ext_range.volume); + } +#endif + } + +#ifdef AMR_USETHREADS + for (int i = 0; i < num_blocks; i++) { + gkyl_job_pool_add_work(coarse_job_pool, euler_init_job_func_block, &coarse_bdata[i]); + +#ifdef AMR_DEBUG + gkyl_job_pool_add_work(intermediate_job_pool, euler_init_job_func_block, &intermediate_bdata[i]); + gkyl_job_pool_add_work(fine_job_pool, euler_init_job_func_block, &fine_bdata[i]); +#endif + } + gkyl_job_pool_wait(coarse_job_pool); + +#ifdef AMR_DEBUG + gkyl_job_pool_wait(intermediate_job_pool); + gkyl_job_pool_wait(fine_job_pool); +#endif +#else + for (int i = 0; i < num_blocks; i++) { + euler_init_job_func_block(&coarse_bdata[i]); + +#ifdef AMR_DEBUG + euler_init_job_func_block(&intermediate_bdata[i]); + euler_init_job_func_block(&fine_bdata[i]); +#endif + } +#endif + +#ifdef AMR_DEBUG + char coarse0[64]; + snprintf(coarse0, 64, "%s_coarse_0", euler_output); + euler_write_sol_block(coarse0, num_blocks, coarse_bdata); + + char intermediate0[64]; + snprintf(intermediate0, 64, "%s_intermediate_0", euler_output); + euler_write_sol_block(intermediate0, num_blocks, intermediate_bdata); + + char fine0[64]; + snprintf(fine0, 64, "%s_fine_0", euler_output); + euler_write_sol_block(fine0, num_blocks, fine_bdata); + + char fine0b0[64]; + char intermediate0b0[64]; + char coarse0b0[64]; + char b0[64]; + snprintf(fine0b0, 64, "%s_fine_0_b0.gkyl", euler_output); + snprintf(intermediate0b0, 64, "%s_intermediate_0_b0.gkyl", euler_output); + snprintf(coarse0b0, 64, "%s_coarse_0_b0.gkyl", euler_output); + snprintf(b0, 64, "%s_0_b0.gkyl", euler_output); + rename(fine0b0, b0); + remove(intermediate0b0); + remove(coarse0b0); + + for (int i = 1; i < 9; i++) { + char fine0bi[64]; + char intermediate0bi[64]; + char coarse0bi[64]; + char bi[64]; + snprintf(fine0bi, 64, "%s_fine_0_b%d.gkyl", euler_output, i); + snprintf(intermediate0bi, 64, "%s_intermediate_0_b%d.gkyl", euler_output, i); + snprintf(coarse0bi, 64, "%s_coarse_0_b%d.gkyl", euler_output, i); + snprintf(bi, 64, "%s_0_b%d.gkyl", euler_output, i); + rename(intermediate0bi, bi); + remove(fine0bi); + remove(coarse0bi); + } + + for (int i = 9; i < 25; i++) { + char buf_old[64]; + char buf_new[64]; + char buf_del1[64]; + char buf_del2[64]; + + snprintf(buf_old, 64, "%s_coarse_0_b%d.gkyl", euler_output, i); + snprintf(buf_new, 64, "%s_0_b%d.gkyl", euler_output, i); + snprintf(buf_del1, 64, "%s_intermediate_0_b%d.gkyl", euler_output, i); + snprintf(buf_del2, 64, "%s_fine_0_b%d.gkyl", euler_output, i); + + rename(buf_old, buf_new); + remove(buf_del1); + remove(buf_del2); + } +#else + char amr0[64]; + snprintf(amr0, 64, "%s_0", euler_output); + euler_write_sol_block(amr0, num_blocks, coarse_bdata); +#endif + + double coarse_t_curr = 0.0; + double intermediate_t_curr = 0.0; + double fine_t_curr = 0.0; + double coarse_dt = euler_max_dt_block(num_blocks, coarse_bdata); + +#ifdef AMR_DEBUG + double intermediate_dt = euler_max_dt_block(num_blocks, intermediate_bdata); + double fine_dt = euler_max_dt_block(num_blocks, fine_bdata); +#else + double intermediate_dt = (1.0 / ref_factor1) * coarse_dt; + double fine_dt = (1.0 / (ref_factor1 * ref_factor2)) * coarse_dt; +#endif + + struct sim_stats stats = { }; + + struct timespec tm_start = gkyl_wall_clock(); + + long coarse_step = 1; + long num_steps = app_args.num_steps; + + double io_trigger = t_end / num_frames; + + double dt_init = -1.0; + int num_failures = 0; + + while ((coarse_t_curr < t_end) && (coarse_step <= num_steps)) { + printf("Taking coarse (level 0) time-step %ld at t = %g; ", coarse_step, coarse_t_curr); + struct gkyl_update_status coarse_status = euler_update_block(coarse_job_pool, btopo, coarse_bdata, coarse_t_curr, coarse_dt, &stats); + printf(" dt = %g\n", coarse_status.dt_actual); + + if (!coarse_status.success) { + printf("** Update method failed! Aborting simulation ....\n"); + break; + } + + for (long intermediate_step = 1; intermediate_step < ref_factor1 + 1; intermediate_step++) { +#ifdef AMR_DEBUG + printf(" Taking intermediate (level 1) time-step %ld at t = %g; ", intermediate_step, intermediate_t_curr); + struct gkyl_update_status intermediate_status = euler_update_block(intermediate_job_pool, btopo, intermediate_bdata, intermediate_t_curr, intermediate_dt, &stats); + printf(" dt = %g\n", intermediate_status.dt_actual); + + if (!intermediate_status.success) { + printf("** Update method failed! Aborting simulation ....\n"); + break; + } + + for (long fine_step = 1; fine_step < ref_factor2 + 1; fine_step++) { + printf(" Taking fine (level 2) time-step %ld at t = %g; ", fine_step, fine_t_curr); + struct gkyl_update_status fine_status = euler_update_block(fine_job_pool, btopo, fine_bdata, fine_t_curr, fine_dt, &stats); + printf( "dt = %g\n", fine_status.dt_actual); + + if (!fine_status.success) { + printf("** Update method failed! Aborting simulation ....\n"); + break; + } + + fine_t_curr += fine_status.dt_actual; + fine_dt = fine_status.dt_suggested; + } + + intermediate_t_curr += intermediate_status.dt_actual; + intermediate_dt = intermediate_status.dt_suggested; +#else + printf(" Taking intermediate (level 1) time-step %ld at t = %g", intermediate_step, intermediate_t_curr); + printf(" dt = %g\n", (1.0 / ref_factor1) * coarse_status.dt_actual); + + for (long fine_step = 1; fine_step < ref_factor2 + 1; fine_step++) { + printf(" Taking fine (level 2) time-step %ld at t = %g", fine_step, fine_t_curr); + printf(" dt = %g\n", (1.0 / (ref_factor1 * ref_factor2)) * coarse_status.dt_actual); + + fine_t_curr += (1.0 / (ref_factor1 * ref_factor2)) * coarse_status.dt_actual; + fine_dt = (1.0 / (ref_factor1 * ref_factor2)) * coarse_status.dt_suggested; + } + + intermediate_t_curr += (1.0 / ref_factor1) * coarse_status.dt_actual; + intermediate_dt = (1.0 / ref_factor1) * coarse_status.dt_suggested; +#endif + } + + for (int i = 1; i < num_frames; i++) { + if (coarse_t_curr < (i * io_trigger) && (coarse_t_curr + coarse_status.dt_actual) > (i * io_trigger)) { + // TODO: Make file output work correctly in the AMR_DEBUG case. +#ifdef AMR_DEBUG + char buf_coarse[64]; + char buf_intermediate[64]; + char buf_fine[64]; + + snprintf(buf_coarse, 64, "%s_coarse_%d", euler_output, i); + snprintf(buf_intermediate, 64, "%s_intermediate_%d", euler_output, i); + snprintf(buf_fine, 64, "%s_fine_%d", euler_output, i); + + euler_write_sol_block(buf_coarse, num_blocks, coarse_bdata); + euler_write_sol_block(buf_intermediate, num_blocks, intermediate_bdata); + euler_write_sol_block(buf_fine, num_blocks, fine_bdata); + + char buf_fine_old[64]; + char buf_fine_new[64]; + char buf_intermediate_old[64]; + char buf_coarse_old[64]; + + snprintf(buf_fine_old, 64, "%s_fine_%d_b0.gkyl", euler_output, i); + snprintf(buf_fine_new, 64, "%s_%d_b0.gkyl", euler_output, i); + snprintf(buf_intermediate_old, 64, "%s_intermediate_%d_b0.gkyl", euler_output, i); + snprintf(buf_coarse_old, 64, "%s_coarse_%d_b0.gkyl", euler_output, i); + + rename(buf_fine_old, buf_fine_new); + remove(buf_intermediate_old); + remove(buf_coarse_old); + + for (int j = 1; j < 9; j++) { + char fine_bi[64]; + char intermediate_bi[64]; + char coarse_bi[64]; + char bi[64]; + snprintf(fine_bi, 64, "%s_fine_%d_b%d.gkyl", euler_output, i, j); + snprintf(intermediate_bi, 64, "%s_intermediate_%d_b%d.gkyl", euler_output, i, j); + snprintf(coarse_bi, 64, "%s_coarse_%d_b%d.gkyl", euler_output, i, j); + snprintf(bi, 64, "%s_%d_b%d.gkyl", euler_output, i, j); + rename(intermediate_bi, bi); + remove(fine_bi); + remove(coarse_bi); + } + + for (int j = 9; j < 25; j++) { + char buf_old[64]; + char buf_new[64]; + char buf_del1[64]; + char buf_del2[64]; + + snprintf(buf_old, 64, "%s_coarse_%d_b%d.gkyl", euler_output, i, j); + snprintf(buf_new, 64, "%s_%d_b%d.gkyl", euler_output, i, j); + snprintf(buf_del1, 64, "%s_intermediate_%d_b%d.gkyl", euler_output, i, j); + snprintf(buf_del2, 64, "%s_fine_%d_b%d.gkyl", euler_output, i, j); + + rename(buf_old, buf_new); + remove(buf_del1); + remove(buf_del2); + } +#else + char buf[64]; + snprintf(buf, 64, "%s_%d", euler_output, i); + + euler_write_sol_block(buf, num_blocks, coarse_bdata); +#endif + } + } + + coarse_t_curr += coarse_status.dt_actual; + coarse_dt = coarse_status.dt_suggested; + + if (dt_init < 0.0) { + dt_init = coarse_status.dt_actual; + } + else if (coarse_status.dt_actual < dt_failure_tol * dt_init) { + num_failures += 1; + + printf("WARNING: Time-step dt = %g", coarse_status.dt_actual); + printf(" is below %g*dt_init ...", dt_failure_tol); + printf(" num_failures = %d\n", num_failures); + if (num_failures >= num_failures_max) { + printf("ERROR: Time-step was below %g*dt_init ", dt_failure_tol); + printf("%d consecutive times. Aborting simulation ....\n", num_failures_max); + break; + } + } + else { + num_failures = 0; + } + + coarse_step += 1; + } + + double tm_total_sec = gkyl_time_diff_now_sec(tm_start); + + // TODO: Make file output work correctly in the AMR_DEBUG case. +#ifdef AMR_DEBUG + char buf_coarse[64]; + char buf_intermediate[64]; + char buf_fine[64]; + + snprintf(buf_coarse, 64, "%s_coarse_%d", euler_output, num_frames); + snprintf(buf_intermediate, 64, "%s_intermediate_%d", euler_output, num_frames); + snprintf(buf_fine, 64, "%s_fine_%d", euler_output, num_frames); + + euler_write_sol_block(buf_coarse, num_blocks, coarse_bdata); + euler_write_sol_block(buf_intermediate, num_blocks, intermediate_bdata); + euler_write_sol_block(buf_fine, num_blocks, fine_bdata); + + char buf_fine_old[64]; + char buf_fine_new[64]; + char buf_intermediate_old[64]; + char buf_coarse_old[64]; + + snprintf(buf_fine_old, 64, "%s_fine_%d_b0.gkyl", euler_output, num_frames); + snprintf(buf_fine_new, 64, "%s_%d_b0.gkyl", euler_output, num_frames); + snprintf(buf_intermediate_old, 64, "%s_intermediate_%d_b0.gkyl", euler_output, num_frames); + snprintf(buf_coarse_old, 64, "%s_coarse_%d_b0.gkyl", euler_output,num_frames); + + rename(buf_fine_old, buf_fine_new); + remove(buf_intermediate_old); + remove(buf_coarse_old); + + for (int i = 1; i < 9; i++) { + char fine_bi[64]; + char intermediate_bi[64]; + char coarse_bi[64]; + char bi[64]; + snprintf(fine_bi, 64, "%s_fine_%d_b%d.gkyl", euler_output, num_frames, i); + snprintf(intermediate_bi, 64, "%s_intermediate_%d_b%d.gkyl", euler_output, num_frames, i); + snprintf(coarse_bi, 64, "%s_coarse_%d_b%d.gkyl", euler_output, num_frames, i); + snprintf(bi, 64, "%s_%d_b%d.gkyl", euler_output, num_frames, i); + rename(intermediate_bi, bi); + remove(fine_bi); + remove(coarse_bi); + } + + for (int i = 9; i < 25; i++) { + char buf_old[64]; + char buf_new[64]; + char buf_del1[64]; + char buf_del2[64]; + + snprintf(buf_old, 64, "%s_coarse_%d_b%d.gkyl", euler_output, num_frames, i); + snprintf(buf_new, 64, "%s_%d_b%d.gkyl", euler_output, num_frames, i); + snprintf(buf_del1, 64, "%s_intermediate_%d_b%d.gkyl", euler_output, num_frames, i); + snprintf(buf_del2, 64, "%s_fine_%d_b%d.gkyl", euler_output, num_frames, i); + + rename(buf_old, buf_new); + remove(buf_del1); + remove(buf_del2); + } +#else + char buf[64]; + snprintf(buf, 64, "%s_%d", euler_output, num_frames); + + euler_write_sol_block(buf, num_blocks, coarse_bdata); +#endif + + printf("Total run-time: %g. Failed steps: %d\n", tm_total_sec, stats.nfail); + + for (int i = 0; i < num_blocks; i++) { + gkyl_fv_proj_release(coarse_bdata[i].fv_proj); + gkyl_wv_eqn_release(coarse_bdata[i].euler); + euler_block_bc_updaters_release(&coarse_bdata[i]); + gkyl_wave_geom_release(coarse_bdata[i].geom); + +#ifdef AMR_DEBUG + gkyl_fv_proj_release(intermediate_bdata[i].fv_proj); + gkyl_wv_eqn_release(intermediate_bdata[i].euler); + euler_block_bc_updaters_release(&intermediate_bdata[i]); + gkyl_wave_geom_release(intermediate_bdata[i].geom); + + gkyl_fv_proj_release(fine_bdata[i].fv_proj); + gkyl_wv_eqn_release(fine_bdata[i].euler); + euler_block_bc_updaters_release(&fine_bdata[i]); + gkyl_wave_geom_release(fine_bdata[i].geom); +#endif + + for (int d = 0; d < ndim; d++) { + gkyl_wave_prop_release(coarse_bdata[i].slvr[d]); + +#ifdef AMR_DEBUG + gkyl_wave_prop_release(intermediate_bdata[i].slvr[d]); + gkyl_wave_prop_release(fine_bdata[i].slvr[d]); +#endif + } + + gkyl_array_release(coarse_bdata[i].fdup); +#ifdef AMR_DEBUG + gkyl_array_release(intermediate_bdata[i].fdup); + gkyl_array_release(fine_bdata[i].fdup); +#endif + + for (int d = 0; d < ndim; d++) { + gkyl_array_release(coarse_bdata[i].f[d]); + +#ifdef AMR_DEBUG + gkyl_array_release(intermediate_bdata[i].f[d]); + gkyl_array_release(fine_bdata[i].f[d]); +#endif + } + } + + gkyl_block_topo_release(btopo); + gkyl_job_pool_release(coarse_job_pool); +#ifdef AMR_DEBUG + gkyl_job_pool_release(intermediate_job_pool); + gkyl_job_pool_release(fine_job_pool); +#endif } \ No newline at end of file diff --git a/amr/gkyl_amr_block_priv.h b/amr/gkyl_amr_block_priv.h index 0d5344a99..c108c75ef 100644 --- a/amr/gkyl_amr_block_priv.h +++ b/amr/gkyl_amr_block_priv.h @@ -129,6 +129,22 @@ void gr_euler_transmissive_bc(double t, int nc, const double* GKYL_RESTRICT skin */ void euler_block_bc_updaters_init(struct euler_block_data* bdata, const struct gkyl_block_connections* conn); +/** +* Initialize nested block AMR updaters for both physical (outer-block) and non-physical (inter-block) boundary conditions for the Euler equations. +* +* @param bdata Block-structured data for the Euler equations. +* @param conn Topology/connectivity data for the block hierarchy. +*/ +void euler_nested_block_bc_updaters_init(struct euler_block_data* bdata, const struct gkyl_block_connections* conn); + +/** +* Initialize nested block AMR updaters for both physical (outer-block) and non-physical (inter-block) boundary conditions for the general relativistic Euler equations. +* +* @param bdata Block-structured data for the general relativistic Euler equations. +* @param conn Topology/connectivity data for the block hierarchy. +*/ +void gr_euler_nested_block_bc_updaters_init(struct euler_block_data* bdata, const struct gkyl_block_connections* conn); + /** * Initialize block AMR updaters for both physical (outer-block) and non-physical (inter-block) boundary conditions for the general relativistic Euler equations. * @@ -248,4 +264,9 @@ double euler_max_dt_block(int num_blocks, const struct euler_block_data bdata[]) /** * Set up the topology/connectivity information for the block AMR hierarchy for a mesh containing a single refinement patch. */ -struct gkyl_block_topo* create_block_topo(); \ No newline at end of file +struct gkyl_block_topo* create_block_topo(); + +/** +* Set up the topology/connectivity information for the block AMR hierarchy for a mesh containing a doubly-nested refinement patch. +*/ +struct gkyl_block_topo* create_nested_block_topo(); \ No newline at end of file diff --git a/amr/gkyl_amr_core.h b/amr/gkyl_amr_core.h index f95d19f67..930403a68 100644 --- a/amr/gkyl_amr_core.h +++ b/amr/gkyl_amr_core.h @@ -151,6 +151,51 @@ struct gr_euler2d_single_init { */ void gr_euler2d_run_single(int argc, char **argv, struct gr_euler2d_single_init* init); +// Initialization data for a 2D simulation using the Euler equations, run with static, block-structured mesh refinement with a doubly-nested refinement patch. +struct euler2d_double_init { + int base_Nx; + int base_Ny; + int ref_factor1; + int ref_factor2; + + double coarse_x1; + double coarse_y1; + double coarse_x2; + double coarse_y2; + + double intermediate_x1; + double intermediate_y1; + double intermediate_x2; + double intermediate_y2; + + double refined_x1; + double refined_y1; + double refined_x2; + double refined_y2; + + evalf_t eval; + double gas_gamma; + + char euler_output[32]; + + bool low_order_flux; + double cfl_frac; + + double t_end; + int num_frames; + double dt_failure_tol; + int num_failures_max; +}; + +/** +* Run a 2D simulation using the Euler equations, with static, block-structured mesh refinement with a doubly-nested refinement patch. +* +* @param argc Number of command line arguments passed to the function. +* @param argv Array of command line arguments passed to the function. +* @param init Initialization data for the 2D Euler equations. +*/ +void euler2d_run_double(int argc, char **argv, struct euler2d_double_init* init); + // Initialization data for a 1D simulation using the coupled five-moment equations, run with static, patch-structured mesh refinement with a single refinement patch. struct five_moment_1d_single_init { int base_Nx; diff --git a/regression/rt_amr_euler_cart_axi_sodshock.c b/regression/rt_amr_euler_cart_axi_sodshock_l1.c similarity index 100% rename from regression/rt_amr_euler_cart_axi_sodshock.c rename to regression/rt_amr_euler_cart_axi_sodshock_l1.c diff --git a/regression/rt_amr_euler_cart_axi_sodshock_l2.c b/regression/rt_amr_euler_cart_axi_sodshock_l2.c new file mode 100644 index 000000000..1bcb99fb8 --- /dev/null +++ b/regression/rt_amr_euler_cart_axi_sodshock_l2.c @@ -0,0 +1,197 @@ +// 2D Sod-type shock tube test in axial symmetry, in Cartesian coordinates, using static, block-structured mesh refinement with a single refinement block (4x refinement), for the 5-moment (Euler) equations. +// Input parameters are an axisymmetric generalization of those in Section 2.6.2, with the contact discontinuity placed at r = 0.75, from the thesis: +// A. Hakim (2006), "High Resolution Wave Propagation Schemes for Two-Fluid Plasma Simulations", +// PhD Thesis, University of Washington. +// https://www.aa.washington.edu/sites/aa/files/research/cpdlab/docs/PhDthesis_hakim.pdf + +#include + +struct amr_euler_cart_axi_sodshock_ctx +{ + // Mathematical constants (dimensionless). + double pi; + + // Physical constants (using normalized code units). + double gas_gamma; // Adiabatic index. + + double rhol; // Left/inner fluid mass density. + double ul; // Left/inner fluid velocity. + double pl; // Left/inner fluid pressure. + + double rhor; // Right/outer fluid mass density. + double ur; // Right/outer fluid velocity. + double pr; // Right/outer fluid pressure. + + // Simulation parameters. + int Nx; // Coarse cell count (x-direction). + int Ny; // Coarse cell count (y-direction). + int ref_factor1; // First refinement factor. + int ref_factor2; // Second refinement factor. + double Lx; // Coarse domain size (x-direction). + double Ly; // Coarse domain size (y-direction). + double intermediate_Lx; // Intermediate domain size (x-direction). + double intermediate_Ly; // Intermediate domain size (y-direction). + double fine_Lx; // Fine domain size (x-direction). + double fine_Ly; // Fine domain size (y-direction). + double cfl_frac; // CFL coefficient. + + double t_end; // Final simulation time. + int num_frames; // Number of output frames. + double dt_failure_tol; // Minimum allowable fraction of initial time-step. + int num_failures_max; // Maximum allowable number of consecutive small time-steps. + + double rloc; // Fluid boundary (radial coordinate). +}; + +struct amr_euler_cart_axi_sodshock_ctx +create_ctx(void) +{ + // Mathematical constants (dimensionless). + double pi = M_PI; + + // Physical constants (using normalized code units). + double gas_gamma = 1.4; // Adiabatic index. + + double rhol = 3.0; // Left/inner fluid mass density. + double ul = 0.0; // Left/inner fluid velocity. + double pl = 3.0; // Left/inner fluid pressure. + + double rhor = 1.0; // Right/outer fluid mass density. + double ur = 0.0; // Right/outer fluid velocity. + double pr = 1.0; // Right/outer fluid pressure. + + // Simulation parameters. + int Nx = 8; // Coarse cell count (x-direction). + int Ny = 8; // Coarse cell count (y-direction). + int ref_factor1 = 4; // First refinement factor. + int ref_factor2 = 4; // Second refinement factor; + double Lx = 2.5; // Coarse domain size (x-direction). + double Ly = 2.5; // Coarse domain size (y-direction). + double intermediate_Lx = 1.8; // Intermediate domain size (x-direction). + double intermediate_Ly = 1.8; // Intermediate domain size (y-direction). + double fine_Lx = 1.0; // Fine domain size (x-direction). + double fine_Ly = 1.0; // Fine domain size (y-direction). + double cfl_frac = 0.95; // CFL coefficient. + + double t_end = 0.2; // Final simulation time. + int num_frames = 1; // Number of output frames. + double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. + int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. + + double rloc = 0.5 * (0.25 + 1.25); // Fluid boundary (radial coordinate). + + struct amr_euler_cart_axi_sodshock_ctx ctx = { + .pi = pi, + .gas_gamma = gas_gamma, + .rhol = rhol, + .ul = ul, + .pl = pl, + .rhor = rhor, + .ur = ur, + .pr = pr, + .Nx = Nx, + .Ny = Ny, + .ref_factor1 = ref_factor1, + .ref_factor2 = ref_factor2, + .Lx = Lx, + .Ly = Ly, + .intermediate_Lx = intermediate_Lx, + .intermediate_Ly = intermediate_Ly, + .fine_Lx = fine_Lx, + .fine_Ly = fine_Ly, + .cfl_frac = cfl_frac, + .t_end = t_end, + .num_frames = num_frames, + .dt_failure_tol = dt_failure_tol, + .num_failures_max = num_failures_max, + .rloc = rloc, + }; + + return ctx; +} + +void +evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +{ + double x = xn[0], y = xn[1]; + struct amr_euler_cart_axi_sodshock_ctx new_ctx = create_ctx(); // Context for initialization functions. + struct amr_euler_cart_axi_sodshock_ctx *app = &new_ctx; + + double gas_gamma = app->gas_gamma; + + double rhol = app->rhol; + double ul = app->ul; + double pl = app->pl; + + double rhor = app->rhor; + double ur = app->ur; + double pr = app->pr; + + double rloc = app->rloc; + + double rho = 0.0; + double u = 0.0; + double p = 0.0; + + double r = sqrt(x * x + y * y); + + if (r < rloc) { + rho = rhol; // Fluid mass density (left/inner). + u = ul; // Fluid velocity (left/inner). + p = pl; // Fluid pressure (left/inner). + } + else { + rho = rhor; // Fluid mass density (right/outer). + u = ur; // Fluid velocity (right/outer). + p = pr; // Fluid pressure (right/outer). + } + + // Set fluid mass density. + fout[0] = rho; + // Set fluid momentum density. + fout[1] = rho * u; fout[2] = 0.0; fout[3] = 0.0; + // Set fluid total energy density. + fout[4] = p / (gas_gamma - 1.0) + 0.5 * rho * u * u; +} + +int main(int argc, char **argv) +{ + struct amr_euler_cart_axi_sodshock_ctx ctx = create_ctx(); // Context for initialization functions. + + struct euler2d_double_init init = { + .base_Nx = ctx.Nx, + .base_Ny = ctx.Ny, + .ref_factor1 = ctx.ref_factor1, + .ref_factor2 = ctx.ref_factor2, + + .coarse_x1 = -0.5 * ctx.Lx, + .coarse_y1 = -0.5 * ctx.Ly, + .coarse_x2 = 0.5 * ctx.Lx, + .coarse_y2 = 0.5 * ctx.Ly, + + .intermediate_x1 = -0.5 * ctx.intermediate_Lx, + .intermediate_y1 = -0.5 * ctx.intermediate_Ly, + .intermediate_x2 = 0.5 * ctx.intermediate_Lx, + .intermediate_y2 = 0.5 * ctx.intermediate_Ly, + + .refined_x1 = -0.5 * ctx.fine_Lx, + .refined_y1 = -0.5 * ctx.fine_Ly, + .refined_x2 = 0.5 * ctx.fine_Lx, + .refined_y2 = 0.5 * ctx.fine_Ly, + + .eval = evalEulerInit, + .gas_gamma = ctx.gas_gamma, + + .euler_output = "amr_euler_cart_axi_sodshock_l2", + + .low_order_flux = false, + .cfl_frac = ctx.cfl_frac, + + .t_end = ctx.t_end, + .num_frames = ctx.num_frames, + .dt_failure_tol = ctx.dt_failure_tol, + .num_failures_max = ctx.num_failures_max, + }; + + euler2d_run_double(argc, argv, &init); +} \ No newline at end of file diff --git a/regression/rt_amr_euler_riem_2d.c b/regression/rt_amr_euler_riem_2d_l1.c similarity index 100% rename from regression/rt_amr_euler_riem_2d.c rename to regression/rt_amr_euler_riem_2d_l1.c diff --git a/regression/rt_amr_euler_riem_2d_l2.c b/regression/rt_amr_euler_riem_2d_l2.c new file mode 100644 index 000000000..1bb004b76 --- /dev/null +++ b/regression/rt_amr_euler_riem_2d_l2.c @@ -0,0 +1,253 @@ +// 2D Riemann (quadrant) problem, using static, block-structured mesh refinement with a single refinement block (4x refinement), for the 5-moment (Euler) equations. +// Input parameters match the initial conditions in Section 4.3, Case 3, with final time set to t = 0.8 rather than t = 0.3, from the article: +// R. Liska and B. Wendroff (2003), "Comparison of Several Difference Schemes on 1D and 2D Test Problems for the Euler Equations", +// SIAM Journal on Scientific Computing, Volume 25 (3): 995-1017. +// https://epubs.siam.org/doi/10.1137/S1064827502402120 + +#include + +struct amr_euler_riem_2d_ctx +{ + // Physical constants (using normalized code units). + double gas_gamma; // Adiabatic index. + + double rho_ul; // Upper left fluid mass density. + double u_ul; // Upper left fluid x-velocity. + double v_ul; // Upper left fluid y-velocity. + double p_ul; // Upper left fluid pressure. + + double rho_ur; // Upper right fluid mass density. + double u_ur; // Upper right fluid x-velocity. + double v_ur; // Upper right fluid y-velocity. + double p_ur; // Upper left fluid pressure. + + double rho_ll; // Lower left fluid mass density. + double u_ll; // Lower left fluid x-velocity. + double v_ll; // Lower left fluid y-velocity. + double p_ll; // Lower left fluid pressure. + + double rho_lr; // Lower right fluid mass density. + double u_lr; // Lower right fluid x-velocity. + double v_lr; // Lower right fluid y-velocity. + double p_lr; // Lower right fluid pressure. + + // Simulation parameters. + int Nx; // Coarse cell count (x-direction). + int Ny; // Coarse cell count (y-direction). + int ref_factor1; // First refinement factor. + int ref_factor2; // Second refinement factor. + double Lx; // Coarse domain size (x-direction). + double Ly; // Coarse domain size (y-direction). + double intermediate_Lx; // Intermediate domain size (x-direction). + double intermediate_Ly; // Intermediate domain size (y-direction). + double fine_Lx; // Fine domain size (x-direction). + double fine_Ly; // Fine domain size (y-direction). + double cfl_frac; // CFL coefficient. + + double t_end; // Final simulation time. + int num_frames; // Number of output frames. + double dt_failure_tol; // Minimum allowable fraction of initial time-step. + int num_failures_max; // Maximum allowable number of consecutive small time-steps. + + double loc; // Fluid boundaries (both x and y coordinates). +}; + +struct amr_euler_riem_2d_ctx +create_ctx(void) +{ + // Physical constants (using normalized code units). + double gas_gamma = 1.4; // Adiabatic index. + + double rho_ul = 0.5323; // Upper-left fluid mass density. + double u_ul = 1.206; // Upper-left fluid x-velocity. + double v_ul = 0.0; // Upper-left fluid y-velocity. + double p_ul = 0.3; // Upper-left fluid pressure. + + double rho_ur = 1.5; // Upper-right fluid mass density. + double u_ur = 0.0; // Upper-right fluid x-velocity. + double v_ur = 0.0; // Upper-right fluid y-velocity. + double p_ur = 1.5; // Upper-right fluid pressure. + + double rho_ll = 0.138; // Lower-left fluid mass density. + double u_ll = 1.206; // Lower-left fluid x-velocity. + double v_ll = 1.206; // Lower-left fluid y-velocity. + double p_ll = 0.029; // Lower-left fluid pressure. + + double rho_lr = 0.5323; // Lower-right fluid mass density. + double u_lr = 0.0; // Lower-right fluid x-velocity. + double v_lr = 1.206; // Lower-right fluid y-velocity. + double p_lr = 0.3; // Lower-right fluid pressure. + + // Simulation parameters. + int Nx = 8; // Coarse cell count (x-direction). + int Ny = 8; // Coarse cell count (y-direction). + int ref_factor1 = 4; // First refinement factor. + int ref_factor2 = 4; // Second refinement factor. + double Lx = 1.0; // Coarse domain size (x-direction). + double Ly = 1.0; // Coarse domain size (y-direction). + double intermediate_Lx = 0.75; // Intermediate domain size (x-direction). + double intermediate_Ly = 0.75; // Intermediate domain size (y-direction). + double fine_Lx = 0.25; // Fine domain size (x-direction). + double fine_Ly = 0.25; // Fine domain size (y-direction). + double cfl_frac = 0.95; // CFL coefficient. + + double t_end = 0.8; // Final simulation time. + int num_frames = 1; // Number of output frames. + double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. + int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. + + double loc = 0.8; // Fluid boundaries (both x and y coordinates). + + struct amr_euler_riem_2d_ctx ctx = { + .gas_gamma = gas_gamma, + .rho_ul = rho_ul, + .u_ul = u_ul, + .v_ul = v_ul, + .p_ul = p_ul, + .rho_ur = rho_ur, + .u_ur = u_ur, + .v_ur = v_ur, + .p_ur = p_ur, + .rho_ll = rho_ll, + .u_ll = u_ll, + .v_ll = v_ll, + .p_ll = p_ll, + .rho_lr = rho_lr, + .u_lr = u_lr, + .v_lr = v_lr, + .p_lr = p_lr, + .Nx = Nx, + .Ny = Ny, + .ref_factor1 = ref_factor1, + .ref_factor2 = ref_factor2, + .Lx = Lx, + .Ly = Ly, + .intermediate_Lx = intermediate_Lx, + .intermediate_Ly = intermediate_Ly, + .fine_Lx = fine_Lx, + .fine_Ly = fine_Ly, + .cfl_frac = cfl_frac, + .t_end = t_end, + .num_frames = num_frames, + .dt_failure_tol = dt_failure_tol, + .num_failures_max = num_failures_max, + .loc = loc, + }; + + return ctx; +} + +void +evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +{ + double x = xn[0], y = xn[1]; + struct amr_euler_riem_2d_ctx new_ctx = create_ctx(); // Context for initialization functions. + struct amr_euler_riem_2d_ctx *app = &new_ctx; + + double gas_gamma = app->gas_gamma; + + double rho_ul = app->rho_ul; + double u_ul = app->u_ul; + double v_ul = app->v_ul; + double p_ul = app->p_ul; + + double rho_ur = app->rho_ur; + double u_ur = app->u_ur; + double v_ur = app->v_ur; + double p_ur = app->p_ur; + + double rho_ll = app->rho_ll; + double u_ll = app->u_ll; + double v_ll = app->v_ll; + double p_ll = app->p_ll; + + double rho_lr = app->rho_lr; + double u_lr = app->u_lr; + double v_lr = app->v_lr; + double p_lr = app->p_lr; + + double loc = app->loc; + + double rho = 0.0; + double u = 0.0; + double v = 0.0; + double p = 0.0; + + if (y > loc) { + if (x < loc) { + rho = rho_ul; // Fluid mass density (upper-left). + u = u_ul; // Fluid x-velocity (upper-left). + v = v_ul; // Fluid y-velocity (upper-left). + p = p_ul; // Fluid pressure (upper-left). + } + else { + rho = rho_ur; // Fluid mass density (upper-right). + u = u_ur; // Fluid x-velocity (upper-right). + v = v_ur; // Fluid y-velocity (upper-right). + p = p_ur; // Fluid pressure (upper-right). + } + } + else { + if (x < loc) { + rho = rho_ll; // Fluid mass density (lower-left). + u = u_ll; // Fluid x-velocity (lower-left). + v = v_ll; // Fluid y-velocity (lower-left). + p = p_ll; // Fluid pressure (lower-left). + } + else { + rho = rho_lr; // Fluid mass density (lower-right). + u = u_lr; // Fluid x-velocity (lower-right). + v = v_lr; // Fluid y-velocity (lower-right). + p = p_lr; // Fluid pressure (lower-right). + } + } + + // Set fluid mass density. + fout[0] = rho; + // Set fluid momentum density. + fout[1] = rho * u; fout[2] = rho * v; fout[3] = 0.0; + // Set fluid total energy density. + fout[4] = p / (gas_gamma - 1.0) + 0.5 * rho * (u * u + v * v); +} + +int main(int argc, char **argv) +{ + struct amr_euler_riem_2d_ctx ctx = create_ctx(); // Context for initialization functions. + + struct euler2d_double_init init = { + .base_Nx = ctx.Nx, + .base_Ny = ctx.Ny, + .ref_factor1 = ctx.ref_factor1, + .ref_factor2 = ctx.ref_factor2, + + .coarse_x1 = 0.0, + .coarse_y1 = 0.0, + .coarse_x2 = ctx.Lx, + .coarse_y2 = ctx.Ly, + + .intermediate_x1 = (0.5 * ctx.Lx) - (0.5 * ctx.intermediate_Lx), + .intermediate_y1 = (0.5 * ctx.Ly) - (0.5 * ctx.intermediate_Ly), + .intermediate_x2 = (0.5 * ctx.Lx) + (0.5 * ctx.intermediate_Lx), + .intermediate_y2 = (0.5 * ctx.Ly) + (0.5 * ctx.intermediate_Ly), + + .refined_x1 = (0.5 * ctx.Lx) - (0.5 * ctx.fine_Lx), + .refined_y1 = (0.5 * ctx.Ly) - (0.5 * ctx.fine_Ly), + .refined_x2 = (0.5 * ctx.Lx) + (0.5 * ctx.fine_Lx), + .refined_y2 = (0.5 * ctx.Ly) + (0.5 * ctx.fine_Ly), + + .eval = evalEulerInit, + .gas_gamma = ctx.gas_gamma, + + .euler_output = "amr_euler_riem_2d_l2", + + .low_order_flux = false, + .cfl_frac = ctx.cfl_frac, + + .t_end = ctx.t_end, + .num_frames = ctx.num_frames, + .dt_failure_tol = ctx.dt_failure_tol, + .num_failures_max = ctx.num_failures_max, + }; + + euler2d_run_double(argc, argv, &init); +} \ No newline at end of file diff --git a/regression/rt_amr_euler_shock_bubble.c b/regression/rt_amr_euler_shock_bubble_l1.c similarity index 100% rename from regression/rt_amr_euler_shock_bubble.c rename to regression/rt_amr_euler_shock_bubble_l1.c diff --git a/regression/rt_amr_euler_shock_bubble_l2.c b/regression/rt_amr_euler_shock_bubble_l2.c new file mode 100644 index 000000000..aedf0c7a0 --- /dev/null +++ b/regression/rt_amr_euler_shock_bubble_l2.c @@ -0,0 +1,213 @@ +#include + +struct amr_euler_shock_bubble_ctx +{ + // Physical constants (using normalized code units). + double gas_gamma; // Adiabatic index. + + double rho_pre; // Pre-shock fluid mass density. + double u_pre; // Pre-shock fluid velocity (x-direction). + double p_pre; // Pre-shock fluid pressure. + + double rho_post; // Post-shock fluid mass density. + double u_post; // Post-shock fluid velocity (x-direction). + double p_post; // Post-shock fluid pressure. + + double rho_bub; // Bubble fluid mass density. + double u_bub; // Bubble fluid velocity (x-direction). + double p_bub; // Bubble fluid pressure. + + // Simulation parameters. + int Nx; // Coarse cell count (x-direction). + int Ny; // Coarse cell count (y-direction). + int ref_factor1; // First refinement factor. + int ref_factor2; // Second refinement factor. + double Lx; // Coarse domain size (x-direction). + double Ly; // Coarse domain size (y-direction). + double intermediate_Lx; // Intermediate domain size (x-direction). + double intermediate_Ly; // Intermediate domain size (y-direction). + double fine_Lx; // Fine domain size (x-direction). + double fine_Ly; // Fine domain size (y-direction). + double cfl_frac; // CFL coefficient. + + double t_end; // Final simulation time. + int num_frames; // Number of output frames. + double dt_failure_tol; // Minimum allowable fraction of initial time-step. + int num_failures_max; // Maximum allowable number of consecutive small time-steps. + + double x_loc; // Shock location (x-direction). + double bub_loc; // Bubble location (x-direction). + double bub_rad; // Bubble radius. +}; + +struct amr_euler_shock_bubble_ctx +create_ctx(void) +{ + // Physical constants (using normalized code units). + double gas_gamma = 1.4; // Adiabatic index. + + double rho_pre = 1.0; // Pre-shock fluid mass density. + double u_pre = -6.0; // Pre-shock fluid velocity (x-direction). + double p_pre = 1.0; // Pre-shock fluid pressure. + + double rho_post = 5.799; // Post-shock fluid mass density. + double u_post = 5.75; // Post-shock fluid velocity (x-direction). + double p_post = 167.833; // Post-shock fluid pressure. + + double rho_bub = 0.138; // Bubble fluid mass density. + double u_bub = -6.0; // Bubble fluid velocity (x-direction). + double p_bub = 1.0; // Bubble fluid pressure. + + // Simulation parameters. + int Nx = 16; // Coarse cell count (x-direction). + int Ny = 16; // Coarse cell count (y-direction). + int ref_factor1 = 4; // First refinement factor. + int ref_factor2 = 4; // Second refinement factor. + double Lx = 1.0; // Coarse domain size (x-direction). + double Ly = 1.0; // Coarse domain size (y-direction). + double intermediate_Lx = 0.75; // Intermediate domain size (x-direction). + double intermediate_Ly = 0.75; // Intermediate domain size (y-direction). + double fine_Lx = 0.5; // Fine domain size (x-direction). + double fine_Ly = 0.5; // Fine domain size (y-direction). + double cfl_frac = 0.85; // CFL coefficient. + + double t_end = 0.075; // Final simulation time. + int num_frames = 1; // Number of output frames. + double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. + int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. + + double x_loc = 0.05; // Shock location (x-direction). + double bub_loc = 0.25; // Bubble location (x-direction). + double bub_rad = 0.15; // Bubble radius. + + struct amr_euler_shock_bubble_ctx ctx = { + .gas_gamma = gas_gamma, + .rho_pre = rho_pre, + .u_pre = u_pre, + .p_pre = p_pre, + .rho_post = rho_post, + .u_post = u_post, + .p_post = p_post, + .rho_bub = rho_bub, + .u_bub = u_bub, + .p_bub = p_bub, + .Nx = Nx, + .Ny = Ny, + .ref_factor1 = ref_factor1, + .ref_factor2 = ref_factor2, + .Lx = Lx, + .Ly = Ly, + .intermediate_Lx = intermediate_Lx, + .intermediate_Ly = intermediate_Ly, + .fine_Lx = fine_Lx, + .fine_Ly = fine_Ly, + .cfl_frac = cfl_frac, + .t_end = t_end, + .num_frames = num_frames, + .dt_failure_tol = dt_failure_tol, + .num_failures_max = num_failures_max, + .x_loc = x_loc, + .bub_loc = bub_loc, + .bub_rad = bub_rad, + }; + + return ctx; +} + +void +evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +{ + double x = xn[0], y = xn[1]; + struct amr_euler_shock_bubble_ctx new_ctx = create_ctx(); // Context for initialization functions. + struct amr_euler_shock_bubble_ctx *app = &new_ctx; + + double gas_gamma = app->gas_gamma; + + double rho_pre = app->rho_pre; + double u_pre = app->u_pre; + double p_pre = app->p_pre; + + double rho_post = app->rho_post; + double u_post = app->u_post; + double p_post = app->p_post; + + double rho_bub = app->rho_bub; + double u_bub = app->u_bub; + double p_bub = app->p_bub; + + double x_loc = app->x_loc; + double bub_loc = app->bub_loc; + double bub_rad = app->bub_rad; + + double rho = 0.0; + double u = 0.0; + double p = 0.0; + + double r = sqrt((x - bub_loc) * (x - bub_loc) + y * y); + + if (x < x_loc) { + rho = rho_post; // Fluid mass density (post-shock). + u = u_post; // Fluid velocity (post-shock). + p = p_post; // Fluid pressure (post-shock). + } + else { + rho = rho_pre; // Fluid mass density (pre-shock). + u = u_pre; // Fluid velocity (pre-shock). + p = p_pre; // Fluid pressure (pre-shock). + } + + if (r < bub_rad) { + rho = rho_bub; // Fluid mass density (bubble). + u = u_bub; // Fluid velocity (bubble). + p = p_bub; // Fluid pressure (bubble). + } + + // Set fluid mass density. + fout[0] = rho; + // Set fluid momentum density. + fout[1] = rho * u; fout[2] = 0.0; fout[3] = 0.0; + // Set fluid total energy density. + fout[4] = p / (gas_gamma - 1.0) + 0.5 * rho * u * u; +} + +int main(int argc, char **argv) +{ + struct amr_euler_shock_bubble_ctx ctx = create_ctx(); // Context for initialization functions. + + struct euler2d_double_init init = { + .base_Nx = ctx.Nx, + .base_Ny = ctx.Ny, + .ref_factor1 = ctx.ref_factor1, + .ref_factor2 = ctx.ref_factor2, + + .coarse_x1 = 0.0, + .coarse_y1 = -0.5 * ctx.Ly, + .coarse_x2 = ctx.Lx, + .coarse_y2 = 0.5 * ctx.Ly, + + .intermediate_x1 = (0.5 * ctx.Lx) - (0.5 * ctx.intermediate_Lx), + .intermediate_y1 = -0.5 * ctx.intermediate_Ly, + .intermediate_x2 = (0.5 * ctx.Lx) + (0.5 * ctx.intermediate_Lx), + .intermediate_y2 = 0.5 * ctx.intermediate_Ly, + + .refined_x1 = (0.5 * ctx.Lx) - (0.5 * ctx.fine_Lx), + .refined_y1 = -0.5 * ctx.fine_Ly, + .refined_x2 = (0.5 * ctx.Lx) + (0.5 * ctx.fine_Lx), + .refined_y2 = 0.5 * ctx.fine_Ly, + + .eval = evalEulerInit, + .gas_gamma = ctx.gas_gamma, + + .euler_output = "amr_euler_shock_bubble_l2", + + .low_order_flux = true, + .cfl_frac = ctx.cfl_frac, + + .t_end = ctx.t_end, + .num_frames = ctx.num_frames, + .dt_failure_tol = ctx.dt_failure_tol, + .num_failures_max = ctx.num_failures_max, + }; + + euler2d_run_double(argc, argv, &init); +} \ No newline at end of file From c3c89cee049b136ab758076691d0dacd1bfdbca9 Mon Sep 17 00:00:00 2001 From: JonathanGorard Date: Mon, 17 Jun 2024 16:31:39 +0200 Subject: [PATCH 02/32] Aesthetic cleanup of AMR core (inconsistent code formatting), and updating level-2 AMR regression comments. --- amr/amr_core_euler.c | 220 ++++++++-------- amr/amr_core_five_moment.c | 242 +++++++++--------- amr/amr_core_gr_euler.c | 108 ++++---- amr/amr_core_ten_moment.c | 236 ++++++++--------- .../rt_amr_euler_cart_axi_sodshock_l2.c | 2 +- regression/rt_amr_euler_riem_2d_l2.c | 2 +- 6 files changed, 406 insertions(+), 404 deletions(-) diff --git a/amr/amr_core_euler.c b/amr/amr_core_euler.c index 844754d1c..142fde2ea 100644 --- a/amr/amr_core_euler.c +++ b/amr/amr_core_euler.c @@ -271,43 +271,43 @@ euler1d_run_single(int argc, char **argv, struct euler1d_single_init* init) for (int i = 1; i < num_frames; i++) { if (coarse_t_curr < (i * io_trigger) && (coarse_t_curr + coarse_status.dt_actual) > (i * io_trigger)) { #ifdef AMR_DEBUG - char buf_coarse[64]; - char buf_fine[64]; + char buf_coarse[64]; + char buf_fine[64]; - snprintf(buf_coarse, 64, "%s_coarse_%d", euler_output, i); - snprintf(buf_fine, 64, "%s_fine_%d", euler_output, i); + snprintf(buf_coarse, 64, "%s_coarse_%d", euler_output, i); + snprintf(buf_fine, 64, "%s_fine_%d", euler_output, i); - euler_write_sol_patch(buf_coarse, num_patches, coarse_pdata); - euler_write_sol_patch(buf_fine, num_patches, fine_pdata); + euler_write_sol_patch(buf_coarse, num_patches, coarse_pdata); + euler_write_sol_patch(buf_fine, num_patches, fine_pdata); - char buf_fine_old[64]; - char buf_fine_new[64]; - char buf_coarse_old[64]; + char buf_fine_old[64]; + char buf_fine_new[64]; + char buf_coarse_old[64]; - snprintf(buf_fine_old, 64, "%s_fine_%d_p0.gkyl", euler_output, i); - snprintf(buf_fine_new, 64, "%s_%d_p0.gkyl", euler_output, i); - snprintf(buf_coarse_old, 64, "%s_coarse_%d_p0.gkyl", euler_output, i); + snprintf(buf_fine_old, 64, "%s_fine_%d_p0.gkyl", euler_output, i); + snprintf(buf_fine_new, 64, "%s_%d_p0.gkyl", euler_output, i); + snprintf(buf_coarse_old, 64, "%s_coarse_%d_p0.gkyl", euler_output, i); - rename(buf_fine_old, buf_fine_new); - remove(buf_coarse_old); + rename(buf_fine_old, buf_fine_new); + remove(buf_coarse_old); - for (int j = 1; j < 3; j++) { - char buf_old[64]; - char buf_new[64]; - char buf_del[64]; + for (int j = 1; j < 3; j++) { + char buf_old[64]; + char buf_new[64]; + char buf_del[64]; - snprintf(buf_old, 64, "%s_coarse_%d_p%d.gkyl", euler_output, i, j); - snprintf(buf_new, 64, "%s_%d_p%d.gkyl", euler_output, i, j); - snprintf(buf_del, 64, "%s_fine_%d_p%d.gkyl", euler_output, i, j); + snprintf(buf_old, 64, "%s_coarse_%d_p%d.gkyl", euler_output, i, j); + snprintf(buf_new, 64, "%s_%d_p%d.gkyl", euler_output, i, j); + snprintf(buf_del, 64, "%s_fine_%d_p%d.gkyl", euler_output, i, j); - rename(buf_old, buf_new); - remove(buf_del); - } + rename(buf_old, buf_new); + remove(buf_del); + } #else - char buf[64]; - snprintf(buf, 64, "%s_%d", euler_output, i); + char buf[64]; + snprintf(buf, 64, "%s_%d", euler_output, i); - euler_write_sol_patch(buf, num_patches, coarse_pdata); + euler_write_sol_patch(buf, num_patches, coarse_pdata); #endif } } @@ -333,7 +333,7 @@ euler1d_run_single(int argc, char **argv, struct euler1d_single_init* init) else { num_failures = 0; } - + coarse_step += 1; } @@ -728,43 +728,43 @@ euler2d_run_single(int argc, char **argv, struct euler2d_single_init* init) for (int i = 1; i < num_frames; i++) { if (coarse_t_curr < (i * io_trigger) && (coarse_t_curr + coarse_status.dt_actual) > (i * io_trigger)) { #ifdef AMR_DEBUG - char buf_coarse[64]; - char buf_fine[64]; + char buf_coarse[64]; + char buf_fine[64]; - snprintf(buf_coarse, 64, "%s_coarse_%d", euler_output, i); - snprintf(buf_fine, 64, "%s_fine_%d", euler_output, i); + snprintf(buf_coarse, 64, "%s_coarse_%d", euler_output, i); + snprintf(buf_fine, 64, "%s_fine_%d", euler_output, i); - euler_write_sol_block(buf_coarse, num_blocks, coarse_bdata); - euler_write_sol_block(buf_fine, num_blocks, fine_bdata); + euler_write_sol_block(buf_coarse, num_blocks, coarse_bdata); + euler_write_sol_block(buf_fine, num_blocks, fine_bdata); - char buf_fine_old[64]; - char buf_fine_new[64]; - char buf_coarse_old[64]; + char buf_fine_old[64]; + char buf_fine_new[64]; + char buf_coarse_old[64]; - snprintf(buf_fine_old, 64, "%s_fine_%d_b0.gkyl", euler_output, i); - snprintf(buf_fine_new, 64, "%s_%d_b0.gkyl", euler_output, i); - snprintf(buf_coarse_old, 64, "%s_coarse_%d_b0.gkyl", euler_output, i); + snprintf(buf_fine_old, 64, "%s_fine_%d_b0.gkyl", euler_output, i); + snprintf(buf_fine_new, 64, "%s_%d_b0.gkyl", euler_output, i); + snprintf(buf_coarse_old, 64, "%s_coarse_%d_b0.gkyl", euler_output, i); - rename(buf_fine_old, buf_fine_new); - remove(buf_coarse_old); + rename(buf_fine_old, buf_fine_new); + remove(buf_coarse_old); - for (int j = 1; j < 9; j++) { - char buf_old[64]; - char buf_new[64]; - char buf_del[64]; + for (int j = 1; j < 9; j++) { + char buf_old[64]; + char buf_new[64]; + char buf_del[64]; - snprintf(buf_old, 64, "%s_coarse_%d_b%d.gkyl", euler_output, i, j); - snprintf(buf_new, 64, "%s_%d_b%d.gkyl", euler_output, i, j); - snprintf(buf_del, 64, "%s_fine_%d_b%d.gkyl", euler_output, i, j); + snprintf(buf_old, 64, "%s_coarse_%d_b%d.gkyl", euler_output, i, j); + snprintf(buf_new, 64, "%s_%d_b%d.gkyl", euler_output, i, j); + snprintf(buf_del, 64, "%s_fine_%d_b%d.gkyl", euler_output, i, j); - rename(buf_old, buf_new); - remove(buf_del); - } + rename(buf_old, buf_new); + remove(buf_del); + } #else - char buf[64]; - snprintf(buf, 64, "%s_%d", euler_output, i); + char buf[64]; + snprintf(buf, 64, "%s_%d", euler_output, i); - euler_write_sol_block(buf, num_blocks, coarse_bdata); + euler_write_sol_block(buf, num_blocks, coarse_bdata); #endif } } @@ -1408,66 +1408,66 @@ euler2d_run_double(int argc, char **argv, struct euler2d_double_init* init) if (coarse_t_curr < (i * io_trigger) && (coarse_t_curr + coarse_status.dt_actual) > (i * io_trigger)) { // TODO: Make file output work correctly in the AMR_DEBUG case. #ifdef AMR_DEBUG - char buf_coarse[64]; - char buf_intermediate[64]; - char buf_fine[64]; - - snprintf(buf_coarse, 64, "%s_coarse_%d", euler_output, i); - snprintf(buf_intermediate, 64, "%s_intermediate_%d", euler_output, i); - snprintf(buf_fine, 64, "%s_fine_%d", euler_output, i); - - euler_write_sol_block(buf_coarse, num_blocks, coarse_bdata); - euler_write_sol_block(buf_intermediate, num_blocks, intermediate_bdata); - euler_write_sol_block(buf_fine, num_blocks, fine_bdata); - - char buf_fine_old[64]; - char buf_fine_new[64]; - char buf_intermediate_old[64]; - char buf_coarse_old[64]; - - snprintf(buf_fine_old, 64, "%s_fine_%d_b0.gkyl", euler_output, i); - snprintf(buf_fine_new, 64, "%s_%d_b0.gkyl", euler_output, i); - snprintf(buf_intermediate_old, 64, "%s_intermediate_%d_b0.gkyl", euler_output, i); - snprintf(buf_coarse_old, 64, "%s_coarse_%d_b0.gkyl", euler_output, i); - - rename(buf_fine_old, buf_fine_new); - remove(buf_intermediate_old); - remove(buf_coarse_old); - - for (int j = 1; j < 9; j++) { - char fine_bi[64]; - char intermediate_bi[64]; - char coarse_bi[64]; - char bi[64]; - snprintf(fine_bi, 64, "%s_fine_%d_b%d.gkyl", euler_output, i, j); - snprintf(intermediate_bi, 64, "%s_intermediate_%d_b%d.gkyl", euler_output, i, j); - snprintf(coarse_bi, 64, "%s_coarse_%d_b%d.gkyl", euler_output, i, j); - snprintf(bi, 64, "%s_%d_b%d.gkyl", euler_output, i, j); - rename(intermediate_bi, bi); - remove(fine_bi); - remove(coarse_bi); - } + char buf_coarse[64]; + char buf_intermediate[64]; + char buf_fine[64]; + + snprintf(buf_coarse, 64, "%s_coarse_%d", euler_output, i); + snprintf(buf_intermediate, 64, "%s_intermediate_%d", euler_output, i); + snprintf(buf_fine, 64, "%s_fine_%d", euler_output, i); + + euler_write_sol_block(buf_coarse, num_blocks, coarse_bdata); + euler_write_sol_block(buf_intermediate, num_blocks, intermediate_bdata); + euler_write_sol_block(buf_fine, num_blocks, fine_bdata); + + char buf_fine_old[64]; + char buf_fine_new[64]; + char buf_intermediate_old[64]; + char buf_coarse_old[64]; + + snprintf(buf_fine_old, 64, "%s_fine_%d_b0.gkyl", euler_output, i); + snprintf(buf_fine_new, 64, "%s_%d_b0.gkyl", euler_output, i); + snprintf(buf_intermediate_old, 64, "%s_intermediate_%d_b0.gkyl", euler_output, i); + snprintf(buf_coarse_old, 64, "%s_coarse_%d_b0.gkyl", euler_output, i); + + rename(buf_fine_old, buf_fine_new); + remove(buf_intermediate_old); + remove(buf_coarse_old); + + for (int j = 1; j < 9; j++) { + char fine_bi[64]; + char intermediate_bi[64]; + char coarse_bi[64]; + char bi[64]; + snprintf(fine_bi, 64, "%s_fine_%d_b%d.gkyl", euler_output, i, j); + snprintf(intermediate_bi, 64, "%s_intermediate_%d_b%d.gkyl", euler_output, i, j); + snprintf(coarse_bi, 64, "%s_coarse_%d_b%d.gkyl", euler_output, i, j); + snprintf(bi, 64, "%s_%d_b%d.gkyl", euler_output, i, j); + rename(intermediate_bi, bi); + remove(fine_bi); + remove(coarse_bi); + } - for (int j = 9; j < 25; j++) { - char buf_old[64]; - char buf_new[64]; - char buf_del1[64]; - char buf_del2[64]; + for (int j = 9; j < 25; j++) { + char buf_old[64]; + char buf_new[64]; + char buf_del1[64]; + char buf_del2[64]; - snprintf(buf_old, 64, "%s_coarse_%d_b%d.gkyl", euler_output, i, j); - snprintf(buf_new, 64, "%s_%d_b%d.gkyl", euler_output, i, j); - snprintf(buf_del1, 64, "%s_intermediate_%d_b%d.gkyl", euler_output, i, j); - snprintf(buf_del2, 64, "%s_fine_%d_b%d.gkyl", euler_output, i, j); + snprintf(buf_old, 64, "%s_coarse_%d_b%d.gkyl", euler_output, i, j); + snprintf(buf_new, 64, "%s_%d_b%d.gkyl", euler_output, i, j); + snprintf(buf_del1, 64, "%s_intermediate_%d_b%d.gkyl", euler_output, i, j); + snprintf(buf_del2, 64, "%s_fine_%d_b%d.gkyl", euler_output, i, j); - rename(buf_old, buf_new); - remove(buf_del1); - remove(buf_del2); - } + rename(buf_old, buf_new); + remove(buf_del1); + remove(buf_del2); + } #else - char buf[64]; - snprintf(buf, 64, "%s_%d", euler_output, i); + char buf[64]; + snprintf(buf, 64, "%s_%d", euler_output, i); - euler_write_sol_block(buf, num_blocks, coarse_bdata); + euler_write_sol_block(buf, num_blocks, coarse_bdata); #endif } } diff --git a/amr/amr_core_five_moment.c b/amr/amr_core_five_moment.c index e13f222f5..56d228cef 100644 --- a/amr/amr_core_five_moment.c +++ b/amr/amr_core_five_moment.c @@ -108,7 +108,8 @@ five_moment_1d_run_single(int argc, char **argv, struct five_moment_1d_single_in }; coarse_pdata[i].euler_elc = gkyl_wv_euler_inew(&inp); coarse_pdata[i].euler_ion = gkyl_wv_euler_inew(&inp); - } else { + } + else { coarse_pdata[i].euler_elc = gkyl_wv_euler_new(gas_gamma, app_args.use_gpu); coarse_pdata[i].euler_ion = gkyl_wv_euler_new(gas_gamma, app_args.use_gpu); } @@ -440,85 +441,85 @@ five_moment_1d_run_single(int argc, char **argv, struct five_moment_1d_single_in for (int i = 1; i < num_frames; i++) { if (coarse_t_curr < (i * io_trigger) && (coarse_t_curr + coarse_status.dt_actual) > (i * io_trigger)) { #ifdef AMR_DEBUG - char buf_coarse[64]; - char buf_fine[64]; + char buf_coarse[64]; + char buf_fine[64]; - snprintf(buf_coarse, 64, "%s_coarse_%d", five_moment_output, i); - snprintf(buf_fine, 64, "%s_fine_%d", five_moment_output, i); + snprintf(buf_coarse, 64, "%s_coarse_%d", five_moment_output, i); + snprintf(buf_fine, 64, "%s_fine_%d", five_moment_output, i); - five_moment_write_sol_patch(buf_coarse, num_patches, coarse_pdata); - five_moment_write_sol_patch(buf_fine, num_patches, fine_pdata); + five_moment_write_sol_patch(buf_coarse, num_patches, coarse_pdata); + five_moment_write_sol_patch(buf_fine, num_patches, fine_pdata); - char buf_fine_old_elc[64]; - char buf_fine_old_ion[64]; - char buf_fine_old_field[64]; + char buf_fine_old_elc[64]; + char buf_fine_old_ion[64]; + char buf_fine_old_field[64]; - char buf_fine_new_elc[64]; - char buf_fine_new_ion[64]; - char buf_fine_new_field[64]; + char buf_fine_new_elc[64]; + char buf_fine_new_ion[64]; + char buf_fine_new_field[64]; - char buf_coarse_old_elc[64]; - char buf_coarse_old_ion[64]; - char buf_coarse_old_field[64]; + char buf_coarse_old_elc[64]; + char buf_coarse_old_ion[64]; + char buf_coarse_old_field[64]; - snprintf(buf_fine_old_elc, 64, "%s_fine_%d_elc_p0.gkyl", five_moment_output, i); - snprintf(buf_fine_old_ion, 64, "%s_fine_%d_ion_p0.gkyl", five_moment_output, i); - snprintf(buf_fine_old_field, 64, "%s_fine_%d_field_p0.gkyl", five_moment_output, i); + snprintf(buf_fine_old_elc, 64, "%s_fine_%d_elc_p0.gkyl", five_moment_output, i); + snprintf(buf_fine_old_ion, 64, "%s_fine_%d_ion_p0.gkyl", five_moment_output, i); + snprintf(buf_fine_old_field, 64, "%s_fine_%d_field_p0.gkyl", five_moment_output, i); - snprintf(buf_fine_new_elc, 64, "%s_%d_elc_p0.gkyl", five_moment_output, i); - snprintf(buf_fine_new_ion, 64, "%s_%d_ion_p0.gkyl", five_moment_output, i); - snprintf(buf_fine_new_field, 64, "%s_%d_field_p0.gkyl", five_moment_output, i); + snprintf(buf_fine_new_elc, 64, "%s_%d_elc_p0.gkyl", five_moment_output, i); + snprintf(buf_fine_new_ion, 64, "%s_%d_ion_p0.gkyl", five_moment_output, i); + snprintf(buf_fine_new_field, 64, "%s_%d_field_p0.gkyl", five_moment_output, i); - snprintf(buf_coarse_old_elc, 64, "%s_coarse_%d_elc_p0.gkyl", five_moment_output, i); - snprintf(buf_coarse_old_ion, 64, "%s_coarse_%d_ion_p0.gkyl", five_moment_output, i); - snprintf(buf_coarse_old_field, 64, "%s_coarse_%d_field_p0.gkyl", five_moment_output, i); + snprintf(buf_coarse_old_elc, 64, "%s_coarse_%d_elc_p0.gkyl", five_moment_output, i); + snprintf(buf_coarse_old_ion, 64, "%s_coarse_%d_ion_p0.gkyl", five_moment_output, i); + snprintf(buf_coarse_old_field, 64, "%s_coarse_%d_field_p0.gkyl", five_moment_output, i); - rename(buf_fine_old_elc, buf_fine_new_elc); - rename(buf_fine_old_ion, buf_fine_new_ion); - rename(buf_fine_old_field, buf_fine_new_field); + rename(buf_fine_old_elc, buf_fine_new_elc); + rename(buf_fine_old_ion, buf_fine_new_ion); + rename(buf_fine_old_field, buf_fine_new_field); - remove(buf_coarse_old_elc); - remove(buf_coarse_old_ion); - remove(buf_coarse_old_field); + remove(buf_coarse_old_elc); + remove(buf_coarse_old_ion); + remove(buf_coarse_old_field); - for (int j = 1; j < 3; j++) { - char buf_old_elc[64]; - char buf_old_ion[64]; - char buf_old_field[64]; + for (int j = 1; j < 3; j++) { + char buf_old_elc[64]; + char buf_old_ion[64]; + char buf_old_field[64]; - char buf_new_elc[64]; - char buf_new_ion[64]; - char buf_new_field[64]; + char buf_new_elc[64]; + char buf_new_ion[64]; + char buf_new_field[64]; - char buf_del_elc[64]; - char buf_del_ion[64]; - char buf_del_field[64]; + char buf_del_elc[64]; + char buf_del_ion[64]; + char buf_del_field[64]; - snprintf(buf_old_elc, 64, "%s_coarse_%d_elc_p%d.gkyl", five_moment_output, i, j); - snprintf(buf_old_ion, 64, "%s_coarse_%d_ion_p%d.gkyl", five_moment_output, i, j); - snprintf(buf_old_field, 64, "%s_coarse_%d_field_p%d.gkyl", five_moment_output, i, j); + snprintf(buf_old_elc, 64, "%s_coarse_%d_elc_p%d.gkyl", five_moment_output, i, j); + snprintf(buf_old_ion, 64, "%s_coarse_%d_ion_p%d.gkyl", five_moment_output, i, j); + snprintf(buf_old_field, 64, "%s_coarse_%d_field_p%d.gkyl", five_moment_output, i, j); - snprintf(buf_new_elc, 64, "%s_%d_elc_p%d.gkyl", five_moment_output, i, j); - snprintf(buf_new_ion, 64, "%s_%d_ion_p%d.gkyl", five_moment_output, i, j); - snprintf(buf_new_field, 64, "%s_%d_field_p%d.gkyl", five_moment_output, i, j); + snprintf(buf_new_elc, 64, "%s_%d_elc_p%d.gkyl", five_moment_output, i, j); + snprintf(buf_new_ion, 64, "%s_%d_ion_p%d.gkyl", five_moment_output, i, j); + snprintf(buf_new_field, 64, "%s_%d_field_p%d.gkyl", five_moment_output, i, j); - snprintf(buf_del_elc, 64, "%s_fine_%d_elc_p%d.gkyl", five_moment_output, i, j); - snprintf(buf_del_ion, 64, "%s_fine_%d_ion_p%d.gkyl", five_moment_output, i, j); - snprintf(buf_del_field, 64, "%s_fine_%d_field_p%d.gkyl", five_moment_output, i, j); + snprintf(buf_del_elc, 64, "%s_fine_%d_elc_p%d.gkyl", five_moment_output, i, j); + snprintf(buf_del_ion, 64, "%s_fine_%d_ion_p%d.gkyl", five_moment_output, i, j); + snprintf(buf_del_field, 64, "%s_fine_%d_field_p%d.gkyl", five_moment_output, i, j); - rename(buf_old_elc, buf_new_elc); - rename(buf_old_ion, buf_new_ion); - rename(buf_old_field, buf_new_field); + rename(buf_old_elc, buf_new_elc); + rename(buf_old_ion, buf_new_ion); + rename(buf_old_field, buf_new_field); - remove(buf_del_elc); - remove(buf_del_ion); - remove(buf_del_field); - } + remove(buf_del_elc); + remove(buf_del_ion); + remove(buf_del_field); + } #else - char buf[64]; - snprintf(buf, 64, "%s_%d", five_moment_output, i); + char buf[64]; + snprintf(buf, 64, "%s_%d", five_moment_output, i); - five_moment_write_sol_patch(buf, num_patches, coarse_pdata); + five_moment_write_sol_patch(buf, num_patches, coarse_pdata); #endif } } @@ -875,7 +876,8 @@ five_moment_2d_run_single(int argc, char **argv, struct five_moment_2d_single_in }; coarse_bdata[i].euler_elc = gkyl_wv_euler_inew(&inp); coarse_bdata[i].euler_ion = gkyl_wv_euler_inew(&inp); - } else { + } + else { coarse_bdata[i].euler_elc = gkyl_wv_euler_new(gas_gamma, app_args.use_gpu); coarse_bdata[i].euler_ion = gkyl_wv_euler_new(gas_gamma, app_args.use_gpu); } @@ -1211,85 +1213,85 @@ five_moment_2d_run_single(int argc, char **argv, struct five_moment_2d_single_in for (int i = 1; i < num_frames; i++) { if (coarse_t_curr < (i * io_trigger) && (coarse_t_curr + coarse_status.dt_actual) > (i * io_trigger)) { #ifdef AMR_DEBUG - char buf_coarse[64]; - char buf_fine[64]; + char buf_coarse[64]; + char buf_fine[64]; - snprintf(buf_coarse, 64, "%s_coarse_%d", five_moment_output, i); - snprintf(buf_fine, 64, "%s_fine_%d", five_moment_output, i); + snprintf(buf_coarse, 64, "%s_coarse_%d", five_moment_output, i); + snprintf(buf_fine, 64, "%s_fine_%d", five_moment_output, i); - five_moment_write_sol_block(buf_coarse, num_blocks, coarse_bdata); - five_moment_write_sol_block(buf_fine, num_blocks, fine_bdata); + five_moment_write_sol_block(buf_coarse, num_blocks, coarse_bdata); + five_moment_write_sol_block(buf_fine, num_blocks, fine_bdata); - char buf_fine_old_elc[64]; - char buf_fine_old_ion[64]; - char buf_fine_old_field[64]; + char buf_fine_old_elc[64]; + char buf_fine_old_ion[64]; + char buf_fine_old_field[64]; - char buf_fine_new_elc[64]; - char buf_fine_new_ion[64]; - char buf_fine_new_field[64]; + char buf_fine_new_elc[64]; + char buf_fine_new_ion[64]; + char buf_fine_new_field[64]; - char buf_coarse_old_elc[64]; - char buf_coarse_old_ion[64]; - char buf_coarse_old_field[64]; + char buf_coarse_old_elc[64]; + char buf_coarse_old_ion[64]; + char buf_coarse_old_field[64]; - snprintf(buf_fine_old_elc, 64, "%s_fine_%d_elc_b0.gkyl", five_moment_output, i); - snprintf(buf_fine_old_ion, 64, "%s_fine_%d_ion_b0.gkyl", five_moment_output, i); - snprintf(buf_fine_old_field, 64, "%s_fine_%d_field_b0.gkyl", five_moment_output, i); + snprintf(buf_fine_old_elc, 64, "%s_fine_%d_elc_b0.gkyl", five_moment_output, i); + snprintf(buf_fine_old_ion, 64, "%s_fine_%d_ion_b0.gkyl", five_moment_output, i); + snprintf(buf_fine_old_field, 64, "%s_fine_%d_field_b0.gkyl", five_moment_output, i); - snprintf(buf_fine_new_elc, 64, "%s_%d_elc_b0.gkyl", five_moment_output, i); - snprintf(buf_fine_new_ion, 64, "%s_%d_ion_b0.gkyl", five_moment_output, i); - snprintf(buf_fine_new_field, 64, "%s_%d_field_b0.gkyl", five_moment_output, i); + snprintf(buf_fine_new_elc, 64, "%s_%d_elc_b0.gkyl", five_moment_output, i); + snprintf(buf_fine_new_ion, 64, "%s_%d_ion_b0.gkyl", five_moment_output, i); + snprintf(buf_fine_new_field, 64, "%s_%d_field_b0.gkyl", five_moment_output, i); - snprintf(buf_coarse_old_elc, 64, "%s_coarse_%d_elc_b0.gkyl", five_moment_output, i); - snprintf(buf_coarse_old_ion, 64, "%s_coarse_%d_ion_b0.gkyl", five_moment_output, i); - snprintf(buf_coarse_old_field, 64, "%s_coarse_%d_field_b0.gkyl", five_moment_output, i); + snprintf(buf_coarse_old_elc, 64, "%s_coarse_%d_elc_b0.gkyl", five_moment_output, i); + snprintf(buf_coarse_old_ion, 64, "%s_coarse_%d_ion_b0.gkyl", five_moment_output, i); + snprintf(buf_coarse_old_field, 64, "%s_coarse_%d_field_b0.gkyl", five_moment_output, i); - rename(buf_fine_old_elc, buf_fine_new_elc); - rename(buf_fine_old_ion, buf_fine_new_ion); - rename(buf_fine_old_field, buf_fine_new_field); + rename(buf_fine_old_elc, buf_fine_new_elc); + rename(buf_fine_old_ion, buf_fine_new_ion); + rename(buf_fine_old_field, buf_fine_new_field); - remove(buf_coarse_old_elc); - remove(buf_coarse_old_ion); - remove(buf_coarse_old_field); + remove(buf_coarse_old_elc); + remove(buf_coarse_old_ion); + remove(buf_coarse_old_field); - for (int j = 1; j < 9; j++) { - char buf_old_elc[64]; - char buf_old_ion[64]; - char buf_old_field[64]; + for (int j = 1; j < 9; j++) { + char buf_old_elc[64]; + char buf_old_ion[64]; + char buf_old_field[64]; - char buf_new_elc[64]; - char buf_new_ion[64]; - char buf_new_field[64]; + char buf_new_elc[64]; + char buf_new_ion[64]; + char buf_new_field[64]; - char buf_del_elc[64]; - char buf_del_ion[64]; - char buf_del_field[64]; + char buf_del_elc[64]; + char buf_del_ion[64]; + char buf_del_field[64]; - snprintf(buf_old_elc, 64, "%s_coarse_%d_elc_b%d.gkyl", five_moment_output, i, j); - snprintf(buf_old_ion, 64, "%s_coarse_%d_ion_b%d.gkyl", five_moment_output, i, j); - snprintf(buf_old_field, 64, "%s_coarse_%d_field_b%d.gkyl", five_moment_output, i, j); + snprintf(buf_old_elc, 64, "%s_coarse_%d_elc_b%d.gkyl", five_moment_output, i, j); + snprintf(buf_old_ion, 64, "%s_coarse_%d_ion_b%d.gkyl", five_moment_output, i, j); + snprintf(buf_old_field, 64, "%s_coarse_%d_field_b%d.gkyl", five_moment_output, i, j); - snprintf(buf_new_elc, 64, "%s_%d_elc_b%d.gkyl", five_moment_output, i, j); - snprintf(buf_new_ion, 64, "%s_%d_ion_b%d.gkyl", five_moment_output, i, j); - snprintf(buf_new_field, 64, "%s_%d_field_b%d.gkyl", five_moment_output, i, j); + snprintf(buf_new_elc, 64, "%s_%d_elc_b%d.gkyl", five_moment_output, i, j); + snprintf(buf_new_ion, 64, "%s_%d_ion_b%d.gkyl", five_moment_output, i, j); + snprintf(buf_new_field, 64, "%s_%d_field_b%d.gkyl", five_moment_output, i, j); - snprintf(buf_del_elc, 64, "%s_fine_%d_elc_b%d.gkyl", five_moment_output, i, j); - snprintf(buf_del_ion, 64, "%s_fine_%d_ion_b%d.gkyl", five_moment_output, i, j); - snprintf(buf_del_field, 64, "%s_fine_%d_field_b%d.gkyl", five_moment_output, i, j); + snprintf(buf_del_elc, 64, "%s_fine_%d_elc_b%d.gkyl", five_moment_output, i, j); + snprintf(buf_del_ion, 64, "%s_fine_%d_ion_b%d.gkyl", five_moment_output, i, j); + snprintf(buf_del_field, 64, "%s_fine_%d_field_b%d.gkyl", five_moment_output, i, j); - rename(buf_old_elc, buf_new_elc); - rename(buf_old_ion, buf_new_ion); - rename(buf_old_field, buf_new_field); + rename(buf_old_elc, buf_new_elc); + rename(buf_old_ion, buf_new_ion); + rename(buf_old_field, buf_new_field); - remove(buf_del_elc); - remove(buf_del_ion); - remove(buf_del_field); - } + remove(buf_del_elc); + remove(buf_del_ion); + remove(buf_del_field); + } #else - char buf[64]; - snprintf(buf, 64, "%s_%d", five_moment_output, i); + char buf[64]; + snprintf(buf, 64, "%s_%d", five_moment_output, i); - five_moment_write_sol_block(buf, num_blocks, coarse_bdata); + five_moment_write_sol_block(buf, num_blocks, coarse_bdata); #endif } } diff --git a/amr/amr_core_gr_euler.c b/amr/amr_core_gr_euler.c index 385b92161..fdddb96e1 100644 --- a/amr/amr_core_gr_euler.c +++ b/amr/amr_core_gr_euler.c @@ -252,43 +252,43 @@ gr_euler1d_run_single(int argc, char **argv, struct gr_euler1d_single_init* init for (int i = 1; i < num_frames; i++) { if (coarse_t_curr < (i * io_trigger) && (coarse_t_curr + coarse_status.dt_actual) > (i * io_trigger)) { #ifdef AMR_DEBUG - char buf_coarse[64]; - char buf_fine[64]; + char buf_coarse[64]; + char buf_fine[64]; - snprintf(buf_coarse, 64, "%s_coarse_%d", gr_euler_output, i); - snprintf(buf_fine, 64, "%s_fine_%d", gr_euler_output, i); + snprintf(buf_coarse, 64, "%s_coarse_%d", gr_euler_output, i); + snprintf(buf_fine, 64, "%s_fine_%d", gr_euler_output, i); - euler_write_sol_patch(buf_coarse, num_patches, coarse_pdata); - euler_write_sol_patch(buf_fine, num_patches, fine_pdata); + euler_write_sol_patch(buf_coarse, num_patches, coarse_pdata); + euler_write_sol_patch(buf_fine, num_patches, fine_pdata); - char buf_fine_old[64]; - char buf_fine_new[64]; - char buf_coarse_old[64]; + char buf_fine_old[64]; + char buf_fine_new[64]; + char buf_coarse_old[64]; - snprintf(buf_fine_old, 64, "%s_fine_%d_p0.gkyl", gr_euler_output, i); - snprintf(buf_fine_new, 64, "%s_%d_p0.gkyl", gr_euler_output, i); - snprintf(buf_coarse_old, 64, "%s_coarse_%d_p0.gkyl", gr_euler_output, i); + snprintf(buf_fine_old, 64, "%s_fine_%d_p0.gkyl", gr_euler_output, i); + snprintf(buf_fine_new, 64, "%s_%d_p0.gkyl", gr_euler_output, i); + snprintf(buf_coarse_old, 64, "%s_coarse_%d_p0.gkyl", gr_euler_output, i); - rename(buf_fine_old, buf_fine_new); - remove(buf_coarse_old); + rename(buf_fine_old, buf_fine_new); + remove(buf_coarse_old); - for (int j = 1; j < 3; j++) { - char buf_old[64]; - char buf_new[64]; - char buf_del[64]; + for (int j = 1; j < 3; j++) { + char buf_old[64]; + char buf_new[64]; + char buf_del[64]; - snprintf(buf_old, 64, "%s_coarse_%d_p%d.gkyl", gr_euler_output, i, j); - snprintf(buf_new, 64, "%s_%d_p%d.gkyl", gr_euler_output, i, j); - snprintf(buf_del, 64, "%s_fine_%d_p%d.gkyl", gr_euler_output, i, j); + snprintf(buf_old, 64, "%s_coarse_%d_p%d.gkyl", gr_euler_output, i, j); + snprintf(buf_new, 64, "%s_%d_p%d.gkyl", gr_euler_output, i, j); + snprintf(buf_del, 64, "%s_fine_%d_p%d.gkyl", gr_euler_output, i, j); - rename(buf_old, buf_new); - remove(buf_del); - } + rename(buf_old, buf_new); + remove(buf_del); + } #else - char buf[64]; - snprintf(buf, 64, "%s_%d", gr_euler_output, i); + char buf[64]; + snprintf(buf, 64, "%s_%d", gr_euler_output, i); - euler_write_sol_patch(buf, num_patches, coarse_pdata); + euler_write_sol_patch(buf, num_patches, coarse_pdata); #endif } } @@ -692,43 +692,43 @@ gr_euler2d_run_single(int argc, char **argv, struct gr_euler2d_single_init* init for (int i = 1; i < num_frames; i++) { if (coarse_t_curr < (i * io_trigger) && (coarse_t_curr + coarse_status.dt_actual) > (i * io_trigger)) { #ifdef AMR_DEBUG - char buf_coarse[64]; - char buf_fine[64]; + char buf_coarse[64]; + char buf_fine[64]; - snprintf(buf_coarse, 64, "%s_coarse_%d", gr_euler_output, i); - snprintf(buf_fine, 64, "%s_fine_%d", gr_euler_output, i); + snprintf(buf_coarse, 64, "%s_coarse_%d", gr_euler_output, i); + snprintf(buf_fine, 64, "%s_fine_%d", gr_euler_output, i); - euler_write_sol_block(buf_coarse, num_blocks, coarse_bdata); - euler_write_sol_block(buf_fine, num_blocks, fine_bdata); + euler_write_sol_block(buf_coarse, num_blocks, coarse_bdata); + euler_write_sol_block(buf_fine, num_blocks, fine_bdata); - char buf_fine_old[64]; - char buf_fine_new[64]; - char buf_coarse_old[64]; + char buf_fine_old[64]; + char buf_fine_new[64]; + char buf_coarse_old[64]; - snprintf(buf_fine_old, 64, "%s_fine_%d_b0.gkyl", gr_euler_output, i); - snprintf(buf_fine_new, 64, "%s_%d_b0.gkyl", gr_euler_output, i); - snprintf(buf_coarse_old, 64, "%s_coarse_%d_b0.gkyl", gr_euler_output, i); + snprintf(buf_fine_old, 64, "%s_fine_%d_b0.gkyl", gr_euler_output, i); + snprintf(buf_fine_new, 64, "%s_%d_b0.gkyl", gr_euler_output, i); + snprintf(buf_coarse_old, 64, "%s_coarse_%d_b0.gkyl", gr_euler_output, i); - rename(buf_fine_old, buf_fine_new); - remove(buf_coarse_old); + rename(buf_fine_old, buf_fine_new); + remove(buf_coarse_old); - for (int j = 1; j < 9; j++) { - char buf_old[64]; - char buf_new[64]; - char buf_del[64]; + for (int j = 1; j < 9; j++) { + char buf_old[64]; + char buf_new[64]; + char buf_del[64]; - snprintf(buf_old, 64, "%s_coarse_%d_b%d.gkyl", gr_euler_output, i, j); - snprintf(buf_new, 64, "%s_%d_b%d.gkyl", gr_euler_output, i, j); - snprintf(buf_del, 64, "%s_fine_%d_b%d.gkyl", gr_euler_output, i, j); + snprintf(buf_old, 64, "%s_coarse_%d_b%d.gkyl", gr_euler_output, i, j); + snprintf(buf_new, 64, "%s_%d_b%d.gkyl", gr_euler_output, i, j); + snprintf(buf_del, 64, "%s_fine_%d_b%d.gkyl", gr_euler_output, i, j); - rename(buf_old, buf_new); - remove(buf_del); - } + rename(buf_old, buf_new); + remove(buf_del); + } #else - char buf[64]; - snprintf(buf, 64, "%s_%d", gr_euler_output, i); + char buf[64]; + snprintf(buf, 64, "%s_%d", gr_euler_output, i); - euler_write_sol_block(buf, num_blocks, coarse_bdata); + euler_write_sol_block(buf, num_blocks, coarse_bdata); #endif } } diff --git a/amr/amr_core_ten_moment.c b/amr/amr_core_ten_moment.c index cc384fd34..92cc1603c 100644 --- a/amr/amr_core_ten_moment.c +++ b/amr/amr_core_ten_moment.c @@ -418,85 +418,85 @@ ten_moment_1d_run_single(int argc, char **argv, struct ten_moment_1d_single_init for (int i = 1; i < num_frames; i++) { if (coarse_t_curr < (i * io_trigger) && (coarse_t_curr + coarse_status.dt_actual) > (i * io_trigger)) { #ifdef AMR_DEBUG - char buf_coarse[64]; - char buf_fine[64]; + char buf_coarse[64]; + char buf_fine[64]; - snprintf(buf_coarse, 64, "%s_coarse_%d", ten_moment_output, i); - snprintf(buf_fine, 64, "%s_fine_%d", ten_moment_output, i); + snprintf(buf_coarse, 64, "%s_coarse_%d", ten_moment_output, i); + snprintf(buf_fine, 64, "%s_fine_%d", ten_moment_output, i); - five_moment_write_sol_patch(buf_coarse, num_patches, coarse_pdata); - five_moment_write_sol_patch(buf_fine, num_patches, fine_pdata); + five_moment_write_sol_patch(buf_coarse, num_patches, coarse_pdata); + five_moment_write_sol_patch(buf_fine, num_patches, fine_pdata); - char buf_fine_old_elc[64]; - char buf_fine_old_ion[64]; - char buf_fine_old_field[64]; + char buf_fine_old_elc[64]; + char buf_fine_old_ion[64]; + char buf_fine_old_field[64]; - char buf_fine_new_elc[64]; - char buf_fine_new_ion[64]; - char buf_fine_new_field[64]; + char buf_fine_new_elc[64]; + char buf_fine_new_ion[64]; + char buf_fine_new_field[64]; - char buf_coarse_old_elc[64]; - char buf_coarse_old_ion[64]; - char buf_coarse_old_field[64]; + char buf_coarse_old_elc[64]; + char buf_coarse_old_ion[64]; + char buf_coarse_old_field[64]; - snprintf(buf_fine_old_elc, 64, "%s_fine_%d_elc_p0.gkyl", ten_moment_output, i); - snprintf(buf_fine_old_ion, 64, "%s_fine_%d_ion_p0.gkyl", ten_moment_output, i); - snprintf(buf_fine_old_field, 64, "%s_fine_%d_field_p0.gkyl", ten_moment_output, i); + snprintf(buf_fine_old_elc, 64, "%s_fine_%d_elc_p0.gkyl", ten_moment_output, i); + snprintf(buf_fine_old_ion, 64, "%s_fine_%d_ion_p0.gkyl", ten_moment_output, i); + snprintf(buf_fine_old_field, 64, "%s_fine_%d_field_p0.gkyl", ten_moment_output, i); - snprintf(buf_fine_new_elc, 64, "%s_%d_elc_p0.gkyl", ten_moment_output, i); - snprintf(buf_fine_new_ion, 64, "%s_%d_ion_p0.gkyl", ten_moment_output, i); - snprintf(buf_fine_new_field, 64, "%s_%d_field_p0.gkyl", ten_moment_output, i); + snprintf(buf_fine_new_elc, 64, "%s_%d_elc_p0.gkyl", ten_moment_output, i); + snprintf(buf_fine_new_ion, 64, "%s_%d_ion_p0.gkyl", ten_moment_output, i); + snprintf(buf_fine_new_field, 64, "%s_%d_field_p0.gkyl", ten_moment_output, i); - snprintf(buf_coarse_old_elc, 64, "%s_coarse_%d_elc_p0.gkyl", ten_moment_output, i); - snprintf(buf_coarse_old_ion, 64, "%s_coarse_%d_ion_p0.gkyl", ten_moment_output, i); - snprintf(buf_coarse_old_field, 64, "%s_coarse_%d_field_p0.gkyl", ten_moment_output, i); + snprintf(buf_coarse_old_elc, 64, "%s_coarse_%d_elc_p0.gkyl", ten_moment_output, i); + snprintf(buf_coarse_old_ion, 64, "%s_coarse_%d_ion_p0.gkyl", ten_moment_output, i); + snprintf(buf_coarse_old_field, 64, "%s_coarse_%d_field_p0.gkyl", ten_moment_output, i); - rename(buf_fine_old_elc, buf_fine_new_elc); - rename(buf_fine_old_ion, buf_fine_new_ion); - rename(buf_fine_old_field, buf_fine_new_field); + rename(buf_fine_old_elc, buf_fine_new_elc); + rename(buf_fine_old_ion, buf_fine_new_ion); + rename(buf_fine_old_field, buf_fine_new_field); - remove(buf_coarse_old_elc); - remove(buf_coarse_old_ion); - remove(buf_coarse_old_field); + remove(buf_coarse_old_elc); + remove(buf_coarse_old_ion); + remove(buf_coarse_old_field); - for (int j = 1; j < 3; j++) { - char buf_old_elc[64]; - char buf_old_ion[64]; - char buf_old_field[64]; + for (int j = 1; j < 3; j++) { + char buf_old_elc[64]; + char buf_old_ion[64]; + char buf_old_field[64]; - char buf_new_elc[64]; - char buf_new_ion[64]; - char buf_new_field[64]; + char buf_new_elc[64]; + char buf_new_ion[64]; + char buf_new_field[64]; - char buf_del_elc[64]; - char buf_del_ion[64]; - char buf_del_field[64]; + char buf_del_elc[64]; + char buf_del_ion[64]; + char buf_del_field[64]; - snprintf(buf_old_elc, 64, "%s_coarse_%d_elc_p%d.gkyl", ten_moment_output, i, j); - snprintf(buf_old_ion, 64, "%s_coarse_%d_ion_p%d.gkyl", ten_moment_output, i, j); - snprintf(buf_old_field, 64, "%s_coarse_%d_field_p%d.gkyl", ten_moment_output, i, j); + snprintf(buf_old_elc, 64, "%s_coarse_%d_elc_p%d.gkyl", ten_moment_output, i, j); + snprintf(buf_old_ion, 64, "%s_coarse_%d_ion_p%d.gkyl", ten_moment_output, i, j); + snprintf(buf_old_field, 64, "%s_coarse_%d_field_p%d.gkyl", ten_moment_output, i, j); - snprintf(buf_new_elc, 64, "%s_%d_elc_p%d.gkyl", ten_moment_output, i, j); - snprintf(buf_new_ion, 64, "%s_%d_ion_p%d.gkyl", ten_moment_output, i, j); - snprintf(buf_new_field, 64, "%s_%d_field_p%d.gkyl", ten_moment_output, i, j); + snprintf(buf_new_elc, 64, "%s_%d_elc_p%d.gkyl", ten_moment_output, i, j); + snprintf(buf_new_ion, 64, "%s_%d_ion_p%d.gkyl", ten_moment_output, i, j); + snprintf(buf_new_field, 64, "%s_%d_field_p%d.gkyl", ten_moment_output, i, j); - snprintf(buf_del_elc, 64, "%s_fine_%d_elc_p%d.gkyl", ten_moment_output, i, j); - snprintf(buf_del_ion, 64, "%s_fine_%d_ion_p%d.gkyl", ten_moment_output, i, j); - snprintf(buf_del_field, 64, "%s_fine_%d_field_p%d.gkyl", ten_moment_output, i, j); + snprintf(buf_del_elc, 64, "%s_fine_%d_elc_p%d.gkyl", ten_moment_output, i, j); + snprintf(buf_del_ion, 64, "%s_fine_%d_ion_p%d.gkyl", ten_moment_output, i, j); + snprintf(buf_del_field, 64, "%s_fine_%d_field_p%d.gkyl", ten_moment_output, i, j); - rename(buf_old_elc, buf_new_elc); - rename(buf_old_ion, buf_new_ion); - rename(buf_old_field, buf_new_field); + rename(buf_old_elc, buf_new_elc); + rename(buf_old_ion, buf_new_ion); + rename(buf_old_field, buf_new_field); - remove(buf_del_elc); - remove(buf_del_ion); - remove(buf_del_field); - } + remove(buf_del_elc); + remove(buf_del_ion); + remove(buf_del_field); + } #else - char buf[64]; - snprintf(buf, 64, "%s_%d", ten_moment_output, i); + char buf[64]; + snprintf(buf, 64, "%s_%d", ten_moment_output, i); - five_moment_write_sol_patch(buf, num_patches, coarse_pdata); + five_moment_write_sol_patch(buf, num_patches, coarse_pdata); #endif } } @@ -1167,85 +1167,85 @@ ten_moment_2d_run_single(int argc, char **argv, struct ten_moment_2d_single_init for (int i = 1; i < num_frames; i++) { if (coarse_t_curr < (i * io_trigger) && (coarse_t_curr + coarse_status.dt_actual) > (i * io_trigger)) { #ifdef AMR_DEBUG - char buf_coarse[64]; - char buf_fine[64]; + char buf_coarse[64]; + char buf_fine[64]; - snprintf(buf_coarse, 64, "%s_coarse_%d", ten_moment_output, i); - snprintf(buf_fine, 64, "%s_fine_%d", ten_moment_output, i); + snprintf(buf_coarse, 64, "%s_coarse_%d", ten_moment_output, i); + snprintf(buf_fine, 64, "%s_fine_%d", ten_moment_output, i); - five_moment_write_sol_block(buf_coarse, num_blocks, coarse_bdata); - five_moment_write_sol_block(buf_fine, num_blocks, fine_bdata); + five_moment_write_sol_block(buf_coarse, num_blocks, coarse_bdata); + five_moment_write_sol_block(buf_fine, num_blocks, fine_bdata); - char buf_fine_old_elc[64]; - char buf_fine_old_ion[64]; - char buf_fine_old_field[64]; + char buf_fine_old_elc[64]; + char buf_fine_old_ion[64]; + char buf_fine_old_field[64]; - char buf_fine_new_elc[64]; - char buf_fine_new_ion[64]; - char buf_fine_new_field[64]; + char buf_fine_new_elc[64]; + char buf_fine_new_ion[64]; + char buf_fine_new_field[64]; - char buf_coarse_old_elc[64]; - char buf_coarse_old_ion[64]; - char buf_coarse_old_field[64]; + char buf_coarse_old_elc[64]; + char buf_coarse_old_ion[64]; + char buf_coarse_old_field[64]; - snprintf(buf_fine_old_elc, 64, "%s_fine_%d_elc_b0.gkyl", ten_moment_output, i); - snprintf(buf_fine_old_ion, 64, "%s_fine_%d_ion_b0.gkyl", ten_moment_output, i); - snprintf(buf_fine_old_field, 64, "%s_fine_%d_field_b0.gkyl", ten_moment_output, i); + snprintf(buf_fine_old_elc, 64, "%s_fine_%d_elc_b0.gkyl", ten_moment_output, i); + snprintf(buf_fine_old_ion, 64, "%s_fine_%d_ion_b0.gkyl", ten_moment_output, i); + snprintf(buf_fine_old_field, 64, "%s_fine_%d_field_b0.gkyl", ten_moment_output, i); - snprintf(buf_fine_new_elc, 64, "%s_%d_elc_b0.gkyl", ten_moment_output, i); - snprintf(buf_fine_new_ion, 64, "%s_%d_ion_b0.gkyl", ten_moment_output, i); - snprintf(buf_fine_new_field, 64, "%s_%d_field_b0.gkyl", ten_moment_output, i); + snprintf(buf_fine_new_elc, 64, "%s_%d_elc_b0.gkyl", ten_moment_output, i); + snprintf(buf_fine_new_ion, 64, "%s_%d_ion_b0.gkyl", ten_moment_output, i); + snprintf(buf_fine_new_field, 64, "%s_%d_field_b0.gkyl", ten_moment_output, i); - snprintf(buf_coarse_old_elc, 64, "%s_coarse_%d_elc_b0.gkyl", ten_moment_output, i); - snprintf(buf_coarse_old_ion, 64, "%s_coarse_%d_ion_b0.gkyl", ten_moment_output, i); - snprintf(buf_coarse_old_field, 64, "%s_coarse_%d_field_b0.gkyl", ten_moment_output, i); + snprintf(buf_coarse_old_elc, 64, "%s_coarse_%d_elc_b0.gkyl", ten_moment_output, i); + snprintf(buf_coarse_old_ion, 64, "%s_coarse_%d_ion_b0.gkyl", ten_moment_output, i); + snprintf(buf_coarse_old_field, 64, "%s_coarse_%d_field_b0.gkyl", ten_moment_output, i); - rename(buf_fine_old_elc, buf_fine_new_elc); - rename(buf_fine_old_ion, buf_fine_new_ion); - rename(buf_fine_old_field, buf_fine_new_field); + rename(buf_fine_old_elc, buf_fine_new_elc); + rename(buf_fine_old_ion, buf_fine_new_ion); + rename(buf_fine_old_field, buf_fine_new_field); - remove(buf_coarse_old_elc); - remove(buf_coarse_old_ion); - remove(buf_coarse_old_field); + remove(buf_coarse_old_elc); + remove(buf_coarse_old_ion); + remove(buf_coarse_old_field); - for (int j = 1; j < 9; j++) { - char buf_old_elc[64]; - char buf_old_ion[64]; - char buf_old_field[64]; + for (int j = 1; j < 9; j++) { + char buf_old_elc[64]; + char buf_old_ion[64]; + char buf_old_field[64]; - char buf_new_elc[64]; - char buf_new_ion[64]; - char buf_new_field[64]; + char buf_new_elc[64]; + char buf_new_ion[64]; + char buf_new_field[64]; - char buf_del_elc[64]; - char buf_del_ion[64]; - char buf_del_field[64]; + char buf_del_elc[64]; + char buf_del_ion[64]; + char buf_del_field[64]; - snprintf(buf_old_elc, 64, "%s_coarse_%d_elc_b%d.gkyl", ten_moment_output, i, j); - snprintf(buf_old_ion, 64, "%s_coarse_%d_ion_b%d.gkyl", ten_moment_output, i, j); - snprintf(buf_old_field, 64, "%s_coarse_%d_field_b%d.gkyl", ten_moment_output, i, j); + snprintf(buf_old_elc, 64, "%s_coarse_%d_elc_b%d.gkyl", ten_moment_output, i, j); + snprintf(buf_old_ion, 64, "%s_coarse_%d_ion_b%d.gkyl", ten_moment_output, i, j); + snprintf(buf_old_field, 64, "%s_coarse_%d_field_b%d.gkyl", ten_moment_output, i, j); - snprintf(buf_new_elc, 64, "%s_%d_elc_b%d.gkyl", ten_moment_output, i, j); - snprintf(buf_new_ion, 64, "%s_%d_ion_b%d.gkyl", ten_moment_output, i, j); - snprintf(buf_new_field, 64, "%s_%d_field_b%d.gkyl", ten_moment_output, i, j); + snprintf(buf_new_elc, 64, "%s_%d_elc_b%d.gkyl", ten_moment_output, i, j); + snprintf(buf_new_ion, 64, "%s_%d_ion_b%d.gkyl", ten_moment_output, i, j); + snprintf(buf_new_field, 64, "%s_%d_field_b%d.gkyl", ten_moment_output, i, j); - snprintf(buf_del_elc, 64, "%s_fine_%d_elc_b%d.gkyl", ten_moment_output, i, j); - snprintf(buf_del_ion, 64, "%s_fine_%d_ion_b%d.gkyl", ten_moment_output, i, j); - snprintf(buf_del_field, 64, "%s_fine_%d_field_b%d.gkyl", ten_moment_output, i, j); + snprintf(buf_del_elc, 64, "%s_fine_%d_elc_b%d.gkyl", ten_moment_output, i, j); + snprintf(buf_del_ion, 64, "%s_fine_%d_ion_b%d.gkyl", ten_moment_output, i, j); + snprintf(buf_del_field, 64, "%s_fine_%d_field_b%d.gkyl", ten_moment_output, i, j); - rename(buf_old_elc, buf_new_elc); - rename(buf_old_ion, buf_new_ion); - rename(buf_old_field, buf_new_field); + rename(buf_old_elc, buf_new_elc); + rename(buf_old_ion, buf_new_ion); + rename(buf_old_field, buf_new_field); - remove(buf_del_elc); - remove(buf_del_ion); - remove(buf_del_field); - } + remove(buf_del_elc); + remove(buf_del_ion); + remove(buf_del_field); + } #else - char buf[64]; - snprintf(buf, 64, "%s_%d", ten_moment_output, i); + char buf[64]; + snprintf(buf, 64, "%s_%d", ten_moment_output, i); - five_moment_write_sol_block(buf, num_blocks, coarse_bdata); + five_moment_write_sol_block(buf, num_blocks, coarse_bdata); #endif } } diff --git a/regression/rt_amr_euler_cart_axi_sodshock_l2.c b/regression/rt_amr_euler_cart_axi_sodshock_l2.c index 1bcb99fb8..227914a13 100644 --- a/regression/rt_amr_euler_cart_axi_sodshock_l2.c +++ b/regression/rt_amr_euler_cart_axi_sodshock_l2.c @@ -1,4 +1,4 @@ -// 2D Sod-type shock tube test in axial symmetry, in Cartesian coordinates, using static, block-structured mesh refinement with a single refinement block (4x refinement), for the 5-moment (Euler) equations. +// 2D Sod-type shock tube test in axial symmetry, in Cartesian coordinates, using static, block-structured mesh refinement with doubly-nested refinement blocks (4x4x refinement), for the 5-moment (Euler) equations. // Input parameters are an axisymmetric generalization of those in Section 2.6.2, with the contact discontinuity placed at r = 0.75, from the thesis: // A. Hakim (2006), "High Resolution Wave Propagation Schemes for Two-Fluid Plasma Simulations", // PhD Thesis, University of Washington. diff --git a/regression/rt_amr_euler_riem_2d_l2.c b/regression/rt_amr_euler_riem_2d_l2.c index 1bb004b76..92be0016e 100644 --- a/regression/rt_amr_euler_riem_2d_l2.c +++ b/regression/rt_amr_euler_riem_2d_l2.c @@ -1,4 +1,4 @@ -// 2D Riemann (quadrant) problem, using static, block-structured mesh refinement with a single refinement block (4x refinement), for the 5-moment (Euler) equations. +// 2D Riemann (quadrant) problem, using static, block-structured mesh refinement with doubly-nested refinement blocks (4x4x refinement), for the 5-moment (Euler) equations. // Input parameters match the initial conditions in Section 4.3, Case 3, with final time set to t = 0.8 rather than t = 0.3, from the article: // R. Liska and B. Wendroff (2003), "Comparison of Several Difference Schemes on 1D and 2D Test Problems for the Euler Equations", // SIAM Journal on Scientific Computing, Volume 25 (3): 995-1017. From cfc144531d398a752a732d10eae9996fa7d11443 Mon Sep 17 00:00:00 2001 From: JonathanGorard Date: Tue, 18 Jun 2024 17:08:12 +0200 Subject: [PATCH 03/32] Singly- and doubly- nested AMR infrastructure now "working" with coupled 5-moment equations (in the sense that simulations run, but the lack of a scale cutoff for the 5-moment equations means that meshes tend to refine unstably and without any obvious termination criterion). Perhaps 10-moments will be better - if they're not, then there may be something more deeply wrong with the AMR algorithm for coupled equations. --- amr/amr_block_coupled.c | 75 ++ amr/amr_core_five_moment.c | 1129 +++++++++++++++++ amr/gkyl_amr_block_coupled_priv.h | 8 + amr/gkyl_amr_block_priv.h | 8 +- amr/gkyl_amr_core.h | 68 +- .../{rt_amr_5m_gem.c => rt_amr_5m_gem_l1.c} | 0 regression/rt_amr_5m_gem_l2.c | 311 +++++ 7 files changed, 1594 insertions(+), 5 deletions(-) rename regression/{rt_amr_5m_gem.c => rt_amr_5m_gem_l1.c} (100%) create mode 100644 regression/rt_amr_5m_gem_l2.c diff --git a/amr/amr_block_coupled.c b/amr/amr_block_coupled.c index 191b6bf18..c6866c484 100644 --- a/amr/amr_block_coupled.c +++ b/amr/amr_block_coupled.c @@ -135,6 +135,81 @@ five_moment_block_bc_updaters_init(struct five_moment_block_data* bdata, const s bdata->bc_buffer_maxwell = gkyl_array_new(GKYL_DOUBLE, 8, buff_sz); } +void +five_moment_nested_block_bc_updaters_init(struct five_moment_block_data* bdata, const struct gkyl_block_connections* conn) +{ + int nghost[25]; + for (int i = 0; i < 25; i++) { + nghost[i] = 2; + } + + bool wall_x = bdata->wall_x; + bool wall_y = bdata->wall_y; + + bool transmissive_x = bdata->transmissive_x; + bool transmissive_y = bdata->transmissive_y; + + for (int d = 0; d < 2; d++) { + bdata->lower_bc_elc[d] = bdata->upper_bc_elc[d] = 0; + bdata->lower_bc_ion[d] = bdata->upper_bc_ion[d] = 0; + bdata->lower_bc_maxwell[d] = bdata->upper_bc_maxwell[d] = 0; + + if ((d == 0 && wall_x) || (d == 1 && wall_y)) { + if (conn->connections[d][0].edge == GKYL_PHYSICAL) { + bdata->lower_bc_elc[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler_elc, bdata->geom, d, GKYL_LOWER_EDGE, nghost, + five_moment_wall_bc, 0); + bdata->lower_bc_ion[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler_ion, bdata->geom, d, GKYL_LOWER_EDGE, nghost, + five_moment_wall_bc, 0); + bdata->lower_bc_maxwell[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->maxwell, bdata->geom, d, GKYL_LOWER_EDGE, nghost, + maxwell_wall_bc, 0); + } + + if (conn->connections[d][1].edge == GKYL_PHYSICAL) { + bdata->upper_bc_elc[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler_elc, bdata->geom, d, GKYL_UPPER_EDGE, nghost, + five_moment_wall_bc, 0); + bdata->upper_bc_ion[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler_ion, bdata->geom, d, GKYL_UPPER_EDGE, nghost, + five_moment_wall_bc, 0); + bdata->upper_bc_maxwell[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->maxwell, bdata->geom, d, GKYL_UPPER_EDGE, nghost, + maxwell_wall_bc, 0); + } + } + else if ((d == 0 && transmissive_x) || (d == 1 && transmissive_y)) { + if (conn->connections[d][0].edge == GKYL_PHYSICAL) { + bdata->lower_bc_elc[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler_elc, bdata->geom, d, GKYL_LOWER_EDGE, nghost, + five_moment_transmissive_bc, 0); + bdata->lower_bc_ion[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler_ion, bdata->geom, d, GKYL_LOWER_EDGE, nghost, + five_moment_transmissive_bc, 0); + bdata->lower_bc_maxwell[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->maxwell, bdata->geom, d, GKYL_LOWER_EDGE, nghost, + maxwell_transmissive_bc, 0); + } + + if (conn->connections[d][1].edge == GKYL_PHYSICAL) { + bdata->upper_bc_elc[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler_elc, bdata->geom, d, GKYL_UPPER_EDGE, nghost, + five_moment_transmissive_bc, 0); + bdata->upper_bc_ion[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler_ion, bdata->geom, d, GKYL_UPPER_EDGE, nghost, + five_moment_transmissive_bc, 0); + bdata->upper_bc_maxwell[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->maxwell, bdata->geom, d, GKYL_UPPER_EDGE, nghost, + maxwell_transmissive_bc, 0); + } + } + } + + skin_ghost_ranges_init_block(&bdata->skin_ghost, &bdata->ext_range, nghost); + long buff_sz = 0; + + for (int d = 0; d < 2; d++) { + long vol = bdata->skin_ghost.lower_skin[d].volume; + + if (buff_sz <= vol) { + buff_sz = vol; + } + } + + bdata->bc_buffer_elc = gkyl_array_new(GKYL_DOUBLE, 5, buff_sz); + bdata->bc_buffer_ion = gkyl_array_new(GKYL_DOUBLE, 5, buff_sz); + bdata->bc_buffer_maxwell = gkyl_array_new(GKYL_DOUBLE, 8, buff_sz); +} + void ten_moment_block_bc_updaters_init(struct five_moment_block_data* bdata, const struct gkyl_block_connections* conn) { diff --git a/amr/amr_core_five_moment.c b/amr/amr_core_five_moment.c index 56d228cef..3fa88e7f9 100644 --- a/amr/amr_core_five_moment.c +++ b/amr/amr_core_five_moment.c @@ -1492,4 +1492,1133 @@ five_moment_2d_run_single(int argc, char **argv, struct five_moment_2d_single_in #ifdef AMR_DEBUG gkyl_job_pool_release(fine_job_pool); #endif +} + +void +five_moment_2d_run_double(int argc, char **argv, struct five_moment_2d_double_init* init) +{ + struct gkyl_app_args app_args = parse_app_args(argc, argv); + + if (app_args.trace_mem) { + gkyl_cu_dev_mem_debug_set(true); + gkyl_mem_debug_set(true); + } + + int base_Nx = init->base_Nx; + int base_Ny = init->base_Ny; + int ref_factor1 = init->ref_factor1; + int ref_factor2 = init->ref_factor2; + + double coarse_x1 = init->coarse_x1; + double coarse_y1 = init->coarse_y1; + double coarse_x2 = init->coarse_x2; + double coarse_y2 = init->coarse_y2; + + double intermediate_x1 = init->intermediate_x1; + double intermediate_y1 = init->intermediate_y1; + double intermediate_x2 = init->intermediate_x2; + double intermediate_y2 = init->intermediate_y2; + + double refined_x1 = init->refined_x1; + double refined_y1 = init->refined_y1; + double refined_x2 = init->refined_x2; + double refined_y2 = init->refined_y2; + + evalf_t eval_elc = init->eval_elc; + evalf_t eval_ion = init->eval_ion; + evalf_t eval_field = init->eval_field; + + double gas_gamma = init->gas_gamma; + double k0_elc = init->k0_elc; + double k0_ion = init->k0_ion; + + double light_speed = init->light_speed; + double e_fact = init->e_fact; + double b_fact = init->b_fact; + + double epsilon0 = init->epsilon0; + double mass_elc = init->mass_elc; + double charge_elc = init->charge_elc; + double mass_ion = init->mass_ion; + double charge_ion = init->charge_ion; + + bool transmissive_x = init->transmissive_x; + bool transmissive_y = init->transmissive_y; + + bool wall_x = init->wall_x; + bool wall_y = init->wall_y; + + char five_moment_output[32]; + strcpy(five_moment_output, init->five_moment_output); + + bool low_order_flux = init->low_order_flux; + int num_frames = init->num_frames; + + double cfl_frac = init->cfl_frac; + double t_end = init->t_end; + double dt_failure_tol = init->dt_failure_tol; + int num_failures_max = init->num_failures_max; + + int ndim = 2; + int num_blocks = 25; + int Nx = base_Nx; + int Ny = base_Ny; + + struct five_moment_block_data coarse_bdata[num_blocks]; + struct gkyl_job_pool *coarse_job_pool = gkyl_thread_pool_new(app_args.num_threads); + +#ifdef AMR_DEBUG + gkyl_rect_grid_init(&coarse_bdata[0].grid, 2, (double []) { refined_x1, refined_y1 }, (double []) { refined_x2, refined_y2 }, + (int []) { Nx, Ny }); + + gkyl_rect_grid_init(&coarse_bdata[1].grid, 2, (double []) { intermediate_x1, refined_y2 }, (double []) { refined_x1, intermediate_y2 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[2].grid, 2, (double []) { refined_x1, refined_y2 }, (double []) { refined_x2, intermediate_y2 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[3].grid, 2, (double []) { refined_x2, refined_y2 }, (double []) { intermediate_x2, intermediate_y2 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[4].grid, 2, (double []) { intermediate_x1, refined_y1 }, (double []) { refined_x1, refined_y2 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[5].grid, 2, (double []) { refined_x2, refined_y1 }, (double []) { intermediate_x2, refined_y2 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[6].grid, 2, (double []) { intermediate_x1, intermediate_y1 }, (double []) { refined_x1, refined_y1 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[7].grid, 2, (double []) { refined_x1, intermediate_y1 }, (double []) { refined_x2, refined_y1 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[8].grid, 2, (double []) { refined_x2, intermediate_y1 }, (double []) { intermediate_x2, refined_y1 }, + (int []) { Nx, Ny }); +#else + gkyl_rect_grid_init(&coarse_bdata[0].grid, 2, (double []) { refined_x1, refined_y1 }, (double []) { refined_x2, refined_y2 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + + gkyl_rect_grid_init(&coarse_bdata[1].grid, 2, (double []) { intermediate_x1, refined_y2 }, (double []) { refined_x1, intermediate_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&coarse_bdata[2].grid, 2, (double []) { refined_x1, refined_y2 }, (double []) { refined_x2, intermediate_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&coarse_bdata[3].grid, 2, (double []) { refined_x2, refined_y2 }, (double []) { intermediate_x2, intermediate_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&coarse_bdata[4].grid, 2, (double []) { intermediate_x1, refined_y1 }, (double []) { refined_x1, refined_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&coarse_bdata[5].grid, 2, (double []) { refined_x2, refined_y1 }, (double []) { intermediate_x2, refined_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&coarse_bdata[6].grid, 2, (double []) { intermediate_x1, intermediate_y1 }, (double []) { refined_x1, refined_y1 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&coarse_bdata[7].grid, 2, (double []) { refined_x1, intermediate_y1 }, (double []) { refined_x2, refined_y1 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&coarse_bdata[8].grid, 2, (double []) { refined_x2, intermediate_y1 }, (double []) { intermediate_x2, refined_y1 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); +#endif + + gkyl_rect_grid_init(&coarse_bdata[9].grid, 2, (double []) { coarse_x1, intermediate_y2 }, (double []) { intermediate_x1, coarse_y2 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[10].grid, 2, (double []) { intermediate_x1, intermediate_y2 }, (double []) { refined_x1, coarse_y2 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[11].grid, 2, (double []) { refined_x1, intermediate_y2 }, (double []) { refined_x2, coarse_y2 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[12].grid, 2, (double []) { refined_x2, intermediate_y2 }, (double []) { intermediate_x2, coarse_y2 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[13].grid, 2, (double []) { intermediate_x2, intermediate_y2 }, (double []) { coarse_x2, coarse_y2 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[14].grid, 2, (double []) { coarse_x1, refined_y2 }, (double []) { intermediate_x1, intermediate_y2 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[15].grid, 2, (double []) { intermediate_x2, refined_y2 }, (double []) { coarse_x2, intermediate_y2 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[16].grid, 2, (double []) { coarse_x1, refined_y1 }, (double []) { intermediate_x1, refined_y2 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[17].grid, 2, (double []) { intermediate_x2, refined_y1 }, (double []) { coarse_x2, refined_y2 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[18].grid, 2, (double []) { coarse_x1, intermediate_y1 }, (double []) { intermediate_x1, refined_y1 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[19].grid, 2, (double []) { intermediate_x2, intermediate_y1 }, (double []) { coarse_x2, refined_y1 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[20].grid, 2, (double []) { coarse_x1, coarse_y1 }, (double []) { intermediate_x1, intermediate_y1 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[21].grid, 2, (double []) { intermediate_x1, coarse_y1 }, (double []) { refined_x1, intermediate_y1 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[22].grid, 2, (double []) { refined_x1, coarse_y1 }, (double []) { refined_x2, intermediate_y1 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[23].grid, 2, (double []) { refined_x2, coarse_y1 }, (double []) { intermediate_x2, intermediate_y1 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[24].grid, 2, (double []) { intermediate_x2, coarse_y1 }, (double []) { coarse_x2, intermediate_y1 }, + (int []) { Nx, Ny }); + +#ifdef AMR_DEBUG + struct five_moment_block_data intermediate_bdata[num_blocks]; + struct gkyl_job_pool *intermediate_job_pool = gkyl_thread_pool_new(app_args.num_threads); + + gkyl_rect_grid_init(&intermediate_bdata[0].grid, 2, (double []) { refined_x1, refined_y1 }, (double []) { refined_x2, refined_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + + gkyl_rect_grid_init(&intermediate_bdata[1].grid, 2, (double []) { coarse_x1, refined_y2 }, (double []) { refined_x1, coarse_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[2].grid, 2, (double []) { refined_x1, refined_y2 }, (double []) { refined_x2, coarse_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[3].grid, 2, (double []) { refined_x2, refined_y2 }, (double []) { coarse_x2, coarse_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[4].grid, 2, (double []) { coarse_x1, refined_y1 }, (double []) { refined_x1, refined_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[5].grid, 2, (double []) { refined_x2, refined_y1 }, (double []) { coarse_x2, refined_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[6].grid, 2, (double []) { coarse_x1, coarse_y1 }, (double []) { refined_x1, refined_y1 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[7].grid, 2, (double []) { refined_x1, coarse_y1 }, (double []) { refined_x2, refined_y1 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[8].grid, 2, (double []) { refined_x2, coarse_y1 }, (double []) { coarse_x2, refined_y1 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + + gkyl_rect_grid_init(&intermediate_bdata[9].grid, 2, (double []) { coarse_x1, intermediate_y2 }, (double []) { intermediate_x1, coarse_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[10].grid, 2, (double []) { intermediate_x1, intermediate_y2 }, (double []) { refined_x1, coarse_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[11].grid, 2, (double []) { refined_x1, intermediate_y2 }, (double []) { refined_x2, coarse_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[12].grid, 2, (double []) { refined_x2, intermediate_y2 }, (double []) { intermediate_x2, coarse_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[13].grid, 2, (double []) { intermediate_x2, intermediate_y2 }, (double []) { coarse_x2, coarse_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[14].grid, 2, (double []) { coarse_x1, refined_y2 }, (double []) { intermediate_x1, intermediate_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[15].grid, 2, (double []) { intermediate_x2, refined_y2 }, (double []) { coarse_x2, intermediate_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[16].grid, 2, (double []) { coarse_x1, refined_y1 }, (double []) { intermediate_x1, refined_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[17].grid, 2, (double []) { intermediate_x2, refined_y1 }, (double []) { coarse_x2, refined_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[18].grid, 2, (double []) { coarse_x1, intermediate_y1 }, (double []) { intermediate_x1, refined_y1 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[19].grid, 2, (double []) { intermediate_x2, intermediate_y1 }, (double []) { coarse_x2, refined_y1 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[20].grid, 2, (double []) { coarse_x1, coarse_y1 }, (double []) { intermediate_x1, intermediate_y1 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[21].grid, 2, (double []) { intermediate_x1, coarse_y1 }, (double []) { refined_x1, intermediate_y1 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[22].grid, 2, (double []) { refined_x1, coarse_y1 }, (double []) { refined_x2, intermediate_y1 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[23].grid, 2, (double []) { refined_x2, coarse_y1 }, (double []) { intermediate_x2, intermediate_y1 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[24].grid, 2, (double []) { intermediate_x2, coarse_y1 }, (double []) { coarse_x2, intermediate_y1 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + + struct five_moment_block_data fine_bdata[num_blocks]; + struct gkyl_job_pool *fine_job_pool = gkyl_thread_pool_new(app_args.num_threads); + + gkyl_rect_grid_init(&fine_bdata[0].grid, 2, (double []) { refined_x1, refined_y1 }, (double []) { refined_x2, refined_y2 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + + gkyl_rect_grid_init(&fine_bdata[1].grid, 2, (double []) { coarse_x1, refined_y2 }, (double []) { refined_x1, coarse_y2 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[2].grid, 2, (double []) { refined_x1, refined_y2 }, (double []) { refined_x2, coarse_y2 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[3].grid, 2, (double []) { refined_x2, refined_y2 }, (double []) { coarse_x2, coarse_y2 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[4].grid, 2, (double []) { coarse_x1, refined_y1 }, (double []) { refined_x1, refined_y2 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[5].grid, 2, (double []) { refined_x2, refined_y1 }, (double []) { coarse_x2, refined_y2 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[6].grid, 2, (double []) { coarse_x1, coarse_y1 }, (double []) { refined_x1, refined_y1 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[7].grid, 2, (double []) { refined_x1, coarse_y1 }, (double []) { refined_x2, refined_y1 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[8].grid, 2, (double []) { refined_x2, coarse_y1 }, (double []) { coarse_x2, refined_y1 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + + gkyl_rect_grid_init(&fine_bdata[9].grid, 2, (double []) { coarse_x1, intermediate_y2 }, (double []) { intermediate_x1, coarse_y2 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[10].grid, 2, (double []) { intermediate_x1, intermediate_y2 }, (double []) { refined_x1, coarse_y2 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[11].grid, 2, (double []) { refined_x1, intermediate_y2 }, (double []) { refined_x2, coarse_y2 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[12].grid, 2, (double []) { refined_x2, intermediate_y2 }, (double []) { intermediate_x2, coarse_y2 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[13].grid, 2, (double []) { intermediate_x2, intermediate_y2 }, (double []) { coarse_x2, coarse_y2 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[14].grid, 2, (double []) { coarse_x1, refined_y2 }, (double []) { intermediate_x1, intermediate_y2 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[15].grid, 2, (double []) { intermediate_x2, refined_y2 }, (double []) { coarse_x2, intermediate_y2 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[16].grid, 2, (double []) { coarse_x1, refined_y1 }, (double []) { intermediate_x1, refined_y2 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[17].grid, 2, (double []) { intermediate_x2, refined_y1 }, (double []) { coarse_x2, refined_y2 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[18].grid, 2, (double []) { coarse_x1, intermediate_y1 }, (double []) { intermediate_x1, refined_y1 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[19].grid, 2, (double []) { intermediate_x2, intermediate_y1 }, (double []) { coarse_x2, refined_y1 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[20].grid, 2, (double []) { coarse_x1, coarse_y1 }, (double []) { intermediate_x1, intermediate_y1 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[21].grid, 2, (double []) { intermediate_x1, coarse_y1 }, (double []) { refined_x1, intermediate_y1 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[22].grid, 2, (double []) { refined_x1, coarse_y1 }, (double []) { refined_x2, intermediate_y1 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[23].grid, 2, (double []) { refined_x2, coarse_y1 }, (double []) { intermediate_x2, intermediate_y1 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[24].grid, 2, (double []) { intermediate_x2, coarse_y1 }, (double []) { coarse_x2, intermediate_y1 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); +#endif + + for (int i = 0; i < num_blocks; i++) { + coarse_bdata[i].fv_proj_elc = gkyl_fv_proj_new(&coarse_bdata[i].grid, 2, 5, eval_elc, 0); + coarse_bdata[i].fv_proj_ion = gkyl_fv_proj_new(&coarse_bdata[i].grid, 2, 5, eval_ion, 0); + coarse_bdata[i].fv_proj_maxwell = gkyl_fv_proj_new(&coarse_bdata[i].grid, 2, 8, eval_field, 0); + +#ifdef AMR_DEBUG + intermediate_bdata[i].fv_proj_elc = gkyl_fv_proj_new(&intermediate_bdata[i].grid, 2, 5, eval_elc, 0); + intermediate_bdata[i].fv_proj_ion = gkyl_fv_proj_new(&intermediate_bdata[i].grid, 2, 5, eval_ion, 0); + intermediate_bdata[i].fv_proj_maxwell = gkyl_fv_proj_new(&intermediate_bdata[i].grid, 2, 8, eval_field, 0); + + fine_bdata[i].fv_proj_elc = gkyl_fv_proj_new(&fine_bdata[i].grid, 2, 5, eval_elc, 0); + fine_bdata[i].fv_proj_ion = gkyl_fv_proj_new(&fine_bdata[i].grid, 2, 5, eval_ion, 0); + fine_bdata[i].fv_proj_maxwell = gkyl_fv_proj_new(&fine_bdata[i].grid, 2, 8, eval_field, 0); +#endif + } + + for (int i = 0; i < num_blocks; i++) { + gkyl_create_grid_ranges(&coarse_bdata[i].grid, (int []) { 2, 2 }, &coarse_bdata[i].ext_range, &coarse_bdata[i].range); + coarse_bdata[i].geom = gkyl_wave_geom_new(&coarse_bdata[i].grid, &coarse_bdata[i].ext_range, 0, 0, false); + + coarse_bdata[i].transmissive_x = transmissive_x; + coarse_bdata[i].transmissive_y = transmissive_y; + + coarse_bdata[i].wall_x = wall_x; + coarse_bdata[i].wall_y = wall_y; + +#ifdef AMR_DEBUG + gkyl_create_grid_ranges(&intermediate_bdata[i].grid, (int []) { 2, 2 }, &intermediate_bdata[i].ext_range, &intermediate_bdata[i].range); + intermediate_bdata[i].geom = gkyl_wave_geom_new(&intermediate_bdata[i].grid, &intermediate_bdata[i].ext_range, 0, 0, false); + + intermediate_bdata[i].transmissive_x = transmissive_x; + intermediate_bdata[i].transmissive_y = transmissive_y; + + intermediate_bdata[i].wall_x = wall_x; + intermediate_bdata[i].wall_y = wall_y; + + gkyl_create_grid_ranges(&fine_bdata[i].grid, (int []) { 2, 2 }, &fine_bdata[i].ext_range, &fine_bdata[i].range); + fine_bdata[i].geom = gkyl_wave_geom_new(&fine_bdata[i].grid, &fine_bdata[i].ext_range, 0, 0, false); + + fine_bdata[i].transmissive_x = transmissive_x; + fine_bdata[i].transmissive_y = transmissive_y; + + fine_bdata[i].wall_x = wall_x; + fine_bdata[i].wall_y = wall_y; +#endif + } + + for (int i = 0; i < num_blocks; i++) { + if (low_order_flux) { + struct gkyl_wv_euler_inp inp = { + .gas_gamma = gas_gamma, + .rp_type = WV_EULER_RP_HLL, + .use_gpu = app_args.use_gpu, + }; + coarse_bdata[i].euler_elc = gkyl_wv_euler_inew(&inp); + coarse_bdata[i].euler_ion = gkyl_wv_euler_inew(&inp); + } + else { + coarse_bdata[i].euler_elc = gkyl_wv_euler_new(gas_gamma, app_args.use_gpu); + coarse_bdata[i].euler_ion = gkyl_wv_euler_new(gas_gamma, app_args.use_gpu); + } + coarse_bdata[i].maxwell = gkyl_wv_maxwell_new(light_speed, e_fact, b_fact); + + for (int d = 0; d < ndim; d++) { + coarse_bdata[i].slvr_elc[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { + .grid = &coarse_bdata[i].grid, + .equation = coarse_bdata[i].euler_elc, + .limiter = GKYL_MONOTONIZED_CENTERED, + .num_up_dirs = 1, + .update_dirs = { d }, + .cfl = cfl_frac, + .geom = coarse_bdata[i].geom, + } + ); + coarse_bdata[i].slvr_ion[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { + .grid = &coarse_bdata[i].grid, + .equation = coarse_bdata[i].euler_ion, + .limiter = GKYL_MONOTONIZED_CENTERED, + .num_up_dirs = 1, + .update_dirs = { d }, + .cfl = cfl_frac, + .geom = coarse_bdata[i].geom, + } + ); + coarse_bdata[i].slvr_maxwell[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { + .grid = &coarse_bdata[i].grid, + .equation = coarse_bdata[i].maxwell, + .limiter = GKYL_MONOTONIZED_CENTERED, + .num_up_dirs = 1, + .update_dirs = { d }, + .cfl = cfl_frac, + .geom = coarse_bdata[i].geom, + } + ); + } + + struct gkyl_moment_em_coupling_inp coarse_src_inp = { + .grid = &coarse_bdata[i].grid, + .nfluids = 2, + .epsilon0 = epsilon0, + }; + + coarse_src_inp.param[0] = (struct gkyl_moment_em_coupling_data) { + .type = coarse_bdata[i].euler_elc->type, + .charge = charge_elc, + .mass = mass_elc, + .k0 = k0_elc, + }; + coarse_src_inp.param[1] = (struct gkyl_moment_em_coupling_data) { + .type = coarse_bdata[i].euler_ion->type, + .charge = charge_ion, + .mass = mass_ion, + .k0 = k0_ion, + }; + + coarse_bdata[i].src_slvr = gkyl_moment_em_coupling_new(coarse_src_inp); + +#ifdef AMR_DEBUG + if (low_order_flux) { + struct gkyl_wv_euler_inp inp = { + .gas_gamma = gas_gamma, + .rp_type = WV_EULER_RP_HLL, + .use_gpu = app_args.use_gpu, + }; + intermediate_bdata[i].euler_elc = gkyl_wv_euler_inew(&inp); + intermediate_bdata[i].euler_ion = gkyl_wv_euler_inew(&inp); + + fine_bdata[i].euler_elc = gkyl_wv_euler_inew(&inp); + fine_bdata[i].euler_ion = gkyl_wv_euler_inew(&inp); + } + else { + intermediate_bdata[i].euler_elc = gkyl_wv_euler_new(gas_gamma, app_args.use_gpu); + intermediate_bdata[i].euler_ion = gkyl_wv_euler_new(gas_gamma, app_args.use_gpu); + + fine_bdata[i].euler_elc = gkyl_wv_euler_new(gas_gamma, app_args.use_gpu); + fine_bdata[i].euler_ion = gkyl_wv_euler_new(gas_gamma, app_args.use_gpu); + } + intermediate_bdata[i].maxwell = gkyl_wv_maxwell_new(light_speed, e_fact, b_fact); + fine_bdata[i].maxwell = gkyl_wv_maxwell_new(light_speed, e_fact, b_fact); + + for (int d = 0; d < ndim; d++) { + fine_bdata[i].slvr_elc[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { + .grid = &fine_bdata[i].grid, + .equation = fine_bdata[i].euler_elc, + .limiter = GKYL_MONOTONIZED_CENTERED, + .num_up_dirs = 1, + .update_dirs = { d }, + .cfl = cfl_frac, + .geom = fine_bdata[i].geom, + } + ); + fine_bdata[i].slvr_ion[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { + .grid = &fine_bdata[i].grid, + .equation = fine_bdata[i].euler_ion, + .limiter = GKYL_MONOTONIZED_CENTERED, + .num_up_dirs = 1, + .update_dirs = { d }, + .cfl = cfl_frac, + .geom = fine_bdata[i].geom, + } + ); + fine_bdata[i].slvr_maxwell[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { + .grid = &fine_bdata[i].grid, + .equation = fine_bdata[i].maxwell, + .limiter = GKYL_MONOTONIZED_CENTERED, + .num_up_dirs = 1, + .update_dirs = { d }, + .cfl = cfl_frac, + .geom = fine_bdata[i].geom, + } + ); + } + + struct gkyl_moment_em_coupling_inp fine_src_inp = { + .grid = &fine_bdata[i].grid, + .nfluids = 2, + .epsilon0 = epsilon0, + }; + + fine_src_inp.param[0] = (struct gkyl_moment_em_coupling_data) { + .type = fine_bdata[i].euler_elc->type, + .charge = charge_elc, + .mass = mass_elc, + .k0 = k0_elc, + }; + fine_src_inp.param[1] = (struct gkyl_moment_em_coupling_data) { + .type = fine_bdata[i].euler_ion->type, + .charge = charge_ion, + .mass = mass_ion, + .k0 = k0_ion, + }; + + fine_bdata[i].src_slvr = gkyl_moment_em_coupling_new(fine_src_inp); + + for (int d = 0; d < ndim; d++) { + intermediate_bdata[i].slvr_elc[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { + .grid = &intermediate_bdata[i].grid, + .equation = intermediate_bdata[i].euler_elc, + .limiter = GKYL_MONOTONIZED_CENTERED, + .num_up_dirs = 1, + .update_dirs = { d }, + .cfl = cfl_frac, + .geom = intermediate_bdata[i].geom, + } + ); + intermediate_bdata[i].slvr_ion[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { + .grid = &intermediate_bdata[i].grid, + .equation = intermediate_bdata[i].euler_ion, + .limiter = GKYL_MONOTONIZED_CENTERED, + .num_up_dirs = 1, + .update_dirs = { d }, + .cfl = cfl_frac, + .geom = intermediate_bdata[i].geom, + } + ); + intermediate_bdata[i].slvr_maxwell[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { + .grid = &intermediate_bdata[i].grid, + .equation = intermediate_bdata[i].maxwell, + .limiter = GKYL_MONOTONIZED_CENTERED, + .num_up_dirs = 1, + .update_dirs = { d }, + .cfl = cfl_frac, + .geom = intermediate_bdata[i].geom, + } + ); + } + + struct gkyl_moment_em_coupling_inp intermediate_src_inp = { + .grid = &intermediate_bdata[i].grid, + .nfluids = 2, + .epsilon0 = epsilon0, + }; + + intermediate_src_inp.param[0] = (struct gkyl_moment_em_coupling_data) { + .type = intermediate_bdata[i].euler_elc->type, + .charge = charge_elc, + .mass = mass_elc, + .k0 = k0_elc, + }; + intermediate_src_inp.param[1] = (struct gkyl_moment_em_coupling_data) { + .type = intermediate_bdata[i].euler_ion->type, + .charge = charge_ion, + .mass = mass_ion, + .k0 = k0_ion, + }; + + intermediate_bdata[i].src_slvr = gkyl_moment_em_coupling_new(intermediate_src_inp); +#endif + } + + struct gkyl_block_topo *btopo = create_nested_block_topo(); + + for (int i = 0; i < num_blocks; i++) { + five_moment_nested_block_bc_updaters_init(&coarse_bdata[i], &btopo->conn[i]); + +#ifdef AMR_DEBUG + five_moment_nested_block_bc_updaters_init(&intermediate_bdata[i], &btopo->conn[i]); + five_moment_nested_block_bc_updaters_init(&fine_bdata[i], &btopo->conn[i]); +#endif + } + + for (int i = 0; i < num_blocks; i++) { + coarse_bdata[i].fdup_elc = gkyl_array_new(GKYL_DOUBLE, 5, coarse_bdata[i].ext_range.volume); + coarse_bdata[i].fdup_ion = gkyl_array_new(GKYL_DOUBLE, 5, coarse_bdata[i].ext_range.volume); + coarse_bdata[i].fdup_maxwell = gkyl_array_new(GKYL_DOUBLE, 8, coarse_bdata[i].ext_range.volume); + + for (int d = 0; d < ndim + 1; d++) { + coarse_bdata[i].f_elc[d] = gkyl_array_new(GKYL_DOUBLE, 5, coarse_bdata[i].ext_range.volume); + coarse_bdata[i].f_ion[d] = gkyl_array_new(GKYL_DOUBLE, 5, coarse_bdata[i].ext_range.volume); + coarse_bdata[i].f_maxwell[d] = gkyl_array_new(GKYL_DOUBLE, 8, coarse_bdata[i].ext_range.volume); + } + + coarse_bdata[i].app_accel_elc = gkyl_array_new(GKYL_DOUBLE, 3, coarse_bdata[i].ext_range.volume); + coarse_bdata[i].app_accel_ion = gkyl_array_new(GKYL_DOUBLE, 3, coarse_bdata[i].ext_range.volume); + coarse_bdata[i].rhs_source_elc = gkyl_array_new(GKYL_DOUBLE, 5, coarse_bdata[i].ext_range.volume); + coarse_bdata[i].rhs_source_ion = gkyl_array_new(GKYL_DOUBLE, 5, coarse_bdata[i].ext_range.volume); + coarse_bdata[i].ext_em = gkyl_array_new(GKYL_DOUBLE, 6, coarse_bdata[i].ext_range.volume); + coarse_bdata[i].app_current = gkyl_array_new(GKYL_DOUBLE, 3, coarse_bdata[i].ext_range.volume); + coarse_bdata[i].nT_source_elc = gkyl_array_new(GKYL_DOUBLE, 2, coarse_bdata[i].ext_range.volume); + coarse_bdata[i].nT_source_ion = gkyl_array_new(GKYL_DOUBLE, 2, coarse_bdata[i].ext_range.volume); + +#ifdef AMR_DEBUG + intermediate_bdata[i].fdup_elc = gkyl_array_new(GKYL_DOUBLE, 5, intermediate_bdata[i].ext_range.volume); + intermediate_bdata[i].fdup_ion = gkyl_array_new(GKYL_DOUBLE, 5, intermediate_bdata[i].ext_range.volume); + intermediate_bdata[i].fdup_maxwell = gkyl_array_new(GKYL_DOUBLE, 8, intermediate_bdata[i].ext_range.volume); + + for (int d = 0; d < ndim + 1; d++) { + intermediate_bdata[i].f_elc[d] = gkyl_array_new(GKYL_DOUBLE, 5, intermediate_bdata[i].ext_range.volume); + intermediate_bdata[i].f_ion[d] = gkyl_array_new(GKYL_DOUBLE, 5, intermediate_bdata[i].ext_range.volume); + intermediate_bdata[i].f_maxwell[d] = gkyl_array_new(GKYL_DOUBLE, 8, intermediate_bdata[i].ext_range.volume); + } + + intermediate_bdata[i].app_accel_elc = gkyl_array_new(GKYL_DOUBLE, 3, intermediate_bdata[i].ext_range.volume); + intermediate_bdata[i].app_accel_ion = gkyl_array_new(GKYL_DOUBLE, 3, intermediate_bdata[i].ext_range.volume); + intermediate_bdata[i].rhs_source_elc = gkyl_array_new(GKYL_DOUBLE, 5, intermediate_bdata[i].ext_range.volume); + intermediate_bdata[i].rhs_source_ion = gkyl_array_new(GKYL_DOUBLE, 5, intermediate_bdata[i].ext_range.volume); + intermediate_bdata[i].ext_em = gkyl_array_new(GKYL_DOUBLE, 6, intermediate_bdata[i].ext_range.volume); + intermediate_bdata[i].app_current = gkyl_array_new(GKYL_DOUBLE, 3, intermediate_bdata[i].ext_range.volume); + intermediate_bdata[i].nT_source_elc = gkyl_array_new(GKYL_DOUBLE, 2, intermediate_bdata[i].ext_range.volume); + intermediate_bdata[i].nT_source_ion = gkyl_array_new(GKYL_DOUBLE, 2, intermediate_bdata[i].ext_range.volume); + + fine_bdata[i].fdup_elc = gkyl_array_new(GKYL_DOUBLE, 5, fine_bdata[i].ext_range.volume); + fine_bdata[i].fdup_ion = gkyl_array_new(GKYL_DOUBLE, 5, fine_bdata[i].ext_range.volume); + fine_bdata[i].fdup_maxwell = gkyl_array_new(GKYL_DOUBLE, 8, fine_bdata[i].ext_range.volume); + + for (int d = 0; d < ndim + 1; d++) { + fine_bdata[i].f_elc[d] = gkyl_array_new(GKYL_DOUBLE, 5, fine_bdata[i].ext_range.volume); + fine_bdata[i].f_ion[d] = gkyl_array_new(GKYL_DOUBLE, 5, fine_bdata[i].ext_range.volume); + fine_bdata[i].f_maxwell[d] = gkyl_array_new(GKYL_DOUBLE, 8, fine_bdata[i].ext_range.volume); + } + + fine_bdata[i].app_accel_elc = gkyl_array_new(GKYL_DOUBLE, 3, fine_bdata[i].ext_range.volume); + fine_bdata[i].app_accel_ion = gkyl_array_new(GKYL_DOUBLE, 3, fine_bdata[i].ext_range.volume); + fine_bdata[i].rhs_source_elc = gkyl_array_new(GKYL_DOUBLE, 5, fine_bdata[i].ext_range.volume); + fine_bdata[i].rhs_source_ion = gkyl_array_new(GKYL_DOUBLE, 5, fine_bdata[i].ext_range.volume); + fine_bdata[i].ext_em = gkyl_array_new(GKYL_DOUBLE, 6, fine_bdata[i].ext_range.volume); + fine_bdata[i].app_current = gkyl_array_new(GKYL_DOUBLE, 3, fine_bdata[i].ext_range.volume); + fine_bdata[i].nT_source_elc = gkyl_array_new(GKYL_DOUBLE, 2, fine_bdata[i].ext_range.volume); + fine_bdata[i].nT_source_ion = gkyl_array_new(GKYL_DOUBLE, 2, fine_bdata[i].ext_range.volume); +#endif + } + +#ifdef AMR_USETHREADS + for (int i = 0; i < num_blocks; i++) { + gkyl_job_pool_add_work(coarse_job_pool, five_moment_init_job_func_block, &coarse_bdata[i]); + +#ifdef AMR_DEBUG + gkyl_job_pool_add_work(intermediate_job_pool, five_moment_init_job_func_block, &intermediate_bdata[i]); + gkyl_job_pool_add_work(fine_job_pool, five_moment_init_job_func_block, &fine_bdata[i]); +#endif + } + gkyl_job_pool_wait(coarse_job_pool); + +#ifdef AMR_DEBUG + gkyl_job_pool_wait(intermediate_job_pool); + gkyl_job_pool_wait(fine_job_pool); +#endif +#else + for (int i = 0; i < num_blocks; i++) { + five_moment_init_job_func_block(&coarse_bdata[i]); + +#ifdef AMR_DEBUG + five_moment_init_job_func_block(&intermediate_bdata[i]); + five_moment_init_job_func_block(&fine_bdata[i]); +#endif + } +#endif + +#ifdef AMR_DEBUG + char coarse0[64]; + snprintf(coarse0, 64, "%s_coarse_0", five_moment_output); + five_moment_write_sol_block(coarse0, num_blocks, coarse_bdata); + + char intermediate0[64]; + snprintf(intermediate0, 64, "%s_intermediate_0", five_moment_output); + five_moment_write_sol_block(intermediate, num_blocks, intermediate_bdata); + + char fine0[64]; + snprintf(fine0, 64, "%s_fine_0", five_moment_output); + five_moment_write_sol_block(fine0, num_blocks, fine_bdata); + + char fine0_elc_b0[64], fine0_ion_b0[64], fine0_field_b0[64]; + char intermediate0_elc_b0[64], intermediate0_ion_b0[64], intermediate0_field_b0[64]; + char coarse0_elc_b0[64], coarse0_ion_b0[64], coarse0_field_b0[64]; + char b0_elc[64], b0_ion[64], b0_field[64]; + + snprintf(fine0_elc_b0, 64, "%s_fine_0_elc_b0.gkyl", five_moment_output); + snprintf(fine0_ion_b0, 64, "%s_fine_0_ion_b0.gkyl", five_moment_output); + snprintf(fine0_field_b0, 64, "%s_fine_0_field_b0.gkyl", five_moment_output); + + snprintf(intermediate0_elc_b0, 64, "%s_intermediate_0_elc_b0.gkyl", five_moment_output); + snprintf(intermediate0_ion_b0, 64, "%s_intermediate_0_ion_b0.gkyl", five_moment_output); + snprintf(intermediate0_field_b0, 64, "%s_intermediate_0_field_b0.gkyl", five_moment_output); + + snprintf(coarse0_elc_b0, 64, "%s_coarse_0_elc_b0.gkyl", five_moment_output); + snprintf(coarse0_ion_b0, 64, "%s_coarse_0_ion_b0.gkyl", five_moment_output); + snprintf(coarse0_field_b0, 64, "%s_coarse_0_field_b0.gkyl", five_moment_output); + + snprintf(b0_elc, 64, "%s_0_elc_b0.gkyl", five_moment_output); + snprintf(b0_ion, 64, "%s_0_ion_b0.gkyl", five_moment_output); + snprintf(b0_field, 64, "%s_0_field_b0.gkyl", five_moment_output); + + rename(fine0_elc_b0, b0_elc); + rename(fine0_ion_b0, b0_ion); + rename(fine0_field_b0, b0_field); + + remove(intermediate0_elc_b0); + remove(intermediate0_ion_b0); + remove(intermediate0_field_b0); + + remove(coarse0_elc_b0); + remove(coarse0_ion_b0); + remove(coarse0_field_b0); + + for (int i = 1; i < 9; i++) { + char fine0_elc_bi[64], fine0_ion_bi[64], fine0_field_bi[64]; + char intermediate0_elc_bi[64], intermediate0_ion_bi[64], intermediate0_field_bi[64]; + char coarse0_elc_bi[64], coarse0_ion_bi[64], coarse0_field_bi[64]; + char elc_bi[64], ion_bi[64], field_bi[64]; + + snprintf(fine0_elc_bi, 64, "%s_fine_0_elc_b%d.gkyl", five_moment_output, i); + snprintf(fine0_ion_bi, 64, "%s_fine_0_ion_b%d.gkyl", five_moment_output, i); + snprintf(fine0_field_bi, 64, "%s_fine_0_field_b%d.gkyl", five_moment_output, i); + + snprintf(intermediate0_elc_bi, 64, "%s_interemediate_0_elc_b%d.gkyl", five_moment_output, i); + snprintf(intermediate0_ion_bi, 64, "%s_interemediate_0_ion_b%d.gkyl", five_moment_output, i); + snprintf(intermediate0_field_bi, 64, "%s_interemediate_0_field_b%d.gkyl", five_moment_output, i); + + snprintf(coarse0_elc_bi, 64, "%s_coarse_0_elc_b%d.gkyl", five_moment_output, i); + snprintf(coarse0_ion_bi, 64, "%s_coarse_0_ion_b%d.gkyl", five_moment_output, i); + snprintf(coarse0_field_bi, 64, "%s_coarse_0_field_b%d.gkyl", five_moment_output, i); + + snprintf(elc_bi, 64, "%s_0_elc_b%d.gkyl", five_moment_output, i); + snprintf(ion_bi, 64, "%s_0_ion_b%d.gkyl", five_moment_output, i); + snprintf(field_bi, 64, "%s_0_field_b%d.gkyl", five_moment_output, i); + + rename(intermediate0_elc_bi, elc_bi); + rename(intermediate0_ion_bi, ion_bi); + rename(intermediate0_field_bi, field_bi); + + remove(fine0_elc_bi); + remove(fine0_ion_bi); + remove(fine0_field_bi); + + remove(coarse0_elc_bi); + remove(coarse0_ion_bi); + remove(coarse0_field_bi); + } + + for (int i = 9; i < 25; i++) { + char buf_old_elc[64], buf_old_ion[64], buf_old_field[64]; + char buf_new_elc[64], buf_new_ion[64], buf_new_field[64]; + char buf_del1_elc[64], buf_del1_ion[64], buf_del1_field[64]; + char buf_del2_elc[64], buf_del2_ion[64], buf_del2_field[64]; + + snprintf(buf_old_elc, 64, "%s_coarse_0_elc_b%d.gkyl", five_moment_output, i); + snprintf(buf_old_ion, 64, "%s_coarse_0_ion_b%d.gkyl", five_moment_output, i); + snprintf(buf_old_field, 64, "%s_coarse_0_field_b%d.gkyl", five_moment_output, i); + + snprintf(buf_new_elc, 64, "%s_0_elc_b%d.gkyl", five_moment_output, i); + snprintf(buf_new_ion, 64, "%s_0_ion_b%d.gkyl", five_moment_output, i); + snprintf(buf_new_field, 64, "%s_0_field_b%d.gkyl", five_moment_output, i); + + snprintf(buf_del1_elc, 64, "%s_intermediate_0_elc_b%d.gkyl", five_moment_output, i); + snprintf(buf_del1_ion, 64, "%s_intermediate_0_ion_b%d.gkyl", five_moment_output, i); + snprintf(buf_del1_field, 64, "%s_intermediate_0_field_b%d.gkyl", five_moment_output, i); + + snprintf(buf_del2_elc, 64, "%s_fine_0_elc_b%d.gkyl", five_moment_output, i); + snprintf(buf_del2_ion, 64, "%s_fine_0_ion_b%d.gkyl", five_moment_output, i); + snprintf(buf_del2_field, 64, "%s_fine_0_field_b%d.gkyl", five_moment_output, i); + + rename(buf_old_elc, buf_new_elc); + rename(buf_old_ion, buf_new_ion); + rename(buf_old_field, buf_new_field); + + remove(buf_del1_elc); + remove(buf_del1_ion); + remove(buf_del1_field); + + remove(buf_del2_elc); + remove(buf_del2_ion); + remove(buf_del2_field); + } +#else + char amr0[64]; + snprintf(amr0, 64, "%s_0", five_moment_output); + five_moment_write_sol_block(amr0, num_blocks, coarse_bdata); +#endif + + double coarse_t_curr = 0.0; + double intermediate_t_curr = 0.0; + double fine_t_curr = 0.0; + double coarse_dt = five_moment_max_dt_block(num_blocks, coarse_bdata); + +#ifdef AMR_DEBUG + double intermediate_dt = five_moment_max_dt_block(num_blocks, intermediate_bdata); + double fine_dt = five_moment_max_dt_block(num_blocks, fine_bdata); +#else + double intermediate_dt = (1.0 / ref_factor1) * coarse_dt; + double fine_dt = (1.0 / (ref_factor1 * ref_factor2)) * coarse_dt; +#endif + + struct sim_stats stats = { }; + + struct timespec tm_start = gkyl_wall_clock(); + + long coarse_step = 1; + long num_steps = app_args.num_steps; + + double io_trigger = t_end / num_frames; + + double dt_init = -1.0; + int num_failures = 0; + + while ((coarse_t_curr < t_end) && (coarse_step <= num_steps)) { + printf("Taking coarse (level 0) time-step %ld at t = %g; ", coarse_step, coarse_t_curr); + struct gkyl_update_status coarse_status = five_moment_update_block(coarse_job_pool, btopo, coarse_bdata, coarse_t_curr, coarse_dt, &stats); + printf(" dt = %g\n", coarse_status.dt_actual); + + if (!coarse_status.success) { + printf("** Update method failed! Aborting simulation ....\n"); + break; + } + + for (long intermediate_step = 1; intermediate_step < ref_factor1 + 1; intermediate_step++) { +#ifdef AMR_DEBUG + printf(" Taking intermediate (level 1) time-step %ld at t = %g; ", intermediate_step, intermediate_t_curr); + struct gkyl_update_status intermediate_status = five_moment_update_block(intermediate_job_pool, btopo, intermediate_bdata, intermediate_t_curr, intermediate_dt, &stats); + printf(" dt = %g\n", intermediate_status.dt_actual); + + if (!intermediate_status.success) { + printf("** Update method failed! Aborting simulation ....\n"); + break; + } + + for (long fine_step = 1; fine_step < ref_factor2 + 1; fine_step++) { + printf(" Taking fine (level 2) time-step %ld at t = %g", fine_step, fine_t_curr); + struct gkyl_update_status fine_status = five_moment_update_block(fine_job_pool, btopo, fine_bdata, fine_t_curr fine_dt, &stats); + printf(" dt = %g\n", fine_status.dt_actual); + + if (!fine_status.success) { + printf("** Update method failed! Aborting simulation ....\n"); + break; + } + + fine_t_curr += fine_status.dt_actual; + fine_dt = fine_status.dt_suggested; + } + + intermediate_t_curr += intermediate_status.dt_actual; + intermediate_dt += intermediate_status.dt_suggested; +#else + printf(" Taking intermediate (level 1) time-step %ld at t = %g", intermediate_step, intermediate_t_curr); + printf(" dt = %g\n", (1.0 / ref_factor1) * coarse_status.dt_actual); + + for (long fine_step = 1; fine_step < ref_factor2 + 1; fine_step++) { + printf(" Taking fine (level 2) time-step %ld at t = %g", fine_step, fine_t_curr); + printf(" dt = %g\n", (1.0 / (ref_factor1 * ref_factor2)) * coarse_status.dt_actual); + + fine_t_curr += (1.0 / (ref_factor1 * ref_factor2)) * coarse_status.dt_actual; + fine_dt = (1.0 / (ref_factor1 * ref_factor2)) * coarse_status.dt_suggested; + } + + intermediate_t_curr += (1.0 / ref_factor1) * coarse_status.dt_actual; + intermediate_dt = (1.0 / ref_factor1) * coarse_status.dt_suggested; +#endif + } + + for (int i = 1; i < num_frames; i++) { + if (coarse_t_curr < (i * io_trigger) && (coarse_t_curr + coarse_status.dt_actual) > (i * io_trigger)) { + // TODO: Make file output work correctly in the AMR_DEBUG case. +#ifdef AMR_DEBUG + char buf_coarse[64]; + char buf_fine[64]; + + snprintf(buf_coarse, 64, "%s_coarse_%d", five_moment_output, i); + snprintf(buf_fine, 64, "%s_fine_%d", five_moment_output, i); + + five_moment_write_sol_block(buf_coarse, num_blocks, coarse_bdata); + five_moment_write_sol_block(buf_fine, num_blocks, fine_bdata); + + char buf_fine_old_elc[64]; + char buf_fine_old_ion[64]; + char buf_fine_old_field[64]; + + char buf_fine_new_elc[64]; + char buf_fine_new_ion[64]; + char buf_fine_new_field[64]; + + char buf_coarse_old_elc[64]; + char buf_coarse_old_ion[64]; + char buf_coarse_old_field[64]; + + snprintf(buf_fine_old_elc, 64, "%s_fine_%d_elc_b0.gkyl", five_moment_output, i); + snprintf(buf_fine_old_ion, 64, "%s_fine_%d_ion_b0.gkyl", five_moment_output, i); + snprintf(buf_fine_old_field, 64, "%s_fine_%d_field_b0.gkyl", five_moment_output, i); + + snprintf(buf_fine_new_elc, 64, "%s_%d_elc_b0.gkyl", five_moment_output, i); + snprintf(buf_fine_new_ion, 64, "%s_%d_ion_b0.gkyl", five_moment_output, i); + snprintf(buf_fine_new_field, 64, "%s_%d_field_b0.gkyl", five_moment_output, i); + + snprintf(buf_coarse_old_elc, 64, "%s_coarse_%d_elc_b0.gkyl", five_moment_output, i); + snprintf(buf_coarse_old_ion, 64, "%s_coarse_%d_ion_b0.gkyl", five_moment_output, i); + snprintf(buf_coarse_old_field, 64, "%s_coarse_%d_field_b0.gkyl", five_moment_output, i); + + rename(buf_fine_old_elc, buf_fine_new_elc); + rename(buf_fine_old_ion, buf_fine_new_ion); + rename(buf_fine_old_field, buf_fine_new_field); + + remove(buf_coarse_old_elc); + remove(buf_coarse_old_ion); + remove(buf_coarse_old_field); + + for (int j = 1; j < 9; j++) { + char buf_old_elc[64]; + char buf_old_ion[64]; + char buf_old_field[64]; + + char buf_new_elc[64]; + char buf_new_ion[64]; + char buf_new_field[64]; + + char buf_del_elc[64]; + char buf_del_ion[64]; + char buf_del_field[64]; + + snprintf(buf_old_elc, 64, "%s_coarse_%d_elc_b%d.gkyl", five_moment_output, i, j); + snprintf(buf_old_ion, 64, "%s_coarse_%d_ion_b%d.gkyl", five_moment_output, i, j); + snprintf(buf_old_field, 64, "%s_coarse_%d_field_b%d.gkyl", five_moment_output, i, j); + + snprintf(buf_new_elc, 64, "%s_%d_elc_b%d.gkyl", five_moment_output, i, j); + snprintf(buf_new_ion, 64, "%s_%d_ion_b%d.gkyl", five_moment_output, i, j); + snprintf(buf_new_field, 64, "%s_%d_field_b%d.gkyl", five_moment_output, i, j); + + snprintf(buf_del_elc, 64, "%s_fine_%d_elc_b%d.gkyl", five_moment_output, i, j); + snprintf(buf_del_ion, 64, "%s_fine_%d_ion_b%d.gkyl", five_moment_output, i, j); + snprintf(buf_del_field, 64, "%s_fine_%d_field_b%d.gkyl", five_moment_output, i, j); + + rename(buf_old_elc, buf_new_elc); + rename(buf_old_ion, buf_new_ion); + rename(buf_old_field, buf_new_field); + + remove(buf_del_elc); + remove(buf_del_ion); + remove(buf_del_field); + } +#else + char buf[64]; + snprintf(buf, 64, "%s_%d", five_moment_output, i); + + five_moment_write_sol_block(buf, num_blocks, coarse_bdata); +#endif + } + } + + coarse_t_curr += coarse_status.dt_actual; + coarse_dt = coarse_status.dt_suggested; + + if (dt_init < 0.0) { + dt_init = coarse_status.dt_actual; + } + else if (coarse_status.dt_actual < dt_failure_tol * dt_init) { + num_failures += 1; + + printf("WARNING: Time-step dt = %g", coarse_status.dt_actual); + printf(" is below %g*dt_init ...", dt_failure_tol); + printf(" num_failures = %d\n", num_failures); + if (num_failures >= num_failures_max) { + printf("ERROR: Time-step was below %g*dt_init ", dt_failure_tol); + printf("%d consecutive times. Aborting simulation ....\n", num_failures_max); + break; + } + } + else { + num_failures = 0; + } + + coarse_step += 1; + } + + double tm_total_sec = gkyl_time_diff_now_sec(tm_start); + + // TODO: Make file output work correctly in the AMR_DEBUG case. +#ifdef AMR_DEBUG + char buf_coarse[64]; + char buf_fine[64]; + + snprintf(buf_coarse, 64, "%s_coarse_%d", five_moment_output, num_frames); + snprintf(buf_fine, 64, "%s_fine_%d", five_moment_output, num_frames); + + five_moment_write_sol_block(buf_coarse, num_blocks, coarse_bdata); + five_moment_write_sol_block(buf_fine, num_blocks, fine_bdata); + + char buf_fine_old_elc[64]; + char buf_fine_old_ion[64]; + char buf_fine_old_field[64]; + + char buf_fine_new_elc[64]; + char buf_fine_new_ion[64]; + char buf_fine_new_field[64]; + + char buf_coarse_old_elc[64]; + char buf_coarse_old_ion[64]; + char buf_coarse_old_field[64]; + + snprintf(buf_fine_old_elc, 64, "%s_fine_%d_elc_b0.gkyl", five_moment_output, num_frames); + snprintf(buf_fine_old_ion, 64, "%s_fine_%d_ion_b0.gkyl", five_moment_output, num_frames); + snprintf(buf_fine_old_field, 64, "%s_fine_%d_field_b0.gkyl", five_moment_output, num_frames); + + snprintf(buf_fine_new_elc, 64, "%s_%d_elc_b0.gkyl", five_moment_output, num_frames); + snprintf(buf_fine_new_ion, 64, "%s_%d_ion_b0.gkyl", five_moment_output, num_frames); + snprintf(buf_fine_new_field, 64, "%s_%d_field_b0.gkyl", five_moment_output, num_frames); + + snprintf(buf_coarse_old_elc, 64, "%s_coarse_%d_elc_b0.gkyl", five_moment_output, num_frames); + snprintf(buf_coarse_old_ion, 64, "%s_coarse_%d_ion_b0.gkyl", five_moment_output, num_frames); + snprintf(buf_coarse_old_field, 64, "%s_coarse_%d_field_b0.gkyl", five_moment_output, num_frames); + + rename(buf_fine_old_elc, buf_fine_new_elc); + rename(buf_fine_old_ion, buf_fine_new_ion); + rename(buf_fine_old_field, buf_fine_new_field); + + remove(buf_coarse_old_elc); + remove(buf_coarse_old_ion); + remove(buf_coarse_old_field); + + for (int i = 1; i < 9; i++) { + char buf_old_elc[64]; + char buf_old_ion[64]; + char buf_old_field[64]; + + char buf_new_elc[64]; + char buf_new_ion[64]; + char buf_new_field[64]; + + char buf_del_elc[64]; + char buf_del_ion[64]; + char buf_del_field[64]; + + snprintf(buf_old_elc, 64, "%s_coarse_%d_elc_b%d.gkyl", five_moment_output, num_frames, i); + snprintf(buf_old_ion, 64, "%s_coarse_%d_ion_b%d.gkyl", five_moment_output, num_frames, i); + snprintf(buf_old_field, 64, "%s_coarse_%d_field_b%d.gkyl", five_moment_output, num_frames, i); + + snprintf(buf_new_elc, 64, "%s_%d_elc_b%d.gkyl", five_moment_output, num_frames, i); + snprintf(buf_new_ion, 64, "%s_%d_ion_b%d.gkyl", five_moment_output, num_frames, i); + snprintf(buf_new_field, 64, "%s_%d_field_b%d.gkyl", five_moment_output, num_frames, i); + + snprintf(buf_del_elc, 64, "%s_fine_%d_elc_b%d.gkyl", five_moment_output, num_frames, i); + snprintf(buf_del_ion, 64, "%s_fine_%d_ion_b%d.gkyl", five_moment_output, num_frames, i); + snprintf(buf_del_field, 64, "%s_fine_%d_field_b%d.gkyl", five_moment_output, num_frames, i); + + rename(buf_old_elc, buf_new_elc); + rename(buf_old_ion, buf_new_ion); + rename(buf_old_field, buf_new_field); + + remove(buf_del_elc); + remove(buf_del_ion); + remove(buf_del_field); + } +#else + char buf[64]; + snprintf(buf, 64, "%s_%d", five_moment_output, num_frames); + + five_moment_write_sol_block(buf, num_blocks, coarse_bdata); +#endif + + printf("Total run-time: %g. Failed steps: %d\n", tm_total_sec, stats.nfail); + + for (int i = 0; i < num_blocks; i++) { + gkyl_fv_proj_release(coarse_bdata[i].fv_proj_elc); + gkyl_fv_proj_release(coarse_bdata[i].fv_proj_ion); + gkyl_fv_proj_release(coarse_bdata[i].fv_proj_maxwell); + + gkyl_wv_eqn_release(coarse_bdata[i].euler_elc); + gkyl_wv_eqn_release(coarse_bdata[i].euler_ion); + gkyl_wv_eqn_release(coarse_bdata[i].maxwell); + + five_moment_block_bc_updaters_release(&coarse_bdata[i]); + gkyl_wave_geom_release(coarse_bdata[i].geom); + +#ifdef AMR_DEBUG + gkyl_fv_proj_release(intermediate_bdata[i].fv_proj_elc); + gkyl_fv_proj_release(intermediate_bdata[i].fv_proj_ion); + gkyl_fv_proj_release(intermediate_bdata[i].fv_proj_maxwell); + + gkyl_wv_eqn_release(intermediate_bdata[i].euler_elc); + gkyl_wv_eqn_release(intermediate_bdata[i].euler_ion); + gkyl_wv_eqn_release(intermediate_bdata[i].maxwell); + + five_moment_block_bc_updaters_release(&intermediate_bdata[i]); + gkyl_wave_geom_release(intermediate_bdata[i].geom); + + gkyl_fv_proj_release(fine_bdata[i].fv_proj_elc); + gkyl_fv_proj_release(fine_bdata[i].fv_proj_ion); + gkyl_fv_proj_release(fine_bdata[i].fv_proj_maxwell); + + gkyl_wv_eqn_release(fine_bdata[i].euler_elc); + gkyl_wv_eqn_release(fine_bdata[i].euler_ion); + gkyl_wv_eqn_release(fine_bdata[i].maxwell); + + five_moment_block_bc_updaters_release(&fine_bdata[i]); + gkyl_wave_geom_release(fine_bdata[i].geom); +#endif + + for (int d = 0; d < ndim; d++) { + gkyl_wave_prop_release(coarse_bdata[i].slvr_elc[d]); + gkyl_wave_prop_release(coarse_bdata[i].slvr_ion[d]); + gkyl_wave_prop_release(coarse_bdata[i].slvr_maxwell[d]); + +#ifdef AMR_DEBUG + gkyl_wave_prop_release(intermediate_bdata[i].slvr_elc[d]); + gkyl_wave_prop_release(intermediate_bdata[i].slvr_ion[d]); + gkyl_wave_prop_release(intermediate_bdata[i].slvr_maxwell[d]); + + gkyl_wave_prop_release(fine_bdata[i].slvr_elc[d]); + gkyl_wave_prop_release(fine_bdata[i].slvr_ion[d]); + gkyl_wave_prop_release(fine_bdata[i].slvr_maxwell[d]); +#endif + } + + gkyl_array_release(coarse_bdata[i].fdup_elc); + gkyl_array_release(coarse_bdata[i].fdup_ion); + gkyl_array_release(coarse_bdata[i].fdup_maxwell); + +#ifdef AMR_DEBUG + gkyl_array_release(intermediate_bdata[i].fdup_elc); + gkyl_array_release(intermediate_bdata[i].fdup_ion); + gkyl_array_release(intermediate_bdata[i].fdup_maxwell); + + gkyl_array_release(fine_bdata[i].fdup_elc); + gkyl_array_release(fine_bdata[i].fdup_ion); + gkyl_array_release(fine_bdata[i].fdup_maxwell); +#endif + + for(int d = 0; d < ndim; d++) { + gkyl_array_release(coarse_bdata[i].f_elc[d]); + gkyl_array_release(coarse_bdata[i].f_ion[d]); + gkyl_array_release(coarse_bdata[i].f_maxwell[d]); + +#ifdef AMR_DEBUG + gkyl_array_release(intermediate_bdata[i].f_elc[d]); + gkyl_array_release(intermediate_bdata[i].f_ion[d]); + gkyl_array_release(intermediate_bdata[i].f_maxwell[d]); + + gkyl_array_release(fine_bdata[i].f_elc[d]); + gkyl_array_release(fine_bdata[i].f_ion[d]); + gkyl_array_release(fine_bdata[i].f_maxwell[d]); +#endif + } + + gkyl_array_release(coarse_bdata[i].app_accel_elc); + gkyl_array_release(coarse_bdata[i].app_accel_ion); + gkyl_array_release(coarse_bdata[i].rhs_source_elc); + gkyl_array_release(coarse_bdata[i].rhs_source_ion); + gkyl_array_release(coarse_bdata[i].ext_em); + gkyl_array_release(coarse_bdata[i].app_current); + gkyl_array_release(coarse_bdata[i].nT_source_elc); + gkyl_array_release(coarse_bdata[i].nT_source_ion); + +#ifdef AMR_DEBUG + gkyl_array_release(intermediate_bdata[i].app_accel_elc); + gkyl_array_release(intermediate_bdata[i].app_accel_ion); + gkyl_array_release(intermediate_bdata[i].rhs_source_elc); + gkyl_array_release(intermediate_bdata[i].rhs_source_ion); + gkyl_array_release(intermediate_bdata[i].ext_em); + gkyl_array_release(intermediate_bdata[i].app_current); + gkyl_array_release(intermediate_bdata[i].nT_source_elc); + gkyl_array_release(intermediate_bdata[i].nT_source_ion); + + gkyl_array_release(fine_bdata[i].app_accel_elc); + gkyl_array_release(fine_bdata[i].app_accel_ion); + gkyl_array_release(fine_bdata[i].rhs_source_elc); + gkyl_array_release(fine_bdata[i].rhs_source_ion); + gkyl_array_release(fine_bdata[i].ext_em); + gkyl_array_release(fine_bdata[i].app_current); + gkyl_array_release(fine_bdata[i].nT_source_elc); + gkyl_array_release(fine_bdata[i].nT_source_ion); +#endif + } + + gkyl_block_topo_release(btopo); + gkyl_job_pool_release(coarse_job_pool); +#ifdef AMR_DEBUG + gkyl_job_pool_release(intermediate_job_pool); + gkyl_job_pool_release(fine_job_pool); +#endif } \ No newline at end of file diff --git a/amr/gkyl_amr_block_coupled_priv.h b/amr/gkyl_amr_block_coupled_priv.h index ec34633c8..de089019b 100644 --- a/amr/gkyl_amr_block_coupled_priv.h +++ b/amr/gkyl_amr_block_coupled_priv.h @@ -170,6 +170,14 @@ void maxwell_transmissive_bc(double t, int nc, const double* GKYL_RESTRICT skin, */ void five_moment_block_bc_updaters_init(struct five_moment_block_data* bdata, const struct gkyl_block_connections* conn); +/** +* Initialize nested block AMR updaters for both physical (outer-block) and non-physical (inter-block) boundary conditions for the coupled five-moment equations. +* +* @param bdata Block-structured data for the coupled five-moment equations. +* @param conn Topology/connectivity data for the block hierarchy. +*/ +void five_moment_nested_block_bc_updaters_init(struct five_moment_block_data* bdata, const struct gkyl_block_connections* conn); + /** * Initialize block AMR updaters for both physical (outer-block) and non-physical (inter-block) boundary conditions for the coupled ten-moment equations. * diff --git a/amr/gkyl_amr_block_priv.h b/amr/gkyl_amr_block_priv.h index c108c75ef..4bf746870 100644 --- a/amr/gkyl_amr_block_priv.h +++ b/amr/gkyl_amr_block_priv.h @@ -138,20 +138,20 @@ void euler_block_bc_updaters_init(struct euler_block_data* bdata, const struct g void euler_nested_block_bc_updaters_init(struct euler_block_data* bdata, const struct gkyl_block_connections* conn); /** -* Initialize nested block AMR updaters for both physical (outer-block) and non-physical (inter-block) boundary conditions for the general relativistic Euler equations. +* Initialize block AMR updaters for both physical (outer-block) and non-physical (inter-block) boundary conditions for the general relativistic Euler equations. * * @param bdata Block-structured data for the general relativistic Euler equations. * @param conn Topology/connectivity data for the block hierarchy. */ -void gr_euler_nested_block_bc_updaters_init(struct euler_block_data* bdata, const struct gkyl_block_connections* conn); +void gr_euler_block_bc_updaters_init(struct euler_block_data* bdata, const struct gkyl_block_connections* conn); /** -* Initialize block AMR updaters for both physical (outer-block) and non-physical (inter-block) boundary conditions for the general relativistic Euler equations. +* Initialize nested block AMR updaters for both physical (outer-block) and non-physical (inter-block) boundary conditions for the general relativistic Euler equations. * * @param bdata Block-structured data for the general relativistic Euler equations. * @param conn Topology/connectivity data for the block hierarchy. */ -void gr_euler_block_bc_updaters_init(struct euler_block_data* bdata, const struct gkyl_block_connections* conn); +void gr_euler_nested_block_bc_updaters_init(struct euler_block_data* bdata, const struct gkyl_block_connections* conn); /** * Release block AMR updaters for both physical (outer-block) and non-physical (inter-block) boundary conditions for the Euler equations. diff --git a/amr/gkyl_amr_core.h b/amr/gkyl_amr_core.h index 930403a68..678a0e2ea 100644 --- a/amr/gkyl_amr_core.h +++ b/amr/gkyl_amr_core.h @@ -410,4 +410,70 @@ struct ten_moment_2d_single_init { * @param argv Array of command line arguments passed to the function. * @param init Initialization data for the 2D coupled ten-moment equations. */ -void ten_moment_2d_run_single(int argc, char **argv, struct ten_moment_2d_single_init* init); \ No newline at end of file +void ten_moment_2d_run_single(int argc, char **argv, struct ten_moment_2d_single_init* init); + +// Initialization data for a 2D simulation using the coupled five-moment equations, run with static, block-structured mesh refinement with a doubly-nested refinement patch. +struct five_moment_2d_double_init { + int base_Nx; + int base_Ny; + int ref_factor1; + int ref_factor2; + + double coarse_x1; + double coarse_y1; + double coarse_x2; + double coarse_y2; + + double intermediate_x1; + double intermediate_y1; + double intermediate_x2; + double intermediate_y2; + + double refined_x1; + double refined_y1; + double refined_x2; + double refined_y2; + + evalf_t eval_elc; + evalf_t eval_ion; + evalf_t eval_field; + + double gas_gamma; + double k0_elc; + double k0_ion; + + double light_speed; + double e_fact; + double b_fact; + + double epsilon0; + double mass_elc; + double charge_elc; + double mass_ion; + double charge_ion; + + bool transmissive_x; + bool transmissive_y; + + bool wall_x; + bool wall_y; + + char five_moment_output[32]; + + bool low_order_flux; + double cfl_frac; + + double t_end; + int num_frames; + double dt_failure_tol; + int num_failures_max; +}; + +/** +* Run a 2D simulation using the coupled five-moment equations, with static, block-structured mesh refinement with a doubly-nested refinement patch. +* +* @param argc Number of command line arguments passed to the function. +* @param argv Array of command line arguments passed to the function. +* @param init Initialization data for the 2D coupled five-moment equations. +*/ +void five_moment_2d_run_double(int argc, char **argv, struct five_moment_2d_double_init* init); \ No newline at end of file diff --git a/regression/rt_amr_5m_gem.c b/regression/rt_amr_5m_gem_l1.c similarity index 100% rename from regression/rt_amr_5m_gem.c rename to regression/rt_amr_5m_gem_l1.c diff --git a/regression/rt_amr_5m_gem_l2.c b/regression/rt_amr_5m_gem_l2.c new file mode 100644 index 000000000..7a852a4f9 --- /dev/null +++ b/regression/rt_amr_5m_gem_l2.c @@ -0,0 +1,311 @@ +// Geospace Environmental Modeling (GEM) magnetic reconnection test, using static, block-structured mesh refinement with doubly-nested refinement blocks (2x2x refinement), for the 5-moment equations. +// Input parameters match the equilibrium and initial conditions in Section 2, from the article: +// J. Birn et al. (2001), "Geospace Environmental Modeling (GEM) Magnetic Reconnection Challenge", +// Journal of Geophysical Research: Space Physics, Volume 106 (A3): 3715-3719. +// https://agupubs.onlinelibrary.wiley.com/doi/10.1029/1999JA900449 + +#include + +struct amr_5m_gem_ctx +{ + // Mathematical constants (dimensionless). + double pi; + + // Physical constants (using normalized code units). + double gas_gamma; // Adiabatic index. + double epsilon0; // Permittivity of free space. + double mu0; // Permeability of free space. + double mass_ion; // Ion mass. + double charge_ion; // Ion charge. + double mass_elc; // Electron mass. + double charge_elc; // Electron charge. + double Ti_over_Te; // Ion temperature / electron temperature. + double lambda; // Wavelength. + double n0; // Reference number density. + double nb_over_n0; // Background number density / reference number density. + double B0; // Reference magnetic field strength. + double beta; // Plasma beta. + + double k0_elc; // Electron closure parameter. + double k0_ion; // Ion closure parameter. + + // Derived physical quantities (using normalized code units). + double psi0; // Reference magnetic scalar potential. + + double Ti_frac; // Fraction of total temperature from ions. + double Te_frac; // Fraction of total temperature from electrons. + double T_tot; // Total temperature. + + // Simulation parameters. + int Nx; // Coarse cell count (x-direction). + int Ny; // Coarse cell count (y-direction). + int ref_factor1; // First refinement factor. + int ref_factor2; // Second refinement factor. + double Lx; // Coarse domain size (x-direction). + double Ly; // Coarse domain size (y-direction). + double intermediate_Lx; // Intermediate domain size (x-direction). + double intermediate_Ly; // Intermediate domain size (y-direction). + double fine_Lx; // Fine domain size (x-direction). + double fine_Ly; // Fine domain size (y-direction). + double cfl_frac; // CFL coefficient. + + double t_end; // Final simulation time. + int num_frames; // Number of output frames. + double dt_failure_tol; // Minimum allowable fraction of initial time-step. + int num_failures_max; // Maximum allowable number of consecutive small time-steps. +}; + +struct amr_5m_gem_ctx +create_ctx(void) +{ + // Mathematical constants (dimensionless). + double pi = M_PI; + + // Physical constants (using normalized code units). + double gas_gamma = 5.0 / 3.0; // Adiabatic index. + double epsilon0 = 1.0; // Permittivity of free space. + double mu0 = 1.0; // Permeability of free space. + double mass_ion = 1.0; // Ion mass. + double charge_ion = 1.0; // Ion charge. + double mass_elc = 1.0 / 25.0; // Electron mass. + double charge_elc = -1.0; // Electron charge. + double Ti_over_Te = 5.0; // Ion temperature / electron temperature. + double lambda = 0.5; // Wavelength + double n0 = 1.0; // Reference number density. + double nb_over_n0 = 0.2; // Background number density / reference number density. + double B0 = 0.1; // Reference magnetic field strength. + double beta = 1.0; // Plasma beta. + + double k0_elc = 0.0; // Electron closure parameter. + double k0_ion = 0.0; // Ion closure parameter. + + // Derived physical quantities (using normalized code units). + double psi0 = 0.1 * B0; // Reference magnetic scalar potential. + + double Ti_frac = Ti_over_Te / (1.0 + Ti_over_Te); // Fraction of total temperature from ions. + double Te_frac = 1.0 / (1.0 + Ti_over_Te); // Fraction of total temperature from electrons. + double T_tot = beta * (B0 * B0) / 2.0 / n0; // Total temperature; + + // Simulation parameters. + int Nx = 16; // Coarse cell count (x-direction). + int Ny = 8; // Coarse cell count (y-direction). + int ref_factor1 = 2; // First refinement factor. + int ref_factor2 = 2; // Second refinement factor. + double Lx = 25.6; // Coarse domain size (x-direction). + double Ly = 12.8; // Coarse domain size (y-direction). + double intermediate_Lx = 8.5333333; // Intermediate domain size (x-direction). + double intermediate_Ly = 4.2666666; // Intermediate domain size (y-direction). + double fine_Lx = 2.8444444; // Fine domain size (x-direction). + double fine_Ly = 1.4222222; // Fine domain size (y-direction). + double cfl_frac = 0.95; // CFL coefficient. + + double t_end = 250.0; // Final simulation time. + int num_frames = 1; // Number of output frames. + double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. + int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. + + struct amr_5m_gem_ctx ctx = { + .pi = pi, + .gas_gamma = gas_gamma, + .epsilon0 = epsilon0, + .mu0 = mu0, + .mass_ion = mass_ion, + .charge_ion = charge_ion, + .mass_elc = mass_elc, + .charge_elc = charge_elc, + .Ti_over_Te = Ti_over_Te, + .lambda = lambda, + .n0 = n0, + .nb_over_n0 = nb_over_n0, + .B0 = B0, + .beta = beta, + .k0_elc = k0_elc, + .k0_ion = k0_ion, + .psi0 = psi0, + .Ti_frac = Ti_frac, + .Te_frac = Te_frac, + .T_tot = T_tot, + .Nx = Nx, + .Ny = Ny, + .ref_factor1 = ref_factor1, + .ref_factor2 = ref_factor2, + .Lx = Lx, + .Ly = Ly, + .intermediate_Lx = intermediate_Lx, + .intermediate_Ly = intermediate_Ly, + .fine_Lx = fine_Lx, + .fine_Ly = fine_Ly, + .cfl_frac = cfl_frac, + .t_end = t_end, + .num_frames = num_frames, + .dt_failure_tol = dt_failure_tol, + .num_failures_max = num_failures_max, + }; + + return ctx; +} + +void +evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +{ + double x = xn[0], y = xn[1]; + struct amr_5m_gem_ctx new_ctx = create_ctx(); // Context for initialization functions. + struct amr_5m_gem_ctx *app = &new_ctx; + + double gas_gamma = app->gas_gamma; + double mass_elc = app->mass_elc; + double charge_elc = app->charge_elc; + double lambda = app->lambda; + double n0 = app->n0; + double nb_over_n0 = app->nb_over_n0; + double B0 = app->B0; + double beta = app->beta; + + double Te_frac = app->Te_frac; + double T_tot = app->T_tot; + + double sech_sq = (1.0 / cosh(y / lambda)) * (1.0 / cosh(y / lambda)); // Hyperbolic secant squared. + + double n = n0 * (sech_sq + nb_over_n0); // Total number density. + double Jz = -(B0 / lambda) * sech_sq; // Total current density (z-direction). + + double rhoe = n * mass_elc; // Electron mass density. + double momze = (mass_elc / charge_elc) * Jz * Te_frac; // Electron momentum density (z-direction). + double Ee_tot = n * T_tot * Te_frac / (gas_gamma - 1.0) + 0.5 * momze * momze / rhoe; // Electron total energy density. + + // Set electron mass density. + fout[0] = rhoe; + // Set electron momentum density. + fout[1] = 0.0; fout[2] = 0.0; fout[3] = momze; + // Set electron total energy density. + fout[4] = Ee_tot; +} + +void +evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +{ + double x = xn[0], y = xn[1]; + struct amr_5m_gem_ctx new_ctx = create_ctx(); // Context for initialization functions. + struct amr_5m_gem_ctx *app = &new_ctx; + + double gas_gamma = app->gas_gamma; + double mass_ion = app->mass_ion; + double charge_ion = app->charge_ion; + double lambda = app->lambda; + double n0 = app->n0; + double nb_over_n0 = app->nb_over_n0; + double B0 = app->B0; + double beta = app->beta; + + double Ti_frac = app->Ti_frac; + double T_tot = app->T_tot; + + double sech_sq = (1.0 / cosh(y / lambda)) * (1.0 / cosh(y / lambda)); // Hyperbolic secant squared. + + double n = n0 * (sech_sq + nb_over_n0); // Total number density. + double Jz = -(B0 / lambda) * sech_sq; // Total current density (z-direction). + + double rhoi = n * mass_ion; // Ion mass density. + double momzi = (mass_ion / charge_ion) * Jz * Ti_frac; // Ion momentum density (z-direction). + double Ei_tot = n * T_tot * Ti_frac / (gas_gamma - 1.0) + 0.5 * momzi * momzi / rhoi; // Ion total energy density. + + // Set ion mass density. + fout[0] = rhoi; + // Set ion momentum density. + fout[1] = 0.0; fout[2] = 0.0; fout[3] = momzi; + // Set ion total energy density. + fout[4] = Ei_tot; +} + +void +evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +{ + double x = xn[0], y = xn[1]; + struct amr_5m_gem_ctx new_ctx = create_ctx(); // Context for initialization functions. + struct amr_5m_gem_ctx *app = &new_ctx; + + double pi = app->pi; + + double lambda = app->lambda; + double B0 = app->B0; + + double psi0 = app->psi0; + + double Lx = app->Lx; + double Ly = app->Ly; + + double Bxb = B0 * tanh(y / lambda); // Total magnetic field strength. + double Bx = Bxb - psi0 * (pi / Ly) * cos(2.0 * pi * x / Lx) * sin(pi * y / Ly); // Total magnetic field (x-direction). + double By = psi0 * (2.0 * pi / Lx) * sin(2.0 * pi * x / Lx) * cos(pi * y / Ly); // Total magnetic field (y-direction). + double Bz = 0.0; // Total magnetic field (z-direction). + + // Set electric field. + fout[0] = 0.0; fout[1] = 0.0; fout[2] = 0.0; + // Set magnetic field. + fout[3] = Bx; fout[4] = By; fout[5] = Bz; + // Set correction potentials. + fout[6] = 0.0; fout[7] = 0.0; +} + +int main(int argc, char **argv) +{ + struct amr_5m_gem_ctx ctx = create_ctx(); // Context for initialization functions. + + struct five_moment_2d_double_init init = { + .base_Nx = ctx.Nx, + .base_Ny = ctx.Ny, + .ref_factor1 = ctx.ref_factor1, + .ref_factor2 = ctx.ref_factor2, + + .coarse_x1 = -0.5 * ctx.Lx, + .coarse_y1 = -0.5 * ctx.Ly, + .coarse_x2 = 0.5 * ctx.Lx, + .coarse_y2 = 0.5 * ctx.Ly, + + .intermediate_x1 = -0.5 * ctx.intermediate_Lx, + .intermediate_y1 = -0.5 * ctx.intermediate_Ly, + .intermediate_x2 = 0.5 * ctx.intermediate_Lx, + .intermediate_y2 = 0.5 * ctx.intermediate_Ly, + + .refined_x1 = -0.5 * ctx.fine_Lx, + .refined_y1 = -0.5 * ctx.fine_Ly, + .refined_x2 = 0.5 * ctx.fine_Lx, + .refined_y2 = 0.5 * ctx.fine_Ly, + + .eval_elc = evalElcInit, + .eval_ion = evalIonInit, + .eval_field = evalFieldInit, + + .gas_gamma = ctx.gas_gamma, + .k0_elc = ctx.k0_elc, + .k0_ion = ctx.k0_ion, + + .light_speed = 1.0, + .e_fact = 0.0, + .b_fact = 1.0, + + .epsilon0 = ctx.epsilon0, + .mass_elc = ctx.mass_elc, + .charge_elc = ctx.charge_elc, + .mass_ion = ctx.mass_ion, + .charge_ion = ctx.charge_ion, + + .transmissive_x = true, + .transmissive_y = false, + + .wall_x = false, + .wall_y = true, + + .five_moment_output = "amr_5m_gem_l2", + + .low_order_flux = false, + .cfl_frac = ctx.cfl_frac, + + .t_end = ctx.t_end, + .num_frames = ctx.num_frames, + .dt_failure_tol = ctx.dt_failure_tol, + .num_failures_max = ctx.num_failures_max, + }; + + five_moment_2d_run_double(argc, argv, &init); +} \ No newline at end of file From 353ba60a33208549af090c00cb0d3a861289a8d5 Mon Sep 17 00:00:00 2001 From: JonathanGorard Date: Tue, 18 Jun 2024 18:21:59 +0200 Subject: [PATCH 04/32] Fixed file output in AMR_DEBUG mode for coupled equation systems. Still requires (a lot of) general code cleanup. --- amr/amr_core_five_moment.c | 197 ++++++++++++++++++++++++++----------- 1 file changed, 138 insertions(+), 59 deletions(-) diff --git a/amr/amr_core_five_moment.c b/amr/amr_core_five_moment.c index 3fa88e7f9..643b55358 100644 --- a/amr/amr_core_five_moment.c +++ b/amr/amr_core_five_moment.c @@ -2111,7 +2111,7 @@ five_moment_2d_run_double(int argc, char **argv, struct five_moment_2d_double_in char intermediate0[64]; snprintf(intermediate0, 64, "%s_intermediate_0", five_moment_output); - five_moment_write_sol_block(intermediate, num_blocks, intermediate_bdata); + five_moment_write_sol_block(intermediate0, num_blocks, intermediate_bdata); char fine0[64]; snprintf(fine0, 64, "%s_fine_0", five_moment_output); @@ -2160,9 +2160,9 @@ five_moment_2d_run_double(int argc, char **argv, struct five_moment_2d_double_in snprintf(fine0_ion_bi, 64, "%s_fine_0_ion_b%d.gkyl", five_moment_output, i); snprintf(fine0_field_bi, 64, "%s_fine_0_field_b%d.gkyl", five_moment_output, i); - snprintf(intermediate0_elc_bi, 64, "%s_interemediate_0_elc_b%d.gkyl", five_moment_output, i); - snprintf(intermediate0_ion_bi, 64, "%s_interemediate_0_ion_b%d.gkyl", five_moment_output, i); - snprintf(intermediate0_field_bi, 64, "%s_interemediate_0_field_b%d.gkyl", five_moment_output, i); + snprintf(intermediate0_elc_bi, 64, "%s_intermediate_0_elc_b%d.gkyl", five_moment_output, i); + snprintf(intermediate0_ion_bi, 64, "%s_intermediate_0_ion_b%d.gkyl", five_moment_output, i); + snprintf(intermediate0_field_bi, 64, "%s_intermediate_0_field_b%d.gkyl", five_moment_output, i); snprintf(coarse0_elc_bi, 64, "%s_coarse_0_elc_b%d.gkyl", five_moment_output, i); snprintf(coarse0_ion_bi, 64, "%s_coarse_0_ion_b%d.gkyl", five_moment_output, i); @@ -2273,7 +2273,7 @@ five_moment_2d_run_double(int argc, char **argv, struct five_moment_2d_double_in for (long fine_step = 1; fine_step < ref_factor2 + 1; fine_step++) { printf(" Taking fine (level 2) time-step %ld at t = %g", fine_step, fine_t_curr); - struct gkyl_update_status fine_status = five_moment_update_block(fine_job_pool, btopo, fine_bdata, fine_t_curr fine_dt, &stats); + struct gkyl_update_status fine_status = five_moment_update_block(fine_job_pool, btopo, fine_bdata, fine_t_curr, fine_dt, &stats); printf(" dt = %g\n", fine_status.dt_actual); if (!fine_status.success) { @@ -2306,33 +2306,32 @@ five_moment_2d_run_double(int argc, char **argv, struct five_moment_2d_double_in for (int i = 1; i < num_frames; i++) { if (coarse_t_curr < (i * io_trigger) && (coarse_t_curr + coarse_status.dt_actual) > (i * io_trigger)) { - // TODO: Make file output work correctly in the AMR_DEBUG case. #ifdef AMR_DEBUG char buf_coarse[64]; + char buf_intermediate[64]; char buf_fine[64]; snprintf(buf_coarse, 64, "%s_coarse_%d", five_moment_output, i); + snprintf(buf_intermediate, 64, "%s_intermediate_%d", five_moment_output, i); snprintf(buf_fine, 64, "%s_fine_%d", five_moment_output, i); five_moment_write_sol_block(buf_coarse, num_blocks, coarse_bdata); + five_moment_write_sol_block(buf_intermediate, num_blocks, intermediate_bdata); five_moment_write_sol_block(buf_fine, num_blocks, fine_bdata); - char buf_fine_old_elc[64]; - char buf_fine_old_ion[64]; - char buf_fine_old_field[64]; - - char buf_fine_new_elc[64]; - char buf_fine_new_ion[64]; - char buf_fine_new_field[64]; - - char buf_coarse_old_elc[64]; - char buf_coarse_old_ion[64]; - char buf_coarse_old_field[64]; + char buf_fine_old_elc[64], buf_fine_old_ion[64], buf_fine_old_field[64]; + char buf_intermediate_old_elc[64], buf_intermediate_old_ion[64], buf_intermediate_old_field[64]; + char buf_fine_new_elc[64], buf_fine_new_ion[64], buf_fine_new_field[64]; + char buf_coarse_old_elc[64], buf_coarse_old_ion[64], buf_coarse_old_field[64]; snprintf(buf_fine_old_elc, 64, "%s_fine_%d_elc_b0.gkyl", five_moment_output, i); snprintf(buf_fine_old_ion, 64, "%s_fine_%d_ion_b0.gkyl", five_moment_output, i); snprintf(buf_fine_old_field, 64, "%s_fine_%d_field_b0.gkyl", five_moment_output, i); + snprintf(buf_intermediate_old_elc, 64, "%s_intermediate_%d_elc_b0.gkyl", five_moment_output, i); + snprintf(buf_intermediate_old_ion, 64, "%s_intermediate_%d_ion_b0.gkyl", five_moment_output, i); + snprintf(buf_intermediate_old_field, 64, "%s_intermediate_%d_field_b0.gkyl", five_moment_output, i); + snprintf(buf_fine_new_elc, 64, "%s_%d_elc_b0.gkyl", five_moment_output, i); snprintf(buf_fine_new_ion, 64, "%s_%d_ion_b0.gkyl", five_moment_output, i); snprintf(buf_fine_new_field, 64, "%s_%d_field_b0.gkyl", five_moment_output, i); @@ -2345,22 +2344,54 @@ five_moment_2d_run_double(int argc, char **argv, struct five_moment_2d_double_in rename(buf_fine_old_ion, buf_fine_new_ion); rename(buf_fine_old_field, buf_fine_new_field); + remove(buf_intermediate_old_elc); + remove(buf_intermediate_old_ion); + remove(buf_intermediate_old_field); + remove(buf_coarse_old_elc); remove(buf_coarse_old_ion); remove(buf_coarse_old_field); - for (int j = 1; j < 9; j++) { - char buf_old_elc[64]; - char buf_old_ion[64]; - char buf_old_field[64]; + for (int j = 1; j < 8; j++) { + char fine0_elc_bi[64], fine0_ion_bi[64], fine0_field_bi[64]; + char intermediate0_elc_bi[64], intermediate0_ion_bi[64], intermediate0_field_bi[64]; + char coarse0_elc_bi[64], coarse0_ion_bi[64], coarse0_field_bi[64]; + char elc_bi[64], ion_bi[64], field_bi[64]; - char buf_new_elc[64]; - char buf_new_ion[64]; - char buf_new_field[64]; + snprintf(fine0_elc_bi, 64, "%s_fine_%d_elc_b%d.gkyl", five_moment_output, i, j); + snprintf(fine0_ion_bi, 64, "%s_fine_%d_ion_b%d.gkyl", five_moment_output, i, j); + snprintf(fine0_field_bi, 64, "%s_fine_%d_field_b%d.gkyl", five_moment_output, i, j); - char buf_del_elc[64]; - char buf_del_ion[64]; - char buf_del_field[64]; + snprintf(intermediate0_elc_bi, 64, "%s_intermediate_%d_elc_b%d.gkyl", five_moment_output, i, j); + snprintf(intermediate0_ion_bi, 64, "%s_intermediate_%d_ion_b%d.gkyl", five_moment_output, i, j); + snprintf(intermediate0_field_bi, 64, "%s_intermediate_%d_field_b%d.gkyl", five_moment_output, i, j); + + snprintf(coarse0_elc_bi, 64, "%s_coarse_%d_elc_b%d.gkyl", five_moment_output, i, j); + snprintf(coarse0_ion_bi, 64, "%s_coarse_%d_ion_b%d.gkyl", five_moment_output, i, j); + snprintf(coarse0_field_bi, 64, "%s_coarse_%d_field_b%d.gkyl", five_moment_output, i, j); + + snprintf(elc_bi, 64, "%s_%d_elc_b%d.gkyl", five_moment_output, i, j); + snprintf(ion_bi, 64, "%s_%d_ion_b%d.gkyl", five_moment_output, i, j); + snprintf(field_bi, 64, "%s_%d_field_b%d.gkyl", five_moment_output, i, j); + + rename(intermediate0_elc_bi, elc_bi); + rename(intermediate0_ion_bi, ion_bi); + rename(intermediate0_field_bi, field_bi); + + remove(fine0_elc_bi); + remove(fine0_ion_bi); + remove(fine0_field_bi); + + remove(coarse0_elc_bi); + remove(coarse0_ion_bi); + remove(coarse0_field_bi); + } + + for (int j = 9; j < 25; j++) { + char buf_old_elc[64], buf_old_ion[64], buf_old_field[64]; + char buf_new_elc[64], buf_new_ion[64], buf_new_field[64]; + char buf_del1_elc[64], buf_del1_ion[64], buf_del1_field[64]; + char buf_del2_elc[64], buf_del2_ion[64], buf_del2_field[64]; snprintf(buf_old_elc, 64, "%s_coarse_%d_elc_b%d.gkyl", five_moment_output, i, j); snprintf(buf_old_ion, 64, "%s_coarse_%d_ion_b%d.gkyl", five_moment_output, i, j); @@ -2370,17 +2401,25 @@ five_moment_2d_run_double(int argc, char **argv, struct five_moment_2d_double_in snprintf(buf_new_ion, 64, "%s_%d_ion_b%d.gkyl", five_moment_output, i, j); snprintf(buf_new_field, 64, "%s_%d_field_b%d.gkyl", five_moment_output, i, j); - snprintf(buf_del_elc, 64, "%s_fine_%d_elc_b%d.gkyl", five_moment_output, i, j); - snprintf(buf_del_ion, 64, "%s_fine_%d_ion_b%d.gkyl", five_moment_output, i, j); - snprintf(buf_del_field, 64, "%s_fine_%d_field_b%d.gkyl", five_moment_output, i, j); + snprintf(buf_del1_elc, 64, "%s_intermediate_%d_elc_b%d.gkyl", five_moment_output, i, j); + snprintf(buf_del1_ion, 64, "%s_intermediate_%d_ion_b%d.gkyl", five_moment_output, i, j); + snprintf(buf_del1_field, 64, "%s_intermediate_%d_field_b%d.gkyl", five_moment_output, i, j); + + snprintf(buf_del2_elc, 64, "%s_fine_%d_elc_b%d.gkyl", five_moment_output, i, j); + snprintf(buf_del2_ion, 64, "%s_fine_%d_ion_b%d.gkyl", five_moment_output, i, j); + snprintf(buf_del2_field, 64, "%s_fine_%d_field_b%d.gkyl", five_moment_output, i, j); rename(buf_old_elc, buf_new_elc); rename(buf_old_ion, buf_new_ion); rename(buf_old_field, buf_new_field); - remove(buf_del_elc); - remove(buf_del_ion); - remove(buf_del_field); + remove(buf_del1_elc); + remove(buf_del1_ion); + remove(buf_del1_field); + + remove(buf_del2_elc); + remove(buf_del2_ion); + remove(buf_del2_field); } #else char buf[64]; @@ -2421,25 +2460,21 @@ five_moment_2d_run_double(int argc, char **argv, struct five_moment_2d_double_in // TODO: Make file output work correctly in the AMR_DEBUG case. #ifdef AMR_DEBUG char buf_coarse[64]; + char buf_intermediate[64]; char buf_fine[64]; snprintf(buf_coarse, 64, "%s_coarse_%d", five_moment_output, num_frames); + snprintf(buf_intermediate, 64, "%s_intermediate_%d", five_moment_output, num_frames); snprintf(buf_fine, 64, "%s_fine_%d", five_moment_output, num_frames); five_moment_write_sol_block(buf_coarse, num_blocks, coarse_bdata); + five_moment_write_sol_block(buf_intermediate, num_blocks, intermediate_bdata); five_moment_write_sol_block(buf_fine, num_blocks, fine_bdata); - char buf_fine_old_elc[64]; - char buf_fine_old_ion[64]; - char buf_fine_old_field[64]; - - char buf_fine_new_elc[64]; - char buf_fine_new_ion[64]; - char buf_fine_new_field[64]; - - char buf_coarse_old_elc[64]; - char buf_coarse_old_ion[64]; - char buf_coarse_old_field[64]; + char buf_fine_old_elc[64], buf_fine_old_ion[64], buf_fine_old_field[64]; + char buf_fine_new_elc[64], buf_fine_new_ion[64], buf_fine_new_field[64]; + char buf_intermediate_old_elc[64], buf_intermediate_old_ion[64], buf_intermediate_old_field[64]; + char buf_coarse_old_elc[64], buf_coarse_old_ion[64], buf_coarse_old_field[64]; snprintf(buf_fine_old_elc, 64, "%s_fine_%d_elc_b0.gkyl", five_moment_output, num_frames); snprintf(buf_fine_old_ion, 64, "%s_fine_%d_ion_b0.gkyl", five_moment_output, num_frames); @@ -2449,6 +2484,10 @@ five_moment_2d_run_double(int argc, char **argv, struct five_moment_2d_double_in snprintf(buf_fine_new_ion, 64, "%s_%d_ion_b0.gkyl", five_moment_output, num_frames); snprintf(buf_fine_new_field, 64, "%s_%d_field_b0.gkyl", five_moment_output, num_frames); + snprintf(buf_intermediate_old_elc, 64, "%s_intermediate_%d_elc_b0.gkyl", five_moment_output, num_frames); + snprintf(buf_intermediate_old_ion, 64, "%s_intermediate_%d_ion_b0.gkyl", five_moment_output, num_frames); + snprintf(buf_intermediate_old_field, 64, "%s_intermediate_%d_field_b0.gkyl", five_moment_output, num_frames); + snprintf(buf_coarse_old_elc, 64, "%s_coarse_%d_elc_b0.gkyl", five_moment_output, num_frames); snprintf(buf_coarse_old_ion, 64, "%s_coarse_%d_ion_b0.gkyl", five_moment_output, num_frames); snprintf(buf_coarse_old_field, 64, "%s_coarse_%d_field_b0.gkyl", five_moment_output, num_frames); @@ -2457,22 +2496,54 @@ five_moment_2d_run_double(int argc, char **argv, struct five_moment_2d_double_in rename(buf_fine_old_ion, buf_fine_new_ion); rename(buf_fine_old_field, buf_fine_new_field); + remove(buf_intermediate_old_elc); + remove(buf_intermediate_old_ion); + remove(buf_intermediate_old_field); + remove(buf_coarse_old_elc); remove(buf_coarse_old_ion); remove(buf_coarse_old_field); for (int i = 1; i < 9; i++) { - char buf_old_elc[64]; - char buf_old_ion[64]; - char buf_old_field[64]; + char fine0_elc_bi[64], fine0_ion_bi[64], fine0_field_bi[64]; + char intermediate0_elc_bi[64], intermediate0_ion_bi[64], intermediate0_field_bi[64]; + char coarse0_elc_bi[64], coarse0_ion_bi[64], coarse0_field_bi[64]; + char elc_bi[64], ion_bi[64], field_bi[64]; - char buf_new_elc[64]; - char buf_new_ion[64]; - char buf_new_field[64]; + snprintf(fine0_elc_bi, 64, "%s_fine_%d_elc_b%d.gkyl", five_moment_output, num_frames, i); + snprintf(fine0_ion_bi, 64, "%s_fine_%d_ion_b%d.gkyl", five_moment_output, num_frames, i); + snprintf(fine0_field_bi, 64, "%s_fine_%d_field_b%d.gkyl", five_moment_output, num_frames, i); - char buf_del_elc[64]; - char buf_del_ion[64]; - char buf_del_field[64]; + snprintf(intermediate0_elc_bi, 64, "%s_intermediate_%d_elc_b%d.gkyl", five_moment_output, num_frames, i); + snprintf(intermediate0_ion_bi, 64, "%s_intermediate_%d_ion_b%d.gkyl", five_moment_output, num_frames, i); + snprintf(intermediate0_field_bi, 64, "%s_intermediate_%d_field_b%d.gkyl", five_moment_output, num_frames, i); + + snprintf(coarse0_elc_bi, 64, "%s_coarse_%d_elc_b%d.gkyl", five_moment_output, num_frames, i); + snprintf(coarse0_ion_bi, 64, "%s_coarse_%d_ion_b%d.gkyl", five_moment_output, num_frames, i); + snprintf(coarse0_field_bi, 64, "%s_coarse_%d_field_b%d.gkyl", five_moment_output, num_frames, i); + + snprintf(elc_bi, 64, "%s_%d_elc_b%d.gkyl", five_moment_output, num_frames, i); + snprintf(ion_bi, 64, "%s_%d_ion_b%d.gkyl", five_moment_output, num_frames, i); + snprintf(field_bi, 64, "%s_%d_field_b%d.gkyl", five_moment_output, num_frames, i); + + rename(intermediate0_elc_bi, elc_bi); + rename(intermediate0_ion_bi, ion_bi); + rename(intermediate0_field_bi, field_bi); + + remove(fine0_elc_bi); + remove(fine0_ion_bi); + remove(fine0_field_bi); + + remove(coarse0_elc_bi); + remove(coarse0_ion_bi); + remove(coarse0_field_bi); + } + + for (int i = 9; i < 25; i++) { + char buf_old_elc[64], buf_old_ion[64], buf_old_field[64]; + char buf_new_elc[64], buf_new_ion[64], buf_new_field[64]; + char buf_del1_elc[64], buf_del1_ion[64], buf_del1_field[64]; + char buf_del2_elc[64], buf_del2_ion[64], buf_del2_field[64]; snprintf(buf_old_elc, 64, "%s_coarse_%d_elc_b%d.gkyl", five_moment_output, num_frames, i); snprintf(buf_old_ion, 64, "%s_coarse_%d_ion_b%d.gkyl", five_moment_output, num_frames, i); @@ -2482,17 +2553,25 @@ five_moment_2d_run_double(int argc, char **argv, struct five_moment_2d_double_in snprintf(buf_new_ion, 64, "%s_%d_ion_b%d.gkyl", five_moment_output, num_frames, i); snprintf(buf_new_field, 64, "%s_%d_field_b%d.gkyl", five_moment_output, num_frames, i); - snprintf(buf_del_elc, 64, "%s_fine_%d_elc_b%d.gkyl", five_moment_output, num_frames, i); - snprintf(buf_del_ion, 64, "%s_fine_%d_ion_b%d.gkyl", five_moment_output, num_frames, i); - snprintf(buf_del_field, 64, "%s_fine_%d_field_b%d.gkyl", five_moment_output, num_frames, i); + snprintf(buf_del1_elc, 64, "%s_intermediate_%d_elc_b%d.gkyl", five_moment_output, num_frames, i); + snprintf(buf_del1_ion, 64, "%s_intermediate_%d_ion_b%d.gkyl", five_moment_output, num_frames, i); + snprintf(buf_del1_field, 64, "%s_intermediate_%d_field_b%d.gkyl", five_moment_output, num_frames, i); + + snprintf(buf_del2_elc, 64, "%s_fine_%d_elc_b%d.gkyl", five_moment_output, num_frames, i); + snprintf(buf_del2_ion, 64, "%s_fine_%d_ion_b%d.gkyl", five_moment_output, num_frames, i); + snprintf(buf_del2_field, 64, "%s_fine_%d_field_b%d.gkyl", five_moment_output, num_frames, i); rename(buf_old_elc, buf_new_elc); rename(buf_old_ion, buf_new_ion); rename(buf_old_field, buf_new_field); - remove(buf_del_elc); - remove(buf_del_ion); - remove(buf_del_field); + remove(buf_del1_elc); + remove(buf_del1_ion); + remove(buf_del1_field); + + remove(buf_del2_elc); + remove(buf_del2_ion); + remove(buf_del2_field); } #else char buf[64]; From dc7c2a8d9a9cce2c202f5d1741e6c000be8a762d Mon Sep 17 00:00:00 2001 From: JonathanGorard Date: Mon, 24 Jun 2024 08:16:42 -0400 Subject: [PATCH 05/32] Singly- and doubly-nested AMR infrastructure now working with the coupled 10-moment equations. 2x2x refinement for the GEM reconnection test converges (in contrast to the corresponding 5-moment case), but with significant instabilities surrounding the coarse-fine boundaries. More investigation and code cleanup work required. --- amr/amr_block_coupled.c | 75 ++ amr/amr_core_ten_moment.c | 1183 +++++++++++++++++ amr/gkyl_amr_block_coupled_priv.h | 8 + amr/gkyl_amr_core.h | 68 +- .../{rt_amr_10m_gem.c => rt_amr_10m_gem_l1.c} | 0 regression/rt_amr_10m_gem_l2.c | 307 +++++ 6 files changed, 1640 insertions(+), 1 deletion(-) rename regression/{rt_amr_10m_gem.c => rt_amr_10m_gem_l1.c} (100%) create mode 100644 regression/rt_amr_10m_gem_l2.c diff --git a/amr/amr_block_coupled.c b/amr/amr_block_coupled.c index c6866c484..598e0a4d1 100644 --- a/amr/amr_block_coupled.c +++ b/amr/amr_block_coupled.c @@ -285,6 +285,81 @@ ten_moment_block_bc_updaters_init(struct five_moment_block_data* bdata, const st bdata->bc_buffer_maxwell = gkyl_array_new(GKYL_DOUBLE, 8, buff_sz); } +void +ten_moment_nested_block_bc_updaters_init(struct five_moment_block_data* bdata, const struct gkyl_block_connections* conn) +{ + int nghost[25]; + for (int i = 0; i < 25; i++) { + nghost[i] = 2; + } + + bool wall_x = bdata->wall_x; + bool wall_y = bdata->wall_y; + + bool transmissive_x = bdata->transmissive_x; + bool transmissive_y = bdata->transmissive_y; + + for (int d = 0; d < 2; d++) { + bdata->lower_bc_elc[d] = bdata->upper_bc_elc[d] = 0; + bdata->lower_bc_ion[d] = bdata->upper_bc_ion[d] = 0; + bdata->lower_bc_maxwell[d] = bdata->upper_bc_maxwell[d] = 0; + + if ((d == 0 && wall_x) || (d == 1 && wall_y)) { + if (conn->connections[d][0].edge == GKYL_PHYSICAL) { + bdata->lower_bc_elc[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler_elc, bdata->geom, d, GKYL_LOWER_EDGE, nghost, + ten_moment_wall_bc, 0); + bdata->lower_bc_ion[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler_ion, bdata->geom, d, GKYL_LOWER_EDGE, nghost, + ten_moment_wall_bc, 0); + bdata->lower_bc_maxwell[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->maxwell, bdata->geom, d, GKYL_LOWER_EDGE, nghost, + maxwell_wall_bc, 0); + } + + if (conn->connections[d][1].edge == GKYL_PHYSICAL) { + bdata->upper_bc_elc[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler_elc, bdata->geom, d, GKYL_UPPER_EDGE, nghost, + ten_moment_wall_bc, 0); + bdata->upper_bc_ion[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler_ion, bdata->geom, d, GKYL_UPPER_EDGE, nghost, + ten_moment_wall_bc, 0); + bdata->upper_bc_maxwell[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->maxwell, bdata->geom, d, GKYL_UPPER_EDGE, nghost, + maxwell_wall_bc, 0); + } + } + else if ((d == 0 && transmissive_x) || (d == 1 && transmissive_y)) { + if (conn->connections[d][0].edge == GKYL_PHYSICAL) { + bdata->lower_bc_elc[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler_elc, bdata->geom, d, GKYL_LOWER_EDGE, nghost, + ten_moment_transmissive_bc, 0); + bdata->lower_bc_ion[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler_ion, bdata->geom, d, GKYL_LOWER_EDGE, nghost, + ten_moment_transmissive_bc, 0); + bdata->lower_bc_maxwell[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->maxwell, bdata->geom, d, GKYL_LOWER_EDGE, nghost, + maxwell_transmissive_bc, 0); + } + + if (conn->connections[d][1].edge == GKYL_PHYSICAL) { + bdata->upper_bc_elc[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler_elc, bdata->geom, d, GKYL_UPPER_EDGE, nghost, + ten_moment_transmissive_bc, 0); + bdata->upper_bc_ion[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler_ion, bdata->geom, d, GKYL_UPPER_EDGE, nghost, + ten_moment_transmissive_bc, 0); + bdata->upper_bc_maxwell[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->maxwell, bdata->geom, d, GKYL_UPPER_EDGE, nghost, + maxwell_transmissive_bc, 0); + } + } + } + + skin_ghost_ranges_init_block(&bdata->skin_ghost, &bdata->ext_range, nghost); + long buff_sz = 0; + + for (int d = 0; d < 2; d++) { + long vol = bdata->skin_ghost.lower_skin[d].volume; + + if (buff_sz <= vol) { + buff_sz = vol; + } + } + + bdata->bc_buffer_elc = gkyl_array_new(GKYL_DOUBLE, 10, buff_sz); + bdata->bc_buffer_ion = gkyl_array_new(GKYL_DOUBLE, 10, buff_sz); + bdata->bc_buffer_maxwell = gkyl_array_new(GKYL_DOUBLE, 8, buff_sz); +} + void five_moment_block_bc_updaters_release(struct five_moment_block_data* bdata) { diff --git a/amr/amr_core_ten_moment.c b/amr/amr_core_ten_moment.c index 92cc1603c..e7356112c 100644 --- a/amr/amr_core_ten_moment.c +++ b/amr/amr_core_ten_moment.c @@ -1446,4 +1446,1187 @@ ten_moment_2d_run_single(int argc, char **argv, struct ten_moment_2d_single_init #ifdef AMR_DEBUG gkyl_job_pool_release(fine_job_pool); #endif +} + +void +ten_moment_2d_run_double(int argc, char **argv, struct ten_moment_2d_double_init* init) +{ + struct gkyl_app_args app_args = parse_app_args(argc, argv); + + if (app_args.trace_mem) { + gkyl_cu_dev_mem_debug_set(true); + gkyl_mem_debug_set(true); + } + + int base_Nx = init->base_Nx; + int base_Ny = init->base_Ny; + int ref_factor1 = init->ref_factor1; + int ref_factor2 = init->ref_factor2; + + double coarse_x1 = init->coarse_x1; + double coarse_y1 = init->coarse_y1; + double coarse_x2 = init->coarse_x2; + double coarse_y2 = init->coarse_y2; + + double intermediate_x1 = init->intermediate_x1; + double intermediate_y1 = init->intermediate_y1; + double intermediate_x2 = init->intermediate_x2; + double intermediate_y2 = init->intermediate_y2; + + double refined_x1 = init->refined_x1; + double refined_y1 = init->refined_y1; + double refined_x2 = init->refined_x2; + double refined_y2 = init->refined_y2; + + evalf_t eval_elc = init->eval_elc; + evalf_t eval_ion = init->eval_ion; + evalf_t eval_field = init->eval_field; + + double gas_gamma = init->gas_gamma; + double k0_elc = init->k0_elc; + double k0_ion = init->k0_ion; + + double light_speed = init->light_speed; + double e_fact = init->e_fact; + double b_fact = init->b_fact; + + double epsilon0 = init->epsilon0; + double mass_elc = init->mass_elc; + double charge_elc = init->charge_elc; + double mass_ion = init->mass_ion; + double charge_ion = init->charge_ion; + + bool transmissive_x = init->transmissive_x; + bool transmissive_y = init->transmissive_y; + + bool wall_x = init->wall_x; + bool wall_y = init->wall_y; + + char ten_moment_output[32]; + strcpy(ten_moment_output, init->ten_moment_output); + + bool low_order_flux = init->low_order_flux; + int num_frames = init->num_frames; + + double cfl_frac = init->cfl_frac; + double t_end = init->t_end; + double dt_failure_tol = init->dt_failure_tol; + int num_failures_max = init->num_failures_max; + + int ndim = 2; + int num_blocks = 25; + int Nx = base_Nx; + int Ny = base_Ny; + + struct five_moment_block_data coarse_bdata[num_blocks]; + struct gkyl_job_pool *coarse_job_pool = gkyl_thread_pool_new(app_args.num_threads); + +#ifdef AMR_DEBUG + gkyl_rect_grid_init(&coarse_bdata[0].grid, 2, (double []) { refined_x1, refined_y1 }, (double []) { refined_x2, refined_y2 }, + (int []) { Nx, Ny }); + + gkyl_rect_grid_init(&coarse_bdata[1].grid, 2, (double []) { intermediate_x1, refined_y2 }, (double []) { refined_x1, intermediate_y2 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[2].grid, 2, (double []) { refined_x1, refined_y2 }, (double []) { refined_x2, intermediate_y2 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[3].grid, 2, (double []) { refined_x2, refined_y2 }, (double []) { intermediate_x2, intermediate_y2 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[4].grid, 2, (double []) { intermediate_x1, refined_y1 }, (double []) { refined_x1, refined_y2 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[5].grid, 2, (double []) { refined_x2, refined_y1 }, (double []) { intermediate_x2, refined_y2 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[6].grid, 2, (double []) { intermediate_x1, intermediate_y1 }, (double []) { refined_x1, refined_y1 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[7].grid, 2, (double []) { refined_x1, intermediate_y1 }, (double []) { refined_x2, refined_y1 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[8].grid, 2, (double []) { refined_x2, intermediate_y1 }, (double []) { intermediate_x2, refined_y1 }, + (int []) { Nx, Ny }); +#else + gkyl_rect_grid_init(&coarse_bdata[0].grid, 2, (double []) { refined_x1, refined_y1 }, (double []) { refined_x2, refined_y2 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + + gkyl_rect_grid_init(&coarse_bdata[1].grid, 2, (double []) { intermediate_x1, refined_y2 }, (double []) { refined_x1, intermediate_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&coarse_bdata[2].grid, 2, (double []) { refined_x1, refined_y2 }, (double []) { refined_x2, intermediate_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&coarse_bdata[3].grid, 2, (double []) { refined_x2, refined_y2 }, (double []) { intermediate_x2, intermediate_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&coarse_bdata[4].grid, 2, (double []) { intermediate_x1, refined_y1 }, (double []) { refined_x1, refined_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&coarse_bdata[5].grid, 2, (double []) { refined_x2, refined_y1 }, (double []) { intermediate_x2, refined_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&coarse_bdata[6].grid, 2, (double []) { intermediate_x1, intermediate_y1 }, (double []) { refined_x1, refined_y1 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&coarse_bdata[7].grid, 2, (double []) { refined_x1, intermediate_y1 }, (double []) { refined_x2, refined_y1 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&coarse_bdata[8].grid, 2, (double []) { refined_x2, intermediate_y1 }, (double []) { intermediate_x2, refined_y1 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); +#endif + + gkyl_rect_grid_init(&coarse_bdata[9].grid, 2, (double []) { coarse_x1, intermediate_y2 }, (double []) { intermediate_x1, coarse_y2 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[10].grid, 2, (double []) { intermediate_x1, intermediate_y2 }, (double []) { refined_x1, coarse_y2 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[11].grid, 2, (double []) { refined_x1, intermediate_y2 }, (double []) { refined_x2, coarse_y2 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[12].grid, 2, (double []) { refined_x2, intermediate_y2 }, (double []) { intermediate_x2, coarse_y2 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[13].grid, 2, (double []) { intermediate_x2, intermediate_y2 }, (double []) { coarse_x2, coarse_y2 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[14].grid, 2, (double []) { coarse_x1, refined_y2 }, (double []) { intermediate_x1, intermediate_y2 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[15].grid, 2, (double []) { intermediate_x2, refined_y2 }, (double []) { coarse_x2, intermediate_y2 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[16].grid, 2, (double []) { coarse_x1, refined_y1 }, (double []) { intermediate_x1, refined_y2 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[17].grid, 2, (double []) { intermediate_x2, refined_y1 }, (double []) { coarse_x2, refined_y2 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[18].grid, 2, (double []) { coarse_x1, intermediate_y1 }, (double []) { intermediate_x1, refined_y1 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[19].grid, 2, (double []) { intermediate_x2, intermediate_y1 }, (double []) { coarse_x2, refined_y1 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[20].grid, 2, (double []) { coarse_x1, coarse_y1 }, (double []) { intermediate_x1, intermediate_y1 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[21].grid, 2, (double []) { intermediate_x1, coarse_y1 }, (double []) { refined_x1, intermediate_y1 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[22].grid, 2, (double []) { refined_x1, coarse_y1 }, (double []) { refined_x2, intermediate_y1 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[23].grid, 2, (double []) { refined_x2, coarse_y1 }, (double []) { intermediate_x2, intermediate_y1 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[24].grid, 2, (double []) { intermediate_x2, coarse_y1 }, (double []) { coarse_x2, intermediate_y1 }, + (int []) { Nx, Ny }); + +#ifdef AMR_DEBUG + struct five_moment_block_data intermediate_bdata[num_blocks]; + struct gkyl_job_pool *intermediate_job_pool = gkyl_thread_pool_new(app_args.num_threads); + + gkyl_rect_grid_init(&intermediate_bdata[0].grid, 2, (double []) { refined_x1, refined_y1 }, (double []) { refined_x2, refined_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + + gkyl_rect_grid_init(&intermediate_bdata[1].grid, 2, (double []) { coarse_x1, refined_y2 }, (double []) { refined_x1, coarse_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[2].grid, 2, (double []) { refined_x1, refined_y2 }, (double []) { refined_x2, coarse_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[3].grid, 2, (double []) { refined_x2, refined_y2 }, (double []) { coarse_x2, coarse_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[4].grid, 2, (double []) { coarse_x1, refined_y1 }, (double []) { refined_x1, refined_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[5].grid, 2, (double []) { refined_x2, refined_y1 }, (double []) { coarse_x2, refined_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[6].grid, 2, (double []) { coarse_x1, coarse_y1 }, (double []) { refined_x1, refined_y1 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[7].grid, 2, (double []) { refined_x1, coarse_y1 }, (double []) { refined_x2, refined_y1 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[8].grid, 2, (double []) { refined_x2, coarse_y1 }, (double []) { coarse_x2, refined_y1 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + + gkyl_rect_grid_init(&intermediate_bdata[9].grid, 2, (double []) { coarse_x1, intermediate_y2 }, (double []) { intermediate_x1, coarse_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[10].grid, 2, (double []) { intermediate_x1, intermediate_y2 }, (double []) { refined_x1, coarse_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[11].grid, 2, (double []) { refined_x1, intermediate_y2 }, (double []) { refined_x2, coarse_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[12].grid, 2, (double []) { refined_x2, intermediate_y2 }, (double []) { intermediate_x2, coarse_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[13].grid, 2, (double []) { intermediate_x2, intermediate_y2 }, (double []) { coarse_x2, coarse_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[14].grid, 2, (double []) { coarse_x1, refined_y2 }, (double []) { intermediate_x1, intermediate_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[15].grid, 2, (double []) { intermediate_x2, refined_y2 }, (double []) { coarse_x2, intermediate_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[16].grid, 2, (double []) { coarse_x1, refined_y1 }, (double []) { intermediate_x1, refined_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[17].grid, 2, (double []) { intermediate_x2, refined_y1 }, (double []) { coarse_x2, refined_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[18].grid, 2, (double []) { coarse_x1, intermediate_y1 }, (double []) { intermediate_x1, refined_y1 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[19].grid, 2, (double []) { intermediate_x2, intermediate_y1 }, (double []) { coarse_x2, refined_y1 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[20].grid, 2, (double []) { coarse_x1, coarse_y1 }, (double []) { intermediate_x1, intermediate_y1 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[21].grid, 2, (double []) { intermediate_x1, coarse_y1 }, (double []) { refined_x1, intermediate_y1 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[22].grid, 2, (double []) { refined_x1, coarse_y1 }, (double []) { refined_x2, intermediate_y1 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[23].grid, 2, (double []) { refined_x2, coarse_y1 }, (double []) { intermediate_x2, intermediate_y1 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[24].grid, 2, (double []) { intermediate_x2, coarse_y1 }, (double []) { coarse_x2, intermediate_y1 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + + struct five_moment_block_data fine_bdata[num_blocks]; + struct gkyl_job_pool *fine_job_pool = gkyl_thread_pool_new(app_args.num_threads); + + gkyl_rect_grid_init(&fine_bdata[0].grid, 2, (double []) { refined_x1, refined_y1 }, (double []) { refined_x2, refined_y2 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + + gkyl_rect_grid_init(&fine_bdata[1].grid, 2, (double []) { coarse_x1, refined_y2 }, (double []) { refined_x1, coarse_y2 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[2].grid, 2, (double []) { refined_x1, refined_y2 }, (double []) { refined_x2, coarse_y2 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[3].grid, 2, (double []) { refined_x2, refined_y2 }, (double []) { coarse_x2, coarse_y2 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[4].grid, 2, (double []) { coarse_x1, refined_y1 }, (double []) { refined_x1, refined_y2 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[5].grid, 2, (double []) { refined_x2, refined_y1 }, (double []) { coarse_x2, refined_y2 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[6].grid, 2, (double []) { coarse_x1, coarse_y1 }, (double []) { refined_x1, refined_y1 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[7].grid, 2, (double []) { refined_x1, coarse_y1 }, (double []) { refined_x2, refined_y1 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[8].grid, 2, (double []) { refined_x2, coarse_y1 }, (double []) { coarse_x2, refined_y1 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + + gkyl_rect_grid_init(&fine_bdata[9].grid, 2, (double []) { coarse_x1, intermediate_y2 }, (double []) { intermediate_x1, coarse_y2 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[10].grid, 2, (double []) { intermediate_x1, intermediate_y2 }, (double []) { refined_x1, coarse_y2 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[11].grid, 2, (double []) { refined_x1, intermediate_y2 }, (double []) { refined_x2, coarse_y2 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[12].grid, 2, (double []) { refined_x2, intermediate_y2 }, (double []) { intermediate_x2, coarse_y2 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[13].grid, 2, (double []) { intermediate_x2, intermediate_y2 }, (double []) { coarse_x2, coarse_y2 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[14].grid, 2, (double []) { coarse_x1, refined_y2 }, (double []) { intermediate_x1, intermediate_y2 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[15].grid, 2, (double []) { intermediate_x2, refined_y2 }, (double []) { coarse_x2, intermediate_y2 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[16].grid, 2, (double []) { coarse_x1, refined_y1 }, (double []) { intermediate_x1, refined_y2 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[17].grid, 2, (double []) { intermediate_x2, refined_y1 }, (double []) { coarse_x2, refined_y2 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[18].grid, 2, (double []) { coarse_x1, intermediate_y1 }, (double []) { intermediate_x1, refined_y1 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[19].grid, 2, (double []) { intermediate_x2, intermediate_y1 }, (double []) { coarse_x2, refined_y1 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[20].grid, 2, (double []) { coarse_x1, coarse_y1 }, (double []) { intermediate_x1, intermediate_y1 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[21].grid, 2, (double []) { intermediate_x1, coarse_y1 }, (double []) { refined_x1, intermediate_y1 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[22].grid, 2, (double []) { refined_x1, coarse_y1 }, (double []) { refined_x2, intermediate_y1 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[23].grid, 2, (double []) { refined_x2, coarse_y1 }, (double []) { intermediate_x2, intermediate_y1 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[24].grid, 2, (double []) { intermediate_x2, coarse_y1 }, (double []) { coarse_x2, intermediate_y1 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); +#endif + + for (int i = 0; i < num_blocks; i++) { + coarse_bdata[i].fv_proj_elc = gkyl_fv_proj_new(&coarse_bdata[i].grid, 2, 10, eval_elc, 0); + coarse_bdata[i].fv_proj_ion = gkyl_fv_proj_new(&coarse_bdata[i].grid, 2, 10, eval_ion, 0); + coarse_bdata[i].fv_proj_maxwell = gkyl_fv_proj_new(&coarse_bdata[i].grid, 2, 8, eval_field, 0); + +#ifdef AMR_DEBUG + intermediate_bdata[i].fv_proj_elc = gkyl_fv_proj_new(&intermediate_bdata[i].grid, 2, 10, eval_elc, 0); + intermediate_bdata[i].fv_proj_ion = gkyl_fv_proj_new(&intermediate_bdata[i].grid, 2, 10, eval_ion, 0); + intermediate_bdata[i].fv_proj_maxwell = gkyl_fv_proj_new(&intermediate_bdata[i].grid, 2, 8, eval_field, 0); + + fine_bdata[i].fv_proj_elc = gkyl_fv_proj_new(&fine_bdata[i].grid, 2, 10, eval_elc, 0); + fine_bdata[i].fv_proj_ion = gkyl_fv_proj_new(&fine_bdata[i].grid, 2, 10, eval_ion, 0); + fine_bdata[i].fv_proj_maxwell = gkyl_fv_proj_new(&fine_bdata[i].grid, 2, 8, eval_field, 0); +#endif + } + + for (int i = 0; i < num_blocks; i++) { + gkyl_create_grid_ranges(&coarse_bdata[i].grid, (int []) { 2, 2 }, &coarse_bdata[i].ext_range, &coarse_bdata[i].range); + coarse_bdata[i].geom = gkyl_wave_geom_new(&coarse_bdata[i].grid, &coarse_bdata[i].ext_range, 0, 0, false); + + coarse_bdata[i].transmissive_x = transmissive_x; + coarse_bdata[i].transmissive_y = transmissive_y; + + coarse_bdata[i].wall_x = wall_x; + coarse_bdata[i].wall_y = wall_y; + +#ifdef AMR_DEBUG + gkyl_create_grid_ranges(&intermediate_bdata[i].grid, (int []) { 2, 2 }, &intermediate_bdata[i].ext_range, &intermediate_bdata[i].range); + intermediate_bdata[i].geom = gkyl_wave_geom_new(&intermediate_bdata[i].grid, &intermediate_bdata[i].ext_range, 0, 0, false); + + intermediate_bdata[i].transmissive_x = transmissive_x; + intermediate_bdata[i].transmissive_y = transmissive_y; + + intermediate_bdata[i].wall_x = wall_x; + intermediate_bdata[i].wall_y = wall_y; + + gkyl_create_grid_ranges(&fine_bdata[i].grid, (int []) { 2, 2 }, &fine_bdata[i].ext_range, &fine_bdata[i].range); + fine_bdata[i].geom = gkyl_wave_geom_new(&fine_bdata[i].grid, &fine_bdata[i].ext_range, 0, 0, false); + + fine_bdata[i].transmissive_x = transmissive_x; + fine_bdata[i].transmissive_y = transmissive_y; + + fine_bdata[i].wall_x = wall_x; + fine_bdata[i].wall_y = wall_y; +#endif + } + + for (int i = 0; i < num_blocks; i++) { + coarse_bdata[i].euler_elc = gkyl_wv_ten_moment_new(k0_elc); + coarse_bdata[i].euler_ion = gkyl_wv_ten_moment_new(k0_ion); + coarse_bdata[i].maxwell = gkyl_wv_maxwell_new(light_speed, e_fact, b_fact); + + for (int d = 0; d < ndim; d++) { + coarse_bdata[i].slvr_elc[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { + .grid = &coarse_bdata[i].grid, + .equation = coarse_bdata[i].euler_elc, + .limiter = GKYL_MONOTONIZED_CENTERED, + .num_up_dirs = 1, + .update_dirs = { d }, + .cfl = cfl_frac, + .geom = coarse_bdata[i].geom, + } + ); + coarse_bdata[i].slvr_ion[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { + .grid = &coarse_bdata[i].grid, + .equation = coarse_bdata[i].euler_ion, + .limiter = GKYL_MONOTONIZED_CENTERED, + .num_up_dirs = 1, + .update_dirs = { d }, + .cfl = cfl_frac, + .geom = coarse_bdata[i].geom, + } + ); + coarse_bdata[i].slvr_maxwell[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { + .grid = &coarse_bdata[i].grid, + .equation = coarse_bdata[i].maxwell, + .limiter = GKYL_MONOTONIZED_CENTERED, + .num_up_dirs = 1, + .update_dirs = { d }, + .cfl = cfl_frac, + .geom = coarse_bdata[i].geom, + } + ); + } + + struct gkyl_moment_em_coupling_inp coarse_src_inp = { + .grid = &coarse_bdata[i].grid, + .nfluids = 2, + .epsilon0 = epsilon0, + }; + + coarse_src_inp.param[0] = (struct gkyl_moment_em_coupling_data) { + .type = coarse_bdata[i].euler_elc->type, + .charge = charge_elc, + .mass = mass_elc, + .k0 = k0_elc, + }; + coarse_src_inp.param[1] = (struct gkyl_moment_em_coupling_data) { + .type = coarse_bdata[i].euler_ion->type, + .charge = charge_ion, + .mass = mass_ion, + .k0 = k0_ion, + }; + + coarse_bdata[i].src_slvr = gkyl_moment_em_coupling_new(coarse_src_inp); + +#ifdef AMR_DEBUG + intermediate_bdata[i].euler_elc = gkyl_wv_ten_moment_new(k0_elc); + intermediate_bdata[i].euler_ion = gkyl_wv_ten_moment_new(k0_ion); + intermediate_bdata[i].maxwell = gkyl_wv_maxwell_new(light_speed, e_fact, b_fact); + + fine_bdata[i].euler_elc = gkyl_wv_ten_moment_new(k0_elc); + fine_bdata[i].euler_ion = gkyl_wv_ten_moment_new(k0_ion); + fine_bdata[i].maxwell = gkyl_wv_maxwell_new(light_speed, e_fact, b_fact); + + for (int d = 0; d < ndim; d++) { + fine_bdata[i].slvr_elc[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { + .grid = &fine_bdata[i].grid, + .equation = fine_bdata[i].euler_elc, + .limiter = GKYL_MONOTONIZED_CENTERED, + .num_up_dirs = 1, + .update_dirs = { d }, + .cfl = cfl_frac, + .geom = fine_bdata[i].geom, + } + ); + fine_bdata[i].slvr_ion[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { + .grid = &fine_bdata[i].grid, + .equation = fine_bdata[i].euler_ion, + .limiter = GKYL_MONOTONIZED_CENTERED, + .num_up_dirs = 1, + .update_dirs = { d }, + .cfl = cfl_frac, + .geom = fine_bdata[i].geom, + } + ); + fine_bdata[i].slvr_maxwell[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { + .grid = &fine_bdata[i].grid, + .equation = fine_bdata[i].maxwell, + .limiter = GKYL_MONOTONIZED_CENTERED, + .num_up_dirs = 1, + .update_dirs = { d }, + .cfl = cfl_frac, + .geom = fine_bdata[i].geom, + } + ); + } + + struct gkyl_moment_em_coupling_inp fine_src_inp = { + .grid = &fine_bdata[i].grid, + .nfluids = 2, + .epsilon0 = epsilon0, + }; + + fine_src_inp.param[0] = (struct gkyl_moment_em_coupling_data) { + .type = fine_bdata[i].euler_elc->type, + .charge = charge_elc, + .mass = mass_elc, + .k0 = k0_elc, + }; + fine_src_inp.param[1] = (struct gkyl_moment_em_coupling_data) { + .type = fine_bdata[i].euler_ion->type, + .charge = charge_ion, + .mass = mass_ion, + .k0 = k0_ion, + }; + + fine_bdata[i].src_slvr = gkyl_moment_em_coupling_new(fine_src_inp); + + for (int d = 0; d < ndim; d++) { + intermediate_bdata[i].slvr_elc[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { + .grid = &intermediate_bdata[i].grid, + .equation = intermediate_bdata[i].euler_elc, + .limiter = GKYL_MONOTONIZED_CENTERED, + .num_up_dirs = 1, + .update_dirs = { d }, + .cfl = cfl_frac, + .geom = intermediate_bdata[i].geom, + } + ); + intermediate_bdata[i].slvr_ion[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { + .grid = &intermediate_bdata[i].grid, + .equation = intermediate_bdata[i].euler_ion, + .limiter = GKYL_MONOTONIZED_CENTERED, + .num_up_dirs = 1, + .update_dirs = { d }, + .cfl = cfl_frac, + .geom = intermediate_bdata[i].geom, + } + ); + intermediate_bdata[i].slvr_maxwell[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { + .grid = &intermediate_bdata[i].grid, + .equation = intermediate_bdata[i].maxwell, + .limiter = GKYL_MONOTONIZED_CENTERED, + .num_up_dirs = 1, + .update_dirs = { d }, + .cfl = cfl_frac, + .geom = intermediate_bdata[i].geom, + } + ); + } + + struct gkyl_moment_em_coupling_inp intermediate_src_inp = { + .grid = &intermediate_bdata[i].grid, + .nfluids = 2, + .epsilon0 = epsilon0, + }; + + intermediate_src_inp.param[0] = (struct gkyl_moment_em_coupling_data) { + .type = intermediate_bdata[i].euler_elc->type, + .charge = charge_elc, + .mass = mass_elc, + .k0 = k0_elc, + }; + intermediate_src_inp.param[1] = (struct gkyl_moment_em_coupling_data) { + .type = intermediate_bdata[i].euler_ion->type, + .charge = charge_ion, + .mass = mass_ion, + .k0 = k0_ion, + }; + + intermediate_bdata[i].src_slvr = gkyl_moment_em_coupling_new(intermediate_src_inp); +#endif + } + + struct gkyl_block_topo *btopo = create_nested_block_topo(); + + for (int i = 0; i < num_blocks; i++) { + ten_moment_nested_block_bc_updaters_init(&coarse_bdata[i], &btopo->conn[i]); + +#ifdef AMR_DEBUG + ten_moment_nested_block_bc_updaters_init(&intermediate_bdata[i], &btopo->conn[i]); + ten_moment_nested_block_bc_updaters_init(&fine_bdata[i], &btopo->conn[i]); +#endif + } + + for (int i = 0; i < num_blocks; i++) { + coarse_bdata[i].fdup_elc = gkyl_array_new(GKYL_DOUBLE, 10, coarse_bdata[i].ext_range.volume); + coarse_bdata[i].fdup_ion = gkyl_array_new(GKYL_DOUBLE, 10, coarse_bdata[i].ext_range.volume); + coarse_bdata[i].fdup_maxwell = gkyl_array_new(GKYL_DOUBLE, 8, coarse_bdata[i].ext_range.volume); + + for (int d = 0; d < ndim + 1; d++) { + coarse_bdata[i].f_elc[d] = gkyl_array_new(GKYL_DOUBLE, 10, coarse_bdata[i].ext_range.volume); + coarse_bdata[i].f_ion[d] = gkyl_array_new(GKYL_DOUBLE, 10, coarse_bdata[i].ext_range.volume); + coarse_bdata[i].f_maxwell[d] = gkyl_array_new(GKYL_DOUBLE, 8, coarse_bdata[i].ext_range.volume); + } + + coarse_bdata[i].app_accel_elc = gkyl_array_new(GKYL_DOUBLE, 3, coarse_bdata[i].ext_range.volume); + coarse_bdata[i].app_accel_ion = gkyl_array_new(GKYL_DOUBLE, 3, coarse_bdata[i].ext_range.volume); + coarse_bdata[i].rhs_source_elc = gkyl_array_new(GKYL_DOUBLE, 10, coarse_bdata[i].ext_range.volume); + coarse_bdata[i].rhs_source_ion = gkyl_array_new(GKYL_DOUBLE, 10, coarse_bdata[i].ext_range.volume); + coarse_bdata[i].ext_em = gkyl_array_new(GKYL_DOUBLE, 6, coarse_bdata[i].ext_range.volume); + coarse_bdata[i].app_current = gkyl_array_new(GKYL_DOUBLE, 3, coarse_bdata[i].ext_range.volume); + coarse_bdata[i].nT_source_elc = gkyl_array_new(GKYL_DOUBLE, 2, coarse_bdata[i].ext_range.volume); + coarse_bdata[i].nT_source_ion = gkyl_array_new(GKYL_DOUBLE, 2, coarse_bdata[i].ext_range.volume); + +#ifdef AMR_DEBUG + intermediate_bdata[i].fdup_elc = gkyl_array_new(GKYL_DOUBLE, 10, intermediate_bdata[i].ext_range.volume); + intermediate_bdata[i].fdup_ion = gkyl_array_new(GKYL_DOUBLE, 10, intermediate_bdata[i].ext_range.volume); + intermediate_bdata[i].fdup_maxwell = gkyl_array_new(GKYL_DOUBLE, 8, intermediate_bdata[i].ext_range.volume); + + for (int d = 0; d < ndim + 1; d++) { + intermediate_bdata[i].f_elc[d] = gkyl_array_new(GKYL_DOUBLE, 10, intermediate_bdata[i].ext_range.volume); + intermediate_bdata[i].f_ion[d] = gkyl_array_new(GKYL_DOUBLE, 10, intermediate_bdata[i].ext_range.volume); + intermediate_bdata[i].f_maxwell[d] = gkyl_array_new(GKYL_DOUBLE, 8, intermediate_bdata[i].ext_range.volume); + } + + intermediate_bdata[i].app_accel_elc = gkyl_array_new(GKYL_DOUBLE, 3, intermediate_bdata[i].ext_range.volume); + intermediate_bdata[i].app_accel_ion = gkyl_array_new(GKYL_DOUBLE, 3, intermediate_bdata[i].ext_range.volume); + intermediate_bdata[i].rhs_source_elc = gkyl_array_new(GKYL_DOUBLE, 10, intermediate_bdata[i].ext_range.volume); + intermediate_bdata[i].rhs_source_ion = gkyl_array_new(GKYL_DOUBLE, 10, intermediate_bdata[i].ext_range.volume); + intermediate_bdata[i].ext_em = gkyl_array_new(GKYL_DOUBLE, 6, intermediate_bdata[i].ext_range.volume); + intermediate_bdata[i].app_current = gkyl_array_new(GKYL_DOUBLE, 3, intermediate_bdata[i].ext_range.volume); + intermediate_bdata[i].nT_source_elc = gkyl_array_new(GKYL_DOUBLE, 2, intermediate_bdata[i].ext_range.volume); + intermediate_bdata[i].nT_source_ion = gkyl_array_new(GKYL_DOUBLE, 2, intermediate_bdata[i].ext_range.volume); + + fine_bdata[i].fdup_elc = gkyl_array_new(GKYL_DOUBLE, 10, fine_bdata[i].ext_range.volume); + fine_bdata[i].fdup_ion = gkyl_array_new(GKYL_DOUBLE, 10, fine_bdata[i].ext_range.volume); + fine_bdata[i].fdup_maxwell = gkyl_array_new(GKYL_DOUBLE, 8, fine_bdata[i].ext_range.volume); + + for (int d = 0; d < ndim + 1; d++) { + fine_bdata[i].f_elc[d] = gkyl_array_new(GKYL_DOUBLE, 10, fine_bdata[i].ext_range.volume); + fine_bdata[i].f_ion[d] = gkyl_array_new(GKYL_DOUBLE, 10, fine_bdata[i].ext_range.volume); + fine_bdata[i].f_maxwell[d] = gkyl_array_new(GKYL_DOUBLE, 8, fine_bdata[i].ext_range.volume); + } + + fine_bdata[i].app_accel_elc = gkyl_array_new(GKYL_DOUBLE, 3, fine_bdata[i].ext_range.volume); + fine_bdata[i].app_accel_ion = gkyl_array_new(GKYL_DOUBLE, 3, fine_bdata[i].ext_range.volume); + fine_bdata[i].rhs_source_elc = gkyl_array_new(GKYL_DOUBLE, 10, fine_bdata[i].ext_range.volume); + fine_bdata[i].rhs_source_ion = gkyl_array_new(GKYL_DOUBLE, 10, fine_bdata[i].ext_range.volume); + fine_bdata[i].ext_em = gkyl_array_new(GKYL_DOUBLE, 6, fine_bdata[i].ext_range.volume); + fine_bdata[i].app_current = gkyl_array_new(GKYL_DOUBLE, 3, fine_bdata[i].ext_range.volume); + fine_bdata[i].nT_source_elc = gkyl_array_new(GKYL_DOUBLE, 2, fine_bdata[i].ext_range.volume); + fine_bdata[i].nT_source_ion = gkyl_array_new(GKYL_DOUBLE, 2, fine_bdata[i].ext_range.volume); +#endif + } + +#ifdef AMR_USETHREADS + for (int i = 0; i < num_blocks; i++) { + gkyl_job_pool_add_work(coarse_job_pool, five_moment_init_job_func_block, &coarse_bdata[i]); + +#ifdef AMR_DEBUG + gkyl_job_pool_add_work(intermediate_job_pool, five_moment_init_job_func_block, &intermediate_bdata[i]); + gkyl_job_pool_add_work(fine_job_pool, five_moment_init_job_func_block, &fine_bdata[i]); +#endif + } + gkyl_job_pool_wait(coarse_job_pool); + +#ifdef AMR_DEBUG + gkyl_job_pool_wait(intermediate_job_pool); + gkyl_job_pool_wait(fine_job_pool); +#endif +#else + for (int i = 0; i < num_blocks; i++) { + five_moment_init_job_func_block(&coarse_bdata[i]); + +#ifdef AMR_DEBUG + five_moment_init_job_func_block(&intermediate_bdata[i]); + five_moment_init_job_func_block(&fine_bdata[i]); +#endif + } +#endif + +#ifdef AMR_DEBUG + char coarse0[64]; + snprintf(coarse0, 64, "%s_coarse_0", ten_moment_output); + five_moment_write_sol_block(coarse0, num_blocks, coarse_bdata); + + char intermediate0[64]; + snprintf(intermediate0, 64, "%s_intermediate_0", ten_moment_output); + five_moment_write_sol_block(intermediate0, num_blocks, intermediate_bdata); + + char fine0[64]; + snprintf(fine0, 64, "%s_fine_0", ten_moment_output); + five_moment_write_sol_block(fine0, num_blocks, fine_bdata); + + char fine0_elc_b0[64], fine0_ion_b0[64], fine0_field_b0[64]; + char intermediate0_elc_b0[64], intermediate0_ion_b0[64], intermediate0_field_b0[64]; + char coarse0_elc_b0[64], coarse0_ion_b0[64], coarse0_field_b0[64]; + char b0_elc[64], b0_ion[64], b0_field[64]; + + snprintf(fine0_elc_b0, 64, "%s_fine_0_elc_b0.gkyl", ten_moment_output); + snprintf(fine0_ion_b0, 64, "%s_fine_0_ion_b0.gkyl", ten_moment_output); + snprintf(fine0_field_b0, 64, "%s_fine_0_field_b0.gkyl", ten_moment_output); + + snprintf(intermediate0_elc_b0, 64, "%s_intermediate_0_elc_b0.gkyl", ten_moment_output); + snprintf(intermediate0_ion_b0, 64, "%s_intermediate_0_ion_b0.gkyl", ten_moment_output); + snprintf(intermediate0_field_b0, 64, "%s_intermediate_0_field_b0.gkyl", ten_moment_output); + + snprintf(coarse0_elc_b0, 64, "%s_coarse_0_elc_b0.gkyl", ten_moment_output); + snprintf(coarse0_ion_b0, 64, "%s_coarse_0_ion_b0.gkyl", ten_moment_output); + snprintf(coarse0_field_b0, 64, "%s_coarse_0_field_b0.gkyl", ten_moment_output); + + snprintf(b0_elc, 64, "%s_0_elc_b0.gkyl", ten_moment_output); + snprintf(b0_ion, 64, "%s_0_ion_b0.gkyl", ten_moment_output); + snprintf(b0_field, 64, "%s_0_field_b0.gkyl", ten_moment_output); + + rename(fine0_elc_b0, b0_elc); + rename(fine0_ion_b0, b0_ion); + rename(fine0_field_b0, b0_field); + + remove(intermediate0_elc_b0); + remove(intermediate0_ion_b0); + remove(intermediate0_field_b0); + + remove(coarse0_elc_b0); + remove(coarse0_ion_b0); + remove(coarse0_field_b0); + + for (int i = 1; i < 9; i++) { + char fine0_elc_bi[64], fine0_ion_bi[64], fine0_field_bi[64]; + char intermediate0_elc_bi[64], intermediate0_ion_bi[64], intermediate0_field_bi[64]; + char coarse0_elc_bi[64], coarse0_ion_bi[64], coarse0_field_bi[64]; + char elc_bi[64], ion_bi[64], field_bi[64]; + + snprintf(fine0_elc_bi, 64, "%s_fine_0_elc_b%d.gkyl", ten_moment_output, i); + snprintf(fine0_ion_bi, 64, "%s_fine_0_ion_b%d.gkyl", ten_moment_output, i); + snprintf(fine0_field_bi, 64, "%s_fine_0_field_b%d.gkyl", ten_moment_output, i); + + snprintf(intermediate0_elc_bi, 64, "%s_intermediate_0_elc_b%d.gkyl", ten_moment_output, i); + snprintf(intermediate0_ion_bi, 64, "%s_intermediate_0_ion_b%d.gkyl", ten_moment_output, i); + snprintf(intermediate0_field_bi, 64, "%s_intermediate_0_field_b%d.gkyl", ten_moment_output, i); + + snprintf(coarse0_elc_bi, 64, "%s_coarse_0_elc_b%d.gkyl", ten_moment_output, i); + snprintf(coarse0_ion_bi, 64, "%s_coarse_0_ion_b%d.gkyl", ten_moment_output, i); + snprintf(coarse0_field_bi, 64, "%s_coarse_0_field_b%d.gkyl", ten_moment_output, i); + + snprintf(elc_bi, 64, "%s_0_elc_b%d.gkyl", ten_moment_output, i); + snprintf(ion_bi, 64, "%s_0_ion_b%d.gkyl", ten_moment_output, i); + snprintf(field_bi, 64, "%s_0_field_b%d.gkyl", ten_moment_output, i); + + rename(intermediate0_elc_bi, elc_bi); + rename(intermediate0_ion_bi, ion_bi); + rename(intermediate0_field_bi, field_bi); + + remove(fine0_elc_bi); + remove(fine0_ion_bi); + remove(fine0_field_bi); + + remove(coarse0_elc_bi); + remove(coarse0_ion_bi); + remove(coarse0_field_bi); + } + + for (int i = 9; i < 25; i++) { + char buf_old_elc[64], buf_old_ion[64], buf_old_field[64]; + char buf_new_elc[64], buf_new_ion[64], buf_new_field[64]; + char buf_del1_elc[64], buf_del1_ion[64], buf_del1_field[64]; + char buf_del2_elc[64], buf_del2_ion[64], buf_del2_field[64]; + + snprintf(buf_old_elc, 64, "%s_coarse_0_elc_b%d.gkyl", ten_moment_output, i); + snprintf(buf_old_ion, 64, "%s_coarse_0_ion_b%d.gkyl", ten_moment_output, i); + snprintf(buf_old_field, 64, "%s_coarse_0_field_b%d.gkyl", ten_moment_output, i); + + snprintf(buf_new_elc, 64, "%s_0_elc_b%d.gkyl", ten_moment_output, i); + snprintf(buf_new_ion, 64, "%s_0_ion_b%d.gkyl", ten_moment_output, i); + snprintf(buf_new_field, 64, "%s_0_field_b%d.gkyl", ten_moment_output, i); + + snprintf(buf_del1_elc, 64, "%s_intermediate_0_elc_b%d.gkyl", ten_moment_output, i); + snprintf(buf_del1_ion, 64, "%s_intermediate_0_ion_b%d.gkyl", ten_moment_output, i); + snprintf(buf_del1_field, 64, "%s_intermediate_0_field_b%d.gkyl", ten_moment_output, i); + + snprintf(buf_del2_elc, 64, "%s_fine_0_elc_b%d.gkyl", ten_moment_output, i); + snprintf(buf_del2_ion, 64, "%s_fine_0_ion_b%d.gkyl", ten_moment_output, i); + snprintf(buf_del2_field, 64, "%s_fine_0_field_b%d.gkyl", ten_moment_output, i); + + rename(buf_old_elc, buf_new_elc); + rename(buf_old_ion, buf_new_ion); + rename(buf_old_field, buf_new_field); + + remove(buf_del1_elc); + remove(buf_del1_ion); + remove(buf_del1_field); + + remove(buf_del2_elc); + remove(buf_del2_ion); + remove(buf_del2_field); + } +#else + char amr0[64]; + snprintf(amr0, 64, "%s_0", ten_moment_output); + five_moment_write_sol_block(amr0, num_blocks, coarse_bdata); +#endif + + double coarse_t_curr = 0.0; + double intermediate_t_curr = 0.0; + double fine_t_curr = 0.0; + double coarse_dt = five_moment_max_dt_block(num_blocks, coarse_bdata); + +#ifdef AMR_DEBUG + double intermediate_dt = five_moment_max_dt_block(num_blocks, intermediate_bdata); + double fine_dt = five_moment_max_dt_block(num_blocks, fine_bdata); +#else + double intermediate_dt = (1.0 / ref_factor1) * coarse_dt; + double fine_dt = (1.0 / (ref_factor1 * ref_factor2)) * coarse_dt; +#endif + + struct sim_stats stats = { }; + + struct timespec tm_start = gkyl_wall_clock(); + + long coarse_step = 1; + long num_steps = app_args.num_steps; + + double io_trigger = t_end / num_frames; + + double dt_init = -1.0; + int num_failures = 0; + + while ((coarse_t_curr < t_end) && (coarse_step <= num_steps)) { + printf("Taking coarse (level 0) time-step %ld at t = %g; ", coarse_step, coarse_t_curr); + struct gkyl_update_status coarse_status = five_moment_update_block(coarse_job_pool, btopo, coarse_bdata, coarse_t_curr, coarse_dt, &stats); + printf(" dt = %g\n", coarse_status.dt_actual); + + if (!coarse_status.success) { + printf("** Update method failed! Aborting simulation ....\n"); + break; + } + + for (long intermediate_step = 1; intermediate_step < ref_factor1 + 1; intermediate_step++) { +#ifdef AMR_DEBUG + printf(" Taking intermediate (level 1) time-step %ld at t = %g; ", intermediate_step, intermediate_t_curr); + struct gkyl_update_status intermediate_status = five_moment_update_block(intermediate_job_pool, btopo, intermediate_bdata, intermediate_t_curr, intermediate_dt, &stats); + printf(" dt = %g\n", intermediate_status.dt_actual); + + if (!intermediate_status.success) { + printf("** Update method failed! Aborting simulation ....\n"); + break; + } + + for (long fine_step = 1; fine_step < ref_factor2 + 1; fine_step++) { + printf(" Taking fine (level 2) time-step %ld at t = %g", fine_step, fine_t_curr); + struct gkyl_update_status fine_status = five_moment_update_block(fine_job_pool, btopo, fine_bdata, fine_t_curr, fine_dt, &stats); + printf(" dt = %g\n", fine_status.dt_actual); + + if (!fine_status.success) { + printf("** Update method failed! Aborting simulation ....\n"); + break; + } + + fine_t_curr += fine_status.dt_actual; + fine_dt = fine_status.dt_suggested; + } + + intermediate_t_curr += intermediate_status.dt_actual; + intermediate_dt += intermediate_status.dt_suggested; +#else + printf(" Taking intermediate (level 1) time-step %ld at t = %g", intermediate_step, intermediate_t_curr); + printf(" dt = %g\n", (1.0 / ref_factor1) * coarse_status.dt_actual); + + for (long fine_step = 1; fine_step < ref_factor2 + 1; fine_step++) { + printf(" Taking fine (level 2) time-step %ld at t = %g", fine_step, fine_t_curr); + printf(" dt = %g\n", (1.0 / (ref_factor1 * ref_factor2)) * coarse_status.dt_actual); + + fine_t_curr += (1.0 / (ref_factor1 * ref_factor2)) * coarse_status.dt_actual; + fine_dt = (1.0 / (ref_factor1 * ref_factor2)) * coarse_status.dt_suggested; + } + + intermediate_t_curr += (1.0 / ref_factor1) * coarse_status.dt_actual; + intermediate_dt = (1.0 / ref_factor1) * coarse_status.dt_suggested; +#endif + } + + for (int i = 1; i < num_frames; i++) { + if (coarse_t_curr < (i * io_trigger) && (coarse_t_curr + coarse_status.dt_actual) > (i * io_trigger)) { +#ifdef AMR_DEBUG + char buf_coarse[64]; + char buf_intermediate[64]; + char buf_fine[64]; + + snprintf(buf_coarse, 64, "%s_coarse_%d", ten_moment_output, i); + snprintf(buf_intermediate, 64, "%s_intermediate_%d", ten_moment_output, i); + snprintf(buf_fine, 64, "%s_fine_%d", ten_moment_output, i); + + five_moment_write_sol_block(buf_coarse, num_blocks, coarse_bdata); + five_moment_write_sol_block(buf_intermediate, num_blocks, intermediate_bdata); + five_moment_write_sol_block(buf_fine, num_blocks, fine_bdata); + + char buf_fine_old_elc[64], buf_fine_old_ion[64], buf_fine_old_field[64]; + char buf_intermediate_old_elc[64], buf_intermediate_old_ion[64], buf_intermediate_old_field[64]; + char buf_fine_new_elc[64], buf_fine_new_ion[64], buf_fine_new_field[64]; + char buf_coarse_old_elc[64], buf_coarse_old_ion[64], buf_coarse_old_field[64]; + + snprintf(buf_fine_old_elc, 64, "%s_fine_%d_elc_b0.gkyl", ten_moment_output, i); + snprintf(buf_fine_old_ion, 64, "%s_fine_%d_ion_b0.gkyl", ten_moment_output, i); + snprintf(buf_fine_old_field, 64, "%s_fine_%d_field_b0.gkyl", ten_moment_output, i); + + snprintf(buf_intermediate_old_elc, 64, "%s_intermediate_%d_elc_b0.gkyl", ten_moment_output, i); + snprintf(buf_intermediate_old_ion, 64, "%s_intermediate_%d_ion_b0.gkyl", ten_moment_output, i); + snprintf(buf_intermediate_old_field, 64, "%s_intermediate_%d_field_b0.gkyl", ten_moment_output, i); + + snprintf(buf_fine_new_elc, 64, "%s_%d_elc_b0.gkyl", ten_moment_output, i); + snprintf(buf_fine_new_ion, 64, "%s_%d_ion_b0.gkyl", ten_moment_output, i); + snprintf(buf_fine_new_field, 64, "%s_%d_field_b0.gkyl", ten_moment_output, i); + + snprintf(buf_coarse_old_elc, 64, "%s_coarse_%d_elc_b0.gkyl", ten_moment_output, i); + snprintf(buf_coarse_old_ion, 64, "%s_coarse_%d_ion_b0.gkyl", ten_moment_output, i); + snprintf(buf_coarse_old_field, 64, "%s_coarse_%d_field_b0.gkyl", ten_moment_output, i); + + rename(buf_fine_old_elc, buf_fine_new_elc); + rename(buf_fine_old_ion, buf_fine_new_ion); + rename(buf_fine_old_field, buf_fine_new_field); + + remove(buf_intermediate_old_elc); + remove(buf_intermediate_old_ion); + remove(buf_intermediate_old_field); + + remove(buf_coarse_old_elc); + remove(buf_coarse_old_ion); + remove(buf_coarse_old_field); + + for (int j = 1; j < 8; j++) { + char fine0_elc_bi[64], fine0_ion_bi[64], fine0_field_bi[64]; + char intermediate0_elc_bi[64], intermediate0_ion_bi[64], intermediate0_field_bi[64]; + char coarse0_elc_bi[64], coarse0_ion_bi[64], coarse0_field_bi[64]; + char elc_bi[64], ion_bi[64], field_bi[64]; + + snprintf(fine0_elc_bi, 64, "%s_fine_%d_elc_b%d.gkyl", ten_moment_output, i, j); + snprintf(fine0_ion_bi, 64, "%s_fine_%d_ion_b%d.gkyl", ten_moment_output, i, j); + snprintf(fine0_field_bi, 64, "%s_fine_%d_field_b%d.gkyl", ten_moment_output, i, j); + + snprintf(intermediate0_elc_bi, 64, "%s_intermediate_%d_elc_b%d.gkyl", ten_moment_output, i, j); + snprintf(intermediate0_ion_bi, 64, "%s_intermediate_%d_ion_b%d.gkyl", ten_moment_output, i, j); + snprintf(intermediate0_field_bi, 64, "%s_intermediate_%d_field_b%d.gkyl", ten_moment_output, i, j); + + snprintf(coarse0_elc_bi, 64, "%s_coarse_%d_elc_b%d.gkyl", ten_moment_output, i, j); + snprintf(coarse0_ion_bi, 64, "%s_coarse_%d_ion_b%d.gkyl", ten_moment_output, i, j); + snprintf(coarse0_field_bi, 64, "%s_coarse_%d_field_b%d.gkyl", ten_moment_output, i, j); + + snprintf(elc_bi, 64, "%s_%d_elc_b%d.gkyl", ten_moment_output, i, j); + snprintf(ion_bi, 64, "%s_%d_ion_b%d.gkyl", ten_moment_output, i, j); + snprintf(field_bi, 64, "%s_%d_field_b%d.gkyl", ten_moment_output, i, j); + + rename(intermediate0_elc_bi, elc_bi); + rename(intermediate0_ion_bi, ion_bi); + rename(intermediate0_field_bi, field_bi); + + remove(fine0_elc_bi); + remove(fine0_ion_bi); + remove(fine0_field_bi); + + remove(coarse0_elc_bi); + remove(coarse0_ion_bi); + remove(coarse0_field_bi); + } + + for (int j = 9; j < 25; j++) { + char buf_old_elc[64], buf_old_ion[64], buf_old_field[64]; + char buf_new_elc[64], buf_new_ion[64], buf_new_field[64]; + char buf_del1_elc[64], buf_del1_ion[64], buf_del1_field[64]; + char buf_del2_elc[64], buf_del2_ion[64], buf_del2_field[64]; + + snprintf(buf_old_elc, 64, "%s_coarse_%d_elc_b%d.gkyl", ten_moment_output, i, j); + snprintf(buf_old_ion, 64, "%s_coarse_%d_ion_b%d.gkyl", ten_moment_output, i, j); + snprintf(buf_old_field, 64, "%s_coarse_%d_field_b%d.gkyl", ten_moment_output, i, j); + + snprintf(buf_new_elc, 64, "%s_%d_elc_b%d.gkyl", ten_moment_output, i, j); + snprintf(buf_new_ion, 64, "%s_%d_ion_b%d.gkyl", ten_moment_output, i, j); + snprintf(buf_new_field, 64, "%s_%d_field_b%d.gkyl", ten_moment_output, i, j); + + snprintf(buf_del1_elc, 64, "%s_intermediate_%d_elc_b%d.gkyl", ten_moment_output, i, j); + snprintf(buf_del1_ion, 64, "%s_intermediate_%d_ion_b%d.gkyl", ten_moment_output, i, j); + snprintf(buf_del1_field, 64, "%s_intermediate_%d_field_b%d.gkyl", ten_moment_output, i, j); + + snprintf(buf_del2_elc, 64, "%s_fine_%d_elc_b%d.gkyl", ten_moment_output, i, j); + snprintf(buf_del2_ion, 64, "%s_fine_%d_ion_b%d.gkyl", ten_moment_output, i, j); + snprintf(buf_del2_field, 64, "%s_fine_%d_field_b%d.gkyl", ten_moment_output, i, j); + + rename(buf_old_elc, buf_new_elc); + rename(buf_old_ion, buf_new_ion); + rename(buf_old_field, buf_new_field); + + remove(buf_del1_elc); + remove(buf_del1_ion); + remove(buf_del1_field); + + remove(buf_del2_elc); + remove(buf_del2_ion); + remove(buf_del2_field); + } +#else + char buf[64]; + snprintf(buf, 64, "%s_%d", ten_moment_output, i); + + five_moment_write_sol_block(buf, num_blocks, coarse_bdata); +#endif + } + } + + coarse_t_curr += coarse_status.dt_actual; + coarse_dt = coarse_status.dt_suggested; + + if (dt_init < 0.0) { + dt_init = coarse_status.dt_actual; + } + else if (coarse_status.dt_actual < dt_failure_tol * dt_init) { + num_failures += 1; + + printf("WARNING: Time-step dt = %g", coarse_status.dt_actual); + printf(" is below %g*dt_init ...", dt_failure_tol); + printf(" num_failures = %d\n", num_failures); + if (num_failures >= num_failures_max) { + printf("ERROR: Time-step was below %g*dt_init ", dt_failure_tol); + printf("%d consecutive times. Aborting simulation ....\n", num_failures_max); + break; + } + } + else { + num_failures = 0; + } + + coarse_step += 1; + } + + double tm_total_sec = gkyl_time_diff_now_sec(tm_start); + + // TODO: Make file output work correctly in the AMR_DEBUG case. +#ifdef AMR_DEBUG + char buf_coarse[64]; + char buf_intermediate[64]; + char buf_fine[64]; + + snprintf(buf_coarse, 64, "%s_coarse_%d", ten_moment_output, num_frames); + snprintf(buf_intermediate, 64, "%s_intermediate_%d", ten_moment_output, num_frames); + snprintf(buf_fine, 64, "%s_fine_%d", ten_moment_output, num_frames); + + five_moment_write_sol_block(buf_coarse, num_blocks, coarse_bdata); + five_moment_write_sol_block(buf_intermediate, num_blocks, intermediate_bdata); + five_moment_write_sol_block(buf_fine, num_blocks, fine_bdata); + + char buf_fine_old_elc[64], buf_fine_old_ion[64], buf_fine_old_field[64]; + char buf_fine_new_elc[64], buf_fine_new_ion[64], buf_fine_new_field[64]; + char buf_intermediate_old_elc[64], buf_intermediate_old_ion[64], buf_intermediate_old_field[64]; + char buf_coarse_old_elc[64], buf_coarse_old_ion[64], buf_coarse_old_field[64]; + + snprintf(buf_fine_old_elc, 64, "%s_fine_%d_elc_b0.gkyl", ten_moment_output, num_frames); + snprintf(buf_fine_old_ion, 64, "%s_fine_%d_ion_b0.gkyl", ten_moment_output, num_frames); + snprintf(buf_fine_old_field, 64, "%s_fine_%d_field_b0.gkyl", ten_moment_output, num_frames); + + snprintf(buf_fine_new_elc, 64, "%s_%d_elc_b0.gkyl", ten_moment_output, num_frames); + snprintf(buf_fine_new_ion, 64, "%s_%d_ion_b0.gkyl", ten_moment_output, num_frames); + snprintf(buf_fine_new_field, 64, "%s_%d_field_b0.gkyl", ten_moment_output, num_frames); + + snprintf(buf_intermediate_old_elc, 64, "%s_intermediate_%d_elc_b0.gkyl", ten_moment_output, num_frames); + snprintf(buf_intermediate_old_ion, 64, "%s_intermediate_%d_ion_b0.gkyl", ten_moment_output, num_frames); + snprintf(buf_intermediate_old_field, 64, "%s_intermediate_%d_field_b0.gkyl", ten_moment_output, num_frames); + + snprintf(buf_coarse_old_elc, 64, "%s_coarse_%d_elc_b0.gkyl", ten_moment_output, num_frames); + snprintf(buf_coarse_old_ion, 64, "%s_coarse_%d_ion_b0.gkyl", ten_moment_output, num_frames); + snprintf(buf_coarse_old_field, 64, "%s_coarse_%d_field_b0.gkyl", ten_moment_output, num_frames); + + rename(buf_fine_old_elc, buf_fine_new_elc); + rename(buf_fine_old_ion, buf_fine_new_ion); + rename(buf_fine_old_field, buf_fine_new_field); + + remove(buf_intermediate_old_elc); + remove(buf_intermediate_old_ion); + remove(buf_intermediate_old_field); + + remove(buf_coarse_old_elc); + remove(buf_coarse_old_ion); + remove(buf_coarse_old_field); + + for (int i = 1; i < 9; i++) { + char fine0_elc_bi[64], fine0_ion_bi[64], fine0_field_bi[64]; + char intermediate0_elc_bi[64], intermediate0_ion_bi[64], intermediate0_field_bi[64]; + char coarse0_elc_bi[64], coarse0_ion_bi[64], coarse0_field_bi[64]; + char elc_bi[64], ion_bi[64], field_bi[64]; + + snprintf(fine0_elc_bi, 64, "%s_fine_%d_elc_b%d.gkyl", ten_moment_output, num_frames, i); + snprintf(fine0_ion_bi, 64, "%s_fine_%d_ion_b%d.gkyl", ten_moment_output, num_frames, i); + snprintf(fine0_field_bi, 64, "%s_fine_%d_field_b%d.gkyl", ten_moment_output, num_frames, i); + + snprintf(intermediate0_elc_bi, 64, "%s_intermediate_%d_elc_b%d.gkyl", ten_moment_output, num_frames, i); + snprintf(intermediate0_ion_bi, 64, "%s_intermediate_%d_ion_b%d.gkyl", ten_moment_output, num_frames, i); + snprintf(intermediate0_field_bi, 64, "%s_intermediate_%d_field_b%d.gkyl", ten_moment_output, num_frames, i); + + snprintf(coarse0_elc_bi, 64, "%s_coarse_%d_elc_b%d.gkyl", ten_moment_output, num_frames, i); + snprintf(coarse0_ion_bi, 64, "%s_coarse_%d_ion_b%d.gkyl", ten_moment_output, num_frames, i); + snprintf(coarse0_field_bi, 64, "%s_coarse_%d_field_b%d.gkyl", ten_moment_output, num_frames, i); + + snprintf(elc_bi, 64, "%s_%d_elc_b%d.gkyl", ten_moment_output, num_frames, i); + snprintf(ion_bi, 64, "%s_%d_ion_b%d.gkyl", ten_moment_output, num_frames, i); + snprintf(field_bi, 64, "%s_%d_field_b%d.gkyl", ten_moment_output, num_frames, i); + + rename(intermediate0_elc_bi, elc_bi); + rename(intermediate0_ion_bi, ion_bi); + rename(intermediate0_field_bi, field_bi); + + remove(fine0_elc_bi); + remove(fine0_ion_bi); + remove(fine0_field_bi); + + remove(coarse0_elc_bi); + remove(coarse0_ion_bi); + remove(coarse0_field_bi); + } + + for (int i = 9; i < 25; i++) { + char buf_old_elc[64], buf_old_ion[64], buf_old_field[64]; + char buf_new_elc[64], buf_new_ion[64], buf_new_field[64]; + char buf_del1_elc[64], buf_del1_ion[64], buf_del1_field[64]; + char buf_del2_elc[64], buf_del2_ion[64], buf_del2_field[64]; + + snprintf(buf_old_elc, 64, "%s_coarse_%d_elc_b%d.gkyl", ten_moment_output, num_frames, i); + snprintf(buf_old_ion, 64, "%s_coarse_%d_ion_b%d.gkyl", ten_moment_output, num_frames, i); + snprintf(buf_old_field, 64, "%s_coarse_%d_field_b%d.gkyl", ten_moment_output, num_frames, i); + + snprintf(buf_new_elc, 64, "%s_%d_elc_b%d.gkyl", ten_moment_output, num_frames, i); + snprintf(buf_new_ion, 64, "%s_%d_ion_b%d.gkyl", ten_moment_output, num_frames, i); + snprintf(buf_new_field, 64, "%s_%d_field_b%d.gkyl", ten_moment_output, num_frames, i); + + snprintf(buf_del1_elc, 64, "%s_intermediate_%d_elc_b%d.gkyl", ten_moment_output, num_frames, i); + snprintf(buf_del1_ion, 64, "%s_intermediate_%d_ion_b%d.gkyl", ten_moment_output, num_frames, i); + snprintf(buf_del1_field, 64, "%s_intermediate_%d_field_b%d.gkyl", ten_moment_output, num_frames, i); + + snprintf(buf_del2_elc, 64, "%s_fine_%d_elc_b%d.gkyl", ten_moment_output, num_frames, i); + snprintf(buf_del2_ion, 64, "%s_fine_%d_ion_b%d.gkyl", ten_moment_output, num_frames, i); + snprintf(buf_del2_field, 64, "%s_fine_%d_field_b%d.gkyl", ten_moment_output, num_frames, i); + + rename(buf_old_elc, buf_new_elc); + rename(buf_old_ion, buf_new_ion); + rename(buf_old_field, buf_new_field); + + remove(buf_del1_elc); + remove(buf_del1_ion); + remove(buf_del1_field); + + remove(buf_del2_elc); + remove(buf_del2_ion); + remove(buf_del2_field); + } +#else + char buf[64]; + snprintf(buf, 64, "%s_%d", ten_moment_output, num_frames); + + five_moment_write_sol_block(buf, num_blocks, coarse_bdata); +#endif + + printf("Total run-time: %g. Failed steps: %d\n", tm_total_sec, stats.nfail); + + for (int i = 0; i < num_blocks; i++) { + gkyl_fv_proj_release(coarse_bdata[i].fv_proj_elc); + gkyl_fv_proj_release(coarse_bdata[i].fv_proj_ion); + gkyl_fv_proj_release(coarse_bdata[i].fv_proj_maxwell); + + gkyl_wv_eqn_release(coarse_bdata[i].euler_elc); + gkyl_wv_eqn_release(coarse_bdata[i].euler_ion); + gkyl_wv_eqn_release(coarse_bdata[i].maxwell); + + five_moment_block_bc_updaters_release(&coarse_bdata[i]); + gkyl_wave_geom_release(coarse_bdata[i].geom); + +#ifdef AMR_DEBUG + gkyl_fv_proj_release(intermediate_bdata[i].fv_proj_elc); + gkyl_fv_proj_release(intermediate_bdata[i].fv_proj_ion); + gkyl_fv_proj_release(intermediate_bdata[i].fv_proj_maxwell); + + gkyl_wv_eqn_release(intermediate_bdata[i].euler_elc); + gkyl_wv_eqn_release(intermediate_bdata[i].euler_ion); + gkyl_wv_eqn_release(intermediate_bdata[i].maxwell); + + five_moment_block_bc_updaters_release(&intermediate_bdata[i]); + gkyl_wave_geom_release(intermediate_bdata[i].geom); + + gkyl_fv_proj_release(fine_bdata[i].fv_proj_elc); + gkyl_fv_proj_release(fine_bdata[i].fv_proj_ion); + gkyl_fv_proj_release(fine_bdata[i].fv_proj_maxwell); + + gkyl_wv_eqn_release(fine_bdata[i].euler_elc); + gkyl_wv_eqn_release(fine_bdata[i].euler_ion); + gkyl_wv_eqn_release(fine_bdata[i].maxwell); + + five_moment_block_bc_updaters_release(&fine_bdata[i]); + gkyl_wave_geom_release(fine_bdata[i].geom); +#endif + + for (int d = 0; d < ndim; d++) { + gkyl_wave_prop_release(coarse_bdata[i].slvr_elc[d]); + gkyl_wave_prop_release(coarse_bdata[i].slvr_ion[d]); + gkyl_wave_prop_release(coarse_bdata[i].slvr_maxwell[d]); + +#ifdef AMR_DEBUG + gkyl_wave_prop_release(intermediate_bdata[i].slvr_elc[d]); + gkyl_wave_prop_release(intermediate_bdata[i].slvr_ion[d]); + gkyl_wave_prop_release(intermediate_bdata[i].slvr_maxwell[d]); + + gkyl_wave_prop_release(fine_bdata[i].slvr_elc[d]); + gkyl_wave_prop_release(fine_bdata[i].slvr_ion[d]); + gkyl_wave_prop_release(fine_bdata[i].slvr_maxwell[d]); +#endif + } + + gkyl_array_release(coarse_bdata[i].fdup_elc); + gkyl_array_release(coarse_bdata[i].fdup_ion); + gkyl_array_release(coarse_bdata[i].fdup_maxwell); + +#ifdef AMR_DEBUG + gkyl_array_release(intermediate_bdata[i].fdup_elc); + gkyl_array_release(intermediate_bdata[i].fdup_ion); + gkyl_array_release(intermediate_bdata[i].fdup_maxwell); + + gkyl_array_release(fine_bdata[i].fdup_elc); + gkyl_array_release(fine_bdata[i].fdup_ion); + gkyl_array_release(fine_bdata[i].fdup_maxwell); +#endif + + for(int d = 0; d < ndim; d++) { + gkyl_array_release(coarse_bdata[i].f_elc[d]); + gkyl_array_release(coarse_bdata[i].f_ion[d]); + gkyl_array_release(coarse_bdata[i].f_maxwell[d]); + +#ifdef AMR_DEBUG + gkyl_array_release(intermediate_bdata[i].f_elc[d]); + gkyl_array_release(intermediate_bdata[i].f_ion[d]); + gkyl_array_release(intermediate_bdata[i].f_maxwell[d]); + + gkyl_array_release(fine_bdata[i].f_elc[d]); + gkyl_array_release(fine_bdata[i].f_ion[d]); + gkyl_array_release(fine_bdata[i].f_maxwell[d]); +#endif + } + + gkyl_array_release(coarse_bdata[i].app_accel_elc); + gkyl_array_release(coarse_bdata[i].app_accel_ion); + gkyl_array_release(coarse_bdata[i].rhs_source_elc); + gkyl_array_release(coarse_bdata[i].rhs_source_ion); + gkyl_array_release(coarse_bdata[i].ext_em); + gkyl_array_release(coarse_bdata[i].app_current); + gkyl_array_release(coarse_bdata[i].nT_source_elc); + gkyl_array_release(coarse_bdata[i].nT_source_ion); + +#ifdef AMR_DEBUG + gkyl_array_release(intermediate_bdata[i].app_accel_elc); + gkyl_array_release(intermediate_bdata[i].app_accel_ion); + gkyl_array_release(intermediate_bdata[i].rhs_source_elc); + gkyl_array_release(intermediate_bdata[i].rhs_source_ion); + gkyl_array_release(intermediate_bdata[i].ext_em); + gkyl_array_release(intermediate_bdata[i].app_current); + gkyl_array_release(intermediate_bdata[i].nT_source_elc); + gkyl_array_release(intermediate_bdata[i].nT_source_ion); + + gkyl_array_release(fine_bdata[i].app_accel_elc); + gkyl_array_release(fine_bdata[i].app_accel_ion); + gkyl_array_release(fine_bdata[i].rhs_source_elc); + gkyl_array_release(fine_bdata[i].rhs_source_ion); + gkyl_array_release(fine_bdata[i].ext_em); + gkyl_array_release(fine_bdata[i].app_current); + gkyl_array_release(fine_bdata[i].nT_source_elc); + gkyl_array_release(fine_bdata[i].nT_source_ion); +#endif + } + + gkyl_block_topo_release(btopo); + gkyl_job_pool_release(coarse_job_pool); +#ifdef AMR_DEBUG + gkyl_job_pool_release(intermediate_job_pool); + gkyl_job_pool_release(fine_job_pool); +#endif } \ No newline at end of file diff --git a/amr/gkyl_amr_block_coupled_priv.h b/amr/gkyl_amr_block_coupled_priv.h index de089019b..b132759b9 100644 --- a/amr/gkyl_amr_block_coupled_priv.h +++ b/amr/gkyl_amr_block_coupled_priv.h @@ -186,6 +186,14 @@ void five_moment_nested_block_bc_updaters_init(struct five_moment_block_data* bd */ void ten_moment_block_bc_updaters_init(struct five_moment_block_data* bdata, const struct gkyl_block_connections* conn); +/** +* Initialize nested block AMR updaters for both physical (outer-block) and non-physical (inter-block) boundary conditions for the coupled ten-moment equations. +* +* @param bdata Block-structured data for the coupled ten-moment equations. +* @param conn Topology/connectivity data for the block hierarchy. +*/ +void ten_moment_nested_block_bc_updaters_init(struct five_moment_block_data* bdata, const struct gkyl_block_connections* conn); + /** * Release block AMR updaters for both physical (outer-block) and non-physical (inter-block) boundary conditions for the coupled five-moment equations. * diff --git a/amr/gkyl_amr_core.h b/amr/gkyl_amr_core.h index 678a0e2ea..da96d982d 100644 --- a/amr/gkyl_amr_core.h +++ b/amr/gkyl_amr_core.h @@ -476,4 +476,70 @@ struct five_moment_2d_double_init { * @param argv Array of command line arguments passed to the function. * @param init Initialization data for the 2D coupled five-moment equations. */ -void five_moment_2d_run_double(int argc, char **argv, struct five_moment_2d_double_init* init); \ No newline at end of file +void five_moment_2d_run_double(int argc, char **argv, struct five_moment_2d_double_init* init); + +// Initialization data for a 2D simulation using the coupled ten-moment equations, run with static, block-structured mesh refinement with a doubly-nested refinement patch. +struct ten_moment_2d_double_init { + int base_Nx; + int base_Ny; + int ref_factor1; + int ref_factor2; + + double coarse_x1; + double coarse_y1; + double coarse_x2; + double coarse_y2; + + double intermediate_x1; + double intermediate_y1; + double intermediate_x2; + double intermediate_y2; + + double refined_x1; + double refined_y1; + double refined_x2; + double refined_y2; + + evalf_t eval_elc; + evalf_t eval_ion; + evalf_t eval_field; + + double gas_gamma; + double k0_elc; + double k0_ion; + + double light_speed; + double e_fact; + double b_fact; + + double epsilon0; + double mass_elc; + double charge_elc; + double mass_ion; + double charge_ion; + + bool transmissive_x; + bool transmissive_y; + + bool wall_x; + bool wall_y; + + char ten_moment_output[32]; + + bool low_order_flux; + double cfl_frac; + + double t_end; + int num_frames; + double dt_failure_tol; + int num_failures_max; +}; + +/** +* Run a 2D simulation using the coupled ten-moment equations, with static, block-structured mesh refinement with a doubly-nested refinement patch. +* +* @param argc Number of command line arguments passed to the function. +* @param argv Array of command line arguments passed to the function. +* @param init Initialization data for the 2D coupled ten-moment equations. +*/ +void ten_moment_2d_run_double(int argc, char **argv, struct ten_moment_2d_double_init* init); \ No newline at end of file diff --git a/regression/rt_amr_10m_gem.c b/regression/rt_amr_10m_gem_l1.c similarity index 100% rename from regression/rt_amr_10m_gem.c rename to regression/rt_amr_10m_gem_l1.c diff --git a/regression/rt_amr_10m_gem_l2.c b/regression/rt_amr_10m_gem_l2.c new file mode 100644 index 000000000..8cbd005f2 --- /dev/null +++ b/regression/rt_amr_10m_gem_l2.c @@ -0,0 +1,307 @@ +// Geospace Environmental Modeling (GEM) magnetic reconnection test, using static, block-structured mesh refinement with doubly-nested refinement blocks (2x2x refinement), for the 10-moment equations. +// Input parameters match the equilibrium and initial conditions in Section 2, from the article: +// J. Birn et al. (2001), "Geospace Environmental Modeling (GEM) Magnetic Reconnection Challenge", +// Journal of Geophysical Research: Space Physics, Volume 106 (A3): 3715-3719. +// https://agupubs.onlinelibrary.wiley.com/doi/10.1029/1999JA900449 + +#include + +struct amr_10m_gem_ctx +{ + // Mathematical constants (dimensionless). + double pi; + + // Physical constants (using normalized code units). + double epsilon0; // Permittivity of free space. + double mu0; // Permeability of free space. + double mass_ion; // Ion mass. + double charge_ion; // Ion charge. + double mass_elc; // Electron mass. + double charge_elc; // Electron charge. + double Ti_over_Te; // Ion temperature / electron temperature. + double lambda; // Wavelength. + double n0; // Reference number density. + double nb_over_n0; // Background number density / reference number density. + double B0; // Reference magnetic field strength. + double beta; // Plasma beta. + + double k0_elc; // Electron closure parameter. + double k0_ion; // Ion closure parameter. + + // Derived physical quantities (using normalized code units). + double psi0; // Reference magnetic scalar potential. + + double Ti_frac; // Fraction of total temperature from ions. + double Te_frac; // Fraction of total temperature from electrons. + double T_tot; // Total temperature. + + // Simulation parameters. + int Nx; // Coarse cell count (x-direction). + int Ny; // Coarse cell count (y-direction). + int ref_factor1; // First refinement factor. + int ref_factor2; // Second refinement factor. + double Lx; // Coarse domain size (x-direction). + double Ly; // Coarse domain size (y-direction). + double intermediate_Lx; // Intermediate domain size (x-direction). + double intermediate_Ly; // Intermediate domain size (y-direction). + double fine_Lx; // Fine domain size (x-direction). + double fine_Ly; // Fine domain size (y-direction). + double cfl_frac; // CFL coefficient. + + double t_end; // Final simulation time. + int num_frames; // Number of output frames. + double dt_failure_tol; // Minimum allowable fraction of initial time-step. + int num_failures_max; // Maximum allowable number of consecutive small time-steps. +}; + +struct amr_10m_gem_ctx +create_ctx(void) +{ + // Mathematical constants (dimensionless). + double pi = M_PI; + + // Physical constants (using normalized code units). + double epsilon0 = 1.0; // Permittivity of free space. + double mu0 = 1.0; // Permeability of free space. + double mass_ion = 1.0; // Ion mass. + double charge_ion = 1.0; // Ion charge. + double mass_elc = 1.0 / 25.0; // Electron mass. + double charge_elc = -1.0; // Electron charge. + double Ti_over_Te = 5.0; // Ion temperature / electron temperature. + double lambda = 0.5; // Wavelength + double n0 = 1.0; // Reference number density. + double nb_over_n0 = 0.2; // Background number density / reference number density. + double B0 = 0.1; // Reference magnetic field strength. + double beta = 1.0; // Plasma beta. + + double k0_elc = 5.0; // Electron closure parameter. + double k0_ion = 5.0; // Ion closure parameter. + + // Derived physical quantities (using normalized code units). + double psi0 = 0.1 * B0; // Reference magnetic scalar potential. + + double Ti_frac = Ti_over_Te / (1.0 + Ti_over_Te); // Fraction of total temperature from ions. + double Te_frac = 1.0 / (1.0 + Ti_over_Te); // Fraction of total temperature from electrons. + double T_tot = beta * (B0 * B0) / 2.0 / n0; // Total temperature; + + // Simulation parameters. + int Nx = 32; // Coarse cell count (x-direction). + int Ny = 16; // Coarse cell count (y-direction). + int ref_factor1 = 2; // First refinement factor. + int ref_factor2 = 2; // Second refinement factor. + double Lx = 25.6; // Coarse domain size (x-direction). + double Ly = 12.8; // Coarse domain size (y-direction). + double intermediate_Lx = 20.6; // Intermediate domain size (x-direction). + double intermediate_Ly = 9.8; // Intermediate domain size (y-direction). + double fine_Lx = 10.6; // Fine domain size (x-direction). + double fine_Ly = 3.8; // Fine domain size (y-direction). + double cfl_frac = 0.95; // CFL coefficient. + + double t_end = 250.0; // Final simulation time. + int num_frames = 1; // Number of output frames. + double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. + int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. + + struct amr_10m_gem_ctx ctx = { + .pi = pi, + .epsilon0 = epsilon0, + .mu0 = mu0, + .mass_ion = mass_ion, + .charge_ion = charge_ion, + .mass_elc = mass_elc, + .charge_elc = charge_elc, + .Ti_over_Te = Ti_over_Te, + .lambda = lambda, + .n0 = n0, + .nb_over_n0 = nb_over_n0, + .B0 = B0, + .beta = beta, + .k0_elc = k0_elc, + .k0_ion = k0_ion, + .psi0 = psi0, + .Ti_frac = Ti_frac, + .Te_frac = Te_frac, + .T_tot = T_tot, + .Nx = Nx, + .Ny = Ny, + .ref_factor1 = ref_factor1, + .ref_factor2 = ref_factor2, + .Lx = Lx, + .Ly = Ly, + .intermediate_Lx = intermediate_Lx, + .intermediate_Ly = intermediate_Ly, + .fine_Lx = fine_Lx, + .fine_Ly = fine_Ly, + .cfl_frac = cfl_frac, + .t_end = t_end, + .num_frames = num_frames, + .dt_failure_tol = dt_failure_tol, + .num_failures_max = num_failures_max, + }; + + return ctx; +} + +void +evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +{ + double x = xn[0], y = xn[1]; + struct amr_10m_gem_ctx new_ctx = create_ctx(); // Context for initialization functions. + struct amr_10m_gem_ctx *app = &new_ctx; + + double mass_elc = app->mass_elc; + double charge_elc = app->charge_elc; + double lambda = app->lambda; + double n0 = app->n0; + double nb_over_n0 = app->nb_over_n0; + double B0 = app->B0; + double beta = app->beta; + + double Te_frac = app->Te_frac; + double T_tot = app->T_tot; + + double sech_sq = (1.0 / cosh(y / lambda)) * (1.0 / cosh(y / lambda)); // Hyperbolic secant squared. + + double n = n0 * (sech_sq + nb_over_n0); // Total number density. + double Jz = -(B0 / lambda) * sech_sq; // Total current density (z-direction). + + double rhoe = n * mass_elc; // Electron mass density. + double momze = (mass_elc / charge_elc) * Jz * Te_frac; // Electron momentum density (z-direction). + double pre = n * T_tot * Te_frac; // Electron pressure (scalar). + + // Set electron mass density. + fout[0] = rhoe; + // Set electron momentum density. + fout[1] = 0.0; fout[2] = 0.0; fout[3] = momze; + // Set electron pressure tensor. + fout[4] = pre; fout[5] = 0.0; fout[6] = 0.0; + fout[7] = pre; fout[8] = 0.0; fout[9] = pre + momze * momze / rhoe; +} + +void +evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +{ + double x = xn[0], y = xn[1]; + struct amr_10m_gem_ctx new_ctx = create_ctx(); // Context for initialization functions. + struct amr_10m_gem_ctx *app = &new_ctx; + + double mass_ion = app->mass_ion; + double charge_ion = app->charge_ion; + double lambda = app->lambda; + double n0 = app->n0; + double nb_over_n0 = app->nb_over_n0; + double B0 = app->B0; + double beta = app->beta; + + double Ti_frac = app->Ti_frac; + double T_tot = app->T_tot; + + double sech_sq = (1.0 / cosh(y / lambda)) * (1.0 / cosh(y / lambda)); // Hyperbolic secant squared. + + double n = n0 * (sech_sq + nb_over_n0); // Total number density. + double Jz = -(B0 / lambda) * sech_sq; // Total current density (z-direction). + + double rhoi = n * mass_ion; // Ion mass density. + double momzi = (mass_ion / charge_ion) * Jz * Ti_frac; // Ion momentum density (z-direction). + double pri = n * T_tot * Ti_frac; // Ion pressure (scalar). + + // Set ion mass density. + fout[0] = rhoi; + // Set ion momentum density. + fout[1] = 0.0; fout[2] = 0.0; fout[3] = momzi; + // Set ion pressure tensor. + fout[4] = pri; fout[5] = 0.0; fout[6] = 0.0; + fout[7] = pri; fout[8] = 0.0; fout[9] = pri + momzi * momzi / rhoi; +} + +void +evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +{ + double x = xn[0], y = xn[1]; + struct amr_10m_gem_ctx new_ctx = create_ctx(); // Context for initialization functions. + struct amr_10m_gem_ctx *app = &new_ctx; + + double pi = app->pi; + + double lambda = app->lambda; + double B0 = app->B0; + + double psi0 = app->psi0; + + double Lx = app->Lx; + double Ly = app->Ly; + + double Bxb = B0 * tanh(y / lambda); // Total magnetic field strength. + double Bx = Bxb - psi0 * (pi / Ly) * cos(2.0 * pi * x / Lx) * sin(pi * y / Ly); // Total magnetic field (x-direction). + double By = psi0 * (2.0 * pi / Lx) * sin(2.0 * pi * x / Lx) * cos(pi * y / Ly); // Total magnetic field (y-direction). + double Bz = 0.0; // Total magnetic field (z-direction). + + // Set electric field. + fout[0] = 0.0, fout[1] = 0.0; fout[2] = 0.0; + // Set magnetic field. + fout[3] = Bx, fout[4] = By; fout[5] = Bz; + // Set correction potentials. + fout[6] = 0.0; fout[7] = 0.0; +} + +int main(int argc, char **argv) +{ + struct amr_10m_gem_ctx ctx = create_ctx(); // Context for initialization functions. + + struct ten_moment_2d_double_init init = { + .base_Nx = ctx.Nx, + .base_Ny = ctx.Ny, + .ref_factor1 = ctx.ref_factor1, + .ref_factor2 = ctx.ref_factor2, + + .coarse_x1 = -0.5 * ctx.Lx, + .coarse_y1 = -0.5 * ctx.Ly, + .coarse_x2 = 0.5 * ctx.Lx, + .coarse_y2 = 0.5 * ctx.Ly, + + .intermediate_x1 = -0.5 * ctx.intermediate_Lx, + .intermediate_y1 = -0.5 * ctx.intermediate_Ly, + .intermediate_x2 = 0.5 * ctx.intermediate_Lx, + .intermediate_y2 = 0.5 * ctx.intermediate_Ly, + + .refined_x1 = -0.5 * ctx.fine_Lx, + .refined_y1 = -0.5 * ctx.fine_Ly, + .refined_x2 = 0.5 * ctx.fine_Lx, + .refined_y2 = 0.5 * ctx.fine_Ly, + + .eval_elc = evalElcInit, + .eval_ion = evalIonInit, + .eval_field = evalFieldInit, + + .k0_elc = ctx.k0_elc, + .k0_ion = ctx.k0_ion, + + .light_speed = 1.0, + .e_fact = 0.0, + .b_fact = 1.0, + + .epsilon0 = ctx.epsilon0, + .mass_elc = ctx.mass_elc, + .charge_elc = ctx.charge_elc, + .mass_ion = ctx.mass_ion, + .charge_ion = ctx.charge_ion, + + .transmissive_x = true, + .transmissive_y = false, + + .wall_x = false, + .wall_y = true, + + .ten_moment_output = "amr_10m_gem_l2", + + .low_order_flux = false, + .cfl_frac = ctx.cfl_frac, + + .t_end = ctx.t_end, + .num_frames = ctx.num_frames, + .dt_failure_tol = ctx.dt_failure_tol, + .num_failures_max = ctx.num_failures_max, + }; + + ten_moment_2d_run_double(argc, argv, &init); +} \ No newline at end of file From 357875211cad4169b9dde4c71a85e3fe3b138aa5 Mon Sep 17 00:00:00 2001 From: JonathanGorard Date: Tue, 25 Jun 2024 08:50:55 -0400 Subject: [PATCH 06/32] General cleanup of patch- and block-coupled AMR code (especially file output in AMR_DEBUG mode). --- amr/amr_core_five_moment.c | 140 ++++++++----------------------------- amr/amr_core_ten_moment.c | 140 ++++++++----------------------------- 2 files changed, 60 insertions(+), 220 deletions(-) diff --git a/amr/amr_core_five_moment.c b/amr/amr_core_five_moment.c index 643b55358..44c7c9fce 100644 --- a/amr/amr_core_five_moment.c +++ b/amr/amr_core_five_moment.c @@ -346,17 +346,9 @@ five_moment_1d_run_single(int argc, char **argv, struct five_moment_1d_single_in remove(coarse0_field_p0); for (int i = 1; i < 3; i++) { - char buf_old_elc[64]; - char buf_old_ion[64]; - char buf_old_field[64]; - - char buf_new_elc[64]; - char buf_new_ion[64]; - char buf_new_field[64]; - - char buf_del_elc[64]; - char buf_del_ion[64]; - char buf_del_field[64]; + char buf_old_elc[64], buf_old_ion[64], buf_old_field[64]; + char buf_new_elc[64], buf_new_ion[64], buf_new_field[64]; + char buf_del_elc[64], buf_del_ion[64], buf_del_field[64]; snprintf(buf_old_elc, 64, "%s_coarse_0_elc_p%d.gkyl", five_moment_output, i); snprintf(buf_old_ion, 64, "%s_coarse_0_ion_p%d.gkyl", five_moment_output, i); @@ -450,17 +442,9 @@ five_moment_1d_run_single(int argc, char **argv, struct five_moment_1d_single_in five_moment_write_sol_patch(buf_coarse, num_patches, coarse_pdata); five_moment_write_sol_patch(buf_fine, num_patches, fine_pdata); - char buf_fine_old_elc[64]; - char buf_fine_old_ion[64]; - char buf_fine_old_field[64]; - - char buf_fine_new_elc[64]; - char buf_fine_new_ion[64]; - char buf_fine_new_field[64]; - - char buf_coarse_old_elc[64]; - char buf_coarse_old_ion[64]; - char buf_coarse_old_field[64]; + char buf_fine_old_elc[64], buf_fine_old_ion[64], buf_fine_old_field[64]; + char buf_fine_new_elc[64], buf_fine_new_ion[64], buf_fine_new_field[64]; + char buf_coarse_old_elc[64], buf_coarse_old_ion[64], buf_coarse_old_field[64]; snprintf(buf_fine_old_elc, 64, "%s_fine_%d_elc_p0.gkyl", five_moment_output, i); snprintf(buf_fine_old_ion, 64, "%s_fine_%d_ion_p0.gkyl", five_moment_output, i); @@ -483,17 +467,9 @@ five_moment_1d_run_single(int argc, char **argv, struct five_moment_1d_single_in remove(buf_coarse_old_field); for (int j = 1; j < 3; j++) { - char buf_old_elc[64]; - char buf_old_ion[64]; - char buf_old_field[64]; - - char buf_new_elc[64]; - char buf_new_ion[64]; - char buf_new_field[64]; - - char buf_del_elc[64]; - char buf_del_ion[64]; - char buf_del_field[64]; + char buf_old_elc[64], buf_old_ion[64], buf_old_field[64]; + char buf_new_elc[64], buf_new_ion[64], buf_new_field[64]; + char buf_del_elc[64], buf_del_ion[64], buf_del_field[64]; snprintf(buf_old_elc, 64, "%s_coarse_%d_elc_p%d.gkyl", five_moment_output, i, j); snprintf(buf_old_ion, 64, "%s_coarse_%d_ion_p%d.gkyl", five_moment_output, i, j); @@ -561,17 +537,9 @@ five_moment_1d_run_single(int argc, char **argv, struct five_moment_1d_single_in five_moment_write_sol_patch(buf_coarse, num_patches, coarse_pdata); five_moment_write_sol_patch(buf_fine, num_patches, fine_pdata); - char buf_fine_old_elc[64]; - char buf_fine_old_ion[64]; - char buf_fine_old_field[64]; - - char buf_fine_new_elc[64]; - char buf_fine_new_ion[64]; - char buf_fine_new_field[64]; - - char buf_coarse_old_elc[64]; - char buf_coarse_old_ion[64]; - char buf_coarse_old_field[64]; + char buf_fine_old_elc[64], buf_fine_old_ion[64], buf_fine_old_field[64]; + char buf_fine_new_elc[64], buf_fine_new_ion[64], buf_fine_new_field[64]; + char buf_coarse_old_elc[64], buf_coarse_old_ion[64], buf_coarse_old_field[64]; snprintf(buf_fine_old_elc, 64, "%s_fine_%d_elc_p0.gkyl", five_moment_output, num_frames); snprintf(buf_fine_old_ion, 64, "%s_fine_%d_ion_p0.gkyl", five_moment_output, num_frames); @@ -594,17 +562,9 @@ five_moment_1d_run_single(int argc, char **argv, struct five_moment_1d_single_in remove(buf_coarse_old_field); for (int i = 1; i < 3; i++) { - char buf_old_elc[64]; - char buf_old_ion[64]; - char buf_old_field[64]; - - char buf_new_elc[64]; - char buf_new_ion[64]; - char buf_new_field[64]; - - char buf_del_elc[64]; - char buf_del_ion[64]; - char buf_del_field[64]; + char buf_old_elc[64], buf_old_ion[64], buf_old_field[64]; + char buf_new_elc[64], buf_new_ion[64], buf_new_field[64]; + char buf_del_elc[64], buf_del_ion[64], buf_del_field[64]; snprintf(buf_old_elc, 64, "%s_coarse_%d_elc_p%d.gkyl", five_moment_output, num_frames, i); snprintf(buf_old_ion, 64, "%s_coarse_%d_ion_p%d.gkyl", five_moment_output, num_frames, i); @@ -1118,17 +1078,9 @@ five_moment_2d_run_single(int argc, char **argv, struct five_moment_2d_single_in remove(coarse0_field_b0); for (int i = 1; i < 9; i++) { - char buf_old_elc[64]; - char buf_old_ion[64]; - char buf_old_field[64]; - - char buf_new_elc[64]; - char buf_new_ion[64]; - char buf_new_field[64]; - - char buf_del_elc[64]; - char buf_del_ion[64]; - char buf_del_field[64]; + char buf_old_elc[64], buf_old_ion[64], buf_old_field[64]; + char buf_new_elc[64], buf_new_ion[64], buf_new_field[64]; + char buf_del_elc[64], buf_del_ion[64], buf_del_field[64]; snprintf(buf_old_elc, 64, "%s_coarse_0_elc_b%d.gkyl", five_moment_output, i); snprintf(buf_old_ion, 64, "%s_coarse_0_ion_b%d.gkyl", five_moment_output, i); @@ -1222,17 +1174,9 @@ five_moment_2d_run_single(int argc, char **argv, struct five_moment_2d_single_in five_moment_write_sol_block(buf_coarse, num_blocks, coarse_bdata); five_moment_write_sol_block(buf_fine, num_blocks, fine_bdata); - char buf_fine_old_elc[64]; - char buf_fine_old_ion[64]; - char buf_fine_old_field[64]; - - char buf_fine_new_elc[64]; - char buf_fine_new_ion[64]; - char buf_fine_new_field[64]; - - char buf_coarse_old_elc[64]; - char buf_coarse_old_ion[64]; - char buf_coarse_old_field[64]; + char buf_fine_old_elc[64], buf_fine_old_ion[64], buf_fine_old_field[64]; + char buf_fine_new_elc[64], buf_fine_new_ion[64], buf_fine_new_field[64]; + char buf_coarse_old_elc[64], buf_coarse_old_ion[64], buf_coarse_old_field[64]; snprintf(buf_fine_old_elc, 64, "%s_fine_%d_elc_b0.gkyl", five_moment_output, i); snprintf(buf_fine_old_ion, 64, "%s_fine_%d_ion_b0.gkyl", five_moment_output, i); @@ -1255,17 +1199,9 @@ five_moment_2d_run_single(int argc, char **argv, struct five_moment_2d_single_in remove(buf_coarse_old_field); for (int j = 1; j < 9; j++) { - char buf_old_elc[64]; - char buf_old_ion[64]; - char buf_old_field[64]; - - char buf_new_elc[64]; - char buf_new_ion[64]; - char buf_new_field[64]; - - char buf_del_elc[64]; - char buf_del_ion[64]; - char buf_del_field[64]; + char buf_old_elc[64], buf_old_ion[64], buf_old_field[64]; + char buf_new_elc[64], buf_new_ion[64], buf_new_field[64]; + char buf_del_elc[64], buf_del_ion[64], buf_del_field[64]; snprintf(buf_old_elc, 64, "%s_coarse_%d_elc_b%d.gkyl", five_moment_output, i, j); snprintf(buf_old_ion, 64, "%s_coarse_%d_ion_b%d.gkyl", five_moment_output, i, j); @@ -1333,17 +1269,9 @@ five_moment_2d_run_single(int argc, char **argv, struct five_moment_2d_single_in five_moment_write_sol_block(buf_coarse, num_blocks, coarse_bdata); five_moment_write_sol_block(buf_fine, num_blocks, fine_bdata); - char buf_fine_old_elc[64]; - char buf_fine_old_ion[64]; - char buf_fine_old_field[64]; - - char buf_fine_new_elc[64]; - char buf_fine_new_ion[64]; - char buf_fine_new_field[64]; - - char buf_coarse_old_elc[64]; - char buf_coarse_old_ion[64]; - char buf_coarse_old_field[64]; + char buf_fine_old_elc[64], buf_fine_old_ion[64], buf_fine_old_field[64]; + char buf_fine_new_elc[64], buf_fine_new_ion[64], buf_fine_new_field[64]; + char buf_coarse_old_elc[64], buf_coarse_old_ion[64], buf_coarse_old_field[64]; snprintf(buf_fine_old_elc, 64, "%s_fine_%d_elc_b0.gkyl", five_moment_output, num_frames); snprintf(buf_fine_old_ion, 64, "%s_fine_%d_ion_b0.gkyl", five_moment_output, num_frames); @@ -1366,17 +1294,9 @@ five_moment_2d_run_single(int argc, char **argv, struct five_moment_2d_single_in remove(buf_coarse_old_field); for (int i = 1; i < 9; i++) { - char buf_old_elc[64]; - char buf_old_ion[64]; - char buf_old_field[64]; - - char buf_new_elc[64]; - char buf_new_ion[64]; - char buf_new_field[64]; - - char buf_del_elc[64]; - char buf_del_ion[64]; - char buf_del_field[64]; + char buf_old_elc[64], buf_old_ion[64], buf_old_field[64]; + char buf_new_elc[64], buf_new_ion[64], buf_new_field[64]; + char buf_del_elc[64], buf_del_ion[64], buf_del_field[64]; snprintf(buf_old_elc, 64, "%s_coarse_%d_elc_b%d.gkyl", five_moment_output, num_frames, i); snprintf(buf_old_ion, 64, "%s_coarse_%d_ion_b%d.gkyl", five_moment_output, num_frames, i); diff --git a/amr/amr_core_ten_moment.c b/amr/amr_core_ten_moment.c index e7356112c..b71feb172 100644 --- a/amr/amr_core_ten_moment.c +++ b/amr/amr_core_ten_moment.c @@ -323,17 +323,9 @@ ten_moment_1d_run_single(int argc, char **argv, struct ten_moment_1d_single_init remove(coarse0_field_p0); for (int i = 1; i < 3; i++) { - char buf_old_elc[64]; - char buf_old_ion[64]; - char buf_old_field[64]; - - char buf_new_elc[64]; - char buf_new_ion[64]; - char buf_new_field[64]; - - char buf_del_elc[64]; - char buf_del_ion[64]; - char buf_del_field[64]; + char buf_old_elc[64], buf_old_ion[64], buf_old_field[64]; + char buf_new_elc[64], buf_new_ion[64], buf_new_field[64]; + char buf_del_elc[64], buf_del_ion[64], buf_del_field[64]; snprintf(buf_old_elc, 64, "%s_coarse_0_elc_p%d.gkyl", ten_moment_output, i); snprintf(buf_old_ion, 64, "%s_coarse_0_ion_p%d.gkyl", ten_moment_output, i); @@ -427,17 +419,9 @@ ten_moment_1d_run_single(int argc, char **argv, struct ten_moment_1d_single_init five_moment_write_sol_patch(buf_coarse, num_patches, coarse_pdata); five_moment_write_sol_patch(buf_fine, num_patches, fine_pdata); - char buf_fine_old_elc[64]; - char buf_fine_old_ion[64]; - char buf_fine_old_field[64]; - - char buf_fine_new_elc[64]; - char buf_fine_new_ion[64]; - char buf_fine_new_field[64]; - - char buf_coarse_old_elc[64]; - char buf_coarse_old_ion[64]; - char buf_coarse_old_field[64]; + char buf_fine_old_elc[64], buf_fine_old_ion[64], buf_fine_old_field[64]; + char buf_fine_new_elc[64], buf_fine_new_ion[64], buf_fine_new_field[64]; + char buf_coarse_old_elc[64], buf_coarse_old_ion[64], buf_coarse_old_field[64]; snprintf(buf_fine_old_elc, 64, "%s_fine_%d_elc_p0.gkyl", ten_moment_output, i); snprintf(buf_fine_old_ion, 64, "%s_fine_%d_ion_p0.gkyl", ten_moment_output, i); @@ -460,17 +444,9 @@ ten_moment_1d_run_single(int argc, char **argv, struct ten_moment_1d_single_init remove(buf_coarse_old_field); for (int j = 1; j < 3; j++) { - char buf_old_elc[64]; - char buf_old_ion[64]; - char buf_old_field[64]; - - char buf_new_elc[64]; - char buf_new_ion[64]; - char buf_new_field[64]; - - char buf_del_elc[64]; - char buf_del_ion[64]; - char buf_del_field[64]; + char buf_old_elc[64], buf_old_ion[64], buf_old_field[64]; + char buf_new_elc[64], buf_new_ion[64], buf_new_field[64]; + char buf_del_elc[64], buf_del_ion[64], buf_del_field[64]; snprintf(buf_old_elc, 64, "%s_coarse_%d_elc_p%d.gkyl", ten_moment_output, i, j); snprintf(buf_old_ion, 64, "%s_coarse_%d_ion_p%d.gkyl", ten_moment_output, i, j); @@ -538,17 +514,9 @@ ten_moment_1d_run_single(int argc, char **argv, struct ten_moment_1d_single_init five_moment_write_sol_patch(buf_coarse, num_patches, coarse_pdata); five_moment_write_sol_patch(buf_fine, num_patches, fine_pdata); - char buf_fine_old_elc[64]; - char buf_fine_old_ion[64]; - char buf_fine_old_field[64]; - - char buf_fine_new_elc[64]; - char buf_fine_new_ion[64]; - char buf_fine_new_field[64]; - - char buf_coarse_old_elc[64]; - char buf_coarse_old_ion[64]; - char buf_coarse_old_field[64]; + char buf_fine_old_elc[64], buf_fine_old_ion[64], buf_fine_old_field[64]; + char buf_fine_new_elc[64], buf_fine_new_ion[64], buf_fine_new_field[64]; + char buf_coarse_old_elc[64], buf_coarse_old_ion[64], buf_coarse_old_field[64]; snprintf(buf_fine_old_elc, 64, "%s_fine_%d_elc_p0.gkyl", ten_moment_output, num_frames); snprintf(buf_fine_old_ion, 64, "%s_fine_%d_ion_p0.gkyl", ten_moment_output, num_frames); @@ -571,17 +539,9 @@ ten_moment_1d_run_single(int argc, char **argv, struct ten_moment_1d_single_init remove(buf_coarse_old_field); for (int i = 1; i < 3; i++) { - char buf_old_elc[64]; - char buf_old_ion[64]; - char buf_old_field[64]; - - char buf_new_elc[64]; - char buf_new_ion[64]; - char buf_new_field[64]; - - char buf_del_elc[64]; - char buf_del_ion[64]; - char buf_del_field[64]; + char buf_old_elc[64], buf_old_ion[64], buf_old_field[64]; + char buf_new_elc[64], buf_new_ion[64], buf_new_field[64]; + char buf_del_elc[64], buf_del_ion[64], buf_del_field[64]; snprintf(buf_old_elc, 64, "%s_coarse_%d_elc_p%d.gkyl", ten_moment_output, num_frames, i); snprintf(buf_old_ion, 64, "%s_coarse_%d_ion_p%d.gkyl", ten_moment_output, num_frames, i); @@ -1072,17 +1032,9 @@ ten_moment_2d_run_single(int argc, char **argv, struct ten_moment_2d_single_init remove(coarse0_field_b0); for (int i = 1; i < 9; i++) { - char buf_old_elc[64]; - char buf_old_ion[64]; - char buf_old_field[64]; - - char buf_new_elc[64]; - char buf_new_ion[64]; - char buf_new_field[64]; - - char buf_del_elc[64]; - char buf_del_ion[64]; - char buf_del_field[64]; + char buf_old_elc[64], buf_old_ion[64], buf_old_field[64]; + char buf_new_elc[64], buf_new_ion[64], buf_new_field[64]; + char buf_del_elc[64], buf_del_ion[64], buf_del_field[64]; snprintf(buf_old_elc, 64, "%s_coarse_0_elc_b%d.gkyl", ten_moment_output, i); snprintf(buf_old_ion, 64, "%s_coarse_0_ion_b%d.gkyl", ten_moment_output, i); @@ -1176,17 +1128,9 @@ ten_moment_2d_run_single(int argc, char **argv, struct ten_moment_2d_single_init five_moment_write_sol_block(buf_coarse, num_blocks, coarse_bdata); five_moment_write_sol_block(buf_fine, num_blocks, fine_bdata); - char buf_fine_old_elc[64]; - char buf_fine_old_ion[64]; - char buf_fine_old_field[64]; - - char buf_fine_new_elc[64]; - char buf_fine_new_ion[64]; - char buf_fine_new_field[64]; - - char buf_coarse_old_elc[64]; - char buf_coarse_old_ion[64]; - char buf_coarse_old_field[64]; + char buf_fine_old_elc[64], buf_fine_old_ion[64], buf_fine_old_field[64]; + char buf_fine_new_elc[64], buf_fine_new_ion[64], buf_fine_new_field[64]; + char buf_coarse_old_elc[64], buf_coarse_old_ion[64], buf_coarse_old_field[64]; snprintf(buf_fine_old_elc, 64, "%s_fine_%d_elc_b0.gkyl", ten_moment_output, i); snprintf(buf_fine_old_ion, 64, "%s_fine_%d_ion_b0.gkyl", ten_moment_output, i); @@ -1209,17 +1153,9 @@ ten_moment_2d_run_single(int argc, char **argv, struct ten_moment_2d_single_init remove(buf_coarse_old_field); for (int j = 1; j < 9; j++) { - char buf_old_elc[64]; - char buf_old_ion[64]; - char buf_old_field[64]; - - char buf_new_elc[64]; - char buf_new_ion[64]; - char buf_new_field[64]; - - char buf_del_elc[64]; - char buf_del_ion[64]; - char buf_del_field[64]; + char buf_old_elc[64], buf_old_ion[64], buf_old_field[64]; + char buf_new_elc[64], buf_new_ion[64], buf_new_field[64]; + char buf_del_elc[64], buf_del_ion[64], buf_del_field[64]; snprintf(buf_old_elc, 64, "%s_coarse_%d_elc_b%d.gkyl", ten_moment_output, i, j); snprintf(buf_old_ion, 64, "%s_coarse_%d_ion_b%d.gkyl", ten_moment_output, i, j); @@ -1287,17 +1223,9 @@ ten_moment_2d_run_single(int argc, char **argv, struct ten_moment_2d_single_init five_moment_write_sol_block(buf_coarse, num_blocks, coarse_bdata); five_moment_write_sol_block(buf_fine, num_blocks, fine_bdata); - char buf_fine_old_elc[64]; - char buf_fine_old_ion[64]; - char buf_fine_old_field[64]; - - char buf_fine_new_elc[64]; - char buf_fine_new_ion[64]; - char buf_fine_new_field[64]; - - char buf_coarse_old_elc[64]; - char buf_coarse_old_ion[64]; - char buf_coarse_old_field[64]; + char buf_fine_old_elc[64], buf_fine_old_ion[64], buf_fine_old_field[64]; + char buf_fine_new_elc[64], buf_fine_new_ion[64], buf_fine_new_field[64]; + char buf_coarse_old_elc[64], buf_coarse_old_ion[64], buf_coarse_old_field[64]; snprintf(buf_fine_old_elc, 64, "%s_fine_%d_elc_b0.gkyl", ten_moment_output, num_frames); snprintf(buf_fine_old_ion, 64, "%s_fine_%d_ion_b0.gkyl", ten_moment_output, num_frames); @@ -1320,17 +1248,9 @@ ten_moment_2d_run_single(int argc, char **argv, struct ten_moment_2d_single_init remove(buf_coarse_old_field); for (int i = 1; i < 9; i++) { - char buf_old_elc[64]; - char buf_old_ion[64]; - char buf_old_field[64]; - - char buf_new_elc[64]; - char buf_new_ion[64]; - char buf_new_field[64]; - - char buf_del_elc[64]; - char buf_del_ion[64]; - char buf_del_field[64]; + char buf_old_elc[64], buf_old_ion[64], buf_old_field[64]; + char buf_new_elc[64], buf_new_ion[64], buf_new_field[64]; + char buf_del_elc[64], buf_del_ion[64], buf_del_field[64]; snprintf(buf_old_elc, 64, "%s_coarse_%d_elc_b%d.gkyl", ten_moment_output, num_frames, i); snprintf(buf_old_ion, 64, "%s_coarse_%d_ion_b%d.gkyl", ten_moment_output, num_frames, i); From ad60dcf00e376c09a0cdd7f056442675925a216d Mon Sep 17 00:00:00 2001 From: JonathanGorard Date: Tue, 25 Jun 2024 12:57:57 -0400 Subject: [PATCH 07/32] Minor clarification to comments (explaining distinction between ref_factor1 and ref_factor2) in the doubly-nested AMR case. --- regression/rt_amr_10m_gem_l2.c | 8 ++++---- regression/rt_amr_5m_gem_l2.c | 8 ++++---- regression/rt_amr_euler_cart_axi_sodshock_l2.c | 8 ++++---- regression/rt_amr_euler_riem_2d_l2.c | 8 ++++---- regression/rt_amr_euler_shock_bubble_l2.c | 8 ++++---- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/regression/rt_amr_10m_gem_l2.c b/regression/rt_amr_10m_gem_l2.c index 8cbd005f2..a17172a1c 100644 --- a/regression/rt_amr_10m_gem_l2.c +++ b/regression/rt_amr_10m_gem_l2.c @@ -38,8 +38,8 @@ struct amr_10m_gem_ctx // Simulation parameters. int Nx; // Coarse cell count (x-direction). int Ny; // Coarse cell count (y-direction). - int ref_factor1; // First refinement factor. - int ref_factor2; // Second refinement factor. + int ref_factor1; // First refinement factor (coarse-to-intermediate). + int ref_factor2; // Second refinement factor (intermediate-to-fine). double Lx; // Coarse domain size (x-direction). double Ly; // Coarse domain size (y-direction). double intermediate_Lx; // Intermediate domain size (x-direction). @@ -87,8 +87,8 @@ create_ctx(void) // Simulation parameters. int Nx = 32; // Coarse cell count (x-direction). int Ny = 16; // Coarse cell count (y-direction). - int ref_factor1 = 2; // First refinement factor. - int ref_factor2 = 2; // Second refinement factor. + int ref_factor1 = 2; // First refinement factor (coarse-to-intermediate). + int ref_factor2 = 2; // Second refinement factor (intermediate-to-fine). double Lx = 25.6; // Coarse domain size (x-direction). double Ly = 12.8; // Coarse domain size (y-direction). double intermediate_Lx = 20.6; // Intermediate domain size (x-direction). diff --git a/regression/rt_amr_5m_gem_l2.c b/regression/rt_amr_5m_gem_l2.c index 7a852a4f9..54cbe63e0 100644 --- a/regression/rt_amr_5m_gem_l2.c +++ b/regression/rt_amr_5m_gem_l2.c @@ -39,8 +39,8 @@ struct amr_5m_gem_ctx // Simulation parameters. int Nx; // Coarse cell count (x-direction). int Ny; // Coarse cell count (y-direction). - int ref_factor1; // First refinement factor. - int ref_factor2; // Second refinement factor. + int ref_factor1; // First refinement factor (coarse-to-intermediate). + int ref_factor2; // Second refinement factor (intermediate-to-fine). double Lx; // Coarse domain size (x-direction). double Ly; // Coarse domain size (y-direction). double intermediate_Lx; // Intermediate domain size (x-direction). @@ -89,8 +89,8 @@ create_ctx(void) // Simulation parameters. int Nx = 16; // Coarse cell count (x-direction). int Ny = 8; // Coarse cell count (y-direction). - int ref_factor1 = 2; // First refinement factor. - int ref_factor2 = 2; // Second refinement factor. + int ref_factor1 = 2; // First refinement factor (coarse-to-intermediate). + int ref_factor2 = 2; // Second refinement factor (intermediate-to-fine). double Lx = 25.6; // Coarse domain size (x-direction). double Ly = 12.8; // Coarse domain size (y-direction). double intermediate_Lx = 8.5333333; // Intermediate domain size (x-direction). diff --git a/regression/rt_amr_euler_cart_axi_sodshock_l2.c b/regression/rt_amr_euler_cart_axi_sodshock_l2.c index 227914a13..d56f3dd1a 100644 --- a/regression/rt_amr_euler_cart_axi_sodshock_l2.c +++ b/regression/rt_amr_euler_cart_axi_sodshock_l2.c @@ -25,8 +25,8 @@ struct amr_euler_cart_axi_sodshock_ctx // Simulation parameters. int Nx; // Coarse cell count (x-direction). int Ny; // Coarse cell count (y-direction). - int ref_factor1; // First refinement factor. - int ref_factor2; // Second refinement factor. + int ref_factor1; // First refinement factor (coarse-to-intermediate). + int ref_factor2; // Second refinement factor (intermediate-to-fine). double Lx; // Coarse domain size (x-direction). double Ly; // Coarse domain size (y-direction). double intermediate_Lx; // Intermediate domain size (x-direction). @@ -63,8 +63,8 @@ create_ctx(void) // Simulation parameters. int Nx = 8; // Coarse cell count (x-direction). int Ny = 8; // Coarse cell count (y-direction). - int ref_factor1 = 4; // First refinement factor. - int ref_factor2 = 4; // Second refinement factor; + int ref_factor1 = 4; // First refinement factor (coarse-to-intermediate). + int ref_factor2 = 4; // Second refinement factor (intermediate-to-fine). double Lx = 2.5; // Coarse domain size (x-direction). double Ly = 2.5; // Coarse domain size (y-direction). double intermediate_Lx = 1.8; // Intermediate domain size (x-direction). diff --git a/regression/rt_amr_euler_riem_2d_l2.c b/regression/rt_amr_euler_riem_2d_l2.c index 92be0016e..4176e66ba 100644 --- a/regression/rt_amr_euler_riem_2d_l2.c +++ b/regression/rt_amr_euler_riem_2d_l2.c @@ -34,8 +34,8 @@ struct amr_euler_riem_2d_ctx // Simulation parameters. int Nx; // Coarse cell count (x-direction). int Ny; // Coarse cell count (y-direction). - int ref_factor1; // First refinement factor. - int ref_factor2; // Second refinement factor. + int ref_factor1; // First refinement factor (coarse-to-intermediate). + int ref_factor2; // Second refinement factor (intermediate-to-fine). double Lx; // Coarse domain size (x-direction). double Ly; // Coarse domain size (y-direction). double intermediate_Lx; // Intermediate domain size (x-direction). @@ -81,8 +81,8 @@ create_ctx(void) // Simulation parameters. int Nx = 8; // Coarse cell count (x-direction). int Ny = 8; // Coarse cell count (y-direction). - int ref_factor1 = 4; // First refinement factor. - int ref_factor2 = 4; // Second refinement factor. + int ref_factor1 = 4; // First refinement factor (coarse-to-intermediate). + int ref_factor2 = 4; // Second refinement factor (intermediate-to-fine). double Lx = 1.0; // Coarse domain size (x-direction). double Ly = 1.0; // Coarse domain size (y-direction). double intermediate_Lx = 0.75; // Intermediate domain size (x-direction). diff --git a/regression/rt_amr_euler_shock_bubble_l2.c b/regression/rt_amr_euler_shock_bubble_l2.c index aedf0c7a0..72a729ea5 100644 --- a/regression/rt_amr_euler_shock_bubble_l2.c +++ b/regression/rt_amr_euler_shock_bubble_l2.c @@ -20,8 +20,8 @@ struct amr_euler_shock_bubble_ctx // Simulation parameters. int Nx; // Coarse cell count (x-direction). int Ny; // Coarse cell count (y-direction). - int ref_factor1; // First refinement factor. - int ref_factor2; // Second refinement factor. + int ref_factor1; // First refinement factor (coarse-to-intermediate). + int ref_factor2; // Second refinement factor (intermediate-to-fine). double Lx; // Coarse domain size (x-direction). double Ly; // Coarse domain size (y-direction). double intermediate_Lx; // Intermediate domain size (x-direction). @@ -61,8 +61,8 @@ create_ctx(void) // Simulation parameters. int Nx = 16; // Coarse cell count (x-direction). int Ny = 16; // Coarse cell count (y-direction). - int ref_factor1 = 4; // First refinement factor. - int ref_factor2 = 4; // Second refinement factor. + int ref_factor1 = 4; // First refinement factor (coarse-to-intermediate). + int ref_factor2 = 4; // Second refinement factor (intermediate-to-fine). double Lx = 1.0; // Coarse domain size (x-direction). double Ly = 1.0; // Coarse domain size (y-direction). double intermediate_Lx = 0.75; // Intermediate domain size (x-direction). From 28b1d7ddbd9181188f66efb72a2d6edf82537610 Mon Sep 17 00:00:00 2001 From: JonathanGorard Date: Tue, 25 Jun 2024 15:09:22 -0400 Subject: [PATCH 08/32] Hooked up singly- and doubly-nested AMR infrastructure to the 2D GR Euler equations. Plus minor cleanup of the 2D Euler case. --- amr/amr_core_euler.c | 2 - amr/amr_core_gr_euler.c | 716 ++++++++++++++++++++++++++++++++++++++++ amr/gkyl_amr_core.h | 46 +++ 3 files changed, 762 insertions(+), 2 deletions(-) diff --git a/amr/amr_core_euler.c b/amr/amr_core_euler.c index 142fde2ea..8ff6db773 100644 --- a/amr/amr_core_euler.c +++ b/amr/amr_core_euler.c @@ -1406,7 +1406,6 @@ euler2d_run_double(int argc, char **argv, struct euler2d_double_init* init) for (int i = 1; i < num_frames; i++) { if (coarse_t_curr < (i * io_trigger) && (coarse_t_curr + coarse_status.dt_actual) > (i * io_trigger)) { - // TODO: Make file output work correctly in the AMR_DEBUG case. #ifdef AMR_DEBUG char buf_coarse[64]; char buf_intermediate[64]; @@ -1499,7 +1498,6 @@ euler2d_run_double(int argc, char **argv, struct euler2d_double_init* init) double tm_total_sec = gkyl_time_diff_now_sec(tm_start); - // TODO: Make file output work correctly in the AMR_DEBUG case. #ifdef AMR_DEBUG char buf_coarse[64]; char buf_intermediate[64]; diff --git a/amr/amr_core_gr_euler.c b/amr/amr_core_gr_euler.c index fdddb96e1..828a23983 100644 --- a/amr/amr_core_gr_euler.c +++ b/amr/amr_core_gr_euler.c @@ -843,4 +843,720 @@ gr_euler2d_run_single(int argc, char **argv, struct gr_euler2d_single_init* init #ifdef AMR_DEBUG gkyl_job_pool_release(fine_job_pool); #endif +} + +void +gr_euler2d_run_double(int argc, char **argv, struct gr_euler2d_double_init* init) +{ + struct gkyl_app_args app_args = parse_app_args(argc, argv); + + if (app_args.trace_mem) { + gkyl_cu_dev_mem_debug_set(true); + gkyl_mem_debug_set(true); + } + + int base_Nx = init->base_Nx; + int base_Ny = init->base_Ny; + int ref_factor1 = init->ref_factor1; + int ref_factor2 = init->ref_factor2; + + double coarse_x1 = init->coarse_x1; + double coarse_y1 = init->coarse_y1; + double coarse_x2 = init->coarse_x2; + double coarse_y2 = init->coarse_y2; + + double intermediate_x1 = init->intermediate_x1; + double intermediate_y1 = init->intermediate_y1; + double intermediate_x2 = init->intermediate_x2; + double intermediate_y2 = init->intermediate_y2; + + double refined_x1 = init->refined_x1; + double refined_y1 = init->refined_y1; + double refined_x2 = init->refined_x2; + double refined_y2 = init->refined_y2; + + evalf_t eval = init->eval; + double gas_gamma = init->gas_gamma; + struct gkyl_gr_spacetime *spacetime = init->spacetime; + + char gr_euler_output[32]; + strcpy(gr_euler_output, init->gr_euler_output); + + bool low_order_flux = init->low_order_flux; + int num_frames = init->num_frames; + + double cfl_frac = init->cfl_frac; + double t_end = init->t_end; + double dt_failure_tol = init->dt_failure_tol; + int num_failures_max = init->num_failures_max; + + int ndim = 2; + int num_blocks = 25; + int Nx = base_Nx; + int Ny = base_Ny; + + struct euler_block_data coarse_bdata[num_blocks]; + struct gkyl_job_pool *coarse_job_pool = gkyl_thread_pool_new(app_args.num_threads); + +#ifdef AMR_DEBUG + gkyl_rect_grid_init(&coarse_bdata[0].grid, 2, (double []) { refined_x1, refined_y1 }, (double []) { refined_x2, refined_y2 }, + (int []) { Nx, Ny }); + + gkyl_rect_grid_init(&coarse_bdata[1].grid, 2, (double []) { intermediate_x1, refined_y2 }, (double []) { refined_x1, intermediate_y2 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[2].grid, 2, (double []) { refined_x1, refined_y2 }, (double []) { refined_x2, intermediate_y2 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[3].grid, 2, (double []) { refined_x2, refined_y2 }, (double []) { intermediate_x2, intermediate_y2 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[4].grid, 2, (double []) { intermediate_x1, refined_y1 }, (double []) { refined_x1, refined_y2 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[5].grid, 2, (double []) { refined_x2, refined_y1 }, (double []) { intermediate_x2, refined_y2 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[6].grid, 2, (double []) { intermediate_x1, intermediate_y1 }, (double []) { refined_x1, refined_y1 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[7].grid, 2, (double []) { refined_x1, intermediate_y1 }, (double []) { refined_x2, refined_y1 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[8].grid, 2, (double []) { refined_x2, intermediate_y1 }, (double []) { intermediate_x2, refined_y1 }, + (int []) { Nx, Ny }); +#else + gkyl_rect_grid_init(&coarse_bdata[0].grid, 2, (double []) { refined_x1, refined_y1 }, (double []) { refined_x2, refined_y2 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + + gkyl_rect_grid_init(&coarse_bdata[1].grid, 2, (double []) { intermediate_x1, refined_y2 }, (double []) { refined_x1, intermediate_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&coarse_bdata[2].grid, 2, (double []) { refined_x1, refined_y2 }, (double []) { refined_x2, intermediate_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&coarse_bdata[3].grid, 2, (double []) { refined_x2, refined_y2 }, (double []) { intermediate_x2, intermediate_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&coarse_bdata[4].grid, 2, (double []) { intermediate_x1, refined_y1 }, (double []) { refined_x1, refined_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&coarse_bdata[5].grid, 2, (double []) { refined_x2, refined_y1 }, (double []) { intermediate_x2, refined_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&coarse_bdata[6].grid, 2, (double []) { intermediate_x1, intermediate_y1 }, (double []) { refined_x1, refined_y1 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&coarse_bdata[7].grid, 2, (double []) { refined_x1, intermediate_y1 }, (double []) { refined_x2, refined_y1 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&coarse_bdata[8].grid, 2, (double []) { refined_x2, intermediate_y1 }, (double []) { intermediate_x2, refined_y1 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); +#endif + + gkyl_rect_grid_init(&coarse_bdata[9].grid, 2, (double []) { coarse_x1, intermediate_y2 }, (double []) { intermediate_x1, coarse_y2 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[10].grid, 2, (double []) { intermediate_x1, intermediate_y2 }, (double []) { refined_x1, coarse_y2 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[11].grid, 2, (double []) { refined_x1, intermediate_y2 }, (double []) { refined_x2, coarse_y2 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[12].grid, 2, (double []) { refined_x2, intermediate_y2 }, (double []) { intermediate_x2, coarse_y2 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[13].grid, 2, (double []) { intermediate_x2, intermediate_y2 }, (double []) { coarse_x2, coarse_y2 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[14].grid, 2, (double []) { coarse_x1, refined_y2 }, (double []) { intermediate_x1, intermediate_y2 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[15].grid, 2, (double []) { intermediate_x2, refined_y2 }, (double []) { coarse_x2, intermediate_y2 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[16].grid, 2, (double []) { coarse_x1, refined_y1 }, (double []) { intermediate_x1, refined_y2 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[17].grid, 2, (double []) { intermediate_x2, refined_y1 }, (double []) { coarse_x2, refined_y2 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[18].grid, 2, (double []) { coarse_x1, intermediate_y1 }, (double []) { intermediate_x1, refined_y1 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[19].grid, 2, (double []) { intermediate_x2, intermediate_y1 }, (double []) { coarse_x2, refined_y1 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[20].grid, 2, (double []) { coarse_x1, coarse_y1 }, (double []) { intermediate_x1, intermediate_y1 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[21].grid, 2, (double []) { intermediate_x1, coarse_y1 }, (double []) { refined_x1, intermediate_y1 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[22].grid, 2, (double []) { refined_x1, coarse_y1 }, (double []) { refined_x2, intermediate_y1 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[23].grid, 2, (double []) { refined_x2, coarse_y1 }, (double []) { intermediate_x2, intermediate_y1 }, + (int []) { Nx, Ny }); + gkyl_rect_grid_init(&coarse_bdata[24].grid, 2, (double []) { intermediate_x2, coarse_y1 }, (double []) { coarse_x2, intermediate_y1 }, + (int []) { Nx, Ny }); + +#ifdef AMR_DEBUG + struct euler_block_data intermediate_bdata[num_blocks]; + struct gkyl_job_pool *intermediate_job_pool = gkyl_thread_pool_new(app_args.num_threads); + + gkyl_rect_grid_init(&intermediate_bdata[0].grid, 2, (double []) { refined_x1, refined_y1 }, (double []) { refined_x2, refined_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + + gkyl_rect_grid_init(&intermediate_bdata[1].grid, 2, (double []) { coarse_x1, refined_y2 }, (double []) { refined_x1, coarse_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[2].grid, 2, (double []) { refined_x1, refined_y2 }, (double []) { refined_x2, coarse_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[3].grid, 2, (double []) { refined_x2, refined_y2 }, (double []) { coarse_x2, coarse_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[4].grid, 2, (double []) { coarse_x1, refined_y1 }, (double []) { refined_x1, refined_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[5].grid, 2, (double []) { refined_x2, refined_y1 }, (double []) { coarse_x2, refined_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[6].grid, 2, (double []) { coarse_x1, coarse_y1 }, (double []) { refined_x1, refined_y1 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[7].grid, 2, (double []) { refined_x1, coarse_y1 }, (double []) { refined_x2, refined_y1 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[8].grid, 2, (double []) { refined_x2, coarse_y1 }, (double []) { coarse_x2, refined_y1 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + + gkyl_rect_grid_init(&intermediate_bdata[9].grid, 2, (double []) { coarse_x1, intermediate_y2 }, (double []) { intermediate_x1, coarse_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[10].grid, 2, (double []) { intermediate_x1, intermediate_y2 }, (double []) { refined_x1, coarse_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[11].grid, 2, (double []) { refined_x1, intermediate_y2 }, (double []) { refined_x2, coarse_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[12].grid, 2, (double []) { refined_x2, intermediate_y2 }, (double []) { intermediate_x2, coarse_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[13].grid, 2, (double []) { intermediate_x2, intermediate_y2 }, (double []) { coarse_x2, coarse_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[14].grid, 2, (double []) { coarse_x1, refined_y2 }, (double []) { intermediate_x1, intermediate_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[15].grid, 2, (double []) { intermediate_x2, refined_y2 }, (double []) { coarse_x2, intermediate_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[16].grid, 2, (double []) { coarse_x1, refined_y1 }, (double []) { intermediate_x1, refined_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[17].grid, 2, (double []) { intermediate_x2, refined_y1 }, (double []) { coarse_x2, refined_y2 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[18].grid, 2, (double []) { coarse_x1, intermediate_y1 }, (double []) { intermediate_x1, refined_y1 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[19].grid, 2, (double []) { intermediate_x2, intermediate_y1 }, (double []) { coarse_x2, refined_y1 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[20].grid, 2, (double []) { coarse_x1, coarse_y1 }, (double []) { intermediate_x1, intermediate_y1 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[21].grid, 2, (double []) { intermediate_x1, coarse_y1 }, (double []) { refined_x1, intermediate_y1 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[22].grid, 2, (double []) { refined_x1, coarse_y1 }, (double []) { refined_x2, intermediate_y1 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[23].grid, 2, (double []) { refined_x2, coarse_y1 }, (double []) { intermediate_x2, intermediate_y1 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + gkyl_rect_grid_init(&intermediate_bdata[24].grid, 2, (double []) { intermediate_x2, coarse_y1 }, (double []) { coarse_x2, intermediate_y1 }, + (int []) { Nx * ref_factor1, Ny * ref_factor1 }); + + struct euler_block_data fine_bdata[num_blocks]; + struct gkyl_job_pool *fine_job_pool = gkyl_thread_pool_new(app_args.num_threads); + + gkyl_rect_grid_init(&fine_bdata[0].grid, 2, (double []) { refined_x1, refined_y1 }, (double []) { refined_x2, refined_y2 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + + gkyl_rect_grid_init(&fine_bdata[1].grid, 2, (double []) { coarse_x1, refined_y2 }, (double []) { refined_x1, coarse_y2 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[2].grid, 2, (double []) { refined_x1, refined_y2 }, (double []) { refined_x2, coarse_y2 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[3].grid, 2, (double []) { refined_x2, refined_y2 }, (double []) { coarse_x2, coarse_y2 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[4].grid, 2, (double []) { coarse_x1, refined_y1 }, (double []) { refined_x1, refined_y2 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[5].grid, 2, (double []) { refined_x2, refined_y1 }, (double []) { coarse_x2, refined_y2 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[6].grid, 2, (double []) { coarse_x1, coarse_y1 }, (double []) { refined_x1, refined_y1 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[7].grid, 2, (double []) { refined_x1, coarse_y1 }, (double []) { refined_x2, refined_y1 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[8].grid, 2, (double []) { refined_x2, coarse_y1 }, (double []) { coarse_x2, refined_y1 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + + gkyl_rect_grid_init(&fine_bdata[9].grid, 2, (double []) { coarse_x1, intermediate_y2 }, (double []) { intermediate_x1, coarse_y2 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[10].grid, 2, (double []) { intermediate_x1, intermediate_y2 }, (double []) { refined_x1, coarse_y2 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[11].grid, 2, (double []) { refined_x1, intermediate_y2 }, (double []) { refined_x2, coarse_y2 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[12].grid, 2, (double []) { refined_x2, intermediate_y2 }, (double []) { intermediate_x2, coarse_y2 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[13].grid, 2, (double []) { intermediate_x2, intermediate_y2 }, (double []) { coarse_x2, coarse_y2 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[14].grid, 2, (double []) { coarse_x1, refined_y2 }, (double []) { intermediate_x1, intermediate_y2 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[15].grid, 2, (double []) { intermediate_x2, refined_y2 }, (double []) { coarse_x2, intermediate_y2 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[16].grid, 2, (double []) { coarse_x1, refined_y1 }, (double []) { intermediate_x1, refined_y2 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[17].grid, 2, (double []) { intermediate_x2, refined_y1 }, (double []) { coarse_x2, refined_y2 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[18].grid, 2, (double []) { coarse_x1, intermediate_y1 }, (double []) { intermediate_x1, refined_y1 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[19].grid, 2, (double []) { intermediate_x2, intermediate_y1 }, (double []) { coarse_x2, refined_y1 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[20].grid, 2, (double []) { coarse_x1, coarse_y1 }, (double []) { intermediate_x1, intermediate_y1 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[21].grid, 2, (double []) { intermediate_x1, coarse_y1 }, (double []) { refined_x1, intermediate_y1 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[22].grid, 2, (double []) { refined_x1, coarse_y1 }, (double []) { refined_x2, intermediate_y1 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[23].grid, 2, (double []) { refined_x2, coarse_y1 }, (double []) { intermediate_x2, intermediate_y1 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); + gkyl_rect_grid_init(&fine_bdata[24].grid, 2, (double []) { intermediate_x2, coarse_y1 }, (double []) { coarse_x2, intermediate_y1 }, + (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); +#endif + + for (int i = 0; i < num_blocks; i++) { + coarse_bdata[i].fv_proj = gkyl_fv_proj_new(&coarse_bdata[i].grid, 2, 5, eval, 0); + +#ifdef AMR_DEBUG + intermediate_bdata[i].fv_proj = gkyl_fv_proj_new(&intermediate_bdata[i].grid, 2, 5, eval, 0); + fine_bdata[i].fv_proj = gkyl_fv_proj_new(&fine_bdata[i].grid, 2, 5, eval, 0); +#endif + } + + for (int i = 0; i < num_blocks; i++) { + gkyl_create_grid_ranges(&coarse_bdata[i].grid, (int []) { 2, 2 }, &coarse_bdata[i].ext_range, &coarse_bdata[i].range); + coarse_bdata[i].geom = gkyl_wave_geom_new(&coarse_bdata[i].grid, &coarse_bdata[i].ext_range, 0, 0, false); + +#ifdef AMR_DEBUG + gkyl_create_grid_ranges(&intermediate_bdata[i].grid, (int []) { 2, 2 }, &intermediate_bdata[i].ext_range, &intermediate_bdata[i].range); + intermediate_bdata[i].geom = gkyl_wave_geom_new(&intermediate_bdata[i].grid, &intermediate_bdata[i].ext_range, 0, 0, false); + + gkyl_create_grid_ranges(&fine_bdata[i].grid, (int []) { 2, 2 }, &fine_bdata[i].ext_range, &fine_bdata[i].range); + fine_bdata[i].geom = gkyl_wave_geom_new(&fine_bdata[i].grid, &fine_bdata[i].ext_range, 0, 0, false); +#endif + } + + for (int i = 0; i < num_blocks; i++) { + coarse_bdata[i].euler = gkyl_wv_gr_euler_new(gas_gamma, spacetime, app_args.use_gpu); + + for (int d = 0; d < ndim; d++) { + coarse_bdata[i].slvr[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { + .grid = &coarse_bdata[i].grid, + .equation = coarse_bdata[i].euler, + .limiter = GKYL_MONOTONIZED_CENTERED, + .num_up_dirs = 1, + .update_dirs = { d }, + .cfl = cfl_frac, + .geom = coarse_bdata[i].geom, + } + ); + } + +#ifdef AMR_DEBUG + intermediate_bdata[i].euler = gkyl_wv_gr_euler_new(gas_gamma, spacetime, app_args.use_gpu); + fine_bdata[i].euler = gkyl_wv_gr_euler_new(gas_gamma, spacetime, app_args.use_gpu); + + for (int d = 0; d < ndim; d++) { + intermediate_bdata[i].slvr[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { + .grid = &intermediate_bdata[i].grid, + .equation = intermediate_bdata[i].euler, + .limiter = GKYL_MONOTONIZED_CENTERED, + .num_up_dirs = 1, + .update_dirs = { d }, + .cfl = cfl_frac, + .geom = intermediate_bdata[i].geom, + } + ); + + fine_bdata[i].slvr[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { + .grid = &fine_bdata[i].grid, + .equation = fine_bdata[i].euler, + .limiter = GKYL_MONOTONIZED_CENTERED, + .num_up_dirs = 1, + .update_dirs = { d }, + .cfl = cfl_frac, + .geom = fine_bdata[i].geom, + } + ); + } +#endif + } + + struct gkyl_block_topo *btopo = create_nested_block_topo(); + + for (int i = 0; i < num_blocks; i++) { + gr_euler_nested_block_bc_updaters_init(&coarse_bdata[i], &btopo->conn[i]); + +#ifdef AMR_DEBUG + gr_euler_nested_block_bc_updaters_init(&intermediate_bdata[i], &btopo->conn[i]); + gr_euler_nested_block_bc_updaters_init(&fine_bdata[i], &btopo->conn[i]); +#endif + } + + for (int i = 0; i < num_blocks; i++) { + coarse_bdata[i].fdup = gkyl_array_new(GKYL_DOUBLE, 29, coarse_bdata[i].ext_range.volume); + + for (int d = 0; d < ndim + 1; d++) { + coarse_bdata[i].f[d] = gkyl_array_new(GKYL_DOUBLE, 20, coarse_bdata[i].ext_range.volume); + } + +#ifdef AMR_DEBUG + intermediate_bdata[i].fdup = gkyl_array_new(GKYL_DOUBLE, 29, intermediate_bdata[i].ext_range.volume); + fine_bdata[i].fdup = gkyl_array_new(GKYL_DOUBLE, 29, fine_bdata[i].ext_range.volume); + + for (int d = 0; d < ndim + 1; d++) { + intermediate_bdata[i].f[d] = gkyl_array_new(GKYL_DOUBLE, 29, intermediate_bdata[i].ext_range.volume); + fine_bdata[i].f[d] = gkyl_array_new(GKYL_DOUBLE, 29, fine_bdata[i].ext_range.volume); + } +#endif + } + +#ifdef AMR_USETHREADS + for (int i = 0; i < num_blocks; i++) { + gkyl_job_pool_add_work(coarse_job_pool, euler_init_job_func_block, &coarse_bdata[i]); + +#ifdef AMR_DEBUG + gkyl_job_pool_add_work(intermediate_job_pool, euler_init_job_func_block, &intermediate_bdata[i]); + gkyl_job_pool_add_work(fine_job_pool, euler_init_job_func_block, &fine_bdata[i]); +#endif + } + gkyl_job_pool_wait(coarse_job_pool); + +#ifdef AMR_DEBUG + gkyl_job_pool_wait(intermediate_job_pool); + gkyl_job_pool_wait(fine_job_pool); +#endif +#else + for (int i = 0; i < num_blocks; i++) { + euler_init_job_func_block(&coarse_bdata[i]); + +#ifdef AMR_DEBUG + euler_init_job_func_block(&intermediate_bdata[i]); + euler_init_job_func_block(&fine_bdata[i]); +#endif + } +#endif + +#ifdef AMR_DEBUG + char coarse0[64]; + snprintf(coarse0, 64, "%s_coarse_0", gr_euler_output); + euler_write_sol_block(coarse0, num_blocks, coarse_bdata); + + char intermediate0[64]; + snprintf(intermediate0, 64, "%s_intermediate_0", gr_euler_output); + euler_write_sol_block(intermediate0, num_blocks, intermediate_bdata); + + char fine0[64]; + snprintf(fine0, 64, "%s_fine_0", gr_euler_output); + euler_write_sol_block(fine0, num_blocks, fine_bdata); + + char fine0b0[64]; + char intermediate0b0[64]; + char coarse0b0[64]; + char b0[64]; + snprintf(fine0b0, 64, "%s_fine_0_b0.gkyl", gr_euler_output); + snprintf(intermediate0b0, 64, "%s_intermediate_0_b0.gkyl", gr_euler_output); + snprintf(coarse0b0, 64, "%s_coarse_0_b0.gkyl", gr_euler_output); + snprintf(b0, 64, "%s_0_b0.gkyl", gr_euler_output); + rename(fine0b0, b0); + remove(intermediate0b0); + remove(coarse0b0); + + for (int i = 1; i < 9; i++) { + char fine0bi[64]; + char intermediate0bi[64]; + char coarse0bi[64]; + char bi[64]; + snprintf(fine0bi, 64, "%s_fine_0_b%d.gkyl", gr_euler_output, i); + snprintf(intermediate0bi, 64, "%s_intermediate_0_b%d.gkyl", gr_euler_output, i); + snprintf(coarse0bi, 64, "%s_coarse_0_b%d.gkyl", gr_euler_output, i); + snprintf(bi, 64, "%s_0_b%d.gkyl", gr_euler_output, i); + rename(intermediate0bi, bi); + remove(fine0bi); + remove(coarse0bi); + } + + for (int i = 9; i < 25; i++) { + char buf_old[64]; + char buf_new[64]; + char buf_del1[64]; + char buf_del2[64]; + + snprintf(buf_old, 64, "%s_coarse_0_b%d.gkyl", gr_euler_output, i); + snprintf(buf_new, 64, "%s_0_b%d.gkyl", gr_euler_output, i); + snprintf(buf_del1, 64, "%s_intermediate_0_b%d.gkyl", gr_euler_output, i); + snprintf(buf_del2, 64, "%s_fine_0_b%d.gkyl", gr_euler_output, i); + + rename(buf_old, buf_new); + remove(buf_del1); + remove(buf_del2); + } +#else + char amr0[64]; + snprintf(amr0, 64, "%s_0", gr_euler_output); + euler_write_sol_block(amr0, num_blocks, coarse_bdata); +#endif + + double coarse_t_curr = 0.0; + double intermediate_t_curr = 0.0; + double fine_t_curr = 0.0; + double coarse_dt = euler_max_dt_block(num_blocks, coarse_bdata); + +#ifdef AMR_DEBUG + double intermediate_dt = euler_max_dt_block(num_blocks, intermediate_bdata); + double fine_dt = euler_max_dt_block(num_blocks, fine_bdata); +#else + double intermediate_dt = (1.0 / ref_factor1) * coarse_dt; + double fine_dt = (1.0 / (ref_factor1 * ref_factor2)) * coarse_dt; +#endif + + struct sim_stats stats = { }; + + struct timespec tm_start = gkyl_wall_clock(); + + long coarse_step = 1; + long num_steps = app_args.num_steps; + + double io_trigger = t_end / num_frames; + + double dt_init = -1.0; + int num_failures = 0; + + while ((coarse_t_curr < t_end) && (coarse_step <= num_steps)) { + printf("Taking coarse (level 0) time-step %ld at t = %g; ", coarse_step, coarse_t_curr); + struct gkyl_update_status coarse_status = euler_update_block(coarse_job_pool, btopo, coarse_bdata, coarse_t_curr, coarse_dt, &stats); + printf(" dt = %g\n", coarse_status.dt_actual); + + if (!coarse_status.success) { + printf("** Update method failed! Aborting simulation ....\n"); + break; + } + + for (long intermediate_step = 1; intermediate_step < ref_factor1 + 1; intermediate_step++) { +#ifdef AMR_DEBUG + printf(" Taking intermediate (level 1) time-step %ld at t = %g; ", intermediate_step, intermediate_t_curr); + struct gkyl_update_status intermediate_status = euler_update_block(intermediate_job_pool, btopo, intermediate_bdata, intermediate_t_curr, intermediate_dt, &stats); + printf(" dt = %g\n", intermediate_status.dt_actual); + + if (!intermediate_status.success) { + printf("** Update method failed! Aborting simulation ....\n"); + break; + } + + for (long fine_step = 1; fine_step < ref_factor2 + 1; fine_step++) { + printf(" Taking fine (level 2) time-step %ld at t = %g; ", fine_step, fine_t_curr); + struct gkyl_update_status fine_status = euler_update_block(fine_job_pool, btopo, fine_bdata, fine_t_curr, fine_dt, &stats); + printf( "dt = %g\n", fine_status.dt_actual); + + if (!fine_status.success) { + printf("** Update method failed! Aborting simulation ....\n"); + break; + } + + fine_t_curr += fine_status.dt_actual; + fine_dt = fine_status.dt_suggested; + } + + intermediate_t_curr += intermediate_status.dt_actual; + intermediate_dt = intermediate_status.dt_suggested; +#else + printf(" Taking intermediate (level 1) time-step %ld at t = %g", intermediate_step, intermediate_t_curr); + printf(" dt = %g\n", (1.0 / ref_factor1) * coarse_status.dt_actual); + + for (long fine_step = 1; fine_step < ref_factor2 + 1; fine_step++) { + printf(" Taking fine (level 2) time-step %ld at t = %g", fine_step, fine_t_curr); + printf(" dt = %g\n", (1.0 / (ref_factor1 * ref_factor2)) * coarse_status.dt_actual); + + fine_t_curr += (1.0 / (ref_factor1 * ref_factor2)) * coarse_status.dt_actual; + fine_dt = (1.0 / (ref_factor1 * ref_factor2)) * coarse_status.dt_suggested; + } + + intermediate_t_curr += (1.0 / ref_factor1) * coarse_status.dt_actual; + intermediate_dt = (1.0 / ref_factor1) * coarse_status.dt_suggested; +#endif + } + + for (int i = 1; i < num_frames; i++) { + if (coarse_t_curr < (i * io_trigger) && (coarse_t_curr + coarse_status.dt_actual) > (i * io_trigger)) { +#ifdef AMR_DEBUG + char buf_coarse[64]; + char buf_intermediate[64]; + char buf_fine[64]; + + snprintf(buf_coarse, 64, "%s_coarse_%d", gr_euler_output, i); + snprintf(buf_intermediate, 64, "%s_intermediate_%d", gr_euler_output, i); + snprintf(buf_fine, 64, "%s_fine_%d", gr_euler_output, i); + + euler_write_sol_block(buf_coarse, num_blocks, coarse_bdata); + euler_write_sol_block(buf_intermediate, num_blocks, intermediate_bdata); + euler_write_sol_block(buf_fine, num_blocks, fine_bdata); + + char buf_fine_old[64]; + char buf_fine_new[64]; + char buf_intermediate_old[64]; + char buf_coarse_old[64]; + + snprintf(buf_fine_old, 64, "%s_fine_%d_b0.gkyl", gr_euler_output, i); + snprintf(buf_fine_new, 64, "%s_%d_b0.gkyl", gr_euler_output, i); + snprintf(buf_intermediate_old, 64, "%s_intermediate_%d_b0.gkyl", gr_euler_output, i); + snprintf(buf_coarse_old, 64, "%s_coarse_%d_b0.gkyl", gr_euler_output, i); + + rename(buf_fine_old, buf_fine_new); + remove(buf_intermediate_old); + remove(buf_coarse_old); + + for (int j = 1; j < 9; j++) { + char fine_bi[64]; + char intermediate_bi[64]; + char coarse_bi[64]; + char bi[64]; + snprintf(fine_bi, 64, "%s_fine_%d_b%d.gkyl", gr_euler_output, i, j); + snprintf(intermediate_bi, 64, "%s_intermediate_%d_b%d.gkyl", gr_euler_output, i, j); + snprintf(coarse_bi, 64, "%s_coarse_%d_b%d.gkyl", gr_euler_output, i, j); + snprintf(bi, 64, "%s_%d_b%d.gkyl", gr_euler_output, i, j); + rename(intermediate_bi, bi); + remove(fine_bi); + remove(coarse_bi); + } + + for (int j = 9; j < 25; j++) { + char buf_old[64]; + char buf_new[64]; + char buf_del1[64]; + char buf_del2[64]; + + snprintf(buf_old, 64, "%s_coarse_%d_b%d.gkyl", gr_euler_output, i, j); + snprintf(buf_new, 64, "%s_%d_b%d.gkyl", gr_euler_output, i, j); + snprintf(buf_del1, 64, "%s_intermediate_%d_b%d.gkyl", gr_euler_output, i, j); + snprintf(buf_del2, 64, "%s_fine_%d_b%d.gkyl", gr_euler_output, i, j); + + rename(buf_old, buf_new); + remove(buf_del1); + remove(buf_del2); + } +#else + char buf[64]; + snprintf(buf, 64, "%s_%d", gr_euler_output, i); + + euler_write_sol_block(buf, num_blocks, coarse_bdata); +#endif + } + } + + coarse_t_curr += coarse_status.dt_actual; + coarse_dt = coarse_status.dt_suggested; + + if (dt_init < 0.0) { + dt_init = coarse_status.dt_actual; + } + else if (coarse_status.dt_actual < dt_failure_tol * dt_init) { + num_failures += 1; + + printf("WARNING: Time-step dt = %g", coarse_status.dt_actual); + printf(" is below %g*dt_init ...", dt_failure_tol); + printf(" num_failures = %d\n", num_failures); + if (num_failures >= num_failures_max) { + printf("ERROR: Time-step was below %g*dt_init ", dt_failure_tol); + printf("%d consecutive times. Aborting simulation ....\n", num_failures_max); + break; + } + } + else { + num_failures = 0; + } + + coarse_step += 1; + } + + double tm_total_sec = gkyl_time_diff_now_sec(tm_start); + + // TODO: Make file output work correctly in the AMR_DEBUG case. +#ifdef AMR_DEBUG + char buf_coarse[64]; + char buf_intermediate[64]; + char buf_fine[64]; + + snprintf(buf_coarse, 64, "%s_coarse_%d", gr_euler_output, num_frames); + snprintf(buf_intermediate, 64, "%s_intermediate_%d", gr_euler_output, num_frames); + snprintf(buf_fine, 64, "%s_fine_%d", gr_euler_output, num_frames); + + euler_write_sol_block(buf_coarse, num_blocks, coarse_bdata); + euler_write_sol_block(buf_intermediate, num_blocks, intermediate_bdata); + euler_write_sol_block(buf_fine, num_blocks, fine_bdata); + + char buf_fine_old[64]; + char buf_fine_new[64]; + char buf_intermediate_old[64]; + char buf_coarse_old[64]; + + snprintf(buf_fine_old, 64, "%s_fine_%d_b0.gkyl", gr_euler_output, num_frames); + snprintf(buf_fine_new, 64, "%s_%d_b0.gkyl", gr_euler_output, num_frames); + snprintf(buf_intermediate_old, 64, "%s_intermediate_%d_b0.gkyl", gr_euler_output, num_frames); + snprintf(buf_coarse_old, 64, "%s_coarse_%d_b0.gkyl", gr_euler_output,num_frames); + + rename(buf_fine_old, buf_fine_new); + remove(buf_intermediate_old); + remove(buf_coarse_old); + + for (int i = 1; i < 9; i++) { + char fine_bi[64]; + char intermediate_bi[64]; + char coarse_bi[64]; + char bi[64]; + snprintf(fine_bi, 64, "%s_fine_%d_b%d.gkyl", gr_euler_output, num_frames, i); + snprintf(intermediate_bi, 64, "%s_intermediate_%d_b%d.gkyl", gr_euler_output, num_frames, i); + snprintf(coarse_bi, 64, "%s_coarse_%d_b%d.gkyl", gr_euler_output, num_frames, i); + snprintf(bi, 64, "%s_%d_b%d.gkyl", gr_euler_output, num_frames, i); + rename(intermediate_bi, bi); + remove(fine_bi); + remove(coarse_bi); + } + + for (int i = 9; i < 25; i++) { + char buf_old[64]; + char buf_new[64]; + char buf_del1[64]; + char buf_del2[64]; + + snprintf(buf_old, 64, "%s_coarse_%d_b%d.gkyl", gr_euler_output, num_frames, i); + snprintf(buf_new, 64, "%s_%d_b%d.gkyl", gr_euler_output, num_frames, i); + snprintf(buf_del1, 64, "%s_intermediate_%d_b%d.gkyl", gr_euler_output, num_frames, i); + snprintf(buf_del2, 64, "%s_fine_%d_b%d.gkyl", gr_euler_output, num_frames, i); + + rename(buf_old, buf_new); + remove(buf_del1); + remove(buf_del2); + } +#else + char buf[64]; + snprintf(buf, 64, "%s_%d", gr_euler_output, num_frames); + + euler_write_sol_block(buf, num_blocks, coarse_bdata); +#endif + + printf("Total run-time: %g. Failed steps: %d\n", tm_total_sec, stats.nfail); + + for (int i = 0; i < num_blocks; i++) { + gkyl_fv_proj_release(coarse_bdata[i].fv_proj); + gkyl_wv_eqn_release(coarse_bdata[i].euler); + euler_block_bc_updaters_release(&coarse_bdata[i]); + gkyl_wave_geom_release(coarse_bdata[i].geom); + +#ifdef AMR_DEBUG + gkyl_fv_proj_release(intermediate_bdata[i].fv_proj); + gkyl_wv_eqn_release(intermediate_bdata[i].euler); + euler_block_bc_updaters_release(&intermediate_bdata[i]); + gkyl_wave_geom_release(intermediate_bdata[i].geom); + + gkyl_fv_proj_release(fine_bdata[i].fv_proj); + gkyl_wv_eqn_release(fine_bdata[i].euler); + euler_block_bc_updaters_release(&fine_bdata[i]); + gkyl_wave_geom_release(fine_bdata[i].geom); +#endif + + for (int d = 0; d < ndim; d++) { + gkyl_wave_prop_release(coarse_bdata[i].slvr[d]); + +#ifdef AMR_DEBUG + gkyl_wave_prop_release(intermediate_bdata[i].slvr[d]); + gkyl_wave_prop_release(fine_bdata[i].slvr[d]); +#endif + } + + gkyl_array_release(coarse_bdata[i].fdup); +#ifdef AMR_DEBUG + gkyl_array_release(intermediate_bdata[i].fdup); + gkyl_array_release(fine_bdata[i].fdup); +#endif + + for (int d = 0; d < ndim; d++) { + gkyl_array_release(coarse_bdata[i].f[d]); + +#ifdef AMR_DEBUG + gkyl_array_release(intermediate_bdata[i].f[d]); + gkyl_array_release(fine_bdata[i].f[d]); +#endif + } + } + + gkyl_block_topo_release(btopo); + gkyl_gr_spacetime_release(spacetime); + gkyl_job_pool_release(coarse_job_pool); +#ifdef AMR_DEBUG + gkyl_job_pool_release(intermediate_job_pool); + gkyl_job_pool_release(fine_job_pool); +#endif } \ No newline at end of file diff --git a/amr/gkyl_amr_core.h b/amr/gkyl_amr_core.h index da96d982d..160049ea8 100644 --- a/amr/gkyl_amr_core.h +++ b/amr/gkyl_amr_core.h @@ -196,6 +196,52 @@ struct euler2d_double_init { */ void euler2d_run_double(int argc, char **argv, struct euler2d_double_init* init); +// Initialization data for a 2D simulation using the general relativistic Euler equations, run with static, block-structured mesh refinement with a doubly-nested refinement patch. +struct gr_euler2d_double_init { + int base_Nx; + int base_Ny; + int ref_factor1; + int ref_factor2; + + double coarse_x1; + double coarse_y1; + double coarse_x2; + double coarse_y2; + + double intermediate_x1; + double intermediate_y1; + double intermediate_x2; + double intermediate_y2; + + double refined_x1; + double refined_y1; + double refined_x2; + double refined_y2; + + evalf_t eval; + double gas_gamma; + struct gkyl_gr_spacetime *spacetime; + + char gr_euler_output[32]; + + bool low_order_flux; + double cfl_frac; + + double t_end; + int num_frames; + double dt_failure_tol; + int num_failures_max; +}; + +/** +* Run a 2D simulation using the general relativistic Euler equations, with static, block-structured mesh refinement with a doubly-nested refinement patch. +* +* @param argc Number of command line arguments passed to the function. +* @param argv Array of command line arguments passed to the function. +* @param init Initialization data for the 2D general relativistic Euler equations. +*/ +void gr_euler2d_run_double(int argc, char **argv, struct gr_euler2d_double_init* init); + // Initialization data for a 1D simulation using the coupled five-moment equations, run with static, patch-structured mesh refinement with a single refinement patch. struct five_moment_1d_single_init { int base_Nx; From dd5dc958899dd1aec70bc632cda7f3fd197338d9 Mon Sep 17 00:00:00 2001 From: JonathanGorard Date: Tue, 25 Jun 2024 16:36:15 -0400 Subject: [PATCH 09/32] Fixed bug-inducing typo in the projection setup in amr_core_gr_euler, and got the 2D GR quadrants test running with the new AMR infrastructure. There's some kind of weird instability appearing in the doubly-nested case that's not appearing in the singly-nested case, though (and it gets worse with decreasing CFL, which is rather mysterious). Remains to be tracked down... --- amr/amr_core_gr_euler.c | 8 +- ...rants_2d.c => rt_amr_gr_quadrants_2d_l1.c} | 0 regression/rt_amr_gr_quadrants_2d_l2.c | 344 ++++++++++++++++++ 3 files changed, 348 insertions(+), 4 deletions(-) rename regression/{rt_amr_gr_quadrants_2d.c => rt_amr_gr_quadrants_2d_l1.c} (100%) create mode 100644 regression/rt_amr_gr_quadrants_2d_l2.c diff --git a/amr/amr_core_gr_euler.c b/amr/amr_core_gr_euler.c index 828a23983..3613193bd 100644 --- a/amr/amr_core_gr_euler.c +++ b/amr/amr_core_gr_euler.c @@ -1088,11 +1088,11 @@ gr_euler2d_run_double(int argc, char **argv, struct gr_euler2d_double_init* init #endif for (int i = 0; i < num_blocks; i++) { - coarse_bdata[i].fv_proj = gkyl_fv_proj_new(&coarse_bdata[i].grid, 2, 5, eval, 0); + coarse_bdata[i].fv_proj = gkyl_fv_proj_new(&coarse_bdata[i].grid, 2, 29, eval, 0); #ifdef AMR_DEBUG - intermediate_bdata[i].fv_proj = gkyl_fv_proj_new(&intermediate_bdata[i].grid, 2, 5, eval, 0); - fine_bdata[i].fv_proj = gkyl_fv_proj_new(&fine_bdata[i].grid, 2, 5, eval, 0); + intermediate_bdata[i].fv_proj = gkyl_fv_proj_new(&intermediate_bdata[i].grid, 2, 29, eval, 0); + fine_bdata[i].fv_proj = gkyl_fv_proj_new(&fine_bdata[i].grid, 2, 29, eval, 0); #endif } @@ -1170,7 +1170,7 @@ gr_euler2d_run_double(int argc, char **argv, struct gr_euler2d_double_init* init coarse_bdata[i].fdup = gkyl_array_new(GKYL_DOUBLE, 29, coarse_bdata[i].ext_range.volume); for (int d = 0; d < ndim + 1; d++) { - coarse_bdata[i].f[d] = gkyl_array_new(GKYL_DOUBLE, 20, coarse_bdata[i].ext_range.volume); + coarse_bdata[i].f[d] = gkyl_array_new(GKYL_DOUBLE, 29, coarse_bdata[i].ext_range.volume); } #ifdef AMR_DEBUG diff --git a/regression/rt_amr_gr_quadrants_2d.c b/regression/rt_amr_gr_quadrants_2d_l1.c similarity index 100% rename from regression/rt_amr_gr_quadrants_2d.c rename to regression/rt_amr_gr_quadrants_2d_l1.c diff --git a/regression/rt_amr_gr_quadrants_2d_l2.c b/regression/rt_amr_gr_quadrants_2d_l2.c new file mode 100644 index 000000000..4126c28ce --- /dev/null +++ b/regression/rt_amr_gr_quadrants_2d_l2.c @@ -0,0 +1,344 @@ +// 2D quadrants test, using static, block-structured mesh refinement with doubly-nested refinement blocks (4x4x refinement), for the general relativistic Euler equations. +// Input parameters taken from the initial conditions in Section 4.2 (Riemann 2-D), from the article: +// L. Del Zanna and N. Bucciantini (2002), "An efficient shock-capturing central-type scheme for multdimensional flows. I. Hydrodynamics", +// Astronomy and Astrophysics, Volume 390 (3): 1177-1186. +// https://arxiv.org/abs/astro-ph/0205290 + +#include +#include +#include + +struct amr_gr_quadrants_2d_ctx +{ + // Physical constants (using normalized code units). + double gas_gamma; // Adiabatic index. + + double rho_ul; // Upper left fluid mass density. + double u_ul; // Upper left fluid x-velocity. + double v_ul; // Upper left fluid y-velocity. + double p_ul; // Upper left fluid pressure. + + double rho_ur; // Upper right fluid mass density. + double u_ur; // Upper right fluid x-velocity. + double v_ur; // Upper right fluid y-velocity. + double p_ur; // Upper left fluid pressure. + + double rho_ll; // Lower left fluid mass density. + double u_ll; // Lower left fluid x-velocity. + double v_ll; // Lower left fluid y-velocity. + double p_ll; // Lower left fluid pressure. + + double rho_lr; // Lower right fluid mass density. + double u_lr; // Lower right fluid x-velocity. + double v_lr; // Lower right fluid y-velocity. + double p_lr; // Lower right fluid pressure. + + // Pointer to spacetime metric. + struct gkyl_gr_spacetime *spacetime; + + // Simulation parameters. + int Nx; // Coarse cell count (x-direction). + int Ny; // Coarse cell count (y-direction). + int ref_factor1; // First refinement factor (coarse-to-intermediate). + int ref_factor2; // Second refinement factor (intermediate-to-fine). + double Lx; // Coarse domain size (x-direction). + double Ly; // Coarse domain size (y-direction). + double intermediate_Lx; // Intermediate domain size (x-direction). + double intermediate_Ly; // Intermediate domain size (y-direction). + double fine_Lx; // Fine domain size (x-direction). + double fine_Ly; // Fine domain size (y-direction). + double cfl_frac; // CFL coefficient. + + double t_end; // Final simulation time. + int num_frames; // Number of output frames. + double dt_failure_tol; // Minimum allowable fraction of initial time-step. + int num_failures_max; // Maximum allowable number of consecutive small time-steps. + + double loc; // Fluid boundaries (both x and y coordinates). +}; + +struct amr_gr_quadrants_2d_ctx +create_ctx(void) +{ + // Physical constants (using normalized code units). + double gas_gamma = 5.0 / 3.0; // Adiabatic index. + + double rho_ul = 0.1; // Upper-left fluid mass density. + double u_ul = 0.99; // Upper-left fluid x-velocity. + double v_ul = 0.0; // Upper-left fluid y-velocity. + double p_ul = 1.0; // Upper-left fluid pressure. + + double rho_ur = 0.1; // Upper-right fluid mass density. + double u_ur = 0.0; // Upper-right fluid x-velocity. + double v_ur = 0.0; // Upper-right fluid y-velocity. + double p_ur = 0.01; // Upper-right fluid pressure. + + double rho_ll = 0.5; // Lower-left fluid mass density. + double u_ll = 0.0; // Lower-left fluid x-velocity. + double v_ll = 0.0; // Lower-left fluid y-velocity. + double p_ll = 1.0; // Lower-left fluid pressure. + + double rho_lr = 0.1; // Lower-right fluid mass density. + double u_lr = 0.0; // Lower-right fluid x-velocity. + double v_lr = 0.99; // Lower-right fluid y-velocity. + double p_lr = 1.0; // Lower-right fluid pressure. + + // Pointer to spacetime metric. + struct gkyl_gr_spacetime *spacetime = gkyl_gr_minkowski_new(false); + + // Simulation parameters. + int Nx = 8; // Coarse cell count (x-direction). + int Ny = 8; // Coarse cell count (y-direction). + int ref_factor1 = 4; // First refinement factor (coarse-to-intermediate). + int ref_factor2 = 4; // Second refinement factor (intermediate-to-fine). + double Lx = 1.0; // Coarse domain size (x-direction). + double Ly = 1.0; // Coarse domain size (y-direction). + double intermediate_Lx = 0.75; // Intermediate domain size (x-direction). + double intermediate_Ly = 0.75; // Intermediate domain size (y-direction). + double fine_Lx = 0.5; // Fine domain size (x-direction). + double fine_Ly = 0.5; // Fine domain size (y-direction). + double cfl_frac = 0.95; // CFL coefficient. + double t_end = 0.3; // Final simulation time. + int num_frames = 1; // Number of output frames. + double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. + int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. + + double loc = 0.5; // Fluid boundaries (both x and y coordinates). + + struct amr_gr_quadrants_2d_ctx ctx = { + .gas_gamma = gas_gamma, + .rho_ul = rho_ul, + .u_ul = u_ul, + .v_ul = v_ul, + .p_ul = p_ul, + .rho_ur = rho_ur, + .u_ur = u_ur, + .v_ur = v_ur, + .p_ur = p_ur, + .rho_ll = rho_ll, + .u_ll = u_ll, + .v_ll = v_ll, + .p_ll = p_ll, + .rho_lr = rho_lr, + .u_lr = u_lr, + .v_lr = v_lr, + .p_lr = p_lr, + .spacetime = spacetime, + .Nx = Nx, + .Ny = Ny, + .ref_factor1 = ref_factor1, + .ref_factor2 = ref_factor2, + .Lx = Lx, + .Ly = Ly, + .intermediate_Lx = intermediate_Lx, + .intermediate_Ly = intermediate_Ly, + .fine_Lx = fine_Lx, + .fine_Ly = fine_Ly, + .cfl_frac = cfl_frac, + .t_end = t_end, + .num_frames = num_frames, + .dt_failure_tol = dt_failure_tol, + .num_failures_max = num_failures_max, + .loc = loc, + }; + + return ctx; +} + +void +evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +{ + double x = xn[0], y = xn[1]; + struct amr_gr_quadrants_2d_ctx new_ctx = create_ctx(); // Context for initialization functions. + struct amr_gr_quadrants_2d_ctx *app = &new_ctx; + + double gas_gamma = app->gas_gamma; + + double rho_ul = app->rho_ul; + double u_ul = app->u_ul; + double v_ul = app->v_ul; + double p_ul = app->p_ul; + + double rho_ur = app->rho_ur; + double u_ur = app->u_ur; + double v_ur = app->v_ur; + double p_ur = app->p_ur; + + double rho_ll = app->rho_ll; + double u_ll = app->u_ll; + double v_ll = app->v_ll; + double p_ll = app->p_ll; + + double rho_lr = app->rho_lr; + double u_lr = app->u_lr; + double v_lr = app->v_lr; + double p_lr = app->p_lr; + + struct gkyl_gr_spacetime *spacetime = app->spacetime; + + double loc = app->loc; + + double rho = 0.0; + double u = 0.0; + double v = 0.0; + double p = 0.0; + + if (y > loc) { + if (x < loc) { + rho = rho_ul; // Fluid mass density (upper-left). + u = u_ul; // Fluid x-velocity (upper-left). + v = v_ul; // Fluid y-velocity (upper-left). + p = p_ul; // Fluid pressure (upper-left). + } + else { + rho = rho_ur; // Fluid mass density (upper-right). + u = u_ur; // Fluid x-velocity (upper-right). + v = v_ur; // Fluid y-velocity (upper-right). + p = p_ur; // Fluid pressure (upper-right). + } + } + else { + if (x < loc) { + rho = rho_ll; // Fluid mass density (lower-left). + u = u_ll; // Fluid x-velocity (lower-left). + v = v_ll; // Fluid y-velocity (lower-left). + p = p_ll; // Fluid pressure (lower-left). + } + else { + rho = rho_lr; // Fluid mass density (lower-right). + u = u_lr; // Fluid x-velocity (lower-right). + v = v_lr; // Fluid y-velocity (lower-right). + p = p_lr; // Fluid pressure (lower-right). + } + } + + double spatial_det, lapse; + double *shift = gkyl_malloc(sizeof(double[3])); + bool in_excision_region; + + double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + for (int i = 0; i < 3; i++) { + spatial_metric[i] = gkyl_malloc(sizeof(double[3])); + } + + double **inv_spatial_metric = gkyl_malloc(sizeof(double*[3])); + for (int i = 0; i < 3; i++) { + inv_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); + } + + spacetime->spatial_metric_det_func(spacetime, 0.0, x, y, 0.0, &spatial_det); + spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); + spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); + spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); + + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); + spacetime->spatial_inv_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &inv_spatial_metric); + + double *vel = gkyl_malloc(sizeof(double[3])); + double v_sq = 0.0; + vel[0] = u; vel[1] = v; vel[2] = 0.0; + + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + v_sq += spatial_metric[i][j] * vel[i] * vel[j]; + } + } + + double W = 1.0 / (sqrt(1.0 - v_sq)); + if (v_sq > 1.0 - pow(10.0, -8.0)) { + W = 1.0 / sqrt(1.0 - pow(10.0, -8.0)); + } + + double h = 1.0 + ((p / rho) * (gas_gamma / (gas_gamma - 1.0))); + + // Set fluid mass density. + fout[0] = sqrt(spatial_det) * rho * W; + // Set fluid momentum density. + fout[1] = sqrt(spatial_det) * rho * h * (W * W) * u; + fout[2] = sqrt(spatial_det) * rho * h * (W * W) * v; + fout[3] = 0.0; + // Set fluid total energy density. + fout[4] = sqrt(spatial_det) * ((rho * h * (W * W)) - p - (rho * W)); + + // Set spatial metric determinant. + fout[5] = spatial_det; + // Set lapse gauge variable. + fout[6] = lapse; + // Set shift gauge variables. + fout[7] = shift[0]; fout[8] = shift[1]; fout[9] = shift[2]; + + // Set spatial metric tensor. + fout[10] = spatial_metric[0][0]; fout[11] = spatial_metric[0][1]; fout[12] = spatial_metric[0][2]; + fout[13] = spatial_metric[1][0]; fout[14] = spatial_metric[1][1]; fout[15] = spatial_metric[1][2]; + fout[16] = spatial_metric[2][0]; fout[17] = spatial_metric[2][1]; fout[18] = spatial_metric[2][2]; + + // Set inverse spatial metric tensor. + fout[19] = inv_spatial_metric[0][0]; fout[20] = inv_spatial_metric[0][1]; fout[21] = inv_spatial_metric[0][2]; + fout[22] = inv_spatial_metric[1][0]; fout[23] = inv_spatial_metric[1][1]; fout[24] = inv_spatial_metric[1][2]; + fout[25] = inv_spatial_metric[2][0]; fout[26] = inv_spatial_metric[2][1]; fout[27] = inv_spatial_metric[2][2]; + + // Set excision boundary conditions. + if (in_excision_region) { + for (int i = 0; i < 28; i++) { + fout[i] = 0.0; + } + + fout[28] = -1.0; + } + else { + fout[28] = 1.0; + } + + // Free all tensorial quantities. + for (int i = 0; i < 3; i++) { + gkyl_free(spatial_metric[i]); + gkyl_free(inv_spatial_metric[i]); + } + gkyl_free(spatial_metric); + gkyl_free(inv_spatial_metric); + gkyl_free(shift); + gkyl_free(vel); +} + +int main(int argc, char **argv) +{ + struct amr_gr_quadrants_2d_ctx ctx = create_ctx(); // Context for initialization functions. + + struct gr_euler2d_double_init init = { + .base_Nx = ctx.Nx, + .base_Ny = ctx.Ny, + .ref_factor1 = ctx.ref_factor1, + .ref_factor2 = ctx.ref_factor2, + + .coarse_x1 = 0.0, + .coarse_y1 = 0.0, + .coarse_x2 = ctx.Lx, + .coarse_y2 = ctx.Ly, + + .intermediate_x1 = (0.5 * ctx.Lx) - (0.5 * ctx.intermediate_Lx), + .intermediate_y1 = (0.5 * ctx.Ly) - (0.5 * ctx.intermediate_Ly), + .intermediate_x2 = (0.5 * ctx.Lx) + (0.5 * ctx.intermediate_Lx), + .intermediate_y2 = (0.5 * ctx.Ly) + (0.5 * ctx.intermediate_Ly), + + .refined_x1 = (0.5 * ctx.Lx) - (0.5 * ctx.fine_Lx), + .refined_y1 = (0.5 * ctx.Ly) - (0.5 * ctx.fine_Ly), + .refined_x2 = (0.5 * ctx.Lx) + (0.5 * ctx.fine_Lx), + .refined_y2 = (0.5 * ctx.Ly) + (0.5 * ctx.fine_Ly), + + .eval = evalGREulerInit, + .gas_gamma = ctx.gas_gamma, + .spacetime = ctx.spacetime, + + .gr_euler_output = "amr_gr_quadrants_2d_l2", + + .low_order_flux = true, + .cfl_frac = ctx.cfl_frac, + + .t_end = ctx.t_end, + .num_frames = ctx.num_frames, + .dt_failure_tol = ctx.dt_failure_tol, + .num_failures_max = ctx.num_failures_max, + }; + + gr_euler2d_run_double(argc, argv, &init); +} \ No newline at end of file From 186cd23a1a692bcc2f73ff29b6ff28e7514003bb Mon Sep 17 00:00:00 2001 From: JonathanGorard Date: Wed, 26 Jun 2024 13:12:03 -0400 Subject: [PATCH 10/32] Static black hole ring accretion test (Schwarzschild) now working with doubly-nested AMR and producing beautifully nice results. Also did minor cleanup to all other AMR regression files. --- regression/rt_amr_10m_gem_l1.c | 2 +- regression/rt_amr_5m_gem_l1.c | 2 +- .../rt_amr_euler_cart_axi_sodshock_l1.c | 2 +- regression/rt_amr_euler_riem_2d_l1.c | 2 +- regression/rt_amr_euler_shock_bubble_l1.c | 2 +- ...atic.c => rt_amr_gr_blackhole_static_l1.c} | 2 +- regression/rt_amr_gr_blackhole_static_l2.c | 336 ++++++++++++++++++ regression/rt_amr_gr_quadrants_2d_l1.c | 2 +- 8 files changed, 343 insertions(+), 7 deletions(-) rename regression/{rt_amr_gr_blackhole_static.c => rt_amr_gr_blackhole_static_l1.c} (99%) create mode 100644 regression/rt_amr_gr_blackhole_static_l2.c diff --git a/regression/rt_amr_10m_gem_l1.c b/regression/rt_amr_10m_gem_l1.c index 5282f3c38..f2a70422e 100644 --- a/regression/rt_amr_10m_gem_l1.c +++ b/regression/rt_amr_10m_gem_l1.c @@ -277,7 +277,7 @@ int main(int argc, char **argv) .wall_x = false, .wall_y = true, - .ten_moment_output = "amr_10m_gem", + .ten_moment_output = "amr_10m_gem_l1", .low_order_flux = false, .cfl_frac = ctx.cfl_frac, diff --git a/regression/rt_amr_5m_gem_l1.c b/regression/rt_amr_5m_gem_l1.c index 5e6107832..8702156fb 100644 --- a/regression/rt_amr_5m_gem_l1.c +++ b/regression/rt_amr_5m_gem_l1.c @@ -281,7 +281,7 @@ int main(int argc, char **argv) .wall_x = false, .wall_y = true, - .five_moment_output = "amr_5m_gem", + .five_moment_output = "amr_5m_gem_l1", .low_order_flux = false, .cfl_frac = ctx.cfl_frac, diff --git a/regression/rt_amr_euler_cart_axi_sodshock_l1.c b/regression/rt_amr_euler_cart_axi_sodshock_l1.c index 808f3401b..0528bc929 100644 --- a/regression/rt_amr_euler_cart_axi_sodshock_l1.c +++ b/regression/rt_amr_euler_cart_axi_sodshock_l1.c @@ -167,7 +167,7 @@ int main(int argc, char **argv) .eval = evalEulerInit, .gas_gamma = ctx.gas_gamma, - .euler_output = "amr_euler_cart_axi_sodshock", + .euler_output = "amr_euler_cart_axi_sodshock_l1", .low_order_flux = false, .cfl_frac = ctx.cfl_frac, diff --git a/regression/rt_amr_euler_riem_2d_l1.c b/regression/rt_amr_euler_riem_2d_l1.c index f17f004ac..dfe148348 100644 --- a/regression/rt_amr_euler_riem_2d_l1.c +++ b/regression/rt_amr_euler_riem_2d_l1.c @@ -223,7 +223,7 @@ int main(int argc, char **argv) .eval = evalEulerInit, .gas_gamma = ctx.gas_gamma, - .euler_output = "amr_euler_riem_2d", + .euler_output = "amr_euler_riem_2d_l1", .low_order_flux = false, .cfl_frac = ctx.cfl_frac, diff --git a/regression/rt_amr_euler_shock_bubble_l1.c b/regression/rt_amr_euler_shock_bubble_l1.c index 25999906d..efda418af 100644 --- a/regression/rt_amr_euler_shock_bubble_l1.c +++ b/regression/rt_amr_euler_shock_bubble_l1.c @@ -183,7 +183,7 @@ int main(int argc, char **argv) .eval = evalEulerInit, .gas_gamma = ctx.gas_gamma, - .euler_output = "amr_euler_shock_bubble", + .euler_output = "amr_euler_shock_bubble_l1", .low_order_flux = true, .cfl_frac = ctx.cfl_frac, diff --git a/regression/rt_amr_gr_blackhole_static.c b/regression/rt_amr_gr_blackhole_static_l1.c similarity index 99% rename from regression/rt_amr_gr_blackhole_static.c rename to regression/rt_amr_gr_blackhole_static_l1.c index 93304c4a5..c182ef284 100644 --- a/regression/rt_amr_gr_blackhole_static.c +++ b/regression/rt_amr_gr_blackhole_static_l1.c @@ -306,7 +306,7 @@ int main(int argc, char **argv) .gas_gamma = ctx.gas_gamma, .spacetime = ctx.spacetime, - .gr_euler_output = "amr_gr_blackhole_static", + .gr_euler_output = "amr_gr_blackhole_static_l1", .low_order_flux = true, .cfl_frac = ctx.cfl_frac, diff --git a/regression/rt_amr_gr_blackhole_static_l2.c b/regression/rt_amr_gr_blackhole_static_l2.c new file mode 100644 index 000000000..cc707b6bb --- /dev/null +++ b/regression/rt_amr_gr_blackhole_static_l2.c @@ -0,0 +1,336 @@ +// 2D ring-accretion problem onto a static (Schwarzschild) black hole, using static, block-structured mesh refinement with doubly-nested refinement blocks (4x4x refinement), for the general relativistic Euler equations. +// Input parameters describe an asymmetrical ring of cold relativistic gas accreting onto a non-rotating black hole. + +#include +#include +#include + +struct amr_gr_blackhole_static_ctx +{ + // Mathematical constants (dimensionless). + double pi; + + // Physical constants (using normalized code units). + double gas_gamma; // Adiabatic index. + + double rhob; // Background fluid mass density. + double ub; // Background fluid velocity. + double pb; // Background fluid pressure. + + double rhol; // Left ring fluid mass density. + double ul; // Left ring fluid velocity. + double pl; // Left ring fluid pressure. + + double rhor; // Right ring fluid mass density. + double ur; // Right ring fluid velocity. + double pr; // Right ring fluid pressure. + + // Spacetime parameters (using geometric units). + double mass; // Mass of the black hole. + double spin; // Spin of the black hole. + + double pos_x; // Position of the black hole (x-direction). + double pos_y; // Position of the black hole (y-direction). + double pos_z; // Position of the black hole (z-direction). + + // Pointer to spacetime metric. + struct gkyl_gr_spacetime *spacetime; + + // Simulation parameters. + int Nx; // Coarse cell count (x-direction). + int Ny; // Coarse cell count (y-direction). + int ref_factor1; // First refinement factor (coarse-to-intermediate). + int ref_factor2; // Second refinement factor (intermediate-to-fine). + double Lx; // Coarse domain size (x-direction). + double Ly; // Coarse domain size (y-direction). + double intermediate_Lx; // Intermediate domain size (x-direction). + double intermediate_Ly; // Intermediate domain size (y-direction). + double fine_Lx; // Fine domain size (x-direction). + double fine_Ly; // Fine domain size (y-direction). + double cfl_frac; // CFL coefficient. + + double t_end; // Final simulation time. + int num_frames; // Number of output frames. + double dt_failure_tol; // Minimum allowable fraction of initial time-step. + int num_failures_max; // Maximum allowable number of consecutive small time-steps. + + double r_inner; // Ring inner radius. + double r_outer; // Ring outer radius. +}; + +struct amr_gr_blackhole_static_ctx +create_ctx(void) +{ + // Mathematical constants (dimensionless). + double pi = M_PI; + + // Physical constants (using normalized code units). + double gas_gamma = 5.0 / 3.0; // Adiabatic index. + + double rhob = 0.01; // Background fluid mass density. + double ub = 0.0; // Background fluid velocity. + double pb = 0.01; // Background fluid pressure. + + double rhol = 1.0; // Left ring fluid mass density. + double ul = 0.0; // Left ring fluid velocity. + double pl = 0.1; // Left ring fluid pressure. + + double rhor = 2.0; // Right ring fluid mass density. + double ur = 0.0; // Right ring fluid velocity. + double pr = 0.1; // Right ring fluid pressure. + + // Spacetime parameters (using geometric units). + double mass = 0.3; // Mass of the black hole. + double spin = 0.0; // Spin of the black hole. + + double pos_x = 2.5; // Position of the black hole (x-direction). + double pos_y = 2.5; // Position of the black hole (y-direction). + double pos_z = 0.0; // Position of the black hole (z-direction). + + // Pointer to spacetime metric. + struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); + + // Simulation parameters. + int Nx = 8; // Coarse cell count (x-direction). + int Ny = 8; // Coarse cell count (y-direction). + int ref_factor1 = 4; // First refinement factor (coarse-to-intermediate). + int ref_factor2 = 4; // Second refinement factor (intermediate-to-fine). + double Lx = 5.0; // Coarse domain size (x-direction). + double Ly = 5.0; // Coarse domain size (y-direction). + double intermediate_Lx = 3.5; // Intermediate domain size (x-direction). + double intermediate_Ly = 3.5; // Intermediate domain size (y-direction). + double fine_Lx = 2.0; // Fine domain size (x-direction). + double fine_Ly = 2.0; // Fine domain size (y-direction). + double cfl_frac = 0.95; // CFL coefficient. + + double t_end = 5.0; // Final simulation time. + int num_frames = 1; // Number of output frames. + double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. + int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. + + double r_inner = 1.2; // Ring inner radius. + double r_outer = 2.4; // Ring outer radius. + + struct amr_gr_blackhole_static_ctx ctx = { + .pi = pi, + .gas_gamma = gas_gamma, + .rhob = rhob, + .ub = ub, + .pb = pb, + .rhol = rhol, + .ul = ul, + .pl = pl, + .rhor = rhor, + .ur = ur, + .pr = pr, + .mass = mass, + .spin = spin, + .pos_x = pos_x, + .pos_y = pos_y, + .pos_z = pos_z, + .spacetime = spacetime, + .Nx = Nx, + .Ny = Ny, + .ref_factor1 = ref_factor1, + .ref_factor2 = ref_factor2, + .Lx = Lx, + .Ly = Ly, + .intermediate_Lx = intermediate_Lx, + .intermediate_Ly = intermediate_Ly, + .fine_Lx = fine_Lx, + .fine_Ly = fine_Ly, + .cfl_frac = cfl_frac, + .t_end = t_end, + .num_frames = num_frames, + .dt_failure_tol = dt_failure_tol, + .num_failures_max = num_failures_max, + .r_inner = r_inner, + .r_outer = r_outer, + }; + + return ctx; +} + +void +evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +{ + double x = xn[0], y = xn[1]; + struct amr_gr_blackhole_static_ctx new_ctx = create_ctx(); // Context for initialization functions. + struct amr_gr_blackhole_static_ctx *app = &new_ctx; + + double gas_gamma = app->gas_gamma; + + double rhob = app->rhob; + double ub = app->ub; + double pb = app->pb; + + double rhol = app->rhol; + double ul = app->ul; + double pl = app->pl; + + double rhor = app->rhor; + double ur = app->ur; + double pr = app->pr; + + struct gkyl_gr_spacetime *spacetime = app->spacetime; + + double r_inner = app->r_inner; + double r_outer = app->r_outer; + + double Lx = app->Lx; + double Ly = app->Ly; + + double rho = 0.0; + double u = 0.0; + double p = 0.0; + + double r = sqrt((x - (0.5 * Lx)) * (x - (0.5 * Lx)) + (y - (0.5 * Ly)) * (y - (0.5 * Ly))); + + if (r > r_inner && r < r_outer) { + if (x < (0.5 * Lx)) { + rho = rhol; // Fluid mass density (left ring). + u = ul; // Fluid velocity (left ring). + p = pl; // Fluid pressure (left ring). + } + else { + rho = rhor; // Fluid mass density (right ring). + u = ur; // Fluid velocity (right ring). + p = pr; // Fluid pressure (right ring). + } + } + else { + rho = rhob; // Fluid mass density (background). + u = ub; // Fluid velocity (background). + p = pb; // Fluid pressure (background). + } + + double spatial_det, lapse; + double *shift = gkyl_malloc(sizeof(double[3])); + bool in_excision_region; + + double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + for (int i = 0; i < 3; i++) { + spatial_metric[i] = gkyl_malloc(sizeof(double[3])); + } + + double **inv_spatial_metric = gkyl_malloc(sizeof(double*[3])); + for (int i = 0; i < 3; i++) { + inv_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); + } + + spacetime->spatial_metric_det_func(spacetime, 0.0, x, y, 0.0, &spatial_det); + spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); + spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); + spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); + + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); + spacetime->spatial_inv_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &inv_spatial_metric); + + double *vel = gkyl_malloc(sizeof(double[3])); + double v_sq = 0.0; + vel[0] = u; vel[1] = 0.0; vel[2] = 0.0; + + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + v_sq += spatial_metric[i][j] * vel[i] * vel[j]; + } + } + + double W = 1.0 / (sqrt(1.0 - v_sq)); + if (v_sq > 1.0 - pow(10.0, -8.0)) { + W = 1.0 / sqrt(1.0 - pow(10.0, -8.0)); + } + + double h = 1.0 + ((p / rho) * (gas_gamma / (gas_gamma - 1.0))); + + // Set fluid mass density. + fout[0] = sqrt(spatial_det) * rho * W; + // Set fluid momentum density. + fout[1] = sqrt(spatial_det) * rho * h * (W * W) * u; + fout[2] = 0.0; + fout[3] = 0.0; + // Set fluid total energy density. + fout[4] = sqrt(spatial_det) * ((rho * h * (W * W)) - p - (rho * W)); + + // Set spatial metric determinant. + fout[5] = spatial_det; + // Set lapse gauge variable. + fout[6] = lapse; + // Set shift gauge variables. + fout[7] = shift[0]; fout[8] = shift[1]; fout[9] = shift[2]; + + // Set spatial metric tensor. + fout[10] = spatial_metric[0][0]; fout[11] = spatial_metric[0][1]; fout[12] = spatial_metric[0][2]; + fout[13] = spatial_metric[1][0]; fout[14] = spatial_metric[1][1]; fout[15] = spatial_metric[1][2]; + fout[16] = spatial_metric[2][0]; fout[17] = spatial_metric[2][1]; fout[18] = spatial_metric[2][2]; + + // Set inverse spatial metric tensor. + fout[19] = inv_spatial_metric[0][0]; fout[20] = inv_spatial_metric[0][1]; fout[21] = inv_spatial_metric[0][2]; + fout[22] = inv_spatial_metric[1][0]; fout[23] = inv_spatial_metric[1][1]; fout[24] = inv_spatial_metric[1][2]; + fout[25] = inv_spatial_metric[2][0]; fout[26] = inv_spatial_metric[2][1]; fout[27] = inv_spatial_metric[2][2]; + + // Set excision boundary conditions. + if (in_excision_region) { + for (int i = 0; i < 28; i++) { + fout[i] = 0.0; + } + + fout[28] = -1.0; + } + else { + fout[28] = 1.0; + } + + // Free all tensorial quantities. + for (int i = 0; i < 3; i++) { + gkyl_free(spatial_metric[i]); + gkyl_free(inv_spatial_metric[i]); + } + gkyl_free(spatial_metric); + gkyl_free(inv_spatial_metric); + gkyl_free(shift); + gkyl_free(vel); +} + +int main(int argc, char **argv) +{ + struct amr_gr_blackhole_static_ctx ctx = create_ctx(); // Context for initialization functions. + + struct gr_euler2d_double_init init = { + .base_Nx = ctx.Nx, + .base_Ny = ctx.Ny, + .ref_factor1 = ctx.ref_factor1, + .ref_factor2 = ctx.ref_factor2, + + .coarse_x1 = 0.0, + .coarse_y1 = 0.0, + .coarse_x2 = ctx.Lx, + .coarse_y2 = ctx.Ly, + + .intermediate_x1 = (0.5 * ctx.Lx) - (0.5 * ctx.intermediate_Lx), + .intermediate_y1 = (0.5 * ctx.Ly) - (0.5 * ctx.intermediate_Ly), + .intermediate_x2 = (0.5 * ctx.Lx) + (0.5 * ctx.intermediate_Lx), + .intermediate_y2 = (0.5 * ctx.Ly) + (0.5 * ctx.intermediate_Ly), + + .refined_x1 = (0.5 * ctx.Lx) - (0.5 * ctx.fine_Lx), + .refined_y1 = (0.5 * ctx.Ly) - (0.5 * ctx.fine_Ly), + .refined_x2 = (0.5 * ctx.Lx) + (0.5 * ctx.fine_Lx), + .refined_y2 = (0.5 * ctx.Ly) + (0.5 * ctx.fine_Ly), + + .eval = evalGREulerInit, + .gas_gamma = ctx.gas_gamma, + .spacetime = ctx.spacetime, + + .gr_euler_output = "amr_gr_blackhole_static_l2", + + .low_order_flux = true, + .cfl_frac = ctx.cfl_frac, + + .t_end = ctx.t_end, + .num_frames = ctx.num_frames, + .dt_failure_tol = ctx.dt_failure_tol, + .num_failures_max = ctx.num_failures_max, + }; + + gr_euler2d_run_double(argc, argv, &init); +} \ No newline at end of file diff --git a/regression/rt_amr_gr_quadrants_2d_l1.c b/regression/rt_amr_gr_quadrants_2d_l1.c index da119f06c..b0547cffb 100644 --- a/regression/rt_amr_gr_quadrants_2d_l1.c +++ b/regression/rt_amr_gr_quadrants_2d_l1.c @@ -315,7 +315,7 @@ int main(int argc, char **argv) .gas_gamma = ctx.gas_gamma, .spacetime = ctx.spacetime, - .gr_euler_output = "amr_gr_quadrants_2d", + .gr_euler_output = "amr_gr_quadrants_2d_l1", .low_order_flux = true, .cfl_frac = ctx.cfl_frac, From d4b67b3430c70858f0e80d0160083813dceab5e0 Mon Sep 17 00:00:00 2001 From: JonathanGorard Date: Wed, 26 Jun 2024 14:15:07 -0400 Subject: [PATCH 11/32] Spinning black hole ring accretion (Kerr), as well as both static and spinning Bondi-Hoyle-Lyttleton accretion, now working with doubly-nested AMR, with appropriate modifications made to ensure numerical stability and correct mesh tracking. --- ...spinning.c => rt_amr_gr_bhl_spinning_l1.c} | 2 +- regression/rt_amr_gr_bhl_spinning_l2.c | 312 ++++++++++++++++ ...bhl_static.c => rt_amr_gr_bhl_static_l1.c} | 2 +- regression/rt_amr_gr_bhl_static_l2.c | 312 ++++++++++++++++ ...ng.c => rt_amr_gr_blackhole_spinning_l1.c} | 2 +- regression/rt_amr_gr_blackhole_spinning_l2.c | 336 ++++++++++++++++++ 6 files changed, 963 insertions(+), 3 deletions(-) rename regression/{rt_amr_gr_bhl_spinning.c => rt_amr_gr_bhl_spinning_l1.c} (99%) create mode 100644 regression/rt_amr_gr_bhl_spinning_l2.c rename regression/{rt_amr_gr_bhl_static.c => rt_amr_gr_bhl_static_l1.c} (99%) create mode 100644 regression/rt_amr_gr_bhl_static_l2.c rename regression/{rt_amr_gr_blackhole_spinning.c => rt_amr_gr_blackhole_spinning_l1.c} (99%) create mode 100644 regression/rt_amr_gr_blackhole_spinning_l2.c diff --git a/regression/rt_amr_gr_bhl_spinning.c b/regression/rt_amr_gr_bhl_spinning_l1.c similarity index 99% rename from regression/rt_amr_gr_bhl_spinning.c rename to regression/rt_amr_gr_bhl_spinning_l1.c index 1742b605f..8e689a2f2 100644 --- a/regression/rt_amr_gr_bhl_spinning.c +++ b/regression/rt_amr_gr_bhl_spinning_l1.c @@ -282,7 +282,7 @@ int main(int argc, char **argv) .gas_gamma = ctx.gas_gamma, .spacetime = ctx.spacetime, - .gr_euler_output = "amr_gr_bhl_spinning", + .gr_euler_output = "amr_gr_bhl_spinning_l1", .low_order_flux = true, .cfl_frac = ctx.cfl_frac, diff --git a/regression/rt_amr_gr_bhl_spinning_l2.c b/regression/rt_amr_gr_bhl_spinning_l2.c new file mode 100644 index 000000000..225dc2d30 --- /dev/null +++ b/regression/rt_amr_gr_bhl_spinning_l2.c @@ -0,0 +1,312 @@ +// 2D Bondi-Hoyle-Lyttleton accretion problem onto a non-static (Kerr) black hole, using static, block-structured mesh refinement with doubly-nested refinement blocks (4x4x refinement), for the general relativistic Euler equations. +// Input parameters describe wind accretion of a cold relativistic gas onto a spinning black hole. +// Based on the analytical solution for stiff relativistic fluids presented in the article: +// L. I. Petrich, S. L. Shapiro and S. A. Teukolsky (1988), "Accretion onto a moving black hole: An exact solution", +// Physical Review Letters, Volume 60 (18): 1781-1784. +// https://journals.aps.org/prl/abstract/10.1103/PhysRevLett.60.1781 + +#include +#include +#include + +struct amr_gr_bhl_spinning_ctx +{ + // Mathematical constants (dimensionless). + double pi; + + // Physical constants (using normalized code units). + double gas_gamma; // Adiabatic index. + + double rhol; // Left fluid mass density. + double ul; // Left fluid velocity. + double pl; // Left fluid pressure. + + double rhor; // Right fluid mass density. + double ur; // Right fluid velocity. + double pr; // Right fluid pressure. + + // Spacetime parameters (using geometric units). + double mass; // Mass of the black hole. + double spin; // Spin of the black hole. + + double pos_x; // Position of the black hole (x-direction). + double pos_y; // Position of the black hole (y-direction). + double pos_z; // Position of the black hole (z-direction). + + // Pointer to spacetime metric. + struct gkyl_gr_spacetime *spacetime; + + // Simulation parameters. + int Nx; // Coarse cell count (x-direction). + int Ny; // Coarse cell count (y-direction). + int ref_factor1; // First refinement factor (coarse-to-intermediate). + int ref_factor2; // Second refinement factor (intermediate-to-fine). + double Lx; // Coarse domain size (x-direction). + double Ly; // Coarse domain size (y-direction). + double intermediate_Lx; // Intermediate domain size (x-direction). + double intermediate_Ly; // Intermediate domain size (y-direction). + double fine_Lx; // Fine domain size (x-direction). + double fine_Ly; // Fine domain size (y-direction). + double cfl_frac; // CFL coefficient. + + double t_end; // Final simulation time. + int num_frames; // Number of output frames. + double dt_failure_tol; // Minimum allowable fraction of initial time-step. + int num_failures_max; // Maximum allowable number of consecutive small time-steps. + + double x_loc; // Shock location (x-direction). +}; + +struct amr_gr_bhl_spinning_ctx +create_ctx(void) +{ + // Mathematical constants (dimensionless). + double pi = M_PI; + + // Physical constants (using normalized code units). + double gas_gamma = 5.0 / 3.0; // Adiabatic index. + + double rhol = 3.0; // Left fluid mass density. + double ul = 0.3; // Left fluid velocity. + double pl = 0.05; // Left fluid pressure. + + double rhor = 0.01; // Right fluid mass density. + double ur = 0.0; // Right fluid velocity. + double pr = 0.01; // Right fluid pressure. + + // Spacetime parameters (using geometric units). + double mass = 0.3; // Mass of the black hole. + double spin = -0.5; // Spin of the black hole. + + double pos_x = 2.5; // Position of the black hole (x-direction). + double pos_y = 2.5; // Position of the black hole (y-direction). + double pos_z = 0.0; // Position of the black hole (z-direction). + + // Pointer to spacetime metric. + struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); + + // Simulation parameters. + int Nx = 8; // Coarse cell count (x-direction). + int Ny = 8; // Coarse cell count (y-direction). + int ref_factor1 = 4; // First refinement factor (coarse-to-intermediate). + int ref_factor2 = 4; // Second refinement factor (intermediate-to-fine). + double Lx = 5.0; // Coarse domain size (x-direction). + double Ly = 5.0; // Coarse domain size (y-direction). + double intermediate_Lx = 4.0; // Intermediate domain size (x-direction). + double intermediate_Ly = 3.75; // Intermediate domain size (y-direction). + double fine_Lx = 2.5; // Fine domain size (x-direction). + double fine_Ly = 2.25; // Fine domain size (y-direction). + double cfl_frac = 0.95; // CFL coefficient. + + double t_end = 15.0; // Final simulation time. + int num_frames = 1; // Number of output frames. + double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. + int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. + + double x_loc = 1.0; // Shock location (x-direction). + + struct amr_gr_bhl_spinning_ctx ctx = { + .pi = pi, + .gas_gamma = gas_gamma, + .rhol = rhol, + .ul = ul, + .pl = pl, + .rhor = rhor, + .ur = ur, + .pr = pr, + .mass = mass, + .spin = spin, + .pos_x = pos_x, + .pos_y = pos_y, + .pos_z = pos_z, + .spacetime = spacetime, + .Nx = Nx, + .Ny = Ny, + .ref_factor1 = ref_factor1, + .ref_factor2 = ref_factor2, + .Lx = Lx, + .Ly = Ly, + .intermediate_Lx = intermediate_Lx, + .intermediate_Ly = intermediate_Ly, + .fine_Lx = fine_Lx, + .fine_Ly = fine_Ly, + .cfl_frac = cfl_frac, + .t_end = t_end, + .num_frames = num_frames, + .dt_failure_tol = dt_failure_tol, + .num_failures_max = num_failures_max, + .x_loc = x_loc, + }; + + return ctx; +} + +void +evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +{ + double x = xn[0], y = xn[1]; + struct amr_gr_bhl_spinning_ctx new_ctx = create_ctx(); // Context for initialization functions. + struct amr_gr_bhl_spinning_ctx *app = &new_ctx; + + double gas_gamma = app->gas_gamma; + + double rhol = app->rhol; + double ul = app->ul; + double pl = app->pl; + + double rhor = app->rhor; + double ur = app->ur; + double pr = app->pr; + + struct gkyl_gr_spacetime *spacetime = app->spacetime; + + double x_loc = app->x_loc; + + double Lx = app->Lx; + double Ly = app->Ly; + + double rho = 0.0; + double u = 0.0; + double p = 0.0; + + if (x < x_loc) { + rho = rhol; // Fluid mass density (left). + u = ul; // Fluid velocity (left). + p = pl; // Fluid pressure (left). + } + else { + rho = rhor; // Fluid mass density (right). + u = ur; // Fluid velocity (right). + p = pr; // Fluid pressure (right). + } + + double spatial_det, lapse; + double *shift = gkyl_malloc(sizeof(double[3])); + bool in_excision_region; + + double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + for (int i = 0; i < 3; i++) { + spatial_metric[i] = gkyl_malloc(sizeof(double[3])); + } + + double **inv_spatial_metric = gkyl_malloc(sizeof(double*[3])); + for (int i = 0; i < 3; i++) { + inv_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); + } + + spacetime->spatial_metric_det_func(spacetime, 0.0, x, y, 0.0, &spatial_det); + spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); + spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); + spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); + + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); + spacetime->spatial_inv_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &inv_spatial_metric); + + double *vel = gkyl_malloc(sizeof(double[3])); + double v_sq = 0.0; + vel[0] = u; vel[1] = 0.0; vel[2] = 0.0; + + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + v_sq += spatial_metric[i][j] * vel[i] * vel[j]; + } + } + + double W = 1.0 / (sqrt(1.0 - v_sq)); + if (v_sq > 1.0 - pow(10.0, -8.0)) { + W = 1.0 / sqrt(1.0 - pow(10.0, -8.0)); + } + + double h = 1.0 + ((p / rho) * (gas_gamma / (gas_gamma - 1.0))); + + // Set fluid mass density. + fout[0] = sqrt(spatial_det) * rho * W; + // Set fluid momentum density. + fout[1] = sqrt(spatial_det) * rho * h * (W * W) * u; + fout[2] = 0.0; + fout[3] = 0.0; + // Set fluid total energy density. + fout[4] = sqrt(spatial_det) * ((rho * h * (W * W)) - p - (rho * W)); + + // Set spatial metric determinant. + fout[5] = spatial_det; + // Set lapse gauge variable. + fout[6] = lapse; + // Set shift gauge variables. + fout[7] = shift[0]; fout[8] = shift[1]; fout[9] = shift[2]; + + // Set spatial metric tensor. + fout[10] = spatial_metric[0][0]; fout[11] = spatial_metric[0][1]; fout[12] = spatial_metric[0][2]; + fout[13] = spatial_metric[1][0]; fout[14] = spatial_metric[1][1]; fout[15] = spatial_metric[1][2]; + fout[16] = spatial_metric[2][0]; fout[17] = spatial_metric[2][1]; fout[18] = spatial_metric[2][2]; + + // Set inverse spatial metric tensor. + fout[19] = inv_spatial_metric[0][0]; fout[20] = inv_spatial_metric[0][1]; fout[21] = inv_spatial_metric[0][2]; + fout[22] = inv_spatial_metric[1][0]; fout[23] = inv_spatial_metric[1][1]; fout[24] = inv_spatial_metric[1][2]; + fout[25] = inv_spatial_metric[2][0]; fout[26] = inv_spatial_metric[2][1]; fout[27] = inv_spatial_metric[2][2]; + + // Set excision boundary conditions. + if (in_excision_region) { + for (int i = 0; i < 28; i++) { + fout[i] = 0.0; + } + + fout[28] = -1.0; + } + else { + fout[28] = 1.0; + } + + // Free all tensorial quantities. + for (int i = 0; i < 3; i++) { + gkyl_free(spatial_metric[i]); + gkyl_free(inv_spatial_metric[i]); + } + gkyl_free(spatial_metric); + gkyl_free(inv_spatial_metric); + gkyl_free(shift); + gkyl_free(vel); +} + +int main(int argc, char **argv) +{ + struct amr_gr_bhl_spinning_ctx ctx = create_ctx(); // Context for initialization functions. + + struct gr_euler2d_double_init init = { + .base_Nx = ctx.Nx, + .base_Ny = ctx.Ny, + .ref_factor1 = ctx.ref_factor1, + .ref_factor2 = ctx.ref_factor2, + + .coarse_x1 = 0.0, + .coarse_y1 = 0.0, + .coarse_x2 = ctx.Lx, + .coarse_y2 = ctx.Ly, + + .intermediate_x1 = (0.55 * ctx.Lx) - (0.5 * ctx.intermediate_Lx), + .intermediate_y1 = (0.475 * ctx.Ly) - (0.5 * ctx.intermediate_Ly), + .intermediate_x2 = (0.55 * ctx.Lx) + (0.5 * ctx.intermediate_Lx), + .intermediate_y2 = (0.475 * ctx.Ly) + (0.5 * ctx.intermediate_Ly), + + .refined_x1 = (0.6 * ctx.Lx) - (0.5 * ctx.fine_Lx), + .refined_y1 = (0.45 * ctx.Ly) - (0.5 * ctx.fine_Ly), + .refined_x2 = (0.6 * ctx.Lx) + (0.5 * ctx.fine_Lx), + .refined_y2 = (0.45 * ctx.Ly) + (0.5 * ctx.fine_Ly), + + .eval = evalGREulerInit, + .gas_gamma = ctx.gas_gamma, + .spacetime = ctx.spacetime, + + .gr_euler_output = "amr_gr_bhl_spinning_l2", + + .low_order_flux = true, + .cfl_frac = ctx.cfl_frac, + + .t_end = ctx.t_end, + .num_frames = ctx.num_frames, + .dt_failure_tol = ctx.dt_failure_tol, + .num_failures_max = ctx.num_failures_max, + }; + + gr_euler2d_run_double(argc, argv, &init); +} \ No newline at end of file diff --git a/regression/rt_amr_gr_bhl_static.c b/regression/rt_amr_gr_bhl_static_l1.c similarity index 99% rename from regression/rt_amr_gr_bhl_static.c rename to regression/rt_amr_gr_bhl_static_l1.c index e434891ab..98d144222 100644 --- a/regression/rt_amr_gr_bhl_static.c +++ b/regression/rt_amr_gr_bhl_static_l1.c @@ -282,7 +282,7 @@ int main(int argc, char **argv) .gas_gamma = ctx.gas_gamma, .spacetime = ctx.spacetime, - .gr_euler_output = "amr_gr_bhl_static", + .gr_euler_output = "amr_gr_bhl_static_l1", .low_order_flux = true, .cfl_frac = ctx.cfl_frac, diff --git a/regression/rt_amr_gr_bhl_static_l2.c b/regression/rt_amr_gr_bhl_static_l2.c new file mode 100644 index 000000000..f43aa0eab --- /dev/null +++ b/regression/rt_amr_gr_bhl_static_l2.c @@ -0,0 +1,312 @@ +// 2D Bondi-Hoyle-Lyttleton accretion problem onto a static (Schwarzschild) black hole, using static, block-structured mesh refinement with doubly-nested refinement blocks (4x4x refinement), for the general relativistic Euler equations. +// Input parameters describe wind accretion of a cold relativistic gas onto a non-rotating black hole. +// Based on the analytical solution for stiff relativistic fluids presented in the article: +// L. I. Petrich, S. L. Shapiro and S. A. Teukolsky (1988), "Accretion onto a moving black hole: An exact solution", +// Physical Review Letters, Volume 60 (18): 1781-1784. +// https://journals.aps.org/prl/abstract/10.1103/PhysRevLett.60.1781 + +#include +#include +#include + +struct amr_gr_bhl_static_ctx +{ + // Mathematical constants (dimensionless). + double pi; + + // Physical constants (using normalized code units). + double gas_gamma; // Adiabatic index. + + double rhol; // Left fluid mass density. + double ul; // Left fluid velocity. + double pl; // Left fluid pressure. + + double rhor; // Right fluid mass density. + double ur; // Right fluid velocity. + double pr; // Right fluid pressure. + + // Spacetime parameters (using geometric units). + double mass; // Mass of the black hole. + double spin; // Spin of the black hole. + + double pos_x; // Position of the black hole (x-direction). + double pos_y; // Position of the black hole (y-direction). + double pos_z; // Position of the black hole (z-direction). + + // Pointer to spacetime metric. + struct gkyl_gr_spacetime *spacetime; + + // Simulation parameters. + int Nx; // Coarse cell count (x-direction). + int Ny; // Coarse cell count (y-direction). + int ref_factor1; // First refinement factor (coarse-to-intermediate). + int ref_factor2; // Second refinement factor (intermediate-to-fine). + double Lx; // Coarse domain size (x-direction). + double Ly; // Coarse domain size (y-direction). + double intermediate_Lx; // Intermediate domain size (x-direction). + double intermediate_Ly; // Intermediate domain size (y-direction). + double fine_Lx; // Fine domain size (x-direction). + double fine_Ly; // Fine domain size (y-direction). + double cfl_frac; // CFL coefficient. + + double t_end; // Final simulation time. + int num_frames; // Number of output frames. + double dt_failure_tol; // Minimum allowable fraction of initial time-step. + int num_failures_max; // Maximum allowable number of consecutive small time-steps. + + double x_loc; // Shock location (x-direction). +}; + +struct amr_gr_bhl_static_ctx +create_ctx(void) +{ + // Mathematical constants (dimensionless). + double pi = M_PI; + + // Physical constants (using normalized code units). + double gas_gamma = 5.0 / 3.0; // Adiabatic index. + + double rhol = 3.0; // Left fluid mass density. + double ul = 0.3; // Left fluid velocity. + double pl = 0.05; // Left fluid pressure. + + double rhor = 0.01; // Right fluid mass density. + double ur = 0.0; // Right fluid velocity. + double pr = 0.01; // Right fluid pressure. + + // Spacetime parameters (using geometric units). + double mass = 0.3; // Mass of the black hole. + double spin = 0.0; // Spin of the black hole. + + double pos_x = 2.5; // Position of the black hole (x-direction). + double pos_y = 2.5; // Position of the black hole (y-direction). + double pos_z = 0.0; // Position of the black hole (z-direction). + + // Pointer to spacetime metric. + struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); + + // Simulation parameters. + int Nx = 8; // Coarse cell count (x-direction). + int Ny = 8; // Coarse cell count (y-direction). + int ref_factor1 = 4; // First refinement factor (coarse-to-intermediate). + int ref_factor2 = 4; // Second refinement factor (intermediate-to-fine). + double Lx = 5.0; // Coarse domain size (x-direction). + double Ly = 5.0; // Coarse domain size (y-direction). + double intermediate_Lx = 4.0; // Intermediate domain size (x-direction). + double intermediate_Ly = 3.5; // Intermediate domain size (y-direction). + double fine_Lx = 2.5; // Fine domain size (x-direction). + double fine_Ly = 2.0; // Fine domain size (y-direction). + double cfl_frac = 0.95; // CFL coefficient. + + double t_end = 15.0; // Final simulation time. + int num_frames = 1; // Number of output frames. + double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. + int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. + + double x_loc = 1.0; // Shock location (x-direction). + + struct amr_gr_bhl_static_ctx ctx = { + .pi = pi, + .gas_gamma = gas_gamma, + .rhol = rhol, + .ul = ul, + .pl = pl, + .rhor = rhor, + .ur = ur, + .pr = pr, + .mass = mass, + .spin = spin, + .pos_x = pos_x, + .pos_y = pos_y, + .pos_z = pos_z, + .spacetime = spacetime, + .Nx = Nx, + .Ny = Ny, + .ref_factor1 = ref_factor1, + .ref_factor2 = ref_factor2, + .Lx = Lx, + .Ly = Ly, + .intermediate_Lx = intermediate_Lx, + .intermediate_Ly = intermediate_Ly, + .fine_Lx = fine_Lx, + .fine_Ly = fine_Ly, + .cfl_frac = cfl_frac, + .t_end = t_end, + .num_frames = num_frames, + .dt_failure_tol = dt_failure_tol, + .num_failures_max = num_failures_max, + .x_loc = x_loc, + }; + + return ctx; +} + +void +evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +{ + double x = xn[0], y = xn[1]; + struct amr_gr_bhl_static_ctx new_ctx = create_ctx(); // Context for initialization functions. + struct amr_gr_bhl_static_ctx *app = &new_ctx; + + double gas_gamma = app->gas_gamma; + + double rhol = app->rhol; + double ul = app->ul; + double pl = app->pl; + + double rhor = app->rhor; + double ur = app->ur; + double pr = app->pr; + + struct gkyl_gr_spacetime *spacetime = app->spacetime; + + double x_loc = app->x_loc; + + double Lx = app->Lx; + double Ly = app->Ly; + + double rho = 0.0; + double u = 0.0; + double p = 0.0; + + if (x < x_loc) { + rho = rhol; // Fluid mass density (left). + u = ul; // Fluid velocity (left). + p = pl; // Fluid pressure (left). + } + else { + rho = rhor; // Fluid mass density (right). + u = ur; // Fluid velocity (right). + p = pr; // Fluid pressure (right). + } + + double spatial_det, lapse; + double *shift = gkyl_malloc(sizeof(double[3])); + bool in_excision_region; + + double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + for (int i = 0; i < 3; i++) { + spatial_metric[i] = gkyl_malloc(sizeof(double[3])); + } + + double **inv_spatial_metric = gkyl_malloc(sizeof(double*[3])); + for (int i = 0; i < 3; i++) { + inv_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); + } + + spacetime->spatial_metric_det_func(spacetime, 0.0, x, y, 0.0, &spatial_det); + spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); + spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); + spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); + + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); + spacetime->spatial_inv_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &inv_spatial_metric); + + double *vel = gkyl_malloc(sizeof(double[3])); + double v_sq = 0.0; + vel[0] = u; vel[1] = 0.0; vel[2] = 0.0; + + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + v_sq += spatial_metric[i][j] * vel[i] * vel[j]; + } + } + + double W = 1.0 / (sqrt(1.0 - v_sq)); + if (v_sq > 1.0 - pow(10.0, -8.0)) { + W = 1.0 / sqrt(1.0 - pow(10.0, -8.0)); + } + + double h = 1.0 + ((p / rho) * (gas_gamma / (gas_gamma - 1.0))); + + // Set fluid mass density. + fout[0] = sqrt(spatial_det) * rho * W; + // Set fluid momentum density. + fout[1] = sqrt(spatial_det) * rho * h * (W * W) * u; + fout[2] = 0.0; + fout[3] = 0.0; + // Set fluid total energy density. + fout[4] = sqrt(spatial_det) * ((rho * h * (W * W)) - p - (rho * W)); + + // Set spatial metric determinant. + fout[5] = spatial_det; + // Set lapse gauge variable. + fout[6] = lapse; + // Set shift gauge variables. + fout[7] = shift[0]; fout[8] = shift[1]; fout[9] = shift[2]; + + // Set spatial metric tensor. + fout[10] = spatial_metric[0][0]; fout[11] = spatial_metric[0][1]; fout[12] = spatial_metric[0][2]; + fout[13] = spatial_metric[1][0]; fout[14] = spatial_metric[1][1]; fout[15] = spatial_metric[1][2]; + fout[16] = spatial_metric[2][0]; fout[17] = spatial_metric[2][1]; fout[18] = spatial_metric[2][2]; + + // Set inverse spatial metric tensor. + fout[19] = inv_spatial_metric[0][0]; fout[20] = inv_spatial_metric[0][1]; fout[21] = inv_spatial_metric[0][2]; + fout[22] = inv_spatial_metric[1][0]; fout[23] = inv_spatial_metric[1][1]; fout[24] = inv_spatial_metric[1][2]; + fout[25] = inv_spatial_metric[2][0]; fout[26] = inv_spatial_metric[2][1]; fout[27] = inv_spatial_metric[2][2]; + + // Set excision boundary conditions. + if (in_excision_region) { + for (int i = 0; i < 28; i++) { + fout[i] = 0.0; + } + + fout[28] = -1.0; + } + else { + fout[28] = 1.0; + } + + // Free all tensorial quantities. + for (int i = 0; i < 3; i++) { + gkyl_free(spatial_metric[i]); + gkyl_free(inv_spatial_metric[i]); + } + gkyl_free(spatial_metric); + gkyl_free(inv_spatial_metric); + gkyl_free(shift); + gkyl_free(vel); +} + +int main(int argc, char **argv) +{ + struct amr_gr_bhl_static_ctx ctx = create_ctx(); // Context for initialization functions. + + struct gr_euler2d_double_init init = { + .base_Nx = ctx.Nx, + .base_Ny = ctx.Ny, + .ref_factor1 = ctx.ref_factor1, + .ref_factor2 = ctx.ref_factor2, + + .coarse_x1 = 0.0, + .coarse_y1 = 0.0, + .coarse_x2 = ctx.Lx, + .coarse_y2 = ctx.Ly, + + .intermediate_x1 = (0.55 * ctx.Lx) - (0.5 * ctx.intermediate_Lx), + .intermediate_y1 = (0.5 * ctx.Ly) - (0.5 * ctx.intermediate_Ly), + .intermediate_x2 = (0.55 * ctx.Lx) + (0.5 * ctx.intermediate_Lx), + .intermediate_y2 = (0.5 * ctx.Ly) + (0.5 * ctx.intermediate_Ly), + + .refined_x1 = (0.6 * ctx.Lx) - (0.5 * ctx.fine_Lx), + .refined_y1 = (0.5 * ctx.Ly) - (0.5 * ctx.fine_Ly), + .refined_x2 = (0.6 * ctx.Lx) + (0.5 * ctx.fine_Lx), + .refined_y2 = (0.5 * ctx.Ly) + (0.5 * ctx.fine_Ly), + + .eval = evalGREulerInit, + .gas_gamma = ctx.gas_gamma, + .spacetime = ctx.spacetime, + + .gr_euler_output = "amr_gr_bhl_static_l2", + + .low_order_flux = true, + .cfl_frac = ctx.cfl_frac, + + .t_end = ctx.t_end, + .num_frames = ctx.num_frames, + .dt_failure_tol = ctx.dt_failure_tol, + .num_failures_max = ctx.num_failures_max, + }; + + gr_euler2d_run_double(argc, argv, &init); +} \ No newline at end of file diff --git a/regression/rt_amr_gr_blackhole_spinning.c b/regression/rt_amr_gr_blackhole_spinning_l1.c similarity index 99% rename from regression/rt_amr_gr_blackhole_spinning.c rename to regression/rt_amr_gr_blackhole_spinning_l1.c index 721e16198..9b132978d 100644 --- a/regression/rt_amr_gr_blackhole_spinning.c +++ b/regression/rt_amr_gr_blackhole_spinning_l1.c @@ -306,7 +306,7 @@ int main(int argc, char **argv) .gas_gamma = ctx.gas_gamma, .spacetime = ctx.spacetime, - .gr_euler_output = "amr_gr_blackhole_spinning", + .gr_euler_output = "amr_gr_blackhole_spinning_l1", .low_order_flux = true, .cfl_frac = ctx.cfl_frac, diff --git a/regression/rt_amr_gr_blackhole_spinning_l2.c b/regression/rt_amr_gr_blackhole_spinning_l2.c new file mode 100644 index 000000000..3b7bbd336 --- /dev/null +++ b/regression/rt_amr_gr_blackhole_spinning_l2.c @@ -0,0 +1,336 @@ +// 2D ring-accretion problem onto a non-static (Kerr) black hole, using static, block-structured mesh refinement with doubly-nested refinement blocks (4x4x refinement), for the general relativistic Euler equations. +// Input parameters describe an asymmetrical ring of cold relativistic gas accreting onto a spinning black hole. + +#include +#include +#include + +struct amr_gr_blackhole_spinning_ctx +{ + // Mathematical constants (dimensionless). + double pi; + + // Physical constants (using normalized code units). + double gas_gamma; // Adiabatic index. + + double rhob; // Background fluid mass density. + double ub; // Background fluid velocity. + double pb; // Background fluid pressure. + + double rhol; // Left ring fluid mass density. + double ul; // Left ring fluid velocity. + double pl; // Left ring fluid pressure. + + double rhor; // Right ring fluid mass density. + double ur; // Right ring fluid velocity. + double pr; // Right ring fluid pressure. + + // Spacetime parameters (using geometric units). + double mass; // Mass of the black hole. + double spin; // Spin of the black hole. + + double pos_x; // Position of the black hole (x-direction). + double pos_y; // Position of the black hole (y-direction). + double pos_z; // Position of the black hole (z-direction). + + // Pointer to spacetime metric. + struct gkyl_gr_spacetime *spacetime; + + // Simulation parameters. + int Nx; // Coarse cell count (x-direction). + int Ny; // Coarse cell count (y-direction). + int ref_factor1; // First refinement factor (coarse-to-intermediate). + int ref_factor2; // Second refinement factor (intermediate-to-fine). + double Lx; // Coarse domain size (x-direction). + double Ly; // Coarse domain size (y-direction). + double intermediate_Lx; // Intermediate domain size (x-direction). + double intermediate_Ly; // Intermediate domain size (y-direction). + double fine_Lx; // Fine domain size (x-direction). + double fine_Ly; // Fine domain size (y-direction). + double cfl_frac; // CFL coefficient. + + double t_end; // Final simulation time. + int num_frames; // Number of output frames. + double dt_failure_tol; // Minimum allowable fraction of initial time-step. + int num_failures_max; // Maximum allowable number of consecutive small time-steps. + + double r_inner; // Ring inner radius. + double r_outer; // Ring outer radius. +}; + +struct amr_gr_blackhole_spinning_ctx +create_ctx(void) +{ + // Mathematical constants (dimensionless). + double pi = M_PI; + + // Physical constants (using normalized code units). + double gas_gamma = 5.0 / 3.0; // Adiabatic index. + + double rhob = 0.01; // Background fluid mass density. + double ub = 0.0; // Background fluid velocity. + double pb = 0.01; // Background fluid pressure. + + double rhol = 1.0; // Left ring fluid mass density. + double ul = 0.0; // Left ring fluid velocity. + double pl = 0.1; // Left ring fluid pressure. + + double rhor = 2.0; // Right ring fluid mass density. + double ur = 0.0; // Right ring fluid velocity. + double pr = 0.1; // Right ring fluid pressure. + + // Spacetime parameters (using geometric units). + double mass = 0.3; // Mass of the black hole. + double spin = -0.99; // Spin of the black hole. + + double pos_x = 2.5; // Position of the black hole (x-direction). + double pos_y = 2.5; // Position of the black hole (y-direction). + double pos_z = 0.0; // Position of the black hole (z-direction). + + // Pointer to spacetime metric. + struct gkyl_gr_spacetime *spacetime = gkyl_gr_blackhole_new(false, mass, spin, pos_x, pos_y, pos_z); + + // Simulation parameters. + int Nx = 8; // Coarse cell count (x-direction). + int Ny = 8; // Coarse cell count (y-direction). + int ref_factor1 = 4; // First refinement factor (coarse-to-intermediate). + int ref_factor2 = 4; // Second refinement factor (intermediate-to-fine). + double Lx = 5.0; // Coarse domain size (x-direction). + double Ly = 5.0; // Coarse domain size (y-direction). + double intermediate_Lx = 3.5; // Intermediate domain size (x-direction). + double intermediate_Ly = 3.5; // Intermediate domain size (y-direction). + double fine_Lx = 2.0; // Fine domain size (x-direction). + double fine_Ly = 2.0; // Fine domain size (y-direction). + double cfl_frac = 0.95; // CFL coefficient. + + double t_end = 5.0; // Final simulation time. + int num_frames = 1; // Number of output frames. + double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. + int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. + + double r_inner = 1.2; // Ring inner radius. + double r_outer = 2.4; // Ring outer radius. + + struct amr_gr_blackhole_spinning_ctx ctx = { + .pi = pi, + .gas_gamma = gas_gamma, + .rhob = rhob, + .ub = ub, + .pb = pb, + .rhol = rhol, + .ul = ul, + .pl = pl, + .rhor = rhor, + .ur = ur, + .pr = pr, + .mass = mass, + .spin = spin, + .pos_x = pos_x, + .pos_y = pos_y, + .pos_z = pos_z, + .spacetime = spacetime, + .Nx = Nx, + .Ny = Ny, + .ref_factor1 = ref_factor1, + .ref_factor2 = ref_factor2, + .Lx = Lx, + .Ly = Ly, + .intermediate_Lx = intermediate_Lx, + .intermediate_Ly = intermediate_Ly, + .fine_Lx = fine_Lx, + .fine_Ly = fine_Ly, + .cfl_frac = cfl_frac, + .t_end = t_end, + .num_frames = num_frames, + .dt_failure_tol = dt_failure_tol, + .num_failures_max = num_failures_max, + .r_inner = r_inner, + .r_outer = r_outer, + }; + + return ctx; +} + +void +evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +{ + double x = xn[0], y = xn[1]; + struct amr_gr_blackhole_spinning_ctx new_ctx = create_ctx(); // Context for initialization functions. + struct amr_gr_blackhole_spinning_ctx *app = &new_ctx; + + double gas_gamma = app->gas_gamma; + + double rhob = app->rhob; + double ub = app->ub; + double pb = app->pb; + + double rhol = app->rhol; + double ul = app->ul; + double pl = app->pl; + + double rhor = app->rhor; + double ur = app->ur; + double pr = app->pr; + + struct gkyl_gr_spacetime *spacetime = app->spacetime; + + double r_inner = app->r_inner; + double r_outer = app->r_outer; + + double Lx = app->Lx; + double Ly = app->Ly; + + double rho = 0.0; + double u = 0.0; + double p = 0.0; + + double r = sqrt((x - (0.5 * Lx)) * (x - (0.5 * Lx)) + (y - (0.5 * Ly)) * (y - (0.5 * Ly))); + + if (r > r_inner && r < r_outer) { + if (x < (0.5 * Lx)) { + rho = rhol; // Fluid mass density (left ring). + u = ul; // Fluid velocity (left ring). + p = pl; // Fluid pressure (left ring). + } + else { + rho = rhor; // Fluid mass density (right ring). + u = ur; // Fluid velocity (right ring). + p = pr; // Fluid pressure (right ring). + } + } + else { + rho = rhob; // Fluid mass density (background). + u = ub; // Fluid velocity (background). + p = pb; // Fluid pressure (background). + } + + double spatial_det, lapse; + double *shift = gkyl_malloc(sizeof(double[3])); + bool in_excision_region; + + double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + for (int i = 0; i < 3; i++) { + spatial_metric[i] = gkyl_malloc(sizeof(double[3])); + } + + double **inv_spatial_metric = gkyl_malloc(sizeof(double*[3])); + for (int i = 0; i < 3; i++) { + inv_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); + } + + spacetime->spatial_metric_det_func(spacetime, 0.0, x, y, 0.0, &spatial_det); + spacetime->lapse_function_func(spacetime, 0.0, x, y, 0.0, &lapse); + spacetime->shift_vector_func(spacetime, 0.0, x, y, 0.0, &shift); + spacetime->excision_region_func(spacetime, 0.0, x, y, 0.0, &in_excision_region); + + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &spatial_metric); + spacetime->spatial_inv_metric_tensor_func(spacetime, 0.0, x, y, 0.0, &inv_spatial_metric); + + double *vel = gkyl_malloc(sizeof(double[3])); + double v_sq = 0.0; + vel[0] = u; vel[1] = 0.0; vel[2] = 0.0; + + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + v_sq += spatial_metric[i][j] * vel[i] * vel[j]; + } + } + + double W = 1.0 / (sqrt(1.0 - v_sq)); + if (v_sq > 1.0 - pow(10.0, -8.0)) { + W = 1.0 / sqrt(1.0 - pow(10.0, -8.0)); + } + + double h = 1.0 + ((p / rho) * (gas_gamma / (gas_gamma - 1.0))); + + // Set fluid mass density. + fout[0] = sqrt(spatial_det) * rho * W; + // Set fluid momentum density. + fout[1] = sqrt(spatial_det) * rho * h * (W * W) * u; + fout[2] = 0.0; + fout[3] = 0.0; + // Set fluid total energy density. + fout[4] = sqrt(spatial_det) * ((rho * h * (W * W)) - p - (rho * W)); + + // Set spatial metric determinant. + fout[5] = spatial_det; + // Set lapse gauge variable. + fout[6] = lapse; + // Set shift gauge variables. + fout[7] = shift[0]; fout[8] = shift[1]; fout[9] = shift[2]; + + // Set spatial metric tensor. + fout[10] = spatial_metric[0][0]; fout[11] = spatial_metric[0][1]; fout[12] = spatial_metric[0][2]; + fout[13] = spatial_metric[1][0]; fout[14] = spatial_metric[1][1]; fout[15] = spatial_metric[1][2]; + fout[16] = spatial_metric[2][0]; fout[17] = spatial_metric[2][1]; fout[18] = spatial_metric[2][2]; + + // Set inverse spatial metric tensor. + fout[19] = inv_spatial_metric[0][0]; fout[20] = inv_spatial_metric[0][1]; fout[21] = inv_spatial_metric[0][2]; + fout[22] = inv_spatial_metric[1][0]; fout[23] = inv_spatial_metric[1][1]; fout[24] = inv_spatial_metric[1][2]; + fout[25] = inv_spatial_metric[2][0]; fout[26] = inv_spatial_metric[2][1]; fout[27] = inv_spatial_metric[2][2]; + + // Set excision boundary conditions. + if (in_excision_region) { + for (int i = 0; i < 28; i++) { + fout[i] = 0.0; + } + + fout[28] = -1.0; + } + else { + fout[28] = 1.0; + } + + // Free all tensorial quantities. + for (int i = 0; i < 3; i++) { + gkyl_free(spatial_metric[i]); + gkyl_free(inv_spatial_metric[i]); + } + gkyl_free(spatial_metric); + gkyl_free(inv_spatial_metric); + gkyl_free(shift); + gkyl_free(vel); +} + +int main(int argc, char **argv) +{ + struct amr_gr_blackhole_spinning_ctx ctx = create_ctx(); // Context for initialization functions. + + struct gr_euler2d_double_init init = { + .base_Nx = ctx.Nx, + .base_Ny = ctx.Ny, + .ref_factor1 = ctx.ref_factor1, + .ref_factor2 = ctx.ref_factor2, + + .coarse_x1 = 0.0, + .coarse_y1 = 0.0, + .coarse_x2 = ctx.Lx, + .coarse_y2 = ctx.Ly, + + .intermediate_x1 = (0.5 * ctx.Lx) - (0.5 * ctx.intermediate_Lx), + .intermediate_y1 = (0.5 * ctx.Ly) - (0.5 * ctx.intermediate_Ly), + .intermediate_x2 = (0.5 * ctx.Lx) + (0.5 * ctx.intermediate_Lx), + .intermediate_y2 = (0.5 * ctx.Ly) + (0.5 * ctx.intermediate_Ly), + + .refined_x1 = (0.5 * ctx.Lx) - (0.5 * ctx.fine_Lx), + .refined_y1 = (0.5 * ctx.Ly) - (0.5 * ctx.fine_Ly), + .refined_x2 = (0.5 * ctx.Lx) + (0.5 * ctx.fine_Lx), + .refined_y2 = (0.5 * ctx.Ly) + (0.5 * ctx.fine_Ly), + + .eval = evalGREulerInit, + .gas_gamma = ctx.gas_gamma, + .spacetime = ctx.spacetime, + + .gr_euler_output = "amr_gr_blackhole_spinning_l2", + + .low_order_flux = true, + .cfl_frac = ctx.cfl_frac, + + .t_end = ctx.t_end, + .num_frames = ctx.num_frames, + .dt_failure_tol = ctx.dt_failure_tol, + .num_failures_max = ctx.num_failures_max, + }; + + gr_euler2d_run_double(argc, argv, &init); +} \ No newline at end of file From 3bd0fa6529166c5769b6fff383da0259115598f6 Mon Sep 17 00:00:00 2001 From: JonathanGorard Date: Wed, 26 Jun 2024 14:59:42 -0400 Subject: [PATCH 12/32] Major cleanup of block-structured and patch-structured AMR infrastructure for both relativistic and non-relativistic hydrodynamics equations (without source coupling), including removal of all debug code and consistent renaming of mesh handles. --- amr/amr_block.c | 34 -- amr/amr_core_euler.c | 1133 ++++--------------------------------- amr/amr_core_gr_euler.c | 1098 ++++------------------------------- amr/amr_patch.c | 34 -- amr/gkyl_amr_block_priv.h | 1 - 5 files changed, 233 insertions(+), 2067 deletions(-) diff --git a/amr/amr_block.c b/amr/amr_block.c index fde03156f..78bdbdb56 100644 --- a/amr/amr_block.c +++ b/amr/amr_block.c @@ -211,39 +211,6 @@ euler_sync_blocks(const struct gkyl_block_topo* btopo, const struct euler_block_ for (int d = 0; d < ndim; d++) { const struct gkyl_target_edge *te = btopo->conn[i].connections[d]; -#ifdef AMR_DEBUG - if (te[0].edge != GKYL_PHYSICAL) { - struct gkyl_array *bc_buffer = bdata[i].bc_buffer; - - gkyl_array_copy_to_buffer(bc_buffer->data, fld[i], &(bdata[i].skin_ghost.lower_skin[d])); - - int tbid = te[0].bid; - int tdir = te[0].dir; - - if (te[0].edge == GKYL_LOWER_POSITIVE) { - gkyl_array_copy_from_buffer(fld[tbid], bc_buffer->data, &(bdata[tbid].skin_ghost.lower_ghost[tdir])); - } - else if (te[0].edge == GKYL_UPPER_POSITIVE) { - gkyl_array_copy_from_buffer(fld[tbid], bc_buffer->data, &(bdata[tbid].skin_ghost.upper_ghost[tdir])); - } - } - - if (te[1].edge != GKYL_PHYSICAL) { - struct gkyl_array *bc_buffer = bdata[i].bc_buffer; - - gkyl_array_copy_to_buffer(bc_buffer->data, fld[i], &(bdata[i].skin_ghost.upper_skin[d])); - - int tbid = te[1].bid; - int tdir = te[1].dir; - - if (te[1].edge == GKYL_LOWER_POSITIVE) { - gkyl_array_copy_from_buffer(fld[tbid], bc_buffer->data, &(bdata[tbid].skin_ghost.lower_ghost[tdir])); - } - else if (te[1].edge == GKYL_UPPER_POSITIVE) { - gkyl_array_copy_from_buffer(fld[tbid], bc_buffer->data, &(bdata[tbid].skin_ghost.upper_ghost[tdir])); - } - } -#else if (te[0].edge != GKYL_PHYSICAL) { struct gkyl_array *bc_buffer = bdata[i].bc_buffer; @@ -451,7 +418,6 @@ euler_sync_blocks(const struct gkyl_block_topo* btopo, const struct euler_block_ } } } -#endif } } } diff --git a/amr/amr_core_euler.c b/amr/amr_core_euler.c index 8ff6db773..2f78caa90 100644 --- a/amr/amr_core_euler.c +++ b/amr/amr_core_euler.c @@ -41,43 +41,21 @@ euler1d_run_single(int argc, char **argv, struct euler1d_single_init* init) int num_patches = 3; int Nx = base_Nx; - struct euler_patch_data coarse_pdata[num_patches]; + struct euler_patch_data mesh_pdata[num_patches]; struct gkyl_job_pool *coarse_job_pool = gkyl_thread_pool_new(app_args.num_threads); -#ifdef AMR_DEBUG - gkyl_rect_grid_init(&coarse_pdata[0].grid, 1, (double []) { refined_x1 }, (double []) { refined_x2 }, (int []) { Nx } ); -#else - gkyl_rect_grid_init(&coarse_pdata[0].grid, 1, (double []) { refined_x1 }, (double []) { refined_x2 }, (int []) { Nx * ref_factor } ); -#endif + gkyl_rect_grid_init(&mesh_pdata[0].grid, 1, (double []) { refined_x1 }, (double []) { refined_x2 }, (int []) { Nx * ref_factor } ); - gkyl_rect_grid_init(&coarse_pdata[1].grid, 1, (double []) { coarse_x1 }, (double []) { refined_x1 }, (int []) { Nx } ); - gkyl_rect_grid_init(&coarse_pdata[2].grid, 1, (double []) { refined_x2 }, (double []) { coarse_x2 }, (int []) { Nx } ); - -#ifdef AMR_DEBUG - struct euler_patch_data fine_pdata[num_patches]; - struct gkyl_job_pool *fine_job_pool = gkyl_thread_pool_new(app_args.num_threads); - - gkyl_rect_grid_init(&fine_pdata[0].grid, 1, (double []) { refined_x1 }, (double []) { refined_x2 }, (int []) { Nx * ref_factor } ); - gkyl_rect_grid_init(&fine_pdata[1].grid, 1, (double []) { coarse_x1 }, (double []) { refined_x1 }, (int []) { Nx * ref_factor } ); - gkyl_rect_grid_init(&fine_pdata[2].grid, 1, (double []) { refined_x2 }, (double []) { coarse_x2 }, (int []) { Nx * ref_factor } ); -#endif + gkyl_rect_grid_init(&mesh_pdata[1].grid, 1, (double []) { coarse_x1 }, (double []) { refined_x1 }, (int []) { Nx } ); + gkyl_rect_grid_init(&mesh_pdata[2].grid, 1, (double []) { refined_x2 }, (double []) { coarse_x2 }, (int []) { Nx } ); for (int i = 0; i < num_patches; i++) { - coarse_pdata[i].fv_proj = gkyl_fv_proj_new(&coarse_pdata[i].grid, 1, 5, eval, 0); - -#ifdef AMR_DEBUG - fine_pdata[i].fv_proj = gkyl_fv_proj_new(&fine_pdata[i].grid, 1, 5, eval, 0); -#endif + mesh_pdata[i].fv_proj = gkyl_fv_proj_new(&mesh_pdata[i].grid, 1, 5, eval, 0); } for (int i = 0; i < num_patches; i++) { - gkyl_create_grid_ranges(&coarse_pdata[i].grid, (int []) { 2 }, &coarse_pdata[i].ext_range, &coarse_pdata[i].range ); - coarse_pdata[i].geom = gkyl_wave_geom_new(&coarse_pdata[i].grid, &coarse_pdata[i].ext_range, 0, 0, false); - -#ifdef AMR_DEBUG - gkyl_create_grid_ranges(&fine_pdata[i].grid, (int []) { 2 }, &fine_pdata[i].ext_range, &fine_pdata[i].range); - fine_pdata[i].geom = gkyl_wave_geom_new(&fine_pdata[i].grid, &fine_pdata[i].ext_range, 0, 0, false); -#endif + gkyl_create_grid_ranges(&mesh_pdata[i].grid, (int []) { 2 }, &mesh_pdata[i].ext_range, &mesh_pdata[i].range ); + mesh_pdata[i].geom = gkyl_wave_geom_new(&mesh_pdata[i].grid, &mesh_pdata[i].ext_range, 0, 0, false); } for (int i = 0; i < num_patches; i++) { @@ -87,142 +65,58 @@ euler1d_run_single(int argc, char **argv, struct euler1d_single_init* init) .rp_type = WV_EULER_RP_HLL, .use_gpu = app_args.use_gpu, }; - coarse_pdata[i].euler = gkyl_wv_euler_inew(&inp); - } - else { - coarse_pdata[i].euler = gkyl_wv_euler_new(gas_gamma, app_args.use_gpu); - } - - coarse_pdata[i].slvr[0] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &coarse_pdata[i].grid, - .equation = coarse_pdata[i].euler, - .limiter = GKYL_MONOTONIZED_CENTERED, - .num_up_dirs = 1, - .update_dirs = { 0 }, - .cfl = cfl_frac, - .geom = coarse_pdata[i].geom, - } - ); - -#ifdef AMR_DEBUG - if (low_order_flux) { - struct gkyl_wv_euler_inp inp = { - .gas_gamma = gas_gamma, - .rp_type = WV_EULER_RP_HLL, - .use_gpu = app_args.use_gpu, - }; - fine_pdata[i].euler = gkyl_wv_euler_inew(&inp); + mesh_pdata[i].euler = gkyl_wv_euler_inew(&inp); } else { - fine_pdata[i].euler = gkyl_wv_euler_new(gas_gamma, app_args.use_gpu); + mesh_pdata[i].euler = gkyl_wv_euler_new(gas_gamma, app_args.use_gpu); } - fine_pdata[i].slvr[0] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &fine_pdata[i].grid, - .equation = fine_pdata[i].euler, + mesh_pdata[i].slvr[0] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { + .grid = &mesh_pdata[i].grid, + .equation = mesh_pdata[i].euler, .limiter = GKYL_MONOTONIZED_CENTERED, .num_up_dirs = 1, .update_dirs = { 0 }, .cfl = cfl_frac, - .geom = fine_pdata[i].geom, + .geom = mesh_pdata[i].geom, } ); -#endif } struct gkyl_block_topo *ptopo = create_patch_topo(); for (int i = 0; i < num_patches; i++) { - euler_patch_bc_updaters_init(&coarse_pdata[i], &ptopo->conn[i]); - -#ifdef AMR_DEBUG - euler_patch_bc_updaters_init(&fine_pdata[i], &ptopo->conn[i]); -#endif + euler_patch_bc_updaters_init(&mesh_pdata[i], &ptopo->conn[i]); } for (int i = 0; i < num_patches; i++) { - coarse_pdata[i].fdup = gkyl_array_new(GKYL_DOUBLE, 5, coarse_pdata[i].ext_range.volume); - - for (int d = 0; d < ndim + 1; d++) { - coarse_pdata[i].f[d] = gkyl_array_new(GKYL_DOUBLE, 5, coarse_pdata[i].ext_range.volume); - } -#ifdef AMR_DEBUG - fine_pdata[i].fdup = gkyl_array_new(GKYL_DOUBLE, 5, fine_pdata[i].ext_range.volume); + mesh_pdata[i].fdup = gkyl_array_new(GKYL_DOUBLE, 5, mesh_pdata[i].ext_range.volume); for (int d = 0; d < ndim + 1; d++) { - fine_pdata[i].f[d] = gkyl_array_new(GKYL_DOUBLE, 5, fine_pdata[i].ext_range.volume); + mesh_pdata[i].f[d] = gkyl_array_new(GKYL_DOUBLE, 5, mesh_pdata[i].ext_range.volume); } -#endif } #ifdef AMR_USETHREADS for (int i = 0; i < num_patches; i++) { - gkyl_job_pool_add_work(coarse_job_pool, euler_init_job_func_patch, &coarse_pdata[i]); - -#ifdef AMR_DEBUG - gkyl_job_pool_add_work(fine_job_pool, euler_init_job_func_patch, &fine_pdata[i]); -#endif + gkyl_job_pool_add_work(coarse_job_pool, euler_init_job_func_patch, &mesh_pdata[i]); } gkyl_job_pool_wait(coarse_job_pool); - -#ifdef AMR_DEBUG - gkyl_job_pool_wait(fine_job_pool); -#endif #else for (int i = 0; i < num_patches; i++) { - euler_init_job_func_patch(&coarse_pdata[i]); - -#ifdef AMR_DEBUG - euler_init_job_func_patch(&fine_pdata[i]); -#endif + euler_init_job_func_patch(&mesh_pdata[i]); } #endif -#ifdef AMR_DEBUG - char coarse0[64]; - snprintf(coarse0, 64, "%s_coarse_0", euler_output); - euler_write_sol_patch(coarse0, num_patches, coarse_pdata); - - char fine0[64]; - snprintf(fine0, 64, "%s_fine_0", euler_output); - euler_write_sol_patch(fine0, num_patches, fine_pdata); - - char fine0p0[64]; - char coarse0p0[64]; - char p0[64]; - snprintf(fine0p0, 64, "%s_fine_0_p0.gkyl", euler_output); - snprintf(coarse0p0, 64, "%s_coarse_0_p0.gkyl", euler_output); - snprintf(p0, 64, "%s_0_p0.gkyl", euler_output); - rename(fine0p0, p0); - remove(coarse0p0); - - for (int i = 1; i < 3; i++) { - char buf_old[64]; - char buf_new[64]; - char buf_del[64]; - - snprintf(buf_old, 64, "%s_coarse_0_p%d.gkyl", euler_output, i); - snprintf(buf_new, 64, "%s_0_p%d.gkyl", euler_output, i); - snprintf(buf_del, 64, "%s_fine_0_p%d.gkyl", euler_output, i); - - rename(buf_old, buf_new); - remove(buf_del); - } -#else char amr0[64]; snprintf(amr0, 64, "%s_0", euler_output); - euler_write_sol_patch(amr0, num_patches, coarse_pdata); -#endif + euler_write_sol_patch(amr0, num_patches, mesh_pdata); double coarse_t_curr = 0.0; double fine_t_curr = 0.0; - double coarse_dt = euler_max_dt_patch(num_patches, coarse_pdata); + double coarse_dt = euler_max_dt_patch(num_patches, mesh_pdata); -#ifdef AMR_DEBUG - double fine_dt = euler_max_dt_patch(num_patches, fine_pdata); -#else double fine_dt = (1.0 / ref_factor) * coarse_dt; -#endif struct sim_stats stats = { }; @@ -238,7 +132,7 @@ euler1d_run_single(int argc, char **argv, struct euler1d_single_init* init) while ((coarse_t_curr < t_end) && (coarse_step <= num_steps)) { printf("Taking coarse (level 0) time-step %ld at t = %g; ", coarse_step, coarse_t_curr); - struct gkyl_update_status coarse_status = euler_update_patch(coarse_job_pool, ptopo, coarse_pdata, coarse_t_curr, coarse_dt, &stats); + struct gkyl_update_status coarse_status = euler_update_patch(coarse_job_pool, ptopo, mesh_pdata, coarse_t_curr, coarse_dt, &stats); printf(" dt = %g\n", coarse_status.dt_actual); if (!coarse_status.success) { @@ -247,68 +141,19 @@ euler1d_run_single(int argc, char **argv, struct euler1d_single_init* init) } for (long fine_step = 1; fine_step < ref_factor + 1; fine_step++) { -#ifdef AMR_DEBUG - printf(" Taking fine (level 1) time-step %ld at t = %g; ", fine_step, fine_t_curr); - struct gkyl_update_status fine_status = euler_update_patch(fine_job_pool, ptopo, fine_pdata, fine_t_curr, fine_dt, &stats); - printf(" dt = %g\n", fine_status.dt_actual); - - if (!fine_status.success) { - printf("** Update method failed! Aborting simulation ....\n"); - break; - } - - fine_t_curr += fine_status.dt_actual; - fine_dt = fine_status.dt_suggested; -#else printf(" Taking fine (level 1) time-step %ld at t = %g", fine_step, fine_t_curr); printf(" dt = %g\n", (1.0 / ref_factor) * coarse_status.dt_actual); fine_t_curr += (1.0 / ref_factor) * coarse_status.dt_actual; fine_dt = (1.0 / ref_factor) * coarse_status.dt_suggested; -#endif } for (int i = 1; i < num_frames; i++) { if (coarse_t_curr < (i * io_trigger) && (coarse_t_curr + coarse_status.dt_actual) > (i * io_trigger)) { -#ifdef AMR_DEBUG - char buf_coarse[64]; - char buf_fine[64]; - - snprintf(buf_coarse, 64, "%s_coarse_%d", euler_output, i); - snprintf(buf_fine, 64, "%s_fine_%d", euler_output, i); - - euler_write_sol_patch(buf_coarse, num_patches, coarse_pdata); - euler_write_sol_patch(buf_fine, num_patches, fine_pdata); - - char buf_fine_old[64]; - char buf_fine_new[64]; - char buf_coarse_old[64]; - - snprintf(buf_fine_old, 64, "%s_fine_%d_p0.gkyl", euler_output, i); - snprintf(buf_fine_new, 64, "%s_%d_p0.gkyl", euler_output, i); - snprintf(buf_coarse_old, 64, "%s_coarse_%d_p0.gkyl", euler_output, i); - - rename(buf_fine_old, buf_fine_new); - remove(buf_coarse_old); - - for (int j = 1; j < 3; j++) { - char buf_old[64]; - char buf_new[64]; - char buf_del[64]; - - snprintf(buf_old, 64, "%s_coarse_%d_p%d.gkyl", euler_output, i, j); - snprintf(buf_new, 64, "%s_%d_p%d.gkyl", euler_output, i, j); - snprintf(buf_del, 64, "%s_fine_%d_p%d.gkyl", euler_output, i, j); - - rename(buf_old, buf_new); - remove(buf_del); - } -#else char buf[64]; snprintf(buf, 64, "%s_%d", euler_output, i); - euler_write_sol_patch(buf, num_patches, coarse_pdata); -#endif + euler_write_sol_patch(buf, num_patches, mesh_pdata); } } @@ -339,84 +184,26 @@ euler1d_run_single(int argc, char **argv, struct euler1d_single_init* init) double tm_total_sec = gkyl_time_diff_now_sec(tm_start); -#ifdef AMR_DEBUG - char buf_coarse[64]; - char buf_fine[64]; - - snprintf(buf_coarse, 64, "%s_coarse_%d", euler_output, num_frames); - snprintf(buf_fine, 64, "%s_fine_%d", euler_output, num_frames); - - euler_write_sol_patch(buf_coarse, num_patches, coarse_pdata); - euler_write_sol_patch(buf_fine, num_patches, fine_pdata); - - char buf_fine_old[64]; - char buf_fine_new[64]; - char buf_coarse_old[64]; - - snprintf(buf_fine_old, 64, "%s_fine_%d_p0.gkyl", euler_output, num_frames); - snprintf(buf_fine_new, 64, "%s_%d_p0.gkyl", euler_output, num_frames); - snprintf(buf_coarse_old, 64, "%s_coarse_%d_p0.gkyl", euler_output,num_frames); - - rename(buf_fine_old, buf_fine_new); - remove(buf_coarse_old); - - for (int i = 1; i < 3; i++) { - char buf_old[64]; - char buf_new[64]; - char buf_del[64]; - - snprintf(buf_old, 64, "%s_coarse_%d_p%d.gkyl", euler_output, num_frames, i); - snprintf(buf_new, 64, "%s_%d_p%d.gkyl", euler_output, num_frames, i); - snprintf(buf_del, 64, "%s_fine_%d_p%d.gkyl", euler_output, num_frames, i); - - rename(buf_old, buf_new); - remove(buf_del); - } -#else char buf[64]; snprintf(buf, 64, "%s_%d", euler_output, num_frames); - euler_write_sol_patch(buf, num_patches, coarse_pdata); -#endif + euler_write_sol_patch(buf, num_patches, mesh_pdata); printf("Total run-time: %g. Failed steps: %d\n", tm_total_sec, stats.nfail); for (int i = 0; i < num_patches; i++) { - gkyl_fv_proj_release(coarse_pdata[i].fv_proj); - gkyl_wv_eqn_release(coarse_pdata[i].euler); - euler_patch_bc_updaters_release(&coarse_pdata[i]); - gkyl_wave_geom_release(coarse_pdata[i].geom); - -#ifdef AMR_DEBUG - gkyl_fv_proj_release(fine_pdata[i].fv_proj); - gkyl_wv_eqn_release(fine_pdata[i].euler); - euler_patch_bc_updaters_release(&fine_pdata[i]); - gkyl_wave_geom_release(fine_pdata[i].geom); -#endif + gkyl_fv_proj_release(mesh_pdata[i].fv_proj); + gkyl_wv_eqn_release(mesh_pdata[i].euler); + euler_patch_bc_updaters_release(&mesh_pdata[i]); + gkyl_wave_geom_release(mesh_pdata[i].geom); - gkyl_wave_prop_release(coarse_pdata[i].slvr[0]); - -#ifdef AMR_DEBUG - gkyl_wave_prop_release(fine_pdata[i].slvr[0]); -#endif - - gkyl_array_release(coarse_pdata[i].fdup); -#ifdef AMR_DEBUG - gkyl_array_release(fine_pdata[i].fdup); -#endif - - gkyl_array_release(coarse_pdata[i].f[0]); - -#ifdef AMR_DEBUG - gkyl_array_release(fine_pdata[i].f[0]); -#endif + gkyl_wave_prop_release(mesh_pdata[i].slvr[0]); + gkyl_array_release(mesh_pdata[i].fdup); + gkyl_array_release(mesh_pdata[i].f[0]); } gkyl_block_topo_release(ptopo); gkyl_job_pool_release(coarse_job_pool); -#ifdef AMR_DEBUG - gkyl_job_pool_release(fine_job_pool); -#endif } void @@ -462,74 +249,36 @@ euler2d_run_single(int argc, char **argv, struct euler2d_single_init* init) int Nx = base_Nx; int Ny = base_Ny; - struct euler_block_data coarse_bdata[num_blocks]; + struct euler_block_data mesh_bdata[num_blocks]; struct gkyl_job_pool *coarse_job_pool = gkyl_thread_pool_new(app_args.num_threads); -#ifdef AMR_DEBUG - gkyl_rect_grid_init(&coarse_bdata[0].grid, 2, (double []) { refined_x1, refined_y1 }, (double []) { refined_x2, refined_y2 }, - (int []) { Nx, Ny }); -#else - gkyl_rect_grid_init(&coarse_bdata[0].grid, 2, (double []) { refined_x1, refined_y1 }, (double []) { refined_x2, refined_y2 }, + gkyl_rect_grid_init(&mesh_bdata[0].grid, 2, (double []) { refined_x1, refined_y1 }, (double []) { refined_x2, refined_y2 }, (int []) { Nx * ref_factor, Ny * ref_factor }); -#endif - gkyl_rect_grid_init(&coarse_bdata[1].grid, 2, (double []) { coarse_x1, refined_y2 }, (double []) { refined_x1, coarse_y2 }, + gkyl_rect_grid_init(&mesh_bdata[1].grid, 2, (double []) { coarse_x1, refined_y2 }, (double []) { refined_x1, coarse_y2 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[2].grid, 2, (double []) { refined_x1, refined_y2 }, (double []) { refined_x2, coarse_y2 }, + gkyl_rect_grid_init(&mesh_bdata[2].grid, 2, (double []) { refined_x1, refined_y2 }, (double []) { refined_x2, coarse_y2 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[3].grid, 2, (double []) { refined_x2, refined_y2 }, (double []) { coarse_x2, coarse_y2 }, + gkyl_rect_grid_init(&mesh_bdata[3].grid, 2, (double []) { refined_x2, refined_y2 }, (double []) { coarse_x2, coarse_y2 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[4].grid, 2, (double []) { coarse_x1, refined_y1 }, (double []) { refined_x1, refined_y2 }, + gkyl_rect_grid_init(&mesh_bdata[4].grid, 2, (double []) { coarse_x1, refined_y1 }, (double []) { refined_x1, refined_y2 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[5].grid, 2, (double []) { refined_x2, refined_y1 }, (double []) { coarse_x2, refined_y2 }, + gkyl_rect_grid_init(&mesh_bdata[5].grid, 2, (double []) { refined_x2, refined_y1 }, (double []) { coarse_x2, refined_y2 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[6].grid, 2, (double []) { coarse_x1, coarse_y1 }, (double []) { refined_x1, refined_y1 }, + gkyl_rect_grid_init(&mesh_bdata[6].grid, 2, (double []) { coarse_x1, coarse_y1 }, (double []) { refined_x1, refined_y1 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[7].grid, 2, (double []) { refined_x1, coarse_y1 }, (double []) { refined_x2, refined_y1 }, + gkyl_rect_grid_init(&mesh_bdata[7].grid, 2, (double []) { refined_x1, coarse_y1 }, (double []) { refined_x2, refined_y1 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[8].grid, 2, (double []) { refined_x2, coarse_y1 }, (double []) { coarse_x2, refined_y1 }, + gkyl_rect_grid_init(&mesh_bdata[8].grid, 2, (double []) { refined_x2, coarse_y1 }, (double []) { coarse_x2, refined_y1 }, (int []) { Nx, Ny }); -#ifdef AMR_DEBUG - struct euler_block_data fine_bdata[num_blocks]; - struct gkyl_job_pool *fine_job_pool = gkyl_thread_pool_new(app_args.num_threads); - - gkyl_rect_grid_init(&fine_bdata[0].grid, 2, (double []) { refined_x1, refined_y1 }, (double []) { refined_x2, refined_y2 }, - (int []) { Nx * ref_factor, Ny * ref_factor }); - gkyl_rect_grid_init(&fine_bdata[1].grid, 2, (double []) { coarse_x1, refined_y2 }, (double []) { refined_x1, coarse_y2 }, - (int []) { Nx * ref_factor, Ny * ref_factor }); - gkyl_rect_grid_init(&fine_bdata[2].grid, 2, (double []) { refined_x1, refined_y2 }, (double []) { refined_x2, coarse_y2 }, - (int []) { Nx * ref_factor, Ny * ref_factor }); - gkyl_rect_grid_init(&fine_bdata[3].grid, 2, (double []) { refined_x2, refined_y2 }, (double []) { coarse_x2, coarse_y2 }, - (int []) { Nx * ref_factor, Ny * ref_factor }); - gkyl_rect_grid_init(&fine_bdata[4].grid, 2, (double []) { coarse_x1, refined_y1 }, (double []) { refined_x1, refined_y2 }, - (int []) { Nx * ref_factor, Ny * ref_factor }); - gkyl_rect_grid_init(&fine_bdata[5].grid, 2, (double []) { refined_x2, refined_y1 }, (double []) { coarse_x2, refined_y2 }, - (int []) { Nx * ref_factor, Ny * ref_factor }); - gkyl_rect_grid_init(&fine_bdata[6].grid, 2, (double []) { coarse_x1, coarse_y1 }, (double []) { refined_x1, refined_y1 }, - (int []) { Nx * ref_factor, Ny * ref_factor }); - gkyl_rect_grid_init(&fine_bdata[7].grid, 2, (double []) { refined_x1, coarse_y1 }, (double []) { refined_x2, refined_y1 }, - (int []) { Nx * ref_factor, Ny * ref_factor }); - gkyl_rect_grid_init(&fine_bdata[8].grid, 2, (double []) { refined_x2, coarse_y1 }, (double []) { coarse_x2, refined_y1 }, - (int []) { Nx * ref_factor, Ny * ref_factor }); -#endif - for (int i = 0; i < num_blocks; i++) { - coarse_bdata[i].fv_proj = gkyl_fv_proj_new(&coarse_bdata[i].grid, 2, 5, eval, 0); - -#ifdef AMR_DEBUG - fine_bdata[i].fv_proj = gkyl_fv_proj_new(&fine_bdata[i].grid, 2, 5, eval, 0); -#endif + mesh_bdata[i].fv_proj = gkyl_fv_proj_new(&mesh_bdata[i].grid, 2, 5, eval, 0); } for (int i = 0; i < num_blocks; i++) { - gkyl_create_grid_ranges(&coarse_bdata[i].grid, (int []) { 2, 2 }, &coarse_bdata[i].ext_range, &coarse_bdata[i].range); - coarse_bdata[i].geom = gkyl_wave_geom_new(&coarse_bdata[i].grid, &coarse_bdata[i].ext_range, 0, 0, false); - -#ifdef AMR_DEBUG - gkyl_create_grid_ranges(&fine_bdata[i].grid, (int []) { 2, 2 }, &fine_bdata[i].ext_range, &fine_bdata[i].range); - fine_bdata[i].geom = gkyl_wave_geom_new(&fine_bdata[i].grid, &fine_bdata[i].ext_range, 0, 0, false); -#endif + gkyl_create_grid_ranges(&mesh_bdata[i].grid, (int []) { 2, 2 }, &mesh_bdata[i].ext_range, &mesh_bdata[i].range); + mesh_bdata[i].geom = gkyl_wave_geom_new(&mesh_bdata[i].grid, &mesh_bdata[i].ext_range, 0, 0, false); } for (int i = 0; i < num_blocks; i++) { @@ -539,147 +288,60 @@ euler2d_run_single(int argc, char **argv, struct euler2d_single_init* init) .rp_type = WV_EULER_RP_HLL, .use_gpu = app_args.use_gpu, }; - coarse_bdata[i].euler = gkyl_wv_euler_inew(&inp); - } - else { - coarse_bdata[i].euler = gkyl_wv_euler_new(gas_gamma, app_args.use_gpu); - } - - for (int d = 0; d < ndim; d++) { - coarse_bdata[i].slvr[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &coarse_bdata[i].grid, - .equation = coarse_bdata[i].euler, - .limiter = GKYL_MONOTONIZED_CENTERED, - .num_up_dirs = 1, - .update_dirs = { d }, - .cfl = cfl_frac, - .geom = coarse_bdata[i].geom, - } - ); - } - -#ifdef AMR_DEBUG - if (low_order_flux) { - struct gkyl_wv_euler_inp inp = { - .gas_gamma = gas_gamma, - .rp_type = WV_EULER_RP_HLL, - .use_gpu = app_args.use_gpu, - }; - fine_bdata[i].euler = gkyl_wv_euler_inew(&inp); + mesh_bdata[i].euler = gkyl_wv_euler_inew(&inp); } else { - fine_bdata[i].euler = gkyl_wv_euler_new(gas_gamma, app_args.use_gpu); + mesh_bdata[i].euler = gkyl_wv_euler_new(gas_gamma, app_args.use_gpu); } for (int d = 0; d < ndim; d++) { - fine_bdata[i].slvr[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &fine_bdata[i].grid, - .equation = fine_bdata[i].euler, + mesh_bdata[i].slvr[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { + .grid = &mesh_bdata[i].grid, + .equation = mesh_bdata[i].euler, .limiter = GKYL_MONOTONIZED_CENTERED, .num_up_dirs = 1, .update_dirs = { d }, .cfl = cfl_frac, - .geom = fine_bdata[i].geom, + .geom = mesh_bdata[i].geom, } ); } -#endif } struct gkyl_block_topo *btopo = create_block_topo(); for (int i = 0; i < num_blocks; i++) { - euler_block_bc_updaters_init(&coarse_bdata[i], &btopo->conn[i]); - -#ifdef AMR_DEBUG - euler_block_bc_updaters_init(&fine_bdata[i], &btopo->conn[i]); -#endif + euler_block_bc_updaters_init(&mesh_bdata[i], &btopo->conn[i]); } for (int i = 0; i < num_blocks; i++) { - coarse_bdata[i].fdup = gkyl_array_new(GKYL_DOUBLE, 5, coarse_bdata[i].ext_range.volume); + mesh_bdata[i].fdup = gkyl_array_new(GKYL_DOUBLE, 5, mesh_bdata[i].ext_range.volume); for (int d = 0; d < ndim + 1; d++) { - coarse_bdata[i].f[d] = gkyl_array_new(GKYL_DOUBLE, 5, coarse_bdata[i].ext_range.volume); + mesh_bdata[i].f[d] = gkyl_array_new(GKYL_DOUBLE, 5, mesh_bdata[i].ext_range.volume); } - -#ifdef AMR_DEBUG - fine_bdata[i].fdup = gkyl_array_new(GKYL_DOUBLE, 5, fine_bdata[i].ext_range.volume); - - for (int d = 0; d < ndim + 1; d++) { - fine_bdata[i].f[d] = gkyl_array_new(GKYL_DOUBLE, 5, fine_bdata[i].ext_range.volume); - } -#endif } #ifdef AMR_USETHREADS for (int i = 0; i < num_blocks; i++) { - gkyl_job_pool_add_work(coarse_job_pool, euler_init_job_func_block, &coarse_bdata[i]); - -#ifdef AMR_DEBUG - gkyl_job_pool_add_work(fine_job_pool, euler_init_job_func_block, &fine_bdata[i]); -#endif + gkyl_job_pool_add_work(coarse_job_pool, euler_init_job_func_block, &mesh_bdata[i]); } gkyl_job_pool_wait(coarse_job_pool); - -#ifdef AMR_DEBUG - gkyl_job_pool_wait(fine_job_pool); -#endif #else for (int i = 0; i < num_blocks; i++) { - euler_init_job_func_block(&coarse_bdata[i]); - -#ifdef AMR_DEBUG - euler_init_job_func_block(&fine_bdata[i]); -#endif + euler_init_job_func_block(&mesh_bdata[i]); } #endif -#ifdef AMR_DEBUG - char coarse0[64]; - snprintf(coarse0, 64, "%s_coarse_0", euler_output); - euler_write_sol_block(coarse0, num_blocks, coarse_bdata); - - char fine0[64]; - snprintf(fine0, 64, "%s_fine_0", euler_output); - euler_write_sol_block(fine0, num_blocks, fine_bdata); - - char fine0b0[64]; - char coarse0b0[64]; - char b0[64]; - snprintf(fine0b0, 64, "%s_fine_0_b0.gkyl", euler_output); - snprintf(coarse0b0, 64, "%s_coarse_0_b0.gkyl", euler_output); - snprintf(b0, 64, "%s_0_b0.gkyl", euler_output); - rename(fine0b0, b0); - remove(coarse0b0); - - for (int i = 1; i < 9; i++) { - char buf_old[64]; - char buf_new[64]; - char buf_del[64]; - - snprintf(buf_old, 64, "%s_coarse_0_b%d.gkyl", euler_output, i); - snprintf(buf_new, 64, "%s_0_b%d.gkyl", euler_output, i); - snprintf(buf_del, 64, "%s_fine_0_b%d.gkyl", euler_output, i); - - rename(buf_old, buf_new); - remove(buf_del); - } -#else char amr0[64]; snprintf(amr0, 64, "%s_0", euler_output); - euler_write_sol_block(amr0, num_blocks, coarse_bdata); -#endif + euler_write_sol_block(amr0, num_blocks, mesh_bdata); double coarse_t_curr = 0.0; double fine_t_curr = 0.0; - double coarse_dt = euler_max_dt_block(num_blocks, coarse_bdata); + double coarse_dt = euler_max_dt_block(num_blocks, mesh_bdata); -#ifdef AMR_DEBUG - double fine_dt = euler_max_dt_block(num_blocks, fine_bdata); -#else double fine_dt = (1.0 / ref_factor) * coarse_dt; -#endif struct sim_stats stats = { }; @@ -695,7 +357,7 @@ euler2d_run_single(int argc, char **argv, struct euler2d_single_init* init) while ((coarse_t_curr < t_end) && (coarse_step <= num_steps)) { printf("Taking coarse (level 0) time-step %ld at t = %g; ", coarse_step, coarse_t_curr); - struct gkyl_update_status coarse_status = euler_update_block(coarse_job_pool, btopo, coarse_bdata, coarse_t_curr, coarse_dt, &stats); + struct gkyl_update_status coarse_status = euler_update_block(coarse_job_pool, btopo, mesh_bdata, coarse_t_curr, coarse_dt, &stats); printf(" dt = %g\n", coarse_status.dt_actual); if (!coarse_status.success) { @@ -704,68 +366,19 @@ euler2d_run_single(int argc, char **argv, struct euler2d_single_init* init) } for (long fine_step = 1; fine_step < ref_factor + 1; fine_step++) { -#ifdef AMR_DEBUG - printf(" Taking fine (level 1) time-step %ld at t = %g; ", fine_step, fine_t_curr); - struct gkyl_update_status fine_status = euler_update_block(fine_job_pool, btopo, fine_bdata, fine_t_curr, fine_dt, &stats); - printf(" dt = %g\n", fine_status.dt_actual); - - if (!fine_status.success) { - printf("** Update method failed! Aborting simulation ....\n"); - break; - } - - fine_t_curr += fine_status.dt_actual; - fine_dt = fine_status.dt_suggested; -#else printf(" Taking fine (level 1) time-step %ld at t = %g", fine_step, fine_t_curr); printf(" dt = %g\n", (1.0 / ref_factor) * coarse_status.dt_actual); fine_t_curr += (1.0 / ref_factor) * coarse_status.dt_actual; fine_dt = (1.0 / ref_factor) * coarse_status.dt_suggested; -#endif } for (int i = 1; i < num_frames; i++) { if (coarse_t_curr < (i * io_trigger) && (coarse_t_curr + coarse_status.dt_actual) > (i * io_trigger)) { -#ifdef AMR_DEBUG - char buf_coarse[64]; - char buf_fine[64]; - - snprintf(buf_coarse, 64, "%s_coarse_%d", euler_output, i); - snprintf(buf_fine, 64, "%s_fine_%d", euler_output, i); - - euler_write_sol_block(buf_coarse, num_blocks, coarse_bdata); - euler_write_sol_block(buf_fine, num_blocks, fine_bdata); - - char buf_fine_old[64]; - char buf_fine_new[64]; - char buf_coarse_old[64]; - - snprintf(buf_fine_old, 64, "%s_fine_%d_b0.gkyl", euler_output, i); - snprintf(buf_fine_new, 64, "%s_%d_b0.gkyl", euler_output, i); - snprintf(buf_coarse_old, 64, "%s_coarse_%d_b0.gkyl", euler_output, i); - - rename(buf_fine_old, buf_fine_new); - remove(buf_coarse_old); - - for (int j = 1; j < 9; j++) { - char buf_old[64]; - char buf_new[64]; - char buf_del[64]; - - snprintf(buf_old, 64, "%s_coarse_%d_b%d.gkyl", euler_output, i, j); - snprintf(buf_new, 64, "%s_%d_b%d.gkyl", euler_output, i, j); - snprintf(buf_del, 64, "%s_fine_%d_b%d.gkyl", euler_output, i, j); - - rename(buf_old, buf_new); - remove(buf_del); - } -#else char buf[64]; snprintf(buf, 64, "%s_%d", euler_output, i); - euler_write_sol_block(buf, num_blocks, coarse_bdata); -#endif + euler_write_sol_block(buf, num_blocks, mesh_bdata); } } @@ -796,88 +409,32 @@ euler2d_run_single(int argc, char **argv, struct euler2d_single_init* init) double tm_total_sec = gkyl_time_diff_now_sec(tm_start); -#ifdef AMR_DEBUG - char buf_coarse[64]; - char buf_fine[64]; - - snprintf(buf_coarse, 64, "%s_coarse_%d", euler_output, num_frames); - snprintf(buf_fine, 64, "%s_fine_%d", euler_output, num_frames); - - euler_write_sol_block(buf_coarse, num_blocks, coarse_bdata); - euler_write_sol_block(buf_fine, num_blocks, fine_bdata); - - char buf_fine_old[64]; - char buf_fine_new[64]; - char buf_coarse_old[64]; - - snprintf(buf_fine_old, 64, "%s_fine_%d_b0.gkyl", euler_output, num_frames); - snprintf(buf_fine_new, 64, "%s_%d_b0.gkyl", euler_output, num_frames); - snprintf(buf_coarse_old, 64, "%s_coarse_%d_b0.gkyl", euler_output,num_frames); - - rename(buf_fine_old, buf_fine_new); - remove(buf_coarse_old); - - for (int i = 1; i < 9; i++) { - char buf_old[64]; - char buf_new[64]; - char buf_del[64]; - - snprintf(buf_old, 64, "%s_coarse_%d_b%d.gkyl", euler_output, num_frames, i); - snprintf(buf_new, 64, "%s_%d_b%d.gkyl", euler_output, num_frames, i); - snprintf(buf_del, 64, "%s_fine_%d_b%d.gkyl", euler_output, num_frames, i); - - rename(buf_old, buf_new); - remove(buf_del); - } -#else char buf[64]; snprintf(buf, 64, "%s_%d", euler_output, num_frames); - euler_write_sol_block(buf, num_blocks, coarse_bdata); -#endif + euler_write_sol_block(buf, num_blocks, mesh_bdata); printf("Total run-time: %g. Failed steps: %d\n", tm_total_sec, stats.nfail); for (int i = 0; i < num_blocks; i++) { - gkyl_fv_proj_release(coarse_bdata[i].fv_proj); - gkyl_wv_eqn_release(coarse_bdata[i].euler); - euler_block_bc_updaters_release(&coarse_bdata[i]); - gkyl_wave_geom_release(coarse_bdata[i].geom); - -#ifdef AMR_DEBUG - gkyl_fv_proj_release(fine_bdata[i].fv_proj); - gkyl_wv_eqn_release(fine_bdata[i].euler); - euler_block_bc_updaters_release(&fine_bdata[i]); - gkyl_wave_geom_release(fine_bdata[i].geom); -#endif + gkyl_fv_proj_release(mesh_bdata[i].fv_proj); + gkyl_wv_eqn_release(mesh_bdata[i].euler); + euler_block_bc_updaters_release(&mesh_bdata[i]); + gkyl_wave_geom_release(mesh_bdata[i].geom); for (int d = 0; d < ndim; d++) { - gkyl_wave_prop_release(coarse_bdata[i].slvr[d]); - -#ifdef AMR_DEBUG - gkyl_wave_prop_release(fine_bdata[i].slvr[d]); -#endif + gkyl_wave_prop_release(mesh_bdata[i].slvr[d]); } - gkyl_array_release(coarse_bdata[i].fdup); -#ifdef AMR_DEBUG - gkyl_array_release(fine_bdata[i].fdup); -#endif + gkyl_array_release(mesh_bdata[i].fdup); for (int d = 0; d < ndim; d++) { - gkyl_array_release(coarse_bdata[i].f[d]); - -#ifdef AMR_DEBUG - gkyl_array_release(fine_bdata[i].f[d]); -#endif + gkyl_array_release(mesh_bdata[i].f[d]); } } gkyl_block_topo_release(btopo); gkyl_job_pool_release(coarse_job_pool); -#ifdef AMR_DEBUG - gkyl_job_pool_release(fine_job_pool); -#endif } void @@ -929,218 +486,69 @@ euler2d_run_double(int argc, char **argv, struct euler2d_double_init* init) int Nx = base_Nx; int Ny = base_Ny; - struct euler_block_data coarse_bdata[num_blocks]; + struct euler_block_data mesh_bdata[num_blocks]; struct gkyl_job_pool *coarse_job_pool = gkyl_thread_pool_new(app_args.num_threads); -#ifdef AMR_DEBUG - gkyl_rect_grid_init(&coarse_bdata[0].grid, 2, (double []) { refined_x1, refined_y1 }, (double []) { refined_x2, refined_y2 }, - (int []) { Nx, Ny }); - - gkyl_rect_grid_init(&coarse_bdata[1].grid, 2, (double []) { intermediate_x1, refined_y2 }, (double []) { refined_x1, intermediate_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[2].grid, 2, (double []) { refined_x1, refined_y2 }, (double []) { refined_x2, intermediate_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[3].grid, 2, (double []) { refined_x2, refined_y2 }, (double []) { intermediate_x2, intermediate_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[4].grid, 2, (double []) { intermediate_x1, refined_y1 }, (double []) { refined_x1, refined_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[5].grid, 2, (double []) { refined_x2, refined_y1 }, (double []) { intermediate_x2, refined_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[6].grid, 2, (double []) { intermediate_x1, intermediate_y1 }, (double []) { refined_x1, refined_y1 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[7].grid, 2, (double []) { refined_x1, intermediate_y1 }, (double []) { refined_x2, refined_y1 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[8].grid, 2, (double []) { refined_x2, intermediate_y1 }, (double []) { intermediate_x2, refined_y1 }, - (int []) { Nx, Ny }); -#else - gkyl_rect_grid_init(&coarse_bdata[0].grid, 2, (double []) { refined_x1, refined_y1 }, (double []) { refined_x2, refined_y2 }, + gkyl_rect_grid_init(&mesh_bdata[0].grid, 2, (double []) { refined_x1, refined_y1 }, (double []) { refined_x2, refined_y2 }, (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&coarse_bdata[1].grid, 2, (double []) { intermediate_x1, refined_y2 }, (double []) { refined_x1, intermediate_y2 }, + gkyl_rect_grid_init(&mesh_bdata[1].grid, 2, (double []) { intermediate_x1, refined_y2 }, (double []) { refined_x1, intermediate_y2 }, (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&coarse_bdata[2].grid, 2, (double []) { refined_x1, refined_y2 }, (double []) { refined_x2, intermediate_y2 }, + gkyl_rect_grid_init(&mesh_bdata[2].grid, 2, (double []) { refined_x1, refined_y2 }, (double []) { refined_x2, intermediate_y2 }, (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&coarse_bdata[3].grid, 2, (double []) { refined_x2, refined_y2 }, (double []) { intermediate_x2, intermediate_y2 }, + gkyl_rect_grid_init(&mesh_bdata[3].grid, 2, (double []) { refined_x2, refined_y2 }, (double []) { intermediate_x2, intermediate_y2 }, (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&coarse_bdata[4].grid, 2, (double []) { intermediate_x1, refined_y1 }, (double []) { refined_x1, refined_y2 }, + gkyl_rect_grid_init(&mesh_bdata[4].grid, 2, (double []) { intermediate_x1, refined_y1 }, (double []) { refined_x1, refined_y2 }, (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&coarse_bdata[5].grid, 2, (double []) { refined_x2, refined_y1 }, (double []) { intermediate_x2, refined_y2 }, + gkyl_rect_grid_init(&mesh_bdata[5].grid, 2, (double []) { refined_x2, refined_y1 }, (double []) { intermediate_x2, refined_y2 }, (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&coarse_bdata[6].grid, 2, (double []) { intermediate_x1, intermediate_y1 }, (double []) { refined_x1, refined_y1 }, + gkyl_rect_grid_init(&mesh_bdata[6].grid, 2, (double []) { intermediate_x1, intermediate_y1 }, (double []) { refined_x1, refined_y1 }, (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&coarse_bdata[7].grid, 2, (double []) { refined_x1, intermediate_y1 }, (double []) { refined_x2, refined_y1 }, + gkyl_rect_grid_init(&mesh_bdata[7].grid, 2, (double []) { refined_x1, intermediate_y1 }, (double []) { refined_x2, refined_y1 }, (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&coarse_bdata[8].grid, 2, (double []) { refined_x2, intermediate_y1 }, (double []) { intermediate_x2, refined_y1 }, + gkyl_rect_grid_init(&mesh_bdata[8].grid, 2, (double []) { refined_x2, intermediate_y1 }, (double []) { intermediate_x2, refined_y1 }, (int []) { Nx * ref_factor1, Ny * ref_factor1 }); -#endif - gkyl_rect_grid_init(&coarse_bdata[9].grid, 2, (double []) { coarse_x1, intermediate_y2 }, (double []) { intermediate_x1, coarse_y2 }, + gkyl_rect_grid_init(&mesh_bdata[9].grid, 2, (double []) { coarse_x1, intermediate_y2 }, (double []) { intermediate_x1, coarse_y2 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[10].grid, 2, (double []) { intermediate_x1, intermediate_y2 }, (double []) { refined_x1, coarse_y2 }, + gkyl_rect_grid_init(&mesh_bdata[10].grid, 2, (double []) { intermediate_x1, intermediate_y2 }, (double []) { refined_x1, coarse_y2 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[11].grid, 2, (double []) { refined_x1, intermediate_y2 }, (double []) { refined_x2, coarse_y2 }, + gkyl_rect_grid_init(&mesh_bdata[11].grid, 2, (double []) { refined_x1, intermediate_y2 }, (double []) { refined_x2, coarse_y2 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[12].grid, 2, (double []) { refined_x2, intermediate_y2 }, (double []) { intermediate_x2, coarse_y2 }, + gkyl_rect_grid_init(&mesh_bdata[12].grid, 2, (double []) { refined_x2, intermediate_y2 }, (double []) { intermediate_x2, coarse_y2 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[13].grid, 2, (double []) { intermediate_x2, intermediate_y2 }, (double []) { coarse_x2, coarse_y2 }, + gkyl_rect_grid_init(&mesh_bdata[13].grid, 2, (double []) { intermediate_x2, intermediate_y2 }, (double []) { coarse_x2, coarse_y2 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[14].grid, 2, (double []) { coarse_x1, refined_y2 }, (double []) { intermediate_x1, intermediate_y2 }, + gkyl_rect_grid_init(&mesh_bdata[14].grid, 2, (double []) { coarse_x1, refined_y2 }, (double []) { intermediate_x1, intermediate_y2 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[15].grid, 2, (double []) { intermediate_x2, refined_y2 }, (double []) { coarse_x2, intermediate_y2 }, + gkyl_rect_grid_init(&mesh_bdata[15].grid, 2, (double []) { intermediate_x2, refined_y2 }, (double []) { coarse_x2, intermediate_y2 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[16].grid, 2, (double []) { coarse_x1, refined_y1 }, (double []) { intermediate_x1, refined_y2 }, + gkyl_rect_grid_init(&mesh_bdata[16].grid, 2, (double []) { coarse_x1, refined_y1 }, (double []) { intermediate_x1, refined_y2 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[17].grid, 2, (double []) { intermediate_x2, refined_y1 }, (double []) { coarse_x2, refined_y2 }, + gkyl_rect_grid_init(&mesh_bdata[17].grid, 2, (double []) { intermediate_x2, refined_y1 }, (double []) { coarse_x2, refined_y2 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[18].grid, 2, (double []) { coarse_x1, intermediate_y1 }, (double []) { intermediate_x1, refined_y1 }, + gkyl_rect_grid_init(&mesh_bdata[18].grid, 2, (double []) { coarse_x1, intermediate_y1 }, (double []) { intermediate_x1, refined_y1 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[19].grid, 2, (double []) { intermediate_x2, intermediate_y1 }, (double []) { coarse_x2, refined_y1 }, + gkyl_rect_grid_init(&mesh_bdata[19].grid, 2, (double []) { intermediate_x2, intermediate_y1 }, (double []) { coarse_x2, refined_y1 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[20].grid, 2, (double []) { coarse_x1, coarse_y1 }, (double []) { intermediate_x1, intermediate_y1 }, + gkyl_rect_grid_init(&mesh_bdata[20].grid, 2, (double []) { coarse_x1, coarse_y1 }, (double []) { intermediate_x1, intermediate_y1 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[21].grid, 2, (double []) { intermediate_x1, coarse_y1 }, (double []) { refined_x1, intermediate_y1 }, + gkyl_rect_grid_init(&mesh_bdata[21].grid, 2, (double []) { intermediate_x1, coarse_y1 }, (double []) { refined_x1, intermediate_y1 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[22].grid, 2, (double []) { refined_x1, coarse_y1 }, (double []) { refined_x2, intermediate_y1 }, + gkyl_rect_grid_init(&mesh_bdata[22].grid, 2, (double []) { refined_x1, coarse_y1 }, (double []) { refined_x2, intermediate_y1 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[23].grid, 2, (double []) { refined_x2, coarse_y1 }, (double []) { intermediate_x2, intermediate_y1 }, + gkyl_rect_grid_init(&mesh_bdata[23].grid, 2, (double []) { refined_x2, coarse_y1 }, (double []) { intermediate_x2, intermediate_y1 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[24].grid, 2, (double []) { intermediate_x2, coarse_y1 }, (double []) { coarse_x2, intermediate_y1 }, + gkyl_rect_grid_init(&mesh_bdata[24].grid, 2, (double []) { intermediate_x2, coarse_y1 }, (double []) { coarse_x2, intermediate_y1 }, (int []) { Nx, Ny }); -#ifdef AMR_DEBUG - struct euler_block_data intermediate_bdata[num_blocks]; - struct gkyl_job_pool *intermediate_job_pool = gkyl_thread_pool_new(app_args.num_threads); - - gkyl_rect_grid_init(&intermediate_bdata[0].grid, 2, (double []) { refined_x1, refined_y1 }, (double []) { refined_x2, refined_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - - gkyl_rect_grid_init(&intermediate_bdata[1].grid, 2, (double []) { coarse_x1, refined_y2 }, (double []) { refined_x1, coarse_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[2].grid, 2, (double []) { refined_x1, refined_y2 }, (double []) { refined_x2, coarse_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[3].grid, 2, (double []) { refined_x2, refined_y2 }, (double []) { coarse_x2, coarse_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[4].grid, 2, (double []) { coarse_x1, refined_y1 }, (double []) { refined_x1, refined_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[5].grid, 2, (double []) { refined_x2, refined_y1 }, (double []) { coarse_x2, refined_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[6].grid, 2, (double []) { coarse_x1, coarse_y1 }, (double []) { refined_x1, refined_y1 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[7].grid, 2, (double []) { refined_x1, coarse_y1 }, (double []) { refined_x2, refined_y1 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[8].grid, 2, (double []) { refined_x2, coarse_y1 }, (double []) { coarse_x2, refined_y1 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - - gkyl_rect_grid_init(&intermediate_bdata[9].grid, 2, (double []) { coarse_x1, intermediate_y2 }, (double []) { intermediate_x1, coarse_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[10].grid, 2, (double []) { intermediate_x1, intermediate_y2 }, (double []) { refined_x1, coarse_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[11].grid, 2, (double []) { refined_x1, intermediate_y2 }, (double []) { refined_x2, coarse_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[12].grid, 2, (double []) { refined_x2, intermediate_y2 }, (double []) { intermediate_x2, coarse_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[13].grid, 2, (double []) { intermediate_x2, intermediate_y2 }, (double []) { coarse_x2, coarse_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[14].grid, 2, (double []) { coarse_x1, refined_y2 }, (double []) { intermediate_x1, intermediate_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[15].grid, 2, (double []) { intermediate_x2, refined_y2 }, (double []) { coarse_x2, intermediate_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[16].grid, 2, (double []) { coarse_x1, refined_y1 }, (double []) { intermediate_x1, refined_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[17].grid, 2, (double []) { intermediate_x2, refined_y1 }, (double []) { coarse_x2, refined_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[18].grid, 2, (double []) { coarse_x1, intermediate_y1 }, (double []) { intermediate_x1, refined_y1 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[19].grid, 2, (double []) { intermediate_x2, intermediate_y1 }, (double []) { coarse_x2, refined_y1 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[20].grid, 2, (double []) { coarse_x1, coarse_y1 }, (double []) { intermediate_x1, intermediate_y1 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[21].grid, 2, (double []) { intermediate_x1, coarse_y1 }, (double []) { refined_x1, intermediate_y1 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[22].grid, 2, (double []) { refined_x1, coarse_y1 }, (double []) { refined_x2, intermediate_y1 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[23].grid, 2, (double []) { refined_x2, coarse_y1 }, (double []) { intermediate_x2, intermediate_y1 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[24].grid, 2, (double []) { intermediate_x2, coarse_y1 }, (double []) { coarse_x2, intermediate_y1 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - - struct euler_block_data fine_bdata[num_blocks]; - struct gkyl_job_pool *fine_job_pool = gkyl_thread_pool_new(app_args.num_threads); - - gkyl_rect_grid_init(&fine_bdata[0].grid, 2, (double []) { refined_x1, refined_y1 }, (double []) { refined_x2, refined_y2 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - - gkyl_rect_grid_init(&fine_bdata[1].grid, 2, (double []) { coarse_x1, refined_y2 }, (double []) { refined_x1, coarse_y2 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[2].grid, 2, (double []) { refined_x1, refined_y2 }, (double []) { refined_x2, coarse_y2 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[3].grid, 2, (double []) { refined_x2, refined_y2 }, (double []) { coarse_x2, coarse_y2 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[4].grid, 2, (double []) { coarse_x1, refined_y1 }, (double []) { refined_x1, refined_y2 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[5].grid, 2, (double []) { refined_x2, refined_y1 }, (double []) { coarse_x2, refined_y2 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[6].grid, 2, (double []) { coarse_x1, coarse_y1 }, (double []) { refined_x1, refined_y1 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[7].grid, 2, (double []) { refined_x1, coarse_y1 }, (double []) { refined_x2, refined_y1 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[8].grid, 2, (double []) { refined_x2, coarse_y1 }, (double []) { coarse_x2, refined_y1 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - - gkyl_rect_grid_init(&fine_bdata[9].grid, 2, (double []) { coarse_x1, intermediate_y2 }, (double []) { intermediate_x1, coarse_y2 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[10].grid, 2, (double []) { intermediate_x1, intermediate_y2 }, (double []) { refined_x1, coarse_y2 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[11].grid, 2, (double []) { refined_x1, intermediate_y2 }, (double []) { refined_x2, coarse_y2 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[12].grid, 2, (double []) { refined_x2, intermediate_y2 }, (double []) { intermediate_x2, coarse_y2 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[13].grid, 2, (double []) { intermediate_x2, intermediate_y2 }, (double []) { coarse_x2, coarse_y2 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[14].grid, 2, (double []) { coarse_x1, refined_y2 }, (double []) { intermediate_x1, intermediate_y2 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[15].grid, 2, (double []) { intermediate_x2, refined_y2 }, (double []) { coarse_x2, intermediate_y2 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[16].grid, 2, (double []) { coarse_x1, refined_y1 }, (double []) { intermediate_x1, refined_y2 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[17].grid, 2, (double []) { intermediate_x2, refined_y1 }, (double []) { coarse_x2, refined_y2 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[18].grid, 2, (double []) { coarse_x1, intermediate_y1 }, (double []) { intermediate_x1, refined_y1 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[19].grid, 2, (double []) { intermediate_x2, intermediate_y1 }, (double []) { coarse_x2, refined_y1 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[20].grid, 2, (double []) { coarse_x1, coarse_y1 }, (double []) { intermediate_x1, intermediate_y1 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[21].grid, 2, (double []) { intermediate_x1, coarse_y1 }, (double []) { refined_x1, intermediate_y1 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[22].grid, 2, (double []) { refined_x1, coarse_y1 }, (double []) { refined_x2, intermediate_y1 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[23].grid, 2, (double []) { refined_x2, coarse_y1 }, (double []) { intermediate_x2, intermediate_y1 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[24].grid, 2, (double []) { intermediate_x2, coarse_y1 }, (double []) { coarse_x2, intermediate_y1 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); -#endif - for (int i = 0; i < num_blocks; i++) { - coarse_bdata[i].fv_proj = gkyl_fv_proj_new(&coarse_bdata[i].grid, 2, 5, eval, 0); - -#ifdef AMR_DEBUG - intermediate_bdata[i].fv_proj = gkyl_fv_proj_new(&intermediate_bdata[i].grid, 2, 5, eval, 0); - fine_bdata[i].fv_proj = gkyl_fv_proj_new(&fine_bdata[i].grid, 2, 5, eval, 0); -#endif + mesh_bdata[i].fv_proj = gkyl_fv_proj_new(&mesh_bdata[i].grid, 2, 5, eval, 0); } for (int i = 0; i < num_blocks; i++) { - gkyl_create_grid_ranges(&coarse_bdata[i].grid, (int []) { 2, 2 }, &coarse_bdata[i].ext_range, &coarse_bdata[i].range); - coarse_bdata[i].geom = gkyl_wave_geom_new(&coarse_bdata[i].grid, &coarse_bdata[i].ext_range, 0, 0, false); - -#ifdef AMR_DEBUG - gkyl_create_grid_ranges(&intermediate_bdata[i].grid, (int []) { 2, 2 }, &intermediate_bdata[i].ext_range, &intermediate_bdata[i].range); - intermediate_bdata[i].geom = gkyl_wave_geom_new(&intermediate_bdata[i].grid, &intermediate_bdata[i].ext_range, 0, 0, false); - - gkyl_create_grid_ranges(&fine_bdata[i].grid, (int []) { 2, 2 }, &fine_bdata[i].ext_range, &fine_bdata[i].range); - fine_bdata[i].geom = gkyl_wave_geom_new(&fine_bdata[i].grid, &fine_bdata[i].ext_range, 0, 0, false); -#endif + gkyl_create_grid_ranges(&mesh_bdata[i].grid, (int []) { 2, 2 }, &mesh_bdata[i].ext_range, &mesh_bdata[i].range); + mesh_bdata[i].geom = gkyl_wave_geom_new(&mesh_bdata[i].grid, &mesh_bdata[i].ext_range, 0, 0, false); } for (int i = 0; i < num_blocks; i++) { @@ -1150,193 +558,62 @@ euler2d_run_double(int argc, char **argv, struct euler2d_double_init* init) .rp_type = WV_EULER_RP_HLL, .use_gpu = app_args.use_gpu, }; - coarse_bdata[i].euler = gkyl_wv_euler_inew(&inp); + mesh_bdata[i].euler = gkyl_wv_euler_inew(&inp); } else { - coarse_bdata[i].euler = gkyl_wv_euler_new(gas_gamma, app_args.use_gpu); + mesh_bdata[i].euler = gkyl_wv_euler_new(gas_gamma, app_args.use_gpu); } for (int d = 0; d < ndim; d++) { - coarse_bdata[i].slvr[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &coarse_bdata[i].grid, - .equation = coarse_bdata[i].euler, + mesh_bdata[i].slvr[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { + .grid = &mesh_bdata[i].grid, + .equation = mesh_bdata[i].euler, .limiter = GKYL_MONOTONIZED_CENTERED, .num_up_dirs = 1, .update_dirs = { d }, .cfl = cfl_frac, - .geom = coarse_bdata[i].geom, + .geom = mesh_bdata[i].geom, } ); } - -#ifdef AMR_DEBUG - if (low_order_flux) { - struct gkyl_wv_euler_inp inp = { - .gas_gamma = gas_gamma, - .rp_type = WV_EULER_RP_HLL, - .use_gpu = app_args.use_gpu, - }; - intermediate_bdata[i].euler = gkyl_wv_euler_inew(&inp); - fine_bdata[i].euler = gkyl_wv_euler_inew(&inp); - } - else { - intermediate_bdata[i].euler = gkyl_wv_euler_new(gas_gamma, app_args.use_gpu); - fine_bdata[i].euler = gkyl_wv_euler_new(gas_gamma, app_args.use_gpu); - } - - for (int d = 0; d < ndim; d++) { - intermediate_bdata[i].slvr[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &intermediate_bdata[i].grid, - .equation = intermediate_bdata[i].euler, - .limiter = GKYL_MONOTONIZED_CENTERED, - .num_up_dirs = 1, - .update_dirs = { d }, - .cfl = cfl_frac, - .geom = intermediate_bdata[i].geom, - } - ); - - fine_bdata[i].slvr[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &fine_bdata[i].grid, - .equation = fine_bdata[i].euler, - .limiter = GKYL_MONOTONIZED_CENTERED, - .num_up_dirs = 1, - .update_dirs = { d }, - .cfl = cfl_frac, - .geom = fine_bdata[i].geom, - } - ); - } -#endif } struct gkyl_block_topo *btopo = create_nested_block_topo(); for (int i = 0; i < num_blocks; i++) { - euler_nested_block_bc_updaters_init(&coarse_bdata[i], &btopo->conn[i]); - -#ifdef AMR_DEBUG - euler_nested_block_bc_updaters_init(&intermediate_bdata[i], &btopo->conn[i]); - euler_nested_block_bc_updaters_init(&fine_bdata[i], &btopo->conn[i]); -#endif + euler_nested_block_bc_updaters_init(&mesh_bdata[i], &btopo->conn[i]); } for (int i = 0; i < num_blocks; i++) { - coarse_bdata[i].fdup = gkyl_array_new(GKYL_DOUBLE, 5, coarse_bdata[i].ext_range.volume); - - for (int d = 0; d < ndim + 1; d++) { - coarse_bdata[i].f[d] = gkyl_array_new(GKYL_DOUBLE, 5, coarse_bdata[i].ext_range.volume); - } - -#ifdef AMR_DEBUG - intermediate_bdata[i].fdup = gkyl_array_new(GKYL_DOUBLE, 5, intermediate_bdata[i].ext_range.volume); - fine_bdata[i].fdup = gkyl_array_new(GKYL_DOUBLE, 5, fine_bdata[i].ext_range.volume); + mesh_bdata[i].fdup = gkyl_array_new(GKYL_DOUBLE, 5, mesh_bdata[i].ext_range.volume); for (int d = 0; d < ndim + 1; d++) { - intermediate_bdata[i].f[d] = gkyl_array_new(GKYL_DOUBLE, 5, intermediate_bdata[i].ext_range.volume); - fine_bdata[i].f[d] = gkyl_array_new(GKYL_DOUBLE, 5, fine_bdata[i].ext_range.volume); + mesh_bdata[i].f[d] = gkyl_array_new(GKYL_DOUBLE, 5, mesh_bdata[i].ext_range.volume); } -#endif } #ifdef AMR_USETHREADS for (int i = 0; i < num_blocks; i++) { - gkyl_job_pool_add_work(coarse_job_pool, euler_init_job_func_block, &coarse_bdata[i]); - -#ifdef AMR_DEBUG - gkyl_job_pool_add_work(intermediate_job_pool, euler_init_job_func_block, &intermediate_bdata[i]); - gkyl_job_pool_add_work(fine_job_pool, euler_init_job_func_block, &fine_bdata[i]); -#endif + gkyl_job_pool_add_work(coarse_job_pool, euler_init_job_func_block, &mesh_bdata[i]); } gkyl_job_pool_wait(coarse_job_pool); - -#ifdef AMR_DEBUG - gkyl_job_pool_wait(intermediate_job_pool); - gkyl_job_pool_wait(fine_job_pool); -#endif #else for (int i = 0; i < num_blocks; i++) { - euler_init_job_func_block(&coarse_bdata[i]); - -#ifdef AMR_DEBUG - euler_init_job_func_block(&intermediate_bdata[i]); - euler_init_job_func_block(&fine_bdata[i]); -#endif + euler_init_job_func_block(&mesh_bdata[i]); } #endif -#ifdef AMR_DEBUG - char coarse0[64]; - snprintf(coarse0, 64, "%s_coarse_0", euler_output); - euler_write_sol_block(coarse0, num_blocks, coarse_bdata); - - char intermediate0[64]; - snprintf(intermediate0, 64, "%s_intermediate_0", euler_output); - euler_write_sol_block(intermediate0, num_blocks, intermediate_bdata); - - char fine0[64]; - snprintf(fine0, 64, "%s_fine_0", euler_output); - euler_write_sol_block(fine0, num_blocks, fine_bdata); - - char fine0b0[64]; - char intermediate0b0[64]; - char coarse0b0[64]; - char b0[64]; - snprintf(fine0b0, 64, "%s_fine_0_b0.gkyl", euler_output); - snprintf(intermediate0b0, 64, "%s_intermediate_0_b0.gkyl", euler_output); - snprintf(coarse0b0, 64, "%s_coarse_0_b0.gkyl", euler_output); - snprintf(b0, 64, "%s_0_b0.gkyl", euler_output); - rename(fine0b0, b0); - remove(intermediate0b0); - remove(coarse0b0); - - for (int i = 1; i < 9; i++) { - char fine0bi[64]; - char intermediate0bi[64]; - char coarse0bi[64]; - char bi[64]; - snprintf(fine0bi, 64, "%s_fine_0_b%d.gkyl", euler_output, i); - snprintf(intermediate0bi, 64, "%s_intermediate_0_b%d.gkyl", euler_output, i); - snprintf(coarse0bi, 64, "%s_coarse_0_b%d.gkyl", euler_output, i); - snprintf(bi, 64, "%s_0_b%d.gkyl", euler_output, i); - rename(intermediate0bi, bi); - remove(fine0bi); - remove(coarse0bi); - } - - for (int i = 9; i < 25; i++) { - char buf_old[64]; - char buf_new[64]; - char buf_del1[64]; - char buf_del2[64]; - - snprintf(buf_old, 64, "%s_coarse_0_b%d.gkyl", euler_output, i); - snprintf(buf_new, 64, "%s_0_b%d.gkyl", euler_output, i); - snprintf(buf_del1, 64, "%s_intermediate_0_b%d.gkyl", euler_output, i); - snprintf(buf_del2, 64, "%s_fine_0_b%d.gkyl", euler_output, i); - - rename(buf_old, buf_new); - remove(buf_del1); - remove(buf_del2); - } -#else char amr0[64]; snprintf(amr0, 64, "%s_0", euler_output); - euler_write_sol_block(amr0, num_blocks, coarse_bdata); -#endif + euler_write_sol_block(amr0, num_blocks, mesh_bdata); double coarse_t_curr = 0.0; double intermediate_t_curr = 0.0; double fine_t_curr = 0.0; - double coarse_dt = euler_max_dt_block(num_blocks, coarse_bdata); + double coarse_dt = euler_max_dt_block(num_blocks, mesh_bdata); -#ifdef AMR_DEBUG - double intermediate_dt = euler_max_dt_block(num_blocks, intermediate_bdata); - double fine_dt = euler_max_dt_block(num_blocks, fine_bdata); -#else double intermediate_dt = (1.0 / ref_factor1) * coarse_dt; double fine_dt = (1.0 / (ref_factor1 * ref_factor2)) * coarse_dt; -#endif struct sim_stats stats = { }; @@ -1352,7 +629,7 @@ euler2d_run_double(int argc, char **argv, struct euler2d_double_init* init) while ((coarse_t_curr < t_end) && (coarse_step <= num_steps)) { printf("Taking coarse (level 0) time-step %ld at t = %g; ", coarse_step, coarse_t_curr); - struct gkyl_update_status coarse_status = euler_update_block(coarse_job_pool, btopo, coarse_bdata, coarse_t_curr, coarse_dt, &stats); + struct gkyl_update_status coarse_status = euler_update_block(coarse_job_pool, btopo, mesh_bdata, coarse_t_curr, coarse_dt, &stats); printf(" dt = %g\n", coarse_status.dt_actual); if (!coarse_status.success) { @@ -1361,33 +638,6 @@ euler2d_run_double(int argc, char **argv, struct euler2d_double_init* init) } for (long intermediate_step = 1; intermediate_step < ref_factor1 + 1; intermediate_step++) { -#ifdef AMR_DEBUG - printf(" Taking intermediate (level 1) time-step %ld at t = %g; ", intermediate_step, intermediate_t_curr); - struct gkyl_update_status intermediate_status = euler_update_block(intermediate_job_pool, btopo, intermediate_bdata, intermediate_t_curr, intermediate_dt, &stats); - printf(" dt = %g\n", intermediate_status.dt_actual); - - if (!intermediate_status.success) { - printf("** Update method failed! Aborting simulation ....\n"); - break; - } - - for (long fine_step = 1; fine_step < ref_factor2 + 1; fine_step++) { - printf(" Taking fine (level 2) time-step %ld at t = %g; ", fine_step, fine_t_curr); - struct gkyl_update_status fine_status = euler_update_block(fine_job_pool, btopo, fine_bdata, fine_t_curr, fine_dt, &stats); - printf( "dt = %g\n", fine_status.dt_actual); - - if (!fine_status.success) { - printf("** Update method failed! Aborting simulation ....\n"); - break; - } - - fine_t_curr += fine_status.dt_actual; - fine_dt = fine_status.dt_suggested; - } - - intermediate_t_curr += intermediate_status.dt_actual; - intermediate_dt = intermediate_status.dt_suggested; -#else printf(" Taking intermediate (level 1) time-step %ld at t = %g", intermediate_step, intermediate_t_curr); printf(" dt = %g\n", (1.0 / ref_factor1) * coarse_status.dt_actual); @@ -1401,73 +651,14 @@ euler2d_run_double(int argc, char **argv, struct euler2d_double_init* init) intermediate_t_curr += (1.0 / ref_factor1) * coarse_status.dt_actual; intermediate_dt = (1.0 / ref_factor1) * coarse_status.dt_suggested; -#endif } for (int i = 1; i < num_frames; i++) { if (coarse_t_curr < (i * io_trigger) && (coarse_t_curr + coarse_status.dt_actual) > (i * io_trigger)) { -#ifdef AMR_DEBUG - char buf_coarse[64]; - char buf_intermediate[64]; - char buf_fine[64]; - - snprintf(buf_coarse, 64, "%s_coarse_%d", euler_output, i); - snprintf(buf_intermediate, 64, "%s_intermediate_%d", euler_output, i); - snprintf(buf_fine, 64, "%s_fine_%d", euler_output, i); - - euler_write_sol_block(buf_coarse, num_blocks, coarse_bdata); - euler_write_sol_block(buf_intermediate, num_blocks, intermediate_bdata); - euler_write_sol_block(buf_fine, num_blocks, fine_bdata); - - char buf_fine_old[64]; - char buf_fine_new[64]; - char buf_intermediate_old[64]; - char buf_coarse_old[64]; - - snprintf(buf_fine_old, 64, "%s_fine_%d_b0.gkyl", euler_output, i); - snprintf(buf_fine_new, 64, "%s_%d_b0.gkyl", euler_output, i); - snprintf(buf_intermediate_old, 64, "%s_intermediate_%d_b0.gkyl", euler_output, i); - snprintf(buf_coarse_old, 64, "%s_coarse_%d_b0.gkyl", euler_output, i); - - rename(buf_fine_old, buf_fine_new); - remove(buf_intermediate_old); - remove(buf_coarse_old); - - for (int j = 1; j < 9; j++) { - char fine_bi[64]; - char intermediate_bi[64]; - char coarse_bi[64]; - char bi[64]; - snprintf(fine_bi, 64, "%s_fine_%d_b%d.gkyl", euler_output, i, j); - snprintf(intermediate_bi, 64, "%s_intermediate_%d_b%d.gkyl", euler_output, i, j); - snprintf(coarse_bi, 64, "%s_coarse_%d_b%d.gkyl", euler_output, i, j); - snprintf(bi, 64, "%s_%d_b%d.gkyl", euler_output, i, j); - rename(intermediate_bi, bi); - remove(fine_bi); - remove(coarse_bi); - } - - for (int j = 9; j < 25; j++) { - char buf_old[64]; - char buf_new[64]; - char buf_del1[64]; - char buf_del2[64]; - - snprintf(buf_old, 64, "%s_coarse_%d_b%d.gkyl", euler_output, i, j); - snprintf(buf_new, 64, "%s_%d_b%d.gkyl", euler_output, i, j); - snprintf(buf_del1, 64, "%s_intermediate_%d_b%d.gkyl", euler_output, i, j); - snprintf(buf_del2, 64, "%s_fine_%d_b%d.gkyl", euler_output, i, j); - - rename(buf_old, buf_new); - remove(buf_del1); - remove(buf_del2); - } -#else char buf[64]; snprintf(buf, 64, "%s_%d", euler_output, i); - euler_write_sol_block(buf, num_blocks, coarse_bdata); -#endif + euler_write_sol_block(buf, num_blocks, mesh_bdata); } } @@ -1498,118 +689,30 @@ euler2d_run_double(int argc, char **argv, struct euler2d_double_init* init) double tm_total_sec = gkyl_time_diff_now_sec(tm_start); -#ifdef AMR_DEBUG - char buf_coarse[64]; - char buf_intermediate[64]; - char buf_fine[64]; - - snprintf(buf_coarse, 64, "%s_coarse_%d", euler_output, num_frames); - snprintf(buf_intermediate, 64, "%s_intermediate_%d", euler_output, num_frames); - snprintf(buf_fine, 64, "%s_fine_%d", euler_output, num_frames); - - euler_write_sol_block(buf_coarse, num_blocks, coarse_bdata); - euler_write_sol_block(buf_intermediate, num_blocks, intermediate_bdata); - euler_write_sol_block(buf_fine, num_blocks, fine_bdata); - - char buf_fine_old[64]; - char buf_fine_new[64]; - char buf_intermediate_old[64]; - char buf_coarse_old[64]; - - snprintf(buf_fine_old, 64, "%s_fine_%d_b0.gkyl", euler_output, num_frames); - snprintf(buf_fine_new, 64, "%s_%d_b0.gkyl", euler_output, num_frames); - snprintf(buf_intermediate_old, 64, "%s_intermediate_%d_b0.gkyl", euler_output, num_frames); - snprintf(buf_coarse_old, 64, "%s_coarse_%d_b0.gkyl", euler_output,num_frames); - - rename(buf_fine_old, buf_fine_new); - remove(buf_intermediate_old); - remove(buf_coarse_old); - - for (int i = 1; i < 9; i++) { - char fine_bi[64]; - char intermediate_bi[64]; - char coarse_bi[64]; - char bi[64]; - snprintf(fine_bi, 64, "%s_fine_%d_b%d.gkyl", euler_output, num_frames, i); - snprintf(intermediate_bi, 64, "%s_intermediate_%d_b%d.gkyl", euler_output, num_frames, i); - snprintf(coarse_bi, 64, "%s_coarse_%d_b%d.gkyl", euler_output, num_frames, i); - snprintf(bi, 64, "%s_%d_b%d.gkyl", euler_output, num_frames, i); - rename(intermediate_bi, bi); - remove(fine_bi); - remove(coarse_bi); - } - - for (int i = 9; i < 25; i++) { - char buf_old[64]; - char buf_new[64]; - char buf_del1[64]; - char buf_del2[64]; - - snprintf(buf_old, 64, "%s_coarse_%d_b%d.gkyl", euler_output, num_frames, i); - snprintf(buf_new, 64, "%s_%d_b%d.gkyl", euler_output, num_frames, i); - snprintf(buf_del1, 64, "%s_intermediate_%d_b%d.gkyl", euler_output, num_frames, i); - snprintf(buf_del2, 64, "%s_fine_%d_b%d.gkyl", euler_output, num_frames, i); - - rename(buf_old, buf_new); - remove(buf_del1); - remove(buf_del2); - } -#else char buf[64]; snprintf(buf, 64, "%s_%d", euler_output, num_frames); - euler_write_sol_block(buf, num_blocks, coarse_bdata); -#endif + euler_write_sol_block(buf, num_blocks, mesh_bdata); printf("Total run-time: %g. Failed steps: %d\n", tm_total_sec, stats.nfail); for (int i = 0; i < num_blocks; i++) { - gkyl_fv_proj_release(coarse_bdata[i].fv_proj); - gkyl_wv_eqn_release(coarse_bdata[i].euler); - euler_block_bc_updaters_release(&coarse_bdata[i]); - gkyl_wave_geom_release(coarse_bdata[i].geom); - -#ifdef AMR_DEBUG - gkyl_fv_proj_release(intermediate_bdata[i].fv_proj); - gkyl_wv_eqn_release(intermediate_bdata[i].euler); - euler_block_bc_updaters_release(&intermediate_bdata[i]); - gkyl_wave_geom_release(intermediate_bdata[i].geom); - - gkyl_fv_proj_release(fine_bdata[i].fv_proj); - gkyl_wv_eqn_release(fine_bdata[i].euler); - euler_block_bc_updaters_release(&fine_bdata[i]); - gkyl_wave_geom_release(fine_bdata[i].geom); -#endif + gkyl_fv_proj_release(mesh_bdata[i].fv_proj); + gkyl_wv_eqn_release(mesh_bdata[i].euler); + euler_block_bc_updaters_release(&mesh_bdata[i]); + gkyl_wave_geom_release(mesh_bdata[i].geom); for (int d = 0; d < ndim; d++) { - gkyl_wave_prop_release(coarse_bdata[i].slvr[d]); - -#ifdef AMR_DEBUG - gkyl_wave_prop_release(intermediate_bdata[i].slvr[d]); - gkyl_wave_prop_release(fine_bdata[i].slvr[d]); -#endif + gkyl_wave_prop_release(mesh_bdata[i].slvr[d]); } - gkyl_array_release(coarse_bdata[i].fdup); -#ifdef AMR_DEBUG - gkyl_array_release(intermediate_bdata[i].fdup); - gkyl_array_release(fine_bdata[i].fdup); -#endif + gkyl_array_release(mesh_bdata[i].fdup); for (int d = 0; d < ndim; d++) { - gkyl_array_release(coarse_bdata[i].f[d]); - -#ifdef AMR_DEBUG - gkyl_array_release(intermediate_bdata[i].f[d]); - gkyl_array_release(fine_bdata[i].f[d]); -#endif + gkyl_array_release(mesh_bdata[i].f[d]); } } gkyl_block_topo_release(btopo); gkyl_job_pool_release(coarse_job_pool); -#ifdef AMR_DEBUG - gkyl_job_pool_release(intermediate_job_pool); - gkyl_job_pool_release(fine_job_pool); -#endif } \ No newline at end of file diff --git a/amr/amr_core_gr_euler.c b/amr/amr_core_gr_euler.c index 3613193bd..309e78d16 100644 --- a/amr/amr_core_gr_euler.c +++ b/amr/amr_core_gr_euler.c @@ -42,168 +42,72 @@ gr_euler1d_run_single(int argc, char **argv, struct gr_euler1d_single_init* init int num_patches = 3; int Nx = base_Nx; - struct euler_patch_data coarse_pdata[num_patches]; + struct euler_patch_data mesh_pdata[num_patches]; struct gkyl_job_pool *coarse_job_pool = gkyl_thread_pool_new(app_args.num_threads); -#ifdef AMR_DEBUG - gkyl_rect_grid_init(&coarse_pdata[0].grid, 1, (double []) { refined_x1 }, (double []) { refined_x2 }, (int []) { Nx } ); -#else - gkyl_rect_grid_init(&coarse_pdata[0].grid, 1, (double []) { refined_x1 }, (double []) { refined_x2 }, (int []) { Nx * ref_factor } ); -#endif + gkyl_rect_grid_init(&mesh_pdata[0].grid, 1, (double []) { refined_x1 }, (double []) { refined_x2 }, (int []) { Nx * ref_factor } ); - gkyl_rect_grid_init(&coarse_pdata[1].grid, 1, (double []) { coarse_x1 }, (double []) { refined_x1 }, (int []) { Nx } ); - gkyl_rect_grid_init(&coarse_pdata[2].grid, 1, (double []) { refined_x2 }, (double []) { coarse_x2 }, (int []) { Nx } ); - -#ifdef AMR_DEBUG - struct euler_patch_data fine_pdata[num_patches]; - struct gkyl_job_pool *fine_job_pool = gkyl_thread_pool_new(app_args.num_threads); - - gkyl_rect_grid_init(&fine_pdata[0].grid, 1, (double []) { refined_x1 }, (double []) { refined_x2 }, (int []) { Nx * ref_factor } ); - gkyl_rect_grid_init(&fine_pdata[1].grid, 1, (double []) { coarse_x1 }, (double []) { refined_x1 }, (int []) { Nx * ref_factor } ); - gkyl_rect_grid_init(&fine_pdata[2].grid, 1, (double []) { refined_x2 }, (double []) { coarse_x2 }, (int []) { Nx * ref_factor } ); -#endif + gkyl_rect_grid_init(&mesh_pdata[1].grid, 1, (double []) { coarse_x1 }, (double []) { refined_x1 }, (int []) { Nx } ); + gkyl_rect_grid_init(&mesh_pdata[2].grid, 1, (double []) { refined_x2 }, (double []) { coarse_x2 }, (int []) { Nx } ); for (int i = 0; i < num_patches; i++) { - coarse_pdata[i].fv_proj = gkyl_fv_proj_new(&coarse_pdata[i].grid, 1, 29, eval, 0); - -#ifdef AMR_DEBUG - fine_pdata[i].fv_proj = gkyl_fv_proj_new(&fine_pdata[i].grid, 1, 29, eval, 0); -#endif + mesh_pdata[i].fv_proj = gkyl_fv_proj_new(&mesh_pdata[i].grid, 1, 29, eval, 0); } for (int i = 0; i < num_patches; i++) { - gkyl_create_grid_ranges(&coarse_pdata[i].grid, (int []) { 2 }, &coarse_pdata[i].ext_range, &coarse_pdata[i].range ); - coarse_pdata[i].geom = gkyl_wave_geom_new(&coarse_pdata[i].grid, &coarse_pdata[i].ext_range, 0, 0, false); - -#ifdef AMR_DEBUG - gkyl_create_grid_ranges(&fine_pdata[i].grid, (int []) { 2 }, &fine_pdata[i].ext_range, &fine_pdata[i].range); - fine_pdata[i].geom = gkyl_wave_geom_new(&fine_pdata[i].grid, &fine_pdata[i].ext_range, 0, 0, false); -#endif + gkyl_create_grid_ranges(&mesh_pdata[i].grid, (int []) { 2 }, &mesh_pdata[i].ext_range, &mesh_pdata[i].range ); + mesh_pdata[i].geom = gkyl_wave_geom_new(&mesh_pdata[i].grid, &mesh_pdata[i].ext_range, 0, 0, false); } for (int i = 0; i < num_patches; i++) { - coarse_pdata[i].euler = gkyl_wv_gr_euler_new(gas_gamma, spacetime, app_args.use_gpu); - - coarse_pdata[i].slvr[0] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &coarse_pdata[i].grid, - .equation = coarse_pdata[i].euler, - .limiter = GKYL_MONOTONIZED_CENTERED, - .num_up_dirs = 1, - .update_dirs = { 0 }, - .cfl = cfl_frac, - .geom = coarse_pdata[i].geom, - } - ); - -#ifdef AMR_DEBUG - fine_pdata[i].euler = gkyl_wv_gr_euler_new(gas_gamma, spacetime, app_args.use_gpu); + mesh_pdata[i].euler = gkyl_wv_gr_euler_new(gas_gamma, spacetime, app_args.use_gpu); - fine_pdata[i].slvr[0] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &fine_pdata[i].grid, - .equation = fine_pdata[i].euler, + mesh_pdata[i].slvr[0] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { + .grid = &mesh_pdata[i].grid, + .equation = mesh_pdata[i].euler, .limiter = GKYL_MONOTONIZED_CENTERED, .num_up_dirs = 1, .update_dirs = { 0 }, .cfl = cfl_frac, - .geom = fine_pdata[i].geom, + .geom = mesh_pdata[i].geom, } ); -#endif } struct gkyl_block_topo *ptopo = create_patch_topo(); for (int i = 0; i < num_patches; i++) { - gr_euler_patch_bc_updaters_init(&coarse_pdata[i], &ptopo->conn[i]); - -#ifdef AMR_DEBUG - gr_euler_patch_bc_updaters_init(&fine_pdata[i], &ptopo->conn[i]); -#endif + gr_euler_patch_bc_updaters_init(&mesh_pdata[i], &ptopo->conn[i]); } for (int i = 0; i < num_patches; i++) { - coarse_pdata[i].fdup = gkyl_array_new(GKYL_DOUBLE, 29, coarse_pdata[i].ext_range.volume); + mesh_pdata[i].fdup = gkyl_array_new(GKYL_DOUBLE, 29, mesh_pdata[i].ext_range.volume); for (int d = 0; d < ndim + 1; d++) { - coarse_pdata[i].f[d] = gkyl_array_new(GKYL_DOUBLE, 29, coarse_pdata[i].ext_range.volume); + mesh_pdata[i].f[d] = gkyl_array_new(GKYL_DOUBLE, 29, mesh_pdata[i].ext_range.volume); } -#ifdef AMR_DEBUG - fine_pdata[i].fdup = gkyl_array_new(GKYL_DOUBLE, 29, fine_pdata[i].ext_range.volume); - - for (int d = 0; d < ndim + 1; d++) { - fine_pdata[i].f[d] = gkyl_array_new(GKYL_DOUBLE, 29, fine_pdata[i].ext_range.volume); - } -#endif } #ifdef AMR_USETHREADS for (int i = 0; i < num_patches; i++) { - gkyl_job_pool_add_work(coarse_job_pool, euler_init_job_func_patch, &coarse_pdata[i]); - -#ifdef AMR_DEBUG - gkyl_job_pool_add_work(fine_job_pool, euler_init_job_func_patch, &fine_pdata[i]); -#endif + gkyl_job_pool_add_work(coarse_job_pool, euler_init_job_func_patch, &mesh_pdata[i]); } gkyl_job_pool_wait(coarse_job_pool); - -#ifdef AMR_DEBUG - gkyl_job_pool_wait(fine_job_pool); -#endif #else for (int i = 0; i < num_patches; i++) { - euler_init_job_func_patch(&coarse_pdata[i]); - -#ifdef AMR_DEBUG - euler_init_job_func_patch(&fine_pdata[i]); -#endif + euler_init_job_func_patch(&mesh_pdata[i]); } #endif -#ifdef AMR_DEBUG - char coarse0[64]; - snprintf(coarse0, 64, "%s_coarse_0", gr_euler_output); - euler_write_sol_patch(coarse0, num_patches, coarse_pdata); - - char fine0[64]; - snprintf(fine0, 64, "%s_fine_0", gr_euler_output); - euler_write_sol_patch(fine0, num_patches, fine_pdata); - - char fine0p0[64]; - char coarse0p0[64]; - char p0[64]; - snprintf(fine0p0, 64, "%s_fine_0_p0.gkyl", gr_euler_output); - snprintf(coarse0p0, 64, "%s_coarse_0_p0.gkyl", gr_euler_output); - snprintf(p0, 64, "%s_0_p0.gkyl", gr_euler_output); - rename(fine0p0, p0); - remove(coarse0p0); - - for (int i = 1; i < 3; i++) { - char buf_old[64]; - char buf_new[64]; - char buf_del[64]; - - snprintf(buf_old, 64, "%s_coarse_0_p%d.gkyl", gr_euler_output, i); - snprintf(buf_new, 64, "%s_0_p%d.gkyl", gr_euler_output, i); - snprintf(buf_del, 64, "%s_fine_0_p%d.gkyl", gr_euler_output, i); - - rename(buf_old, buf_new); - remove(buf_del); - } -#else char amr0[64]; snprintf(amr0, 64, "%s_0", gr_euler_output); - euler_write_sol_patch(amr0, num_patches, coarse_pdata); -#endif + euler_write_sol_patch(amr0, num_patches, mesh_pdata); double coarse_t_curr = 0.0; double fine_t_curr = 0.0; - double coarse_dt = euler_max_dt_patch(num_patches, coarse_pdata); + double coarse_dt = euler_max_dt_patch(num_patches, mesh_pdata); -#ifdef AMR_DEBUG - double fine_dt = euler_max_dt_patch(num_patches, fine_pdata); -#else double fine_dt = (1.0 / ref_factor) * coarse_dt; -#endif struct sim_stats stats = { }; @@ -219,7 +123,7 @@ gr_euler1d_run_single(int argc, char **argv, struct gr_euler1d_single_init* init while ((coarse_t_curr < t_end) && (coarse_step <= num_steps)) { printf("Taking coarse (level 0) time-step %ld at t = %g; ", coarse_step, coarse_t_curr); - struct gkyl_update_status coarse_status = euler_update_patch(coarse_job_pool, ptopo, coarse_pdata, coarse_t_curr, coarse_dt, &stats); + struct gkyl_update_status coarse_status = euler_update_patch(coarse_job_pool, ptopo, mesh_pdata, coarse_t_curr, coarse_dt, &stats); printf(" dt = %g\n", coarse_status.dt_actual); if (!coarse_status.success) { @@ -228,68 +132,19 @@ gr_euler1d_run_single(int argc, char **argv, struct gr_euler1d_single_init* init } for (long fine_step = 1; fine_step < ref_factor + 1; fine_step++) { -#ifdef AMR_DEBUG - printf(" Taking fine (level 1) time-step %ld at t = %g; ", fine_step, fine_t_curr); - struct gkyl_update_status fine_status = euler_update_patch(fine_job_pool, ptopo, fine_pdata, fine_t_curr, fine_dt, &stats); - printf(" dt = %g\n", fine_status.dt_actual); - - if (!fine_status.success) { - printf("** Update method failed! Aborting simulation ....\n"); - break; - } - - fine_t_curr += fine_status.dt_actual; - fine_dt = fine_status.dt_suggested; -#else printf(" Taking fine (level 1) time-step %ld at t = %g", fine_step, fine_t_curr); printf(" dt = %g\n", (1.0 / ref_factor) * coarse_status.dt_actual); fine_t_curr += (1.0 / ref_factor) * coarse_status.dt_actual; fine_dt = (1.0 / ref_factor) * coarse_status.dt_suggested; -#endif } for (int i = 1; i < num_frames; i++) { if (coarse_t_curr < (i * io_trigger) && (coarse_t_curr + coarse_status.dt_actual) > (i * io_trigger)) { -#ifdef AMR_DEBUG - char buf_coarse[64]; - char buf_fine[64]; - - snprintf(buf_coarse, 64, "%s_coarse_%d", gr_euler_output, i); - snprintf(buf_fine, 64, "%s_fine_%d", gr_euler_output, i); - - euler_write_sol_patch(buf_coarse, num_patches, coarse_pdata); - euler_write_sol_patch(buf_fine, num_patches, fine_pdata); - - char buf_fine_old[64]; - char buf_fine_new[64]; - char buf_coarse_old[64]; - - snprintf(buf_fine_old, 64, "%s_fine_%d_p0.gkyl", gr_euler_output, i); - snprintf(buf_fine_new, 64, "%s_%d_p0.gkyl", gr_euler_output, i); - snprintf(buf_coarse_old, 64, "%s_coarse_%d_p0.gkyl", gr_euler_output, i); - - rename(buf_fine_old, buf_fine_new); - remove(buf_coarse_old); - - for (int j = 1; j < 3; j++) { - char buf_old[64]; - char buf_new[64]; - char buf_del[64]; - - snprintf(buf_old, 64, "%s_coarse_%d_p%d.gkyl", gr_euler_output, i, j); - snprintf(buf_new, 64, "%s_%d_p%d.gkyl", gr_euler_output, i, j); - snprintf(buf_del, 64, "%s_fine_%d_p%d.gkyl", gr_euler_output, i, j); - - rename(buf_old, buf_new); - remove(buf_del); - } -#else char buf[64]; snprintf(buf, 64, "%s_%d", gr_euler_output, i); - euler_write_sol_patch(buf, num_patches, coarse_pdata); -#endif + euler_write_sol_patch(buf, num_patches, mesh_pdata); } } @@ -320,86 +175,27 @@ gr_euler1d_run_single(int argc, char **argv, struct gr_euler1d_single_init* init double tm_total_sec = gkyl_time_diff_now_sec(tm_start); -#ifdef AMR_DEBUG - char buf_coarse[64]; - char buf_fine[64]; - - snprintf(buf_coarse, 64, "%s_coarse_%d", gr_euler_output, num_frames); - snprintf(buf_fine, 64, "%s_fine_%d", gr_euler_output, num_frames); - - euler_write_sol_patch(buf_coarse, num_patches, coarse_pdata); - euler_write_sol_patch(buf_fine, num_patches, fine_pdata); - - char buf_fine_old[64]; - char buf_fine_new[64]; - char buf_coarse_old[64]; - - snprintf(buf_fine_old, 64, "%s_fine_%d_p0.gkyl", gr_euler_output, num_frames); - snprintf(buf_fine_new, 64, "%s_%d_p0.gkyl", gr_euler_output, num_frames); - snprintf(buf_coarse_old, 64, "%s_coarse_%d_p0.gkyl", gr_euler_output,num_frames); - - rename(buf_fine_old, buf_fine_new); - remove(buf_coarse_old); - - for (int i = 1; i < 3; i++) { - char buf_old[64]; - char buf_new[64]; - char buf_del[64]; - - snprintf(buf_old, 64, "%s_coarse_%d_p%d.gkyl", gr_euler_output, num_frames, i); - snprintf(buf_new, 64, "%s_%d_p%d.gkyl", gr_euler_output, num_frames, i); - snprintf(buf_del, 64, "%s_fine_%d_p%d.gkyl", gr_euler_output, num_frames, i); - - - rename(buf_old, buf_new); - remove(buf_del); - } -#else char buf[64]; snprintf(buf, 64, "%s_%d", gr_euler_output, num_frames); - euler_write_sol_patch(buf, num_patches, coarse_pdata); -#endif + euler_write_sol_patch(buf, num_patches, mesh_pdata); printf("Total run-time: %g. Failed steps: %d\n", tm_total_sec, stats.nfail); for (int i = 0; i < num_patches; i++) { - gkyl_fv_proj_release(coarse_pdata[i].fv_proj); - gkyl_wv_eqn_release(coarse_pdata[i].euler); - euler_patch_bc_updaters_release(&coarse_pdata[i]); - gkyl_wave_geom_release(coarse_pdata[i].geom); - -#ifdef AMR_DEBUG - gkyl_fv_proj_release(fine_pdata[i].fv_proj); - gkyl_wv_eqn_release(fine_pdata[i].euler); - euler_patch_bc_updaters_release(&fine_pdata[i]); - gkyl_wave_geom_release(fine_pdata[i].geom); -#endif - - gkyl_wave_prop_release(coarse_pdata[i].slvr[0]); + gkyl_fv_proj_release(mesh_pdata[i].fv_proj); + gkyl_wv_eqn_release(mesh_pdata[i].euler); + euler_patch_bc_updaters_release(&mesh_pdata[i]); + gkyl_wave_geom_release(mesh_pdata[i].geom); -#ifdef AMR_DEBUG - gkyl_wave_prop_release(fine_pdata[i].slvr[0]); -#endif - - gkyl_array_release(coarse_pdata[i].fdup); -#ifdef AMR_DEBUG - gkyl_array_release(fine_pdata[i].fdup); -#endif - - gkyl_array_release(coarse_pdata[i].f[0]); - -#ifdef AMR_DEBUG - gkyl_array_release(fine_pdata[i].f[0]); -#endif + gkyl_wave_prop_release(mesh_pdata[i].slvr[0]); + gkyl_array_release(mesh_pdata[i].fdup); + gkyl_array_release(mesh_pdata[i].f[0]); } gkyl_block_topo_release(ptopo); gkyl_gr_spacetime_release(spacetime); gkyl_job_pool_release(coarse_job_pool); -#ifdef AMR_DEBUG - gkyl_job_pool_release(fine_job_pool); -#endif } void @@ -446,204 +242,89 @@ gr_euler2d_run_single(int argc, char **argv, struct gr_euler2d_single_init* init int Nx = base_Nx; int Ny = base_Ny; - struct euler_block_data coarse_bdata[num_blocks]; + struct euler_block_data mesh_bdata[num_blocks]; struct gkyl_job_pool *coarse_job_pool = gkyl_thread_pool_new(app_args.num_threads); -#ifdef AMR_DEBUG - gkyl_rect_grid_init(&coarse_bdata[0].grid, 2, (double []) { refined_x1, refined_y1 }, (double []) { refined_x2, refined_y2 }, - (int []) { Nx, Ny }); -#else - gkyl_rect_grid_init(&coarse_bdata[0].grid, 2, (double []) { refined_x1, refined_y1 }, (double []) { refined_x2, refined_y2 }, + gkyl_rect_grid_init(&mesh_bdata[0].grid, 2, (double []) { refined_x1, refined_y1 }, (double []) { refined_x2, refined_y2 }, (int []) { Nx * ref_factor, Ny * ref_factor }); -#endif - gkyl_rect_grid_init(&coarse_bdata[1].grid, 2, (double []) { coarse_x1, refined_y2 }, (double []) { refined_x1, coarse_y2 }, + gkyl_rect_grid_init(&mesh_bdata[1].grid, 2, (double []) { coarse_x1, refined_y2 }, (double []) { refined_x1, coarse_y2 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[2].grid, 2, (double []) { refined_x1, refined_y2 }, (double []) { refined_x2, coarse_y2 }, + gkyl_rect_grid_init(&mesh_bdata[2].grid, 2, (double []) { refined_x1, refined_y2 }, (double []) { refined_x2, coarse_y2 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[3].grid, 2, (double []) { refined_x2, refined_y2 }, (double []) { coarse_x2, coarse_y2 }, + gkyl_rect_grid_init(&mesh_bdata[3].grid, 2, (double []) { refined_x2, refined_y2 }, (double []) { coarse_x2, coarse_y2 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[4].grid, 2, (double []) { coarse_x1, refined_y1 }, (double []) { refined_x1, refined_y2 }, + gkyl_rect_grid_init(&mesh_bdata[4].grid, 2, (double []) { coarse_x1, refined_y1 }, (double []) { refined_x1, refined_y2 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[5].grid, 2, (double []) { refined_x2, refined_y1 }, (double []) { coarse_x2, refined_y2 }, + gkyl_rect_grid_init(&mesh_bdata[5].grid, 2, (double []) { refined_x2, refined_y1 }, (double []) { coarse_x2, refined_y2 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[6].grid, 2, (double []) { coarse_x1, coarse_y1 }, (double []) { refined_x1, refined_y1 }, + gkyl_rect_grid_init(&mesh_bdata[6].grid, 2, (double []) { coarse_x1, coarse_y1 }, (double []) { refined_x1, refined_y1 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[7].grid, 2, (double []) { refined_x1, coarse_y1 }, (double []) { refined_x2, refined_y1 }, + gkyl_rect_grid_init(&mesh_bdata[7].grid, 2, (double []) { refined_x1, coarse_y1 }, (double []) { refined_x2, refined_y1 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[8].grid, 2, (double []) { refined_x2, coarse_y1 }, (double []) { coarse_x2, refined_y1 }, + gkyl_rect_grid_init(&mesh_bdata[8].grid, 2, (double []) { refined_x2, coarse_y1 }, (double []) { coarse_x2, refined_y1 }, (int []) { Nx, Ny }); -#ifdef AMR_DEBUG - struct euler_block_data fine_bdata[num_blocks]; - struct gkyl_job_pool *fine_job_pool = gkyl_thread_pool_new(app_args.num_threads); - - gkyl_rect_grid_init(&fine_bdata[0].grid, 2, (double []) { refined_x1, refined_y1 }, (double []) { refined_x2, refined_y2 }, - (int []) { Nx * ref_factor, Ny * ref_factor }); - gkyl_rect_grid_init(&fine_bdata[1].grid, 2, (double []) { coarse_x1, refined_y2 }, (double []) { refined_x1, coarse_y2 }, - (int []) { Nx * ref_factor, Ny * ref_factor }); - gkyl_rect_grid_init(&fine_bdata[2].grid, 2, (double []) { refined_x1, refined_y2 }, (double []) { refined_x2, coarse_y2 }, - (int []) { Nx * ref_factor, Ny * ref_factor }); - gkyl_rect_grid_init(&fine_bdata[3].grid, 2, (double []) { refined_x2, refined_y2 }, (double []) { coarse_x2, coarse_y2 }, - (int []) { Nx * ref_factor, Ny * ref_factor }); - gkyl_rect_grid_init(&fine_bdata[4].grid, 2, (double []) { coarse_x1, refined_y1 }, (double []) { refined_x1, refined_y2 }, - (int []) { Nx * ref_factor, Ny * ref_factor }); - gkyl_rect_grid_init(&fine_bdata[5].grid, 2, (double []) { refined_x2, refined_y1 }, (double []) { coarse_x2, refined_y2 }, - (int []) { Nx * ref_factor, Ny * ref_factor }); - gkyl_rect_grid_init(&fine_bdata[6].grid, 2, (double []) { coarse_x1, coarse_y1 }, (double []) { refined_x1, refined_y1 }, - (int []) { Nx * ref_factor, Ny * ref_factor }); - gkyl_rect_grid_init(&fine_bdata[7].grid, 2, (double []) { refined_x1, coarse_y1 }, (double []) { refined_x2, refined_y1 }, - (int []) { Nx * ref_factor, Ny * ref_factor }); - gkyl_rect_grid_init(&fine_bdata[8].grid, 2, (double []) { refined_x2, coarse_y1 }, (double []) { coarse_x2, refined_y1 }, - (int []) { Nx * ref_factor, Ny * ref_factor }); -#endif - for (int i = 0; i < num_blocks; i++) { - coarse_bdata[i].fv_proj = gkyl_fv_proj_new(&coarse_bdata[i].grid, 2, 29, eval, 0); - -#ifdef AMR_DEBUG - fine_bdata[i].fv_proj = gkyl_fv_proj_new(&fine_bdata[i].grid, 2, 29, eval, 0); -#endif + mesh_bdata[i].fv_proj = gkyl_fv_proj_new(&mesh_bdata[i].grid, 2, 29, eval, 0); } for (int i = 0; i < num_blocks; i++) { - gkyl_create_grid_ranges(&coarse_bdata[i].grid, (int []) { 2, 2 }, &coarse_bdata[i].ext_range, &coarse_bdata[i].range); - coarse_bdata[i].geom = gkyl_wave_geom_new(&coarse_bdata[i].grid, &coarse_bdata[i].ext_range, 0, 0, false); - -#ifdef AMR_DEBUG - gkyl_create_grid_ranges(&fine_bdata[i].grid, (int []) { 2, 2 }, &fine_bdata[i].ext_range, &fine_bdata[i].range); - fine_bdata[i].geom = gkyl_wave_geom_new(&fine_bdata[i].grid, &fine_bdata[i].ext_range, 0, 0, false); -#endif + gkyl_create_grid_ranges(&mesh_bdata[i].grid, (int []) { 2, 2 }, &mesh_bdata[i].ext_range, &mesh_bdata[i].range); + mesh_bdata[i].geom = gkyl_wave_geom_new(&mesh_bdata[i].grid, &mesh_bdata[i].ext_range, 0, 0, false); } for (int i = 0; i < num_blocks; i++) { - coarse_bdata[i].euler = gkyl_wv_gr_euler_new(gas_gamma, spacetime, app_args.use_gpu); - - for (int d = 0; d < ndim; d++) { - coarse_bdata[i].slvr[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &coarse_bdata[i].grid, - .equation = coarse_bdata[i].euler, - .limiter = GKYL_MONOTONIZED_CENTERED, - .num_up_dirs = 1, - .update_dirs = { d }, - .cfl = cfl_frac, - .geom = coarse_bdata[i].geom, - } - ); - } - -#ifdef AMR_DEBUG - fine_bdata[i].euler = gkyl_wv_gr_euler_new(gas_gamma, spacetime, app_args.use_gpu); + mesh_bdata[i].euler = gkyl_wv_gr_euler_new(gas_gamma, spacetime, app_args.use_gpu); for (int d = 0; d < ndim; d++) { - fine_bdata[i].slvr[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &fine_bdata[i].grid, - .equation = fine_bdata[i].euler, + mesh_bdata[i].slvr[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { + .grid = &mesh_bdata[i].grid, + .equation = mesh_bdata[i].euler, .limiter = GKYL_MONOTONIZED_CENTERED, .num_up_dirs = 1, .update_dirs = { d }, .cfl = cfl_frac, - .geom = fine_bdata[i].geom, + .geom = mesh_bdata[i].geom, } ); } -#endif } struct gkyl_block_topo *btopo = create_block_topo(); for (int i = 0; i < num_blocks; i++) { - gr_euler_block_bc_updaters_init(&coarse_bdata[i], &btopo->conn[i]); - -#ifdef AMR_DEBUG - gr_euler_block_bc_updaters_init(&fine_bdata[i], &btopo->conn[i]); -#endif + gr_euler_block_bc_updaters_init(&mesh_bdata[i], &btopo->conn[i]); } for (int i = 0; i < num_blocks; i++) { - coarse_bdata[i].fdup = gkyl_array_new(GKYL_DOUBLE, 29, coarse_bdata[i].ext_range.volume); + mesh_bdata[i].fdup = gkyl_array_new(GKYL_DOUBLE, 29, mesh_bdata[i].ext_range.volume); for (int d = 0; d < ndim + 1; d++) { - coarse_bdata[i].f[d] = gkyl_array_new(GKYL_DOUBLE, 29, coarse_bdata[i].ext_range.volume); + mesh_bdata[i].f[d] = gkyl_array_new(GKYL_DOUBLE, 29, mesh_bdata[i].ext_range.volume); } - -#ifdef AMR_DEBUG - fine_bdata[i].fdup = gkyl_array_new(GKYL_DOUBLE, 29, fine_bdata[i].ext_range.volume); - - for (int d = 0; d < ndim + 1; d++) { - fine_bdata[i].f[d] = gkyl_array_new(GKYL_DOUBLE, 29, fine_bdata[i].ext_range.volume); - } -#endif } #ifdef AMR_USETHREADS for (int i = 0; i < num_blocks; i++) { - gkyl_job_pool_add_work(coarse_job_pool, euler_init_job_func_block, &coarse_bdata[i]); - -#ifdef AMR_DEBUG - gkyl_job_pool_add_work(fine_job_pool, euler_init_job_func_block, &fine_bdata[i]); -#endif + gkyl_job_pool_add_work(coarse_job_pool, euler_init_job_func_block, &mesh_bdata[i]); } gkyl_job_pool_wait(coarse_job_pool); - -#ifdef AMR_DEBUG - gkyl_job_pool_wait(fine_job_pool); -#endif #else for (int i = 0; i < num_blocks; i++) { - euler_init_job_func_block(&coarse_bdata[i]); - -#ifdef AMR_DEBUG - euler_init_job_func_block(&fine_bdata[i]); -#endif + euler_init_job_func_block(&mesh_bdata[i]); } #endif -#ifdef AMR_DEBUG - char coarse0[64]; - snprintf(coarse0, 64, "%s_coarse_0", gr_euler_output); - euler_write_sol_block(coarse0, num_blocks, coarse_bdata); - - char fine0[64]; - snprintf(fine0, 64, "%s_fine_0", gr_euler_output); - euler_write_sol_block(fine0, num_blocks, fine_bdata); - - char fine0b0[64]; - char coarse0b0[64]; - char b0[64]; - snprintf(fine0b0, 64, "%s_fine_0_b0.gkyl", gr_euler_output); - snprintf(coarse0b0, 64, "%s_coarse_0_b0.gkyl", gr_euler_output); - snprintf(b0, 64, "%s_0_b0.gkyl", gr_euler_output); - rename(fine0b0, b0); - remove(coarse0b0); - - for (int i = 1; i < 9; i++) { - char buf_old[64]; - char buf_new[64]; - char buf_del[64]; - - snprintf(buf_old, 64, "%s_coarse_0_p%d.gkyl", gr_euler_output, i); - snprintf(buf_new, 64, "%s_0_p%d.gkyl", gr_euler_output, i); - snprintf(buf_del, 64, "%s_fine_0_p%d.gkyl", gr_euler_output, i); - - rename(buf_old, buf_new); - remove(buf_del); - } -#else char amr0[64]; snprintf(amr0, 64, "%s_0", gr_euler_output); - euler_write_sol_block(amr0, num_blocks, coarse_bdata); -#endif + euler_write_sol_block(amr0, num_blocks, mesh_bdata); double coarse_t_curr = 0.0; double fine_t_curr = 0.0; - double coarse_dt = euler_max_dt_block(num_blocks, coarse_bdata); + double coarse_dt = euler_max_dt_block(num_blocks, mesh_bdata); -#ifdef AMR_DEBUG - double fine_dt = euler_max_dt_block(num_blocks, fine_bdata); -#else double fine_dt = (1.0 / ref_factor) * coarse_dt; -#endif struct sim_stats stats = { }; @@ -659,7 +340,7 @@ gr_euler2d_run_single(int argc, char **argv, struct gr_euler2d_single_init* init while ((coarse_t_curr < t_end) && (coarse_step <= num_steps)) { printf("Taking coarse (level 0) time-step %ld at t = %g; ", coarse_step, coarse_t_curr); - struct gkyl_update_status coarse_status = euler_update_block(coarse_job_pool, btopo, coarse_bdata, coarse_t_curr, coarse_dt, &stats); + struct gkyl_update_status coarse_status = euler_update_block(coarse_job_pool, btopo, mesh_bdata, coarse_t_curr, coarse_dt, &stats); printf(" dt = %g\n", coarse_status.dt_actual); if (!coarse_status.success) { @@ -668,68 +349,19 @@ gr_euler2d_run_single(int argc, char **argv, struct gr_euler2d_single_init* init } for (long fine_step = 1; fine_step < ref_factor + 1; fine_step++) { -#ifdef AMR_DEBUG - printf(" Taking fine (level 1) time-step %ld at t = %g; ", fine_step, fine_t_curr); - struct gkyl_update_status fine_status = euler_update_block(fine_job_pool, btopo, fine_bdata, fine_t_curr, fine_dt, &stats); - printf(" dt = %g\n", fine_status.dt_actual); - - if (!fine_status.success) { - printf("** Update method failed! Aborting simulation ....\n"); - break; - } - - fine_t_curr += fine_status.dt_actual; - fine_dt = fine_status.dt_suggested; -#else printf(" Taking fine (level 1) time-step %ld at t = %g", fine_step, fine_t_curr); printf(" dt = %g\n", (1.0 / ref_factor) * coarse_status.dt_actual); fine_t_curr += (1.0 / ref_factor) * coarse_status.dt_actual; fine_dt = (1.0 / ref_factor) * coarse_status.dt_suggested; -#endif } for (int i = 1; i < num_frames; i++) { if (coarse_t_curr < (i * io_trigger) && (coarse_t_curr + coarse_status.dt_actual) > (i * io_trigger)) { -#ifdef AMR_DEBUG - char buf_coarse[64]; - char buf_fine[64]; - - snprintf(buf_coarse, 64, "%s_coarse_%d", gr_euler_output, i); - snprintf(buf_fine, 64, "%s_fine_%d", gr_euler_output, i); - - euler_write_sol_block(buf_coarse, num_blocks, coarse_bdata); - euler_write_sol_block(buf_fine, num_blocks, fine_bdata); - - char buf_fine_old[64]; - char buf_fine_new[64]; - char buf_coarse_old[64]; - - snprintf(buf_fine_old, 64, "%s_fine_%d_b0.gkyl", gr_euler_output, i); - snprintf(buf_fine_new, 64, "%s_%d_b0.gkyl", gr_euler_output, i); - snprintf(buf_coarse_old, 64, "%s_coarse_%d_b0.gkyl", gr_euler_output, i); - - rename(buf_fine_old, buf_fine_new); - remove(buf_coarse_old); - - for (int j = 1; j < 9; j++) { - char buf_old[64]; - char buf_new[64]; - char buf_del[64]; - - snprintf(buf_old, 64, "%s_coarse_%d_b%d.gkyl", gr_euler_output, i, j); - snprintf(buf_new, 64, "%s_%d_b%d.gkyl", gr_euler_output, i, j); - snprintf(buf_del, 64, "%s_fine_%d_b%d.gkyl", gr_euler_output, i, j); - - rename(buf_old, buf_new); - remove(buf_del); - } -#else char buf[64]; snprintf(buf, 64, "%s_%d", gr_euler_output, i); - euler_write_sol_block(buf, num_blocks, coarse_bdata); -#endif + euler_write_sol_block(buf, num_blocks, mesh_bdata); } } @@ -760,89 +392,33 @@ gr_euler2d_run_single(int argc, char **argv, struct gr_euler2d_single_init* init double tm_total_sec = gkyl_time_diff_now_sec(tm_start); -#ifdef AMR_DEBUG - char buf_coarse[64]; - char buf_fine[64]; - - snprintf(buf_coarse, 64, "%s_coarse_%d", gr_euler_output, num_frames); - snprintf(buf_fine, 64, "%s_fine_%d", gr_euler_output, num_frames); - - euler_write_sol_block(buf_coarse, num_blocks, coarse_bdata); - euler_write_sol_block(buf_fine, num_blocks, fine_bdata); - - char buf_fine_old[64]; - char buf_fine_new[64]; - char buf_coarse_old[64]; - - snprintf(buf_fine_old, 64, "%s_fine_%d_b0.gkyl", gr_euler_output, num_frames); - snprintf(buf_fine_new, 64, "%s_%d_b0.gkyl", gr_euler_output, num_frames); - snprintf(buf_coarse_old, 64, "%s_coarse_%d_b0.gkyl", gr_euler_output,num_frames); - - rename(buf_fine_old, buf_fine_new); - remove(buf_coarse_old); - - for (int i = 1; i < 9; i++) { - char buf_old[64]; - char buf_new[64]; - char buf_del[64]; - - snprintf(buf_old, 64, "%s_coarse_%d_b%d.gkyl", gr_euler_output, num_frames, i); - snprintf(buf_new, 64, "%s_%d_b%d.gkyl", gr_euler_output, num_frames, i); - snprintf(buf_del, 64, "%s_fine_%d_b%d.gkyl", gr_euler_output, num_frames, i); - - rename(buf_old, buf_new); - remove(buf_del); - } -#else char buf[64]; snprintf(buf, 64, "%s_%d", gr_euler_output, num_frames); - euler_write_sol_block(buf, num_blocks, coarse_bdata); -#endif + euler_write_sol_block(buf, num_blocks, mesh_bdata); printf("Total run-time: %g. Failed steps: %d\n", tm_total_sec, stats.nfail); for (int i = 0; i < num_blocks; i++) { - gkyl_fv_proj_release(coarse_bdata[i].fv_proj); - gkyl_wv_eqn_release(coarse_bdata[i].euler); - euler_block_bc_updaters_release(&coarse_bdata[i]); - gkyl_wave_geom_release(coarse_bdata[i].geom); - -#ifdef AMR_DEBUG - gkyl_fv_proj_release(fine_bdata[i].fv_proj); - gkyl_wv_eqn_release(fine_bdata[i].euler); - euler_block_bc_updaters_release(&fine_bdata[i]); - gkyl_wave_geom_release(fine_bdata[i].geom); -#endif + gkyl_fv_proj_release(mesh_bdata[i].fv_proj); + gkyl_wv_eqn_release(mesh_bdata[i].euler); + euler_block_bc_updaters_release(&mesh_bdata[i]); + gkyl_wave_geom_release(mesh_bdata[i].geom); for (int d = 0; d < ndim; d++) { - gkyl_wave_prop_release(coarse_bdata[i].slvr[d]); - -#ifdef AMR_DEBUG - gkyl_wave_prop_release(fine_bdata[i].slvr[d]); -#endif + gkyl_wave_prop_release(mesh_bdata[i].slvr[d]); } - gkyl_array_release(coarse_bdata[i].fdup); -#ifdef AMR_DEBUG - gkyl_array_release(fine_bdata[i].fdup); -#endif + gkyl_array_release(mesh_bdata[i].fdup); for (int d = 0; d < ndim; d++) { - gkyl_array_release(coarse_bdata[i].f[d]); - -#ifdef AMR_DEBUG - gkyl_array_release(fine_bdata[i].f[d]); -#endif + gkyl_array_release(mesh_bdata[i].f[d]); } } gkyl_block_topo_release(btopo); gkyl_gr_spacetime_release(spacetime); gkyl_job_pool_release(coarse_job_pool); -#ifdef AMR_DEBUG - gkyl_job_pool_release(fine_job_pool); -#endif } void @@ -895,393 +471,124 @@ gr_euler2d_run_double(int argc, char **argv, struct gr_euler2d_double_init* init int Nx = base_Nx; int Ny = base_Ny; - struct euler_block_data coarse_bdata[num_blocks]; + struct euler_block_data mesh_bdata[num_blocks]; struct gkyl_job_pool *coarse_job_pool = gkyl_thread_pool_new(app_args.num_threads); -#ifdef AMR_DEBUG - gkyl_rect_grid_init(&coarse_bdata[0].grid, 2, (double []) { refined_x1, refined_y1 }, (double []) { refined_x2, refined_y2 }, - (int []) { Nx, Ny }); - - gkyl_rect_grid_init(&coarse_bdata[1].grid, 2, (double []) { intermediate_x1, refined_y2 }, (double []) { refined_x1, intermediate_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[2].grid, 2, (double []) { refined_x1, refined_y2 }, (double []) { refined_x2, intermediate_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[3].grid, 2, (double []) { refined_x2, refined_y2 }, (double []) { intermediate_x2, intermediate_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[4].grid, 2, (double []) { intermediate_x1, refined_y1 }, (double []) { refined_x1, refined_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[5].grid, 2, (double []) { refined_x2, refined_y1 }, (double []) { intermediate_x2, refined_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[6].grid, 2, (double []) { intermediate_x1, intermediate_y1 }, (double []) { refined_x1, refined_y1 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[7].grid, 2, (double []) { refined_x1, intermediate_y1 }, (double []) { refined_x2, refined_y1 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[8].grid, 2, (double []) { refined_x2, intermediate_y1 }, (double []) { intermediate_x2, refined_y1 }, - (int []) { Nx, Ny }); -#else - gkyl_rect_grid_init(&coarse_bdata[0].grid, 2, (double []) { refined_x1, refined_y1 }, (double []) { refined_x2, refined_y2 }, + gkyl_rect_grid_init(&mesh_bdata[0].grid, 2, (double []) { refined_x1, refined_y1 }, (double []) { refined_x2, refined_y2 }, (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&coarse_bdata[1].grid, 2, (double []) { intermediate_x1, refined_y2 }, (double []) { refined_x1, intermediate_y2 }, + gkyl_rect_grid_init(&mesh_bdata[1].grid, 2, (double []) { intermediate_x1, refined_y2 }, (double []) { refined_x1, intermediate_y2 }, (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&coarse_bdata[2].grid, 2, (double []) { refined_x1, refined_y2 }, (double []) { refined_x2, intermediate_y2 }, + gkyl_rect_grid_init(&mesh_bdata[2].grid, 2, (double []) { refined_x1, refined_y2 }, (double []) { refined_x2, intermediate_y2 }, (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&coarse_bdata[3].grid, 2, (double []) { refined_x2, refined_y2 }, (double []) { intermediate_x2, intermediate_y2 }, + gkyl_rect_grid_init(&mesh_bdata[3].grid, 2, (double []) { refined_x2, refined_y2 }, (double []) { intermediate_x2, intermediate_y2 }, (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&coarse_bdata[4].grid, 2, (double []) { intermediate_x1, refined_y1 }, (double []) { refined_x1, refined_y2 }, + gkyl_rect_grid_init(&mesh_bdata[4].grid, 2, (double []) { intermediate_x1, refined_y1 }, (double []) { refined_x1, refined_y2 }, (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&coarse_bdata[5].grid, 2, (double []) { refined_x2, refined_y1 }, (double []) { intermediate_x2, refined_y2 }, + gkyl_rect_grid_init(&mesh_bdata[5].grid, 2, (double []) { refined_x2, refined_y1 }, (double []) { intermediate_x2, refined_y2 }, (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&coarse_bdata[6].grid, 2, (double []) { intermediate_x1, intermediate_y1 }, (double []) { refined_x1, refined_y1 }, + gkyl_rect_grid_init(&mesh_bdata[6].grid, 2, (double []) { intermediate_x1, intermediate_y1 }, (double []) { refined_x1, refined_y1 }, (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&coarse_bdata[7].grid, 2, (double []) { refined_x1, intermediate_y1 }, (double []) { refined_x2, refined_y1 }, + gkyl_rect_grid_init(&mesh_bdata[7].grid, 2, (double []) { refined_x1, intermediate_y1 }, (double []) { refined_x2, refined_y1 }, (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&coarse_bdata[8].grid, 2, (double []) { refined_x2, intermediate_y1 }, (double []) { intermediate_x2, refined_y1 }, + gkyl_rect_grid_init(&mesh_bdata[8].grid, 2, (double []) { refined_x2, intermediate_y1 }, (double []) { intermediate_x2, refined_y1 }, (int []) { Nx * ref_factor1, Ny * ref_factor1 }); -#endif - gkyl_rect_grid_init(&coarse_bdata[9].grid, 2, (double []) { coarse_x1, intermediate_y2 }, (double []) { intermediate_x1, coarse_y2 }, + gkyl_rect_grid_init(&mesh_bdata[9].grid, 2, (double []) { coarse_x1, intermediate_y2 }, (double []) { intermediate_x1, coarse_y2 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[10].grid, 2, (double []) { intermediate_x1, intermediate_y2 }, (double []) { refined_x1, coarse_y2 }, + gkyl_rect_grid_init(&mesh_bdata[10].grid, 2, (double []) { intermediate_x1, intermediate_y2 }, (double []) { refined_x1, coarse_y2 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[11].grid, 2, (double []) { refined_x1, intermediate_y2 }, (double []) { refined_x2, coarse_y2 }, + gkyl_rect_grid_init(&mesh_bdata[11].grid, 2, (double []) { refined_x1, intermediate_y2 }, (double []) { refined_x2, coarse_y2 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[12].grid, 2, (double []) { refined_x2, intermediate_y2 }, (double []) { intermediate_x2, coarse_y2 }, + gkyl_rect_grid_init(&mesh_bdata[12].grid, 2, (double []) { refined_x2, intermediate_y2 }, (double []) { intermediate_x2, coarse_y2 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[13].grid, 2, (double []) { intermediate_x2, intermediate_y2 }, (double []) { coarse_x2, coarse_y2 }, + gkyl_rect_grid_init(&mesh_bdata[13].grid, 2, (double []) { intermediate_x2, intermediate_y2 }, (double []) { coarse_x2, coarse_y2 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[14].grid, 2, (double []) { coarse_x1, refined_y2 }, (double []) { intermediate_x1, intermediate_y2 }, + gkyl_rect_grid_init(&mesh_bdata[14].grid, 2, (double []) { coarse_x1, refined_y2 }, (double []) { intermediate_x1, intermediate_y2 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[15].grid, 2, (double []) { intermediate_x2, refined_y2 }, (double []) { coarse_x2, intermediate_y2 }, + gkyl_rect_grid_init(&mesh_bdata[15].grid, 2, (double []) { intermediate_x2, refined_y2 }, (double []) { coarse_x2, intermediate_y2 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[16].grid, 2, (double []) { coarse_x1, refined_y1 }, (double []) { intermediate_x1, refined_y2 }, + gkyl_rect_grid_init(&mesh_bdata[16].grid, 2, (double []) { coarse_x1, refined_y1 }, (double []) { intermediate_x1, refined_y2 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[17].grid, 2, (double []) { intermediate_x2, refined_y1 }, (double []) { coarse_x2, refined_y2 }, + gkyl_rect_grid_init(&mesh_bdata[17].grid, 2, (double []) { intermediate_x2, refined_y1 }, (double []) { coarse_x2, refined_y2 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[18].grid, 2, (double []) { coarse_x1, intermediate_y1 }, (double []) { intermediate_x1, refined_y1 }, + gkyl_rect_grid_init(&mesh_bdata[18].grid, 2, (double []) { coarse_x1, intermediate_y1 }, (double []) { intermediate_x1, refined_y1 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[19].grid, 2, (double []) { intermediate_x2, intermediate_y1 }, (double []) { coarse_x2, refined_y1 }, + gkyl_rect_grid_init(&mesh_bdata[19].grid, 2, (double []) { intermediate_x2, intermediate_y1 }, (double []) { coarse_x2, refined_y1 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[20].grid, 2, (double []) { coarse_x1, coarse_y1 }, (double []) { intermediate_x1, intermediate_y1 }, + gkyl_rect_grid_init(&mesh_bdata[20].grid, 2, (double []) { coarse_x1, coarse_y1 }, (double []) { intermediate_x1, intermediate_y1 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[21].grid, 2, (double []) { intermediate_x1, coarse_y1 }, (double []) { refined_x1, intermediate_y1 }, + gkyl_rect_grid_init(&mesh_bdata[21].grid, 2, (double []) { intermediate_x1, coarse_y1 }, (double []) { refined_x1, intermediate_y1 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[22].grid, 2, (double []) { refined_x1, coarse_y1 }, (double []) { refined_x2, intermediate_y1 }, + gkyl_rect_grid_init(&mesh_bdata[22].grid, 2, (double []) { refined_x1, coarse_y1 }, (double []) { refined_x2, intermediate_y1 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[23].grid, 2, (double []) { refined_x2, coarse_y1 }, (double []) { intermediate_x2, intermediate_y1 }, + gkyl_rect_grid_init(&mesh_bdata[23].grid, 2, (double []) { refined_x2, coarse_y1 }, (double []) { intermediate_x2, intermediate_y1 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[24].grid, 2, (double []) { intermediate_x2, coarse_y1 }, (double []) { coarse_x2, intermediate_y1 }, + gkyl_rect_grid_init(&mesh_bdata[24].grid, 2, (double []) { intermediate_x2, coarse_y1 }, (double []) { coarse_x2, intermediate_y1 }, (int []) { Nx, Ny }); -#ifdef AMR_DEBUG - struct euler_block_data intermediate_bdata[num_blocks]; - struct gkyl_job_pool *intermediate_job_pool = gkyl_thread_pool_new(app_args.num_threads); - - gkyl_rect_grid_init(&intermediate_bdata[0].grid, 2, (double []) { refined_x1, refined_y1 }, (double []) { refined_x2, refined_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - - gkyl_rect_grid_init(&intermediate_bdata[1].grid, 2, (double []) { coarse_x1, refined_y2 }, (double []) { refined_x1, coarse_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[2].grid, 2, (double []) { refined_x1, refined_y2 }, (double []) { refined_x2, coarse_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[3].grid, 2, (double []) { refined_x2, refined_y2 }, (double []) { coarse_x2, coarse_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[4].grid, 2, (double []) { coarse_x1, refined_y1 }, (double []) { refined_x1, refined_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[5].grid, 2, (double []) { refined_x2, refined_y1 }, (double []) { coarse_x2, refined_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[6].grid, 2, (double []) { coarse_x1, coarse_y1 }, (double []) { refined_x1, refined_y1 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[7].grid, 2, (double []) { refined_x1, coarse_y1 }, (double []) { refined_x2, refined_y1 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[8].grid, 2, (double []) { refined_x2, coarse_y1 }, (double []) { coarse_x2, refined_y1 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - - gkyl_rect_grid_init(&intermediate_bdata[9].grid, 2, (double []) { coarse_x1, intermediate_y2 }, (double []) { intermediate_x1, coarse_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[10].grid, 2, (double []) { intermediate_x1, intermediate_y2 }, (double []) { refined_x1, coarse_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[11].grid, 2, (double []) { refined_x1, intermediate_y2 }, (double []) { refined_x2, coarse_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[12].grid, 2, (double []) { refined_x2, intermediate_y2 }, (double []) { intermediate_x2, coarse_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[13].grid, 2, (double []) { intermediate_x2, intermediate_y2 }, (double []) { coarse_x2, coarse_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[14].grid, 2, (double []) { coarse_x1, refined_y2 }, (double []) { intermediate_x1, intermediate_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[15].grid, 2, (double []) { intermediate_x2, refined_y2 }, (double []) { coarse_x2, intermediate_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[16].grid, 2, (double []) { coarse_x1, refined_y1 }, (double []) { intermediate_x1, refined_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[17].grid, 2, (double []) { intermediate_x2, refined_y1 }, (double []) { coarse_x2, refined_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[18].grid, 2, (double []) { coarse_x1, intermediate_y1 }, (double []) { intermediate_x1, refined_y1 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[19].grid, 2, (double []) { intermediate_x2, intermediate_y1 }, (double []) { coarse_x2, refined_y1 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[20].grid, 2, (double []) { coarse_x1, coarse_y1 }, (double []) { intermediate_x1, intermediate_y1 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[21].grid, 2, (double []) { intermediate_x1, coarse_y1 }, (double []) { refined_x1, intermediate_y1 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[22].grid, 2, (double []) { refined_x1, coarse_y1 }, (double []) { refined_x2, intermediate_y1 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[23].grid, 2, (double []) { refined_x2, coarse_y1 }, (double []) { intermediate_x2, intermediate_y1 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[24].grid, 2, (double []) { intermediate_x2, coarse_y1 }, (double []) { coarse_x2, intermediate_y1 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - - struct euler_block_data fine_bdata[num_blocks]; - struct gkyl_job_pool *fine_job_pool = gkyl_thread_pool_new(app_args.num_threads); - - gkyl_rect_grid_init(&fine_bdata[0].grid, 2, (double []) { refined_x1, refined_y1 }, (double []) { refined_x2, refined_y2 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - - gkyl_rect_grid_init(&fine_bdata[1].grid, 2, (double []) { coarse_x1, refined_y2 }, (double []) { refined_x1, coarse_y2 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[2].grid, 2, (double []) { refined_x1, refined_y2 }, (double []) { refined_x2, coarse_y2 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[3].grid, 2, (double []) { refined_x2, refined_y2 }, (double []) { coarse_x2, coarse_y2 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[4].grid, 2, (double []) { coarse_x1, refined_y1 }, (double []) { refined_x1, refined_y2 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[5].grid, 2, (double []) { refined_x2, refined_y1 }, (double []) { coarse_x2, refined_y2 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[6].grid, 2, (double []) { coarse_x1, coarse_y1 }, (double []) { refined_x1, refined_y1 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[7].grid, 2, (double []) { refined_x1, coarse_y1 }, (double []) { refined_x2, refined_y1 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[8].grid, 2, (double []) { refined_x2, coarse_y1 }, (double []) { coarse_x2, refined_y1 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - - gkyl_rect_grid_init(&fine_bdata[9].grid, 2, (double []) { coarse_x1, intermediate_y2 }, (double []) { intermediate_x1, coarse_y2 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[10].grid, 2, (double []) { intermediate_x1, intermediate_y2 }, (double []) { refined_x1, coarse_y2 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[11].grid, 2, (double []) { refined_x1, intermediate_y2 }, (double []) { refined_x2, coarse_y2 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[12].grid, 2, (double []) { refined_x2, intermediate_y2 }, (double []) { intermediate_x2, coarse_y2 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[13].grid, 2, (double []) { intermediate_x2, intermediate_y2 }, (double []) { coarse_x2, coarse_y2 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[14].grid, 2, (double []) { coarse_x1, refined_y2 }, (double []) { intermediate_x1, intermediate_y2 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[15].grid, 2, (double []) { intermediate_x2, refined_y2 }, (double []) { coarse_x2, intermediate_y2 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[16].grid, 2, (double []) { coarse_x1, refined_y1 }, (double []) { intermediate_x1, refined_y2 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[17].grid, 2, (double []) { intermediate_x2, refined_y1 }, (double []) { coarse_x2, refined_y2 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[18].grid, 2, (double []) { coarse_x1, intermediate_y1 }, (double []) { intermediate_x1, refined_y1 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[19].grid, 2, (double []) { intermediate_x2, intermediate_y1 }, (double []) { coarse_x2, refined_y1 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[20].grid, 2, (double []) { coarse_x1, coarse_y1 }, (double []) { intermediate_x1, intermediate_y1 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[21].grid, 2, (double []) { intermediate_x1, coarse_y1 }, (double []) { refined_x1, intermediate_y1 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[22].grid, 2, (double []) { refined_x1, coarse_y1 }, (double []) { refined_x2, intermediate_y1 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[23].grid, 2, (double []) { refined_x2, coarse_y1 }, (double []) { intermediate_x2, intermediate_y1 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[24].grid, 2, (double []) { intermediate_x2, coarse_y1 }, (double []) { coarse_x2, intermediate_y1 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); -#endif - for (int i = 0; i < num_blocks; i++) { - coarse_bdata[i].fv_proj = gkyl_fv_proj_new(&coarse_bdata[i].grid, 2, 29, eval, 0); - -#ifdef AMR_DEBUG - intermediate_bdata[i].fv_proj = gkyl_fv_proj_new(&intermediate_bdata[i].grid, 2, 29, eval, 0); - fine_bdata[i].fv_proj = gkyl_fv_proj_new(&fine_bdata[i].grid, 2, 29, eval, 0); -#endif + mesh_bdata[i].fv_proj = gkyl_fv_proj_new(&mesh_bdata[i].grid, 2, 29, eval, 0); } for (int i = 0; i < num_blocks; i++) { - gkyl_create_grid_ranges(&coarse_bdata[i].grid, (int []) { 2, 2 }, &coarse_bdata[i].ext_range, &coarse_bdata[i].range); - coarse_bdata[i].geom = gkyl_wave_geom_new(&coarse_bdata[i].grid, &coarse_bdata[i].ext_range, 0, 0, false); - -#ifdef AMR_DEBUG - gkyl_create_grid_ranges(&intermediate_bdata[i].grid, (int []) { 2, 2 }, &intermediate_bdata[i].ext_range, &intermediate_bdata[i].range); - intermediate_bdata[i].geom = gkyl_wave_geom_new(&intermediate_bdata[i].grid, &intermediate_bdata[i].ext_range, 0, 0, false); - - gkyl_create_grid_ranges(&fine_bdata[i].grid, (int []) { 2, 2 }, &fine_bdata[i].ext_range, &fine_bdata[i].range); - fine_bdata[i].geom = gkyl_wave_geom_new(&fine_bdata[i].grid, &fine_bdata[i].ext_range, 0, 0, false); -#endif + gkyl_create_grid_ranges(&mesh_bdata[i].grid, (int []) { 2, 2 }, &mesh_bdata[i].ext_range, &mesh_bdata[i].range); + mesh_bdata[i].geom = gkyl_wave_geom_new(&mesh_bdata[i].grid, &mesh_bdata[i].ext_range, 0, 0, false); } for (int i = 0; i < num_blocks; i++) { - coarse_bdata[i].euler = gkyl_wv_gr_euler_new(gas_gamma, spacetime, app_args.use_gpu); + mesh_bdata[i].euler = gkyl_wv_gr_euler_new(gas_gamma, spacetime, app_args.use_gpu); for (int d = 0; d < ndim; d++) { - coarse_bdata[i].slvr[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &coarse_bdata[i].grid, - .equation = coarse_bdata[i].euler, - .limiter = GKYL_MONOTONIZED_CENTERED, - .num_up_dirs = 1, - .update_dirs = { d }, - .cfl = cfl_frac, - .geom = coarse_bdata[i].geom, - } - ); - } - -#ifdef AMR_DEBUG - intermediate_bdata[i].euler = gkyl_wv_gr_euler_new(gas_gamma, spacetime, app_args.use_gpu); - fine_bdata[i].euler = gkyl_wv_gr_euler_new(gas_gamma, spacetime, app_args.use_gpu); - - for (int d = 0; d < ndim; d++) { - intermediate_bdata[i].slvr[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &intermediate_bdata[i].grid, - .equation = intermediate_bdata[i].euler, - .limiter = GKYL_MONOTONIZED_CENTERED, - .num_up_dirs = 1, - .update_dirs = { d }, - .cfl = cfl_frac, - .geom = intermediate_bdata[i].geom, - } - ); - - fine_bdata[i].slvr[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &fine_bdata[i].grid, - .equation = fine_bdata[i].euler, + mesh_bdata[i].slvr[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { + .grid = &mesh_bdata[i].grid, + .equation = mesh_bdata[i].euler, .limiter = GKYL_MONOTONIZED_CENTERED, .num_up_dirs = 1, .update_dirs = { d }, .cfl = cfl_frac, - .geom = fine_bdata[i].geom, + .geom = mesh_bdata[i].geom, } ); } -#endif } struct gkyl_block_topo *btopo = create_nested_block_topo(); for (int i = 0; i < num_blocks; i++) { - gr_euler_nested_block_bc_updaters_init(&coarse_bdata[i], &btopo->conn[i]); - -#ifdef AMR_DEBUG - gr_euler_nested_block_bc_updaters_init(&intermediate_bdata[i], &btopo->conn[i]); - gr_euler_nested_block_bc_updaters_init(&fine_bdata[i], &btopo->conn[i]); -#endif + gr_euler_nested_block_bc_updaters_init(&mesh_bdata[i], &btopo->conn[i]); } for (int i = 0; i < num_blocks; i++) { - coarse_bdata[i].fdup = gkyl_array_new(GKYL_DOUBLE, 29, coarse_bdata[i].ext_range.volume); - - for (int d = 0; d < ndim + 1; d++) { - coarse_bdata[i].f[d] = gkyl_array_new(GKYL_DOUBLE, 29, coarse_bdata[i].ext_range.volume); - } - -#ifdef AMR_DEBUG - intermediate_bdata[i].fdup = gkyl_array_new(GKYL_DOUBLE, 29, intermediate_bdata[i].ext_range.volume); - fine_bdata[i].fdup = gkyl_array_new(GKYL_DOUBLE, 29, fine_bdata[i].ext_range.volume); + mesh_bdata[i].fdup = gkyl_array_new(GKYL_DOUBLE, 29, mesh_bdata[i].ext_range.volume); for (int d = 0; d < ndim + 1; d++) { - intermediate_bdata[i].f[d] = gkyl_array_new(GKYL_DOUBLE, 29, intermediate_bdata[i].ext_range.volume); - fine_bdata[i].f[d] = gkyl_array_new(GKYL_DOUBLE, 29, fine_bdata[i].ext_range.volume); + mesh_bdata[i].f[d] = gkyl_array_new(GKYL_DOUBLE, 29, mesh_bdata[i].ext_range.volume); } -#endif } #ifdef AMR_USETHREADS for (int i = 0; i < num_blocks; i++) { - gkyl_job_pool_add_work(coarse_job_pool, euler_init_job_func_block, &coarse_bdata[i]); - -#ifdef AMR_DEBUG - gkyl_job_pool_add_work(intermediate_job_pool, euler_init_job_func_block, &intermediate_bdata[i]); - gkyl_job_pool_add_work(fine_job_pool, euler_init_job_func_block, &fine_bdata[i]); -#endif + gkyl_job_pool_add_work(coarse_job_pool, euler_init_job_func_block, &mesh_bdata[i]); } gkyl_job_pool_wait(coarse_job_pool); - -#ifdef AMR_DEBUG - gkyl_job_pool_wait(intermediate_job_pool); - gkyl_job_pool_wait(fine_job_pool); -#endif #else for (int i = 0; i < num_blocks; i++) { - euler_init_job_func_block(&coarse_bdata[i]); - -#ifdef AMR_DEBUG - euler_init_job_func_block(&intermediate_bdata[i]); - euler_init_job_func_block(&fine_bdata[i]); -#endif + euler_init_job_func_block(&mesh_bdata[i]); } #endif -#ifdef AMR_DEBUG - char coarse0[64]; - snprintf(coarse0, 64, "%s_coarse_0", gr_euler_output); - euler_write_sol_block(coarse0, num_blocks, coarse_bdata); - - char intermediate0[64]; - snprintf(intermediate0, 64, "%s_intermediate_0", gr_euler_output); - euler_write_sol_block(intermediate0, num_blocks, intermediate_bdata); - - char fine0[64]; - snprintf(fine0, 64, "%s_fine_0", gr_euler_output); - euler_write_sol_block(fine0, num_blocks, fine_bdata); - - char fine0b0[64]; - char intermediate0b0[64]; - char coarse0b0[64]; - char b0[64]; - snprintf(fine0b0, 64, "%s_fine_0_b0.gkyl", gr_euler_output); - snprintf(intermediate0b0, 64, "%s_intermediate_0_b0.gkyl", gr_euler_output); - snprintf(coarse0b0, 64, "%s_coarse_0_b0.gkyl", gr_euler_output); - snprintf(b0, 64, "%s_0_b0.gkyl", gr_euler_output); - rename(fine0b0, b0); - remove(intermediate0b0); - remove(coarse0b0); - - for (int i = 1; i < 9; i++) { - char fine0bi[64]; - char intermediate0bi[64]; - char coarse0bi[64]; - char bi[64]; - snprintf(fine0bi, 64, "%s_fine_0_b%d.gkyl", gr_euler_output, i); - snprintf(intermediate0bi, 64, "%s_intermediate_0_b%d.gkyl", gr_euler_output, i); - snprintf(coarse0bi, 64, "%s_coarse_0_b%d.gkyl", gr_euler_output, i); - snprintf(bi, 64, "%s_0_b%d.gkyl", gr_euler_output, i); - rename(intermediate0bi, bi); - remove(fine0bi); - remove(coarse0bi); - } - - for (int i = 9; i < 25; i++) { - char buf_old[64]; - char buf_new[64]; - char buf_del1[64]; - char buf_del2[64]; - - snprintf(buf_old, 64, "%s_coarse_0_b%d.gkyl", gr_euler_output, i); - snprintf(buf_new, 64, "%s_0_b%d.gkyl", gr_euler_output, i); - snprintf(buf_del1, 64, "%s_intermediate_0_b%d.gkyl", gr_euler_output, i); - snprintf(buf_del2, 64, "%s_fine_0_b%d.gkyl", gr_euler_output, i); - - rename(buf_old, buf_new); - remove(buf_del1); - remove(buf_del2); - } -#else char amr0[64]; snprintf(amr0, 64, "%s_0", gr_euler_output); - euler_write_sol_block(amr0, num_blocks, coarse_bdata); -#endif + euler_write_sol_block(amr0, num_blocks, mesh_bdata); double coarse_t_curr = 0.0; double intermediate_t_curr = 0.0; double fine_t_curr = 0.0; - double coarse_dt = euler_max_dt_block(num_blocks, coarse_bdata); + double coarse_dt = euler_max_dt_block(num_blocks, mesh_bdata); -#ifdef AMR_DEBUG - double intermediate_dt = euler_max_dt_block(num_blocks, intermediate_bdata); - double fine_dt = euler_max_dt_block(num_blocks, fine_bdata); -#else double intermediate_dt = (1.0 / ref_factor1) * coarse_dt; double fine_dt = (1.0 / (ref_factor1 * ref_factor2)) * coarse_dt; -#endif struct sim_stats stats = { }; @@ -1297,7 +604,7 @@ gr_euler2d_run_double(int argc, char **argv, struct gr_euler2d_double_init* init while ((coarse_t_curr < t_end) && (coarse_step <= num_steps)) { printf("Taking coarse (level 0) time-step %ld at t = %g; ", coarse_step, coarse_t_curr); - struct gkyl_update_status coarse_status = euler_update_block(coarse_job_pool, btopo, coarse_bdata, coarse_t_curr, coarse_dt, &stats); + struct gkyl_update_status coarse_status = euler_update_block(coarse_job_pool, btopo, mesh_bdata, coarse_t_curr, coarse_dt, &stats); printf(" dt = %g\n", coarse_status.dt_actual); if (!coarse_status.success) { @@ -1306,33 +613,6 @@ gr_euler2d_run_double(int argc, char **argv, struct gr_euler2d_double_init* init } for (long intermediate_step = 1; intermediate_step < ref_factor1 + 1; intermediate_step++) { -#ifdef AMR_DEBUG - printf(" Taking intermediate (level 1) time-step %ld at t = %g; ", intermediate_step, intermediate_t_curr); - struct gkyl_update_status intermediate_status = euler_update_block(intermediate_job_pool, btopo, intermediate_bdata, intermediate_t_curr, intermediate_dt, &stats); - printf(" dt = %g\n", intermediate_status.dt_actual); - - if (!intermediate_status.success) { - printf("** Update method failed! Aborting simulation ....\n"); - break; - } - - for (long fine_step = 1; fine_step < ref_factor2 + 1; fine_step++) { - printf(" Taking fine (level 2) time-step %ld at t = %g; ", fine_step, fine_t_curr); - struct gkyl_update_status fine_status = euler_update_block(fine_job_pool, btopo, fine_bdata, fine_t_curr, fine_dt, &stats); - printf( "dt = %g\n", fine_status.dt_actual); - - if (!fine_status.success) { - printf("** Update method failed! Aborting simulation ....\n"); - break; - } - - fine_t_curr += fine_status.dt_actual; - fine_dt = fine_status.dt_suggested; - } - - intermediate_t_curr += intermediate_status.dt_actual; - intermediate_dt = intermediate_status.dt_suggested; -#else printf(" Taking intermediate (level 1) time-step %ld at t = %g", intermediate_step, intermediate_t_curr); printf(" dt = %g\n", (1.0 / ref_factor1) * coarse_status.dt_actual); @@ -1346,73 +626,14 @@ gr_euler2d_run_double(int argc, char **argv, struct gr_euler2d_double_init* init intermediate_t_curr += (1.0 / ref_factor1) * coarse_status.dt_actual; intermediate_dt = (1.0 / ref_factor1) * coarse_status.dt_suggested; -#endif } for (int i = 1; i < num_frames; i++) { if (coarse_t_curr < (i * io_trigger) && (coarse_t_curr + coarse_status.dt_actual) > (i * io_trigger)) { -#ifdef AMR_DEBUG - char buf_coarse[64]; - char buf_intermediate[64]; - char buf_fine[64]; - - snprintf(buf_coarse, 64, "%s_coarse_%d", gr_euler_output, i); - snprintf(buf_intermediate, 64, "%s_intermediate_%d", gr_euler_output, i); - snprintf(buf_fine, 64, "%s_fine_%d", gr_euler_output, i); - - euler_write_sol_block(buf_coarse, num_blocks, coarse_bdata); - euler_write_sol_block(buf_intermediate, num_blocks, intermediate_bdata); - euler_write_sol_block(buf_fine, num_blocks, fine_bdata); - - char buf_fine_old[64]; - char buf_fine_new[64]; - char buf_intermediate_old[64]; - char buf_coarse_old[64]; - - snprintf(buf_fine_old, 64, "%s_fine_%d_b0.gkyl", gr_euler_output, i); - snprintf(buf_fine_new, 64, "%s_%d_b0.gkyl", gr_euler_output, i); - snprintf(buf_intermediate_old, 64, "%s_intermediate_%d_b0.gkyl", gr_euler_output, i); - snprintf(buf_coarse_old, 64, "%s_coarse_%d_b0.gkyl", gr_euler_output, i); - - rename(buf_fine_old, buf_fine_new); - remove(buf_intermediate_old); - remove(buf_coarse_old); - - for (int j = 1; j < 9; j++) { - char fine_bi[64]; - char intermediate_bi[64]; - char coarse_bi[64]; - char bi[64]; - snprintf(fine_bi, 64, "%s_fine_%d_b%d.gkyl", gr_euler_output, i, j); - snprintf(intermediate_bi, 64, "%s_intermediate_%d_b%d.gkyl", gr_euler_output, i, j); - snprintf(coarse_bi, 64, "%s_coarse_%d_b%d.gkyl", gr_euler_output, i, j); - snprintf(bi, 64, "%s_%d_b%d.gkyl", gr_euler_output, i, j); - rename(intermediate_bi, bi); - remove(fine_bi); - remove(coarse_bi); - } - - for (int j = 9; j < 25; j++) { - char buf_old[64]; - char buf_new[64]; - char buf_del1[64]; - char buf_del2[64]; - - snprintf(buf_old, 64, "%s_coarse_%d_b%d.gkyl", gr_euler_output, i, j); - snprintf(buf_new, 64, "%s_%d_b%d.gkyl", gr_euler_output, i, j); - snprintf(buf_del1, 64, "%s_intermediate_%d_b%d.gkyl", gr_euler_output, i, j); - snprintf(buf_del2, 64, "%s_fine_%d_b%d.gkyl", gr_euler_output, i, j); - - rename(buf_old, buf_new); - remove(buf_del1); - remove(buf_del2); - } -#else char buf[64]; snprintf(buf, 64, "%s_%d", gr_euler_output, i); - euler_write_sol_block(buf, num_blocks, coarse_bdata); -#endif + euler_write_sol_block(buf, num_blocks, mesh_bdata); } } @@ -1443,120 +664,31 @@ gr_euler2d_run_double(int argc, char **argv, struct gr_euler2d_double_init* init double tm_total_sec = gkyl_time_diff_now_sec(tm_start); - // TODO: Make file output work correctly in the AMR_DEBUG case. -#ifdef AMR_DEBUG - char buf_coarse[64]; - char buf_intermediate[64]; - char buf_fine[64]; - - snprintf(buf_coarse, 64, "%s_coarse_%d", gr_euler_output, num_frames); - snprintf(buf_intermediate, 64, "%s_intermediate_%d", gr_euler_output, num_frames); - snprintf(buf_fine, 64, "%s_fine_%d", gr_euler_output, num_frames); - - euler_write_sol_block(buf_coarse, num_blocks, coarse_bdata); - euler_write_sol_block(buf_intermediate, num_blocks, intermediate_bdata); - euler_write_sol_block(buf_fine, num_blocks, fine_bdata); - - char buf_fine_old[64]; - char buf_fine_new[64]; - char buf_intermediate_old[64]; - char buf_coarse_old[64]; - - snprintf(buf_fine_old, 64, "%s_fine_%d_b0.gkyl", gr_euler_output, num_frames); - snprintf(buf_fine_new, 64, "%s_%d_b0.gkyl", gr_euler_output, num_frames); - snprintf(buf_intermediate_old, 64, "%s_intermediate_%d_b0.gkyl", gr_euler_output, num_frames); - snprintf(buf_coarse_old, 64, "%s_coarse_%d_b0.gkyl", gr_euler_output,num_frames); - - rename(buf_fine_old, buf_fine_new); - remove(buf_intermediate_old); - remove(buf_coarse_old); - - for (int i = 1; i < 9; i++) { - char fine_bi[64]; - char intermediate_bi[64]; - char coarse_bi[64]; - char bi[64]; - snprintf(fine_bi, 64, "%s_fine_%d_b%d.gkyl", gr_euler_output, num_frames, i); - snprintf(intermediate_bi, 64, "%s_intermediate_%d_b%d.gkyl", gr_euler_output, num_frames, i); - snprintf(coarse_bi, 64, "%s_coarse_%d_b%d.gkyl", gr_euler_output, num_frames, i); - snprintf(bi, 64, "%s_%d_b%d.gkyl", gr_euler_output, num_frames, i); - rename(intermediate_bi, bi); - remove(fine_bi); - remove(coarse_bi); - } - - for (int i = 9; i < 25; i++) { - char buf_old[64]; - char buf_new[64]; - char buf_del1[64]; - char buf_del2[64]; - - snprintf(buf_old, 64, "%s_coarse_%d_b%d.gkyl", gr_euler_output, num_frames, i); - snprintf(buf_new, 64, "%s_%d_b%d.gkyl", gr_euler_output, num_frames, i); - snprintf(buf_del1, 64, "%s_intermediate_%d_b%d.gkyl", gr_euler_output, num_frames, i); - snprintf(buf_del2, 64, "%s_fine_%d_b%d.gkyl", gr_euler_output, num_frames, i); - - rename(buf_old, buf_new); - remove(buf_del1); - remove(buf_del2); - } -#else char buf[64]; snprintf(buf, 64, "%s_%d", gr_euler_output, num_frames); - euler_write_sol_block(buf, num_blocks, coarse_bdata); -#endif + euler_write_sol_block(buf, num_blocks, mesh_bdata); printf("Total run-time: %g. Failed steps: %d\n", tm_total_sec, stats.nfail); for (int i = 0; i < num_blocks; i++) { - gkyl_fv_proj_release(coarse_bdata[i].fv_proj); - gkyl_wv_eqn_release(coarse_bdata[i].euler); - euler_block_bc_updaters_release(&coarse_bdata[i]); - gkyl_wave_geom_release(coarse_bdata[i].geom); - -#ifdef AMR_DEBUG - gkyl_fv_proj_release(intermediate_bdata[i].fv_proj); - gkyl_wv_eqn_release(intermediate_bdata[i].euler); - euler_block_bc_updaters_release(&intermediate_bdata[i]); - gkyl_wave_geom_release(intermediate_bdata[i].geom); - - gkyl_fv_proj_release(fine_bdata[i].fv_proj); - gkyl_wv_eqn_release(fine_bdata[i].euler); - euler_block_bc_updaters_release(&fine_bdata[i]); - gkyl_wave_geom_release(fine_bdata[i].geom); -#endif + gkyl_fv_proj_release(mesh_bdata[i].fv_proj); + gkyl_wv_eqn_release(mesh_bdata[i].euler); + euler_block_bc_updaters_release(&mesh_bdata[i]); + gkyl_wave_geom_release(mesh_bdata[i].geom); for (int d = 0; d < ndim; d++) { - gkyl_wave_prop_release(coarse_bdata[i].slvr[d]); - -#ifdef AMR_DEBUG - gkyl_wave_prop_release(intermediate_bdata[i].slvr[d]); - gkyl_wave_prop_release(fine_bdata[i].slvr[d]); -#endif + gkyl_wave_prop_release(mesh_bdata[i].slvr[d]); } - gkyl_array_release(coarse_bdata[i].fdup); -#ifdef AMR_DEBUG - gkyl_array_release(intermediate_bdata[i].fdup); - gkyl_array_release(fine_bdata[i].fdup); -#endif + gkyl_array_release(mesh_bdata[i].fdup); for (int d = 0; d < ndim; d++) { - gkyl_array_release(coarse_bdata[i].f[d]); - -#ifdef AMR_DEBUG - gkyl_array_release(intermediate_bdata[i].f[d]); - gkyl_array_release(fine_bdata[i].f[d]); -#endif + gkyl_array_release(mesh_bdata[i].f[d]); } } gkyl_block_topo_release(btopo); gkyl_gr_spacetime_release(spacetime); gkyl_job_pool_release(coarse_job_pool); -#ifdef AMR_DEBUG - gkyl_job_pool_release(intermediate_job_pool); - gkyl_job_pool_release(fine_job_pool); -#endif } \ No newline at end of file diff --git a/amr/amr_patch.c b/amr/amr_patch.c index 4f2bd8662..f57277bd3 100644 --- a/amr/amr_patch.c +++ b/amr/amr_patch.c @@ -105,39 +105,6 @@ euler_sync_patches(const struct gkyl_block_topo* ptopo, const struct euler_patch for (int i = 0; i < num_patches; i++) { const struct gkyl_target_edge *te = ptopo->conn[i].connections[0]; -#ifdef AMR_DEBUG - if (te[0].edge != GKYL_PHYSICAL) { - struct gkyl_array *bc_buffer = pdata[i].bc_buffer; - - gkyl_array_copy_to_buffer(bc_buffer->data, fld[i], &(pdata[i].skin_ghost.lower_skin[0])); - - int tbid = te[0].bid; - int tdir = te[0].dir; - - if (te[0].edge == GKYL_LOWER_POSITIVE) { - gkyl_array_copy_from_buffer(fld[tbid], bc_buffer->data, &(pdata[tbid].skin_ghost.lower_ghost[tdir])); - } - else if (te[0].edge == GKYL_UPPER_POSITIVE) { - gkyl_array_copy_from_buffer(fld[tbid], bc_buffer->data, &(pdata[tbid].skin_ghost.upper_ghost[tdir])); - } - } - - if (te[1].edge != GKYL_PHYSICAL) { - struct gkyl_array *bc_buffer = pdata[i].bc_buffer; - - gkyl_array_copy_to_buffer(bc_buffer->data, fld[i], &(pdata[i].skin_ghost.upper_skin[0])); - - int tbid = te[1].bid; - int tdir = te[1].dir; - - if (te[1].edge == GKYL_LOWER_POSITIVE) { - gkyl_array_copy_from_buffer(fld[tbid], bc_buffer->data, &(pdata[tbid].skin_ghost.lower_ghost[tdir])); - } - else if (te[1].edge == GKYL_UPPER_POSITIVE) { - gkyl_array_copy_from_buffer(fld[tbid], bc_buffer->data, &(pdata[tbid].skin_ghost.upper_ghost[tdir])); - } - } -#else if (te[0].edge != GKYL_PHYSICAL) { struct gkyl_array *bc_buffer = pdata[i].bc_buffer; @@ -345,7 +312,6 @@ euler_sync_patches(const struct gkyl_block_topo* ptopo, const struct euler_patch } } } -#endif } } diff --git a/amr/gkyl_amr_block_priv.h b/amr/gkyl_amr_block_priv.h index 4bf746870..56ba34bbc 100644 --- a/amr/gkyl_amr_block_priv.h +++ b/amr/gkyl_amr_block_priv.h @@ -32,7 +32,6 @@ #include -//#define AMR_DEBUG #define AMR_USETHREADS // Definitions of private structs and APIs attached to these objects, for use in the block AMR subsystem. From e8a47818236750b43af2571848d6fd74ff7e5b7a Mon Sep 17 00:00:00 2001 From: JonathanGorard Date: Wed, 26 Jun 2024 15:17:06 -0400 Subject: [PATCH 13/32] Extended cleanup of block-structured and patch-structured AMR infrastructure to the coupled 5-moment and 10-moment cases. All tests pass, but this requires some slightly closer inspection to guarantee that there are truly no regressions. --- amr/amr_block_coupled.c | 50 - amr/amr_core_five_moment.c | 2162 +++++------------------------------- amr/amr_core_ten_moment.c | 2081 +++++----------------------------- amr/amr_patch_coupled.c | 50 - 4 files changed, 545 insertions(+), 3798 deletions(-) diff --git a/amr/amr_block_coupled.c b/amr/amr_block_coupled.c index 598e0a4d1..84b3b7124 100644 --- a/amr/amr_block_coupled.c +++ b/amr/amr_block_coupled.c @@ -428,55 +428,6 @@ five_moment_sync_blocks(const struct gkyl_block_topo* btopo, const struct five_m for (int d = 0; d < ndim; d++) { const struct gkyl_target_edge *te = btopo->conn[i].connections[d]; -#ifdef AMR_DEBUG - if (te[0].edge != GKYL_PHYSICAL) { - struct gkyl_array *bc_buffer_elc = bdata[i].bc_buffer_elc; - struct gkyl_array *bc_buffer_ion = bdata[i].bc_buffer_ion; - struct gkyl_array *bc_buffer_maxwell = bdata[i].bc_buffer_maxwell; - - gkyl_array_copy_to_buffer(bc_buffer_elc->data, fld_elc[i], &(bdata[i].skin_ghost.lower_skin[d])); - gkyl_array_copy_to_buffer(bc_buffer_ion->data, fld_ion[i], &(bdata[i].skin_ghost.lower_skin[d])); - gkyl_array_copy_to_buffer(bc_buffer_maxwell->data, fld_maxwell[i], &(bdata[i].skin_ghost.lower_skin[d])); - - int tbid = te[0].bid; - int tdir = te[0].dir; - - if (te[0].edge == GKYL_LOWER_POSITIVE) { - gkyl_array_copy_from_buffer(fld_elc[tbid], bc_buffer_elc->data, &(bdata[tbid].skin_ghost.lower_ghost[tdir])); - gkyl_array_copy_from_buffer(fld_ion[tbid], bc_buffer_ion->data, &(bdata[tbid].skin_ghost.lower_ghost[tdir])); - gkyl_array_copy_from_buffer(fld_maxwell[tbid], bc_buffer_maxwell->data, &(bdata[tbid].skin_ghost.lower_ghost[tdir])); - } - else if (te[0].edge == GKYL_UPPER_POSITIVE) { - gkyl_array_copy_from_buffer(fld_elc[tbid], bc_buffer_elc->data, &(bdata[tbid].skin_ghost.upper_ghost[tdir])); - gkyl_array_copy_from_buffer(fld_ion[tbid], bc_buffer_ion->data, &(bdata[tbid].skin_ghost.upper_ghost[tdir])); - gkyl_array_copy_from_buffer(fld_maxwell[tbid], bc_buffer_maxwell->data, &(bdata[tbid].skin_ghost.upper_ghost[tdir])); - } - } - - if (te[1].edge != GKYL_PHYSICAL) { - struct gkyl_array *bc_buffer_elc = bdata[i].bc_buffer_elc; - struct gkyl_array *bc_buffer_ion = bdata[i].bc_buffer_ion; - struct gkyl_array *bc_buffer_maxwell = bdata[i].bc_buffer_maxwell; - - gkyl_array_copy_to_buffer(bc_buffer_elc->data, fld_elc[i], &(bdata[i].skin_ghost.upper_skin[d])); - gkyl_array_copy_to_buffer(bc_buffer_ion->data, fld_ion[i], &(bdata[i].skin_ghost.upper_skin[d])); - gkyl_array_copy_to_buffer(bc_buffer_maxwell->data, fld_maxwell[i], &(bdata[i].skin_ghost.upper_skin[d])); - - int tbid = te[1].bid; - int tdir = te[1].dir; - - if (te[1].edge == GKYL_LOWER_POSITIVE) { - gkyl_array_copy_from_buffer(fld_elc[tbid], bc_buffer_elc->data, &(bdata[tbid].skin_ghost.lower_ghost[tdir])); - gkyl_array_copy_from_buffer(fld_ion[tbid], bc_buffer_ion->data, &(bdata[tbid].skin_ghost.lower_ghost[tdir])); - gkyl_array_copy_from_buffer(fld_maxwell[tbid], bc_buffer_maxwell->data, &(bdata[tbid].skin_ghost.lower_ghost[tdir])); - } - else if (te[1].edge == GKYL_UPPER_POSITIVE) { - gkyl_array_copy_from_buffer(fld_elc[tbid], bc_buffer_elc->data, &(bdata[tbid].skin_ghost.upper_ghost[tdir])); - gkyl_array_copy_from_buffer(fld_ion[tbid], bc_buffer_ion->data, &(bdata[tbid].skin_ghost.upper_ghost[tdir])); - gkyl_array_copy_from_buffer(fld_maxwell[tbid], bc_buffer_maxwell->data, &(bdata[tbid].skin_ghost.upper_ghost[tdir])); - } - } -#else if (te[0].edge != GKYL_PHYSICAL) { struct gkyl_array *bc_buffer_elc = bdata[i].bc_buffer_elc; struct gkyl_array *bc_buffer_ion = bdata[i].bc_buffer_ion; @@ -772,7 +723,6 @@ five_moment_sync_blocks(const struct gkyl_block_topo* btopo, const struct five_m } } } -#endif } } } diff --git a/amr/amr_core_five_moment.c b/amr/amr_core_five_moment.c index 44c7c9fce..e953d2cfa 100644 --- a/amr/amr_core_five_moment.c +++ b/amr/amr_core_five_moment.c @@ -56,47 +56,24 @@ five_moment_1d_run_single(int argc, char **argv, struct five_moment_1d_single_in int num_patches = 3; int Nx = base_Nx; - struct five_moment_patch_data coarse_pdata[num_patches]; + struct five_moment_patch_data mesh_pdata[num_patches]; struct gkyl_job_pool *coarse_job_pool = gkyl_thread_pool_new(app_args.num_threads); -#ifdef AMR_DEBUG - gkyl_rect_grid_init(&coarse_pdata[0].grid, 1, (double []) { refined_x1 }, (double []) { refined_x2 }, (int []) { Nx } ); -#else - gkyl_rect_grid_init(&coarse_pdata[0].grid, 1, (double []) { refined_x1 }, (double []) { refined_x2 }, (int []) { Nx * ref_factor } ); -#endif + gkyl_rect_grid_init(&mesh_pdata[0].grid, 1, (double []) { refined_x1 }, (double []) { refined_x2 }, (int []) { Nx * ref_factor } ); - gkyl_rect_grid_init(&coarse_pdata[1].grid, 1, (double []) { coarse_x1 }, (double []) { refined_x1 }, (int []) { Nx } ); - gkyl_rect_grid_init(&coarse_pdata[2].grid, 1, (double []) { refined_x2 }, (double []) { coarse_x2 }, (int []) { Nx } ); + gkyl_rect_grid_init(&mesh_pdata[1].grid, 1, (double []) { coarse_x1 }, (double []) { refined_x1 }, (int []) { Nx } ); + gkyl_rect_grid_init(&mesh_pdata[2].grid, 1, (double []) { refined_x2 }, (double []) { coarse_x2 }, (int []) { Nx } ); -#ifdef AMR_DEBUG - struct five_moment_patch_data fine_pdata[num_patches]; - struct gkyl_job_pool *fine_job_pool = gkyl_thread_pool_new(app_args.num_threads); - - gkyl_rect_grid_init(&fine_pdata[0].grid, 1, (double []) { refined_x1 }, (double []) { refined_x2 }, (int []) { Nx * ref_factor } ); - gkyl_rect_grid_init(&fine_pdata[1].grid, 1, (double []) { coarse_x1 }, (double []) { refined_x1 }, (int []) { Nx * ref_factor } ); - gkyl_rect_grid_init(&fine_pdata[2].grid, 1, (double []) { refined_x2 }, (double []) { coarse_x2 }, (int []) { Nx * ref_factor } ); -#endif for (int i = 0; i < num_patches; i++) { - coarse_pdata[i].fv_proj_elc = gkyl_fv_proj_new(&coarse_pdata[i].grid, 1, 5, eval_elc, 0); - coarse_pdata[i].fv_proj_ion = gkyl_fv_proj_new(&coarse_pdata[i].grid, 1, 5, eval_ion, 0); - coarse_pdata[i].fv_proj_maxwell = gkyl_fv_proj_new(&coarse_pdata[i].grid, 1, 8, eval_field, 0); - -#ifdef AMR_DEBUG - fine_pdata[i].fv_proj_elc = gkyl_fv_proj_new(&fine_pdata[i].grid, 1, 5, eval_elc, 0); - fine_pdata[i].fv_proj_ion = gkyl_fv_proj_new(&fine_pdata[i].grid, 1, 5, eval_ion, 0); - fine_pdata[i].fv_proj_maxwell = gkyl_fv_proj_new(&fine_pdata[i].grid, 1, 8, eval_field, 0); -#endif + mesh_pdata[i].fv_proj_elc = gkyl_fv_proj_new(&mesh_pdata[i].grid, 1, 5, eval_elc, 0); + mesh_pdata[i].fv_proj_ion = gkyl_fv_proj_new(&mesh_pdata[i].grid, 1, 5, eval_ion, 0); + mesh_pdata[i].fv_proj_maxwell = gkyl_fv_proj_new(&mesh_pdata[i].grid, 1, 8, eval_field, 0); } for (int i = 0; i < num_patches; i++) { - gkyl_create_grid_ranges(&coarse_pdata[i].grid, (int []) { 2 }, &coarse_pdata[i].ext_range, &coarse_pdata[i].range); - coarse_pdata[i].geom = gkyl_wave_geom_new(&coarse_pdata[i].grid, &coarse_pdata[i].ext_range, 0, 0, false); - -#ifdef AMR_DEBUG - gkyl_create_grid_ranges(&fine_pdata[i].grid, (int []) { 2 }, &fine_pdata[i].ext_range, &fine_pdata[i].range); - fine_pdata[i].geom = gkyl_wave_geom_new(&fine_pdata[i].grid, &fine_pdata[i].ext_range, 0, 0, false); -#endif + gkyl_create_grid_ranges(&mesh_pdata[i].grid, (int []) { 2 }, &mesh_pdata[i].ext_range, &mesh_pdata[i].range); + mesh_pdata[i].geom = gkyl_wave_geom_new(&mesh_pdata[i].grid, &mesh_pdata[i].ext_range, 0, 0, false); } for (int i = 0; i < num_patches; i++) { @@ -106,285 +83,115 @@ five_moment_1d_run_single(int argc, char **argv, struct five_moment_1d_single_in .rp_type = WV_EULER_RP_HLL, .use_gpu = app_args.use_gpu, }; - coarse_pdata[i].euler_elc = gkyl_wv_euler_inew(&inp); - coarse_pdata[i].euler_ion = gkyl_wv_euler_inew(&inp); + mesh_pdata[i].euler_elc = gkyl_wv_euler_inew(&inp); + mesh_pdata[i].euler_ion = gkyl_wv_euler_inew(&inp); } else { - coarse_pdata[i].euler_elc = gkyl_wv_euler_new(gas_gamma, app_args.use_gpu); - coarse_pdata[i].euler_ion = gkyl_wv_euler_new(gas_gamma, app_args.use_gpu); + mesh_pdata[i].euler_elc = gkyl_wv_euler_new(gas_gamma, app_args.use_gpu); + mesh_pdata[i].euler_ion = gkyl_wv_euler_new(gas_gamma, app_args.use_gpu); } - coarse_pdata[i].maxwell = gkyl_wv_maxwell_new(light_speed, e_fact, b_fact); + mesh_pdata[i].maxwell = gkyl_wv_maxwell_new(light_speed, e_fact, b_fact); - coarse_pdata[i].slvr_elc[0] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &coarse_pdata[i].grid, - .equation = coarse_pdata[i].euler_elc, + mesh_pdata[i].slvr_elc[0] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { + .grid = &mesh_pdata[i].grid, + .equation = mesh_pdata[i].euler_elc, .limiter = GKYL_MONOTONIZED_CENTERED, .num_up_dirs = 1, .update_dirs = { 0 }, .cfl = cfl_frac, - .geom = coarse_pdata[i].geom, + .geom = mesh_pdata[i].geom, } ); - coarse_pdata[i].slvr_ion[0] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &coarse_pdata[i].grid, - .equation = coarse_pdata[i].euler_ion, + mesh_pdata[i].slvr_ion[0] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { + .grid = &mesh_pdata[i].grid, + .equation = mesh_pdata[i].euler_ion, .limiter = GKYL_MONOTONIZED_CENTERED, .num_up_dirs = 1, .update_dirs = { 0 }, .cfl = cfl_frac, - .geom = coarse_pdata[i].geom, + .geom = mesh_pdata[i].geom, } ); - coarse_pdata[i].slvr_maxwell[0] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &coarse_pdata[i].grid, - .equation = coarse_pdata[i].maxwell, + mesh_pdata[i].slvr_maxwell[0] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { + .grid = &mesh_pdata[i].grid, + .equation = mesh_pdata[i].maxwell, .limiter = GKYL_MONOTONIZED_CENTERED, .num_up_dirs = 1, .update_dirs = { 0 }, .cfl = cfl_frac, - .geom = coarse_pdata[i].geom, + .geom = mesh_pdata[i].geom, } ); struct gkyl_moment_em_coupling_inp coarse_src_inp = { - .grid = &coarse_pdata[i].grid, + .grid = &mesh_pdata[i].grid, .nfluids = 2, .epsilon0 = epsilon0, }; coarse_src_inp.param[0] = (struct gkyl_moment_em_coupling_data) { - .type = coarse_pdata[i].euler_elc->type, + .type = mesh_pdata[i].euler_elc->type, .charge = charge_elc, .mass = mass_elc, .k0 = k0_elc, }; coarse_src_inp.param[1] = (struct gkyl_moment_em_coupling_data) { - .type = coarse_pdata[i].euler_ion->type, - .charge = charge_ion, - .mass = mass_ion, - .k0 = k0_ion, - }; - - coarse_pdata[i].src_slvr = gkyl_moment_em_coupling_new(coarse_src_inp); - -#ifdef AMR_DEBUG - if (low_order_flux) { - struct gkyl_wv_euler_inp inp = { - .gas_gamma = gas_gamma, - .rp_type = WV_EULER_RP_HLL, - .use_gpu = app_args.use_gpu, - }; - fine_pdata[i].euler_elc = gkyl_wv_euler_inew(&inp); - fine_pdata[i].euler_ion = gkyl_wv_euler_inew(&inp); - } - else { - fine_pdata[i].euler_elc = gkyl_wv_euler_new(gas_gamma, app_args.use_gpu); - fine_pdata[i].euler_ion = gkyl_wv_euler_new(gas_gamma, app_args.use_gpu); - } - fine_pdata[i].maxwell = gkyl_wv_maxwell_new(light_speed, e_fact, b_fact); - - fine_pdata[i].slvr_elc[0] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &fine_pdata[i].grid, - .equation = fine_pdata[i].euler_elc, - .limiter = GKYL_MONOTONIZED_CENTERED, - .num_up_dirs = 1, - .update_dirs = { 0 }, - .cfl = cfl_frac, - .geom = fine_pdata[i].geom, - } - ); - fine_pdata[i].slvr_ion[0] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &fine_pdata[i].grid, - .equation = fine_pdata[i].euler_ion, - .limiter = GKYL_MONOTONIZED_CENTERED, - .num_up_dirs = 1, - .update_dirs = { 0 }, - .cfl = cfl_frac, - .geom = fine_pdata[i].geom, - } - ); - fine_pdata[i].slvr_maxwell[0] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &fine_pdata[i].grid, - .equation = fine_pdata[i].maxwell, - .limiter = GKYL_MONOTONIZED_CENTERED, - .num_up_dirs = 1, - .update_dirs = { 0 }, - .cfl = cfl_frac, - .geom = fine_pdata[i].geom, - } - ); - - struct gkyl_moment_em_coupling_inp fine_src_inp = { - .grid = &fine_pdata[i].grid, - .nfluids = 2, - .epsilon0 = epsilon0, - }; - - fine_src_inp.param[0] = (struct gkyl_moment_em_coupling_data) { - .type = fine_pdata[i].euler_elc->type, - .charge = charge_elc, - .mass = mass_elc, - .k0 = k0_elc, - }; - fine_src_inp.param[1] = (struct gkyl_moment_em_coupling_data) { - .type = fine_pdata[i].euler_ion->type, + .type = mesh_pdata[i].euler_ion->type, .charge = charge_ion, .mass = mass_ion, .k0 = k0_ion, }; - fine_pdata[i].src_slvr = gkyl_moment_em_coupling_new(fine_src_inp); -#endif + mesh_pdata[i].src_slvr = gkyl_moment_em_coupling_new(coarse_src_inp); } struct gkyl_block_topo *ptopo = create_patch_topo(); for (int i = 0; i < num_patches; i++) { - five_moment_patch_bc_updaters_init(&coarse_pdata[i], &ptopo->conn[i]); - -#ifdef AMR_DEBUG - five_moment_patch_bc_updaters_init(&fine_pdata[i], &ptopo->conn[i]); -#endif + five_moment_patch_bc_updaters_init(&mesh_pdata[i], &ptopo->conn[i]); } for (int i = 0; i < num_patches; i++) { - coarse_pdata[i].fdup_elc = gkyl_array_new(GKYL_DOUBLE, 5, coarse_pdata[i].ext_range.volume); - coarse_pdata[i].fdup_ion = gkyl_array_new(GKYL_DOUBLE, 5, coarse_pdata[i].ext_range.volume); - coarse_pdata[i].fdup_maxwell = gkyl_array_new(GKYL_DOUBLE, 8, coarse_pdata[i].ext_range.volume); - - for (int d = 0; d < ndim + 1; d++) { - coarse_pdata[i].f_elc[d] = gkyl_array_new(GKYL_DOUBLE, 5, coarse_pdata[i].ext_range.volume); - coarse_pdata[i].f_ion[d] = gkyl_array_new(GKYL_DOUBLE, 5, coarse_pdata[i].ext_range.volume); - coarse_pdata[i].f_maxwell[d] = gkyl_array_new(GKYL_DOUBLE, 8, coarse_pdata[i].ext_range.volume); - } - - coarse_pdata[i].app_accel_elc = gkyl_array_new(GKYL_DOUBLE, 3, coarse_pdata[i].ext_range.volume); - coarse_pdata[i].app_accel_ion = gkyl_array_new(GKYL_DOUBLE, 3, coarse_pdata[i].ext_range.volume); - coarse_pdata[i].rhs_source_elc = gkyl_array_new(GKYL_DOUBLE, 5, coarse_pdata[i].ext_range.volume); - coarse_pdata[i].rhs_source_ion = gkyl_array_new(GKYL_DOUBLE, 5, coarse_pdata[i].ext_range.volume); - coarse_pdata[i].ext_em = gkyl_array_new(GKYL_DOUBLE, 6, coarse_pdata[i].ext_range.volume); - coarse_pdata[i].app_current = gkyl_array_new(GKYL_DOUBLE, 3, coarse_pdata[i].ext_range.volume); - coarse_pdata[i].nT_source_elc = gkyl_array_new(GKYL_DOUBLE, 2, coarse_pdata[i].ext_range.volume); - coarse_pdata[i].nT_source_ion = gkyl_array_new(GKYL_DOUBLE, 2, coarse_pdata[i].ext_range.volume); - -#ifdef AMR_DEBUG - fine_pdata[i].fdup_elc = gkyl_array_new(GKYL_DOUBLE, 5, fine_pdata[i].ext_range.volume); - fine_pdata[i].fdup_ion = gkyl_array_new(GKYL_DOUBLE, 5, fine_pdata[i].ext_range.volume); - fine_pdata[i].fdup_maxwell = gkyl_array_new(GKYL_DOUBLE, 8, fine_pdata[i].ext_range.volume); + mesh_pdata[i].fdup_elc = gkyl_array_new(GKYL_DOUBLE, 5, mesh_pdata[i].ext_range.volume); + mesh_pdata[i].fdup_ion = gkyl_array_new(GKYL_DOUBLE, 5, mesh_pdata[i].ext_range.volume); + mesh_pdata[i].fdup_maxwell = gkyl_array_new(GKYL_DOUBLE, 8, mesh_pdata[i].ext_range.volume); for (int d = 0; d < ndim + 1; d++) { - fine_pdata[i].f_elc[d] = gkyl_array_new(GKYL_DOUBLE, 5, fine_pdata[i].ext_range.volume); - fine_pdata[i].f_ion[d] = gkyl_array_new(GKYL_DOUBLE, 5, fine_pdata[i].ext_range.volume); - fine_pdata[i].f_maxwell[d] = gkyl_array_new(GKYL_DOUBLE, 8, fine_pdata[i].ext_range.volume); + mesh_pdata[i].f_elc[d] = gkyl_array_new(GKYL_DOUBLE, 5, mesh_pdata[i].ext_range.volume); + mesh_pdata[i].f_ion[d] = gkyl_array_new(GKYL_DOUBLE, 5, mesh_pdata[i].ext_range.volume); + mesh_pdata[i].f_maxwell[d] = gkyl_array_new(GKYL_DOUBLE, 8, mesh_pdata[i].ext_range.volume); } - fine_pdata[i].app_accel_elc = gkyl_array_new(GKYL_DOUBLE, 3, fine_pdata[i].ext_range.volume); - fine_pdata[i].app_accel_ion = gkyl_array_new(GKYL_DOUBLE, 3, fine_pdata[i].ext_range.volume); - fine_pdata[i].rhs_source_elc = gkyl_array_new(GKYL_DOUBLE, 5, fine_pdata[i].ext_range.volume); - fine_pdata[i].rhs_source_ion = gkyl_array_new(GKYL_DOUBLE, 5, fine_pdata[i].ext_range.volume); - fine_pdata[i].ext_em = gkyl_array_new(GKYL_DOUBLE, 6, fine_pdata[i].ext_range.volume); - fine_pdata[i].app_current = gkyl_array_new(GKYL_DOUBLE, 3, fine_pdata[i].ext_range.volume); - fine_pdata[i].nT_source_elc = gkyl_array_new(GKYL_DOUBLE, 2, fine_pdata[i].ext_range.volume); - fine_pdata[i].nT_source_ion = gkyl_array_new(GKYL_DOUBLE, 2, fine_pdata[i].ext_range.volume); -#endif + mesh_pdata[i].app_accel_elc = gkyl_array_new(GKYL_DOUBLE, 3, mesh_pdata[i].ext_range.volume); + mesh_pdata[i].app_accel_ion = gkyl_array_new(GKYL_DOUBLE, 3, mesh_pdata[i].ext_range.volume); + mesh_pdata[i].rhs_source_elc = gkyl_array_new(GKYL_DOUBLE, 5, mesh_pdata[i].ext_range.volume); + mesh_pdata[i].rhs_source_ion = gkyl_array_new(GKYL_DOUBLE, 5, mesh_pdata[i].ext_range.volume); + mesh_pdata[i].ext_em = gkyl_array_new(GKYL_DOUBLE, 6, mesh_pdata[i].ext_range.volume); + mesh_pdata[i].app_current = gkyl_array_new(GKYL_DOUBLE, 3, mesh_pdata[i].ext_range.volume); + mesh_pdata[i].nT_source_elc = gkyl_array_new(GKYL_DOUBLE, 2, mesh_pdata[i].ext_range.volume); + mesh_pdata[i].nT_source_ion = gkyl_array_new(GKYL_DOUBLE, 2, mesh_pdata[i].ext_range.volume); } #ifdef AMR_USETHREADS for (int i = 0; i < num_patches; i++) { - gkyl_job_pool_add_work(coarse_job_pool, five_moment_init_job_func_patch, &coarse_pdata[i]); - -#ifdef AMR_DEBUG - gkyl_job_pool_add_work(fine_job_pool, five_moment_init_job_func_patch, &fine_pdata[i]); -#endif + gkyl_job_pool_add_work(coarse_job_pool, five_moment_init_job_func_patch, &mesh_pdata[i]); } gkyl_job_pool_wait(coarse_job_pool); - -#ifdef AMR_DEBUG - gkyl_job_pool_wait(fine_job_pool); -#endif #else for (int i = 0; i < num_patches; i++) { - five_moment_init_job_func_patch(&coarse_pdata[i]); - -#ifdef AMR_DEBUG - five_moment_init_job_func_patch(&fine_pdata[i]); -#endif + five_moment_init_job_func_patch(&mesh_pdata[i]); } #endif -#ifdef AMR_DEBUG - char coarse0[64]; - snprintf(coarse0, 64, "%s_coarse_0", five_moment_output); - five_moment_write_sol_patch(coarse0, num_patches, coarse_pdata); - - char fine0[64]; - snprintf(fine0, 64, "%s_fine_0", five_moment_output); - five_moment_write_sol_patch(fine0, num_patches, fine_pdata); - - char fine0_elc_p0[64], fine0_ion_p0[64], fine0_field_p0[64]; - char coarse0_elc_p0[64], coarse0_ion_p0[64], coarse0_field_p0[64]; - char p0_elc[64], p0_ion[64], p0_field[64]; - - snprintf(fine0_elc_p0, 64, "%s_fine_0_elc_p0.gkyl", five_moment_output); - snprintf(fine0_ion_p0, 64, "%s_fine_0_ion_p0.gkyl", five_moment_output); - snprintf(fine0_field_p0, 64, "%s_fine_0_field_p0.gkyl", five_moment_output); - - snprintf(coarse0_elc_p0, 64, "%s_coarse_0_elc_p0.gkyl", five_moment_output); - snprintf(coarse0_ion_p0, 64, "%s_coarse_0_ion_p0.gkyl", five_moment_output); - snprintf(coarse0_field_p0, 64, "%s_coarse_0_field_p0.gkyl", five_moment_output); - - snprintf(p0_elc, 64, "%s_0_elc_p0.gkyl", five_moment_output); - snprintf(p0_ion, 64, "%s_0_ion_p0.gkyl", five_moment_output); - snprintf(p0_field, 64, "%s_0_field_p0.gkyl", five_moment_output); - - rename(fine0_elc_p0, p0_elc); - rename(fine0_ion_p0, p0_ion); - rename(fine0_field_p0, p0_field); - - remove(coarse0_elc_p0); - remove(coarse0_ion_p0); - remove(coarse0_field_p0); - - for (int i = 1; i < 3; i++) { - char buf_old_elc[64], buf_old_ion[64], buf_old_field[64]; - char buf_new_elc[64], buf_new_ion[64], buf_new_field[64]; - char buf_del_elc[64], buf_del_ion[64], buf_del_field[64]; - - snprintf(buf_old_elc, 64, "%s_coarse_0_elc_p%d.gkyl", five_moment_output, i); - snprintf(buf_old_ion, 64, "%s_coarse_0_ion_p%d.gkyl", five_moment_output, i); - snprintf(buf_old_field, 64, "%s_coarse_0_field_p%d.gkyl", five_moment_output, i); - - snprintf(buf_new_elc, 64, "%s_0_elc_p%d.gkyl", five_moment_output, i); - snprintf(buf_new_ion, 64, "%s_0_ion_p%d.gkyl", five_moment_output, i); - snprintf(buf_new_field, 64, "%s_0_field_p%d.gkyl", five_moment_output, i); - - snprintf(buf_del_elc, 64, "%s_fine_0_elc_p%d.gkyl", five_moment_output, i); - snprintf(buf_del_ion, 64, "%s_fine_0_ion_p%d.gkyl", five_moment_output, i); - snprintf(buf_del_field, 64, "%s_fine_0_field_p%d.gkyl", five_moment_output, i); - - rename(buf_old_elc, buf_new_elc); - rename(buf_old_ion, buf_new_ion); - rename(buf_old_field, buf_new_field); - - remove(buf_del_elc); - remove(buf_del_ion); - remove(buf_del_field); - } -#else char amr0[64]; snprintf(amr0, 64, "%s_0", five_moment_output); - five_moment_write_sol_patch(amr0, num_patches, coarse_pdata); -#endif + five_moment_write_sol_patch(amr0, num_patches, mesh_pdata); double coarse_t_curr = 0.0; double fine_t_curr = 0.0; - double coarse_dt = five_moment_max_dt_patch(num_patches, coarse_pdata); + double coarse_dt = five_moment_max_dt_patch(num_patches, mesh_pdata); -#ifdef AMR_DEBUG - double fine_dt = five_moment_max_dt_patch(num_patches, fine_pdata); -#else double fine_dt = (1.0 / ref_factor) * coarse_dt; -#endif struct sim_stats stats = { }; @@ -400,7 +207,7 @@ five_moment_1d_run_single(int argc, char **argv, struct five_moment_1d_single_in while ((coarse_t_curr < t_end) && (coarse_step <= num_steps)) { printf("Taking coarse (level 0) time-step %ld at t = %g; ", coarse_step, coarse_t_curr); - struct gkyl_update_status coarse_status = five_moment_update_patch(coarse_job_pool, ptopo, coarse_pdata, coarse_t_curr, coarse_dt, &stats); + struct gkyl_update_status coarse_status = five_moment_update_patch(coarse_job_pool, ptopo, mesh_pdata, coarse_t_curr, coarse_dt, &stats); printf(" dt = %g\n", coarse_status.dt_actual); if (!coarse_status.success) { @@ -409,94 +216,19 @@ five_moment_1d_run_single(int argc, char **argv, struct five_moment_1d_single_in } for (long fine_step = 1; fine_step < ref_factor + 1; fine_step++) { -#ifdef AMR_DEBUG - printf(" Taking fine (level 1) time-step %ld at t = %g; ", fine_step, fine_t_curr); - struct gkyl_update_status fine_status = five_moment_update_patch(fine_job_pool, ptopo, fine_pdata, fine_t_curr, fine_dt, &stats); - printf(" dt = %g\n", fine_status.dt_actual); - - if (!fine_status.success) { - printf("** Update method failed! Aborting simulation ....\n"); - break; - } - - fine_t_curr += fine_status.dt_actual; - fine_dt += fine_status.dt_suggested; -#else printf(" Taking fine (level 1) time-step %ld at t = %g", fine_step, fine_t_curr); printf(" dt = %g\n", (1.0 / ref_factor) * coarse_status.dt_actual); fine_t_curr += (1.0 / ref_factor) * coarse_status.dt_actual; fine_dt = (1.0 / ref_factor) * coarse_status.dt_suggested; -#endif } for (int i = 1; i < num_frames; i++) { if (coarse_t_curr < (i * io_trigger) && (coarse_t_curr + coarse_status.dt_actual) > (i * io_trigger)) { -#ifdef AMR_DEBUG - char buf_coarse[64]; - char buf_fine[64]; - - snprintf(buf_coarse, 64, "%s_coarse_%d", five_moment_output, i); - snprintf(buf_fine, 64, "%s_fine_%d", five_moment_output, i); - - five_moment_write_sol_patch(buf_coarse, num_patches, coarse_pdata); - five_moment_write_sol_patch(buf_fine, num_patches, fine_pdata); - - char buf_fine_old_elc[64], buf_fine_old_ion[64], buf_fine_old_field[64]; - char buf_fine_new_elc[64], buf_fine_new_ion[64], buf_fine_new_field[64]; - char buf_coarse_old_elc[64], buf_coarse_old_ion[64], buf_coarse_old_field[64]; - - snprintf(buf_fine_old_elc, 64, "%s_fine_%d_elc_p0.gkyl", five_moment_output, i); - snprintf(buf_fine_old_ion, 64, "%s_fine_%d_ion_p0.gkyl", five_moment_output, i); - snprintf(buf_fine_old_field, 64, "%s_fine_%d_field_p0.gkyl", five_moment_output, i); - - snprintf(buf_fine_new_elc, 64, "%s_%d_elc_p0.gkyl", five_moment_output, i); - snprintf(buf_fine_new_ion, 64, "%s_%d_ion_p0.gkyl", five_moment_output, i); - snprintf(buf_fine_new_field, 64, "%s_%d_field_p0.gkyl", five_moment_output, i); - - snprintf(buf_coarse_old_elc, 64, "%s_coarse_%d_elc_p0.gkyl", five_moment_output, i); - snprintf(buf_coarse_old_ion, 64, "%s_coarse_%d_ion_p0.gkyl", five_moment_output, i); - snprintf(buf_coarse_old_field, 64, "%s_coarse_%d_field_p0.gkyl", five_moment_output, i); - - rename(buf_fine_old_elc, buf_fine_new_elc); - rename(buf_fine_old_ion, buf_fine_new_ion); - rename(buf_fine_old_field, buf_fine_new_field); - - remove(buf_coarse_old_elc); - remove(buf_coarse_old_ion); - remove(buf_coarse_old_field); - - for (int j = 1; j < 3; j++) { - char buf_old_elc[64], buf_old_ion[64], buf_old_field[64]; - char buf_new_elc[64], buf_new_ion[64], buf_new_field[64]; - char buf_del_elc[64], buf_del_ion[64], buf_del_field[64]; - - snprintf(buf_old_elc, 64, "%s_coarse_%d_elc_p%d.gkyl", five_moment_output, i, j); - snprintf(buf_old_ion, 64, "%s_coarse_%d_ion_p%d.gkyl", five_moment_output, i, j); - snprintf(buf_old_field, 64, "%s_coarse_%d_field_p%d.gkyl", five_moment_output, i, j); - - snprintf(buf_new_elc, 64, "%s_%d_elc_p%d.gkyl", five_moment_output, i, j); - snprintf(buf_new_ion, 64, "%s_%d_ion_p%d.gkyl", five_moment_output, i, j); - snprintf(buf_new_field, 64, "%s_%d_field_p%d.gkyl", five_moment_output, i, j); - - snprintf(buf_del_elc, 64, "%s_fine_%d_elc_p%d.gkyl", five_moment_output, i, j); - snprintf(buf_del_ion, 64, "%s_fine_%d_ion_p%d.gkyl", five_moment_output, i, j); - snprintf(buf_del_field, 64, "%s_fine_%d_field_p%d.gkyl", five_moment_output, i, j); - - rename(buf_old_elc, buf_new_elc); - rename(buf_old_ion, buf_new_ion); - rename(buf_old_field, buf_new_field); - - remove(buf_del_elc); - remove(buf_del_ion); - remove(buf_del_field); - } -#else char buf[64]; snprintf(buf, 64, "%s_%d", five_moment_output, i); - five_moment_write_sol_patch(buf, num_patches, coarse_pdata); -#endif + five_moment_write_sol_patch(buf, num_patches, mesh_pdata); } } @@ -527,154 +259,48 @@ five_moment_1d_run_single(int argc, char **argv, struct five_moment_1d_single_in double tm_total_sec = gkyl_time_diff_now_sec(tm_start); -#ifdef AMR_DEBUG - char buf_coarse[64]; - char buf_fine[64]; - - snprintf(buf_coarse, 64, "%s_coarse_%d", five_moment_output, num_frames); - snprintf(buf_fine, 64, "%s_fine_%d", five_moment_output, num_frames); - - five_moment_write_sol_patch(buf_coarse, num_patches, coarse_pdata); - five_moment_write_sol_patch(buf_fine, num_patches, fine_pdata); - - char buf_fine_old_elc[64], buf_fine_old_ion[64], buf_fine_old_field[64]; - char buf_fine_new_elc[64], buf_fine_new_ion[64], buf_fine_new_field[64]; - char buf_coarse_old_elc[64], buf_coarse_old_ion[64], buf_coarse_old_field[64]; - - snprintf(buf_fine_old_elc, 64, "%s_fine_%d_elc_p0.gkyl", five_moment_output, num_frames); - snprintf(buf_fine_old_ion, 64, "%s_fine_%d_ion_p0.gkyl", five_moment_output, num_frames); - snprintf(buf_fine_old_field, 64, "%s_fine_%d_field_p0.gkyl", five_moment_output, num_frames); - - snprintf(buf_fine_new_elc, 64, "%s_%d_elc_p0.gkyl", five_moment_output, num_frames); - snprintf(buf_fine_new_ion, 64, "%s_%d_ion_p0.gkyl", five_moment_output, num_frames); - snprintf(buf_fine_new_field, 64, "%s_%d_field_p0.gkyl", five_moment_output, num_frames); - - snprintf(buf_coarse_old_elc, 64, "%s_coarse_%d_elc_p0.gkyl", five_moment_output, num_frames); - snprintf(buf_coarse_old_ion, 64, "%s_coarse_%d_ion_p0.gkyl", five_moment_output, num_frames); - snprintf(buf_coarse_old_field, 64, "%s_coarse_%d_field_p0.gkyl", five_moment_output, num_frames); - - rename(buf_fine_old_elc, buf_fine_new_elc); - rename(buf_fine_old_ion, buf_fine_new_ion); - rename(buf_fine_old_field, buf_fine_new_field); - - remove(buf_coarse_old_elc); - remove(buf_coarse_old_ion); - remove(buf_coarse_old_field); - - for (int i = 1; i < 3; i++) { - char buf_old_elc[64], buf_old_ion[64], buf_old_field[64]; - char buf_new_elc[64], buf_new_ion[64], buf_new_field[64]; - char buf_del_elc[64], buf_del_ion[64], buf_del_field[64]; - - snprintf(buf_old_elc, 64, "%s_coarse_%d_elc_p%d.gkyl", five_moment_output, num_frames, i); - snprintf(buf_old_ion, 64, "%s_coarse_%d_ion_p%d.gkyl", five_moment_output, num_frames, i); - snprintf(buf_old_field, 64, "%s_coarse_%d_field_p%d.gkyl", five_moment_output, num_frames, i); - - snprintf(buf_new_elc, 64, "%s_%d_elc_p%d.gkyl", five_moment_output, num_frames, i); - snprintf(buf_new_ion, 64, "%s_%d_ion_p%d.gkyl", five_moment_output, num_frames, i); - snprintf(buf_new_field, 64, "%s_%d_field_p%d.gkyl", five_moment_output, num_frames, i); - - snprintf(buf_del_elc, 64, "%s_fine_%d_elc_p%d.gkyl", five_moment_output, num_frames, i); - snprintf(buf_del_ion, 64, "%s_fine_%d_ion_p%d.gkyl", five_moment_output, num_frames, i); - snprintf(buf_del_field, 64, "%s_fine_%d_field_p%d.gkyl", five_moment_output, num_frames, i); - - rename(buf_old_elc, buf_new_elc); - rename(buf_old_ion, buf_new_ion); - rename(buf_old_field, buf_new_field); - - remove(buf_del_elc); - remove(buf_del_ion); - remove(buf_del_field); - } -#else char buf[64]; snprintf(buf, 64, "%s_%d", five_moment_output, num_frames); - five_moment_write_sol_patch(buf, num_patches, coarse_pdata); -#endif + five_moment_write_sol_patch(buf, num_patches, mesh_pdata); printf("Total run-time: %g. Failed steps: %d\n", tm_total_sec, stats.nfail); for (int i = 0; i < num_patches; i++) { - gkyl_fv_proj_release(coarse_pdata[i].fv_proj_elc); - gkyl_fv_proj_release(coarse_pdata[i].fv_proj_ion); - gkyl_fv_proj_release(coarse_pdata[i].fv_proj_maxwell); - - gkyl_wv_eqn_release(coarse_pdata[i].euler_elc); - gkyl_wv_eqn_release(coarse_pdata[i].euler_ion); - gkyl_wv_eqn_release(coarse_pdata[i].maxwell); - - five_moment_patch_bc_updaters_release(&coarse_pdata[i]); - gkyl_wave_geom_release(coarse_pdata[i].geom); - -#ifdef AMR_DEBUG - gkyl_fv_proj_release(fine_pdata[i].fv_proj_elc); - gkyl_fv_proj_release(fine_pdata[i].fv_proj_ion); - gkyl_fv_proj_release(fine_pdata[i].fv_proj_maxwell); - - gkyl_wv_eqn_release(fine_pdata[i].euler_elc); - gkyl_wv_eqn_release(fine_pdata[i].euler_ion); - gkyl_wv_eqn_release(fine_pdata[i].maxwell); - - five_moment_patch_bc_updaters_release(&fine_pdata[i]); - gkyl_wave_geom_release(fine_pdata[i].geom); -#endif - - gkyl_wave_prop_release(coarse_pdata[i].slvr_elc[0]); - gkyl_wave_prop_release(coarse_pdata[i].slvr_ion[0]); - gkyl_wave_prop_release(coarse_pdata[i].slvr_maxwell[0]); - -#ifdef AMR_DEBUG - gkyl_wave_prop_release(fine_pdata[i].slvr_elc[0]); - gkyl_wave_prop_release(fine_pdata[i].slvr_ion[0]); - gkyl_wave_prop_release(fine_pdata[i].slvr_maxwell[0]); -#endif - - gkyl_array_release(coarse_pdata[i].fdup_elc); - gkyl_array_release(coarse_pdata[i].fdup_ion); - gkyl_array_release(coarse_pdata[i].fdup_maxwell); - -#ifdef AMR_DEBUG - gkyl_array_release(fine_pdata[i].fdup_elc); - gkyl_array_release(fine_pdata[i].fdup_ion); - gkyl_array_release(fine_pdata[i].fdup_maxwell); -#endif - - gkyl_array_release(coarse_pdata[i].f_elc[0]); - gkyl_array_release(coarse_pdata[i].f_ion[0]); - gkyl_array_release(coarse_pdata[i].f_maxwell[0]); - -#ifdef AMR_DEBUG - gkyl_array_release(fine_pdata[i].f_elc[0]); - gkyl_array_release(fine_pdata[i].f_ion[0]); - gkyl_array_release(fine_pdata[i].f_maxwell[0]); -#endif - - gkyl_array_release(coarse_pdata[i].app_accel_elc); - gkyl_array_release(coarse_pdata[i].app_accel_ion); - gkyl_array_release(coarse_pdata[i].rhs_source_elc); - gkyl_array_release(coarse_pdata[i].rhs_source_ion); - gkyl_array_release(coarse_pdata[i].ext_em); - gkyl_array_release(coarse_pdata[i].app_current); - gkyl_array_release(coarse_pdata[i].nT_source_elc); - gkyl_array_release(coarse_pdata[i].nT_source_ion); - -#ifdef AMR_DEBUG - gkyl_array_release(fine_pdata[i].app_accel_elc); - gkyl_array_release(fine_pdata[i].app_accel_ion); - gkyl_array_release(fine_pdata[i].rhs_source_elc); - gkyl_array_release(fine_pdata[i].rhs_source_ion); - gkyl_array_release(fine_pdata[i].ext_em); - gkyl_array_release(fine_pdata[i].app_current); - gkyl_array_release(fine_pdata[i].nT_source_elc); - gkyl_array_release(fine_pdata[i].nT_source_ion); -#endif + gkyl_fv_proj_release(mesh_pdata[i].fv_proj_elc); + gkyl_fv_proj_release(mesh_pdata[i].fv_proj_ion); + gkyl_fv_proj_release(mesh_pdata[i].fv_proj_maxwell); + + gkyl_wv_eqn_release(mesh_pdata[i].euler_elc); + gkyl_wv_eqn_release(mesh_pdata[i].euler_ion); + gkyl_wv_eqn_release(mesh_pdata[i].maxwell); + + five_moment_patch_bc_updaters_release(&mesh_pdata[i]); + gkyl_wave_geom_release(mesh_pdata[i].geom); + + gkyl_wave_prop_release(mesh_pdata[i].slvr_elc[0]); + gkyl_wave_prop_release(mesh_pdata[i].slvr_ion[0]); + gkyl_wave_prop_release(mesh_pdata[i].slvr_maxwell[0]); + + gkyl_array_release(mesh_pdata[i].fdup_elc); + gkyl_array_release(mesh_pdata[i].fdup_ion); + gkyl_array_release(mesh_pdata[i].fdup_maxwell); + + gkyl_array_release(mesh_pdata[i].f_elc[0]); + gkyl_array_release(mesh_pdata[i].f_ion[0]); + gkyl_array_release(mesh_pdata[i].f_maxwell[0]); + + gkyl_array_release(mesh_pdata[i].app_accel_elc); + gkyl_array_release(mesh_pdata[i].app_accel_ion); + gkyl_array_release(mesh_pdata[i].rhs_source_elc); + gkyl_array_release(mesh_pdata[i].rhs_source_ion); + gkyl_array_release(mesh_pdata[i].ext_em); + gkyl_array_release(mesh_pdata[i].app_current); + gkyl_array_release(mesh_pdata[i].nT_source_elc); + gkyl_array_release(mesh_pdata[i].nT_source_ion); } gkyl_block_topo_release(ptopo); gkyl_job_pool_release(coarse_job_pool); -#ifdef AMR_DEBUG - gkyl_job_pool_release(fine_job_pool); -#endif } void @@ -741,90 +367,44 @@ five_moment_2d_run_single(int argc, char **argv, struct five_moment_2d_single_in int Nx = base_Nx; int Ny = base_Ny; - struct five_moment_block_data coarse_bdata[num_blocks]; + struct five_moment_block_data mesh_bdata[num_blocks]; struct gkyl_job_pool *coarse_job_pool = gkyl_thread_pool_new(app_args.num_threads); -#ifdef AMR_DEBUG - gkyl_rect_grid_init(&coarse_bdata[0].grid, 2, (double []) { refined_x1, refined_y1 }, (double []) { refined_x2, refined_y2 }, - (int []) { Nx, Ny }); -#else - gkyl_rect_grid_init(&coarse_bdata[0].grid, 2, (double []) { refined_x1, refined_y1 }, (double []) { refined_x2, refined_y2 }, + gkyl_rect_grid_init(&mesh_bdata[0].grid, 2, (double []) { refined_x1, refined_y1 }, (double []) { refined_x2, refined_y2 }, (int []) { Nx * ref_factor, Ny * ref_factor }); -#endif - gkyl_rect_grid_init(&coarse_bdata[1].grid, 2, (double []) { coarse_x1, refined_y2 }, (double []) { refined_x1, coarse_y2 }, + gkyl_rect_grid_init(&mesh_bdata[1].grid, 2, (double []) { coarse_x1, refined_y2 }, (double []) { refined_x1, coarse_y2 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[2].grid, 2, (double []) { refined_x1, refined_y2 }, (double []) { refined_x2, coarse_y2 }, + gkyl_rect_grid_init(&mesh_bdata[2].grid, 2, (double []) { refined_x1, refined_y2 }, (double []) { refined_x2, coarse_y2 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[3].grid, 2, (double []) { refined_x2, refined_y2 }, (double []) { coarse_x2, coarse_y2 }, + gkyl_rect_grid_init(&mesh_bdata[3].grid, 2, (double []) { refined_x2, refined_y2 }, (double []) { coarse_x2, coarse_y2 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[4].grid, 2, (double []) { coarse_x1, refined_y1 }, (double []) { refined_x1, refined_y2 }, + gkyl_rect_grid_init(&mesh_bdata[4].grid, 2, (double []) { coarse_x1, refined_y1 }, (double []) { refined_x1, refined_y2 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[5].grid, 2, (double []) { refined_x2, refined_y1 }, (double []) { coarse_x2, refined_y2 }, + gkyl_rect_grid_init(&mesh_bdata[5].grid, 2, (double []) { refined_x2, refined_y1 }, (double []) { coarse_x2, refined_y2 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[6].grid, 2, (double []) { coarse_x1, coarse_y1 }, (double []) { refined_x1, refined_y1 }, + gkyl_rect_grid_init(&mesh_bdata[6].grid, 2, (double []) { coarse_x1, coarse_y1 }, (double []) { refined_x1, refined_y1 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[7].grid, 2, (double []) { refined_x1, coarse_y1 }, (double []) { refined_x2, refined_y1 }, + gkyl_rect_grid_init(&mesh_bdata[7].grid, 2, (double []) { refined_x1, coarse_y1 }, (double []) { refined_x2, refined_y1 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[8].grid, 2, (double []) { refined_x2, coarse_y1 }, (double []) { coarse_x2, refined_y1 }, + gkyl_rect_grid_init(&mesh_bdata[8].grid, 2, (double []) { refined_x2, coarse_y1 }, (double []) { coarse_x2, refined_y1 }, (int []) { Nx, Ny }); -#ifdef AMR_DEBUG - struct five_moment_block_data fine_bdata[num_blocks]; - struct gkyl_job_pool *fine_job_pool = gkyl_thread_pool_new(app_args.num_threads); - - gkyl_rect_grid_init(&fine_bdata[0].grid, 2, (double []) { refined_x1, refined_y1 }, (double []) { refined_x2, refined_y2 }, - (int []) { Nx * ref_factor, Ny * ref_factor }); - gkyl_rect_grid_init(&fine_bdata[1].grid, 2, (double []) { coarse_x1, refined_y2 }, (double []) { refined_x1, coarse_y2 }, - (int []) { Nx * ref_factor, Ny * ref_factor }); - gkyl_rect_grid_init(&fine_bdata[2].grid, 2, (double []) { refined_x1, refined_y2 }, (double []) { refined_x2, coarse_y2 }, - (int []) { Nx * ref_factor, Ny * ref_factor }); - gkyl_rect_grid_init(&fine_bdata[3].grid, 2, (double []) { refined_x2, refined_y2 }, (double []) { coarse_x2, coarse_y2 }, - (int []) { Nx * ref_factor, Ny * ref_factor }); - gkyl_rect_grid_init(&fine_bdata[4].grid, 2, (double []) { coarse_x1, refined_y1 }, (double []) { refined_x1, refined_y2 }, - (int []) { Nx * ref_factor, Ny * ref_factor }); - gkyl_rect_grid_init(&fine_bdata[5].grid, 2, (double []) { refined_x2, refined_y1 }, (double []) { coarse_x2, refined_y2 }, - (int []) { Nx * ref_factor, Ny * ref_factor }); - gkyl_rect_grid_init(&fine_bdata[6].grid, 2, (double []) { coarse_x1, coarse_y1 }, (double []) { refined_x1, refined_y1 }, - (int []) { Nx * ref_factor, Ny * ref_factor }); - gkyl_rect_grid_init(&fine_bdata[7].grid, 2, (double []) { refined_x1, coarse_y1 }, (double []) { refined_x2, refined_y1 }, - (int []) { Nx * ref_factor, Ny * ref_factor }); - gkyl_rect_grid_init(&fine_bdata[8].grid, 2, (double []) { refined_x2, coarse_y1 }, (double []) { coarse_x2, refined_y1 }, - (int []) { Nx * ref_factor, Ny * ref_factor }); -#endif - for (int i = 0; i < num_blocks; i++) { - coarse_bdata[i].fv_proj_elc = gkyl_fv_proj_new(&coarse_bdata[i].grid, 2, 5, eval_elc, 0); - coarse_bdata[i].fv_proj_ion = gkyl_fv_proj_new(&coarse_bdata[i].grid, 2, 5, eval_ion, 0); - coarse_bdata[i].fv_proj_maxwell = gkyl_fv_proj_new(&coarse_bdata[i].grid, 2, 8, eval_field, 0); - -#ifdef AMR_DEBUG - fine_bdata[i].fv_proj_elc = gkyl_fv_proj_new(&fine_bdata[i].grid, 2, 5, eval_elc, 0); - fine_bdata[i].fv_proj_ion = gkyl_fv_proj_new(&fine_bdata[i].grid, 2, 5, eval_ion, 0); - fine_bdata[i].fv_proj_maxwell = gkyl_fv_proj_new(&fine_bdata[i].grid, 2, 8, eval_field, 0); -#endif + mesh_bdata[i].fv_proj_elc = gkyl_fv_proj_new(&mesh_bdata[i].grid, 2, 5, eval_elc, 0); + mesh_bdata[i].fv_proj_ion = gkyl_fv_proj_new(&mesh_bdata[i].grid, 2, 5, eval_ion, 0); + mesh_bdata[i].fv_proj_maxwell = gkyl_fv_proj_new(&mesh_bdata[i].grid, 2, 8, eval_field, 0); } for (int i = 0; i < num_blocks; i++) { - gkyl_create_grid_ranges(&coarse_bdata[i].grid, (int []) { 2, 2 }, &coarse_bdata[i].ext_range, &coarse_bdata[i].range); - coarse_bdata[i].geom = gkyl_wave_geom_new(&coarse_bdata[i].grid, &coarse_bdata[i].ext_range, 0, 0, false); + gkyl_create_grid_ranges(&mesh_bdata[i].grid, (int []) { 2, 2 }, &mesh_bdata[i].ext_range, &mesh_bdata[i].range); + mesh_bdata[i].geom = gkyl_wave_geom_new(&mesh_bdata[i].grid, &mesh_bdata[i].ext_range, 0, 0, false); - coarse_bdata[i].transmissive_x = transmissive_x; - coarse_bdata[i].transmissive_y = transmissive_y; - - coarse_bdata[i].wall_x = wall_x; - coarse_bdata[i].wall_y = wall_y; - -#ifdef AMR_DEBUG - gkyl_create_grid_ranges(&fine_bdata[i].grid, (int []) { 2, 2 }, &fine_bdata[i].ext_range, &fine_bdata[i].range); - fine_bdata[i].geom = gkyl_wave_geom_new(&fine_bdata[i].grid, &fine_bdata[i].ext_range, 0, 0, false); - - fine_bdata[i].transmissive_x = transmissive_x; - fine_bdata[i].transmissive_y = transmissive_y; + mesh_bdata[i].transmissive_x = transmissive_x; + mesh_bdata[i].transmissive_y = transmissive_y; - fine_bdata[i].wall_x = wall_x; - fine_bdata[i].wall_y = wall_y; -#endif + mesh_bdata[i].wall_x = wall_x; + mesh_bdata[i].wall_y = wall_y; } for (int i = 0; i < num_blocks; i++) { @@ -834,289 +414,117 @@ five_moment_2d_run_single(int argc, char **argv, struct five_moment_2d_single_in .rp_type = WV_EULER_RP_HLL, .use_gpu = app_args.use_gpu, }; - coarse_bdata[i].euler_elc = gkyl_wv_euler_inew(&inp); - coarse_bdata[i].euler_ion = gkyl_wv_euler_inew(&inp); + mesh_bdata[i].euler_elc = gkyl_wv_euler_inew(&inp); + mesh_bdata[i].euler_ion = gkyl_wv_euler_inew(&inp); } else { - coarse_bdata[i].euler_elc = gkyl_wv_euler_new(gas_gamma, app_args.use_gpu); - coarse_bdata[i].euler_ion = gkyl_wv_euler_new(gas_gamma, app_args.use_gpu); + mesh_bdata[i].euler_elc = gkyl_wv_euler_new(gas_gamma, app_args.use_gpu); + mesh_bdata[i].euler_ion = gkyl_wv_euler_new(gas_gamma, app_args.use_gpu); } - coarse_bdata[i].maxwell = gkyl_wv_maxwell_new(light_speed, e_fact, b_fact); + mesh_bdata[i].maxwell = gkyl_wv_maxwell_new(light_speed, e_fact, b_fact); for (int d = 0; d < ndim; d++) { - coarse_bdata[i].slvr_elc[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &coarse_bdata[i].grid, - .equation = coarse_bdata[i].euler_elc, + mesh_bdata[i].slvr_elc[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { + .grid = &mesh_bdata[i].grid, + .equation = mesh_bdata[i].euler_elc, .limiter = GKYL_MONOTONIZED_CENTERED, .num_up_dirs = 1, .update_dirs = { d }, .cfl = cfl_frac, - .geom = coarse_bdata[i].geom, + .geom = mesh_bdata[i].geom, } ); - coarse_bdata[i].slvr_ion[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &coarse_bdata[i].grid, - .equation = coarse_bdata[i].euler_ion, + mesh_bdata[i].slvr_ion[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { + .grid = &mesh_bdata[i].grid, + .equation = mesh_bdata[i].euler_ion, .limiter = GKYL_MONOTONIZED_CENTERED, .num_up_dirs = 1, .update_dirs = { d }, .cfl = cfl_frac, - .geom = coarse_bdata[i].geom, + .geom = mesh_bdata[i].geom, } ); - coarse_bdata[i].slvr_maxwell[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &coarse_bdata[i].grid, - .equation = coarse_bdata[i].maxwell, + mesh_bdata[i].slvr_maxwell[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { + .grid = &mesh_bdata[i].grid, + .equation = mesh_bdata[i].maxwell, .limiter = GKYL_MONOTONIZED_CENTERED, .num_up_dirs = 1, .update_dirs = { d }, .cfl = cfl_frac, - .geom = coarse_bdata[i].geom, + .geom = mesh_bdata[i].geom, } ); } struct gkyl_moment_em_coupling_inp coarse_src_inp = { - .grid = &coarse_bdata[i].grid, + .grid = &mesh_bdata[i].grid, .nfluids = 2, .epsilon0 = epsilon0, }; coarse_src_inp.param[0] = (struct gkyl_moment_em_coupling_data) { - .type = coarse_bdata[i].euler_elc->type, + .type = mesh_bdata[i].euler_elc->type, .charge = charge_elc, .mass = mass_elc, .k0 = k0_elc, }; coarse_src_inp.param[1] = (struct gkyl_moment_em_coupling_data) { - .type = coarse_bdata[i].euler_ion->type, - .charge = charge_ion, - .mass = mass_ion, - .k0 = k0_ion, - }; - - coarse_bdata[i].src_slvr = gkyl_moment_em_coupling_new(coarse_src_inp); - -#ifdef AMR_DEBUG - if (low_order_flux) { - struct gkyl_wv_euler_inp inp = { - .gas_gamma = gas_gamma, - .rp_type = WV_EULER_RP_HLL, - .use_gpu = app_args.use_gpu, - }; - fine_bdata[i].euler_elc = gkyl_wv_euler_inew(&inp); - fine_bdata[i].euler_ion = gkyl_wv_euler_inew(&inp); - } - else { - fine_bdata[i].euler_elc = gkyl_wv_euler_new(gas_gamma, app_args.use_gpu); - fine_bdata[i].euler_ion = gkyl_wv_euler_new(gas_gamma, app_args.use_gpu); - } - fine_bdata[i].maxwell = gkyl_wv_maxwell_new(light_speed, e_fact, b_fact); - - for (int d = 0; d < ndim; d++) { - fine_bdata[i].slvr_elc[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &fine_bdata[i].grid, - .equation = fine_bdata[i].euler_elc, - .limiter = GKYL_MONOTONIZED_CENTERED, - .num_up_dirs = 1, - .update_dirs = { d }, - .cfl = cfl_frac, - .geom = fine_bdata[i].geom, - } - ); - fine_bdata[i].slvr_ion[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &fine_bdata[i].grid, - .equation = fine_bdata[i].euler_ion, - .limiter = GKYL_MONOTONIZED_CENTERED, - .num_up_dirs = 1, - .update_dirs = { d }, - .cfl = cfl_frac, - .geom = fine_bdata[i].geom, - } - ); - fine_bdata[i].slvr_maxwell[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &fine_bdata[i].grid, - .equation = fine_bdata[i].maxwell, - .limiter = GKYL_MONOTONIZED_CENTERED, - .num_up_dirs = 1, - .update_dirs = { d }, - .cfl = cfl_frac, - .geom = fine_bdata[i].geom, - } - ); - } - - struct gkyl_moment_em_coupling_inp fine_src_inp = { - .grid = &fine_bdata[i].grid, - .nfluids = 2, - .epsilon0 = epsilon0, - }; - - fine_src_inp.param[0] = (struct gkyl_moment_em_coupling_data) { - .type = fine_bdata[i].euler_elc->type, - .charge = charge_elc, - .mass = mass_elc, - .k0 = k0_elc, - }; - fine_src_inp.param[1] = (struct gkyl_moment_em_coupling_data) { - .type = fine_bdata[i].euler_ion->type, + .type = mesh_bdata[i].euler_ion->type, .charge = charge_ion, .mass = mass_ion, .k0 = k0_ion, }; - fine_bdata[i].src_slvr = gkyl_moment_em_coupling_new(fine_src_inp); -#endif + mesh_bdata[i].src_slvr = gkyl_moment_em_coupling_new(coarse_src_inp); } struct gkyl_block_topo *btopo = create_block_topo(); for (int i = 0; i < num_blocks; i++) { - five_moment_block_bc_updaters_init(&coarse_bdata[i], &btopo->conn[i]); - -#ifdef AMR_DEBUG - five_moment_block_bc_updaters_init(&fine_bdata[i], &btopo->conn[i]); -#endif + five_moment_block_bc_updaters_init(&mesh_bdata[i], &btopo->conn[i]); } for (int i = 0; i < num_blocks; i++) { - coarse_bdata[i].fdup_elc = gkyl_array_new(GKYL_DOUBLE, 5, coarse_bdata[i].ext_range.volume); - coarse_bdata[i].fdup_ion = gkyl_array_new(GKYL_DOUBLE, 5, coarse_bdata[i].ext_range.volume); - coarse_bdata[i].fdup_maxwell = gkyl_array_new(GKYL_DOUBLE, 8, coarse_bdata[i].ext_range.volume); - - for (int d = 0; d < ndim + 1; d++) { - coarse_bdata[i].f_elc[d] = gkyl_array_new(GKYL_DOUBLE, 5, coarse_bdata[i].ext_range.volume); - coarse_bdata[i].f_ion[d] = gkyl_array_new(GKYL_DOUBLE, 5, coarse_bdata[i].ext_range.volume); - coarse_bdata[i].f_maxwell[d] = gkyl_array_new(GKYL_DOUBLE, 8, coarse_bdata[i].ext_range.volume); - } - - coarse_bdata[i].app_accel_elc = gkyl_array_new(GKYL_DOUBLE, 3, coarse_bdata[i].ext_range.volume); - coarse_bdata[i].app_accel_ion = gkyl_array_new(GKYL_DOUBLE, 3, coarse_bdata[i].ext_range.volume); - coarse_bdata[i].rhs_source_elc = gkyl_array_new(GKYL_DOUBLE, 5, coarse_bdata[i].ext_range.volume); - coarse_bdata[i].rhs_source_ion = gkyl_array_new(GKYL_DOUBLE, 5, coarse_bdata[i].ext_range.volume); - coarse_bdata[i].ext_em = gkyl_array_new(GKYL_DOUBLE, 6, coarse_bdata[i].ext_range.volume); - coarse_bdata[i].app_current = gkyl_array_new(GKYL_DOUBLE, 3, coarse_bdata[i].ext_range.volume); - coarse_bdata[i].nT_source_elc = gkyl_array_new(GKYL_DOUBLE, 2, coarse_bdata[i].ext_range.volume); - coarse_bdata[i].nT_source_ion = gkyl_array_new(GKYL_DOUBLE, 2, coarse_bdata[i].ext_range.volume); - -#ifdef AMR_DEBUG - fine_bdata[i].fdup_elc = gkyl_array_new(GKYL_DOUBLE, 5, fine_bdata[i].ext_range.volume); - fine_bdata[i].fdup_ion = gkyl_array_new(GKYL_DOUBLE, 5, fine_bdata[i].ext_range.volume); - fine_bdata[i].fdup_maxwell = gkyl_array_new(GKYL_DOUBLE, 8, fine_bdata[i].ext_range.volume); + mesh_bdata[i].fdup_elc = gkyl_array_new(GKYL_DOUBLE, 5, mesh_bdata[i].ext_range.volume); + mesh_bdata[i].fdup_ion = gkyl_array_new(GKYL_DOUBLE, 5, mesh_bdata[i].ext_range.volume); + mesh_bdata[i].fdup_maxwell = gkyl_array_new(GKYL_DOUBLE, 8, mesh_bdata[i].ext_range.volume); for (int d = 0; d < ndim + 1; d++) { - fine_bdata[i].f_elc[d] = gkyl_array_new(GKYL_DOUBLE, 5, fine_bdata[i].ext_range.volume); - fine_bdata[i].f_ion[d] = gkyl_array_new(GKYL_DOUBLE, 5, fine_bdata[i].ext_range.volume); - fine_bdata[i].f_maxwell[d] = gkyl_array_new(GKYL_DOUBLE, 8, fine_bdata[i].ext_range.volume); + mesh_bdata[i].f_elc[d] = gkyl_array_new(GKYL_DOUBLE, 5, mesh_bdata[i].ext_range.volume); + mesh_bdata[i].f_ion[d] = gkyl_array_new(GKYL_DOUBLE, 5, mesh_bdata[i].ext_range.volume); + mesh_bdata[i].f_maxwell[d] = gkyl_array_new(GKYL_DOUBLE, 8, mesh_bdata[i].ext_range.volume); } - fine_bdata[i].app_accel_elc = gkyl_array_new(GKYL_DOUBLE, 3, fine_bdata[i].ext_range.volume); - fine_bdata[i].app_accel_ion = gkyl_array_new(GKYL_DOUBLE, 3, fine_bdata[i].ext_range.volume); - fine_bdata[i].rhs_source_elc = gkyl_array_new(GKYL_DOUBLE, 5, fine_bdata[i].ext_range.volume); - fine_bdata[i].rhs_source_ion = gkyl_array_new(GKYL_DOUBLE, 5, fine_bdata[i].ext_range.volume); - fine_bdata[i].ext_em = gkyl_array_new(GKYL_DOUBLE, 6, fine_bdata[i].ext_range.volume); - fine_bdata[i].app_current = gkyl_array_new(GKYL_DOUBLE, 3, fine_bdata[i].ext_range.volume); - fine_bdata[i].nT_source_elc = gkyl_array_new(GKYL_DOUBLE, 2, fine_bdata[i].ext_range.volume); - fine_bdata[i].nT_source_ion = gkyl_array_new(GKYL_DOUBLE, 2, fine_bdata[i].ext_range.volume); -#endif + mesh_bdata[i].app_accel_elc = gkyl_array_new(GKYL_DOUBLE, 3, mesh_bdata[i].ext_range.volume); + mesh_bdata[i].app_accel_ion = gkyl_array_new(GKYL_DOUBLE, 3, mesh_bdata[i].ext_range.volume); + mesh_bdata[i].rhs_source_elc = gkyl_array_new(GKYL_DOUBLE, 5, mesh_bdata[i].ext_range.volume); + mesh_bdata[i].rhs_source_ion = gkyl_array_new(GKYL_DOUBLE, 5, mesh_bdata[i].ext_range.volume); + mesh_bdata[i].ext_em = gkyl_array_new(GKYL_DOUBLE, 6, mesh_bdata[i].ext_range.volume); + mesh_bdata[i].app_current = gkyl_array_new(GKYL_DOUBLE, 3, mesh_bdata[i].ext_range.volume); + mesh_bdata[i].nT_source_elc = gkyl_array_new(GKYL_DOUBLE, 2, mesh_bdata[i].ext_range.volume); + mesh_bdata[i].nT_source_ion = gkyl_array_new(GKYL_DOUBLE, 2, mesh_bdata[i].ext_range.volume); } #ifdef AMR_USETHREADS for (int i = 0; i < num_blocks; i++) { - gkyl_job_pool_add_work(coarse_job_pool, five_moment_init_job_func_block, &coarse_bdata[i]); - -#ifdef AMR_DEBUG - gkyl_job_pool_add_work(fine_job_pool, five_moment_init_job_func_block, &fine_bdata[i]); -#endif + gkyl_job_pool_add_work(coarse_job_pool, five_moment_init_job_func_block, &mesh_bdata[i]); } gkyl_job_pool_wait(coarse_job_pool); - -#ifdef AMR_DEBUG - gkyl_job_pool_wait(fine_job_pool); -#endif #else for (int i = 0; i < num_blocks; i++) { - five_moment_init_job_func_block(&coarse_bdata[i]); - -#ifdef AMR_DEBUG - five_moment_init_job_func_block(&fine_bdata[i]); -#endif + five_moment_init_job_func_block(&mesh_bdata[i]); } #endif -#ifdef AMR_DEBUG - char coarse0[64]; - snprintf(coarse0, 64, "%s_coarse_0", five_moment_output); - five_moment_write_sol_block(coarse0, num_blocks, coarse_bdata); - - char fine0[64]; - snprintf(fine0, 64, "%s_fine_0", five_moment_output); - five_moment_write_sol_block(fine0, num_blocks, fine_bdata); - - char fine0_elc_b0[64], fine0_ion_b0[64], fine0_field_b0[64]; - char coarse0_elc_b0[64], coarse0_ion_b0[64], coarse0_field_b0[64]; - char b0_elc[64], b0_ion[64], b0_field[64]; - - snprintf(fine0_elc_b0, 64, "%s_fine_0_elc_b0.gkyl", five_moment_output); - snprintf(fine0_ion_b0, 64, "%s_fine_0_ion_b0.gkyl", five_moment_output); - snprintf(fine0_field_b0, 64, "%s_fine_0_field_b0.gkyl", five_moment_output); - - snprintf(coarse0_elc_b0, 64, "%s_coarse_0_elc_b0.gkyl", five_moment_output); - snprintf(coarse0_ion_b0, 64, "%s_coarse_0_ion_b0.gkyl", five_moment_output); - snprintf(coarse0_field_b0, 64, "%s_coarse_0_field_b0.gkyl", five_moment_output); - - snprintf(b0_elc, 64, "%s_0_elc_b0.gkyl", five_moment_output); - snprintf(b0_ion, 64, "%s_0_ion_b0.gkyl", five_moment_output); - snprintf(b0_field, 64, "%s_0_field_b0.gkyl", five_moment_output); - - rename(fine0_elc_b0, b0_elc); - rename(fine0_ion_b0, b0_ion); - rename(fine0_field_b0, b0_field); - - remove(coarse0_elc_b0); - remove(coarse0_ion_b0); - remove(coarse0_field_b0); - - for (int i = 1; i < 9; i++) { - char buf_old_elc[64], buf_old_ion[64], buf_old_field[64]; - char buf_new_elc[64], buf_new_ion[64], buf_new_field[64]; - char buf_del_elc[64], buf_del_ion[64], buf_del_field[64]; - - snprintf(buf_old_elc, 64, "%s_coarse_0_elc_b%d.gkyl", five_moment_output, i); - snprintf(buf_old_ion, 64, "%s_coarse_0_ion_b%d.gkyl", five_moment_output, i); - snprintf(buf_old_field, 64, "%s_coarse_0_field_b%d.gkyl", five_moment_output, i); - - snprintf(buf_new_elc, 64, "%s_0_elc_b%d.gkyl", five_moment_output, i); - snprintf(buf_new_ion, 64, "%s_0_ion_b%d.gkyl", five_moment_output, i); - snprintf(buf_new_field, 64, "%s_0_field_b%d.gkyl", five_moment_output, i); - - snprintf(buf_del_elc, 64, "%s_fine_0_elc_b%d.gkyl", five_moment_output, i); - snprintf(buf_del_ion, 64, "%s_fine_0_ion_b%d.gkyl", five_moment_output, i); - snprintf(buf_del_field, 64, "%s_fine_0_field_b%d.gkyl", five_moment_output, i); - - rename(buf_old_elc, buf_new_elc); - rename(buf_old_ion, buf_new_ion); - rename(buf_old_field, buf_new_field); - - remove(buf_del_elc); - remove(buf_del_ion); - remove(buf_del_field); - } -#else char amr0[64]; snprintf(amr0, 64, "%s_0", five_moment_output); - five_moment_write_sol_block(amr0, num_blocks, coarse_bdata); -#endif + five_moment_write_sol_block(amr0, num_blocks, mesh_bdata); double coarse_t_curr = 0.0; double fine_t_curr = 0.0; - double coarse_dt = five_moment_max_dt_block(num_blocks, coarse_bdata); + double coarse_dt = five_moment_max_dt_block(num_blocks, mesh_bdata); -#ifdef AMR_DEBUG - double fine_dt = five_moment_max_dt_block(num_blocks, fine_bdata); -#else double fine_dt = (1.0 / ref_factor) * coarse_dt; -#endif struct sim_stats stats = { }; @@ -1132,7 +540,7 @@ five_moment_2d_run_single(int argc, char **argv, struct five_moment_2d_single_in while ((coarse_t_curr < t_end) && (coarse_step <= num_steps)) { printf("Taking coarse (level 0) time-step %ld at t = %g; ", coarse_step, coarse_t_curr); - struct gkyl_update_status coarse_status = five_moment_update_block(coarse_job_pool, btopo, coarse_bdata, coarse_t_curr, coarse_dt, &stats); + struct gkyl_update_status coarse_status = five_moment_update_block(coarse_job_pool, btopo, mesh_bdata, coarse_t_curr, coarse_dt, &stats); printf(" dt = %g\n", coarse_status.dt_actual); if (!coarse_status.success) { @@ -1141,105 +549,30 @@ five_moment_2d_run_single(int argc, char **argv, struct five_moment_2d_single_in } for (long fine_step = 1; fine_step < ref_factor + 1; fine_step++) { -#ifdef AMR_DEBUG - printf(" Taking fine (level 1) time-step %ld at t = %g; ", fine_step, fine_t_curr); - struct gkyl_update_status fine_status = five_moment_update_block(fine_job_pool, btopo, fine_bdata, fine_t_curr, fine_dt, &stats); - printf(" dt = %g\n", fine_status.dt_actual); - - if (!fine_status.success) { - printf("** Update method failed! Aborting simulation ....\n"); - break; - } - - fine_t_curr += fine_status.dt_actual; - fine_dt += fine_status.dt_suggested; -#else printf(" Taking fine (level 1) time-step %ld at t = %g", fine_step, fine_t_curr); printf(" dt = %g\n", (1.0 / ref_factor) * coarse_status.dt_actual); fine_t_curr += (1.0 / ref_factor) * coarse_status.dt_actual; fine_dt = (1.0 / ref_factor) * coarse_status.dt_suggested; -#endif } for (int i = 1; i < num_frames; i++) { if (coarse_t_curr < (i * io_trigger) && (coarse_t_curr + coarse_status.dt_actual) > (i * io_trigger)) { -#ifdef AMR_DEBUG - char buf_coarse[64]; - char buf_fine[64]; + char buf[64]; + snprintf(buf, 64, "%s_%d", five_moment_output, i); - snprintf(buf_coarse, 64, "%s_coarse_%d", five_moment_output, i); - snprintf(buf_fine, 64, "%s_fine_%d", five_moment_output, i); + five_moment_write_sol_block(buf, num_blocks, mesh_bdata); + } + } - five_moment_write_sol_block(buf_coarse, num_blocks, coarse_bdata); - five_moment_write_sol_block(buf_fine, num_blocks, fine_bdata); + coarse_t_curr += coarse_status.dt_actual; + coarse_dt = coarse_status.dt_suggested; - char buf_fine_old_elc[64], buf_fine_old_ion[64], buf_fine_old_field[64]; - char buf_fine_new_elc[64], buf_fine_new_ion[64], buf_fine_new_field[64]; - char buf_coarse_old_elc[64], buf_coarse_old_ion[64], buf_coarse_old_field[64]; - - snprintf(buf_fine_old_elc, 64, "%s_fine_%d_elc_b0.gkyl", five_moment_output, i); - snprintf(buf_fine_old_ion, 64, "%s_fine_%d_ion_b0.gkyl", five_moment_output, i); - snprintf(buf_fine_old_field, 64, "%s_fine_%d_field_b0.gkyl", five_moment_output, i); - - snprintf(buf_fine_new_elc, 64, "%s_%d_elc_b0.gkyl", five_moment_output, i); - snprintf(buf_fine_new_ion, 64, "%s_%d_ion_b0.gkyl", five_moment_output, i); - snprintf(buf_fine_new_field, 64, "%s_%d_field_b0.gkyl", five_moment_output, i); - - snprintf(buf_coarse_old_elc, 64, "%s_coarse_%d_elc_b0.gkyl", five_moment_output, i); - snprintf(buf_coarse_old_ion, 64, "%s_coarse_%d_ion_b0.gkyl", five_moment_output, i); - snprintf(buf_coarse_old_field, 64, "%s_coarse_%d_field_b0.gkyl", five_moment_output, i); - - rename(buf_fine_old_elc, buf_fine_new_elc); - rename(buf_fine_old_ion, buf_fine_new_ion); - rename(buf_fine_old_field, buf_fine_new_field); - - remove(buf_coarse_old_elc); - remove(buf_coarse_old_ion); - remove(buf_coarse_old_field); - - for (int j = 1; j < 9; j++) { - char buf_old_elc[64], buf_old_ion[64], buf_old_field[64]; - char buf_new_elc[64], buf_new_ion[64], buf_new_field[64]; - char buf_del_elc[64], buf_del_ion[64], buf_del_field[64]; - - snprintf(buf_old_elc, 64, "%s_coarse_%d_elc_b%d.gkyl", five_moment_output, i, j); - snprintf(buf_old_ion, 64, "%s_coarse_%d_ion_b%d.gkyl", five_moment_output, i, j); - snprintf(buf_old_field, 64, "%s_coarse_%d_field_b%d.gkyl", five_moment_output, i, j); - - snprintf(buf_new_elc, 64, "%s_%d_elc_b%d.gkyl", five_moment_output, i, j); - snprintf(buf_new_ion, 64, "%s_%d_ion_b%d.gkyl", five_moment_output, i, j); - snprintf(buf_new_field, 64, "%s_%d_field_b%d.gkyl", five_moment_output, i, j); - - snprintf(buf_del_elc, 64, "%s_fine_%d_elc_b%d.gkyl", five_moment_output, i, j); - snprintf(buf_del_ion, 64, "%s_fine_%d_ion_b%d.gkyl", five_moment_output, i, j); - snprintf(buf_del_field, 64, "%s_fine_%d_field_b%d.gkyl", five_moment_output, i, j); - - rename(buf_old_elc, buf_new_elc); - rename(buf_old_ion, buf_new_ion); - rename(buf_old_field, buf_new_field); - - remove(buf_del_elc); - remove(buf_del_ion); - remove(buf_del_field); - } -#else - char buf[64]; - snprintf(buf, 64, "%s_%d", five_moment_output, i); - - five_moment_write_sol_block(buf, num_blocks, coarse_bdata); -#endif - } - } - - coarse_t_curr += coarse_status.dt_actual; - coarse_dt = coarse_status.dt_suggested; - - if (dt_init < 0.0) { - dt_init = coarse_status.dt_actual; - } - else if (coarse_status.dt_actual < dt_failure_tol * dt_init) { - num_failures += 1; + if (dt_init < 0.0) { + dt_init = coarse_status.dt_actual; + } + else if (coarse_status.dt_actual < dt_failure_tol * dt_init) { + num_failures += 1; printf("WARNING: Time-step dt = %g", coarse_status.dt_actual); printf(" is below %g*dt_init ...", dt_failure_tol); @@ -1259,159 +592,53 @@ five_moment_2d_run_single(int argc, char **argv, struct five_moment_2d_single_in double tm_total_sec = gkyl_time_diff_now_sec(tm_start); -#ifdef AMR_DEBUG - char buf_coarse[64]; - char buf_fine[64]; - - snprintf(buf_coarse, 64, "%s_coarse_%d", five_moment_output, num_frames); - snprintf(buf_fine, 64, "%s_fine_%d", five_moment_output, num_frames); - - five_moment_write_sol_block(buf_coarse, num_blocks, coarse_bdata); - five_moment_write_sol_block(buf_fine, num_blocks, fine_bdata); - - char buf_fine_old_elc[64], buf_fine_old_ion[64], buf_fine_old_field[64]; - char buf_fine_new_elc[64], buf_fine_new_ion[64], buf_fine_new_field[64]; - char buf_coarse_old_elc[64], buf_coarse_old_ion[64], buf_coarse_old_field[64]; - - snprintf(buf_fine_old_elc, 64, "%s_fine_%d_elc_b0.gkyl", five_moment_output, num_frames); - snprintf(buf_fine_old_ion, 64, "%s_fine_%d_ion_b0.gkyl", five_moment_output, num_frames); - snprintf(buf_fine_old_field, 64, "%s_fine_%d_field_b0.gkyl", five_moment_output, num_frames); - - snprintf(buf_fine_new_elc, 64, "%s_%d_elc_b0.gkyl", five_moment_output, num_frames); - snprintf(buf_fine_new_ion, 64, "%s_%d_ion_b0.gkyl", five_moment_output, num_frames); - snprintf(buf_fine_new_field, 64, "%s_%d_field_b0.gkyl", five_moment_output, num_frames); - - snprintf(buf_coarse_old_elc, 64, "%s_coarse_%d_elc_b0.gkyl", five_moment_output, num_frames); - snprintf(buf_coarse_old_ion, 64, "%s_coarse_%d_ion_b0.gkyl", five_moment_output, num_frames); - snprintf(buf_coarse_old_field, 64, "%s_coarse_%d_field_b0.gkyl", five_moment_output, num_frames); - - rename(buf_fine_old_elc, buf_fine_new_elc); - rename(buf_fine_old_ion, buf_fine_new_ion); - rename(buf_fine_old_field, buf_fine_new_field); - - remove(buf_coarse_old_elc); - remove(buf_coarse_old_ion); - remove(buf_coarse_old_field); - - for (int i = 1; i < 9; i++) { - char buf_old_elc[64], buf_old_ion[64], buf_old_field[64]; - char buf_new_elc[64], buf_new_ion[64], buf_new_field[64]; - char buf_del_elc[64], buf_del_ion[64], buf_del_field[64]; - - snprintf(buf_old_elc, 64, "%s_coarse_%d_elc_b%d.gkyl", five_moment_output, num_frames, i); - snprintf(buf_old_ion, 64, "%s_coarse_%d_ion_b%d.gkyl", five_moment_output, num_frames, i); - snprintf(buf_old_field, 64, "%s_coarse_%d_field_b%d.gkyl", five_moment_output, num_frames, i); - - snprintf(buf_new_elc, 64, "%s_%d_elc_b%d.gkyl", five_moment_output, num_frames, i); - snprintf(buf_new_ion, 64, "%s_%d_ion_b%d.gkyl", five_moment_output, num_frames, i); - snprintf(buf_new_field, 64, "%s_%d_field_b%d.gkyl", five_moment_output, num_frames, i); - - snprintf(buf_del_elc, 64, "%s_fine_%d_elc_b%d.gkyl", five_moment_output, num_frames, i); - snprintf(buf_del_ion, 64, "%s_fine_%d_ion_b%d.gkyl", five_moment_output, num_frames, i); - snprintf(buf_del_field, 64, "%s_fine_%d_field_b%d.gkyl", five_moment_output, num_frames, i); - - rename(buf_old_elc, buf_new_elc); - rename(buf_old_ion, buf_new_ion); - rename(buf_old_field, buf_new_field); - - remove(buf_del_elc); - remove(buf_del_ion); - remove(buf_del_field); - } -#else char buf[64]; snprintf(buf, 64, "%s_%d", five_moment_output, num_frames); - five_moment_write_sol_block(buf, num_blocks, coarse_bdata); -#endif + five_moment_write_sol_block(buf, num_blocks, mesh_bdata); printf("Total run-time: %g. Failed steps: %d\n", tm_total_sec, stats.nfail); for (int i = 0; i < num_blocks; i++) { - gkyl_fv_proj_release(coarse_bdata[i].fv_proj_elc); - gkyl_fv_proj_release(coarse_bdata[i].fv_proj_ion); - gkyl_fv_proj_release(coarse_bdata[i].fv_proj_maxwell); - - gkyl_wv_eqn_release(coarse_bdata[i].euler_elc); - gkyl_wv_eqn_release(coarse_bdata[i].euler_ion); - gkyl_wv_eqn_release(coarse_bdata[i].maxwell); - - five_moment_block_bc_updaters_release(&coarse_bdata[i]); - gkyl_wave_geom_release(coarse_bdata[i].geom); + gkyl_fv_proj_release(mesh_bdata[i].fv_proj_elc); + gkyl_fv_proj_release(mesh_bdata[i].fv_proj_ion); + gkyl_fv_proj_release(mesh_bdata[i].fv_proj_maxwell); -#ifdef AMR_DEBUG - gkyl_fv_proj_release(fine_bdata[i].fv_proj_elc); - gkyl_fv_proj_release(fine_bdata[i].fv_proj_ion); - gkyl_fv_proj_release(fine_bdata[i].fv_proj_maxwell); + gkyl_wv_eqn_release(mesh_bdata[i].euler_elc); + gkyl_wv_eqn_release(mesh_bdata[i].euler_ion); + gkyl_wv_eqn_release(mesh_bdata[i].maxwell); - gkyl_wv_eqn_release(fine_bdata[i].euler_elc); - gkyl_wv_eqn_release(fine_bdata[i].euler_ion); - gkyl_wv_eqn_release(fine_bdata[i].maxwell); - - five_moment_block_bc_updaters_release(&fine_bdata[i]); - gkyl_wave_geom_release(fine_bdata[i].geom); -#endif + five_moment_block_bc_updaters_release(&mesh_bdata[i]); + gkyl_wave_geom_release(mesh_bdata[i].geom); for (int d = 0; d < ndim; d++) { - gkyl_wave_prop_release(coarse_bdata[i].slvr_elc[d]); - gkyl_wave_prop_release(coarse_bdata[i].slvr_ion[d]); - gkyl_wave_prop_release(coarse_bdata[i].slvr_maxwell[d]); - -#ifdef AMR_DEBUG - gkyl_wave_prop_release(fine_bdata[i].slvr_elc[d]); - gkyl_wave_prop_release(fine_bdata[i].slvr_ion[d]); - gkyl_wave_prop_release(fine_bdata[i].slvr_maxwell[d]); -#endif + gkyl_wave_prop_release(mesh_bdata[i].slvr_elc[d]); + gkyl_wave_prop_release(mesh_bdata[i].slvr_ion[d]); + gkyl_wave_prop_release(mesh_bdata[i].slvr_maxwell[d]); } - gkyl_array_release(coarse_bdata[i].fdup_elc); - gkyl_array_release(coarse_bdata[i].fdup_ion); - gkyl_array_release(coarse_bdata[i].fdup_maxwell); - -#ifdef AMR_DEBUG - gkyl_array_release(fine_bdata[i].fdup_elc); - gkyl_array_release(fine_bdata[i].fdup_ion); - gkyl_array_release(fine_bdata[i].fdup_maxwell); -#endif + gkyl_array_release(mesh_bdata[i].fdup_elc); + gkyl_array_release(mesh_bdata[i].fdup_ion); + gkyl_array_release(mesh_bdata[i].fdup_maxwell); for(int d = 0; d < ndim; d++) { - gkyl_array_release(coarse_bdata[i].f_elc[d]); - gkyl_array_release(coarse_bdata[i].f_ion[d]); - gkyl_array_release(coarse_bdata[i].f_maxwell[d]); - -#ifdef AMR_DEBUG - gkyl_array_release(fine_bdata[i].f_elc[d]); - gkyl_array_release(fine_bdata[i].f_ion[d]); - gkyl_array_release(fine_bdata[i].f_maxwell[d]); -#endif + gkyl_array_release(mesh_bdata[i].f_elc[d]); + gkyl_array_release(mesh_bdata[i].f_ion[d]); + gkyl_array_release(mesh_bdata[i].f_maxwell[d]); } - gkyl_array_release(coarse_bdata[i].app_accel_elc); - gkyl_array_release(coarse_bdata[i].app_accel_ion); - gkyl_array_release(coarse_bdata[i].rhs_source_elc); - gkyl_array_release(coarse_bdata[i].rhs_source_ion); - gkyl_array_release(coarse_bdata[i].ext_em); - gkyl_array_release(coarse_bdata[i].app_current); - gkyl_array_release(coarse_bdata[i].nT_source_elc); - gkyl_array_release(coarse_bdata[i].nT_source_ion); - -#ifdef AMR_DEBUG - gkyl_array_release(fine_bdata[i].app_accel_elc); - gkyl_array_release(fine_bdata[i].app_accel_ion); - gkyl_array_release(fine_bdata[i].rhs_source_elc); - gkyl_array_release(fine_bdata[i].rhs_source_ion); - gkyl_array_release(fine_bdata[i].ext_em); - gkyl_array_release(fine_bdata[i].app_current); - gkyl_array_release(fine_bdata[i].nT_source_elc); - gkyl_array_release(fine_bdata[i].nT_source_ion); -#endif + gkyl_array_release(mesh_bdata[i].app_accel_elc); + gkyl_array_release(mesh_bdata[i].app_accel_ion); + gkyl_array_release(mesh_bdata[i].rhs_source_elc); + gkyl_array_release(mesh_bdata[i].rhs_source_ion); + gkyl_array_release(mesh_bdata[i].ext_em); + gkyl_array_release(mesh_bdata[i].app_current); + gkyl_array_release(mesh_bdata[i].nT_source_elc); + gkyl_array_release(mesh_bdata[i].nT_source_ion); } gkyl_block_topo_release(btopo); gkyl_job_pool_release(coarse_job_pool); -#ifdef AMR_DEBUG - gkyl_job_pool_release(fine_job_pool); -#endif } void @@ -1484,243 +711,77 @@ five_moment_2d_run_double(int argc, char **argv, struct five_moment_2d_double_in int Nx = base_Nx; int Ny = base_Ny; - struct five_moment_block_data coarse_bdata[num_blocks]; + struct five_moment_block_data mesh_bdata[num_blocks]; struct gkyl_job_pool *coarse_job_pool = gkyl_thread_pool_new(app_args.num_threads); -#ifdef AMR_DEBUG - gkyl_rect_grid_init(&coarse_bdata[0].grid, 2, (double []) { refined_x1, refined_y1 }, (double []) { refined_x2, refined_y2 }, - (int []) { Nx, Ny }); - - gkyl_rect_grid_init(&coarse_bdata[1].grid, 2, (double []) { intermediate_x1, refined_y2 }, (double []) { refined_x1, intermediate_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[2].grid, 2, (double []) { refined_x1, refined_y2 }, (double []) { refined_x2, intermediate_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[3].grid, 2, (double []) { refined_x2, refined_y2 }, (double []) { intermediate_x2, intermediate_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[4].grid, 2, (double []) { intermediate_x1, refined_y1 }, (double []) { refined_x1, refined_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[5].grid, 2, (double []) { refined_x2, refined_y1 }, (double []) { intermediate_x2, refined_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[6].grid, 2, (double []) { intermediate_x1, intermediate_y1 }, (double []) { refined_x1, refined_y1 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[7].grid, 2, (double []) { refined_x1, intermediate_y1 }, (double []) { refined_x2, refined_y1 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[8].grid, 2, (double []) { refined_x2, intermediate_y1 }, (double []) { intermediate_x2, refined_y1 }, - (int []) { Nx, Ny }); -#else - gkyl_rect_grid_init(&coarse_bdata[0].grid, 2, (double []) { refined_x1, refined_y1 }, (double []) { refined_x2, refined_y2 }, + gkyl_rect_grid_init(&mesh_bdata[0].grid, 2, (double []) { refined_x1, refined_y1 }, (double []) { refined_x2, refined_y2 }, (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&coarse_bdata[1].grid, 2, (double []) { intermediate_x1, refined_y2 }, (double []) { refined_x1, intermediate_y2 }, + gkyl_rect_grid_init(&mesh_bdata[1].grid, 2, (double []) { intermediate_x1, refined_y2 }, (double []) { refined_x1, intermediate_y2 }, (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&coarse_bdata[2].grid, 2, (double []) { refined_x1, refined_y2 }, (double []) { refined_x2, intermediate_y2 }, + gkyl_rect_grid_init(&mesh_bdata[2].grid, 2, (double []) { refined_x1, refined_y2 }, (double []) { refined_x2, intermediate_y2 }, (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&coarse_bdata[3].grid, 2, (double []) { refined_x2, refined_y2 }, (double []) { intermediate_x2, intermediate_y2 }, + gkyl_rect_grid_init(&mesh_bdata[3].grid, 2, (double []) { refined_x2, refined_y2 }, (double []) { intermediate_x2, intermediate_y2 }, (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&coarse_bdata[4].grid, 2, (double []) { intermediate_x1, refined_y1 }, (double []) { refined_x1, refined_y2 }, + gkyl_rect_grid_init(&mesh_bdata[4].grid, 2, (double []) { intermediate_x1, refined_y1 }, (double []) { refined_x1, refined_y2 }, (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&coarse_bdata[5].grid, 2, (double []) { refined_x2, refined_y1 }, (double []) { intermediate_x2, refined_y2 }, + gkyl_rect_grid_init(&mesh_bdata[5].grid, 2, (double []) { refined_x2, refined_y1 }, (double []) { intermediate_x2, refined_y2 }, (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&coarse_bdata[6].grid, 2, (double []) { intermediate_x1, intermediate_y1 }, (double []) { refined_x1, refined_y1 }, + gkyl_rect_grid_init(&mesh_bdata[6].grid, 2, (double []) { intermediate_x1, intermediate_y1 }, (double []) { refined_x1, refined_y1 }, (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&coarse_bdata[7].grid, 2, (double []) { refined_x1, intermediate_y1 }, (double []) { refined_x2, refined_y1 }, + gkyl_rect_grid_init(&mesh_bdata[7].grid, 2, (double []) { refined_x1, intermediate_y1 }, (double []) { refined_x2, refined_y1 }, (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&coarse_bdata[8].grid, 2, (double []) { refined_x2, intermediate_y1 }, (double []) { intermediate_x2, refined_y1 }, + gkyl_rect_grid_init(&mesh_bdata[8].grid, 2, (double []) { refined_x2, intermediate_y1 }, (double []) { intermediate_x2, refined_y1 }, (int []) { Nx * ref_factor1, Ny * ref_factor1 }); -#endif - gkyl_rect_grid_init(&coarse_bdata[9].grid, 2, (double []) { coarse_x1, intermediate_y2 }, (double []) { intermediate_x1, coarse_y2 }, + gkyl_rect_grid_init(&mesh_bdata[9].grid, 2, (double []) { coarse_x1, intermediate_y2 }, (double []) { intermediate_x1, coarse_y2 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[10].grid, 2, (double []) { intermediate_x1, intermediate_y2 }, (double []) { refined_x1, coarse_y2 }, + gkyl_rect_grid_init(&mesh_bdata[10].grid, 2, (double []) { intermediate_x1, intermediate_y2 }, (double []) { refined_x1, coarse_y2 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[11].grid, 2, (double []) { refined_x1, intermediate_y2 }, (double []) { refined_x2, coarse_y2 }, + gkyl_rect_grid_init(&mesh_bdata[11].grid, 2, (double []) { refined_x1, intermediate_y2 }, (double []) { refined_x2, coarse_y2 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[12].grid, 2, (double []) { refined_x2, intermediate_y2 }, (double []) { intermediate_x2, coarse_y2 }, + gkyl_rect_grid_init(&mesh_bdata[12].grid, 2, (double []) { refined_x2, intermediate_y2 }, (double []) { intermediate_x2, coarse_y2 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[13].grid, 2, (double []) { intermediate_x2, intermediate_y2 }, (double []) { coarse_x2, coarse_y2 }, + gkyl_rect_grid_init(&mesh_bdata[13].grid, 2, (double []) { intermediate_x2, intermediate_y2 }, (double []) { coarse_x2, coarse_y2 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[14].grid, 2, (double []) { coarse_x1, refined_y2 }, (double []) { intermediate_x1, intermediate_y2 }, + gkyl_rect_grid_init(&mesh_bdata[14].grid, 2, (double []) { coarse_x1, refined_y2 }, (double []) { intermediate_x1, intermediate_y2 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[15].grid, 2, (double []) { intermediate_x2, refined_y2 }, (double []) { coarse_x2, intermediate_y2 }, + gkyl_rect_grid_init(&mesh_bdata[15].grid, 2, (double []) { intermediate_x2, refined_y2 }, (double []) { coarse_x2, intermediate_y2 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[16].grid, 2, (double []) { coarse_x1, refined_y1 }, (double []) { intermediate_x1, refined_y2 }, + gkyl_rect_grid_init(&mesh_bdata[16].grid, 2, (double []) { coarse_x1, refined_y1 }, (double []) { intermediate_x1, refined_y2 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[17].grid, 2, (double []) { intermediate_x2, refined_y1 }, (double []) { coarse_x2, refined_y2 }, + gkyl_rect_grid_init(&mesh_bdata[17].grid, 2, (double []) { intermediate_x2, refined_y1 }, (double []) { coarse_x2, refined_y2 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[18].grid, 2, (double []) { coarse_x1, intermediate_y1 }, (double []) { intermediate_x1, refined_y1 }, + gkyl_rect_grid_init(&mesh_bdata[18].grid, 2, (double []) { coarse_x1, intermediate_y1 }, (double []) { intermediate_x1, refined_y1 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[19].grid, 2, (double []) { intermediate_x2, intermediate_y1 }, (double []) { coarse_x2, refined_y1 }, + gkyl_rect_grid_init(&mesh_bdata[19].grid, 2, (double []) { intermediate_x2, intermediate_y1 }, (double []) { coarse_x2, refined_y1 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[20].grid, 2, (double []) { coarse_x1, coarse_y1 }, (double []) { intermediate_x1, intermediate_y1 }, + gkyl_rect_grid_init(&mesh_bdata[20].grid, 2, (double []) { coarse_x1, coarse_y1 }, (double []) { intermediate_x1, intermediate_y1 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[21].grid, 2, (double []) { intermediate_x1, coarse_y1 }, (double []) { refined_x1, intermediate_y1 }, + gkyl_rect_grid_init(&mesh_bdata[21].grid, 2, (double []) { intermediate_x1, coarse_y1 }, (double []) { refined_x1, intermediate_y1 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[22].grid, 2, (double []) { refined_x1, coarse_y1 }, (double []) { refined_x2, intermediate_y1 }, + gkyl_rect_grid_init(&mesh_bdata[22].grid, 2, (double []) { refined_x1, coarse_y1 }, (double []) { refined_x2, intermediate_y1 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[23].grid, 2, (double []) { refined_x2, coarse_y1 }, (double []) { intermediate_x2, intermediate_y1 }, + gkyl_rect_grid_init(&mesh_bdata[23].grid, 2, (double []) { refined_x2, coarse_y1 }, (double []) { intermediate_x2, intermediate_y1 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[24].grid, 2, (double []) { intermediate_x2, coarse_y1 }, (double []) { coarse_x2, intermediate_y1 }, + gkyl_rect_grid_init(&mesh_bdata[24].grid, 2, (double []) { intermediate_x2, coarse_y1 }, (double []) { coarse_x2, intermediate_y1 }, (int []) { Nx, Ny }); -#ifdef AMR_DEBUG - struct five_moment_block_data intermediate_bdata[num_blocks]; - struct gkyl_job_pool *intermediate_job_pool = gkyl_thread_pool_new(app_args.num_threads); - - gkyl_rect_grid_init(&intermediate_bdata[0].grid, 2, (double []) { refined_x1, refined_y1 }, (double []) { refined_x2, refined_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - - gkyl_rect_grid_init(&intermediate_bdata[1].grid, 2, (double []) { coarse_x1, refined_y2 }, (double []) { refined_x1, coarse_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[2].grid, 2, (double []) { refined_x1, refined_y2 }, (double []) { refined_x2, coarse_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[3].grid, 2, (double []) { refined_x2, refined_y2 }, (double []) { coarse_x2, coarse_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[4].grid, 2, (double []) { coarse_x1, refined_y1 }, (double []) { refined_x1, refined_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[5].grid, 2, (double []) { refined_x2, refined_y1 }, (double []) { coarse_x2, refined_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[6].grid, 2, (double []) { coarse_x1, coarse_y1 }, (double []) { refined_x1, refined_y1 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[7].grid, 2, (double []) { refined_x1, coarse_y1 }, (double []) { refined_x2, refined_y1 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[8].grid, 2, (double []) { refined_x2, coarse_y1 }, (double []) { coarse_x2, refined_y1 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - - gkyl_rect_grid_init(&intermediate_bdata[9].grid, 2, (double []) { coarse_x1, intermediate_y2 }, (double []) { intermediate_x1, coarse_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[10].grid, 2, (double []) { intermediate_x1, intermediate_y2 }, (double []) { refined_x1, coarse_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[11].grid, 2, (double []) { refined_x1, intermediate_y2 }, (double []) { refined_x2, coarse_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[12].grid, 2, (double []) { refined_x2, intermediate_y2 }, (double []) { intermediate_x2, coarse_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[13].grid, 2, (double []) { intermediate_x2, intermediate_y2 }, (double []) { coarse_x2, coarse_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[14].grid, 2, (double []) { coarse_x1, refined_y2 }, (double []) { intermediate_x1, intermediate_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[15].grid, 2, (double []) { intermediate_x2, refined_y2 }, (double []) { coarse_x2, intermediate_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[16].grid, 2, (double []) { coarse_x1, refined_y1 }, (double []) { intermediate_x1, refined_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[17].grid, 2, (double []) { intermediate_x2, refined_y1 }, (double []) { coarse_x2, refined_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[18].grid, 2, (double []) { coarse_x1, intermediate_y1 }, (double []) { intermediate_x1, refined_y1 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[19].grid, 2, (double []) { intermediate_x2, intermediate_y1 }, (double []) { coarse_x2, refined_y1 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[20].grid, 2, (double []) { coarse_x1, coarse_y1 }, (double []) { intermediate_x1, intermediate_y1 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[21].grid, 2, (double []) { intermediate_x1, coarse_y1 }, (double []) { refined_x1, intermediate_y1 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[22].grid, 2, (double []) { refined_x1, coarse_y1 }, (double []) { refined_x2, intermediate_y1 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[23].grid, 2, (double []) { refined_x2, coarse_y1 }, (double []) { intermediate_x2, intermediate_y1 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[24].grid, 2, (double []) { intermediate_x2, coarse_y1 }, (double []) { coarse_x2, intermediate_y1 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - - struct five_moment_block_data fine_bdata[num_blocks]; - struct gkyl_job_pool *fine_job_pool = gkyl_thread_pool_new(app_args.num_threads); - - gkyl_rect_grid_init(&fine_bdata[0].grid, 2, (double []) { refined_x1, refined_y1 }, (double []) { refined_x2, refined_y2 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - - gkyl_rect_grid_init(&fine_bdata[1].grid, 2, (double []) { coarse_x1, refined_y2 }, (double []) { refined_x1, coarse_y2 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[2].grid, 2, (double []) { refined_x1, refined_y2 }, (double []) { refined_x2, coarse_y2 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[3].grid, 2, (double []) { refined_x2, refined_y2 }, (double []) { coarse_x2, coarse_y2 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[4].grid, 2, (double []) { coarse_x1, refined_y1 }, (double []) { refined_x1, refined_y2 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[5].grid, 2, (double []) { refined_x2, refined_y1 }, (double []) { coarse_x2, refined_y2 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[6].grid, 2, (double []) { coarse_x1, coarse_y1 }, (double []) { refined_x1, refined_y1 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[7].grid, 2, (double []) { refined_x1, coarse_y1 }, (double []) { refined_x2, refined_y1 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[8].grid, 2, (double []) { refined_x2, coarse_y1 }, (double []) { coarse_x2, refined_y1 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - - gkyl_rect_grid_init(&fine_bdata[9].grid, 2, (double []) { coarse_x1, intermediate_y2 }, (double []) { intermediate_x1, coarse_y2 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[10].grid, 2, (double []) { intermediate_x1, intermediate_y2 }, (double []) { refined_x1, coarse_y2 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[11].grid, 2, (double []) { refined_x1, intermediate_y2 }, (double []) { refined_x2, coarse_y2 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[12].grid, 2, (double []) { refined_x2, intermediate_y2 }, (double []) { intermediate_x2, coarse_y2 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[13].grid, 2, (double []) { intermediate_x2, intermediate_y2 }, (double []) { coarse_x2, coarse_y2 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[14].grid, 2, (double []) { coarse_x1, refined_y2 }, (double []) { intermediate_x1, intermediate_y2 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[15].grid, 2, (double []) { intermediate_x2, refined_y2 }, (double []) { coarse_x2, intermediate_y2 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[16].grid, 2, (double []) { coarse_x1, refined_y1 }, (double []) { intermediate_x1, refined_y2 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[17].grid, 2, (double []) { intermediate_x2, refined_y1 }, (double []) { coarse_x2, refined_y2 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[18].grid, 2, (double []) { coarse_x1, intermediate_y1 }, (double []) { intermediate_x1, refined_y1 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[19].grid, 2, (double []) { intermediate_x2, intermediate_y1 }, (double []) { coarse_x2, refined_y1 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[20].grid, 2, (double []) { coarse_x1, coarse_y1 }, (double []) { intermediate_x1, intermediate_y1 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[21].grid, 2, (double []) { intermediate_x1, coarse_y1 }, (double []) { refined_x1, intermediate_y1 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[22].grid, 2, (double []) { refined_x1, coarse_y1 }, (double []) { refined_x2, intermediate_y1 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[23].grid, 2, (double []) { refined_x2, coarse_y1 }, (double []) { intermediate_x2, intermediate_y1 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[24].grid, 2, (double []) { intermediate_x2, coarse_y1 }, (double []) { coarse_x2, intermediate_y1 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); -#endif - for (int i = 0; i < num_blocks; i++) { - coarse_bdata[i].fv_proj_elc = gkyl_fv_proj_new(&coarse_bdata[i].grid, 2, 5, eval_elc, 0); - coarse_bdata[i].fv_proj_ion = gkyl_fv_proj_new(&coarse_bdata[i].grid, 2, 5, eval_ion, 0); - coarse_bdata[i].fv_proj_maxwell = gkyl_fv_proj_new(&coarse_bdata[i].grid, 2, 8, eval_field, 0); - -#ifdef AMR_DEBUG - intermediate_bdata[i].fv_proj_elc = gkyl_fv_proj_new(&intermediate_bdata[i].grid, 2, 5, eval_elc, 0); - intermediate_bdata[i].fv_proj_ion = gkyl_fv_proj_new(&intermediate_bdata[i].grid, 2, 5, eval_ion, 0); - intermediate_bdata[i].fv_proj_maxwell = gkyl_fv_proj_new(&intermediate_bdata[i].grid, 2, 8, eval_field, 0); - - fine_bdata[i].fv_proj_elc = gkyl_fv_proj_new(&fine_bdata[i].grid, 2, 5, eval_elc, 0); - fine_bdata[i].fv_proj_ion = gkyl_fv_proj_new(&fine_bdata[i].grid, 2, 5, eval_ion, 0); - fine_bdata[i].fv_proj_maxwell = gkyl_fv_proj_new(&fine_bdata[i].grid, 2, 8, eval_field, 0); -#endif + mesh_bdata[i].fv_proj_elc = gkyl_fv_proj_new(&mesh_bdata[i].grid, 2, 5, eval_elc, 0); + mesh_bdata[i].fv_proj_ion = gkyl_fv_proj_new(&mesh_bdata[i].grid, 2, 5, eval_ion, 0); + mesh_bdata[i].fv_proj_maxwell = gkyl_fv_proj_new(&mesh_bdata[i].grid, 2, 8, eval_field, 0); } for (int i = 0; i < num_blocks; i++) { - gkyl_create_grid_ranges(&coarse_bdata[i].grid, (int []) { 2, 2 }, &coarse_bdata[i].ext_range, &coarse_bdata[i].range); - coarse_bdata[i].geom = gkyl_wave_geom_new(&coarse_bdata[i].grid, &coarse_bdata[i].ext_range, 0, 0, false); + gkyl_create_grid_ranges(&mesh_bdata[i].grid, (int []) { 2, 2 }, &mesh_bdata[i].ext_range, &mesh_bdata[i].range); + mesh_bdata[i].geom = gkyl_wave_geom_new(&mesh_bdata[i].grid, &mesh_bdata[i].ext_range, 0, 0, false); - coarse_bdata[i].transmissive_x = transmissive_x; - coarse_bdata[i].transmissive_y = transmissive_y; + mesh_bdata[i].transmissive_x = transmissive_x; + mesh_bdata[i].transmissive_y = transmissive_y; - coarse_bdata[i].wall_x = wall_x; - coarse_bdata[i].wall_y = wall_y; - -#ifdef AMR_DEBUG - gkyl_create_grid_ranges(&intermediate_bdata[i].grid, (int []) { 2, 2 }, &intermediate_bdata[i].ext_range, &intermediate_bdata[i].range); - intermediate_bdata[i].geom = gkyl_wave_geom_new(&intermediate_bdata[i].grid, &intermediate_bdata[i].ext_range, 0, 0, false); - - intermediate_bdata[i].transmissive_x = transmissive_x; - intermediate_bdata[i].transmissive_y = transmissive_y; - - intermediate_bdata[i].wall_x = wall_x; - intermediate_bdata[i].wall_y = wall_y; - - gkyl_create_grid_ranges(&fine_bdata[i].grid, (int []) { 2, 2 }, &fine_bdata[i].ext_range, &fine_bdata[i].range); - fine_bdata[i].geom = gkyl_wave_geom_new(&fine_bdata[i].grid, &fine_bdata[i].ext_range, 0, 0, false); - - fine_bdata[i].transmissive_x = transmissive_x; - fine_bdata[i].transmissive_y = transmissive_y; - - fine_bdata[i].wall_x = wall_x; - fine_bdata[i].wall_y = wall_y; -#endif + mesh_bdata[i].wall_x = wall_x; + mesh_bdata[i].wall_y = wall_y; } for (int i = 0; i < num_blocks; i++) { @@ -1730,433 +791,119 @@ five_moment_2d_run_double(int argc, char **argv, struct five_moment_2d_double_in .rp_type = WV_EULER_RP_HLL, .use_gpu = app_args.use_gpu, }; - coarse_bdata[i].euler_elc = gkyl_wv_euler_inew(&inp); - coarse_bdata[i].euler_ion = gkyl_wv_euler_inew(&inp); + mesh_bdata[i].euler_elc = gkyl_wv_euler_inew(&inp); + mesh_bdata[i].euler_ion = gkyl_wv_euler_inew(&inp); } else { - coarse_bdata[i].euler_elc = gkyl_wv_euler_new(gas_gamma, app_args.use_gpu); - coarse_bdata[i].euler_ion = gkyl_wv_euler_new(gas_gamma, app_args.use_gpu); + mesh_bdata[i].euler_elc = gkyl_wv_euler_new(gas_gamma, app_args.use_gpu); + mesh_bdata[i].euler_ion = gkyl_wv_euler_new(gas_gamma, app_args.use_gpu); } - coarse_bdata[i].maxwell = gkyl_wv_maxwell_new(light_speed, e_fact, b_fact); + mesh_bdata[i].maxwell = gkyl_wv_maxwell_new(light_speed, e_fact, b_fact); for (int d = 0; d < ndim; d++) { - coarse_bdata[i].slvr_elc[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &coarse_bdata[i].grid, - .equation = coarse_bdata[i].euler_elc, + mesh_bdata[i].slvr_elc[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { + .grid = &mesh_bdata[i].grid, + .equation = mesh_bdata[i].euler_elc, .limiter = GKYL_MONOTONIZED_CENTERED, .num_up_dirs = 1, .update_dirs = { d }, .cfl = cfl_frac, - .geom = coarse_bdata[i].geom, + .geom = mesh_bdata[i].geom, } ); - coarse_bdata[i].slvr_ion[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &coarse_bdata[i].grid, - .equation = coarse_bdata[i].euler_ion, + mesh_bdata[i].slvr_ion[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { + .grid = &mesh_bdata[i].grid, + .equation = mesh_bdata[i].euler_ion, .limiter = GKYL_MONOTONIZED_CENTERED, .num_up_dirs = 1, .update_dirs = { d }, .cfl = cfl_frac, - .geom = coarse_bdata[i].geom, + .geom = mesh_bdata[i].geom, } ); - coarse_bdata[i].slvr_maxwell[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &coarse_bdata[i].grid, - .equation = coarse_bdata[i].maxwell, + mesh_bdata[i].slvr_maxwell[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { + .grid = &mesh_bdata[i].grid, + .equation = mesh_bdata[i].maxwell, .limiter = GKYL_MONOTONIZED_CENTERED, .num_up_dirs = 1, .update_dirs = { d }, .cfl = cfl_frac, - .geom = coarse_bdata[i].geom, + .geom = mesh_bdata[i].geom, } ); } struct gkyl_moment_em_coupling_inp coarse_src_inp = { - .grid = &coarse_bdata[i].grid, + .grid = &mesh_bdata[i].grid, .nfluids = 2, .epsilon0 = epsilon0, }; coarse_src_inp.param[0] = (struct gkyl_moment_em_coupling_data) { - .type = coarse_bdata[i].euler_elc->type, + .type = mesh_bdata[i].euler_elc->type, .charge = charge_elc, .mass = mass_elc, .k0 = k0_elc, }; coarse_src_inp.param[1] = (struct gkyl_moment_em_coupling_data) { - .type = coarse_bdata[i].euler_ion->type, - .charge = charge_ion, - .mass = mass_ion, - .k0 = k0_ion, - }; - - coarse_bdata[i].src_slvr = gkyl_moment_em_coupling_new(coarse_src_inp); - -#ifdef AMR_DEBUG - if (low_order_flux) { - struct gkyl_wv_euler_inp inp = { - .gas_gamma = gas_gamma, - .rp_type = WV_EULER_RP_HLL, - .use_gpu = app_args.use_gpu, - }; - intermediate_bdata[i].euler_elc = gkyl_wv_euler_inew(&inp); - intermediate_bdata[i].euler_ion = gkyl_wv_euler_inew(&inp); - - fine_bdata[i].euler_elc = gkyl_wv_euler_inew(&inp); - fine_bdata[i].euler_ion = gkyl_wv_euler_inew(&inp); - } - else { - intermediate_bdata[i].euler_elc = gkyl_wv_euler_new(gas_gamma, app_args.use_gpu); - intermediate_bdata[i].euler_ion = gkyl_wv_euler_new(gas_gamma, app_args.use_gpu); - - fine_bdata[i].euler_elc = gkyl_wv_euler_new(gas_gamma, app_args.use_gpu); - fine_bdata[i].euler_ion = gkyl_wv_euler_new(gas_gamma, app_args.use_gpu); - } - intermediate_bdata[i].maxwell = gkyl_wv_maxwell_new(light_speed, e_fact, b_fact); - fine_bdata[i].maxwell = gkyl_wv_maxwell_new(light_speed, e_fact, b_fact); - - for (int d = 0; d < ndim; d++) { - fine_bdata[i].slvr_elc[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &fine_bdata[i].grid, - .equation = fine_bdata[i].euler_elc, - .limiter = GKYL_MONOTONIZED_CENTERED, - .num_up_dirs = 1, - .update_dirs = { d }, - .cfl = cfl_frac, - .geom = fine_bdata[i].geom, - } - ); - fine_bdata[i].slvr_ion[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &fine_bdata[i].grid, - .equation = fine_bdata[i].euler_ion, - .limiter = GKYL_MONOTONIZED_CENTERED, - .num_up_dirs = 1, - .update_dirs = { d }, - .cfl = cfl_frac, - .geom = fine_bdata[i].geom, - } - ); - fine_bdata[i].slvr_maxwell[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &fine_bdata[i].grid, - .equation = fine_bdata[i].maxwell, - .limiter = GKYL_MONOTONIZED_CENTERED, - .num_up_dirs = 1, - .update_dirs = { d }, - .cfl = cfl_frac, - .geom = fine_bdata[i].geom, - } - ); - } - - struct gkyl_moment_em_coupling_inp fine_src_inp = { - .grid = &fine_bdata[i].grid, - .nfluids = 2, - .epsilon0 = epsilon0, - }; - - fine_src_inp.param[0] = (struct gkyl_moment_em_coupling_data) { - .type = fine_bdata[i].euler_elc->type, - .charge = charge_elc, - .mass = mass_elc, - .k0 = k0_elc, - }; - fine_src_inp.param[1] = (struct gkyl_moment_em_coupling_data) { - .type = fine_bdata[i].euler_ion->type, - .charge = charge_ion, - .mass = mass_ion, - .k0 = k0_ion, - }; - - fine_bdata[i].src_slvr = gkyl_moment_em_coupling_new(fine_src_inp); - - for (int d = 0; d < ndim; d++) { - intermediate_bdata[i].slvr_elc[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &intermediate_bdata[i].grid, - .equation = intermediate_bdata[i].euler_elc, - .limiter = GKYL_MONOTONIZED_CENTERED, - .num_up_dirs = 1, - .update_dirs = { d }, - .cfl = cfl_frac, - .geom = intermediate_bdata[i].geom, - } - ); - intermediate_bdata[i].slvr_ion[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &intermediate_bdata[i].grid, - .equation = intermediate_bdata[i].euler_ion, - .limiter = GKYL_MONOTONIZED_CENTERED, - .num_up_dirs = 1, - .update_dirs = { d }, - .cfl = cfl_frac, - .geom = intermediate_bdata[i].geom, - } - ); - intermediate_bdata[i].slvr_maxwell[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &intermediate_bdata[i].grid, - .equation = intermediate_bdata[i].maxwell, - .limiter = GKYL_MONOTONIZED_CENTERED, - .num_up_dirs = 1, - .update_dirs = { d }, - .cfl = cfl_frac, - .geom = intermediate_bdata[i].geom, - } - ); - } - - struct gkyl_moment_em_coupling_inp intermediate_src_inp = { - .grid = &intermediate_bdata[i].grid, - .nfluids = 2, - .epsilon0 = epsilon0, - }; - - intermediate_src_inp.param[0] = (struct gkyl_moment_em_coupling_data) { - .type = intermediate_bdata[i].euler_elc->type, - .charge = charge_elc, - .mass = mass_elc, - .k0 = k0_elc, - }; - intermediate_src_inp.param[1] = (struct gkyl_moment_em_coupling_data) { - .type = intermediate_bdata[i].euler_ion->type, + .type = mesh_bdata[i].euler_ion->type, .charge = charge_ion, .mass = mass_ion, .k0 = k0_ion, }; - intermediate_bdata[i].src_slvr = gkyl_moment_em_coupling_new(intermediate_src_inp); -#endif + mesh_bdata[i].src_slvr = gkyl_moment_em_coupling_new(coarse_src_inp); } struct gkyl_block_topo *btopo = create_nested_block_topo(); for (int i = 0; i < num_blocks; i++) { - five_moment_nested_block_bc_updaters_init(&coarse_bdata[i], &btopo->conn[i]); - -#ifdef AMR_DEBUG - five_moment_nested_block_bc_updaters_init(&intermediate_bdata[i], &btopo->conn[i]); - five_moment_nested_block_bc_updaters_init(&fine_bdata[i], &btopo->conn[i]); -#endif + five_moment_nested_block_bc_updaters_init(&mesh_bdata[i], &btopo->conn[i]); } for (int i = 0; i < num_blocks; i++) { - coarse_bdata[i].fdup_elc = gkyl_array_new(GKYL_DOUBLE, 5, coarse_bdata[i].ext_range.volume); - coarse_bdata[i].fdup_ion = gkyl_array_new(GKYL_DOUBLE, 5, coarse_bdata[i].ext_range.volume); - coarse_bdata[i].fdup_maxwell = gkyl_array_new(GKYL_DOUBLE, 8, coarse_bdata[i].ext_range.volume); - - for (int d = 0; d < ndim + 1; d++) { - coarse_bdata[i].f_elc[d] = gkyl_array_new(GKYL_DOUBLE, 5, coarse_bdata[i].ext_range.volume); - coarse_bdata[i].f_ion[d] = gkyl_array_new(GKYL_DOUBLE, 5, coarse_bdata[i].ext_range.volume); - coarse_bdata[i].f_maxwell[d] = gkyl_array_new(GKYL_DOUBLE, 8, coarse_bdata[i].ext_range.volume); - } - - coarse_bdata[i].app_accel_elc = gkyl_array_new(GKYL_DOUBLE, 3, coarse_bdata[i].ext_range.volume); - coarse_bdata[i].app_accel_ion = gkyl_array_new(GKYL_DOUBLE, 3, coarse_bdata[i].ext_range.volume); - coarse_bdata[i].rhs_source_elc = gkyl_array_new(GKYL_DOUBLE, 5, coarse_bdata[i].ext_range.volume); - coarse_bdata[i].rhs_source_ion = gkyl_array_new(GKYL_DOUBLE, 5, coarse_bdata[i].ext_range.volume); - coarse_bdata[i].ext_em = gkyl_array_new(GKYL_DOUBLE, 6, coarse_bdata[i].ext_range.volume); - coarse_bdata[i].app_current = gkyl_array_new(GKYL_DOUBLE, 3, coarse_bdata[i].ext_range.volume); - coarse_bdata[i].nT_source_elc = gkyl_array_new(GKYL_DOUBLE, 2, coarse_bdata[i].ext_range.volume); - coarse_bdata[i].nT_source_ion = gkyl_array_new(GKYL_DOUBLE, 2, coarse_bdata[i].ext_range.volume); - -#ifdef AMR_DEBUG - intermediate_bdata[i].fdup_elc = gkyl_array_new(GKYL_DOUBLE, 5, intermediate_bdata[i].ext_range.volume); - intermediate_bdata[i].fdup_ion = gkyl_array_new(GKYL_DOUBLE, 5, intermediate_bdata[i].ext_range.volume); - intermediate_bdata[i].fdup_maxwell = gkyl_array_new(GKYL_DOUBLE, 8, intermediate_bdata[i].ext_range.volume); + mesh_bdata[i].fdup_elc = gkyl_array_new(GKYL_DOUBLE, 5, mesh_bdata[i].ext_range.volume); + mesh_bdata[i].fdup_ion = gkyl_array_new(GKYL_DOUBLE, 5, mesh_bdata[i].ext_range.volume); + mesh_bdata[i].fdup_maxwell = gkyl_array_new(GKYL_DOUBLE, 8, mesh_bdata[i].ext_range.volume); for (int d = 0; d < ndim + 1; d++) { - intermediate_bdata[i].f_elc[d] = gkyl_array_new(GKYL_DOUBLE, 5, intermediate_bdata[i].ext_range.volume); - intermediate_bdata[i].f_ion[d] = gkyl_array_new(GKYL_DOUBLE, 5, intermediate_bdata[i].ext_range.volume); - intermediate_bdata[i].f_maxwell[d] = gkyl_array_new(GKYL_DOUBLE, 8, intermediate_bdata[i].ext_range.volume); + mesh_bdata[i].f_elc[d] = gkyl_array_new(GKYL_DOUBLE, 5, mesh_bdata[i].ext_range.volume); + mesh_bdata[i].f_ion[d] = gkyl_array_new(GKYL_DOUBLE, 5, mesh_bdata[i].ext_range.volume); + mesh_bdata[i].f_maxwell[d] = gkyl_array_new(GKYL_DOUBLE, 8, mesh_bdata[i].ext_range.volume); } - intermediate_bdata[i].app_accel_elc = gkyl_array_new(GKYL_DOUBLE, 3, intermediate_bdata[i].ext_range.volume); - intermediate_bdata[i].app_accel_ion = gkyl_array_new(GKYL_DOUBLE, 3, intermediate_bdata[i].ext_range.volume); - intermediate_bdata[i].rhs_source_elc = gkyl_array_new(GKYL_DOUBLE, 5, intermediate_bdata[i].ext_range.volume); - intermediate_bdata[i].rhs_source_ion = gkyl_array_new(GKYL_DOUBLE, 5, intermediate_bdata[i].ext_range.volume); - intermediate_bdata[i].ext_em = gkyl_array_new(GKYL_DOUBLE, 6, intermediate_bdata[i].ext_range.volume); - intermediate_bdata[i].app_current = gkyl_array_new(GKYL_DOUBLE, 3, intermediate_bdata[i].ext_range.volume); - intermediate_bdata[i].nT_source_elc = gkyl_array_new(GKYL_DOUBLE, 2, intermediate_bdata[i].ext_range.volume); - intermediate_bdata[i].nT_source_ion = gkyl_array_new(GKYL_DOUBLE, 2, intermediate_bdata[i].ext_range.volume); - - fine_bdata[i].fdup_elc = gkyl_array_new(GKYL_DOUBLE, 5, fine_bdata[i].ext_range.volume); - fine_bdata[i].fdup_ion = gkyl_array_new(GKYL_DOUBLE, 5, fine_bdata[i].ext_range.volume); - fine_bdata[i].fdup_maxwell = gkyl_array_new(GKYL_DOUBLE, 8, fine_bdata[i].ext_range.volume); - - for (int d = 0; d < ndim + 1; d++) { - fine_bdata[i].f_elc[d] = gkyl_array_new(GKYL_DOUBLE, 5, fine_bdata[i].ext_range.volume); - fine_bdata[i].f_ion[d] = gkyl_array_new(GKYL_DOUBLE, 5, fine_bdata[i].ext_range.volume); - fine_bdata[i].f_maxwell[d] = gkyl_array_new(GKYL_DOUBLE, 8, fine_bdata[i].ext_range.volume); - } - - fine_bdata[i].app_accel_elc = gkyl_array_new(GKYL_DOUBLE, 3, fine_bdata[i].ext_range.volume); - fine_bdata[i].app_accel_ion = gkyl_array_new(GKYL_DOUBLE, 3, fine_bdata[i].ext_range.volume); - fine_bdata[i].rhs_source_elc = gkyl_array_new(GKYL_DOUBLE, 5, fine_bdata[i].ext_range.volume); - fine_bdata[i].rhs_source_ion = gkyl_array_new(GKYL_DOUBLE, 5, fine_bdata[i].ext_range.volume); - fine_bdata[i].ext_em = gkyl_array_new(GKYL_DOUBLE, 6, fine_bdata[i].ext_range.volume); - fine_bdata[i].app_current = gkyl_array_new(GKYL_DOUBLE, 3, fine_bdata[i].ext_range.volume); - fine_bdata[i].nT_source_elc = gkyl_array_new(GKYL_DOUBLE, 2, fine_bdata[i].ext_range.volume); - fine_bdata[i].nT_source_ion = gkyl_array_new(GKYL_DOUBLE, 2, fine_bdata[i].ext_range.volume); -#endif + mesh_bdata[i].app_accel_elc = gkyl_array_new(GKYL_DOUBLE, 3, mesh_bdata[i].ext_range.volume); + mesh_bdata[i].app_accel_ion = gkyl_array_new(GKYL_DOUBLE, 3, mesh_bdata[i].ext_range.volume); + mesh_bdata[i].rhs_source_elc = gkyl_array_new(GKYL_DOUBLE, 5, mesh_bdata[i].ext_range.volume); + mesh_bdata[i].rhs_source_ion = gkyl_array_new(GKYL_DOUBLE, 5, mesh_bdata[i].ext_range.volume); + mesh_bdata[i].ext_em = gkyl_array_new(GKYL_DOUBLE, 6, mesh_bdata[i].ext_range.volume); + mesh_bdata[i].app_current = gkyl_array_new(GKYL_DOUBLE, 3, mesh_bdata[i].ext_range.volume); + mesh_bdata[i].nT_source_elc = gkyl_array_new(GKYL_DOUBLE, 2, mesh_bdata[i].ext_range.volume); + mesh_bdata[i].nT_source_ion = gkyl_array_new(GKYL_DOUBLE, 2, mesh_bdata[i].ext_range.volume); } #ifdef AMR_USETHREADS for (int i = 0; i < num_blocks; i++) { - gkyl_job_pool_add_work(coarse_job_pool, five_moment_init_job_func_block, &coarse_bdata[i]); - -#ifdef AMR_DEBUG - gkyl_job_pool_add_work(intermediate_job_pool, five_moment_init_job_func_block, &intermediate_bdata[i]); - gkyl_job_pool_add_work(fine_job_pool, five_moment_init_job_func_block, &fine_bdata[i]); -#endif + gkyl_job_pool_add_work(coarse_job_pool, five_moment_init_job_func_block, &mesh_bdata[i]); } gkyl_job_pool_wait(coarse_job_pool); - -#ifdef AMR_DEBUG - gkyl_job_pool_wait(intermediate_job_pool); - gkyl_job_pool_wait(fine_job_pool); -#endif #else for (int i = 0; i < num_blocks; i++) { - five_moment_init_job_func_block(&coarse_bdata[i]); - -#ifdef AMR_DEBUG - five_moment_init_job_func_block(&intermediate_bdata[i]); - five_moment_init_job_func_block(&fine_bdata[i]); -#endif + five_moment_init_job_func_block(&mesh_bdata[i]); } #endif -#ifdef AMR_DEBUG - char coarse0[64]; - snprintf(coarse0, 64, "%s_coarse_0", five_moment_output); - five_moment_write_sol_block(coarse0, num_blocks, coarse_bdata); - - char intermediate0[64]; - snprintf(intermediate0, 64, "%s_intermediate_0", five_moment_output); - five_moment_write_sol_block(intermediate0, num_blocks, intermediate_bdata); - - char fine0[64]; - snprintf(fine0, 64, "%s_fine_0", five_moment_output); - five_moment_write_sol_block(fine0, num_blocks, fine_bdata); - - char fine0_elc_b0[64], fine0_ion_b0[64], fine0_field_b0[64]; - char intermediate0_elc_b0[64], intermediate0_ion_b0[64], intermediate0_field_b0[64]; - char coarse0_elc_b0[64], coarse0_ion_b0[64], coarse0_field_b0[64]; - char b0_elc[64], b0_ion[64], b0_field[64]; - - snprintf(fine0_elc_b0, 64, "%s_fine_0_elc_b0.gkyl", five_moment_output); - snprintf(fine0_ion_b0, 64, "%s_fine_0_ion_b0.gkyl", five_moment_output); - snprintf(fine0_field_b0, 64, "%s_fine_0_field_b0.gkyl", five_moment_output); - - snprintf(intermediate0_elc_b0, 64, "%s_intermediate_0_elc_b0.gkyl", five_moment_output); - snprintf(intermediate0_ion_b0, 64, "%s_intermediate_0_ion_b0.gkyl", five_moment_output); - snprintf(intermediate0_field_b0, 64, "%s_intermediate_0_field_b0.gkyl", five_moment_output); - - snprintf(coarse0_elc_b0, 64, "%s_coarse_0_elc_b0.gkyl", five_moment_output); - snprintf(coarse0_ion_b0, 64, "%s_coarse_0_ion_b0.gkyl", five_moment_output); - snprintf(coarse0_field_b0, 64, "%s_coarse_0_field_b0.gkyl", five_moment_output); - - snprintf(b0_elc, 64, "%s_0_elc_b0.gkyl", five_moment_output); - snprintf(b0_ion, 64, "%s_0_ion_b0.gkyl", five_moment_output); - snprintf(b0_field, 64, "%s_0_field_b0.gkyl", five_moment_output); - - rename(fine0_elc_b0, b0_elc); - rename(fine0_ion_b0, b0_ion); - rename(fine0_field_b0, b0_field); - - remove(intermediate0_elc_b0); - remove(intermediate0_ion_b0); - remove(intermediate0_field_b0); - - remove(coarse0_elc_b0); - remove(coarse0_ion_b0); - remove(coarse0_field_b0); - - for (int i = 1; i < 9; i++) { - char fine0_elc_bi[64], fine0_ion_bi[64], fine0_field_bi[64]; - char intermediate0_elc_bi[64], intermediate0_ion_bi[64], intermediate0_field_bi[64]; - char coarse0_elc_bi[64], coarse0_ion_bi[64], coarse0_field_bi[64]; - char elc_bi[64], ion_bi[64], field_bi[64]; - - snprintf(fine0_elc_bi, 64, "%s_fine_0_elc_b%d.gkyl", five_moment_output, i); - snprintf(fine0_ion_bi, 64, "%s_fine_0_ion_b%d.gkyl", five_moment_output, i); - snprintf(fine0_field_bi, 64, "%s_fine_0_field_b%d.gkyl", five_moment_output, i); - - snprintf(intermediate0_elc_bi, 64, "%s_intermediate_0_elc_b%d.gkyl", five_moment_output, i); - snprintf(intermediate0_ion_bi, 64, "%s_intermediate_0_ion_b%d.gkyl", five_moment_output, i); - snprintf(intermediate0_field_bi, 64, "%s_intermediate_0_field_b%d.gkyl", five_moment_output, i); - - snprintf(coarse0_elc_bi, 64, "%s_coarse_0_elc_b%d.gkyl", five_moment_output, i); - snprintf(coarse0_ion_bi, 64, "%s_coarse_0_ion_b%d.gkyl", five_moment_output, i); - snprintf(coarse0_field_bi, 64, "%s_coarse_0_field_b%d.gkyl", five_moment_output, i); - - snprintf(elc_bi, 64, "%s_0_elc_b%d.gkyl", five_moment_output, i); - snprintf(ion_bi, 64, "%s_0_ion_b%d.gkyl", five_moment_output, i); - snprintf(field_bi, 64, "%s_0_field_b%d.gkyl", five_moment_output, i); - - rename(intermediate0_elc_bi, elc_bi); - rename(intermediate0_ion_bi, ion_bi); - rename(intermediate0_field_bi, field_bi); - - remove(fine0_elc_bi); - remove(fine0_ion_bi); - remove(fine0_field_bi); - - remove(coarse0_elc_bi); - remove(coarse0_ion_bi); - remove(coarse0_field_bi); - } - - for (int i = 9; i < 25; i++) { - char buf_old_elc[64], buf_old_ion[64], buf_old_field[64]; - char buf_new_elc[64], buf_new_ion[64], buf_new_field[64]; - char buf_del1_elc[64], buf_del1_ion[64], buf_del1_field[64]; - char buf_del2_elc[64], buf_del2_ion[64], buf_del2_field[64]; - - snprintf(buf_old_elc, 64, "%s_coarse_0_elc_b%d.gkyl", five_moment_output, i); - snprintf(buf_old_ion, 64, "%s_coarse_0_ion_b%d.gkyl", five_moment_output, i); - snprintf(buf_old_field, 64, "%s_coarse_0_field_b%d.gkyl", five_moment_output, i); - - snprintf(buf_new_elc, 64, "%s_0_elc_b%d.gkyl", five_moment_output, i); - snprintf(buf_new_ion, 64, "%s_0_ion_b%d.gkyl", five_moment_output, i); - snprintf(buf_new_field, 64, "%s_0_field_b%d.gkyl", five_moment_output, i); - - snprintf(buf_del1_elc, 64, "%s_intermediate_0_elc_b%d.gkyl", five_moment_output, i); - snprintf(buf_del1_ion, 64, "%s_intermediate_0_ion_b%d.gkyl", five_moment_output, i); - snprintf(buf_del1_field, 64, "%s_intermediate_0_field_b%d.gkyl", five_moment_output, i); - - snprintf(buf_del2_elc, 64, "%s_fine_0_elc_b%d.gkyl", five_moment_output, i); - snprintf(buf_del2_ion, 64, "%s_fine_0_ion_b%d.gkyl", five_moment_output, i); - snprintf(buf_del2_field, 64, "%s_fine_0_field_b%d.gkyl", five_moment_output, i); - - rename(buf_old_elc, buf_new_elc); - rename(buf_old_ion, buf_new_ion); - rename(buf_old_field, buf_new_field); - - remove(buf_del1_elc); - remove(buf_del1_ion); - remove(buf_del1_field); - - remove(buf_del2_elc); - remove(buf_del2_ion); - remove(buf_del2_field); - } -#else char amr0[64]; snprintf(amr0, 64, "%s_0", five_moment_output); - five_moment_write_sol_block(amr0, num_blocks, coarse_bdata); -#endif + five_moment_write_sol_block(amr0, num_blocks, mesh_bdata); double coarse_t_curr = 0.0; double intermediate_t_curr = 0.0; double fine_t_curr = 0.0; - double coarse_dt = five_moment_max_dt_block(num_blocks, coarse_bdata); + double coarse_dt = five_moment_max_dt_block(num_blocks, mesh_bdata); -#ifdef AMR_DEBUG - double intermediate_dt = five_moment_max_dt_block(num_blocks, intermediate_bdata); - double fine_dt = five_moment_max_dt_block(num_blocks, fine_bdata); -#else double intermediate_dt = (1.0 / ref_factor1) * coarse_dt; double fine_dt = (1.0 / (ref_factor1 * ref_factor2)) * coarse_dt; -#endif struct sim_stats stats = { }; @@ -2172,7 +919,7 @@ five_moment_2d_run_double(int argc, char **argv, struct five_moment_2d_double_in while ((coarse_t_curr < t_end) && (coarse_step <= num_steps)) { printf("Taking coarse (level 0) time-step %ld at t = %g; ", coarse_step, coarse_t_curr); - struct gkyl_update_status coarse_status = five_moment_update_block(coarse_job_pool, btopo, coarse_bdata, coarse_t_curr, coarse_dt, &stats); + struct gkyl_update_status coarse_status = five_moment_update_block(coarse_job_pool, btopo, mesh_bdata, coarse_t_curr, coarse_dt, &stats); printf(" dt = %g\n", coarse_status.dt_actual); if (!coarse_status.success) { @@ -2181,33 +928,6 @@ five_moment_2d_run_double(int argc, char **argv, struct five_moment_2d_double_in } for (long intermediate_step = 1; intermediate_step < ref_factor1 + 1; intermediate_step++) { -#ifdef AMR_DEBUG - printf(" Taking intermediate (level 1) time-step %ld at t = %g; ", intermediate_step, intermediate_t_curr); - struct gkyl_update_status intermediate_status = five_moment_update_block(intermediate_job_pool, btopo, intermediate_bdata, intermediate_t_curr, intermediate_dt, &stats); - printf(" dt = %g\n", intermediate_status.dt_actual); - - if (!intermediate_status.success) { - printf("** Update method failed! Aborting simulation ....\n"); - break; - } - - for (long fine_step = 1; fine_step < ref_factor2 + 1; fine_step++) { - printf(" Taking fine (level 2) time-step %ld at t = %g", fine_step, fine_t_curr); - struct gkyl_update_status fine_status = five_moment_update_block(fine_job_pool, btopo, fine_bdata, fine_t_curr, fine_dt, &stats); - printf(" dt = %g\n", fine_status.dt_actual); - - if (!fine_status.success) { - printf("** Update method failed! Aborting simulation ....\n"); - break; - } - - fine_t_curr += fine_status.dt_actual; - fine_dt = fine_status.dt_suggested; - } - - intermediate_t_curr += intermediate_status.dt_actual; - intermediate_dt += intermediate_status.dt_suggested; -#else printf(" Taking intermediate (level 1) time-step %ld at t = %g", intermediate_step, intermediate_t_curr); printf(" dt = %g\n", (1.0 / ref_factor1) * coarse_status.dt_actual); @@ -2221,132 +941,14 @@ five_moment_2d_run_double(int argc, char **argv, struct five_moment_2d_double_in intermediate_t_curr += (1.0 / ref_factor1) * coarse_status.dt_actual; intermediate_dt = (1.0 / ref_factor1) * coarse_status.dt_suggested; -#endif } for (int i = 1; i < num_frames; i++) { if (coarse_t_curr < (i * io_trigger) && (coarse_t_curr + coarse_status.dt_actual) > (i * io_trigger)) { -#ifdef AMR_DEBUG - char buf_coarse[64]; - char buf_intermediate[64]; - char buf_fine[64]; - - snprintf(buf_coarse, 64, "%s_coarse_%d", five_moment_output, i); - snprintf(buf_intermediate, 64, "%s_intermediate_%d", five_moment_output, i); - snprintf(buf_fine, 64, "%s_fine_%d", five_moment_output, i); - - five_moment_write_sol_block(buf_coarse, num_blocks, coarse_bdata); - five_moment_write_sol_block(buf_intermediate, num_blocks, intermediate_bdata); - five_moment_write_sol_block(buf_fine, num_blocks, fine_bdata); - - char buf_fine_old_elc[64], buf_fine_old_ion[64], buf_fine_old_field[64]; - char buf_intermediate_old_elc[64], buf_intermediate_old_ion[64], buf_intermediate_old_field[64]; - char buf_fine_new_elc[64], buf_fine_new_ion[64], buf_fine_new_field[64]; - char buf_coarse_old_elc[64], buf_coarse_old_ion[64], buf_coarse_old_field[64]; - - snprintf(buf_fine_old_elc, 64, "%s_fine_%d_elc_b0.gkyl", five_moment_output, i); - snprintf(buf_fine_old_ion, 64, "%s_fine_%d_ion_b0.gkyl", five_moment_output, i); - snprintf(buf_fine_old_field, 64, "%s_fine_%d_field_b0.gkyl", five_moment_output, i); - - snprintf(buf_intermediate_old_elc, 64, "%s_intermediate_%d_elc_b0.gkyl", five_moment_output, i); - snprintf(buf_intermediate_old_ion, 64, "%s_intermediate_%d_ion_b0.gkyl", five_moment_output, i); - snprintf(buf_intermediate_old_field, 64, "%s_intermediate_%d_field_b0.gkyl", five_moment_output, i); - - snprintf(buf_fine_new_elc, 64, "%s_%d_elc_b0.gkyl", five_moment_output, i); - snprintf(buf_fine_new_ion, 64, "%s_%d_ion_b0.gkyl", five_moment_output, i); - snprintf(buf_fine_new_field, 64, "%s_%d_field_b0.gkyl", five_moment_output, i); - - snprintf(buf_coarse_old_elc, 64, "%s_coarse_%d_elc_b0.gkyl", five_moment_output, i); - snprintf(buf_coarse_old_ion, 64, "%s_coarse_%d_ion_b0.gkyl", five_moment_output, i); - snprintf(buf_coarse_old_field, 64, "%s_coarse_%d_field_b0.gkyl", five_moment_output, i); - - rename(buf_fine_old_elc, buf_fine_new_elc); - rename(buf_fine_old_ion, buf_fine_new_ion); - rename(buf_fine_old_field, buf_fine_new_field); - - remove(buf_intermediate_old_elc); - remove(buf_intermediate_old_ion); - remove(buf_intermediate_old_field); - - remove(buf_coarse_old_elc); - remove(buf_coarse_old_ion); - remove(buf_coarse_old_field); - - for (int j = 1; j < 8; j++) { - char fine0_elc_bi[64], fine0_ion_bi[64], fine0_field_bi[64]; - char intermediate0_elc_bi[64], intermediate0_ion_bi[64], intermediate0_field_bi[64]; - char coarse0_elc_bi[64], coarse0_ion_bi[64], coarse0_field_bi[64]; - char elc_bi[64], ion_bi[64], field_bi[64]; - - snprintf(fine0_elc_bi, 64, "%s_fine_%d_elc_b%d.gkyl", five_moment_output, i, j); - snprintf(fine0_ion_bi, 64, "%s_fine_%d_ion_b%d.gkyl", five_moment_output, i, j); - snprintf(fine0_field_bi, 64, "%s_fine_%d_field_b%d.gkyl", five_moment_output, i, j); - - snprintf(intermediate0_elc_bi, 64, "%s_intermediate_%d_elc_b%d.gkyl", five_moment_output, i, j); - snprintf(intermediate0_ion_bi, 64, "%s_intermediate_%d_ion_b%d.gkyl", five_moment_output, i, j); - snprintf(intermediate0_field_bi, 64, "%s_intermediate_%d_field_b%d.gkyl", five_moment_output, i, j); - - snprintf(coarse0_elc_bi, 64, "%s_coarse_%d_elc_b%d.gkyl", five_moment_output, i, j); - snprintf(coarse0_ion_bi, 64, "%s_coarse_%d_ion_b%d.gkyl", five_moment_output, i, j); - snprintf(coarse0_field_bi, 64, "%s_coarse_%d_field_b%d.gkyl", five_moment_output, i, j); - - snprintf(elc_bi, 64, "%s_%d_elc_b%d.gkyl", five_moment_output, i, j); - snprintf(ion_bi, 64, "%s_%d_ion_b%d.gkyl", five_moment_output, i, j); - snprintf(field_bi, 64, "%s_%d_field_b%d.gkyl", five_moment_output, i, j); - - rename(intermediate0_elc_bi, elc_bi); - rename(intermediate0_ion_bi, ion_bi); - rename(intermediate0_field_bi, field_bi); - - remove(fine0_elc_bi); - remove(fine0_ion_bi); - remove(fine0_field_bi); - - remove(coarse0_elc_bi); - remove(coarse0_ion_bi); - remove(coarse0_field_bi); - } - - for (int j = 9; j < 25; j++) { - char buf_old_elc[64], buf_old_ion[64], buf_old_field[64]; - char buf_new_elc[64], buf_new_ion[64], buf_new_field[64]; - char buf_del1_elc[64], buf_del1_ion[64], buf_del1_field[64]; - char buf_del2_elc[64], buf_del2_ion[64], buf_del2_field[64]; - - snprintf(buf_old_elc, 64, "%s_coarse_%d_elc_b%d.gkyl", five_moment_output, i, j); - snprintf(buf_old_ion, 64, "%s_coarse_%d_ion_b%d.gkyl", five_moment_output, i, j); - snprintf(buf_old_field, 64, "%s_coarse_%d_field_b%d.gkyl", five_moment_output, i, j); - - snprintf(buf_new_elc, 64, "%s_%d_elc_b%d.gkyl", five_moment_output, i, j); - snprintf(buf_new_ion, 64, "%s_%d_ion_b%d.gkyl", five_moment_output, i, j); - snprintf(buf_new_field, 64, "%s_%d_field_b%d.gkyl", five_moment_output, i, j); - - snprintf(buf_del1_elc, 64, "%s_intermediate_%d_elc_b%d.gkyl", five_moment_output, i, j); - snprintf(buf_del1_ion, 64, "%s_intermediate_%d_ion_b%d.gkyl", five_moment_output, i, j); - snprintf(buf_del1_field, 64, "%s_intermediate_%d_field_b%d.gkyl", five_moment_output, i, j); - - snprintf(buf_del2_elc, 64, "%s_fine_%d_elc_b%d.gkyl", five_moment_output, i, j); - snprintf(buf_del2_ion, 64, "%s_fine_%d_ion_b%d.gkyl", five_moment_output, i, j); - snprintf(buf_del2_field, 64, "%s_fine_%d_field_b%d.gkyl", five_moment_output, i, j); - - rename(buf_old_elc, buf_new_elc); - rename(buf_old_ion, buf_new_ion); - rename(buf_old_field, buf_new_field); - - remove(buf_del1_elc); - remove(buf_del1_ion); - remove(buf_del1_field); - - remove(buf_del2_elc); - remove(buf_del2_ion); - remove(buf_del2_field); - } -#else char buf[64]; snprintf(buf, 64, "%s_%d", five_moment_output, i); - five_moment_write_sol_block(buf, num_blocks, coarse_bdata); -#endif + five_moment_write_sol_block(buf, num_blocks, mesh_bdata); } } @@ -2377,247 +979,51 @@ five_moment_2d_run_double(int argc, char **argv, struct five_moment_2d_double_in double tm_total_sec = gkyl_time_diff_now_sec(tm_start); - // TODO: Make file output work correctly in the AMR_DEBUG case. -#ifdef AMR_DEBUG - char buf_coarse[64]; - char buf_intermediate[64]; - char buf_fine[64]; - - snprintf(buf_coarse, 64, "%s_coarse_%d", five_moment_output, num_frames); - snprintf(buf_intermediate, 64, "%s_intermediate_%d", five_moment_output, num_frames); - snprintf(buf_fine, 64, "%s_fine_%d", five_moment_output, num_frames); - - five_moment_write_sol_block(buf_coarse, num_blocks, coarse_bdata); - five_moment_write_sol_block(buf_intermediate, num_blocks, intermediate_bdata); - five_moment_write_sol_block(buf_fine, num_blocks, fine_bdata); - - char buf_fine_old_elc[64], buf_fine_old_ion[64], buf_fine_old_field[64]; - char buf_fine_new_elc[64], buf_fine_new_ion[64], buf_fine_new_field[64]; - char buf_intermediate_old_elc[64], buf_intermediate_old_ion[64], buf_intermediate_old_field[64]; - char buf_coarse_old_elc[64], buf_coarse_old_ion[64], buf_coarse_old_field[64]; - - snprintf(buf_fine_old_elc, 64, "%s_fine_%d_elc_b0.gkyl", five_moment_output, num_frames); - snprintf(buf_fine_old_ion, 64, "%s_fine_%d_ion_b0.gkyl", five_moment_output, num_frames); - snprintf(buf_fine_old_field, 64, "%s_fine_%d_field_b0.gkyl", five_moment_output, num_frames); - - snprintf(buf_fine_new_elc, 64, "%s_%d_elc_b0.gkyl", five_moment_output, num_frames); - snprintf(buf_fine_new_ion, 64, "%s_%d_ion_b0.gkyl", five_moment_output, num_frames); - snprintf(buf_fine_new_field, 64, "%s_%d_field_b0.gkyl", five_moment_output, num_frames); - - snprintf(buf_intermediate_old_elc, 64, "%s_intermediate_%d_elc_b0.gkyl", five_moment_output, num_frames); - snprintf(buf_intermediate_old_ion, 64, "%s_intermediate_%d_ion_b0.gkyl", five_moment_output, num_frames); - snprintf(buf_intermediate_old_field, 64, "%s_intermediate_%d_field_b0.gkyl", five_moment_output, num_frames); - - snprintf(buf_coarse_old_elc, 64, "%s_coarse_%d_elc_b0.gkyl", five_moment_output, num_frames); - snprintf(buf_coarse_old_ion, 64, "%s_coarse_%d_ion_b0.gkyl", five_moment_output, num_frames); - snprintf(buf_coarse_old_field, 64, "%s_coarse_%d_field_b0.gkyl", five_moment_output, num_frames); - - rename(buf_fine_old_elc, buf_fine_new_elc); - rename(buf_fine_old_ion, buf_fine_new_ion); - rename(buf_fine_old_field, buf_fine_new_field); - - remove(buf_intermediate_old_elc); - remove(buf_intermediate_old_ion); - remove(buf_intermediate_old_field); - - remove(buf_coarse_old_elc); - remove(buf_coarse_old_ion); - remove(buf_coarse_old_field); - - for (int i = 1; i < 9; i++) { - char fine0_elc_bi[64], fine0_ion_bi[64], fine0_field_bi[64]; - char intermediate0_elc_bi[64], intermediate0_ion_bi[64], intermediate0_field_bi[64]; - char coarse0_elc_bi[64], coarse0_ion_bi[64], coarse0_field_bi[64]; - char elc_bi[64], ion_bi[64], field_bi[64]; - - snprintf(fine0_elc_bi, 64, "%s_fine_%d_elc_b%d.gkyl", five_moment_output, num_frames, i); - snprintf(fine0_ion_bi, 64, "%s_fine_%d_ion_b%d.gkyl", five_moment_output, num_frames, i); - snprintf(fine0_field_bi, 64, "%s_fine_%d_field_b%d.gkyl", five_moment_output, num_frames, i); - - snprintf(intermediate0_elc_bi, 64, "%s_intermediate_%d_elc_b%d.gkyl", five_moment_output, num_frames, i); - snprintf(intermediate0_ion_bi, 64, "%s_intermediate_%d_ion_b%d.gkyl", five_moment_output, num_frames, i); - snprintf(intermediate0_field_bi, 64, "%s_intermediate_%d_field_b%d.gkyl", five_moment_output, num_frames, i); - - snprintf(coarse0_elc_bi, 64, "%s_coarse_%d_elc_b%d.gkyl", five_moment_output, num_frames, i); - snprintf(coarse0_ion_bi, 64, "%s_coarse_%d_ion_b%d.gkyl", five_moment_output, num_frames, i); - snprintf(coarse0_field_bi, 64, "%s_coarse_%d_field_b%d.gkyl", five_moment_output, num_frames, i); - - snprintf(elc_bi, 64, "%s_%d_elc_b%d.gkyl", five_moment_output, num_frames, i); - snprintf(ion_bi, 64, "%s_%d_ion_b%d.gkyl", five_moment_output, num_frames, i); - snprintf(field_bi, 64, "%s_%d_field_b%d.gkyl", five_moment_output, num_frames, i); - - rename(intermediate0_elc_bi, elc_bi); - rename(intermediate0_ion_bi, ion_bi); - rename(intermediate0_field_bi, field_bi); - - remove(fine0_elc_bi); - remove(fine0_ion_bi); - remove(fine0_field_bi); - - remove(coarse0_elc_bi); - remove(coarse0_ion_bi); - remove(coarse0_field_bi); - } - - for (int i = 9; i < 25; i++) { - char buf_old_elc[64], buf_old_ion[64], buf_old_field[64]; - char buf_new_elc[64], buf_new_ion[64], buf_new_field[64]; - char buf_del1_elc[64], buf_del1_ion[64], buf_del1_field[64]; - char buf_del2_elc[64], buf_del2_ion[64], buf_del2_field[64]; - - snprintf(buf_old_elc, 64, "%s_coarse_%d_elc_b%d.gkyl", five_moment_output, num_frames, i); - snprintf(buf_old_ion, 64, "%s_coarse_%d_ion_b%d.gkyl", five_moment_output, num_frames, i); - snprintf(buf_old_field, 64, "%s_coarse_%d_field_b%d.gkyl", five_moment_output, num_frames, i); - - snprintf(buf_new_elc, 64, "%s_%d_elc_b%d.gkyl", five_moment_output, num_frames, i); - snprintf(buf_new_ion, 64, "%s_%d_ion_b%d.gkyl", five_moment_output, num_frames, i); - snprintf(buf_new_field, 64, "%s_%d_field_b%d.gkyl", five_moment_output, num_frames, i); - - snprintf(buf_del1_elc, 64, "%s_intermediate_%d_elc_b%d.gkyl", five_moment_output, num_frames, i); - snprintf(buf_del1_ion, 64, "%s_intermediate_%d_ion_b%d.gkyl", five_moment_output, num_frames, i); - snprintf(buf_del1_field, 64, "%s_intermediate_%d_field_b%d.gkyl", five_moment_output, num_frames, i); - - snprintf(buf_del2_elc, 64, "%s_fine_%d_elc_b%d.gkyl", five_moment_output, num_frames, i); - snprintf(buf_del2_ion, 64, "%s_fine_%d_ion_b%d.gkyl", five_moment_output, num_frames, i); - snprintf(buf_del2_field, 64, "%s_fine_%d_field_b%d.gkyl", five_moment_output, num_frames, i); - - rename(buf_old_elc, buf_new_elc); - rename(buf_old_ion, buf_new_ion); - rename(buf_old_field, buf_new_field); - - remove(buf_del1_elc); - remove(buf_del1_ion); - remove(buf_del1_field); - - remove(buf_del2_elc); - remove(buf_del2_ion); - remove(buf_del2_field); - } -#else char buf[64]; snprintf(buf, 64, "%s_%d", five_moment_output, num_frames); - five_moment_write_sol_block(buf, num_blocks, coarse_bdata); -#endif + five_moment_write_sol_block(buf, num_blocks, mesh_bdata); printf("Total run-time: %g. Failed steps: %d\n", tm_total_sec, stats.nfail); for (int i = 0; i < num_blocks; i++) { - gkyl_fv_proj_release(coarse_bdata[i].fv_proj_elc); - gkyl_fv_proj_release(coarse_bdata[i].fv_proj_ion); - gkyl_fv_proj_release(coarse_bdata[i].fv_proj_maxwell); - - gkyl_wv_eqn_release(coarse_bdata[i].euler_elc); - gkyl_wv_eqn_release(coarse_bdata[i].euler_ion); - gkyl_wv_eqn_release(coarse_bdata[i].maxwell); - - five_moment_block_bc_updaters_release(&coarse_bdata[i]); - gkyl_wave_geom_release(coarse_bdata[i].geom); - -#ifdef AMR_DEBUG - gkyl_fv_proj_release(intermediate_bdata[i].fv_proj_elc); - gkyl_fv_proj_release(intermediate_bdata[i].fv_proj_ion); - gkyl_fv_proj_release(intermediate_bdata[i].fv_proj_maxwell); - - gkyl_wv_eqn_release(intermediate_bdata[i].euler_elc); - gkyl_wv_eqn_release(intermediate_bdata[i].euler_ion); - gkyl_wv_eqn_release(intermediate_bdata[i].maxwell); - - five_moment_block_bc_updaters_release(&intermediate_bdata[i]); - gkyl_wave_geom_release(intermediate_bdata[i].geom); + gkyl_fv_proj_release(mesh_bdata[i].fv_proj_elc); + gkyl_fv_proj_release(mesh_bdata[i].fv_proj_ion); + gkyl_fv_proj_release(mesh_bdata[i].fv_proj_maxwell); - gkyl_fv_proj_release(fine_bdata[i].fv_proj_elc); - gkyl_fv_proj_release(fine_bdata[i].fv_proj_ion); - gkyl_fv_proj_release(fine_bdata[i].fv_proj_maxwell); + gkyl_wv_eqn_release(mesh_bdata[i].euler_elc); + gkyl_wv_eqn_release(mesh_bdata[i].euler_ion); + gkyl_wv_eqn_release(mesh_bdata[i].maxwell); - gkyl_wv_eqn_release(fine_bdata[i].euler_elc); - gkyl_wv_eqn_release(fine_bdata[i].euler_ion); - gkyl_wv_eqn_release(fine_bdata[i].maxwell); - - five_moment_block_bc_updaters_release(&fine_bdata[i]); - gkyl_wave_geom_release(fine_bdata[i].geom); -#endif + five_moment_block_bc_updaters_release(&mesh_bdata[i]); + gkyl_wave_geom_release(mesh_bdata[i].geom); for (int d = 0; d < ndim; d++) { - gkyl_wave_prop_release(coarse_bdata[i].slvr_elc[d]); - gkyl_wave_prop_release(coarse_bdata[i].slvr_ion[d]); - gkyl_wave_prop_release(coarse_bdata[i].slvr_maxwell[d]); - -#ifdef AMR_DEBUG - gkyl_wave_prop_release(intermediate_bdata[i].slvr_elc[d]); - gkyl_wave_prop_release(intermediate_bdata[i].slvr_ion[d]); - gkyl_wave_prop_release(intermediate_bdata[i].slvr_maxwell[d]); - - gkyl_wave_prop_release(fine_bdata[i].slvr_elc[d]); - gkyl_wave_prop_release(fine_bdata[i].slvr_ion[d]); - gkyl_wave_prop_release(fine_bdata[i].slvr_maxwell[d]); -#endif + gkyl_wave_prop_release(mesh_bdata[i].slvr_elc[d]); + gkyl_wave_prop_release(mesh_bdata[i].slvr_ion[d]); + gkyl_wave_prop_release(mesh_bdata[i].slvr_maxwell[d]); } - gkyl_array_release(coarse_bdata[i].fdup_elc); - gkyl_array_release(coarse_bdata[i].fdup_ion); - gkyl_array_release(coarse_bdata[i].fdup_maxwell); - -#ifdef AMR_DEBUG - gkyl_array_release(intermediate_bdata[i].fdup_elc); - gkyl_array_release(intermediate_bdata[i].fdup_ion); - gkyl_array_release(intermediate_bdata[i].fdup_maxwell); - - gkyl_array_release(fine_bdata[i].fdup_elc); - gkyl_array_release(fine_bdata[i].fdup_ion); - gkyl_array_release(fine_bdata[i].fdup_maxwell); -#endif + gkyl_array_release(mesh_bdata[i].fdup_elc); + gkyl_array_release(mesh_bdata[i].fdup_ion); + gkyl_array_release(mesh_bdata[i].fdup_maxwell); for(int d = 0; d < ndim; d++) { - gkyl_array_release(coarse_bdata[i].f_elc[d]); - gkyl_array_release(coarse_bdata[i].f_ion[d]); - gkyl_array_release(coarse_bdata[i].f_maxwell[d]); - -#ifdef AMR_DEBUG - gkyl_array_release(intermediate_bdata[i].f_elc[d]); - gkyl_array_release(intermediate_bdata[i].f_ion[d]); - gkyl_array_release(intermediate_bdata[i].f_maxwell[d]); - - gkyl_array_release(fine_bdata[i].f_elc[d]); - gkyl_array_release(fine_bdata[i].f_ion[d]); - gkyl_array_release(fine_bdata[i].f_maxwell[d]); -#endif + gkyl_array_release(mesh_bdata[i].f_elc[d]); + gkyl_array_release(mesh_bdata[i].f_ion[d]); + gkyl_array_release(mesh_bdata[i].f_maxwell[d]); } - gkyl_array_release(coarse_bdata[i].app_accel_elc); - gkyl_array_release(coarse_bdata[i].app_accel_ion); - gkyl_array_release(coarse_bdata[i].rhs_source_elc); - gkyl_array_release(coarse_bdata[i].rhs_source_ion); - gkyl_array_release(coarse_bdata[i].ext_em); - gkyl_array_release(coarse_bdata[i].app_current); - gkyl_array_release(coarse_bdata[i].nT_source_elc); - gkyl_array_release(coarse_bdata[i].nT_source_ion); - -#ifdef AMR_DEBUG - gkyl_array_release(intermediate_bdata[i].app_accel_elc); - gkyl_array_release(intermediate_bdata[i].app_accel_ion); - gkyl_array_release(intermediate_bdata[i].rhs_source_elc); - gkyl_array_release(intermediate_bdata[i].rhs_source_ion); - gkyl_array_release(intermediate_bdata[i].ext_em); - gkyl_array_release(intermediate_bdata[i].app_current); - gkyl_array_release(intermediate_bdata[i].nT_source_elc); - gkyl_array_release(intermediate_bdata[i].nT_source_ion); - - gkyl_array_release(fine_bdata[i].app_accel_elc); - gkyl_array_release(fine_bdata[i].app_accel_ion); - gkyl_array_release(fine_bdata[i].rhs_source_elc); - gkyl_array_release(fine_bdata[i].rhs_source_ion); - gkyl_array_release(fine_bdata[i].ext_em); - gkyl_array_release(fine_bdata[i].app_current); - gkyl_array_release(fine_bdata[i].nT_source_elc); - gkyl_array_release(fine_bdata[i].nT_source_ion); -#endif + gkyl_array_release(mesh_bdata[i].app_accel_elc); + gkyl_array_release(mesh_bdata[i].app_accel_ion); + gkyl_array_release(mesh_bdata[i].rhs_source_elc); + gkyl_array_release(mesh_bdata[i].rhs_source_ion); + gkyl_array_release(mesh_bdata[i].ext_em); + gkyl_array_release(mesh_bdata[i].app_current); + gkyl_array_release(mesh_bdata[i].nT_source_elc); + gkyl_array_release(mesh_bdata[i].nT_source_ion); } gkyl_block_topo_release(btopo); gkyl_job_pool_release(coarse_job_pool); -#ifdef AMR_DEBUG - gkyl_job_pool_release(intermediate_job_pool); - gkyl_job_pool_release(fine_job_pool); -#endif } \ No newline at end of file diff --git a/amr/amr_core_ten_moment.c b/amr/amr_core_ten_moment.c index b71feb172..39a48f71e 100644 --- a/amr/amr_core_ten_moment.c +++ b/amr/amr_core_ten_moment.c @@ -55,313 +55,130 @@ ten_moment_1d_run_single(int argc, char **argv, struct ten_moment_1d_single_init int num_patches = 3; int Nx = base_Nx; - struct five_moment_patch_data coarse_pdata[num_patches]; + struct five_moment_patch_data mesh_pdata[num_patches]; struct gkyl_job_pool *coarse_job_pool = gkyl_thread_pool_new(app_args.num_threads); -#ifdef AMR_DEBUG - gkyl_rect_grid_init(&coarse_pdata[0].grid, 1, (double []) { refined_x1 }, (double []) { refined_x2 }, (int []) { Nx } ); -#else - gkyl_rect_grid_init(&coarse_pdata[0].grid, 1, (double []) { refined_x1 }, (double []) { refined_x2 }, (int []) { Nx * ref_factor } ); -#endif + gkyl_rect_grid_init(&mesh_pdata[0].grid, 1, (double []) { refined_x1 }, (double []) { refined_x2 }, (int []) { Nx * ref_factor } ); - gkyl_rect_grid_init(&coarse_pdata[1].grid, 1, (double []) { coarse_x1 }, (double []) { refined_x1 }, (int []) { Nx } ); - gkyl_rect_grid_init(&coarse_pdata[2].grid, 1, (double []) { refined_x2 }, (double []) { coarse_x2 }, (int []) { Nx } ); - -#ifdef AMR_DEBUG - struct five_moment_patch_data fine_pdata[num_patches]; - struct gkyl_job_pool *fine_job_pool = gkyl_thread_pool_new(app_args.num_threads); - - gkyl_rect_grid_init(&fine_pdata[0].grid, 1, (double []) { refined_x1 }, (double []) { refined_x2 }, (int []) { Nx * ref_factor } ); - gkyl_rect_grid_init(&fine_pdata[1].grid, 1, (double []) { coarse_x1 }, (double []) { refined_x1 }, (int []) { Nx * ref_factor } ); - gkyl_rect_grid_init(&fine_pdata[2].grid, 1, (double []) { refined_x2 }, (double []) { coarse_x2 }, (int []) { Nx * ref_factor } ); -#endif + gkyl_rect_grid_init(&mesh_pdata[1].grid, 1, (double []) { coarse_x1 }, (double []) { refined_x1 }, (int []) { Nx } ); + gkyl_rect_grid_init(&mesh_pdata[2].grid, 1, (double []) { refined_x2 }, (double []) { coarse_x2 }, (int []) { Nx } ); for (int i = 0; i < num_patches; i++) { - coarse_pdata[i].fv_proj_elc = gkyl_fv_proj_new(&coarse_pdata[i].grid, 1, 10, eval_elc, 0); - coarse_pdata[i].fv_proj_ion = gkyl_fv_proj_new(&coarse_pdata[i].grid, 1, 10, eval_ion, 0); - coarse_pdata[i].fv_proj_maxwell = gkyl_fv_proj_new(&coarse_pdata[i].grid, 1, 8, eval_field, 0); - -#ifdef AMR_DEBUG - fine_pdata[i].fv_proj_elc = gkyl_fv_proj_new(&fine_pdata[i].grid, 1, 10, eval_elc, 0); - fine_pdata[i].fv_proj_ion = gkyl_fv_proj_new(&fine_pdata[i].grid, 1, 10, eval_ion, 0); - fine_pdata[i].fv_proj_maxwell = gkyl_fv_proj_new(&fine_pdata[i].grid, 1, 8, eval_field, 0); -#endif + mesh_pdata[i].fv_proj_elc = gkyl_fv_proj_new(&mesh_pdata[i].grid, 1, 10, eval_elc, 0); + mesh_pdata[i].fv_proj_ion = gkyl_fv_proj_new(&mesh_pdata[i].grid, 1, 10, eval_ion, 0); + mesh_pdata[i].fv_proj_maxwell = gkyl_fv_proj_new(&mesh_pdata[i].grid, 1, 8, eval_field, 0); } for (int i = 0; i < num_patches; i++) { - gkyl_create_grid_ranges(&coarse_pdata[i].grid, (int []) { 2 }, &coarse_pdata[i].ext_range, &coarse_pdata[i].range); - coarse_pdata[i].geom = gkyl_wave_geom_new(&coarse_pdata[i].grid, &coarse_pdata[i].ext_range, 0, 0, false); - -#ifdef AMR_DEBUG - gkyl_create_grid_ranges(&fine_pdata[i].grid, (int []) { 2 }, &fine_pdata[i].ext_range, &fine_pdata[i].range); - fine_pdata[i].geom = gkyl_wave_geom_new(&fine_pdata[i].grid, &fine_pdata[i].ext_range, 0, 0, false); -#endif + gkyl_create_grid_ranges(&mesh_pdata[i].grid, (int []) { 2 }, &mesh_pdata[i].ext_range, &mesh_pdata[i].range); + mesh_pdata[i].geom = gkyl_wave_geom_new(&mesh_pdata[i].grid, &mesh_pdata[i].ext_range, 0, 0, false); } for (int i = 0; i < num_patches; i++) { - coarse_pdata[i].euler_elc = gkyl_wv_ten_moment_new(k0_elc); - coarse_pdata[i].euler_ion = gkyl_wv_ten_moment_new(k0_ion); - coarse_pdata[i].maxwell = gkyl_wv_maxwell_new(light_speed, e_fact, b_fact); + mesh_pdata[i].euler_elc = gkyl_wv_ten_moment_new(k0_elc); + mesh_pdata[i].euler_ion = gkyl_wv_ten_moment_new(k0_ion); + mesh_pdata[i].maxwell = gkyl_wv_maxwell_new(light_speed, e_fact, b_fact); - coarse_pdata[i].slvr_elc[0] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &coarse_pdata[i].grid, - .equation = coarse_pdata[i].euler_elc, + mesh_pdata[i].slvr_elc[0] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { + .grid = &mesh_pdata[i].grid, + .equation = mesh_pdata[i].euler_elc, .limiter = GKYL_MONOTONIZED_CENTERED, .num_up_dirs = 1, .update_dirs = { 0 }, .cfl = cfl_frac, - .geom = coarse_pdata[i].geom, + .geom = mesh_pdata[i].geom, } ); - coarse_pdata[i].slvr_ion[0] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &coarse_pdata[i].grid, - .equation = coarse_pdata[i].euler_ion, + mesh_pdata[i].slvr_ion[0] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { + .grid = &mesh_pdata[i].grid, + .equation = mesh_pdata[i].euler_ion, .limiter = GKYL_MONOTONIZED_CENTERED, .num_up_dirs = 1, .update_dirs = { 0 }, .cfl = cfl_frac, - .geom = coarse_pdata[i].geom, + .geom = mesh_pdata[i].geom, } ); - coarse_pdata[i].slvr_maxwell[0] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &coarse_pdata[i].grid, - .equation = coarse_pdata[i].maxwell, + mesh_pdata[i].slvr_maxwell[0] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { + .grid = &mesh_pdata[i].grid, + .equation = mesh_pdata[i].maxwell, .limiter = GKYL_MONOTONIZED_CENTERED, .num_up_dirs = 1, .update_dirs = { 0 }, .cfl = cfl_frac, - .geom = coarse_pdata[i].geom, + .geom = mesh_pdata[i].geom, } ); struct gkyl_moment_em_coupling_inp coarse_src_inp = { - .grid = &coarse_pdata[i].grid, + .grid = &mesh_pdata[i].grid, .nfluids = 2, .epsilon0 = epsilon0, }; coarse_src_inp.param[0] = (struct gkyl_moment_em_coupling_data) { - .type = coarse_pdata[i].euler_elc->type, + .type = mesh_pdata[i].euler_elc->type, .charge = charge_elc, .mass = mass_elc, .k0 = k0_elc, }; coarse_src_inp.param[1] = (struct gkyl_moment_em_coupling_data) { - .type = coarse_pdata[i].euler_ion->type, - .charge = charge_ion, - .mass = mass_ion, - .k0 = k0_ion, - }; - - coarse_pdata[i].src_slvr = gkyl_moment_em_coupling_new(coarse_src_inp); - -#ifdef AMR_DEBUG - fine_pdata[i].euler_elc = gkyl_wv_ten_moment_new(k0_elc); - fine_pdata[i].euler_ion = gkyl_wv_ten_moment_new(k0_ion); - fine_pdata[i].maxwell = gkyl_wv_maxwell_new(light_speed, e_fact, b_fact); - - fine_pdata[i].slvr_elc[0] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &fine_pdata[i].grid, - .equation = fine_pdata[i].euler_elc, - .limiter = GKYL_MONOTONIZED_CENTERED, - .num_up_dirs = 1, - .update_dirs = { 0 }, - .cfl = cfl_frac, - .geom = fine_pdata[i].geom, - } - ); - fine_pdata[i].slvr_ion[0] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &fine_pdata[i].grid, - .equation = fine_pdata[i].euler_ion, - .limiter = GKYL_MONOTONIZED_CENTERED, - .num_up_dirs = 1, - .update_dirs = { 0 }, - .cfl = cfl_frac, - .geom = fine_pdata[i].geom, - } - ); - fine_pdata[i].slvr_maxwell[0] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &fine_pdata[i].grid, - .equation = fine_pdata[i].maxwell, - .limiter = GKYL_MONOTONIZED_CENTERED, - .num_up_dirs = 1, - .update_dirs = { 0 }, - .cfl = cfl_frac, - .geom = fine_pdata[i].geom, - } - ); - - struct gkyl_moment_em_coupling_inp fine_src_inp = { - .grid = &fine_pdata[i].grid, - .nfluids = 2, - .epsilon0 = epsilon0, - }; - - fine_src_inp.param[0] = (struct gkyl_moment_em_coupling_data) { - .type = fine_pdata[i].euler_elc->type, - .charge = charge_elc, - .mass = mass_elc, - .k0 = k0_elc, - }; - fine_src_inp.param[1] = (struct gkyl_moment_em_coupling_data) { - .type = fine_pdata[i].euler_ion->type, + .type = mesh_pdata[i].euler_ion->type, .charge = charge_ion, .mass = mass_ion, .k0 = k0_ion, }; - fine_pdata[i].src_slvr = gkyl_moment_em_coupling_new(fine_src_inp); -#endif + mesh_pdata[i].src_slvr = gkyl_moment_em_coupling_new(coarse_src_inp); } struct gkyl_block_topo *ptopo = create_patch_topo(); for (int i = 0; i < num_patches; i++) { - ten_moment_patch_bc_updaters_init(&coarse_pdata[i], &ptopo->conn[i]); - -#ifdef AMR_DEBUG - ten_moment_patch_bc_updaters_init(&fine_pdata[i], &ptopo->conn[i]); -#endif + ten_moment_patch_bc_updaters_init(&mesh_pdata[i], &ptopo->conn[i]); } for (int i = 0; i < num_patches; i++) { - coarse_pdata[i].fdup_elc = gkyl_array_new(GKYL_DOUBLE, 10, coarse_pdata[i].ext_range.volume); - coarse_pdata[i].fdup_ion = gkyl_array_new(GKYL_DOUBLE, 10, coarse_pdata[i].ext_range.volume); - coarse_pdata[i].fdup_maxwell = gkyl_array_new(GKYL_DOUBLE, 8, coarse_pdata[i].ext_range.volume); - - for (int d = 0; d < ndim + 1; d++) { - coarse_pdata[i].f_elc[d] = gkyl_array_new(GKYL_DOUBLE, 10, coarse_pdata[i].ext_range.volume); - coarse_pdata[i].f_ion[d] = gkyl_array_new(GKYL_DOUBLE, 10, coarse_pdata[i].ext_range.volume); - coarse_pdata[i].f_maxwell[d] = gkyl_array_new(GKYL_DOUBLE, 8, coarse_pdata[i].ext_range.volume); - } - - coarse_pdata[i].app_accel_elc = gkyl_array_new(GKYL_DOUBLE, 3, coarse_pdata[i].ext_range.volume); - coarse_pdata[i].app_accel_ion = gkyl_array_new(GKYL_DOUBLE, 3, coarse_pdata[i].ext_range.volume); - coarse_pdata[i].rhs_source_elc = gkyl_array_new(GKYL_DOUBLE, 10, coarse_pdata[i].ext_range.volume); - coarse_pdata[i].rhs_source_ion = gkyl_array_new(GKYL_DOUBLE, 10, coarse_pdata[i].ext_range.volume); - coarse_pdata[i].ext_em = gkyl_array_new(GKYL_DOUBLE, 6, coarse_pdata[i].ext_range.volume); - coarse_pdata[i].app_current = gkyl_array_new(GKYL_DOUBLE, 3, coarse_pdata[i].ext_range.volume); - coarse_pdata[i].nT_source_elc = gkyl_array_new(GKYL_DOUBLE, 2, coarse_pdata[i].ext_range.volume); - coarse_pdata[i].nT_source_ion = gkyl_array_new(GKYL_DOUBLE, 2, coarse_pdata[i].ext_range.volume); - -#ifdef AMR_DEBUG - fine_pdata[i].fdup_elc = gkyl_array_new(GKYL_DOUBLE, 10, fine_pdata[i].ext_range.volume); - fine_pdata[i].fdup_ion = gkyl_array_new(GKYL_DOUBLE, 10, fine_pdata[i].ext_range.volume); - fine_pdata[i].fdup_maxwell = gkyl_array_new(GKYL_DOUBLE, 8, fine_pdata[i].ext_range.volume); + mesh_pdata[i].fdup_elc = gkyl_array_new(GKYL_DOUBLE, 10, mesh_pdata[i].ext_range.volume); + mesh_pdata[i].fdup_ion = gkyl_array_new(GKYL_DOUBLE, 10, mesh_pdata[i].ext_range.volume); + mesh_pdata[i].fdup_maxwell = gkyl_array_new(GKYL_DOUBLE, 8, mesh_pdata[i].ext_range.volume); for (int d = 0; d < ndim + 1; d++) { - fine_pdata[i].f_elc[d] = gkyl_array_new(GKYL_DOUBLE, 10, fine_pdata[i].ext_range.volume); - fine_pdata[i].f_ion[d] = gkyl_array_new(GKYL_DOUBLE, 10, fine_pdata[i].ext_range.volume); - fine_pdata[i].f_maxwell[d] = gkyl_array_new(GKYL_DOUBLE, 8, fine_pdata[i].ext_range.volume); + mesh_pdata[i].f_elc[d] = gkyl_array_new(GKYL_DOUBLE, 10, mesh_pdata[i].ext_range.volume); + mesh_pdata[i].f_ion[d] = gkyl_array_new(GKYL_DOUBLE, 10, mesh_pdata[i].ext_range.volume); + mesh_pdata[i].f_maxwell[d] = gkyl_array_new(GKYL_DOUBLE, 8, mesh_pdata[i].ext_range.volume); } - fine_pdata[i].app_accel_elc = gkyl_array_new(GKYL_DOUBLE, 3, fine_pdata[i].ext_range.volume); - fine_pdata[i].app_accel_ion = gkyl_array_new(GKYL_DOUBLE, 3, fine_pdata[i].ext_range.volume); - fine_pdata[i].rhs_source_elc = gkyl_array_new(GKYL_DOUBLE, 10, fine_pdata[i].ext_range.volume); - fine_pdata[i].rhs_source_ion = gkyl_array_new(GKYL_DOUBLE, 10, fine_pdata[i].ext_range.volume); - fine_pdata[i].ext_em = gkyl_array_new(GKYL_DOUBLE, 6, fine_pdata[i].ext_range.volume); - fine_pdata[i].app_current = gkyl_array_new(GKYL_DOUBLE, 3, fine_pdata[i].ext_range.volume); - fine_pdata[i].nT_source_elc = gkyl_array_new(GKYL_DOUBLE, 2, fine_pdata[i].ext_range.volume); - fine_pdata[i].nT_source_ion = gkyl_array_new(GKYL_DOUBLE, 2, fine_pdata[i].ext_range.volume); -#endif + mesh_pdata[i].app_accel_elc = gkyl_array_new(GKYL_DOUBLE, 3, mesh_pdata[i].ext_range.volume); + mesh_pdata[i].app_accel_ion = gkyl_array_new(GKYL_DOUBLE, 3, mesh_pdata[i].ext_range.volume); + mesh_pdata[i].rhs_source_elc = gkyl_array_new(GKYL_DOUBLE, 10, mesh_pdata[i].ext_range.volume); + mesh_pdata[i].rhs_source_ion = gkyl_array_new(GKYL_DOUBLE, 10, mesh_pdata[i].ext_range.volume); + mesh_pdata[i].ext_em = gkyl_array_new(GKYL_DOUBLE, 6, mesh_pdata[i].ext_range.volume); + mesh_pdata[i].app_current = gkyl_array_new(GKYL_DOUBLE, 3, mesh_pdata[i].ext_range.volume); + mesh_pdata[i].nT_source_elc = gkyl_array_new(GKYL_DOUBLE, 2, mesh_pdata[i].ext_range.volume); + mesh_pdata[i].nT_source_ion = gkyl_array_new(GKYL_DOUBLE, 2, mesh_pdata[i].ext_range.volume); } #ifdef AMR_USETHREADS for (int i = 0; i < num_patches; i++) { - gkyl_job_pool_add_work(coarse_job_pool, five_moment_init_job_func_patch, &coarse_pdata[i]); - -#ifdef AMR_DEBUG - gkyl_job_pool_add_work(fine_job_pool, five_moment_init_job_func_patch, &fine_pdata[i]); -#endif + gkyl_job_pool_add_work(coarse_job_pool, five_moment_init_job_func_patch, &mesh_pdata[i]); } gkyl_job_pool_wait(coarse_job_pool); - -#ifdef AMR_DEBUG - gkyl_job_pool_wait(fine_job_pool); -#endif #else for (int i = 0; i < num_patches; i++) { - five_moment_init_job_func_patch(&coarse_pdata[i]); - -#ifdef AMR_DEBUG - five_moment_init_job_func_patch(&fine_pdata[i]); -#endif + five_moment_init_job_func_patch(&mesh_pdata[i]); } #endif -#ifdef AMR_DEBUG - char coarse0[64]; - snprintf(coarse0, 64, "%s_coarse_0", ten_moment_output); - five_moment_write_sol_patch(coarse0, num_patches, coarse_pdata); - - char fine0[64]; - snprintf(fine0, 64, "%s_fine_0", ten_moment_output); - five_moment_write_sol_patch(fine0, num_patches, fine_pdata); - - char fine0_elc_p0[64], fine0_ion_p0[64], fine0_field_p0[64]; - char coarse0_elc_p0[64], coarse0_ion_p0[64], coarse0_field_p0[64]; - char p0_elc[64], p0_ion[64], p0_field[64]; - - snprintf(fine0_elc_p0, 64, "%s_fine_0_elc_p0.gkyl", ten_moment_output); - snprintf(fine0_ion_p0, 64, "%s_fine_0_ion_p0.gkyl", ten_moment_output); - snprintf(fine0_field_p0, 64, "%s_fine_0_field_p0.gkyl", ten_moment_output); - - snprintf(coarse0_elc_p0, 64, "%s_coarse_0_elc_p0.gkyl", ten_moment_output); - snprintf(coarse0_ion_p0, 64, "%s_coarse_0_ion_p0.gkyl", ten_moment_output); - snprintf(coarse0_field_p0, 64, "%s_coarse_0_field_p0.gkyl", ten_moment_output); - - snprintf(p0_elc, 64, "%s_0_elc_p0.gkyl", ten_moment_output); - snprintf(p0_ion, 64, "%s_0_ion_p0.gkyl", ten_moment_output); - snprintf(p0_field, 64, "%s_0_field_p0.gkyl", ten_moment_output); - - rename(fine0_elc_p0, p0_elc); - rename(fine0_ion_p0, p0_ion); - rename(fine0_field_p0, p0_field); - - remove(coarse0_elc_p0); - remove(coarse0_ion_p0); - remove(coarse0_field_p0); - - for (int i = 1; i < 3; i++) { - char buf_old_elc[64], buf_old_ion[64], buf_old_field[64]; - char buf_new_elc[64], buf_new_ion[64], buf_new_field[64]; - char buf_del_elc[64], buf_del_ion[64], buf_del_field[64]; - - snprintf(buf_old_elc, 64, "%s_coarse_0_elc_p%d.gkyl", ten_moment_output, i); - snprintf(buf_old_ion, 64, "%s_coarse_0_ion_p%d.gkyl", ten_moment_output, i); - snprintf(buf_old_field, 64, "%s_coarse_0_field_p%d.gkyl", ten_moment_output, i); - - snprintf(buf_new_elc, 64, "%s_0_elc_p%d.gkyl", ten_moment_output, i); - snprintf(buf_new_ion, 64, "%s_0_ion_p%d.gkyl", ten_moment_output, i); - snprintf(buf_new_field, 64, "%s_0_field_p%d.gkyl", ten_moment_output, i); - - snprintf(buf_del_elc, 64, "%s_fine_0_elc_p%d.gkyl", ten_moment_output, i); - snprintf(buf_del_ion, 64, "%s_fine_0_ion_p%d.gkyl", ten_moment_output, i); - snprintf(buf_del_field, 64, "%s_fine_0_field_p%d.gkyl", ten_moment_output, i); - - rename(buf_old_elc, buf_new_elc); - rename(buf_old_ion, buf_new_ion); - rename(buf_old_field, buf_new_field); - - remove(buf_del_elc); - remove(buf_del_ion); - remove(buf_del_field); - } -#else char amr0[64]; snprintf(amr0, 64, "%s_0", ten_moment_output); - five_moment_write_sol_patch(amr0, num_patches, coarse_pdata); -#endif + five_moment_write_sol_patch(amr0, num_patches, mesh_pdata); double coarse_t_curr = 0.0; double fine_t_curr = 0.0; - double coarse_dt = five_moment_max_dt_patch(num_patches, coarse_pdata); + double coarse_dt = five_moment_max_dt_patch(num_patches, mesh_pdata); -#ifdef AMR_DEBUG - double fine_dt = five_moment_max_dt_patch(num_patches, fine_pdata); -#else double fine_dt = (1.0 / ref_factor) * coarse_dt; -#endif struct sim_stats stats = { }; @@ -377,7 +194,7 @@ ten_moment_1d_run_single(int argc, char **argv, struct ten_moment_1d_single_init while ((coarse_t_curr < t_end) && (coarse_step <= num_steps)) { printf("Taking coarse (level 0) time-step %ld at t = %g; ", coarse_step, coarse_t_curr); - struct gkyl_update_status coarse_status = five_moment_update_patch(coarse_job_pool, ptopo, coarse_pdata, coarse_t_curr, coarse_dt, &stats); + struct gkyl_update_status coarse_status = five_moment_update_patch(coarse_job_pool, ptopo, mesh_pdata, coarse_t_curr, coarse_dt, &stats); printf(" dt = %g\n", coarse_status.dt_actual); if (!coarse_status.success) { @@ -386,94 +203,19 @@ ten_moment_1d_run_single(int argc, char **argv, struct ten_moment_1d_single_init } for (long fine_step = 1; fine_step < ref_factor + 1; fine_step++) { -#ifdef AMR_DEBUG - printf(" Taking fine (level 1) time-step %ld at t = %g; ", fine_step, fine_t_curr); - struct gkyl_update_status fine_status = five_moment_update_patch(fine_job_pool, ptopo, fine_pdata, fine_t_curr, fine_dt, &stats); - printf(" dt = %g\n", fine_status.dt_actual); - - if (!fine_status.success) { - printf("** Update method failed! Aborting simulation ....\n"); - break; - } - - fine_t_curr += fine_status.dt_actual; - fine_dt += fine_status.dt_suggested; -#else printf(" Taking fine (level 1) time-step %ld at t = %g", fine_step, fine_t_curr); printf(" dt = %g\n", (1.0 / ref_factor) * coarse_status.dt_actual); fine_t_curr += (1.0 / ref_factor) * coarse_status.dt_actual; fine_dt = (1.0 / ref_factor) * coarse_status.dt_suggested; -#endif } for (int i = 1; i < num_frames; i++) { if (coarse_t_curr < (i * io_trigger) && (coarse_t_curr + coarse_status.dt_actual) > (i * io_trigger)) { -#ifdef AMR_DEBUG - char buf_coarse[64]; - char buf_fine[64]; - - snprintf(buf_coarse, 64, "%s_coarse_%d", ten_moment_output, i); - snprintf(buf_fine, 64, "%s_fine_%d", ten_moment_output, i); - - five_moment_write_sol_patch(buf_coarse, num_patches, coarse_pdata); - five_moment_write_sol_patch(buf_fine, num_patches, fine_pdata); - - char buf_fine_old_elc[64], buf_fine_old_ion[64], buf_fine_old_field[64]; - char buf_fine_new_elc[64], buf_fine_new_ion[64], buf_fine_new_field[64]; - char buf_coarse_old_elc[64], buf_coarse_old_ion[64], buf_coarse_old_field[64]; - - snprintf(buf_fine_old_elc, 64, "%s_fine_%d_elc_p0.gkyl", ten_moment_output, i); - snprintf(buf_fine_old_ion, 64, "%s_fine_%d_ion_p0.gkyl", ten_moment_output, i); - snprintf(buf_fine_old_field, 64, "%s_fine_%d_field_p0.gkyl", ten_moment_output, i); - - snprintf(buf_fine_new_elc, 64, "%s_%d_elc_p0.gkyl", ten_moment_output, i); - snprintf(buf_fine_new_ion, 64, "%s_%d_ion_p0.gkyl", ten_moment_output, i); - snprintf(buf_fine_new_field, 64, "%s_%d_field_p0.gkyl", ten_moment_output, i); - - snprintf(buf_coarse_old_elc, 64, "%s_coarse_%d_elc_p0.gkyl", ten_moment_output, i); - snprintf(buf_coarse_old_ion, 64, "%s_coarse_%d_ion_p0.gkyl", ten_moment_output, i); - snprintf(buf_coarse_old_field, 64, "%s_coarse_%d_field_p0.gkyl", ten_moment_output, i); - - rename(buf_fine_old_elc, buf_fine_new_elc); - rename(buf_fine_old_ion, buf_fine_new_ion); - rename(buf_fine_old_field, buf_fine_new_field); - - remove(buf_coarse_old_elc); - remove(buf_coarse_old_ion); - remove(buf_coarse_old_field); - - for (int j = 1; j < 3; j++) { - char buf_old_elc[64], buf_old_ion[64], buf_old_field[64]; - char buf_new_elc[64], buf_new_ion[64], buf_new_field[64]; - char buf_del_elc[64], buf_del_ion[64], buf_del_field[64]; - - snprintf(buf_old_elc, 64, "%s_coarse_%d_elc_p%d.gkyl", ten_moment_output, i, j); - snprintf(buf_old_ion, 64, "%s_coarse_%d_ion_p%d.gkyl", ten_moment_output, i, j); - snprintf(buf_old_field, 64, "%s_coarse_%d_field_p%d.gkyl", ten_moment_output, i, j); - - snprintf(buf_new_elc, 64, "%s_%d_elc_p%d.gkyl", ten_moment_output, i, j); - snprintf(buf_new_ion, 64, "%s_%d_ion_p%d.gkyl", ten_moment_output, i, j); - snprintf(buf_new_field, 64, "%s_%d_field_p%d.gkyl", ten_moment_output, i, j); - - snprintf(buf_del_elc, 64, "%s_fine_%d_elc_p%d.gkyl", ten_moment_output, i, j); - snprintf(buf_del_ion, 64, "%s_fine_%d_ion_p%d.gkyl", ten_moment_output, i, j); - snprintf(buf_del_field, 64, "%s_fine_%d_field_p%d.gkyl", ten_moment_output, i, j); - - rename(buf_old_elc, buf_new_elc); - rename(buf_old_ion, buf_new_ion); - rename(buf_old_field, buf_new_field); - - remove(buf_del_elc); - remove(buf_del_ion); - remove(buf_del_field); - } -#else char buf[64]; snprintf(buf, 64, "%s_%d", ten_moment_output, i); - five_moment_write_sol_patch(buf, num_patches, coarse_pdata); -#endif + five_moment_write_sol_patch(buf, num_patches, mesh_pdata); } } @@ -504,154 +246,48 @@ ten_moment_1d_run_single(int argc, char **argv, struct ten_moment_1d_single_init double tm_total_sec = gkyl_time_diff_now_sec(tm_start); -#ifdef AMR_DEBUG - char buf_coarse[64]; - char buf_fine[64]; - - snprintf(buf_coarse, 64, "%s_coarse_%d", ten_moment_output, num_frames); - snprintf(buf_fine, 64, "%s_fine_%d", ten_moment_output, num_frames); - - five_moment_write_sol_patch(buf_coarse, num_patches, coarse_pdata); - five_moment_write_sol_patch(buf_fine, num_patches, fine_pdata); - - char buf_fine_old_elc[64], buf_fine_old_ion[64], buf_fine_old_field[64]; - char buf_fine_new_elc[64], buf_fine_new_ion[64], buf_fine_new_field[64]; - char buf_coarse_old_elc[64], buf_coarse_old_ion[64], buf_coarse_old_field[64]; - - snprintf(buf_fine_old_elc, 64, "%s_fine_%d_elc_p0.gkyl", ten_moment_output, num_frames); - snprintf(buf_fine_old_ion, 64, "%s_fine_%d_ion_p0.gkyl", ten_moment_output, num_frames); - snprintf(buf_fine_old_field, 64, "%s_fine_%d_field_p0.gkyl", ten_moment_output, num_frames); - - snprintf(buf_fine_new_elc, 64, "%s_%d_elc_p0.gkyl", ten_moment_output, num_frames); - snprintf(buf_fine_new_ion, 64, "%s_%d_ion_p0.gkyl", ten_moment_output, num_frames); - snprintf(buf_fine_new_field, 64, "%s_%d_field_p0.gkyl", ten_moment_output, num_frames); - - snprintf(buf_coarse_old_elc, 64, "%s_coarse_%d_elc_p0.gkyl", ten_moment_output, num_frames); - snprintf(buf_coarse_old_ion, 64, "%s_coarse_%d_ion_p0.gkyl", ten_moment_output, num_frames); - snprintf(buf_coarse_old_field, 64, "%s_coarse_%d_field_p0.gkyl", ten_moment_output, num_frames); - - rename(buf_fine_old_elc, buf_fine_new_elc); - rename(buf_fine_old_ion, buf_fine_new_ion); - rename(buf_fine_old_field, buf_fine_new_field); - - remove(buf_coarse_old_elc); - remove(buf_coarse_old_ion); - remove(buf_coarse_old_field); - - for (int i = 1; i < 3; i++) { - char buf_old_elc[64], buf_old_ion[64], buf_old_field[64]; - char buf_new_elc[64], buf_new_ion[64], buf_new_field[64]; - char buf_del_elc[64], buf_del_ion[64], buf_del_field[64]; - - snprintf(buf_old_elc, 64, "%s_coarse_%d_elc_p%d.gkyl", ten_moment_output, num_frames, i); - snprintf(buf_old_ion, 64, "%s_coarse_%d_ion_p%d.gkyl", ten_moment_output, num_frames, i); - snprintf(buf_old_field, 64, "%s_coarse_%d_field_p%d.gkyl", ten_moment_output, num_frames, i); - - snprintf(buf_new_elc, 64, "%s_%d_elc_p%d.gkyl", ten_moment_output, num_frames, i); - snprintf(buf_new_ion, 64, "%s_%d_ion_p%d.gkyl", ten_moment_output, num_frames, i); - snprintf(buf_new_field, 64, "%s_%d_field_p%d.gkyl", ten_moment_output, num_frames, i); - - snprintf(buf_del_elc, 64, "%s_fine_%d_elc_p%d.gkyl", ten_moment_output, num_frames, i); - snprintf(buf_del_ion, 64, "%s_fine_%d_ion_p%d.gkyl", ten_moment_output, num_frames, i); - snprintf(buf_del_field, 64, "%s_fine_%d_field_p%d.gkyl", ten_moment_output, num_frames, i); - - rename(buf_old_elc, buf_new_elc); - rename(buf_old_ion, buf_new_ion); - rename(buf_old_field, buf_new_field); - - remove(buf_del_elc); - remove(buf_del_ion); - remove(buf_del_field); - } -#else char buf[64]; snprintf(buf, 64, "%s_%d", ten_moment_output, num_frames); - five_moment_write_sol_patch(buf, num_patches, coarse_pdata); -#endif + five_moment_write_sol_patch(buf, num_patches, mesh_pdata); printf("Total run-time: %g. Failed steps: %d\n", tm_total_sec, stats.nfail); for (int i = 0; i < num_patches; i++) { - gkyl_fv_proj_release(coarse_pdata[i].fv_proj_elc); - gkyl_fv_proj_release(coarse_pdata[i].fv_proj_ion); - gkyl_fv_proj_release(coarse_pdata[i].fv_proj_maxwell); - - gkyl_wv_eqn_release(coarse_pdata[i].euler_elc); - gkyl_wv_eqn_release(coarse_pdata[i].euler_ion); - gkyl_wv_eqn_release(coarse_pdata[i].maxwell); - - five_moment_patch_bc_updaters_release(&coarse_pdata[i]); - gkyl_wave_geom_release(coarse_pdata[i].geom); - -#ifdef AMR_DEBUG - gkyl_fv_proj_release(fine_pdata[i].fv_proj_elc); - gkyl_fv_proj_release(fine_pdata[i].fv_proj_ion); - gkyl_fv_proj_release(fine_pdata[i].fv_proj_maxwell); - - gkyl_wv_eqn_release(fine_pdata[i].euler_elc); - gkyl_wv_eqn_release(fine_pdata[i].euler_ion); - gkyl_wv_eqn_release(fine_pdata[i].maxwell); - - five_moment_patch_bc_updaters_release(&fine_pdata[i]); - gkyl_wave_geom_release(fine_pdata[i].geom); -#endif - - gkyl_wave_prop_release(coarse_pdata[i].slvr_elc[0]); - gkyl_wave_prop_release(coarse_pdata[i].slvr_ion[0]); - gkyl_wave_prop_release(coarse_pdata[i].slvr_maxwell[0]); + gkyl_fv_proj_release(mesh_pdata[i].fv_proj_elc); + gkyl_fv_proj_release(mesh_pdata[i].fv_proj_ion); + gkyl_fv_proj_release(mesh_pdata[i].fv_proj_maxwell); -#ifdef AMR_DEBUG - gkyl_wave_prop_release(fine_pdata[i].slvr_elc[0]); - gkyl_wave_prop_release(fine_pdata[i].slvr_ion[0]); - gkyl_wave_prop_release(fine_pdata[i].slvr_maxwell[0]); -#endif + gkyl_wv_eqn_release(mesh_pdata[i].euler_elc); + gkyl_wv_eqn_release(mesh_pdata[i].euler_ion); + gkyl_wv_eqn_release(mesh_pdata[i].maxwell); - gkyl_array_release(coarse_pdata[i].fdup_elc); - gkyl_array_release(coarse_pdata[i].fdup_ion); - gkyl_array_release(coarse_pdata[i].fdup_maxwell); + five_moment_patch_bc_updaters_release(&mesh_pdata[i]); + gkyl_wave_geom_release(mesh_pdata[i].geom); -#ifdef AMR_DEBUG - gkyl_array_release(fine_pdata[i].fdup_elc); - gkyl_array_release(fine_pdata[i].fdup_ion); - gkyl_array_release(fine_pdata[i].fdup_maxwell); -#endif + gkyl_wave_prop_release(mesh_pdata[i].slvr_elc[0]); + gkyl_wave_prop_release(mesh_pdata[i].slvr_ion[0]); + gkyl_wave_prop_release(mesh_pdata[i].slvr_maxwell[0]); - gkyl_array_release(coarse_pdata[i].f_elc[0]); - gkyl_array_release(coarse_pdata[i].f_ion[0]); - gkyl_array_release(coarse_pdata[i].f_maxwell[0]); + gkyl_array_release(mesh_pdata[i].fdup_elc); + gkyl_array_release(mesh_pdata[i].fdup_ion); + gkyl_array_release(mesh_pdata[i].fdup_maxwell); -#ifdef AMR_DEBUG - gkyl_array_release(fine_pdata[i].f_elc[0]); - gkyl_array_release(fine_pdata[i].f_ion[0]); - gkyl_array_release(fine_pdata[i].f_maxwell[0]); -#endif + gkyl_array_release(mesh_pdata[i].f_elc[0]); + gkyl_array_release(mesh_pdata[i].f_ion[0]); + gkyl_array_release(mesh_pdata[i].f_maxwell[0]); - gkyl_array_release(coarse_pdata[i].app_accel_elc); - gkyl_array_release(coarse_pdata[i].app_accel_ion); - gkyl_array_release(coarse_pdata[i].rhs_source_elc); - gkyl_array_release(coarse_pdata[i].rhs_source_ion); - gkyl_array_release(coarse_pdata[i].ext_em); - gkyl_array_release(coarse_pdata[i].app_current); - gkyl_array_release(coarse_pdata[i].nT_source_elc); - gkyl_array_release(coarse_pdata[i].nT_source_ion); - -#ifdef AMR_DEBUG - gkyl_array_release(fine_pdata[i].app_accel_elc); - gkyl_array_release(fine_pdata[i].app_accel_ion); - gkyl_array_release(fine_pdata[i].rhs_source_elc); - gkyl_array_release(fine_pdata[i].rhs_source_ion); - gkyl_array_release(fine_pdata[i].ext_em); - gkyl_array_release(fine_pdata[i].app_current); - gkyl_array_release(fine_pdata[i].nT_source_elc); - gkyl_array_release(fine_pdata[i].nT_source_ion); -#endif + gkyl_array_release(mesh_pdata[i].app_accel_elc); + gkyl_array_release(mesh_pdata[i].app_accel_ion); + gkyl_array_release(mesh_pdata[i].rhs_source_elc); + gkyl_array_release(mesh_pdata[i].rhs_source_ion); + gkyl_array_release(mesh_pdata[i].ext_em); + gkyl_array_release(mesh_pdata[i].app_current); + gkyl_array_release(mesh_pdata[i].nT_source_elc); + gkyl_array_release(mesh_pdata[i].nT_source_ion); } gkyl_block_topo_release(ptopo); gkyl_job_pool_release(coarse_job_pool); -#ifdef AMR_DEBUG - gkyl_job_pool_release(fine_job_pool); -#endif } void @@ -717,360 +353,153 @@ ten_moment_2d_run_single(int argc, char **argv, struct ten_moment_2d_single_init int Nx = base_Nx; int Ny = base_Ny; - struct five_moment_block_data coarse_bdata[num_blocks]; + struct five_moment_block_data mesh_bdata[num_blocks]; struct gkyl_job_pool *coarse_job_pool = gkyl_thread_pool_new(app_args.num_threads); -#ifdef AMR_DEBUG - gkyl_rect_grid_init(&coarse_bdata[0].grid, 2, (double []) { refined_x1, refined_y1 }, (double []) { refined_x2, refined_y2 }, - (int []) { Nx, Ny }); -#else - gkyl_rect_grid_init(&coarse_bdata[0].grid, 2, (double []) { refined_x1, refined_y1 }, (double []) { refined_x2, refined_y2 }, + gkyl_rect_grid_init(&mesh_bdata[0].grid, 2, (double []) { refined_x1, refined_y1 }, (double []) { refined_x2, refined_y2 }, (int []) { Nx * ref_factor, Ny * ref_factor }); -#endif - gkyl_rect_grid_init(&coarse_bdata[1].grid, 2, (double []) { coarse_x1, refined_y2 }, (double []) { refined_x1, coarse_y2 }, + gkyl_rect_grid_init(&mesh_bdata[1].grid, 2, (double []) { coarse_x1, refined_y2 }, (double []) { refined_x1, coarse_y2 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[2].grid, 2, (double []) { refined_x1, refined_y2 }, (double []) { refined_x2, coarse_y2 }, + gkyl_rect_grid_init(&mesh_bdata[2].grid, 2, (double []) { refined_x1, refined_y2 }, (double []) { refined_x2, coarse_y2 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[3].grid, 2, (double []) { refined_x2, refined_y2 }, (double []) { coarse_x2, coarse_y2 }, + gkyl_rect_grid_init(&mesh_bdata[3].grid, 2, (double []) { refined_x2, refined_y2 }, (double []) { coarse_x2, coarse_y2 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[4].grid, 2, (double []) { coarse_x1, refined_y1 }, (double []) { refined_x1, refined_y2 }, + gkyl_rect_grid_init(&mesh_bdata[4].grid, 2, (double []) { coarse_x1, refined_y1 }, (double []) { refined_x1, refined_y2 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[5].grid, 2, (double []) { refined_x2, refined_y1 }, (double []) { coarse_x2, refined_y2 }, + gkyl_rect_grid_init(&mesh_bdata[5].grid, 2, (double []) { refined_x2, refined_y1 }, (double []) { coarse_x2, refined_y2 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[6].grid, 2, (double []) { coarse_x1, coarse_y1 }, (double []) { refined_x1, refined_y1 }, + gkyl_rect_grid_init(&mesh_bdata[6].grid, 2, (double []) { coarse_x1, coarse_y1 }, (double []) { refined_x1, refined_y1 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[7].grid, 2, (double []) { refined_x1, coarse_y1 }, (double []) { refined_x2, refined_y1 }, + gkyl_rect_grid_init(&mesh_bdata[7].grid, 2, (double []) { refined_x1, coarse_y1 }, (double []) { refined_x2, refined_y1 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[8].grid, 2, (double []) { refined_x2, coarse_y1 }, (double []) { coarse_x2, refined_y1 }, + gkyl_rect_grid_init(&mesh_bdata[8].grid, 2, (double []) { refined_x2, coarse_y1 }, (double []) { coarse_x2, refined_y1 }, (int []) { Nx, Ny }); -#ifdef AMR_DEBUG - struct five_moment_block_data fine_bdata[num_blocks]; - struct gkyl_job_pool *fine_job_pool = gkyl_thread_pool_new(app_args.num_threads); - - gkyl_rect_grid_init(&fine_bdata[0].grid, 2, (double []) { refined_x1, refined_y1 }, (double []) { refined_x2, refined_y2 }, - (int []) { Nx * ref_factor, Ny * ref_factor }); - gkyl_rect_grid_init(&fine_bdata[1].grid, 2, (double []) { coarse_x1, refined_y2 }, (double []) { refined_x1, coarse_y2 }, - (int []) { Nx * ref_factor, Ny * ref_factor }); - gkyl_rect_grid_init(&fine_bdata[2].grid, 2, (double []) { refined_x1, refined_y2 }, (double []) { refined_x2, coarse_y2 }, - (int []) { Nx * ref_factor, Ny * ref_factor }); - gkyl_rect_grid_init(&fine_bdata[3].grid, 2, (double []) { refined_x2, refined_y2 }, (double []) { coarse_x2, coarse_y2 }, - (int []) { Nx * ref_factor, Ny * ref_factor }); - gkyl_rect_grid_init(&fine_bdata[4].grid, 2, (double []) { coarse_x1, refined_y1 }, (double []) { refined_x1, refined_y2 }, - (int []) { Nx * ref_factor, Ny * ref_factor }); - gkyl_rect_grid_init(&fine_bdata[5].grid, 2, (double []) { refined_x2, refined_y1 }, (double []) { coarse_x2, refined_y2 }, - (int []) { Nx * ref_factor, Ny * ref_factor }); - gkyl_rect_grid_init(&fine_bdata[6].grid, 2, (double []) { coarse_x1, coarse_y1 }, (double []) { refined_x1, refined_y1 }, - (int []) { Nx * ref_factor, Ny * ref_factor }); - gkyl_rect_grid_init(&fine_bdata[7].grid, 2, (double []) { refined_x1, coarse_y1 }, (double []) { refined_x2, refined_y1 }, - (int []) { Nx * ref_factor, Ny * ref_factor }); - gkyl_rect_grid_init(&fine_bdata[8].grid, 2, (double []) { refined_x2, coarse_y1 }, (double []) { coarse_x2, refined_y1 }, - (int []) { Nx * ref_factor, Ny * ref_factor }); -#endif - for (int i = 0; i < num_blocks; i++) { - coarse_bdata[i].fv_proj_elc = gkyl_fv_proj_new(&coarse_bdata[i].grid, 2, 10, eval_elc, 0); - coarse_bdata[i].fv_proj_ion = gkyl_fv_proj_new(&coarse_bdata[i].grid, 2, 10, eval_ion, 0); - coarse_bdata[i].fv_proj_maxwell = gkyl_fv_proj_new(&coarse_bdata[i].grid, 2, 8, eval_field, 0); - -#ifdef AMR_DEBUG - fine_bdata[i].fv_proj_elc = gkyl_fv_proj_new(&fine_bdata[i].grid, 2, 10, eval_elc, 0); - fine_bdata[i].fv_proj_ion = gkyl_fv_proj_new(&fine_bdata[i].grid, 2, 10, eval_ion, 0); - fine_bdata[i].fv_proj_maxwell = gkyl_fv_proj_new(&fine_bdata[i].grid, 2, 8, eval_field, 0); -#endif + mesh_bdata[i].fv_proj_elc = gkyl_fv_proj_new(&mesh_bdata[i].grid, 2, 10, eval_elc, 0); + mesh_bdata[i].fv_proj_ion = gkyl_fv_proj_new(&mesh_bdata[i].grid, 2, 10, eval_ion, 0); + mesh_bdata[i].fv_proj_maxwell = gkyl_fv_proj_new(&mesh_bdata[i].grid, 2, 8, eval_field, 0); } for (int i = 0; i < num_blocks; i++) { - gkyl_create_grid_ranges(&coarse_bdata[i].grid, (int []) { 2, 2 }, &coarse_bdata[i].ext_range, &coarse_bdata[i].range); - coarse_bdata[i].geom = gkyl_wave_geom_new(&coarse_bdata[i].grid, &coarse_bdata[i].ext_range, 0, 0, false); + gkyl_create_grid_ranges(&mesh_bdata[i].grid, (int []) { 2, 2 }, &mesh_bdata[i].ext_range, &mesh_bdata[i].range); + mesh_bdata[i].geom = gkyl_wave_geom_new(&mesh_bdata[i].grid, &mesh_bdata[i].ext_range, 0, 0, false); - coarse_bdata[i].transmissive_x = transmissive_x; - coarse_bdata[i].transmissive_y = transmissive_y; - - coarse_bdata[i].wall_x = wall_x; - coarse_bdata[i].wall_y = wall_y; + mesh_bdata[i].transmissive_x = transmissive_x; + mesh_bdata[i].transmissive_y = transmissive_y; -#ifdef AMR_DEBUG - gkyl_create_grid_ranges(&fine_bdata[i].grid, (int []) { 2, 2 }, &fine_bdata[i].ext_range, &fine_bdata[i].range); - fine_bdata[i].geom = gkyl_wave_geom_new(&fine_bdata[i].grid, &fine_bdata[i].ext_range, 0, 0, false); - - fine_bdata[i].transmissive_x = transmissive_x; - fine_bdata[i].transmissive_y = transmissive_y; - - fine_bdata[i].wall_x = wall_x; - fine_bdata[i].wall_y = wall_y; -#endif + mesh_bdata[i].wall_x = wall_x; + mesh_bdata[i].wall_y = wall_y; } for (int i = 0; i < num_blocks; i++) { - coarse_bdata[i].euler_elc = gkyl_wv_ten_moment_new(k0_elc); - coarse_bdata[i].euler_ion = gkyl_wv_ten_moment_new(k0_ion); - coarse_bdata[i].maxwell = gkyl_wv_maxwell_new(light_speed, e_fact, b_fact); + mesh_bdata[i].euler_elc = gkyl_wv_ten_moment_new(k0_elc); + mesh_bdata[i].euler_ion = gkyl_wv_ten_moment_new(k0_ion); + mesh_bdata[i].maxwell = gkyl_wv_maxwell_new(light_speed, e_fact, b_fact); for (int d = 0; d < ndim; d++) { - coarse_bdata[i].slvr_elc[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &coarse_bdata[i].grid, - .equation = coarse_bdata[i].euler_elc, + mesh_bdata[i].slvr_elc[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { + .grid = &mesh_bdata[i].grid, + .equation = mesh_bdata[i].euler_elc, .limiter = GKYL_MONOTONIZED_CENTERED, .num_up_dirs = 1, .update_dirs = { d }, .cfl = cfl_frac, - .geom = coarse_bdata[i].geom, + .geom = mesh_bdata[i].geom, } ); - coarse_bdata[i].slvr_ion[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &coarse_bdata[i].grid, - .equation = coarse_bdata[i].euler_ion, + mesh_bdata[i].slvr_ion[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { + .grid = &mesh_bdata[i].grid, + .equation = mesh_bdata[i].euler_ion, .limiter = GKYL_MONOTONIZED_CENTERED, .num_up_dirs = 1, .update_dirs = { d }, .cfl = cfl_frac, - .geom = coarse_bdata[i].geom, + .geom = mesh_bdata[i].geom, } ); - coarse_bdata[i].slvr_maxwell[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &coarse_bdata[i].grid, - .equation = coarse_bdata[i].maxwell, + mesh_bdata[i].slvr_maxwell[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { + .grid = &mesh_bdata[i].grid, + .equation = mesh_bdata[i].maxwell, .limiter = GKYL_MONOTONIZED_CENTERED, .num_up_dirs = 1, .update_dirs = { d }, .cfl = cfl_frac, - .geom = coarse_bdata[i].geom, + .geom = mesh_bdata[i].geom, } ); } struct gkyl_moment_em_coupling_inp coarse_src_inp = { - .grid = &coarse_bdata[i].grid, + .grid = &mesh_bdata[i].grid, .nfluids = 2, .epsilon0 = epsilon0, }; coarse_src_inp.param[0] = (struct gkyl_moment_em_coupling_data) { - .type = coarse_bdata[i].euler_elc->type, + .type = mesh_bdata[i].euler_elc->type, .charge = charge_elc, .mass = mass_elc, .k0 = k0_elc, }; coarse_src_inp.param[1] = (struct gkyl_moment_em_coupling_data) { - .type = coarse_bdata[i].euler_ion->type, - .charge = charge_ion, - .mass = mass_ion, - .k0 = k0_ion, - }; - - coarse_bdata[i].src_slvr = gkyl_moment_em_coupling_new(coarse_src_inp); - -#ifdef AMR_DEBUG - fine_bdata[i].euler_elc = gkyl_wv_ten_moment_new(k0_elc); - fine_bdata[i].euler_ion = gkyl_wv_ten_moment_new(k0_ion); - fine_bdata[i].maxwell = gkyl_wv_maxwell_new(light_speed, e_fact, b_fact); - - for (int d = 0; d < ndim; d++) { - fine_bdata[i].slvr_elc[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &fine_bdata[i].grid, - .equation = fine_bdata[i].euler_elc, - .limiter = GKYL_MONOTONIZED_CENTERED, - .num_up_dirs = 1, - .update_dirs = { d }, - .cfl = cfl_frac, - .geom = fine_bdata[i].geom, - } - ); - fine_bdata[i].slvr_ion[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &fine_bdata[i].grid, - .equation = fine_bdata[i].euler_ion, - .limiter = GKYL_MONOTONIZED_CENTERED, - .num_up_dirs = 1, - .update_dirs = { d }, - .cfl = cfl_frac, - .geom = fine_bdata[i].geom, - } - ); - fine_bdata[i].slvr_maxwell[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &fine_bdata[i].grid, - .equation = fine_bdata[i].maxwell, - .limiter = GKYL_MONOTONIZED_CENTERED, - .num_up_dirs = 1, - .update_dirs = { d }, - .cfl = cfl_frac, - .geom = fine_bdata[i].geom, - } - ); - } - - struct gkyl_moment_em_coupling_inp fine_src_inp = { - .grid = &fine_bdata[i].grid, - .nfluids = 2, - .epsilon0 = epsilon0, - }; - - fine_src_inp.param[0] = (struct gkyl_moment_em_coupling_data) { - .type = fine_bdata[i].euler_elc->type, - .charge = charge_elc, - .mass = mass_elc, - .k0 = k0_elc, - }; - fine_src_inp.param[1] = (struct gkyl_moment_em_coupling_data) { - .type = fine_bdata[i].euler_ion->type, + .type = mesh_bdata[i].euler_ion->type, .charge = charge_ion, .mass = mass_ion, .k0 = k0_ion, }; - fine_bdata[i].src_slvr = gkyl_moment_em_coupling_new(fine_src_inp); -#endif + mesh_bdata[i].src_slvr = gkyl_moment_em_coupling_new(coarse_src_inp); } struct gkyl_block_topo *btopo = create_block_topo(); for (int i = 0; i < num_blocks; i++) { - ten_moment_block_bc_updaters_init(&coarse_bdata[i], &btopo->conn[i]); - -#ifdef AMR_DEBUG - ten_moment_block_bc_updaters_init(&fine_bdata[i], &btopo->conn[i]); -#endif + ten_moment_block_bc_updaters_init(&mesh_bdata[i], &btopo->conn[i]); } for (int i = 0; i < num_blocks; i++) { - coarse_bdata[i].fdup_elc = gkyl_array_new(GKYL_DOUBLE, 10, coarse_bdata[i].ext_range.volume); - coarse_bdata[i].fdup_ion = gkyl_array_new(GKYL_DOUBLE, 10, coarse_bdata[i].ext_range.volume); - coarse_bdata[i].fdup_maxwell = gkyl_array_new(GKYL_DOUBLE, 8, coarse_bdata[i].ext_range.volume); - - for (int d = 0; d < ndim + 1; d++) { - coarse_bdata[i].f_elc[d] = gkyl_array_new(GKYL_DOUBLE, 10, coarse_bdata[i].ext_range.volume); - coarse_bdata[i].f_ion[d] = gkyl_array_new(GKYL_DOUBLE, 10, coarse_bdata[i].ext_range.volume); - coarse_bdata[i].f_maxwell[d] = gkyl_array_new(GKYL_DOUBLE, 8, coarse_bdata[i].ext_range.volume); - } - - coarse_bdata[i].app_accel_elc = gkyl_array_new(GKYL_DOUBLE, 3, coarse_bdata[i].ext_range.volume); - coarse_bdata[i].app_accel_ion = gkyl_array_new(GKYL_DOUBLE, 3, coarse_bdata[i].ext_range.volume); - coarse_bdata[i].rhs_source_elc = gkyl_array_new(GKYL_DOUBLE, 10, coarse_bdata[i].ext_range.volume); - coarse_bdata[i].rhs_source_ion = gkyl_array_new(GKYL_DOUBLE, 10, coarse_bdata[i].ext_range.volume); - coarse_bdata[i].ext_em = gkyl_array_new(GKYL_DOUBLE, 6, coarse_bdata[i].ext_range.volume); - coarse_bdata[i].app_current = gkyl_array_new(GKYL_DOUBLE, 3, coarse_bdata[i].ext_range.volume); - coarse_bdata[i].nT_source_elc = gkyl_array_new(GKYL_DOUBLE, 2, coarse_bdata[i].ext_range.volume); - coarse_bdata[i].nT_source_ion = gkyl_array_new(GKYL_DOUBLE, 2, coarse_bdata[i].ext_range.volume); - -#ifdef AMR_DEBUG - fine_bdata[i].fdup_elc = gkyl_array_new(GKYL_DOUBLE, 10, fine_bdata[i].ext_range.volume); - fine_bdata[i].fdup_ion = gkyl_array_new(GKYL_DOUBLE, 10, fine_bdata[i].ext_range.volume); - fine_bdata[i].fdup_maxwell = gkyl_array_new(GKYL_DOUBLE, 8, fine_bdata[i].ext_range.volume); + mesh_bdata[i].fdup_elc = gkyl_array_new(GKYL_DOUBLE, 10, mesh_bdata[i].ext_range.volume); + mesh_bdata[i].fdup_ion = gkyl_array_new(GKYL_DOUBLE, 10, mesh_bdata[i].ext_range.volume); + mesh_bdata[i].fdup_maxwell = gkyl_array_new(GKYL_DOUBLE, 8, mesh_bdata[i].ext_range.volume); for (int d = 0; d < ndim + 1; d++) { - fine_bdata[i].f_elc[d] = gkyl_array_new(GKYL_DOUBLE, 10, fine_bdata[i].ext_range.volume); - fine_bdata[i].f_ion[d] = gkyl_array_new(GKYL_DOUBLE, 10, fine_bdata[i].ext_range.volume); - fine_bdata[i].f_maxwell[d] = gkyl_array_new(GKYL_DOUBLE, 8, fine_bdata[i].ext_range.volume); + mesh_bdata[i].f_elc[d] = gkyl_array_new(GKYL_DOUBLE, 10, mesh_bdata[i].ext_range.volume); + mesh_bdata[i].f_ion[d] = gkyl_array_new(GKYL_DOUBLE, 10, mesh_bdata[i].ext_range.volume); + mesh_bdata[i].f_maxwell[d] = gkyl_array_new(GKYL_DOUBLE, 8, mesh_bdata[i].ext_range.volume); } - fine_bdata[i].app_accel_elc = gkyl_array_new(GKYL_DOUBLE, 3, fine_bdata[i].ext_range.volume); - fine_bdata[i].app_accel_ion = gkyl_array_new(GKYL_DOUBLE, 3, fine_bdata[i].ext_range.volume); - fine_bdata[i].rhs_source_elc = gkyl_array_new(GKYL_DOUBLE, 10, fine_bdata[i].ext_range.volume); - fine_bdata[i].rhs_source_ion = gkyl_array_new(GKYL_DOUBLE, 10, fine_bdata[i].ext_range.volume); - fine_bdata[i].ext_em = gkyl_array_new(GKYL_DOUBLE, 6, fine_bdata[i].ext_range.volume); - fine_bdata[i].app_current = gkyl_array_new(GKYL_DOUBLE, 3, fine_bdata[i].ext_range.volume); - fine_bdata[i].nT_source_elc = gkyl_array_new(GKYL_DOUBLE, 2, fine_bdata[i].ext_range.volume); - fine_bdata[i].nT_source_ion = gkyl_array_new(GKYL_DOUBLE, 2, fine_bdata[i].ext_range.volume); -#endif + mesh_bdata[i].app_accel_elc = gkyl_array_new(GKYL_DOUBLE, 3, mesh_bdata[i].ext_range.volume); + mesh_bdata[i].app_accel_ion = gkyl_array_new(GKYL_DOUBLE, 3, mesh_bdata[i].ext_range.volume); + mesh_bdata[i].rhs_source_elc = gkyl_array_new(GKYL_DOUBLE, 10, mesh_bdata[i].ext_range.volume); + mesh_bdata[i].rhs_source_ion = gkyl_array_new(GKYL_DOUBLE, 10, mesh_bdata[i].ext_range.volume); + mesh_bdata[i].ext_em = gkyl_array_new(GKYL_DOUBLE, 6, mesh_bdata[i].ext_range.volume); + mesh_bdata[i].app_current = gkyl_array_new(GKYL_DOUBLE, 3, mesh_bdata[i].ext_range.volume); + mesh_bdata[i].nT_source_elc = gkyl_array_new(GKYL_DOUBLE, 2, mesh_bdata[i].ext_range.volume); + mesh_bdata[i].nT_source_ion = gkyl_array_new(GKYL_DOUBLE, 2, mesh_bdata[i].ext_range.volume); } #ifdef AMR_USETHREADS for (int i = 0; i < num_blocks; i++) { - gkyl_job_pool_add_work(coarse_job_pool, five_moment_init_job_func_block, &coarse_bdata[i]); - -#ifdef AMR_DEBUG - gkyl_job_pool_add_work(fine_job_pool, five_moment_init_job_func_block, &fine_bdata[i]); -#endif + gkyl_job_pool_add_work(coarse_job_pool, five_moment_init_job_func_block, &mesh_bdata[i]); } gkyl_job_pool_wait(coarse_job_pool); - -#ifdef AMR_DEBUG - gkyl_job_pool_wait(fine_job_pool); -#endif #else for (int i = 0; i < num_blocks; i++) { - five_moment_init_job_func_block(&coarse_bdata[i]); - -#ifdef AMR_DEBUG - five_moment_init_job_func_block(&fine_bdata[i]); -#endif + five_moment_init_job_func_block(&mesh_bdata[i]); } #endif -#ifdef AMR_DEBUG - char coarse0[64]; - snprintf(coarse0, 64, "%s_coarse_0", ten_moment_output); - five_moment_write_sol_block(coarse0, num_blocks, coarse_bdata); - - char fine0[64]; - snprintf(fine0, 64, "%s_fine_0", ten_moment_output); - five_moment_write_sol_block(fine0, num_blocks, fine_bdata); - - char fine0_elc_b0[64], fine0_ion_b0[64], fine0_field_b0[64]; - char coarse0_elc_b0[64], coarse0_ion_b0[64], coarse0_field_b0[64]; - char b0_elc[64], b0_ion[64], b0_field[64]; - - snprintf(fine0_elc_b0, 64, "%s_fine_0_elc_b0.gkyl", ten_moment_output); - snprintf(fine0_ion_b0, 64, "%s_fine_0_ion_b0.gkyl", ten_moment_output); - snprintf(fine0_field_b0, 64, "%s_fine_0_field_b0.gkyl", ten_moment_output); - - snprintf(coarse0_elc_b0, 64, "%s_coarse_0_elc_b0.gkyl", ten_moment_output); - snprintf(coarse0_ion_b0, 64, "%s_coarse_0_ion_b0.gkyl", ten_moment_output); - snprintf(coarse0_field_b0, 64, "%s_coarse_0_field_b0.gkyl", ten_moment_output); - - snprintf(b0_elc, 64, "%s_0_elc_b0.gkyl", ten_moment_output); - snprintf(b0_ion, 64, "%s_0_ion_b0.gkyl", ten_moment_output); - snprintf(b0_field, 64, "%s_0_field_b0.gkyl", ten_moment_output); - - rename(fine0_elc_b0, b0_elc); - rename(fine0_ion_b0, b0_ion); - rename(fine0_field_b0, b0_field); - - remove(coarse0_elc_b0); - remove(coarse0_ion_b0); - remove(coarse0_field_b0); - - for (int i = 1; i < 9; i++) { - char buf_old_elc[64], buf_old_ion[64], buf_old_field[64]; - char buf_new_elc[64], buf_new_ion[64], buf_new_field[64]; - char buf_del_elc[64], buf_del_ion[64], buf_del_field[64]; - - snprintf(buf_old_elc, 64, "%s_coarse_0_elc_b%d.gkyl", ten_moment_output, i); - snprintf(buf_old_ion, 64, "%s_coarse_0_ion_b%d.gkyl", ten_moment_output, i); - snprintf(buf_old_field, 64, "%s_coarse_0_field_b%d.gkyl", ten_moment_output, i); - - snprintf(buf_new_elc, 64, "%s_0_elc_b%d.gkyl", ten_moment_output, i); - snprintf(buf_new_ion, 64, "%s_0_ion_b%d.gkyl", ten_moment_output, i); - snprintf(buf_new_field, 64, "%s_0_field_b%d.gkyl", ten_moment_output, i); - - snprintf(buf_del_elc, 64, "%s_fine_0_elc_b%d.gkyl", ten_moment_output, i); - snprintf(buf_del_ion, 64, "%s_fine_0_ion_b%d.gkyl", ten_moment_output, i); - snprintf(buf_del_field, 64, "%s_fine_0_field_b%d.gkyl", ten_moment_output, i); - - rename(buf_old_elc, buf_new_elc); - rename(buf_old_ion, buf_new_ion); - rename(buf_old_field, buf_new_field); - - remove(buf_del_elc); - remove(buf_del_ion); - remove(buf_del_field); - } -#else char amr0[64]; snprintf(amr0, 64, "%s_0", ten_moment_output); - five_moment_write_sol_block(amr0, num_blocks, coarse_bdata); -#endif + five_moment_write_sol_block(amr0, num_blocks, mesh_bdata); double coarse_t_curr = 0.0; double fine_t_curr = 0.0; - double coarse_dt = five_moment_max_dt_block(num_blocks, coarse_bdata); + double coarse_dt = five_moment_max_dt_block(num_blocks, mesh_bdata); -#ifdef AMR_DEBUG - double fine_dt = five_moment_max_dt_block(num_blocks, fine_bdata); -#else double fine_dt = (1.0 / ref_factor) * coarse_dt; -#endif struct sim_stats stats = { }; @@ -1086,7 +515,7 @@ ten_moment_2d_run_single(int argc, char **argv, struct ten_moment_2d_single_init while ((coarse_t_curr < t_end) && (coarse_step <= num_steps)) { printf("Taking coarse (level 0) time-step %ld at t = %g; ", coarse_step, coarse_t_curr); - struct gkyl_update_status coarse_status = five_moment_update_block(coarse_job_pool, btopo, coarse_bdata, coarse_t_curr, coarse_dt, &stats); + struct gkyl_update_status coarse_status = five_moment_update_block(coarse_job_pool, btopo, mesh_bdata, coarse_t_curr, coarse_dt, &stats); printf(" dt = %g\n", coarse_status.dt_actual); if (!coarse_status.success) { @@ -1095,94 +524,19 @@ ten_moment_2d_run_single(int argc, char **argv, struct ten_moment_2d_single_init } for (long fine_step = 1; fine_step < ref_factor + 1; fine_step++) { -#ifdef AMR_DEBUG - printf(" Taking fine (level 1) time-step %ld at t = %g; ", fine_step, fine_t_curr); - struct gkyl_update_status fine_status = five_moment_update_block(fine_job_pool, btopo, fine_bdata, fine_t_curr, fine_dt, &stats); - printf(" dt = %g\n", fine_status.dt_actual); - - if (!fine_status.success) { - printf("** Update method failed! Aborting simulation ....\n"); - break; - } - - fine_t_curr += fine_status.dt_actual; - fine_dt += fine_status.dt_suggested; -#else printf(" Taking fine (level 1) time-step %ld at t = %g", fine_step, fine_t_curr); printf(" dt = %g\n", (1.0 / ref_factor) * coarse_status.dt_actual); fine_t_curr += (1.0 / ref_factor) * coarse_status.dt_actual; fine_dt = (1.0 / ref_factor) * coarse_status.dt_suggested; -#endif } for (int i = 1; i < num_frames; i++) { if (coarse_t_curr < (i * io_trigger) && (coarse_t_curr + coarse_status.dt_actual) > (i * io_trigger)) { -#ifdef AMR_DEBUG - char buf_coarse[64]; - char buf_fine[64]; - - snprintf(buf_coarse, 64, "%s_coarse_%d", ten_moment_output, i); - snprintf(buf_fine, 64, "%s_fine_%d", ten_moment_output, i); - - five_moment_write_sol_block(buf_coarse, num_blocks, coarse_bdata); - five_moment_write_sol_block(buf_fine, num_blocks, fine_bdata); - - char buf_fine_old_elc[64], buf_fine_old_ion[64], buf_fine_old_field[64]; - char buf_fine_new_elc[64], buf_fine_new_ion[64], buf_fine_new_field[64]; - char buf_coarse_old_elc[64], buf_coarse_old_ion[64], buf_coarse_old_field[64]; - - snprintf(buf_fine_old_elc, 64, "%s_fine_%d_elc_b0.gkyl", ten_moment_output, i); - snprintf(buf_fine_old_ion, 64, "%s_fine_%d_ion_b0.gkyl", ten_moment_output, i); - snprintf(buf_fine_old_field, 64, "%s_fine_%d_field_b0.gkyl", ten_moment_output, i); - - snprintf(buf_fine_new_elc, 64, "%s_%d_elc_b0.gkyl", ten_moment_output, i); - snprintf(buf_fine_new_ion, 64, "%s_%d_ion_b0.gkyl", ten_moment_output, i); - snprintf(buf_fine_new_field, 64, "%s_%d_field_b0.gkyl", ten_moment_output, i); - - snprintf(buf_coarse_old_elc, 64, "%s_coarse_%d_elc_b0.gkyl", ten_moment_output, i); - snprintf(buf_coarse_old_ion, 64, "%s_coarse_%d_ion_b0.gkyl", ten_moment_output, i); - snprintf(buf_coarse_old_field, 64, "%s_coarse_%d_field_b0.gkyl", ten_moment_output, i); - - rename(buf_fine_old_elc, buf_fine_new_elc); - rename(buf_fine_old_ion, buf_fine_new_ion); - rename(buf_fine_old_field, buf_fine_new_field); - - remove(buf_coarse_old_elc); - remove(buf_coarse_old_ion); - remove(buf_coarse_old_field); - - for (int j = 1; j < 9; j++) { - char buf_old_elc[64], buf_old_ion[64], buf_old_field[64]; - char buf_new_elc[64], buf_new_ion[64], buf_new_field[64]; - char buf_del_elc[64], buf_del_ion[64], buf_del_field[64]; - - snprintf(buf_old_elc, 64, "%s_coarse_%d_elc_b%d.gkyl", ten_moment_output, i, j); - snprintf(buf_old_ion, 64, "%s_coarse_%d_ion_b%d.gkyl", ten_moment_output, i, j); - snprintf(buf_old_field, 64, "%s_coarse_%d_field_b%d.gkyl", ten_moment_output, i, j); - - snprintf(buf_new_elc, 64, "%s_%d_elc_b%d.gkyl", ten_moment_output, i, j); - snprintf(buf_new_ion, 64, "%s_%d_ion_b%d.gkyl", ten_moment_output, i, j); - snprintf(buf_new_field, 64, "%s_%d_field_b%d.gkyl", ten_moment_output, i, j); - - snprintf(buf_del_elc, 64, "%s_fine_%d_elc_b%d.gkyl", ten_moment_output, i, j); - snprintf(buf_del_ion, 64, "%s_fine_%d_ion_b%d.gkyl", ten_moment_output, i, j); - snprintf(buf_del_field, 64, "%s_fine_%d_field_b%d.gkyl", ten_moment_output, i, j); - - rename(buf_old_elc, buf_new_elc); - rename(buf_old_ion, buf_new_ion); - rename(buf_old_field, buf_new_field); - - remove(buf_del_elc); - remove(buf_del_ion); - remove(buf_del_field); - } -#else char buf[64]; snprintf(buf, 64, "%s_%d", ten_moment_output, i); - five_moment_write_sol_block(buf, num_blocks, coarse_bdata); -#endif + five_moment_write_sol_block(buf, num_blocks, mesh_bdata); } } @@ -1213,159 +567,53 @@ ten_moment_2d_run_single(int argc, char **argv, struct ten_moment_2d_single_init double tm_total_sec = gkyl_time_diff_now_sec(tm_start); -#ifdef AMR_DEBUG - char buf_coarse[64]; - char buf_fine[64]; - - snprintf(buf_coarse, 64, "%s_coarse_%d", ten_moment_output, num_frames); - snprintf(buf_fine, 64, "%s_fine_%d", ten_moment_output, num_frames); - - five_moment_write_sol_block(buf_coarse, num_blocks, coarse_bdata); - five_moment_write_sol_block(buf_fine, num_blocks, fine_bdata); - - char buf_fine_old_elc[64], buf_fine_old_ion[64], buf_fine_old_field[64]; - char buf_fine_new_elc[64], buf_fine_new_ion[64], buf_fine_new_field[64]; - char buf_coarse_old_elc[64], buf_coarse_old_ion[64], buf_coarse_old_field[64]; - - snprintf(buf_fine_old_elc, 64, "%s_fine_%d_elc_b0.gkyl", ten_moment_output, num_frames); - snprintf(buf_fine_old_ion, 64, "%s_fine_%d_ion_b0.gkyl", ten_moment_output, num_frames); - snprintf(buf_fine_old_field, 64, "%s_fine_%d_field_b0.gkyl", ten_moment_output, num_frames); - - snprintf(buf_fine_new_elc, 64, "%s_%d_elc_b0.gkyl", ten_moment_output, num_frames); - snprintf(buf_fine_new_ion, 64, "%s_%d_ion_b0.gkyl", ten_moment_output, num_frames); - snprintf(buf_fine_new_field, 64, "%s_%d_field_b0.gkyl", ten_moment_output, num_frames); - - snprintf(buf_coarse_old_elc, 64, "%s_coarse_%d_elc_b0.gkyl", ten_moment_output, num_frames); - snprintf(buf_coarse_old_ion, 64, "%s_coarse_%d_ion_b0.gkyl", ten_moment_output, num_frames); - snprintf(buf_coarse_old_field, 64, "%s_coarse_%d_field_b0.gkyl", ten_moment_output, num_frames); - - rename(buf_fine_old_elc, buf_fine_new_elc); - rename(buf_fine_old_ion, buf_fine_new_ion); - rename(buf_fine_old_field, buf_fine_new_field); - - remove(buf_coarse_old_elc); - remove(buf_coarse_old_ion); - remove(buf_coarse_old_field); - - for (int i = 1; i < 9; i++) { - char buf_old_elc[64], buf_old_ion[64], buf_old_field[64]; - char buf_new_elc[64], buf_new_ion[64], buf_new_field[64]; - char buf_del_elc[64], buf_del_ion[64], buf_del_field[64]; - - snprintf(buf_old_elc, 64, "%s_coarse_%d_elc_b%d.gkyl", ten_moment_output, num_frames, i); - snprintf(buf_old_ion, 64, "%s_coarse_%d_ion_b%d.gkyl", ten_moment_output, num_frames, i); - snprintf(buf_old_field, 64, "%s_coarse_%d_field_b%d.gkyl", ten_moment_output, num_frames, i); - - snprintf(buf_new_elc, 64, "%s_%d_elc_b%d.gkyl", ten_moment_output, num_frames, i); - snprintf(buf_new_ion, 64, "%s_%d_ion_b%d.gkyl", ten_moment_output, num_frames, i); - snprintf(buf_new_field, 64, "%s_%d_field_b%d.gkyl", ten_moment_output, num_frames, i); - - snprintf(buf_del_elc, 64, "%s_fine_%d_elc_b%d.gkyl", ten_moment_output, num_frames, i); - snprintf(buf_del_ion, 64, "%s_fine_%d_ion_b%d.gkyl", ten_moment_output, num_frames, i); - snprintf(buf_del_field, 64, "%s_fine_%d_field_b%d.gkyl", ten_moment_output, num_frames, i); - - rename(buf_old_elc, buf_new_elc); - rename(buf_old_ion, buf_new_ion); - rename(buf_old_field, buf_new_field); - - remove(buf_del_elc); - remove(buf_del_ion); - remove(buf_del_field); - } -#else char buf[64]; snprintf(buf, 64, "%s_%d", ten_moment_output, num_frames); - five_moment_write_sol_block(buf, num_blocks, coarse_bdata); -#endif + five_moment_write_sol_block(buf, num_blocks, mesh_bdata); printf("Total run-time: %g. Failed steps: %d\n", tm_total_sec, stats.nfail); for (int i = 0; i < num_blocks; i++) { - gkyl_fv_proj_release(coarse_bdata[i].fv_proj_elc); - gkyl_fv_proj_release(coarse_bdata[i].fv_proj_ion); - gkyl_fv_proj_release(coarse_bdata[i].fv_proj_maxwell); + gkyl_fv_proj_release(mesh_bdata[i].fv_proj_elc); + gkyl_fv_proj_release(mesh_bdata[i].fv_proj_ion); + gkyl_fv_proj_release(mesh_bdata[i].fv_proj_maxwell); - gkyl_wv_eqn_release(coarse_bdata[i].euler_elc); - gkyl_wv_eqn_release(coarse_bdata[i].euler_ion); - gkyl_wv_eqn_release(coarse_bdata[i].maxwell); + gkyl_wv_eqn_release(mesh_bdata[i].euler_elc); + gkyl_wv_eqn_release(mesh_bdata[i].euler_ion); + gkyl_wv_eqn_release(mesh_bdata[i].maxwell); - five_moment_block_bc_updaters_release(&coarse_bdata[i]); - gkyl_wave_geom_release(coarse_bdata[i].geom); - -#ifdef AMR_DEBUG - gkyl_fv_proj_release(fine_bdata[i].fv_proj_elc); - gkyl_fv_proj_release(fine_bdata[i].fv_proj_ion); - gkyl_fv_proj_release(fine_bdata[i].fv_proj_maxwell); - - gkyl_wv_eqn_release(fine_bdata[i].euler_elc); - gkyl_wv_eqn_release(fine_bdata[i].euler_ion); - gkyl_wv_eqn_release(fine_bdata[i].maxwell); - - five_moment_block_bc_updaters_release(&fine_bdata[i]); - gkyl_wave_geom_release(fine_bdata[i].geom); -#endif + five_moment_block_bc_updaters_release(&mesh_bdata[i]); + gkyl_wave_geom_release(mesh_bdata[i].geom); for (int d = 0; d < ndim; d++) { - gkyl_wave_prop_release(coarse_bdata[i].slvr_elc[d]); - gkyl_wave_prop_release(coarse_bdata[i].slvr_ion[d]); - gkyl_wave_prop_release(coarse_bdata[i].slvr_maxwell[d]); - -#ifdef AMR_DEBUG - gkyl_wave_prop_release(fine_bdata[i].slvr_elc[d]); - gkyl_wave_prop_release(fine_bdata[i].slvr_ion[d]); - gkyl_wave_prop_release(fine_bdata[i].slvr_maxwell[d]); -#endif + gkyl_wave_prop_release(mesh_bdata[i].slvr_elc[d]); + gkyl_wave_prop_release(mesh_bdata[i].slvr_ion[d]); + gkyl_wave_prop_release(mesh_bdata[i].slvr_maxwell[d]); } - gkyl_array_release(coarse_bdata[i].fdup_elc); - gkyl_array_release(coarse_bdata[i].fdup_ion); - gkyl_array_release(coarse_bdata[i].fdup_maxwell); - -#ifdef AMR_DEBUG - gkyl_array_release(fine_bdata[i].fdup_elc); - gkyl_array_release(fine_bdata[i].fdup_ion); - gkyl_array_release(fine_bdata[i].fdup_maxwell); -#endif + gkyl_array_release(mesh_bdata[i].fdup_elc); + gkyl_array_release(mesh_bdata[i].fdup_ion); + gkyl_array_release(mesh_bdata[i].fdup_maxwell); for(int d = 0; d < ndim; d++) { - gkyl_array_release(coarse_bdata[i].f_elc[d]); - gkyl_array_release(coarse_bdata[i].f_ion[d]); - gkyl_array_release(coarse_bdata[i].f_maxwell[d]); - -#ifdef AMR_DEBUG - gkyl_array_release(fine_bdata[i].f_elc[d]); - gkyl_array_release(fine_bdata[i].f_ion[d]); - gkyl_array_release(fine_bdata[i].f_maxwell[d]); -#endif + gkyl_array_release(mesh_bdata[i].f_elc[d]); + gkyl_array_release(mesh_bdata[i].f_ion[d]); + gkyl_array_release(mesh_bdata[i].f_maxwell[d]); } - gkyl_array_release(coarse_bdata[i].app_accel_elc); - gkyl_array_release(coarse_bdata[i].app_accel_ion); - gkyl_array_release(coarse_bdata[i].rhs_source_elc); - gkyl_array_release(coarse_bdata[i].rhs_source_ion); - gkyl_array_release(coarse_bdata[i].ext_em); - gkyl_array_release(coarse_bdata[i].app_current); - gkyl_array_release(coarse_bdata[i].nT_source_elc); - gkyl_array_release(coarse_bdata[i].nT_source_ion); - -#ifdef AMR_DEBUG - gkyl_array_release(fine_bdata[i].app_accel_elc); - gkyl_array_release(fine_bdata[i].app_accel_ion); - gkyl_array_release(fine_bdata[i].rhs_source_elc); - gkyl_array_release(fine_bdata[i].rhs_source_ion); - gkyl_array_release(fine_bdata[i].ext_em); - gkyl_array_release(fine_bdata[i].app_current); - gkyl_array_release(fine_bdata[i].nT_source_elc); - gkyl_array_release(fine_bdata[i].nT_source_ion); -#endif + gkyl_array_release(mesh_bdata[i].app_accel_elc); + gkyl_array_release(mesh_bdata[i].app_accel_ion); + gkyl_array_release(mesh_bdata[i].rhs_source_elc); + gkyl_array_release(mesh_bdata[i].rhs_source_ion); + gkyl_array_release(mesh_bdata[i].ext_em); + gkyl_array_release(mesh_bdata[i].app_current); + gkyl_array_release(mesh_bdata[i].nT_source_elc); + gkyl_array_release(mesh_bdata[i].nT_source_ion); } gkyl_block_topo_release(btopo); gkyl_job_pool_release(coarse_job_pool); -#ifdef AMR_DEBUG - gkyl_job_pool_release(fine_job_pool); -#endif } void @@ -1438,654 +686,188 @@ ten_moment_2d_run_double(int argc, char **argv, struct ten_moment_2d_double_init int Nx = base_Nx; int Ny = base_Ny; - struct five_moment_block_data coarse_bdata[num_blocks]; + struct five_moment_block_data mesh_bdata[num_blocks]; struct gkyl_job_pool *coarse_job_pool = gkyl_thread_pool_new(app_args.num_threads); -#ifdef AMR_DEBUG - gkyl_rect_grid_init(&coarse_bdata[0].grid, 2, (double []) { refined_x1, refined_y1 }, (double []) { refined_x2, refined_y2 }, - (int []) { Nx, Ny }); - - gkyl_rect_grid_init(&coarse_bdata[1].grid, 2, (double []) { intermediate_x1, refined_y2 }, (double []) { refined_x1, intermediate_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[2].grid, 2, (double []) { refined_x1, refined_y2 }, (double []) { refined_x2, intermediate_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[3].grid, 2, (double []) { refined_x2, refined_y2 }, (double []) { intermediate_x2, intermediate_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[4].grid, 2, (double []) { intermediate_x1, refined_y1 }, (double []) { refined_x1, refined_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[5].grid, 2, (double []) { refined_x2, refined_y1 }, (double []) { intermediate_x2, refined_y2 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[6].grid, 2, (double []) { intermediate_x1, intermediate_y1 }, (double []) { refined_x1, refined_y1 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[7].grid, 2, (double []) { refined_x1, intermediate_y1 }, (double []) { refined_x2, refined_y1 }, - (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[8].grid, 2, (double []) { refined_x2, intermediate_y1 }, (double []) { intermediate_x2, refined_y1 }, - (int []) { Nx, Ny }); -#else - gkyl_rect_grid_init(&coarse_bdata[0].grid, 2, (double []) { refined_x1, refined_y1 }, (double []) { refined_x2, refined_y2 }, + gkyl_rect_grid_init(&mesh_bdata[0].grid, 2, (double []) { refined_x1, refined_y1 }, (double []) { refined_x2, refined_y2 }, (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&coarse_bdata[1].grid, 2, (double []) { intermediate_x1, refined_y2 }, (double []) { refined_x1, intermediate_y2 }, + gkyl_rect_grid_init(&mesh_bdata[1].grid, 2, (double []) { intermediate_x1, refined_y2 }, (double []) { refined_x1, intermediate_y2 }, (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&coarse_bdata[2].grid, 2, (double []) { refined_x1, refined_y2 }, (double []) { refined_x2, intermediate_y2 }, + gkyl_rect_grid_init(&mesh_bdata[2].grid, 2, (double []) { refined_x1, refined_y2 }, (double []) { refined_x2, intermediate_y2 }, (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&coarse_bdata[3].grid, 2, (double []) { refined_x2, refined_y2 }, (double []) { intermediate_x2, intermediate_y2 }, + gkyl_rect_grid_init(&mesh_bdata[3].grid, 2, (double []) { refined_x2, refined_y2 }, (double []) { intermediate_x2, intermediate_y2 }, (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&coarse_bdata[4].grid, 2, (double []) { intermediate_x1, refined_y1 }, (double []) { refined_x1, refined_y2 }, + gkyl_rect_grid_init(&mesh_bdata[4].grid, 2, (double []) { intermediate_x1, refined_y1 }, (double []) { refined_x1, refined_y2 }, (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&coarse_bdata[5].grid, 2, (double []) { refined_x2, refined_y1 }, (double []) { intermediate_x2, refined_y2 }, + gkyl_rect_grid_init(&mesh_bdata[5].grid, 2, (double []) { refined_x2, refined_y1 }, (double []) { intermediate_x2, refined_y2 }, (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&coarse_bdata[6].grid, 2, (double []) { intermediate_x1, intermediate_y1 }, (double []) { refined_x1, refined_y1 }, + gkyl_rect_grid_init(&mesh_bdata[6].grid, 2, (double []) { intermediate_x1, intermediate_y1 }, (double []) { refined_x1, refined_y1 }, (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&coarse_bdata[7].grid, 2, (double []) { refined_x1, intermediate_y1 }, (double []) { refined_x2, refined_y1 }, + gkyl_rect_grid_init(&mesh_bdata[7].grid, 2, (double []) { refined_x1, intermediate_y1 }, (double []) { refined_x2, refined_y1 }, (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&coarse_bdata[8].grid, 2, (double []) { refined_x2, intermediate_y1 }, (double []) { intermediate_x2, refined_y1 }, + gkyl_rect_grid_init(&mesh_bdata[8].grid, 2, (double []) { refined_x2, intermediate_y1 }, (double []) { intermediate_x2, refined_y1 }, (int []) { Nx * ref_factor1, Ny * ref_factor1 }); -#endif - gkyl_rect_grid_init(&coarse_bdata[9].grid, 2, (double []) { coarse_x1, intermediate_y2 }, (double []) { intermediate_x1, coarse_y2 }, + gkyl_rect_grid_init(&mesh_bdata[9].grid, 2, (double []) { coarse_x1, intermediate_y2 }, (double []) { intermediate_x1, coarse_y2 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[10].grid, 2, (double []) { intermediate_x1, intermediate_y2 }, (double []) { refined_x1, coarse_y2 }, + gkyl_rect_grid_init(&mesh_bdata[10].grid, 2, (double []) { intermediate_x1, intermediate_y2 }, (double []) { refined_x1, coarse_y2 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[11].grid, 2, (double []) { refined_x1, intermediate_y2 }, (double []) { refined_x2, coarse_y2 }, + gkyl_rect_grid_init(&mesh_bdata[11].grid, 2, (double []) { refined_x1, intermediate_y2 }, (double []) { refined_x2, coarse_y2 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[12].grid, 2, (double []) { refined_x2, intermediate_y2 }, (double []) { intermediate_x2, coarse_y2 }, + gkyl_rect_grid_init(&mesh_bdata[12].grid, 2, (double []) { refined_x2, intermediate_y2 }, (double []) { intermediate_x2, coarse_y2 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[13].grid, 2, (double []) { intermediate_x2, intermediate_y2 }, (double []) { coarse_x2, coarse_y2 }, + gkyl_rect_grid_init(&mesh_bdata[13].grid, 2, (double []) { intermediate_x2, intermediate_y2 }, (double []) { coarse_x2, coarse_y2 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[14].grid, 2, (double []) { coarse_x1, refined_y2 }, (double []) { intermediate_x1, intermediate_y2 }, + gkyl_rect_grid_init(&mesh_bdata[14].grid, 2, (double []) { coarse_x1, refined_y2 }, (double []) { intermediate_x1, intermediate_y2 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[15].grid, 2, (double []) { intermediate_x2, refined_y2 }, (double []) { coarse_x2, intermediate_y2 }, + gkyl_rect_grid_init(&mesh_bdata[15].grid, 2, (double []) { intermediate_x2, refined_y2 }, (double []) { coarse_x2, intermediate_y2 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[16].grid, 2, (double []) { coarse_x1, refined_y1 }, (double []) { intermediate_x1, refined_y2 }, + gkyl_rect_grid_init(&mesh_bdata[16].grid, 2, (double []) { coarse_x1, refined_y1 }, (double []) { intermediate_x1, refined_y2 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[17].grid, 2, (double []) { intermediate_x2, refined_y1 }, (double []) { coarse_x2, refined_y2 }, + gkyl_rect_grid_init(&mesh_bdata[17].grid, 2, (double []) { intermediate_x2, refined_y1 }, (double []) { coarse_x2, refined_y2 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[18].grid, 2, (double []) { coarse_x1, intermediate_y1 }, (double []) { intermediate_x1, refined_y1 }, + gkyl_rect_grid_init(&mesh_bdata[18].grid, 2, (double []) { coarse_x1, intermediate_y1 }, (double []) { intermediate_x1, refined_y1 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[19].grid, 2, (double []) { intermediate_x2, intermediate_y1 }, (double []) { coarse_x2, refined_y1 }, + gkyl_rect_grid_init(&mesh_bdata[19].grid, 2, (double []) { intermediate_x2, intermediate_y1 }, (double []) { coarse_x2, refined_y1 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[20].grid, 2, (double []) { coarse_x1, coarse_y1 }, (double []) { intermediate_x1, intermediate_y1 }, + gkyl_rect_grid_init(&mesh_bdata[20].grid, 2, (double []) { coarse_x1, coarse_y1 }, (double []) { intermediate_x1, intermediate_y1 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[21].grid, 2, (double []) { intermediate_x1, coarse_y1 }, (double []) { refined_x1, intermediate_y1 }, + gkyl_rect_grid_init(&mesh_bdata[21].grid, 2, (double []) { intermediate_x1, coarse_y1 }, (double []) { refined_x1, intermediate_y1 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[22].grid, 2, (double []) { refined_x1, coarse_y1 }, (double []) { refined_x2, intermediate_y1 }, + gkyl_rect_grid_init(&mesh_bdata[22].grid, 2, (double []) { refined_x1, coarse_y1 }, (double []) { refined_x2, intermediate_y1 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[23].grid, 2, (double []) { refined_x2, coarse_y1 }, (double []) { intermediate_x2, intermediate_y1 }, + gkyl_rect_grid_init(&mesh_bdata[23].grid, 2, (double []) { refined_x2, coarse_y1 }, (double []) { intermediate_x2, intermediate_y1 }, (int []) { Nx, Ny }); - gkyl_rect_grid_init(&coarse_bdata[24].grid, 2, (double []) { intermediate_x2, coarse_y1 }, (double []) { coarse_x2, intermediate_y1 }, + gkyl_rect_grid_init(&mesh_bdata[24].grid, 2, (double []) { intermediate_x2, coarse_y1 }, (double []) { coarse_x2, intermediate_y1 }, (int []) { Nx, Ny }); -#ifdef AMR_DEBUG - struct five_moment_block_data intermediate_bdata[num_blocks]; - struct gkyl_job_pool *intermediate_job_pool = gkyl_thread_pool_new(app_args.num_threads); - - gkyl_rect_grid_init(&intermediate_bdata[0].grid, 2, (double []) { refined_x1, refined_y1 }, (double []) { refined_x2, refined_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - - gkyl_rect_grid_init(&intermediate_bdata[1].grid, 2, (double []) { coarse_x1, refined_y2 }, (double []) { refined_x1, coarse_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[2].grid, 2, (double []) { refined_x1, refined_y2 }, (double []) { refined_x2, coarse_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[3].grid, 2, (double []) { refined_x2, refined_y2 }, (double []) { coarse_x2, coarse_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[4].grid, 2, (double []) { coarse_x1, refined_y1 }, (double []) { refined_x1, refined_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[5].grid, 2, (double []) { refined_x2, refined_y1 }, (double []) { coarse_x2, refined_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[6].grid, 2, (double []) { coarse_x1, coarse_y1 }, (double []) { refined_x1, refined_y1 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[7].grid, 2, (double []) { refined_x1, coarse_y1 }, (double []) { refined_x2, refined_y1 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[8].grid, 2, (double []) { refined_x2, coarse_y1 }, (double []) { coarse_x2, refined_y1 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - - gkyl_rect_grid_init(&intermediate_bdata[9].grid, 2, (double []) { coarse_x1, intermediate_y2 }, (double []) { intermediate_x1, coarse_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[10].grid, 2, (double []) { intermediate_x1, intermediate_y2 }, (double []) { refined_x1, coarse_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[11].grid, 2, (double []) { refined_x1, intermediate_y2 }, (double []) { refined_x2, coarse_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[12].grid, 2, (double []) { refined_x2, intermediate_y2 }, (double []) { intermediate_x2, coarse_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[13].grid, 2, (double []) { intermediate_x2, intermediate_y2 }, (double []) { coarse_x2, coarse_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[14].grid, 2, (double []) { coarse_x1, refined_y2 }, (double []) { intermediate_x1, intermediate_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[15].grid, 2, (double []) { intermediate_x2, refined_y2 }, (double []) { coarse_x2, intermediate_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[16].grid, 2, (double []) { coarse_x1, refined_y1 }, (double []) { intermediate_x1, refined_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[17].grid, 2, (double []) { intermediate_x2, refined_y1 }, (double []) { coarse_x2, refined_y2 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[18].grid, 2, (double []) { coarse_x1, intermediate_y1 }, (double []) { intermediate_x1, refined_y1 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[19].grid, 2, (double []) { intermediate_x2, intermediate_y1 }, (double []) { coarse_x2, refined_y1 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[20].grid, 2, (double []) { coarse_x1, coarse_y1 }, (double []) { intermediate_x1, intermediate_y1 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[21].grid, 2, (double []) { intermediate_x1, coarse_y1 }, (double []) { refined_x1, intermediate_y1 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[22].grid, 2, (double []) { refined_x1, coarse_y1 }, (double []) { refined_x2, intermediate_y1 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[23].grid, 2, (double []) { refined_x2, coarse_y1 }, (double []) { intermediate_x2, intermediate_y1 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - gkyl_rect_grid_init(&intermediate_bdata[24].grid, 2, (double []) { intermediate_x2, coarse_y1 }, (double []) { coarse_x2, intermediate_y1 }, - (int []) { Nx * ref_factor1, Ny * ref_factor1 }); - - struct five_moment_block_data fine_bdata[num_blocks]; - struct gkyl_job_pool *fine_job_pool = gkyl_thread_pool_new(app_args.num_threads); - - gkyl_rect_grid_init(&fine_bdata[0].grid, 2, (double []) { refined_x1, refined_y1 }, (double []) { refined_x2, refined_y2 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - - gkyl_rect_grid_init(&fine_bdata[1].grid, 2, (double []) { coarse_x1, refined_y2 }, (double []) { refined_x1, coarse_y2 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[2].grid, 2, (double []) { refined_x1, refined_y2 }, (double []) { refined_x2, coarse_y2 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[3].grid, 2, (double []) { refined_x2, refined_y2 }, (double []) { coarse_x2, coarse_y2 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[4].grid, 2, (double []) { coarse_x1, refined_y1 }, (double []) { refined_x1, refined_y2 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[5].grid, 2, (double []) { refined_x2, refined_y1 }, (double []) { coarse_x2, refined_y2 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[6].grid, 2, (double []) { coarse_x1, coarse_y1 }, (double []) { refined_x1, refined_y1 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[7].grid, 2, (double []) { refined_x1, coarse_y1 }, (double []) { refined_x2, refined_y1 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[8].grid, 2, (double []) { refined_x2, coarse_y1 }, (double []) { coarse_x2, refined_y1 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - - gkyl_rect_grid_init(&fine_bdata[9].grid, 2, (double []) { coarse_x1, intermediate_y2 }, (double []) { intermediate_x1, coarse_y2 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[10].grid, 2, (double []) { intermediate_x1, intermediate_y2 }, (double []) { refined_x1, coarse_y2 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[11].grid, 2, (double []) { refined_x1, intermediate_y2 }, (double []) { refined_x2, coarse_y2 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[12].grid, 2, (double []) { refined_x2, intermediate_y2 }, (double []) { intermediate_x2, coarse_y2 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[13].grid, 2, (double []) { intermediate_x2, intermediate_y2 }, (double []) { coarse_x2, coarse_y2 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[14].grid, 2, (double []) { coarse_x1, refined_y2 }, (double []) { intermediate_x1, intermediate_y2 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[15].grid, 2, (double []) { intermediate_x2, refined_y2 }, (double []) { coarse_x2, intermediate_y2 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[16].grid, 2, (double []) { coarse_x1, refined_y1 }, (double []) { intermediate_x1, refined_y2 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[17].grid, 2, (double []) { intermediate_x2, refined_y1 }, (double []) { coarse_x2, refined_y2 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[18].grid, 2, (double []) { coarse_x1, intermediate_y1 }, (double []) { intermediate_x1, refined_y1 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[19].grid, 2, (double []) { intermediate_x2, intermediate_y1 }, (double []) { coarse_x2, refined_y1 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[20].grid, 2, (double []) { coarse_x1, coarse_y1 }, (double []) { intermediate_x1, intermediate_y1 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[21].grid, 2, (double []) { intermediate_x1, coarse_y1 }, (double []) { refined_x1, intermediate_y1 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[22].grid, 2, (double []) { refined_x1, coarse_y1 }, (double []) { refined_x2, intermediate_y1 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[23].grid, 2, (double []) { refined_x2, coarse_y1 }, (double []) { intermediate_x2, intermediate_y1 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); - gkyl_rect_grid_init(&fine_bdata[24].grid, 2, (double []) { intermediate_x2, coarse_y1 }, (double []) { coarse_x2, intermediate_y1 }, - (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); -#endif - for (int i = 0; i < num_blocks; i++) { - coarse_bdata[i].fv_proj_elc = gkyl_fv_proj_new(&coarse_bdata[i].grid, 2, 10, eval_elc, 0); - coarse_bdata[i].fv_proj_ion = gkyl_fv_proj_new(&coarse_bdata[i].grid, 2, 10, eval_ion, 0); - coarse_bdata[i].fv_proj_maxwell = gkyl_fv_proj_new(&coarse_bdata[i].grid, 2, 8, eval_field, 0); - -#ifdef AMR_DEBUG - intermediate_bdata[i].fv_proj_elc = gkyl_fv_proj_new(&intermediate_bdata[i].grid, 2, 10, eval_elc, 0); - intermediate_bdata[i].fv_proj_ion = gkyl_fv_proj_new(&intermediate_bdata[i].grid, 2, 10, eval_ion, 0); - intermediate_bdata[i].fv_proj_maxwell = gkyl_fv_proj_new(&intermediate_bdata[i].grid, 2, 8, eval_field, 0); - - fine_bdata[i].fv_proj_elc = gkyl_fv_proj_new(&fine_bdata[i].grid, 2, 10, eval_elc, 0); - fine_bdata[i].fv_proj_ion = gkyl_fv_proj_new(&fine_bdata[i].grid, 2, 10, eval_ion, 0); - fine_bdata[i].fv_proj_maxwell = gkyl_fv_proj_new(&fine_bdata[i].grid, 2, 8, eval_field, 0); -#endif + mesh_bdata[i].fv_proj_elc = gkyl_fv_proj_new(&mesh_bdata[i].grid, 2, 10, eval_elc, 0); + mesh_bdata[i].fv_proj_ion = gkyl_fv_proj_new(&mesh_bdata[i].grid, 2, 10, eval_ion, 0); + mesh_bdata[i].fv_proj_maxwell = gkyl_fv_proj_new(&mesh_bdata[i].grid, 2, 8, eval_field, 0); } for (int i = 0; i < num_blocks; i++) { - gkyl_create_grid_ranges(&coarse_bdata[i].grid, (int []) { 2, 2 }, &coarse_bdata[i].ext_range, &coarse_bdata[i].range); - coarse_bdata[i].geom = gkyl_wave_geom_new(&coarse_bdata[i].grid, &coarse_bdata[i].ext_range, 0, 0, false); - - coarse_bdata[i].transmissive_x = transmissive_x; - coarse_bdata[i].transmissive_y = transmissive_y; - - coarse_bdata[i].wall_x = wall_x; - coarse_bdata[i].wall_y = wall_y; - -#ifdef AMR_DEBUG - gkyl_create_grid_ranges(&intermediate_bdata[i].grid, (int []) { 2, 2 }, &intermediate_bdata[i].ext_range, &intermediate_bdata[i].range); - intermediate_bdata[i].geom = gkyl_wave_geom_new(&intermediate_bdata[i].grid, &intermediate_bdata[i].ext_range, 0, 0, false); + gkyl_create_grid_ranges(&mesh_bdata[i].grid, (int []) { 2, 2 }, &mesh_bdata[i].ext_range, &mesh_bdata[i].range); + mesh_bdata[i].geom = gkyl_wave_geom_new(&mesh_bdata[i].grid, &mesh_bdata[i].ext_range, 0, 0, false); - intermediate_bdata[i].transmissive_x = transmissive_x; - intermediate_bdata[i].transmissive_y = transmissive_y; - - intermediate_bdata[i].wall_x = wall_x; - intermediate_bdata[i].wall_y = wall_y; - - gkyl_create_grid_ranges(&fine_bdata[i].grid, (int []) { 2, 2 }, &fine_bdata[i].ext_range, &fine_bdata[i].range); - fine_bdata[i].geom = gkyl_wave_geom_new(&fine_bdata[i].grid, &fine_bdata[i].ext_range, 0, 0, false); - - fine_bdata[i].transmissive_x = transmissive_x; - fine_bdata[i].transmissive_y = transmissive_y; + mesh_bdata[i].transmissive_x = transmissive_x; + mesh_bdata[i].transmissive_y = transmissive_y; - fine_bdata[i].wall_x = wall_x; - fine_bdata[i].wall_y = wall_y; -#endif + mesh_bdata[i].wall_x = wall_x; + mesh_bdata[i].wall_y = wall_y; } for (int i = 0; i < num_blocks; i++) { - coarse_bdata[i].euler_elc = gkyl_wv_ten_moment_new(k0_elc); - coarse_bdata[i].euler_ion = gkyl_wv_ten_moment_new(k0_ion); - coarse_bdata[i].maxwell = gkyl_wv_maxwell_new(light_speed, e_fact, b_fact); + mesh_bdata[i].euler_elc = gkyl_wv_ten_moment_new(k0_elc); + mesh_bdata[i].euler_ion = gkyl_wv_ten_moment_new(k0_ion); + mesh_bdata[i].maxwell = gkyl_wv_maxwell_new(light_speed, e_fact, b_fact); for (int d = 0; d < ndim; d++) { - coarse_bdata[i].slvr_elc[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &coarse_bdata[i].grid, - .equation = coarse_bdata[i].euler_elc, + mesh_bdata[i].slvr_elc[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { + .grid = &mesh_bdata[i].grid, + .equation = mesh_bdata[i].euler_elc, .limiter = GKYL_MONOTONIZED_CENTERED, .num_up_dirs = 1, .update_dirs = { d }, .cfl = cfl_frac, - .geom = coarse_bdata[i].geom, + .geom = mesh_bdata[i].geom, } ); - coarse_bdata[i].slvr_ion[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &coarse_bdata[i].grid, - .equation = coarse_bdata[i].euler_ion, + mesh_bdata[i].slvr_ion[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { + .grid = &mesh_bdata[i].grid, + .equation = mesh_bdata[i].euler_ion, .limiter = GKYL_MONOTONIZED_CENTERED, .num_up_dirs = 1, .update_dirs = { d }, .cfl = cfl_frac, - .geom = coarse_bdata[i].geom, + .geom = mesh_bdata[i].geom, } ); - coarse_bdata[i].slvr_maxwell[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &coarse_bdata[i].grid, - .equation = coarse_bdata[i].maxwell, + mesh_bdata[i].slvr_maxwell[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { + .grid = &mesh_bdata[i].grid, + .equation = mesh_bdata[i].maxwell, .limiter = GKYL_MONOTONIZED_CENTERED, .num_up_dirs = 1, .update_dirs = { d }, .cfl = cfl_frac, - .geom = coarse_bdata[i].geom, + .geom = mesh_bdata[i].geom, } ); } struct gkyl_moment_em_coupling_inp coarse_src_inp = { - .grid = &coarse_bdata[i].grid, + .grid = &mesh_bdata[i].grid, .nfluids = 2, .epsilon0 = epsilon0, }; coarse_src_inp.param[0] = (struct gkyl_moment_em_coupling_data) { - .type = coarse_bdata[i].euler_elc->type, + .type = mesh_bdata[i].euler_elc->type, .charge = charge_elc, .mass = mass_elc, .k0 = k0_elc, }; coarse_src_inp.param[1] = (struct gkyl_moment_em_coupling_data) { - .type = coarse_bdata[i].euler_ion->type, - .charge = charge_ion, - .mass = mass_ion, - .k0 = k0_ion, - }; - - coarse_bdata[i].src_slvr = gkyl_moment_em_coupling_new(coarse_src_inp); - -#ifdef AMR_DEBUG - intermediate_bdata[i].euler_elc = gkyl_wv_ten_moment_new(k0_elc); - intermediate_bdata[i].euler_ion = gkyl_wv_ten_moment_new(k0_ion); - intermediate_bdata[i].maxwell = gkyl_wv_maxwell_new(light_speed, e_fact, b_fact); - - fine_bdata[i].euler_elc = gkyl_wv_ten_moment_new(k0_elc); - fine_bdata[i].euler_ion = gkyl_wv_ten_moment_new(k0_ion); - fine_bdata[i].maxwell = gkyl_wv_maxwell_new(light_speed, e_fact, b_fact); - - for (int d = 0; d < ndim; d++) { - fine_bdata[i].slvr_elc[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &fine_bdata[i].grid, - .equation = fine_bdata[i].euler_elc, - .limiter = GKYL_MONOTONIZED_CENTERED, - .num_up_dirs = 1, - .update_dirs = { d }, - .cfl = cfl_frac, - .geom = fine_bdata[i].geom, - } - ); - fine_bdata[i].slvr_ion[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &fine_bdata[i].grid, - .equation = fine_bdata[i].euler_ion, - .limiter = GKYL_MONOTONIZED_CENTERED, - .num_up_dirs = 1, - .update_dirs = { d }, - .cfl = cfl_frac, - .geom = fine_bdata[i].geom, - } - ); - fine_bdata[i].slvr_maxwell[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &fine_bdata[i].grid, - .equation = fine_bdata[i].maxwell, - .limiter = GKYL_MONOTONIZED_CENTERED, - .num_up_dirs = 1, - .update_dirs = { d }, - .cfl = cfl_frac, - .geom = fine_bdata[i].geom, - } - ); - } - - struct gkyl_moment_em_coupling_inp fine_src_inp = { - .grid = &fine_bdata[i].grid, - .nfluids = 2, - .epsilon0 = epsilon0, - }; - - fine_src_inp.param[0] = (struct gkyl_moment_em_coupling_data) { - .type = fine_bdata[i].euler_elc->type, - .charge = charge_elc, - .mass = mass_elc, - .k0 = k0_elc, - }; - fine_src_inp.param[1] = (struct gkyl_moment_em_coupling_data) { - .type = fine_bdata[i].euler_ion->type, + .type = mesh_bdata[i].euler_ion->type, .charge = charge_ion, .mass = mass_ion, .k0 = k0_ion, }; - fine_bdata[i].src_slvr = gkyl_moment_em_coupling_new(fine_src_inp); - - for (int d = 0; d < ndim; d++) { - intermediate_bdata[i].slvr_elc[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &intermediate_bdata[i].grid, - .equation = intermediate_bdata[i].euler_elc, - .limiter = GKYL_MONOTONIZED_CENTERED, - .num_up_dirs = 1, - .update_dirs = { d }, - .cfl = cfl_frac, - .geom = intermediate_bdata[i].geom, - } - ); - intermediate_bdata[i].slvr_ion[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &intermediate_bdata[i].grid, - .equation = intermediate_bdata[i].euler_ion, - .limiter = GKYL_MONOTONIZED_CENTERED, - .num_up_dirs = 1, - .update_dirs = { d }, - .cfl = cfl_frac, - .geom = intermediate_bdata[i].geom, - } - ); - intermediate_bdata[i].slvr_maxwell[d] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { - .grid = &intermediate_bdata[i].grid, - .equation = intermediate_bdata[i].maxwell, - .limiter = GKYL_MONOTONIZED_CENTERED, - .num_up_dirs = 1, - .update_dirs = { d }, - .cfl = cfl_frac, - .geom = intermediate_bdata[i].geom, - } - ); - } - - struct gkyl_moment_em_coupling_inp intermediate_src_inp = { - .grid = &intermediate_bdata[i].grid, - .nfluids = 2, - .epsilon0 = epsilon0, - }; - - intermediate_src_inp.param[0] = (struct gkyl_moment_em_coupling_data) { - .type = intermediate_bdata[i].euler_elc->type, - .charge = charge_elc, - .mass = mass_elc, - .k0 = k0_elc, - }; - intermediate_src_inp.param[1] = (struct gkyl_moment_em_coupling_data) { - .type = intermediate_bdata[i].euler_ion->type, - .charge = charge_ion, - .mass = mass_ion, - .k0 = k0_ion, - }; - - intermediate_bdata[i].src_slvr = gkyl_moment_em_coupling_new(intermediate_src_inp); -#endif + mesh_bdata[i].src_slvr = gkyl_moment_em_coupling_new(coarse_src_inp); } struct gkyl_block_topo *btopo = create_nested_block_topo(); for (int i = 0; i < num_blocks; i++) { - ten_moment_nested_block_bc_updaters_init(&coarse_bdata[i], &btopo->conn[i]); - -#ifdef AMR_DEBUG - ten_moment_nested_block_bc_updaters_init(&intermediate_bdata[i], &btopo->conn[i]); - ten_moment_nested_block_bc_updaters_init(&fine_bdata[i], &btopo->conn[i]); -#endif + ten_moment_nested_block_bc_updaters_init(&mesh_bdata[i], &btopo->conn[i]); } for (int i = 0; i < num_blocks; i++) { - coarse_bdata[i].fdup_elc = gkyl_array_new(GKYL_DOUBLE, 10, coarse_bdata[i].ext_range.volume); - coarse_bdata[i].fdup_ion = gkyl_array_new(GKYL_DOUBLE, 10, coarse_bdata[i].ext_range.volume); - coarse_bdata[i].fdup_maxwell = gkyl_array_new(GKYL_DOUBLE, 8, coarse_bdata[i].ext_range.volume); - - for (int d = 0; d < ndim + 1; d++) { - coarse_bdata[i].f_elc[d] = gkyl_array_new(GKYL_DOUBLE, 10, coarse_bdata[i].ext_range.volume); - coarse_bdata[i].f_ion[d] = gkyl_array_new(GKYL_DOUBLE, 10, coarse_bdata[i].ext_range.volume); - coarse_bdata[i].f_maxwell[d] = gkyl_array_new(GKYL_DOUBLE, 8, coarse_bdata[i].ext_range.volume); - } - - coarse_bdata[i].app_accel_elc = gkyl_array_new(GKYL_DOUBLE, 3, coarse_bdata[i].ext_range.volume); - coarse_bdata[i].app_accel_ion = gkyl_array_new(GKYL_DOUBLE, 3, coarse_bdata[i].ext_range.volume); - coarse_bdata[i].rhs_source_elc = gkyl_array_new(GKYL_DOUBLE, 10, coarse_bdata[i].ext_range.volume); - coarse_bdata[i].rhs_source_ion = gkyl_array_new(GKYL_DOUBLE, 10, coarse_bdata[i].ext_range.volume); - coarse_bdata[i].ext_em = gkyl_array_new(GKYL_DOUBLE, 6, coarse_bdata[i].ext_range.volume); - coarse_bdata[i].app_current = gkyl_array_new(GKYL_DOUBLE, 3, coarse_bdata[i].ext_range.volume); - coarse_bdata[i].nT_source_elc = gkyl_array_new(GKYL_DOUBLE, 2, coarse_bdata[i].ext_range.volume); - coarse_bdata[i].nT_source_ion = gkyl_array_new(GKYL_DOUBLE, 2, coarse_bdata[i].ext_range.volume); - -#ifdef AMR_DEBUG - intermediate_bdata[i].fdup_elc = gkyl_array_new(GKYL_DOUBLE, 10, intermediate_bdata[i].ext_range.volume); - intermediate_bdata[i].fdup_ion = gkyl_array_new(GKYL_DOUBLE, 10, intermediate_bdata[i].ext_range.volume); - intermediate_bdata[i].fdup_maxwell = gkyl_array_new(GKYL_DOUBLE, 8, intermediate_bdata[i].ext_range.volume); - - for (int d = 0; d < ndim + 1; d++) { - intermediate_bdata[i].f_elc[d] = gkyl_array_new(GKYL_DOUBLE, 10, intermediate_bdata[i].ext_range.volume); - intermediate_bdata[i].f_ion[d] = gkyl_array_new(GKYL_DOUBLE, 10, intermediate_bdata[i].ext_range.volume); - intermediate_bdata[i].f_maxwell[d] = gkyl_array_new(GKYL_DOUBLE, 8, intermediate_bdata[i].ext_range.volume); - } - - intermediate_bdata[i].app_accel_elc = gkyl_array_new(GKYL_DOUBLE, 3, intermediate_bdata[i].ext_range.volume); - intermediate_bdata[i].app_accel_ion = gkyl_array_new(GKYL_DOUBLE, 3, intermediate_bdata[i].ext_range.volume); - intermediate_bdata[i].rhs_source_elc = gkyl_array_new(GKYL_DOUBLE, 10, intermediate_bdata[i].ext_range.volume); - intermediate_bdata[i].rhs_source_ion = gkyl_array_new(GKYL_DOUBLE, 10, intermediate_bdata[i].ext_range.volume); - intermediate_bdata[i].ext_em = gkyl_array_new(GKYL_DOUBLE, 6, intermediate_bdata[i].ext_range.volume); - intermediate_bdata[i].app_current = gkyl_array_new(GKYL_DOUBLE, 3, intermediate_bdata[i].ext_range.volume); - intermediate_bdata[i].nT_source_elc = gkyl_array_new(GKYL_DOUBLE, 2, intermediate_bdata[i].ext_range.volume); - intermediate_bdata[i].nT_source_ion = gkyl_array_new(GKYL_DOUBLE, 2, intermediate_bdata[i].ext_range.volume); - - fine_bdata[i].fdup_elc = gkyl_array_new(GKYL_DOUBLE, 10, fine_bdata[i].ext_range.volume); - fine_bdata[i].fdup_ion = gkyl_array_new(GKYL_DOUBLE, 10, fine_bdata[i].ext_range.volume); - fine_bdata[i].fdup_maxwell = gkyl_array_new(GKYL_DOUBLE, 8, fine_bdata[i].ext_range.volume); + mesh_bdata[i].fdup_elc = gkyl_array_new(GKYL_DOUBLE, 10, mesh_bdata[i].ext_range.volume); + mesh_bdata[i].fdup_ion = gkyl_array_new(GKYL_DOUBLE, 10, mesh_bdata[i].ext_range.volume); + mesh_bdata[i].fdup_maxwell = gkyl_array_new(GKYL_DOUBLE, 8, mesh_bdata[i].ext_range.volume); for (int d = 0; d < ndim + 1; d++) { - fine_bdata[i].f_elc[d] = gkyl_array_new(GKYL_DOUBLE, 10, fine_bdata[i].ext_range.volume); - fine_bdata[i].f_ion[d] = gkyl_array_new(GKYL_DOUBLE, 10, fine_bdata[i].ext_range.volume); - fine_bdata[i].f_maxwell[d] = gkyl_array_new(GKYL_DOUBLE, 8, fine_bdata[i].ext_range.volume); + mesh_bdata[i].f_elc[d] = gkyl_array_new(GKYL_DOUBLE, 10, mesh_bdata[i].ext_range.volume); + mesh_bdata[i].f_ion[d] = gkyl_array_new(GKYL_DOUBLE, 10, mesh_bdata[i].ext_range.volume); + mesh_bdata[i].f_maxwell[d] = gkyl_array_new(GKYL_DOUBLE, 8, mesh_bdata[i].ext_range.volume); } - fine_bdata[i].app_accel_elc = gkyl_array_new(GKYL_DOUBLE, 3, fine_bdata[i].ext_range.volume); - fine_bdata[i].app_accel_ion = gkyl_array_new(GKYL_DOUBLE, 3, fine_bdata[i].ext_range.volume); - fine_bdata[i].rhs_source_elc = gkyl_array_new(GKYL_DOUBLE, 10, fine_bdata[i].ext_range.volume); - fine_bdata[i].rhs_source_ion = gkyl_array_new(GKYL_DOUBLE, 10, fine_bdata[i].ext_range.volume); - fine_bdata[i].ext_em = gkyl_array_new(GKYL_DOUBLE, 6, fine_bdata[i].ext_range.volume); - fine_bdata[i].app_current = gkyl_array_new(GKYL_DOUBLE, 3, fine_bdata[i].ext_range.volume); - fine_bdata[i].nT_source_elc = gkyl_array_new(GKYL_DOUBLE, 2, fine_bdata[i].ext_range.volume); - fine_bdata[i].nT_source_ion = gkyl_array_new(GKYL_DOUBLE, 2, fine_bdata[i].ext_range.volume); -#endif + mesh_bdata[i].app_accel_elc = gkyl_array_new(GKYL_DOUBLE, 3, mesh_bdata[i].ext_range.volume); + mesh_bdata[i].app_accel_ion = gkyl_array_new(GKYL_DOUBLE, 3, mesh_bdata[i].ext_range.volume); + mesh_bdata[i].rhs_source_elc = gkyl_array_new(GKYL_DOUBLE, 10, mesh_bdata[i].ext_range.volume); + mesh_bdata[i].rhs_source_ion = gkyl_array_new(GKYL_DOUBLE, 10, mesh_bdata[i].ext_range.volume); + mesh_bdata[i].ext_em = gkyl_array_new(GKYL_DOUBLE, 6, mesh_bdata[i].ext_range.volume); + mesh_bdata[i].app_current = gkyl_array_new(GKYL_DOUBLE, 3, mesh_bdata[i].ext_range.volume); + mesh_bdata[i].nT_source_elc = gkyl_array_new(GKYL_DOUBLE, 2, mesh_bdata[i].ext_range.volume); + mesh_bdata[i].nT_source_ion = gkyl_array_new(GKYL_DOUBLE, 2, mesh_bdata[i].ext_range.volume); } #ifdef AMR_USETHREADS for (int i = 0; i < num_blocks; i++) { - gkyl_job_pool_add_work(coarse_job_pool, five_moment_init_job_func_block, &coarse_bdata[i]); - -#ifdef AMR_DEBUG - gkyl_job_pool_add_work(intermediate_job_pool, five_moment_init_job_func_block, &intermediate_bdata[i]); - gkyl_job_pool_add_work(fine_job_pool, five_moment_init_job_func_block, &fine_bdata[i]); -#endif + gkyl_job_pool_add_work(coarse_job_pool, five_moment_init_job_func_block, &mesh_bdata[i]); } gkyl_job_pool_wait(coarse_job_pool); - -#ifdef AMR_DEBUG - gkyl_job_pool_wait(intermediate_job_pool); - gkyl_job_pool_wait(fine_job_pool); -#endif #else for (int i = 0; i < num_blocks; i++) { - five_moment_init_job_func_block(&coarse_bdata[i]); - -#ifdef AMR_DEBUG - five_moment_init_job_func_block(&intermediate_bdata[i]); - five_moment_init_job_func_block(&fine_bdata[i]); -#endif + five_moment_init_job_func_block(&mesh_bdata[i]); } #endif -#ifdef AMR_DEBUG - char coarse0[64]; - snprintf(coarse0, 64, "%s_coarse_0", ten_moment_output); - five_moment_write_sol_block(coarse0, num_blocks, coarse_bdata); - - char intermediate0[64]; - snprintf(intermediate0, 64, "%s_intermediate_0", ten_moment_output); - five_moment_write_sol_block(intermediate0, num_blocks, intermediate_bdata); - - char fine0[64]; - snprintf(fine0, 64, "%s_fine_0", ten_moment_output); - five_moment_write_sol_block(fine0, num_blocks, fine_bdata); - - char fine0_elc_b0[64], fine0_ion_b0[64], fine0_field_b0[64]; - char intermediate0_elc_b0[64], intermediate0_ion_b0[64], intermediate0_field_b0[64]; - char coarse0_elc_b0[64], coarse0_ion_b0[64], coarse0_field_b0[64]; - char b0_elc[64], b0_ion[64], b0_field[64]; - - snprintf(fine0_elc_b0, 64, "%s_fine_0_elc_b0.gkyl", ten_moment_output); - snprintf(fine0_ion_b0, 64, "%s_fine_0_ion_b0.gkyl", ten_moment_output); - snprintf(fine0_field_b0, 64, "%s_fine_0_field_b0.gkyl", ten_moment_output); - - snprintf(intermediate0_elc_b0, 64, "%s_intermediate_0_elc_b0.gkyl", ten_moment_output); - snprintf(intermediate0_ion_b0, 64, "%s_intermediate_0_ion_b0.gkyl", ten_moment_output); - snprintf(intermediate0_field_b0, 64, "%s_intermediate_0_field_b0.gkyl", ten_moment_output); - - snprintf(coarse0_elc_b0, 64, "%s_coarse_0_elc_b0.gkyl", ten_moment_output); - snprintf(coarse0_ion_b0, 64, "%s_coarse_0_ion_b0.gkyl", ten_moment_output); - snprintf(coarse0_field_b0, 64, "%s_coarse_0_field_b0.gkyl", ten_moment_output); - - snprintf(b0_elc, 64, "%s_0_elc_b0.gkyl", ten_moment_output); - snprintf(b0_ion, 64, "%s_0_ion_b0.gkyl", ten_moment_output); - snprintf(b0_field, 64, "%s_0_field_b0.gkyl", ten_moment_output); - - rename(fine0_elc_b0, b0_elc); - rename(fine0_ion_b0, b0_ion); - rename(fine0_field_b0, b0_field); - - remove(intermediate0_elc_b0); - remove(intermediate0_ion_b0); - remove(intermediate0_field_b0); - - remove(coarse0_elc_b0); - remove(coarse0_ion_b0); - remove(coarse0_field_b0); - - for (int i = 1; i < 9; i++) { - char fine0_elc_bi[64], fine0_ion_bi[64], fine0_field_bi[64]; - char intermediate0_elc_bi[64], intermediate0_ion_bi[64], intermediate0_field_bi[64]; - char coarse0_elc_bi[64], coarse0_ion_bi[64], coarse0_field_bi[64]; - char elc_bi[64], ion_bi[64], field_bi[64]; - - snprintf(fine0_elc_bi, 64, "%s_fine_0_elc_b%d.gkyl", ten_moment_output, i); - snprintf(fine0_ion_bi, 64, "%s_fine_0_ion_b%d.gkyl", ten_moment_output, i); - snprintf(fine0_field_bi, 64, "%s_fine_0_field_b%d.gkyl", ten_moment_output, i); - - snprintf(intermediate0_elc_bi, 64, "%s_intermediate_0_elc_b%d.gkyl", ten_moment_output, i); - snprintf(intermediate0_ion_bi, 64, "%s_intermediate_0_ion_b%d.gkyl", ten_moment_output, i); - snprintf(intermediate0_field_bi, 64, "%s_intermediate_0_field_b%d.gkyl", ten_moment_output, i); - - snprintf(coarse0_elc_bi, 64, "%s_coarse_0_elc_b%d.gkyl", ten_moment_output, i); - snprintf(coarse0_ion_bi, 64, "%s_coarse_0_ion_b%d.gkyl", ten_moment_output, i); - snprintf(coarse0_field_bi, 64, "%s_coarse_0_field_b%d.gkyl", ten_moment_output, i); - - snprintf(elc_bi, 64, "%s_0_elc_b%d.gkyl", ten_moment_output, i); - snprintf(ion_bi, 64, "%s_0_ion_b%d.gkyl", ten_moment_output, i); - snprintf(field_bi, 64, "%s_0_field_b%d.gkyl", ten_moment_output, i); - - rename(intermediate0_elc_bi, elc_bi); - rename(intermediate0_ion_bi, ion_bi); - rename(intermediate0_field_bi, field_bi); - - remove(fine0_elc_bi); - remove(fine0_ion_bi); - remove(fine0_field_bi); - - remove(coarse0_elc_bi); - remove(coarse0_ion_bi); - remove(coarse0_field_bi); - } - - for (int i = 9; i < 25; i++) { - char buf_old_elc[64], buf_old_ion[64], buf_old_field[64]; - char buf_new_elc[64], buf_new_ion[64], buf_new_field[64]; - char buf_del1_elc[64], buf_del1_ion[64], buf_del1_field[64]; - char buf_del2_elc[64], buf_del2_ion[64], buf_del2_field[64]; - - snprintf(buf_old_elc, 64, "%s_coarse_0_elc_b%d.gkyl", ten_moment_output, i); - snprintf(buf_old_ion, 64, "%s_coarse_0_ion_b%d.gkyl", ten_moment_output, i); - snprintf(buf_old_field, 64, "%s_coarse_0_field_b%d.gkyl", ten_moment_output, i); - - snprintf(buf_new_elc, 64, "%s_0_elc_b%d.gkyl", ten_moment_output, i); - snprintf(buf_new_ion, 64, "%s_0_ion_b%d.gkyl", ten_moment_output, i); - snprintf(buf_new_field, 64, "%s_0_field_b%d.gkyl", ten_moment_output, i); - - snprintf(buf_del1_elc, 64, "%s_intermediate_0_elc_b%d.gkyl", ten_moment_output, i); - snprintf(buf_del1_ion, 64, "%s_intermediate_0_ion_b%d.gkyl", ten_moment_output, i); - snprintf(buf_del1_field, 64, "%s_intermediate_0_field_b%d.gkyl", ten_moment_output, i); - - snprintf(buf_del2_elc, 64, "%s_fine_0_elc_b%d.gkyl", ten_moment_output, i); - snprintf(buf_del2_ion, 64, "%s_fine_0_ion_b%d.gkyl", ten_moment_output, i); - snprintf(buf_del2_field, 64, "%s_fine_0_field_b%d.gkyl", ten_moment_output, i); - - rename(buf_old_elc, buf_new_elc); - rename(buf_old_ion, buf_new_ion); - rename(buf_old_field, buf_new_field); - - remove(buf_del1_elc); - remove(buf_del1_ion); - remove(buf_del1_field); - - remove(buf_del2_elc); - remove(buf_del2_ion); - remove(buf_del2_field); - } -#else char amr0[64]; snprintf(amr0, 64, "%s_0", ten_moment_output); - five_moment_write_sol_block(amr0, num_blocks, coarse_bdata); -#endif + five_moment_write_sol_block(amr0, num_blocks, mesh_bdata); double coarse_t_curr = 0.0; double intermediate_t_curr = 0.0; double fine_t_curr = 0.0; - double coarse_dt = five_moment_max_dt_block(num_blocks, coarse_bdata); + double coarse_dt = five_moment_max_dt_block(num_blocks, mesh_bdata); -#ifdef AMR_DEBUG - double intermediate_dt = five_moment_max_dt_block(num_blocks, intermediate_bdata); - double fine_dt = five_moment_max_dt_block(num_blocks, fine_bdata); -#else double intermediate_dt = (1.0 / ref_factor1) * coarse_dt; double fine_dt = (1.0 / (ref_factor1 * ref_factor2)) * coarse_dt; -#endif struct sim_stats stats = { }; @@ -2101,7 +883,7 @@ ten_moment_2d_run_double(int argc, char **argv, struct ten_moment_2d_double_init while ((coarse_t_curr < t_end) && (coarse_step <= num_steps)) { printf("Taking coarse (level 0) time-step %ld at t = %g; ", coarse_step, coarse_t_curr); - struct gkyl_update_status coarse_status = five_moment_update_block(coarse_job_pool, btopo, coarse_bdata, coarse_t_curr, coarse_dt, &stats); + struct gkyl_update_status coarse_status = five_moment_update_block(coarse_job_pool, btopo, mesh_bdata, coarse_t_curr, coarse_dt, &stats); printf(" dt = %g\n", coarse_status.dt_actual); if (!coarse_status.success) { @@ -2110,33 +892,6 @@ ten_moment_2d_run_double(int argc, char **argv, struct ten_moment_2d_double_init } for (long intermediate_step = 1; intermediate_step < ref_factor1 + 1; intermediate_step++) { -#ifdef AMR_DEBUG - printf(" Taking intermediate (level 1) time-step %ld at t = %g; ", intermediate_step, intermediate_t_curr); - struct gkyl_update_status intermediate_status = five_moment_update_block(intermediate_job_pool, btopo, intermediate_bdata, intermediate_t_curr, intermediate_dt, &stats); - printf(" dt = %g\n", intermediate_status.dt_actual); - - if (!intermediate_status.success) { - printf("** Update method failed! Aborting simulation ....\n"); - break; - } - - for (long fine_step = 1; fine_step < ref_factor2 + 1; fine_step++) { - printf(" Taking fine (level 2) time-step %ld at t = %g", fine_step, fine_t_curr); - struct gkyl_update_status fine_status = five_moment_update_block(fine_job_pool, btopo, fine_bdata, fine_t_curr, fine_dt, &stats); - printf(" dt = %g\n", fine_status.dt_actual); - - if (!fine_status.success) { - printf("** Update method failed! Aborting simulation ....\n"); - break; - } - - fine_t_curr += fine_status.dt_actual; - fine_dt = fine_status.dt_suggested; - } - - intermediate_t_curr += intermediate_status.dt_actual; - intermediate_dt += intermediate_status.dt_suggested; -#else printf(" Taking intermediate (level 1) time-step %ld at t = %g", intermediate_step, intermediate_t_curr); printf(" dt = %g\n", (1.0 / ref_factor1) * coarse_status.dt_actual); @@ -2150,132 +905,14 @@ ten_moment_2d_run_double(int argc, char **argv, struct ten_moment_2d_double_init intermediate_t_curr += (1.0 / ref_factor1) * coarse_status.dt_actual; intermediate_dt = (1.0 / ref_factor1) * coarse_status.dt_suggested; -#endif } for (int i = 1; i < num_frames; i++) { if (coarse_t_curr < (i * io_trigger) && (coarse_t_curr + coarse_status.dt_actual) > (i * io_trigger)) { -#ifdef AMR_DEBUG - char buf_coarse[64]; - char buf_intermediate[64]; - char buf_fine[64]; - - snprintf(buf_coarse, 64, "%s_coarse_%d", ten_moment_output, i); - snprintf(buf_intermediate, 64, "%s_intermediate_%d", ten_moment_output, i); - snprintf(buf_fine, 64, "%s_fine_%d", ten_moment_output, i); - - five_moment_write_sol_block(buf_coarse, num_blocks, coarse_bdata); - five_moment_write_sol_block(buf_intermediate, num_blocks, intermediate_bdata); - five_moment_write_sol_block(buf_fine, num_blocks, fine_bdata); - - char buf_fine_old_elc[64], buf_fine_old_ion[64], buf_fine_old_field[64]; - char buf_intermediate_old_elc[64], buf_intermediate_old_ion[64], buf_intermediate_old_field[64]; - char buf_fine_new_elc[64], buf_fine_new_ion[64], buf_fine_new_field[64]; - char buf_coarse_old_elc[64], buf_coarse_old_ion[64], buf_coarse_old_field[64]; - - snprintf(buf_fine_old_elc, 64, "%s_fine_%d_elc_b0.gkyl", ten_moment_output, i); - snprintf(buf_fine_old_ion, 64, "%s_fine_%d_ion_b0.gkyl", ten_moment_output, i); - snprintf(buf_fine_old_field, 64, "%s_fine_%d_field_b0.gkyl", ten_moment_output, i); - - snprintf(buf_intermediate_old_elc, 64, "%s_intermediate_%d_elc_b0.gkyl", ten_moment_output, i); - snprintf(buf_intermediate_old_ion, 64, "%s_intermediate_%d_ion_b0.gkyl", ten_moment_output, i); - snprintf(buf_intermediate_old_field, 64, "%s_intermediate_%d_field_b0.gkyl", ten_moment_output, i); - - snprintf(buf_fine_new_elc, 64, "%s_%d_elc_b0.gkyl", ten_moment_output, i); - snprintf(buf_fine_new_ion, 64, "%s_%d_ion_b0.gkyl", ten_moment_output, i); - snprintf(buf_fine_new_field, 64, "%s_%d_field_b0.gkyl", ten_moment_output, i); - - snprintf(buf_coarse_old_elc, 64, "%s_coarse_%d_elc_b0.gkyl", ten_moment_output, i); - snprintf(buf_coarse_old_ion, 64, "%s_coarse_%d_ion_b0.gkyl", ten_moment_output, i); - snprintf(buf_coarse_old_field, 64, "%s_coarse_%d_field_b0.gkyl", ten_moment_output, i); - - rename(buf_fine_old_elc, buf_fine_new_elc); - rename(buf_fine_old_ion, buf_fine_new_ion); - rename(buf_fine_old_field, buf_fine_new_field); - - remove(buf_intermediate_old_elc); - remove(buf_intermediate_old_ion); - remove(buf_intermediate_old_field); - - remove(buf_coarse_old_elc); - remove(buf_coarse_old_ion); - remove(buf_coarse_old_field); - - for (int j = 1; j < 8; j++) { - char fine0_elc_bi[64], fine0_ion_bi[64], fine0_field_bi[64]; - char intermediate0_elc_bi[64], intermediate0_ion_bi[64], intermediate0_field_bi[64]; - char coarse0_elc_bi[64], coarse0_ion_bi[64], coarse0_field_bi[64]; - char elc_bi[64], ion_bi[64], field_bi[64]; - - snprintf(fine0_elc_bi, 64, "%s_fine_%d_elc_b%d.gkyl", ten_moment_output, i, j); - snprintf(fine0_ion_bi, 64, "%s_fine_%d_ion_b%d.gkyl", ten_moment_output, i, j); - snprintf(fine0_field_bi, 64, "%s_fine_%d_field_b%d.gkyl", ten_moment_output, i, j); - - snprintf(intermediate0_elc_bi, 64, "%s_intermediate_%d_elc_b%d.gkyl", ten_moment_output, i, j); - snprintf(intermediate0_ion_bi, 64, "%s_intermediate_%d_ion_b%d.gkyl", ten_moment_output, i, j); - snprintf(intermediate0_field_bi, 64, "%s_intermediate_%d_field_b%d.gkyl", ten_moment_output, i, j); - - snprintf(coarse0_elc_bi, 64, "%s_coarse_%d_elc_b%d.gkyl", ten_moment_output, i, j); - snprintf(coarse0_ion_bi, 64, "%s_coarse_%d_ion_b%d.gkyl", ten_moment_output, i, j); - snprintf(coarse0_field_bi, 64, "%s_coarse_%d_field_b%d.gkyl", ten_moment_output, i, j); - - snprintf(elc_bi, 64, "%s_%d_elc_b%d.gkyl", ten_moment_output, i, j); - snprintf(ion_bi, 64, "%s_%d_ion_b%d.gkyl", ten_moment_output, i, j); - snprintf(field_bi, 64, "%s_%d_field_b%d.gkyl", ten_moment_output, i, j); - - rename(intermediate0_elc_bi, elc_bi); - rename(intermediate0_ion_bi, ion_bi); - rename(intermediate0_field_bi, field_bi); - - remove(fine0_elc_bi); - remove(fine0_ion_bi); - remove(fine0_field_bi); - - remove(coarse0_elc_bi); - remove(coarse0_ion_bi); - remove(coarse0_field_bi); - } - - for (int j = 9; j < 25; j++) { - char buf_old_elc[64], buf_old_ion[64], buf_old_field[64]; - char buf_new_elc[64], buf_new_ion[64], buf_new_field[64]; - char buf_del1_elc[64], buf_del1_ion[64], buf_del1_field[64]; - char buf_del2_elc[64], buf_del2_ion[64], buf_del2_field[64]; - - snprintf(buf_old_elc, 64, "%s_coarse_%d_elc_b%d.gkyl", ten_moment_output, i, j); - snprintf(buf_old_ion, 64, "%s_coarse_%d_ion_b%d.gkyl", ten_moment_output, i, j); - snprintf(buf_old_field, 64, "%s_coarse_%d_field_b%d.gkyl", ten_moment_output, i, j); - - snprintf(buf_new_elc, 64, "%s_%d_elc_b%d.gkyl", ten_moment_output, i, j); - snprintf(buf_new_ion, 64, "%s_%d_ion_b%d.gkyl", ten_moment_output, i, j); - snprintf(buf_new_field, 64, "%s_%d_field_b%d.gkyl", ten_moment_output, i, j); - - snprintf(buf_del1_elc, 64, "%s_intermediate_%d_elc_b%d.gkyl", ten_moment_output, i, j); - snprintf(buf_del1_ion, 64, "%s_intermediate_%d_ion_b%d.gkyl", ten_moment_output, i, j); - snprintf(buf_del1_field, 64, "%s_intermediate_%d_field_b%d.gkyl", ten_moment_output, i, j); - - snprintf(buf_del2_elc, 64, "%s_fine_%d_elc_b%d.gkyl", ten_moment_output, i, j); - snprintf(buf_del2_ion, 64, "%s_fine_%d_ion_b%d.gkyl", ten_moment_output, i, j); - snprintf(buf_del2_field, 64, "%s_fine_%d_field_b%d.gkyl", ten_moment_output, i, j); - - rename(buf_old_elc, buf_new_elc); - rename(buf_old_ion, buf_new_ion); - rename(buf_old_field, buf_new_field); - - remove(buf_del1_elc); - remove(buf_del1_ion); - remove(buf_del1_field); - - remove(buf_del2_elc); - remove(buf_del2_ion); - remove(buf_del2_field); - } -#else char buf[64]; snprintf(buf, 64, "%s_%d", ten_moment_output, i); - five_moment_write_sol_block(buf, num_blocks, coarse_bdata); -#endif + five_moment_write_sol_block(buf, num_blocks, mesh_bdata); } } @@ -2306,247 +943,51 @@ ten_moment_2d_run_double(int argc, char **argv, struct ten_moment_2d_double_init double tm_total_sec = gkyl_time_diff_now_sec(tm_start); - // TODO: Make file output work correctly in the AMR_DEBUG case. -#ifdef AMR_DEBUG - char buf_coarse[64]; - char buf_intermediate[64]; - char buf_fine[64]; - - snprintf(buf_coarse, 64, "%s_coarse_%d", ten_moment_output, num_frames); - snprintf(buf_intermediate, 64, "%s_intermediate_%d", ten_moment_output, num_frames); - snprintf(buf_fine, 64, "%s_fine_%d", ten_moment_output, num_frames); - - five_moment_write_sol_block(buf_coarse, num_blocks, coarse_bdata); - five_moment_write_sol_block(buf_intermediate, num_blocks, intermediate_bdata); - five_moment_write_sol_block(buf_fine, num_blocks, fine_bdata); - - char buf_fine_old_elc[64], buf_fine_old_ion[64], buf_fine_old_field[64]; - char buf_fine_new_elc[64], buf_fine_new_ion[64], buf_fine_new_field[64]; - char buf_intermediate_old_elc[64], buf_intermediate_old_ion[64], buf_intermediate_old_field[64]; - char buf_coarse_old_elc[64], buf_coarse_old_ion[64], buf_coarse_old_field[64]; - - snprintf(buf_fine_old_elc, 64, "%s_fine_%d_elc_b0.gkyl", ten_moment_output, num_frames); - snprintf(buf_fine_old_ion, 64, "%s_fine_%d_ion_b0.gkyl", ten_moment_output, num_frames); - snprintf(buf_fine_old_field, 64, "%s_fine_%d_field_b0.gkyl", ten_moment_output, num_frames); - - snprintf(buf_fine_new_elc, 64, "%s_%d_elc_b0.gkyl", ten_moment_output, num_frames); - snprintf(buf_fine_new_ion, 64, "%s_%d_ion_b0.gkyl", ten_moment_output, num_frames); - snprintf(buf_fine_new_field, 64, "%s_%d_field_b0.gkyl", ten_moment_output, num_frames); - - snprintf(buf_intermediate_old_elc, 64, "%s_intermediate_%d_elc_b0.gkyl", ten_moment_output, num_frames); - snprintf(buf_intermediate_old_ion, 64, "%s_intermediate_%d_ion_b0.gkyl", ten_moment_output, num_frames); - snprintf(buf_intermediate_old_field, 64, "%s_intermediate_%d_field_b0.gkyl", ten_moment_output, num_frames); - - snprintf(buf_coarse_old_elc, 64, "%s_coarse_%d_elc_b0.gkyl", ten_moment_output, num_frames); - snprintf(buf_coarse_old_ion, 64, "%s_coarse_%d_ion_b0.gkyl", ten_moment_output, num_frames); - snprintf(buf_coarse_old_field, 64, "%s_coarse_%d_field_b0.gkyl", ten_moment_output, num_frames); - - rename(buf_fine_old_elc, buf_fine_new_elc); - rename(buf_fine_old_ion, buf_fine_new_ion); - rename(buf_fine_old_field, buf_fine_new_field); - - remove(buf_intermediate_old_elc); - remove(buf_intermediate_old_ion); - remove(buf_intermediate_old_field); - - remove(buf_coarse_old_elc); - remove(buf_coarse_old_ion); - remove(buf_coarse_old_field); - - for (int i = 1; i < 9; i++) { - char fine0_elc_bi[64], fine0_ion_bi[64], fine0_field_bi[64]; - char intermediate0_elc_bi[64], intermediate0_ion_bi[64], intermediate0_field_bi[64]; - char coarse0_elc_bi[64], coarse0_ion_bi[64], coarse0_field_bi[64]; - char elc_bi[64], ion_bi[64], field_bi[64]; - - snprintf(fine0_elc_bi, 64, "%s_fine_%d_elc_b%d.gkyl", ten_moment_output, num_frames, i); - snprintf(fine0_ion_bi, 64, "%s_fine_%d_ion_b%d.gkyl", ten_moment_output, num_frames, i); - snprintf(fine0_field_bi, 64, "%s_fine_%d_field_b%d.gkyl", ten_moment_output, num_frames, i); - - snprintf(intermediate0_elc_bi, 64, "%s_intermediate_%d_elc_b%d.gkyl", ten_moment_output, num_frames, i); - snprintf(intermediate0_ion_bi, 64, "%s_intermediate_%d_ion_b%d.gkyl", ten_moment_output, num_frames, i); - snprintf(intermediate0_field_bi, 64, "%s_intermediate_%d_field_b%d.gkyl", ten_moment_output, num_frames, i); - - snprintf(coarse0_elc_bi, 64, "%s_coarse_%d_elc_b%d.gkyl", ten_moment_output, num_frames, i); - snprintf(coarse0_ion_bi, 64, "%s_coarse_%d_ion_b%d.gkyl", ten_moment_output, num_frames, i); - snprintf(coarse0_field_bi, 64, "%s_coarse_%d_field_b%d.gkyl", ten_moment_output, num_frames, i); - - snprintf(elc_bi, 64, "%s_%d_elc_b%d.gkyl", ten_moment_output, num_frames, i); - snprintf(ion_bi, 64, "%s_%d_ion_b%d.gkyl", ten_moment_output, num_frames, i); - snprintf(field_bi, 64, "%s_%d_field_b%d.gkyl", ten_moment_output, num_frames, i); - - rename(intermediate0_elc_bi, elc_bi); - rename(intermediate0_ion_bi, ion_bi); - rename(intermediate0_field_bi, field_bi); - - remove(fine0_elc_bi); - remove(fine0_ion_bi); - remove(fine0_field_bi); - - remove(coarse0_elc_bi); - remove(coarse0_ion_bi); - remove(coarse0_field_bi); - } - - for (int i = 9; i < 25; i++) { - char buf_old_elc[64], buf_old_ion[64], buf_old_field[64]; - char buf_new_elc[64], buf_new_ion[64], buf_new_field[64]; - char buf_del1_elc[64], buf_del1_ion[64], buf_del1_field[64]; - char buf_del2_elc[64], buf_del2_ion[64], buf_del2_field[64]; - - snprintf(buf_old_elc, 64, "%s_coarse_%d_elc_b%d.gkyl", ten_moment_output, num_frames, i); - snprintf(buf_old_ion, 64, "%s_coarse_%d_ion_b%d.gkyl", ten_moment_output, num_frames, i); - snprintf(buf_old_field, 64, "%s_coarse_%d_field_b%d.gkyl", ten_moment_output, num_frames, i); - - snprintf(buf_new_elc, 64, "%s_%d_elc_b%d.gkyl", ten_moment_output, num_frames, i); - snprintf(buf_new_ion, 64, "%s_%d_ion_b%d.gkyl", ten_moment_output, num_frames, i); - snprintf(buf_new_field, 64, "%s_%d_field_b%d.gkyl", ten_moment_output, num_frames, i); - - snprintf(buf_del1_elc, 64, "%s_intermediate_%d_elc_b%d.gkyl", ten_moment_output, num_frames, i); - snprintf(buf_del1_ion, 64, "%s_intermediate_%d_ion_b%d.gkyl", ten_moment_output, num_frames, i); - snprintf(buf_del1_field, 64, "%s_intermediate_%d_field_b%d.gkyl", ten_moment_output, num_frames, i); - - snprintf(buf_del2_elc, 64, "%s_fine_%d_elc_b%d.gkyl", ten_moment_output, num_frames, i); - snprintf(buf_del2_ion, 64, "%s_fine_%d_ion_b%d.gkyl", ten_moment_output, num_frames, i); - snprintf(buf_del2_field, 64, "%s_fine_%d_field_b%d.gkyl", ten_moment_output, num_frames, i); - - rename(buf_old_elc, buf_new_elc); - rename(buf_old_ion, buf_new_ion); - rename(buf_old_field, buf_new_field); - - remove(buf_del1_elc); - remove(buf_del1_ion); - remove(buf_del1_field); - - remove(buf_del2_elc); - remove(buf_del2_ion); - remove(buf_del2_field); - } -#else char buf[64]; snprintf(buf, 64, "%s_%d", ten_moment_output, num_frames); - five_moment_write_sol_block(buf, num_blocks, coarse_bdata); -#endif + five_moment_write_sol_block(buf, num_blocks, mesh_bdata); printf("Total run-time: %g. Failed steps: %d\n", tm_total_sec, stats.nfail); for (int i = 0; i < num_blocks; i++) { - gkyl_fv_proj_release(coarse_bdata[i].fv_proj_elc); - gkyl_fv_proj_release(coarse_bdata[i].fv_proj_ion); - gkyl_fv_proj_release(coarse_bdata[i].fv_proj_maxwell); - - gkyl_wv_eqn_release(coarse_bdata[i].euler_elc); - gkyl_wv_eqn_release(coarse_bdata[i].euler_ion); - gkyl_wv_eqn_release(coarse_bdata[i].maxwell); - - five_moment_block_bc_updaters_release(&coarse_bdata[i]); - gkyl_wave_geom_release(coarse_bdata[i].geom); - -#ifdef AMR_DEBUG - gkyl_fv_proj_release(intermediate_bdata[i].fv_proj_elc); - gkyl_fv_proj_release(intermediate_bdata[i].fv_proj_ion); - gkyl_fv_proj_release(intermediate_bdata[i].fv_proj_maxwell); + gkyl_fv_proj_release(mesh_bdata[i].fv_proj_elc); + gkyl_fv_proj_release(mesh_bdata[i].fv_proj_ion); + gkyl_fv_proj_release(mesh_bdata[i].fv_proj_maxwell); - gkyl_wv_eqn_release(intermediate_bdata[i].euler_elc); - gkyl_wv_eqn_release(intermediate_bdata[i].euler_ion); - gkyl_wv_eqn_release(intermediate_bdata[i].maxwell); + gkyl_wv_eqn_release(mesh_bdata[i].euler_elc); + gkyl_wv_eqn_release(mesh_bdata[i].euler_ion); + gkyl_wv_eqn_release(mesh_bdata[i].maxwell); - five_moment_block_bc_updaters_release(&intermediate_bdata[i]); - gkyl_wave_geom_release(intermediate_bdata[i].geom); - - gkyl_fv_proj_release(fine_bdata[i].fv_proj_elc); - gkyl_fv_proj_release(fine_bdata[i].fv_proj_ion); - gkyl_fv_proj_release(fine_bdata[i].fv_proj_maxwell); - - gkyl_wv_eqn_release(fine_bdata[i].euler_elc); - gkyl_wv_eqn_release(fine_bdata[i].euler_ion); - gkyl_wv_eqn_release(fine_bdata[i].maxwell); - - five_moment_block_bc_updaters_release(&fine_bdata[i]); - gkyl_wave_geom_release(fine_bdata[i].geom); -#endif + five_moment_block_bc_updaters_release(&mesh_bdata[i]); + gkyl_wave_geom_release(mesh_bdata[i].geom); for (int d = 0; d < ndim; d++) { - gkyl_wave_prop_release(coarse_bdata[i].slvr_elc[d]); - gkyl_wave_prop_release(coarse_bdata[i].slvr_ion[d]); - gkyl_wave_prop_release(coarse_bdata[i].slvr_maxwell[d]); - -#ifdef AMR_DEBUG - gkyl_wave_prop_release(intermediate_bdata[i].slvr_elc[d]); - gkyl_wave_prop_release(intermediate_bdata[i].slvr_ion[d]); - gkyl_wave_prop_release(intermediate_bdata[i].slvr_maxwell[d]); - - gkyl_wave_prop_release(fine_bdata[i].slvr_elc[d]); - gkyl_wave_prop_release(fine_bdata[i].slvr_ion[d]); - gkyl_wave_prop_release(fine_bdata[i].slvr_maxwell[d]); -#endif + gkyl_wave_prop_release(mesh_bdata[i].slvr_elc[d]); + gkyl_wave_prop_release(mesh_bdata[i].slvr_ion[d]); + gkyl_wave_prop_release(mesh_bdata[i].slvr_maxwell[d]); } - gkyl_array_release(coarse_bdata[i].fdup_elc); - gkyl_array_release(coarse_bdata[i].fdup_ion); - gkyl_array_release(coarse_bdata[i].fdup_maxwell); - -#ifdef AMR_DEBUG - gkyl_array_release(intermediate_bdata[i].fdup_elc); - gkyl_array_release(intermediate_bdata[i].fdup_ion); - gkyl_array_release(intermediate_bdata[i].fdup_maxwell); - - gkyl_array_release(fine_bdata[i].fdup_elc); - gkyl_array_release(fine_bdata[i].fdup_ion); - gkyl_array_release(fine_bdata[i].fdup_maxwell); -#endif + gkyl_array_release(mesh_bdata[i].fdup_elc); + gkyl_array_release(mesh_bdata[i].fdup_ion); + gkyl_array_release(mesh_bdata[i].fdup_maxwell); for(int d = 0; d < ndim; d++) { - gkyl_array_release(coarse_bdata[i].f_elc[d]); - gkyl_array_release(coarse_bdata[i].f_ion[d]); - gkyl_array_release(coarse_bdata[i].f_maxwell[d]); - -#ifdef AMR_DEBUG - gkyl_array_release(intermediate_bdata[i].f_elc[d]); - gkyl_array_release(intermediate_bdata[i].f_ion[d]); - gkyl_array_release(intermediate_bdata[i].f_maxwell[d]); - - gkyl_array_release(fine_bdata[i].f_elc[d]); - gkyl_array_release(fine_bdata[i].f_ion[d]); - gkyl_array_release(fine_bdata[i].f_maxwell[d]); -#endif + gkyl_array_release(mesh_bdata[i].f_elc[d]); + gkyl_array_release(mesh_bdata[i].f_ion[d]); + gkyl_array_release(mesh_bdata[i].f_maxwell[d]); } - gkyl_array_release(coarse_bdata[i].app_accel_elc); - gkyl_array_release(coarse_bdata[i].app_accel_ion); - gkyl_array_release(coarse_bdata[i].rhs_source_elc); - gkyl_array_release(coarse_bdata[i].rhs_source_ion); - gkyl_array_release(coarse_bdata[i].ext_em); - gkyl_array_release(coarse_bdata[i].app_current); - gkyl_array_release(coarse_bdata[i].nT_source_elc); - gkyl_array_release(coarse_bdata[i].nT_source_ion); - -#ifdef AMR_DEBUG - gkyl_array_release(intermediate_bdata[i].app_accel_elc); - gkyl_array_release(intermediate_bdata[i].app_accel_ion); - gkyl_array_release(intermediate_bdata[i].rhs_source_elc); - gkyl_array_release(intermediate_bdata[i].rhs_source_ion); - gkyl_array_release(intermediate_bdata[i].ext_em); - gkyl_array_release(intermediate_bdata[i].app_current); - gkyl_array_release(intermediate_bdata[i].nT_source_elc); - gkyl_array_release(intermediate_bdata[i].nT_source_ion); - - gkyl_array_release(fine_bdata[i].app_accel_elc); - gkyl_array_release(fine_bdata[i].app_accel_ion); - gkyl_array_release(fine_bdata[i].rhs_source_elc); - gkyl_array_release(fine_bdata[i].rhs_source_ion); - gkyl_array_release(fine_bdata[i].ext_em); - gkyl_array_release(fine_bdata[i].app_current); - gkyl_array_release(fine_bdata[i].nT_source_elc); - gkyl_array_release(fine_bdata[i].nT_source_ion); -#endif + gkyl_array_release(mesh_bdata[i].app_accel_elc); + gkyl_array_release(mesh_bdata[i].app_accel_ion); + gkyl_array_release(mesh_bdata[i].rhs_source_elc); + gkyl_array_release(mesh_bdata[i].rhs_source_ion); + gkyl_array_release(mesh_bdata[i].ext_em); + gkyl_array_release(mesh_bdata[i].app_current); + gkyl_array_release(mesh_bdata[i].nT_source_elc); + gkyl_array_release(mesh_bdata[i].nT_source_ion); } gkyl_block_topo_release(btopo); gkyl_job_pool_release(coarse_job_pool); -#ifdef AMR_DEBUG - gkyl_job_pool_release(intermediate_job_pool); - gkyl_job_pool_release(fine_job_pool); -#endif } \ No newline at end of file diff --git a/amr/amr_patch_coupled.c b/amr/amr_patch_coupled.c index 32b3b4b6b..06b3a5b80 100644 --- a/amr/amr_patch_coupled.c +++ b/amr/amr_patch_coupled.c @@ -151,55 +151,6 @@ five_moment_sync_patches(const struct gkyl_block_topo* ptopo, const struct five_ for (int i = 0; i < num_patches; i++) { const struct gkyl_target_edge *te = ptopo->conn[i].connections[0]; -#ifdef AMR_DEBUG - if (te[0].edge != GKYL_PHYSICAL) { - struct gkyl_array *bc_buffer_elc = pdata[i].bc_buffer_elc; - struct gkyl_array *bc_buffer_ion = pdata[i].bc_buffer_ion; - struct gkyl_array *bc_buffer_maxwell = pdata[i].bc_buffer_maxwell; - - gkyl_array_copy_to_buffer(bc_buffer_elc->data, fld_elc[i], &(pdata[i].skin_ghost.lower_skin[0])); - gkyl_array_copy_to_buffer(bc_buffer_ion->data, fld_ion[i], &(pdata[i].skin_ghost.lower_skin[0])); - gkyl_array_copy_to_buffer(bc_buffer_maxwell->data, fld_maxwell[i], &(pdata[i].skin_ghost.lower_skin[0])); - - int tbid = te[0].bid; - int tdir = te[0].dir; - - if (te[0].edge == GKYL_LOWER_POSITIVE) { - gkyl_array_copy_from_buffer(fld_elc[tbid], bc_buffer_elc->data, &(pdata[tbid].skin_ghost.lower_ghost[tdir])); - gkyl_array_copy_from_buffer(fld_ion[tbid], bc_buffer_ion->data, &(pdata[tbid].skin_ghost.lower_ghost[tdir])); - gkyl_array_copy_from_buffer(fld_maxwell[tbid], bc_buffer_maxwell->data, &(pdata[tbid].skin_ghost.lower_ghost[tdir])); - } - else if (te[0].edge == GKYL_UPPER_POSITIVE) { - gkyl_array_copy_from_buffer(fld_elc[tbid], bc_buffer_elc->data, &(pdata[tbid].skin_ghost.upper_ghost[tdir])); - gkyl_array_copy_from_buffer(fld_ion[tbid], bc_buffer_ion->data, &(pdata[tbid].skin_ghost.upper_ghost[tdir])); - gkyl_array_copy_from_buffer(fld_maxwell[tbid], bc_buffer_maxwell->data, &(pdata[tbid].skin_ghost.upper_ghost[tdir])); - } - } - - if (te[1].edge != GKYL_PHYSICAL) { - struct gkyl_array *bc_buffer_elc = pdata[i].bc_buffer_elc; - struct gkyl_array *bc_buffer_ion = pdata[i].bc_buffer_ion; - struct gkyl_array *bc_buffer_maxwell = pdata[i].bc_buffer_maxwell; - - gkyl_array_copy_to_buffer(bc_buffer_elc->data, fld_elc[i], &(pdata[i].skin_ghost.upper_skin[0])); - gkyl_array_copy_to_buffer(bc_buffer_ion->data, fld_ion[i], &(pdata[i].skin_ghost.upper_skin[0])); - gkyl_array_copy_to_buffer(bc_buffer_maxwell->data, fld_maxwell[i], &(pdata[i].skin_ghost.upper_skin[0])); - - int tbid = te[1].bid; - int tdir = te[1].dir; - - if (te[1].edge == GKYL_LOWER_POSITIVE) { - gkyl_array_copy_from_buffer(fld_elc[tbid], bc_buffer_elc->data, &(pdata[tbid].skin_ghost.lower_ghost[tdir])); - gkyl_array_copy_from_buffer(fld_ion[tbid], bc_buffer_ion->data, &(pdata[tbid].skin_ghost.lower_ghost[tdir])); - gkyl_array_copy_from_buffer(fld_maxwell[tbid], bc_buffer_maxwell->data, &(pdata[tbid].skin_ghost.lower_ghost[tdir])); - } - else if (te[1].edge == GKYL_UPPER_POSITIVE) { - gkyl_array_copy_from_buffer(fld_elc[tbid], bc_buffer_elc->data, &(pdata[tbid].skin_ghost.upper_ghost[tdir])); - gkyl_array_copy_from_buffer(fld_ion[tbid], bc_buffer_ion->data, &(pdata[tbid].skin_ghost.upper_ghost[tdir])); - gkyl_array_copy_from_buffer(fld_maxwell[tbid], bc_buffer_maxwell->data, &(pdata[tbid].skin_ghost.upper_ghost[tdir])); - } - } -#else if (te[0].edge != GKYL_PHYSICAL) { struct gkyl_array *bc_buffer_elc = pdata[i].bc_buffer_elc; struct gkyl_array *bc_buffer_ion = pdata[i].bc_buffer_ion; @@ -495,7 +446,6 @@ five_moment_sync_patches(const struct gkyl_block_topo* ptopo, const struct five_ } } } -#endif } } From c77beafe7274a29274d616f48a2dacb9c65b377a Mon Sep 17 00:00:00 2001 From: JonathanGorard Date: Wed, 26 Jun 2024 16:50:10 -0400 Subject: [PATCH 14/32] Patch-structured adaptive mesh refinement is now working in the doubly-nested case (at least for non-coupled, non-relativistic Euler equations). Sod-type shock tube test is performing wonderfully (no signs of numerical instability, even at coarse-fine boundaries). --- amr/amr_core_euler.c | 219 ++++++++++++++++++ amr/amr_patch.c | 88 +++++++ amr/gkyl_amr_core.h | 38 +++ amr/gkyl_amr_patch_priv.h | 23 +- ..._sodshock.c => rt_amr_euler_sodshock_l1.c} | 2 +- regression/rt_amr_euler_sodshock_l2.c | 162 +++++++++++++ 6 files changed, 530 insertions(+), 2 deletions(-) rename regression/{rt_amr_euler_sodshock.c => rt_amr_euler_sodshock_l1.c} (99%) create mode 100644 regression/rt_amr_euler_sodshock_l2.c diff --git a/amr/amr_core_euler.c b/amr/amr_core_euler.c index 2f78caa90..23526de12 100644 --- a/amr/amr_core_euler.c +++ b/amr/amr_core_euler.c @@ -206,6 +206,225 @@ euler1d_run_single(int argc, char **argv, struct euler1d_single_init* init) gkyl_job_pool_release(coarse_job_pool); } +void +euler1d_run_double(int argc, char **argv, struct euler1d_double_init* init) +{ + struct gkyl_app_args app_args = parse_app_args(argc, argv); + + if (app_args.trace_mem) { + gkyl_cu_dev_mem_debug_set(true); + gkyl_mem_debug_set(true); + } + + int base_Nx = init->base_Nx; + int ref_factor1 = init->ref_factor1; + int ref_factor2 = init->ref_factor2; + + double coarse_x1 = init->coarse_x1; + double coarse_x2 = init->coarse_x2; + + double intermediate_x1 = init->intermediate_x1; + double intermediate_x2 = init->intermediate_x2; + + double refined_x1 = init->refined_x1; + double refined_x2 = init->refined_x2; + + evalf_t eval = init->eval; + double gas_gamma = init->gas_gamma; + + char euler_output[32]; + strcpy(euler_output, init->euler_output); + + bool low_order_flux = init->low_order_flux; + int num_frames = init->num_frames; + + double cfl_frac = init->cfl_frac; + double t_end = init->t_end; + double dt_failure_tol = init->dt_failure_tol; + int num_failures_max = init->num_failures_max; + + int ndim = 1; + int num_patches = 5; + int Nx = base_Nx; + + struct euler_patch_data mesh_pdata[num_patches]; + struct gkyl_job_pool *coarse_job_pool = gkyl_thread_pool_new(app_args.num_threads); + + gkyl_rect_grid_init(&mesh_pdata[0].grid, 1, (double []) { refined_x1 }, (double []) { refined_x2 }, (int []) { Nx * (ref_factor1 * ref_factor2) } ); + + gkyl_rect_grid_init(&mesh_pdata[1].grid, 1, (double []) { intermediate_x1 }, (double []) { refined_x1 }, (int []) { Nx * ref_factor1 } ); + gkyl_rect_grid_init(&mesh_pdata[2].grid, 1, (double []) { refined_x2 }, (double []) { intermediate_x2 }, (int []) { Nx * ref_factor1 } ); + + gkyl_rect_grid_init(&mesh_pdata[3].grid, 1, (double []) { coarse_x1 }, (double []) { intermediate_x1 }, (int []) { Nx } ); + gkyl_rect_grid_init(&mesh_pdata[4].grid, 1, (double []) { intermediate_x2 }, (double []) { coarse_x2 }, (int []) { Nx } ); + + for (int i = 0; i < num_patches; i++) { + mesh_pdata[i].fv_proj = gkyl_fv_proj_new(&mesh_pdata[i].grid, 1, 5, eval, 0); + } + + for (int i = 0; i < num_patches; i++) { + gkyl_create_grid_ranges(&mesh_pdata[i].grid, (int []) { 2 }, &mesh_pdata[i].ext_range, &mesh_pdata[i].range ); + mesh_pdata[i].geom = gkyl_wave_geom_new(&mesh_pdata[i].grid, &mesh_pdata[i].ext_range, 0, 0, false); + } + + for (int i = 0; i < num_patches; i++) { + if (low_order_flux) { + struct gkyl_wv_euler_inp inp = { + .gas_gamma = gas_gamma, + .rp_type = WV_EULER_RP_HLL, + .use_gpu = app_args.use_gpu, + }; + mesh_pdata[i].euler = gkyl_wv_euler_inew(&inp); + } + else { + mesh_pdata[i].euler = gkyl_wv_euler_new(gas_gamma, app_args.use_gpu); + } + + mesh_pdata[i].slvr[0] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { + .grid = &mesh_pdata[i].grid, + .equation = mesh_pdata[i].euler, + .limiter = GKYL_MONOTONIZED_CENTERED, + .num_up_dirs = 1, + .update_dirs = { 0 }, + .cfl = cfl_frac, + .geom = mesh_pdata[i].geom, + } + ); + } + + struct gkyl_block_topo *ptopo = create_nested_patch_topo(); + + for (int i = 0; i < num_patches; i++) { + euler_patch_bc_updaters_init(&mesh_pdata[i], &ptopo->conn[i]); + } + + for (int i = 0; i < num_patches; i++) { + mesh_pdata[i].fdup = gkyl_array_new(GKYL_DOUBLE, 5, mesh_pdata[i].ext_range.volume); + + for (int d = 0; d < ndim + 1; d++) { + mesh_pdata[i].f[d] = gkyl_array_new(GKYL_DOUBLE, 5, mesh_pdata[i].ext_range.volume); + } + } + +#ifdef AMR_USETHREADS + for (int i = 0; i < num_patches; i++) { + gkyl_job_pool_add_work(coarse_job_pool, euler_init_job_func_patch, &mesh_pdata[i]); + } + gkyl_job_pool_wait(coarse_job_pool); +#else + for (int i = 0; i < num_patches; i++) { + euler_init_job_func_patch(&mesh_pdata[i]); + } +#endif + + char amr0[64]; + snprintf(amr0, 64, "%s_0", euler_output); + euler_write_sol_patch(amr0, num_patches, mesh_pdata); + + double coarse_t_curr = 0.0; + double intermediate_t_curr = 0.0; + double fine_t_curr = 0.0; + double coarse_dt = euler_max_dt_patch(num_patches, mesh_pdata); + + double intermediate_dt = (1.0 / ref_factor1) * coarse_dt; + double fine_dt = (1.0 / (ref_factor1 * ref_factor2)) * coarse_dt; + + struct sim_stats stats = { }; + + struct timespec tm_start = gkyl_wall_clock(); + + long coarse_step = 1; + long num_steps = app_args.num_steps; + + double io_trigger = t_end / num_frames; + + double dt_init = -1.0; + int num_failures = 0; + + while ((coarse_t_curr < t_end) && (coarse_step <= num_steps)) { + printf("Taking coarse (level 0) time-step %ld at t = %g; ", coarse_step, coarse_t_curr); + struct gkyl_update_status coarse_status = euler_update_patch(coarse_job_pool, ptopo, mesh_pdata, coarse_t_curr, coarse_dt, &stats); + printf(" dt = %g\n", coarse_status.dt_actual); + + if (!coarse_status.success) { + printf("** Update method failed! Aborting simulation ....\n"); + break; + } + + for (long intermediate_step = 1; intermediate_step < ref_factor1 + 1; intermediate_step++) { + printf(" Taking intermediate (level 1) time-step %ld at t = %g", intermediate_step, intermediate_t_curr); + printf(" dt = %g\n", (1.0 / ref_factor1) * coarse_status.dt_actual); + + for (long fine_step = 1; fine_step < ref_factor2 + 1; fine_step++) { + printf(" Taking fine (level 2) time-step %ld at t = %g", fine_step, fine_t_curr); + printf(" dt = %g\n", (1.0 / (ref_factor1 * ref_factor2)) * coarse_status.dt_actual); + + fine_t_curr += (1.0 / (ref_factor1 * ref_factor2)) * coarse_status.dt_actual; + fine_dt += (1.0 / (ref_factor1 * ref_factor2)) * coarse_status.dt_suggested; + } + + intermediate_t_curr += (1.0 / ref_factor1) * coarse_status.dt_actual; + intermediate_dt = (1.0 / ref_factor1) * coarse_status.dt_suggested; + } + + for (int i = 1; i < num_frames; i++) { + if (coarse_t_curr < (i * io_trigger) && (coarse_t_curr + coarse_status.dt_actual) > (i * io_trigger)) { + char buf[64]; + snprintf(buf, 64, "%s_%d", euler_output, i); + + euler_write_sol_patch(buf, num_patches, mesh_pdata); + } + } + + coarse_t_curr += coarse_status.dt_actual; + coarse_dt = coarse_status.dt_suggested; + + if (dt_init < 0.0) { + dt_init = coarse_status.dt_actual; + } + else if (coarse_status.dt_actual < dt_failure_tol * dt_init) { + num_failures += 1; + + printf("WARNING: Time-step dt = %g", coarse_status.dt_actual); + printf(" is below %g*dt_init ...", dt_failure_tol); + printf(" num_failures = %d\n", num_failures); + if (num_failures >= num_failures_max) { + printf("ERROR: Time-step was below %g*dt_init ", dt_failure_tol); + printf("%d consecutive times. Aborting simulation ....\n", num_failures_max); + break; + } + } + else { + num_failures = 0; + } + + coarse_step += 1; + } + + double tm_total_sec = gkyl_time_diff_now_sec(tm_start); + + char buf[64]; + snprintf(buf, 64, "%s_%d", euler_output, num_frames); + + euler_write_sol_patch(buf, num_patches, mesh_pdata); + + printf("Total run-time: %g. Failed steps: %d\n", tm_total_sec, stats.nfail); + + for (int i = 0; i < num_patches; i++) { + gkyl_fv_proj_release(mesh_pdata[i].fv_proj); + gkyl_wv_eqn_release(mesh_pdata[i].euler); + euler_patch_bc_updaters_release(&mesh_pdata[i]); + gkyl_wave_geom_release(mesh_pdata[i].geom); + + gkyl_wave_prop_release(mesh_pdata[i].slvr[0]); + gkyl_array_release(mesh_pdata[i].fdup); + gkyl_array_release(mesh_pdata[i].f[0]); + } + + gkyl_block_topo_release(ptopo); + gkyl_job_pool_release(coarse_job_pool); +} + void euler2d_run_single(int argc, char **argv, struct euler2d_single_init* init) { diff --git a/amr/amr_patch.c b/amr/amr_patch.c index f57277bd3..a69d74714 100644 --- a/amr/amr_patch.c +++ b/amr/amr_patch.c @@ -39,6 +39,38 @@ euler_patch_bc_updaters_init(struct euler_patch_data* pdata, const struct gkyl_b pdata->bc_buffer = gkyl_array_new(GKYL_DOUBLE, 5, buff_sz); } +void +euler_nested_patch_bc_updaters_init(struct euler_patch_data* pdata, const struct gkyl_block_connections* conn) +{ + int nghost[5]; + for (int i = 0; i < 5; i++) { + nghost[i] = 2; + } + + pdata->lower_bc[0] = pdata->upper_bc[0] = 0; + + if (conn->connections[0][0].edge == GKYL_PHYSICAL) { + pdata->lower_bc[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->euler, pdata->geom, 0, GKYL_LOWER_EDGE, nghost, + euler_transmissive_bc, 0); + } + + if (conn->connections[0][1].edge == GKYL_PHYSICAL) { + pdata->upper_bc[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->euler, pdata->geom, 0, GKYL_UPPER_EDGE, nghost, + euler_transmissive_bc, 0); + } + + skin_ghost_ranges_init_patch(&pdata->skin_ghost, &pdata->ext_range, nghost); + long buff_sz = 0; + + long vol = pdata->skin_ghost.lower_skin[0].volume; + + if (buff_sz <= vol) { + buff_sz = vol; + } + + pdata->bc_buffer = gkyl_array_new(GKYL_DOUBLE, 5, buff_sz); +} + void gr_euler_patch_bc_updaters_init(struct euler_patch_data* pdata, const struct gkyl_block_connections* conn) { @@ -71,6 +103,38 @@ gr_euler_patch_bc_updaters_init(struct euler_patch_data* pdata, const struct gky pdata->bc_buffer = gkyl_array_new(GKYL_DOUBLE, 29, buff_sz); } +void +gr_euler_nested_patch_bc_updaters_init(struct euler_patch_data* pdata, const struct gkyl_block_connections* conn) +{ + int nghost[5]; + for (int i = 0; i < 5; i++) { + nghost[i] = 2; + } + + pdata->lower_bc[0] = pdata->upper_bc[0] = 0; + + if (conn->connections[0][0].edge == GKYL_PHYSICAL) { + pdata->lower_bc[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->euler, pdata->geom, 0, GKYL_LOWER_EDGE, nghost, + gr_euler_transmissive_bc, 0); + } + + if (conn->connections[0][1].edge == GKYL_PHYSICAL) { + pdata->upper_bc[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->euler, pdata->geom, 0, GKYL_UPPER_EDGE, nghost, + gr_euler_transmissive_bc, 0); + } + + skin_ghost_ranges_init_patch(&pdata->skin_ghost, &pdata->ext_range, nghost); + long buff_sz = 0; + + long vol = pdata->skin_ghost.lower_skin[0].volume; + + if (buff_sz <= vol) { + buff_sz = vol; + } + + pdata->bc_buffer = gkyl_array_new(GKYL_DOUBLE, 29, buff_sz); +} + void euler_patch_bc_updaters_release(struct euler_patch_data* pdata) { @@ -554,5 +618,29 @@ create_patch_topo() .connections[0] = { { .bid = 0, .dir = 0, .edge = GKYL_UPPER_POSITIVE }, { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL } }, }; + return ptopo; +} + +struct gkyl_block_topo* +create_nested_patch_topo() +{ + struct gkyl_block_topo *ptopo = gkyl_block_topo_new(1, 5); + + ptopo->conn[0] = (struct gkyl_block_connections) { + .connections[0] = { { .bid = 1, .dir = 0, .edge = GKYL_UPPER_POSITIVE }, { .bid = 2, .dir = 0, .edge = GKYL_LOWER_POSITIVE } }, + }; + ptopo->conn[1] = (struct gkyl_block_connections) { + .connections[0] = { { .bid = 3, .dir = 0, .edge = GKYL_UPPER_POSITIVE }, { .bid = 0, .dir = 0, .edge = GKYL_LOWER_POSITIVE } }, + }; + ptopo->conn[2] = (struct gkyl_block_connections) { + .connections[0] = { { .bid = 0, .dir = 0, .edge = GKYL_UPPER_POSITIVE }, { .bid = 4, .dir = 0, .edge = GKYL_LOWER_POSITIVE } }, + }; + ptopo->conn[3] = (struct gkyl_block_connections) { + .connections[0] = { { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL }, { .bid = 1, .dir = 0, .edge = GKYL_LOWER_POSITIVE } }, + }; + ptopo->conn[4] = (struct gkyl_block_connections) { + .connections[0] = { { .bid = 2, .dir = 0, .edge = GKYL_UPPER_POSITIVE }, { .bid = 0, .dir = 0, .edge = GKYL_PHYSICAL } }, + }; + return ptopo; } \ No newline at end of file diff --git a/amr/gkyl_amr_core.h b/amr/gkyl_amr_core.h index 160049ea8..c6530989f 100644 --- a/amr/gkyl_amr_core.h +++ b/amr/gkyl_amr_core.h @@ -72,6 +72,44 @@ struct gr_euler1d_single_init { */ void gr_euler1d_run_single(int argc, char **argv, struct gr_euler1d_single_init* init); +// Initialization data for a 1D simulation using the Euler equations, run with static, patch-structured mesh refinement with a doubly-nested refinement patch. +struct euler1d_double_init { + int base_Nx; + int ref_factor1; + int ref_factor2; + + double coarse_x1; + double coarse_x2; + + double intermediate_x1; + double intermediate_x2; + + double refined_x1; + double refined_x2; + + evalf_t eval; + double gas_gamma; + + char euler_output[32]; + + bool low_order_flux; + double cfl_frac; + + double t_end; + int num_frames; + double dt_failure_tol; + int num_failures_max; +}; + +/** +* Run a 1D simulation using the Euler equations, with static, patch-structured mesh refinement with a doubly-nested refinement patch. +* +* @param argc Number of command line arguments passed to the function. +* @param argv Array of command line arguments passed to the function. +* @param init Initialization data for the 1D Euler equations. +*/ +void euler1d_run_double(int argc, char **argv, struct euler1d_double_init* init); + // Initialization data for a 2D simulation using the Euler equations, run with static, block-structured mesh refinement with a single refinement patch. struct euler2d_single_init { int base_Nx; diff --git a/amr/gkyl_amr_patch_priv.h b/amr/gkyl_amr_patch_priv.h index 739de3b52..c9f9e164f 100644 --- a/amr/gkyl_amr_patch_priv.h +++ b/amr/gkyl_amr_patch_priv.h @@ -62,6 +62,14 @@ void skin_ghost_ranges_init_patch(struct skin_ghost_ranges_patch* sgr, const str */ void euler_patch_bc_updaters_init(struct euler_patch_data* pdata, const struct gkyl_block_connections* conn); +/** +* Initialize nested patch AMR updaters for both physical (outer-patch) and non-physical (inter-patch) boundary conditions for the Euler equations. +* +* @param pdata Patch-structured data for the Euler equations. +* @param conn Topology/connectivity data for the patch hierarchy. +*/ +void euler_nested_patch_bc_updaters_init(struct euler_patch_data* pdata, const struct gkyl_block_connections* conn); + /** * Initialize patch AMR updaters for both physical (outer-patch) and non-physical (inter-patch) boundary conditions for the general relativistic Euler equations. * @@ -70,6 +78,14 @@ void euler_patch_bc_updaters_init(struct euler_patch_data* pdata, const struct g */ void gr_euler_patch_bc_updaters_init(struct euler_patch_data* pdata, const struct gkyl_block_connections* conn); +/** +* Initialize nested patch AMR updaters for both physical (outer-patch) and non-physical (inter-patch) boundary conditions for the general relativistic Euler equations. +* +* @param pdata Patch-structured data for the general relativistic Euler equations. +* @param conn Topology/connectivity data for the patch hierarchy. +*/ +void gr_euler_nested_patch_bc_updaters_init(struct euler_patch_data* pdata, const struct gkyl_block_connections* conn); + /** * Release patch AMR updaters for both physical (outer-patch) and non-physical (inter-patch) boundary conditions for the Euler equations. * @@ -174,4 +190,9 @@ double euler_max_dt_patch(int num_patches, const struct euler_patch_data pdata[] /** * Set up the topology/connectivity information for the patch AMR hierarchy for a mesh containing a single refinement patch. */ -struct gkyl_block_topo* create_patch_topo(); \ No newline at end of file +struct gkyl_block_topo* create_patch_topo(); + +/** +* Set up the topology/connectivity information for the patch AMR hierarchy for a mesh containing a doubly-nested refinement patch. +*/ +struct gkyl_block_topo* create_nested_patch_topo(); \ No newline at end of file diff --git a/regression/rt_amr_euler_sodshock.c b/regression/rt_amr_euler_sodshock_l1.c similarity index 99% rename from regression/rt_amr_euler_sodshock.c rename to regression/rt_amr_euler_sodshock_l1.c index 95d2f9bf1..12a6afcb7 100644 --- a/regression/rt_amr_euler_sodshock.c +++ b/regression/rt_amr_euler_sodshock_l1.c @@ -137,7 +137,7 @@ int main(int argc, char **argv) .eval = evalEulerInit, .gas_gamma = ctx.gas_gamma, - .euler_output = "amr_euler_sodshock", + .euler_output = "amr_euler_sodshock_l1", .low_order_flux = false, .cfl_frac = ctx.cfl_frac, diff --git a/regression/rt_amr_euler_sodshock_l2.c b/regression/rt_amr_euler_sodshock_l2.c new file mode 100644 index 000000000..ca8e07ca4 --- /dev/null +++ b/regression/rt_amr_euler_sodshock_l2.c @@ -0,0 +1,162 @@ +// Sod-type shock tube test, using static, patch-structured mesh refinement with doubly-nested refinement patches (4x4x refinement), for the 5-moment (Euler) equations. +// Input parameters match the initial conditions in Section 2.6.2, with the contact discontinuity placed at x = 0.75 rather than x = 0.5, from the thesis: +// A. Hakim (2006), "High Resolution Wave Propagation Schemes for Two-Fluid Plasma Simulations", +// PhD Thesis, University of Washington. +// https://www.aa.washington.edu/sites/aa/files/research/cpdlab/docs/PhDthesis_hakim.pdf + +#include + +struct amr_euler_sodshock_ctx +{ + // Physical constants (using normalized code units). + double gas_gamma; // Adiabatic index. + + double rhol; // Left fluid mass density. + double ul; // Left fluid velocity. + double pl; // Left fluid pressure. + + double rhor; // Right fluid mass density. + double ur; // Right fluid velocity. + double pr; // Right fluid pressure. + + // Simulation parameters. + int Nx; // Coarse cell count (x-direction). + int ref_factor1; // First refinement factor (coarse-to-intermediate). + int ref_factor2; // Second refinement factor (intermediate-to-fine). + double Lx; // Coarse domain size (x-direction). + double intermediate_Lx; // Intermediate domain size (x-direction). + double fine_Lx; // Fine domain size (x-direction). + double cfl_frac; // CFL coefficient. + + double t_end; // Final simulation time. + int num_frames; // Number of output frames. + double dt_failure_tol; // Minimum allowable fraction of initial time-step. + int num_failures_max; // Maximum allowable number of consecutive small time-steps. +}; + +struct amr_euler_sodshock_ctx +create_ctx(void) +{ + // Physical constants (using normalized code units). + double gas_gamma = 1.4; // Adiabatic index. + + double rhol = 3.0; // Left fluid mass density. + double ul = 0.0; // Left fluid velocity. + double pl = 3.0; // Left fluid pressure. + + double rhor = 1.0; // Right fluid mass density. + double ur = 0.0; // Right fluid velocity. + double pr = 1.0; // Right fluid pressure. + + // Simulation parameters. + int Nx = 8; // Coarse cell count (x-direction). + int ref_factor1 = 4; // First refinement factor (coarse-to-intermediate). + int ref_factor2 = 4; // Second refinement factor (intermediate-to-fine). + double Lx = 1.0; // Coarse domain size (x-direction). + double intermediate_Lx = 0.4; // Intermediate domain size (x-direction). + double fine_Lx = 0.2; // Fine domain size (x-direction). + double cfl_frac = 0.95; // CFL coefficient. + + double t_end = 0.1; // Final simulation time. + int num_frames = 1; // Number of output frames. + double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. + int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. + + struct amr_euler_sodshock_ctx ctx = { + .gas_gamma = gas_gamma, + .rhol = rhol, + .ul = ul, + .pl = pl, + .rhor = rhor, + .ur = ur, + .pr = pr, + .Nx = Nx, + .ref_factor1 = ref_factor1, + .ref_factor2 = ref_factor2, + .Lx = Lx, + .intermediate_Lx = intermediate_Lx, + .fine_Lx = fine_Lx, + .cfl_frac = cfl_frac, + .t_end = t_end, + .num_frames = num_frames, + .dt_failure_tol = dt_failure_tol, + .num_failures_max = num_failures_max, + }; + + return ctx; +} + +void +evalEulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +{ + double x = xn[0]; + struct amr_euler_sodshock_ctx new_ctx = create_ctx(); // Context for initialization functions. + struct amr_euler_sodshock_ctx *app = &new_ctx; + + double gas_gamma = app->gas_gamma; + + double rhol = app->rhol; + double ul = app->ul; + double pl = app->pl; + + double rhor = app->rhor; + double ur = app->ur; + double pr = app->pr; + + double rho = 0.0; + double u = 0.0; + double p = 0.0; + + if (x < 0.75) { + rho = rhol; // Fluid mass density (left). + u = ul; // Fluid velocity (left). + p = pl; // Fluid pressure (left). + } + else { + rho = rhor; // Fluid mass density (right). + u = ur; // Fluid velocity (right). + p = pr; // Fluid pressure (right). + } + + // Set fluid mass density. + fout[0] = rho; + // Set fluid momentum density. + fout[1] = rho * u; fout[2] = 0.0; fout[3] = 0.0; + // Set fluid total energy density. + fout[4] = p / (gas_gamma - 1.0) + 0.5 * rho * u * u; +} + +int main(int argc, char **argv) +{ + struct amr_euler_sodshock_ctx ctx = create_ctx(); // Context for initialization functions. + + struct euler1d_double_init init = { + .base_Nx = ctx.Nx, + .ref_factor1 = ctx.ref_factor1, + .ref_factor2 = ctx.ref_factor2, + + .coarse_x1 = 0.25, + .coarse_x2 = 0.25 + ctx.Lx, + + .intermediate_x1 = (0.25 + (0.5 * ctx.Lx)) - (0.5 * ctx.intermediate_Lx), + .intermediate_x2 = (0.25 + (0.5 * ctx.Lx)) + (0.5 * ctx.intermediate_Lx), + + .refined_x1 = (0.25 + (0.5 * ctx.Lx)) - (0.5 * ctx.fine_Lx), + .refined_x2 = (0.25 + (0.5 * ctx.Lx)) + (0.5 * ctx.fine_Lx), + + .eval = evalEulerInit, + .gas_gamma = ctx.gas_gamma, + + .euler_output = "amr_euler_sodshock_l2", + + .low_order_flux = false, + .cfl_frac = ctx.cfl_frac, + + .t_end = ctx.t_end, + .num_frames = ctx.num_frames, + .dt_failure_tol = ctx.dt_failure_tol, + .num_failures_max = ctx.num_failures_max, + }; + + euler1d_run_double(argc, argv, &init); +} \ No newline at end of file From 4faae50adf93271358a2f108c4e504769edf5158 Mon Sep 17 00:00:00 2001 From: JonathanGorard Date: Thu, 27 Jun 2024 09:29:26 -0400 Subject: [PATCH 15/32] Patch-structured AMR is now hooked up to the (non-coupled) general relativistic Euler equations, and performing well for the mild relativistic shock test. Also made some minor bugfixes to the patch-structured Euler solver. --- amr/amr_core_euler.c | 4 +- amr/amr_core_gr_euler.c | 211 +++++++++++++++ amr/gkyl_amr_core.h | 39 +++ ...mild_shock.c => rt_amr_gr_mild_shock_l1.c} | 2 +- regression/rt_amr_gr_mild_shock_l2.c | 254 ++++++++++++++++++ 5 files changed, 507 insertions(+), 3 deletions(-) rename regression/{rt_amr_gr_mild_shock.c => rt_amr_gr_mild_shock_l1.c} (99%) create mode 100644 regression/rt_amr_gr_mild_shock_l2.c diff --git a/amr/amr_core_euler.c b/amr/amr_core_euler.c index 23526de12..a471705dc 100644 --- a/amr/amr_core_euler.c +++ b/amr/amr_core_euler.c @@ -295,7 +295,7 @@ euler1d_run_double(int argc, char **argv, struct euler1d_double_init* init) struct gkyl_block_topo *ptopo = create_nested_patch_topo(); for (int i = 0; i < num_patches; i++) { - euler_patch_bc_updaters_init(&mesh_pdata[i], &ptopo->conn[i]); + euler_nested_patch_bc_updaters_init(&mesh_pdata[i], &ptopo->conn[i]); } for (int i = 0; i < num_patches; i++) { @@ -360,7 +360,7 @@ euler1d_run_double(int argc, char **argv, struct euler1d_double_init* init) printf(" dt = %g\n", (1.0 / (ref_factor1 * ref_factor2)) * coarse_status.dt_actual); fine_t_curr += (1.0 / (ref_factor1 * ref_factor2)) * coarse_status.dt_actual; - fine_dt += (1.0 / (ref_factor1 * ref_factor2)) * coarse_status.dt_suggested; + fine_dt = (1.0 / (ref_factor1 * ref_factor2)) * coarse_status.dt_suggested; } intermediate_t_curr += (1.0 / ref_factor1) * coarse_status.dt_actual; diff --git a/amr/amr_core_gr_euler.c b/amr/amr_core_gr_euler.c index 309e78d16..f99c9016d 100644 --- a/amr/amr_core_gr_euler.c +++ b/amr/amr_core_gr_euler.c @@ -198,6 +198,217 @@ gr_euler1d_run_single(int argc, char **argv, struct gr_euler1d_single_init* init gkyl_job_pool_release(coarse_job_pool); } +void +gr_euler1d_run_double(int argc, char **argv, struct gr_euler1d_double_init* init) +{ + struct gkyl_app_args app_args = parse_app_args(argc, argv); + + if (app_args.trace_mem) { + gkyl_cu_dev_mem_debug_set(true); + gkyl_mem_debug_set(true); + } + + int base_Nx = init->base_Nx; + int ref_factor1 = init->ref_factor1; + int ref_factor2 = init->ref_factor2; + + double coarse_x1 = init->coarse_x1; + double coarse_x2 = init->coarse_x2; + + double intermediate_x1 = init->intermediate_x1; + double intermediate_x2 = init->intermediate_x2; + + double refined_x1 = init->refined_x1; + double refined_x2 = init->refined_x2; + + evalf_t eval = init->eval; + double gas_gamma = init->gas_gamma; + struct gkyl_gr_spacetime *spacetime = init->spacetime; + + char gr_euler_output[32]; + strcpy(gr_euler_output, init->gr_euler_output); + + bool low_order_flux = init->low_order_flux; + int num_frames = init->num_frames; + + double cfl_frac = init->cfl_frac; + double t_end = init->t_end; + double dt_failure_tol = init->dt_failure_tol; + int num_failures_max = init->num_failures_max; + + int ndim = 1; + int num_patches = 5; + int Nx = base_Nx; + + struct euler_patch_data mesh_pdata[num_patches]; + struct gkyl_job_pool *coarse_job_pool = gkyl_thread_pool_new(app_args.num_threads); + + gkyl_rect_grid_init(&mesh_pdata[0].grid, 1, (double []) { refined_x1 }, (double []) { refined_x2 }, (int []) { Nx * (ref_factor1 * ref_factor2) } ); + + gkyl_rect_grid_init(&mesh_pdata[1].grid, 1, (double []) { intermediate_x1 }, (double []) { refined_x1 }, (int []) { Nx * ref_factor1 } ); + gkyl_rect_grid_init(&mesh_pdata[2].grid, 1, (double []) { refined_x2 }, (double []) { intermediate_x2 }, (int []) { Nx * ref_factor1 } ); + + gkyl_rect_grid_init(&mesh_pdata[3].grid, 1, (double []) { coarse_x1 }, (double []) { intermediate_x1 }, (int []) { Nx } ); + gkyl_rect_grid_init(&mesh_pdata[4].grid, 1, (double []) { intermediate_x2 }, (double []) { coarse_x2 }, (int []) { Nx } ); + + for (int i = 0; i < num_patches; i++) { + mesh_pdata[i].fv_proj = gkyl_fv_proj_new(&mesh_pdata[i].grid, 1, 29, eval, 0); + } + + for (int i = 0; i < num_patches; i++) { + gkyl_create_grid_ranges(&mesh_pdata[i].grid, (int []) { 2 }, &mesh_pdata[i].ext_range, &mesh_pdata[i].range ); + mesh_pdata[i].geom = gkyl_wave_geom_new(&mesh_pdata[i].grid, &mesh_pdata[i].ext_range, 0, 0, false); + } + + for (int i = 0; i < num_patches; i++) { + mesh_pdata[i].euler = gkyl_wv_gr_euler_new(gas_gamma, spacetime, app_args.use_gpu); + + mesh_pdata[i].slvr[0] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { + .grid = &mesh_pdata[i].grid, + .equation = mesh_pdata[i].euler, + .limiter = GKYL_MONOTONIZED_CENTERED, + .num_up_dirs = 1, + .update_dirs = { 0 }, + .cfl = cfl_frac, + .geom = mesh_pdata[i].geom, + } + ); + } + + struct gkyl_block_topo *ptopo = create_nested_patch_topo(); + + for (int i = 0; i < num_patches; i++) { + gr_euler_nested_patch_bc_updaters_init(&mesh_pdata[i], &ptopo->conn[i]); + } + + for (int i = 0; i < num_patches; i++) { + mesh_pdata[i].fdup = gkyl_array_new(GKYL_DOUBLE, 29, mesh_pdata[i].ext_range.volume); + + for (int d = 0; d < ndim + 1; d++) { + mesh_pdata[i].f[d] = gkyl_array_new(GKYL_DOUBLE, 29, mesh_pdata[i].ext_range.volume); + } + } + +#ifdef AMR_USETHREADS + for (int i = 0; i < num_patches; i++) { + gkyl_job_pool_add_work(coarse_job_pool, euler_init_job_func_patch, &mesh_pdata[i]); + } + gkyl_job_pool_wait(coarse_job_pool); +#else + for (int i = 0; i < num_patches; i++) { + euler_init_job_func_patch(&mesh_pdata[i]); + } +#endif + + char amr0[64]; + snprintf(amr0, 64, "%s_0", gr_euler_output); + euler_write_sol_patch(amr0, num_patches, mesh_pdata); + + double coarse_t_curr = 0.0; + double intermediate_t_curr = 0.0; + double fine_t_curr = 0.0; + double coarse_dt = euler_max_dt_patch(num_patches, mesh_pdata); + + double intermediate_dt = (1.0 / ref_factor1) * coarse_dt; + double fine_dt = (1.0 / (ref_factor1 * ref_factor2)) * coarse_dt; + + struct sim_stats stats = { }; + + struct timespec tm_start = gkyl_wall_clock(); + + long coarse_step = 1; + long num_steps = app_args.num_steps; + + double io_trigger = t_end / num_frames; + + double dt_init = -1.0; + int num_failures = 0; + + while ((coarse_t_curr < t_end) && (coarse_step <= num_steps)) { + printf("Taking coarse (level 0) time-step %ld at t = %g; ", coarse_step, coarse_t_curr); + struct gkyl_update_status coarse_status = euler_update_patch(coarse_job_pool, ptopo, mesh_pdata, coarse_t_curr, coarse_dt, &stats); + printf(" dt = %g\n", coarse_status.dt_actual); + + if (!coarse_status.success) { + printf("** Update method failed! Aborting simulation ....\n"); + break; + } + + for (long intermediate_step = 1; intermediate_step < ref_factor1 + 1; intermediate_step++) { + printf(" Taking intermediate (level 1) time-step %ld at t = %g", intermediate_step, intermediate_t_curr); + printf(" dt = %g\n", (1.0 / ref_factor1) * coarse_status.dt_actual); + + for (long fine_step = 1; fine_step < ref_factor2 + 1; fine_step++) { + printf(" Taking fine (level 2) time-step %ld at t = %g", fine_step, fine_t_curr); + printf(" dt = %g\n", (1.0 / (ref_factor1 * ref_factor2)) * coarse_status.dt_actual); + + fine_t_curr += (1.0 / (ref_factor1 * ref_factor2)) * coarse_status.dt_actual; + fine_dt = (1.0 / (ref_factor1 * ref_factor2)) * coarse_status.dt_suggested; + } + + intermediate_t_curr += (1.0 / ref_factor1) * coarse_status.dt_actual; + intermediate_dt = (1.0 / ref_factor1) * coarse_status.dt_suggested; + } + + for (int i = 1; i < num_frames; i++) { + if (coarse_t_curr < (i * io_trigger) && (coarse_t_curr + coarse_status.dt_actual) > (i * io_trigger)) { + char buf[64]; + snprintf(buf, 64, "%s_%d", gr_euler_output, i); + + euler_write_sol_patch(buf, num_patches, mesh_pdata); + } + } + + coarse_t_curr += coarse_status.dt_actual; + coarse_dt = coarse_status.dt_suggested; + + if (dt_init < 0.0) { + dt_init = coarse_status.dt_actual; + } + else if (coarse_status.dt_actual < dt_failure_tol * dt_init) { + num_failures += 1; + + printf("WARNING: Time-step dt = %g", coarse_status.dt_actual); + printf(" is below %g*dt_init ...", dt_failure_tol); + printf(" num_failures = %d\n", num_failures); + if (num_failures >= num_failures_max) { + printf("ERROR: Time-step was below %g*dt_init ", dt_failure_tol); + printf("%d consecutive times. Aborting simulation ....\n", num_failures_max); + break; + } + } + else { + num_failures = 0; + } + + coarse_step += 1; + } + + double tm_total_sec = gkyl_time_diff_now_sec(tm_start); + + char buf[64]; + snprintf(buf, 64, "%s_%d", gr_euler_output, num_frames); + + euler_write_sol_patch(buf, num_patches, mesh_pdata); + + printf("Total run-time: %g. Failed steps: %d\n", tm_total_sec, stats.nfail); + + for (int i = 0; i < num_patches; i++) { + gkyl_fv_proj_release(mesh_pdata[i].fv_proj); + gkyl_wv_eqn_release(mesh_pdata[i].euler); + euler_patch_bc_updaters_release(&mesh_pdata[i]); + gkyl_wave_geom_release(mesh_pdata[i].geom); + + gkyl_wave_prop_release(mesh_pdata[i].slvr[0]); + gkyl_array_release(mesh_pdata[i].fdup); + gkyl_array_release(mesh_pdata[i].f[0]); + } + + gkyl_block_topo_release(ptopo); + gkyl_gr_spacetime_release(spacetime); + gkyl_job_pool_release(coarse_job_pool); +} + void gr_euler2d_run_single(int argc, char **argv, struct gr_euler2d_single_init* init) { diff --git a/amr/gkyl_amr_core.h b/amr/gkyl_amr_core.h index c6530989f..8e2c9aeb3 100644 --- a/amr/gkyl_amr_core.h +++ b/amr/gkyl_amr_core.h @@ -110,6 +110,45 @@ struct euler1d_double_init { */ void euler1d_run_double(int argc, char **argv, struct euler1d_double_init* init); +// Initialization data for a 1D simulation using the general relativistic Euler equations, run with static, patch-structured mesh refinement with a doubly-nested refinement patch. +struct gr_euler1d_double_init { + int base_Nx; + int ref_factor1; + int ref_factor2; + + double coarse_x1; + double coarse_x2; + + double intermediate_x1; + double intermediate_x2; + + double refined_x1; + double refined_x2; + + evalf_t eval; + double gas_gamma; + struct gkyl_gr_spacetime *spacetime; + + char gr_euler_output[32]; + + bool low_order_flux; + double cfl_frac; + + double t_end; + int num_frames; + double dt_failure_tol; + int num_failures_max; +}; + +/** +* Run a 1D simulation using the general relativistic Euler equations, with static, patch-structured mesh refinement with a doubly-nested refinement patch. +* +* @param argc Number of command line arguments passed to the function. +* @param argv Array of command line arguments passed to the function. +* @param init Initialization data for the 1D general relativistic Euler equations. +*/ +void gr_euler1d_run_double(int argc, char **argv, struct gr_euler1d_double_init* init); + // Initialization data for a 2D simulation using the Euler equations, run with static, block-structured mesh refinement with a single refinement patch. struct euler2d_single_init { int base_Nx; diff --git a/regression/rt_amr_gr_mild_shock.c b/regression/rt_amr_gr_mild_shock_l1.c similarity index 99% rename from regression/rt_amr_gr_mild_shock.c rename to regression/rt_amr_gr_mild_shock_l1.c index 3c5a451b8..ad84b3eb3 100644 --- a/regression/rt_amr_gr_mild_shock.c +++ b/regression/rt_amr_gr_mild_shock_l1.c @@ -229,7 +229,7 @@ int main(int argc, char **argv) .gas_gamma = ctx.gas_gamma, .spacetime = ctx.spacetime, - .gr_euler_output = "amr_gr_mild_shock", + .gr_euler_output = "amr_gr_mild_shock_l1", .low_order_flux = true, .cfl_frac = ctx.cfl_frac, diff --git a/regression/rt_amr_gr_mild_shock_l2.c b/regression/rt_amr_gr_mild_shock_l2.c new file mode 100644 index 000000000..7adc9b1e1 --- /dev/null +++ b/regression/rt_amr_gr_mild_shock_l2.c @@ -0,0 +1,254 @@ +// Mildly relativistic blast wave test, using static, patch-structured mesh refinement with doubly-nested refinement patches (4x4x refinement), for the general relativistic Euler equations. +// Input parameters taken from the initial conditions in Section 4.1 (blast wave 1), from the article: +// L. Del Zanna and N. Bucciantini (2002), "An efficient shock-cpaturing central-type scheme for multidimensional relativistic flows. I. Hydrodynamics", +// Astronomy and Astrophysics, Volume 390 (3): 1177-1186. +// https://arxiv.org/abs/astro-ph/0205290 + +#include +#include +#include + +struct amr_gr_mild_shock_ctx +{ + // Physical constants (using normalized code units). + double gas_gamma; // Adiabatic index. + + double rhol; // Left fluid mass density. + double ul; // Left fluid velocity. + double pl; // Left fluid pressure. + + double rhor; // Right fluid mass density. + double ur; // Right fluid velocity. + double pr; // Right fluid pressure. + + // Pointer to spacetime metric. + struct gkyl_gr_spacetime *spacetime; + + // Simulation parameters. + int Nx; // Coarse cell count (x-direction). + int ref_factor1; // First refinement factor (coarse-to-intermediate). + int ref_factor2; // Second refinement factor (intermediate-to-fine). + double Lx; // Coarse domain size (x-direction). + double intermediate_Lx; // Intermediate domain size (x-direction). + double fine_Lx; // Fine domain size (x-direction). + double cfl_frac; // CFL coefficient. + + double t_end; // Final simulation time. + int num_frames; // Number of output frames. + double dt_failure_tol; // Minimum allowable fraction of initial time-step. + int num_failures_max; // Maximum allowable number of consecutive small time-steps. +}; + +struct amr_gr_mild_shock_ctx +create_ctx(void) +{ + // Physical constants (using normalized code units). + double gas_gamma = 5.0 / 3.0; // Adiabatic index. + + double rhol = 10.0; // Left fluid mass density. + double ul = 0.0; // Left fluid velocity. + double pl = 13.3; // Left fluid pressure. + + double rhor = 1.0; // Right fluid mass density. + double ur = 0.0; // Right fluid velocity. + double pr = pow(10.0, -6.0); // Right fluid pressure. + + // Pointer to spacetime metric. + struct gkyl_gr_spacetime *spacetime = gkyl_gr_minkowski_new(false); + + // Simulation parameters. + int Nx = 64; // Coarse cell count (x-direction). + int ref_factor1 = 4; // First refinement factor (coarse-to-intermediate). + int ref_factor2 = 4; // Second refinement factor (intermediate-to-fine). + double Lx = 1.0; // Coarse domain size (x-direction). + double intermediate_Lx = 0.4; // Intermediate domain size (x-direction). + double fine_Lx = 0.2; // Fine domain size (x-direction). + double cfl_frac = 0.95; // CFL coefficient. + + double t_end = 0.4; // Final simulation time. + int num_frames = 1; // Number of output frames. + double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. + int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. + + struct amr_gr_mild_shock_ctx ctx = { + .gas_gamma = gas_gamma, + .rhol = rhol, + .ul = ul, + .pl = pl, + .rhor = rhor, + .ur = ur, + .pr = pr, + .spacetime = spacetime, + .Nx = Nx, + .ref_factor1 = ref_factor1, + .ref_factor2 = ref_factor2, + .Lx = Lx, + .intermediate_Lx = intermediate_Lx, + .fine_Lx = fine_Lx, + .cfl_frac = cfl_frac, + .t_end = t_end, + .num_frames = num_frames, + .dt_failure_tol = dt_failure_tol, + .num_failures_max = num_failures_max, + }; + + return ctx; +} + +void +evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +{ + double x = xn[0]; + struct amr_gr_mild_shock_ctx new_ctx = create_ctx(); // Context for initialization functions. + struct amr_gr_mild_shock_ctx *app = &new_ctx; + + double gas_gamma = app->gas_gamma; + + double rhol = app->rhol; + double ul = app->ul; + double pl = app->pl; + + double rhor = app->rhor; + double ur = app->ur; + double pr = app->pr; + + double rho = 0.0; + double u = 0.0; + double p = 0.0; + + struct gkyl_gr_spacetime *spacetime = app->spacetime; + + if (x < 0.5) { + rho = rhol; // Fluid mass density (left). + u = ul; // Fluid velocity (left). + p = pl; // Fluid pressure (left). + } + else { + rho = rhor; // Fluid mass density (right). + u = ur; // Fluid velocity (right). + p = pr; // Fluid pressure (right). + } + + double spatial_det, lapse; + double *shift = gkyl_malloc(sizeof(double[3])); + bool in_excision_region; + + double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + for (int i = 0; i < 3; i++) { + spatial_metric[i] = gkyl_malloc(sizeof(double[3])); + } + + double **inv_spatial_metric = gkyl_malloc(sizeof(double*[3])); + for (int i = 0; i < 3; i++) { + inv_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); + } + + spacetime->spatial_metric_det_func(spacetime, 0.0, x, 0.0, 0.0, &spatial_det); + spacetime->lapse_function_func(spacetime, 0.0, x, 0.0, 0.0, &lapse); + spacetime->shift_vector_func(spacetime, 0.0, x, 0.0, 0.0, &shift); + spacetime->excision_region_func(spacetime, 0.0, x, 0.0, 0.0, &in_excision_region); + + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, 0.0, 0.0, &spatial_metric); + spacetime->spatial_inv_metric_tensor_func(spacetime, 0.0, x, 0.0, 0.0, &inv_spatial_metric); + + double *vel = gkyl_malloc(sizeof(double[3])); + double v_sq = 0.0; + vel[0] = u; vel[1] = 0.0; vel[2] = 0.0; + + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + v_sq += spatial_metric[i][j] * vel[i] * vel[j]; + } + } + + double W = 1.0 / (sqrt(1.0 - v_sq)); + if (v_sq > 1.0 - pow(10.0, -8.0)) { + W = 1.0 / sqrt(1.0 - pow(10.0, -8.0)); + } + + double h = 1.0 + ((p / rho) * (gas_gamma / (gas_gamma - 1.0))); + + // Set fluid mass density. + fout[0] = sqrt(spatial_det) * rho * W; + // Set fluid momentum density. + fout[1] = sqrt(spatial_det) * rho * h * (W * W) * u; + fout[2] = 0.0; + fout[3] = 0.0; + // Set fluid total energy density. + fout[4] = sqrt(spatial_det) * ((rho * h * (W * W)) - p - (rho * W)); + + // Set spatial metric determinant. + fout[5] = spatial_det; + // Set lapse gauge variable. + fout[6] = lapse; + // Set shift gauge variables. + fout[7] = shift[0]; fout[8] = shift[1]; fout[9] = shift[2]; + + // Set spatial metric tensor. + fout[10] = spatial_metric[0][0]; fout[11] = spatial_metric[0][1]; fout[12] = spatial_metric[0][2]; + fout[13] = spatial_metric[1][0]; fout[14] = spatial_metric[1][1]; fout[15] = spatial_metric[1][2]; + fout[16] = spatial_metric[2][0]; fout[17] = spatial_metric[2][1]; fout[18] = spatial_metric[2][2]; + + // Set inverse spatial metric tensor. + fout[19] = inv_spatial_metric[0][0]; fout[20] = inv_spatial_metric[0][1]; fout[21] = inv_spatial_metric[0][2]; + fout[22] = inv_spatial_metric[1][0]; fout[23] = inv_spatial_metric[1][1]; fout[24] = inv_spatial_metric[1][2]; + fout[25] = inv_spatial_metric[2][0]; fout[26] = inv_spatial_metric[2][1]; fout[27] = inv_spatial_metric[2][2]; + + // Set excision boundary conditions. + if (in_excision_region) { + for (int i = 0; i < 28; i++) { + fout[i] = 0.0; + } + + fout[28] = -1.0; + } + else { + fout[28] = 1.0; + } + + // Free all tensorial quantities. + for (int i = 0; i < 3; i++) { + gkyl_free(spatial_metric[i]); + gkyl_free(inv_spatial_metric[i]); + } + gkyl_free(spatial_metric); + gkyl_free(inv_spatial_metric); + gkyl_free(shift); + gkyl_free(vel); +} + +int main(int argc, char **argv) +{ + struct amr_gr_mild_shock_ctx ctx = create_ctx(); // Context for initialization functions. + + struct gr_euler1d_double_init init = { + .base_Nx = ctx.Nx, + .ref_factor1 = ctx.ref_factor1, + .ref_factor2 = ctx.ref_factor2, + + .coarse_x1 = 0.0, + .coarse_x2 = ctx.Lx, + + .intermediate_x1 = (0.75 * ctx.Lx) - (0.5 * ctx.intermediate_Lx), + .intermediate_x2 = (0.75 * ctx.Lx) + (0.5 * ctx.intermediate_Lx), + + .refined_x1 = (0.75 * ctx.Lx) - (0.5 * ctx.fine_Lx), + .refined_x2 = (0.75 * ctx.Lx) + (0.5 * ctx.fine_Lx), + + .eval = evalGREulerInit, + .gas_gamma = ctx.gas_gamma, + .spacetime = ctx.spacetime, + + .gr_euler_output = "amr_gr_mild_shock_l2", + + .low_order_flux = true, + .cfl_frac = ctx.cfl_frac, + + .t_end = ctx.t_end, + .num_frames = ctx.num_frames, + .dt_failure_tol = ctx.dt_failure_tol, + .num_failures_max = ctx.num_failures_max, + }; + + gr_euler1d_run_double(argc, argv, &init); +} \ No newline at end of file From 4380808a78061ef9ae5d9458e50e07d841e19d17 Mon Sep 17 00:00:00 2001 From: JonathanGorard Date: Thu, 27 Jun 2024 11:04:54 -0400 Subject: [PATCH 16/32] Strong relativistic blast wave and relativistic perturbed density test now working correctly with doubly-nested patch-structured AMR. Shock-tracking behavior appears good across all 1D tests. --- ...ity.c => rt_amr_gr_perturbed_density_l1.c} | 2 +- regression/rt_amr_gr_perturbed_density_l2.c | 254 ++++++++++++++++++ ...ng_blast.c => rt_amr_gr_strong_blast_l1.c} | 2 +- regression/rt_amr_gr_strong_blast_l2.c | 254 ++++++++++++++++++ 4 files changed, 510 insertions(+), 2 deletions(-) rename regression/{rt_amr_gr_perturbed_density.c => rt_amr_gr_perturbed_density_l1.c} (99%) create mode 100644 regression/rt_amr_gr_perturbed_density_l2.c rename regression/{rt_amr_gr_strong_blast.c => rt_amr_gr_strong_blast_l1.c} (99%) create mode 100644 regression/rt_amr_gr_strong_blast_l2.c diff --git a/regression/rt_amr_gr_perturbed_density.c b/regression/rt_amr_gr_perturbed_density_l1.c similarity index 99% rename from regression/rt_amr_gr_perturbed_density.c rename to regression/rt_amr_gr_perturbed_density_l1.c index bad2029c6..10166865f 100644 --- a/regression/rt_amr_gr_perturbed_density.c +++ b/regression/rt_amr_gr_perturbed_density_l1.c @@ -229,7 +229,7 @@ int main(int argc, char **argv) .gas_gamma = ctx.gas_gamma, .spacetime = ctx.spacetime, - .gr_euler_output = "amr_gr_perturbed_density", + .gr_euler_output = "amr_gr_perturbed_density_l1", .low_order_flux = true, .cfl_frac = ctx.cfl_frac, diff --git a/regression/rt_amr_gr_perturbed_density_l2.c b/regression/rt_amr_gr_perturbed_density_l2.c new file mode 100644 index 000000000..74b78a556 --- /dev/null +++ b/regression/rt_amr_gr_perturbed_density_l2.c @@ -0,0 +1,254 @@ +// Perturbed density test, using static, patch-structured mesh refinement with a doubly-nested refinement patches (4x4x refinement), for the general relativistic Euler equations. +// Input parameters taken from the initial conditions in Section 4.1 (density perturbation), from the article: +// L. Del Zanna and N. Bucciantini (2002), "An efficient shock-capturing central-type scheme for multidimensional relativistic flows. I. Hydrodynamics", +// Astronomy and Astrophysics, Volume 390 (3): 1177-1186. +// https://arxiv.org/abs/astro-ph/0205290 + +#include +#include +#include + +struct amr_gr_perturbed_density_ctx +{ + // Physical constants (using normalized code units). + double gas_gamma; // Adiabatic index. + + double rhol; // Left fluid mass density. + double ul; // Left fluid velocity. + double pl; // Left fluid pressure. + + double rhor; // Right fluid mass density. + double ur; // Right fluid velocity. + double pr; // Right fluid pressure. + + // Pointer to spacetime metric. + struct gkyl_gr_spacetime *spacetime; + + // Simulation parameters. + int Nx; // Coarse cell count (x-direction). + int ref_factor1; // First refinement factor (coarse-to-intermediate). + int ref_factor2; // Second refinement factor (intermediate-to-fine). + double Lx; // Coarse domain size (x-direction). + double intermediate_Lx; // Intermediate domain size (x-direction). + double fine_Lx; // Fine domain size (x-direction). + double cfl_frac; // CFL coefficient. + + double t_end; // Final simulation time. + int num_frames; // Number of output frames. + double dt_failure_tol; // Minimum allowable fraction of initial time-step. + int num_failures_max; // Maximum allowable number of consecutive small time-steps. +}; + +struct amr_gr_perturbed_density_ctx +create_ctx(void) +{ + // Physical constants (using normalized code units). + double gas_gamma = 5.0 / 3.0; // Adiabatic index. + + double rhol = 5.0; // Left fluid mass density. + double ul = 0.0; // Left fluid velocity. + double pl = 50.0; // Left fluid pressure. + + double rhor = 2.0; // Right fluid mass density. + double ur = 0.0; // Right fluid velocity. + double pr = 5.0; // Right fluid pressure. + + // Pointer to spacetime metric. + struct gkyl_gr_spacetime *spacetime = gkyl_gr_minkowski_new(false); + + // Simulation parameters. + int Nx = 64; // Coarse cell count (x-direction). + int ref_factor1 = 4; // First refinement factor (coarse-to-intermediate). + int ref_factor2 = 4; // Second refinement factor (intermediate-to-fine). + double Lx = 1.0; // Coarse domain size (x-direction). + double intermediate_Lx = 0.4; // Intermediate domain size (x-direction). + double fine_Lx = 0.2; // Fine domain size (x-direction). + double cfl_frac = 0.95; // CFL coefficient. + + double t_end = 0.35; // Final simulation time. + int num_frames = 1; // Number of output frames. + double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. + int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. + + struct amr_gr_perturbed_density_ctx ctx = { + .gas_gamma = gas_gamma, + .rhol = rhol, + .ul = ul, + .pl = pl, + .rhor = rhor, + .ur = ur, + .pr = pr, + .spacetime = spacetime, + .Nx = Nx, + .ref_factor1 = ref_factor1, + .ref_factor2 = ref_factor2, + .Lx = Lx, + .intermediate_Lx = intermediate_Lx, + .fine_Lx = fine_Lx, + .cfl_frac = cfl_frac, + .t_end = t_end, + .num_frames = num_frames, + .dt_failure_tol = dt_failure_tol, + .num_failures_max = num_failures_max, + }; + + return ctx; +} + +void +evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +{ + double x = xn[0]; + struct amr_gr_perturbed_density_ctx new_ctx = create_ctx(); // Context for initialization functions. + struct amr_gr_perturbed_density_ctx *app = &new_ctx; + + double gas_gamma = app->gas_gamma; + + double rhol = app->rhol; + double ul = app->ul; + double pl = app->pl; + + double rhor = app->rhor; + double ur = app->ur; + double pr = app->pr; + + double rho = 0.0; + double u = 0.0; + double p = 0.0; + + struct gkyl_gr_spacetime *spacetime = app->spacetime; + + if (x < 0.5) { + rho = rhol; // Fluid mass density (left). + u = ul; // Fluid velocity (left). + p = pl; // Fluid pressure (left). + } + else { + rho = rhor + 0.3 * sin(50.0 * x); // Fluid mass density (right). + u = ur; // Fluid velocity (right). + p = pr; // Fluid pressure (right). + } + + double spatial_det, lapse; + double *shift = gkyl_malloc(sizeof(double[3])); + bool in_excision_region; + + double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + for (int i = 0; i < 3; i++) { + spatial_metric[i] = gkyl_malloc(sizeof(double[3])); + } + + double **inv_spatial_metric = gkyl_malloc(sizeof(double*[3])); + for (int i = 0; i < 3; i++) { + inv_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); + } + + spacetime->spatial_metric_det_func(spacetime, 0.0, x, 0.0, 0.0, &spatial_det); + spacetime->lapse_function_func(spacetime, 0.0, x, 0.0, 0.0, &lapse); + spacetime->shift_vector_func(spacetime, 0.0, x, 0.0, 0.0, &shift); + spacetime->excision_region_func(spacetime, 0.0, x, 0.0, 0.0, &in_excision_region); + + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, 0.0, 0.0, &spatial_metric); + spacetime->spatial_inv_metric_tensor_func(spacetime, 0.0, x, 0.0, 0.0, &inv_spatial_metric); + + double *vel = gkyl_malloc(sizeof(double[3])); + double v_sq = 0.0; + vel[0] = u; vel[1] = 0.0; vel[2] = 0.0; + + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + v_sq += spatial_metric[i][j] * vel[i] * vel[j]; + } + } + + double W = 1.0 / (sqrt(1.0 - v_sq)); + if (v_sq > 1.0 - pow(10.0, -8.0)) { + W = 1.0 / sqrt(1.0 - pow(10.0, -8.0)); + } + + double h = 1.0 + ((p / rho) * (gas_gamma / (gas_gamma - 1.0))); + + // Set fluid mass density. + fout[0] = sqrt(spatial_det) * rho * W; + // Set fluid momentum density. + fout[1] = sqrt(spatial_det) * rho * h * (W * W) * u; + fout[2] = 0.0; + fout[3] = 0.0; + // Set fluid total energy density. + fout[4] = sqrt(spatial_det) * ((rho * h * (W * W)) - p - (rho * W)); + + // Set spatial metric determinant. + fout[5] = spatial_det; + // Set lapse gauge variable. + fout[6] = lapse; + // Set shift gauge variables. + fout[7] = shift[0]; fout[8] = shift[1]; fout[9] = shift[2]; + + // Set spatial metric tensor. + fout[10] = spatial_metric[0][0]; fout[11] = spatial_metric[0][1]; fout[12] = spatial_metric[0][2]; + fout[13] = spatial_metric[1][0]; fout[14] = spatial_metric[1][1]; fout[15] = spatial_metric[1][2]; + fout[16] = spatial_metric[2][0]; fout[17] = spatial_metric[2][1]; fout[18] = spatial_metric[2][2]; + + // Set inverse spatial metric tensor. + fout[19] = inv_spatial_metric[0][0]; fout[20] = inv_spatial_metric[0][1]; fout[21] = inv_spatial_metric[0][2]; + fout[22] = inv_spatial_metric[1][0]; fout[23] = inv_spatial_metric[1][1]; fout[24] = inv_spatial_metric[1][2]; + fout[25] = inv_spatial_metric[2][0]; fout[26] = inv_spatial_metric[2][1]; fout[27] = inv_spatial_metric[2][2]; + + // Set excision boundary conditions. + if (in_excision_region) { + for (int i = 0; i < 28; i++) { + fout[i] = 0.0; + } + + fout[28] = -1.0; + } + else { + fout[28] = 1.0; + } + + // Free all tensorial quantities. + for (int i = 0; i < 3; i++) { + gkyl_free(spatial_metric[i]); + gkyl_free(inv_spatial_metric[i]); + } + gkyl_free(spatial_metric); + gkyl_free(inv_spatial_metric); + gkyl_free(shift); + gkyl_free(vel); +} + +int main(int argc, char **argv) +{ + struct amr_gr_perturbed_density_ctx ctx = create_ctx(); // Context for initialization functions. + + struct gr_euler1d_double_init init = { + .base_Nx = ctx.Nx, + .ref_factor1 = ctx.ref_factor1, + .ref_factor2 = ctx.ref_factor2, + + .coarse_x1 = 0.0, + .coarse_x2 = ctx.Lx, + + .intermediate_x1 = (0.75 * ctx.Lx) - (0.5 * ctx.intermediate_Lx), + .intermediate_x2 = (0.75 * ctx.Lx) + (0.5 * ctx.intermediate_Lx), + + .refined_x1 = (0.75 * ctx.Lx) - (0.5 * ctx.fine_Lx), + .refined_x2 = (0.75 * ctx.Lx) + (0.5 * ctx.fine_Lx), + + .eval = evalGREulerInit, + .gas_gamma = ctx.gas_gamma, + .spacetime = ctx.spacetime, + + .gr_euler_output = "amr_gr_perturbed_density_l2", + + .low_order_flux = true, + .cfl_frac = ctx.cfl_frac, + + .t_end = ctx.t_end, + .num_frames = ctx.num_frames, + .dt_failure_tol = ctx.dt_failure_tol, + .num_failures_max = ctx.num_failures_max, + }; + + gr_euler1d_run_double(argc, argv, &init); +} \ No newline at end of file diff --git a/regression/rt_amr_gr_strong_blast.c b/regression/rt_amr_gr_strong_blast_l1.c similarity index 99% rename from regression/rt_amr_gr_strong_blast.c rename to regression/rt_amr_gr_strong_blast_l1.c index 483e96f98..5c31f18cd 100644 --- a/regression/rt_amr_gr_strong_blast.c +++ b/regression/rt_amr_gr_strong_blast_l1.c @@ -229,7 +229,7 @@ int main(int argc, char **argv) .gas_gamma = ctx.gas_gamma, .spacetime = ctx.spacetime, - .gr_euler_output = "amr_gr_strong_blast", + .gr_euler_output = "amr_gr_strong_blast_l1", .low_order_flux = true, .cfl_frac = ctx.cfl_frac, diff --git a/regression/rt_amr_gr_strong_blast_l2.c b/regression/rt_amr_gr_strong_blast_l2.c new file mode 100644 index 000000000..301ccab92 --- /dev/null +++ b/regression/rt_amr_gr_strong_blast_l2.c @@ -0,0 +1,254 @@ +// Strongly relativistic blast wave test, using static, patch-structured mesh refinement with doubly-nested refinement patches (4x4x refinement), for the general relativistic Euler equations. +// Input parameters taken from the initial conditions in Section 4.1 (blast wave 2), from the article: +// L. Del Zanna and N. Bucciantini (2002), "An efficient shock-capturing central-type scheme for multidimensional relativistic flows. I. Hydrodynamics", +// Astronomy and Astrophysics, Volume 390 (3): 1177-1186. +// https://arxiv.org/abs/astro-ph/0205290 + +#include +#include +#include + +struct amr_gr_strong_blast_ctx +{ + // Physical constants (using normalized code units). + double gas_gamma; // Adiabatic index. + + double rhol; // Left fluid mass density. + double ul; // Left fluid velocity. + double pl; // Left fluid pressure. + + double rhor; // Right fluid mass density. + double ur; // Right fluid velocity. + double pr; // Right fluid pressure. + + // Pointer to spacetime metric. + struct gkyl_gr_spacetime *spacetime; + + // Simulation parameters. + int Nx; // Coarse cell count (x-direction). + int ref_factor1; // First refinement factor (coarse-to-intermediate). + int ref_factor2; // Second refinement factor (intermediate-to-fine). + double Lx; // Coarse domain size (x-direction). + double intermediate_Lx; // Intermediate domain size (x-direction). + double fine_Lx; // Fine domain size (x-direction). + double cfl_frac; // CFL coefficient. + + double t_end; // Final simulation time. + int num_frames; // Number of output frames. + double dt_failure_tol; // Minimum allowable fraction of initial time-step. + int num_failures_max; // Maximum allowable number of consecutive small time-steps. +}; + +struct amr_gr_strong_blast_ctx +create_ctx(void) +{ + // Physical constants (using normalized code units). + double gas_gamma = 5.0 / 3.0; // Adiabatic index. + + double rhol = 1.0; // Left fluid mass density. + double ul = 0.0; // Left fluid velocity. + double pl = 1000.0; // Left fluid pressure. + + double rhor = 1.0; // Right fluid mass density. + double ur = 0.0; // Right fluid velocity. + double pr = 0.01; // Right fluid pressure. + + // Pointer to spacetime metric. + struct gkyl_gr_spacetime *spacetime = gkyl_gr_minkowski_new(false); + + // Simulation parameters. + int Nx = 64; // Coarse cell count (x-direction). + int ref_factor1 = 4; // First refinement factor (coarse-to-intermediate). + int ref_factor2 = 4; // Second refinement factor (intermediate-to-fine). + double Lx = 1.0; // Coarse domain size (x-direction). + double intermediate_Lx = 0.3; // Intermediate domain size (x-direction). + double fine_Lx = 0.15; // Fine domain size (x-direction). + double cfl_frac = 0.95; // CFL coefficient. + + double t_end = 0.35; // Final simulation time. + int num_frames = 1; // Number of output frames. + double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. + int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. + + struct amr_gr_strong_blast_ctx ctx = { + .gas_gamma = gas_gamma, + .rhol = rhol, + .ul = ul, + .pl = pl, + .rhor = rhor, + .ur = ur, + .pr = pr, + .spacetime = spacetime, + .Nx = Nx, + .ref_factor1 = ref_factor1, + .ref_factor2 = ref_factor2, + .Lx = Lx, + .intermediate_Lx = intermediate_Lx, + .fine_Lx = fine_Lx, + .cfl_frac = cfl_frac, + .t_end = t_end, + .num_frames = num_frames, + .dt_failure_tol = dt_failure_tol, + .num_failures_max = num_failures_max, + }; + + return ctx; +} + +void +evalGREulerInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +{ + double x = xn[0]; + struct amr_gr_strong_blast_ctx new_ctx = create_ctx(); // Context for initialization functions. + struct amr_gr_strong_blast_ctx *app = &new_ctx; + + double gas_gamma = app->gas_gamma; + + double rhol = app->rhol; + double ul = app->ul; + double pl = app->pl; + + double rhor = app->rhor; + double ur = app->ur; + double pr = app->pr; + + double rho = 0.0; + double u = 0.0; + double p = 0.0; + + struct gkyl_gr_spacetime *spacetime = app->spacetime; + + if (x < 0.5) { + rho = rhol; // Fluid mass density (left). + u = ul; // Fluid velocity (left). + p = pl; // Fluid pressure (left). + } + else { + rho = rhor; // Fluid mass density (right). + u = ur; // Fluid velocity (right). + p = pr; // Fluid pressure (right). + } + + double spatial_det, lapse; + double *shift = gkyl_malloc(sizeof(double[3])); + bool in_excision_region; + + double **spatial_metric = gkyl_malloc(sizeof(double*[3])); + for (int i = 0; i < 3; i++) { + spatial_metric[i] = gkyl_malloc(sizeof(double[3])); + } + + double **inv_spatial_metric = gkyl_malloc(sizeof(double*[3])); + for (int i = 0; i < 3; i++) { + inv_spatial_metric[i] = gkyl_malloc(sizeof(double[3])); + } + + spacetime->spatial_metric_det_func(spacetime, 0.0, x, 0.0, 0.0, &spatial_det); + spacetime->lapse_function_func(spacetime, 0.0, x, 0.0, 0.0, &lapse); + spacetime->shift_vector_func(spacetime, 0.0, x, 0.0, 0.0, &shift); + spacetime->excision_region_func(spacetime, 0.0, x, 0.0, 0.0, &in_excision_region); + + spacetime->spatial_metric_tensor_func(spacetime, 0.0, x, 0.0, 0.0, &spatial_metric); + spacetime->spatial_inv_metric_tensor_func(spacetime, 0.0, x, 0.0, 0.0, &inv_spatial_metric); + + double *vel = gkyl_malloc(sizeof(double[3])); + double v_sq = 0.0; + vel[0] = u; vel[1] = 0.0; vel[2] = 0.0; + + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + v_sq += spatial_metric[i][j] * vel[i] * vel[j]; + } + } + + double W = 1.0 / (sqrt(1.0 - v_sq)); + if (v_sq > 1.0 - pow(10.0, -8.0)) { + W = 1.0 / sqrt(1.0 - pow(10.0, -8.0)); + } + + double h = 1.0 + ((p / rho) * (gas_gamma / (gas_gamma - 1.0))); + + // Set fluid mass density. + fout[0] = sqrt(spatial_det) * rho * W; + // Set fluid momentum density. + fout[1] = sqrt(spatial_det) * rho * h * (W * W) * u; + fout[2] = 0.0; + fout[3] = 0.0; + // Set fluid total energy density. + fout[4] = sqrt(spatial_det) * ((rho * h * (W * W)) - p - (rho * W)); + + // Set spatial metric determinant. + fout[5] = spatial_det; + // Set lapse gauge variable. + fout[6] = lapse; + // Set shift gauge variables. + fout[7] = shift[0]; fout[8] = shift[1]; fout[9] = shift[2]; + + // Set spatial metric tensor. + fout[10] = spatial_metric[0][0]; fout[11] = spatial_metric[0][1]; fout[12] = spatial_metric[0][2]; + fout[13] = spatial_metric[1][0]; fout[14] = spatial_metric[1][1]; fout[15] = spatial_metric[1][2]; + fout[16] = spatial_metric[2][0]; fout[17] = spatial_metric[2][1]; fout[18] = spatial_metric[2][2]; + + // Set inverse spatial metric tensor. + fout[19] = inv_spatial_metric[0][0]; fout[20] = inv_spatial_metric[0][1]; fout[21] = inv_spatial_metric[0][2]; + fout[22] = inv_spatial_metric[1][0]; fout[23] = inv_spatial_metric[1][1]; fout[24] = inv_spatial_metric[1][2]; + fout[25] = inv_spatial_metric[2][0]; fout[26] = inv_spatial_metric[2][1]; fout[27] = inv_spatial_metric[2][2]; + + // Set excision boundary conditions. + if (in_excision_region) { + for (int i = 0; i < 28; i++) { + fout[i] = 0.0; + } + + fout[28] = -1.0; + } + else { + fout[28] = 1.0; + } + + // Free all tensorial quantities. + for (int i = 0; i < 3; i++) { + gkyl_free(spatial_metric[i]); + gkyl_free(inv_spatial_metric[i]); + } + gkyl_free(spatial_metric); + gkyl_free(inv_spatial_metric); + gkyl_free(shift); + gkyl_free(vel); +} + +int main(int argc, char **argv) +{ + struct amr_gr_strong_blast_ctx ctx = create_ctx(); // Context for initialization functions. + + struct gr_euler1d_double_init init = { + .base_Nx = ctx.Nx, + .ref_factor1 = ctx.ref_factor1, + .ref_factor2 = ctx.ref_factor2, + + .coarse_x1 = 0.0, + .coarse_x2 = ctx.Lx, + + .intermediate_x1 = (0.8 * ctx.Lx) - (0.5 * ctx.intermediate_Lx), + .intermediate_x2 = (0.8 * ctx.Lx) + (0.5 * ctx.intermediate_Lx), + + .refined_x1 = (0.8 * ctx.Lx) - (0.5 * ctx.fine_Lx), + .refined_x2 = (0.8 * ctx.Lx) + (0.5 * ctx.fine_Lx), + + .eval = evalGREulerInit, + .gas_gamma = ctx.gas_gamma, + .spacetime = ctx.spacetime, + + .gr_euler_output = "amr_gr_strong_blast_l2", + + .low_order_flux = true, + .cfl_frac = ctx.cfl_frac, + + .t_end = ctx.t_end, + .num_frames = ctx.num_frames, + .dt_failure_tol = ctx.dt_failure_tol, + .num_failures_max = ctx.num_failures_max, + }; + + gr_euler1d_run_double(argc, argv, &init); +} \ No newline at end of file From eeefc2fdf5df00c6490ae4d946a59be0012dbe81 Mon Sep 17 00:00:00 2001 From: JonathanGorard Date: Thu, 27 Jun 2024 13:18:26 -0400 Subject: [PATCH 17/32] Hooked up (doubly-nested) patch-structured AMR infrastructure to the coupled 5-moment equations, and confirmed good performance - with good shock-tracking capabilities - for the generalized Brio-Wu Riemann problem. --- amr/amr_core_five_moment.c | 315 ++++++++++++++++++ amr/amr_patch_coupled.c | 88 +++++ amr/gkyl_amr_core.h | 53 +++ amr/gkyl_amr_patch_coupled_priv.h | 16 + .../{rt_amr_5m_riem.c => rt_amr_5m_riem_l1.c} | 2 +- regression/rt_amr_5m_riem_l2.c | 281 ++++++++++++++++ 6 files changed, 754 insertions(+), 1 deletion(-) rename regression/{rt_amr_5m_riem.c => rt_amr_5m_riem_l1.c} (99%) create mode 100644 regression/rt_amr_5m_riem_l2.c diff --git a/amr/amr_core_five_moment.c b/amr/amr_core_five_moment.c index e953d2cfa..80a2c3c92 100644 --- a/amr/amr_core_five_moment.c +++ b/amr/amr_core_five_moment.c @@ -303,6 +303,321 @@ five_moment_1d_run_single(int argc, char **argv, struct five_moment_1d_single_in gkyl_job_pool_release(coarse_job_pool); } +void +five_moment_1d_run_double(int argc, char **argv, struct five_moment_1d_double_init* init) +{ + struct gkyl_app_args app_args = parse_app_args(argc, argv); + + if (app_args.trace_mem) { + gkyl_cu_dev_mem_debug_set(true); + gkyl_mem_debug_set(true); + } + + int base_Nx = init->base_Nx; + int ref_factor1 = init->ref_factor1; + int ref_factor2 = init->ref_factor2; + + double coarse_x1 = init->coarse_x1; + double coarse_x2 = init->coarse_x2; + + double intermediate_x1 = init->intermediate_x1; + double intermediate_x2 = init->intermediate_x2; + + double refined_x1 = init->refined_x1; + double refined_x2 = init->refined_x2; + + evalf_t eval_elc = init->eval_elc; + evalf_t eval_ion = init->eval_ion; + evalf_t eval_field = init->eval_field; + + double gas_gamma = init->gas_gamma; + double k0_elc = init->k0_elc; + double k0_ion = init->k0_ion; + + double light_speed = init->light_speed; + double e_fact = init->e_fact; + double b_fact = init->b_fact; + + double epsilon0 = init->epsilon0; + double mass_elc = init->mass_elc; + double charge_elc = init->charge_elc; + double mass_ion = init->mass_ion; + double charge_ion = init->charge_ion; + + char five_moment_output[32]; + strcpy(five_moment_output, init->five_moment_output); + + bool low_order_flux = init->low_order_flux; + int num_frames = init->num_frames; + + double cfl_frac = init->cfl_frac; + double t_end = init->t_end; + double dt_failure_tol = init->dt_failure_tol; + int num_failures_max = init->num_failures_max; + + int ndim = 1; + int num_patches = 5; + int Nx = base_Nx; + + struct five_moment_patch_data mesh_pdata[num_patches]; + struct gkyl_job_pool *coarse_job_pool = gkyl_thread_pool_new(app_args.num_threads); + + gkyl_rect_grid_init(&mesh_pdata[0].grid, 1, (double []) { refined_x1 }, (double []) { refined_x2 }, (int []) { Nx * (ref_factor1 * ref_factor2) } ); + + gkyl_rect_grid_init(&mesh_pdata[1].grid, 1, (double []) { intermediate_x1 }, (double []) { refined_x1 }, (int []) { Nx * ref_factor1 } ); + gkyl_rect_grid_init(&mesh_pdata[2].grid, 1, (double []) { refined_x2 }, (double []) { intermediate_x2 }, (int []) { Nx * ref_factor1 } ); + + gkyl_rect_grid_init(&mesh_pdata[3].grid, 1, (double []) { coarse_x1 }, (double []) { intermediate_x1 }, (int []) { Nx } ); + gkyl_rect_grid_init(&mesh_pdata[4].grid, 1, (double []) { intermediate_x2 }, (double []) { coarse_x2 }, (int []) { Nx } ); + + for (int i = 0; i < num_patches; i++) { + mesh_pdata[i].fv_proj_elc = gkyl_fv_proj_new(&mesh_pdata[i].grid, 1, 5, eval_elc, 0); + mesh_pdata[i].fv_proj_ion = gkyl_fv_proj_new(&mesh_pdata[i].grid, 1, 5, eval_ion, 0); + mesh_pdata[i].fv_proj_maxwell = gkyl_fv_proj_new(&mesh_pdata[i].grid, 1, 8, eval_field, 0); + } + + for (int i = 0; i < num_patches; i++) { + gkyl_create_grid_ranges(&mesh_pdata[i].grid, (int []) { 2 }, &mesh_pdata[i].ext_range, &mesh_pdata[i].range); + mesh_pdata[i].geom = gkyl_wave_geom_new(&mesh_pdata[i].grid, &mesh_pdata[i].ext_range, 0, 0, false); + } + + for (int i = 0; i < num_patches; i++) { + if (low_order_flux) { + struct gkyl_wv_euler_inp inp = { + .gas_gamma = gas_gamma, + .rp_type = WV_EULER_RP_HLL, + .use_gpu = app_args.use_gpu, + }; + mesh_pdata[i].euler_elc = gkyl_wv_euler_inew(&inp); + mesh_pdata[i].euler_ion = gkyl_wv_euler_inew(&inp); + } + else { + mesh_pdata[i].euler_elc = gkyl_wv_euler_new(gas_gamma, app_args.use_gpu); + mesh_pdata[i].euler_ion = gkyl_wv_euler_new(gas_gamma, app_args.use_gpu); + } + mesh_pdata[i].maxwell = gkyl_wv_maxwell_new(light_speed, e_fact, b_fact); + + mesh_pdata[i].slvr_elc[0] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { + .grid = &mesh_pdata[i].grid, + .equation = mesh_pdata[i].euler_elc, + .limiter = GKYL_MONOTONIZED_CENTERED, + .num_up_dirs = 1, + .update_dirs = { 0 }, + .cfl = cfl_frac, + .geom = mesh_pdata[i].geom, + } + ); + mesh_pdata[i].slvr_ion[0] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { + .grid = &mesh_pdata[i].grid, + .equation = mesh_pdata[i].euler_ion, + .limiter = GKYL_MONOTONIZED_CENTERED, + .num_up_dirs = 1, + .update_dirs = { 0 }, + .cfl = cfl_frac, + .geom = mesh_pdata[i].geom, + } + ); + mesh_pdata[i].slvr_maxwell[0] = gkyl_wave_prop_new(& (struct gkyl_wave_prop_inp) { + .grid = &mesh_pdata[i].grid, + .equation = mesh_pdata[i].maxwell, + .limiter = GKYL_MONOTONIZED_CENTERED, + .num_up_dirs = 1, + .update_dirs = { 0 }, + .cfl = cfl_frac, + .geom = mesh_pdata[i].geom, + } + ); + + struct gkyl_moment_em_coupling_inp coarse_src_inp = { + .grid = &mesh_pdata[i].grid, + .nfluids = 2, + .epsilon0 = epsilon0, + }; + + coarse_src_inp.param[0] = (struct gkyl_moment_em_coupling_data) { + .type = mesh_pdata[i].euler_elc->type, + .charge = charge_elc, + .mass = mass_elc, + .k0 = k0_elc, + }; + coarse_src_inp.param[1] = (struct gkyl_moment_em_coupling_data) { + .type = mesh_pdata[i].euler_ion->type, + .charge = charge_ion, + .mass = mass_ion, + .k0 = k0_ion, + }; + + mesh_pdata[i].src_slvr = gkyl_moment_em_coupling_new(coarse_src_inp); + } + + struct gkyl_block_topo *ptopo = create_nested_patch_topo(); + + for (int i = 0; i < num_patches; i++) { + five_moment_nested_patch_bc_updaters_init(&mesh_pdata[i], &ptopo->conn[i]); + } + + for (int i = 0; i < num_patches; i++) { + mesh_pdata[i].fdup_elc = gkyl_array_new(GKYL_DOUBLE, 5, mesh_pdata[i].ext_range.volume); + mesh_pdata[i].fdup_ion = gkyl_array_new(GKYL_DOUBLE, 5, mesh_pdata[i].ext_range.volume); + mesh_pdata[i].fdup_maxwell = gkyl_array_new(GKYL_DOUBLE, 8, mesh_pdata[i].ext_range.volume); + + for (int d = 0; d < ndim + 1; d++) { + mesh_pdata[i].f_elc[d] = gkyl_array_new(GKYL_DOUBLE, 5, mesh_pdata[i].ext_range.volume); + mesh_pdata[i].f_ion[d] = gkyl_array_new(GKYL_DOUBLE, 5, mesh_pdata[i].ext_range.volume); + mesh_pdata[i].f_maxwell[d] = gkyl_array_new(GKYL_DOUBLE, 8, mesh_pdata[i].ext_range.volume); + } + + mesh_pdata[i].app_accel_elc = gkyl_array_new(GKYL_DOUBLE, 3, mesh_pdata[i].ext_range.volume); + mesh_pdata[i].app_accel_ion = gkyl_array_new(GKYL_DOUBLE, 3, mesh_pdata[i].ext_range.volume); + mesh_pdata[i].rhs_source_elc = gkyl_array_new(GKYL_DOUBLE, 5, mesh_pdata[i].ext_range.volume); + mesh_pdata[i].rhs_source_ion = gkyl_array_new(GKYL_DOUBLE, 5, mesh_pdata[i].ext_range.volume); + mesh_pdata[i].ext_em = gkyl_array_new(GKYL_DOUBLE, 6, mesh_pdata[i].ext_range.volume); + mesh_pdata[i].app_current = gkyl_array_new(GKYL_DOUBLE, 3, mesh_pdata[i].ext_range.volume); + mesh_pdata[i].nT_source_elc = gkyl_array_new(GKYL_DOUBLE, 2, mesh_pdata[i].ext_range.volume); + mesh_pdata[i].nT_source_ion = gkyl_array_new(GKYL_DOUBLE, 2, mesh_pdata[i].ext_range.volume); + } + +#ifdef AMR_USETHREADS + for (int i = 0; i < num_patches; i++) { + gkyl_job_pool_add_work(coarse_job_pool, five_moment_init_job_func_patch, &mesh_pdata[i]); + } + gkyl_job_pool_wait(coarse_job_pool); +#else + for (int i = 0; i < num_patches; i++) { + five_moment_init_job_func_patch(&mesh_pdata[i]); + } +#endif + + char amr0[64]; + snprintf(amr0, 64, "%s_0", five_moment_output); + five_moment_write_sol_patch(amr0, num_patches, mesh_pdata); + + double coarse_t_curr = 0.0; + double intermediate_t_curr = 0.0; + double fine_t_curr = 0.0; + double coarse_dt = five_moment_max_dt_patch(num_patches, mesh_pdata); + + double intermediate_dt = (1.0 / ref_factor1) * coarse_dt; + double fine_dt = (1.0 / (ref_factor1 * ref_factor2)) * coarse_dt; + + struct sim_stats stats = { }; + + struct timespec tm_start = gkyl_wall_clock(); + + long coarse_step = 1; + long num_steps = app_args.num_steps; + + double io_trigger = t_end / num_frames; + + double dt_init = -1.0; + int num_failures = 0; + + while ((coarse_t_curr < t_end) && (coarse_step <= num_steps)) { + printf("Taking coarse (level 0) time-step %ld at t = %g; ", coarse_step, coarse_t_curr); + struct gkyl_update_status coarse_status = five_moment_update_patch(coarse_job_pool, ptopo, mesh_pdata, coarse_t_curr, coarse_dt, &stats); + printf(" dt = %g\n", coarse_status.dt_actual); + + if (!coarse_status.success) { + printf("** Update method failed! Aborting simulation ....\n"); + break; + } + + for (long intermediate_step = 1; intermediate_step < ref_factor1 + 1; intermediate_step++) { + printf(" Taking intermediate (level 1) time-step %ld at t = %g", intermediate_step, intermediate_t_curr); + printf(" dt = %g\n", (1.0 / ref_factor1) * coarse_status.dt_actual); + + for (long fine_step = 1; fine_step < ref_factor2 + 1; fine_step++) { + printf(" Taking fine (level 2) time-step %ld at t = %g", fine_step, fine_t_curr); + printf(" dt = %g\n", (1.0 / (ref_factor1 * ref_factor2)) * coarse_status.dt_actual); + + fine_t_curr += (1.0 / (ref_factor1 * ref_factor2)) * coarse_status.dt_actual; + fine_dt = (1.0 / (ref_factor1 * ref_factor2)) * coarse_status.dt_suggested; + } + + intermediate_t_curr += (1.0 / ref_factor1) * coarse_status.dt_actual; + intermediate_dt = (1.0 / ref_factor1) * coarse_status.dt_suggested; + } + + for (int i = 1; i < num_frames; i++) { + if (coarse_t_curr < (i * io_trigger) && (coarse_t_curr + coarse_status.dt_actual) > (i * io_trigger)) { + char buf[64]; + snprintf(buf, 64, "%s_%d", five_moment_output, i); + + five_moment_write_sol_patch(buf, num_patches, mesh_pdata); + } + } + + coarse_t_curr += coarse_status.dt_actual; + coarse_dt = coarse_status.dt_suggested; + + if (dt_init < 0.0) { + dt_init = coarse_status.dt_actual; + } + else if (coarse_status.dt_actual < dt_failure_tol * dt_init) { + num_failures += 1; + + printf("WARNING: Time-step dt = %g", coarse_status.dt_actual); + printf(" is below %g*dt_init ...", dt_failure_tol); + printf(" num_failures = %d\n", num_failures); + if (num_failures >= num_failures_max) { + printf("ERROR: Time-step was below %g*dt_init ", dt_failure_tol); + printf("%d consecutive times. Aborting simulation ....\n", num_failures_max); + break; + } + } + else { + num_failures = 0; + } + + coarse_step += 1; + } + + double tm_total_sec = gkyl_time_diff_now_sec(tm_start); + + char buf[64]; + snprintf(buf, 64, "%s_%d", five_moment_output, num_frames); + + five_moment_write_sol_patch(buf, num_patches, mesh_pdata); + + printf("Total run-time: %g. Failed steps: %d\n", tm_total_sec, stats.nfail); + for (int i = 0; i < num_patches; i++) { + gkyl_fv_proj_release(mesh_pdata[i].fv_proj_elc); + gkyl_fv_proj_release(mesh_pdata[i].fv_proj_ion); + gkyl_fv_proj_release(mesh_pdata[i].fv_proj_maxwell); + + gkyl_wv_eqn_release(mesh_pdata[i].euler_elc); + gkyl_wv_eqn_release(mesh_pdata[i].euler_ion); + gkyl_wv_eqn_release(mesh_pdata[i].maxwell); + + five_moment_patch_bc_updaters_release(&mesh_pdata[i]); + gkyl_wave_geom_release(mesh_pdata[i].geom); + + gkyl_wave_prop_release(mesh_pdata[i].slvr_elc[0]); + gkyl_wave_prop_release(mesh_pdata[i].slvr_ion[0]); + gkyl_wave_prop_release(mesh_pdata[i].slvr_maxwell[0]); + + gkyl_array_release(mesh_pdata[i].fdup_elc); + gkyl_array_release(mesh_pdata[i].fdup_ion); + gkyl_array_release(mesh_pdata[i].fdup_maxwell); + + gkyl_array_release(mesh_pdata[i].f_elc[0]); + gkyl_array_release(mesh_pdata[i].f_ion[0]); + gkyl_array_release(mesh_pdata[i].f_maxwell[0]); + + gkyl_array_release(mesh_pdata[i].app_accel_elc); + gkyl_array_release(mesh_pdata[i].app_accel_ion); + gkyl_array_release(mesh_pdata[i].rhs_source_elc); + gkyl_array_release(mesh_pdata[i].rhs_source_ion); + gkyl_array_release(mesh_pdata[i].ext_em); + gkyl_array_release(mesh_pdata[i].app_current); + gkyl_array_release(mesh_pdata[i].nT_source_elc); + gkyl_array_release(mesh_pdata[i].nT_source_ion); + } + + gkyl_block_topo_release(ptopo); + gkyl_job_pool_release(coarse_job_pool); +} + void five_moment_2d_run_single(int argc, char **argv, struct five_moment_2d_single_init* init) { diff --git a/amr/amr_patch_coupled.c b/amr/amr_patch_coupled.c index 06b3a5b80..44e6d3631 100644 --- a/amr/amr_patch_coupled.c +++ b/amr/amr_patch_coupled.c @@ -45,6 +45,50 @@ five_moment_patch_bc_updaters_init(struct five_moment_patch_data* pdata, const s pdata->bc_buffer_maxwell = gkyl_array_new(GKYL_DOUBLE, 8, buff_sz); } +void +five_moment_nested_patch_bc_updaters_init(struct five_moment_patch_data* pdata, const struct gkyl_block_connections* conn) +{ + int nghost[5]; + for (int i = 0; i < 5; i++) { + nghost[i] = 2; + } + + pdata->lower_bc_elc[0] = pdata->upper_bc_elc[0] = 0; + pdata->lower_bc_ion[0] = pdata->upper_bc_ion[0] = 0; + pdata->lower_bc_maxwell[0] = pdata->upper_bc_maxwell[0] = 0; + + if (conn->connections[0][0].edge == GKYL_PHYSICAL) { + pdata->lower_bc_elc[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->euler_elc, pdata->geom, 0, GKYL_LOWER_EDGE, nghost, + five_moment_transmissive_bc, 0); + pdata->lower_bc_ion[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->euler_ion, pdata->geom, 0, GKYL_LOWER_EDGE, nghost, + five_moment_transmissive_bc, 0); + pdata->lower_bc_maxwell[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->maxwell, pdata->geom, 0, GKYL_LOWER_EDGE, nghost, + maxwell_transmissive_bc, 0); + } + + if (conn->connections[0][1].edge == GKYL_PHYSICAL) { + pdata->upper_bc_elc[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->euler_elc, pdata->geom, 0, GKYL_UPPER_EDGE, nghost, + five_moment_transmissive_bc, 0); + pdata->upper_bc_ion[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->euler_ion, pdata->geom, 0, GKYL_UPPER_EDGE, nghost, + five_moment_transmissive_bc, 0); + pdata->upper_bc_maxwell[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->maxwell, pdata->geom, 0, GKYL_UPPER_EDGE, nghost, + maxwell_transmissive_bc, 0); + } + + skin_ghost_ranges_init_patch(&pdata->skin_ghost, &pdata->ext_range, nghost); + long buff_sz = 0; + + long vol = pdata->skin_ghost.lower_skin[0].volume; + + if (buff_sz <= vol) { + buff_sz = vol; + } + + pdata->bc_buffer_elc = gkyl_array_new(GKYL_DOUBLE, 5, buff_sz); + pdata->bc_buffer_ion = gkyl_array_new(GKYL_DOUBLE, 5, buff_sz); + pdata->bc_buffer_maxwell = gkyl_array_new(GKYL_DOUBLE, 8, buff_sz); +} + void ten_moment_patch_bc_updaters_init(struct five_moment_patch_data* pdata, const struct gkyl_block_connections* conn) { @@ -89,6 +133,50 @@ ten_moment_patch_bc_updaters_init(struct five_moment_patch_data* pdata, const st pdata->bc_buffer_maxwell = gkyl_array_new(GKYL_DOUBLE, 8, buff_sz); } +void +ten_moment_nested_patch_bc_updaters_init(struct five_moment_patch_data* pdata, const struct gkyl_block_connections* conn) +{ + int nghost[5]; + for (int i = 0; i < 5; i++) { + nghost[i] = 2; + } + + pdata->lower_bc_elc[0] = pdata->upper_bc_elc[0] = 0; + pdata->lower_bc_ion[0] = pdata->upper_bc_ion[0] = 0; + pdata->lower_bc_maxwell[0] = pdata->upper_bc_maxwell[0] = 0; + + if (conn->connections[0][0].edge == GKYL_PHYSICAL) { + pdata->lower_bc_elc[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->euler_elc, pdata->geom, 0, GKYL_LOWER_EDGE, nghost, + ten_moment_transmissive_bc, 0); + pdata->lower_bc_ion[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->euler_ion, pdata->geom, 0, GKYL_LOWER_EDGE, nghost, + ten_moment_transmissive_bc, 0); + pdata->lower_bc_maxwell[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->maxwell, pdata->geom, 0, GKYL_LOWER_EDGE, nghost, + maxwell_transmissive_bc, 0); + } + + if (conn->connections[0][1].edge == GKYL_PHYSICAL) { + pdata->upper_bc_elc[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->euler_elc, pdata->geom, 0, GKYL_UPPER_EDGE, nghost, + ten_moment_transmissive_bc, 0); + pdata->upper_bc_ion[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->euler_ion, pdata->geom, 0, GKYL_UPPER_EDGE, nghost, + ten_moment_transmissive_bc, 0); + pdata->upper_bc_maxwell[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->maxwell, pdata->geom, 0, GKYL_UPPER_EDGE, nghost, + maxwell_transmissive_bc, 0); + } + + skin_ghost_ranges_init_patch(&pdata->skin_ghost, &pdata->ext_range, nghost); + long buff_sz = 0; + + long vol = pdata->skin_ghost.lower_skin[0].volume; + + if (buff_sz <= vol) { + buff_sz = vol; + } + + pdata->bc_buffer_elc = gkyl_array_new(GKYL_DOUBLE, 10, buff_sz); + pdata->bc_buffer_ion = gkyl_array_new(GKYL_DOUBLE, 10, buff_sz); + pdata->bc_buffer_maxwell = gkyl_array_new(GKYL_DOUBLE, 8, buff_sz); +} + void five_moment_patch_bc_updaters_release(struct five_moment_patch_data* pdata) { diff --git a/amr/gkyl_amr_core.h b/amr/gkyl_amr_core.h index 8e2c9aeb3..29258fc3c 100644 --- a/amr/gkyl_amr_core.h +++ b/amr/gkyl_amr_core.h @@ -416,6 +416,59 @@ struct ten_moment_1d_single_init { */ void ten_moment_1d_run_single(int argc, char **argv, struct ten_moment_1d_single_init* init); +// Initialization data for a 1D simulation using the coupled five-moment equations, run with static, patch-structured mesh refinement with a doubly-nested refinement patch. +struct five_moment_1d_double_init { + int base_Nx; + int ref_factor1; + int ref_factor2; + + double coarse_x1; + double coarse_x2; + + double intermediate_x1; + double intermediate_x2; + + double refined_x1; + double refined_x2; + + evalf_t eval_elc; + evalf_t eval_ion; + evalf_t eval_field; + + double gas_gamma; + double k0_elc; + double k0_ion; + + double light_speed; + double e_fact; + double b_fact; + + double epsilon0; + double mass_elc; + double charge_elc; + double mass_ion; + double charge_ion; + + char five_moment_output[32]; + + bool low_order_flux; + double cfl_frac; + + double t_end; + int num_frames; + double dt_failure_tol; + int num_failures_max; +}; + +/** +* Run a 1D simulation using the coupled five-moment equations, with static, patch-structured mesh refinement with a doubly-nested refinement patch. +* +* @param argc Number of command line arguments passed to the function. +* @param argv Array of command line arguments passed to the function. +* @param init Initialization data for the 1D coupled five-moment equations. +*/ +void five_moment_1d_run_double(int argc, char **argv, struct five_moment_1d_double_init* init); + // Initialization data for a 2D simulation using the coupled five-moment equations, run with static, block-structured mesh refinement with a single refinement patch. struct five_moment_2d_single_init { int base_Nx; diff --git a/amr/gkyl_amr_patch_coupled_priv.h b/amr/gkyl_amr_patch_coupled_priv.h index 9b757f807..d03b475d7 100644 --- a/amr/gkyl_amr_patch_coupled_priv.h +++ b/amr/gkyl_amr_patch_coupled_priv.h @@ -86,6 +86,14 @@ struct five_moment_update_patch_ctx { */ void five_moment_patch_bc_updaters_init(struct five_moment_patch_data* pdata, const struct gkyl_block_connections* conn); +/** +* Initialize nested patch AMR updaters for both physical (outer-patch) and non-physical (inter-patch) boundary conditions for the coupled five-moment equations. +* +* @param pdata Patch-structured data for the coupled five-moment equations. +* @param conn Topology/connectivity data for the patch hierarchy. +*/ +void five_moment_nested_patch_bc_updaters_init(struct five_moment_patch_data* pdata, const struct gkyl_block_connections* conn); + /** * Initialize patch AMR updaters for both physical (outer-patch) and non-physical (inter-patch) boundary conditions for the coupled ten-moment equations. * @@ -94,6 +102,14 @@ void five_moment_patch_bc_updaters_init(struct five_moment_patch_data* pdata, co */ void ten_moment_patch_bc_updaters_init(struct five_moment_patch_data* pdata, const struct gkyl_block_connections* conn); +/** +* Initialize nested patch AMR updaters for both physical (outer-patch) and non-physical (inter-patch) boundary conditions for the coupled ten-moment equations. +* +* @param pdata Patch-structured data for the coupled ten-moment equations. +* @param conn Topology/connectivity data for the patch hierarchy. +*/ +void ten_moment_nested_patch_bc_updaters_init(struct five_moment_patch_data* pdata, const struct gkyl_block_connections* conn); + /** * Release patch AMR updaters for both physical (outer-patch) and non-physical (inter-patch) boundary conditions for the coupled five-moment equations. * diff --git a/regression/rt_amr_5m_riem.c b/regression/rt_amr_5m_riem_l1.c similarity index 99% rename from regression/rt_amr_5m_riem.c rename to regression/rt_amr_5m_riem_l1.c index b8890fe47..625c3abf5 100644 --- a/regression/rt_amr_5m_riem.c +++ b/regression/rt_amr_5m_riem_l1.c @@ -256,7 +256,7 @@ int main(int argc, char **argv) .mass_ion = ctx.mass_ion, .charge_ion = ctx.charge_ion, - .five_moment_output = "amr_5m_riem", + .five_moment_output = "amr_5m_riem_l1", .low_order_flux = false, .cfl_frac = ctx.cfl_frac, diff --git a/regression/rt_amr_5m_riem_l2.c b/regression/rt_amr_5m_riem_l2.c new file mode 100644 index 000000000..d7daa905f --- /dev/null +++ b/regression/rt_amr_5m_riem_l2.c @@ -0,0 +1,281 @@ +// Generalized Brio-Wu Riemann problem, using static, patch-structured mesh refinement with doubly-nested refinement patches (4x4x refinement), for the 5-moment equations. +// Input parameters match the initial conditions found in entry JE4 of Ammar's Simulation Journal (https://ammar-hakim.org/sj/je/je4/je4-twofluid-shock.html), adapted from Section 7.1 of the article: +// A. Hakim, J. Loverich and U. Shumlak (2006), "A high resolution wave propagation scheme for ideal Two-Fluid plasma equations", +// Journal of Computational Physics, Volume 219 (1): 418-442. +// https://www.sciencedirect.com/science/article/pii/S0021999106001707 + +#include + +struct amr_5m_riem_ctx +{ + // Physical constants (using normalized code units). + double gas_gamma; // Adiabatic index. + double epsilon0; // Permittivity of free space. + double mu0; // Permeability of free space. + double mass_ion; // Proton mass. + double charge_ion; // Proton charge. + double mass_elc; // Electron mass. + double charge_elc; // Electron charge. + + double rhol_ion; // Left ion mass density. + double rhor_ion; // Right ion mass density; + double pl; // Left electron/ion pressure. + double pr; // Right electron/ion pressure. + + double Bx; // Total magnetic field (x-direction). + double Bzl; // Left total magneic field (z-direction). + double Bzr; // Right total magnetic field (z-direction). + + bool has_collision; // Whether to include collisions. + double nu_base_ei; // Base electron-ion collision frequency. + + double k0_elc; // Electron closure parameter. + double k0_ion; // Ion closure parameter. + + // Derived physical quantities (using normalized code units). + double rhol_elc; // Left electron mass density. + double rhor_elc; // Right electron mass density. + + // Simulation parameters. + int Nx; // Coarse cell count (x-direction). + int ref_factor1; // First refinement factor (coarse-to-intermediate). + int ref_factor2; // Second refinement factor (intermediate-to-fine). + double Lx; // Coarse domain size (x-direction). + double intermediate_Lx; // Intermediate domain size (x-direction). + double fine_Lx; // Fine domain size (x-direction). + double cfl_frac; // CFL coefficient. + + double t_end; // Final simulation time. + int num_frames; // Number of output frames. + double dt_failure_tol; // Minimum allowable fraction of initial time-step. + int num_failures_max; // Maximum allowable number of consecutive small time-steps. +}; + +struct amr_5m_riem_ctx +create_ctx(void) +{ + // Physical constants (using normalized code units). + double gas_gamma = 5.0 / 3.0; // Adiabatic index. + double epsilon0 = 1.0; // Permittivity of free space. + double mu0 = 1.0; // Permeability of free space. + double mass_ion = 1.0; // Proton mass. + double charge_ion = 1.0; // Proton charge. + double mass_elc = 1.0 / 1836.2; // Electron mass. + double charge_elc = -1.0; // Electron charge. + + double rhol_ion = 1.0; // Left ion mass density. + double rhor_ion = 0.125; // Right ion mass density; + double pl = 5.0e-5; // Left electron/ion pressure. + double pr = 5.0e-6; // Right electron/ion pressure. + + double Bx = 0.75e-2; // Total magnetic field (x-direction). + double Bzl = 1.0e-2; // Left total magneic field (z-direction). + double Bzr = -1.0e-2; // Right total magnetic field (z-direction). + + bool has_collision = false; // Whether to include collisions. + double nu_base_ei = 0.5; // Base electron-ion collision frequency. + + double k0_elc = 0.0; // Electron closure parameter. + double k0_ion = 0.0; // Ion closure parameter. + + // Derived physical quantities (using normalized code units). + double rhol_elc = rhol_ion * mass_elc / mass_ion; // Left electron mass density. + double rhor_elc = rhor_ion * mass_elc / mass_ion; // Right electron mass density. + + // Simulation parameters. + int Nx = 32; // Coarse cell count (x-direction). + int ref_factor1 = 4; // First refinement factor (coarse-to-intermediate). + int ref_factor2 = 4; // Second refinement factor (intermediate-to-fine). + double Lx = 1.0; // Coarse domain size (x-direction). + double intermediate_Lx = 0.4; // Intermediate domain size (x-direction). + double fine_Lx = 0.2; // Fine domain size (x-direction). + double cfl_frac = 0.95; // CFL coefficient. + + double t_end = 10.0; // Final simulation time. + int num_frames = 1; // Number of output frames. + double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. + int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. + + struct amr_5m_riem_ctx ctx = { + .gas_gamma = gas_gamma, + .epsilon0 = epsilon0, + .mu0 = mu0, + .mass_ion = mass_ion, + .charge_ion = charge_ion, + .mass_elc = mass_elc, + .charge_elc = charge_elc, + .rhol_ion = rhol_ion, + .rhor_ion = rhor_ion, + .pl = pl, + .pr = pr, + .Bx = Bx, + .Bzl = Bzl, + .Bzr = Bzr, + .has_collision = has_collision, + .nu_base_ei = nu_base_ei, + .k0_elc = k0_elc, + .k0_ion = k0_ion, + .rhol_elc = rhol_elc, + .rhor_elc = rhor_elc, + .Nx = Nx, + .ref_factor1 = ref_factor1, + .ref_factor2 = ref_factor2, + .Lx = Lx, + .intermediate_Lx = intermediate_Lx, + .fine_Lx = fine_Lx, + .cfl_frac = cfl_frac, + .t_end = t_end, + .num_frames = num_frames, + .dt_failure_tol = dt_failure_tol, + .num_failures_max = num_failures_max, + }; + + return ctx; +} + +void +evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +{ + double x = xn[0]; + struct amr_5m_riem_ctx new_ctx = create_ctx(); // Context for initialization functions. + struct amr_5m_riem_ctx *app = &new_ctx; + + double gas_gamma = app->gas_gamma; + + double pl = app->pl; + double pr = app->pr; + + double rhol_elc = app->rhol_elc; + double rhor_elc = app->rhor_elc; + + double rho = 0.0; + double p = 0.0; + + if (x < 0.5) { + rho = rhol_elc; // Electron mass density (left). + p = pl; // Electron pressure (left). + } + else { + rho = rhor_elc; // Electron mass density (right). + p = pr; // Electron pressure (right). + } + + // Set electron mass density. + fout[0] = rho; + // Set electron momentum density. + fout[1] = 0.0; fout[2] = 0.0; fout[3] = 0.0; + // Set electron total energy density. + fout[4] = p / (gas_gamma - 1.0); +} + +void +evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +{ + double x = xn[0]; + struct amr_5m_riem_ctx new_ctx = create_ctx(); // Context for initialization functions. + struct amr_5m_riem_ctx *app = &new_ctx; + + double gas_gamma = app->gas_gamma; + + double rhol_ion = app->rhol_ion; + double rhor_ion = app->rhor_ion; + double pl = app->pl; + double pr = app->pr; + + double rho = 0.0; + double p = 0.0; + + if (x < 0.5) { + rho = rhol_ion; // Ion mass density (left). + p = pl; // Ion pressure (left). + } + else { + rho = rhor_ion; // Ion mass density (right). + p = pr; // Ion pressure (right). + } + + // Set ion mass density. + fout[0] = rho; + // Set ion momentum density. + fout[1] = 0.0; fout[2] = 0.0; fout[3] = 0.0; + // Set ion total energy density. + fout[4] = p / (gas_gamma - 1.0); +} + +void +evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +{ + double x = xn[0]; + struct amr_5m_riem_ctx new_ctx = create_ctx(); // Context for initialization functions. + struct amr_5m_riem_ctx *app = &new_ctx; + + double Bx = app->Bx; + double Bzl = app->Bzl; + double Bzr = app->Bzr; + + double Bz = 0.0; + + if (x < 0.5) { + Bz = Bzl; // Total magnetic field (z-direction, left). + } + else { + Bz = Bzr; // Total magnetic field (z-direction, right). + } + + // Set electric field. + fout[0] = 0.0, fout[1] = 0.0; fout[2] = 0.0; + // Set magnetic field. + fout[3] = Bx, fout[4] = 0.0; fout[5] = Bz; + // Set correction potentials. + fout[6] = 0.0; fout[7] = 0.0; +} + +int main(int argc, char **argv) +{ + struct amr_5m_riem_ctx ctx = create_ctx(); // Context for initialization functions. + + struct five_moment_1d_double_init init = { + .base_Nx = ctx.Nx, + .ref_factor1 = ctx.ref_factor1, + .ref_factor2 = ctx.ref_factor2, + + .coarse_x1 = 0.0, + .coarse_x2 = ctx.Lx, + + .intermediate_x1 = (0.5 * ctx.Lx) - (0.5 * ctx.intermediate_Lx), + .intermediate_x2 = (0.5 * ctx.Lx) + (0.5 * ctx.intermediate_Lx), + + .refined_x1 = (0.5 * ctx.Lx) - (0.5 * ctx.fine_Lx), + .refined_x2 = (0.5 * ctx.Lx) + (0.5 * ctx.fine_Lx), + + .eval_elc = evalElcInit, + .eval_ion = evalIonInit, + .eval_field = evalFieldInit, + + .gas_gamma = ctx.gas_gamma, + .k0_elc = ctx.k0_elc, + .k0_ion = ctx.k0_ion, + + .light_speed = 1.0, + .e_fact = 0.0, + .b_fact = 1.0, + + .epsilon0 = ctx.epsilon0, + .mass_elc = ctx.mass_elc, + .charge_elc = ctx.charge_elc, + .mass_ion = ctx.mass_ion, + .charge_ion = ctx.charge_ion, + + .five_moment_output = "amr_5m_riem_l2", + + .low_order_flux = false, + .cfl_frac = ctx.cfl_frac, + + .t_end = ctx.t_end, + .num_frames = ctx.num_frames, + .dt_failure_tol = ctx.dt_failure_tol, + .num_failures_max = ctx.num_failures_max, + }; + + five_moment_1d_run_double(argc, argv, &init); +} \ No newline at end of file From eb299993f3ec01f58311d3e12deb2a2c93befb6b Mon Sep 17 00:00:00 2001 From: JonathanGorard Date: Thu, 27 Jun 2024 13:52:51 -0400 Subject: [PATCH 18/32] Further code cleanup (standardizing job pool naming conventions across all AMR core modules). --- amr/amr_core_euler.c | 40 +++++++++++++++++++------------------- amr/amr_core_five_moment.c | 40 +++++++++++++++++++------------------- amr/amr_core_gr_euler.c | 40 +++++++++++++++++++------------------- amr/amr_core_ten_moment.c | 30 ++++++++++++++-------------- 4 files changed, 75 insertions(+), 75 deletions(-) diff --git a/amr/amr_core_euler.c b/amr/amr_core_euler.c index a471705dc..85f0aeeed 100644 --- a/amr/amr_core_euler.c +++ b/amr/amr_core_euler.c @@ -42,7 +42,7 @@ euler1d_run_single(int argc, char **argv, struct euler1d_single_init* init) int Nx = base_Nx; struct euler_patch_data mesh_pdata[num_patches]; - struct gkyl_job_pool *coarse_job_pool = gkyl_thread_pool_new(app_args.num_threads); + struct gkyl_job_pool *mesh_job_pool = gkyl_thread_pool_new(app_args.num_threads); gkyl_rect_grid_init(&mesh_pdata[0].grid, 1, (double []) { refined_x1 }, (double []) { refined_x2 }, (int []) { Nx * ref_factor } ); @@ -99,9 +99,9 @@ euler1d_run_single(int argc, char **argv, struct euler1d_single_init* init) #ifdef AMR_USETHREADS for (int i = 0; i < num_patches; i++) { - gkyl_job_pool_add_work(coarse_job_pool, euler_init_job_func_patch, &mesh_pdata[i]); + gkyl_job_pool_add_work(mesh_job_pool, euler_init_job_func_patch, &mesh_pdata[i]); } - gkyl_job_pool_wait(coarse_job_pool); + gkyl_job_pool_wait(mesh_job_pool); #else for (int i = 0; i < num_patches; i++) { euler_init_job_func_patch(&mesh_pdata[i]); @@ -132,7 +132,7 @@ euler1d_run_single(int argc, char **argv, struct euler1d_single_init* init) while ((coarse_t_curr < t_end) && (coarse_step <= num_steps)) { printf("Taking coarse (level 0) time-step %ld at t = %g; ", coarse_step, coarse_t_curr); - struct gkyl_update_status coarse_status = euler_update_patch(coarse_job_pool, ptopo, mesh_pdata, coarse_t_curr, coarse_dt, &stats); + struct gkyl_update_status coarse_status = euler_update_patch(mesh_job_pool, ptopo, mesh_pdata, coarse_t_curr, coarse_dt, &stats); printf(" dt = %g\n", coarse_status.dt_actual); if (!coarse_status.success) { @@ -203,7 +203,7 @@ euler1d_run_single(int argc, char **argv, struct euler1d_single_init* init) } gkyl_block_topo_release(ptopo); - gkyl_job_pool_release(coarse_job_pool); + gkyl_job_pool_release(mesh_job_pool); } void @@ -248,7 +248,7 @@ euler1d_run_double(int argc, char **argv, struct euler1d_double_init* init) int Nx = base_Nx; struct euler_patch_data mesh_pdata[num_patches]; - struct gkyl_job_pool *coarse_job_pool = gkyl_thread_pool_new(app_args.num_threads); + struct gkyl_job_pool *mesh_job_pool = gkyl_thread_pool_new(app_args.num_threads); gkyl_rect_grid_init(&mesh_pdata[0].grid, 1, (double []) { refined_x1 }, (double []) { refined_x2 }, (int []) { Nx * (ref_factor1 * ref_factor2) } ); @@ -308,9 +308,9 @@ euler1d_run_double(int argc, char **argv, struct euler1d_double_init* init) #ifdef AMR_USETHREADS for (int i = 0; i < num_patches; i++) { - gkyl_job_pool_add_work(coarse_job_pool, euler_init_job_func_patch, &mesh_pdata[i]); + gkyl_job_pool_add_work(mesh_job_pool, euler_init_job_func_patch, &mesh_pdata[i]); } - gkyl_job_pool_wait(coarse_job_pool); + gkyl_job_pool_wait(mesh_job_pool); #else for (int i = 0; i < num_patches; i++) { euler_init_job_func_patch(&mesh_pdata[i]); @@ -343,7 +343,7 @@ euler1d_run_double(int argc, char **argv, struct euler1d_double_init* init) while ((coarse_t_curr < t_end) && (coarse_step <= num_steps)) { printf("Taking coarse (level 0) time-step %ld at t = %g; ", coarse_step, coarse_t_curr); - struct gkyl_update_status coarse_status = euler_update_patch(coarse_job_pool, ptopo, mesh_pdata, coarse_t_curr, coarse_dt, &stats); + struct gkyl_update_status coarse_status = euler_update_patch(mesh_job_pool, ptopo, mesh_pdata, coarse_t_curr, coarse_dt, &stats); printf(" dt = %g\n", coarse_status.dt_actual); if (!coarse_status.success) { @@ -422,7 +422,7 @@ euler1d_run_double(int argc, char **argv, struct euler1d_double_init* init) } gkyl_block_topo_release(ptopo); - gkyl_job_pool_release(coarse_job_pool); + gkyl_job_pool_release(mesh_job_pool); } void @@ -469,7 +469,7 @@ euler2d_run_single(int argc, char **argv, struct euler2d_single_init* init) int Ny = base_Ny; struct euler_block_data mesh_bdata[num_blocks]; - struct gkyl_job_pool *coarse_job_pool = gkyl_thread_pool_new(app_args.num_threads); + struct gkyl_job_pool *mesh_job_pool = gkyl_thread_pool_new(app_args.num_threads); gkyl_rect_grid_init(&mesh_bdata[0].grid, 2, (double []) { refined_x1, refined_y1 }, (double []) { refined_x2, refined_y2 }, (int []) { Nx * ref_factor, Ny * ref_factor }); @@ -543,9 +543,9 @@ euler2d_run_single(int argc, char **argv, struct euler2d_single_init* init) #ifdef AMR_USETHREADS for (int i = 0; i < num_blocks; i++) { - gkyl_job_pool_add_work(coarse_job_pool, euler_init_job_func_block, &mesh_bdata[i]); + gkyl_job_pool_add_work(mesh_job_pool, euler_init_job_func_block, &mesh_bdata[i]); } - gkyl_job_pool_wait(coarse_job_pool); + gkyl_job_pool_wait(mesh_job_pool); #else for (int i = 0; i < num_blocks; i++) { euler_init_job_func_block(&mesh_bdata[i]); @@ -576,7 +576,7 @@ euler2d_run_single(int argc, char **argv, struct euler2d_single_init* init) while ((coarse_t_curr < t_end) && (coarse_step <= num_steps)) { printf("Taking coarse (level 0) time-step %ld at t = %g; ", coarse_step, coarse_t_curr); - struct gkyl_update_status coarse_status = euler_update_block(coarse_job_pool, btopo, mesh_bdata, coarse_t_curr, coarse_dt, &stats); + struct gkyl_update_status coarse_status = euler_update_block(mesh_job_pool, btopo, mesh_bdata, coarse_t_curr, coarse_dt, &stats); printf(" dt = %g\n", coarse_status.dt_actual); if (!coarse_status.success) { @@ -653,7 +653,7 @@ euler2d_run_single(int argc, char **argv, struct euler2d_single_init* init) } gkyl_block_topo_release(btopo); - gkyl_job_pool_release(coarse_job_pool); + gkyl_job_pool_release(mesh_job_pool); } void @@ -706,7 +706,7 @@ euler2d_run_double(int argc, char **argv, struct euler2d_double_init* init) int Ny = base_Ny; struct euler_block_data mesh_bdata[num_blocks]; - struct gkyl_job_pool *coarse_job_pool = gkyl_thread_pool_new(app_args.num_threads); + struct gkyl_job_pool *mesh_job_pool = gkyl_thread_pool_new(app_args.num_threads); gkyl_rect_grid_init(&mesh_bdata[0].grid, 2, (double []) { refined_x1, refined_y1 }, (double []) { refined_x2, refined_y2 }, (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); @@ -813,9 +813,9 @@ euler2d_run_double(int argc, char **argv, struct euler2d_double_init* init) #ifdef AMR_USETHREADS for (int i = 0; i < num_blocks; i++) { - gkyl_job_pool_add_work(coarse_job_pool, euler_init_job_func_block, &mesh_bdata[i]); + gkyl_job_pool_add_work(mesh_job_pool, euler_init_job_func_block, &mesh_bdata[i]); } - gkyl_job_pool_wait(coarse_job_pool); + gkyl_job_pool_wait(mesh_job_pool); #else for (int i = 0; i < num_blocks; i++) { euler_init_job_func_block(&mesh_bdata[i]); @@ -848,7 +848,7 @@ euler2d_run_double(int argc, char **argv, struct euler2d_double_init* init) while ((coarse_t_curr < t_end) && (coarse_step <= num_steps)) { printf("Taking coarse (level 0) time-step %ld at t = %g; ", coarse_step, coarse_t_curr); - struct gkyl_update_status coarse_status = euler_update_block(coarse_job_pool, btopo, mesh_bdata, coarse_t_curr, coarse_dt, &stats); + struct gkyl_update_status coarse_status = euler_update_block(mesh_job_pool, btopo, mesh_bdata, coarse_t_curr, coarse_dt, &stats); printf(" dt = %g\n", coarse_status.dt_actual); if (!coarse_status.success) { @@ -933,5 +933,5 @@ euler2d_run_double(int argc, char **argv, struct euler2d_double_init* init) } gkyl_block_topo_release(btopo); - gkyl_job_pool_release(coarse_job_pool); + gkyl_job_pool_release(mesh_job_pool); } \ No newline at end of file diff --git a/amr/amr_core_five_moment.c b/amr/amr_core_five_moment.c index 80a2c3c92..c043e539c 100644 --- a/amr/amr_core_five_moment.c +++ b/amr/amr_core_five_moment.c @@ -57,7 +57,7 @@ five_moment_1d_run_single(int argc, char **argv, struct five_moment_1d_single_in int Nx = base_Nx; struct five_moment_patch_data mesh_pdata[num_patches]; - struct gkyl_job_pool *coarse_job_pool = gkyl_thread_pool_new(app_args.num_threads); + struct gkyl_job_pool *mesh_job_pool = gkyl_thread_pool_new(app_args.num_threads); gkyl_rect_grid_init(&mesh_pdata[0].grid, 1, (double []) { refined_x1 }, (double []) { refined_x2 }, (int []) { Nx * ref_factor } ); @@ -174,9 +174,9 @@ five_moment_1d_run_single(int argc, char **argv, struct five_moment_1d_single_in #ifdef AMR_USETHREADS for (int i = 0; i < num_patches; i++) { - gkyl_job_pool_add_work(coarse_job_pool, five_moment_init_job_func_patch, &mesh_pdata[i]); + gkyl_job_pool_add_work(mesh_job_pool, five_moment_init_job_func_patch, &mesh_pdata[i]); } - gkyl_job_pool_wait(coarse_job_pool); + gkyl_job_pool_wait(mesh_job_pool); #else for (int i = 0; i < num_patches; i++) { five_moment_init_job_func_patch(&mesh_pdata[i]); @@ -207,7 +207,7 @@ five_moment_1d_run_single(int argc, char **argv, struct five_moment_1d_single_in while ((coarse_t_curr < t_end) && (coarse_step <= num_steps)) { printf("Taking coarse (level 0) time-step %ld at t = %g; ", coarse_step, coarse_t_curr); - struct gkyl_update_status coarse_status = five_moment_update_patch(coarse_job_pool, ptopo, mesh_pdata, coarse_t_curr, coarse_dt, &stats); + struct gkyl_update_status coarse_status = five_moment_update_patch(mesh_job_pool, ptopo, mesh_pdata, coarse_t_curr, coarse_dt, &stats); printf(" dt = %g\n", coarse_status.dt_actual); if (!coarse_status.success) { @@ -300,7 +300,7 @@ five_moment_1d_run_single(int argc, char **argv, struct five_moment_1d_single_in } gkyl_block_topo_release(ptopo); - gkyl_job_pool_release(coarse_job_pool); + gkyl_job_pool_release(mesh_job_pool); } void @@ -360,7 +360,7 @@ five_moment_1d_run_double(int argc, char **argv, struct five_moment_1d_double_in int Nx = base_Nx; struct five_moment_patch_data mesh_pdata[num_patches]; - struct gkyl_job_pool *coarse_job_pool = gkyl_thread_pool_new(app_args.num_threads); + struct gkyl_job_pool *mesh_job_pool = gkyl_thread_pool_new(app_args.num_threads); gkyl_rect_grid_init(&mesh_pdata[0].grid, 1, (double []) { refined_x1 }, (double []) { refined_x2 }, (int []) { Nx * (ref_factor1 * ref_factor2) } ); @@ -479,9 +479,9 @@ five_moment_1d_run_double(int argc, char **argv, struct five_moment_1d_double_in #ifdef AMR_USETHREADS for (int i = 0; i < num_patches; i++) { - gkyl_job_pool_add_work(coarse_job_pool, five_moment_init_job_func_patch, &mesh_pdata[i]); + gkyl_job_pool_add_work(mesh_job_pool, five_moment_init_job_func_patch, &mesh_pdata[i]); } - gkyl_job_pool_wait(coarse_job_pool); + gkyl_job_pool_wait(mesh_job_pool); #else for (int i = 0; i < num_patches; i++) { five_moment_init_job_func_patch(&mesh_pdata[i]); @@ -514,7 +514,7 @@ five_moment_1d_run_double(int argc, char **argv, struct five_moment_1d_double_in while ((coarse_t_curr < t_end) && (coarse_step <= num_steps)) { printf("Taking coarse (level 0) time-step %ld at t = %g; ", coarse_step, coarse_t_curr); - struct gkyl_update_status coarse_status = five_moment_update_patch(coarse_job_pool, ptopo, mesh_pdata, coarse_t_curr, coarse_dt, &stats); + struct gkyl_update_status coarse_status = five_moment_update_patch(mesh_job_pool, ptopo, mesh_pdata, coarse_t_curr, coarse_dt, &stats); printf(" dt = %g\n", coarse_status.dt_actual); if (!coarse_status.success) { @@ -615,7 +615,7 @@ five_moment_1d_run_double(int argc, char **argv, struct five_moment_1d_double_in } gkyl_block_topo_release(ptopo); - gkyl_job_pool_release(coarse_job_pool); + gkyl_job_pool_release(mesh_job_pool); } void @@ -683,7 +683,7 @@ five_moment_2d_run_single(int argc, char **argv, struct five_moment_2d_single_in int Ny = base_Ny; struct five_moment_block_data mesh_bdata[num_blocks]; - struct gkyl_job_pool *coarse_job_pool = gkyl_thread_pool_new(app_args.num_threads); + struct gkyl_job_pool *mesh_job_pool = gkyl_thread_pool_new(app_args.num_threads); gkyl_rect_grid_init(&mesh_bdata[0].grid, 2, (double []) { refined_x1, refined_y1 }, (double []) { refined_x2, refined_y2 }, (int []) { Nx * ref_factor, Ny * ref_factor }); @@ -822,9 +822,9 @@ five_moment_2d_run_single(int argc, char **argv, struct five_moment_2d_single_in #ifdef AMR_USETHREADS for (int i = 0; i < num_blocks; i++) { - gkyl_job_pool_add_work(coarse_job_pool, five_moment_init_job_func_block, &mesh_bdata[i]); + gkyl_job_pool_add_work(mesh_job_pool, five_moment_init_job_func_block, &mesh_bdata[i]); } - gkyl_job_pool_wait(coarse_job_pool); + gkyl_job_pool_wait(mesh_job_pool); #else for (int i = 0; i < num_blocks; i++) { five_moment_init_job_func_block(&mesh_bdata[i]); @@ -855,7 +855,7 @@ five_moment_2d_run_single(int argc, char **argv, struct five_moment_2d_single_in while ((coarse_t_curr < t_end) && (coarse_step <= num_steps)) { printf("Taking coarse (level 0) time-step %ld at t = %g; ", coarse_step, coarse_t_curr); - struct gkyl_update_status coarse_status = five_moment_update_block(coarse_job_pool, btopo, mesh_bdata, coarse_t_curr, coarse_dt, &stats); + struct gkyl_update_status coarse_status = five_moment_update_block(mesh_job_pool, btopo, mesh_bdata, coarse_t_curr, coarse_dt, &stats); printf(" dt = %g\n", coarse_status.dt_actual); if (!coarse_status.success) { @@ -953,7 +953,7 @@ five_moment_2d_run_single(int argc, char **argv, struct five_moment_2d_single_in } gkyl_block_topo_release(btopo); - gkyl_job_pool_release(coarse_job_pool); + gkyl_job_pool_release(mesh_job_pool); } void @@ -1027,7 +1027,7 @@ five_moment_2d_run_double(int argc, char **argv, struct five_moment_2d_double_in int Ny = base_Ny; struct five_moment_block_data mesh_bdata[num_blocks]; - struct gkyl_job_pool *coarse_job_pool = gkyl_thread_pool_new(app_args.num_threads); + struct gkyl_job_pool *mesh_job_pool = gkyl_thread_pool_new(app_args.num_threads); gkyl_rect_grid_init(&mesh_bdata[0].grid, 2, (double []) { refined_x1, refined_y1 }, (double []) { refined_x2, refined_y2 }, (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); @@ -1199,9 +1199,9 @@ five_moment_2d_run_double(int argc, char **argv, struct five_moment_2d_double_in #ifdef AMR_USETHREADS for (int i = 0; i < num_blocks; i++) { - gkyl_job_pool_add_work(coarse_job_pool, five_moment_init_job_func_block, &mesh_bdata[i]); + gkyl_job_pool_add_work(mesh_job_pool, five_moment_init_job_func_block, &mesh_bdata[i]); } - gkyl_job_pool_wait(coarse_job_pool); + gkyl_job_pool_wait(mesh_job_pool); #else for (int i = 0; i < num_blocks; i++) { five_moment_init_job_func_block(&mesh_bdata[i]); @@ -1234,7 +1234,7 @@ five_moment_2d_run_double(int argc, char **argv, struct five_moment_2d_double_in while ((coarse_t_curr < t_end) && (coarse_step <= num_steps)) { printf("Taking coarse (level 0) time-step %ld at t = %g; ", coarse_step, coarse_t_curr); - struct gkyl_update_status coarse_status = five_moment_update_block(coarse_job_pool, btopo, mesh_bdata, coarse_t_curr, coarse_dt, &stats); + struct gkyl_update_status coarse_status = five_moment_update_block(mesh_job_pool, btopo, mesh_bdata, coarse_t_curr, coarse_dt, &stats); printf(" dt = %g\n", coarse_status.dt_actual); if (!coarse_status.success) { @@ -1340,5 +1340,5 @@ five_moment_2d_run_double(int argc, char **argv, struct five_moment_2d_double_in } gkyl_block_topo_release(btopo); - gkyl_job_pool_release(coarse_job_pool); + gkyl_job_pool_release(mesh_job_pool); } \ No newline at end of file diff --git a/amr/amr_core_gr_euler.c b/amr/amr_core_gr_euler.c index f99c9016d..0bcf58408 100644 --- a/amr/amr_core_gr_euler.c +++ b/amr/amr_core_gr_euler.c @@ -43,7 +43,7 @@ gr_euler1d_run_single(int argc, char **argv, struct gr_euler1d_single_init* init int Nx = base_Nx; struct euler_patch_data mesh_pdata[num_patches]; - struct gkyl_job_pool *coarse_job_pool = gkyl_thread_pool_new(app_args.num_threads); + struct gkyl_job_pool *mesh_job_pool = gkyl_thread_pool_new(app_args.num_threads); gkyl_rect_grid_init(&mesh_pdata[0].grid, 1, (double []) { refined_x1 }, (double []) { refined_x2 }, (int []) { Nx * ref_factor } ); @@ -90,9 +90,9 @@ gr_euler1d_run_single(int argc, char **argv, struct gr_euler1d_single_init* init #ifdef AMR_USETHREADS for (int i = 0; i < num_patches; i++) { - gkyl_job_pool_add_work(coarse_job_pool, euler_init_job_func_patch, &mesh_pdata[i]); + gkyl_job_pool_add_work(mesh_job_pool, euler_init_job_func_patch, &mesh_pdata[i]); } - gkyl_job_pool_wait(coarse_job_pool); + gkyl_job_pool_wait(mesh_job_pool); #else for (int i = 0; i < num_patches; i++) { euler_init_job_func_patch(&mesh_pdata[i]); @@ -123,7 +123,7 @@ gr_euler1d_run_single(int argc, char **argv, struct gr_euler1d_single_init* init while ((coarse_t_curr < t_end) && (coarse_step <= num_steps)) { printf("Taking coarse (level 0) time-step %ld at t = %g; ", coarse_step, coarse_t_curr); - struct gkyl_update_status coarse_status = euler_update_patch(coarse_job_pool, ptopo, mesh_pdata, coarse_t_curr, coarse_dt, &stats); + struct gkyl_update_status coarse_status = euler_update_patch(mesh_job_pool, ptopo, mesh_pdata, coarse_t_curr, coarse_dt, &stats); printf(" dt = %g\n", coarse_status.dt_actual); if (!coarse_status.success) { @@ -195,7 +195,7 @@ gr_euler1d_run_single(int argc, char **argv, struct gr_euler1d_single_init* init gkyl_block_topo_release(ptopo); gkyl_gr_spacetime_release(spacetime); - gkyl_job_pool_release(coarse_job_pool); + gkyl_job_pool_release(mesh_job_pool); } void @@ -241,7 +241,7 @@ gr_euler1d_run_double(int argc, char **argv, struct gr_euler1d_double_init* init int Nx = base_Nx; struct euler_patch_data mesh_pdata[num_patches]; - struct gkyl_job_pool *coarse_job_pool = gkyl_thread_pool_new(app_args.num_threads); + struct gkyl_job_pool *mesh_job_pool = gkyl_thread_pool_new(app_args.num_threads); gkyl_rect_grid_init(&mesh_pdata[0].grid, 1, (double []) { refined_x1 }, (double []) { refined_x2 }, (int []) { Nx * (ref_factor1 * ref_factor2) } ); @@ -291,9 +291,9 @@ gr_euler1d_run_double(int argc, char **argv, struct gr_euler1d_double_init* init #ifdef AMR_USETHREADS for (int i = 0; i < num_patches; i++) { - gkyl_job_pool_add_work(coarse_job_pool, euler_init_job_func_patch, &mesh_pdata[i]); + gkyl_job_pool_add_work(mesh_job_pool, euler_init_job_func_patch, &mesh_pdata[i]); } - gkyl_job_pool_wait(coarse_job_pool); + gkyl_job_pool_wait(mesh_job_pool); #else for (int i = 0; i < num_patches; i++) { euler_init_job_func_patch(&mesh_pdata[i]); @@ -326,7 +326,7 @@ gr_euler1d_run_double(int argc, char **argv, struct gr_euler1d_double_init* init while ((coarse_t_curr < t_end) && (coarse_step <= num_steps)) { printf("Taking coarse (level 0) time-step %ld at t = %g; ", coarse_step, coarse_t_curr); - struct gkyl_update_status coarse_status = euler_update_patch(coarse_job_pool, ptopo, mesh_pdata, coarse_t_curr, coarse_dt, &stats); + struct gkyl_update_status coarse_status = euler_update_patch(mesh_job_pool, ptopo, mesh_pdata, coarse_t_curr, coarse_dt, &stats); printf(" dt = %g\n", coarse_status.dt_actual); if (!coarse_status.success) { @@ -406,7 +406,7 @@ gr_euler1d_run_double(int argc, char **argv, struct gr_euler1d_double_init* init gkyl_block_topo_release(ptopo); gkyl_gr_spacetime_release(spacetime); - gkyl_job_pool_release(coarse_job_pool); + gkyl_job_pool_release(mesh_job_pool); } void @@ -454,7 +454,7 @@ gr_euler2d_run_single(int argc, char **argv, struct gr_euler2d_single_init* init int Ny = base_Ny; struct euler_block_data mesh_bdata[num_blocks]; - struct gkyl_job_pool *coarse_job_pool = gkyl_thread_pool_new(app_args.num_threads); + struct gkyl_job_pool *mesh_job_pool = gkyl_thread_pool_new(app_args.num_threads); gkyl_rect_grid_init(&mesh_bdata[0].grid, 2, (double []) { refined_x1, refined_y1 }, (double []) { refined_x2, refined_y2 }, (int []) { Nx * ref_factor, Ny * ref_factor }); @@ -518,9 +518,9 @@ gr_euler2d_run_single(int argc, char **argv, struct gr_euler2d_single_init* init #ifdef AMR_USETHREADS for (int i = 0; i < num_blocks; i++) { - gkyl_job_pool_add_work(coarse_job_pool, euler_init_job_func_block, &mesh_bdata[i]); + gkyl_job_pool_add_work(mesh_job_pool, euler_init_job_func_block, &mesh_bdata[i]); } - gkyl_job_pool_wait(coarse_job_pool); + gkyl_job_pool_wait(mesh_job_pool); #else for (int i = 0; i < num_blocks; i++) { euler_init_job_func_block(&mesh_bdata[i]); @@ -551,7 +551,7 @@ gr_euler2d_run_single(int argc, char **argv, struct gr_euler2d_single_init* init while ((coarse_t_curr < t_end) && (coarse_step <= num_steps)) { printf("Taking coarse (level 0) time-step %ld at t = %g; ", coarse_step, coarse_t_curr); - struct gkyl_update_status coarse_status = euler_update_block(coarse_job_pool, btopo, mesh_bdata, coarse_t_curr, coarse_dt, &stats); + struct gkyl_update_status coarse_status = euler_update_block(mesh_job_pool, btopo, mesh_bdata, coarse_t_curr, coarse_dt, &stats); printf(" dt = %g\n", coarse_status.dt_actual); if (!coarse_status.success) { @@ -629,7 +629,7 @@ gr_euler2d_run_single(int argc, char **argv, struct gr_euler2d_single_init* init gkyl_block_topo_release(btopo); gkyl_gr_spacetime_release(spacetime); - gkyl_job_pool_release(coarse_job_pool); + gkyl_job_pool_release(mesh_job_pool); } void @@ -683,7 +683,7 @@ gr_euler2d_run_double(int argc, char **argv, struct gr_euler2d_double_init* init int Ny = base_Ny; struct euler_block_data mesh_bdata[num_blocks]; - struct gkyl_job_pool *coarse_job_pool = gkyl_thread_pool_new(app_args.num_threads); + struct gkyl_job_pool *mesh_job_pool = gkyl_thread_pool_new(app_args.num_threads); gkyl_rect_grid_init(&mesh_bdata[0].grid, 2, (double []) { refined_x1, refined_y1 }, (double []) { refined_x2, refined_y2 }, (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); @@ -780,9 +780,9 @@ gr_euler2d_run_double(int argc, char **argv, struct gr_euler2d_double_init* init #ifdef AMR_USETHREADS for (int i = 0; i < num_blocks; i++) { - gkyl_job_pool_add_work(coarse_job_pool, euler_init_job_func_block, &mesh_bdata[i]); + gkyl_job_pool_add_work(mesh_job_pool, euler_init_job_func_block, &mesh_bdata[i]); } - gkyl_job_pool_wait(coarse_job_pool); + gkyl_job_pool_wait(mesh_job_pool); #else for (int i = 0; i < num_blocks; i++) { euler_init_job_func_block(&mesh_bdata[i]); @@ -815,7 +815,7 @@ gr_euler2d_run_double(int argc, char **argv, struct gr_euler2d_double_init* init while ((coarse_t_curr < t_end) && (coarse_step <= num_steps)) { printf("Taking coarse (level 0) time-step %ld at t = %g; ", coarse_step, coarse_t_curr); - struct gkyl_update_status coarse_status = euler_update_block(coarse_job_pool, btopo, mesh_bdata, coarse_t_curr, coarse_dt, &stats); + struct gkyl_update_status coarse_status = euler_update_block(mesh_job_pool, btopo, mesh_bdata, coarse_t_curr, coarse_dt, &stats); printf(" dt = %g\n", coarse_status.dt_actual); if (!coarse_status.success) { @@ -901,5 +901,5 @@ gr_euler2d_run_double(int argc, char **argv, struct gr_euler2d_double_init* init gkyl_block_topo_release(btopo); gkyl_gr_spacetime_release(spacetime); - gkyl_job_pool_release(coarse_job_pool); + gkyl_job_pool_release(mesh_job_pool); } \ No newline at end of file diff --git a/amr/amr_core_ten_moment.c b/amr/amr_core_ten_moment.c index 39a48f71e..71cfcd2de 100644 --- a/amr/amr_core_ten_moment.c +++ b/amr/amr_core_ten_moment.c @@ -56,7 +56,7 @@ ten_moment_1d_run_single(int argc, char **argv, struct ten_moment_1d_single_init int Nx = base_Nx; struct five_moment_patch_data mesh_pdata[num_patches]; - struct gkyl_job_pool *coarse_job_pool = gkyl_thread_pool_new(app_args.num_threads); + struct gkyl_job_pool *mesh_job_pool = gkyl_thread_pool_new(app_args.num_threads); gkyl_rect_grid_init(&mesh_pdata[0].grid, 1, (double []) { refined_x1 }, (double []) { refined_x2 }, (int []) { Nx * ref_factor } ); @@ -161,9 +161,9 @@ ten_moment_1d_run_single(int argc, char **argv, struct ten_moment_1d_single_init #ifdef AMR_USETHREADS for (int i = 0; i < num_patches; i++) { - gkyl_job_pool_add_work(coarse_job_pool, five_moment_init_job_func_patch, &mesh_pdata[i]); + gkyl_job_pool_add_work(mesh_job_pool, five_moment_init_job_func_patch, &mesh_pdata[i]); } - gkyl_job_pool_wait(coarse_job_pool); + gkyl_job_pool_wait(mesh_job_pool); #else for (int i = 0; i < num_patches; i++) { five_moment_init_job_func_patch(&mesh_pdata[i]); @@ -194,7 +194,7 @@ ten_moment_1d_run_single(int argc, char **argv, struct ten_moment_1d_single_init while ((coarse_t_curr < t_end) && (coarse_step <= num_steps)) { printf("Taking coarse (level 0) time-step %ld at t = %g; ", coarse_step, coarse_t_curr); - struct gkyl_update_status coarse_status = five_moment_update_patch(coarse_job_pool, ptopo, mesh_pdata, coarse_t_curr, coarse_dt, &stats); + struct gkyl_update_status coarse_status = five_moment_update_patch(mesh_job_pool, ptopo, mesh_pdata, coarse_t_curr, coarse_dt, &stats); printf(" dt = %g\n", coarse_status.dt_actual); if (!coarse_status.success) { @@ -287,7 +287,7 @@ ten_moment_1d_run_single(int argc, char **argv, struct ten_moment_1d_single_init } gkyl_block_topo_release(ptopo); - gkyl_job_pool_release(coarse_job_pool); + gkyl_job_pool_release(mesh_job_pool); } void @@ -354,7 +354,7 @@ ten_moment_2d_run_single(int argc, char **argv, struct ten_moment_2d_single_init int Ny = base_Ny; struct five_moment_block_data mesh_bdata[num_blocks]; - struct gkyl_job_pool *coarse_job_pool = gkyl_thread_pool_new(app_args.num_threads); + struct gkyl_job_pool *mesh_job_pool = gkyl_thread_pool_new(app_args.num_threads); gkyl_rect_grid_init(&mesh_bdata[0].grid, 2, (double []) { refined_x1, refined_y1 }, (double []) { refined_x2, refined_y2 }, (int []) { Nx * ref_factor, Ny * ref_factor }); @@ -482,9 +482,9 @@ ten_moment_2d_run_single(int argc, char **argv, struct ten_moment_2d_single_init #ifdef AMR_USETHREADS for (int i = 0; i < num_blocks; i++) { - gkyl_job_pool_add_work(coarse_job_pool, five_moment_init_job_func_block, &mesh_bdata[i]); + gkyl_job_pool_add_work(mesh_job_pool, five_moment_init_job_func_block, &mesh_bdata[i]); } - gkyl_job_pool_wait(coarse_job_pool); + gkyl_job_pool_wait(mesh_job_pool); #else for (int i = 0; i < num_blocks; i++) { five_moment_init_job_func_block(&mesh_bdata[i]); @@ -515,7 +515,7 @@ ten_moment_2d_run_single(int argc, char **argv, struct ten_moment_2d_single_init while ((coarse_t_curr < t_end) && (coarse_step <= num_steps)) { printf("Taking coarse (level 0) time-step %ld at t = %g; ", coarse_step, coarse_t_curr); - struct gkyl_update_status coarse_status = five_moment_update_block(coarse_job_pool, btopo, mesh_bdata, coarse_t_curr, coarse_dt, &stats); + struct gkyl_update_status coarse_status = five_moment_update_block(mesh_job_pool, btopo, mesh_bdata, coarse_t_curr, coarse_dt, &stats); printf(" dt = %g\n", coarse_status.dt_actual); if (!coarse_status.success) { @@ -613,7 +613,7 @@ ten_moment_2d_run_single(int argc, char **argv, struct ten_moment_2d_single_init } gkyl_block_topo_release(btopo); - gkyl_job_pool_release(coarse_job_pool); + gkyl_job_pool_release(mesh_job_pool); } void @@ -687,7 +687,7 @@ ten_moment_2d_run_double(int argc, char **argv, struct ten_moment_2d_double_init int Ny = base_Ny; struct five_moment_block_data mesh_bdata[num_blocks]; - struct gkyl_job_pool *coarse_job_pool = gkyl_thread_pool_new(app_args.num_threads); + struct gkyl_job_pool *mesh_job_pool = gkyl_thread_pool_new(app_args.num_threads); gkyl_rect_grid_init(&mesh_bdata[0].grid, 2, (double []) { refined_x1, refined_y1 }, (double []) { refined_x2, refined_y2 }, (int []) { Nx * (ref_factor1 * ref_factor2), Ny * (ref_factor1 * ref_factor2) }); @@ -848,9 +848,9 @@ ten_moment_2d_run_double(int argc, char **argv, struct ten_moment_2d_double_init #ifdef AMR_USETHREADS for (int i = 0; i < num_blocks; i++) { - gkyl_job_pool_add_work(coarse_job_pool, five_moment_init_job_func_block, &mesh_bdata[i]); + gkyl_job_pool_add_work(mesh_job_pool, five_moment_init_job_func_block, &mesh_bdata[i]); } - gkyl_job_pool_wait(coarse_job_pool); + gkyl_job_pool_wait(mesh_job_pool); #else for (int i = 0; i < num_blocks; i++) { five_moment_init_job_func_block(&mesh_bdata[i]); @@ -883,7 +883,7 @@ ten_moment_2d_run_double(int argc, char **argv, struct ten_moment_2d_double_init while ((coarse_t_curr < t_end) && (coarse_step <= num_steps)) { printf("Taking coarse (level 0) time-step %ld at t = %g; ", coarse_step, coarse_t_curr); - struct gkyl_update_status coarse_status = five_moment_update_block(coarse_job_pool, btopo, mesh_bdata, coarse_t_curr, coarse_dt, &stats); + struct gkyl_update_status coarse_status = five_moment_update_block(mesh_job_pool, btopo, mesh_bdata, coarse_t_curr, coarse_dt, &stats); printf(" dt = %g\n", coarse_status.dt_actual); if (!coarse_status.success) { @@ -989,5 +989,5 @@ ten_moment_2d_run_double(int argc, char **argv, struct ten_moment_2d_double_init } gkyl_block_topo_release(btopo); - gkyl_job_pool_release(coarse_job_pool); + gkyl_job_pool_release(mesh_job_pool); } \ No newline at end of file From e1dbb4d70a84441bf43bd750385fe7ea06841643 Mon Sep 17 00:00:00 2001 From: JonathanGorard Date: Thu, 27 Jun 2024 14:53:16 -0400 Subject: [PATCH 19/32] Fixed naming conventions in the moment-EM coupling source input structs. --- amr/amr_core_five_moment.c | 32 ++++++++++++++++---------------- amr/amr_core_ten_moment.c | 24 ++++++++++++------------ 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/amr/amr_core_five_moment.c b/amr/amr_core_five_moment.c index c043e539c..ca1b832c8 100644 --- a/amr/amr_core_five_moment.c +++ b/amr/amr_core_five_moment.c @@ -123,26 +123,26 @@ five_moment_1d_run_single(int argc, char **argv, struct five_moment_1d_single_in } ); - struct gkyl_moment_em_coupling_inp coarse_src_inp = { + struct gkyl_moment_em_coupling_inp mesh_src_inp = { .grid = &mesh_pdata[i].grid, .nfluids = 2, .epsilon0 = epsilon0, }; - coarse_src_inp.param[0] = (struct gkyl_moment_em_coupling_data) { + mesh_src_inp.param[0] = (struct gkyl_moment_em_coupling_data) { .type = mesh_pdata[i].euler_elc->type, .charge = charge_elc, .mass = mass_elc, .k0 = k0_elc, }; - coarse_src_inp.param[1] = (struct gkyl_moment_em_coupling_data) { + mesh_src_inp.param[1] = (struct gkyl_moment_em_coupling_data) { .type = mesh_pdata[i].euler_ion->type, .charge = charge_ion, .mass = mass_ion, .k0 = k0_ion, }; - mesh_pdata[i].src_slvr = gkyl_moment_em_coupling_new(coarse_src_inp); + mesh_pdata[i].src_slvr = gkyl_moment_em_coupling_new(mesh_src_inp); } struct gkyl_block_topo *ptopo = create_patch_topo(); @@ -428,26 +428,26 @@ five_moment_1d_run_double(int argc, char **argv, struct five_moment_1d_double_in } ); - struct gkyl_moment_em_coupling_inp coarse_src_inp = { + struct gkyl_moment_em_coupling_inp mesh_src_inp = { .grid = &mesh_pdata[i].grid, .nfluids = 2, .epsilon0 = epsilon0, }; - coarse_src_inp.param[0] = (struct gkyl_moment_em_coupling_data) { + mesh_src_inp.param[0] = (struct gkyl_moment_em_coupling_data) { .type = mesh_pdata[i].euler_elc->type, .charge = charge_elc, .mass = mass_elc, .k0 = k0_elc, }; - coarse_src_inp.param[1] = (struct gkyl_moment_em_coupling_data) { + mesh_src_inp.param[1] = (struct gkyl_moment_em_coupling_data) { .type = mesh_pdata[i].euler_ion->type, .charge = charge_ion, .mass = mass_ion, .k0 = k0_ion, }; - mesh_pdata[i].src_slvr = gkyl_moment_em_coupling_new(coarse_src_inp); + mesh_pdata[i].src_slvr = gkyl_moment_em_coupling_new(mesh_src_inp); } struct gkyl_block_topo *ptopo = create_nested_patch_topo(); @@ -771,26 +771,26 @@ five_moment_2d_run_single(int argc, char **argv, struct five_moment_2d_single_in ); } - struct gkyl_moment_em_coupling_inp coarse_src_inp = { + struct gkyl_moment_em_coupling_inp mesh_src_inp = { .grid = &mesh_bdata[i].grid, .nfluids = 2, .epsilon0 = epsilon0, }; - coarse_src_inp.param[0] = (struct gkyl_moment_em_coupling_data) { + mesh_src_inp.param[0] = (struct gkyl_moment_em_coupling_data) { .type = mesh_bdata[i].euler_elc->type, .charge = charge_elc, .mass = mass_elc, .k0 = k0_elc, }; - coarse_src_inp.param[1] = (struct gkyl_moment_em_coupling_data) { + mesh_src_inp.param[1] = (struct gkyl_moment_em_coupling_data) { .type = mesh_bdata[i].euler_ion->type, .charge = charge_ion, .mass = mass_ion, .k0 = k0_ion, }; - mesh_bdata[i].src_slvr = gkyl_moment_em_coupling_new(coarse_src_inp); + mesh_bdata[i].src_slvr = gkyl_moment_em_coupling_new(mesh_src_inp); } struct gkyl_block_topo *btopo = create_block_topo(); @@ -1148,26 +1148,26 @@ five_moment_2d_run_double(int argc, char **argv, struct five_moment_2d_double_in ); } - struct gkyl_moment_em_coupling_inp coarse_src_inp = { + struct gkyl_moment_em_coupling_inp mesh_src_inp = { .grid = &mesh_bdata[i].grid, .nfluids = 2, .epsilon0 = epsilon0, }; - coarse_src_inp.param[0] = (struct gkyl_moment_em_coupling_data) { + mesh_src_inp.param[0] = (struct gkyl_moment_em_coupling_data) { .type = mesh_bdata[i].euler_elc->type, .charge = charge_elc, .mass = mass_elc, .k0 = k0_elc, }; - coarse_src_inp.param[1] = (struct gkyl_moment_em_coupling_data) { + mesh_src_inp.param[1] = (struct gkyl_moment_em_coupling_data) { .type = mesh_bdata[i].euler_ion->type, .charge = charge_ion, .mass = mass_ion, .k0 = k0_ion, }; - mesh_bdata[i].src_slvr = gkyl_moment_em_coupling_new(coarse_src_inp); + mesh_bdata[i].src_slvr = gkyl_moment_em_coupling_new(mesh_src_inp); } struct gkyl_block_topo *btopo = create_nested_block_topo(); diff --git a/amr/amr_core_ten_moment.c b/amr/amr_core_ten_moment.c index 71cfcd2de..f323fcf54 100644 --- a/amr/amr_core_ten_moment.c +++ b/amr/amr_core_ten_moment.c @@ -110,26 +110,26 @@ ten_moment_1d_run_single(int argc, char **argv, struct ten_moment_1d_single_init } ); - struct gkyl_moment_em_coupling_inp coarse_src_inp = { + struct gkyl_moment_em_coupling_inp mesh_src_inp = { .grid = &mesh_pdata[i].grid, .nfluids = 2, .epsilon0 = epsilon0, }; - coarse_src_inp.param[0] = (struct gkyl_moment_em_coupling_data) { + mesh_src_inp.param[0] = (struct gkyl_moment_em_coupling_data) { .type = mesh_pdata[i].euler_elc->type, .charge = charge_elc, .mass = mass_elc, .k0 = k0_elc, }; - coarse_src_inp.param[1] = (struct gkyl_moment_em_coupling_data) { + mesh_src_inp.param[1] = (struct gkyl_moment_em_coupling_data) { .type = mesh_pdata[i].euler_ion->type, .charge = charge_ion, .mass = mass_ion, .k0 = k0_ion, }; - mesh_pdata[i].src_slvr = gkyl_moment_em_coupling_new(coarse_src_inp); + mesh_pdata[i].src_slvr = gkyl_moment_em_coupling_new(mesh_src_inp); } struct gkyl_block_topo *ptopo = create_patch_topo(); @@ -431,26 +431,26 @@ ten_moment_2d_run_single(int argc, char **argv, struct ten_moment_2d_single_init ); } - struct gkyl_moment_em_coupling_inp coarse_src_inp = { + struct gkyl_moment_em_coupling_inp mesh_src_inp = { .grid = &mesh_bdata[i].grid, .nfluids = 2, .epsilon0 = epsilon0, }; - coarse_src_inp.param[0] = (struct gkyl_moment_em_coupling_data) { + mesh_src_inp.param[0] = (struct gkyl_moment_em_coupling_data) { .type = mesh_bdata[i].euler_elc->type, .charge = charge_elc, .mass = mass_elc, .k0 = k0_elc, }; - coarse_src_inp.param[1] = (struct gkyl_moment_em_coupling_data) { + mesh_src_inp.param[1] = (struct gkyl_moment_em_coupling_data) { .type = mesh_bdata[i].euler_ion->type, .charge = charge_ion, .mass = mass_ion, .k0 = k0_ion, }; - mesh_bdata[i].src_slvr = gkyl_moment_em_coupling_new(coarse_src_inp); + mesh_bdata[i].src_slvr = gkyl_moment_em_coupling_new(mesh_src_inp); } struct gkyl_block_topo *btopo = create_block_topo(); @@ -797,26 +797,26 @@ ten_moment_2d_run_double(int argc, char **argv, struct ten_moment_2d_double_init ); } - struct gkyl_moment_em_coupling_inp coarse_src_inp = { + struct gkyl_moment_em_coupling_inp mesh_src_inp = { .grid = &mesh_bdata[i].grid, .nfluids = 2, .epsilon0 = epsilon0, }; - coarse_src_inp.param[0] = (struct gkyl_moment_em_coupling_data) { + mesh_src_inp.param[0] = (struct gkyl_moment_em_coupling_data) { .type = mesh_bdata[i].euler_elc->type, .charge = charge_elc, .mass = mass_elc, .k0 = k0_elc, }; - coarse_src_inp.param[1] = (struct gkyl_moment_em_coupling_data) { + mesh_src_inp.param[1] = (struct gkyl_moment_em_coupling_data) { .type = mesh_bdata[i].euler_ion->type, .charge = charge_ion, .mass = mass_ion, .k0 = k0_ion, }; - mesh_bdata[i].src_slvr = gkyl_moment_em_coupling_new(coarse_src_inp); + mesh_bdata[i].src_slvr = gkyl_moment_em_coupling_new(mesh_src_inp); } struct gkyl_block_topo *btopo = create_nested_block_topo(); From 7acf5da98d80014514c362c0a14e90a343e09ee3 Mon Sep 17 00:00:00 2001 From: JonathanGorard Date: Thu, 27 Jun 2024 16:02:34 -0400 Subject: [PATCH 20/32] Added a 10-moment version of the generalized Brio-Wu Riemann problem test in unigrid (so as to facilitate AMR comparisons for the 10-moment equations, while I continue to track down the origin of these instabilities in the moment-EM coupling on heterogeneous meshes). It looks qualitatively correct even though I used a completely made up value for the closure parameter (k0 = 5.0). With gradient-based closure switched on, however, it crashes after 2 time-steps, which I will now attempt to track down. --- regression/rt_10m_riem.c | 480 +++++++++++++++++++++++++++++++++++++++ regression/rt_5m_riem.c | 7 +- 2 files changed, 484 insertions(+), 3 deletions(-) create mode 100644 regression/rt_10m_riem.c diff --git a/regression/rt_10m_riem.c b/regression/rt_10m_riem.c new file mode 100644 index 000000000..6c9576298 --- /dev/null +++ b/regression/rt_10m_riem.c @@ -0,0 +1,480 @@ +// Generalized Brio-Wu Riemann problem for the 10-moment equations. +// Input parameters match the initial conditions found in entry JE4 of Ammar's Simulation Journal (https://ammar-hakim.org/sj/je/je4/je4-twofluid-shock.html), adapted from Section 7.1 of the article: +// A. Hakim, J. Loverich and U. Shumlak (2006), "A high resolution wave propagation scheme for ideal Two-Fluid plasma equations", +// Journal of Computational Physics, Volume 219 (1): 418-442. +// https://www.sciencedirect.com/science/article/pii/S0021999106001707 + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include + +#ifdef GKYL_HAVE_MPI +#include +#include +#endif + +#include + +struct riem_ctx +{ + // Physical constants (using normalized code units). + double epsilon0; // Permittivity of free space. + double mu0; // Permeability of free space. + double mass_ion; // Proton mass. + double charge_ion; // Proton charge. + double mass_elc; // Electron mass. + double charge_elc; // Electron charge. + + double rhol_ion; // Left ion mass density. + double rhor_ion; // Right ion mass density; + double pl; // Left electron/ion pressure. + double pr; // Right electron/ion pressure. + + double Bx; // Total magnetic field (x-direction). + double Bzl; // Left total magneic field (z-direction). + double Bzr; // Right total magnetic field (z-direction). + + bool has_collision; // Whether to include collisions. + double nu_base_ei; // Base electron-ion collision frequency. + + // Derived physical quantities (using normalized code units). + double rhol_elc; // Left electron mass density. + double rhor_elc; // Right electron mass density. + + // Simulation parameters. + int Nx; // Cell count (x-direction). + double Lx; // Domain size (x-direction). + double k0; // Closure parameter. + double cfl_frac; // CFL coefficient. + + double t_end; // Final simulation time. + int num_frames; // Number of output frames. + double dt_failure_tol; // Minimum allowable fraction of initial time-step. + int num_failures_max; // Maximum allowable number of consecutive small time-steps. +}; + +struct riem_ctx +create_ctx(void) +{ + // Physical constants (using normalized code units). + double epsilon0 = 1.0; // Permittivity of free space. + double mu0 = 1.0; // Permeability of free space. + double mass_ion = 1.0; // Proton mass. + double charge_ion = 1.0; // Proton charge. + double mass_elc = 1.0 / 1836.2; // Electron mass. + double charge_elc = -1.0; // Electron charge. + + double rhol_ion = 1.0; // Left ion mass density. + double rhor_ion = 0.125; // Right ion mass density; + double pl = 5.0e-5; // Left electron/ion pressure. + double pr = 5.0e-6; // Right electron/ion pressure. + + double Bx = 0.75e-2; // Total magnetic field (x-direction). + double Bzl = 1.0e-2; // Left total magneic field (z-direction). + double Bzr = -1.0e-2; // Right total magnetic field (z-direction). + + bool has_collision = false; // Whether to include collisions. + double nu_base_ei = 0.5; // Base electron-ion collision frequency. + + // Derived physical quantities (using normalized code units). + double rhol_elc = rhol_ion * mass_elc / mass_ion; // Left electron mass density. + double rhor_elc = rhor_ion * mass_elc / mass_ion; // Right electron mass density. + + // Simulation parameters. + int Nx = 1024; // Cell count (x-direction). + double Lx = 1.0; // Domain size (x-direction). + double k0 = 5.0; // Closure parameter. + double cfl_frac = 0.95; // CFL coefficient. + + double t_end = 10.0; // Final simulation time. + int num_frames = 1; // Number of output frames. + double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. + int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. + + struct riem_ctx ctx = { + .epsilon0 = epsilon0, + .mu0 = mu0, + .mass_ion = mass_ion, + .charge_ion = charge_ion, + .mass_elc = mass_elc, + .charge_elc = charge_elc, + .rhol_ion = rhol_ion, + .rhor_ion = rhor_ion, + .pl = pl, + .pr = pr, + .Bx = Bx, + .Bzl = Bzl, + .Bzr = Bzr, + .has_collision = has_collision, + .nu_base_ei = nu_base_ei, + .rhol_elc = rhol_elc, + .rhor_elc = rhor_elc, + .Nx = Nx, + .Lx = Lx, + .k0 = k0, + .cfl_frac = cfl_frac, + .t_end = t_end, + .num_frames = num_frames, + .dt_failure_tol = dt_failure_tol, + .num_failures_max = num_failures_max, + }; + + return ctx; +} + +void +evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +{ + double x = xn[0]; + struct riem_ctx *app = ctx; + + double rhol_elc = app->rhol_elc; + double rhor_elc = app->rhor_elc; + + double pl = app->pl; + double pr = app->pr; + + double rho = 0.0; + double p = 0.0; + + if (x < 0.5) { + rho = rhol_elc; // Electron mass density (left). + p = pl; // Electron pressure (left). + } + else { + rho = rhor_elc; // Electron mass density (right). + p = pr; // Electron pressure (right). + } + + // Set electron mass density. + fout[0] = rho; + // Set electron momentum density. + fout[1] = 0.0; fout[2] = 0.0; fout[3] = 0.0; + // Set electron pressure tensor. + fout[4] = p; fout[5] = 0.0; fout[6] = 0.0; + fout[7] = p; fout[8] = 0.0; fout[9] = p; +} + +void +evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +{ + double x = xn[0]; + struct riem_ctx *app = ctx; + + double rhol_ion = app->rhol_ion; + double rhor_ion = app->rhor_ion; + + double pl = app->pl; + double pr = app->pr; + + double rho = 0.0; + double p = 0.0; + + if (x < 0.5) { + rho = rhol_ion; // Ion mass density (left). + p = pl; // Ion pressure (left). + } + else { + rho = rhor_ion; // Ion mass density (right). + p = pr; // Ion pressure (right). + } + + // Set ion mass density. + fout[0] = rho; + // Set ion momentum density. + fout[1] = 0.0; fout[2] = 0.0; fout[3] = 0.0; + // Set ion pressure tensor. + fout[4] = p; fout[5] = 0.0; fout[6] = 0.0; + fout[7] = p; fout[8] = 0.0; fout[9] = p; +} + +void +evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +{ + double x = xn[0]; + struct riem_ctx *app = ctx; + + double Bx = app->Bx; + double Bzl = app->Bzl; + double Bzr = app->Bzr; + + double Bz = 0.0; + + if (x < 0.5) { + Bz = Bzl; // Total magnetic field (z-direction, left). + } + else { + Bz = Bzr; // Total magnetic field (z-direction, right). + } + + // Set electric field. + fout[0] = 0.0, fout[1] = 0.0; fout[2] = 0.0; + // Set magnetic field. + fout[3] = Bx, fout[4] = 0.0; fout[5] = Bz; + // Set correction potentials. + fout[6] = 0.0; fout[7] = 0.0; +} + +void +write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +{ + if (gkyl_tm_trigger_check_and_bump(iot, t_curr)) { + int frame = iot->curr - 1; + if (force_write) { + frame = iot->curr; + } + + gkyl_moment_app_write(app, t_curr, frame); + } +} + +int +main(int argc, char **argv) +{ + struct gkyl_app_args app_args = parse_app_args(argc, argv); + +#ifdef GKYL_HAVE_MPI + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } +#endif + + if (app_args.trace_mem) { + gkyl_cu_dev_mem_debug_set(true); + gkyl_mem_debug_set(true); + } + + struct riem_ctx ctx = create_ctx(); // Context for initialization functions. + + int NX = APP_ARGS_CHOOSE(app_args.xcells[0], ctx.Nx); + + // Electron/ion equations. + struct gkyl_wv_eqn *elc_ten_moment = gkyl_wv_ten_moment_new(ctx.k0); + struct gkyl_wv_eqn *ion_ten_moment = gkyl_wv_ten_moment_new(ctx.k0); + + struct gkyl_moment_species elc = { + .name = "elc", + .charge = ctx.charge_elc, .mass = ctx.mass_elc, + .equation = elc_ten_moment, + .evolve = true, + .init = evalElcInit, + .ctx = &ctx, + }; + + struct gkyl_moment_species ion = { + .name = "ion", + .charge = ctx.charge_ion, .mass = ctx.mass_ion, + .equation = ion_ten_moment, + .evolve = true, + .init = evalIonInit, + .ctx = &ctx, + }; + + // Field. + struct gkyl_moment_field field = { + .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + + .evolve = true, + .init = evalFieldInit, + .ctx = &ctx, + }; + + int nrank = 1; // Number of processes in simulation. +#ifdef GKYL_HAVE_MPI + if (app_args.use_mpi) { + MPI_Comm_size(MPI_COMM_WORLD, &nrank); + } +#endif + + // Create global range. + int cells[] = { NX }; + int dim = sizeof(cells) / sizeof(cells[0]); + struct gkyl_range global_r; + gkyl_create_global_range(dim, cells, &global_r); + + // Create decomposition. + int cuts[dim]; +#ifdef GKYL_HAVE_MPI + for (int d = 0; d < dim; d++) { + if (app_args.use_mpi) { + cuts[d] = app_args.cuts[d]; + } + else { + cuts[d] = 1; + } + } +#else + for (int d = 0; d < dim; d++) { + cuts[d] = 1; + } +#endif + + struct gkyl_rect_decomp *decomp = gkyl_rect_decomp_new_from_cuts(dim, cuts, &global_r); + + // Construct communicator for use in app. + struct gkyl_comm *comm; +#ifdef GKYL_HAVE_MPI + if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { + .mpi_comm = MPI_COMM_WORLD, + .decomp = decomp + } + ); + } + else { + comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { + .decomp = decomp, + .use_gpu = app_args.use_gpu + } + ); + } +#else + comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { + .decomp = decomp, + .use_gpu = app_args.use_gpu + } + ); +#endif + + int my_rank; + gkyl_comm_get_rank(comm, &my_rank); + int comm_size; + gkyl_comm_get_size(comm, &comm_size); + + int ncuts = 1; + for (int d = 0; d < dim; d++) { + ncuts *= cuts[d]; + } + + if (ncuts != comm_size) { + if (my_rank == 0) { + fprintf(stderr, "*** Number of ranks, %d, does not match total cuts, %d!\n", comm_size, ncuts); + } + goto mpifinalize; + } + + // Moment app. + struct gkyl_moment app_inp = { + .name = "10m_riem", + + .ndim = 1, + .lower = { 0.0 }, + .upper = { ctx.Lx }, + .cells = { NX }, + + .cfl_frac = ctx.cfl_frac, + + .num_species = 2, + .species = { elc, ion }, + + .has_collision = ctx.has_collision, + .nu_base = { + {0, ctx.nu_base_ei}, + {ctx.nu_base_ei, 0} + }, + + .field = field, + + .has_low_inp = true, + .low_inp = { + .local_range = decomp->ranges[my_rank], + .comm = comm + } + }; + + // Create app object. + gkyl_moment_app *app = gkyl_moment_app_new(&app_inp); + + // Initial and final simulation times. + double t_curr = 0.0, t_end = ctx.t_end; + + // Create trigger for IO. + int num_frames = ctx.num_frames; + struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames }; + + // Initialize simulation. + gkyl_moment_app_apply_ic(app, t_curr); + write_data(&io_trig, app, t_curr, false); + + // Compute estimate of maximum stable time-step. + double dt = gkyl_moment_app_max_dt(app); + + // Initialize small time-step check. + double dt_init = -1.0, dt_failure_tol = ctx.dt_failure_tol; + int num_failures = 0, num_failures_max = ctx.num_failures_max; + + long step = 1; + while ((t_curr < t_end) && (step <= app_args.num_steps)) { + gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); + struct gkyl_update_status status = gkyl_moment_update(app, dt); + gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); + + if (!status.success) { + gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); + break; + } + + t_curr += status.dt_actual; + dt = status.dt_suggested; + + write_data(&io_trig, app, t_curr, false); + + if (dt_init < 0.0) { + dt_init = status.dt_actual; + } + else if (status.dt_actual < dt_failure_tol * dt_init) { + num_failures += 1; + + gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); + gkyl_moment_app_cout(app, stdout, " is below %g*dt_init ...", dt_failure_tol); + gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); + if (num_failures >= num_failures_max) { + gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); + gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + break; + } + } + else { + num_failures = 0; + } + + step += 1; + } + + write_data(&io_trig, app, t_curr, false); + gkyl_moment_app_stat_write(app); + + struct gkyl_moment_stat stat = gkyl_moment_app_stat(app); + + gkyl_moment_app_cout(app, stdout, "\n"); + gkyl_moment_app_cout(app, stdout, "Number of update calls %ld\n", stat.nup); + gkyl_moment_app_cout(app, stdout, "Number of failed time-steps %ld\n", stat.nfail); + gkyl_moment_app_cout(app, stdout, "Species updates took %g secs\n", stat.species_tm); + gkyl_moment_app_cout(app, stdout, "Field updates took %g secs\n", stat.field_tm); + gkyl_moment_app_cout(app, stdout, "Source updates took %g secs\n", stat.sources_tm); + gkyl_moment_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); + + // Free resources after simulation completion. + gkyl_wv_eqn_release(elc_ten_moment); + gkyl_wv_eqn_release(ion_ten_moment); + gkyl_rect_decomp_release(decomp); + gkyl_comm_release(comm); + gkyl_moment_app_release(app); + +mpifinalize: +#ifdef GKYL_HAVE_MPI + if (app_args.use_mpi) { + MPI_Finalize(); + } +#endif + + return 0; +} diff --git a/regression/rt_5m_riem.c b/regression/rt_5m_riem.c index 48cbfef41..726474549 100644 --- a/regression/rt_5m_riem.c +++ b/regression/rt_5m_riem.c @@ -138,12 +138,12 @@ evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout double gas_gamma = app->gas_gamma; - double pl = app->pl; - double pr = app->pr; - double rhol_elc = app->rhol_elc; double rhor_elc = app->rhor_elc; + double pl = app->pl; + double pr = app->pr; + double rho = 0.0; double p = 0.0; @@ -174,6 +174,7 @@ evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout double rhol_ion = app->rhol_ion; double rhor_ion = app->rhor_ion; + double pl = app->pl; double pr = app->pr; From 2de870372c1da6bedfc72e93bd0005e0a986ceaf Mon Sep 17 00:00:00 2001 From: JonathanGorard Date: Fri, 28 Jun 2024 10:31:28 -0400 Subject: [PATCH 21/32] Added a gradient-based closure variant of the 10-moment generalized Brio-Wu Riemann problem, which only stops crashing for fairly large values of k0 (approximately 500.0 seems to be the threshold). Nevertheless, this will assist with debugging the AMR algorithm's interactions with moment-EM coupling. --- regression/rt_10m_riem_grad_closure.c | 482 ++++++++++++++++++++++++++ 1 file changed, 482 insertions(+) create mode 100644 regression/rt_10m_riem_grad_closure.c diff --git a/regression/rt_10m_riem_grad_closure.c b/regression/rt_10m_riem_grad_closure.c new file mode 100644 index 000000000..b47b7606c --- /dev/null +++ b/regression/rt_10m_riem_grad_closure.c @@ -0,0 +1,482 @@ +// Generalized Brio-Wu Riemann problem, with gradient-closure, for the 10-moment equations. +// Input parameters match the initial conditions found in entry JE4 of Ammar's Simulation Journal (https://ammar-hakim.org/sj/je/je4/je4-twofluid-shock.html), adapted from Section 7.1 of the article: +// A. Hakim, J. Loverich and U. Shumlak (2006), "A high resolution wave propagation scheme for ideal Two-Fluid plasma equations", +// Journal of Computational Physics, Volume 219 (1): 418-442. +// https://www.sciencedirect.com/science/article/pii/S0021999106001707 + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include + +#ifdef GKYL_HAVE_MPI +#include +#include +#endif + +#include + +struct riem_grad_closure_ctx +{ + // Physical constants (using normalized code units). + double epsilon0; // Permittivity of free space. + double mu0; // Permeability of free space. + double mass_ion; // Proton mass. + double charge_ion; // Proton charge. + double mass_elc; // Electron mass. + double charge_elc; // Electron charge. + + double rhol_ion; // Left ion mass density. + double rhor_ion; // Right ion mass density; + double pl; // Left electron/ion pressure. + double pr; // Right electron/ion pressure. + + double Bx; // Total magnetic field (x-direction). + double Bzl; // Left total magneic field (z-direction). + double Bzr; // Right total magnetic field (z-direction). + + bool has_collision; // Whether to include collisions. + double nu_base_ei; // Base electron-ion collision frequency. + + // Derived physical quantities (using normalized code units). + double rhol_elc; // Left electron mass density. + double rhor_elc; // Right electron mass density. + + // Simulation parameters. + int Nx; // Cell count (x-direction). + double Lx; // Domain size (x-direction). + double k0; // Closure parameter. + double cfl_frac; // CFL coefficient. + + double t_end; // Final simulation time. + int num_frames; // Number of output frames. + double dt_failure_tol; // Minimum allowable fraction of initial time-step. + int num_failures_max; // Maximum allowable number of consecutive small time-steps. +}; + +struct riem_grad_closure_ctx +create_ctx(void) +{ + // Physical constants (using normalized code units). + double epsilon0 = 1.0; // Permittivity of free space. + double mu0 = 1.0; // Permeability of free space. + double mass_ion = 1.0; // Proton mass. + double charge_ion = 1.0; // Proton charge. + double mass_elc = 1.0 / 1836.2; // Electron mass. + double charge_elc = -1.0; // Electron charge. + + double rhol_ion = 1.0; // Left ion mass density. + double rhor_ion = 0.125; // Right ion mass density; + double pl = 5.0e-5; // Left electron/ion pressure. + double pr = 5.0e-6; // Right electron/ion pressure. + + double Bx = 0.75e-2; // Total magnetic field (x-direction). + double Bzl = 1.0e-2; // Left total magneic field (z-direction). + double Bzr = -1.0e-2; // Right total magnetic field (z-direction). + + bool has_collision = false; // Whether to include collisions. + double nu_base_ei = 0.5; // Base electron-ion collision frequency. + + // Derived physical quantities (using normalized code units). + double rhol_elc = rhol_ion * mass_elc / mass_ion; // Left electron mass density. + double rhor_elc = rhor_ion * mass_elc / mass_ion; // Right electron mass density. + + // Simulation parameters. + int Nx = 1024; // Cell count (x-direction). + double Lx = 1.0; // Domain size (x-direction). + double k0 = 500.0; // Closure parameter. + double cfl_frac = 0.95; // CFL coefficient. + + double t_end = 10.0; // Final simulation time. + int num_frames = 1; // Number of output frames. + double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. + int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. + + struct riem_grad_closure_ctx ctx = { + .epsilon0 = epsilon0, + .mu0 = mu0, + .mass_ion = mass_ion, + .charge_ion = charge_ion, + .mass_elc = mass_elc, + .charge_elc = charge_elc, + .rhol_ion = rhol_ion, + .rhor_ion = rhor_ion, + .pl = pl, + .pr = pr, + .Bx = Bx, + .Bzl = Bzl, + .Bzr = Bzr, + .has_collision = has_collision, + .nu_base_ei = nu_base_ei, + .rhol_elc = rhol_elc, + .rhor_elc = rhor_elc, + .Nx = Nx, + .Lx = Lx, + .k0 = k0, + .cfl_frac = cfl_frac, + .t_end = t_end, + .num_frames = num_frames, + .dt_failure_tol = dt_failure_tol, + .num_failures_max = num_failures_max, + }; + + return ctx; +} + +void +evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +{ + double x = xn[0]; + struct riem_grad_closure_ctx *app = ctx; + + double rhol_elc = app->rhol_elc; + double rhor_elc = app->rhor_elc; + + double pl = app->pl; + double pr = app->pr; + + double rho = 0.0; + double p = 0.0; + + if (x < 0.5) { + rho = rhol_elc; // Electron mass density (left). + p = pl; // Electron pressure (left). + } + else { + rho = rhor_elc; // Electron mass density (right). + p = pr; // Electron pressure (right). + } + + // Set electron mass density. + fout[0] = rho; + // Set electron momentum density. + fout[1] = 0.0; fout[2] = 0.0; fout[3] = 0.0; + // Set electron pressure tensor. + fout[4] = p; fout[5] = 0.0; fout[6] = 0.0; + fout[7] = p; fout[8] = 0.0; fout[9] = p; +} + +void +evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +{ + double x = xn[0]; + struct riem_grad_closure_ctx *app = ctx; + + double rhol_ion = app->rhol_ion; + double rhor_ion = app->rhor_ion; + + double pl = app->pl; + double pr = app->pr; + + double rho = 0.0; + double p = 0.0; + + if (x < 0.5) { + rho = rhol_ion; // Ion mass density (left). + p = pl; // Ion pressure (left). + } + else { + rho = rhor_ion; // Ion mass density (right). + p = pr; // Ion pressure (right). + } + + // Set ion mass density. + fout[0] = rho; + // Set ion momentum density. + fout[1] = 0.0; fout[2] = 0.0; fout[3] = 0.0; + // Set ion pressure tensor. + fout[4] = p; fout[5] = 0.0; fout[6] = 0.0; + fout[7] = p; fout[8] = 0.0; fout[9] = p; +} + +void +evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +{ + double x = xn[0]; + struct riem_grad_closure_ctx *app = ctx; + + double Bx = app->Bx; + double Bzl = app->Bzl; + double Bzr = app->Bzr; + + double Bz = 0.0; + + if (x < 0.5) { + Bz = Bzl; // Total magnetic field (z-direction, left). + } + else { + Bz = Bzr; // Total magnetic field (z-direction, right). + } + + // Set electric field. + fout[0] = 0.0, fout[1] = 0.0; fout[2] = 0.0; + // Set magnetic field. + fout[3] = Bx, fout[4] = 0.0; fout[5] = Bz; + // Set correction potentials. + fout[6] = 0.0; fout[7] = 0.0; +} + +void +write_data(struct gkyl_tm_trigger* iot, gkyl_moment_app* app, double t_curr, bool force_write) +{ + if (gkyl_tm_trigger_check_and_bump(iot, t_curr)) { + int frame = iot->curr - 1; + if (force_write) { + frame = iot->curr; + } + + gkyl_moment_app_write(app, t_curr, frame); + } +} + +int +main(int argc, char **argv) +{ + struct gkyl_app_args app_args = parse_app_args(argc, argv); + +#ifdef GKYL_HAVE_MPI + if (app_args.use_mpi) { + MPI_Init(&argc, &argv); + } +#endif + + if (app_args.trace_mem) { + gkyl_cu_dev_mem_debug_set(true); + gkyl_mem_debug_set(true); + } + + struct riem_grad_closure_ctx ctx = create_ctx(); // Context for initialization functions. + + int NX = APP_ARGS_CHOOSE(app_args.xcells[0], ctx.Nx); + + // Electron/ion equations. + struct gkyl_wv_eqn *elc_ten_moment = gkyl_wv_ten_moment_new(ctx.k0); + struct gkyl_wv_eqn *ion_ten_moment = gkyl_wv_ten_moment_new(ctx.k0); + + struct gkyl_moment_species elc = { + .name = "elc", + .charge = ctx.charge_elc, .mass = ctx.mass_elc, + .equation = elc_ten_moment, + .has_grad_closure = true, // Include gradient closure. + .evolve = true, + .init = evalElcInit, + .ctx = &ctx, + }; + + struct gkyl_moment_species ion = { + .name = "ion", + .charge = ctx.charge_ion, .mass = ctx.mass_ion, + .equation = ion_ten_moment, + .has_grad_closure = true, // Include gradient closure. + .evolve = true, + .init = evalIonInit, + .ctx = &ctx, + }; + + // Field. + struct gkyl_moment_field field = { + .epsilon0 = ctx.epsilon0, .mu0 = ctx.mu0, + + .evolve = true, + .init = evalFieldInit, + .ctx = &ctx, + }; + + int nrank = 1; // Number of processes in simulation. +#ifdef GKYL_HAVE_MPI + if (app_args.use_mpi) { + MPI_Comm_size(MPI_COMM_WORLD, &nrank); + } +#endif + + // Create global range. + int cells[] = { NX }; + int dim = sizeof(cells) / sizeof(cells[0]); + struct gkyl_range global_r; + gkyl_create_global_range(dim, cells, &global_r); + + // Create decomposition. + int cuts[dim]; +#ifdef GKYL_HAVE_MPI + for (int d = 0; d < dim; d++) { + if (app_args.use_mpi) { + cuts[d] = app_args.cuts[d]; + } + else { + cuts[d] = 1; + } + } +#else + for (int d = 0; d < dim; d++) { + cuts[d] = 1; + } +#endif + + struct gkyl_rect_decomp *decomp = gkyl_rect_decomp_new_from_cuts(dim, cuts, &global_r); + + // Construct communicator for use in app. + struct gkyl_comm *comm; +#ifdef GKYL_HAVE_MPI + if (app_args.use_mpi) { + comm = gkyl_mpi_comm_new( &(struct gkyl_mpi_comm_inp) { + .mpi_comm = MPI_COMM_WORLD, + .decomp = decomp + } + ); + } + else { + comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { + .decomp = decomp, + .use_gpu = app_args.use_gpu + } + ); + } +#else + comm = gkyl_null_comm_inew( &(struct gkyl_null_comm_inp) { + .decomp = decomp, + .use_gpu = app_args.use_gpu + } + ); +#endif + + int my_rank; + gkyl_comm_get_rank(comm, &my_rank); + int comm_size; + gkyl_comm_get_size(comm, &comm_size); + + int ncuts = 1; + for (int d = 0; d < dim; d++) { + ncuts *= cuts[d]; + } + + if (ncuts != comm_size) { + if (my_rank == 0) { + fprintf(stderr, "*** Number of ranks, %d, does not match total cuts, %d!\n", comm_size, ncuts); + } + goto mpifinalize; + } + + // Moment app. + struct gkyl_moment app_inp = { + .name = "10m_riem_grad_closure", + + .ndim = 1, + .lower = { 0.0 }, + .upper = { ctx.Lx }, + .cells = { NX }, + + .cfl_frac = ctx.cfl_frac, + + .num_species = 2, + .species = { elc, ion }, + + .has_collision = ctx.has_collision, + .nu_base = { + {0, ctx.nu_base_ei}, + {ctx.nu_base_ei, 0} + }, + + .field = field, + + .has_low_inp = true, + .low_inp = { + .local_range = decomp->ranges[my_rank], + .comm = comm + } + }; + + // Create app object. + gkyl_moment_app *app = gkyl_moment_app_new(&app_inp); + + // Initial and final simulation times. + double t_curr = 0.0, t_end = ctx.t_end; + + // Create trigger for IO. + int num_frames = ctx.num_frames; + struct gkyl_tm_trigger io_trig = { .dt = t_end / num_frames }; + + // Initialize simulation. + gkyl_moment_app_apply_ic(app, t_curr); + write_data(&io_trig, app, t_curr, false); + + // Compute estimate of maximum stable time-step. + double dt = gkyl_moment_app_max_dt(app); + + // Initialize small time-step check. + double dt_init = -1.0, dt_failure_tol = ctx.dt_failure_tol; + int num_failures = 0, num_failures_max = ctx.num_failures_max; + + long step = 1; + while ((t_curr < t_end) && (step <= app_args.num_steps)) { + gkyl_moment_app_cout(app, stdout, "Taking time-step %ld at t = %g ...", step, t_curr); + struct gkyl_update_status status = gkyl_moment_update(app, dt); + gkyl_moment_app_cout(app, stdout, " dt = %g\n", status.dt_actual); + + if (!status.success) { + gkyl_moment_app_cout(app, stdout, "** Update method failed! Aborting simulation ....\n"); + break; + } + + t_curr += status.dt_actual; + dt = status.dt_suggested; + + write_data(&io_trig, app, t_curr, false); + + if (dt_init < 0.0) { + dt_init = status.dt_actual; + } + else if (status.dt_actual < dt_failure_tol * dt_init) { + num_failures += 1; + + gkyl_moment_app_cout(app, stdout, "WARNING: Time-step dt = %g", status.dt_actual); + gkyl_moment_app_cout(app, stdout, " is below %g*dt_init ...", dt_failure_tol); + gkyl_moment_app_cout(app, stdout, " num_failures = %d\n", num_failures); + if (num_failures >= num_failures_max) { + gkyl_moment_app_cout(app, stdout, "ERROR: Time-step was below %g*dt_init ", dt_failure_tol); + gkyl_moment_app_cout(app, stdout, "%d consecutive times. Aborting simulation ....\n", num_failures_max); + break; + } + } + else { + num_failures = 0; + } + + step += 1; + } + + write_data(&io_trig, app, t_curr, false); + gkyl_moment_app_stat_write(app); + + struct gkyl_moment_stat stat = gkyl_moment_app_stat(app); + + gkyl_moment_app_cout(app, stdout, "\n"); + gkyl_moment_app_cout(app, stdout, "Number of update calls %ld\n", stat.nup); + gkyl_moment_app_cout(app, stdout, "Number of failed time-steps %ld\n", stat.nfail); + gkyl_moment_app_cout(app, stdout, "Species updates took %g secs\n", stat.species_tm); + gkyl_moment_app_cout(app, stdout, "Field updates took %g secs\n", stat.field_tm); + gkyl_moment_app_cout(app, stdout, "Source updates took %g secs\n", stat.sources_tm); + gkyl_moment_app_cout(app, stdout, "Total updates took %g secs\n", stat.total_tm); + + // Free resources after simulation completion. + gkyl_wv_eqn_release(elc_ten_moment); + gkyl_wv_eqn_release(ion_ten_moment); + gkyl_rect_decomp_release(decomp); + gkyl_comm_release(comm); + gkyl_moment_app_release(app); + +mpifinalize: +#ifdef GKYL_HAVE_MPI + if (app_args.use_mpi) { + MPI_Finalize(); + } +#endif + + return 0; +} From f90aa917a7ed83d2e921c774cc8d793abe5c978c Mon Sep 17 00:00:00 2001 From: JonathanGorard Date: Fri, 28 Jun 2024 15:10:35 -0400 Subject: [PATCH 22/32] Thus the epic saga of debugging the AMR-induced instabilities in the moment-EM solver continues. I've removed the AMR version of the 10-moment parallel firehose instability test (because it didn't work), and have replaced it with an AMR version of the 10-moment generalized Brio-Wu Riemann problem test (which doesn't work either, but is somehow more diagnostically useful). I have tracked the problem down to the gkyl_moment_em_coupling_implicit_advance call helpfully replacing the entire domain with NaNs on the second time-step (but curiously never the first). Strange, and requires further analysis. I also fixed a minor typo/bug in the patch-structured AMR update function when threads are switched off (which I happened to catch incidentally while debugging this). --- amr/amr_core_ten_moment.c | 11 +- amr/amr_patch_coupled.c | 8 +- regression/rt_amr_10m_par_firehose.c | 320 --------------------------- regression/rt_amr_10m_riem_l1.c | 267 ++++++++++++++++++++++ 4 files changed, 278 insertions(+), 328 deletions(-) delete mode 100644 regression/rt_amr_10m_par_firehose.c create mode 100644 regression/rt_amr_10m_riem_l1.c diff --git a/amr/amr_core_ten_moment.c b/amr/amr_core_ten_moment.c index f323fcf54..0d85d89ee 100644 --- a/amr/amr_core_ten_moment.c +++ b/amr/amr_core_ten_moment.c @@ -44,10 +44,10 @@ ten_moment_1d_run_single(int argc, char **argv, struct ten_moment_1d_single_init strcpy(ten_moment_output, init->ten_moment_output); bool low_order_flux = init->low_order_flux; - double cfl_frac = init->cfl_frac; + int num_frames = init->num_frames; + double cfl_frac = init->cfl_frac; double t_end = init->t_end; - int num_frames = init->num_frames; double dt_failure_tol = init->dt_failure_tol; int num_failures_max = init->num_failures_max; @@ -63,6 +63,7 @@ ten_moment_1d_run_single(int argc, char **argv, struct ten_moment_1d_single_init gkyl_rect_grid_init(&mesh_pdata[1].grid, 1, (double []) { coarse_x1 }, (double []) { refined_x1 }, (int []) { Nx } ); gkyl_rect_grid_init(&mesh_pdata[2].grid, 1, (double []) { refined_x2 }, (double []) { coarse_x2 }, (int []) { Nx } ); + for (int i = 0; i < num_patches; i++) { mesh_pdata[i].fv_proj_elc = gkyl_fv_proj_new(&mesh_pdata[i].grid, 1, 10, eval_elc, 0); mesh_pdata[i].fv_proj_ion = gkyl_fv_proj_new(&mesh_pdata[i].grid, 1, 10, eval_ion, 0); @@ -120,13 +121,15 @@ ten_moment_1d_run_single(int argc, char **argv, struct ten_moment_1d_single_init .type = mesh_pdata[i].euler_elc->type, .charge = charge_elc, .mass = mass_elc, - .k0 = k0_elc, + //.k0 = k0_elc, + .k0 = 0.0, }; mesh_src_inp.param[1] = (struct gkyl_moment_em_coupling_data) { .type = mesh_pdata[i].euler_ion->type, .charge = charge_ion, .mass = mass_ion, - .k0 = k0_ion, + //.k0 = k0_ion, + .k0 = 0.0, }; mesh_pdata[i].src_slvr = gkyl_moment_em_coupling_new(mesh_src_inp); diff --git a/amr/amr_patch_coupled.c b/amr/amr_patch_coupled.c index 44e6d3631..64e3629b1 100644 --- a/amr/amr_patch_coupled.c +++ b/amr/amr_patch_coupled.c @@ -200,7 +200,7 @@ five_moment_patch_bc_updaters_release(struct five_moment_patch_data* pdata) gkyl_wv_apply_bc_release(pdata->upper_bc_maxwell[0]); } - //gkyl_array_release(pdata->bc_buffer_elc); + gkyl_array_release(pdata->bc_buffer_elc); gkyl_array_release(pdata->bc_buffer_ion); gkyl_array_release(pdata->bc_buffer_maxwell); } @@ -601,8 +601,8 @@ five_moment_update_patch_job_func_source(void* ctx) nT_source[0] = pdata->nT_source_elc; nT_source[1] = pdata->nT_source_ion; - gkyl_moment_em_coupling_implicit_advance(pdata->src_slvr, t_curr, dt, &pdata->range, fluids, app_accel, rhs_source, - pdata->f_maxwell[nstrang], pdata->app_current, pdata->ext_em, nT_source); + /*gkyl_moment_em_coupling_implicit_advance(pdata->src_slvr, t_curr, dt, &pdata->range, fluids, app_accel, rhs_source, + pdata->f_maxwell[nstrang], pdata->app_current, pdata->ext_em, nT_source);*/ five_moment_patch_bc_updaters_apply(pdata, t_curr, pdata->f_elc[nstrang], pdata->f_ion[nstrang], pdata->f_maxwell[nstrang]); } @@ -634,7 +634,7 @@ five_moment_update_all_patches(const struct gkyl_job_pool* job_pool, const struc gkyl_job_pool_wait(job_pool); #else for (int i = 0; i < num_patches; i++) { - five_moment_update_patches_job_func(&five_moment_patch_ctx[i]); + five_moment_update_patch_job_func(&five_moment_patch_ctx[i]); } #endif diff --git a/regression/rt_amr_10m_par_firehose.c b/regression/rt_amr_10m_par_firehose.c deleted file mode 100644 index 2005ac18a..000000000 --- a/regression/rt_amr_10m_par_firehose.c +++ /dev/null @@ -1,320 +0,0 @@ -// Parallel-propagating firehose instability test, using static, patch-structured mesh refinement with a single refinement patch (2x refinement), for the 10-moment equations. -// Input parameters match the initial conditions in Section 4.4, from the article: -// M. W. Kunz, J. M. Stone and X-N. Bai (2014), "Pegasus: A new hybrid-kinetic particle-in-cell code for astrophysical plasma dynamics", -// Journal of Computational Physics, Volume 259: 154-174. -// https://www.sciencedirect.com/science/article/pii/S0021999113007973 - -// THIS TEST CURRENTLY FAILS (AS OF 05/20/2024) - JG TO TRACK DOWN WHY. - -#include - -struct amr_10m_par_firehose_ctx -{ - // Mathematical constants (dimensionless). - double pi; - - // Physical constants (using normalized code units). - double epsilon0; // Permittivity of free space. - double mu0; // Permeability of free space. - double mass_ion; // Proton mass. - double charge_ion; // Proton charge. - double mass_elc; // Electron mass. - double charge_elc; // Electron charge. - - double vAe; // Electron Alfven velocity. - double n0; // Reference number density. - - // Derived physical quantities (using normalized code units). - double light_speed; // Speed of light. - double B0; // Reference magnetic field strength. - double beta; // Trace proton plasma beta. - double dbeta; // Parallel proton plasma beta - perpendicular proton plasma beta. - double beta_par; // Parallel proton plasma beta. - double beta_perp; // Perpendicular proton plasma beta. - - double vte; // Electron thermal velocity. - double Te; // Electron temperature. - - double Ti_par; // Parallel ion temperature. - double Ti_perp; // Perpendicular ion temperature. - - double omega_ci; // Ion cyclotron frequency. - double omega_pe; // Electron plasma frequency. - double de; // Electron skin depth. - double omega_pi; // Ion plasma frequency. - double di; // Ion skin depth. - double lambdaD; // Electron Debye length. - - double noise_amp; // Noise level for perturbation. - int mode_init; // Initial wave mode to perturb with noise. - int mode_final; // Final wave mode to perturb with noise. - - double k0_elc; // Electron closure parameter. - double k0_ion; // Ion closure parameter. - - // Simulation parameters. - int Nx; // Coarse cell count (x-direction). - int ref_factor; // Refinement factor. - double Lx; // Coarse domain size (x-direction). - double fine_Lx; // Fine domain size (x-direction). - double cfl_frac; // CFL coefficient. - - double t_end; // Final simulation time. - int num_frames; // Number of output frames. - double dt_failure_tol; // Minimum allowable fraction of initial time-step. - int num_failures_max; // Maximum allowable number of consecutive small time-steps. -}; - -struct amr_10m_par_firehose_ctx -create_ctx(void) -{ - // Mathematical constants (dimensionless). - double pi = M_PI; - - // Physical constants (using normalized code units). - double epsilon0 = 1.0; // Permittivity of free space. - double mu0 = 1.0; // Permeability of free space. - double mass_ion = 1836.0; // Proton mass. - double charge_ion = 1.0; // Proton charge. - double mass_elc = 1.0; // Electron mass. - double charge_elc = -1.0; // Electron charge. - - double vAe = 0.0125; // Electron Alfven velocity. - double n0 = 1.0; // Reference number density. - - // Derived physical quantities (using normalized code units). - double light_speed = 1.0 / sqrt(mu0 * epsilon0); // Speed of light. - double B0 = vAe * sqrt(mu0 * n0 * mass_elc); // Reference magnetic field strength. - double beta = 300.0 / pi; // Trace proton plasma beta. - double dbeta = 100.0; // Parallel proton plasma beta - perpendicular proton plasma beta. - double beta_par = beta + 2.0 * dbeta / 3.0; // Parallel proton plasma beta. - double beta_perp = beta - dbeta / 3.0; // Perpendicular proton plasma beta. - - double vte = vAe * sqrt(beta); // Electron thermal velocity. - double Te = vte * vte * mass_elc / 2.0; // Electron temperature. - - double Ti_par = vAe * vAe * (beta_par * mass_elc / 2.0); // Parallel ion temperature. - double Ti_perp = vAe * vAe * (beta_perp * mass_elc / 2.0); // Perpendicular ion temperature. - - double omega_ci = charge_ion * B0 / mass_ion; // Ion cyclotron frequency. - double omega_pe = sqrt(n0 * charge_elc * charge_elc / (epsilon0 * mass_elc)); // Electron plasma frequency. - double de = light_speed / omega_pe; // Electron skin depth. - double omega_pi = sqrt(n0 * charge_ion * charge_ion / (epsilon0 * mass_ion)); // Ion plasma frequency. - double di = light_speed / omega_pi; // Ion skin depth. - double lambdaD = vte / omega_pe; // Electron Debye length. - - double noise_amp = 1.0e-6 * B0; // Noise level for perturbation. - int mode_init = 1; // Initial wave mode to perturb with noise. - int mode_final = 48; // Final wave mode to perturb with noise. - - double k0_elc = 0.1 / de; // Electron closure parameter. - double k0_ion = 0.1 / di; // Ion closure parameter. - - // Simulation parameters. - int Nx = 64; // Coarse cell count (x-direction). - int ref_factor = 2; // Refinement factor. - double Lx = 300.0 * di; // Coarse domain size (x-direction). - double fine_Lx = 0.5 * (300.0 * di); // Fine domain size (x-direction). - double cfl_frac = 0.95; // CFL coefficient. - - double t_end = 10.0 / omega_ci; // Final simulation time. - int num_frames = 1; // Number of output frames. - double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. - int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. - - struct amr_10m_par_firehose_ctx ctx = { - .pi = pi, - .epsilon0 = epsilon0, - .mu0 = mu0, - .mass_ion = mass_ion, - .charge_ion = charge_ion, - .mass_elc = mass_elc, - .charge_elc = charge_elc, - .vAe = vAe, - .n0 = n0, - .light_speed = light_speed, - .B0 = B0, - .beta = beta, - .dbeta = dbeta, - .beta_par = beta_par, - .beta_perp = beta_perp, - .vte = vte, - .Te = Te, - .Ti_par = Ti_par, - .Ti_perp = Ti_perp, - .omega_ci = omega_ci, - .omega_pe = omega_pe, - .de = de, - .omega_pi = omega_pi, - .di = di, - .lambdaD = lambdaD, - .noise_amp = noise_amp, - .mode_init = mode_init, - .mode_final = mode_final, - .k0_elc = k0_elc, - .k0_ion = k0_ion, - .Nx = Nx, - .ref_factor = ref_factor, - .Lx = Lx, - .fine_Lx = fine_Lx, - .cfl_frac = cfl_frac, - .t_end = t_end, - .num_frames = num_frames, - .dt_failure_tol = dt_failure_tol, - .num_failures_max = num_failures_max, - }; - - return ctx; -} - -void -evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) -{ - double x = xn[0]; - struct amr_10m_par_firehose_ctx new_ctx = create_ctx(); // Context for initialization functions. - struct amr_10m_par_firehose_ctx *app = &new_ctx; - - double mass_elc = app->mass_elc; - - double n0 = app->n0; - - double Te = app->Te; - - double rhoe = mass_elc * n0; // Electron mass density. - double momxe = 0.0; // Electron momentum density (x-direction). - double momye = 0.0; // Electron momentum density (y-direction). - double momze = 0.0; // Electron momentum density (z-direction). - double pxxe = n0 * Te + momxe * momxe / rhoe; // Electron pressure tensor (x-x component). - double pxye = momxe * momye / rhoe; // Electron pressure tensor (x-y/y-x component). - double pxze = momxe * momze / rhoe; // Electron pressure tensor (x-z/z-x component). - double pyye = n0 * Te + momye * momye / rhoe; // Electron pressure tensor (y-y component). - double pyze = momye * momye / rhoe; // Electron pressure tensor (y-z/z-y component). - double pzze = n0 * Te + momze * momze / rhoe; // Electron pressure tensor (z-z component). - - // Set electron mass density. - fout[0] = rhoe; - // Set electron momentum density. - fout[1] = momxe; fout[2] = momye; fout[3] = momze; - // Set electron pressure tensor. - fout[4] = pxxe; fout[5] = pxye; fout[6] = pxze; - fout[7] = pyye; fout[8] = pyze; fout[9] = pzze; -} - -void -evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) -{ - double x = xn[0]; - struct amr_10m_par_firehose_ctx new_ctx = create_ctx(); // Context for initialization functions. - struct amr_10m_par_firehose_ctx *app = &new_ctx; - - double mass_ion = app->mass_ion; - - double n0 = app->n0; - - double Ti_par = app->Ti_par; - double Ti_perp = app->Ti_perp; - - double rhoi = mass_ion * n0; // Ion mass density. - double momxi = 0.0; // Ion momentum density (x-direction). - double momyi = 0.0; // Ion momentum density (y-direction). - double momzi = 0.0; // Ion momentum density (z-direction). - double pxxi = n0 * Ti_par + momxi * momxi / rhoi; // Ion pressure tensor (x-x component). - double pxyi = momxi * momyi / rhoi; // Ion pressure tensor (x-y/y-x component). - double pxzi = momxi * momzi / rhoi; // Ion pressure tensor (x-z/z-x component). - double pyyi = n0 * Ti_perp + momyi * momyi / rhoi; // Ion pressure tensor (y-y component). - double pyzi = momyi * momyi / rhoi; // Ion pressure tensor (y-z/z-y component). - double pzzi = n0 * Ti_perp + momzi * momzi / rhoi; // Ion pressure tensor (z-z component). - - // Set ion mass density. - fout[0] = rhoi; - // Set ion momentum density. - fout[1] = momxi; fout[2] = momyi; fout[3] = momzi; - // Set ion pressure tensor. - fout[4] = pxxi; fout[5] = pxyi; fout[6] = pxzi; - fout[7] = pyyi; fout[8] = pyzi; fout[9] = pzzi; -} - -void -evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) -{ - double x = xn[0]; - struct amr_10m_par_firehose_ctx new_ctx = create_ctx(); // Context for initialization functions. - struct amr_10m_par_firehose_ctx *app = &new_ctx; - - double pi = app->pi; - - double B0 = app->B0; - - double noise_amp = app->noise_amp; - double mode_init = app->mode_init; - double mode_final = app->mode_final; - - double Lx = app->Lx; - - double Bx = B0; // Total magnetic field (x-direction). - double By = 0.0; - double Bz = 0.0; - - double alpha = noise_amp * Bx; // Applied amplitude. - double kx = 2.0 * pi / Lx; // Wave number (x-direction). - - pcg64_random_t rng = gkyl_pcg64_init(0); // Random number generator. - - for (int i = mode_init; i < mode_final; i++) - { - By -= alpha * gkyl_pcg64_rand_double(&rng) * sin(i * kx * x + 2.0 * pi * gkyl_pcg64_rand_double(&rng)); // Total magnetic field (y-direction). - Bz -= alpha * gkyl_pcg64_rand_double(&rng) * sin(i * kx * x + 2.0 * pi * gkyl_pcg64_rand_double(&rng)); // Total magnetic field (z-direction). - } - - // Set electric field. - fout[0] = 0.0; fout[1] = 0.0; fout[2] = 0.0; - // Set magnetic field. - fout[3] = Bx; fout[4] = By; fout[5] = Bz; - // Set correction potentials. - fout[6] = 0.0; fout[7] = 0.0; -} - -int main(int argc, char **argv) -{ - struct amr_10m_par_firehose_ctx ctx = create_ctx(); // Context for initialization functions. - - struct ten_moment_1d_single_init init = { - .base_Nx = ctx.Nx, - .ref_factor = ctx.ref_factor, - - .coarse_x1 = 0.0, - .coarse_x2 = ctx.Lx, - - .refined_x1 = (0.5 * ctx.Lx) - (0.5 * ctx.fine_Lx), - .refined_x2 = (0.5 * ctx.Lx) + (0.5 * ctx.fine_Lx), - - .eval_elc = evalElcInit, - .eval_ion = evalIonInit, - .eval_field = evalFieldInit, - - .k0_elc = ctx.k0_elc, - .k0_ion = ctx.k0_ion, - - .light_speed = 1.0, - .e_fact = 0.0, - .b_fact = 1.0, - - .epsilon0 = ctx.epsilon0, - .mass_elc = ctx.mass_elc, - .charge_elc = ctx.charge_elc, - .mass_ion = ctx.mass_ion, - .charge_ion = ctx.charge_ion, - - .ten_moment_output = "amr_10m_par_firehose", - - .low_order_flux = false, - .cfl_frac = ctx.cfl_frac, - - .t_end = ctx.t_end, - .num_frames = ctx.num_frames, - .dt_failure_tol = ctx.dt_failure_tol, - .num_failures_max = ctx.num_failures_max, - }; - - ten_moment_1d_run_single(argc, argv, &init); -} \ No newline at end of file diff --git a/regression/rt_amr_10m_riem_l1.c b/regression/rt_amr_10m_riem_l1.c new file mode 100644 index 000000000..e1250780f --- /dev/null +++ b/regression/rt_amr_10m_riem_l1.c @@ -0,0 +1,267 @@ +// Generalized Brio-Wu Riemann problem, using static, patch-structured mesh refinement with a single refinement patch (4x refinement), for the 10-moment equations. +// Input parameters match the initial conditions found in entry JE4 of Ammar's Simulation Journal (https://ammar-hakim.org/sj/je/je4/je4-twofluid-shock.html), adapted from Section 7.1 of the article: +// A. Hakim, J. Loverich and U. Shumlak (2006), "A high resolution wave propagation scheme for ideal Two-Fluid plasma equations", +// Journal of Computational Physics, Volume 219 (1): 418-442. +// https://www.sciencedirect.com/science/article/pii/S0021999106001707 + +#include + +struct amr_10m_riem_ctx +{ + // Physical constants (using normalized code units). + double epsilon0; // Permittivity of free space. + double mu0; // Permeability of free space. + double mass_ion; // Proton mass. + double charge_ion; // Proton charge. + double mass_elc; // Electron mass. + double charge_elc; // Electron charge. + + double rhol_ion; // Left ion mass density. + double rhor_ion; // Right ion mass density; + double pl; // Left electron/ion pressure. + double pr; // Right electron/ion pressure. + + double Bx; // Total magnetic field (x-direction). + double Bzl; // Left total magneic field (z-direction). + double Bzr; // Right total magnetic field (z-direction). + + bool has_collision; // Whether to include collisions. + double nu_base_ei; // Base electron-ion collision frequency. + + double k0_elc; // Electron closure parameter. + double k0_ion; // Ion closure parameter. + + // Derived physical quantities (using normalized code units). + double rhol_elc; // Left electron mass density. + double rhor_elc; // Right electron mass density. + + // Simulation parameters. + int Nx; // Coarse cell count (x-direction). + int ref_factor; // Refinement factor. + double Lx; // Coarse domain size (x-direction). + double fine_Lx; // Fine domain size (x-direction). + double cfl_frac; // CFL coefficient. + + double t_end; // Final simulation time. + int num_frames; // Number of output frames. + double dt_failure_tol; // Minimum allowable fraction of initial time-step. + int num_failures_max; // Maximum allowable number of consecutive small time-steps. +}; + +struct amr_10m_riem_ctx +create_ctx(void) +{ + // Physical constants (using normalized code units). + double gas_gamma = 5.0 / 3.0; // Adiabatic index. + double epsilon0 = 1.0; // Permittivity of free space. + double mu0 = 1.0; // Permeability of free space. + double mass_ion = 1.0; // Proton mass. + double charge_ion = 1.0; // Proton charge. + double mass_elc = 1.0 / 1836.2; // Electron mass. + double charge_elc = -1.0; // Electron charge. + + double rhol_ion = 1.0; // Left ion mass density. + double rhor_ion = 0.125; // Right ion mass density; + double pl = 5.0e-5; // Left electron/ion pressure. + double pr = 5.0e-6; // Right electron/ion pressure. + + double Bx = 0.75e-2; // Total magnetic field (x-direction). + double Bzl = 1.0e-2; // Left total magneic field (z-direction). + double Bzr = -1.0e-2; // Right total magnetic field (z-direction). + + bool has_collision = false; // Whether to include collisions. + double nu_base_ei = 0.5; // Base electron-ion collision frequency. + + double k0_elc = 5.0; // Electron closure parameter. + double k0_ion = 5.0; // Ion closure parameter. + + // Derived physical quantities (using normalized code units). + double rhol_elc = rhol_ion * mass_elc / mass_ion; // Left electron mass density. + double rhor_elc = rhor_ion * mass_elc / mass_ion; // Right electron mass density. + + // Simulation parameters. + int Nx = 64; // Coarse cell count (x-direction). + int ref_factor = 1; // Refinement factor. + double Lx = 1.0; // Coarse domain size (x-direction). + double fine_Lx = 0.2; // Fine domain size (x-direction). + double cfl_frac = 0.95; // CFL coefficient. + + double t_end = 0.5; // Final simulation time. + int num_frames = 1; // Number of output frames. + double dt_failure_tol = 1.0e-4; // Minimum allowable fraction of initial time-step. + int num_failures_max = 20; // Maximum allowable number of consecutive small time-steps. + + struct amr_10m_riem_ctx ctx = { + .epsilon0 = epsilon0, + .mu0 = mu0, + .mass_ion = mass_ion, + .charge_ion = charge_ion, + .mass_elc = mass_elc, + .charge_elc = charge_elc, + .rhol_ion = rhol_ion, + .rhor_ion = rhor_ion, + .pl = pl, + .pr = pr, + .Bx = Bx, + .Bzl = Bzl, + .Bzr = Bzr, + .has_collision = has_collision, + .nu_base_ei = nu_base_ei, + .k0_elc = k0_elc, + .k0_ion = k0_ion, + .rhol_elc = rhol_elc, + .rhor_elc = rhor_elc, + .Nx = Nx, + .ref_factor = ref_factor, + .Lx = Lx, + .fine_Lx = fine_Lx, + .cfl_frac = cfl_frac, + .t_end = t_end, + .num_frames = num_frames, + .dt_failure_tol = dt_failure_tol, + .num_failures_max = num_failures_max, + }; + + return ctx; +} + +void +evalElcInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +{ + double x = xn[0]; + struct amr_10m_riem_ctx new_ctx = create_ctx(); // Context for initialization functions. + struct amr_10m_riem_ctx *app = &new_ctx; + + double rhol_elc = app->rhol_elc; + double rhor_elc = app->rhor_elc; + + double pl = app->pl; + double pr = app->pr; + + double rho = 0.0; + double p = 0.0; + + if (x < 0.5) { + rho = rhol_elc; // Electron mass density (left). + p = pl; // Electron pressure (left). + } + else { + rho = rhor_elc; // Electron mass density (right). + p = pr; // Electron pressure (right). + } + + // Set electron mass density. + fout[0] = rho; + // Set electron momentum density. + fout[1] = 0.0; fout[2] = 0.0; fout[3] = 0.0; + // Set electron pressure tensor. + fout[4] = p; fout[5] = 0.0; fout[6] = 0.0; + fout[7] = p; fout[8] = 0.0; fout[9] = 0.0; +} + +void +evalIonInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +{ + double x = xn[0]; + struct amr_10m_riem_ctx new_ctx = create_ctx(); // Context for initialization functions. + struct amr_10m_riem_ctx *app = &new_ctx; + + double rhol_ion = app->rhol_ion; + double rhor_ion = app->rhor_ion; + + double pl = app->pl; + double pr = app->pr; + + double rho = 0.0; + double p = 0.0; + + if (x < 0.5) { + rho = rhol_ion; // Ion mass density (left). + p = pl; // Ion pressure (left). + } + else { + rho = rhor_ion; // Ion mass density (right). + p = pr; // Ion pressure (right). + } + + // Set ion mass density. + fout[0] = rho; + // Set ion momentum density. + fout[1] = 0.0; fout[2] = 0.0; fout[3] = 0.0; + // Set ion pressure tensor. + fout[4] = p; fout[5] = 0.0; fout[6] = 0.0; + fout[7] = p; fout[8] = 0.0; fout[9] = p; +} + +void +evalFieldInit(double t, const double* GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void* ctx) +{ + double x = xn[0]; + struct amr_10m_riem_ctx new_ctx = create_ctx(); // Context for initialization functions. + struct amr_10m_riem_ctx *app = &new_ctx; + + double Bx = app->Bx; + double Bzl = app->Bzl; + double Bzr = app->Bzr; + + double Bz = 0.0; + + if (x < 0.5) { + Bz = Bzl; // Total magnetic field (z-direction, left). + } + else { + Bz = Bzr; // Total magnetic field (z-direction, right). + } + + // Set electric field. + fout[0] = 0.0, fout[1] = 0.0; fout[2] = 0.0; + // Set magnetic field. + fout[3] = Bx, fout[4] = 0.0; fout[5] = Bz; + // Set correction potentials. + fout[6] = 0.0; fout[7] = 0.0; +} + +int main(int argc, char **argv) +{ + struct amr_10m_riem_ctx ctx = create_ctx(); // Context for initialization functions. + + struct ten_moment_1d_single_init init = { + .base_Nx = ctx.Nx, + .ref_factor = ctx.ref_factor, + + .coarse_x1 = 0.0, + .coarse_x2 = ctx.Lx, + + .refined_x1 = (0.5 * ctx.Lx) - (0.5 * ctx.fine_Lx), + .refined_x2 = (0.5 * ctx.Lx) + (0.5 * ctx.fine_Lx), + + .eval_elc = evalElcInit, + .eval_ion = evalIonInit, + .eval_field = evalFieldInit, + + .k0_elc = ctx.k0_elc, + .k0_ion = ctx.k0_ion, + + .light_speed = 1.0, + .e_fact = 0.0, + .b_fact = 1.0, + + .epsilon0 = ctx.epsilon0, + .mass_elc = ctx.mass_elc, + .charge_elc = ctx.charge_elc, + .mass_ion = ctx.mass_ion, + .charge_ion = ctx.charge_ion, + + .ten_moment_output = "amr_10m_riem_l1", + + .low_order_flux = false, + .cfl_frac = ctx.cfl_frac, + + .t_end = ctx.t_end, + .num_frames = ctx.num_frames, + .dt_failure_tol = ctx.dt_failure_tol, + .num_failures_max = ctx.num_failures_max, + }; + + ten_moment_1d_run_single(argc, argv, &init); +} \ No newline at end of file From 6f535d59dd65f070226e92da7285f282ad004453 Mon Sep 17 00:00:00 2001 From: JonathanGorard Date: Mon, 1 Jul 2024 12:04:55 -0400 Subject: [PATCH 23/32] Adding all GR and AMR tests to the automatic regression system - significant rearchitecting of the CI system is going to be required to deal with handling correctness checking (and other things) for patch-structured and block-structured AMR data. I have begun making those changes here, but this is by no means complete - the regression system currently does not work for these cases. WIP. --- ci/moment_regression.c | 224 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 197 insertions(+), 27 deletions(-) diff --git a/ci/moment_regression.c b/ci/moment_regression.c index ce0215ea0..0d882fdb3 100644 --- a/ci/moment_regression.c +++ b/ci/moment_regression.c @@ -16,7 +16,7 @@ int system(const char *command); void -runTest(const char* test_name, const char* test_name_human, const int test_output_count, const char test_outputs[][64]) +runTest(const char* test_name, const char* test_name_human, const int test_output_count, const char test_outputs[][64], const int test_amr) { int counter = 0; @@ -48,28 +48,44 @@ runTest(const char* test_name, const char* test_name_human, const int test_outpu snprintf(command_buffer3, 256, "./build/regression/rt_%s -m > ./ci/output/rt_%s_%d.dat 2>&1", test_name, test_name, counter); system(command_buffer3); - char file_buffer1[128]; - snprintf(file_buffer1, 128, "./%s-stat.json", test_name); - FILE *file_ptr1 = fopen(file_buffer1, "r"); - if (file_ptr1 == NULL) { - printf("*** Something catastrophic happened. Test aborting... ***\n"); - } - else { - char command_buffer4[256]; - snprintf(command_buffer4, 256, "mv ./%s-stat.json ci/output/%s-stat_%d.json", test_name, test_name, counter); - system(command_buffer4); + if (test_amr == 0) { + char file_buffer1[128]; + snprintf(file_buffer1, 128, "./%s-stat.json", test_name); + FILE *file_ptr1 = fopen(file_buffer1, "r"); + if (file_ptr1 == NULL) { + printf("*** Something catastrophic happened. Test aborting... ***\n"); + } + else { + char command_buffer4[256]; + snprintf(command_buffer4, 256, "mv ./%s-stat.json ci/output/%s-stat_%d.json", test_name, test_name, counter); + system(command_buffer4); + } } for (int i = 0; i < test_output_count; i++) { char file_buffer2[128]; - snprintf(file_buffer2, 128, "./%s-%s.gkyl", test_name, test_outputs[i]); + + if (test_amr == 0) { + snprintf(file_buffer2, 128, "./%s-%s.gkyl", test_name, test_outputs[i]); + } + else { + snprintf(file_buffer2, 128, "./%s_%s.gkyl", test_name, test_outputs[i]); + } + FILE *file_ptr2 = fopen(file_buffer2, "r"); if (file_ptr2 == NULL) { printf("*** Something catastrophic happened. Test aborting... ***\n"); } else { char command_buffer5[256]; - snprintf(command_buffer5, 256, "mv ./%s-%s.gkyl ci/output/%s-%s_%d.gkyl", test_name, test_outputs[i], test_name, test_outputs[i], counter); + + if (test_amr == 0) { + snprintf(command_buffer5, 256, "mv ./%s-%s.gkyl ci/output/%s-%s_%d.gkyl", test_name, test_outputs[i], test_name, test_outputs[i], counter); + } + else { + snprintf(command_buffer5, 256, "mv ./%s_%s.gkyl ci/output/%s-%s_%d.gkyl", test_name, test_outputs[i], test_name, test_outputs[i], counter); + } + system(command_buffer5); } } @@ -492,8 +508,8 @@ regenerateTest(const char* test_name, const int test_output_count, const char te int main(int argc, char **argv) { - int test_count = 47; - char test_names[47][32] = { + int test_count = 86; + char test_names[86][32] = { "10m_burch", "10m_burch_grad_closure", "10m_gem", @@ -541,8 +557,47 @@ main(int argc, char **argv) "iso_euler_sodshock", "iso_euler_sodshock_lax", "iso_gem", + "gr_mild_shock", + "gr_strong_blast", + "gr_perturbed_density", + "gr_quadrants_2d", + "gr_kh_2d", + "gr_blackhole_static", + "gr_blackhole_spinning", + "gr_bhl_static", + "gr_bhl_spinning", + "amr_euler_sodshock_l1", + "amr_euler_sodshock_l2", + "amr_euler_cart_axi_sodshock_l1", + "amr_euler_cart_axi_sodshock_l2", + "amr_euler_riem_2d_l1", + "amr_euler_riem_2d_l2", + "amr_euler_shock_bubble_l1", + "amr_euler_shock_bubble_l2", + "amr_gr_mild_shock_l1", + "amr_gr_mild_shock_l2", + "amr_gr_strong_blast_l1", + "amr_gr_strong_blast_l2", + "amr_gr_perturbed_density_l1", + "amr_gr_perturbed_density_l2", + "amr_gr_quadrants_2d_l1", + "amr_gr_quadrants_2d_l2", + "amr_gr_blackhole_static_l1", + "amr_gr_blackhole_static_l2", + "amr_gr_blackhole_spinning_l1", + "amr_gr_blackhole_spinning_l2", + "amr_gr_bhl_static_l1", + "amr_gr_bhl_static_l2", + "amr_gr_bhl_spinning_l1", + "amr_gr_bhl_spinning_l2", + "amr_5m_riem_l1", + "amr_5m_riem_l2", + "amr_5m_gem_l1", + "amr_5m_gem_l2", + "amr_10m_gem_l1", + "amr_10m_gem_l2", }; - char test_names_human[47][128] = { + char test_names_human[86][256] = { "Burch et al. Magnetic Reconnection Test (10-moment equations)", "Burch et al. Magnetic Reconnection Gradient-Closure Test (10-moment equations)", "Geospace Environment Modeling Reconnection Test (10-moment equations)", @@ -590,10 +645,50 @@ main(int argc, char **argv) "Sod-Type Shock Tube Test, with Roe fluxes (isothermal Euler equations)", "Sod-Type Shock Tube Test, with Lax fluxes (isothermal Euler equations)", "Geospace Environment Modeling Reconnection Test (isothermal Euler equations)", + "Mildly Relativistic Blast Wave Test (general relativistic Euler equations)", + "Strongly Relativistic Blast Wave Test (general relativistic Euler equations)", + "Perturbed Density Test (general relativistic Euler equations)", + "2D Quadrants Test (general relativistic Euler equations)", + "2D Relativistic Kelvin-Helmholtz Instability Test (general relativistic Euler equations)", + "2D Ring-Accretion Problem onto a Static/Schwarzschild Black Hole (general relativistic Euler equations)", + "2D Ring-Accretion Problem onto a Spinning/Kerr Black Hole (general relativistic Euler equations)", + "2D Bondi-Hoyle-Lyttleton Accretion Problem onto a Static/Schwarzschild Black Hole (general relativistic Euler equations)", + "2D Bondi-Hoyle-Lyttleton Accretion Problem onto a Spinning/Kerr Black Hole (general relativistic Euler equations)", + "Sod-Type Shock Tube Test with Level-1 Patch-Structured AMR (Euler equations)", + "Sod-Type Shock Tube Test with Level-2 Patch-Structured AMR (Euler equations)", + "2D Sod-Type Shock Tube Test in Axial Symmetry with Level-1 Block-Structured AMR (Euler equations)", + "2D Sod-Type Shock Tube Test in Axial Symmetry with Level-2 Block-Structured AMR (Euler equations)", + "2D Riemann/quadrant Problem with Level-1 Block-Structured AMR (Euler equations)", + "2D Riemann/quadrant Problem with Level-2 Block-Structured AMR (Euler equations)", + "2D Shock Bubble Collapse Test with Level-1 Block-Structured AMR (Euler equations)", + "2D Shock Bubble Collapse Test with Level-2 Block-Structured AMR (Euler equations)", + "Mildly Relativistic Blast Wave Test with Level-1 Patch-Structured AMR (general relativistic Euler equations)", + "Mildly Relativistic Blast Wave Test with Level-2 Patch-Structured AMR (general relativistic Euler equations)", + "Strongly Relativistic Blast Wave Test with Level-1 Patch-Structured AMR (general relativistic Euler equations)", + "Strongly Relativistic Blast Wave Test with Level-2 Patch-Structured AMR (general relativistic Euler equations)", + "Perturbed Density Test with Level-1 Patch-Structured AMR (general relativistic Euler equations)", + "Perturbed Density Test with Level-2 Patch-Structured AMR (general relativistic Euler equations)", + "2D Quadrants Test with Level-1 Block-Structured AMR (general relativistic Euler equations)", + "2D Quadrants Test with Level-2 Block-Structured AMR (general relativistic Euler equations)", + "2D Ring-Accretion Problem onto a Static/Schwarzschild Black Hole with Level-1 Block-Structured AMR (general relativistic Euler equations)", + "2D Ring-Accretion Problem onto a Static/Schwarzschild Black Hole with Level-2 Block-Structured AMR (general relativistic Euler equations)", + "2D Ring-Accretion Problem onto a Spinning/Kerr Black Hole with Level-1 Block-Structured AMR (general relativistic Euler equations)", + "2D Ring-Accretion Problem onto a Spinning/Kerr Black Hole with Level-2 Block-Structured AMR (general relativistic Euler equations)", + "2D Bondi-Hoyle-Lyttleton Accretion Problem onto a Static/Schwarzschild Black Hole with Level-1 Block-Structured AMR (general relativistic Euler equations)", + "2D Bondi-Hoyle-Lyttleton Accretion Problem onto a Static/Schwarzschild Black Hole with Level-2 Block-Structured AMR (general relativistic Euler equations)", + "2D Bondi-Hoyle-Lyttleton Accretion Problem onto a Spinning/Kerr Black Hole with Level-1 Block-Structured AMR (general relativistic Euler equations)", + "2D Bondi-Hoyle-Lyttleton Accretion Problem onto a Spinning/Kerr Black Hole with Level-2 Block-Structured AMR (general relativistic Euler equations)", + "Generalized Brio-Wu Riemann Problem Test with Level-1 Patch-Structured AMR (5-moment equations)", + "Generalized Brio-Wu Riemann Problem Test with Level-2 Patch-Structured AMR (5-moment equations)", + "Geospace Environment Modeling Reconnection Test with Level-1 Block-Structured AMR (5-moment equations)", + "Geospace Environment Modeling Reconnection Test with Level-2 Block-Strutcured AMR (5-moment equations)", + "Geospace Environment Modeling Reconnection Test with Level-1 Block-Structured AMR (10-moment equations)", + "Geospace Environment Modeling Reconnection Test with Level-2 Block-Structured AMR (10-moment equations)", }; - int test_output_count[47] = { 4, 4, 4, 4, 4, 4, 4, 4, 1, 1, 4, 4, 3, 4, 1, 1, 1, 1, 3, 1, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 2, 1, 1, 2, 1, 1, 4 }; - char test_outputs[47][64][64] = { + int test_output_count[86] = { 4, 4, 4, 4, 4, 4, 4, 4, 1, 1, 4, 4, 3, 4, 1, 1, 1, 1, 3, 1, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 2, 1, 1, 2, 1, 1, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 5, 9, 25, 9, 25, 9, 25, 3, 5, 3, 5, 3, 5, 9, 25, 9, 25, 9, + 25, 9, 25, 9, 25, 9, 15, 27, 75, 27, 75 }; + char test_outputs[86][128][64] = { { "elc_1", "ion_1", "field_1", "ext_em_field_1" }, { "elc_1", "ion_1", "field_1", "ext_em_field_1" }, { "elc_1", "ion_1", "field_1", "ext_em_field_1" }, @@ -641,7 +736,78 @@ main(int argc, char **argv) { "iso_euler_1" }, { "iso_euler_1" }, { "elc_1", "ion_1", "field_1", "ext_em_field_1" }, + { "gr_euler_1" }, + { "gr_euler_1" }, + { "gr_euler_1" }, + { "gr_euler_1" }, + { "gr_euler_1" }, + { "gr_euler_1" }, + { "gr_euler_1" }, + { "gr_euler_1" }, + { "gr_euler_1" }, + { "1_p0", "1_p1", "1_p2" }, + { "1_p0", "1_p1", "1_p2", "1_p3", "1_p4" }, + { "1_b0", "1_b1", "1_b2", "1_b3", "1_b4", "1_b5", "1_b6", "1_b7", "1_b8" }, + { "1_b0", "1_b1", "1_b2", "1_b3", "1_b4", "1_b5", "1_b6", "1_b7", "1_b8", "1_b9", "1_b10", "1_b11", "1_b12", "1_b13", "1_b14", + "1_b15", "1_b16", "1_b17", "1_b18", "1_b19", "1_b20", "1_b21", "1_b22", "1_b23", "1_b24" }, + { "1_b0", "1_b1", "1_b2", "1_b3", "1_b4", "1_b5", "1_b6", "1_b7", "1_b8" }, + { "1_b0", "1_b1", "1_b2", "1_b3", "1_b4", "1_b5", "1_b6", "1_b7", "1_b8", "1_b9", "1_b10", "1_b11", "1_b12", "1_b13", "1_b14", + "1_b15", "1_b16", "1_b17", "1_b18", "1_b19", "1_b20", "1_b21", "1_b22", "1_b23", "1_b24" }, + { "1_b0", "1_b1", "1_b2", "1_b3", "1_b4", "1_b5", "1_b6", "1_b7", "1_b8" }, + { "1_b0", "1_b1", "1_b2", "1_b3", "1_b4", "1_b5", "1_b6", "1_b7", "1_b8", "1_b9", "1_b10", "1_b11", "1_b12", "1_b13", "1_b14", + "1_b15", "1_b16", "1_b17", "1_b18", "1_b19", "1_b20", "1_b21", "1_b22", "1_b23", "1_b24" }, + { "1_p0", "1_p1", "1_p2" }, + { "1_p0", "1_p1", "1_p2", "1_p3", "1_p4" }, + { "1_p0", "1_p1", "1_p2" }, + { "1_p0", "1_p1", "1_p2", "1_p3", "1_p4" }, + { "1_p0", "1_p1", "1_p2" }, + { "1_p0", "1_p1", "1_p2", "1_p3", "1_p4" }, + { "1_b0", "1_b1", "1_b2", "1_b3", "1_b4", "1_b5", "1_b6", "1_b7", "1_b8" }, + { "1_b0", "1_b1", "1_b2", "1_b3", "1_b4", "1_b5", "1_b6", "1_b7", "1_b8", "1_b9", "1_b10", "1_b11", "1_b12", "1_b13", "1_b14", + "1_b15", "1_b16", "1_b17", "1_b18", "1_b19", "1_b20", "1_b21", "1_b22", "1_b23", "1_b24" }, + { "1_b0", "1_b1", "1_b2", "1_b3", "1_b4", "1_b5", "1_b6", "1_b7", "1_b8" }, + { "1_b0", "1_b1", "1_b2", "1_b3", "1_b4", "1_b5", "1_b6", "1_b7", "1_b8", "1_b9", "1_b10", "1_b11", "1_b12", "1_b13", "1_b14", + "1_b15", "1_b16", "1_b17", "1_b18", "1_b19", "1_b20", "1_b21", "1_b22", "1_b23", "1_b24" }, + { "1_b0", "1_b1", "1_b2", "1_b3", "1_b4", "1_b5", "1_b6", "1_b7", "1_b8" }, + { "1_b0", "1_b1", "1_b2", "1_b3", "1_b4", "1_b5", "1_b6", "1_b7", "1_b8", "1_b9", "1_b10", "1_b11", "1_b12", "1_b13", "1_b14", + "1_b15", "1_b16", "1_b17", "1_b18", "1_b19", "1_b20", "1_b21", "1_b22", "1_b23", "1_b24" }, + { "1_b0", "1_b1", "1_b2", "1_b3", "1_b4", "1_b5", "1_b6", "1_b7", "1_b8" }, + { "1_b0", "1_b1", "1_b2", "1_b3", "1_b4", "1_b5", "1_b6", "1_b7", "1_b8", "1_b9", "1_b10", "1_b11", "1_b12", "1_b13", "1_b14", + "1_b15", "1_b16", "1_b17", "1_b18", "1_b19", "1_b20", "1_b21", "1_b22", "1_b23", "1_b24" }, + { "1_b0", "1_b1", "1_b2", "1_b3", "1_b4", "1_b5", "1_b6", "1_b7", "1_b8" }, + { "1_b0", "1_b1", "1_b2", "1_b3", "1_b4", "1_b5", "1_b6", "1_b7", "1_b8", "1_b9", "1_b10", "1_b11", "1_b12", "1_b13", "1_b14", + "1_b15", "1_b16", "1_b17", "1_b18", "1_b19", "1_b20", "1_b21", "1_b22", "1_b23", "1_b24" }, + { "1_elc_p0", "1_ion_p0", "1_field_p0", "1_elc_p1", "1_ion_p1", "1_field_p1", "1_elc_p2", "1_ion_p2", "1_field_p2", }, + { "1_elc_p0", "1_ion_p0", "1_field_p0", "1_elc_p1", "1_ion_p1", "1_field_p1", "1_elc_p2", "1_ion_p2", "1_field_p2", + "1_elc_p3", "1_ion_p3", "1_field_p3", "1_elc_p4", "1_ion_p4", "1_field_p4" }, + { "1_elc_b0", "1_ion_b0", "1_field_b0", "1_elc_b1", "1_ion_b1", "1_field_b1", "1_elc_b2", "1_ion_b2", "1_field_b2", + "1_elc_b3", "1_ion_b3", "1_field_b3", "1_elc_b4", "1_ion_b4", "1_field_b4", "1_elc_b5", "1_ion_b5", "1_field_b5", + "1_elc_b6", "1_ion_b6", "1_field_b6", "1_elc_b7", "1_ion_b7", "1_field_b7", "1_elc_b8", "1_ion_b8", "1_field_b8", }, + { "1_elc_b0", "1_ion_b0", "1_field_b0", "1_elc_b1", "1_ion_b1", "1_field_b1", "1_elc_b2", "1_ion_b2", "1_field_b2", + "1_elc_b3", "1_ion_b3", "1_field_b3", "1_elc_b4", "1_ion_b4", "1_field_b4", "1_elc_b5", "1_ion_b5", "1_field_b5", + "1_elc_b6", "1_ion_b6", "1_field_b6", "1_elc_b7", "1_ion_b7", "1_field_b7", "1_elc_b8", "1_ion_b8", "1_field_b8", + "1_elc_b9", "1_ion_b9", "1_field_b9", "1_elc_b10", "1_ion_b10", "1_field_b10", "1_elc_b11", "1_ion_b11", "1_field_b11", + "1_elc_b12", "1_ion_b12", "1_field_b12", "1_elc_b13", "1_ion_b13", "1_field_b13", "1_elc_b14", "1_ion_b14", "1_field_b14", + "1_elc_b15", "1_ion_b15", "1_field_b15", "1_elc_b16", "1_ion_b16", "1_field_b16", "1_elc_b17", "1_ion_b17", "1_field_b17", + "1_elc_b18", "1_ion_b18", "1_field_b18", "1_elc_b19", "1_ion_b19", "1_field_b19", "1_elc_b20", "1_ion_b20", "1_field_b20", + "1_elc_b21", "1_ion_b21", "1_field_b21", "1_elc_b22", "1_ion_b22", "1_field_b22", "1_elc_b23", "1_ion_b23", "1_field_b23", + "1_elc_b24", "1_ion_b24", "1_field_b24" }, + { "1_elc_b0", "1_ion_b0", "1_field_b0", "1_elc_b1", "1_ion_b1", "1_field_b1", "1_elc_b2", "1_ion_b2", "1_field_b2", + "1_elc_b3", "1_ion_b3", "1_field_b3", "1_elc_b4", "1_ion_b4", "1_field_b4", "1_elc_b5", "1_ion_b5", "1_field_b5", + "1_elc_b6", "1_ion_b6", "1_field_b6", "1_elc_b7", "1_ion_b7", "1_field_b7", "1_elc_b8", "1_ion_b8", "1_field_b8", }, + { "1_elc_b0", "1_ion_b0", "1_field_b0", "1_elc_b1", "1_ion_b1", "1_field_b1", "1_elc_b2", "1_ion_b2", "1_field_b2", + "1_elc_b3", "1_ion_b3", "1_field_b3", "1_elc_b4", "1_ion_b4", "1_field_b4", "1_elc_b5", "1_ion_b5", "1_field_b5", + "1_elc_b6", "1_ion_b6", "1_field_b6", "1_elc_b7", "1_ion_b7", "1_field_b7", "1_elc_b8", "1_ion_b8", "1_field_b8", + "1_elc_b9", "1_ion_b9", "1_field_b9", "1_elc_b10", "1_ion_b10", "1_field_b10", "1_elc_b11", "1_ion_b11", "1_field_b11", + "1_elc_b12", "1_ion_b12", "1_field_b12", "1_elc_b13", "1_ion_b13", "1_field_b13", "1_elc_b14", "1_ion_b14", "1_field_b14", + "1_elc_b15", "1_ion_b15", "1_field_b15", "1_elc_b16", "1_ion_b16", "1_field_b16", "1_elc_b17", "1_ion_b17", "1_field_b17", + "1_elc_b18", "1_ion_b18", "1_field_b18", "1_elc_b19", "1_ion_b19", "1_field_b19", "1_elc_b20", "1_ion_b20", "1_field_b20", + "1_elc_b21", "1_ion_b21", "1_field_b21", "1_elc_b22", "1_ion_b22", "1_field_b22", "1_elc_b23", "1_ion_b23", "1_field_b23", + "1_elc_b24", "1_ion_b24", "1_field_b24" } }; + int test_amr[86] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; system("clear"); system("mkdir -p ci/output"); @@ -653,7 +819,7 @@ main(int argc, char **argv) if (strtol(argv[1], &arg_ptr, 10) == 1) { for (int i = 0; i < test_count; i++) { - runTest(test_names[i], test_names_human[i], test_output_count[i], test_outputs[i]); + runTest(test_names[i], test_names_human[i], test_output_count[i], test_outputs[i], test_amr[i]); } } else if (strtol(argv[1], &arg_ptr, 10) == 2) { @@ -665,7 +831,8 @@ main(int argc, char **argv) if (argc > 2) { if (strtol(argv[2], &arg_ptr, 10) >= 1 && strtol(argv[2], &arg_ptr, 10) <= test_count) { runTest(test_names[strtol(argv[2], &arg_ptr, 10) - 1], test_names_human[strtol(argv[2], &arg_ptr, 10) - 1], - test_output_count[strtol(argv[2], &arg_ptr, 10) - 1], test_outputs[strtol(argv[2], &arg_ptr, 10) - 1]); + test_output_count[strtol(argv[2], &arg_ptr, 10) - 1], test_outputs[strtol(argv[2], &arg_ptr, 10) - 1], + test_amr[strtol(argv[2], &arg_ptr, 10) - 1]); } else { printf("Invalid test!\n"); @@ -692,7 +859,7 @@ main(int argc, char **argv) else if (strtol(argv[1], &arg_ptr, 10) == 5) { for (int i = 0; i < test_count; i++) { regenerateTest(test_names[i], test_output_count[i], test_outputs[i]); - runTest(test_names[i], test_names_human[i], test_output_count[i], test_outputs[i]); + runTest(test_names[i], test_names_human[i], test_output_count[i], test_outputs[i], test_amr[i]); } } else if (strtol(argv[1], &arg_ptr, 10) == 6) { @@ -701,7 +868,8 @@ main(int argc, char **argv) regenerateTest(test_names[strtol(argv[2], &arg_ptr, 10) - 1], test_output_count[strtol(argv[2], &arg_ptr, 10) - 1], test_outputs[strtol(argv[2], &arg_ptr, 10) - 1]); runTest(test_names[strtol(argv[2], &arg_ptr, 10) - 1], test_names_human[strtol(argv[2], &arg_ptr, 10) - 1], - test_output_count[strtol(argv[2], &arg_ptr, 10) - 1], test_outputs[strtol(argv[2], &arg_ptr, 10) - 1]); + test_output_count[strtol(argv[2], &arg_ptr, 10) - 1], test_outputs[strtol(argv[2], &arg_ptr, 10) - 1], + test_amr[strtol(argv[2], &arg_ptr, 10) - 1]); } else { printf("Invalid test!\n"); @@ -732,7 +900,7 @@ main(int argc, char **argv) if (option == 1) { for (int i = 0; i < test_count; i++) { - runTest(test_names[i], test_names_human[i], test_output_count[i], test_outputs[i]); + runTest(test_names[i], test_names_human[i], test_output_count[i], test_outputs[i], test_amr[i]); } } else if (option == 2) { @@ -751,7 +919,8 @@ main(int argc, char **argv) printf("\n"); if (option2 >= 1 && option2 <= test_count) { - runTest(test_names[option2 - 1], test_names_human[option2 - 1], test_output_count[option2 - 1], test_outputs[option2 - 1]); + runTest(test_names[option2 - 1], test_names_human[option2 - 1], test_output_count[option2 - 1], test_outputs[option2 - 1], + test_amr[option2 - 1]); } else { printf("Invalid test!\n\n"); @@ -777,7 +946,7 @@ main(int argc, char **argv) else if (option == 5) { for (int i = 0; i < test_count; i++) { regenerateTest(test_names[i], test_output_count[i], test_outputs[i]); - runTest(test_names[i], test_names_human[i], test_output_count[i], test_outputs[i]); + runTest(test_names[i], test_names_human[i], test_output_count[i], test_outputs[i], test_amr[i]); } } else if (option == 6) { @@ -792,7 +961,8 @@ main(int argc, char **argv) if (option2 >= 1 && option2 <= test_count) { regenerateTest(test_names[option2 - 1], test_output_count[option2 - 1], test_outputs[option2 - 1]); - runTest(test_names[option2 - 1], test_names_human[option2 - 1], test_output_count[option2 - 1], test_outputs[option2 - 1]); + runTest(test_names[option2 - 1], test_names_human[option2 - 1], test_output_count[option2 - 1], test_outputs[option2 - 1], + test_amr[option2 - 1]); } else { printf("Invalid test!\n\n"); From 3b98be8a2b5e054659df7b536f06600f6dce8a94 Mon Sep 17 00:00:00 2001 From: JonathanGorard Date: Mon, 1 Jul 2024 13:28:20 -0400 Subject: [PATCH 24/32] Added consistent output format for AMR simulation stats, and reinstated the implicit moment-EM coupling in amr_patch_coupling (even though it doesn't work, but I'm not going to debug this now). --- amr/amr_core_euler.c | 20 ++++++++++++++++---- amr/amr_core_five_moment.c | 22 ++++++++++++++++++---- amr/amr_core_gr_euler.c | 20 ++++++++++++++++---- amr/amr_core_ten_moment.c | 16 +++++++++++++--- amr/amr_patch_coupled.c | 6 +++--- 5 files changed, 66 insertions(+), 18 deletions(-) diff --git a/amr/amr_core_euler.c b/amr/amr_core_euler.c index 85f0aeeed..85b3d6e50 100644 --- a/amr/amr_core_euler.c +++ b/amr/amr_core_euler.c @@ -189,7 +189,10 @@ euler1d_run_single(int argc, char **argv, struct euler1d_single_init* init) euler_write_sol_patch(buf, num_patches, mesh_pdata); - printf("Total run-time: %g. Failed steps: %d\n", tm_total_sec, stats.nfail); + printf("\n"); + printf("Number of update calls %ld\n", (coarse_step - 1)); + printf("Number of failed time-steps %d\n", stats.nfail); + printf("Total updates took %g secs\n", tm_total_sec); for (int i = 0; i < num_patches; i++) { gkyl_fv_proj_release(mesh_pdata[i].fv_proj); @@ -408,7 +411,10 @@ euler1d_run_double(int argc, char **argv, struct euler1d_double_init* init) euler_write_sol_patch(buf, num_patches, mesh_pdata); - printf("Total run-time: %g. Failed steps: %d\n", tm_total_sec, stats.nfail); + printf("\n"); + printf("Number of update calls %ld\n", (coarse_step - 1)); + printf("Number of failed time-steps %d\n", stats.nfail); + printf("Total updates took %g secs\n", tm_total_sec); for (int i = 0; i < num_patches; i++) { gkyl_fv_proj_release(mesh_pdata[i].fv_proj); @@ -633,7 +639,10 @@ euler2d_run_single(int argc, char **argv, struct euler2d_single_init* init) euler_write_sol_block(buf, num_blocks, mesh_bdata); - printf("Total run-time: %g. Failed steps: %d\n", tm_total_sec, stats.nfail); + printf("\n"); + printf("Number of update calls %ld\n", (coarse_step - 1)); + printf("Number of failed time-steps %d\n", stats.nfail); + printf("Total updates took %g secs\n", tm_total_sec); for (int i = 0; i < num_blocks; i++) { gkyl_fv_proj_release(mesh_bdata[i].fv_proj); @@ -913,7 +922,10 @@ euler2d_run_double(int argc, char **argv, struct euler2d_double_init* init) euler_write_sol_block(buf, num_blocks, mesh_bdata); - printf("Total run-time: %g. Failed steps: %d\n", tm_total_sec, stats.nfail); + printf("\n"); + printf("Number of update calls %ld\n", (coarse_step - 1)); + printf("Number of failed time-steps %d\n", stats.nfail); + printf("Total updates took %g secs\n", tm_total_sec); for (int i = 0; i < num_blocks; i++) { gkyl_fv_proj_release(mesh_bdata[i].fv_proj); diff --git a/amr/amr_core_five_moment.c b/amr/amr_core_five_moment.c index ca1b832c8..1e6200ada 100644 --- a/amr/amr_core_five_moment.c +++ b/amr/amr_core_five_moment.c @@ -264,7 +264,11 @@ five_moment_1d_run_single(int argc, char **argv, struct five_moment_1d_single_in five_moment_write_sol_patch(buf, num_patches, mesh_pdata); - printf("Total run-time: %g. Failed steps: %d\n", tm_total_sec, stats.nfail); + printf("\n"); + printf("Number of update calls %ld\n", (coarse_step - 1)); + printf("Number of failed time-steps %d\n", stats.nfail); + printf("Total updates took %g secs\n", tm_total_sec); + for (int i = 0; i < num_patches; i++) { gkyl_fv_proj_release(mesh_pdata[i].fv_proj_elc); gkyl_fv_proj_release(mesh_pdata[i].fv_proj_ion); @@ -579,7 +583,11 @@ five_moment_1d_run_double(int argc, char **argv, struct five_moment_1d_double_in five_moment_write_sol_patch(buf, num_patches, mesh_pdata); - printf("Total run-time: %g. Failed steps: %d\n", tm_total_sec, stats.nfail); + printf("\n"); + printf("Number of update calls %ld\n", (coarse_step - 1)); + printf("Number of failed time-steps %d\n", stats.nfail); + printf("Total updates took %g secs\n", tm_total_sec); + for (int i = 0; i < num_patches; i++) { gkyl_fv_proj_release(mesh_pdata[i].fv_proj_elc); gkyl_fv_proj_release(mesh_pdata[i].fv_proj_ion); @@ -912,7 +920,10 @@ five_moment_2d_run_single(int argc, char **argv, struct five_moment_2d_single_in five_moment_write_sol_block(buf, num_blocks, mesh_bdata); - printf("Total run-time: %g. Failed steps: %d\n", tm_total_sec, stats.nfail); + printf("\n"); + printf("Number of update calls %ld\n", (coarse_step - 1)); + printf("Number of failed time-steps %d\n", stats.nfail); + printf("Total updates took %g secs\n", tm_total_sec); for (int i = 0; i < num_blocks; i++) { gkyl_fv_proj_release(mesh_bdata[i].fv_proj_elc); @@ -1299,7 +1310,10 @@ five_moment_2d_run_double(int argc, char **argv, struct five_moment_2d_double_in five_moment_write_sol_block(buf, num_blocks, mesh_bdata); - printf("Total run-time: %g. Failed steps: %d\n", tm_total_sec, stats.nfail); + printf("\n"); + printf("Number of update calls %ld\n", (coarse_step - 1)); + printf("Number of failed time-steps %d\n", stats.nfail); + printf("Total updates took %g secs\n", tm_total_sec); for (int i = 0; i < num_blocks; i++) { gkyl_fv_proj_release(mesh_bdata[i].fv_proj_elc); diff --git a/amr/amr_core_gr_euler.c b/amr/amr_core_gr_euler.c index 0bcf58408..852952617 100644 --- a/amr/amr_core_gr_euler.c +++ b/amr/amr_core_gr_euler.c @@ -180,7 +180,10 @@ gr_euler1d_run_single(int argc, char **argv, struct gr_euler1d_single_init* init euler_write_sol_patch(buf, num_patches, mesh_pdata); - printf("Total run-time: %g. Failed steps: %d\n", tm_total_sec, stats.nfail); + printf("\n"); + printf("Number of update calls %ld\n", (coarse_step - 1)); + printf("Number of failed time-steps %d\n", stats.nfail); + printf("Total updates took %g secs\n", tm_total_sec); for (int i = 0; i < num_patches; i++) { gkyl_fv_proj_release(mesh_pdata[i].fv_proj); @@ -391,7 +394,10 @@ gr_euler1d_run_double(int argc, char **argv, struct gr_euler1d_double_init* init euler_write_sol_patch(buf, num_patches, mesh_pdata); - printf("Total run-time: %g. Failed steps: %d\n", tm_total_sec, stats.nfail); + printf("\n"); + printf("Number of update calls %ld\n", (coarse_step - 1)); + printf("Number of failed time-steps %d\n", stats.nfail); + printf("Total updates took %g secs\n", tm_total_sec); for (int i = 0; i < num_patches; i++) { gkyl_fv_proj_release(mesh_pdata[i].fv_proj); @@ -608,7 +614,10 @@ gr_euler2d_run_single(int argc, char **argv, struct gr_euler2d_single_init* init euler_write_sol_block(buf, num_blocks, mesh_bdata); - printf("Total run-time: %g. Failed steps: %d\n", tm_total_sec, stats.nfail); + printf("\n"); + printf("Number of update calls %ld\n", (coarse_step - 1)); + printf("Number of failed time-steps %d\n", stats.nfail); + printf("Total updates took %g secs\n", tm_total_sec); for (int i = 0; i < num_blocks; i++) { gkyl_fv_proj_release(mesh_bdata[i].fv_proj); @@ -880,7 +889,10 @@ gr_euler2d_run_double(int argc, char **argv, struct gr_euler2d_double_init* init euler_write_sol_block(buf, num_blocks, mesh_bdata); - printf("Total run-time: %g. Failed steps: %d\n", tm_total_sec, stats.nfail); + printf("\n"); + printf("Number of update calls %ld\n", (coarse_step - 1)); + printf("Number of failed time-steps %d\n", stats.nfail); + printf("Total updates took %g secs\n", tm_total_sec); for (int i = 0; i < num_blocks; i++) { gkyl_fv_proj_release(mesh_bdata[i].fv_proj); diff --git a/amr/amr_core_ten_moment.c b/amr/amr_core_ten_moment.c index 0d85d89ee..dd908cfc5 100644 --- a/amr/amr_core_ten_moment.c +++ b/amr/amr_core_ten_moment.c @@ -254,7 +254,11 @@ ten_moment_1d_run_single(int argc, char **argv, struct ten_moment_1d_single_init five_moment_write_sol_patch(buf, num_patches, mesh_pdata); - printf("Total run-time: %g. Failed steps: %d\n", tm_total_sec, stats.nfail); + printf("\n"); + printf("Number of update calls %ld\n", (coarse_step - 1)); + printf("Number of failed time-steps %d\n", stats.nfail); + printf("Total updates took %g secs\n", tm_total_sec); + for (int i = 0; i < num_patches; i++) { gkyl_fv_proj_release(mesh_pdata[i].fv_proj_elc); gkyl_fv_proj_release(mesh_pdata[i].fv_proj_ion); @@ -575,7 +579,10 @@ ten_moment_2d_run_single(int argc, char **argv, struct ten_moment_2d_single_init five_moment_write_sol_block(buf, num_blocks, mesh_bdata); - printf("Total run-time: %g. Failed steps: %d\n", tm_total_sec, stats.nfail); + printf("\n"); + printf("Number of update calls %ld\n", (coarse_step - 1)); + printf("Number of failed time-steps %d\n", stats.nfail); + printf("Total updates took %g secs\n", tm_total_sec); for (int i = 0; i < num_blocks; i++) { gkyl_fv_proj_release(mesh_bdata[i].fv_proj_elc); @@ -951,7 +958,10 @@ ten_moment_2d_run_double(int argc, char **argv, struct ten_moment_2d_double_init five_moment_write_sol_block(buf, num_blocks, mesh_bdata); - printf("Total run-time: %g. Failed steps: %d\n", tm_total_sec, stats.nfail); + printf("\n"); + printf("Number of update calls %ld\n", (coarse_step - 1)); + printf("Number of failed time-steps %d\n", stats.nfail); + printf("Total updates took %g secs\n", tm_total_sec); for (int i = 0; i < num_blocks; i++) { gkyl_fv_proj_release(mesh_bdata[i].fv_proj_elc); diff --git a/amr/amr_patch_coupled.c b/amr/amr_patch_coupled.c index 64e3629b1..31a764b02 100644 --- a/amr/amr_patch_coupled.c +++ b/amr/amr_patch_coupled.c @@ -600,9 +600,9 @@ five_moment_update_patch_job_func_source(void* ctx) const struct gkyl_array *nT_source[2]; nT_source[0] = pdata->nT_source_elc; nT_source[1] = pdata->nT_source_ion; - - /*gkyl_moment_em_coupling_implicit_advance(pdata->src_slvr, t_curr, dt, &pdata->range, fluids, app_accel, rhs_source, - pdata->f_maxwell[nstrang], pdata->app_current, pdata->ext_em, nT_source);*/ + + gkyl_moment_em_coupling_implicit_advance(pdata->src_slvr, t_curr, dt, &pdata->range, fluids, app_accel, rhs_source, + pdata->f_maxwell[nstrang], pdata->app_current, pdata->ext_em, nT_source); five_moment_patch_bc_updaters_apply(pdata, t_curr, pdata->f_elc[nstrang], pdata->f_ion[nstrang], pdata->f_maxwell[nstrang]); } From b4a69148a0f63c9a8c6cfa9bac501d6c5a392939 Mon Sep 17 00:00:00 2001 From: JonathanGorard Date: Mon, 1 Jul 2024 14:11:30 -0400 Subject: [PATCH 25/32] Rearchitected the serial CI system to (hopefully) account for two things: the difference in output format for patch-structured/block-structured data from AMR simulations; and the fact that automatic memory error checking currently does not work correctly for GR simulations (due to the extremely large memory allocations and deallocations involved in defining and manipulating tensor data). Tried on a few simple example cases and it seemed to work just fine, but I'm currently in the processing of running the complete regression suite to confirm correctness, before moving on to parallelism. --- ci/moment_regression.c | 272 ++++++++++++++++++++++------------------- 1 file changed, 149 insertions(+), 123 deletions(-) diff --git a/ci/moment_regression.c b/ci/moment_regression.c index 0d882fdb3..9bdd77143 100644 --- a/ci/moment_regression.c +++ b/ci/moment_regression.c @@ -16,7 +16,7 @@ int system(const char *command); void -runTest(const char* test_name, const char* test_name_human, const int test_output_count, const char test_outputs[][64], const int test_amr) +runTest(const char* test_name, const char* test_name_human, const int test_output_count, const char test_outputs[][64], const int test_amr, const int test_gr) { int counter = 0; @@ -45,7 +45,14 @@ runTest(const char* test_name, const char* test_name_human, const int test_outpu system(command_buffer2); char command_buffer3[256]; - snprintf(command_buffer3, 256, "./build/regression/rt_%s -m > ./ci/output/rt_%s_%d.dat 2>&1", test_name, test_name, counter); + + if (test_gr == 0) { + snprintf(command_buffer3, 256, "./build/regression/rt_%s -m > ./ci/output/rt_%s_%d.dat 2>&1", test_name, test_name, counter); + } + else { + snprintf(command_buffer3, 256, "./build/regression/rt_%s > ./ci/output/rt_%s_%d.dat 2>&1", test_name, test_name, counter); + } + system(command_buffer3); if (test_amr == 0) { @@ -94,7 +101,8 @@ runTest(const char* test_name, const char* test_name_human, const int test_outpu } void -analyzeTestOutput(const char* test_name, const char* test_name_human, const int test_output_count, const char test_outputs[][64]) +analyzeTestOutput(const char* test_name, const char* test_name_human, const int test_output_count, const char test_outputs[][64], const int test_amr, + const int test_gr) { printf("%s:\n\n", test_name_human); @@ -177,67 +185,69 @@ analyzeTestOutput(const char* test_name, const char* test_name_human, const int failure[i] = 1; } - speciesupdate[i] = 0.0; - if (strstr(output, "Species updates took ") != NULL) { - char *full_substring = strstr(output, "Species updates took "); - char substring[64]; - for (int j = 0; j < 64; j++) { - substring[j] = '\0'; - } - int substring_index = 0; + if (test_amr == 0) { + speciesupdate[i] = 0.0; + if (strstr(output, "Species updates took ") != NULL) { + char *full_substring = strstr(output, "Species updates took "); + char substring[64]; + for (int j = 0; j < 64; j++) { + substring[j] = '\0'; + } + int substring_index = 0; - while (full_substring[substring_index + strlen("Species updates took ")] != '\n') { - substring[substring_index] = full_substring[substring_index + strlen("Species updates took ")]; - substring_index += 1; + while (full_substring[substring_index + strlen("Species updates took ")] != '\n') { + substring[substring_index] = full_substring[substring_index + strlen("Species updates took ")]; + substring_index += 1; + } + + char *end_ptr; + speciesupdate[i] = strtod(substring, &end_ptr); + } + else { + failure[i] = 1; } - char *end_ptr; - speciesupdate[i] = strtod(substring, &end_ptr); - } - else { - failure[i] = 1; - } + fieldupdate[i] = 0.0; + if (strstr(output, "Field updates took ") != NULL) { + char *full_substring = strstr(output, "Field updates took "); + char substring[64]; + for (int j = 0; j < 64; j++) { + substring[j] = '\0'; + } + int substring_index = 0; - fieldupdate[i] = 0.0; - if (strstr(output, "Field updates took ") != NULL) { - char *full_substring = strstr(output, "Field updates took "); - char substring[64]; - for (int j = 0; j < 64; j++) { - substring[j] = '\0'; - } - int substring_index = 0; + while (full_substring[substring_index + strlen("Field updates took ")] != '\n') { + substring[substring_index] = full_substring[substring_index + strlen("Field updates took ")]; + substring_index += 1; + } - while (full_substring[substring_index + strlen("Field updates took ")] != '\n') { - substring[substring_index] = full_substring[substring_index + strlen("Field updates took ")]; - substring_index += 1; + char *end_ptr; + fieldupdate[i] = strtod(substring, &end_ptr); + } + else { + failure[i] = 1; } - char *end_ptr; - fieldupdate[i] = strtod(substring, &end_ptr); - } - else { - failure[i] = 1; - } + sourceupdate[i] = 0.0; + if (strstr(output, "Source updates took ") != NULL) { + char *full_substring = strstr(output, "Source updates took "); + char substring[64]; + for (int j = 0; j < 64; j++) { + substring[j] = '\0'; + } + int substring_index = 0; - sourceupdate[i] = 0.0; - if (strstr(output, "Source updates took ") != NULL) { - char *full_substring = strstr(output, "Source updates took "); - char substring[64]; - for (int j = 0; j < 64; j++) { - substring[j] = '\0'; - } - int substring_index = 0; + while (full_substring[substring_index + strlen("Source updates took ")] != '\n') { + substring[substring_index] = full_substring[substring_index + strlen("Source updates took ")]; + substring_index += 1; + } - while (full_substring[substring_index + strlen("Source updates took ")] != '\n') { - substring[substring_index] = full_substring[substring_index + strlen("Source updates took ")]; - substring_index += 1; + char *end_ptr; + sourceupdate[i] = strtod(substring, &end_ptr); + } + else { + failure[i] = 1; } - - char *end_ptr; - sourceupdate[i] = strtod(substring, &end_ptr); - } - else { - failure[i] = 1; } totalupdate[i] = 0.0; @@ -261,7 +271,7 @@ analyzeTestOutput(const char* test_name, const char* test_name_human, const int failure[i] = 1; } - if (failure[i] == 0) { + if (failure[i] == 0 && test_gr == 0) { char *temp = output; memoryleakcount[i] = 0; memoryleaks[i] = (char*)calloc(8192, sizeof(char)); @@ -344,15 +354,22 @@ analyzeTestOutput(const char* test_name, const char* test_name_human, const int if (i == 1 || failure[i - 1] == 1) { printf("Update calls: %d\n", updatecalls[i]); printf("Failed time-steps: %d\n", failedsteps[i]); - printf("Species update time: %f\n", speciesupdate[i]); - printf("Field update time: %f\n", fieldupdate[i]); - printf("Source update time: %f\n", sourceupdate[i]); - printf("Total update time: %f\n", totalupdate[i]); - if (memoryleakcount[i] != 0) { - printf("Memory leaks: " ANSI_COLOR_RED "%s" ANSI_COLOR_RESET "\n", memoryleaks[i]); + + if (test_amr == 0) { + printf("Species update time: %f\n", speciesupdate[i]); + printf("Field update time: %f\n", fieldupdate[i]); + printf("Source update time: %f\n", sourceupdate[i]); } - else { - printf("Memory leaks: " ANSI_COLOR_GREEN "None" ANSI_COLOR_RESET "\n"); + + printf("Total update time: %f\n", totalupdate[i]); + + if (test_gr == 0) { + if (memoryleakcount[i] != 0) { + printf("Memory leaks: " ANSI_COLOR_RED "%s" ANSI_COLOR_RESET "\n", memoryleaks[i]); + } + else { + printf("Memory leaks: " ANSI_COLOR_GREEN "None" ANSI_COLOR_RESET "\n"); + } } printf("Correct: N/A\n\n"); } @@ -371,59 +388,61 @@ analyzeTestOutput(const char* test_name, const char* test_name_human, const int printf("Failed time-steps: " ANSI_COLOR_GREEN "%d" ANSI_COLOR_RESET "\n", failedsteps[i]); } - if (speciesupdate[i] > speciesupdate[i - 1]) { - if (speciesupdate[i - 1] > pow(10.0, -8.0)) { - printf("Species update time: " ANSI_COLOR_RED "%f (+%.2f%%)" ANSI_COLOR_RESET "\n", speciesupdate[i], - (((double)speciesupdate[i] / (double)speciesupdate[i - 1]) - 1.0) * 100.0); - } else { - printf("Species update time: " ANSI_COLOR_RED "%f (N/A)" ANSI_COLOR_RESET "\n", speciesupdate[i]); - } - } - else { - if (speciesupdate[i - 1] > pow(10.0, -8.0)) { - printf("Species update time: " ANSI_COLOR_GREEN "%f (%.2f%%)" ANSI_COLOR_RESET "\n", speciesupdate[i], - (((double)speciesupdate[i] / (double)speciesupdate[i - 1]) - 1.0) * 100.0); + if (test_amr == 0) { + if (speciesupdate[i] > speciesupdate[i - 1]) { + if (speciesupdate[i - 1] > pow(10.0, -8.0)) { + printf("Species update time: " ANSI_COLOR_RED "%f (+%.2f%%)" ANSI_COLOR_RESET "\n", speciesupdate[i], + (((double)speciesupdate[i] / (double)speciesupdate[i - 1]) - 1.0) * 100.0); + } else { + printf("Species update time: " ANSI_COLOR_RED "%f (N/A)" ANSI_COLOR_RESET "\n", speciesupdate[i]); + } } else { - printf("Species update time: " ANSI_COLOR_GREEN "%f (N/A)" ANSI_COLOR_RESET "\n", speciesupdate[i]); + if (speciesupdate[i - 1] > pow(10.0, -8.0)) { + printf("Species update time: " ANSI_COLOR_GREEN "%f (%.2f%%)" ANSI_COLOR_RESET "\n", speciesupdate[i], + (((double)speciesupdate[i] / (double)speciesupdate[i - 1]) - 1.0) * 100.0); + } + else { + printf("Species update time: " ANSI_COLOR_GREEN "%f (N/A)" ANSI_COLOR_RESET "\n", speciesupdate[i]); + } } - } - if (fieldupdate[i] > fieldupdate[i - 1]) { - if (fieldupdate[i - 1] > pow(10.0, -8.0)) { - printf("Field update time: " ANSI_COLOR_RED "%f (+%.2f%%)" ANSI_COLOR_RESET "\n", fieldupdate[i], - (((double)fieldupdate[i] / (double)fieldupdate[i - 1]) - 1.0) * 100.0); - } - else { - printf("Field update time: " ANSI_COLOR_RED "%f (N/A)" ANSI_COLOR_RESET, fieldupdate[i]); - } - } - else { - if (fieldupdate[i - 1] > pow(10.0, -8.0)) { - printf("Field update time: " ANSI_COLOR_GREEN "%f (%.2f%%)" ANSI_COLOR_RESET "\n", fieldupdate[i], - (((double)fieldupdate[i] / (double)fieldupdate[i - 1]) - 1.0) * 100.0); + if (fieldupdate[i] > fieldupdate[i - 1]) { + if (fieldupdate[i - 1] > pow(10.0, -8.0)) { + printf("Field update time: " ANSI_COLOR_RED "%f (+%.2f%%)" ANSI_COLOR_RESET "\n", fieldupdate[i], + (((double)fieldupdate[i] / (double)fieldupdate[i - 1]) - 1.0) * 100.0); + } + else { + printf("Field update time: " ANSI_COLOR_RED "%f (N/A)" ANSI_COLOR_RESET, fieldupdate[i]); + } } else { - printf("Field update time: " ANSI_COLOR_GREEN "%f (N/A)" ANSI_COLOR_RESET "\n", fieldupdate[i]); + if (fieldupdate[i - 1] > pow(10.0, -8.0)) { + printf("Field update time: " ANSI_COLOR_GREEN "%f (%.2f%%)" ANSI_COLOR_RESET "\n", fieldupdate[i], + (((double)fieldupdate[i] / (double)fieldupdate[i - 1]) - 1.0) * 100.0); + } + else { + printf("Field update time: " ANSI_COLOR_GREEN "%f (N/A)" ANSI_COLOR_RESET "\n", fieldupdate[i]); + } } - } - if (sourceupdate[i] > sourceupdate[i - 1]) { - if (sourceupdate[i - 1] > pow(10.0, -8.0)) { - printf("Source update time: " ANSI_COLOR_RED "%f (+%.2f%%)" ANSI_COLOR_RESET "\n", sourceupdate[i], - (((double)sourceupdate[i] / (double)sourceupdate[i - 1]) - 1.0) * 100.0); - } - else { - printf("Source update time: " ANSI_COLOR_RED "%f (N/A)" ANSI_COLOR_RESET "\n", sourceupdate[i]); - } - } - else { - if (sourceupdate[i - 1] > pow(10.0, -8.0)) { - printf("Source update time: " ANSI_COLOR_GREEN "%f (%.2f%%)" ANSI_COLOR_RESET "\n", sourceupdate[i], - (((double)sourceupdate[i] / (double)sourceupdate[i - 1]) - 1.0) * 100.0); + if (sourceupdate[i] > sourceupdate[i - 1]) { + if (sourceupdate[i - 1] > pow(10.0, -8.0)) { + printf("Source update time: " ANSI_COLOR_RED "%f (+%.2f%%)" ANSI_COLOR_RESET "\n", sourceupdate[i], + (((double)sourceupdate[i] / (double)sourceupdate[i - 1]) - 1.0) * 100.0); + } + else { + printf("Source update time: " ANSI_COLOR_RED "%f (N/A)" ANSI_COLOR_RESET "\n", sourceupdate[i]); + } } else { - printf("Source update time: " ANSI_COLOR_GREEN "%f (N/A)" ANSI_COLOR_RESET "\n", sourceupdate[i]); + if (sourceupdate[i - 1] > pow(10.0, -8.0)) { + printf("Source update time: " ANSI_COLOR_GREEN "%f (%.2f%%)" ANSI_COLOR_RESET "\n", sourceupdate[i], + (((double)sourceupdate[i] / (double)sourceupdate[i - 1]) - 1.0) * 100.0); + } + else { + printf("Source update time: " ANSI_COLOR_GREEN "%f (N/A)" ANSI_COLOR_RESET "\n", sourceupdate[i]); + } } } @@ -446,11 +465,13 @@ analyzeTestOutput(const char* test_name, const char* test_name_human, const int } } - if (memoryleakcount[i] != 0) { - printf("Memory leaks: " ANSI_COLOR_RED "%s" ANSI_COLOR_RESET "\n", memoryleaks[i]); - } - else { - printf("Memory leaks: " ANSI_COLOR_GREEN "None" ANSI_COLOR_RESET "\n"); + if (test_gr == 0) { + if (memoryleakcount[i] != 0) { + printf("Memory leaks: " ANSI_COLOR_RED "%s" ANSI_COLOR_RESET "\n", memoryleaks[i]); + } + else { + printf("Memory leaks: " ANSI_COLOR_GREEN "None" ANSI_COLOR_RESET "\n"); + } } int correct = 1; @@ -808,6 +829,9 @@ main(int argc, char **argv) int test_amr[86] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; + int test_gr[86] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 }; system("clear"); system("mkdir -p ci/output"); @@ -819,12 +843,12 @@ main(int argc, char **argv) if (strtol(argv[1], &arg_ptr, 10) == 1) { for (int i = 0; i < test_count; i++) { - runTest(test_names[i], test_names_human[i], test_output_count[i], test_outputs[i], test_amr[i]); + runTest(test_names[i], test_names_human[i], test_output_count[i], test_outputs[i], test_amr[i], test_gr[i]); } } else if (strtol(argv[1], &arg_ptr, 10) == 2) { for (int i = 0; i < test_count; i++) { - analyzeTestOutput(test_names[i], test_names_human[i], test_output_count[i], test_outputs[i]); + analyzeTestOutput(test_names[i], test_names_human[i], test_output_count[i], test_outputs[i], test_amr[i], test_gr[i]); } } else if (strtol(argv[1], &arg_ptr, 10) == 3) { @@ -832,7 +856,7 @@ main(int argc, char **argv) if (strtol(argv[2], &arg_ptr, 10) >= 1 && strtol(argv[2], &arg_ptr, 10) <= test_count) { runTest(test_names[strtol(argv[2], &arg_ptr, 10) - 1], test_names_human[strtol(argv[2], &arg_ptr, 10) - 1], test_output_count[strtol(argv[2], &arg_ptr, 10) - 1], test_outputs[strtol(argv[2], &arg_ptr, 10) - 1], - test_amr[strtol(argv[2], &arg_ptr, 10) - 1]); + test_amr[strtol(argv[2], &arg_ptr, 10) - 1], test_gr[strtol(argv[2], &arg_ptr, 10) - 1]); } else { printf("Invalid test!\n"); @@ -846,7 +870,8 @@ main(int argc, char **argv) if (argc > 2) { if (strtol(argv[2], &arg_ptr, 10) >= 1 && strtol(argv[2], &arg_ptr, 10) <= test_count) { analyzeTestOutput(test_names[strtol(argv[2], &arg_ptr, 10) - 1], test_names_human[strtol(argv[2], &arg_ptr, 10) - 1], - test_output_count[strtol(argv[2], &arg_ptr, 10) - 1], test_outputs[strtol(argv[2], &arg_ptr, 10) - 1]); + test_output_count[strtol(argv[2], &arg_ptr, 10) - 1], test_outputs[strtol(argv[2], &arg_ptr, 10) - 1], + test_amr[strtol(argv[2], &arg_ptr, 10) - 1], test_gr[strtol(argv[2], &arg_ptr, 10) - 1]); } else { printf("Invalid test!\n"); @@ -859,7 +884,7 @@ main(int argc, char **argv) else if (strtol(argv[1], &arg_ptr, 10) == 5) { for (int i = 0; i < test_count; i++) { regenerateTest(test_names[i], test_output_count[i], test_outputs[i]); - runTest(test_names[i], test_names_human[i], test_output_count[i], test_outputs[i], test_amr[i]); + runTest(test_names[i], test_names_human[i], test_output_count[i], test_outputs[i], test_amr[i], test_gr[i]); } } else if (strtol(argv[1], &arg_ptr, 10) == 6) { @@ -869,7 +894,7 @@ main(int argc, char **argv) test_outputs[strtol(argv[2], &arg_ptr, 10) - 1]); runTest(test_names[strtol(argv[2], &arg_ptr, 10) - 1], test_names_human[strtol(argv[2], &arg_ptr, 10) - 1], test_output_count[strtol(argv[2], &arg_ptr, 10) - 1], test_outputs[strtol(argv[2], &arg_ptr, 10) - 1], - test_amr[strtol(argv[2], &arg_ptr, 10) - 1]); + test_amr[strtol(argv[2], &arg_ptr, 10) - 1], test_gr[strtol(argv[2], &arg_ptr, 10) - 1]); } else { printf("Invalid test!\n"); @@ -900,12 +925,12 @@ main(int argc, char **argv) if (option == 1) { for (int i = 0; i < test_count; i++) { - runTest(test_names[i], test_names_human[i], test_output_count[i], test_outputs[i], test_amr[i]); + runTest(test_names[i], test_names_human[i], test_output_count[i], test_outputs[i], test_amr[i], test_gr[i]); } } else if (option == 2) { for (int i = 0; i < test_count; i++) { - analyzeTestOutput(test_names[i], test_names_human[i], test_output_count[i], test_outputs[i]); + analyzeTestOutput(test_names[i], test_names_human[i], test_output_count[i], test_outputs[i], test_amr[i], test_gr[i]); } } else if (option == 3) { @@ -920,7 +945,7 @@ main(int argc, char **argv) if (option2 >= 1 && option2 <= test_count) { runTest(test_names[option2 - 1], test_names_human[option2 - 1], test_output_count[option2 - 1], test_outputs[option2 - 1], - test_amr[option2 - 1]); + test_amr[option2 - 1], test_gr[option2 - 1]); } else { printf("Invalid test!\n\n"); @@ -937,7 +962,8 @@ main(int argc, char **argv) printf("\n"); if (option2 >= 1 && option2 <= test_count) { - analyzeTestOutput(test_names[option2 - 1], test_names_human[option2 - 1], test_output_count[option2 - 1], test_outputs[option2 - 1]); + analyzeTestOutput(test_names[option2 - 1], test_names_human[option2 - 1], test_output_count[option2 - 1], test_outputs[option2 - 1], + test_amr[option2 - 1], test_gr[option2 - 1]); } else { printf("Invalid test!\n\n"); @@ -946,7 +972,7 @@ main(int argc, char **argv) else if (option == 5) { for (int i = 0; i < test_count; i++) { regenerateTest(test_names[i], test_output_count[i], test_outputs[i]); - runTest(test_names[i], test_names_human[i], test_output_count[i], test_outputs[i], test_amr[i]); + runTest(test_names[i], test_names_human[i], test_output_count[i], test_outputs[i], test_amr[i], test_gr[i]); } } else if (option == 6) { @@ -962,7 +988,7 @@ main(int argc, char **argv) if (option2 >= 1 && option2 <= test_count) { regenerateTest(test_names[option2 - 1], test_output_count[option2 - 1], test_outputs[option2 - 1]); runTest(test_names[option2 - 1], test_names_human[option2 - 1], test_output_count[option2 - 1], test_outputs[option2 - 1], - test_amr[option2 - 1]); + test_amr[option2 - 1], test_gr[option2 - 1]); } else { printf("Invalid test!\n\n"); From 1406c482b4ce538ad88dd82980f2a2a0249eab54 Mon Sep 17 00:00:00 2001 From: JonathanGorard Date: Mon, 1 Jul 2024 15:05:35 -0400 Subject: [PATCH 26/32] First pass at extending the parallel CI system to deal with AMR and GR simulations (it builds, but has not yet been tested on Stellar), including appropriate modifications to handle thread-based parallelism with multi-blocks. --- ci/moment_regression.c | 2 +- ci/moment_regression_parallel.c | 519 +++++++++++++++++++++++--------- 2 files changed, 371 insertions(+), 150 deletions(-) diff --git a/ci/moment_regression.c b/ci/moment_regression.c index 9bdd77143..ce89185f0 100644 --- a/ci/moment_regression.c +++ b/ci/moment_regression.c @@ -702,7 +702,7 @@ main(int argc, char **argv) "Generalized Brio-Wu Riemann Problem Test with Level-1 Patch-Structured AMR (5-moment equations)", "Generalized Brio-Wu Riemann Problem Test with Level-2 Patch-Structured AMR (5-moment equations)", "Geospace Environment Modeling Reconnection Test with Level-1 Block-Structured AMR (5-moment equations)", - "Geospace Environment Modeling Reconnection Test with Level-2 Block-Strutcured AMR (5-moment equations)", + "Geospace Environment Modeling Reconnection Test with Level-2 Block-Structured AMR (5-moment equations)", "Geospace Environment Modeling Reconnection Test with Level-1 Block-Structured AMR (10-moment equations)", "Geospace Environment Modeling Reconnection Test with Level-2 Block-Structured AMR (10-moment equations)", }; diff --git a/ci/moment_regression_parallel.c b/ci/moment_regression_parallel.c index 5ae68742b..cdcc454bb 100644 --- a/ci/moment_regression_parallel.c +++ b/ci/moment_regression_parallel.c @@ -17,7 +17,7 @@ int system(const char *command); void runTestParallel(const char* test_name, const char* test_name_human, const int test_dimensions, const int test_cuts, - const int test_output_count, const char test_outputs[][64]) + const int test_output_count, const char test_outputs[][64], const int test_amr, const int test_gr) { int counter = 0; @@ -46,42 +46,88 @@ runTestParallel(const char* test_name, const char* test_name_human, const int te system(command_buffer2); char command_buffer3[256]; - if (test_dimensions == 1) { - snprintf(command_buffer3, 256, "mpirun -np %d ./cuda-build/regression/rt_%s -m -M -c %d > ./ci/output_parallel/rt_%s_%d.dat 2>&1", - test_cuts, test_name, test_cuts, test_name, counter); - } - else if (test_dimensions == 2) { - snprintf(command_buffer3, 256, "mpirun -np %d ./cuda-build/regression/rt_%s -m -M -c %d -d %d > ./ci/output_parallel/rt_%s_%d.dat 2>&1", - test_cuts * test_cuts, test_name, test_cuts, test_cuts, test_name, counter); + + if (test_amr == 0) { + if (test_gr == 0) { + if (test_dimensions == 1) { + snprintf(command_buffer3, 256, "mpirun -np %d ./cuda-build/regression/rt_%s -m -M -c %d > ./ci/output_parallel/rt_%s_%d.dat 2>&1", + test_cuts, test_name, test_cuts, test_name, counter); + } + else if (test_dimensions == 2) { + snprintf(command_buffer3, 256, "mpirun -np %d ./cuda-build/regression/rt_%s -m -M -c %d -d %d > ./ci/output_parallel/rt_%s_%d.dat 2>&1", + test_cuts * test_cuts, test_name, test_cuts, test_cuts, test_name, counter); + } + else if (test_dimensions == 3) { + snprintf(command_buffer3, 256, "mpirun -np %d ./cuda-build/regression/rt_%s -m -M -c %d -d %d -e %d > ./ci/output_parallel/rt_%s_%d.dat 2>&1", + test_cuts * test_cuts * test_cuts, test_name, test_cuts, test_cuts, test_cuts, test_name, counter); + } + } + else { + if (test_dimensions == 1) { + snprintf(command_buffer3, 256, "mpirun -np %d ./cuda-build/regression/rt_%s -M -c %d > ./ci/output_parallel/rt_%s_%d.dat 2>&1", + test_cuts, test_name, test_cuts, test_name, counter); + } + else if (test_dimensions == 2) { + snprintf(command_buffer3, 256, "mpirun -np %d ./cuda-build/regression/rt_%s -M -c %d -d %d > ./ci/output_parallel/rt_%s_%d.dat 2>&1", + test_cuts * test_cuts, test_name, test_cuts, test_cuts, test_name, counter); + } + else if (test_dimensions == 3) { + snprintf(command_buffer3, 256, "mpirun -np %d ./cuda-build/regression/rt_%s -M -c %d -d %d -e %d > ./ci/output_parallel/rt_%s_%d.dat 2>&1", + test_cuts * test_cuts * test_cuts, test_name, test_cuts, test_cuts, test_cuts, test_name, counter); + } + } } - else if (test_dimensions == 3) { - snprintf(command_buffer3, 256, "mpirun -np %d ./cuda-build/regression/rt_%s -m -M -c %d -d %d -e %d > ./ci/output_parallel/rt_%s_%d.dat 2>&1", - test_cuts * test_cuts * test_cuts, test_name, test_cuts, test_cuts, test_cuts, test_name, counter); + else { + if (test_gr == 0) { + snprintf(command_buffer3, 256, "mpirun -np 1 ./cuda-build/regression/rt_%s -m -M -t 100 > ./ci/output_parallel/rt_%s_%d.dat 2>&1", + test_name, test_name, counter); + } + else { + snprintf(command_buffer3, 256, "mpirun -np 1 ./cuda-build/regression/rt_%s -M -t 100 > ./ci/output_parallel/rt_%s_%d.dat 2>&1", + test_name, test_name, counter); + } } + system(command_buffer3); - char file_buffer1[128]; - snprintf(file_buffer1, 128, "./%s-stat.json", test_name); - FILE *file_ptr1 = fopen(file_buffer1, "r"); - if (file_ptr1 == NULL) { - printf("*** Something catastrophic happened. Test aborting... ***\n"); - } - else { - char command_buffer4[256]; - snprintf(command_buffer4, 256, "mv ./%s-stat.json ci/output_parallel/%s-stat_%d.json", test_name, test_name, counter); - system(command_buffer4); + if (test_amr == 0) { + char file_buffer1[128]; + snprintf(file_buffer1, 128, "./%s-stat.json", test_name); + FILE *file_ptr1 = fopen(file_buffer1, "r"); + if (file_ptr1 == NULL) { + printf("*** Something catastrophic happened. Test aborting... ***\n"); + } + else { + char command_buffer4[256]; + snprintf(command_buffer4, 256, "mv ./%s-stat.json ci/output_parallel/%s-stat_%d.json", test_name, test_name, counter); + system(command_buffer4); + } } for (int i = 0; i < test_output_count; i++) { char file_buffer2[128]; - snprintf(file_buffer2, 128, "./%s-%s.gkyl", test_name, test_outputs[i]); + + if (test_amr == 0) { + snprintf(file_buffer2, 128, "./%s-%s.gkyl", test_name, test_outputs[i]); + } + else { + snprintf(file_buffer2, 128, "./%s_%s.gkyl", test_name, test_outputs[i]); + } + FILE *file_ptr2 = fopen(file_buffer2, "r"); if (file_ptr2 == NULL) { printf("*** Something catastrophic happened. Test aborting... ***\n"); } else { char command_buffer5[256]; - snprintf(command_buffer5, 256, "mv ./%s-%s.gkyl ci/output_parallel/%s-%s_%d.gkyl", test_name, test_outputs[i], test_name, test_outputs[i], counter); + + if (test_amr == 0) { + snprintf(command_buffer5, 256, "mv ./%s-%s.gkyl ci/output_parallel/%s-%s_%d.gkyl", test_name, test_outputs[i], test_name, test_outputs[i], counter); + } + else { + snprintf(command_buffer5, 256, "mv ./%s_%s.gkyl ci/output_parallel/%s-%s_%d.gkyl", test_name, test_outputs[i], test_name, test_outputs[i], counter); + } + system(command_buffer5); } } @@ -90,7 +136,8 @@ runTestParallel(const char* test_name, const char* test_name_human, const int te } void -analyzeTestOutputParallel(const char* test_name, const char* test_name_human, const int test_output_count, const char test_outputs[][64]) +analyzeTestOutputParallel(const char* test_name, const char* test_name_human, const int test_output_count, const char test_outputs[][64], const int test_amr, + const int test_gr) { printf("%s:\n\n", test_name_human); @@ -173,67 +220,69 @@ analyzeTestOutputParallel(const char* test_name, const char* test_name_human, co failure[i] = 1; } - speciesupdate[i] = 0.0; - if (strstr(output, "Species updates took ") != NULL) { - char *full_substring = strstr(output, "Species updates took "); - char substring[64]; - for (int j = 0; j < 64; j++) { - substring[j] = '\0'; - } - int substring_index = 0; + if (test_amr == 0) { + speciesupdate[i] = 0.0; + if (strstr(output, "Species updates took ") != NULL) { + char *full_substring = strstr(output, "Species updates took "); + char substring[64]; + for (int j = 0; j < 64; j++) { + substring[j] = '\0'; + } + int substring_index = 0; - while (full_substring[substring_index + strlen("Species updates took ")] != '\n') { - substring[substring_index] = full_substring[substring_index + strlen("Species updates took ")]; - substring_index += 1; + while (full_substring[substring_index + strlen("Species updates took ")] != '\n') { + substring[substring_index] = full_substring[substring_index + strlen("Species updates took ")]; + substring_index += 1; + } + + char *end_ptr; + speciesupdate[i] = strtod(substring, &end_ptr); + } + else { + failure[i] = 1; } - char *end_ptr; - speciesupdate[i] = strtod(substring, &end_ptr); - } - else { - failure[i] = 1; - } + fieldupdate[i] = 0.0; + if (strstr(output, "Field updates took ") != NULL) { + char *full_substring = strstr(output, "Field updates took "); + char substring[64]; + for (int j = 0; j < 64; j++) { + substring[j] = '\0'; + } + int substring_index = 0; - fieldupdate[i] = 0.0; - if (strstr(output, "Field updates took ") != NULL) { - char *full_substring = strstr(output, "Field updates took "); - char substring[64]; - for (int j = 0; j < 64; j++) { - substring[j] = '\0'; - } - int substring_index = 0; + while (full_substring[substring_index + strlen("Field updates took ")] != '\n') { + substring[substring_index] = full_substring[substring_index + strlen("Field updates took ")]; + substring_index += 1; + } - while (full_substring[substring_index + strlen("Field updates took ")] != '\n') { - substring[substring_index] = full_substring[substring_index + strlen("Field updates took ")]; - substring_index += 1; + char *end_ptr; + fieldupdate[i] = strtod(substring, &end_ptr); + } + else { + failure[i] = 1; } - char *end_ptr; - fieldupdate[i] = strtod(substring, &end_ptr); - } - else { - failure[i] = 1; - } + sourceupdate[i] = 0.0; + if (strstr(output, "Source updates took ") != NULL) { + char *full_substring = strstr(output, "Source updates took "); + char substring[64]; + for (int j = 0; j < 64; j++) { + substring[j] = '\0'; + } + int substring_index = 0; - sourceupdate[i] = 0.0; - if (strstr(output, "Source updates took ") != NULL) { - char *full_substring = strstr(output, "Source updates took "); - char substring[64]; - for (int j = 0; j < 64; j++) { - substring[j] = '\0'; - } - int substring_index = 0; + while (full_substring[substring_index + strlen("Source updates took ")] != '\n') { + substring[substring_index] = full_substring[substring_index + strlen("Source updates took ")]; + substring_index += 1; + } - while (full_substring[substring_index + strlen("Source updates took ")] != '\n') { - substring[substring_index] = full_substring[substring_index + strlen("Source updates took ")]; - substring_index += 1; + char *end_ptr; + sourceupdate[i] = strtod(substring, &end_ptr); + } + else { + failure[i] = 1; } - - char *end_ptr; - sourceupdate[i] = strtod(substring, &end_ptr); - } - else { - failure[i] = 1; } totalupdate[i] = 0.0; @@ -257,7 +306,7 @@ analyzeTestOutputParallel(const char* test_name, const char* test_name_human, co failure[i] = 1; } - if (failure[i] == 0) { + if (failure[i] == 0 && test_gr == 0) { char *temp = output; memoryleakcount[i] = 0; memoryleaks[i] = (char*)calloc(8192, sizeof(char)); @@ -340,10 +389,15 @@ analyzeTestOutputParallel(const char* test_name, const char* test_name_human, co if (i == 1 || failure[i - 1] == 1) { printf("Update calls: %d\n", updatecalls[i]); printf("Failed time-steps: %d\n", failedsteps[i]); - printf("Species update time: %f\n", speciesupdate[i]); - printf("Field update time: %f\n", fieldupdate[i]); - printf("Source update time: %f\n", sourceupdate[i]); + + if (test_amr == 0) { + printf("Species update time: %f\n", speciesupdate[i]); + printf("Field update time: %f\n", fieldupdate[i]); + printf("Source update time: %f\n", sourceupdate[i]); + } + printf("Total update time: %f\n", totalupdate[i]); + if (memoryleakcount[i] != 0) { printf("Memory leaks: " ANSI_COLOR_RED "%s" ANSI_COLOR_RESET "\n", memoryleaks[i]); } @@ -367,59 +421,61 @@ analyzeTestOutputParallel(const char* test_name, const char* test_name_human, co printf("Failed time-steps: " ANSI_COLOR_GREEN "%d" ANSI_COLOR_RESET "\n", failedsteps[i]); } - if (speciesupdate[i] > speciesupdate[i - 1]) { - if (speciesupdate[i - 1] > pow(10.0, -8.0)) { - printf("Species update time: " ANSI_COLOR_RED "%f (+%.2f%%)" ANSI_COLOR_RESET "\n", speciesupdate[i], - (((double)speciesupdate[i] / (double)speciesupdate[i - 1]) - 1.0) * 100.0); - } else { - printf("Species update time: " ANSI_COLOR_RED "%f (N/A)" ANSI_COLOR_RESET "\n", speciesupdate[i]); - } - } - else { - if (speciesupdate[i - 1] > pow(10.0, -8.0)) { - printf("Species update time: " ANSI_COLOR_GREEN "%f (%.2f%%)" ANSI_COLOR_RESET "\n", speciesupdate[i], - (((double)speciesupdate[i] / (double)speciesupdate[i - 1]) - 1.0) * 100.0); + if (test_amr == 0) { + if (speciesupdate[i] > speciesupdate[i - 1]) { + if (speciesupdate[i - 1] > pow(10.0, -8.0)) { + printf("Species update time: " ANSI_COLOR_RED "%f (+%.2f%%)" ANSI_COLOR_RESET "\n", speciesupdate[i], + (((double)speciesupdate[i] / (double)speciesupdate[i - 1]) - 1.0) * 100.0); + } else { + printf("Species update time: " ANSI_COLOR_RED "%f (N/A)" ANSI_COLOR_RESET "\n", speciesupdate[i]); + } } else { - printf("Species update time: " ANSI_COLOR_GREEN "%f (N/A)" ANSI_COLOR_RESET "\n", speciesupdate[i]); + if (speciesupdate[i - 1] > pow(10.0, -8.0)) { + printf("Species update time: " ANSI_COLOR_GREEN "%f (%.2f%%)" ANSI_COLOR_RESET "\n", speciesupdate[i], + (((double)speciesupdate[i] / (double)speciesupdate[i - 1]) - 1.0) * 100.0); + } + else { + printf("Species update time: " ANSI_COLOR_GREEN "%f (N/A)" ANSI_COLOR_RESET "\n", speciesupdate[i]); + } } - } - if (fieldupdate[i] > fieldupdate[i - 1]) { - if (fieldupdate[i - 1] > pow(10.0, -8.0)) { - printf("Field update time: " ANSI_COLOR_RED "%f (+%.2f%%)" ANSI_COLOR_RESET "\n", fieldupdate[i], - (((double)fieldupdate[i] / (double)fieldupdate[i - 1]) - 1.0) * 100.0); - } - else { - printf("Field update time: " ANSI_COLOR_RED "%f (N/A)" ANSI_COLOR_RESET, fieldupdate[i]); - } - } - else { - if (fieldupdate[i - 1] > pow(10.0, -8.0)) { - printf("Field update time: " ANSI_COLOR_GREEN "%f (%.2f%%)" ANSI_COLOR_RESET "\n", fieldupdate[i], - (((double)fieldupdate[i] / (double)fieldupdate[i - 1]) - 1.0) * 100.0); + if (fieldupdate[i] > fieldupdate[i - 1]) { + if (fieldupdate[i - 1] > pow(10.0, -8.0)) { + printf("Field update time: " ANSI_COLOR_RED "%f (+%.2f%%)" ANSI_COLOR_RESET "\n", fieldupdate[i], + (((double)fieldupdate[i] / (double)fieldupdate[i - 1]) - 1.0) * 100.0); + } + else { + printf("Field update time: " ANSI_COLOR_RED "%f (N/A)" ANSI_COLOR_RESET, fieldupdate[i]); + } } else { - printf("Field update time: " ANSI_COLOR_GREEN "%f (N/A)" ANSI_COLOR_RESET "\n", fieldupdate[i]); + if (fieldupdate[i - 1] > pow(10.0, -8.0)) { + printf("Field update time: " ANSI_COLOR_GREEN "%f (%.2f%%)" ANSI_COLOR_RESET "\n", fieldupdate[i], + (((double)fieldupdate[i] / (double)fieldupdate[i - 1]) - 1.0) * 100.0); + } + else { + printf("Field update time: " ANSI_COLOR_GREEN "%f (N/A)" ANSI_COLOR_RESET "\n", fieldupdate[i]); + } } - } - if (sourceupdate[i] > sourceupdate[i - 1]) { - if (sourceupdate[i - 1] > pow(10.0, -8.0)) { - printf("Source update time: " ANSI_COLOR_RED "%f (+%.2f%%)" ANSI_COLOR_RESET "\n", sourceupdate[i], - (((double)sourceupdate[i] / (double)sourceupdate[i - 1]) - 1.0) * 100.0); - } - else { - printf("Source update time: " ANSI_COLOR_RED "%f (N/A)" ANSI_COLOR_RESET "\n", sourceupdate[i]); - } - } - else { - if (sourceupdate[i - 1] > pow(10.0, -8.0)) { - printf("Source update time: " ANSI_COLOR_GREEN "%f (%.2f%%)" ANSI_COLOR_RESET "\n", sourceupdate[i], - (((double)sourceupdate[i] / (double)sourceupdate[i - 1]) - 1.0) * 100.0); + if (sourceupdate[i] > sourceupdate[i - 1]) { + if (sourceupdate[i - 1] > pow(10.0, -8.0)) { + printf("Source update time: " ANSI_COLOR_RED "%f (+%.2f%%)" ANSI_COLOR_RESET "\n", sourceupdate[i], + (((double)sourceupdate[i] / (double)sourceupdate[i - 1]) - 1.0) * 100.0); + } + else { + printf("Source update time: " ANSI_COLOR_RED "%f (N/A)" ANSI_COLOR_RESET "\n", sourceupdate[i]); + } } else { - printf("Source update time: " ANSI_COLOR_GREEN "%f (N/A)" ANSI_COLOR_RESET "\n", sourceupdate[i]); + if (sourceupdate[i - 1] > pow(10.0, -8.0)) { + printf("Source update time: " ANSI_COLOR_GREEN "%f (%.2f%%)" ANSI_COLOR_RESET "\n", sourceupdate[i], + (((double)sourceupdate[i] / (double)sourceupdate[i - 1]) - 1.0) * 100.0); + } + else { + printf("Source update time: " ANSI_COLOR_GREEN "%f (N/A)" ANSI_COLOR_RESET "\n", sourceupdate[i]); + } } } @@ -442,11 +498,13 @@ analyzeTestOutputParallel(const char* test_name, const char* test_name_human, co } } - if (memoryleakcount[i] != 0) { - printf("Memory leaks: " ANSI_COLOR_RED "%s" ANSI_COLOR_RESET "\n", memoryleaks[i]); - } - else { - printf("Memory leaks: " ANSI_COLOR_GREEN "None" ANSI_COLOR_RESET "\n"); + if (test_gr == 0) { + if (memoryleakcount[i] != 0) { + printf("Memory leaks: " ANSI_COLOR_RED "%s" ANSI_COLOR_RESET "\n", memoryleaks[i]); + } + else { + printf("Memory leaks: " ANSI_COLOR_GREEN "None" ANSI_COLOR_RESET "\n"); + } } int correct = 1; @@ -504,8 +562,8 @@ regenerateTestParallel(const char* test_name, const int test_output_count, const int main(int argc, char **argv) { - int test_count = 47 - 7; - char test_names[47 - 7][32] = { + int test_count = 86 - 7; + char test_names[86 - 7][32] = { "10m_burch", "10m_burch_grad_closure", "10m_gem", @@ -553,8 +611,47 @@ main(int argc, char **argv) "iso_euler_sodshock", "iso_euler_sodshock_lax", "iso_gem", + "gr_mild_shock", + "gr_strong_blast", + "gr_perturbed_density", + "gr_quadrants_2d", + "gr_kh_2d", + "gr_blackhole_static", + "gr_blackhole_spinning", + "gr_bhl_static", + "gr_bhl_spinning", + "amr_euler_sodshock_l1", + "amr_euler_sodshock_l2", + "amr_euler_cart_axi_sodshock_l1", + "amr_euler_cart_axi_sodshock_l2", + "amr_euler_riem_2d_l1", + "amr_euler_riem_2d_l2", + "amr_euler_shock_bubble_l1", + "amr_euler_shock_bubble_l2", + "amr_gr_mild_shock_l1", + "amr_gr_mild_shock_l2", + "amr_gr_strong_blast_l1", + "amr_gr_strong_blast_l2", + "amr_gr_perturbed_density_l1", + "amr_gr_perturbed_density_l2", + "amr_gr_quadrants_2d_l1", + "amr_gr_quadrants_2d_l2", + "amr_gr_blackhole_static_l1", + "amr_gr_blackhole_static_l2", + "amr_gr_blackhole_spinning_l1", + "amr_gr_blackhole_spinning_l2", + "amr_gr_bhl_static_l1", + "amr_gr_bhl_static_l2", + "amr_gr_bhl_spinning_l1", + "amr_gr_bhl_spinning_l2", + "amr_5m_riem_l1", + "amr_5m_riem_l2", + "amr_5m_gem_l1", + "amr_5m_gem_l2", + "amr_10m_gem_l1", + "amr_10m_gem_l2", }; - char test_names_human[47 - 7][128] = { + char test_names_human[86 - 7][256] = { "Burch et al. Magnetic Reconnection Test (10-moment equations)", "Burch et al. Magnetic Reconnection Gradient-Closure Test (10-moment equations)", "Geospace Environment Modeling Reconnection Test (10-moment equations)", @@ -602,14 +699,56 @@ main(int argc, char **argv) "Sod-Type Shock Tube Test, with Roe fluxes (isothermal Euler equations)", "Sod-Type Shock Tube Test, with Lax fluxes (isothermal Euler equations)", "Geospace Environment Modeling Reconnection Test (isothermal Euler equations)", + "Mildly Relativistic Blast Wave Test (general relativistic Euler equations)", + "Strongly Relativistic Blast Wave Test (general relativistic Euler equations)", + "Perturbed Density Test (general relativistic Euler equations)", + "2D Quadrants Test (general relativistic Euler equations)", + "2D Relativistic Kelvin-Helmholtz Instability Test (general relativistic Euler equations)", + "2D Ring-Accretion Problem onto a Static/Schwarzschild Black Hole (general relativistic Euler equations)", + "2D Ring-Accretion Problem onto a Spinning/Kerr Black Hole (general relativistic Euler equations)", + "2D Bondi-Hoyle-Lyttleton Accretion Problem onto a Static/Schwarzschild Black Hole (general relativistic Euler equations)", + "2D Bondi-Hoyle-Lyttleton Accretion Problem onto a Spinning/Kerr Black Hole (general relativistic Euler equations)", + "Sod-Type Shock Tube Test with Level-1 Patch-Structured AMR (Euler equations)", + "Sod-Type Shock Tube Test with Level-2 Patch-Structured AMR (Euler equations)", + "2D Sod-Type Shock Tube Test in Axial Symmetry with Level-1 Block-Structured AMR (Euler equations)", + "2D Sod-Type Shock Tube Test in Axial Symmetry with Level-2 Block-Structured AMR (Euler equations)", + "2D Riemann/quadrant Problem with Level-1 Block-Structured AMR (Euler equations)", + "2D Riemann/quadrant Problem with Level-2 Block-Structured AMR (Euler equations)", + "2D Shock Bubble Collapse Test with Level-1 Block-Structured AMR (Euler equations)", + "2D Shock Bubble Collapse Test with Level-2 Block-Structured AMR (Euler equations)", + "Mildly Relativistic Blast Wave Test with Level-1 Patch-Structured AMR (general relativistic Euler equations)", + "Mildly Relativistic Blast Wave Test with Level-2 Patch-Structured AMR (general relativistic Euler equations)", + "Strongly Relativistic Blast Wave Test with Level-1 Patch-Structured AMR (general relativistic Euler equations)", + "Strongly Relativistic Blast Wave Test with Level-2 Patch-Structured AMR (general relativistic Euler equations)", + "Perturbed Density Test with Level-1 Patch-Structured AMR (general relativistic Euler equations)", + "Perturbed Density Test with Level-2 Patch-Structured AMR (general relativistic Euler equations)", + "2D Quadrants Test with Level-1 Block-Structured AMR (general relativistic Euler equations)", + "2D Quadrants Test with Level-2 Block-Structured AMR (general relativistic Euler equations)", + "2D Ring-Accretion Problem onto a Static/Schwarzschild Black Hole with Level-1 Block-Structured AMR (general relativistic Euler equations)", + "2D Ring-Accretion Problem onto a Static/Schwarzschild Black Hole with Level-2 Block-Structured AMR (general relativistic Euler equations)", + "2D Ring-Accretion Problem onto a Spinning/Kerr Black Hole with Level-1 Block-Structured AMR (general relativistic Euler equations)", + "2D Ring-Accretion Problem onto a Spinning/Kerr Black Hole with Level-2 Block-Structured AMR (general relativistic Euler equations)", + "2D Bondi-Hoyle-Lyttleton Accretion Problem onto a Static/Schwarzschild Black Hole with Level-1 Block-Structured AMR (general relativistic Euler equations)", + "2D Bondi-Hoyle-Lyttleton Accretion Problem onto a Static/Schwarzschild Black Hole with Level-2 Block-Structured AMR (general relativistic Euler equations)", + "2D Bondi-Hoyle-Lyttleton Accretion Problem onto a Spinning/Kerr Black Hole with Level-1 Block-Structured AMR (general relativistic Euler equations)", + "2D Bondi-Hoyle-Lyttleton Accretion Problem onto a Spinning/Kerr Black Hole with Level-2 Block-Structured AMR (general relativistic Euler equations)", + "Generalized Brio-Wu Riemann Problem Test with Level-1 Patch-Structured AMR (5-moment equations)", + "Generalized Brio-Wu Riemann Problem Test with Level-2 Patch-Structured AMR (5-moment equations)", + "Geospace Environment Modeling Reconnection Test with Level-1 Block-Structured AMR (5-moment equations)", + "Geospace Environment Modeling Reconnection Test with Level-2 Block-Structured AMR (5-moment equations)", + "Geospace Environment Modeling Reconnection Test with Level-1 Block-Structured AMR (10-moment equations)", + "Geospace Environment Modeling Reconnection Test with Level-2 Block-Structured AMR (10-moment equations)", }; - int test_dimensions[47 - 7] = { 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 2, 2, 1, 1, 1, /*1,*/ 1, /*1,*/ 1, 1, 2, 2, 2, 1, 2, 2, 1, 1, 2, 2, 2, /*2,*/ 2, 3, 1, - 1, /*1,*/ 2, 1, 1, /*2,*/ /*2,*/ 2, /*2,*/ 1, 1, 2 }; - int test_cuts[47 - 7] = { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, /*4,*/ 4, /*4,*/ 4, 4, 4, 4, 5, 4, 4, 4, 5, 4, 4, 4, 4, /*4,*/ 4, 1, 4, 4, /*4,*/ - 5, 5, 4, /*5,*/ /*5,*/ 5, /*2,*/ 4, 4, 4 }; - int test_output_count[47 - 7] = { 4, 4, 4, 4, 4, 4, 4, 4, 1, 1, 4, 4, 3, 4, 1, /*1,*/ 1, /*1,*/ 3, 1, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, /*1,*/ 1, 1, - 1, 1, /*1,*/ 1, 1, 1, /*2,*/ /*1,*/ 1, /*2,*/ 1, 1, 4 }; - char test_outputs[47 - 7][64][64] = { + int test_dimensions[86 - 7] = { 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 2, 2, 1, 1, 1, /*1,*/ 1, /*1,*/ 1, 1, 2, 2, 2, 1, 2, 2, 1, 1, 2, 2, 2, /*2,*/ 2, 3, 1, + 1, /*1,*/ 2, 1, 1, /*2,*/ /*2,*/ 2, /*2,*/ 1, 1, 2, 1, 1, 1, 2, 2, 2, 2, 2, 2, 1, 1, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 1, 1, 2, 2, 2, 2 }; + int test_cuts[86 - 7] = { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, /*4,*/ 4, /*4,*/ 4, 4, 4, 4, 5, 4, 4, 4, 5, 4, 4, 4, 4, /*4,*/ 4, 1, 4, 4, /*4,*/ + 5, 5, 4, /*5,*/ /*5,*/ 5, /*2,*/ 4, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ,0, 0, 0, 0 ,0, 0, 0, + 0, 0, 0 }; + int test_output_count[86 - 7] = { 4, 4, 4, 4, 4, 4, 4, 4, 1, 1, 4, 4, 3, 4, 1, /*1,*/ 1, /*1,*/ 3, 1, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, /*1,*/ 1, 1, + 1, 1, /*1,*/ 1, 1, 1, /*2,*/ /*1,*/ 1, /*2,*/ 1, 1, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 5, 9, 25, 9, 25, 9, 25, 3, 5, 3, 5, 3, 5, 9, 25, 9, 25, 9, + 25, 9, 25, 9, 25, 9, 15, 27, 75, 27, 75 }; + char test_outputs[86 - 7][128][64] = { { "elc_1", "ion_1", "field_1", "ext_em_field_1" }, { "elc_1", "ion_1", "field_1", "ext_em_field_1" }, { "elc_1", "ion_1", "field_1", "ext_em_field_1" }, @@ -657,7 +796,81 @@ main(int argc, char **argv) { "iso_euler_1" }, { "iso_euler_1" }, { "elc_1", "ion_1", "field_1", "ext_em_field_1" }, + { "gr_euler_1" }, + { "gr_euler_1" }, + { "gr_euler_1" }, + { "gr_euler_1" }, + { "gr_euler_1" }, + { "gr_euler_1" }, + { "gr_euler_1" }, + { "gr_euler_1" }, + { "gr_euler_1" }, + { "1_p0", "1_p1", "1_p2" }, + { "1_p0", "1_p1", "1_p2", "1_p3", "1_p4" }, + { "1_b0", "1_b1", "1_b2", "1_b3", "1_b4", "1_b5", "1_b6", "1_b7", "1_b8" }, + { "1_b0", "1_b1", "1_b2", "1_b3", "1_b4", "1_b5", "1_b6", "1_b7", "1_b8", "1_b9", "1_b10", "1_b11", "1_b12", "1_b13", "1_b14", + "1_b15", "1_b16", "1_b17", "1_b18", "1_b19", "1_b20", "1_b21", "1_b22", "1_b23", "1_b24" }, + { "1_b0", "1_b1", "1_b2", "1_b3", "1_b4", "1_b5", "1_b6", "1_b7", "1_b8" }, + { "1_b0", "1_b1", "1_b2", "1_b3", "1_b4", "1_b5", "1_b6", "1_b7", "1_b8", "1_b9", "1_b10", "1_b11", "1_b12", "1_b13", "1_b14", + "1_b15", "1_b16", "1_b17", "1_b18", "1_b19", "1_b20", "1_b21", "1_b22", "1_b23", "1_b24" }, + { "1_b0", "1_b1", "1_b2", "1_b3", "1_b4", "1_b5", "1_b6", "1_b7", "1_b8" }, + { "1_b0", "1_b1", "1_b2", "1_b3", "1_b4", "1_b5", "1_b6", "1_b7", "1_b8", "1_b9", "1_b10", "1_b11", "1_b12", "1_b13", "1_b14", + "1_b15", "1_b16", "1_b17", "1_b18", "1_b19", "1_b20", "1_b21", "1_b22", "1_b23", "1_b24" }, + { "1_p0", "1_p1", "1_p2" }, + { "1_p0", "1_p1", "1_p2", "1_p3", "1_p4" }, + { "1_p0", "1_p1", "1_p2" }, + { "1_p0", "1_p1", "1_p2", "1_p3", "1_p4" }, + { "1_p0", "1_p1", "1_p2" }, + { "1_p0", "1_p1", "1_p2", "1_p3", "1_p4" }, + { "1_b0", "1_b1", "1_b2", "1_b3", "1_b4", "1_b5", "1_b6", "1_b7", "1_b8" }, + { "1_b0", "1_b1", "1_b2", "1_b3", "1_b4", "1_b5", "1_b6", "1_b7", "1_b8", "1_b9", "1_b10", "1_b11", "1_b12", "1_b13", "1_b14", + "1_b15", "1_b16", "1_b17", "1_b18", "1_b19", "1_b20", "1_b21", "1_b22", "1_b23", "1_b24" }, + { "1_b0", "1_b1", "1_b2", "1_b3", "1_b4", "1_b5", "1_b6", "1_b7", "1_b8" }, + { "1_b0", "1_b1", "1_b2", "1_b3", "1_b4", "1_b5", "1_b6", "1_b7", "1_b8", "1_b9", "1_b10", "1_b11", "1_b12", "1_b13", "1_b14", + "1_b15", "1_b16", "1_b17", "1_b18", "1_b19", "1_b20", "1_b21", "1_b22", "1_b23", "1_b24" }, + { "1_b0", "1_b1", "1_b2", "1_b3", "1_b4", "1_b5", "1_b6", "1_b7", "1_b8" }, + { "1_b0", "1_b1", "1_b2", "1_b3", "1_b4", "1_b5", "1_b6", "1_b7", "1_b8", "1_b9", "1_b10", "1_b11", "1_b12", "1_b13", "1_b14", + "1_b15", "1_b16", "1_b17", "1_b18", "1_b19", "1_b20", "1_b21", "1_b22", "1_b23", "1_b24" }, + { "1_b0", "1_b1", "1_b2", "1_b3", "1_b4", "1_b5", "1_b6", "1_b7", "1_b8" }, + { "1_b0", "1_b1", "1_b2", "1_b3", "1_b4", "1_b5", "1_b6", "1_b7", "1_b8", "1_b9", "1_b10", "1_b11", "1_b12", "1_b13", "1_b14", + "1_b15", "1_b16", "1_b17", "1_b18", "1_b19", "1_b20", "1_b21", "1_b22", "1_b23", "1_b24" }, + { "1_b0", "1_b1", "1_b2", "1_b3", "1_b4", "1_b5", "1_b6", "1_b7", "1_b8" }, + { "1_b0", "1_b1", "1_b2", "1_b3", "1_b4", "1_b5", "1_b6", "1_b7", "1_b8", "1_b9", "1_b10", "1_b11", "1_b12", "1_b13", "1_b14", + "1_b15", "1_b16", "1_b17", "1_b18", "1_b19", "1_b20", "1_b21", "1_b22", "1_b23", "1_b24" }, + { "1_elc_p0", "1_ion_p0", "1_field_p0", "1_elc_p1", "1_ion_p1", "1_field_p1", "1_elc_p2", "1_ion_p2", "1_field_p2", }, + { "1_elc_p0", "1_ion_p0", "1_field_p0", "1_elc_p1", "1_ion_p1", "1_field_p1", "1_elc_p2", "1_ion_p2", "1_field_p2", + "1_elc_p3", "1_ion_p3", "1_field_p3", "1_elc_p4", "1_ion_p4", "1_field_p4" }, + { "1_elc_b0", "1_ion_b0", "1_field_b0", "1_elc_b1", "1_ion_b1", "1_field_b1", "1_elc_b2", "1_ion_b2", "1_field_b2", + "1_elc_b3", "1_ion_b3", "1_field_b3", "1_elc_b4", "1_ion_b4", "1_field_b4", "1_elc_b5", "1_ion_b5", "1_field_b5", + "1_elc_b6", "1_ion_b6", "1_field_b6", "1_elc_b7", "1_ion_b7", "1_field_b7", "1_elc_b8", "1_ion_b8", "1_field_b8", }, + { "1_elc_b0", "1_ion_b0", "1_field_b0", "1_elc_b1", "1_ion_b1", "1_field_b1", "1_elc_b2", "1_ion_b2", "1_field_b2", + "1_elc_b3", "1_ion_b3", "1_field_b3", "1_elc_b4", "1_ion_b4", "1_field_b4", "1_elc_b5", "1_ion_b5", "1_field_b5", + "1_elc_b6", "1_ion_b6", "1_field_b6", "1_elc_b7", "1_ion_b7", "1_field_b7", "1_elc_b8", "1_ion_b8", "1_field_b8", + "1_elc_b9", "1_ion_b9", "1_field_b9", "1_elc_b10", "1_ion_b10", "1_field_b10", "1_elc_b11", "1_ion_b11", "1_field_b11", + "1_elc_b12", "1_ion_b12", "1_field_b12", "1_elc_b13", "1_ion_b13", "1_field_b13", "1_elc_b14", "1_ion_b14", "1_field_b14", + "1_elc_b15", "1_ion_b15", "1_field_b15", "1_elc_b16", "1_ion_b16", "1_field_b16", "1_elc_b17", "1_ion_b17", "1_field_b17", + "1_elc_b18", "1_ion_b18", "1_field_b18", "1_elc_b19", "1_ion_b19", "1_field_b19", "1_elc_b20", "1_ion_b20", "1_field_b20", + "1_elc_b21", "1_ion_b21", "1_field_b21", "1_elc_b22", "1_ion_b22", "1_field_b22", "1_elc_b23", "1_ion_b23", "1_field_b23", + "1_elc_b24", "1_ion_b24", "1_field_b24" }, + { "1_elc_b0", "1_ion_b0", "1_field_b0", "1_elc_b1", "1_ion_b1", "1_field_b1", "1_elc_b2", "1_ion_b2", "1_field_b2", + "1_elc_b3", "1_ion_b3", "1_field_b3", "1_elc_b4", "1_ion_b4", "1_field_b4", "1_elc_b5", "1_ion_b5", "1_field_b5", + "1_elc_b6", "1_ion_b6", "1_field_b6", "1_elc_b7", "1_ion_b7", "1_field_b7", "1_elc_b8", "1_ion_b8", "1_field_b8", }, + { "1_elc_b0", "1_ion_b0", "1_field_b0", "1_elc_b1", "1_ion_b1", "1_field_b1", "1_elc_b2", "1_ion_b2", "1_field_b2", + "1_elc_b3", "1_ion_b3", "1_field_b3", "1_elc_b4", "1_ion_b4", "1_field_b4", "1_elc_b5", "1_ion_b5", "1_field_b5", + "1_elc_b6", "1_ion_b6", "1_field_b6", "1_elc_b7", "1_ion_b7", "1_field_b7", "1_elc_b8", "1_ion_b8", "1_field_b8", + "1_elc_b9", "1_ion_b9", "1_field_b9", "1_elc_b10", "1_ion_b10", "1_field_b10", "1_elc_b11", "1_ion_b11", "1_field_b11", + "1_elc_b12", "1_ion_b12", "1_field_b12", "1_elc_b13", "1_ion_b13", "1_field_b13", "1_elc_b14", "1_ion_b14", "1_field_b14", + "1_elc_b15", "1_ion_b15", "1_field_b15", "1_elc_b16", "1_ion_b16", "1_field_b16", "1_elc_b17", "1_ion_b17", "1_field_b17", + "1_elc_b18", "1_ion_b18", "1_field_b18", "1_elc_b19", "1_ion_b19", "1_field_b19", "1_elc_b20", "1_ion_b20", "1_field_b20", + "1_elc_b21", "1_ion_b21", "1_field_b21", "1_elc_b22", "1_ion_b22", "1_field_b22", "1_elc_b23", "1_ion_b23", "1_field_b23", + "1_elc_b24", "1_ion_b24", "1_field_b24" } }; + int test_amr[86 - 7] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*0,*/ 0, /*0,*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*0,*/ 0, 0, 0, + 0, /*0,*/ 0, 0, 0, /*0,*/ /*0,*/ 0, /*0,*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; + int test_gr[86 - 7] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*0,*/ 0, /*0,*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*0,*/ 0, 0, 0, + 0, /*0,*/ 0, 0, 0, /*0,*/ /*0,*/ 0, /*0,*/ 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 }; system("clear"); system("mkdir -p ci/output_parallel"); @@ -669,12 +882,13 @@ main(int argc, char **argv) if (strtol(argv[1], &arg_ptr, 10) == 1) { for (int i = 0; i < test_count; i++) { - runTestParallel(test_names[i], test_names_human[i], test_dimensions[i], test_cuts[i], test_output_count[i], test_outputs[i]); + runTestParallel(test_names[i], test_names_human[i], test_dimensions[i], test_cuts[i], test_output_count[i], test_outputs[i], + test_amr[i], test_gr[i]); } } else if (strtol(argv[1], &arg_ptr, 10) == 2) { for (int i = 0; i < test_count; i++) { - analyzeTestOutputParallel(test_names[i], test_names_human[i], test_output_count[i], test_outputs[i]); + analyzeTestOutputParallel(test_names[i], test_names_human[i], test_output_count[i], test_outputs[i], test_amr[i], test_gr[i]); } } else if (strtol(argv[1], &arg_ptr, 10) == 3) { @@ -682,7 +896,8 @@ main(int argc, char **argv) if (strtol(argv[2], &arg_ptr, 10) >= 1 && strtol(argv[2], &arg_ptr, 10) <= test_count) { runTestParallel(test_names[strtol(argv[2], &arg_ptr, 10) - 1], test_names_human[strtol(argv[2], &arg_ptr, 10) - 1], test_dimensions[strtol(argv[2], &arg_ptr, 10) - 1], test_cuts[strtol(argv[2], &arg_ptr, 10) - 1], - test_output_count[strtol(argv[2], &arg_ptr, 10) - 1], test_outputs[strtol(argv[2], &arg_ptr, 10) - 1]); + test_output_count[strtol(argv[2], &arg_ptr, 10) - 1], test_outputs[strtol(argv[2], &arg_ptr, 10) - 1], + test_amr[strtol(argv[2], &arg_ptr, 10) - 1], test_gr[strtol(argv[2], &arg_ptr, 10) - 1]); } else { printf("Invalid test!\n"); @@ -696,7 +911,8 @@ main(int argc, char **argv) if (argc > 2) { if (strtol(argv[2], &arg_ptr, 10) >= 1 && strtol(argv[2], &arg_ptr, 10) <= test_count) { analyzeTestOutputParallel(test_names[strtol(argv[2], &arg_ptr, 10) - 1], test_names_human[strtol(argv[2], &arg_ptr, 10) - 1], - test_output_count[strtol(argv[2], &arg_ptr, 10) - 1], test_outputs[strtol(argv[2], &arg_ptr, 10) - 1]); + test_output_count[strtol(argv[2], &arg_ptr, 10) - 1], test_outputs[strtol(argv[2], &arg_ptr, 10) - 1], + test_amr[strtol(argv[2], &arg_ptr, 10) - 1], test_gr[strtol(argv[2], &arg_ptr, 10) - 1]); } else { printf("Invalid test!\n"); @@ -709,7 +925,8 @@ main(int argc, char **argv) else if (strtol(argv[1], &arg_ptr, 10) == 5) { for (int i = 0; i < test_count; i++) { regenerateTestParallel(test_names[i], test_output_count[i], test_outputs[i]); - runTestParallel(test_names[i], test_names_human[i], test_dimensions[i], test_cuts[i], test_output_count[i], test_outputs[i]); + runTestParallel(test_names[i], test_names_human[i], test_dimensions[i], test_cuts[i], test_output_count[i], test_outputs[i], + test_amr[i], test_gr[i]); } } else if (strtol(argv[1], &arg_ptr, 10) == 6) { @@ -719,7 +936,8 @@ main(int argc, char **argv) test_outputs[strtol(argv[2], &arg_ptr, 10) - 1]); runTestParallel(test_names[strtol(argv[2], &arg_ptr, 10) - 1], test_names_human[strtol(argv[2], &arg_ptr, 10) - 1], test_dimensions[strtol(argv[2], &arg_ptr, 10) - 1], test_cuts[strtol(argv[2], &arg_ptr, 10) - 1], - test_output_count[strtol(argv[2], &arg_ptr, 10) - 1], test_outputs[strtol(argv[2], &arg_ptr, 10) - 1]); + test_output_count[strtol(argv[2], &arg_ptr, 10) - 1], test_outputs[strtol(argv[2], &arg_ptr, 10) - 1], + test_amr[strtol(argv[2], &arg_ptr, 10) - 1], test_gr[strtol(argv[2], &arg_ptr, 10) - 1]); } else { printf("Invalid test!\n"); @@ -750,12 +968,13 @@ main(int argc, char **argv) if (option == 1) { for (int i = 0; i < test_count; i++) { - runTestParallel(test_names[i], test_names_human[i], test_dimensions[i], test_cuts[i], test_output_count[i], test_outputs[i]); + runTestParallel(test_names[i], test_names_human[i], test_dimensions[i], test_cuts[i], test_output_count[i], test_outputs[i], + test_amr[i], test_gr[i]); } } else if (option == 2) { for (int i = 0; i < test_count; i++) { - analyzeTestOutputParallel(test_names[i], test_names_human[i], test_output_count[i], test_outputs[i]); + analyzeTestOutputParallel(test_names[i], test_names_human[i], test_output_count[i], test_outputs[i], test_amr[i], test_gr[i]); } } else if (option == 3) { @@ -770,7 +989,7 @@ main(int argc, char **argv) if (option2 >= 1 && option2 <= test_count) { runTestParallel(test_names[option2 - 1], test_names_human[option2 - 1], test_dimensions[option2 - 1], test_cuts[option2 - 1], - test_output_count[option2 - 1], test_outputs[option2 - 1]); + test_output_count[option2 - 1], test_outputs[option2 - 1], test_amr[option2 - 1], test_gr[option2 - 1]); } else { printf("Invalid test!\n\n"); @@ -787,7 +1006,8 @@ main(int argc, char **argv) printf("\n"); if (option2 >= 1 && option2 <= test_count) { - analyzeTestOutputParallel(test_names[option2 - 1], test_names_human[option2 - 1], test_output_count[option2 - 1], test_outputs[option2 - 1]); + analyzeTestOutputParallel(test_names[option2 - 1], test_names_human[option2 - 1], test_output_count[option2 - 1], test_outputs[option2 - 1], + test_amr[option2 - 1], test_gr[option2 - 1]); } else { printf("Invalid test!\n\n"); @@ -796,7 +1016,8 @@ main(int argc, char **argv) else if (option == 5) { for (int i = 0; i < test_count; i++) { regenerateTestParallel(test_names[i], test_output_count[i], test_outputs[i]); - runTestParallel(test_names[i], test_names_human[i], test_dimensions[i], test_cuts[i], test_output_count[i], test_outputs[i]); + runTestParallel(test_names[i], test_names_human[i], test_dimensions[i], test_cuts[i], test_output_count[i], test_outputs[i], + test_amr[i], test_gr[i]); } } else if (option == 6) { @@ -812,7 +1033,7 @@ main(int argc, char **argv) if (option2 >= 1 && option2 <= test_count) { regenerateTestParallel(test_names[option2 - 1], test_output_count[option2 - 1], test_outputs[option2 - 1]); runTestParallel(test_names[option2 - 1], test_names_human[option2 - 1], test_dimensions[option2 - 1], test_cuts[option2 - 1], - test_output_count[option2 - 1], test_outputs[option2 - 1]); + test_output_count[option2 - 1], test_outputs[option2 - 1], test_amr[option2 - 1], test_gr[option2 - 1]); } else { printf("Invalid test!\n\n"); From 1ea596489bfc99b387f1f0a687b1bb4b28edfea1 Mon Sep 17 00:00:00 2001 From: JonathanGorard Date: Mon, 1 Jul 2024 16:21:43 -0400 Subject: [PATCH 27/32] Final(!) fix to the parallel CI system to handle the case of GR and AMR+GR tests (with appropriate modifications to memory leak-checking and automatic choice of domain cuts). --- ci/moment_regression_parallel.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/ci/moment_regression_parallel.c b/ci/moment_regression_parallel.c index cdcc454bb..79fedede6 100644 --- a/ci/moment_regression_parallel.c +++ b/ci/moment_regression_parallel.c @@ -398,11 +398,13 @@ analyzeTestOutputParallel(const char* test_name, const char* test_name_human, co printf("Total update time: %f\n", totalupdate[i]); - if (memoryleakcount[i] != 0) { - printf("Memory leaks: " ANSI_COLOR_RED "%s" ANSI_COLOR_RESET "\n", memoryleaks[i]); - } - else { - printf("Memory leaks: " ANSI_COLOR_GREEN "None" ANSI_COLOR_RESET "\n"); + if (test_gr == 0) { + if (memoryleakcount[i] != 0) { + printf("Memory leaks: " ANSI_COLOR_RED "%s" ANSI_COLOR_RESET "\n", memoryleaks[i]); + } + else { + printf("Memory leaks: " ANSI_COLOR_GREEN "None" ANSI_COLOR_RESET "\n"); + } } printf("Correct: N/A\n\n"); } @@ -743,7 +745,7 @@ main(int argc, char **argv) 1, /*1,*/ 2, 1, 1, /*2,*/ /*2,*/ 2, /*2,*/ 1, 1, 2, 1, 1, 1, 2, 2, 2, 2, 2, 2, 1, 1, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 2, 2, 2, 2 }; int test_cuts[86 - 7] = { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, /*4,*/ 4, /*4,*/ 4, 4, 4, 4, 5, 4, 4, 4, 5, 4, 4, 4, 4, /*4,*/ 4, 1, 4, 4, /*4,*/ - 5, 5, 4, /*5,*/ /*5,*/ 5, /*2,*/ 4, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ,0, 0, 0, 0 ,0, 0, 0, + 5, 5, 4, /*5,*/ /*5,*/ 5, /*2,*/ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; int test_output_count[86 - 7] = { 4, 4, 4, 4, 4, 4, 4, 4, 1, 1, 4, 4, 3, 4, 1, /*1,*/ 1, /*1,*/ 3, 1, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, /*1,*/ 1, 1, 1, 1, /*1,*/ 1, 1, 1, /*2,*/ /*1,*/ 1, /*2,*/ 1, 1, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 5, 9, 25, 9, 25, 9, 25, 3, 5, 3, 5, 3, 5, 9, 25, 9, 25, 9, From fd092fc2a95b90a59ae6f050e2d01f8bccdd1b3a Mon Sep 17 00:00:00 2001 From: JonathanGorard Date: Mon, 8 Jul 2024 15:32:40 -0400 Subject: [PATCH 28/32] As per @JunoRavin's suggestion, factoring out fully customizable projection (coarse-to-fine) and restriction (fine-to-coarse) operators from the block-structured AMR framework. --- amr/amr_block.c | 360 ++++++++++++++++++++++---------------- amr/gkyl_amr_block_priv.h | 112 ++++++++++++ 2 files changed, 320 insertions(+), 152 deletions(-) diff --git a/amr/amr_block.c b/amr/amr_block.c index 78bdbdb56..3793df8d1 100644 --- a/amr/amr_block.c +++ b/amr/amr_block.c @@ -201,6 +201,206 @@ euler_block_bc_updaters_apply(const struct euler_block_data* bdata, double tm, s } } +void +block_ll_projection_op(const int tbid, const int tdir, const int i, const int d, const struct euler_block_data bdata[], + const struct gkyl_array* bc_buffer, struct gkyl_array* fld[]) +{ + struct gkyl_range_iter iter; + gkyl_range_iter_init(&iter, &(bdata[tbid].skin_ghost.lower_ghost[tdir])); + + double ref_factor_inv = ((double)bdata[i].skin_ghost.lower_skin[d].volume / (double)bdata[tbid].skin_ghost.lower_ghost[tdir].volume); + + long count = 0; + while (gkyl_range_iter_next(&iter)) { + long start = gkyl_range_idx(&(bdata[tbid].skin_ghost.lower_ghost[tdir]), iter.idx); + + if ((bdata[tbid].skin_ghost.lower_ghost[tdir].upper[0] - bdata[tbid].skin_ghost.lower_ghost[tdir].lower[0]) == 1) { + memcpy(gkyl_array_fetch(fld[tbid], start), + ((char*) bc_buffer->data) + fld[tbid]->esznc * ((int)(ref_factor_inv * count++)), fld[tbid]->esznc); + } + else { + memcpy(gkyl_array_fetch(fld[tbid], start), + ((char*) bc_buffer->data) + fld[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld[tbid]->esznc); + count += 1; + } + } +} + +void +block_ll_restriction_op(const int tbid, const int tdir, const int i, const int d, const struct euler_block_data bdata[], + const struct gkyl_array* bc_buffer, struct gkyl_array* fld[]) +{ + struct gkyl_range_iter iter; + gkyl_range_iter_init(&iter, &(bdata[tbid].skin_ghost.lower_ghost[tdir])); + + int ref_factor = (int)(bdata[i].skin_ghost.lower_skin[d].volume / bdata[tbid].skin_ghost.lower_ghost[tdir].volume); + + long count = 0; + while (gkyl_range_iter_next(&iter)) { + long start = gkyl_range_idx(&(bdata[tbid].skin_ghost.lower_ghost[tdir]), iter.idx); + + if ((bdata[tbid].skin_ghost.lower_ghost[tdir].upper[0] - bdata[tbid].skin_ghost.lower_ghost[tdir].lower[0]) == 1) { + memcpy(gkyl_array_fetch(fld[tbid], start), + ((char*) bc_buffer->data) + fld[tbid]->esznc * (ref_factor * count++), fld[tbid]->esznc); + } + else { + memcpy(gkyl_array_fetch(fld[tbid], start), + ((char*) bc_buffer->data) + fld[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld[tbid]->esznc); + count += 1; + } + } +} + +void +block_lu_projection_op(const int tbid, const int tdir, const int i, const int d, const struct euler_block_data bdata[], + const struct gkyl_array* bc_buffer, struct gkyl_array* fld[]) +{ + struct gkyl_range_iter iter; + gkyl_range_iter_init(&iter, &(bdata[tbid].skin_ghost.upper_ghost[tdir])); + + double ref_factor_inv = ((double)bdata[i].skin_ghost.lower_skin[d].volume / (double)bdata[tbid].skin_ghost.upper_ghost[tdir].volume); + + long count = 0; + while (gkyl_range_iter_next(&iter)) { + long start = gkyl_range_idx(&(bdata[tbid].skin_ghost.upper_ghost[tdir]), iter.idx); + + if ((bdata[tbid].skin_ghost.upper_ghost[tdir].upper[0] - bdata[tbid].skin_ghost.upper_ghost[tdir].lower[0]) == 1) { + memcpy(gkyl_array_fetch(fld[tbid], start), + ((char*) bc_buffer->data) + fld[tbid]->esznc * ((int)(ref_factor_inv * count++)), fld[tbid]->esznc); + } + else { + memcpy(gkyl_array_fetch(fld[tbid], start), + ((char*) bc_buffer->data) + fld[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld[tbid]->esznc); + count += 1; + } + } +} + +void +block_lu_restriction_op(const int tbid, const int tdir, const int i, const int d, const struct euler_block_data bdata[], + const struct gkyl_array* bc_buffer, struct gkyl_array* fld[]) +{ + struct gkyl_range_iter iter; + gkyl_range_iter_init(&iter, &(bdata[tbid].skin_ghost.upper_ghost[tdir])); + + int ref_factor = (int)(bdata[i].skin_ghost.lower_skin[d].volume / bdata[tbid].skin_ghost.upper_ghost[tdir].volume); + + long count = 0; + while (gkyl_range_iter_next(&iter)) { + long start = gkyl_range_idx(&(bdata[tbid].skin_ghost.upper_ghost[tdir]), iter.idx); + + if ((bdata[tbid].skin_ghost.upper_ghost[tdir].upper[0] - bdata[tbid].skin_ghost.upper_ghost[tdir].lower[0]) == 1) { + memcpy(gkyl_array_fetch(fld[tbid], start), + ((char*) bc_buffer->data) + fld[tbid]->esznc * (ref_factor * count++), fld[tbid]->esznc); + } + else { + memcpy(gkyl_array_fetch(fld[tbid], start), + ((char*) bc_buffer->data) + fld[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld[tbid]->esznc); + count += 1; + } + } +} + +void +block_ul_projection_op(const int tbid, const int tdir, const int i, const int d, const struct euler_block_data bdata[], + const struct gkyl_array* bc_buffer, struct gkyl_array* fld[]) +{ + struct gkyl_range_iter iter; + gkyl_range_iter_init(&iter, &(bdata[tbid].skin_ghost.lower_ghost[tdir])); + + double ref_factor_inv = ((double)bdata[i].skin_ghost.upper_skin[d].volume / (double)bdata[tbid].skin_ghost.lower_ghost[tdir].volume); + + long count = 0; + while (gkyl_range_iter_next(&iter)) { + long start = gkyl_range_idx(&(bdata[tbid].skin_ghost.lower_ghost[tdir]), iter.idx); + + if ((bdata[tbid].skin_ghost.lower_ghost[tdir].upper[0] - bdata[tbid].skin_ghost.lower_ghost[tdir].lower[0]) == 1) { + memcpy(gkyl_array_fetch(fld[tbid], start), + ((char*) bc_buffer->data) + fld[tbid]->esznc * ((int)(ref_factor_inv * count++)), fld[tbid]->esznc); + } + else { + memcpy(gkyl_array_fetch(fld[tbid], start), + ((char*) bc_buffer->data) + fld[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld[tbid]->esznc); + count += 1; + } + } +} + +void +block_ul_restriction_op(const int tbid, const int tdir, const int i, const int d, const struct euler_block_data bdata[], + const struct gkyl_array* bc_buffer, struct gkyl_array* fld[]) +{ + struct gkyl_range_iter iter; + gkyl_range_iter_init(&iter, &(bdata[tbid].skin_ghost.lower_ghost[tdir])); + + int ref_factor = (int)(bdata[i].skin_ghost.upper_skin[d].volume / bdata[tbid].skin_ghost.lower_ghost[tdir].volume); + + long count = 0; + while (gkyl_range_iter_next(&iter)) { + long start = gkyl_range_idx(&(bdata[tbid].skin_ghost.lower_ghost[tdir]), iter.idx); + + if ((bdata[tbid].skin_ghost.lower_ghost[tdir].upper[0] - bdata[tbid].skin_ghost.lower_ghost[tdir].lower[0]) == 1) { + memcpy(gkyl_array_fetch(fld[tbid], start), + ((char*) bc_buffer->data) + fld[tbid]->esznc * (ref_factor * count++), fld[tbid]->esznc); + } + else { + memcpy(gkyl_array_fetch(fld[tbid], start), + ((char*) bc_buffer->data) + fld[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld[tbid]->esznc); + count += 1; + } + } +} + +void +block_uu_projection_op(const int tbid, const int tdir, const int i, const int d, const struct euler_block_data bdata[], + const struct gkyl_array* bc_buffer, struct gkyl_array* fld[]) +{ + struct gkyl_range_iter iter; + gkyl_range_iter_init(&iter, &(bdata[tbid].skin_ghost.upper_ghost[tdir])); + + double ref_factor_inv = ((double)bdata[i].skin_ghost.upper_skin[d].volume / (double)bdata[tbid].skin_ghost.upper_ghost[tdir].volume); + + long count = 0; + while (gkyl_range_iter_next(&iter)) { + long start = gkyl_range_idx(&(bdata[tbid].skin_ghost.upper_ghost[tdir]), iter.idx); + + if ((bdata[tbid].skin_ghost.upper_ghost[tdir].upper[0] - bdata[tbid].skin_ghost.upper_ghost[tdir].lower[0]) == 1) { + memcpy(gkyl_array_fetch(fld[tbid], start), + ((char*) bc_buffer->data) + fld[tbid]->esznc * ((int)(ref_factor_inv * count++)), fld[tbid]->esznc); + } + else { + memcpy(gkyl_array_fetch(fld[tbid], start), + ((char*) bc_buffer->data) + fld[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld[tbid]->esznc); + count += 1; + } + } +} + +void +block_uu_restriction_op(const int tbid, const int tdir, const int i, const int d, const struct euler_block_data bdata[], + const struct gkyl_array* bc_buffer, struct gkyl_array* fld[]) +{ + struct gkyl_range_iter iter; + gkyl_range_iter_init(&iter, &(bdata[tbid].skin_ghost.upper_ghost[tdir])); + + int ref_factor = (int)(bdata[i].skin_ghost.upper_skin[d].volume / bdata[tbid].skin_ghost.upper_ghost[tdir].volume); + + long count = 0; + while (gkyl_range_iter_next(&iter)) { + long start = gkyl_range_idx(&(bdata[tbid].skin_ghost.upper_ghost[tdir]), iter.idx); + + if ((bdata[tbid].skin_ghost.upper_ghost[tdir].upper[0] - bdata[tbid].skin_ghost.upper_ghost[tdir].lower[0]) == 1) { + memcpy(gkyl_array_fetch(fld[tbid], start), + ((char*) bc_buffer->data) + fld[tbid]->esznc * (ref_factor * count++), fld[tbid]->esznc); + } + else { + memcpy(gkyl_array_fetch(fld[tbid], start), + ((char*) bc_buffer->data) + fld[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld[tbid]->esznc); + count += 1; + } + } +} + void euler_sync_blocks(const struct gkyl_block_topo* btopo, const struct euler_block_data bdata[], struct gkyl_array* fld[]) { @@ -224,46 +424,10 @@ euler_sync_blocks(const struct gkyl_block_topo* btopo, const struct euler_block_ gkyl_array_copy_from_buffer(fld[tbid], bc_buffer->data, &(bdata[tbid].skin_ghost.lower_ghost[tdir])); } else if (bdata[i].skin_ghost.lower_skin[d].volume > bdata[tbid].skin_ghost.lower_ghost[tdir].volume) { - struct gkyl_range_iter iter; - gkyl_range_iter_init(&iter, &(bdata[tbid].skin_ghost.lower_ghost[tdir])); - - int ref_factor = (int)(bdata[i].skin_ghost.lower_skin[d].volume / bdata[tbid].skin_ghost.lower_ghost[tdir].volume); - - long count = 0; - while (gkyl_range_iter_next(&iter)) { - long start = gkyl_range_idx(&(bdata[tbid].skin_ghost.lower_ghost[tdir]), iter.idx); - - if ((bdata[tbid].skin_ghost.lower_ghost[tdir].upper[0] - bdata[tbid].skin_ghost.lower_ghost[tdir].lower[0]) == 1) { - memcpy(gkyl_array_fetch(fld[tbid], start), - ((char*) bc_buffer->data) + fld[tbid]->esznc * (ref_factor * count++), fld[tbid]->esznc); - } - else { - memcpy(gkyl_array_fetch(fld[tbid], start), - ((char*) bc_buffer->data) + fld[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld[tbid]->esznc); - count += 1; - } - } + block_ll_restriction_op(tbid, tdir, i, d, bdata, bc_buffer, fld); } else if (bdata[i].skin_ghost.lower_skin[d].volume < bdata[tbid].skin_ghost.lower_ghost[tdir].volume) { - struct gkyl_range_iter iter; - gkyl_range_iter_init(&iter, &(bdata[tbid].skin_ghost.lower_ghost[tdir])); - - double ref_factor_inv = ((double)bdata[i].skin_ghost.lower_skin[d].volume / (double)bdata[tbid].skin_ghost.lower_ghost[tdir].volume); - - long count = 0; - while (gkyl_range_iter_next(&iter)) { - long start = gkyl_range_idx(&(bdata[tbid].skin_ghost.lower_ghost[tdir]), iter.idx); - - if ((bdata[tbid].skin_ghost.lower_ghost[tdir].upper[0] - bdata[tbid].skin_ghost.lower_ghost[tdir].lower[0]) == 1) { - memcpy(gkyl_array_fetch(fld[tbid], start), - ((char*) bc_buffer->data) + fld[tbid]->esznc * ((int)(ref_factor_inv * count++)), fld[tbid]->esznc); - } - else { - memcpy(gkyl_array_fetch(fld[tbid], start), - ((char*) bc_buffer->data) + fld[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld[tbid]->esznc); - count += 1; - } - } + block_ll_projection_op(tbid, tdir, i, d, bdata, bc_buffer, fld); } } else if (te[0].edge == GKYL_UPPER_POSITIVE) { @@ -271,46 +435,10 @@ euler_sync_blocks(const struct gkyl_block_topo* btopo, const struct euler_block_ gkyl_array_copy_from_buffer(fld[tbid], bc_buffer->data, &(bdata[tbid].skin_ghost.upper_ghost[tdir])); } else if (bdata[i].skin_ghost.lower_skin[d].volume > bdata[tbid].skin_ghost.upper_ghost[tdir].volume) { - struct gkyl_range_iter iter; - gkyl_range_iter_init(&iter, &(bdata[tbid].skin_ghost.upper_ghost[tdir])); - - int ref_factor = (int)(bdata[i].skin_ghost.lower_skin[d].volume / bdata[tbid].skin_ghost.upper_ghost[tdir].volume); - - long count = 0; - while (gkyl_range_iter_next(&iter)) { - long start = gkyl_range_idx(&(bdata[tbid].skin_ghost.upper_ghost[tdir]), iter.idx); - - if ((bdata[tbid].skin_ghost.upper_ghost[tdir].upper[0] - bdata[tbid].skin_ghost.upper_ghost[tdir].lower[0]) == 1) { - memcpy(gkyl_array_fetch(fld[tbid], start), - ((char*) bc_buffer->data) + fld[tbid]->esznc * (ref_factor * count++), fld[tbid]->esznc); - } - else { - memcpy(gkyl_array_fetch(fld[tbid], start), - ((char*) bc_buffer->data) + fld[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld[tbid]->esznc); - count += 1; - } - } + block_lu_restriction_op(tbid, tdir, i, d, bdata, bc_buffer, fld); } else if (bdata[i].skin_ghost.lower_skin[d].volume < bdata[tbid].skin_ghost.upper_ghost[tdir].volume) { - struct gkyl_range_iter iter; - gkyl_range_iter_init(&iter, &(bdata[tbid].skin_ghost.upper_ghost[tdir])); - - double ref_factor_inv = ((double)bdata[i].skin_ghost.lower_skin[d].volume / (double)bdata[tbid].skin_ghost.upper_ghost[tdir].volume); - - long count = 0; - while (gkyl_range_iter_next(&iter)) { - long start = gkyl_range_idx(&(bdata[tbid].skin_ghost.upper_ghost[tdir]), iter.idx); - - if ((bdata[tbid].skin_ghost.upper_ghost[tdir].upper[0] - bdata[tbid].skin_ghost.upper_ghost[tdir].lower[0]) == 1) { - memcpy(gkyl_array_fetch(fld[tbid], start), - ((char*) bc_buffer->data) + fld[tbid]->esznc * ((int)(ref_factor_inv * count++)), fld[tbid]->esznc); - } - else { - memcpy(gkyl_array_fetch(fld[tbid], start), - ((char*) bc_buffer->data) + fld[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld[tbid]->esznc); - count += 1; - } - } + block_lu_projection_op(tbid, tdir, i, d, bdata, bc_buffer, fld); } } } @@ -328,46 +456,10 @@ euler_sync_blocks(const struct gkyl_block_topo* btopo, const struct euler_block_ gkyl_array_copy_from_buffer(fld[tbid], bc_buffer->data, &(bdata[tbid].skin_ghost.lower_ghost[tdir])); } else if (bdata[i].skin_ghost.upper_skin[d].volume > bdata[tbid].skin_ghost.lower_ghost[tdir].volume) { - struct gkyl_range_iter iter; - gkyl_range_iter_init(&iter, &(bdata[tbid].skin_ghost.lower_ghost[tdir])); - - int ref_factor = (int)(bdata[i].skin_ghost.upper_skin[d].volume / bdata[tbid].skin_ghost.lower_ghost[tdir].volume); - - long count = 0; - while (gkyl_range_iter_next(&iter)) { - long start = gkyl_range_idx(&(bdata[tbid].skin_ghost.lower_ghost[tdir]), iter.idx); - - if ((bdata[tbid].skin_ghost.lower_ghost[tdir].upper[0] - bdata[tbid].skin_ghost.lower_ghost[tdir].lower[0]) == 1) { - memcpy(gkyl_array_fetch(fld[tbid], start), - ((char*) bc_buffer->data) + fld[tbid]->esznc * (ref_factor * count++), fld[tbid]->esznc); - } - else { - memcpy(gkyl_array_fetch(fld[tbid], start), - ((char*) bc_buffer->data) + fld[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld[tbid]->esznc); - count += 1; - } - } + block_ul_restriction_op(tbid, tdir, i, d, bdata, bc_buffer, fld); } else if (bdata[i].skin_ghost.upper_skin[d].volume < bdata[tbid].skin_ghost.lower_ghost[tdir].volume) { - struct gkyl_range_iter iter; - gkyl_range_iter_init(&iter, &(bdata[tbid].skin_ghost.lower_ghost[tdir])); - - double ref_factor_inv = ((double)bdata[i].skin_ghost.upper_skin[d].volume / (double)bdata[tbid].skin_ghost.lower_ghost[tdir].volume); - - long count = 0; - while (gkyl_range_iter_next(&iter)) { - long start = gkyl_range_idx(&(bdata[tbid].skin_ghost.lower_ghost[tdir]), iter.idx); - - if ((bdata[tbid].skin_ghost.lower_ghost[tdir].upper[0] - bdata[tbid].skin_ghost.lower_ghost[tdir].lower[0]) == 1) { - memcpy(gkyl_array_fetch(fld[tbid], start), - ((char*) bc_buffer->data) + fld[tbid]->esznc * ((int)(ref_factor_inv * count++)), fld[tbid]->esznc); - } - else { - memcpy(gkyl_array_fetch(fld[tbid], start), - ((char*) bc_buffer->data) + fld[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld[tbid]->esznc); - count += 1; - } - } + block_ul_projection_op(tbid, tdir, i, d, bdata, bc_buffer, fld); } } else if (te[1].edge == GKYL_UPPER_POSITIVE) { @@ -375,46 +467,10 @@ euler_sync_blocks(const struct gkyl_block_topo* btopo, const struct euler_block_ gkyl_array_copy_from_buffer(fld[tbid], bc_buffer->data, &(bdata[tbid].skin_ghost.upper_ghost[tdir])); } else if (bdata[i].skin_ghost.upper_skin[d].volume > bdata[tbid].skin_ghost.upper_ghost[tdir].volume) { - struct gkyl_range_iter iter; - gkyl_range_iter_init(&iter, &(bdata[tbid].skin_ghost.upper_ghost[tdir])); - - int ref_factor = (int)(bdata[i].skin_ghost.upper_skin[d].volume / bdata[tbid].skin_ghost.upper_ghost[tdir].volume); - - long count = 0; - while (gkyl_range_iter_next(&iter)) { - long start = gkyl_range_idx(&(bdata[tbid].skin_ghost.upper_ghost[tdir]), iter.idx); - - if ((bdata[tbid].skin_ghost.upper_ghost[tdir].upper[0] - bdata[tbid].skin_ghost.upper_ghost[tdir].lower[0]) == 1) { - memcpy(gkyl_array_fetch(fld[tbid], start), - ((char*) bc_buffer->data) + fld[tbid]->esznc * (ref_factor * count++), fld[tbid]->esznc); - } - else { - memcpy(gkyl_array_fetch(fld[tbid], start), - ((char*) bc_buffer->data) + fld[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld[tbid]->esznc); - count += 1; - } - } + block_uu_restriction_op(tbid, tdir, i, d, bdata, bc_buffer, fld); } else if (bdata[i].skin_ghost.upper_skin[d].volume < bdata[tbid].skin_ghost.upper_ghost[tdir].volume) { - struct gkyl_range_iter iter; - gkyl_range_iter_init(&iter, &(bdata[tbid].skin_ghost.upper_ghost[tdir])); - - double ref_factor_inv = ((double)bdata[i].skin_ghost.upper_skin[d].volume / (double)bdata[tbid].skin_ghost.upper_ghost[tdir].volume); - - long count = 0; - while (gkyl_range_iter_next(&iter)) { - long start = gkyl_range_idx(&(bdata[tbid].skin_ghost.upper_ghost[tdir]), iter.idx); - - if ((bdata[tbid].skin_ghost.upper_ghost[tdir].upper[0] - bdata[tbid].skin_ghost.upper_ghost[tdir].lower[0]) == 1) { - memcpy(gkyl_array_fetch(fld[tbid], start), - ((char*) bc_buffer->data) + fld[tbid]->esznc * ((int)(ref_factor_inv * count++)), fld[tbid]->esznc); - } - else { - memcpy(gkyl_array_fetch(fld[tbid], start), - ((char*) bc_buffer->data) + fld[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld[tbid]->esznc); - count += 1; - } - } + block_uu_projection_op(tbid, tdir, i, d, bdata, bc_buffer, fld); } } } diff --git a/amr/gkyl_amr_block_priv.h b/amr/gkyl_amr_block_priv.h index 56ba34bbc..cd68eb74e 100644 --- a/amr/gkyl_amr_block_priv.h +++ b/amr/gkyl_amr_block_priv.h @@ -168,6 +168,118 @@ void euler_block_bc_updaters_release(struct euler_block_data* bdata); */ void euler_block_bc_updaters_apply(const struct euler_block_data* bdata, double tm, struct gkyl_array* fld); +/** +* Coarse-to-fine projection operator for block-structured AMR, assuming a lower coarse block and a lower fine block. +* +* @param tbid Target (fine) block ID. +* @param tdir Target (fine) block direction. +* @param i Reference (coarse) block ID. +* @param d Reference (coarse) block direction. +* @param bdata Block-structured data for the Euler equations. +* @param bc_buffer Buffer for applying boundary conditions. +* @param fld Output array. +*/ +void block_ll_projection_op(const int tbid, const int tdir, const int i, const int d, const struct euler_block_data bdata[], + const struct gkyl_array* bc_buffer, struct gkyl_array* fld[]); + +/** +* Fine-to-coarse restriction operator for block-structured AMR, assuming a lower fine block and a lower coarse block. +* +* @param tbid Target (coarse) block ID. +* @param tdir Target (coarse) block direction. +* @param i Reference (fine) block ID. +* @param d Reference (fine) block direction. +* @param bdata Block-structured data for the Euler equations. +* @param bc_buffer Buffer for applying boundary conditions. +* @param fld Output array. +*/ +void block_ll_restriction_op(const int tbid, const int tdir, const int i, const int d, const struct euler_block_data bdata[], + const struct gkyl_array* bc_buffer, struct gkyl_array* fld[]); + +/** +* Coarse-to-fine projection operator for block-structured AMR, assuming a lower coarse block and an upper fine block. +* +* @param tbid Target (fine) block ID. +* @param tdir Target (fine) block direction. +* @param i Reference (coarse) block ID. +* @param d Reference (coarse) block direction. +* @param bdata Block-structured data for the Euler equations. +* @param bc_buffer Buffer for applying boundary conditions. +* @param fld Output array. +*/ +void block_lu_projection_op(const int tbid, const int tdir, const int i, const int d, const struct euler_block_data bdata[], + const struct gkyl_array* bc_buffer, struct gkyl_array* fld[]); + +/** +* Fine-to-coarse restriction operator for block-structured AMR, assuming a lower fine block and an upper coarse block. +* +* @param tbid Target (coarse) block ID. +* @param tdir Target (coarse) block direction. +* @param i Reference (fine) block ID. +* @param d Reference (fine) block direction. +* @param bdata Block-structured data for the Euler equations. +* @param bc_buffer Buffer for applying boundary conditions. +* @param fld Output array. +*/ +void block_lu_restriction_op(const int tbid, const int tdir, const int i, const int d, const struct euler_block_data bdata[], + const struct gkyl_array* bc_buffer, struct gkyl_array* fld[]); + + /** +* Coarse-to-fine projection operator for block-structured AMR, assuming an upper coarse block and a lower fine block. +* +* @param tbid Target (fine) block ID. +* @param tdir Target (fine) block direction. +* @param i Reference (coarse) block ID. +* @param d Reference (coarse) block direction. +* @param bdata Block-structured data for the Euler equations. +* @param bc_buffer Buffer for applying boundary conditions. +* @param fld Output array. +*/ +void block_ul_projection_op(const int tbid, const int tdir, const int i, const int d, const struct euler_block_data bdata[], + const struct gkyl_array* bc_buffer, struct gkyl_array* fld[]); + +/** +* Fine-to-coarse restriction operator for block-structured AMR, assuming an upper fine block and a lower coarse block. +* +* @param tbid Target (coarse) block ID. +* @param tdir Target (coarse) block direction. +* @param i Reference (fine) block ID. +* @param d Reference (fine) block direction. +* @param bdata Block-structured data for the Euler equations. +* @param bc_buffer Buffer for applying boundary conditions. +* @param fld Output array. +*/ +void block_ul_restriction_op(const int tbid, const int tdir, const int i, const int d, const struct euler_block_data bdata[], + const struct gkyl_array* bc_buffer, struct gkyl_array* fld[]); + +/** +* Coarse-to-fine projection operator for block-structured AMR, assuming an upper coarse block and an upper fine block. +* +* @param tbid Target (fine) block ID. +* @param tdir Target (fine) block direction. +* @param i Reference (coarse) block ID. +* @param d Reference (coarse) block direction. +* @param bdata Block-structured data for the Euler equations. +* @param bc_buffer Buffer for applying boundary conditions. +* @param fld Output array. +*/ +void block_uu_projection_op(const int tbid, const int tdir, const int i, const int d, const struct euler_block_data bdata[], + const struct gkyl_array* bc_buffer, struct gkyl_array* fld[]); + +/** +* Fine-to-coarse restriction operator for block-structured AMR, assuming an upper fine block and an upper coarse block. +* +* @param tbid Target (coarse) block ID. +* @param tdir Target (coarse) block direction. +* @param i Reference (fine) block ID. +* @param d Reference (fine) block direction. +* @param bdata Block-structured data for the Euler equations. +* @param bc_buffer Buffer for applying boundary conditions. +* @param fld Output array. +*/ +void block_uu_restriction_op(const int tbid, const int tdir, const int i, const int d, const struct euler_block_data bdata[], + const struct gkyl_array* bc_buffer, struct gkyl_array* fld[]); + /** * Synchronize all blocks in the block AMR hierarchy by applying all appropriate physical (outer-block) and non-physical (inter-block) * boundary conditions for the Euler equations. From 856e549b848d06c68ff802be1ca9312f4da67df2 Mon Sep 17 00:00:00 2001 From: JonathanGorard Date: Mon, 8 Jul 2024 16:54:52 -0400 Subject: [PATCH 29/32] Also factored out customizable projecton and restriction operators for the coupled (block-structured) AMR case. 5m GEM test is still running just fine, although I will run the full regression suite shortly to confirm that there were no screwups. --- amr/amr_block_coupled.c | 520 +++++++++++++++++------------- amr/gkyl_amr_block_coupled_priv.h | 152 +++++++++ 2 files changed, 448 insertions(+), 224 deletions(-) diff --git a/amr/amr_block_coupled.c b/amr/amr_block_coupled.c index 84b3b7124..87c9d4997 100644 --- a/amr/amr_block_coupled.c +++ b/amr/amr_block_coupled.c @@ -417,6 +417,286 @@ five_moment_block_bc_updaters_apply(const struct five_moment_block_data* bdata, } } +void +block_coupled_ll_projection_op(const int tbid, const int tdir, const int i, const int d, const struct five_moment_block_data bdata[], + const struct gkyl_array* bc_buffer_elc, const struct gkyl_array* bc_buffer_ion, const struct gkyl_array* bc_buffer_maxwell, + struct gkyl_array* fld_elc[], struct gkyl_array* fld_ion[], struct gkyl_array* fld_maxwell[]) +{ + struct gkyl_range_iter iter; + gkyl_range_iter_init(&iter, &(bdata[tbid].skin_ghost.lower_ghost[tdir])); + + double ref_factor_inv = ((double)bdata[i].skin_ghost.lower_skin[d].volume / (double)bdata[tbid].skin_ghost.lower_ghost[tdir].volume); + + long count = 0; + while (gkyl_range_iter_next(&iter)) { + long start = gkyl_range_idx(&(bdata[tbid].skin_ghost.lower_ghost[tdir]), iter.idx); + + if ((bdata[tbid].skin_ghost.lower_ghost[tdir].upper[0] - bdata[tbid].skin_ghost.lower_ghost[tdir].lower[0]) == 1) { + memcpy(gkyl_array_fetch(fld_elc[tbid], start), + ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * ((int)(ref_factor_inv * count)), fld_elc[tbid]->esznc); + memcpy(gkyl_array_fetch(fld_ion[tbid], start), + ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * ((int)(ref_factor_inv * count)), fld_ion[tbid]->esznc); + memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), + ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * ((int)(ref_factor_inv * count)), fld_maxwell[tbid]->esznc); + count += 1; + } + else { + memcpy(gkyl_array_fetch(fld_elc[tbid], start), + ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld_elc[tbid]->esznc); + memcpy(gkyl_array_fetch(fld_ion[tbid], start), + ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld_ion[tbid]->esznc); + memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), + ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld_maxwell[tbid]->esznc); + count += 1; + } + } +} + +void +block_coupled_ll_restriction_op(const int tbid, const int tdir, const int i, const int d, const struct five_moment_block_data bdata[], + const struct gkyl_array* bc_buffer_elc, const struct gkyl_array* bc_buffer_ion, const struct gkyl_array* bc_buffer_maxwell, + struct gkyl_array* fld_elc[], struct gkyl_array* fld_ion[], struct gkyl_array* fld_maxwell[]) +{ + struct gkyl_range_iter iter; + gkyl_range_iter_init(&iter, &(bdata[tbid].skin_ghost.lower_ghost[tdir])); + + int ref_factor = (int)(bdata[i].skin_ghost.lower_skin[d].volume / bdata[tbid].skin_ghost.lower_ghost[tdir].volume); + + long count = 0; + while (gkyl_range_iter_next(&iter)) { + long start = gkyl_range_idx(&(bdata[tbid].skin_ghost.lower_ghost[tdir]), iter.idx); + + if ((bdata[tbid].skin_ghost.lower_ghost[tdir].upper[0] - bdata[tbid].skin_ghost.lower_ghost[tdir].lower[0]) == 1) { + memcpy(gkyl_array_fetch(fld_elc[tbid], start), + ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * (ref_factor * count), fld_elc[tbid]->esznc); + memcpy(gkyl_array_fetch(fld_ion[tbid], start), + ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * (ref_factor * count), fld_ion[tbid]->esznc); + memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), + ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * (ref_factor * count), fld_maxwell[tbid]->esznc); + count += 1; + } + else { + memcpy(gkyl_array_fetch(fld_elc[tbid], start), + ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld_elc[tbid]->esznc); + memcpy(gkyl_array_fetch(fld_ion[tbid], start), + ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld_ion[tbid]->esznc); + memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), + ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld_maxwell[tbid]->esznc); + count += 1; + } + } +} + +void +block_coupled_lu_projection_op(const int tbid, const int tdir, const int i, const int d, const struct five_moment_block_data bdata[], + const struct gkyl_array* bc_buffer_elc, const struct gkyl_array* bc_buffer_ion, const struct gkyl_array* bc_buffer_maxwell, + struct gkyl_array* fld_elc[], struct gkyl_array* fld_ion[], struct gkyl_array* fld_maxwell[]) +{ + struct gkyl_range_iter iter; + gkyl_range_iter_init(&iter, &(bdata[tbid].skin_ghost.upper_ghost[tdir])); + + double ref_factor_inv = ((double)bdata[i].skin_ghost.lower_skin[d].volume / (double)bdata[tbid].skin_ghost.upper_ghost[tdir].volume); + + long count = 0; + while (gkyl_range_iter_next(&iter)) { + long start = gkyl_range_idx(&(bdata[tbid].skin_ghost.upper_ghost[tdir]), iter.idx); + + if ((bdata[tbid].skin_ghost.upper_ghost[tdir].upper[0] - bdata[tbid].skin_ghost.upper_ghost[tdir].lower[0]) == 1) { + memcpy(gkyl_array_fetch(fld_elc[tbid], start), + ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * ((int)(ref_factor_inv * count)), fld_elc[tbid]->esznc); + memcpy(gkyl_array_fetch(fld_ion[tbid], start), + ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * ((int)(ref_factor_inv * count)), fld_ion[tbid]->esznc); + memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), + ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * ((int)(ref_factor_inv * count)), fld_maxwell[tbid]->esznc); + count += 1; + } + else { + memcpy(gkyl_array_fetch(fld_elc[tbid], start), + ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld_elc[tbid]->esznc); + memcpy(gkyl_array_fetch(fld_ion[tbid], start), + ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld_ion[tbid]->esznc); + memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), + ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld_maxwell[tbid]->esznc); + count += 1; + } + } +} + +void +block_coupled_lu_restriction_op(const int tbid, const int tdir, const int i, const int d, const struct five_moment_block_data bdata[], + const struct gkyl_array* bc_buffer_elc, const struct gkyl_array* bc_buffer_ion, const struct gkyl_array* bc_buffer_maxwell, + struct gkyl_array* fld_elc[], struct gkyl_array* fld_ion[], struct gkyl_array* fld_maxwell[]) +{ + struct gkyl_range_iter iter; + gkyl_range_iter_init(&iter, &(bdata[tbid].skin_ghost.upper_ghost[tdir])); + + int ref_factor = (int)(bdata[i].skin_ghost.lower_skin[d].volume / bdata[tbid].skin_ghost.upper_ghost[tdir].volume); + + long count = 0; + while (gkyl_range_iter_next(&iter)) { + long start = gkyl_range_idx(&(bdata[tbid].skin_ghost.upper_ghost[tdir]), iter.idx); + + if ((bdata[tbid].skin_ghost.upper_ghost[tdir].upper[0] - bdata[tbid].skin_ghost.upper_ghost[tdir].lower[0]) == 1) { + memcpy(gkyl_array_fetch(fld_elc[tbid], start), + ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * (ref_factor * count), fld_elc[tbid]->esznc); + memcpy(gkyl_array_fetch(fld_ion[tbid], start), + ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * (ref_factor * count), fld_ion[tbid]->esznc); + memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), + ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * (ref_factor * count), fld_maxwell[tbid]->esznc); + count += 1; + } + else { + memcpy(gkyl_array_fetch(fld_elc[tbid], start), + ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld_elc[tbid]->esznc); + memcpy(gkyl_array_fetch(fld_ion[tbid], start), + ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld_ion[tbid]->esznc); + memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), + ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld_maxwell[tbid]->esznc); + count += 1; + } + } +} + +void +block_coupled_ul_projection_op(const int tbid, const int tdir, const int i, const int d, const struct five_moment_block_data bdata[], + const struct gkyl_array* bc_buffer_elc, const struct gkyl_array* bc_buffer_ion, const struct gkyl_array* bc_buffer_maxwell, + struct gkyl_array* fld_elc[], struct gkyl_array* fld_ion[], struct gkyl_array* fld_maxwell[]) +{ + struct gkyl_range_iter iter; + gkyl_range_iter_init(&iter, &(bdata[tbid].skin_ghost.lower_ghost[tdir])); + + double ref_factor_inv = ((double)bdata[i].skin_ghost.upper_skin[d].volume / (double)bdata[tbid].skin_ghost.lower_ghost[tdir].volume); + + long count = 0; + while (gkyl_range_iter_next(&iter)) { + long start = gkyl_range_idx(&(bdata[tbid].skin_ghost.lower_ghost[tdir]), iter.idx); + + if ((bdata[tbid].skin_ghost.lower_ghost[tdir].upper[0] - bdata[tbid].skin_ghost.lower_ghost[tdir].lower[0]) == 1) { + memcpy(gkyl_array_fetch(fld_elc[tbid], start), + ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * ((int)(ref_factor_inv * count)), fld_elc[tbid]->esznc); + memcpy(gkyl_array_fetch(fld_ion[tbid], start), + ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * ((int)(ref_factor_inv * count)), fld_ion[tbid]->esznc); + memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), + ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * ((int)(ref_factor_inv * count)), fld_maxwell[tbid]->esznc); + count += 1; + } + else { + memcpy(gkyl_array_fetch(fld_elc[tbid], start), + ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld_elc[tbid]->esznc); + memcpy(gkyl_array_fetch(fld_ion[tbid], start), + ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld_ion[tbid]->esznc); + memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), + ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld_maxwell[tbid]->esznc); + count += 1; + } + } +} + +void +block_coupled_ul_restriction_op(const int tbid, const int tdir, const int i, const int d, const struct five_moment_block_data bdata[], + const struct gkyl_array* bc_buffer_elc, const struct gkyl_array* bc_buffer_ion, const struct gkyl_array* bc_buffer_maxwell, + struct gkyl_array* fld_elc[], struct gkyl_array* fld_ion[], struct gkyl_array* fld_maxwell[]) +{ + struct gkyl_range_iter iter; + gkyl_range_iter_init(&iter, &(bdata[tbid].skin_ghost.lower_ghost[tdir])); + + int ref_factor = (int)(bdata[i].skin_ghost.upper_skin[d].volume / bdata[tbid].skin_ghost.lower_ghost[tdir].volume); + + long count = 0; + while (gkyl_range_iter_next(&iter)) { + long start = gkyl_range_idx(&(bdata[tbid].skin_ghost.lower_ghost[tdir]), iter.idx); + + if ((bdata[tbid].skin_ghost.lower_ghost[tdir].upper[0] - bdata[tbid].skin_ghost.lower_ghost[tdir].lower[0]) == 1) { + memcpy(gkyl_array_fetch(fld_elc[tbid], start), + ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * (ref_factor * count), fld_elc[tbid]->esznc); + memcpy(gkyl_array_fetch(fld_ion[tbid], start), + ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * (ref_factor * count), fld_ion[tbid]->esznc); + memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), + ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * (ref_factor * count), fld_maxwell[tbid]->esznc); + count += 1; + } + else { + memcpy(gkyl_array_fetch(fld_elc[tbid], start), + ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld_elc[tbid]->esznc); + memcpy(gkyl_array_fetch(fld_ion[tbid], start), + ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld_ion[tbid]->esznc); + memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), + ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld_maxwell[tbid]->esznc); + count += 1; + } + } +} + +void +block_coupled_uu_projection_op(const int tbid, const int tdir, const int i, const int d, const struct five_moment_block_data bdata[], + const struct gkyl_array* bc_buffer_elc, const struct gkyl_array* bc_buffer_ion, const struct gkyl_array* bc_buffer_maxwell, + struct gkyl_array* fld_elc[], struct gkyl_array* fld_ion[], struct gkyl_array* fld_maxwell[]) +{ + struct gkyl_range_iter iter; + gkyl_range_iter_init(&iter, &(bdata[tbid].skin_ghost.upper_ghost[tdir])); + + double ref_factor_inv = ((double)bdata[i].skin_ghost.upper_skin[d].volume / (double)bdata[tbid].skin_ghost.upper_ghost[tdir].volume); + + long count = 0; + while (gkyl_range_iter_next(&iter)) { + long start = gkyl_range_idx(&(bdata[tbid].skin_ghost.upper_ghost[tdir]), iter.idx); + + if ((bdata[tbid].skin_ghost.upper_ghost[tdir].upper[0] - bdata[tbid].skin_ghost.upper_ghost[tdir].lower[0]) == 1) { + memcpy(gkyl_array_fetch(fld_elc[tbid], start), + ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * ((int)(ref_factor_inv * count)), fld_elc[tbid]->esznc); + memcpy(gkyl_array_fetch(fld_ion[tbid], start), + ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * ((int)(ref_factor_inv * count)), fld_ion[tbid]->esznc); + memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), + ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * ((int)(ref_factor_inv * count)), fld_maxwell[tbid]->esznc); + count += 1; + } + else { + memcpy(gkyl_array_fetch(fld_elc[tbid], start), + ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld_elc[tbid]->esznc); + memcpy(gkyl_array_fetch(fld_ion[tbid], start), + ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld_ion[tbid]->esznc); + memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), + ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld_maxwell[tbid]->esznc); + count += 1; + } + } +} + +void +block_coupled_uu_restriction_op(const int tbid, const int tdir, const int i, const int d, const struct five_moment_block_data bdata[], + const struct gkyl_array* bc_buffer_elc, const struct gkyl_array* bc_buffer_ion, const struct gkyl_array* bc_buffer_maxwell, + struct gkyl_array* fld_elc[], struct gkyl_array* fld_ion[], struct gkyl_array* fld_maxwell[]) +{ + struct gkyl_range_iter iter; + gkyl_range_iter_init(&iter, &(bdata[tbid].skin_ghost.upper_ghost[tdir])); + + int ref_factor = (int)(bdata[i].skin_ghost.upper_skin[d].volume / bdata[tbid].skin_ghost.upper_ghost[tdir].volume); + + long count = 0; + while (gkyl_range_iter_next(&iter)) { + long start = gkyl_range_idx(&(bdata[tbid].skin_ghost.upper_ghost[tdir]), iter.idx); + + if ((bdata[tbid].skin_ghost.upper_ghost[tdir].upper[0] - bdata[tbid].skin_ghost.upper_ghost[tdir].lower[0]) == 1) { + memcpy(gkyl_array_fetch(fld_elc[tbid], start), + ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * (ref_factor * count), fld_elc[tbid]->esznc); + memcpy(gkyl_array_fetch(fld_ion[tbid], start), + ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * (ref_factor * count), fld_ion[tbid]->esznc); + memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), + ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * (ref_factor * count), fld_maxwell[tbid]->esznc); + count += 1; + } + else { + memcpy(gkyl_array_fetch(fld_elc[tbid], start), + ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld_elc[tbid]->esznc); + memcpy(gkyl_array_fetch(fld_ion[tbid], start), + ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld_ion[tbid]->esznc); + memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), + ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld_maxwell[tbid]->esznc); + count += 1; + } + } +} + void five_moment_sync_blocks(const struct gkyl_block_topo* btopo, const struct five_moment_block_data bdata[], struct gkyl_array* fld_elc[], struct gkyl_array* fld_ion[], struct gkyl_array* fld_maxwell[]) @@ -447,64 +727,12 @@ five_moment_sync_blocks(const struct gkyl_block_topo* btopo, const struct five_m gkyl_array_copy_from_buffer(fld_maxwell[tbid], bc_buffer_maxwell->data, &(bdata[tbid].skin_ghost.lower_ghost[tdir])); } else if (bdata[i].skin_ghost.lower_skin[d].volume > bdata[tbid].skin_ghost.lower_ghost[tdir].volume) { - struct gkyl_range_iter iter; - gkyl_range_iter_init(&iter, &(bdata[tbid].skin_ghost.lower_ghost[tdir])); - - int ref_factor = (int)(bdata[i].skin_ghost.lower_skin[d].volume / bdata[tbid].skin_ghost.lower_ghost[tdir].volume); - - long count = 0; - while (gkyl_range_iter_next(&iter)) { - long start = gkyl_range_idx(&(bdata[tbid].skin_ghost.lower_ghost[tdir]), iter.idx); - - if ((bdata[tbid].skin_ghost.lower_ghost[tdir].upper[0] - bdata[tbid].skin_ghost.lower_ghost[tdir].lower[0]) == 1) { - memcpy(gkyl_array_fetch(fld_elc[tbid], start), - ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * (ref_factor * count), fld_elc[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_ion[tbid], start), - ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * (ref_factor * count), fld_ion[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), - ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * (ref_factor * count), fld_maxwell[tbid]->esznc); - count += 1; - } - else { - memcpy(gkyl_array_fetch(fld_elc[tbid], start), - ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld_elc[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_ion[tbid], start), - ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld_ion[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), - ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld_maxwell[tbid]->esznc); - count += 1; - } - } + block_coupled_ll_restriction_op(tbid, tdir, i, d, bdata, bc_buffer_elc, bc_buffer_ion, bc_buffer_maxwell, + fld_elc, fld_ion, fld_maxwell); } else if (bdata[i].skin_ghost.lower_skin[d].volume < bdata[tbid].skin_ghost.lower_ghost[tdir].volume) { - struct gkyl_range_iter iter; - gkyl_range_iter_init(&iter, &(bdata[tbid].skin_ghost.lower_ghost[tdir])); - - double ref_factor_inv = ((double)bdata[i].skin_ghost.lower_skin[d].volume / (double)bdata[tbid].skin_ghost.lower_ghost[tdir].volume); - - long count = 0; - while (gkyl_range_iter_next(&iter)) { - long start = gkyl_range_idx(&(bdata[tbid].skin_ghost.lower_ghost[tdir]), iter.idx); - - if ((bdata[tbid].skin_ghost.lower_ghost[tdir].upper[0] - bdata[tbid].skin_ghost.lower_ghost[tdir].lower[0]) == 1) { - memcpy(gkyl_array_fetch(fld_elc[tbid], start), - ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * ((int)(ref_factor_inv * count)), fld_elc[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_ion[tbid], start), - ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * ((int)(ref_factor_inv * count)), fld_ion[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), - ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * ((int)(ref_factor_inv * count)), fld_maxwell[tbid]->esznc); - count += 1; - } - else { - memcpy(gkyl_array_fetch(fld_elc[tbid], start), - ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld_elc[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_ion[tbid], start), - ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld_ion[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), - ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld_maxwell[tbid]->esznc); - count += 1; - } - } + block_coupled_ll_projection_op(tbid, tdir, i, d, bdata, bc_buffer_elc, bc_buffer_ion, bc_buffer_maxwell, + fld_elc, fld_ion, fld_maxwell); } } else if (te[0].edge == GKYL_UPPER_POSITIVE) { @@ -514,64 +742,12 @@ five_moment_sync_blocks(const struct gkyl_block_topo* btopo, const struct five_m gkyl_array_copy_from_buffer(fld_maxwell[tbid], bc_buffer_maxwell->data, &(bdata[tbid].skin_ghost.upper_ghost[tdir])); } else if (bdata[i].skin_ghost.lower_skin[d].volume > bdata[tbid].skin_ghost.upper_ghost[tdir].volume) { - struct gkyl_range_iter iter; - gkyl_range_iter_init(&iter, &(bdata[tbid].skin_ghost.upper_ghost[tdir])); - - int ref_factor = (int)(bdata[i].skin_ghost.lower_skin[d].volume / bdata[tbid].skin_ghost.upper_ghost[tdir].volume); - - long count = 0; - while (gkyl_range_iter_next(&iter)) { - long start = gkyl_range_idx(&(bdata[tbid].skin_ghost.upper_ghost[tdir]), iter.idx); - - if ((bdata[tbid].skin_ghost.upper_ghost[tdir].upper[0] - bdata[tbid].skin_ghost.upper_ghost[tdir].lower[0]) == 1) { - memcpy(gkyl_array_fetch(fld_elc[tbid], start), - ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * (ref_factor * count), fld_elc[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_ion[tbid], start), - ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * (ref_factor * count), fld_ion[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), - ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * (ref_factor * count), fld_maxwell[tbid]->esznc); - count += 1; - } - else { - memcpy(gkyl_array_fetch(fld_elc[tbid], start), - ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld_elc[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_ion[tbid], start), - ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld_ion[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), - ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld_maxwell[tbid]->esznc); - count += 1; - } - } + block_coupled_lu_restriction_op(tbid, tdir, i, d, bdata, bc_buffer_elc, bc_buffer_ion, bc_buffer_maxwell, + fld_elc, fld_ion, fld_maxwell); } else if (bdata[i].skin_ghost.lower_skin[d].volume < bdata[tbid].skin_ghost.upper_ghost[tdir].volume) { - struct gkyl_range_iter iter; - gkyl_range_iter_init(&iter, &(bdata[tbid].skin_ghost.upper_ghost[tdir])); - - double ref_factor_inv = ((double)bdata[i].skin_ghost.lower_skin[d].volume / (double)bdata[tbid].skin_ghost.upper_ghost[tdir].volume); - - long count = 0; - while (gkyl_range_iter_next(&iter)) { - long start = gkyl_range_idx(&(bdata[tbid].skin_ghost.upper_ghost[tdir]), iter.idx); - - if ((bdata[tbid].skin_ghost.upper_ghost[tdir].upper[0] - bdata[tbid].skin_ghost.upper_ghost[tdir].lower[0]) == 1) { - memcpy(gkyl_array_fetch(fld_elc[tbid], start), - ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * ((int)(ref_factor_inv * count)), fld_elc[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_ion[tbid], start), - ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * ((int)(ref_factor_inv * count)), fld_ion[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), - ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * ((int)(ref_factor_inv * count)), fld_maxwell[tbid]->esznc); - count += 1; - } - else { - memcpy(gkyl_array_fetch(fld_elc[tbid], start), - ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld_elc[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_ion[tbid], start), - ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld_ion[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), - ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld_maxwell[tbid]->esznc); - count += 1; - } - } + block_coupled_lu_projection_op(tbid, tdir, i, d, bdata, bc_buffer_elc, bc_buffer_ion, bc_buffer_maxwell, + fld_elc, fld_ion, fld_maxwell); } } } @@ -595,64 +771,12 @@ five_moment_sync_blocks(const struct gkyl_block_topo* btopo, const struct five_m gkyl_array_copy_from_buffer(fld_maxwell[tbid], bc_buffer_maxwell->data, &(bdata[tbid].skin_ghost.lower_ghost[tdir])); } else if (bdata[i].skin_ghost.upper_skin[d].volume > bdata[tbid].skin_ghost.lower_ghost[tdir].volume) { - struct gkyl_range_iter iter; - gkyl_range_iter_init(&iter, &(bdata[tbid].skin_ghost.lower_ghost[tdir])); - - int ref_factor = (int)(bdata[i].skin_ghost.upper_skin[d].volume / bdata[tbid].skin_ghost.lower_ghost[tdir].volume); - - long count = 0; - while (gkyl_range_iter_next(&iter)) { - long start = gkyl_range_idx(&(bdata[tbid].skin_ghost.lower_ghost[tdir]), iter.idx); - - if ((bdata[tbid].skin_ghost.lower_ghost[tdir].upper[0] - bdata[tbid].skin_ghost.lower_ghost[tdir].lower[0]) == 1) { - memcpy(gkyl_array_fetch(fld_elc[tbid], start), - ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * (ref_factor * count), fld_elc[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_ion[tbid], start), - ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * (ref_factor * count), fld_ion[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), - ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * (ref_factor * count), fld_maxwell[tbid]->esznc); - count += 1; - } - else { - memcpy(gkyl_array_fetch(fld_elc[tbid], start), - ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld_elc[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_ion[tbid], start), - ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld_ion[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), - ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld_maxwell[tbid]->esznc); - count += 1; - } - } + block_coupled_ul_restriction_op(tbid, tdir, i, d, bdata, bc_buffer_elc, bc_buffer_ion, bc_buffer_maxwell, + fld_elc, fld_ion, fld_maxwell); } else if (bdata[i].skin_ghost.upper_skin[d].volume < bdata[tbid].skin_ghost.lower_ghost[tdir].volume) { - struct gkyl_range_iter iter; - gkyl_range_iter_init(&iter, &(bdata[tbid].skin_ghost.lower_ghost[tdir])); - - double ref_factor_inv = ((double)bdata[i].skin_ghost.upper_skin[d].volume / (double)bdata[tbid].skin_ghost.lower_ghost[tdir].volume); - - long count = 0; - while (gkyl_range_iter_next(&iter)) { - long start = gkyl_range_idx(&(bdata[tbid].skin_ghost.lower_ghost[tdir]), iter.idx); - - if ((bdata[tbid].skin_ghost.lower_ghost[tdir].upper[0] - bdata[tbid].skin_ghost.lower_ghost[tdir].lower[0]) == 1) { - memcpy(gkyl_array_fetch(fld_elc[tbid], start), - ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * ((int)(ref_factor_inv * count)), fld_elc[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_ion[tbid], start), - ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * ((int)(ref_factor_inv * count)), fld_ion[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), - ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * ((int)(ref_factor_inv * count)), fld_maxwell[tbid]->esznc); - count += 1; - } - else { - memcpy(gkyl_array_fetch(fld_elc[tbid], start), - ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld_elc[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_ion[tbid], start), - ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld_ion[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), - ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld_maxwell[tbid]->esznc); - count += 1; - } - } + block_coupled_ul_projection_op(tbid, tdir, i, d, bdata, bc_buffer_elc, bc_buffer_ion, bc_buffer_maxwell, + fld_elc, fld_ion, fld_maxwell); } } else if (te[1].edge == GKYL_UPPER_POSITIVE) { @@ -662,64 +786,12 @@ five_moment_sync_blocks(const struct gkyl_block_topo* btopo, const struct five_m gkyl_array_copy_from_buffer(fld_maxwell[tbid], bc_buffer_maxwell->data, &(bdata[tbid].skin_ghost.upper_ghost[tdir])); } else if (bdata[i].skin_ghost.upper_skin[d].volume > bdata[tbid].skin_ghost.upper_ghost[tdir].volume) { - struct gkyl_range_iter iter; - gkyl_range_iter_init(&iter, &(bdata[tbid].skin_ghost.upper_ghost[tdir])); - - int ref_factor = (int)(bdata[i].skin_ghost.upper_skin[d].volume / bdata[tbid].skin_ghost.upper_ghost[tdir].volume); - - long count = 0; - while (gkyl_range_iter_next(&iter)) { - long start = gkyl_range_idx(&(bdata[tbid].skin_ghost.upper_ghost[tdir]), iter.idx); - - if ((bdata[tbid].skin_ghost.upper_ghost[tdir].upper[0] - bdata[tbid].skin_ghost.upper_ghost[tdir].lower[0]) == 1) { - memcpy(gkyl_array_fetch(fld_elc[tbid], start), - ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * (ref_factor * count), fld_elc[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_ion[tbid], start), - ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * (ref_factor * count), fld_ion[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), - ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * (ref_factor * count), fld_maxwell[tbid]->esznc); - count += 1; - } - else { - memcpy(gkyl_array_fetch(fld_elc[tbid], start), - ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld_elc[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_ion[tbid], start), - ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld_ion[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), - ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld_maxwell[tbid]->esznc); - count += 1; - } - } + block_coupled_uu_restriction_op(tbid, tdir, i, d, bdata, bc_buffer_elc, bc_buffer_ion, bc_buffer_maxwell, + fld_elc, fld_ion, fld_maxwell); } else if (bdata[i].skin_ghost.upper_skin[d].volume < bdata[tbid].skin_ghost.upper_ghost[tdir].volume) { - struct gkyl_range_iter iter; - gkyl_range_iter_init(&iter, &(bdata[tbid].skin_ghost.upper_ghost[tdir])); - - double ref_factor_inv = ((double)bdata[i].skin_ghost.upper_skin[d].volume / (double)bdata[tbid].skin_ghost.upper_ghost[tdir].volume); - - long count = 0; - while (gkyl_range_iter_next(&iter)) { - long start = gkyl_range_idx(&(bdata[tbid].skin_ghost.upper_ghost[tdir]), iter.idx); - - if ((bdata[tbid].skin_ghost.upper_ghost[tdir].upper[0] - bdata[tbid].skin_ghost.upper_ghost[tdir].lower[0]) == 1) { - memcpy(gkyl_array_fetch(fld_elc[tbid], start), - ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * ((int)(ref_factor_inv * count)), fld_elc[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_ion[tbid], start), - ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * ((int)(ref_factor_inv * count)), fld_ion[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), - ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * ((int)(ref_factor_inv * count)), fld_maxwell[tbid]->esznc); - count += 1; - } - else { - memcpy(gkyl_array_fetch(fld_elc[tbid], start), - ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld_elc[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_ion[tbid], start), - ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld_ion[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), - ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld_maxwell[tbid]->esznc); - count += 1; - } - } + block_coupled_uu_projection_op(tbid, tdir, i, d, bdata, bc_buffer_elc, bc_buffer_ion, bc_buffer_maxwell, + fld_elc, fld_ion, fld_maxwell); } } } diff --git a/amr/gkyl_amr_block_coupled_priv.h b/amr/gkyl_amr_block_coupled_priv.h index b132759b9..bda1ad807 100644 --- a/amr/gkyl_amr_block_coupled_priv.h +++ b/amr/gkyl_amr_block_coupled_priv.h @@ -213,6 +213,158 @@ void five_moment_block_bc_updaters_release(struct five_moment_block_data* bdata) void five_moment_block_bc_updaters_apply(const struct five_moment_block_data* bdata, double tm, struct gkyl_array* fld_elc, struct gkyl_array *fld_ion, struct gkyl_array* fld_maxwell); +/** +* Coarse-to-fine projection operator for coupled, block-structured AMR, assuming a lower coarse block and a lower fine block. +* +* @param tbid Target (fine) block ID. +* @param tdir Target (fine) block direction. +* @param i Reference (coarse) block ID. +* @param d Reference (coarse) block direction. +* @param bdata Block-structured data for the Euler equations. +* @param bc_buffer_elc Buffer for applying electron boundary conditions. +* @param bc_buffer_ion Buffer for applying ion boundary conditions. +* @param bc_buffer_maxwell Buffer for applying Maxwell field boundary conditions. +* @param fld_elc Output array (electons). +* @param fld_ion Output array (ions). +* @param fld_maxwell Output array (Maxwell field). +*/ +void block_coupled_ll_projection_op(const int tbid, const int tdir, const int i, const int d, const struct five_moment_block_data bdata[], + const struct gkyl_array* bc_buffer_elc, const struct gkyl_array* bc_buffer_ion, const struct gkyl_array* bc_buffer_maxwell, + struct gkyl_array* fld_elc[], struct gkyl_array* fld_ion[], struct gkyl_array* fld_maxwell[]); + +/** +* Fine-to-coarse restriction operator for coupled, block-structured AMR, assuming a lower fine block and a lower coarse block. +* +* @param tbid Target (coarse) block ID. +* @param tdir Target (coarse) block direction. +* @param i Reference (fine) block ID. +* @param d Reference (fine) block direction. +* @param bdata Block-structured data for the Euler equations. +* @param bc_buffer_elc Buffer for applying electron boundary conditions. +* @param bc_buffer_ion Buffer for applying ion boundary conditions. +* @param bc_buffer_maxwell Buffer for applying Maxwell field boundary conditions. +* @param fld_elc Output array (electons). +* @param fld_ion Output array (ions). +* @param fld_maxwell Output array (Maxwell field). +*/ +void block_coupled_ll_restriction_op(const int tbid, const int tdir, const int i, const int d, const struct five_moment_block_data bdata[], + const struct gkyl_array* bc_buffer_elc, const struct gkyl_array* bc_buffer_ion, const struct gkyl_array* bc_buffer_maxwell, + struct gkyl_array* fld_elc[], struct gkyl_array* fld_ion[], struct gkyl_array* fld_maxwell[]); + +/** +* Coarse-to-fine projection operator for coupled, block-structured AMR, assuming a lower coarse block and an upper fine block. +* +* @param tbid Target (fine) block ID. +* @param tdir Target (fine) block direction. +* @param i Reference (coarse) block ID. +* @param d Reference (coarse) block direction. +* @param bdata Block-structured data for the Euler equations. +* @param bc_buffer_elc Buffer for applying electron boundary conditions. +* @param bc_buffer_ion Buffer for applying ion boundary conditions. +* @param bc_buffer_maxwell Buffer for applying Maxwell field boundary conditions. +* @param fld_elc Output array (electons). +* @param fld_ion Output array (ions). +* @param fld_maxwell Output array (Maxwell field). +*/ +void block_coupled_lu_projection_op(const int tbid, const int tdir, const int i, const int d, const struct five_moment_block_data bdata[], + const struct gkyl_array* bc_buffer_elc, const struct gkyl_array* bc_buffer_ion, const struct gkyl_array* bc_buffer_maxwell, + struct gkyl_array* fld_elc[], struct gkyl_array* fld_ion[], struct gkyl_array* fld_maxwell[]); + +/** +* Fine-to-coarse restriction operator for coupled, block-structured AMR, assuming a lower fine block and an upper coarse block. +* +* @param tbid Target (coarse) block ID. +* @param tdir Target (coarse) block direction. +* @param i Reference (fine) block ID. +* @param d Reference (fine) block direction. +* @param bdata Block-structured data for the Euler equations. +* @param bc_buffer_elc Buffer for applying electron boundary conditions. +* @param bc_buffer_ion Buffer for applying ion boundary conditions. +* @param bc_buffer_maxwell Buffer for applying Maxwell field boundary conditions. +* @param fld_elc Output array (electons). +* @param fld_ion Output array (ions). +* @param fld_maxwell Output array (Maxwell field). +*/ +void block_coupled_lu_restriction_op(const int tbid, const int tdir, const int i, const int d, const struct five_moment_block_data bdata[], + const struct gkyl_array* bc_buffer_elc, const struct gkyl_array* bc_buffer_ion, const struct gkyl_array* bc_buffer_maxwell, + struct gkyl_array* fld_elc[], struct gkyl_array* fld_ion[], struct gkyl_array* fld_maxwell[]); + +/** +* Coarse-to-fine projection operator for coupled, block-structured AMR, assuming an upper coarse block and a lower fine block. +* +* @param tbid Target (fine) block ID. +* @param tdir Target (fine) block direction. +* @param i Reference (coarse) block ID. +* @param d Reference (coarse) block direction. +* @param bdata Block-structured data for the Euler equations. +* @param bc_buffer_elc Buffer for applying electron boundary conditions. +* @param bc_buffer_ion Buffer for applying ion boundary conditions. +* @param bc_buffer_maxwell Buffer for applying Maxwell field boundary conditions. +* @param fld_elc Output array (electons). +* @param fld_ion Output array (ions). +* @param fld_maxwell Output array (Maxwell field). +*/ +void block_coupled_ul_projection_op(const int tbid, const int tdir, const int i, const int d, const struct five_moment_block_data bdata[], + const struct gkyl_array* bc_buffer_elc, const struct gkyl_array* bc_buffer_ion, const struct gkyl_array* bc_buffer_maxwell, + struct gkyl_array* fld_elc[], struct gkyl_array* fld_ion[], struct gkyl_array* fld_maxwell[]); + +/** +* Fine-to-coarse restriction operator for coupled, block-structured AMR, assuming an upper fine block and a lower coarse block. +* +* @param tbid Target (coarse) block ID. +* @param tdir Target (coarse) block direction. +* @param i Reference (fine) block ID. +* @param d Reference (fine) block direction. +* @param bdata Block-structured data for the Euler equations. +* @param bc_buffer_elc Buffer for applying electron boundary conditions. +* @param bc_buffer_ion Buffer for applying ion boundary conditions. +* @param bc_buffer_maxwell Buffer for applying Maxwell field boundary conditions. +* @param fld_elc Output array (electons). +* @param fld_ion Output array (ions). +* @param fld_maxwell Output array (Maxwell field). +*/ +void block_coupled_ul_restriction_op(const int tbid, const int tdir, const int i, const int d, const struct five_moment_block_data bdata[], + const struct gkyl_array* bc_buffer_elc, const struct gkyl_array* bc_buffer_ion, const struct gkyl_array* bc_buffer_maxwell, + struct gkyl_array* fld_elc[], struct gkyl_array* fld_ion[], struct gkyl_array* fld_maxwell[]); + +/** +* Coarse-to-fine projection operator for coupled, block-structured AMR, assuming an upper coarse block and an upper fine block. +* +* @param tbid Target (fine) block ID. +* @param tdir Target (fine) block direction. +* @param i Reference (coarse) block ID. +* @param d Reference (coarse) block direction. +* @param bdata Block-structured data for the Euler equations. +* @param bc_buffer_elc Buffer for applying electron boundary conditions. +* @param bc_buffer_ion Buffer for applying ion boundary conditions. +* @param bc_buffer_maxwell Buffer for applying Maxwell field boundary conditions. +* @param fld_elc Output array (electons). +* @param fld_ion Output array (ions). +* @param fld_maxwell Output array (Maxwell field). +*/ +void block_coupled_uu_projection_op(const int tbid, const int tdir, const int i, const int d, const struct five_moment_block_data bdata[], + const struct gkyl_array* bc_buffer_elc, const struct gkyl_array* bc_buffer_ion, const struct gkyl_array* bc_buffer_maxwell, + struct gkyl_array* fld_elc[], struct gkyl_array* fld_ion[], struct gkyl_array* fld_maxwell[]); + +/** +* Fine-to-coarse restriction operator for coupled, block-structured AMR, assuming an upper fine block and an upper coarse block. +* +* @param tbid Target (coarse) block ID. +* @param tdir Target (coarse) block direction. +* @param i Reference (fine) block ID. +* @param d Reference (fine) block direction. +* @param bdata Block-structured data for the Euler equations. +* @param bc_buffer_elc Buffer for applying electron boundary conditions. +* @param bc_buffer_ion Buffer for applying ion boundary conditions. +* @param bc_buffer_maxwell Buffer for applying Maxwell field boundary conditions. +* @param fld_elc Output array (electons). +* @param fld_ion Output array (ions). +* @param fld_maxwell Output array (Maxwell field). +*/ +void block_coupled_uu_restriction_op(const int tbid, const int tdir, const int i, const int d, const struct five_moment_block_data bdata[], + const struct gkyl_array* bc_buffer_elc, const struct gkyl_array* bc_buffer_ion, const struct gkyl_array* bc_buffer_maxwell, + struct gkyl_array* fld_elc[], struct gkyl_array* fld_ion[], struct gkyl_array* fld_maxwell[]); + /** * Synchronize all blocks in the block AMR hierarchy by applying all appropriate physical (outer-block) and non-physical (inter-block) * boundary conditions for the coupled five-moment equations. From 95e30bdf1e67607afb4d260dafcbbdd843d904d6 Mon Sep 17 00:00:00 2001 From: JonathanGorard Date: Mon, 8 Jul 2024 21:49:01 -0400 Subject: [PATCH 30/32] Fixed inconsistencies in block-coupled AMR comments, and extended projection/restriction operator refactoring to the patch-structured AMR case. --- amr/amr_patch.c | 360 +++++++++++++++++------------- amr/gkyl_amr_block_coupled_priv.h | 16 +- amr/gkyl_amr_patch_priv.h | 112 ++++++++++ 3 files changed, 328 insertions(+), 160 deletions(-) diff --git a/amr/amr_patch.c b/amr/amr_patch.c index a69d74714..00fd6576c 100644 --- a/amr/amr_patch.c +++ b/amr/amr_patch.c @@ -161,6 +161,206 @@ euler_patch_bc_updaters_apply(const struct euler_patch_data* pdata, double tm, s } } +void +patch_ll_projection_op(const int tbid, const int tdir, const int i, const int d, const struct euler_patch_data pdata[], + const struct gkyl_array* bc_buffer, struct gkyl_array* fld[]) +{ + struct gkyl_range_iter iter; + gkyl_range_iter_init(&iter, &(pdata[tbid].skin_ghost.lower_ghost[tdir])); + + double ref_factor_inv = ((double)pdata[i].skin_ghost.lower_skin[d].volume / (double)pdata[tbid].skin_ghost.lower_ghost[tdir].volume); + + long count = 0; + while (gkyl_range_iter_next(&iter)) { + long start = gkyl_range_idx(&(pdata[tbid].skin_ghost.lower_ghost[tdir]), iter.idx); + + if ((pdata[tbid].skin_ghost.lower_ghost[tdir].upper[0] - pdata[tbid].skin_ghost.lower_ghost[tdir].lower[0]) == 1) { + memcpy(gkyl_array_fetch(fld[tbid], start), + ((char*) bc_buffer->data) + fld[tbid]->esznc * ((int)(ref_factor_inv * count++)), fld[tbid]->esznc); + } + else { + memcpy(gkyl_array_fetch(fld[tbid], start), + ((char*) bc_buffer->data) + fld[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld[tbid]->esznc); + count += 1; + } + } +} + +void +patch_ll_restriction_op(const int tbid, const int tdir, const int i, const int d, const struct euler_patch_data pdata[], + const struct gkyl_array* bc_buffer, struct gkyl_array* fld[]) +{ + struct gkyl_range_iter iter; + gkyl_range_iter_init(&iter, &(pdata[tbid].skin_ghost.lower_ghost[tdir])); + + int ref_factor = (int)(pdata[i].skin_ghost.lower_skin[d].volume / pdata[tbid].skin_ghost.lower_ghost[tdir].volume); + + long count = 0; + while (gkyl_range_iter_next(&iter)) { + long start = gkyl_range_idx(&(pdata[tbid].skin_ghost.lower_ghost[tdir]), iter.idx); + + if ((pdata[tbid].skin_ghost.lower_ghost[tdir].upper[0] - pdata[tbid].skin_ghost.lower_ghost[tdir].lower[0]) == 1) { + memcpy(gkyl_array_fetch(fld[tbid], start), + ((char*) bc_buffer->data) + fld[tbid]->esznc * (ref_factor * count++), fld[tbid]->esznc); + } + else { + memcpy(gkyl_array_fetch(fld[tbid], start), + ((char*) bc_buffer->data) + fld[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld[tbid]->esznc); + count += 1; + } + } +} + +void +patch_lu_projection_op(const int tbid, const int tdir, const int i, const int d, const struct euler_patch_data pdata[], + const struct gkyl_array* bc_buffer, struct gkyl_array* fld[]) +{ + struct gkyl_range_iter iter; + gkyl_range_iter_init(&iter, &(pdata[tbid].skin_ghost.upper_ghost[tdir])); + + double ref_factor_inv = ((double)pdata[i].skin_ghost.lower_skin[d].volume / (double)pdata[tbid].skin_ghost.upper_ghost[tdir].volume); + + long count = 0; + while (gkyl_range_iter_next(&iter)) { + long start = gkyl_range_idx(&(pdata[tbid].skin_ghost.upper_ghost[tdir]), iter.idx); + + if ((pdata[tbid].skin_ghost.upper_ghost[tdir].upper[0] - pdata[tbid].skin_ghost.upper_ghost[tdir].lower[0]) == 1) { + memcpy(gkyl_array_fetch(fld[tbid], start), + ((char*) bc_buffer->data) + fld[tbid]->esznc * ((int)(ref_factor_inv * count++)), fld[tbid]->esznc); + } + else { + memcpy(gkyl_array_fetch(fld[tbid], start), + ((char*) bc_buffer->data) + fld[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld[tbid]->esznc); + count += 1; + } + } +} + +void +patch_lu_restriction_op(const int tbid, const int tdir, const int i, const int d, const struct euler_patch_data pdata[], + const struct gkyl_array* bc_buffer, struct gkyl_array* fld[]) +{ + struct gkyl_range_iter iter; + gkyl_range_iter_init(&iter, &(pdata[tbid].skin_ghost.upper_ghost[tdir])); + + int ref_factor = (int)(pdata[i].skin_ghost.lower_skin[d].volume / pdata[tbid].skin_ghost.upper_ghost[tdir].volume); + + long count = 0; + while (gkyl_range_iter_next(&iter)) { + long start = gkyl_range_idx(&(pdata[tbid].skin_ghost.upper_ghost[tdir]), iter.idx); + + if ((pdata[tbid].skin_ghost.upper_ghost[tdir].upper[0] - pdata[tbid].skin_ghost.upper_ghost[tdir].lower[0]) == 1) { + memcpy(gkyl_array_fetch(fld[tbid], start), + ((char*) bc_buffer->data) + fld[tbid]->esznc * (ref_factor * count++), fld[tbid]->esznc); + } + else { + memcpy(gkyl_array_fetch(fld[tbid], start), + ((char*) bc_buffer->data) + fld[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld[tbid]->esznc); + count += 1; + } + } +} + +void +patch_ul_projection_op(const int tbid, const int tdir, const int i, const int d, const struct euler_patch_data pdata[], + const struct gkyl_array* bc_buffer, struct gkyl_array* fld[]) +{ + struct gkyl_range_iter iter; + gkyl_range_iter_init(&iter, &(pdata[tbid].skin_ghost.lower_ghost[tdir])); + + double ref_factor_inv = ((double)pdata[i].skin_ghost.upper_skin[d].volume / (double)pdata[tbid].skin_ghost.lower_ghost[tdir].volume); + + long count = 0; + while (gkyl_range_iter_next(&iter)) { + long start = gkyl_range_idx(&(pdata[tbid].skin_ghost.lower_ghost[tdir]), iter.idx); + + if ((pdata[tbid].skin_ghost.lower_ghost[tdir].upper[0] - pdata[tbid].skin_ghost.lower_ghost[tdir].lower[0]) == 1) { + memcpy(gkyl_array_fetch(fld[tbid], start), + ((char*) bc_buffer->data) + fld[tbid]->esznc * ((int)(ref_factor_inv * count++)), fld[tbid]->esznc); + } + else { + memcpy(gkyl_array_fetch(fld[tbid], start), + ((char*) bc_buffer->data) + fld[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld[tbid]->esznc); + count += 1; + } + } +} + +void +patch_ul_restriction_op(const int tbid, const int tdir, const int i, const int d, const struct euler_patch_data pdata[], + const struct gkyl_array* bc_buffer, struct gkyl_array* fld[]) +{ + struct gkyl_range_iter iter; + gkyl_range_iter_init(&iter, &(pdata[tbid].skin_ghost.lower_ghost[tdir])); + + int ref_factor = (int)(pdata[i].skin_ghost.upper_skin[d].volume / pdata[tbid].skin_ghost.lower_ghost[tdir].volume); + + long count = 0; + while (gkyl_range_iter_next(&iter)) { + long start = gkyl_range_idx(&(pdata[tbid].skin_ghost.lower_ghost[tdir]), iter.idx); + + if ((pdata[tbid].skin_ghost.lower_ghost[tdir].upper[0] - pdata[tbid].skin_ghost.lower_ghost[tdir].lower[0]) == 1) { + memcpy(gkyl_array_fetch(fld[tbid], start), + ((char*) bc_buffer->data) + fld[tbid]->esznc * (ref_factor * count++), fld[tbid]->esznc); + } + else { + memcpy(gkyl_array_fetch(fld[tbid], start), + ((char*) bc_buffer->data) + fld[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld[tbid]->esznc); + count += 1; + } + } +} + +void +patch_uu_projection_op(const int tbid, const int tdir, const int i, const int d, const struct euler_patch_data pdata[], + const struct gkyl_array* bc_buffer, struct gkyl_array* fld[]) +{ + struct gkyl_range_iter iter; + gkyl_range_iter_init(&iter, &(pdata[tbid].skin_ghost.upper_ghost[tdir])); + + double ref_factor_inv = ((double)pdata[i].skin_ghost.upper_skin[d].volume / (double)pdata[tbid].skin_ghost.upper_ghost[tdir].volume); + + long count = 0; + while (gkyl_range_iter_next(&iter)) { + long start = gkyl_range_idx(&(pdata[tbid].skin_ghost.upper_ghost[tdir]), iter.idx); + + if ((pdata[tbid].skin_ghost.upper_ghost[tdir].upper[0] - pdata[tbid].skin_ghost.upper_ghost[tdir].lower[0]) == 1) { + memcpy(gkyl_array_fetch(fld[tbid], start), + ((char*) bc_buffer->data) + fld[tbid]->esznc * ((int)(ref_factor_inv * count++)), fld[tbid]->esznc); + } + else { + memcpy(gkyl_array_fetch(fld[tbid], start), + ((char*) bc_buffer->data) + fld[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld[tbid]->esznc); + count += 1; + } + } +} + +void +patch_uu_restriction_op(const int tbid, const int tdir, const int i, const int d, const struct euler_patch_data pdata[], + const struct gkyl_array* bc_buffer, struct gkyl_array* fld[]) +{ + struct gkyl_range_iter iter; + gkyl_range_iter_init(&iter, &(pdata[tbid].skin_ghost.upper_ghost[tdir])); + + int ref_factor = (int)(pdata[i].skin_ghost.upper_skin[d].volume / pdata[tbid].skin_ghost.upper_ghost[tdir].volume); + + long count = 0; + while (gkyl_range_iter_next(&iter)) { + long start = gkyl_range_idx(&(pdata[tbid].skin_ghost.upper_ghost[tdir]), iter.idx); + + if ((pdata[tbid].skin_ghost.upper_ghost[tdir].upper[0] - pdata[tbid].skin_ghost.upper_ghost[tdir].lower[0]) == 1) { + memcpy(gkyl_array_fetch(fld[tbid], start), + ((char*) bc_buffer->data) + fld[tbid]->esznc * (ref_factor * count++), fld[tbid]->esznc); + } + else { + memcpy(gkyl_array_fetch(fld[tbid], start), + ((char*) bc_buffer->data) + fld[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld[tbid]->esznc); + count += 1; + } + } +} + void euler_sync_patches(const struct gkyl_block_topo* ptopo, const struct euler_patch_data pdata[], struct gkyl_array* fld[]) { @@ -182,46 +382,10 @@ euler_sync_patches(const struct gkyl_block_topo* ptopo, const struct euler_patch gkyl_array_copy_from_buffer(fld[tbid], bc_buffer->data, &(pdata[tbid].skin_ghost.lower_ghost[tdir])); } else if (pdata[i].skin_ghost.lower_skin[0].volume > pdata[tbid].skin_ghost.lower_ghost[tdir].volume) { - struct gkyl_range_iter iter; - gkyl_range_iter_init(&iter, &(pdata[tbid].skin_ghost.lower_ghost[tdir])); - - int ref_factor = (int)(pdata[i].skin_ghost.lower_skin[0].volume / pdata[tbid].skin_ghost.lower_ghost[tdir].volume); - - long count = 0; - while (gkyl_range_iter_next(&iter)) { - long start = gkyl_range_idx(&(pdata[tbid].skin_ghost.lower_ghost[tdir]), iter.idx); - - if ((pdata[tbid].skin_ghost.lower_ghost[tdir].upper[0] - pdata[tbid].skin_ghost.lower_ghost[tdir].lower[0]) == 1) { - memcpy(gkyl_array_fetch(fld[tbid], start), - ((char*) bc_buffer->data) + fld[tbid]->esznc * (ref_factor * count++), fld[tbid]->esznc); - } - else { - memcpy(gkyl_array_fetch(fld[tbid], start), - ((char*) bc_buffer->data) + fld[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld[tbid]->esznc); - count += 1; - } - } + patch_ll_restriction_op(tbid, tdir, i, 0, pdata, bc_buffer, fld); } else if (pdata[i].skin_ghost.lower_skin[0].volume < pdata[tbid].skin_ghost.lower_ghost[tdir].volume) { - struct gkyl_range_iter iter; - gkyl_range_iter_init(&iter, &(pdata[tbid].skin_ghost.lower_ghost[tdir])); - - double ref_factor_inv = ((double)pdata[i].skin_ghost.lower_skin[0].volume / (double)pdata[tbid].skin_ghost.lower_ghost[tdir].volume); - - long count = 0; - while (gkyl_range_iter_next(&iter)) { - long start = gkyl_range_idx(&(pdata[tbid].skin_ghost.lower_ghost[tdir]), iter.idx); - - if ((pdata[tbid].skin_ghost.lower_ghost[tdir].upper[0] - pdata[tbid].skin_ghost.lower_ghost[tdir].lower[0]) == 1) { - memcpy(gkyl_array_fetch(fld[tbid], start), - ((char*) bc_buffer->data) + fld[tbid]->esznc * ((int)(ref_factor_inv * count++)), fld[tbid]->esznc); - } - else { - memcpy(gkyl_array_fetch(fld[tbid], start), - ((char*) bc_buffer->data) + fld[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld[tbid]->esznc); - count += 1; - } - } + patch_ll_projection_op(tbid, tdir, i, 0, pdata, bc_buffer, fld); } } else if (te[0].edge == GKYL_UPPER_POSITIVE) { @@ -229,46 +393,10 @@ euler_sync_patches(const struct gkyl_block_topo* ptopo, const struct euler_patch gkyl_array_copy_from_buffer(fld[tbid], bc_buffer->data, &(pdata[tbid].skin_ghost.upper_ghost[tdir])); } else if (pdata[i].skin_ghost.lower_skin[0].volume > pdata[tbid].skin_ghost.upper_ghost[tdir].volume) { - struct gkyl_range_iter iter; - gkyl_range_iter_init(&iter, &(pdata[tbid].skin_ghost.upper_ghost[tdir])); - - int ref_factor = (int)(pdata[i].skin_ghost.lower_skin[0].volume / pdata[tbid].skin_ghost.upper_ghost[tdir].volume); - - long count = 0; - while (gkyl_range_iter_next(&iter)) { - long start = gkyl_range_idx(&(pdata[tbid].skin_ghost.upper_ghost[tdir]), iter.idx); - - if ((pdata[tbid].skin_ghost.upper_ghost[tdir].upper[0] - pdata[tbid].skin_ghost.upper_ghost[tdir].lower[0]) == 1) { - memcpy(gkyl_array_fetch(fld[tbid], start), - ((char*) bc_buffer->data) + fld[tbid]->esznc * (ref_factor * count++), fld[tbid]->esznc); - } - else { - memcpy(gkyl_array_fetch(fld[tbid], start), - ((char*) bc_buffer->data) + fld[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld[tbid]->esznc); - count += 1; - } - } + patch_lu_restriction_op(tbid, tdir, i, 0, pdata, bc_buffer, fld); } else if (pdata[i].skin_ghost.lower_skin[0].volume < pdata[tbid].skin_ghost.upper_ghost[tdir].volume) { - struct gkyl_range_iter iter; - gkyl_range_iter_init(&iter, &(pdata[tbid].skin_ghost.upper_ghost[tdir])); - - double ref_factor_inv = ((double)pdata[i].skin_ghost.lower_skin[0].volume / (double)pdata[tbid].skin_ghost.upper_ghost[tdir].volume); - - long count = 0; - while (gkyl_range_iter_next(&iter)) { - long start = gkyl_range_idx(&(pdata[tbid].skin_ghost.upper_ghost[tdir]), iter.idx); - - if ((pdata[tbid].skin_ghost.upper_ghost[tdir].upper[0] - pdata[tbid].skin_ghost.upper_ghost[tdir].lower[0]) == 1) { - memcpy(gkyl_array_fetch(fld[tbid], start), - ((char*) bc_buffer->data) + fld[tbid]->esznc * ((int)(ref_factor_inv * count++)), fld[tbid]->esznc); - } - else { - memcpy(gkyl_array_fetch(fld[tbid], start), - ((char*) bc_buffer->data) + fld[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld[tbid]->esznc); - count += 1; - } - } + patch_lu_projection_op(tbid, tdir, i, 0, pdata, bc_buffer, fld); } } } @@ -286,46 +414,10 @@ euler_sync_patches(const struct gkyl_block_topo* ptopo, const struct euler_patch gkyl_array_copy_from_buffer(fld[tbid], bc_buffer->data, &(pdata[tbid].skin_ghost.lower_ghost[tdir])); } else if (pdata[i].skin_ghost.upper_skin[0].volume > pdata[tbid].skin_ghost.lower_ghost[tdir].volume) { - struct gkyl_range_iter iter; - gkyl_range_iter_init(&iter, &(pdata[tbid].skin_ghost.lower_ghost[tdir])); - - int ref_factor = (int)(pdata[i].skin_ghost.upper_skin[0].volume / pdata[tbid].skin_ghost.lower_ghost[tdir].volume); - - long count = 0; - while (gkyl_range_iter_next(&iter)) { - long start = gkyl_range_idx(&(pdata[tbid].skin_ghost.lower_ghost[tdir]), iter.idx); - - if ((pdata[tbid].skin_ghost.lower_ghost[tdir].upper[0] - pdata[tbid].skin_ghost.lower_ghost[tdir].lower[0]) == 1) { - memcpy(gkyl_array_fetch(fld[tbid], start), - ((char*) bc_buffer->data) + fld[tbid]->esznc * (ref_factor * count++), fld[tbid]->esznc); - } - else { - memcpy(gkyl_array_fetch(fld[tbid], start), - ((char*) bc_buffer->data) + fld[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld[tbid]->esznc); - count += 1; - } - } + patch_ul_restriction_op(tbid, tdir, i, 0, pdata, bc_buffer, fld); } else if (pdata[i].skin_ghost.upper_skin[0].volume < pdata[tbid].skin_ghost.lower_ghost[tdir].volume) { - struct gkyl_range_iter iter; - gkyl_range_iter_init(&iter, &(pdata[tbid].skin_ghost.lower_ghost[tdir])); - - double ref_factor_inv = ((double)pdata[i].skin_ghost.upper_skin[0].volume / (double)pdata[tbid].skin_ghost.lower_ghost[tdir].volume); - - long count = 0; - while (gkyl_range_iter_next(&iter)) { - long start = gkyl_range_idx(&(pdata[tbid].skin_ghost.lower_ghost[tdir]), iter.idx); - - if ((pdata[tbid].skin_ghost.lower_ghost[tdir].upper[0] - pdata[tbid].skin_ghost.lower_ghost[tdir].lower[0]) == 1) { - memcpy(gkyl_array_fetch(fld[tbid], start), - ((char*) bc_buffer->data) + fld[tbid]->esznc * ((int)(ref_factor_inv * count++)), fld[tbid]->esznc); - } - else { - memcpy(gkyl_array_fetch(fld[tbid], start), - ((char*) bc_buffer->data) + fld[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld[tbid]->esznc); - count += 1; - } - } + patch_ul_projection_op(tbid, tdir, i, 0, pdata, bc_buffer, fld); } } else if (te[1].edge == GKYL_UPPER_POSITIVE) { @@ -333,46 +425,10 @@ euler_sync_patches(const struct gkyl_block_topo* ptopo, const struct euler_patch gkyl_array_copy_from_buffer(fld[tbid], bc_buffer->data, &(pdata[tbid].skin_ghost.upper_ghost[tdir])); } else if (pdata[i].skin_ghost.upper_skin[0].volume > pdata[tbid].skin_ghost.upper_ghost[tdir].volume) { - struct gkyl_range_iter iter; - gkyl_range_iter_init(&iter, &(pdata[tbid].skin_ghost.upper_ghost[tdir])); - - int ref_factor = (int)(pdata[i].skin_ghost.upper_skin[0].volume / pdata[tbid].skin_ghost.upper_ghost[tdir].volume); - - long count = 0; - while (gkyl_range_iter_next(&iter)) { - long start = gkyl_range_idx(&(pdata[tbid].skin_ghost.upper_ghost[tdir]), iter.idx); - - if ((pdata[tbid].skin_ghost.upper_ghost[tdir].upper[0] - pdata[tbid].skin_ghost.upper_ghost[tdir].lower[0]) == 1) { - memcpy(gkyl_array_fetch(fld[tbid], start), - ((char*) bc_buffer->data) + fld[tbid]->esznc * (ref_factor * count++), fld[tbid]->esznc); - } - else { - memcpy(gkyl_array_fetch(fld[tbid], start), - ((char*) bc_buffer->data) + fld[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld[tbid]->esznc); - count += 1; - } - } + patch_uu_restriction_op(tbid, tdir, i, 0, pdata, bc_buffer, fld); } else if (pdata[i].skin_ghost.upper_skin[0].volume < pdata[tbid].skin_ghost.upper_ghost[tdir].volume) { - struct gkyl_range_iter iter; - gkyl_range_iter_init(&iter, &(pdata[tbid].skin_ghost.upper_ghost[tdir])); - - double ref_factor_inv = ((double)pdata[i].skin_ghost.upper_skin[0].volume / (double)pdata[tbid].skin_ghost.upper_ghost[tdir].volume); - - long count = 0; - while (gkyl_range_iter_next(&iter)) { - long start = gkyl_range_idx(&(pdata[tbid].skin_ghost.upper_ghost[tdir]), iter.idx); - - if ((pdata[tbid].skin_ghost.upper_ghost[tdir].upper[0] - pdata[tbid].skin_ghost.upper_ghost[tdir].lower[0]) == 1) { - memcpy(gkyl_array_fetch(fld[tbid], start), - ((char*) bc_buffer->data) + fld[tbid]->esznc * ((int)(ref_factor_inv * count++)), fld[tbid]->esznc); - } - else { - memcpy(gkyl_array_fetch(fld[tbid], start), - ((char*) bc_buffer->data) + fld[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld[tbid]->esznc); - count += 1; - } - } + patch_uu_projection_op(tbid, tdir, i, 0, pdata, bc_buffer, fld); } } } diff --git a/amr/gkyl_amr_block_coupled_priv.h b/amr/gkyl_amr_block_coupled_priv.h index bda1ad807..8d52263e4 100644 --- a/amr/gkyl_amr_block_coupled_priv.h +++ b/amr/gkyl_amr_block_coupled_priv.h @@ -220,7 +220,7 @@ void five_moment_block_bc_updaters_apply(const struct five_moment_block_data* bd * @param tdir Target (fine) block direction. * @param i Reference (coarse) block ID. * @param d Reference (coarse) block direction. -* @param bdata Block-structured data for the Euler equations. +* @param bdata Block-structured data for the coupled five-moment equations. * @param bc_buffer_elc Buffer for applying electron boundary conditions. * @param bc_buffer_ion Buffer for applying ion boundary conditions. * @param bc_buffer_maxwell Buffer for applying Maxwell field boundary conditions. @@ -239,7 +239,7 @@ void block_coupled_ll_projection_op(const int tbid, const int tdir, const int i, * @param tdir Target (coarse) block direction. * @param i Reference (fine) block ID. * @param d Reference (fine) block direction. -* @param bdata Block-structured data for the Euler equations. +* @param bdata Block-structured data for the coupled five-moment equations. * @param bc_buffer_elc Buffer for applying electron boundary conditions. * @param bc_buffer_ion Buffer for applying ion boundary conditions. * @param bc_buffer_maxwell Buffer for applying Maxwell field boundary conditions. @@ -258,7 +258,7 @@ void block_coupled_ll_restriction_op(const int tbid, const int tdir, const int i * @param tdir Target (fine) block direction. * @param i Reference (coarse) block ID. * @param d Reference (coarse) block direction. -* @param bdata Block-structured data for the Euler equations. +* @param bdata Block-structured data for the coupled five-moment equations. * @param bc_buffer_elc Buffer for applying electron boundary conditions. * @param bc_buffer_ion Buffer for applying ion boundary conditions. * @param bc_buffer_maxwell Buffer for applying Maxwell field boundary conditions. @@ -277,7 +277,7 @@ void block_coupled_lu_projection_op(const int tbid, const int tdir, const int i, * @param tdir Target (coarse) block direction. * @param i Reference (fine) block ID. * @param d Reference (fine) block direction. -* @param bdata Block-structured data for the Euler equations. +* @param bdata Block-structured data for the coupled five-moment equations. * @param bc_buffer_elc Buffer for applying electron boundary conditions. * @param bc_buffer_ion Buffer for applying ion boundary conditions. * @param bc_buffer_maxwell Buffer for applying Maxwell field boundary conditions. @@ -296,7 +296,7 @@ void block_coupled_lu_restriction_op(const int tbid, const int tdir, const int i * @param tdir Target (fine) block direction. * @param i Reference (coarse) block ID. * @param d Reference (coarse) block direction. -* @param bdata Block-structured data for the Euler equations. +* @param bdata Block-structured data for the coupled five-moment equations. * @param bc_buffer_elc Buffer for applying electron boundary conditions. * @param bc_buffer_ion Buffer for applying ion boundary conditions. * @param bc_buffer_maxwell Buffer for applying Maxwell field boundary conditions. @@ -315,7 +315,7 @@ void block_coupled_ul_projection_op(const int tbid, const int tdir, const int i, * @param tdir Target (coarse) block direction. * @param i Reference (fine) block ID. * @param d Reference (fine) block direction. -* @param bdata Block-structured data for the Euler equations. +* @param bdata Block-structured data for the coupled five-moment equations. * @param bc_buffer_elc Buffer for applying electron boundary conditions. * @param bc_buffer_ion Buffer for applying ion boundary conditions. * @param bc_buffer_maxwell Buffer for applying Maxwell field boundary conditions. @@ -334,7 +334,7 @@ void block_coupled_ul_restriction_op(const int tbid, const int tdir, const int i * @param tdir Target (fine) block direction. * @param i Reference (coarse) block ID. * @param d Reference (coarse) block direction. -* @param bdata Block-structured data for the Euler equations. +* @param bdata Block-structured data for the coupled five-moment equations. * @param bc_buffer_elc Buffer for applying electron boundary conditions. * @param bc_buffer_ion Buffer for applying ion boundary conditions. * @param bc_buffer_maxwell Buffer for applying Maxwell field boundary conditions. @@ -353,7 +353,7 @@ void block_coupled_uu_projection_op(const int tbid, const int tdir, const int i, * @param tdir Target (coarse) block direction. * @param i Reference (fine) block ID. * @param d Reference (fine) block direction. -* @param bdata Block-structured data for the Euler equations. +* @param bdata Block-structured data for the coupled five-moment equations. * @param bc_buffer_elc Buffer for applying electron boundary conditions. * @param bc_buffer_ion Buffer for applying ion boundary conditions. * @param bc_buffer_maxwell Buffer for applying Maxwell field boundary conditions. diff --git a/amr/gkyl_amr_patch_priv.h b/amr/gkyl_amr_patch_priv.h index c9f9e164f..1367b37ea 100644 --- a/amr/gkyl_amr_patch_priv.h +++ b/amr/gkyl_amr_patch_priv.h @@ -102,6 +102,118 @@ void euler_patch_bc_updaters_release(struct euler_patch_data* pdata); */ void euler_patch_bc_updaters_apply(const struct euler_patch_data* pdata, double tm, struct gkyl_array* fld); +/** +* Coarse-to-fine projection operator for patch-structured AMR, assuming a lower coarse patch and a lower fine patch. +* +* @param tbid Target (fine) patch ID. +* @param tdir Target (fine) patch direction. +* @param i Reference (coarse) patch ID. +* @param d Reference (coarse) patch direction. +* @param pdata Patch-structured data for the Euler equations. +* @param bc_buffer Buffer for applying boundary conditions. +* @param fld Output array. +*/ +void patch_ll_projection_op(const int tbid, const int tdir, const int i, const int d, const struct euler_patch_data pdata[], + const struct gkyl_array* bc_buffer, struct gkyl_array* fld[]); + +/** +* Fine-to-coarse restriction operator for patch-structured AMR, assuming a lower fine patch and a lower coarse patch. +* +* @param tbid Target (coarse) patch ID. +* @param tdir Target (coarse) patch direction. +* @param i Reference (fine) patch ID. +* @param d Reference (fine) patch direction. +* @param pdata Patch-structured data for the Euler equations. +* @param bc_buffer Buffer for applying boundary conditions. +* @param fld Output array. +*/ +void patch_ll_restriction_op(const int tbid, const int tdir, const int i, const int d, const struct euler_patch_data pdata[], + const struct gkyl_array* bc_buffer, struct gkyl_array* fld[]); + +/** +* Coarse-to-fine projection operator for patch-structured AMR, assuming a lower coarse patch and an upper fine patch. +* +* @param tbid Target (fine) patch ID. +* @param tdir Target (fine) patch direction. +* @param i Reference (coarse) patch ID. +* @param d Reference (coarse) patch direction. +* @param pdata Patch-structured data for the Euler equations. +* @param bc_buffer Buffer for applying boundary conditions. +* @param fld Output array. +*/ +void patch_lu_projection_op(const int tbid, const int tdir, const int i, const int d, const struct euler_patch_data pdata[], + const struct gkyl_array* bc_buffer, struct gkyl_array* fld[]); + +/** +* Fine-to-coarse restriction operator for patch-structured AMR, assuming a lower fine patch and an upper coarse patch. +* +* @param tbid Target (coarse) patch ID. +* @param tdir Target (coarse) patch direction. +* @param i Reference (fine) patch ID. +* @param d Reference (fine) patch direction. +* @param pdata Patch-structured data for the Euler equations. +* @param bc_buffer Buffer for applying boundary conditions. +* @param fld Output array. +*/ +void patch_lu_restriction_op(const int tbid, const int tdir, const int i, const int d, const struct euler_patch_data pdata[], + const struct gkyl_array* bc_buffer, struct gkyl_array* fld[]); + + /** +* Coarse-to-fine projection operator for patch-structured AMR, assuming an upper coarse patch and a lower fine patch. +* +* @param tbid Target (fine) patch ID. +* @param tdir Target (fine) patch direction. +* @param i Reference (coarse) patch ID. +* @param d Reference (coarse) patch direction. +* @param pdata Patch-structured data for the Euler equations. +* @param bc_buffer Buffer for applying boundary conditions. +* @param fld Output array. +*/ +void patch_ul_projection_op(const int tbid, const int tdir, const int i, const int d, const struct euler_patch_data pdata[], + const struct gkyl_array* bc_buffer, struct gkyl_array* fld[]); + +/** +* Fine-to-coarse restriction operator for patch-structured AMR, assuming an upper fine patch and a lower coarse patch. +* +* @param tbid Target (coarse) patch ID. +* @param tdir Target (coarse) patch direction. +* @param i Reference (fine) patch ID. +* @param d Reference (fine) patch direction. +* @param pdata Patch-structured data for the Euler equations. +* @param bc_buffer Buffer for applying boundary conditions. +* @param fld Output array. +*/ +void patch_ul_restriction_op(const int tbid, const int tdir, const int i, const int d, const struct euler_patch_data pdata[], + const struct gkyl_array* bc_buffer, struct gkyl_array* fld[]); + +/** +* Coarse-to-fine projection operator for patch-structured AMR, assuming an upper coarse patch and an upper fine patch. +* +* @param tbid Target (fine) patch ID. +* @param tdir Target (fine) patch direction. +* @param i Reference (coarse) patch ID. +* @param d Reference (coarse) patch direction. +* @param pdata Patch-structured data for the Euler equations. +* @param bc_buffer Buffer for applying boundary conditions. +* @param fld Output array. +*/ +void patch_uu_projection_op(const int tbid, const int tdir, const int i, const int d, const struct euler_patch_data pdata[], + const struct gkyl_array* bc_buffer, struct gkyl_array* fld[]); + +/** +* Fine-to-coarse restriction operator for patch-structured AMR, assuming an upper fine patch and an upper coarse patch. +* +* @param tbid Target (coarse) patch ID. +* @param tdir Target (coarse) patch direction. +* @param i Reference (fine) patch ID. +* @param d Reference (fine) patch direction. +* @param pdata Patch-structured data for the Euler equations. +* @param bc_buffer Buffer for applying boundary conditions. +* @param fld Output array. +*/ +void patch_uu_restriction_op(const int tbid, const int tdir, const int i, const int d, const struct euler_patch_data pdata[], + const struct gkyl_array* bc_buffer, struct gkyl_array* fld[]); + /** * Synchronize all patches in the patch AMR hierarchy by applying all appropriate physical (outer-patch) and non-physical (inter-patch) * boundary conditions for the Euler equations. From 3b3ddfa79a3f63c45dc59d97c470661ae7ba5f16 Mon Sep 17 00:00:00 2001 From: JonathanGorard Date: Tue, 9 Jul 2024 10:17:54 -0400 Subject: [PATCH 31/32] Added, and fully tested, patch-structured AMR variants of the projection and restriction operators for coupled moments. All AMR regression tests show full correctness with the new refactoring. --- amr/amr_patch_coupled.c | 520 +++++++++++++++++------------- amr/gkyl_amr_patch_coupled_priv.h | 152 +++++++++ 2 files changed, 448 insertions(+), 224 deletions(-) diff --git a/amr/amr_patch_coupled.c b/amr/amr_patch_coupled.c index 31a764b02..ef5dac522 100644 --- a/amr/amr_patch_coupled.c +++ b/amr/amr_patch_coupled.c @@ -230,6 +230,286 @@ five_moment_patch_bc_updaters_apply(const struct five_moment_patch_data* pdata, } } +void +patch_coupled_ll_projection_op(const int tbid, const int tdir, const int i, const int d, const struct five_moment_patch_data pdata[], + const struct gkyl_array* bc_buffer_elc, const struct gkyl_array* bc_buffer_ion, const struct gkyl_array* bc_buffer_maxwell, + struct gkyl_array* fld_elc[], struct gkyl_array* fld_ion[], struct gkyl_array* fld_maxwell[]) +{ + struct gkyl_range_iter iter; + gkyl_range_iter_init(&iter, &(pdata[tbid].skin_ghost.lower_ghost[tdir])); + + double ref_factor_inv = ((double)pdata[i].skin_ghost.lower_skin[d].volume / (double)pdata[tbid].skin_ghost.lower_ghost[tdir].volume); + + long count = 0; + while (gkyl_range_iter_next(&iter)) { + long start = gkyl_range_idx(&(pdata[tbid].skin_ghost.lower_ghost[tdir]), iter.idx); + + if ((pdata[tbid].skin_ghost.lower_ghost[tdir].upper[0] - pdata[tbid].skin_ghost.lower_ghost[tdir].lower[0]) == 1) { + memcpy(gkyl_array_fetch(fld_elc[tbid], start), + ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * ((int)(ref_factor_inv * count)), fld_elc[tbid]->esznc); + memcpy(gkyl_array_fetch(fld_ion[tbid], start), + ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * ((int)(ref_factor_inv * count)), fld_ion[tbid]->esznc); + memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), + ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * ((int)(ref_factor_inv * count)), fld_maxwell[tbid]->esznc); + count += 1; + } + else { + memcpy(gkyl_array_fetch(fld_elc[tbid], start), + ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld_elc[tbid]->esznc); + memcpy(gkyl_array_fetch(fld_ion[tbid], start), + ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld_ion[tbid]->esznc); + memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), + ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld_maxwell[tbid]->esznc); + count += 1; + } + } +} + +void +patch_coupled_ll_restriction_op(const int tbid, const int tdir, const int i, const int d, const struct five_moment_patch_data pdata[], + const struct gkyl_array* bc_buffer_elc, const struct gkyl_array* bc_buffer_ion, const struct gkyl_array* bc_buffer_maxwell, + struct gkyl_array* fld_elc[], struct gkyl_array* fld_ion[], struct gkyl_array* fld_maxwell[]) +{ + struct gkyl_range_iter iter; + gkyl_range_iter_init(&iter, &(pdata[tbid].skin_ghost.lower_ghost[tdir])); + + int ref_factor = (int)(pdata[i].skin_ghost.lower_skin[d].volume / pdata[tbid].skin_ghost.lower_ghost[tdir].volume); + + long count = 0; + while (gkyl_range_iter_next(&iter)) { + long start = gkyl_range_idx(&(pdata[tbid].skin_ghost.lower_ghost[tdir]), iter.idx); + + if ((pdata[tbid].skin_ghost.lower_ghost[tdir].upper[0] - pdata[tbid].skin_ghost.lower_ghost[tdir].lower[0]) == 1) { + memcpy(gkyl_array_fetch(fld_elc[tbid], start), + ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * (ref_factor * count), fld_elc[tbid]->esznc); + memcpy(gkyl_array_fetch(fld_ion[tbid], start), + ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * (ref_factor * count), fld_ion[tbid]->esznc); + memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), + ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * (ref_factor * count), fld_maxwell[tbid]->esznc); + count += 1; + } + else { + memcpy(gkyl_array_fetch(fld_elc[tbid], start), + ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld_elc[tbid]->esznc); + memcpy(gkyl_array_fetch(fld_ion[tbid], start), + ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld_ion[tbid]->esznc); + memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), + ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld_maxwell[tbid]->esznc); + count += 1; + } + } +} + +void +patch_coupled_lu_projection_op(const int tbid, const int tdir, const int i, const int d, const struct five_moment_patch_data pdata[], + const struct gkyl_array* bc_buffer_elc, const struct gkyl_array* bc_buffer_ion, const struct gkyl_array* bc_buffer_maxwell, + struct gkyl_array* fld_elc[], struct gkyl_array* fld_ion[], struct gkyl_array* fld_maxwell[]) +{ + struct gkyl_range_iter iter; + gkyl_range_iter_init(&iter, &(pdata[tbid].skin_ghost.upper_ghost[tdir])); + + double ref_factor_inv = ((double)pdata[i].skin_ghost.lower_skin[d].volume / (double)pdata[tbid].skin_ghost.upper_ghost[tdir].volume); + + long count = 0; + while (gkyl_range_iter_next(&iter)) { + long start = gkyl_range_idx(&(pdata[tbid].skin_ghost.upper_ghost[tdir]), iter.idx); + + if ((pdata[tbid].skin_ghost.upper_ghost[tdir].upper[0] - pdata[tbid].skin_ghost.upper_ghost[tdir].lower[0]) == 1) { + memcpy(gkyl_array_fetch(fld_elc[tbid], start), + ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * ((int)(ref_factor_inv * count)), fld_elc[tbid]->esznc); + memcpy(gkyl_array_fetch(fld_ion[tbid], start), + ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * ((int)(ref_factor_inv * count)), fld_ion[tbid]->esznc); + memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), + ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * ((int)(ref_factor_inv * count)), fld_maxwell[tbid]->esznc); + count += 1; + } + else { + memcpy(gkyl_array_fetch(fld_elc[tbid], start), + ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld_elc[tbid]->esznc); + memcpy(gkyl_array_fetch(fld_ion[tbid], start), + ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld_ion[tbid]->esznc); + memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), + ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld_maxwell[tbid]->esznc); + count += 1; + } + } +} + +void +patch_coupled_lu_restriction_op(const int tbid, const int tdir, const int i, const int d, const struct five_moment_patch_data pdata[], + const struct gkyl_array* bc_buffer_elc, const struct gkyl_array* bc_buffer_ion, const struct gkyl_array* bc_buffer_maxwell, + struct gkyl_array* fld_elc[], struct gkyl_array* fld_ion[], struct gkyl_array* fld_maxwell[]) +{ + struct gkyl_range_iter iter; + gkyl_range_iter_init(&iter, &(pdata[tbid].skin_ghost.upper_ghost[tdir])); + + int ref_factor = (int)(pdata[i].skin_ghost.lower_skin[d].volume / pdata[tbid].skin_ghost.upper_ghost[tdir].volume); + + long count = 0; + while (gkyl_range_iter_next(&iter)) { + long start = gkyl_range_idx(&(pdata[tbid].skin_ghost.upper_ghost[tdir]), iter.idx); + + if ((pdata[tbid].skin_ghost.upper_ghost[tdir].upper[0] - pdata[tbid].skin_ghost.upper_ghost[tdir].lower[0]) == 1) { + memcpy(gkyl_array_fetch(fld_elc[tbid], start), + ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * (ref_factor * count), fld_elc[tbid]->esznc); + memcpy(gkyl_array_fetch(fld_ion[tbid], start), + ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * (ref_factor * count), fld_ion[tbid]->esznc); + memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), + ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * (ref_factor * count), fld_maxwell[tbid]->esznc); + count += 1; + } + else { + memcpy(gkyl_array_fetch(fld_elc[tbid], start), + ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld_elc[tbid]->esznc); + memcpy(gkyl_array_fetch(fld_ion[tbid], start), + ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld_ion[tbid]->esznc); + memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), + ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld_maxwell[tbid]->esznc); + count += 1; + } + } +} + +void +patch_coupled_ul_projection_op(const int tbid, const int tdir, const int i, const int d, const struct five_moment_patch_data pdata[], + const struct gkyl_array* bc_buffer_elc, const struct gkyl_array* bc_buffer_ion, const struct gkyl_array* bc_buffer_maxwell, + struct gkyl_array* fld_elc[], struct gkyl_array* fld_ion[], struct gkyl_array* fld_maxwell[]) +{ + struct gkyl_range_iter iter; + gkyl_range_iter_init(&iter, &(pdata[tbid].skin_ghost.lower_ghost[tdir])); + + double ref_factor_inv = ((double)pdata[i].skin_ghost.upper_skin[d].volume / (double)pdata[tbid].skin_ghost.lower_ghost[tdir].volume); + + long count = 0; + while (gkyl_range_iter_next(&iter)) { + long start = gkyl_range_idx(&(pdata[tbid].skin_ghost.lower_ghost[tdir]), iter.idx); + + if ((pdata[tbid].skin_ghost.lower_ghost[tdir].upper[0] - pdata[tbid].skin_ghost.lower_ghost[tdir].lower[0]) == 1) { + memcpy(gkyl_array_fetch(fld_elc[tbid], start), + ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * ((int)(ref_factor_inv * count)), fld_elc[tbid]->esznc); + memcpy(gkyl_array_fetch(fld_ion[tbid], start), + ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * ((int)(ref_factor_inv * count)), fld_ion[tbid]->esznc); + memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), + ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * ((int)(ref_factor_inv * count)), fld_maxwell[tbid]->esznc); + count += 1; + } + else { + memcpy(gkyl_array_fetch(fld_elc[tbid], start), + ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld_elc[tbid]->esznc); + memcpy(gkyl_array_fetch(fld_ion[tbid], start), + ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld_ion[tbid]->esznc); + memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), + ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld_maxwell[tbid]->esznc); + count += 1; + } + } +} + +void +patch_coupled_ul_restriction_op(const int tbid, const int tdir, const int i, const int d, const struct five_moment_patch_data pdata[], + const struct gkyl_array* bc_buffer_elc, const struct gkyl_array* bc_buffer_ion, const struct gkyl_array* bc_buffer_maxwell, + struct gkyl_array* fld_elc[], struct gkyl_array* fld_ion[], struct gkyl_array* fld_maxwell[]) +{ + struct gkyl_range_iter iter; + gkyl_range_iter_init(&iter, &(pdata[tbid].skin_ghost.lower_ghost[tdir])); + + int ref_factor = (int)(pdata[i].skin_ghost.upper_skin[d].volume / pdata[tbid].skin_ghost.lower_ghost[tdir].volume); + + long count = 0; + while (gkyl_range_iter_next(&iter)) { + long start = gkyl_range_idx(&(pdata[tbid].skin_ghost.lower_ghost[tdir]), iter.idx); + + if ((pdata[tbid].skin_ghost.lower_ghost[tdir].upper[0] - pdata[tbid].skin_ghost.lower_ghost[tdir].lower[0]) == 1) { + memcpy(gkyl_array_fetch(fld_elc[tbid], start), + ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * (ref_factor * count), fld_elc[tbid]->esznc); + memcpy(gkyl_array_fetch(fld_ion[tbid], start), + ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * (ref_factor * count), fld_ion[tbid]->esznc); + memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), + ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * (ref_factor * count), fld_maxwell[tbid]->esznc); + count += 1; + } + else { + memcpy(gkyl_array_fetch(fld_elc[tbid], start), + ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld_elc[tbid]->esznc); + memcpy(gkyl_array_fetch(fld_ion[tbid], start), + ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld_ion[tbid]->esznc); + memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), + ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld_maxwell[tbid]->esznc); + count += 1; + } + } +} + +void +patch_coupled_uu_projection_op(const int tbid, const int tdir, const int i, const int d, const struct five_moment_patch_data pdata[], + const struct gkyl_array* bc_buffer_elc, const struct gkyl_array* bc_buffer_ion, const struct gkyl_array* bc_buffer_maxwell, + struct gkyl_array* fld_elc[], struct gkyl_array* fld_ion[], struct gkyl_array* fld_maxwell[]) +{ + struct gkyl_range_iter iter; + gkyl_range_iter_init(&iter, &(pdata[tbid].skin_ghost.upper_ghost[tdir])); + + double ref_factor_inv = ((double)pdata[i].skin_ghost.upper_skin[d].volume / (double)pdata[tbid].skin_ghost.upper_ghost[tdir].volume); + + long count = 0; + while (gkyl_range_iter_next(&iter)) { + long start = gkyl_range_idx(&(pdata[tbid].skin_ghost.upper_ghost[tdir]), iter.idx); + + if ((pdata[tbid].skin_ghost.upper_ghost[tdir].upper[0] - pdata[tbid].skin_ghost.upper_ghost[tdir].lower[0]) == 1) { + memcpy(gkyl_array_fetch(fld_elc[tbid], start), + ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * ((int)(ref_factor_inv * count)), fld_elc[tbid]->esznc); + memcpy(gkyl_array_fetch(fld_ion[tbid], start), + ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * ((int)(ref_factor_inv * count)), fld_ion[tbid]->esznc); + memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), + ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * ((int)(ref_factor_inv * count)), fld_maxwell[tbid]->esznc); + count += 1; + } + else { + memcpy(gkyl_array_fetch(fld_elc[tbid], start), + ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld_elc[tbid]->esznc); + memcpy(gkyl_array_fetch(fld_ion[tbid], start), + ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld_ion[tbid]->esznc); + memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), + ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld_maxwell[tbid]->esznc); + count += 1; + } + } +} + +void +patch_coupled_uu_restriction_op(const int tbid, const int tdir, const int i, const int d, const struct five_moment_patch_data pdata[], + const struct gkyl_array* bc_buffer_elc, const struct gkyl_array* bc_buffer_ion, const struct gkyl_array* bc_buffer_maxwell, + struct gkyl_array* fld_elc[], struct gkyl_array* fld_ion[], struct gkyl_array* fld_maxwell[]) +{ + struct gkyl_range_iter iter; + gkyl_range_iter_init(&iter, &(pdata[tbid].skin_ghost.upper_ghost[tdir])); + + int ref_factor = (int)(pdata[i].skin_ghost.upper_skin[d].volume / pdata[tbid].skin_ghost.upper_ghost[tdir].volume); + + long count = 0; + while (gkyl_range_iter_next(&iter)) { + long start = gkyl_range_idx(&(pdata[tbid].skin_ghost.upper_ghost[tdir]), iter.idx); + + if ((pdata[tbid].skin_ghost.upper_ghost[tdir].upper[0] - pdata[tbid].skin_ghost.upper_ghost[tdir].lower[0]) == 1) { + memcpy(gkyl_array_fetch(fld_elc[tbid], start), + ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * (ref_factor * count), fld_elc[tbid]->esznc); + memcpy(gkyl_array_fetch(fld_ion[tbid], start), + ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * (ref_factor * count), fld_ion[tbid]->esznc); + memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), + ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * (ref_factor * count), fld_maxwell[tbid]->esznc); + count += 1; + } + else { + memcpy(gkyl_array_fetch(fld_elc[tbid], start), + ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld_elc[tbid]->esznc); + memcpy(gkyl_array_fetch(fld_ion[tbid], start), + ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld_ion[tbid]->esznc); + memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), + ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld_maxwell[tbid]->esznc); + count += 1; + } + } +} + void five_moment_sync_patches(const struct gkyl_block_topo* ptopo, const struct five_moment_patch_data pdata[], struct gkyl_array* fld_elc[], struct gkyl_array* fld_ion[], struct gkyl_array* fld_maxwell[]) @@ -258,64 +538,12 @@ five_moment_sync_patches(const struct gkyl_block_topo* ptopo, const struct five_ gkyl_array_copy_from_buffer(fld_maxwell[tbid], bc_buffer_maxwell->data, &(pdata[tbid].skin_ghost.lower_ghost[tdir])); } else if (pdata[i].skin_ghost.lower_skin[0].volume > pdata[tbid].skin_ghost.lower_ghost[tdir].volume) { - struct gkyl_range_iter iter; - gkyl_range_iter_init(&iter, &(pdata[tbid].skin_ghost.lower_ghost[tdir])); - - int ref_factor = (int)(pdata[i].skin_ghost.lower_skin[0].volume / pdata[tbid].skin_ghost.lower_ghost[tdir].volume); - - long count = 0; - while (gkyl_range_iter_next(&iter)) { - long start = gkyl_range_idx(&(pdata[tbid].skin_ghost.lower_ghost[tdir]), iter.idx); - - if ((pdata[tbid].skin_ghost.lower_ghost[tdir].upper[0] - pdata[tbid].skin_ghost.lower_ghost[tdir].lower[0]) == 1) { - memcpy(gkyl_array_fetch(fld_elc[tbid], start), - ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * (ref_factor * count), fld_elc[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_ion[tbid], start), - ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * (ref_factor * count), fld_ion[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), - ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * (ref_factor * count), fld_maxwell[tbid]->esznc); - count += 1; - } - else { - memcpy(gkyl_array_fetch(fld_elc[tbid], start), - ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld_elc[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_ion[tbid], start), - ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld_ion[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), - ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld_maxwell[tbid]->esznc); - count += 1; - } - } + patch_coupled_ll_restriction_op(tbid, tdir, i, 0, pdata, bc_buffer_elc, bc_buffer_ion, bc_buffer_maxwell, + fld_elc, fld_ion, fld_maxwell); } else if (pdata[i].skin_ghost.lower_skin[0].volume < pdata[tbid].skin_ghost.lower_ghost[tdir].volume) { - struct gkyl_range_iter iter; - gkyl_range_iter_init(&iter, &(pdata[tbid].skin_ghost.lower_ghost[tdir])); - - double ref_factor_inv = ((double)pdata[i].skin_ghost.lower_skin[0].volume / (double)pdata[tbid].skin_ghost.lower_ghost[tdir].volume); - - long count = 0; - while (gkyl_range_iter_next(&iter)) { - long start = gkyl_range_idx(&(pdata[tbid].skin_ghost.lower_ghost[tdir]), iter.idx); - - if ((pdata[tbid].skin_ghost.lower_ghost[tdir].upper[0] - pdata[tbid].skin_ghost.lower_ghost[tdir].lower[0]) == 1) { - memcpy(gkyl_array_fetch(fld_elc[tbid], start), - ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * ((int)(ref_factor_inv * count)), fld_elc[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_ion[tbid], start), - ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * ((int)(ref_factor_inv * count)), fld_ion[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), - ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * ((int)(ref_factor_inv * count)), fld_maxwell[tbid]->esznc); - count += 1; - } - else { - memcpy(gkyl_array_fetch(fld_elc[tbid], start), - ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld_elc[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_ion[tbid], start), - ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld_ion[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), - ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld_maxwell[tbid]->esznc); - count += 1; - } - } + patch_coupled_ll_projection_op(tbid, tdir, i, 0, pdata, bc_buffer_elc, bc_buffer_ion, bc_buffer_maxwell, + fld_elc, fld_ion, fld_maxwell); } } else if (te[0].edge == GKYL_UPPER_POSITIVE) { @@ -325,64 +553,12 @@ five_moment_sync_patches(const struct gkyl_block_topo* ptopo, const struct five_ gkyl_array_copy_from_buffer(fld_maxwell[tbid], bc_buffer_maxwell->data, &(pdata[tbid].skin_ghost.upper_ghost[tdir])); } else if (pdata[i].skin_ghost.lower_skin[0].volume > pdata[tbid].skin_ghost.upper_ghost[tdir].volume) { - struct gkyl_range_iter iter; - gkyl_range_iter_init(&iter, &(pdata[tbid].skin_ghost.upper_ghost[tdir])); - - int ref_factor = (int)(pdata[i].skin_ghost.lower_skin[0].volume / pdata[tbid].skin_ghost.upper_ghost[tdir].volume); - - long count = 0; - while (gkyl_range_iter_next(&iter)) { - long start = gkyl_range_idx(&(pdata[tbid].skin_ghost.upper_ghost[tdir]), iter.idx); - - if ((pdata[tbid].skin_ghost.upper_ghost[tdir].upper[0] - pdata[tbid].skin_ghost.upper_ghost[tdir].lower[0]) == 1) { - memcpy(gkyl_array_fetch(fld_elc[tbid], start), - ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * (ref_factor * count), fld_elc[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_ion[tbid], start), - ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * (ref_factor * count), fld_ion[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), - ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * (ref_factor * count), fld_maxwell[tbid]->esznc); - count += 1; - } - else { - memcpy(gkyl_array_fetch(fld_elc[tbid], start), - ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld_elc[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_ion[tbid], start), - ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld_ion[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), - ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld_maxwell[tbid]->esznc); - count += 1; - } - } + patch_coupled_lu_restriction_op(tbid, tdir, i, 0, pdata, bc_buffer_elc, bc_buffer_ion, bc_buffer_maxwell, + fld_elc, fld_ion, fld_maxwell); } else if (pdata[i].skin_ghost.lower_skin[0].volume < pdata[tbid].skin_ghost.upper_ghost[tdir].volume) { - struct gkyl_range_iter iter; - gkyl_range_iter_init(&iter, &(pdata[tbid].skin_ghost.upper_ghost[tdir])); - - double ref_factor_inv = ((double)pdata[i].skin_ghost.lower_skin[0].volume / (double)pdata[tbid].skin_ghost.upper_ghost[tdir].volume); - - long count = 0; - while (gkyl_range_iter_next(&iter)) { - long start = gkyl_range_idx(&(pdata[tbid].skin_ghost.upper_ghost[tdir]), iter.idx); - - if ((pdata[tbid].skin_ghost.upper_ghost[tdir].upper[0] - pdata[tbid].skin_ghost.upper_ghost[tdir].lower[0]) == 1) { - memcpy(gkyl_array_fetch(fld_elc[tbid], start), - ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * ((int)(ref_factor_inv * count)), fld_elc[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_ion[tbid], start), - ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * ((int)(ref_factor_inv * count)), fld_ion[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), - ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * ((int)(ref_factor_inv * count)), fld_maxwell[tbid]->esznc); - count += 1; - } - else { - memcpy(gkyl_array_fetch(fld_elc[tbid], start), - ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld_elc[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_ion[tbid], start), - ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld_ion[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), - ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld_maxwell[tbid]->esznc); - count += 1; - } - } + patch_coupled_lu_projection_op(tbid, tdir, i, 0, pdata, bc_buffer_elc, bc_buffer_ion, bc_buffer_maxwell, + fld_elc, fld_ion, fld_maxwell); } } } @@ -406,64 +582,12 @@ five_moment_sync_patches(const struct gkyl_block_topo* ptopo, const struct five_ gkyl_array_copy_from_buffer(fld_maxwell[tbid], bc_buffer_maxwell->data, &(pdata[tbid].skin_ghost.lower_ghost[tdir])); } else if (pdata[i].skin_ghost.upper_skin[0].volume > pdata[tbid].skin_ghost.lower_ghost[tdir].volume) { - struct gkyl_range_iter iter; - gkyl_range_iter_init(&iter, &(pdata[tbid].skin_ghost.lower_ghost[tdir])); - - int ref_factor = (int)(pdata[i].skin_ghost.upper_skin[0].volume / pdata[tbid].skin_ghost.lower_ghost[tdir].volume); - - long count = 0; - while (gkyl_range_iter_next(&iter)) { - long start = gkyl_range_idx(&(pdata[tbid].skin_ghost.lower_ghost[tdir]), iter.idx); - - if ((pdata[tbid].skin_ghost.lower_ghost[tdir].upper[0] - pdata[tbid].skin_ghost.lower_ghost[tdir].lower[0]) == 1) { - memcpy(gkyl_array_fetch(fld_elc[tbid], start), - ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * (ref_factor * count), fld_elc[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_ion[tbid], start), - ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * (ref_factor * count), fld_ion[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), - ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * (ref_factor * count), fld_maxwell[tbid]->esznc); - count += 1; - } - else { - memcpy(gkyl_array_fetch(fld_elc[tbid], start), - ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld_elc[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_ion[tbid], start), - ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld_ion[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), - ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld_maxwell[tbid]->esznc); - count += 1; - } - } + patch_coupled_ul_restriction_op(tbid, tdir, i, 0, pdata, bc_buffer_elc, bc_buffer_ion, bc_buffer_maxwell, + fld_elc, fld_ion, fld_maxwell); } else if (pdata[i].skin_ghost.upper_skin[0].volume < pdata[tbid].skin_ghost.lower_ghost[tdir].volume) { - struct gkyl_range_iter iter; - gkyl_range_iter_init(&iter, &(pdata[tbid].skin_ghost.lower_ghost[tdir])); - - double ref_factor_inv = ((double)pdata[i].skin_ghost.upper_skin[0].volume / (double)pdata[tbid].skin_ghost.lower_ghost[tdir].volume); - - long count = 0; - while (gkyl_range_iter_next(&iter)) { - long start = gkyl_range_idx(&(pdata[tbid].skin_ghost.lower_ghost[tdir]), iter.idx); - - if ((pdata[tbid].skin_ghost.lower_ghost[tdir].upper[0] - pdata[tbid].skin_ghost.lower_ghost[tdir].lower[0]) == 1) { - memcpy(gkyl_array_fetch(fld_elc[tbid], start), - ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * ((int)(ref_factor_inv * count)), fld_elc[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_ion[tbid], start), - ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * ((int)(ref_factor_inv * count)), fld_ion[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), - ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * ((int)(ref_factor_inv * count)), fld_maxwell[tbid]->esznc); - count += 1; - } - else { - memcpy(gkyl_array_fetch(fld_elc[tbid], start), - ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld_elc[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_ion[tbid], start), - ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld_ion[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), - ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld_maxwell[tbid]->esznc); - count += 1; - } - } + patch_coupled_ul_projection_op(tbid, tdir, i, 0, pdata, bc_buffer_elc, bc_buffer_ion, bc_buffer_maxwell, + fld_elc, fld_ion, fld_maxwell); } } else if (te[1].edge == GKYL_UPPER_POSITIVE) { @@ -473,64 +597,12 @@ five_moment_sync_patches(const struct gkyl_block_topo* ptopo, const struct five_ gkyl_array_copy_from_buffer(fld_maxwell[tbid], bc_buffer_maxwell->data, &(pdata[tbid].skin_ghost.upper_ghost[tdir])); } else if (pdata[i].skin_ghost.upper_skin[0].volume > pdata[tbid].skin_ghost.upper_ghost[tdir].volume) { - struct gkyl_range_iter iter; - gkyl_range_iter_init(&iter, &(pdata[tbid].skin_ghost.upper_ghost[tdir])); - - int ref_factor = (int)(pdata[i].skin_ghost.upper_skin[0].volume / pdata[tbid].skin_ghost.upper_ghost[tdir].volume); - - long count = 0; - while (gkyl_range_iter_next(&iter)) { - long start = gkyl_range_idx(&(pdata[tbid].skin_ghost.upper_ghost[tdir]), iter.idx); - - if ((pdata[tbid].skin_ghost.upper_ghost[tdir].upper[0] - pdata[tbid].skin_ghost.upper_ghost[tdir].lower[0]) == 1) { - memcpy(gkyl_array_fetch(fld_elc[tbid], start), - ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * (ref_factor * count), fld_elc[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_ion[tbid], start), - ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * (ref_factor * count), fld_ion[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), - ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * (ref_factor * count), fld_maxwell[tbid]->esznc); - count += 1; - } - else { - memcpy(gkyl_array_fetch(fld_elc[tbid], start), - ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld_elc[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_ion[tbid], start), - ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld_ion[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), - ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * ((ref_factor * (count - (count % 2))) + (count % 2)), fld_maxwell[tbid]->esznc); - count += 1; - } - } + patch_coupled_uu_restriction_op(tbid, tdir, i, 0, pdata, bc_buffer_elc, bc_buffer_ion, bc_buffer_maxwell, + fld_elc, fld_ion, fld_maxwell); } else if (pdata[i].skin_ghost.upper_skin[0].volume < pdata[tbid].skin_ghost.upper_ghost[tdir].volume) { - struct gkyl_range_iter iter; - gkyl_range_iter_init(&iter, &(pdata[tbid].skin_ghost.upper_ghost[tdir])); - - double ref_factor_inv = ((double)pdata[i].skin_ghost.upper_skin[0].volume / (double)pdata[tbid].skin_ghost.upper_ghost[tdir].volume); - - long count = 0; - while (gkyl_range_iter_next(&iter)) { - long start = gkyl_range_idx(&(pdata[tbid].skin_ghost.upper_ghost[tdir]), iter.idx); - - if ((pdata[tbid].skin_ghost.upper_ghost[tdir].upper[0] - pdata[tbid].skin_ghost.upper_ghost[tdir].lower[0]) == 1) { - memcpy(gkyl_array_fetch(fld_elc[tbid], start), - ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * ((int)(ref_factor_inv * count)), fld_elc[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_ion[tbid], start), - ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * ((int)(ref_factor_inv * count)), fld_ion[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), - ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * ((int)(ref_factor_inv * count)), fld_maxwell[tbid]->esznc); - count += 1; - } - else { - memcpy(gkyl_array_fetch(fld_elc[tbid], start), - ((char*) bc_buffer_elc->data) + fld_elc[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld_elc[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_ion[tbid], start), - ((char*) bc_buffer_ion->data) + fld_ion[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld_ion[tbid]->esznc); - memcpy(gkyl_array_fetch(fld_maxwell[tbid], start), - ((char*) bc_buffer_maxwell->data) + fld_maxwell[tbid]->esznc * (2 * (int)(0.5 * ref_factor_inv * count) + (count % 2)), fld_maxwell[tbid]->esznc); - count += 1; - } - } + patch_coupled_uu_projection_op(tbid, tdir, i, 0, pdata, bc_buffer_elc, bc_buffer_ion, bc_buffer_maxwell, + fld_elc, fld_ion, fld_maxwell); } } } diff --git a/amr/gkyl_amr_patch_coupled_priv.h b/amr/gkyl_amr_patch_coupled_priv.h index d03b475d7..fc72b6f9d 100644 --- a/amr/gkyl_amr_patch_coupled_priv.h +++ b/amr/gkyl_amr_patch_coupled_priv.h @@ -129,6 +129,158 @@ void five_moment_patch_bc_updaters_release(struct five_moment_patch_data* pdata) void five_moment_patch_bc_updaters_apply(const struct five_moment_patch_data* pdata, double tm, struct gkyl_array* fld_elc, struct gkyl_array *fld_ion, struct gkyl_array* fld_maxwell); +/** +* Coarse-to-fine projection operator for coupled, patch-structured AMR, assuming a lower coarse patch and a lower fine patch. +* +* @param tbid Target (fine) patch ID. +* @param tdir Target (fine) patch direction. +* @param i Reference (coarse) patch ID. +* @param d Reference (coarse) patch direction. +* @param pdata Patch-structured data for the coupled five-moment equations. +* @param bc_buffer_elc Buffer for applying electron boundary conditions. +* @param bc_buffer_ion Buffer for applying ion boundary conditions. +* @param bc_buffer_maxwell Buffer for applying Maxwell field boundary conditions. +* @param fld_elc Output array (electons). +* @param fld_ion Output array (ions). +* @param fld_maxwell Output array (Maxwell field). +*/ +void patch_coupled_ll_projection_op(const int tbid, const int tdir, const int i, const int d, const struct five_moment_patch_data pdata[], + const struct gkyl_array* bc_buffer_elc, const struct gkyl_array* bc_buffer_ion, const struct gkyl_array* bc_buffer_maxwell, + struct gkyl_array* fld_elc[], struct gkyl_array* fld_ion[], struct gkyl_array* fld_maxwell[]); + +/** +* Fine-to-coarse restriction operator for coupled, patch-structured AMR, assuming a lower fine patch and a lower coarse patch. +* +* @param tbid Target (coarse) patch ID. +* @param tdir Target (coarse) patch direction. +* @param i Reference (fine) patch ID. +* @param d Reference (fine) patch direction. +* @param pdata Patch-structured data for the coupled five-moment equations. +* @param bc_buffer_elc Buffer for applying electron boundary conditions. +* @param bc_buffer_ion Buffer for applying ion boundary conditions. +* @param bc_buffer_maxwell Buffer for applying Maxwell field boundary conditions. +* @param fld_elc Output array (electons). +* @param fld_ion Output array (ions). +* @param fld_maxwell Output array (Maxwell field). +*/ +void patch_coupled_ll_restriction_op(const int tbid, const int tdir, const int i, const int d, const struct five_moment_patch_data pdata[], + const struct gkyl_array* bc_buffer_elc, const struct gkyl_array* bc_buffer_ion, const struct gkyl_array* bc_buffer_maxwell, + struct gkyl_array* fld_elc[], struct gkyl_array* fld_ion[], struct gkyl_array* fld_maxwell[]); + +/** +* Coarse-to-fine projection operator for coupled, patch-structured AMR, assuming a lower coarse patch and an upper fine patch. +* +* @param tbid Target (fine) patch ID. +* @param tdir Target (fine) patch direction. +* @param i Reference (coarse) patch ID. +* @param d Reference (coarse) patch direction. +* @param pdata Patch-structured data for the coupled five-moment equations. +* @param bc_buffer_elc Buffer for applying electron boundary conditions. +* @param bc_buffer_ion Buffer for applying ion boundary conditions. +* @param bc_buffer_maxwell Buffer for applying Maxwell field boundary conditions. +* @param fld_elc Output array (electons). +* @param fld_ion Output array (ions). +* @param fld_maxwell Output array (Maxwell field). +*/ +void patch_coupled_lu_projection_op(const int tbid, const int tdir, const int i, const int d, const struct five_moment_patch_data pdata[], + const struct gkyl_array* bc_buffer_elc, const struct gkyl_array* bc_buffer_ion, const struct gkyl_array* bc_buffer_maxwell, + struct gkyl_array* fld_elc[], struct gkyl_array* fld_ion[], struct gkyl_array* fld_maxwell[]); + +/** +* Fine-to-coarse restriction operator for coupled, patch-structured AMR, assuming a lower fine patch and an upper coarse patch. +* +* @param tbid Target (coarse) patch ID. +* @param tdir Target (coarse) patch direction. +* @param i Reference (fine) patch ID. +* @param d Reference (fine) patch direction. +* @param pdata Patch-structured data for the coupled five-moment equations. +* @param bc_buffer_elc Buffer for applying electron boundary conditions. +* @param bc_buffer_ion Buffer for applying ion boundary conditions. +* @param bc_buffer_maxwell Buffer for applying Maxwell field boundary conditions. +* @param fld_elc Output array (electons). +* @param fld_ion Output array (ions). +* @param fld_maxwell Output array (Maxwell field). +*/ +void patch_coupled_lu_restriction_op(const int tbid, const int tdir, const int i, const int d, const struct five_moment_patch_data pdata[], + const struct gkyl_array* bc_buffer_elc, const struct gkyl_array* bc_buffer_ion, const struct gkyl_array* bc_buffer_maxwell, + struct gkyl_array* fld_elc[], struct gkyl_array* fld_ion[], struct gkyl_array* fld_maxwell[]); + +/** +* Coarse-to-fine projection operator for coupled, patch-structured AMR, assuming an upper coarse patch and a lower fine patch. +* +* @param tbid Target (fine) patch ID. +* @param tdir Target (fine) patch direction. +* @param i Reference (coarse) patch ID. +* @param d Reference (coarse) patch direction. +* @param pdata Patch-structured data for the coupled five-moment equations. +* @param bc_buffer_elc Buffer for applying electron boundary conditions. +* @param bc_buffer_ion Buffer for applying ion boundary conditions. +* @param bc_buffer_maxwell Buffer for applying Maxwell field boundary conditions. +* @param fld_elc Output array (electons). +* @param fld_ion Output array (ions). +* @param fld_maxwell Output array (Maxwell field). +*/ +void patch_coupled_ul_projection_op(const int tbid, const int tdir, const int i, const int d, const struct five_moment_patch_data pdata[], + const struct gkyl_array* bc_buffer_elc, const struct gkyl_array* bc_buffer_ion, const struct gkyl_array* bc_buffer_maxwell, + struct gkyl_array* fld_elc[], struct gkyl_array* fld_ion[], struct gkyl_array* fld_maxwell[]); + +/** +* Fine-to-coarse restriction operator for coupled, patch-structured AMR, assuming an upper fine patch and a lower coarse patch. +* +* @param tbid Target (coarse) patch ID. +* @param tdir Target (coarse) patch direction. +* @param i Reference (fine) patch ID. +* @param d Reference (fine) patch direction. +* @param pdata Patch-structured data for the coupled five-moment equations. +* @param bc_buffer_elc Buffer for applying electron boundary conditions. +* @param bc_buffer_ion Buffer for applying ion boundary conditions. +* @param bc_buffer_maxwell Buffer for applying Maxwell field boundary conditions. +* @param fld_elc Output array (electons). +* @param fld_ion Output array (ions). +* @param fld_maxwell Output array (Maxwell field). +*/ +void patch_coupled_ul_restriction_op(const int tbid, const int tdir, const int i, const int d, const struct five_moment_patch_data pdata[], + const struct gkyl_array* bc_buffer_elc, const struct gkyl_array* bc_buffer_ion, const struct gkyl_array* bc_buffer_maxwell, + struct gkyl_array* fld_elc[], struct gkyl_array* fld_ion[], struct gkyl_array* fld_maxwell[]); + +/** +* Coarse-to-fine projection operator for coupled, patch-structured AMR, assuming an upper coarse patch and an upper fine patch. +* +* @param tbid Target (fine) patch ID. +* @param tdir Target (fine) patch direction. +* @param i Reference (coarse) patch ID. +* @param d Reference (coarse) patch direction. +* @param pdata Patch-structured data for the coupled five-moment equations. +* @param bc_buffer_elc Buffer for applying electron boundary conditions. +* @param bc_buffer_ion Buffer for applying ion boundary conditions. +* @param bc_buffer_maxwell Buffer for applying Maxwell field boundary conditions. +* @param fld_elc Output array (electons). +* @param fld_ion Output array (ions). +* @param fld_maxwell Output array (Maxwell field). +*/ +void patch_coupled_uu_projection_op(const int tbid, const int tdir, const int i, const int d, const struct five_moment_patch_data pdata[], + const struct gkyl_array* bc_buffer_elc, const struct gkyl_array* bc_buffer_ion, const struct gkyl_array* bc_buffer_maxwell, + struct gkyl_array* fld_elc[], struct gkyl_array* fld_ion[], struct gkyl_array* fld_maxwell[]); + +/** +* Fine-to-coarse restriction operator for coupled, patch-structured AMR, assuming an upper fine patch and an upper coarse patch. +* +* @param tbid Target (coarse) patch ID. +* @param tdir Target (coarse) patch direction. +* @param i Reference (fine) patch ID. +* @param d Reference (fine) patch direction. +* @param pdata Patch-structured data for the coupled five-moment equations. +* @param bc_buffer_elc Buffer for applying electron boundary conditions. +* @param bc_buffer_ion Buffer for applying ion boundary conditions. +* @param bc_buffer_maxwell Buffer for applying Maxwell field boundary conditions. +* @param fld_elc Output array (electons). +* @param fld_ion Output array (ions). +* @param fld_maxwell Output array (Maxwell field). +*/ +void patch_coupled_uu_restriction_op(const int tbid, const int tdir, const int i, const int d, const struct five_moment_patch_data pdata[], + const struct gkyl_array* bc_buffer_elc, const struct gkyl_array* bc_buffer_ion, const struct gkyl_array* bc_buffer_maxwell, + struct gkyl_array* fld_elc[], struct gkyl_array* fld_ion[], struct gkyl_array* fld_maxwell[]); + /** * Synchronize all patches in the patch AMR hierarchy by applying all appropriate physical (outer-patch) and non-physical (inter-patch) * boundary conditions for the coupled five-moment equations. From 3cb9c99f3546eec72543b0e99e016fb572ae72a9 Mon Sep 17 00:00:00 2001 From: JonathanGorard Date: Tue, 9 Jul 2024 10:33:12 -0400 Subject: [PATCH 32/32] Globally renamed transmissive BCs -> copy BCs across the AMR framework, for reasons of consistency with existing naming conventions, as suggested by @JunoRavin --- amr/amr_block.c | 20 ++++---- amr/amr_block_coupled.c | 78 +++++++++++++++---------------- amr/amr_core_five_moment.c | 16 +++---- amr/amr_core_ten_moment.c | 16 +++---- amr/amr_patch.c | 16 +++---- amr/amr_patch_coupled.c | 48 +++++++++---------- amr/gkyl_amr_block_coupled_priv.h | 20 ++++---- amr/gkyl_amr_block_priv.h | 12 ++--- amr/gkyl_amr_core.h | 16 +++---- regression/rt_amr_10m_gem_l1.c | 4 +- regression/rt_amr_10m_gem_l2.c | 4 +- regression/rt_amr_5m_gem_l1.c | 4 +- regression/rt_amr_5m_gem_l2.c | 4 +- 13 files changed, 129 insertions(+), 129 deletions(-) diff --git a/amr/amr_block.c b/amr/amr_block.c index 3793df8d1..d182df8c0 100644 --- a/amr/amr_block.c +++ b/amr/amr_block.c @@ -12,7 +12,7 @@ skin_ghost_ranges_init_block(struct skin_ghost_ranges_block* sgr, const struct g } void -euler_transmissive_bc(double t, int nc, const double* GKYL_RESTRICT skin, double* GKYL_RESTRICT ghost, void* ctx) +euler_copy_bc(double t, int nc, const double* GKYL_RESTRICT skin, double* GKYL_RESTRICT ghost, void* ctx) { for (int i = 0; i < 5; i++) { ghost[i] = skin[i]; @@ -20,7 +20,7 @@ euler_transmissive_bc(double t, int nc, const double* GKYL_RESTRICT skin, double } void -gr_euler_transmissive_bc(double t, int nc, const double* GKYL_RESTRICT skin, double* GKYL_RESTRICT ghost, void* ctx) +gr_euler_copy_bc(double t, int nc, const double* GKYL_RESTRICT skin, double* GKYL_RESTRICT ghost, void* ctx) { for (int i = 0; i < 29; i++) { ghost[i] = skin[i]; @@ -40,12 +40,12 @@ euler_block_bc_updaters_init(struct euler_block_data* bdata, const struct gkyl_b if (conn->connections[d][0].edge == GKYL_PHYSICAL) { bdata->lower_bc[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler, bdata->geom, d, GKYL_LOWER_EDGE, nghost, - euler_transmissive_bc, 0); + euler_copy_bc, 0); } if (conn->connections[d][1].edge == GKYL_PHYSICAL) { bdata->upper_bc[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler, bdata->geom, d, GKYL_UPPER_EDGE, nghost, - euler_transmissive_bc, 0); + euler_copy_bc, 0); } } @@ -76,12 +76,12 @@ euler_nested_block_bc_updaters_init(struct euler_block_data* bdata, const struct if (conn->connections[d][0].edge == GKYL_PHYSICAL) { bdata->lower_bc[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler, bdata->geom, d, GKYL_LOWER_EDGE, nghost, - euler_transmissive_bc, 0); + euler_copy_bc, 0); } if (conn->connections[d][1].edge == GKYL_PHYSICAL) { bdata->upper_bc[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler, bdata->geom, d, GKYL_UPPER_EDGE, nghost, - euler_transmissive_bc, 0); + euler_copy_bc, 0); } } @@ -112,12 +112,12 @@ gr_euler_block_bc_updaters_init(struct euler_block_data* bdata, const struct gky if (conn->connections[d][0].edge == GKYL_PHYSICAL) { bdata->lower_bc[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler, bdata->geom, d, GKYL_LOWER_EDGE, nghost, - gr_euler_transmissive_bc, 0); + gr_euler_copy_bc, 0); } if (conn->connections[d][1].edge == GKYL_PHYSICAL) { bdata->upper_bc[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler, bdata->geom, d, GKYL_UPPER_EDGE, nghost, - gr_euler_transmissive_bc, 0); + gr_euler_copy_bc, 0); } } @@ -148,12 +148,12 @@ gr_euler_nested_block_bc_updaters_init(struct euler_block_data* bdata, const str if (conn->connections[d][0].edge == GKYL_PHYSICAL) { bdata->lower_bc[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler, bdata->geom, d, GKYL_LOWER_EDGE, nghost, - gr_euler_transmissive_bc, 0); + gr_euler_copy_bc, 0); } if (conn->connections[d][1].edge == GKYL_PHYSICAL) { bdata->upper_bc[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler, bdata->geom, d, GKYL_UPPER_EDGE, nghost, - gr_euler_transmissive_bc, 0); + gr_euler_copy_bc, 0); } } diff --git a/amr/amr_block_coupled.c b/amr/amr_block_coupled.c index 87c9d4997..262f25ccf 100644 --- a/amr/amr_block_coupled.c +++ b/amr/amr_block_coupled.c @@ -37,7 +37,7 @@ maxwell_wall_bc(double t, int nc, const double* GKYL_RESTRICT skin, double* GKYL } void -five_moment_transmissive_bc(double t, int nc, const double* GKYL_RESTRICT skin, double* GKYL_RESTRICT ghost, void* ctx) +five_moment_copy_bc(double t, int nc, const double* GKYL_RESTRICT skin, double* GKYL_RESTRICT ghost, void* ctx) { for (int i = 0; i < 5; i++) { ghost[i] = skin[i]; @@ -45,7 +45,7 @@ five_moment_transmissive_bc(double t, int nc, const double* GKYL_RESTRICT skin, } void -ten_moment_transmissive_bc(double t, int nc, const double* GKYL_RESTRICT skin, double* GKYL_RESTRICT ghost, void* ctx) +ten_moment_copy_bc(double t, int nc, const double* GKYL_RESTRICT skin, double* GKYL_RESTRICT ghost, void* ctx) { for (int i = 0; i < 10; i++) { ghost[i] = skin[i]; @@ -53,7 +53,7 @@ ten_moment_transmissive_bc(double t, int nc, const double* GKYL_RESTRICT skin, d } void -maxwell_transmissive_bc(double t, int nc, const double* GKYL_RESTRICT skin, double* GKYL_RESTRICT ghost, void* ctx) +maxwell_copy_bc(double t, int nc, const double* GKYL_RESTRICT skin, double* GKYL_RESTRICT ghost, void* ctx) { for (int i = 0; i < 8; i++) { ghost[i] = skin[i]; @@ -71,8 +71,8 @@ five_moment_block_bc_updaters_init(struct five_moment_block_data* bdata, const s bool wall_x = bdata->wall_x; bool wall_y = bdata->wall_y; - bool transmissive_x = bdata->transmissive_x; - bool transmissive_y = bdata->transmissive_y; + bool copy_x = bdata->copy_x; + bool copy_y = bdata->copy_y; for (int d = 0; d < 2; d++) { bdata->lower_bc_elc[d] = bdata->upper_bc_elc[d] = 0; @@ -98,23 +98,23 @@ five_moment_block_bc_updaters_init(struct five_moment_block_data* bdata, const s maxwell_wall_bc, 0); } } - else if ((d == 0 && transmissive_x) || (d == 1 && transmissive_y)) { + else if ((d == 0 && copy_x) || (d == 1 && copy_y)) { if (conn->connections[d][0].edge == GKYL_PHYSICAL) { bdata->lower_bc_elc[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler_elc, bdata->geom, d, GKYL_LOWER_EDGE, nghost, - five_moment_transmissive_bc, 0); + five_moment_copy_bc, 0); bdata->lower_bc_ion[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler_ion, bdata->geom, d, GKYL_LOWER_EDGE, nghost, - five_moment_transmissive_bc, 0); + five_moment_copy_bc, 0); bdata->lower_bc_maxwell[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->maxwell, bdata->geom, d, GKYL_LOWER_EDGE, nghost, - maxwell_transmissive_bc, 0); + maxwell_copy_bc, 0); } if (conn->connections[d][1].edge == GKYL_PHYSICAL) { bdata->upper_bc_elc[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler_elc, bdata->geom, d, GKYL_UPPER_EDGE, nghost, - five_moment_transmissive_bc, 0); + five_moment_copy_bc, 0); bdata->upper_bc_ion[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler_ion, bdata->geom, d, GKYL_UPPER_EDGE, nghost, - five_moment_transmissive_bc, 0); + five_moment_copy_bc, 0); bdata->upper_bc_maxwell[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->maxwell, bdata->geom, d, GKYL_UPPER_EDGE, nghost, - maxwell_transmissive_bc, 0); + maxwell_copy_bc, 0); } } } @@ -146,8 +146,8 @@ five_moment_nested_block_bc_updaters_init(struct five_moment_block_data* bdata, bool wall_x = bdata->wall_x; bool wall_y = bdata->wall_y; - bool transmissive_x = bdata->transmissive_x; - bool transmissive_y = bdata->transmissive_y; + bool copy_x = bdata->copy_x; + bool copy_y = bdata->copy_y; for (int d = 0; d < 2; d++) { bdata->lower_bc_elc[d] = bdata->upper_bc_elc[d] = 0; @@ -173,23 +173,23 @@ five_moment_nested_block_bc_updaters_init(struct five_moment_block_data* bdata, maxwell_wall_bc, 0); } } - else if ((d == 0 && transmissive_x) || (d == 1 && transmissive_y)) { + else if ((d == 0 && copy_x) || (d == 1 && copy_y)) { if (conn->connections[d][0].edge == GKYL_PHYSICAL) { bdata->lower_bc_elc[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler_elc, bdata->geom, d, GKYL_LOWER_EDGE, nghost, - five_moment_transmissive_bc, 0); + five_moment_copy_bc, 0); bdata->lower_bc_ion[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler_ion, bdata->geom, d, GKYL_LOWER_EDGE, nghost, - five_moment_transmissive_bc, 0); + five_moment_copy_bc, 0); bdata->lower_bc_maxwell[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->maxwell, bdata->geom, d, GKYL_LOWER_EDGE, nghost, - maxwell_transmissive_bc, 0); + maxwell_copy_bc, 0); } if (conn->connections[d][1].edge == GKYL_PHYSICAL) { bdata->upper_bc_elc[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler_elc, bdata->geom, d, GKYL_UPPER_EDGE, nghost, - five_moment_transmissive_bc, 0); + five_moment_copy_bc, 0); bdata->upper_bc_ion[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler_ion, bdata->geom, d, GKYL_UPPER_EDGE, nghost, - five_moment_transmissive_bc, 0); + five_moment_copy_bc, 0); bdata->upper_bc_maxwell[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->maxwell, bdata->geom, d, GKYL_UPPER_EDGE, nghost, - maxwell_transmissive_bc, 0); + maxwell_copy_bc, 0); } } } @@ -221,8 +221,8 @@ ten_moment_block_bc_updaters_init(struct five_moment_block_data* bdata, const st bool wall_x = bdata->wall_x; bool wall_y = bdata->wall_y; - bool transmissive_x = bdata->transmissive_x; - bool transmissive_y = bdata->transmissive_y; + bool copy_x = bdata->copy_x; + bool copy_y = bdata->copy_y; for (int d = 0; d < 2; d++) { bdata->lower_bc_elc[d] = bdata->upper_bc_elc[d] = 0; @@ -248,23 +248,23 @@ ten_moment_block_bc_updaters_init(struct five_moment_block_data* bdata, const st maxwell_wall_bc, 0); } } - else if ((d == 0 && transmissive_x) || (d == 1 && transmissive_y)) { + else if ((d == 0 && copy_x) || (d == 1 && copy_y)) { if (conn->connections[d][0].edge == GKYL_PHYSICAL) { bdata->lower_bc_elc[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler_elc, bdata->geom, d, GKYL_LOWER_EDGE, nghost, - ten_moment_transmissive_bc, 0); + ten_moment_copy_bc, 0); bdata->lower_bc_ion[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler_ion, bdata->geom, d, GKYL_LOWER_EDGE, nghost, - ten_moment_transmissive_bc, 0); + ten_moment_copy_bc, 0); bdata->lower_bc_maxwell[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->maxwell, bdata->geom, d, GKYL_LOWER_EDGE, nghost, - maxwell_transmissive_bc, 0); + maxwell_copy_bc, 0); } if (conn->connections[d][1].edge == GKYL_PHYSICAL) { bdata->upper_bc_elc[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler_elc, bdata->geom, d, GKYL_UPPER_EDGE, nghost, - ten_moment_transmissive_bc, 0); + ten_moment_copy_bc, 0); bdata->upper_bc_ion[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler_ion, bdata->geom, d, GKYL_UPPER_EDGE, nghost, - ten_moment_transmissive_bc, 0); + ten_moment_copy_bc, 0); bdata->upper_bc_maxwell[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->maxwell, bdata->geom, d, GKYL_UPPER_EDGE, nghost, - maxwell_transmissive_bc, 0); + maxwell_copy_bc, 0); } } } @@ -296,8 +296,8 @@ ten_moment_nested_block_bc_updaters_init(struct five_moment_block_data* bdata, c bool wall_x = bdata->wall_x; bool wall_y = bdata->wall_y; - bool transmissive_x = bdata->transmissive_x; - bool transmissive_y = bdata->transmissive_y; + bool copy_x = bdata->copy_x; + bool copy_y = bdata->copy_y; for (int d = 0; d < 2; d++) { bdata->lower_bc_elc[d] = bdata->upper_bc_elc[d] = 0; @@ -323,23 +323,23 @@ ten_moment_nested_block_bc_updaters_init(struct five_moment_block_data* bdata, c maxwell_wall_bc, 0); } } - else if ((d == 0 && transmissive_x) || (d == 1 && transmissive_y)) { + else if ((d == 0 && copy_x) || (d == 1 && copy_y)) { if (conn->connections[d][0].edge == GKYL_PHYSICAL) { bdata->lower_bc_elc[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler_elc, bdata->geom, d, GKYL_LOWER_EDGE, nghost, - ten_moment_transmissive_bc, 0); + ten_moment_copy_bc, 0); bdata->lower_bc_ion[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler_ion, bdata->geom, d, GKYL_LOWER_EDGE, nghost, - ten_moment_transmissive_bc, 0); + ten_moment_copy_bc, 0); bdata->lower_bc_maxwell[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->maxwell, bdata->geom, d, GKYL_LOWER_EDGE, nghost, - maxwell_transmissive_bc, 0); + maxwell_copy_bc, 0); } if (conn->connections[d][1].edge == GKYL_PHYSICAL) { bdata->upper_bc_elc[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler_elc, bdata->geom, d, GKYL_UPPER_EDGE, nghost, - ten_moment_transmissive_bc, 0); + ten_moment_copy_bc, 0); bdata->upper_bc_ion[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->euler_ion, bdata->geom, d, GKYL_UPPER_EDGE, nghost, - ten_moment_transmissive_bc, 0); + ten_moment_copy_bc, 0); bdata->upper_bc_maxwell[d] = gkyl_wv_apply_bc_new(&bdata->grid, bdata->maxwell, bdata->geom, d, GKYL_UPPER_EDGE, nghost, - maxwell_transmissive_bc, 0); + maxwell_copy_bc, 0); } } } diff --git a/amr/amr_core_five_moment.c b/amr/amr_core_five_moment.c index 1e6200ada..9de0e5565 100644 --- a/amr/amr_core_five_moment.c +++ b/amr/amr_core_five_moment.c @@ -668,8 +668,8 @@ five_moment_2d_run_single(int argc, char **argv, struct five_moment_2d_single_in double mass_ion = init->mass_ion; double charge_ion = init->charge_ion; - bool transmissive_x = init->transmissive_x; - bool transmissive_y = init->transmissive_y; + bool copy_x = init->copy_x; + bool copy_y = init->copy_y; bool wall_x = init->wall_x; bool wall_y = init->wall_y; @@ -723,8 +723,8 @@ five_moment_2d_run_single(int argc, char **argv, struct five_moment_2d_single_in gkyl_create_grid_ranges(&mesh_bdata[i].grid, (int []) { 2, 2 }, &mesh_bdata[i].ext_range, &mesh_bdata[i].range); mesh_bdata[i].geom = gkyl_wave_geom_new(&mesh_bdata[i].grid, &mesh_bdata[i].ext_range, 0, 0, false); - mesh_bdata[i].transmissive_x = transmissive_x; - mesh_bdata[i].transmissive_y = transmissive_y; + mesh_bdata[i].copy_x = copy_x; + mesh_bdata[i].copy_y = copy_y; mesh_bdata[i].wall_x = wall_x; mesh_bdata[i].wall_y = wall_y; @@ -1015,8 +1015,8 @@ five_moment_2d_run_double(int argc, char **argv, struct five_moment_2d_double_in double mass_ion = init->mass_ion; double charge_ion = init->charge_ion; - bool transmissive_x = init->transmissive_x; - bool transmissive_y = init->transmissive_y; + bool copy_x = init->copy_x; + bool copy_y = init->copy_y; bool wall_x = init->wall_x; bool wall_y = init->wall_y; @@ -1103,8 +1103,8 @@ five_moment_2d_run_double(int argc, char **argv, struct five_moment_2d_double_in gkyl_create_grid_ranges(&mesh_bdata[i].grid, (int []) { 2, 2 }, &mesh_bdata[i].ext_range, &mesh_bdata[i].range); mesh_bdata[i].geom = gkyl_wave_geom_new(&mesh_bdata[i].grid, &mesh_bdata[i].ext_range, 0, 0, false); - mesh_bdata[i].transmissive_x = transmissive_x; - mesh_bdata[i].transmissive_y = transmissive_y; + mesh_bdata[i].copy_x = copy_x; + mesh_bdata[i].copy_y = copy_y; mesh_bdata[i].wall_x = wall_x; mesh_bdata[i].wall_y = wall_y; diff --git a/amr/amr_core_ten_moment.c b/amr/amr_core_ten_moment.c index dd908cfc5..a16c8fe92 100644 --- a/amr/amr_core_ten_moment.c +++ b/amr/amr_core_ten_moment.c @@ -338,8 +338,8 @@ ten_moment_2d_run_single(int argc, char **argv, struct ten_moment_2d_single_init double mass_ion = init->mass_ion; double charge_ion = init->charge_ion; - bool transmissive_x = init->transmissive_x; - bool transmissive_y = init->transmissive_y; + bool copy_x = init->copy_x; + bool copy_y = init->copy_y; bool wall_x = init->wall_x; bool wall_y = init->wall_y; @@ -393,8 +393,8 @@ ten_moment_2d_run_single(int argc, char **argv, struct ten_moment_2d_single_init gkyl_create_grid_ranges(&mesh_bdata[i].grid, (int []) { 2, 2 }, &mesh_bdata[i].ext_range, &mesh_bdata[i].range); mesh_bdata[i].geom = gkyl_wave_geom_new(&mesh_bdata[i].grid, &mesh_bdata[i].ext_range, 0, 0, false); - mesh_bdata[i].transmissive_x = transmissive_x; - mesh_bdata[i].transmissive_y = transmissive_y; + mesh_bdata[i].copy_x = copy_x; + mesh_bdata[i].copy_y = copy_y; mesh_bdata[i].wall_x = wall_x; mesh_bdata[i].wall_y = wall_y; @@ -674,8 +674,8 @@ ten_moment_2d_run_double(int argc, char **argv, struct ten_moment_2d_double_init double mass_ion = init->mass_ion; double charge_ion = init->charge_ion; - bool transmissive_x = init->transmissive_x; - bool transmissive_y = init->transmissive_y; + bool copy_x = init->copy_x; + bool copy_y = init->copy_y; bool wall_x = init->wall_x; bool wall_y = init->wall_y; @@ -762,8 +762,8 @@ ten_moment_2d_run_double(int argc, char **argv, struct ten_moment_2d_double_init gkyl_create_grid_ranges(&mesh_bdata[i].grid, (int []) { 2, 2 }, &mesh_bdata[i].ext_range, &mesh_bdata[i].range); mesh_bdata[i].geom = gkyl_wave_geom_new(&mesh_bdata[i].grid, &mesh_bdata[i].ext_range, 0, 0, false); - mesh_bdata[i].transmissive_x = transmissive_x; - mesh_bdata[i].transmissive_y = transmissive_y; + mesh_bdata[i].copy_x = copy_x; + mesh_bdata[i].copy_y = copy_y; mesh_bdata[i].wall_x = wall_x; mesh_bdata[i].wall_y = wall_y; diff --git a/amr/amr_patch.c b/amr/amr_patch.c index 00fd6576c..6ca442661 100644 --- a/amr/amr_patch.c +++ b/amr/amr_patch.c @@ -19,12 +19,12 @@ euler_patch_bc_updaters_init(struct euler_patch_data* pdata, const struct gkyl_b if (conn->connections[0][0].edge == GKYL_PHYSICAL) { pdata->lower_bc[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->euler, pdata->geom, 0, GKYL_LOWER_EDGE, nghost, - euler_transmissive_bc, 0); + euler_copy_bc, 0); } if (conn->connections[0][1].edge == GKYL_PHYSICAL) { pdata->upper_bc[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->euler, pdata->geom, 0, GKYL_UPPER_EDGE, nghost, - euler_transmissive_bc, 0); + euler_copy_bc, 0); } skin_ghost_ranges_init_patch(&pdata->skin_ghost, &pdata->ext_range, nghost); @@ -51,12 +51,12 @@ euler_nested_patch_bc_updaters_init(struct euler_patch_data* pdata, const struct if (conn->connections[0][0].edge == GKYL_PHYSICAL) { pdata->lower_bc[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->euler, pdata->geom, 0, GKYL_LOWER_EDGE, nghost, - euler_transmissive_bc, 0); + euler_copy_bc, 0); } if (conn->connections[0][1].edge == GKYL_PHYSICAL) { pdata->upper_bc[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->euler, pdata->geom, 0, GKYL_UPPER_EDGE, nghost, - euler_transmissive_bc, 0); + euler_copy_bc, 0); } skin_ghost_ranges_init_patch(&pdata->skin_ghost, &pdata->ext_range, nghost); @@ -83,12 +83,12 @@ gr_euler_patch_bc_updaters_init(struct euler_patch_data* pdata, const struct gky if (conn->connections[0][0].edge == GKYL_PHYSICAL) { pdata->lower_bc[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->euler, pdata->geom, 0, GKYL_LOWER_EDGE, nghost, - gr_euler_transmissive_bc, 0); + gr_euler_copy_bc, 0); } if (conn->connections[0][1].edge == GKYL_PHYSICAL) { pdata->upper_bc[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->euler, pdata->geom, 0, GKYL_UPPER_EDGE, nghost, - gr_euler_transmissive_bc, 0); + gr_euler_copy_bc, 0); } skin_ghost_ranges_init_patch(&pdata->skin_ghost, &pdata->ext_range, nghost); @@ -115,12 +115,12 @@ gr_euler_nested_patch_bc_updaters_init(struct euler_patch_data* pdata, const str if (conn->connections[0][0].edge == GKYL_PHYSICAL) { pdata->lower_bc[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->euler, pdata->geom, 0, GKYL_LOWER_EDGE, nghost, - gr_euler_transmissive_bc, 0); + gr_euler_copy_bc, 0); } if (conn->connections[0][1].edge == GKYL_PHYSICAL) { pdata->upper_bc[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->euler, pdata->geom, 0, GKYL_UPPER_EDGE, nghost, - gr_euler_transmissive_bc, 0); + gr_euler_copy_bc, 0); } skin_ghost_ranges_init_patch(&pdata->skin_ghost, &pdata->ext_range, nghost); diff --git a/amr/amr_patch_coupled.c b/amr/amr_patch_coupled.c index ef5dac522..e4886b051 100644 --- a/amr/amr_patch_coupled.c +++ b/amr/amr_patch_coupled.c @@ -15,20 +15,20 @@ five_moment_patch_bc_updaters_init(struct five_moment_patch_data* pdata, const s if (conn->connections[0][0].edge == GKYL_PHYSICAL) { pdata->lower_bc_elc[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->euler_elc, pdata->geom, 0, GKYL_LOWER_EDGE, nghost, - five_moment_transmissive_bc, 0); + five_moment_copy_bc, 0); pdata->lower_bc_ion[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->euler_ion, pdata->geom, 0, GKYL_LOWER_EDGE, nghost, - five_moment_transmissive_bc, 0); + five_moment_copy_bc, 0); pdata->lower_bc_maxwell[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->maxwell, pdata->geom, 0, GKYL_LOWER_EDGE, nghost, - maxwell_transmissive_bc, 0); + maxwell_copy_bc, 0); } if (conn->connections[0][1].edge == GKYL_PHYSICAL) { pdata->upper_bc_elc[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->euler_elc, pdata->geom, 0, GKYL_UPPER_EDGE, nghost, - five_moment_transmissive_bc, 0); + five_moment_copy_bc, 0); pdata->upper_bc_ion[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->euler_ion, pdata->geom, 0, GKYL_UPPER_EDGE, nghost, - five_moment_transmissive_bc, 0); + five_moment_copy_bc, 0); pdata->upper_bc_maxwell[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->maxwell, pdata->geom, 0, GKYL_UPPER_EDGE, nghost, - maxwell_transmissive_bc, 0); + maxwell_copy_bc, 0); } skin_ghost_ranges_init_patch(&pdata->skin_ghost, &pdata->ext_range, nghost); @@ -59,20 +59,20 @@ five_moment_nested_patch_bc_updaters_init(struct five_moment_patch_data* pdata, if (conn->connections[0][0].edge == GKYL_PHYSICAL) { pdata->lower_bc_elc[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->euler_elc, pdata->geom, 0, GKYL_LOWER_EDGE, nghost, - five_moment_transmissive_bc, 0); + five_moment_copy_bc, 0); pdata->lower_bc_ion[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->euler_ion, pdata->geom, 0, GKYL_LOWER_EDGE, nghost, - five_moment_transmissive_bc, 0); + five_moment_copy_bc, 0); pdata->lower_bc_maxwell[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->maxwell, pdata->geom, 0, GKYL_LOWER_EDGE, nghost, - maxwell_transmissive_bc, 0); + maxwell_copy_bc, 0); } if (conn->connections[0][1].edge == GKYL_PHYSICAL) { pdata->upper_bc_elc[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->euler_elc, pdata->geom, 0, GKYL_UPPER_EDGE, nghost, - five_moment_transmissive_bc, 0); + five_moment_copy_bc, 0); pdata->upper_bc_ion[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->euler_ion, pdata->geom, 0, GKYL_UPPER_EDGE, nghost, - five_moment_transmissive_bc, 0); + five_moment_copy_bc, 0); pdata->upper_bc_maxwell[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->maxwell, pdata->geom, 0, GKYL_UPPER_EDGE, nghost, - maxwell_transmissive_bc, 0); + maxwell_copy_bc, 0); } skin_ghost_ranges_init_patch(&pdata->skin_ghost, &pdata->ext_range, nghost); @@ -103,20 +103,20 @@ ten_moment_patch_bc_updaters_init(struct five_moment_patch_data* pdata, const st if (conn->connections[0][0].edge == GKYL_PHYSICAL) { pdata->lower_bc_elc[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->euler_elc, pdata->geom, 0, GKYL_LOWER_EDGE, nghost, - ten_moment_transmissive_bc, 0); + ten_moment_copy_bc, 0); pdata->lower_bc_ion[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->euler_ion, pdata->geom, 0, GKYL_LOWER_EDGE, nghost, - ten_moment_transmissive_bc, 0); + ten_moment_copy_bc, 0); pdata->lower_bc_maxwell[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->maxwell, pdata->geom, 0, GKYL_LOWER_EDGE, nghost, - maxwell_transmissive_bc, 0); + maxwell_copy_bc, 0); } if (conn->connections[0][1].edge == GKYL_PHYSICAL) { pdata->upper_bc_elc[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->euler_elc, pdata->geom, 0, GKYL_UPPER_EDGE, nghost, - ten_moment_transmissive_bc, 0); + ten_moment_copy_bc, 0); pdata->upper_bc_ion[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->euler_ion, pdata->geom, 0, GKYL_UPPER_EDGE, nghost, - ten_moment_transmissive_bc, 0); + ten_moment_copy_bc, 0); pdata->upper_bc_maxwell[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->maxwell, pdata->geom, 0, GKYL_UPPER_EDGE, nghost, - maxwell_transmissive_bc, 0); + maxwell_copy_bc, 0); } skin_ghost_ranges_init_patch(&pdata->skin_ghost, &pdata->ext_range, nghost); @@ -147,20 +147,20 @@ ten_moment_nested_patch_bc_updaters_init(struct five_moment_patch_data* pdata, c if (conn->connections[0][0].edge == GKYL_PHYSICAL) { pdata->lower_bc_elc[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->euler_elc, pdata->geom, 0, GKYL_LOWER_EDGE, nghost, - ten_moment_transmissive_bc, 0); + ten_moment_copy_bc, 0); pdata->lower_bc_ion[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->euler_ion, pdata->geom, 0, GKYL_LOWER_EDGE, nghost, - ten_moment_transmissive_bc, 0); + ten_moment_copy_bc, 0); pdata->lower_bc_maxwell[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->maxwell, pdata->geom, 0, GKYL_LOWER_EDGE, nghost, - maxwell_transmissive_bc, 0); + maxwell_copy_bc, 0); } if (conn->connections[0][1].edge == GKYL_PHYSICAL) { pdata->upper_bc_elc[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->euler_elc, pdata->geom, 0, GKYL_UPPER_EDGE, nghost, - ten_moment_transmissive_bc, 0); + ten_moment_copy_bc, 0); pdata->upper_bc_ion[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->euler_ion, pdata->geom, 0, GKYL_UPPER_EDGE, nghost, - ten_moment_transmissive_bc, 0); + ten_moment_copy_bc, 0); pdata->upper_bc_maxwell[0] = gkyl_wv_apply_bc_new(&pdata->grid, pdata->maxwell, pdata->geom, 0, GKYL_UPPER_EDGE, nghost, - maxwell_transmissive_bc, 0); + maxwell_copy_bc, 0); } skin_ghost_ranges_init_patch(&pdata->skin_ghost, &pdata->ext_range, nghost); diff --git a/amr/gkyl_amr_block_coupled_priv.h b/amr/gkyl_amr_block_coupled_priv.h index 8d52263e4..58a8ac191 100644 --- a/amr/gkyl_amr_block_coupled_priv.h +++ b/amr/gkyl_amr_block_coupled_priv.h @@ -61,8 +61,8 @@ struct five_moment_block_data { gkyl_moment_em_coupling *src_slvr; - bool transmissive_x; - bool transmissive_y; + bool copy_x; + bool copy_y; bool wall_x; bool wall_y; @@ -130,29 +130,29 @@ void ten_moment_wall_bc(double t, int nc, const double* GKYL_RESTRICT skin, doub void maxwell_wall_bc(double t, int nc, const double* GKYL_RESTRICT skin, double* GKYL_RESTRICT ghost, void* ctx); /** -* Boundary condition function for applying transmissive boundary conditions for the coupled five-moment equations. +* Boundary condition function for applying copy boundary conditions for the coupled five-moment equations. * * @param t Current simulation time. -* @param nc Number of boundary cells to which to apply transmissive boundary conditions. +* @param nc Number of boundary cells to which to apply copy boundary conditions. * @param skin Skin cells in boundary region (from which values are copied). * @param ghost Ghost cells in boundary region (to which values are copied). * @param ctx Context to pass to the function. */ -void five_moment_transmissive_bc(double t, int nc, const double* GKYL_RESTRICT skin, double* GKYL_RESTRICT ghost, void* ctx); +void five_moment_copy_bc(double t, int nc, const double* GKYL_RESTRICT skin, double* GKYL_RESTRICT ghost, void* ctx); /** -* Boundary condition function for applying transmissive boundary conditions for the coupled ten-moment equations. +* Boundary condition function for applying copy boundary conditions for the coupled ten-moment equations. * * @param t Current simulation time. -* @param nc Number of boundary cells to which to apply transmissive boundary conditions. +* @param nc Number of boundary cells to which to apply copy boundary conditions. * @param skin Skin cells in boundary region (from which values are copied). * @param ghost Ghost cells in boundary region (to which values are copied). * @param ctx Context to pass to the function. */ -void ten_moment_transmissive_bc(double t, int nc, const double* GKYL_RESTRICT skin, double* GKYL_RESTRICT ghost, void* ctx); +void ten_moment_copy_bc(double t, int nc, const double* GKYL_RESTRICT skin, double* GKYL_RESTRICT ghost, void* ctx); /** -* Boundary condition function for applying transmissive boundary conditions for the Maxwell equations. +* Boundary condition function for applying copy boundary conditions for the Maxwell equations. * * @param t Current simulation time. * @param nc Number of boundary cells to which to apply tranmissive boundary conditions. @@ -160,7 +160,7 @@ void ten_moment_transmissive_bc(double t, int nc, const double* GKYL_RESTRICT sk * @param ghost Ghost cells in boundary region (to which values are copied). * @param ctx Context to pass to the function. */ -void maxwell_transmissive_bc(double t, int nc, const double* GKYL_RESTRICT skin, double* GKYL_RESTRICT ghost, void* ctx); +void maxwell_copy_bc(double t, int nc, const double* GKYL_RESTRICT skin, double* GKYL_RESTRICT ghost, void* ctx); /** * Initialize block AMR updaters for both physical (outer-block) and non-physical (inter-block) boundary conditions for the coupled five-moment equations. diff --git a/amr/gkyl_amr_block_priv.h b/amr/gkyl_amr_block_priv.h index cd68eb74e..fafcd50df 100644 --- a/amr/gkyl_amr_block_priv.h +++ b/amr/gkyl_amr_block_priv.h @@ -99,26 +99,26 @@ struct sim_stats { void skin_ghost_ranges_init_block(struct skin_ghost_ranges_block* sgr, const struct gkyl_range* parent, const int* ghost); /** -* Boundary condition function for applying transmissive boundary conditions for the Euler equations. +* Boundary condition function for applying copy boundary conditions for the Euler equations. * * @param t Current simulation time. -* @param nc Number of boundary cells to which to apply transmissive boundary conditions. +* @param nc Number of boundary cells to which to apply copy boundary conditions. * @param skin Skin cells in boundary region (from which values are copied). * @param ghost Ghost cells in boundary region (to which values are copied). * @param ctx Context to pass to the function. */ -void euler_transmissive_bc(double t, int nc, const double* GKYL_RESTRICT skin, double* GKYL_RESTRICT ghost, void* ctx); +void euler_copy_bc(double t, int nc, const double* GKYL_RESTRICT skin, double* GKYL_RESTRICT ghost, void* ctx); /** -* Boundary condition function for applying transmissive boundary conditions for the general relativistic Euler equations. +* Boundary condition function for applying copy boundary conditions for the general relativistic Euler equations. * * @param t Current simulation time. -* @param nc Number of boundary cells to which to apply transmissive boundary conditions. +* @param nc Number of boundary cells to which to apply copy boundary conditions. * @param skin Skin cells in boundary region (from which values are copied). * @param ghost Ghost cells in boundary region (to which values are copied). * @param ctx Context to pass to the function. */ -void gr_euler_transmissive_bc(double t, int nc, const double* GKYL_RESTRICT skin, double* GKYL_RESTRICT ghost, void* ctx); +void gr_euler_copy_bc(double t, int nc, const double* GKYL_RESTRICT skin, double* GKYL_RESTRICT ghost, void* ctx); /** * Initialize block AMR updaters for both physical (outer-block) and non-physical (inter-block) boundary conditions for the Euler equations. diff --git a/amr/gkyl_amr_core.h b/amr/gkyl_amr_core.h index 29258fc3c..21951882e 100644 --- a/amr/gkyl_amr_core.h +++ b/amr/gkyl_amr_core.h @@ -503,8 +503,8 @@ struct five_moment_2d_single_init { double mass_ion; double charge_ion; - bool transmissive_x; - bool transmissive_y; + bool copy_x; + bool copy_y; bool wall_x; bool wall_y; @@ -562,8 +562,8 @@ struct ten_moment_2d_single_init { double mass_ion; double charge_ion; - bool transmissive_x; - bool transmissive_y; + bool copy_x; + bool copy_y; bool wall_x; bool wall_y; @@ -628,8 +628,8 @@ struct five_moment_2d_double_init { double mass_ion; double charge_ion; - bool transmissive_x; - bool transmissive_y; + bool copy_x; + bool copy_y; bool wall_x; bool wall_y; @@ -694,8 +694,8 @@ struct ten_moment_2d_double_init { double mass_ion; double charge_ion; - bool transmissive_x; - bool transmissive_y; + bool copy_x; + bool copy_y; bool wall_x; bool wall_y; diff --git a/regression/rt_amr_10m_gem_l1.c b/regression/rt_amr_10m_gem_l1.c index f2a70422e..e5554d5cf 100644 --- a/regression/rt_amr_10m_gem_l1.c +++ b/regression/rt_amr_10m_gem_l1.c @@ -271,8 +271,8 @@ int main(int argc, char **argv) .mass_ion = ctx.mass_ion, .charge_ion = ctx.charge_ion, - .transmissive_x = true, - .transmissive_y = false, + .copy_x = true, + .copy_y = false, .wall_x = false, .wall_y = true, diff --git a/regression/rt_amr_10m_gem_l2.c b/regression/rt_amr_10m_gem_l2.c index a17172a1c..d416a96af 100644 --- a/regression/rt_amr_10m_gem_l2.c +++ b/regression/rt_amr_10m_gem_l2.c @@ -286,8 +286,8 @@ int main(int argc, char **argv) .mass_ion = ctx.mass_ion, .charge_ion = ctx.charge_ion, - .transmissive_x = true, - .transmissive_y = false, + .copy_x = true, + .copy_y = false, .wall_x = false, .wall_y = true, diff --git a/regression/rt_amr_5m_gem_l1.c b/regression/rt_amr_5m_gem_l1.c index 8702156fb..8feb8aeed 100644 --- a/regression/rt_amr_5m_gem_l1.c +++ b/regression/rt_amr_5m_gem_l1.c @@ -275,8 +275,8 @@ int main(int argc, char **argv) .mass_ion = ctx.mass_ion, .charge_ion = ctx.charge_ion, - .transmissive_x = true, - .transmissive_y = false, + .copy_x = true, + .copy_y = false, .wall_x = false, .wall_y = true, diff --git a/regression/rt_amr_5m_gem_l2.c b/regression/rt_amr_5m_gem_l2.c index 54cbe63e0..dd602568b 100644 --- a/regression/rt_amr_5m_gem_l2.c +++ b/regression/rt_amr_5m_gem_l2.c @@ -290,8 +290,8 @@ int main(int argc, char **argv) .mass_ion = ctx.mass_ion, .charge_ion = ctx.charge_ion, - .transmissive_x = true, - .transmissive_y = false, + .copy_x = true, + .copy_y = false, .wall_x = false, .wall_y = true,