214 UserCtx *user,
const DMDALocalInfo *info,
215 PetscInt xs_gnode_rank, PetscInt ys_gnode_rank, PetscInt zs_gnode_rank,
216 PetscInt IM_cells_global, PetscInt JM_cells_global, PetscInt KM_cells_global,
217 PetscInt64 particle_global_id,
218 PetscInt *ci_metric_lnode_out, PetscInt *cj_metric_lnode_out, PetscInt *ck_metric_lnode_out,
219 PetscReal *xi_metric_logic_out, PetscReal *eta_metric_logic_out, PetscReal *zta_metric_logic_out,
220 PetscBool *placement_successful_out)
223 PetscReal global_logic_i = 0.0, global_logic_j = 0.0, global_logic_k = 0.0;
225 PetscMPIInt rank_for_logging;
227 PetscFunctionBeginUser;
228 ierr = MPI_Comm_rank(PETSC_COMM_WORLD, &rank_for_logging); CHKERRQ(ierr);
230 *placement_successful_out = PETSC_FALSE;
235 const PetscInt grid_layers = 2;
238 "[Rank %d] Placing particle %lld on face %s with grid_layers=%d in global domain (%d,%d,%d) cells.\n",
240 IM_cells_global, JM_cells_global, KM_cells_global);
248 if (JM_cells_global <= 1 || KM_cells_global <= 1) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG,
"Cannot place grid on face %s for a 2D/1D domain (J-cells=%d, K-cells=%d).", face_name, JM_cells_global, KM_cells_global);
249 if (2 * grid_layers >= JM_cells_global || 2 * grid_layers >= KM_cells_global) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE,
"Grid layers (%d) from opposing J/K faces would overlap in this domain (J-cells=%d, K-cells=%d).", grid_layers, JM_cells_global, KM_cells_global);
252 if (IM_cells_global <= 1 || KM_cells_global <= 1) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG,
"Cannot place grid on face %s for a 2D/1D domain (I-cells=%d, K-cells=%d).", face_name, IM_cells_global, KM_cells_global);
253 if (2 * grid_layers >= IM_cells_global || 2 * grid_layers >= KM_cells_global) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE,
"Grid layers (%d) from opposing I/K faces would overlap in this domain (I-cells=%d, K-cells=%d).", grid_layers, IM_cells_global, KM_cells_global);
256 if (IM_cells_global <= 1 || JM_cells_global <= 1) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG,
"Cannot place grid on face %s for a 2D/1D domain (I-cells=%d, J-cells=%d).", face_name, IM_cells_global, JM_cells_global);
257 if (2 * grid_layers >= IM_cells_global || 2 * grid_layers >= JM_cells_global) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE,
"Grid layers (%d) from opposing I/J faces would overlap in this domain (I-cells=%d, J-cells=%d).", grid_layers, IM_cells_global, JM_cells_global);
259 default: SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG,
"Invalid identifiedInletBCFace specified: %d", user->
identifiedInletBCFace);
262 const PetscInt num_lines_total = 4 * grid_layers;
263 if (simCtx->
np < num_lines_total) {
264 LOG_ALLOW(
GLOBAL,
LOG_WARNING,
"Warning: Total particle count (%lld) is less than the number of grid lines requested (%d). Some lines may be empty.\n", (
long long)simCtx->
np, num_lines_total);
266 if (simCtx->
np > 0 && simCtx->
np % num_lines_total != 0) {
267 LOG_ALLOW(
GLOBAL,
LOG_WARNING,
"Warning: Total particle count (%lld) is not evenly divisible by the number of grid lines (%d). Distribution will be uneven.\n", (
long long)simCtx->
np, num_lines_total);
271 if (simCtx->
np == 0) PetscFunctionReturn(0);
274 rank_for_logging, (
long long)simCtx->
np, num_lines_total, face_name);
276 const PetscInt points_per_line = PetscMax(1, simCtx->
np / num_lines_total);
277 PetscInt line_index = particle_global_id / points_per_line;
278 PetscInt point_index_on_line = particle_global_id % points_per_line;
279 line_index = PetscMin(line_index, num_lines_total - 1);
282 const PetscInt edge_group = line_index / grid_layers;
283 const PetscInt layer_index = line_index % grid_layers;
286 const PetscReal layer_spacing_norm_i = (IM_cells_global > 0) ? 1.0 / (PetscReal)IM_cells_global : 0.0;
287 const PetscReal layer_spacing_norm_j = (JM_cells_global > 0) ? 1.0 / (PetscReal)JM_cells_global : 0.0;
288 const PetscReal layer_spacing_norm_k = (KM_cells_global > 0) ? 1.0 / (PetscReal)KM_cells_global : 0.0;
291 const PetscReal min_layer_spacing = PetscMin(layer_spacing_norm_i, PetscMin(layer_spacing_norm_j, layer_spacing_norm_k));
292 const PetscReal epsilon = 0.5 * min_layer_spacing;
294 PetscReal variable_coord;
295 if (points_per_line <= 1) {
296 variable_coord = 0.5;
298 variable_coord = ((PetscReal)point_index_on_line + 0.5)/ (PetscReal)(points_per_line);
300 variable_coord = PetscMin(1.0 - epsilon, PetscMax(epsilon, variable_coord));
305 global_logic_i = 0.5 * layer_spacing_norm_i;
306 if (edge_group == 0) { global_logic_j = (PetscReal)layer_index * layer_spacing_norm_j + epsilon; global_logic_k = variable_coord; }
307 else if (edge_group == 1) { global_logic_j = 1.0 - ((PetscReal)layer_index * layer_spacing_norm_j) - epsilon; global_logic_k = variable_coord; }
308 else if (edge_group == 2) { global_logic_k = (PetscReal)layer_index * layer_spacing_norm_k + epsilon; global_logic_j = variable_coord; }
309 else { global_logic_k = 1.0 - ((PetscReal)layer_index * layer_spacing_norm_k) - epsilon; global_logic_j = variable_coord; }
312 global_logic_i = 1.0 - (0.5 * layer_spacing_norm_i);
313 if (edge_group == 0) { global_logic_j = (PetscReal)layer_index * layer_spacing_norm_j + epsilon; global_logic_k = variable_coord; }
314 else if (edge_group == 1) { global_logic_j = 1.0 - ((PetscReal)layer_index * layer_spacing_norm_j) - epsilon; global_logic_k = variable_coord; }
315 else if (edge_group == 2) { global_logic_k = (PetscReal)layer_index * layer_spacing_norm_k + epsilon; global_logic_j = variable_coord; }
316 else { global_logic_k = 1.0 - ((PetscReal)layer_index * layer_spacing_norm_k) - epsilon; global_logic_j = variable_coord; }
319 global_logic_j = 0.5 * layer_spacing_norm_j;
320 if (edge_group == 0) { global_logic_i = (PetscReal)layer_index * layer_spacing_norm_i + epsilon; global_logic_k = variable_coord; }
321 else if (edge_group == 1) { global_logic_i = 1.0 - ((PetscReal)layer_index * layer_spacing_norm_i) - epsilon; global_logic_k = variable_coord; }
322 else if (edge_group == 2) { global_logic_k = (PetscReal)layer_index * layer_spacing_norm_k + epsilon; global_logic_i = variable_coord; }
323 else { global_logic_k = 1.0 - ((PetscReal)layer_index * layer_spacing_norm_k) - epsilon; global_logic_i = variable_coord; }
326 global_logic_j = 1.0 - (0.5 * layer_spacing_norm_j);
327 if (edge_group == 0) { global_logic_i = (PetscReal)layer_index * layer_spacing_norm_i + epsilon; global_logic_k = variable_coord; }
328 else if (edge_group == 1) { global_logic_i = 1.0 - ((PetscReal)layer_index * layer_spacing_norm_i) - epsilon; global_logic_k = variable_coord; }
329 else if (edge_group == 2) { global_logic_k = (PetscReal)layer_index * layer_spacing_norm_k + epsilon; global_logic_i = variable_coord; }
330 else { global_logic_k = 1.0 - ((PetscReal)layer_index * layer_spacing_norm_k) - epsilon; global_logic_i = variable_coord; }
333 global_logic_k = 0.5 * layer_spacing_norm_k;
334 if (edge_group == 0) { global_logic_i = (PetscReal)layer_index * layer_spacing_norm_i + epsilon; global_logic_j = variable_coord; }
335 else if (edge_group == 1) { global_logic_i = 1.0 - ((PetscReal)layer_index * layer_spacing_norm_i) - epsilon; global_logic_j = variable_coord; }
336 else if (edge_group == 2) { global_logic_j = (PetscReal)layer_index * layer_spacing_norm_j + epsilon; global_logic_i = variable_coord; }
337 else { global_logic_j = 1.0 - ((PetscReal)layer_index * layer_spacing_norm_j) - epsilon; global_logic_i = variable_coord; }
340 global_logic_k = 1.0 - (0.5 * layer_spacing_norm_k);
341 if (edge_group == 0) { global_logic_i = (PetscReal)layer_index * layer_spacing_norm_i + epsilon; global_logic_j = variable_coord; }
342 else if (edge_group == 1) { global_logic_i = 1.0 - ((PetscReal)layer_index * layer_spacing_norm_i) - epsilon; global_logic_j = variable_coord; }
343 else if (edge_group == 2) { global_logic_j = (PetscReal)layer_index * layer_spacing_norm_j + epsilon; global_logic_i = variable_coord; }
344 else { global_logic_j = 1.0 - ((PetscReal)layer_index * layer_spacing_norm_j) - epsilon; global_logic_i = variable_coord; }
349 "[Rank %d] Particle %lld assigned to line %d (edge group %d, layer %d) with variable_coord=%.4f.\n"
350 " -> Global logical coords: (i,j,k) = (%.6f, %.6f, %.6f)\n",
351 rank_for_logging, (
long long)particle_global_id, line_index, edge_group, layer_index, variable_coord,
352 global_logic_i, global_logic_j, global_logic_k);
355 PetscReal global_cell_coord_i = global_logic_i * IM_cells_global;
356 PetscInt I_g = (PetscInt)global_cell_coord_i;
357 *xi_metric_logic_out = global_cell_coord_i - I_g;
359 PetscReal global_cell_coord_j = global_logic_j * JM_cells_global;
360 PetscInt J_g = (PetscInt)global_cell_coord_j;
361 *eta_metric_logic_out = global_cell_coord_j - J_g;
363 PetscReal global_cell_coord_k = global_logic_k * KM_cells_global;
364 PetscInt K_g = (PetscInt)global_cell_coord_k;
365 *zta_metric_logic_out = global_cell_coord_k - K_g;
368 if ((I_g >= info->xs && I_g < info->xs + info->xm) &&
369 (J_g >= info->ys && J_g < info->ys + info->ym) &&
370 (K_g >= info->zs && K_g < info->zs + info->zm))
373 *ci_metric_lnode_out = (I_g - info->xs) + xs_gnode_rank;
374 *cj_metric_lnode_out = (J_g - info->ys) + ys_gnode_rank;
375 *ck_metric_lnode_out = (K_g - info->zs) + zs_gnode_rank;
376 *placement_successful_out = PETSC_TRUE;
380 "[Rank %d] Particle %lld placement %s.\n",
381 rank_for_logging, (
long long)particle_global_id,
382 (*placement_successful_out ?
"SUCCESSFUL" :
"NOT ON THIS RANK"));
384 if(*placement_successful_out){
385 LOG_ALLOW(
LOCAL,
LOG_TRACE,
"Local cell origin node: (I,J,K) = (%d,%d,%d), intra-cell logicals: (xi,eta,zta)=(%.6f,%.6f,%.6f)\n",
386 *ci_metric_lnode_out, *cj_metric_lnode_out, *ck_metric_lnode_out,
387 *xi_metric_logic_out, *eta_metric_logic_out, *zta_metric_logic_out);
390 PetscFunctionReturn(0);
401 UserCtx *user,
const DMDALocalInfo *info,
402 PetscInt xs_gnode_rank, PetscInt ys_gnode_rank, PetscInt zs_gnode_rank,
403 PetscInt IM_nodes_global, PetscInt JM_nodes_global, PetscInt KM_nodes_global,
404 PetscRandom *rand_logic_i_ptr, PetscRandom *rand_logic_j_ptr, PetscRandom *rand_logic_k_ptr,
405 PetscInt *ci_metric_lnode_out, PetscInt *cj_metric_lnode_out, PetscInt *ck_metric_lnode_out,
406 PetscReal *xi_metric_logic_out, PetscReal *eta_metric_logic_out, PetscReal *zta_metric_logic_out)
408 PetscErrorCode ierr = 0;
409 PetscReal r_val_i_sel, r_val_j_sel, r_val_k_sel;
410 PetscInt local_cell_idx_on_face_dim1 = 0;
411 PetscInt local_cell_idx_on_face_dim2 = 0;
412 PetscMPIInt rank_for_logging;
414 PetscFunctionBeginUser;
418 ierr = MPI_Comm_rank(PETSC_COMM_WORLD, &rank_for_logging); CHKERRQ(ierr);
421 PetscInt owned_start_cell_i, num_owned_cells_on_rank_i;
422 PetscInt owned_start_cell_j, num_owned_cells_on_rank_j;
423 PetscInt owned_start_cell_k, num_owned_cells_on_rank_k;
425 ierr =
GetOwnedCellRange(info, 0, &owned_start_cell_i, &num_owned_cells_on_rank_i); CHKERRQ(ierr);
426 ierr =
GetOwnedCellRange(info, 1, &owned_start_cell_j, &num_owned_cells_on_rank_j); CHKERRQ(ierr);
427 ierr =
GetOwnedCellRange(info, 2, &owned_start_cell_k, &num_owned_cells_on_rank_k); CHKERRQ(ierr);
430 *ci_metric_lnode_out = xs_gnode_rank; *cj_metric_lnode_out = ys_gnode_rank; *ck_metric_lnode_out = zs_gnode_rank;
432 *xi_metric_logic_out = 0.5; *eta_metric_logic_out = 0.5; *zta_metric_logic_out = 0.5;
435 PetscInt last_global_cell_idx_i = (IM_nodes_global > 1) ? (IM_nodes_global - 2) : -1;
436 PetscInt last_global_cell_idx_j = (JM_nodes_global > 1) ? (JM_nodes_global - 2) : -1;
437 PetscInt last_global_cell_idx_k = (KM_nodes_global > 1) ? (KM_nodes_global - 2) : -1;
440 " Owned cells (i,j,k): (%d,%d,%d)\n"
441 " Global nodes (I,J,K): (%d,%d,%d)\n"
442 " info->xs,ys,zs (first owned node GLOBAL): (%d,%d,%d)\n"
443 " info->xm,ym,zm (num owned nodes GLOBAL): (%d,%d,%d)\n"
444 " xs_gnode_rank,ys_gnode_rank,zs_gnode_rank (DMDAGetCorners): (%d,%d,%d)\n"
445 " owned_start_cell (i,j,k) GLOBAL: (%d,%d,%d)\n"
446 " last_global_cell_idx (i,j,k): (%d,%d,%d)\n",
448 num_owned_cells_on_rank_i,num_owned_cells_on_rank_j,num_owned_cells_on_rank_k,
449 IM_nodes_global,JM_nodes_global,KM_nodes_global,
450 info->xs, info->ys, info->zs,
451 info->xm, info->ym, info->zm,
452 xs_gnode_rank,ys_gnode_rank,zs_gnode_rank,
453 owned_start_cell_i, owned_start_cell_j, owned_start_cell_k,
454 last_global_cell_idx_i, last_global_cell_idx_j, last_global_cell_idx_k);
461 *ci_metric_lnode_out = xs_gnode_rank;
462 *xi_metric_logic_out = 1.0e-6;
466 ierr = PetscRandomGetValueReal(*rand_logic_j_ptr, &r_val_j_sel); CHKERRQ(ierr);
467 local_cell_idx_on_face_dim1 = (PetscInt)(r_val_j_sel * num_owned_cells_on_rank_j);
468 local_cell_idx_on_face_dim1 = PetscMin(PetscMax(0, local_cell_idx_on_face_dim1), num_owned_cells_on_rank_j - 1);
469 *cj_metric_lnode_out = ys_gnode_rank + local_cell_idx_on_face_dim1;
471 ierr = PetscRandomGetValueReal(*rand_logic_k_ptr, &r_val_k_sel); CHKERRQ(ierr);
472 local_cell_idx_on_face_dim2 = (PetscInt)(r_val_k_sel * num_owned_cells_on_rank_k);
473 local_cell_idx_on_face_dim2 = PetscMin(PetscMax(0, local_cell_idx_on_face_dim2), num_owned_cells_on_rank_k - 1);
474 *ck_metric_lnode_out = zs_gnode_rank + local_cell_idx_on_face_dim2;
476 ierr = PetscRandomGetValueReal(*rand_logic_j_ptr, eta_metric_logic_out); CHKERRQ(ierr);
477 ierr = PetscRandomGetValueReal(*rand_logic_k_ptr, zta_metric_logic_out); CHKERRQ(ierr);
483 *ci_metric_lnode_out = xs_gnode_rank + (last_global_cell_idx_i - info->xs);
484 *xi_metric_logic_out = 1.0 - 1.0e-6;
486 ierr = PetscRandomGetValueReal(*rand_logic_j_ptr, &r_val_j_sel); CHKERRQ(ierr);
487 local_cell_idx_on_face_dim1 = (PetscInt)(r_val_j_sel * num_owned_cells_on_rank_j);
488 local_cell_idx_on_face_dim1 = PetscMin(PetscMax(0, local_cell_idx_on_face_dim1), num_owned_cells_on_rank_j - 1);
489 *cj_metric_lnode_out = ys_gnode_rank + local_cell_idx_on_face_dim1;
491 ierr = PetscRandomGetValueReal(*rand_logic_k_ptr, &r_val_k_sel); CHKERRQ(ierr);
492 local_cell_idx_on_face_dim2 = (PetscInt)(r_val_k_sel * num_owned_cells_on_rank_k);
493 local_cell_idx_on_face_dim2 = PetscMin(PetscMax(0, local_cell_idx_on_face_dim2), num_owned_cells_on_rank_k - 1);
494 *ck_metric_lnode_out = zs_gnode_rank + local_cell_idx_on_face_dim2;
496 ierr = PetscRandomGetValueReal(*rand_logic_j_ptr, eta_metric_logic_out); CHKERRQ(ierr);
497 ierr = PetscRandomGetValueReal(*rand_logic_k_ptr, zta_metric_logic_out); CHKERRQ(ierr);
501 *cj_metric_lnode_out = ys_gnode_rank;
502 *eta_metric_logic_out = 1.0e-6;
503 ierr = PetscRandomGetValueReal(*rand_logic_i_ptr, &r_val_i_sel); CHKERRQ(ierr);
504 local_cell_idx_on_face_dim1 = (PetscInt)(r_val_i_sel * num_owned_cells_on_rank_i);
505 local_cell_idx_on_face_dim1 = PetscMin(PetscMax(0, local_cell_idx_on_face_dim1), num_owned_cells_on_rank_i - 1);
506 *ci_metric_lnode_out = xs_gnode_rank + local_cell_idx_on_face_dim1;
507 ierr = PetscRandomGetValueReal(*rand_logic_k_ptr, &r_val_k_sel); CHKERRQ(ierr);
508 local_cell_idx_on_face_dim2 = (PetscInt)(r_val_k_sel * num_owned_cells_on_rank_k);
509 local_cell_idx_on_face_dim2 = PetscMin(PetscMax(0, local_cell_idx_on_face_dim2), num_owned_cells_on_rank_k - 1);
510 *ck_metric_lnode_out = zs_gnode_rank + local_cell_idx_on_face_dim2;
511 ierr = PetscRandomGetValueReal(*rand_logic_i_ptr, xi_metric_logic_out); CHKERRQ(ierr);
512 ierr = PetscRandomGetValueReal(*rand_logic_k_ptr, zta_metric_logic_out); CHKERRQ(ierr);
515 *cj_metric_lnode_out = ys_gnode_rank + (last_global_cell_idx_j - info->ys);
516 *eta_metric_logic_out = 1.0 - 1.0e-6;
517 ierr = PetscRandomGetValueReal(*rand_logic_i_ptr, &r_val_i_sel); CHKERRQ(ierr);
518 local_cell_idx_on_face_dim1 = (PetscInt)(r_val_i_sel * num_owned_cells_on_rank_i);
519 local_cell_idx_on_face_dim1 = PetscMin(PetscMax(0, local_cell_idx_on_face_dim1), num_owned_cells_on_rank_i - 1);
520 *ci_metric_lnode_out = xs_gnode_rank + local_cell_idx_on_face_dim1;
521 ierr = PetscRandomGetValueReal(*rand_logic_k_ptr, &r_val_k_sel); CHKERRQ(ierr);
522 local_cell_idx_on_face_dim2 = (PetscInt)(r_val_k_sel * num_owned_cells_on_rank_k);
523 local_cell_idx_on_face_dim2 = PetscMin(PetscMax(0, local_cell_idx_on_face_dim2), num_owned_cells_on_rank_k - 1);
524 *ck_metric_lnode_out = zs_gnode_rank + local_cell_idx_on_face_dim2;
525 ierr = PetscRandomGetValueReal(*rand_logic_i_ptr, xi_metric_logic_out); CHKERRQ(ierr);
526 ierr = PetscRandomGetValueReal(*rand_logic_k_ptr, zta_metric_logic_out); CHKERRQ(ierr);
529 *ck_metric_lnode_out = zs_gnode_rank;
530 *zta_metric_logic_out = 1.0e-6;
532 ierr = PetscRandomGetValueReal(*rand_logic_i_ptr, &r_val_i_sel); CHKERRQ(ierr);
533 local_cell_idx_on_face_dim1 = (PetscInt)(r_val_i_sel * num_owned_cells_on_rank_i);
534 local_cell_idx_on_face_dim1 = PetscMin(PetscMax(0, local_cell_idx_on_face_dim1), num_owned_cells_on_rank_i - 1);
535 *ci_metric_lnode_out = xs_gnode_rank + local_cell_idx_on_face_dim1;
537 ierr = PetscRandomGetValueReal(*rand_logic_j_ptr, &r_val_j_sel); CHKERRQ(ierr);
538 local_cell_idx_on_face_dim2 = (PetscInt)(r_val_j_sel * num_owned_cells_on_rank_j);
539 local_cell_idx_on_face_dim2 = PetscMin(PetscMax(0, local_cell_idx_on_face_dim2), num_owned_cells_on_rank_j - 1);
540 *cj_metric_lnode_out = ys_gnode_rank + local_cell_idx_on_face_dim2;
542 ierr = PetscRandomGetValueReal(*rand_logic_i_ptr, xi_metric_logic_out); CHKERRQ(ierr);
543 ierr = PetscRandomGetValueReal(*rand_logic_j_ptr, eta_metric_logic_out); CHKERRQ(ierr);
546 *ck_metric_lnode_out = zs_gnode_rank + (last_global_cell_idx_k - info->zs);
547 *zta_metric_logic_out = 1.0 - 1.0e-6;
548 ierr = PetscRandomGetValueReal(*rand_logic_i_ptr, &r_val_i_sel); CHKERRQ(ierr);
549 local_cell_idx_on_face_dim1 = (PetscInt)(r_val_i_sel * num_owned_cells_on_rank_i);
550 local_cell_idx_on_face_dim1 = PetscMin(PetscMax(0, local_cell_idx_on_face_dim1), num_owned_cells_on_rank_i - 1);
551 *ci_metric_lnode_out = xs_gnode_rank + local_cell_idx_on_face_dim1;
552 ierr = PetscRandomGetValueReal(*rand_logic_j_ptr, &r_val_j_sel); CHKERRQ(ierr);
553 local_cell_idx_on_face_dim2 = (PetscInt)(r_val_j_sel * num_owned_cells_on_rank_j);
554 local_cell_idx_on_face_dim2 = PetscMin(PetscMax(0, local_cell_idx_on_face_dim2), num_owned_cells_on_rank_j - 1);
555 *cj_metric_lnode_out = ys_gnode_rank + local_cell_idx_on_face_dim2;
556 ierr = PetscRandomGetValueReal(*rand_logic_i_ptr, xi_metric_logic_out); CHKERRQ(ierr);
557 ierr = PetscRandomGetValueReal(*rand_logic_j_ptr, eta_metric_logic_out); CHKERRQ(ierr);
560 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG,
"GetRandomCellAndLogicOnInletFace: Invalid user->identifiedInletBCFace %d. \n", user->
identifiedInletBCFace);
563 PetscReal eps = 1.0e-7;
565 *eta_metric_logic_out = PetscMin(PetscMax(0.0, *eta_metric_logic_out), 1.0 - eps);
566 *zta_metric_logic_out = PetscMin(PetscMax(0.0, *zta_metric_logic_out), 1.0 - eps);
568 *xi_metric_logic_out = PetscMin(PetscMax(0.0, *xi_metric_logic_out), 1.0 - eps);
569 *zta_metric_logic_out = PetscMin(PetscMax(0.0, *zta_metric_logic_out), 1.0 - eps);
571 *xi_metric_logic_out = PetscMin(PetscMax(0.0, *xi_metric_logic_out), 1.0 - eps);
572 *eta_metric_logic_out = PetscMin(PetscMax(0.0, *eta_metric_logic_out), 1.0 - eps);
576 rank_for_logging, *ci_metric_lnode_out, *cj_metric_lnode_out, *ck_metric_lnode_out,
577 *xi_metric_logic_out, *eta_metric_logic_out, *zta_metric_logic_out);
581 PetscFunctionReturn(0);
1020 PetscErrorCode ierr;
1021 PetscFunctionBeginUser;
1030 PetscReal local_inflow_pre = 0.0;
1031 PetscReal local_inflow_post = 0.0;
1032 PetscReal global_inflow_pre = 0.0;
1033 PetscReal global_inflow_post = 0.0;
1034 PetscInt num_handlers[3] = {0,0,0};
1039 for (
int i = 0; i < 6; i++) {
1042 if (!handler->
PreStep)
continue;
1048 .global_inflow_sum = NULL,
1049 .global_outflow_sum = NULL,
1055 ierr = handler->
PreStep(handler, &ctx, &local_inflow_pre, NULL); CHKERRQ(ierr);
1059 if (local_inflow_pre != 0.0) {
1060 ierr = MPI_Allreduce(&local_inflow_pre, &global_inflow_pre, 1, MPIU_REAL,
1061 MPI_SUM, PETSC_COMM_WORLD); CHKERRQ(ierr);
1066 for (
int i = 0; i < 6; i++) {
1069 if(!handler->
Apply)
continue;
1076 .global_inflow_sum = NULL,
1077 .global_outflow_sum = NULL,
1083 ierr = handler->
Apply(handler, &ctx); CHKERRQ(ierr);
1087 for (
int i = 0; i < 6; i++) {
1097 .global_inflow_sum = NULL,
1098 .global_outflow_sum = NULL,
1104 ierr = handler->
PostStep(handler, &ctx, &local_inflow_post, NULL); CHKERRQ(ierr);
1108 ierr = MPI_Allreduce(&local_inflow_post, &global_inflow_post, 1, MPIU_REAL,
1109 MPI_SUM, PETSC_COMM_WORLD); CHKERRQ(ierr);
1115 " (INLETS): %d Prestep(s), %d Application(s), %d Poststep(s), FluxInSum = %.6e\n",
1116 num_handlers[0],num_handlers[1],num_handlers[2], global_inflow_post);
1122 PetscReal local_farfield_in_pre = 0.0;
1123 PetscReal local_farfield_out_pre = 0.0;
1124 PetscReal local_farfield_in_post = 0.0;
1125 PetscReal local_farfield_out_post = 0.0;
1126 PetscReal global_farfield_in_pre = 0.0;
1127 PetscReal global_farfield_out_pre = 0.0;
1128 PetscReal global_farfield_in_post = 0.0;
1129 PetscReal global_farfield_out_post = 0.0;
1130 memset(num_handlers,0,
sizeof(num_handlers));
1135 for (
int i = 0; i < 6; i++) {
1138 if (!handler->
PreStep)
continue;
1145 .global_outflow_sum = NULL,
1151 ierr = handler->
PreStep(handler, &ctx, &local_farfield_in_pre, &local_farfield_out_pre);
1156 if (local_farfield_in_pre != 0.0 || local_farfield_out_pre != 0.0) {
1157 ierr = MPI_Allreduce(&local_farfield_in_pre, &global_farfield_in_pre, 1, MPIU_REAL,
1158 MPI_SUM, PETSC_COMM_WORLD); CHKERRQ(ierr);
1159 ierr = MPI_Allreduce(&local_farfield_out_pre, &global_farfield_out_pre, 1, MPIU_REAL,
1160 MPI_SUM, PETSC_COMM_WORLD); CHKERRQ(ierr);
1163 " Farfield pre-analysis: In=%.6e, Out=%.6e\n",
1164 global_farfield_in_pre, global_farfield_out_pre);
1168 for (
int i = 0; i < 6; i++) {
1171 if(!handler->
Apply)
continue;
1179 .global_outflow_sum = NULL,
1185 ierr = handler->
Apply(handler, &ctx); CHKERRQ(ierr);
1189 for (
int i = 0; i < 6; i++) {
1200 .global_outflow_sum = NULL,
1206 ierr = handler->
PostStep(handler, &ctx, &local_farfield_in_post, &local_farfield_out_post);
1211 if (num_handlers > 0) {
1212 ierr = MPI_Allreduce(&local_farfield_in_post, &global_farfield_in_post, 1, MPIU_REAL,
1213 MPI_SUM, PETSC_COMM_WORLD); CHKERRQ(ierr);
1214 ierr = MPI_Allreduce(&local_farfield_out_post, &global_farfield_out_post, 1, MPIU_REAL,
1215 MPI_SUM, PETSC_COMM_WORLD); CHKERRQ(ierr);
1222 " (FARFIELD): %d Prestep(s), %d Application(s), %d Poststep(s) , InFlux=%.6e, OutFlux=%.6e\n",
1223 num_handlers[0],num_handlers[1],num_handlers[2], global_farfield_in_post, global_farfield_out_post);
1235 memset(num_handlers,0,
sizeof(num_handlers));
1240 for (
int i = 0; i < 6; i++) {
1243 if (!handler->
PreStep)
continue;
1250 .global_outflow_sum = NULL,
1256 ierr = handler->
PreStep(handler, &ctx, NULL, NULL); CHKERRQ(ierr);
1262 for (
int i = 0; i < 6; i++) {
1265 if(!handler->
Apply)
continue;
1273 .global_outflow_sum = NULL,
1279 ierr = handler->
Apply(handler, &ctx); CHKERRQ(ierr);
1283 for (
int i = 0; i < 6; i++) {
1294 .global_outflow_sum = NULL,
1300 ierr = handler->
PostStep(handler, &ctx, NULL, NULL); CHKERRQ(ierr);
1306 num_handlers[0],num_handlers[1],num_handlers[2]);
1313 PetscReal local_outflow_pre = 0.0;
1314 PetscReal local_outflow_post = 0.0;
1315 PetscReal global_outflow_pre = 0.0;
1316 PetscReal global_outflow_post = 0.0;
1317 memset(num_handlers,0,
sizeof(num_handlers));
1322 for (
int i = 0; i < 6; i++) {
1325 if (!handler->
PreStep)
continue;
1332 .global_outflow_sum = NULL,
1338 ierr = handler->
PreStep(handler, &ctx, NULL, &local_outflow_pre); CHKERRQ(ierr);
1342 ierr = MPI_Allreduce(&local_outflow_pre, &global_outflow_pre, 1, MPIU_REAL,
1343 MPI_SUM, PETSC_COMM_WORLD); CHKERRQ(ierr);
1349 " Uncorrected outflow: %.6e, Total inflow: %.6e (Inlet: %.6e + Farfield: %.6e)\n",
1354 for (
int i = 0; i < 6; i++) {
1357 if(!handler->
Apply)
continue;
1365 .global_outflow_sum = &global_outflow_pre,
1371 ierr = handler->
Apply(handler, &ctx); CHKERRQ(ierr);
1375 for (
int i = 0; i < 6; i++) {
1386 .global_outflow_sum = &global_outflow_pre,
1392 ierr = handler->
PostStep(handler, &ctx, NULL, &local_outflow_post); CHKERRQ(ierr);
1396 ierr = MPI_Allreduce(&local_outflow_post, &global_outflow_post, 1, MPIU_REAL,
1397 MPI_SUM, PETSC_COMM_WORLD); CHKERRQ(ierr);
1404 PetscReal flux_error = PetscAbsReal(total_outflow - total_inflow);
1405 PetscReal relative_error = (total_inflow > 1e-16) ?
1406 flux_error / total_inflow : flux_error;
1409 " (OUTLETS): %d Prestep(s), %d Application(s), %d Poststep(s), FluxOutSum = %.6e\n",
1410 num_handlers[0],num_handlers[1],num_handlers[2], global_outflow_post);
1412 " Conservation: Total In=%.6e, Total Out=%.6e, Error=%.3e (%.2e)%%)\n",
1413 total_inflow, total_outflow, flux_error, relative_error * 100.0);
1415 if (relative_error > 1e-6) {
1417 " WARNING: Large mass conservation error (%.2e%%)!\n",
1418 relative_error * 100.0);
1425 PetscFunctionReturn(0);
2316 PetscErrorCode ierr;
2317 DM da = user->
da, fda = user->
fda;
2318 DMDALocalInfo info = user->
info;
2319 PetscInt xs = info.xs, xe = info.xs + info.xm;
2320 PetscInt ys = info.ys, ye = info.ys + info.ym;
2321 PetscInt zs = info.zs, ze = info.zs + info.zm;
2322 PetscInt mx = info.mx, my = info.my, mz = info.mz;
2327 PetscFunctionBeginUser;
2329 ierr = DMDAVecGetArray(fda, user->
Ucat, &ucat); CHKERRQ(ierr);
2330 ierr = DMDAVecGetArray(da, user->
P, &p); CHKERRQ(ierr);
2338 for (PetscInt j = ys; j < ye; j++) {
2339 p[zs][j][xs] = 0.5 * (p[zs+1][j][xs] + p[zs][j][xs+1]);
2340 ucat[zs][j][xs].
x = 0.5 * (ucat[zs+1][j][xs].
x + ucat[zs][j][xs+1].
x);
2341 ucat[zs][j][xs].
y = 0.5 * (ucat[zs+1][j][xs].
y + ucat[zs][j][xs+1].
y);
2342 ucat[zs][j][xs].
z = 0.5 * (ucat[zs+1][j][xs].
z + ucat[zs][j][xs+1].
z);
2346 for (PetscInt j = ys; j < ye; j++) {
2347 p[zs][j][mx-1] = 0.5 * (p[zs+1][j][mx-1] + p[zs][j][mx-2]);
2348 ucat[zs][j][mx-1].
x = 0.5 * (ucat[zs+1][j][mx-1].
x + ucat[zs][j][mx-2].
x);
2349 ucat[zs][j][mx-1].
y = 0.5 * (ucat[zs+1][j][mx-1].
y + ucat[zs][j][mx-2].
y);
2350 ucat[zs][j][mx-1].
z = 0.5 * (ucat[zs+1][j][mx-1].
z + ucat[zs][j][mx-2].
z);
2354 for (PetscInt i = xs; i < xe; i++) {
2355 p[zs][ys][i] = 0.5 * (p[zs+1][ys][i] + p[zs][ys+1][i]);
2356 ucat[zs][ys][i].
x = 0.5 * (ucat[zs+1][ys][i].
x + ucat[zs][ys+1][i].
x);
2357 ucat[zs][ys][i].
y = 0.5 * (ucat[zs+1][ys][i].
y + ucat[zs][ys+1][i].
y);
2358 ucat[zs][ys][i].
z = 0.5 * (ucat[zs+1][ys][i].
z + ucat[zs][ys+1][i].
z);
2362 for (PetscInt i = xs; i < xe; i++) {
2363 p[zs][my-1][i] = 0.5 * (p[zs+1][my-1][i] + p[zs][my-2][i]);
2364 ucat[zs][my-1][i].
x = 0.5 * (ucat[zs+1][my-1][i].
x + ucat[zs][my-2][i].
x);
2365 ucat[zs][my-1][i].
y = 0.5 * (ucat[zs+1][my-1][i].
y + ucat[zs][my-2][i].
y);
2366 ucat[zs][my-1][i].
z = 0.5 * (ucat[zs+1][my-1][i].
z + ucat[zs][my-2][i].
z);
2374 for (PetscInt j = ys; j < ye; j++) {
2375 p[mz-1][j][xs] = 0.5 * (p[mz-2][j][xs] + p[mz-1][j][xs+1]);
2376 ucat[mz-1][j][xs].
x = 0.5 * (ucat[mz-2][j][xs].
x + ucat[mz-1][j][xs+1].
x);
2377 ucat[mz-1][j][xs].
y = 0.5 * (ucat[mz-2][j][xs].
y + ucat[mz-1][j][xs+1].
y);
2378 ucat[mz-1][j][xs].
z = 0.5 * (ucat[mz-2][j][xs].
z + ucat[mz-1][j][xs+1].
z);
2382 for (PetscInt j = ys; j < ye; j++) {
2383 p[mz-1][j][mx-1] = 0.5 * (p[mz-2][j][mx-1] + p[mz-1][j][mx-2]);
2384 ucat[mz-1][j][mx-1].
x = 0.5 * (ucat[mz-2][j][mx-1].
x + ucat[mz-1][j][mx-2].
x);
2385 ucat[mz-1][j][mx-1].
y = 0.5 * (ucat[mz-2][j][mx-1].
y + ucat[mz-1][j][mx-2].
y);
2386 ucat[mz-1][j][mx-1].
z = 0.5 * (ucat[mz-2][j][mx-1].
z + ucat[mz-1][j][mx-2].
z);
2390 for (PetscInt i = xs; i < xe; i++) {
2391 p[mz-1][ys][i] = 0.5 * (p[mz-2][ys][i] + p[mz-1][ys+1][i]);
2392 ucat[mz-1][ys][i].
x = 0.5 * (ucat[mz-2][ys][i].
x + ucat[mz-1][ys+1][i].
x);
2393 ucat[mz-1][ys][i].
y = 0.5 * (ucat[mz-2][ys][i].
y + ucat[mz-1][ys+1][i].
y);
2394 ucat[mz-1][ys][i].
z = 0.5 * (ucat[mz-2][ys][i].
z + ucat[mz-1][ys+1][i].
z);
2398 for (PetscInt i = xs; i < xe; i++) {
2399 p[mz-1][my-1][i] = 0.5 * (p[mz-2][my-1][i] + p[mz-1][my-2][i]);
2400 ucat[mz-1][my-1][i].
x = 0.5 * (ucat[mz-2][my-1][i].
x + ucat[mz-1][my-2][i].
x);
2401 ucat[mz-1][my-1][i].
y = 0.5 * (ucat[mz-2][my-1][i].
y + ucat[mz-1][my-2][i].
y);
2402 ucat[mz-1][my-1][i].
z = 0.5 * (ucat[mz-2][my-1][i].
z + ucat[mz-1][my-2][i].
z);
2410 for (PetscInt k = zs; k < ze; k++) {
2411 p[k][ys][xs] = 0.5 * (p[k][ys+1][xs] + p[k][ys][xs+1]);
2412 ucat[k][ys][xs].
x = 0.5 * (ucat[k][ys+1][xs].
x + ucat[k][ys][xs+1].
x);
2413 ucat[k][ys][xs].
y = 0.5 * (ucat[k][ys+1][xs].
y + ucat[k][ys][xs+1].
y);
2414 ucat[k][ys][xs].
z = 0.5 * (ucat[k][ys+1][xs].
z + ucat[k][ys][xs+1].
z);
2418 for (PetscInt k = zs; k < ze; k++) {
2419 p[k][ys][mx-1] = 0.5 * (p[k][ys+1][mx-1] + p[k][ys][mx-2]);
2420 ucat[k][ys][mx-1].
x = 0.5 * (ucat[k][ys+1][mx-1].
x + ucat[k][ys][mx-2].
x);
2421 ucat[k][ys][mx-1].
y = 0.5 * (ucat[k][ys+1][mx-1].
y + ucat[k][ys][mx-2].
y);
2422 ucat[k][ys][mx-1].
z = 0.5 * (ucat[k][ys+1][mx-1].
z + ucat[k][ys][mx-2].
z);
2429 for (PetscInt k = zs; k < ze; k++) {
2430 p[k][my-1][xs] = 0.5 * (p[k][my-2][xs] + p[k][my-1][xs+1]);
2431 ucat[k][my-1][xs].
x = 0.5 * (ucat[k][my-2][xs].
x + ucat[k][my-1][xs+1].
x);
2432 ucat[k][my-1][xs].
y = 0.5 * (ucat[k][my-2][xs].
y + ucat[k][my-1][xs+1].
y);
2433 ucat[k][my-1][xs].
z = 0.5 * (ucat[k][my-2][xs].
z + ucat[k][my-1][xs+1].
z);
2437 for (PetscInt k = zs; k < ze; k++) {
2438 p[k][my-1][mx-1] = 0.5 * (p[k][my-2][mx-1] + p[k][my-1][mx-2]);
2439 ucat[k][my-1][mx-1].
x = 0.5 * (ucat[k][my-2][mx-1].
x + ucat[k][my-1][mx-2].
x);
2440 ucat[k][my-1][mx-1].
y = 0.5 * (ucat[k][my-2][mx-1].
y + ucat[k][my-1][mx-2].
y);
2441 ucat[k][my-1][mx-1].
z = 0.5 * (ucat[k][my-2][mx-1].
z + ucat[k][my-1][mx-2].
z);
2446 ierr = DMDAVecRestoreArray(fda, user->
Ucat, &ucat); CHKERRQ(ierr);
2447 ierr = DMDAVecRestoreArray(da, user->
P, &p); CHKERRQ(ierr);
2449 PetscFunctionReturn(0);
2460 PetscErrorCode ierr;
2462 DMDALocalInfo *info = &user->
info;
2464 PetscFunctionBeginUser;
2470 PetscFunctionReturn(0);
2478 Cmpnts ***velocity_cartesian;
2479 Cmpnts ***velocity_contravariant;
2480 Cmpnts ***velocity_boundary;
2481 Cmpnts ***csi, ***eta, ***zet;
2482 PetscReal ***node_vertex_flag;
2483 PetscReal ***cell_jacobian;
2484 PetscReal ***friction_velocity;
2486 ierr = DMDAVecGetArray(user->
fda, user->
Ucat, &velocity_cartesian); CHKERRQ(ierr);
2487 ierr = DMDAVecGetArray(user->
fda, user->
Ucont, &velocity_contravariant); CHKERRQ(ierr);
2488 ierr = DMDAVecGetArray(user->
fda, user->
Bcs.
Ubcs, &velocity_boundary); CHKERRQ(ierr);
2489 ierr = DMDAVecGetArrayRead(user->
fda, user->
lCsi, (
const Cmpnts***)&csi); CHKERRQ(ierr);
2490 ierr = DMDAVecGetArrayRead(user->
fda, user->
lEta, (
const Cmpnts***)&eta); CHKERRQ(ierr);
2491 ierr = DMDAVecGetArrayRead(user->
fda, user->
lZet, (
const Cmpnts***)&zet); CHKERRQ(ierr);
2492 ierr = DMDAVecGetArrayRead(user->
da, user->
lNvert, (
const PetscReal***)&node_vertex_flag); CHKERRQ(ierr);
2493 ierr = DMDAVecGetArrayRead(user->
da, user->
lAj, (
const PetscReal***)&cell_jacobian); CHKERRQ(ierr);
2499 PetscInt grid_start_i = info->xs, grid_end_i = info->xs + info->xm;
2500 PetscInt grid_start_j = info->ys, grid_end_j = info->ys + info->ym;
2501 PetscInt grid_start_k = info->zs, grid_end_k = info->zs + info->zm;
2502 PetscInt grid_size_i = info->mx, grid_size_j = info->my, grid_size_k = info->mz;
2505 PetscInt loop_start_i = grid_start_i, loop_end_i = grid_end_i;
2506 PetscInt loop_start_j = grid_start_j, loop_end_j = grid_end_j;
2507 PetscInt loop_start_k = grid_start_k, loop_end_k = grid_end_k;
2509 if (grid_start_i == 0) loop_start_i = grid_start_i + 1;
2510 if (grid_end_i == grid_size_i) loop_end_i = grid_end_i - 1;
2511 if (grid_start_j == 0) loop_start_j = grid_start_j + 1;
2512 if (grid_end_j == grid_size_j) loop_end_j = grid_end_j - 1;
2513 if (grid_start_k == 0) loop_start_k = grid_start_k + 1;
2514 if (grid_end_k == grid_size_k) loop_end_k = grid_end_k - 1;
2522 for (
int face_index = 0; face_index < 6; face_index++) {
2532 PetscBool rank_owns_this_face;
2534 current_face_id, &rank_owns_this_face); CHKERRQ(ierr);
2536 if (!rank_owns_this_face) {
2546 switch(current_face_id) {
2552 if (grid_start_i == 0) {
2553 const PetscInt ghost_cell_index = grid_start_i;
2554 const PetscInt first_interior_cell = grid_start_i + 1;
2555 const PetscInt second_interior_cell = grid_start_i + 2;
2557 for (PetscInt k = loop_start_k; k < loop_end_k; k++) {
2558 for (PetscInt j = loop_start_j; j < loop_end_j; j++) {
2561 if (node_vertex_flag[k][j][first_interior_cell] < 0.1) {
2564 PetscReal face_area = sqrt(
2565 csi[k][j][ghost_cell_index].x * csi[k][j][ghost_cell_index].x +
2566 csi[k][j][ghost_cell_index].y * csi[k][j][ghost_cell_index].y +
2567 csi[k][j][ghost_cell_index].z * csi[k][j][ghost_cell_index].z
2573 PetscReal distance_to_first_cell = 0.5 / cell_jacobian[k][j][first_interior_cell] / face_area;
2574 PetscReal distance_to_second_cell = 2.0 * distance_to_first_cell +
2575 0.5 / cell_jacobian[k][j][second_interior_cell] / face_area;
2578 PetscReal wall_normal[3];
2579 wall_normal[0] = csi[k][j][ghost_cell_index].
x / face_area;
2580 wall_normal[1] = csi[k][j][ghost_cell_index].
y / face_area;
2581 wall_normal[2] = csi[k][j][ghost_cell_index].
z / face_area;
2585 Cmpnts reference_velocity;
2587 wall_velocity.
x = wall_velocity.
y = wall_velocity.
z = 0.0;
2588 reference_velocity = velocity_cartesian[k][j][second_interior_cell];
2591 noslip(user, distance_to_second_cell, distance_to_first_cell,
2592 wall_velocity, reference_velocity,
2593 &velocity_cartesian[k][j][first_interior_cell],
2594 wall_normal[0], wall_normal[1], wall_normal[2]);
2598 distance_to_second_cell, distance_to_first_cell,
2599 wall_velocity, reference_velocity,
2600 &velocity_cartesian[k][j][first_interior_cell],
2601 &friction_velocity[k][j][first_interior_cell],
2602 wall_normal[0], wall_normal[1], wall_normal[2]);
2605 velocity_boundary[k][j][ghost_cell_index].
x = 0.0;
2606 velocity_boundary[k][j][ghost_cell_index].
y = 0.0;
2607 velocity_boundary[k][j][ghost_cell_index].
z = 0.0;
2608 velocity_contravariant[k][j][ghost_cell_index].
x = 0.0;
2619 if (grid_end_i == grid_size_i) {
2620 const PetscInt ghost_cell_index = grid_end_i - 1;
2621 const PetscInt first_interior_cell = grid_end_i - 2;
2622 const PetscInt second_interior_cell = grid_end_i - 3;
2624 for (PetscInt k = loop_start_k; k < loop_end_k; k++) {
2625 for (PetscInt j = loop_start_j; j < loop_end_j; j++) {
2627 if (node_vertex_flag[k][j][first_interior_cell] < 0.1) {
2629 PetscReal face_area = sqrt(
2630 csi[k][j][first_interior_cell].x * csi[k][j][first_interior_cell].x +
2631 csi[k][j][first_interior_cell].y * csi[k][j][first_interior_cell].y +
2632 csi[k][j][first_interior_cell].z * csi[k][j][first_interior_cell].z
2635 PetscReal distance_to_first_cell = 0.5 / cell_jacobian[k][j][first_interior_cell] / face_area;
2636 PetscReal distance_to_second_cell = 2.0 * distance_to_first_cell +
2637 0.5 / cell_jacobian[k][j][second_interior_cell] / face_area;
2640 PetscReal wall_normal[3];
2641 wall_normal[0] = -csi[k][j][first_interior_cell].
x / face_area;
2642 wall_normal[1] = -csi[k][j][first_interior_cell].
y / face_area;
2643 wall_normal[2] = -csi[k][j][first_interior_cell].
z / face_area;
2645 Cmpnts wall_velocity, reference_velocity;
2646 wall_velocity.
x = wall_velocity.
y = wall_velocity.
z = 0.0;
2647 reference_velocity = velocity_cartesian[k][j][second_interior_cell];
2649 noslip(user, distance_to_second_cell, distance_to_first_cell,
2650 wall_velocity, reference_velocity,
2651 &velocity_cartesian[k][j][first_interior_cell],
2652 wall_normal[0], wall_normal[1], wall_normal[2]);
2655 distance_to_second_cell, distance_to_first_cell,
2656 wall_velocity, reference_velocity,
2657 &velocity_cartesian[k][j][first_interior_cell],
2658 &friction_velocity[k][j][first_interior_cell],
2659 wall_normal[0], wall_normal[1], wall_normal[2]);
2661 velocity_boundary[k][j][ghost_cell_index].
x = 0.0;
2662 velocity_boundary[k][j][ghost_cell_index].
y = 0.0;
2663 velocity_boundary[k][j][ghost_cell_index].
z = 0.0;
2664 velocity_contravariant[k][j][first_interior_cell].
x = 0.0;
2675 if (grid_start_j == 0) {
2676 const PetscInt ghost_cell_index = grid_start_j;
2677 const PetscInt first_interior_cell = grid_start_j + 1;
2678 const PetscInt second_interior_cell = grid_start_j + 2;
2680 for (PetscInt k = loop_start_k; k < loop_end_k; k++) {
2681 for (PetscInt i = loop_start_i; i < loop_end_i; i++) {
2683 if (node_vertex_flag[k][first_interior_cell][i] < 0.1) {
2685 PetscReal face_area = sqrt(
2686 eta[k][ghost_cell_index][i].x * eta[k][ghost_cell_index][i].x +
2687 eta[k][ghost_cell_index][i].y * eta[k][ghost_cell_index][i].y +
2688 eta[k][ghost_cell_index][i].z * eta[k][ghost_cell_index][i].z
2691 PetscReal distance_to_first_cell = 0.5 / cell_jacobian[k][first_interior_cell][i] / face_area;
2692 PetscReal distance_to_second_cell = 2.0 * distance_to_first_cell +
2693 0.5 / cell_jacobian[k][second_interior_cell][i] / face_area;
2695 PetscReal wall_normal[3];
2696 wall_normal[0] = eta[k][ghost_cell_index][i].
x / face_area;
2697 wall_normal[1] = eta[k][ghost_cell_index][i].
y / face_area;
2698 wall_normal[2] = eta[k][ghost_cell_index][i].
z / face_area;
2700 Cmpnts wall_velocity, reference_velocity;
2701 wall_velocity.
x = wall_velocity.
y = wall_velocity.
z = 0.0;
2702 reference_velocity = velocity_cartesian[k][second_interior_cell][i];
2704 noslip(user, distance_to_second_cell, distance_to_first_cell,
2705 wall_velocity, reference_velocity,
2706 &velocity_cartesian[k][first_interior_cell][i],
2707 wall_normal[0], wall_normal[1], wall_normal[2]);
2710 distance_to_second_cell, distance_to_first_cell,
2711 wall_velocity, reference_velocity,
2712 &velocity_cartesian[k][first_interior_cell][i],
2713 &friction_velocity[k][first_interior_cell][i],
2714 wall_normal[0], wall_normal[1], wall_normal[2]);
2716 velocity_boundary[k][ghost_cell_index][i].
x = 0.0;
2717 velocity_boundary[k][ghost_cell_index][i].
y = 0.0;
2718 velocity_boundary[k][ghost_cell_index][i].
z = 0.0;
2719 velocity_contravariant[k][ghost_cell_index][i].
y = 0.0;
2730 if (grid_end_j == grid_size_j) {
2731 const PetscInt ghost_cell_index = grid_end_j - 1;
2732 const PetscInt first_interior_cell = grid_end_j - 2;
2733 const PetscInt second_interior_cell = grid_end_j - 3;
2735 for (PetscInt k = loop_start_k; k < loop_end_k; k++) {
2736 for (PetscInt i = loop_start_i; i < loop_end_i; i++) {
2738 if (node_vertex_flag[k][first_interior_cell][i] < 0.1) {
2740 PetscReal face_area = sqrt(
2741 eta[k][first_interior_cell][i].x * eta[k][first_interior_cell][i].x +
2742 eta[k][first_interior_cell][i].y * eta[k][first_interior_cell][i].y +
2743 eta[k][first_interior_cell][i].z * eta[k][first_interior_cell][i].z
2746 PetscReal distance_to_first_cell = 0.5 / cell_jacobian[k][first_interior_cell][i] / face_area;
2747 PetscReal distance_to_second_cell = 2.0 * distance_to_first_cell +
2748 0.5 / cell_jacobian[k][second_interior_cell][i] / face_area;
2750 PetscReal wall_normal[3];
2751 wall_normal[0] = -eta[k][first_interior_cell][i].
x / face_area;
2752 wall_normal[1] = -eta[k][first_interior_cell][i].
y / face_area;
2753 wall_normal[2] = -eta[k][first_interior_cell][i].
z / face_area;
2755 Cmpnts wall_velocity, reference_velocity;
2756 wall_velocity.
x = wall_velocity.
y = wall_velocity.
z = 0.0;
2757 reference_velocity = velocity_cartesian[k][second_interior_cell][i];
2759 noslip(user, distance_to_second_cell, distance_to_first_cell,
2760 wall_velocity, reference_velocity,
2761 &velocity_cartesian[k][first_interior_cell][i],
2762 wall_normal[0], wall_normal[1], wall_normal[2]);
2765 distance_to_second_cell, distance_to_first_cell,
2766 wall_velocity, reference_velocity,
2767 &velocity_cartesian[k][first_interior_cell][i],
2768 &friction_velocity[k][first_interior_cell][i],
2769 wall_normal[0], wall_normal[1], wall_normal[2]);
2771 velocity_boundary[k][ghost_cell_index][i].
x = 0.0;
2772 velocity_boundary[k][ghost_cell_index][i].
y = 0.0;
2773 velocity_boundary[k][ghost_cell_index][i].
z = 0.0;
2774 velocity_contravariant[k][first_interior_cell][i].
y = 0.0;
2785 if (grid_start_k == 0) {
2786 const PetscInt ghost_cell_index = grid_start_k;
2787 const PetscInt first_interior_cell = grid_start_k + 1;
2788 const PetscInt second_interior_cell = grid_start_k + 2;
2790 for (PetscInt j = loop_start_j; j < loop_end_j; j++) {
2791 for (PetscInt i = loop_start_i; i < loop_end_i; i++) {
2793 if (node_vertex_flag[first_interior_cell][j][i] < 0.1) {
2795 PetscReal face_area = sqrt(
2796 zet[ghost_cell_index][j][i].x * zet[ghost_cell_index][j][i].x +
2797 zet[ghost_cell_index][j][i].y * zet[ghost_cell_index][j][i].y +
2798 zet[ghost_cell_index][j][i].z * zet[ghost_cell_index][j][i].z
2801 PetscReal distance_to_first_cell = 0.5 / cell_jacobian[first_interior_cell][j][i] / face_area;
2802 PetscReal distance_to_second_cell = 2.0 * distance_to_first_cell +
2803 0.5 / cell_jacobian[second_interior_cell][j][i] / face_area;
2805 PetscReal wall_normal[3];
2806 wall_normal[0] = zet[ghost_cell_index][j][i].
x / face_area;
2807 wall_normal[1] = zet[ghost_cell_index][j][i].
y / face_area;
2808 wall_normal[2] = zet[ghost_cell_index][j][i].
z / face_area;
2810 Cmpnts wall_velocity, reference_velocity;
2811 wall_velocity.
x = wall_velocity.
y = wall_velocity.
z = 0.0;
2812 reference_velocity = velocity_cartesian[second_interior_cell][j][i];
2814 noslip(user, distance_to_second_cell, distance_to_first_cell,
2815 wall_velocity, reference_velocity,
2816 &velocity_cartesian[first_interior_cell][j][i],
2817 wall_normal[0], wall_normal[1], wall_normal[2]);
2820 distance_to_second_cell, distance_to_first_cell,
2821 wall_velocity, reference_velocity,
2822 &velocity_cartesian[first_interior_cell][j][i],
2823 &friction_velocity[first_interior_cell][j][i],
2824 wall_normal[0], wall_normal[1], wall_normal[2]);
2826 velocity_boundary[ghost_cell_index][j][i].
x = 0.0;
2827 velocity_boundary[ghost_cell_index][j][i].
y = 0.0;
2828 velocity_boundary[ghost_cell_index][j][i].
z = 0.0;
2829 velocity_contravariant[ghost_cell_index][j][i].
z = 0.0;
2840 if (grid_end_k == grid_size_k) {
2841 const PetscInt ghost_cell_index = grid_end_k - 1;
2842 const PetscInt first_interior_cell = grid_end_k - 2;
2843 const PetscInt second_interior_cell = grid_end_k - 3;
2845 for (PetscInt j = loop_start_j; j < loop_end_j; j++) {
2846 for (PetscInt i = loop_start_i; i < loop_end_i; i++) {
2848 if (node_vertex_flag[first_interior_cell][j][i] < 0.1) {
2850 PetscReal face_area = sqrt(
2851 zet[first_interior_cell][j][i].x * zet[first_interior_cell][j][i].x +
2852 zet[first_interior_cell][j][i].y * zet[first_interior_cell][j][i].y +
2853 zet[first_interior_cell][j][i].z * zet[first_interior_cell][j][i].z
2856 PetscReal distance_to_first_cell = 0.5 / cell_jacobian[first_interior_cell][j][i] / face_area;
2857 PetscReal distance_to_second_cell = 2.0 * distance_to_first_cell +
2858 0.5 / cell_jacobian[second_interior_cell][j][i] / face_area;
2860 PetscReal wall_normal[3];
2861 wall_normal[0] = -zet[first_interior_cell][j][i].
x / face_area;
2862 wall_normal[1] = -zet[first_interior_cell][j][i].
y / face_area;
2863 wall_normal[2] = -zet[first_interior_cell][j][i].
z / face_area;
2865 Cmpnts wall_velocity, reference_velocity;
2866 wall_velocity.
x = wall_velocity.
y = wall_velocity.
z = 0.0;
2867 reference_velocity = velocity_cartesian[second_interior_cell][j][i];
2869 noslip(user, distance_to_second_cell, distance_to_first_cell,
2870 wall_velocity, reference_velocity,
2871 &velocity_cartesian[first_interior_cell][j][i],
2872 wall_normal[0], wall_normal[1], wall_normal[2]);
2875 distance_to_second_cell, distance_to_first_cell,
2876 wall_velocity, reference_velocity,
2877 &velocity_cartesian[first_interior_cell][j][i],
2878 &friction_velocity[first_interior_cell][j][i],
2879 wall_normal[0], wall_normal[1], wall_normal[2]);
2881 velocity_boundary[ghost_cell_index][j][i].
x = 0.0;
2882 velocity_boundary[ghost_cell_index][j][i].
y = 0.0;
2883 velocity_boundary[ghost_cell_index][j][i].
z = 0.0;
2884 velocity_contravariant[first_interior_cell][j][i].
z = 0.0;
2896 ierr = DMDAVecRestoreArray(user->
fda, user->
Ucat, &velocity_cartesian); CHKERRQ(ierr);
2897 ierr = DMDAVecRestoreArray(user->
fda, user->
Ucont, &velocity_contravariant); CHKERRQ(ierr);
2898 ierr = DMDAVecRestoreArray(user->
fda, user->
Bcs.
Ubcs, &velocity_boundary); CHKERRQ(ierr);
2899 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lCsi, (
const Cmpnts***)&csi); CHKERRQ(ierr);
2900 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lEta, (
const Cmpnts***)&eta); CHKERRQ(ierr);
2901 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lZet, (
const Cmpnts***)&zet); CHKERRQ(ierr);
2902 ierr = DMDAVecRestoreArrayRead(user->
da, user->
lNvert, (
const PetscReal***)&node_vertex_flag); CHKERRQ(ierr);
2903 ierr = DMDAVecRestoreArrayRead(user->
da, user->
lAj, (
const PetscReal***)&cell_jacobian); CHKERRQ(ierr);
2904 ierr = DMDAVecRestoreArray(user->
da, user->
lFriction_Velocity, &friction_velocity); CHKERRQ(ierr);
2908 PetscFunctionReturn(0);