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);
1060 PetscErrorCode ierr;
1061 PetscFunctionBeginUser;
1070 PetscReal local_inflow_pre = 0.0;
1071 PetscReal local_inflow_post = 0.0;
1072 PetscReal global_inflow_pre = 0.0;
1073 PetscReal global_inflow_post = 0.0;
1074 PetscInt num_handlers[3] = {0,0,0};
1079 for (
int i = 0; i < 6; i++) {
1082 if (!handler->
PreStep)
continue;
1088 .global_inflow_sum = NULL,
1089 .global_outflow_sum = NULL,
1095 ierr = handler->
PreStep(handler, &ctx, &local_inflow_pre, NULL); CHKERRQ(ierr);
1099 if (local_inflow_pre != 0.0) {
1100 ierr = MPI_Allreduce(&local_inflow_pre, &global_inflow_pre, 1, MPIU_REAL,
1101 MPI_SUM, PETSC_COMM_WORLD); CHKERRQ(ierr);
1106 for (
int i = 0; i < 6; i++) {
1109 if(!handler->
Apply)
continue;
1116 .global_inflow_sum = NULL,
1117 .global_outflow_sum = NULL,
1123 ierr = handler->
Apply(handler, &ctx); CHKERRQ(ierr);
1127 for (
int i = 0; i < 6; i++) {
1137 .global_inflow_sum = NULL,
1138 .global_outflow_sum = NULL,
1144 ierr = handler->
PostStep(handler, &ctx, &local_inflow_post, NULL); CHKERRQ(ierr);
1148 ierr = MPI_Allreduce(&local_inflow_post, &global_inflow_post, 1, MPIU_REAL,
1149 MPI_SUM, PETSC_COMM_WORLD); CHKERRQ(ierr);
1155 " (INLETS): %d Prestep(s), %d Application(s), %d Poststep(s), FluxInSum = %.6e\n",
1156 num_handlers[0],num_handlers[1],num_handlers[2], global_inflow_post);
1162 PetscReal local_farfield_in_pre = 0.0;
1163 PetscReal local_farfield_out_pre = 0.0;
1164 PetscReal local_farfield_in_post = 0.0;
1165 PetscReal local_farfield_out_post = 0.0;
1166 PetscReal global_farfield_in_pre = 0.0;
1167 PetscReal global_farfield_out_pre = 0.0;
1168 PetscReal global_farfield_in_post = 0.0;
1169 PetscReal global_farfield_out_post = 0.0;
1170 memset(num_handlers,0,
sizeof(num_handlers));
1175 for (
int i = 0; i < 6; i++) {
1178 if (!handler->
PreStep)
continue;
1185 .global_outflow_sum = NULL,
1191 ierr = handler->
PreStep(handler, &ctx, &local_farfield_in_pre, &local_farfield_out_pre);
1196 if (local_farfield_in_pre != 0.0 || local_farfield_out_pre != 0.0) {
1197 ierr = MPI_Allreduce(&local_farfield_in_pre, &global_farfield_in_pre, 1, MPIU_REAL,
1198 MPI_SUM, PETSC_COMM_WORLD); CHKERRQ(ierr);
1199 ierr = MPI_Allreduce(&local_farfield_out_pre, &global_farfield_out_pre, 1, MPIU_REAL,
1200 MPI_SUM, PETSC_COMM_WORLD); CHKERRQ(ierr);
1203 " Farfield pre-analysis: In=%.6e, Out=%.6e\n",
1204 global_farfield_in_pre, global_farfield_out_pre);
1208 for (
int i = 0; i < 6; i++) {
1211 if(!handler->
Apply)
continue;
1219 .global_outflow_sum = NULL,
1225 ierr = handler->
Apply(handler, &ctx); CHKERRQ(ierr);
1229 for (
int i = 0; i < 6; i++) {
1240 .global_outflow_sum = NULL,
1246 ierr = handler->
PostStep(handler, &ctx, &local_farfield_in_post, &local_farfield_out_post);
1251 if (num_handlers > 0) {
1252 ierr = MPI_Allreduce(&local_farfield_in_post, &global_farfield_in_post, 1, MPIU_REAL,
1253 MPI_SUM, PETSC_COMM_WORLD); CHKERRQ(ierr);
1254 ierr = MPI_Allreduce(&local_farfield_out_post, &global_farfield_out_post, 1, MPIU_REAL,
1255 MPI_SUM, PETSC_COMM_WORLD); CHKERRQ(ierr);
1262 " (FARFIELD): %d Prestep(s), %d Application(s), %d Poststep(s) , InFlux=%.6e, OutFlux=%.6e\n",
1263 num_handlers[0],num_handlers[1],num_handlers[2], global_farfield_in_post, global_farfield_out_post);
1275 memset(num_handlers,0,
sizeof(num_handlers));
1280 for (
int i = 0; i < 6; i++) {
1283 if (!handler->
PreStep)
continue;
1290 .global_outflow_sum = NULL,
1296 ierr = handler->
PreStep(handler, &ctx, NULL, NULL); CHKERRQ(ierr);
1302 for (
int i = 0; i < 6; i++) {
1305 if(!handler->
Apply)
continue;
1313 .global_outflow_sum = NULL,
1319 ierr = handler->
Apply(handler, &ctx); CHKERRQ(ierr);
1323 for (
int i = 0; i < 6; i++) {
1334 .global_outflow_sum = NULL,
1340 ierr = handler->
PostStep(handler, &ctx, NULL, NULL); CHKERRQ(ierr);
1346 num_handlers[0],num_handlers[1],num_handlers[2]);
1353 PetscReal local_outflow_pre = 0.0;
1354 PetscReal local_outflow_post = 0.0;
1355 PetscReal global_outflow_pre = 0.0;
1356 PetscReal global_outflow_post = 0.0;
1357 memset(num_handlers,0,
sizeof(num_handlers));
1362 for (
int i = 0; i < 6; i++) {
1365 if (!handler->
PreStep)
continue;
1372 .global_outflow_sum = NULL,
1378 ierr = handler->
PreStep(handler, &ctx, NULL, &local_outflow_pre); CHKERRQ(ierr);
1382 ierr = MPI_Allreduce(&local_outflow_pre, &global_outflow_pre, 1, MPIU_REAL,
1383 MPI_SUM, PETSC_COMM_WORLD); CHKERRQ(ierr);
1389 " Uncorrected outflow: %.6e, Total inflow: %.6e (Inlet: %.6e + Farfield: %.6e)\n",
1394 for (
int i = 0; i < 6; i++) {
1397 if(!handler->
Apply)
continue;
1405 .global_outflow_sum = &global_outflow_pre,
1411 ierr = handler->
Apply(handler, &ctx); CHKERRQ(ierr);
1415 for (
int i = 0; i < 6; i++) {
1426 .global_outflow_sum = &global_outflow_pre,
1432 ierr = handler->
PostStep(handler, &ctx, NULL, &local_outflow_post); CHKERRQ(ierr);
1436 ierr = MPI_Allreduce(&local_outflow_post, &global_outflow_post, 1, MPIU_REAL,
1437 MPI_SUM, PETSC_COMM_WORLD); CHKERRQ(ierr);
1444 PetscReal flux_error = PetscAbsReal(total_outflow - total_inflow);
1445 PetscReal relative_error = (total_inflow > 1e-16) ?
1446 flux_error / total_inflow : flux_error;
1449 " (OUTLETS): %d Prestep(s), %d Application(s), %d Poststep(s), FluxOutSum = %.6e\n",
1450 num_handlers[0],num_handlers[1],num_handlers[2], global_outflow_post);
1452 " Conservation: Total In=%.6e, Total Out=%.6e, Error=%.3e (%.2e)%%)\n",
1453 total_inflow, total_outflow, flux_error, relative_error * 100.0);
1455 if (relative_error > 1e-6) {
1457 " WARNING: Large mass conservation error (%.2e%%)!\n",
1458 relative_error * 100.0);
1465 PetscFunctionReturn(0);
2158 PetscErrorCode ierr;
2159 DM da = user->
da, fda = user->
fda;
2160 DMDALocalInfo info = user->
info;
2161 PetscInt xs = info.xs, xe = info.xs + info.xm;
2162 PetscInt ys = info.ys, ye = info.ys + info.ym;
2163 PetscInt zs = info.zs, ze = info.zs + info.zm;
2164 PetscInt mx = info.mx, my = info.my, mz = info.mz;
2169 PetscFunctionBeginUser;
2171 ierr = DMDAVecGetArray(fda, user->
Ucat, &ucat); CHKERRQ(ierr);
2172 ierr = DMDAVecGetArray(da, user->
P, &p); CHKERRQ(ierr);
2180 for (PetscInt j = ys; j < ye; j++) {
2181 p[zs][j][xs] = 0.5 * (p[zs+1][j][xs] + p[zs][j][xs+1]);
2182 ucat[zs][j][xs].
x = 0.5 * (ucat[zs+1][j][xs].
x + ucat[zs][j][xs+1].
x);
2183 ucat[zs][j][xs].
y = 0.5 * (ucat[zs+1][j][xs].
y + ucat[zs][j][xs+1].
y);
2184 ucat[zs][j][xs].
z = 0.5 * (ucat[zs+1][j][xs].
z + ucat[zs][j][xs+1].
z);
2188 for (PetscInt j = ys; j < ye; j++) {
2189 p[zs][j][mx-1] = 0.5 * (p[zs+1][j][mx-1] + p[zs][j][mx-2]);
2190 ucat[zs][j][mx-1].
x = 0.5 * (ucat[zs+1][j][mx-1].
x + ucat[zs][j][mx-2].
x);
2191 ucat[zs][j][mx-1].
y = 0.5 * (ucat[zs+1][j][mx-1].
y + ucat[zs][j][mx-2].
y);
2192 ucat[zs][j][mx-1].
z = 0.5 * (ucat[zs+1][j][mx-1].
z + ucat[zs][j][mx-2].
z);
2196 for (PetscInt i = xs; i < xe; i++) {
2197 p[zs][ys][i] = 0.5 * (p[zs+1][ys][i] + p[zs][ys+1][i]);
2198 ucat[zs][ys][i].
x = 0.5 * (ucat[zs+1][ys][i].
x + ucat[zs][ys+1][i].
x);
2199 ucat[zs][ys][i].
y = 0.5 * (ucat[zs+1][ys][i].
y + ucat[zs][ys+1][i].
y);
2200 ucat[zs][ys][i].
z = 0.5 * (ucat[zs+1][ys][i].
z + ucat[zs][ys+1][i].
z);
2204 for (PetscInt i = xs; i < xe; i++) {
2205 p[zs][my-1][i] = 0.5 * (p[zs+1][my-1][i] + p[zs][my-2][i]);
2206 ucat[zs][my-1][i].
x = 0.5 * (ucat[zs+1][my-1][i].
x + ucat[zs][my-2][i].
x);
2207 ucat[zs][my-1][i].
y = 0.5 * (ucat[zs+1][my-1][i].
y + ucat[zs][my-2][i].
y);
2208 ucat[zs][my-1][i].
z = 0.5 * (ucat[zs+1][my-1][i].
z + ucat[zs][my-2][i].
z);
2216 for (PetscInt j = ys; j < ye; j++) {
2217 p[mz-1][j][xs] = 0.5 * (p[mz-2][j][xs] + p[mz-1][j][xs+1]);
2218 ucat[mz-1][j][xs].
x = 0.5 * (ucat[mz-2][j][xs].
x + ucat[mz-1][j][xs+1].
x);
2219 ucat[mz-1][j][xs].
y = 0.5 * (ucat[mz-2][j][xs].
y + ucat[mz-1][j][xs+1].
y);
2220 ucat[mz-1][j][xs].
z = 0.5 * (ucat[mz-2][j][xs].
z + ucat[mz-1][j][xs+1].
z);
2224 for (PetscInt j = ys; j < ye; j++) {
2225 p[mz-1][j][mx-1] = 0.5 * (p[mz-2][j][mx-1] + p[mz-1][j][mx-2]);
2226 ucat[mz-1][j][mx-1].
x = 0.5 * (ucat[mz-2][j][mx-1].
x + ucat[mz-1][j][mx-2].
x);
2227 ucat[mz-1][j][mx-1].
y = 0.5 * (ucat[mz-2][j][mx-1].
y + ucat[mz-1][j][mx-2].
y);
2228 ucat[mz-1][j][mx-1].
z = 0.5 * (ucat[mz-2][j][mx-1].
z + ucat[mz-1][j][mx-2].
z);
2232 for (PetscInt i = xs; i < xe; i++) {
2233 p[mz-1][ys][i] = 0.5 * (p[mz-2][ys][i] + p[mz-1][ys+1][i]);
2234 ucat[mz-1][ys][i].
x = 0.5 * (ucat[mz-2][ys][i].
x + ucat[mz-1][ys+1][i].
x);
2235 ucat[mz-1][ys][i].
y = 0.5 * (ucat[mz-2][ys][i].
y + ucat[mz-1][ys+1][i].
y);
2236 ucat[mz-1][ys][i].
z = 0.5 * (ucat[mz-2][ys][i].
z + ucat[mz-1][ys+1][i].
z);
2240 for (PetscInt i = xs; i < xe; i++) {
2241 p[mz-1][my-1][i] = 0.5 * (p[mz-2][my-1][i] + p[mz-1][my-2][i]);
2242 ucat[mz-1][my-1][i].
x = 0.5 * (ucat[mz-2][my-1][i].
x + ucat[mz-1][my-2][i].
x);
2243 ucat[mz-1][my-1][i].
y = 0.5 * (ucat[mz-2][my-1][i].
y + ucat[mz-1][my-2][i].
y);
2244 ucat[mz-1][my-1][i].
z = 0.5 * (ucat[mz-2][my-1][i].
z + ucat[mz-1][my-2][i].
z);
2252 for (PetscInt k = zs; k < ze; k++) {
2253 p[k][ys][xs] = 0.5 * (p[k][ys+1][xs] + p[k][ys][xs+1]);
2254 ucat[k][ys][xs].
x = 0.5 * (ucat[k][ys+1][xs].
x + ucat[k][ys][xs+1].
x);
2255 ucat[k][ys][xs].
y = 0.5 * (ucat[k][ys+1][xs].
y + ucat[k][ys][xs+1].
y);
2256 ucat[k][ys][xs].
z = 0.5 * (ucat[k][ys+1][xs].
z + ucat[k][ys][xs+1].
z);
2260 for (PetscInt k = zs; k < ze; k++) {
2261 p[k][ys][mx-1] = 0.5 * (p[k][ys+1][mx-1] + p[k][ys][mx-2]);
2262 ucat[k][ys][mx-1].
x = 0.5 * (ucat[k][ys+1][mx-1].
x + ucat[k][ys][mx-2].
x);
2263 ucat[k][ys][mx-1].
y = 0.5 * (ucat[k][ys+1][mx-1].
y + ucat[k][ys][mx-2].
y);
2264 ucat[k][ys][mx-1].
z = 0.5 * (ucat[k][ys+1][mx-1].
z + ucat[k][ys][mx-2].
z);
2271 for (PetscInt k = zs; k < ze; k++) {
2272 p[k][my-1][xs] = 0.5 * (p[k][my-2][xs] + p[k][my-1][xs+1]);
2273 ucat[k][my-1][xs].
x = 0.5 * (ucat[k][my-2][xs].
x + ucat[k][my-1][xs+1].
x);
2274 ucat[k][my-1][xs].
y = 0.5 * (ucat[k][my-2][xs].
y + ucat[k][my-1][xs+1].
y);
2275 ucat[k][my-1][xs].
z = 0.5 * (ucat[k][my-2][xs].
z + ucat[k][my-1][xs+1].
z);
2279 for (PetscInt k = zs; k < ze; k++) {
2280 p[k][my-1][mx-1] = 0.5 * (p[k][my-2][mx-1] + p[k][my-1][mx-2]);
2281 ucat[k][my-1][mx-1].
x = 0.5 * (ucat[k][my-2][mx-1].
x + ucat[k][my-1][mx-2].
x);
2282 ucat[k][my-1][mx-1].
y = 0.5 * (ucat[k][my-2][mx-1].
y + ucat[k][my-1][mx-2].
y);
2283 ucat[k][my-1][mx-1].
z = 0.5 * (ucat[k][my-2][mx-1].
z + ucat[k][my-1][mx-2].
z);
2288 ierr = DMDAVecRestoreArray(fda, user->
Ucat, &ucat); CHKERRQ(ierr);
2289 ierr = DMDAVecRestoreArray(da, user->
P, &p); CHKERRQ(ierr);
2291 PetscFunctionReturn(0);
2345 PetscErrorCode ierr;
2347 DMDALocalInfo *info = &user->
info;
2349 PetscFunctionBeginUser;
2355 PetscFunctionReturn(0);
2363 Cmpnts ***velocity_cartesian;
2364 Cmpnts ***velocity_contravariant;
2365 Cmpnts ***velocity_boundary;
2366 Cmpnts ***csi, ***eta, ***zet;
2367 PetscReal ***node_vertex_flag;
2368 PetscReal ***cell_jacobian;
2369 PetscReal ***friction_velocity;
2371 ierr = DMDAVecGetArray(user->
fda, user->
Ucat, &velocity_cartesian); CHKERRQ(ierr);
2372 ierr = DMDAVecGetArray(user->
fda, user->
Ucont, &velocity_contravariant); CHKERRQ(ierr);
2373 ierr = DMDAVecGetArray(user->
fda, user->
Bcs.
Ubcs, &velocity_boundary); CHKERRQ(ierr);
2374 ierr = DMDAVecGetArrayRead(user->
fda, user->
lCsi, (
const Cmpnts***)&csi); CHKERRQ(ierr);
2375 ierr = DMDAVecGetArrayRead(user->
fda, user->
lEta, (
const Cmpnts***)&eta); CHKERRQ(ierr);
2376 ierr = DMDAVecGetArrayRead(user->
fda, user->
lZet, (
const Cmpnts***)&zet); CHKERRQ(ierr);
2377 ierr = DMDAVecGetArrayRead(user->
da, user->
lNvert, (
const PetscReal***)&node_vertex_flag); CHKERRQ(ierr);
2378 ierr = DMDAVecGetArrayRead(user->
da, user->
lAj, (
const PetscReal***)&cell_jacobian); CHKERRQ(ierr);
2384 PetscInt grid_start_i = info->xs, grid_end_i = info->xs + info->xm;
2385 PetscInt grid_start_j = info->ys, grid_end_j = info->ys + info->ym;
2386 PetscInt grid_start_k = info->zs, grid_end_k = info->zs + info->zm;
2387 PetscInt grid_size_i = info->mx, grid_size_j = info->my, grid_size_k = info->mz;
2390 PetscInt loop_start_i = grid_start_i, loop_end_i = grid_end_i;
2391 PetscInt loop_start_j = grid_start_j, loop_end_j = grid_end_j;
2392 PetscInt loop_start_k = grid_start_k, loop_end_k = grid_end_k;
2394 if (grid_start_i == 0) loop_start_i = grid_start_i + 1;
2395 if (grid_end_i == grid_size_i) loop_end_i = grid_end_i - 1;
2396 if (grid_start_j == 0) loop_start_j = grid_start_j + 1;
2397 if (grid_end_j == grid_size_j) loop_end_j = grid_end_j - 1;
2398 if (grid_start_k == 0) loop_start_k = grid_start_k + 1;
2399 if (grid_end_k == grid_size_k) loop_end_k = grid_end_k - 1;
2402 const PetscReal wall_roughness_height = 1.e-16;
2407 for (
int face_index = 0; face_index < 6; face_index++) {
2417 PetscBool rank_owns_this_face;
2419 current_face_id, &rank_owns_this_face); CHKERRQ(ierr);
2421 if (!rank_owns_this_face) {
2431 switch(current_face_id) {
2437 if (grid_start_i == 0) {
2438 const PetscInt ghost_cell_index = grid_start_i;
2439 const PetscInt first_interior_cell = grid_start_i + 1;
2440 const PetscInt second_interior_cell = grid_start_i + 2;
2442 for (PetscInt k = loop_start_k; k < loop_end_k; k++) {
2443 for (PetscInt j = loop_start_j; j < loop_end_j; j++) {
2446 if (node_vertex_flag[k][j][first_interior_cell] < 0.1) {
2449 PetscReal face_area = sqrt(
2450 csi[k][j][ghost_cell_index].x * csi[k][j][ghost_cell_index].x +
2451 csi[k][j][ghost_cell_index].y * csi[k][j][ghost_cell_index].y +
2452 csi[k][j][ghost_cell_index].z * csi[k][j][ghost_cell_index].z
2458 PetscReal distance_to_first_cell = 0.5 / cell_jacobian[k][j][first_interior_cell] / face_area;
2459 PetscReal distance_to_second_cell = 2.0 * distance_to_first_cell +
2460 0.5 / cell_jacobian[k][j][second_interior_cell] / face_area;
2463 PetscReal wall_normal[3];
2464 wall_normal[0] = csi[k][j][ghost_cell_index].
x / face_area;
2465 wall_normal[1] = csi[k][j][ghost_cell_index].
y / face_area;
2466 wall_normal[2] = csi[k][j][ghost_cell_index].
z / face_area;
2470 Cmpnts reference_velocity;
2472 wall_velocity.
x = wall_velocity.
y = wall_velocity.
z = 0.0;
2473 reference_velocity = velocity_cartesian[k][j][second_interior_cell];
2476 noslip(user, distance_to_second_cell, distance_to_first_cell,
2477 wall_velocity, reference_velocity,
2478 &velocity_cartesian[k][j][first_interior_cell],
2479 wall_normal[0], wall_normal[1], wall_normal[2]);
2483 distance_to_second_cell, distance_to_first_cell,
2484 wall_velocity, reference_velocity,
2485 &velocity_cartesian[k][j][first_interior_cell],
2486 &friction_velocity[k][j][first_interior_cell],
2487 wall_normal[0], wall_normal[1], wall_normal[2]);
2490 velocity_boundary[k][j][ghost_cell_index].
x = 0.0;
2491 velocity_boundary[k][j][ghost_cell_index].
y = 0.0;
2492 velocity_boundary[k][j][ghost_cell_index].
z = 0.0;
2493 velocity_contravariant[k][j][ghost_cell_index].
x = 0.0;
2504 if (grid_end_i == grid_size_i) {
2505 const PetscInt ghost_cell_index = grid_end_i - 1;
2506 const PetscInt first_interior_cell = grid_end_i - 2;
2507 const PetscInt second_interior_cell = grid_end_i - 3;
2509 for (PetscInt k = loop_start_k; k < loop_end_k; k++) {
2510 for (PetscInt j = loop_start_j; j < loop_end_j; j++) {
2512 if (node_vertex_flag[k][j][first_interior_cell] < 0.1) {
2514 PetscReal face_area = sqrt(
2515 csi[k][j][first_interior_cell].x * csi[k][j][first_interior_cell].x +
2516 csi[k][j][first_interior_cell].y * csi[k][j][first_interior_cell].y +
2517 csi[k][j][first_interior_cell].z * csi[k][j][first_interior_cell].z
2520 PetscReal distance_to_first_cell = 0.5 / cell_jacobian[k][j][first_interior_cell] / face_area;
2521 PetscReal distance_to_second_cell = 2.0 * distance_to_first_cell +
2522 0.5 / cell_jacobian[k][j][second_interior_cell] / face_area;
2525 PetscReal wall_normal[3];
2526 wall_normal[0] = -csi[k][j][first_interior_cell].
x / face_area;
2527 wall_normal[1] = -csi[k][j][first_interior_cell].
y / face_area;
2528 wall_normal[2] = -csi[k][j][first_interior_cell].
z / face_area;
2530 Cmpnts wall_velocity, reference_velocity;
2531 wall_velocity.
x = wall_velocity.
y = wall_velocity.
z = 0.0;
2532 reference_velocity = velocity_cartesian[k][j][second_interior_cell];
2534 noslip(user, distance_to_second_cell, distance_to_first_cell,
2535 wall_velocity, reference_velocity,
2536 &velocity_cartesian[k][j][first_interior_cell],
2537 wall_normal[0], wall_normal[1], wall_normal[2]);
2540 distance_to_second_cell, distance_to_first_cell,
2541 wall_velocity, reference_velocity,
2542 &velocity_cartesian[k][j][first_interior_cell],
2543 &friction_velocity[k][j][first_interior_cell],
2544 wall_normal[0], wall_normal[1], wall_normal[2]);
2546 velocity_boundary[k][j][ghost_cell_index].
x = 0.0;
2547 velocity_boundary[k][j][ghost_cell_index].
y = 0.0;
2548 velocity_boundary[k][j][ghost_cell_index].
z = 0.0;
2549 velocity_contravariant[k][j][first_interior_cell].
x = 0.0;
2560 if (grid_start_j == 0) {
2561 const PetscInt ghost_cell_index = grid_start_j;
2562 const PetscInt first_interior_cell = grid_start_j + 1;
2563 const PetscInt second_interior_cell = grid_start_j + 2;
2565 for (PetscInt k = loop_start_k; k < loop_end_k; k++) {
2566 for (PetscInt i = loop_start_i; i < loop_end_i; i++) {
2568 if (node_vertex_flag[k][first_interior_cell][i] < 0.1) {
2570 PetscReal face_area = sqrt(
2571 eta[k][ghost_cell_index][i].x * eta[k][ghost_cell_index][i].x +
2572 eta[k][ghost_cell_index][i].y * eta[k][ghost_cell_index][i].y +
2573 eta[k][ghost_cell_index][i].z * eta[k][ghost_cell_index][i].z
2576 PetscReal distance_to_first_cell = 0.5 / cell_jacobian[k][first_interior_cell][i] / face_area;
2577 PetscReal distance_to_second_cell = 2.0 * distance_to_first_cell +
2578 0.5 / cell_jacobian[k][second_interior_cell][i] / face_area;
2580 PetscReal wall_normal[3];
2581 wall_normal[0] = eta[k][ghost_cell_index][i].
x / face_area;
2582 wall_normal[1] = eta[k][ghost_cell_index][i].
y / face_area;
2583 wall_normal[2] = eta[k][ghost_cell_index][i].
z / face_area;
2585 Cmpnts wall_velocity, reference_velocity;
2586 wall_velocity.
x = wall_velocity.
y = wall_velocity.
z = 0.0;
2587 reference_velocity = velocity_cartesian[k][second_interior_cell][i];
2589 noslip(user, distance_to_second_cell, distance_to_first_cell,
2590 wall_velocity, reference_velocity,
2591 &velocity_cartesian[k][first_interior_cell][i],
2592 wall_normal[0], wall_normal[1], wall_normal[2]);
2595 distance_to_second_cell, distance_to_first_cell,
2596 wall_velocity, reference_velocity,
2597 &velocity_cartesian[k][first_interior_cell][i],
2598 &friction_velocity[k][first_interior_cell][i],
2599 wall_normal[0], wall_normal[1], wall_normal[2]);
2601 velocity_boundary[k][ghost_cell_index][i].
x = 0.0;
2602 velocity_boundary[k][ghost_cell_index][i].
y = 0.0;
2603 velocity_boundary[k][ghost_cell_index][i].
z = 0.0;
2604 velocity_contravariant[k][ghost_cell_index][i].
y = 0.0;
2615 if (grid_end_j == grid_size_j) {
2616 const PetscInt ghost_cell_index = grid_end_j - 1;
2617 const PetscInt first_interior_cell = grid_end_j - 2;
2618 const PetscInt second_interior_cell = grid_end_j - 3;
2620 for (PetscInt k = loop_start_k; k < loop_end_k; k++) {
2621 for (PetscInt i = loop_start_i; i < loop_end_i; i++) {
2623 if (node_vertex_flag[k][first_interior_cell][i] < 0.1) {
2625 PetscReal face_area = sqrt(
2626 eta[k][first_interior_cell][i].x * eta[k][first_interior_cell][i].x +
2627 eta[k][first_interior_cell][i].y * eta[k][first_interior_cell][i].y +
2628 eta[k][first_interior_cell][i].z * eta[k][first_interior_cell][i].z
2631 PetscReal distance_to_first_cell = 0.5 / cell_jacobian[k][first_interior_cell][i] / face_area;
2632 PetscReal distance_to_second_cell = 2.0 * distance_to_first_cell +
2633 0.5 / cell_jacobian[k][second_interior_cell][i] / face_area;
2635 PetscReal wall_normal[3];
2636 wall_normal[0] = -eta[k][first_interior_cell][i].
x / face_area;
2637 wall_normal[1] = -eta[k][first_interior_cell][i].
y / face_area;
2638 wall_normal[2] = -eta[k][first_interior_cell][i].
z / face_area;
2640 Cmpnts wall_velocity, reference_velocity;
2641 wall_velocity.
x = wall_velocity.
y = wall_velocity.
z = 0.0;
2642 reference_velocity = velocity_cartesian[k][second_interior_cell][i];
2644 noslip(user, distance_to_second_cell, distance_to_first_cell,
2645 wall_velocity, reference_velocity,
2646 &velocity_cartesian[k][first_interior_cell][i],
2647 wall_normal[0], wall_normal[1], wall_normal[2]);
2650 distance_to_second_cell, distance_to_first_cell,
2651 wall_velocity, reference_velocity,
2652 &velocity_cartesian[k][first_interior_cell][i],
2653 &friction_velocity[k][first_interior_cell][i],
2654 wall_normal[0], wall_normal[1], wall_normal[2]);
2656 velocity_boundary[k][ghost_cell_index][i].
x = 0.0;
2657 velocity_boundary[k][ghost_cell_index][i].
y = 0.0;
2658 velocity_boundary[k][ghost_cell_index][i].
z = 0.0;
2659 velocity_contravariant[k][first_interior_cell][i].
y = 0.0;
2670 if (grid_start_k == 0) {
2671 const PetscInt ghost_cell_index = grid_start_k;
2672 const PetscInt first_interior_cell = grid_start_k + 1;
2673 const PetscInt second_interior_cell = grid_start_k + 2;
2675 for (PetscInt j = loop_start_j; j < loop_end_j; j++) {
2676 for (PetscInt i = loop_start_i; i < loop_end_i; i++) {
2678 if (node_vertex_flag[first_interior_cell][j][i] < 0.1) {
2680 PetscReal face_area = sqrt(
2681 zet[ghost_cell_index][j][i].x * zet[ghost_cell_index][j][i].x +
2682 zet[ghost_cell_index][j][i].y * zet[ghost_cell_index][j][i].y +
2683 zet[ghost_cell_index][j][i].z * zet[ghost_cell_index][j][i].z
2686 PetscReal distance_to_first_cell = 0.5 / cell_jacobian[first_interior_cell][j][i] / face_area;
2687 PetscReal distance_to_second_cell = 2.0 * distance_to_first_cell +
2688 0.5 / cell_jacobian[second_interior_cell][j][i] / face_area;
2690 PetscReal wall_normal[3];
2691 wall_normal[0] = zet[ghost_cell_index][j][i].
x / face_area;
2692 wall_normal[1] = zet[ghost_cell_index][j][i].
y / face_area;
2693 wall_normal[2] = zet[ghost_cell_index][j][i].
z / face_area;
2695 Cmpnts wall_velocity, reference_velocity;
2696 wall_velocity.
x = wall_velocity.
y = wall_velocity.
z = 0.0;
2697 reference_velocity = velocity_cartesian[second_interior_cell][j][i];
2699 noslip(user, distance_to_second_cell, distance_to_first_cell,
2700 wall_velocity, reference_velocity,
2701 &velocity_cartesian[first_interior_cell][j][i],
2702 wall_normal[0], wall_normal[1], wall_normal[2]);
2705 distance_to_second_cell, distance_to_first_cell,
2706 wall_velocity, reference_velocity,
2707 &velocity_cartesian[first_interior_cell][j][i],
2708 &friction_velocity[first_interior_cell][j][i],
2709 wall_normal[0], wall_normal[1], wall_normal[2]);
2711 velocity_boundary[ghost_cell_index][j][i].
x = 0.0;
2712 velocity_boundary[ghost_cell_index][j][i].
y = 0.0;
2713 velocity_boundary[ghost_cell_index][j][i].
z = 0.0;
2714 velocity_contravariant[ghost_cell_index][j][i].
z = 0.0;
2725 if (grid_end_k == grid_size_k) {
2726 const PetscInt ghost_cell_index = grid_end_k - 1;
2727 const PetscInt first_interior_cell = grid_end_k - 2;
2728 const PetscInt second_interior_cell = grid_end_k - 3;
2730 for (PetscInt j = loop_start_j; j < loop_end_j; j++) {
2731 for (PetscInt i = loop_start_i; i < loop_end_i; i++) {
2733 if (node_vertex_flag[first_interior_cell][j][i] < 0.1) {
2735 PetscReal face_area = sqrt(
2736 zet[first_interior_cell][j][i].x * zet[first_interior_cell][j][i].x +
2737 zet[first_interior_cell][j][i].y * zet[first_interior_cell][j][i].y +
2738 zet[first_interior_cell][j][i].z * zet[first_interior_cell][j][i].z
2741 PetscReal distance_to_first_cell = 0.5 / cell_jacobian[first_interior_cell][j][i] / face_area;
2742 PetscReal distance_to_second_cell = 2.0 * distance_to_first_cell +
2743 0.5 / cell_jacobian[second_interior_cell][j][i] / face_area;
2745 PetscReal wall_normal[3];
2746 wall_normal[0] = -zet[first_interior_cell][j][i].
x / face_area;
2747 wall_normal[1] = -zet[first_interior_cell][j][i].
y / face_area;
2748 wall_normal[2] = -zet[first_interior_cell][j][i].
z / face_area;
2750 Cmpnts wall_velocity, reference_velocity;
2751 wall_velocity.
x = wall_velocity.
y = wall_velocity.
z = 0.0;
2752 reference_velocity = velocity_cartesian[second_interior_cell][j][i];
2754 noslip(user, distance_to_second_cell, distance_to_first_cell,
2755 wall_velocity, reference_velocity,
2756 &velocity_cartesian[first_interior_cell][j][i],
2757 wall_normal[0], wall_normal[1], wall_normal[2]);
2760 distance_to_second_cell, distance_to_first_cell,
2761 wall_velocity, reference_velocity,
2762 &velocity_cartesian[first_interior_cell][j][i],
2763 &friction_velocity[first_interior_cell][j][i],
2764 wall_normal[0], wall_normal[1], wall_normal[2]);
2766 velocity_boundary[ghost_cell_index][j][i].
x = 0.0;
2767 velocity_boundary[ghost_cell_index][j][i].
y = 0.0;
2768 velocity_boundary[ghost_cell_index][j][i].
z = 0.0;
2769 velocity_contravariant[first_interior_cell][j][i].
z = 0.0;
2781 ierr = DMDAVecRestoreArray(user->
fda, user->
Ucat, &velocity_cartesian); CHKERRQ(ierr);
2782 ierr = DMDAVecRestoreArray(user->
fda, user->
Ucont, &velocity_contravariant); CHKERRQ(ierr);
2783 ierr = DMDAVecRestoreArray(user->
fda, user->
Bcs.
Ubcs, &velocity_boundary); CHKERRQ(ierr);
2784 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lCsi, (
const Cmpnts***)&csi); CHKERRQ(ierr);
2785 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lEta, (
const Cmpnts***)&eta); CHKERRQ(ierr);
2786 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lZet, (
const Cmpnts***)&zet); CHKERRQ(ierr);
2787 ierr = DMDAVecRestoreArrayRead(user->
da, user->
lNvert, (
const PetscReal***)&node_vertex_flag); CHKERRQ(ierr);
2788 ierr = DMDAVecRestoreArrayRead(user->
da, user->
lAj, (
const PetscReal***)&cell_jacobian); CHKERRQ(ierr);
2789 ierr = DMDAVecRestoreArray(user->
da, user->
lFriction_Velocity, &friction_velocity); CHKERRQ(ierr);
2793 PetscFunctionReturn(0);