213 UserCtx *user,
const DMDALocalInfo *info,
214 PetscInt xs_gnode_rank, PetscInt ys_gnode_rank, PetscInt zs_gnode_rank,
215 PetscInt IM_cells_global, PetscInt JM_cells_global, PetscInt KM_cells_global,
216 PetscInt64 particle_global_id,
217 PetscInt *ci_metric_lnode_out, PetscInt *cj_metric_lnode_out, PetscInt *ck_metric_lnode_out,
218 PetscReal *xi_metric_logic_out, PetscReal *eta_metric_logic_out, PetscReal *zta_metric_logic_out,
219 PetscBool *placement_successful_out)
222 PetscReal global_logic_i = 0.0, global_logic_j = 0.0, global_logic_k = 0.0;
224 PetscMPIInt rank_for_logging;
226 PetscFunctionBeginUser;
227 ierr = MPI_Comm_rank(PETSC_COMM_WORLD, &rank_for_logging); CHKERRQ(ierr);
229 *placement_successful_out = PETSC_FALSE;
234 const PetscInt grid_layers = 2;
237 "[Rank %d] Placing particle %lld on face %s with grid_layers=%d in global domain (%d,%d,%d) cells.\n",
239 IM_cells_global, JM_cells_global, KM_cells_global);
247 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);
248 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);
251 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);
252 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);
255 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);
256 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);
258 default: SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG,
"Invalid identifiedInletBCFace specified: %d", user->
identifiedInletBCFace);
261 const PetscInt num_lines_total = 4 * grid_layers;
262 if (simCtx->
np < num_lines_total) {
263 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);
265 if (simCtx->
np > 0 && simCtx->
np % num_lines_total != 0) {
266 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);
270 if (simCtx->
np == 0) PetscFunctionReturn(0);
273 rank_for_logging, (
long long)simCtx->
np, num_lines_total, face_name);
275 const PetscInt points_per_line = PetscMax(1, simCtx->
np / num_lines_total);
276 PetscInt line_index = particle_global_id / points_per_line;
277 PetscInt point_index_on_line = particle_global_id % points_per_line;
278 line_index = PetscMin(line_index, num_lines_total - 1);
281 const PetscInt edge_group = line_index / grid_layers;
282 const PetscInt layer_index = line_index % grid_layers;
285 const PetscReal layer_spacing_norm_i = (IM_cells_global > 0) ? 1.0 / (PetscReal)IM_cells_global : 0.0;
286 const PetscReal layer_spacing_norm_j = (JM_cells_global > 0) ? 1.0 / (PetscReal)JM_cells_global : 0.0;
287 const PetscReal layer_spacing_norm_k = (KM_cells_global > 0) ? 1.0 / (PetscReal)KM_cells_global : 0.0;
290 const PetscReal min_layer_spacing = PetscMin(layer_spacing_norm_i, PetscMin(layer_spacing_norm_j, layer_spacing_norm_k));
291 const PetscReal epsilon = 0.5 * min_layer_spacing;
293 PetscReal variable_coord;
294 if (points_per_line <= 1) {
295 variable_coord = 0.5;
297 variable_coord = ((PetscReal)point_index_on_line + 0.5)/ (PetscReal)(points_per_line);
299 variable_coord = PetscMin(1.0 - epsilon, PetscMax(epsilon, variable_coord));
304 global_logic_i = 0.5 * layer_spacing_norm_i;
305 if (edge_group == 0) { global_logic_j = (PetscReal)layer_index * layer_spacing_norm_j + epsilon; global_logic_k = variable_coord; }
306 else if (edge_group == 1) { global_logic_j = 1.0 - ((PetscReal)layer_index * layer_spacing_norm_j) - epsilon; global_logic_k = variable_coord; }
307 else if (edge_group == 2) { global_logic_k = (PetscReal)layer_index * layer_spacing_norm_k + epsilon; global_logic_j = variable_coord; }
308 else { global_logic_k = 1.0 - ((PetscReal)layer_index * layer_spacing_norm_k) - epsilon; global_logic_j = variable_coord; }
311 global_logic_i = 1.0 - (0.5 * layer_spacing_norm_i);
312 if (edge_group == 0) { global_logic_j = (PetscReal)layer_index * layer_spacing_norm_j + epsilon; global_logic_k = variable_coord; }
313 else if (edge_group == 1) { global_logic_j = 1.0 - ((PetscReal)layer_index * layer_spacing_norm_j) - epsilon; global_logic_k = variable_coord; }
314 else if (edge_group == 2) { global_logic_k = (PetscReal)layer_index * layer_spacing_norm_k + epsilon; global_logic_j = variable_coord; }
315 else { global_logic_k = 1.0 - ((PetscReal)layer_index * layer_spacing_norm_k) - epsilon; global_logic_j = variable_coord; }
318 global_logic_j = 0.5 * layer_spacing_norm_j;
319 if (edge_group == 0) { global_logic_i = (PetscReal)layer_index * layer_spacing_norm_i + epsilon; global_logic_k = variable_coord; }
320 else if (edge_group == 1) { global_logic_i = 1.0 - ((PetscReal)layer_index * layer_spacing_norm_i) - epsilon; global_logic_k = variable_coord; }
321 else if (edge_group == 2) { global_logic_k = (PetscReal)layer_index * layer_spacing_norm_k + epsilon; global_logic_i = variable_coord; }
322 else { global_logic_k = 1.0 - ((PetscReal)layer_index * layer_spacing_norm_k) - epsilon; global_logic_i = variable_coord; }
325 global_logic_j = 1.0 - (0.5 * layer_spacing_norm_j);
326 if (edge_group == 0) { global_logic_i = (PetscReal)layer_index * layer_spacing_norm_i + epsilon; global_logic_k = variable_coord; }
327 else if (edge_group == 1) { global_logic_i = 1.0 - ((PetscReal)layer_index * layer_spacing_norm_i) - epsilon; global_logic_k = variable_coord; }
328 else if (edge_group == 2) { global_logic_k = (PetscReal)layer_index * layer_spacing_norm_k + epsilon; global_logic_i = variable_coord; }
329 else { global_logic_k = 1.0 - ((PetscReal)layer_index * layer_spacing_norm_k) - epsilon; global_logic_i = variable_coord; }
332 global_logic_k = 0.5 * layer_spacing_norm_k;
333 if (edge_group == 0) { global_logic_i = (PetscReal)layer_index * layer_spacing_norm_i + epsilon; global_logic_j = variable_coord; }
334 else if (edge_group == 1) { global_logic_i = 1.0 - ((PetscReal)layer_index * layer_spacing_norm_i) - epsilon; global_logic_j = variable_coord; }
335 else if (edge_group == 2) { global_logic_j = (PetscReal)layer_index * layer_spacing_norm_j + epsilon; global_logic_i = variable_coord; }
336 else { global_logic_j = 1.0 - ((PetscReal)layer_index * layer_spacing_norm_j) - epsilon; global_logic_i = variable_coord; }
339 global_logic_k = 1.0 - (0.5 * layer_spacing_norm_k);
340 if (edge_group == 0) { global_logic_i = (PetscReal)layer_index * layer_spacing_norm_i + epsilon; global_logic_j = variable_coord; }
341 else if (edge_group == 1) { global_logic_i = 1.0 - ((PetscReal)layer_index * layer_spacing_norm_i) - epsilon; global_logic_j = variable_coord; }
342 else if (edge_group == 2) { global_logic_j = (PetscReal)layer_index * layer_spacing_norm_j + epsilon; global_logic_i = variable_coord; }
343 else { global_logic_j = 1.0 - ((PetscReal)layer_index * layer_spacing_norm_j) - epsilon; global_logic_i = variable_coord; }
348 "[Rank %d] Particle %lld assigned to line %d (edge group %d, layer %d) with variable_coord=%.4f.\n"
349 " -> Global logical coords: (i,j,k) = (%.6f, %.6f, %.6f)\n",
350 rank_for_logging, (
long long)particle_global_id, line_index, edge_group, layer_index, variable_coord,
351 global_logic_i, global_logic_j, global_logic_k);
354 PetscReal global_cell_coord_i = global_logic_i * IM_cells_global;
355 PetscInt I_g = (PetscInt)global_cell_coord_i;
356 *xi_metric_logic_out = global_cell_coord_i - I_g;
358 PetscReal global_cell_coord_j = global_logic_j * JM_cells_global;
359 PetscInt J_g = (PetscInt)global_cell_coord_j;
360 *eta_metric_logic_out = global_cell_coord_j - J_g;
362 PetscReal global_cell_coord_k = global_logic_k * KM_cells_global;
363 PetscInt K_g = (PetscInt)global_cell_coord_k;
364 *zta_metric_logic_out = global_cell_coord_k - K_g;
367 if ((I_g >= info->xs && I_g < info->xs + info->xm) &&
368 (J_g >= info->ys && J_g < info->ys + info->ym) &&
369 (K_g >= info->zs && K_g < info->zs + info->zm))
372 *ci_metric_lnode_out = (I_g - info->xs) + xs_gnode_rank;
373 *cj_metric_lnode_out = (J_g - info->ys) + ys_gnode_rank;
374 *ck_metric_lnode_out = (K_g - info->zs) + zs_gnode_rank;
375 *placement_successful_out = PETSC_TRUE;
379 "[Rank %d] Particle %lld placement %s.\n",
380 rank_for_logging, (
long long)particle_global_id,
381 (*placement_successful_out ?
"SUCCESSFUL" :
"NOT ON THIS RANK"));
383 if(*placement_successful_out){
384 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",
385 *ci_metric_lnode_out, *cj_metric_lnode_out, *ck_metric_lnode_out,
386 *xi_metric_logic_out, *eta_metric_logic_out, *zta_metric_logic_out);
389 PetscFunctionReturn(0);
400 UserCtx *user,
const DMDALocalInfo *info,
401 PetscInt xs_gnode_rank, PetscInt ys_gnode_rank, PetscInt zs_gnode_rank,
402 PetscInt IM_nodes_global, PetscInt JM_nodes_global, PetscInt KM_nodes_global,
403 PetscRandom *rand_logic_i_ptr, PetscRandom *rand_logic_j_ptr, PetscRandom *rand_logic_k_ptr,
404 PetscInt *ci_metric_lnode_out, PetscInt *cj_metric_lnode_out, PetscInt *ck_metric_lnode_out,
405 PetscReal *xi_metric_logic_out, PetscReal *eta_metric_logic_out, PetscReal *zta_metric_logic_out)
407 PetscErrorCode ierr = 0;
408 PetscReal r_val_i_sel, r_val_j_sel, r_val_k_sel;
409 PetscInt local_cell_idx_on_face_dim1 = 0;
410 PetscInt local_cell_idx_on_face_dim2 = 0;
411 PetscMPIInt rank_for_logging;
413 PetscFunctionBeginUser;
417 ierr = MPI_Comm_rank(PETSC_COMM_WORLD, &rank_for_logging); CHKERRQ(ierr);
420 PetscInt owned_start_cell_i, num_owned_cells_on_rank_i;
421 PetscInt owned_start_cell_j, num_owned_cells_on_rank_j;
422 PetscInt owned_start_cell_k, num_owned_cells_on_rank_k;
424 ierr =
GetOwnedCellRange(info, 0, &owned_start_cell_i, &num_owned_cells_on_rank_i); CHKERRQ(ierr);
425 ierr =
GetOwnedCellRange(info, 1, &owned_start_cell_j, &num_owned_cells_on_rank_j); CHKERRQ(ierr);
426 ierr =
GetOwnedCellRange(info, 2, &owned_start_cell_k, &num_owned_cells_on_rank_k); CHKERRQ(ierr);
429 *ci_metric_lnode_out = xs_gnode_rank; *cj_metric_lnode_out = ys_gnode_rank; *ck_metric_lnode_out = zs_gnode_rank;
431 *xi_metric_logic_out = 0.5; *eta_metric_logic_out = 0.5; *zta_metric_logic_out = 0.5;
434 PetscInt last_global_cell_idx_i = (IM_nodes_global > 1) ? (IM_nodes_global - 2) : -1;
435 PetscInt last_global_cell_idx_j = (JM_nodes_global > 1) ? (JM_nodes_global - 2) : -1;
436 PetscInt last_global_cell_idx_k = (KM_nodes_global > 1) ? (KM_nodes_global - 2) : -1;
439 " Owned cells (i,j,k): (%d,%d,%d)\n"
440 " Global nodes (I,J,K): (%d,%d,%d)\n"
441 " info->xs,ys,zs (first owned node GLOBAL): (%d,%d,%d)\n"
442 " info->xm,ym,zm (num owned nodes GLOBAL): (%d,%d,%d)\n"
443 " xs_gnode_rank,ys_gnode_rank,zs_gnode_rank (DMDAGetCorners): (%d,%d,%d)\n"
444 " owned_start_cell (i,j,k) GLOBAL: (%d,%d,%d)\n"
445 " last_global_cell_idx (i,j,k): (%d,%d,%d)\n",
447 num_owned_cells_on_rank_i,num_owned_cells_on_rank_j,num_owned_cells_on_rank_k,
448 IM_nodes_global,JM_nodes_global,KM_nodes_global,
449 info->xs, info->ys, info->zs,
450 info->xm, info->ym, info->zm,
451 xs_gnode_rank,ys_gnode_rank,zs_gnode_rank,
452 owned_start_cell_i, owned_start_cell_j, owned_start_cell_k,
453 last_global_cell_idx_i, last_global_cell_idx_j, last_global_cell_idx_k);
460 *ci_metric_lnode_out = xs_gnode_rank;
461 *xi_metric_logic_out = 1.0e-6;
465 ierr = PetscRandomGetValueReal(*rand_logic_j_ptr, &r_val_j_sel); CHKERRQ(ierr);
466 local_cell_idx_on_face_dim1 = (PetscInt)(r_val_j_sel * num_owned_cells_on_rank_j);
467 local_cell_idx_on_face_dim1 = PetscMin(PetscMax(0, local_cell_idx_on_face_dim1), num_owned_cells_on_rank_j - 1);
468 *cj_metric_lnode_out = ys_gnode_rank + local_cell_idx_on_face_dim1;
470 ierr = PetscRandomGetValueReal(*rand_logic_k_ptr, &r_val_k_sel); CHKERRQ(ierr);
471 local_cell_idx_on_face_dim2 = (PetscInt)(r_val_k_sel * num_owned_cells_on_rank_k);
472 local_cell_idx_on_face_dim2 = PetscMin(PetscMax(0, local_cell_idx_on_face_dim2), num_owned_cells_on_rank_k - 1);
473 *ck_metric_lnode_out = zs_gnode_rank + local_cell_idx_on_face_dim2;
475 ierr = PetscRandomGetValueReal(*rand_logic_j_ptr, eta_metric_logic_out); CHKERRQ(ierr);
476 ierr = PetscRandomGetValueReal(*rand_logic_k_ptr, zta_metric_logic_out); CHKERRQ(ierr);
482 *ci_metric_lnode_out = xs_gnode_rank + (last_global_cell_idx_i - info->xs);
483 *xi_metric_logic_out = 1.0 - 1.0e-6;
485 ierr = PetscRandomGetValueReal(*rand_logic_j_ptr, &r_val_j_sel); CHKERRQ(ierr);
486 local_cell_idx_on_face_dim1 = (PetscInt)(r_val_j_sel * num_owned_cells_on_rank_j);
487 local_cell_idx_on_face_dim1 = PetscMin(PetscMax(0, local_cell_idx_on_face_dim1), num_owned_cells_on_rank_j - 1);
488 *cj_metric_lnode_out = ys_gnode_rank + local_cell_idx_on_face_dim1;
490 ierr = PetscRandomGetValueReal(*rand_logic_k_ptr, &r_val_k_sel); CHKERRQ(ierr);
491 local_cell_idx_on_face_dim2 = (PetscInt)(r_val_k_sel * num_owned_cells_on_rank_k);
492 local_cell_idx_on_face_dim2 = PetscMin(PetscMax(0, local_cell_idx_on_face_dim2), num_owned_cells_on_rank_k - 1);
493 *ck_metric_lnode_out = zs_gnode_rank + local_cell_idx_on_face_dim2;
495 ierr = PetscRandomGetValueReal(*rand_logic_j_ptr, eta_metric_logic_out); CHKERRQ(ierr);
496 ierr = PetscRandomGetValueReal(*rand_logic_k_ptr, zta_metric_logic_out); CHKERRQ(ierr);
500 *cj_metric_lnode_out = ys_gnode_rank;
501 *eta_metric_logic_out = 1.0e-6;
502 ierr = PetscRandomGetValueReal(*rand_logic_i_ptr, &r_val_i_sel); CHKERRQ(ierr);
503 local_cell_idx_on_face_dim1 = (PetscInt)(r_val_i_sel * num_owned_cells_on_rank_i);
504 local_cell_idx_on_face_dim1 = PetscMin(PetscMax(0, local_cell_idx_on_face_dim1), num_owned_cells_on_rank_i - 1);
505 *ci_metric_lnode_out = xs_gnode_rank + local_cell_idx_on_face_dim1;
506 ierr = PetscRandomGetValueReal(*rand_logic_k_ptr, &r_val_k_sel); CHKERRQ(ierr);
507 local_cell_idx_on_face_dim2 = (PetscInt)(r_val_k_sel * num_owned_cells_on_rank_k);
508 local_cell_idx_on_face_dim2 = PetscMin(PetscMax(0, local_cell_idx_on_face_dim2), num_owned_cells_on_rank_k - 1);
509 *ck_metric_lnode_out = zs_gnode_rank + local_cell_idx_on_face_dim2;
510 ierr = PetscRandomGetValueReal(*rand_logic_i_ptr, xi_metric_logic_out); CHKERRQ(ierr);
511 ierr = PetscRandomGetValueReal(*rand_logic_k_ptr, zta_metric_logic_out); CHKERRQ(ierr);
514 *cj_metric_lnode_out = ys_gnode_rank + (last_global_cell_idx_j - info->ys);
515 *eta_metric_logic_out = 1.0 - 1.0e-6;
516 ierr = PetscRandomGetValueReal(*rand_logic_i_ptr, &r_val_i_sel); CHKERRQ(ierr);
517 local_cell_idx_on_face_dim1 = (PetscInt)(r_val_i_sel * num_owned_cells_on_rank_i);
518 local_cell_idx_on_face_dim1 = PetscMin(PetscMax(0, local_cell_idx_on_face_dim1), num_owned_cells_on_rank_i - 1);
519 *ci_metric_lnode_out = xs_gnode_rank + local_cell_idx_on_face_dim1;
520 ierr = PetscRandomGetValueReal(*rand_logic_k_ptr, &r_val_k_sel); CHKERRQ(ierr);
521 local_cell_idx_on_face_dim2 = (PetscInt)(r_val_k_sel * num_owned_cells_on_rank_k);
522 local_cell_idx_on_face_dim2 = PetscMin(PetscMax(0, local_cell_idx_on_face_dim2), num_owned_cells_on_rank_k - 1);
523 *ck_metric_lnode_out = zs_gnode_rank + local_cell_idx_on_face_dim2;
524 ierr = PetscRandomGetValueReal(*rand_logic_i_ptr, xi_metric_logic_out); CHKERRQ(ierr);
525 ierr = PetscRandomGetValueReal(*rand_logic_k_ptr, zta_metric_logic_out); CHKERRQ(ierr);
528 *ck_metric_lnode_out = zs_gnode_rank;
529 *zta_metric_logic_out = 1.0e-6;
531 ierr = PetscRandomGetValueReal(*rand_logic_i_ptr, &r_val_i_sel); CHKERRQ(ierr);
532 local_cell_idx_on_face_dim1 = (PetscInt)(r_val_i_sel * num_owned_cells_on_rank_i);
533 local_cell_idx_on_face_dim1 = PetscMin(PetscMax(0, local_cell_idx_on_face_dim1), num_owned_cells_on_rank_i - 1);
534 *ci_metric_lnode_out = xs_gnode_rank + local_cell_idx_on_face_dim1;
536 ierr = PetscRandomGetValueReal(*rand_logic_j_ptr, &r_val_j_sel); CHKERRQ(ierr);
537 local_cell_idx_on_face_dim2 = (PetscInt)(r_val_j_sel * num_owned_cells_on_rank_j);
538 local_cell_idx_on_face_dim2 = PetscMin(PetscMax(0, local_cell_idx_on_face_dim2), num_owned_cells_on_rank_j - 1);
539 *cj_metric_lnode_out = ys_gnode_rank + local_cell_idx_on_face_dim2;
541 ierr = PetscRandomGetValueReal(*rand_logic_i_ptr, xi_metric_logic_out); CHKERRQ(ierr);
542 ierr = PetscRandomGetValueReal(*rand_logic_j_ptr, eta_metric_logic_out); CHKERRQ(ierr);
545 *ck_metric_lnode_out = zs_gnode_rank + (last_global_cell_idx_k - info->zs);
546 *zta_metric_logic_out = 1.0 - 1.0e-6;
547 ierr = PetscRandomGetValueReal(*rand_logic_i_ptr, &r_val_i_sel); CHKERRQ(ierr);
548 local_cell_idx_on_face_dim1 = (PetscInt)(r_val_i_sel * num_owned_cells_on_rank_i);
549 local_cell_idx_on_face_dim1 = PetscMin(PetscMax(0, local_cell_idx_on_face_dim1), num_owned_cells_on_rank_i - 1);
550 *ci_metric_lnode_out = xs_gnode_rank + local_cell_idx_on_face_dim1;
551 ierr = PetscRandomGetValueReal(*rand_logic_j_ptr, &r_val_j_sel); CHKERRQ(ierr);
552 local_cell_idx_on_face_dim2 = (PetscInt)(r_val_j_sel * num_owned_cells_on_rank_j);
553 local_cell_idx_on_face_dim2 = PetscMin(PetscMax(0, local_cell_idx_on_face_dim2), num_owned_cells_on_rank_j - 1);
554 *cj_metric_lnode_out = ys_gnode_rank + local_cell_idx_on_face_dim2;
555 ierr = PetscRandomGetValueReal(*rand_logic_i_ptr, xi_metric_logic_out); CHKERRQ(ierr);
556 ierr = PetscRandomGetValueReal(*rand_logic_j_ptr, eta_metric_logic_out); CHKERRQ(ierr);
559 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG,
"GetRandomCellAndLogicOnInletFace: Invalid user->identifiedInletBCFace %d. \n", user->
identifiedInletBCFace);
562 PetscReal eps = 1.0e-7;
564 *eta_metric_logic_out = PetscMin(PetscMax(0.0, *eta_metric_logic_out), 1.0 - eps);
565 *zta_metric_logic_out = PetscMin(PetscMax(0.0, *zta_metric_logic_out), 1.0 - eps);
567 *xi_metric_logic_out = PetscMin(PetscMax(0.0, *xi_metric_logic_out), 1.0 - eps);
568 *zta_metric_logic_out = PetscMin(PetscMax(0.0, *zta_metric_logic_out), 1.0 - eps);
570 *xi_metric_logic_out = PetscMin(PetscMax(0.0, *xi_metric_logic_out), 1.0 - eps);
571 *eta_metric_logic_out = PetscMin(PetscMax(0.0, *eta_metric_logic_out), 1.0 - eps);
575 rank_for_logging, *ci_metric_lnode_out, *cj_metric_lnode_out, *ck_metric_lnode_out,
576 *xi_metric_logic_out, *eta_metric_logic_out, *zta_metric_logic_out);
580 PetscFunctionReturn(0);
1055 PetscErrorCode ierr;
1056 PetscFunctionBeginUser;
1065 PetscReal local_inflow_pre = 0.0;
1066 PetscReal local_inflow_post = 0.0;
1067 PetscReal global_inflow_pre = 0.0;
1068 PetscReal global_inflow_post = 0.0;
1069 PetscInt num_handlers[3] = {0,0,0};
1074 for (
int i = 0; i < 6; i++) {
1077 if (!handler->
PreStep)
continue;
1083 .global_inflow_sum = NULL,
1084 .global_outflow_sum = NULL,
1090 ierr = handler->
PreStep(handler, &ctx, &local_inflow_pre, NULL); CHKERRQ(ierr);
1094 if (local_inflow_pre != 0.0) {
1095 ierr = MPI_Allreduce(&local_inflow_pre, &global_inflow_pre, 1, MPIU_REAL,
1096 MPI_SUM, PETSC_COMM_WORLD); CHKERRQ(ierr);
1101 for (
int i = 0; i < 6; i++) {
1104 if(!handler->
Apply)
continue;
1111 .global_inflow_sum = NULL,
1112 .global_outflow_sum = NULL,
1118 ierr = handler->
Apply(handler, &ctx); CHKERRQ(ierr);
1122 for (
int i = 0; i < 6; i++) {
1132 .global_inflow_sum = NULL,
1133 .global_outflow_sum = NULL,
1139 ierr = handler->
PostStep(handler, &ctx, &local_inflow_post, NULL); CHKERRQ(ierr);
1143 ierr = MPI_Allreduce(&local_inflow_post, &global_inflow_post, 1, MPIU_REAL,
1144 MPI_SUM, PETSC_COMM_WORLD); CHKERRQ(ierr);
1150 " (INLETS): %d Prestep(s), %d Application(s), %d Poststep(s), FluxInSum = %.6e\n",
1151 num_handlers[0],num_handlers[1],num_handlers[2], global_inflow_post);
1157 PetscReal local_farfield_in_pre = 0.0;
1158 PetscReal local_farfield_out_pre = 0.0;
1159 PetscReal local_farfield_in_post = 0.0;
1160 PetscReal local_farfield_out_post = 0.0;
1161 PetscReal global_farfield_in_pre = 0.0;
1162 PetscReal global_farfield_out_pre = 0.0;
1163 PetscReal global_farfield_in_post = 0.0;
1164 PetscReal global_farfield_out_post = 0.0;
1165 memset(num_handlers,0,
sizeof(num_handlers));
1170 for (
int i = 0; i < 6; i++) {
1173 if (!handler->
PreStep)
continue;
1180 .global_outflow_sum = NULL,
1186 ierr = handler->
PreStep(handler, &ctx, &local_farfield_in_pre, &local_farfield_out_pre);
1191 if (local_farfield_in_pre != 0.0 || local_farfield_out_pre != 0.0) {
1192 ierr = MPI_Allreduce(&local_farfield_in_pre, &global_farfield_in_pre, 1, MPIU_REAL,
1193 MPI_SUM, PETSC_COMM_WORLD); CHKERRQ(ierr);
1194 ierr = MPI_Allreduce(&local_farfield_out_pre, &global_farfield_out_pre, 1, MPIU_REAL,
1195 MPI_SUM, PETSC_COMM_WORLD); CHKERRQ(ierr);
1198 " Farfield pre-analysis: In=%.6e, Out=%.6e\n",
1199 global_farfield_in_pre, global_farfield_out_pre);
1203 for (
int i = 0; i < 6; i++) {
1206 if(!handler->
Apply)
continue;
1214 .global_outflow_sum = NULL,
1220 ierr = handler->
Apply(handler, &ctx); CHKERRQ(ierr);
1224 for (
int i = 0; i < 6; i++) {
1235 .global_outflow_sum = NULL,
1241 ierr = handler->
PostStep(handler, &ctx, &local_farfield_in_post, &local_farfield_out_post);
1246 if (num_handlers > 0) {
1247 ierr = MPI_Allreduce(&local_farfield_in_post, &global_farfield_in_post, 1, MPIU_REAL,
1248 MPI_SUM, PETSC_COMM_WORLD); CHKERRQ(ierr);
1249 ierr = MPI_Allreduce(&local_farfield_out_post, &global_farfield_out_post, 1, MPIU_REAL,
1250 MPI_SUM, PETSC_COMM_WORLD); CHKERRQ(ierr);
1257 " (FARFIELD): %d Prestep(s), %d Application(s), %d Poststep(s) , InFlux=%.6e, OutFlux=%.6e\n",
1258 num_handlers[0],num_handlers[1],num_handlers[2], global_farfield_in_post, global_farfield_out_post);
1270 memset(num_handlers,0,
sizeof(num_handlers));
1275 for (
int i = 0; i < 6; i++) {
1278 if (!handler->
PreStep)
continue;
1285 .global_outflow_sum = NULL,
1291 ierr = handler->
PreStep(handler, &ctx, NULL, NULL); CHKERRQ(ierr);
1297 for (
int i = 0; i < 6; i++) {
1300 if(!handler->
Apply)
continue;
1308 .global_outflow_sum = NULL,
1314 ierr = handler->
Apply(handler, &ctx); CHKERRQ(ierr);
1318 for (
int i = 0; i < 6; i++) {
1329 .global_outflow_sum = NULL,
1335 ierr = handler->
PostStep(handler, &ctx, NULL, NULL); CHKERRQ(ierr);
1341 num_handlers[0],num_handlers[1],num_handlers[2]);
1348 PetscReal local_outflow_pre = 0.0;
1349 PetscReal local_outflow_post = 0.0;
1350 PetscReal global_outflow_pre = 0.0;
1351 PetscReal global_outflow_post = 0.0;
1352 memset(num_handlers,0,
sizeof(num_handlers));
1357 for (
int i = 0; i < 6; i++) {
1360 if (!handler->
PreStep)
continue;
1367 .global_outflow_sum = NULL,
1373 ierr = handler->
PreStep(handler, &ctx, NULL, &local_outflow_pre); CHKERRQ(ierr);
1377 ierr = MPI_Allreduce(&local_outflow_pre, &global_outflow_pre, 1, MPIU_REAL,
1378 MPI_SUM, PETSC_COMM_WORLD); CHKERRQ(ierr);
1384 " Uncorrected outflow: %.6e, Total inflow: %.6e (Inlet: %.6e + Farfield: %.6e)\n",
1389 for (
int i = 0; i < 6; i++) {
1392 if(!handler->
Apply)
continue;
1400 .global_outflow_sum = &global_outflow_pre,
1406 ierr = handler->
Apply(handler, &ctx); CHKERRQ(ierr);
1410 for (
int i = 0; i < 6; i++) {
1421 .global_outflow_sum = &global_outflow_pre,
1427 ierr = handler->
PostStep(handler, &ctx, NULL, &local_outflow_post); CHKERRQ(ierr);
1431 ierr = MPI_Allreduce(&local_outflow_post, &global_outflow_post, 1, MPIU_REAL,
1432 MPI_SUM, PETSC_COMM_WORLD); CHKERRQ(ierr);
1439 PetscReal flux_error = PetscAbsReal(total_outflow - total_inflow);
1440 PetscReal relative_error = (total_inflow > 1e-16) ?
1441 flux_error / total_inflow : flux_error;
1444 " (OUTLETS): %d Prestep(s), %d Application(s), %d Poststep(s), FluxOutSum = %.6e\n",
1445 num_handlers[0],num_handlers[1],num_handlers[2], global_outflow_post);
1447 " Conservation: Total In=%.6e, Total Out=%.6e, Error=%.3e (%.2e)%%)\n",
1448 total_inflow, total_outflow, flux_error, relative_error * 100.0);
1450 if (relative_error > 1e-6) {
1452 " WARNING: Large mass conservation error (%.2e%%)!\n",
1453 relative_error * 100.0);
1460 PetscFunctionReturn(0);
2153 PetscErrorCode ierr;
2154 DM da = user->
da, fda = user->
fda;
2155 DMDALocalInfo info = user->
info;
2156 PetscInt xs = info.xs, xe = info.xs + info.xm;
2157 PetscInt ys = info.ys, ye = info.ys + info.ym;
2158 PetscInt zs = info.zs, ze = info.zs + info.zm;
2159 PetscInt mx = info.mx, my = info.my, mz = info.mz;
2164 PetscFunctionBeginUser;
2166 ierr = DMDAVecGetArray(fda, user->
Ucat, &ucat); CHKERRQ(ierr);
2167 ierr = DMDAVecGetArray(da, user->
P, &p); CHKERRQ(ierr);
2175 for (PetscInt j = ys; j < ye; j++) {
2176 p[zs][j][xs] = 0.5 * (p[zs+1][j][xs] + p[zs][j][xs+1]);
2177 ucat[zs][j][xs].
x = 0.5 * (ucat[zs+1][j][xs].
x + ucat[zs][j][xs+1].
x);
2178 ucat[zs][j][xs].
y = 0.5 * (ucat[zs+1][j][xs].
y + ucat[zs][j][xs+1].
y);
2179 ucat[zs][j][xs].
z = 0.5 * (ucat[zs+1][j][xs].
z + ucat[zs][j][xs+1].
z);
2183 for (PetscInt j = ys; j < ye; j++) {
2184 p[zs][j][mx-1] = 0.5 * (p[zs+1][j][mx-1] + p[zs][j][mx-2]);
2185 ucat[zs][j][mx-1].
x = 0.5 * (ucat[zs+1][j][mx-1].
x + ucat[zs][j][mx-2].
x);
2186 ucat[zs][j][mx-1].
y = 0.5 * (ucat[zs+1][j][mx-1].
y + ucat[zs][j][mx-2].
y);
2187 ucat[zs][j][mx-1].
z = 0.5 * (ucat[zs+1][j][mx-1].
z + ucat[zs][j][mx-2].
z);
2191 for (PetscInt i = xs; i < xe; i++) {
2192 p[zs][ys][i] = 0.5 * (p[zs+1][ys][i] + p[zs][ys+1][i]);
2193 ucat[zs][ys][i].
x = 0.5 * (ucat[zs+1][ys][i].
x + ucat[zs][ys+1][i].
x);
2194 ucat[zs][ys][i].
y = 0.5 * (ucat[zs+1][ys][i].
y + ucat[zs][ys+1][i].
y);
2195 ucat[zs][ys][i].
z = 0.5 * (ucat[zs+1][ys][i].
z + ucat[zs][ys+1][i].
z);
2199 for (PetscInt i = xs; i < xe; i++) {
2200 p[zs][my-1][i] = 0.5 * (p[zs+1][my-1][i] + p[zs][my-2][i]);
2201 ucat[zs][my-1][i].
x = 0.5 * (ucat[zs+1][my-1][i].
x + ucat[zs][my-2][i].
x);
2202 ucat[zs][my-1][i].
y = 0.5 * (ucat[zs+1][my-1][i].
y + ucat[zs][my-2][i].
y);
2203 ucat[zs][my-1][i].
z = 0.5 * (ucat[zs+1][my-1][i].
z + ucat[zs][my-2][i].
z);
2211 for (PetscInt j = ys; j < ye; j++) {
2212 p[mz-1][j][xs] = 0.5 * (p[mz-2][j][xs] + p[mz-1][j][xs+1]);
2213 ucat[mz-1][j][xs].
x = 0.5 * (ucat[mz-2][j][xs].
x + ucat[mz-1][j][xs+1].
x);
2214 ucat[mz-1][j][xs].
y = 0.5 * (ucat[mz-2][j][xs].
y + ucat[mz-1][j][xs+1].
y);
2215 ucat[mz-1][j][xs].
z = 0.5 * (ucat[mz-2][j][xs].
z + ucat[mz-1][j][xs+1].
z);
2219 for (PetscInt j = ys; j < ye; j++) {
2220 p[mz-1][j][mx-1] = 0.5 * (p[mz-2][j][mx-1] + p[mz-1][j][mx-2]);
2221 ucat[mz-1][j][mx-1].
x = 0.5 * (ucat[mz-2][j][mx-1].
x + ucat[mz-1][j][mx-2].
x);
2222 ucat[mz-1][j][mx-1].
y = 0.5 * (ucat[mz-2][j][mx-1].
y + ucat[mz-1][j][mx-2].
y);
2223 ucat[mz-1][j][mx-1].
z = 0.5 * (ucat[mz-2][j][mx-1].
z + ucat[mz-1][j][mx-2].
z);
2227 for (PetscInt i = xs; i < xe; i++) {
2228 p[mz-1][ys][i] = 0.5 * (p[mz-2][ys][i] + p[mz-1][ys+1][i]);
2229 ucat[mz-1][ys][i].
x = 0.5 * (ucat[mz-2][ys][i].
x + ucat[mz-1][ys+1][i].
x);
2230 ucat[mz-1][ys][i].
y = 0.5 * (ucat[mz-2][ys][i].
y + ucat[mz-1][ys+1][i].
y);
2231 ucat[mz-1][ys][i].
z = 0.5 * (ucat[mz-2][ys][i].
z + ucat[mz-1][ys+1][i].
z);
2235 for (PetscInt i = xs; i < xe; i++) {
2236 p[mz-1][my-1][i] = 0.5 * (p[mz-2][my-1][i] + p[mz-1][my-2][i]);
2237 ucat[mz-1][my-1][i].
x = 0.5 * (ucat[mz-2][my-1][i].
x + ucat[mz-1][my-2][i].
x);
2238 ucat[mz-1][my-1][i].
y = 0.5 * (ucat[mz-2][my-1][i].
y + ucat[mz-1][my-2][i].
y);
2239 ucat[mz-1][my-1][i].
z = 0.5 * (ucat[mz-2][my-1][i].
z + ucat[mz-1][my-2][i].
z);
2247 for (PetscInt k = zs; k < ze; k++) {
2248 p[k][ys][xs] = 0.5 * (p[k][ys+1][xs] + p[k][ys][xs+1]);
2249 ucat[k][ys][xs].
x = 0.5 * (ucat[k][ys+1][xs].
x + ucat[k][ys][xs+1].
x);
2250 ucat[k][ys][xs].
y = 0.5 * (ucat[k][ys+1][xs].
y + ucat[k][ys][xs+1].
y);
2251 ucat[k][ys][xs].
z = 0.5 * (ucat[k][ys+1][xs].
z + ucat[k][ys][xs+1].
z);
2255 for (PetscInt k = zs; k < ze; k++) {
2256 p[k][ys][mx-1] = 0.5 * (p[k][ys+1][mx-1] + p[k][ys][mx-2]);
2257 ucat[k][ys][mx-1].
x = 0.5 * (ucat[k][ys+1][mx-1].
x + ucat[k][ys][mx-2].
x);
2258 ucat[k][ys][mx-1].
y = 0.5 * (ucat[k][ys+1][mx-1].
y + ucat[k][ys][mx-2].
y);
2259 ucat[k][ys][mx-1].
z = 0.5 * (ucat[k][ys+1][mx-1].
z + ucat[k][ys][mx-2].
z);
2266 for (PetscInt k = zs; k < ze; k++) {
2267 p[k][my-1][xs] = 0.5 * (p[k][my-2][xs] + p[k][my-1][xs+1]);
2268 ucat[k][my-1][xs].
x = 0.5 * (ucat[k][my-2][xs].
x + ucat[k][my-1][xs+1].
x);
2269 ucat[k][my-1][xs].
y = 0.5 * (ucat[k][my-2][xs].
y + ucat[k][my-1][xs+1].
y);
2270 ucat[k][my-1][xs].
z = 0.5 * (ucat[k][my-2][xs].
z + ucat[k][my-1][xs+1].
z);
2274 for (PetscInt k = zs; k < ze; k++) {
2275 p[k][my-1][mx-1] = 0.5 * (p[k][my-2][mx-1] + p[k][my-1][mx-2]);
2276 ucat[k][my-1][mx-1].
x = 0.5 * (ucat[k][my-2][mx-1].
x + ucat[k][my-1][mx-2].
x);
2277 ucat[k][my-1][mx-1].
y = 0.5 * (ucat[k][my-2][mx-1].
y + ucat[k][my-1][mx-2].
y);
2278 ucat[k][my-1][mx-1].
z = 0.5 * (ucat[k][my-2][mx-1].
z + ucat[k][my-1][mx-2].
z);
2283 ierr = DMDAVecRestoreArray(fda, user->
Ucat, &ucat); CHKERRQ(ierr);
2284 ierr = DMDAVecRestoreArray(da, user->
P, &p); CHKERRQ(ierr);
2286 PetscFunctionReturn(0);
2340 PetscErrorCode ierr;
2342 DMDALocalInfo *info = &user->
info;
2344 PetscFunctionBeginUser;
2350 PetscFunctionReturn(0);
2358 Cmpnts ***velocity_cartesian;
2359 Cmpnts ***velocity_contravariant;
2360 Cmpnts ***velocity_boundary;
2361 Cmpnts ***csi, ***eta, ***zet;
2362 PetscReal ***node_vertex_flag;
2363 PetscReal ***cell_jacobian;
2364 PetscReal ***friction_velocity;
2366 ierr = DMDAVecGetArray(user->
fda, user->
Ucat, &velocity_cartesian); CHKERRQ(ierr);
2367 ierr = DMDAVecGetArray(user->
fda, user->
Ucont, &velocity_contravariant); CHKERRQ(ierr);
2368 ierr = DMDAVecGetArray(user->
fda, user->
Bcs.
Ubcs, &velocity_boundary); CHKERRQ(ierr);
2369 ierr = DMDAVecGetArrayRead(user->
fda, user->
lCsi, (
const Cmpnts***)&csi); CHKERRQ(ierr);
2370 ierr = DMDAVecGetArrayRead(user->
fda, user->
lEta, (
const Cmpnts***)&eta); CHKERRQ(ierr);
2371 ierr = DMDAVecGetArrayRead(user->
fda, user->
lZet, (
const Cmpnts***)&zet); CHKERRQ(ierr);
2372 ierr = DMDAVecGetArrayRead(user->
da, user->
lNvert, (
const PetscReal***)&node_vertex_flag); CHKERRQ(ierr);
2373 ierr = DMDAVecGetArrayRead(user->
da, user->
lAj, (
const PetscReal***)&cell_jacobian); CHKERRQ(ierr);
2379 PetscInt grid_start_i = info->xs, grid_end_i = info->xs + info->xm;
2380 PetscInt grid_start_j = info->ys, grid_end_j = info->ys + info->ym;
2381 PetscInt grid_start_k = info->zs, grid_end_k = info->zs + info->zm;
2382 PetscInt grid_size_i = info->mx, grid_size_j = info->my, grid_size_k = info->mz;
2385 PetscInt loop_start_i = grid_start_i, loop_end_i = grid_end_i;
2386 PetscInt loop_start_j = grid_start_j, loop_end_j = grid_end_j;
2387 PetscInt loop_start_k = grid_start_k, loop_end_k = grid_end_k;
2389 if (grid_start_i == 0) loop_start_i = grid_start_i + 1;
2390 if (grid_end_i == grid_size_i) loop_end_i = grid_end_i - 1;
2391 if (grid_start_j == 0) loop_start_j = grid_start_j + 1;
2392 if (grid_end_j == grid_size_j) loop_end_j = grid_end_j - 1;
2393 if (grid_start_k == 0) loop_start_k = grid_start_k + 1;
2394 if (grid_end_k == grid_size_k) loop_end_k = grid_end_k - 1;
2397 const PetscReal wall_roughness_height = 1.e-16;
2402 for (
int face_index = 0; face_index < 6; face_index++) {
2412 PetscBool rank_owns_this_face;
2414 current_face_id, &rank_owns_this_face); CHKERRQ(ierr);
2416 if (!rank_owns_this_face) {
2426 switch(current_face_id) {
2432 if (grid_start_i == 0) {
2433 const PetscInt ghost_cell_index = grid_start_i;
2434 const PetscInt first_interior_cell = grid_start_i + 1;
2435 const PetscInt second_interior_cell = grid_start_i + 2;
2437 for (PetscInt k = loop_start_k; k < loop_end_k; k++) {
2438 for (PetscInt j = loop_start_j; j < loop_end_j; j++) {
2441 if (node_vertex_flag[k][j][first_interior_cell] < 0.1) {
2444 PetscReal face_area = sqrt(
2445 csi[k][j][ghost_cell_index].x * csi[k][j][ghost_cell_index].x +
2446 csi[k][j][ghost_cell_index].y * csi[k][j][ghost_cell_index].y +
2447 csi[k][j][ghost_cell_index].z * csi[k][j][ghost_cell_index].z
2453 PetscReal distance_to_first_cell = 0.5 / cell_jacobian[k][j][first_interior_cell] / face_area;
2454 PetscReal distance_to_second_cell = 2.0 * distance_to_first_cell +
2455 0.5 / cell_jacobian[k][j][second_interior_cell] / face_area;
2458 PetscReal wall_normal[3];
2459 wall_normal[0] = csi[k][j][ghost_cell_index].
x / face_area;
2460 wall_normal[1] = csi[k][j][ghost_cell_index].
y / face_area;
2461 wall_normal[2] = csi[k][j][ghost_cell_index].
z / face_area;
2465 Cmpnts reference_velocity;
2467 wall_velocity.
x = wall_velocity.
y = wall_velocity.
z = 0.0;
2468 reference_velocity = velocity_cartesian[k][j][second_interior_cell];
2471 noslip(user, distance_to_second_cell, distance_to_first_cell,
2472 wall_velocity, reference_velocity,
2473 &velocity_cartesian[k][j][first_interior_cell],
2474 wall_normal[0], wall_normal[1], wall_normal[2]);
2478 distance_to_second_cell, distance_to_first_cell,
2479 wall_velocity, reference_velocity,
2480 &velocity_cartesian[k][j][first_interior_cell],
2481 &friction_velocity[k][j][first_interior_cell],
2482 wall_normal[0], wall_normal[1], wall_normal[2]);
2485 velocity_boundary[k][j][ghost_cell_index].
x = 0.0;
2486 velocity_boundary[k][j][ghost_cell_index].
y = 0.0;
2487 velocity_boundary[k][j][ghost_cell_index].
z = 0.0;
2488 velocity_contravariant[k][j][ghost_cell_index].
x = 0.0;
2499 if (grid_end_i == grid_size_i) {
2500 const PetscInt ghost_cell_index = grid_end_i - 1;
2501 const PetscInt first_interior_cell = grid_end_i - 2;
2502 const PetscInt second_interior_cell = grid_end_i - 3;
2504 for (PetscInt k = loop_start_k; k < loop_end_k; k++) {
2505 for (PetscInt j = loop_start_j; j < loop_end_j; j++) {
2507 if (node_vertex_flag[k][j][first_interior_cell] < 0.1) {
2509 PetscReal face_area = sqrt(
2510 csi[k][j][first_interior_cell].x * csi[k][j][first_interior_cell].x +
2511 csi[k][j][first_interior_cell].y * csi[k][j][first_interior_cell].y +
2512 csi[k][j][first_interior_cell].z * csi[k][j][first_interior_cell].z
2515 PetscReal distance_to_first_cell = 0.5 / cell_jacobian[k][j][first_interior_cell] / face_area;
2516 PetscReal distance_to_second_cell = 2.0 * distance_to_first_cell +
2517 0.5 / cell_jacobian[k][j][second_interior_cell] / face_area;
2520 PetscReal wall_normal[3];
2521 wall_normal[0] = -csi[k][j][first_interior_cell].
x / face_area;
2522 wall_normal[1] = -csi[k][j][first_interior_cell].
y / face_area;
2523 wall_normal[2] = -csi[k][j][first_interior_cell].
z / face_area;
2525 Cmpnts wall_velocity, reference_velocity;
2526 wall_velocity.
x = wall_velocity.
y = wall_velocity.
z = 0.0;
2527 reference_velocity = velocity_cartesian[k][j][second_interior_cell];
2529 noslip(user, distance_to_second_cell, distance_to_first_cell,
2530 wall_velocity, reference_velocity,
2531 &velocity_cartesian[k][j][first_interior_cell],
2532 wall_normal[0], wall_normal[1], wall_normal[2]);
2535 distance_to_second_cell, distance_to_first_cell,
2536 wall_velocity, reference_velocity,
2537 &velocity_cartesian[k][j][first_interior_cell],
2538 &friction_velocity[k][j][first_interior_cell],
2539 wall_normal[0], wall_normal[1], wall_normal[2]);
2541 velocity_boundary[k][j][ghost_cell_index].
x = 0.0;
2542 velocity_boundary[k][j][ghost_cell_index].
y = 0.0;
2543 velocity_boundary[k][j][ghost_cell_index].
z = 0.0;
2544 velocity_contravariant[k][j][first_interior_cell].
x = 0.0;
2555 if (grid_start_j == 0) {
2556 const PetscInt ghost_cell_index = grid_start_j;
2557 const PetscInt first_interior_cell = grid_start_j + 1;
2558 const PetscInt second_interior_cell = grid_start_j + 2;
2560 for (PetscInt k = loop_start_k; k < loop_end_k; k++) {
2561 for (PetscInt i = loop_start_i; i < loop_end_i; i++) {
2563 if (node_vertex_flag[k][first_interior_cell][i] < 0.1) {
2565 PetscReal face_area = sqrt(
2566 eta[k][ghost_cell_index][i].x * eta[k][ghost_cell_index][i].x +
2567 eta[k][ghost_cell_index][i].y * eta[k][ghost_cell_index][i].y +
2568 eta[k][ghost_cell_index][i].z * eta[k][ghost_cell_index][i].z
2571 PetscReal distance_to_first_cell = 0.5 / cell_jacobian[k][first_interior_cell][i] / face_area;
2572 PetscReal distance_to_second_cell = 2.0 * distance_to_first_cell +
2573 0.5 / cell_jacobian[k][second_interior_cell][i] / face_area;
2575 PetscReal wall_normal[3];
2576 wall_normal[0] = eta[k][ghost_cell_index][i].
x / face_area;
2577 wall_normal[1] = eta[k][ghost_cell_index][i].
y / face_area;
2578 wall_normal[2] = eta[k][ghost_cell_index][i].
z / face_area;
2580 Cmpnts wall_velocity, reference_velocity;
2581 wall_velocity.
x = wall_velocity.
y = wall_velocity.
z = 0.0;
2582 reference_velocity = velocity_cartesian[k][second_interior_cell][i];
2584 noslip(user, distance_to_second_cell, distance_to_first_cell,
2585 wall_velocity, reference_velocity,
2586 &velocity_cartesian[k][first_interior_cell][i],
2587 wall_normal[0], wall_normal[1], wall_normal[2]);
2590 distance_to_second_cell, distance_to_first_cell,
2591 wall_velocity, reference_velocity,
2592 &velocity_cartesian[k][first_interior_cell][i],
2593 &friction_velocity[k][first_interior_cell][i],
2594 wall_normal[0], wall_normal[1], wall_normal[2]);
2596 velocity_boundary[k][ghost_cell_index][i].
x = 0.0;
2597 velocity_boundary[k][ghost_cell_index][i].
y = 0.0;
2598 velocity_boundary[k][ghost_cell_index][i].
z = 0.0;
2599 velocity_contravariant[k][ghost_cell_index][i].
y = 0.0;
2610 if (grid_end_j == grid_size_j) {
2611 const PetscInt ghost_cell_index = grid_end_j - 1;
2612 const PetscInt first_interior_cell = grid_end_j - 2;
2613 const PetscInt second_interior_cell = grid_end_j - 3;
2615 for (PetscInt k = loop_start_k; k < loop_end_k; k++) {
2616 for (PetscInt i = loop_start_i; i < loop_end_i; i++) {
2618 if (node_vertex_flag[k][first_interior_cell][i] < 0.1) {
2620 PetscReal face_area = sqrt(
2621 eta[k][first_interior_cell][i].x * eta[k][first_interior_cell][i].x +
2622 eta[k][first_interior_cell][i].y * eta[k][first_interior_cell][i].y +
2623 eta[k][first_interior_cell][i].z * eta[k][first_interior_cell][i].z
2626 PetscReal distance_to_first_cell = 0.5 / cell_jacobian[k][first_interior_cell][i] / face_area;
2627 PetscReal distance_to_second_cell = 2.0 * distance_to_first_cell +
2628 0.5 / cell_jacobian[k][second_interior_cell][i] / face_area;
2630 PetscReal wall_normal[3];
2631 wall_normal[0] = -eta[k][first_interior_cell][i].
x / face_area;
2632 wall_normal[1] = -eta[k][first_interior_cell][i].
y / face_area;
2633 wall_normal[2] = -eta[k][first_interior_cell][i].
z / face_area;
2635 Cmpnts wall_velocity, reference_velocity;
2636 wall_velocity.
x = wall_velocity.
y = wall_velocity.
z = 0.0;
2637 reference_velocity = velocity_cartesian[k][second_interior_cell][i];
2639 noslip(user, distance_to_second_cell, distance_to_first_cell,
2640 wall_velocity, reference_velocity,
2641 &velocity_cartesian[k][first_interior_cell][i],
2642 wall_normal[0], wall_normal[1], wall_normal[2]);
2645 distance_to_second_cell, distance_to_first_cell,
2646 wall_velocity, reference_velocity,
2647 &velocity_cartesian[k][first_interior_cell][i],
2648 &friction_velocity[k][first_interior_cell][i],
2649 wall_normal[0], wall_normal[1], wall_normal[2]);
2651 velocity_boundary[k][ghost_cell_index][i].
x = 0.0;
2652 velocity_boundary[k][ghost_cell_index][i].
y = 0.0;
2653 velocity_boundary[k][ghost_cell_index][i].
z = 0.0;
2654 velocity_contravariant[k][first_interior_cell][i].
y = 0.0;
2665 if (grid_start_k == 0) {
2666 const PetscInt ghost_cell_index = grid_start_k;
2667 const PetscInt first_interior_cell = grid_start_k + 1;
2668 const PetscInt second_interior_cell = grid_start_k + 2;
2670 for (PetscInt j = loop_start_j; j < loop_end_j; j++) {
2671 for (PetscInt i = loop_start_i; i < loop_end_i; i++) {
2673 if (node_vertex_flag[first_interior_cell][j][i] < 0.1) {
2675 PetscReal face_area = sqrt(
2676 zet[ghost_cell_index][j][i].x * zet[ghost_cell_index][j][i].x +
2677 zet[ghost_cell_index][j][i].y * zet[ghost_cell_index][j][i].y +
2678 zet[ghost_cell_index][j][i].z * zet[ghost_cell_index][j][i].z
2681 PetscReal distance_to_first_cell = 0.5 / cell_jacobian[first_interior_cell][j][i] / face_area;
2682 PetscReal distance_to_second_cell = 2.0 * distance_to_first_cell +
2683 0.5 / cell_jacobian[second_interior_cell][j][i] / face_area;
2685 PetscReal wall_normal[3];
2686 wall_normal[0] = zet[ghost_cell_index][j][i].
x / face_area;
2687 wall_normal[1] = zet[ghost_cell_index][j][i].
y / face_area;
2688 wall_normal[2] = zet[ghost_cell_index][j][i].
z / face_area;
2690 Cmpnts wall_velocity, reference_velocity;
2691 wall_velocity.
x = wall_velocity.
y = wall_velocity.
z = 0.0;
2692 reference_velocity = velocity_cartesian[second_interior_cell][j][i];
2694 noslip(user, distance_to_second_cell, distance_to_first_cell,
2695 wall_velocity, reference_velocity,
2696 &velocity_cartesian[first_interior_cell][j][i],
2697 wall_normal[0], wall_normal[1], wall_normal[2]);
2700 distance_to_second_cell, distance_to_first_cell,
2701 wall_velocity, reference_velocity,
2702 &velocity_cartesian[first_interior_cell][j][i],
2703 &friction_velocity[first_interior_cell][j][i],
2704 wall_normal[0], wall_normal[1], wall_normal[2]);
2706 velocity_boundary[ghost_cell_index][j][i].
x = 0.0;
2707 velocity_boundary[ghost_cell_index][j][i].
y = 0.0;
2708 velocity_boundary[ghost_cell_index][j][i].
z = 0.0;
2709 velocity_contravariant[ghost_cell_index][j][i].
z = 0.0;
2720 if (grid_end_k == grid_size_k) {
2721 const PetscInt ghost_cell_index = grid_end_k - 1;
2722 const PetscInt first_interior_cell = grid_end_k - 2;
2723 const PetscInt second_interior_cell = grid_end_k - 3;
2725 for (PetscInt j = loop_start_j; j < loop_end_j; j++) {
2726 for (PetscInt i = loop_start_i; i < loop_end_i; i++) {
2728 if (node_vertex_flag[first_interior_cell][j][i] < 0.1) {
2730 PetscReal face_area = sqrt(
2731 zet[first_interior_cell][j][i].x * zet[first_interior_cell][j][i].x +
2732 zet[first_interior_cell][j][i].y * zet[first_interior_cell][j][i].y +
2733 zet[first_interior_cell][j][i].z * zet[first_interior_cell][j][i].z
2736 PetscReal distance_to_first_cell = 0.5 / cell_jacobian[first_interior_cell][j][i] / face_area;
2737 PetscReal distance_to_second_cell = 2.0 * distance_to_first_cell +
2738 0.5 / cell_jacobian[second_interior_cell][j][i] / face_area;
2740 PetscReal wall_normal[3];
2741 wall_normal[0] = -zet[first_interior_cell][j][i].
x / face_area;
2742 wall_normal[1] = -zet[first_interior_cell][j][i].
y / face_area;
2743 wall_normal[2] = -zet[first_interior_cell][j][i].
z / face_area;
2745 Cmpnts wall_velocity, reference_velocity;
2746 wall_velocity.
x = wall_velocity.
y = wall_velocity.
z = 0.0;
2747 reference_velocity = velocity_cartesian[second_interior_cell][j][i];
2749 noslip(user, distance_to_second_cell, distance_to_first_cell,
2750 wall_velocity, reference_velocity,
2751 &velocity_cartesian[first_interior_cell][j][i],
2752 wall_normal[0], wall_normal[1], wall_normal[2]);
2755 distance_to_second_cell, distance_to_first_cell,
2756 wall_velocity, reference_velocity,
2757 &velocity_cartesian[first_interior_cell][j][i],
2758 &friction_velocity[first_interior_cell][j][i],
2759 wall_normal[0], wall_normal[1], wall_normal[2]);
2761 velocity_boundary[ghost_cell_index][j][i].
x = 0.0;
2762 velocity_boundary[ghost_cell_index][j][i].
y = 0.0;
2763 velocity_boundary[ghost_cell_index][j][i].
z = 0.0;
2764 velocity_contravariant[first_interior_cell][j][i].
z = 0.0;
2776 ierr = DMDAVecRestoreArray(user->
fda, user->
Ucat, &velocity_cartesian); CHKERRQ(ierr);
2777 ierr = DMDAVecRestoreArray(user->
fda, user->
Ucont, &velocity_contravariant); CHKERRQ(ierr);
2778 ierr = DMDAVecRestoreArray(user->
fda, user->
Bcs.
Ubcs, &velocity_boundary); CHKERRQ(ierr);
2779 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lCsi, (
const Cmpnts***)&csi); CHKERRQ(ierr);
2780 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lEta, (
const Cmpnts***)&eta); CHKERRQ(ierr);
2781 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lZet, (
const Cmpnts***)&zet); CHKERRQ(ierr);
2782 ierr = DMDAVecRestoreArrayRead(user->
da, user->
lNvert, (
const PetscReal***)&node_vertex_flag); CHKERRQ(ierr);
2783 ierr = DMDAVecRestoreArrayRead(user->
da, user->
lAj, (
const PetscReal***)&cell_jacobian); CHKERRQ(ierr);
2784 ierr = DMDAVecRestoreArray(user->
da, user->
lFriction_Velocity, &friction_velocity); CHKERRQ(ierr);
2788 PetscFunctionReturn(0);