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);
1061 PetscErrorCode ierr;
1062 PetscFunctionBeginUser;
1071 PetscReal local_inflow_pre = 0.0;
1072 PetscReal local_inflow_post = 0.0;
1073 PetscReal global_inflow_pre = 0.0;
1074 PetscReal global_inflow_post = 0.0;
1075 PetscInt num_handlers[3] = {0,0,0};
1080 for (
int i = 0; i < 6; i++) {
1083 if (!handler->
PreStep)
continue;
1089 .global_inflow_sum = NULL,
1090 .global_outflow_sum = NULL,
1096 ierr = handler->
PreStep(handler, &ctx, &local_inflow_pre, NULL); CHKERRQ(ierr);
1100 if (local_inflow_pre != 0.0) {
1101 ierr = MPI_Allreduce(&local_inflow_pre, &global_inflow_pre, 1, MPIU_REAL,
1102 MPI_SUM, PETSC_COMM_WORLD); CHKERRQ(ierr);
1107 for (
int i = 0; i < 6; i++) {
1110 if(!handler->
Apply)
continue;
1117 .global_inflow_sum = NULL,
1118 .global_outflow_sum = NULL,
1124 ierr = handler->
Apply(handler, &ctx); CHKERRQ(ierr);
1128 for (
int i = 0; i < 6; i++) {
1138 .global_inflow_sum = NULL,
1139 .global_outflow_sum = NULL,
1145 ierr = handler->
PostStep(handler, &ctx, &local_inflow_post, NULL); CHKERRQ(ierr);
1149 ierr = MPI_Allreduce(&local_inflow_post, &global_inflow_post, 1, MPIU_REAL,
1150 MPI_SUM, PETSC_COMM_WORLD); CHKERRQ(ierr);
1156 " (INLETS): %d Prestep(s), %d Application(s), %d Poststep(s), FluxInSum = %.6e\n",
1157 num_handlers[0],num_handlers[1],num_handlers[2], global_inflow_post);
1163 PetscReal local_farfield_in_pre = 0.0;
1164 PetscReal local_farfield_out_pre = 0.0;
1165 PetscReal local_farfield_in_post = 0.0;
1166 PetscReal local_farfield_out_post = 0.0;
1167 PetscReal global_farfield_in_pre = 0.0;
1168 PetscReal global_farfield_out_pre = 0.0;
1169 PetscReal global_farfield_in_post = 0.0;
1170 PetscReal global_farfield_out_post = 0.0;
1171 memset(num_handlers,0,
sizeof(num_handlers));
1176 for (
int i = 0; i < 6; i++) {
1179 if (!handler->
PreStep)
continue;
1186 .global_outflow_sum = NULL,
1192 ierr = handler->
PreStep(handler, &ctx, &local_farfield_in_pre, &local_farfield_out_pre);
1197 if (local_farfield_in_pre != 0.0 || local_farfield_out_pre != 0.0) {
1198 ierr = MPI_Allreduce(&local_farfield_in_pre, &global_farfield_in_pre, 1, MPIU_REAL,
1199 MPI_SUM, PETSC_COMM_WORLD); CHKERRQ(ierr);
1200 ierr = MPI_Allreduce(&local_farfield_out_pre, &global_farfield_out_pre, 1, MPIU_REAL,
1201 MPI_SUM, PETSC_COMM_WORLD); CHKERRQ(ierr);
1204 " Farfield pre-analysis: In=%.6e, Out=%.6e\n",
1205 global_farfield_in_pre, global_farfield_out_pre);
1209 for (
int i = 0; i < 6; i++) {
1212 if(!handler->
Apply)
continue;
1220 .global_outflow_sum = NULL,
1226 ierr = handler->
Apply(handler, &ctx); CHKERRQ(ierr);
1230 for (
int i = 0; i < 6; i++) {
1241 .global_outflow_sum = NULL,
1247 ierr = handler->
PostStep(handler, &ctx, &local_farfield_in_post, &local_farfield_out_post);
1252 if (num_handlers > 0) {
1253 ierr = MPI_Allreduce(&local_farfield_in_post, &global_farfield_in_post, 1, MPIU_REAL,
1254 MPI_SUM, PETSC_COMM_WORLD); CHKERRQ(ierr);
1255 ierr = MPI_Allreduce(&local_farfield_out_post, &global_farfield_out_post, 1, MPIU_REAL,
1256 MPI_SUM, PETSC_COMM_WORLD); CHKERRQ(ierr);
1263 " (FARFIELD): %d Prestep(s), %d Application(s), %d Poststep(s) , InFlux=%.6e, OutFlux=%.6e\n",
1264 num_handlers[0],num_handlers[1],num_handlers[2], global_farfield_in_post, global_farfield_out_post);
1276 memset(num_handlers,0,
sizeof(num_handlers));
1281 for (
int i = 0; i < 6; i++) {
1284 if (!handler->
PreStep)
continue;
1291 .global_outflow_sum = NULL,
1297 ierr = handler->
PreStep(handler, &ctx, NULL, NULL); CHKERRQ(ierr);
1303 for (
int i = 0; i < 6; i++) {
1306 if(!handler->
Apply)
continue;
1314 .global_outflow_sum = NULL,
1320 ierr = handler->
Apply(handler, &ctx); CHKERRQ(ierr);
1324 for (
int i = 0; i < 6; i++) {
1335 .global_outflow_sum = NULL,
1341 ierr = handler->
PostStep(handler, &ctx, NULL, NULL); CHKERRQ(ierr);
1347 num_handlers[0],num_handlers[1],num_handlers[2]);
1354 PetscReal local_outflow_pre = 0.0;
1355 PetscReal local_outflow_post = 0.0;
1356 PetscReal global_outflow_pre = 0.0;
1357 PetscReal global_outflow_post = 0.0;
1358 memset(num_handlers,0,
sizeof(num_handlers));
1363 for (
int i = 0; i < 6; i++) {
1366 if (!handler->
PreStep)
continue;
1373 .global_outflow_sum = NULL,
1379 ierr = handler->
PreStep(handler, &ctx, NULL, &local_outflow_pre); CHKERRQ(ierr);
1383 ierr = MPI_Allreduce(&local_outflow_pre, &global_outflow_pre, 1, MPIU_REAL,
1384 MPI_SUM, PETSC_COMM_WORLD); CHKERRQ(ierr);
1390 " Uncorrected outflow: %.6e, Total inflow: %.6e (Inlet: %.6e + Farfield: %.6e)\n",
1395 for (
int i = 0; i < 6; i++) {
1398 if(!handler->
Apply)
continue;
1406 .global_outflow_sum = &global_outflow_pre,
1412 ierr = handler->
Apply(handler, &ctx); CHKERRQ(ierr);
1416 for (
int i = 0; i < 6; i++) {
1427 .global_outflow_sum = &global_outflow_pre,
1433 ierr = handler->
PostStep(handler, &ctx, NULL, &local_outflow_post); CHKERRQ(ierr);
1437 ierr = MPI_Allreduce(&local_outflow_post, &global_outflow_post, 1, MPIU_REAL,
1438 MPI_SUM, PETSC_COMM_WORLD); CHKERRQ(ierr);
1445 PetscReal flux_error = PetscAbsReal(total_outflow - total_inflow);
1446 PetscReal relative_error = (total_inflow > 1e-16) ?
1447 flux_error / total_inflow : flux_error;
1450 " (OUTLETS): %d Prestep(s), %d Application(s), %d Poststep(s), FluxOutSum = %.6e\n",
1451 num_handlers[0],num_handlers[1],num_handlers[2], global_outflow_post);
1453 " Conservation: Total In=%.6e, Total Out=%.6e, Error=%.3e (%.2e)%%)\n",
1454 total_inflow, total_outflow, flux_error, relative_error * 100.0);
1456 if (relative_error > 1e-6) {
1458 " WARNING: Large mass conservation error (%.2e%%)!\n",
1459 relative_error * 100.0);
1466 PetscFunctionReturn(0);
2612 PetscErrorCode ierr;
2613 DM da = user->
da, fda = user->
fda;
2614 DMDALocalInfo info = user->
info;
2615 PetscInt xs = info.xs, xe = info.xs + info.xm;
2616 PetscInt ys = info.ys, ye = info.ys + info.ym;
2617 PetscInt zs = info.zs, ze = info.zs + info.zm;
2618 PetscInt mx = info.mx, my = info.my, mz = info.mz;
2623 PetscFunctionBeginUser;
2625 ierr = DMDAVecGetArray(fda, user->
Ucat, &ucat); CHKERRQ(ierr);
2626 ierr = DMDAVecGetArray(da, user->
P, &p); CHKERRQ(ierr);
2634 for (PetscInt j = ys; j < ye; j++) {
2635 p[zs][j][xs] = 0.5 * (p[zs+1][j][xs] + p[zs][j][xs+1]);
2636 ucat[zs][j][xs].
x = 0.5 * (ucat[zs+1][j][xs].
x + ucat[zs][j][xs+1].
x);
2637 ucat[zs][j][xs].
y = 0.5 * (ucat[zs+1][j][xs].
y + ucat[zs][j][xs+1].
y);
2638 ucat[zs][j][xs].
z = 0.5 * (ucat[zs+1][j][xs].
z + ucat[zs][j][xs+1].
z);
2642 for (PetscInt j = ys; j < ye; j++) {
2643 p[zs][j][mx-1] = 0.5 * (p[zs+1][j][mx-1] + p[zs][j][mx-2]);
2644 ucat[zs][j][mx-1].
x = 0.5 * (ucat[zs+1][j][mx-1].
x + ucat[zs][j][mx-2].
x);
2645 ucat[zs][j][mx-1].
y = 0.5 * (ucat[zs+1][j][mx-1].
y + ucat[zs][j][mx-2].
y);
2646 ucat[zs][j][mx-1].
z = 0.5 * (ucat[zs+1][j][mx-1].
z + ucat[zs][j][mx-2].
z);
2650 for (PetscInt i = xs; i < xe; i++) {
2651 p[zs][ys][i] = 0.5 * (p[zs+1][ys][i] + p[zs][ys+1][i]);
2652 ucat[zs][ys][i].
x = 0.5 * (ucat[zs+1][ys][i].
x + ucat[zs][ys+1][i].
x);
2653 ucat[zs][ys][i].
y = 0.5 * (ucat[zs+1][ys][i].
y + ucat[zs][ys+1][i].
y);
2654 ucat[zs][ys][i].
z = 0.5 * (ucat[zs+1][ys][i].
z + ucat[zs][ys+1][i].
z);
2658 for (PetscInt i = xs; i < xe; i++) {
2659 p[zs][my-1][i] = 0.5 * (p[zs+1][my-1][i] + p[zs][my-2][i]);
2660 ucat[zs][my-1][i].
x = 0.5 * (ucat[zs+1][my-1][i].
x + ucat[zs][my-2][i].
x);
2661 ucat[zs][my-1][i].
y = 0.5 * (ucat[zs+1][my-1][i].
y + ucat[zs][my-2][i].
y);
2662 ucat[zs][my-1][i].
z = 0.5 * (ucat[zs+1][my-1][i].
z + ucat[zs][my-2][i].
z);
2670 for (PetscInt j = ys; j < ye; j++) {
2671 p[mz-1][j][xs] = 0.5 * (p[mz-2][j][xs] + p[mz-1][j][xs+1]);
2672 ucat[mz-1][j][xs].
x = 0.5 * (ucat[mz-2][j][xs].
x + ucat[mz-1][j][xs+1].
x);
2673 ucat[mz-1][j][xs].
y = 0.5 * (ucat[mz-2][j][xs].
y + ucat[mz-1][j][xs+1].
y);
2674 ucat[mz-1][j][xs].
z = 0.5 * (ucat[mz-2][j][xs].
z + ucat[mz-1][j][xs+1].
z);
2678 for (PetscInt j = ys; j < ye; j++) {
2679 p[mz-1][j][mx-1] = 0.5 * (p[mz-2][j][mx-1] + p[mz-1][j][mx-2]);
2680 ucat[mz-1][j][mx-1].
x = 0.5 * (ucat[mz-2][j][mx-1].
x + ucat[mz-1][j][mx-2].
x);
2681 ucat[mz-1][j][mx-1].
y = 0.5 * (ucat[mz-2][j][mx-1].
y + ucat[mz-1][j][mx-2].
y);
2682 ucat[mz-1][j][mx-1].
z = 0.5 * (ucat[mz-2][j][mx-1].
z + ucat[mz-1][j][mx-2].
z);
2686 for (PetscInt i = xs; i < xe; i++) {
2687 p[mz-1][ys][i] = 0.5 * (p[mz-2][ys][i] + p[mz-1][ys+1][i]);
2688 ucat[mz-1][ys][i].
x = 0.5 * (ucat[mz-2][ys][i].
x + ucat[mz-1][ys+1][i].
x);
2689 ucat[mz-1][ys][i].
y = 0.5 * (ucat[mz-2][ys][i].
y + ucat[mz-1][ys+1][i].
y);
2690 ucat[mz-1][ys][i].
z = 0.5 * (ucat[mz-2][ys][i].
z + ucat[mz-1][ys+1][i].
z);
2694 for (PetscInt i = xs; i < xe; i++) {
2695 p[mz-1][my-1][i] = 0.5 * (p[mz-2][my-1][i] + p[mz-1][my-2][i]);
2696 ucat[mz-1][my-1][i].
x = 0.5 * (ucat[mz-2][my-1][i].
x + ucat[mz-1][my-2][i].
x);
2697 ucat[mz-1][my-1][i].
y = 0.5 * (ucat[mz-2][my-1][i].
y + ucat[mz-1][my-2][i].
y);
2698 ucat[mz-1][my-1][i].
z = 0.5 * (ucat[mz-2][my-1][i].
z + ucat[mz-1][my-2][i].
z);
2706 for (PetscInt k = zs; k < ze; k++) {
2707 p[k][ys][xs] = 0.5 * (p[k][ys+1][xs] + p[k][ys][xs+1]);
2708 ucat[k][ys][xs].
x = 0.5 * (ucat[k][ys+1][xs].
x + ucat[k][ys][xs+1].
x);
2709 ucat[k][ys][xs].
y = 0.5 * (ucat[k][ys+1][xs].
y + ucat[k][ys][xs+1].
y);
2710 ucat[k][ys][xs].
z = 0.5 * (ucat[k][ys+1][xs].
z + ucat[k][ys][xs+1].
z);
2714 for (PetscInt k = zs; k < ze; k++) {
2715 p[k][ys][mx-1] = 0.5 * (p[k][ys+1][mx-1] + p[k][ys][mx-2]);
2716 ucat[k][ys][mx-1].
x = 0.5 * (ucat[k][ys+1][mx-1].
x + ucat[k][ys][mx-2].
x);
2717 ucat[k][ys][mx-1].
y = 0.5 * (ucat[k][ys+1][mx-1].
y + ucat[k][ys][mx-2].
y);
2718 ucat[k][ys][mx-1].
z = 0.5 * (ucat[k][ys+1][mx-1].
z + ucat[k][ys][mx-2].
z);
2725 for (PetscInt k = zs; k < ze; k++) {
2726 p[k][my-1][xs] = 0.5 * (p[k][my-2][xs] + p[k][my-1][xs+1]);
2727 ucat[k][my-1][xs].
x = 0.5 * (ucat[k][my-2][xs].
x + ucat[k][my-1][xs+1].
x);
2728 ucat[k][my-1][xs].
y = 0.5 * (ucat[k][my-2][xs].
y + ucat[k][my-1][xs+1].
y);
2729 ucat[k][my-1][xs].
z = 0.5 * (ucat[k][my-2][xs].
z + ucat[k][my-1][xs+1].
z);
2733 for (PetscInt k = zs; k < ze; k++) {
2734 p[k][my-1][mx-1] = 0.5 * (p[k][my-2][mx-1] + p[k][my-1][mx-2]);
2735 ucat[k][my-1][mx-1].
x = 0.5 * (ucat[k][my-2][mx-1].
x + ucat[k][my-1][mx-2].
x);
2736 ucat[k][my-1][mx-1].
y = 0.5 * (ucat[k][my-2][mx-1].
y + ucat[k][my-1][mx-2].
y);
2737 ucat[k][my-1][mx-1].
z = 0.5 * (ucat[k][my-2][mx-1].
z + ucat[k][my-1][mx-2].
z);
2742 ierr = DMDAVecRestoreArray(fda, user->
Ucat, &ucat); CHKERRQ(ierr);
2743 ierr = DMDAVecRestoreArray(da, user->
P, &p); CHKERRQ(ierr);
2745 PetscFunctionReturn(0);
2799 PetscErrorCode ierr;
2801 DMDALocalInfo *info = &user->
info;
2803 PetscFunctionBeginUser;
2809 PetscFunctionReturn(0);
2817 Cmpnts ***velocity_cartesian;
2818 Cmpnts ***velocity_contravariant;
2819 Cmpnts ***velocity_boundary;
2820 Cmpnts ***csi, ***eta, ***zet;
2821 PetscReal ***node_vertex_flag;
2822 PetscReal ***cell_jacobian;
2823 PetscReal ***friction_velocity;
2825 ierr = DMDAVecGetArray(user->
fda, user->
Ucat, &velocity_cartesian); CHKERRQ(ierr);
2826 ierr = DMDAVecGetArray(user->
fda, user->
Ucont, &velocity_contravariant); CHKERRQ(ierr);
2827 ierr = DMDAVecGetArray(user->
fda, user->
Bcs.
Ubcs, &velocity_boundary); CHKERRQ(ierr);
2828 ierr = DMDAVecGetArrayRead(user->
fda, user->
lCsi, (
const Cmpnts***)&csi); CHKERRQ(ierr);
2829 ierr = DMDAVecGetArrayRead(user->
fda, user->
lEta, (
const Cmpnts***)&eta); CHKERRQ(ierr);
2830 ierr = DMDAVecGetArrayRead(user->
fda, user->
lZet, (
const Cmpnts***)&zet); CHKERRQ(ierr);
2831 ierr = DMDAVecGetArrayRead(user->
da, user->
lNvert, (
const PetscReal***)&node_vertex_flag); CHKERRQ(ierr);
2832 ierr = DMDAVecGetArrayRead(user->
da, user->
lAj, (
const PetscReal***)&cell_jacobian); CHKERRQ(ierr);
2838 PetscInt grid_start_i = info->xs, grid_end_i = info->xs + info->xm;
2839 PetscInt grid_start_j = info->ys, grid_end_j = info->ys + info->ym;
2840 PetscInt grid_start_k = info->zs, grid_end_k = info->zs + info->zm;
2841 PetscInt grid_size_i = info->mx, grid_size_j = info->my, grid_size_k = info->mz;
2844 PetscInt loop_start_i = grid_start_i, loop_end_i = grid_end_i;
2845 PetscInt loop_start_j = grid_start_j, loop_end_j = grid_end_j;
2846 PetscInt loop_start_k = grid_start_k, loop_end_k = grid_end_k;
2848 if (grid_start_i == 0) loop_start_i = grid_start_i + 1;
2849 if (grid_end_i == grid_size_i) loop_end_i = grid_end_i - 1;
2850 if (grid_start_j == 0) loop_start_j = grid_start_j + 1;
2851 if (grid_end_j == grid_size_j) loop_end_j = grid_end_j - 1;
2852 if (grid_start_k == 0) loop_start_k = grid_start_k + 1;
2853 if (grid_end_k == grid_size_k) loop_end_k = grid_end_k - 1;
2861 for (
int face_index = 0; face_index < 6; face_index++) {
2871 PetscBool rank_owns_this_face;
2873 current_face_id, &rank_owns_this_face); CHKERRQ(ierr);
2875 if (!rank_owns_this_face) {
2885 switch(current_face_id) {
2891 if (grid_start_i == 0) {
2892 const PetscInt ghost_cell_index = grid_start_i;
2893 const PetscInt first_interior_cell = grid_start_i + 1;
2894 const PetscInt second_interior_cell = grid_start_i + 2;
2896 for (PetscInt k = loop_start_k; k < loop_end_k; k++) {
2897 for (PetscInt j = loop_start_j; j < loop_end_j; j++) {
2900 if (node_vertex_flag[k][j][first_interior_cell] < 0.1) {
2903 PetscReal face_area = sqrt(
2904 csi[k][j][ghost_cell_index].x * csi[k][j][ghost_cell_index].x +
2905 csi[k][j][ghost_cell_index].y * csi[k][j][ghost_cell_index].y +
2906 csi[k][j][ghost_cell_index].z * csi[k][j][ghost_cell_index].z
2912 PetscReal distance_to_first_cell = 0.5 / cell_jacobian[k][j][first_interior_cell] / face_area;
2913 PetscReal distance_to_second_cell = 2.0 * distance_to_first_cell +
2914 0.5 / cell_jacobian[k][j][second_interior_cell] / face_area;
2917 PetscReal wall_normal[3];
2918 wall_normal[0] = csi[k][j][ghost_cell_index].
x / face_area;
2919 wall_normal[1] = csi[k][j][ghost_cell_index].
y / face_area;
2920 wall_normal[2] = csi[k][j][ghost_cell_index].
z / face_area;
2924 Cmpnts reference_velocity;
2926 wall_velocity.
x = wall_velocity.
y = wall_velocity.
z = 0.0;
2927 reference_velocity = velocity_cartesian[k][j][second_interior_cell];
2930 noslip(user, distance_to_second_cell, distance_to_first_cell,
2931 wall_velocity, reference_velocity,
2932 &velocity_cartesian[k][j][first_interior_cell],
2933 wall_normal[0], wall_normal[1], wall_normal[2]);
2937 distance_to_second_cell, distance_to_first_cell,
2938 wall_velocity, reference_velocity,
2939 &velocity_cartesian[k][j][first_interior_cell],
2940 &friction_velocity[k][j][first_interior_cell],
2941 wall_normal[0], wall_normal[1], wall_normal[2]);
2944 velocity_boundary[k][j][ghost_cell_index].
x = 0.0;
2945 velocity_boundary[k][j][ghost_cell_index].
y = 0.0;
2946 velocity_boundary[k][j][ghost_cell_index].
z = 0.0;
2947 velocity_contravariant[k][j][ghost_cell_index].
x = 0.0;
2958 if (grid_end_i == grid_size_i) {
2959 const PetscInt ghost_cell_index = grid_end_i - 1;
2960 const PetscInt first_interior_cell = grid_end_i - 2;
2961 const PetscInt second_interior_cell = grid_end_i - 3;
2963 for (PetscInt k = loop_start_k; k < loop_end_k; k++) {
2964 for (PetscInt j = loop_start_j; j < loop_end_j; j++) {
2966 if (node_vertex_flag[k][j][first_interior_cell] < 0.1) {
2968 PetscReal face_area = sqrt(
2969 csi[k][j][first_interior_cell].x * csi[k][j][first_interior_cell].x +
2970 csi[k][j][first_interior_cell].y * csi[k][j][first_interior_cell].y +
2971 csi[k][j][first_interior_cell].z * csi[k][j][first_interior_cell].z
2974 PetscReal distance_to_first_cell = 0.5 / cell_jacobian[k][j][first_interior_cell] / face_area;
2975 PetscReal distance_to_second_cell = 2.0 * distance_to_first_cell +
2976 0.5 / cell_jacobian[k][j][second_interior_cell] / face_area;
2979 PetscReal wall_normal[3];
2980 wall_normal[0] = -csi[k][j][first_interior_cell].
x / face_area;
2981 wall_normal[1] = -csi[k][j][first_interior_cell].
y / face_area;
2982 wall_normal[2] = -csi[k][j][first_interior_cell].
z / face_area;
2984 Cmpnts wall_velocity, reference_velocity;
2985 wall_velocity.
x = wall_velocity.
y = wall_velocity.
z = 0.0;
2986 reference_velocity = velocity_cartesian[k][j][second_interior_cell];
2988 noslip(user, distance_to_second_cell, distance_to_first_cell,
2989 wall_velocity, reference_velocity,
2990 &velocity_cartesian[k][j][first_interior_cell],
2991 wall_normal[0], wall_normal[1], wall_normal[2]);
2994 distance_to_second_cell, distance_to_first_cell,
2995 wall_velocity, reference_velocity,
2996 &velocity_cartesian[k][j][first_interior_cell],
2997 &friction_velocity[k][j][first_interior_cell],
2998 wall_normal[0], wall_normal[1], wall_normal[2]);
3000 velocity_boundary[k][j][ghost_cell_index].
x = 0.0;
3001 velocity_boundary[k][j][ghost_cell_index].
y = 0.0;
3002 velocity_boundary[k][j][ghost_cell_index].
z = 0.0;
3003 velocity_contravariant[k][j][first_interior_cell].
x = 0.0;
3014 if (grid_start_j == 0) {
3015 const PetscInt ghost_cell_index = grid_start_j;
3016 const PetscInt first_interior_cell = grid_start_j + 1;
3017 const PetscInt second_interior_cell = grid_start_j + 2;
3019 for (PetscInt k = loop_start_k; k < loop_end_k; k++) {
3020 for (PetscInt i = loop_start_i; i < loop_end_i; i++) {
3022 if (node_vertex_flag[k][first_interior_cell][i] < 0.1) {
3024 PetscReal face_area = sqrt(
3025 eta[k][ghost_cell_index][i].x * eta[k][ghost_cell_index][i].x +
3026 eta[k][ghost_cell_index][i].y * eta[k][ghost_cell_index][i].y +
3027 eta[k][ghost_cell_index][i].z * eta[k][ghost_cell_index][i].z
3030 PetscReal distance_to_first_cell = 0.5 / cell_jacobian[k][first_interior_cell][i] / face_area;
3031 PetscReal distance_to_second_cell = 2.0 * distance_to_first_cell +
3032 0.5 / cell_jacobian[k][second_interior_cell][i] / face_area;
3034 PetscReal wall_normal[3];
3035 wall_normal[0] = eta[k][ghost_cell_index][i].
x / face_area;
3036 wall_normal[1] = eta[k][ghost_cell_index][i].
y / face_area;
3037 wall_normal[2] = eta[k][ghost_cell_index][i].
z / face_area;
3039 Cmpnts wall_velocity, reference_velocity;
3040 wall_velocity.
x = wall_velocity.
y = wall_velocity.
z = 0.0;
3041 reference_velocity = velocity_cartesian[k][second_interior_cell][i];
3043 noslip(user, distance_to_second_cell, distance_to_first_cell,
3044 wall_velocity, reference_velocity,
3045 &velocity_cartesian[k][first_interior_cell][i],
3046 wall_normal[0], wall_normal[1], wall_normal[2]);
3049 distance_to_second_cell, distance_to_first_cell,
3050 wall_velocity, reference_velocity,
3051 &velocity_cartesian[k][first_interior_cell][i],
3052 &friction_velocity[k][first_interior_cell][i],
3053 wall_normal[0], wall_normal[1], wall_normal[2]);
3055 velocity_boundary[k][ghost_cell_index][i].
x = 0.0;
3056 velocity_boundary[k][ghost_cell_index][i].
y = 0.0;
3057 velocity_boundary[k][ghost_cell_index][i].
z = 0.0;
3058 velocity_contravariant[k][ghost_cell_index][i].
y = 0.0;
3069 if (grid_end_j == grid_size_j) {
3070 const PetscInt ghost_cell_index = grid_end_j - 1;
3071 const PetscInt first_interior_cell = grid_end_j - 2;
3072 const PetscInt second_interior_cell = grid_end_j - 3;
3074 for (PetscInt k = loop_start_k; k < loop_end_k; k++) {
3075 for (PetscInt i = loop_start_i; i < loop_end_i; i++) {
3077 if (node_vertex_flag[k][first_interior_cell][i] < 0.1) {
3079 PetscReal face_area = sqrt(
3080 eta[k][first_interior_cell][i].x * eta[k][first_interior_cell][i].x +
3081 eta[k][first_interior_cell][i].y * eta[k][first_interior_cell][i].y +
3082 eta[k][first_interior_cell][i].z * eta[k][first_interior_cell][i].z
3085 PetscReal distance_to_first_cell = 0.5 / cell_jacobian[k][first_interior_cell][i] / face_area;
3086 PetscReal distance_to_second_cell = 2.0 * distance_to_first_cell +
3087 0.5 / cell_jacobian[k][second_interior_cell][i] / face_area;
3089 PetscReal wall_normal[3];
3090 wall_normal[0] = -eta[k][first_interior_cell][i].
x / face_area;
3091 wall_normal[1] = -eta[k][first_interior_cell][i].
y / face_area;
3092 wall_normal[2] = -eta[k][first_interior_cell][i].
z / face_area;
3094 Cmpnts wall_velocity, reference_velocity;
3095 wall_velocity.
x = wall_velocity.
y = wall_velocity.
z = 0.0;
3096 reference_velocity = velocity_cartesian[k][second_interior_cell][i];
3098 noslip(user, distance_to_second_cell, distance_to_first_cell,
3099 wall_velocity, reference_velocity,
3100 &velocity_cartesian[k][first_interior_cell][i],
3101 wall_normal[0], wall_normal[1], wall_normal[2]);
3104 distance_to_second_cell, distance_to_first_cell,
3105 wall_velocity, reference_velocity,
3106 &velocity_cartesian[k][first_interior_cell][i],
3107 &friction_velocity[k][first_interior_cell][i],
3108 wall_normal[0], wall_normal[1], wall_normal[2]);
3110 velocity_boundary[k][ghost_cell_index][i].
x = 0.0;
3111 velocity_boundary[k][ghost_cell_index][i].
y = 0.0;
3112 velocity_boundary[k][ghost_cell_index][i].
z = 0.0;
3113 velocity_contravariant[k][first_interior_cell][i].
y = 0.0;
3124 if (grid_start_k == 0) {
3125 const PetscInt ghost_cell_index = grid_start_k;
3126 const PetscInt first_interior_cell = grid_start_k + 1;
3127 const PetscInt second_interior_cell = grid_start_k + 2;
3129 for (PetscInt j = loop_start_j; j < loop_end_j; j++) {
3130 for (PetscInt i = loop_start_i; i < loop_end_i; i++) {
3132 if (node_vertex_flag[first_interior_cell][j][i] < 0.1) {
3134 PetscReal face_area = sqrt(
3135 zet[ghost_cell_index][j][i].x * zet[ghost_cell_index][j][i].x +
3136 zet[ghost_cell_index][j][i].y * zet[ghost_cell_index][j][i].y +
3137 zet[ghost_cell_index][j][i].z * zet[ghost_cell_index][j][i].z
3140 PetscReal distance_to_first_cell = 0.5 / cell_jacobian[first_interior_cell][j][i] / face_area;
3141 PetscReal distance_to_second_cell = 2.0 * distance_to_first_cell +
3142 0.5 / cell_jacobian[second_interior_cell][j][i] / face_area;
3144 PetscReal wall_normal[3];
3145 wall_normal[0] = zet[ghost_cell_index][j][i].
x / face_area;
3146 wall_normal[1] = zet[ghost_cell_index][j][i].
y / face_area;
3147 wall_normal[2] = zet[ghost_cell_index][j][i].
z / face_area;
3149 Cmpnts wall_velocity, reference_velocity;
3150 wall_velocity.
x = wall_velocity.
y = wall_velocity.
z = 0.0;
3151 reference_velocity = velocity_cartesian[second_interior_cell][j][i];
3153 noslip(user, distance_to_second_cell, distance_to_first_cell,
3154 wall_velocity, reference_velocity,
3155 &velocity_cartesian[first_interior_cell][j][i],
3156 wall_normal[0], wall_normal[1], wall_normal[2]);
3159 distance_to_second_cell, distance_to_first_cell,
3160 wall_velocity, reference_velocity,
3161 &velocity_cartesian[first_interior_cell][j][i],
3162 &friction_velocity[first_interior_cell][j][i],
3163 wall_normal[0], wall_normal[1], wall_normal[2]);
3165 velocity_boundary[ghost_cell_index][j][i].
x = 0.0;
3166 velocity_boundary[ghost_cell_index][j][i].
y = 0.0;
3167 velocity_boundary[ghost_cell_index][j][i].
z = 0.0;
3168 velocity_contravariant[ghost_cell_index][j][i].
z = 0.0;
3179 if (grid_end_k == grid_size_k) {
3180 const PetscInt ghost_cell_index = grid_end_k - 1;
3181 const PetscInt first_interior_cell = grid_end_k - 2;
3182 const PetscInt second_interior_cell = grid_end_k - 3;
3184 for (PetscInt j = loop_start_j; j < loop_end_j; j++) {
3185 for (PetscInt i = loop_start_i; i < loop_end_i; i++) {
3187 if (node_vertex_flag[first_interior_cell][j][i] < 0.1) {
3189 PetscReal face_area = sqrt(
3190 zet[first_interior_cell][j][i].x * zet[first_interior_cell][j][i].x +
3191 zet[first_interior_cell][j][i].y * zet[first_interior_cell][j][i].y +
3192 zet[first_interior_cell][j][i].z * zet[first_interior_cell][j][i].z
3195 PetscReal distance_to_first_cell = 0.5 / cell_jacobian[first_interior_cell][j][i] / face_area;
3196 PetscReal distance_to_second_cell = 2.0 * distance_to_first_cell +
3197 0.5 / cell_jacobian[second_interior_cell][j][i] / face_area;
3199 PetscReal wall_normal[3];
3200 wall_normal[0] = -zet[first_interior_cell][j][i].
x / face_area;
3201 wall_normal[1] = -zet[first_interior_cell][j][i].
y / face_area;
3202 wall_normal[2] = -zet[first_interior_cell][j][i].
z / face_area;
3204 Cmpnts wall_velocity, reference_velocity;
3205 wall_velocity.
x = wall_velocity.
y = wall_velocity.
z = 0.0;
3206 reference_velocity = velocity_cartesian[second_interior_cell][j][i];
3208 noslip(user, distance_to_second_cell, distance_to_first_cell,
3209 wall_velocity, reference_velocity,
3210 &velocity_cartesian[first_interior_cell][j][i],
3211 wall_normal[0], wall_normal[1], wall_normal[2]);
3214 distance_to_second_cell, distance_to_first_cell,
3215 wall_velocity, reference_velocity,
3216 &velocity_cartesian[first_interior_cell][j][i],
3217 &friction_velocity[first_interior_cell][j][i],
3218 wall_normal[0], wall_normal[1], wall_normal[2]);
3220 velocity_boundary[ghost_cell_index][j][i].
x = 0.0;
3221 velocity_boundary[ghost_cell_index][j][i].
y = 0.0;
3222 velocity_boundary[ghost_cell_index][j][i].
z = 0.0;
3223 velocity_contravariant[first_interior_cell][j][i].
z = 0.0;
3235 ierr = DMDAVecRestoreArray(user->
fda, user->
Ucat, &velocity_cartesian); CHKERRQ(ierr);
3236 ierr = DMDAVecRestoreArray(user->
fda, user->
Ucont, &velocity_contravariant); CHKERRQ(ierr);
3237 ierr = DMDAVecRestoreArray(user->
fda, user->
Bcs.
Ubcs, &velocity_boundary); CHKERRQ(ierr);
3238 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lCsi, (
const Cmpnts***)&csi); CHKERRQ(ierr);
3239 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lEta, (
const Cmpnts***)&eta); CHKERRQ(ierr);
3240 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lZet, (
const Cmpnts***)&zet); CHKERRQ(ierr);
3241 ierr = DMDAVecRestoreArrayRead(user->
da, user->
lNvert, (
const PetscReal***)&node_vertex_flag); CHKERRQ(ierr);
3242 ierr = DMDAVecRestoreArrayRead(user->
da, user->
lAj, (
const PetscReal***)&cell_jacobian); CHKERRQ(ierr);
3243 ierr = DMDAVecRestoreArray(user->
da, user->
lFriction_Velocity, &friction_velocity); CHKERRQ(ierr);
3247 PetscFunctionReturn(0);