268 UserCtx *user,
const DMDALocalInfo *info,
269 PetscInt xs_gnode_rank, PetscInt ys_gnode_rank, PetscInt zs_gnode_rank,
270 PetscInt IM_cells_global, PetscInt JM_cells_global, PetscInt KM_cells_global,
271 PetscInt64 particle_global_id,
272 PetscInt *ci_metric_lnode_out, PetscInt *cj_metric_lnode_out, PetscInt *ck_metric_lnode_out,
273 PetscReal *xi_metric_logic_out, PetscReal *eta_metric_logic_out, PetscReal *zta_metric_logic_out,
274 PetscBool *placement_successful_out)
277 PetscReal global_logic_i, global_logic_j, global_logic_k;
279 PetscMPIInt rank_for_logging;
281 PetscFunctionBeginUser;
282 ierr = MPI_Comm_rank(PETSC_COMM_WORLD, &rank_for_logging); CHKERRQ(ierr);
284 *placement_successful_out = PETSC_FALSE;
289 const PetscInt grid_layers = 2;
292 "[Rank %d] Placing particle %lld on face %s with grid_layers=%d in global domain (%d,%d,%d) cells.\n",
294 IM_cells_global, JM_cells_global, KM_cells_global);
302 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);
303 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);
306 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);
307 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);
310 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);
311 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);
313 default: SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG,
"Invalid identifiedInletBCFace specified: %d", user->
identifiedInletBCFace);
316 const PetscInt num_lines_total = 4 * grid_layers;
317 if (simCtx->
np < num_lines_total) {
318 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);
320 if (simCtx->
np > 0 && simCtx->
np % num_lines_total != 0) {
321 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);
325 if (simCtx->
np == 0) PetscFunctionReturn(0);
328 rank_for_logging, (
long long)simCtx->
np, num_lines_total, face_name);
330 const PetscInt points_per_line = PetscMax(1, simCtx->
np / num_lines_total);
331 PetscInt line_index = particle_global_id / points_per_line;
332 PetscInt point_index_on_line = particle_global_id % points_per_line;
333 line_index = PetscMin(line_index, num_lines_total - 1);
336 const PetscInt edge_group = line_index / grid_layers;
337 const PetscInt layer_index = line_index % grid_layers;
340 const PetscReal epsilon = 1.0e-6;
341 const PetscReal layer_spacing_norm_i = (IM_cells_global > 0) ? 1.0 / (PetscReal)IM_cells_global : 0.0;
342 const PetscReal layer_spacing_norm_j = (JM_cells_global > 0) ? 1.0 / (PetscReal)JM_cells_global : 0.0;
343 const PetscReal layer_spacing_norm_k = (KM_cells_global > 0) ? 1.0 / (PetscReal)KM_cells_global : 0.0;
345 PetscReal variable_coord;
346 if (points_per_line <= 1) {
347 variable_coord = 0.5;
349 variable_coord = ((PetscReal)point_index_on_line + 0.5)/ (PetscReal)(points_per_line);
351 variable_coord = PetscMin(1.0 - epsilon, PetscMax(epsilon, variable_coord));
356 global_logic_i = 0.5 * layer_spacing_norm_i;
357 if (edge_group == 0) { global_logic_j = (PetscReal)layer_index * layer_spacing_norm_j + epsilon; global_logic_k = variable_coord; }
358 else if (edge_group == 1) { global_logic_j = 1.0 - ((PetscReal)layer_index * layer_spacing_norm_j) - epsilon; global_logic_k = variable_coord; }
359 else if (edge_group == 2) { global_logic_k = (PetscReal)layer_index * layer_spacing_norm_k + epsilon; global_logic_j = variable_coord; }
360 else { global_logic_k = 1.0 - ((PetscReal)layer_index * layer_spacing_norm_k) - epsilon; global_logic_j = variable_coord; }
363 global_logic_i = 1.0 - (0.5 * layer_spacing_norm_i);
364 if (edge_group == 0) { global_logic_j = (PetscReal)layer_index * layer_spacing_norm_j + epsilon; global_logic_k = variable_coord; }
365 else if (edge_group == 1) { global_logic_j = 1.0 - ((PetscReal)layer_index * layer_spacing_norm_j) - epsilon; global_logic_k = variable_coord; }
366 else if (edge_group == 2) { global_logic_k = (PetscReal)layer_index * layer_spacing_norm_k + epsilon; global_logic_j = variable_coord; }
367 else { global_logic_k = 1.0 - ((PetscReal)layer_index * layer_spacing_norm_k) - epsilon; global_logic_j = variable_coord; }
370 global_logic_j = 0.5 * layer_spacing_norm_j;
371 if (edge_group == 0) { global_logic_i = (PetscReal)layer_index * layer_spacing_norm_i + epsilon; global_logic_k = variable_coord; }
372 else if (edge_group == 1) { global_logic_i = 1.0 - ((PetscReal)layer_index * layer_spacing_norm_i) - epsilon; global_logic_k = variable_coord; }
373 else if (edge_group == 2) { global_logic_k = (PetscReal)layer_index * layer_spacing_norm_k + epsilon; global_logic_i = variable_coord; }
374 else { global_logic_k = 1.0 - ((PetscReal)layer_index * layer_spacing_norm_k) - epsilon; global_logic_i = variable_coord; }
377 global_logic_j = 1.0 - (0.5 * layer_spacing_norm_j);
378 if (edge_group == 0) { global_logic_i = (PetscReal)layer_index * layer_spacing_norm_i + epsilon; global_logic_k = variable_coord; }
379 else if (edge_group == 1) { global_logic_i = 1.0 - ((PetscReal)layer_index * layer_spacing_norm_i) - epsilon; global_logic_k = variable_coord; }
380 else if (edge_group == 2) { global_logic_k = (PetscReal)layer_index * layer_spacing_norm_k + epsilon; global_logic_i = variable_coord; }
381 else { global_logic_k = 1.0 - ((PetscReal)layer_index * layer_spacing_norm_k) - epsilon; global_logic_i = variable_coord; }
384 global_logic_k = 0.5 * layer_spacing_norm_k;
385 if (edge_group == 0) { global_logic_i = (PetscReal)layer_index * layer_spacing_norm_i + epsilon; global_logic_j = variable_coord; }
386 else if (edge_group == 1) { global_logic_i = 1.0 - ((PetscReal)layer_index * layer_spacing_norm_i) - epsilon; global_logic_j = variable_coord; }
387 else if (edge_group == 2) { global_logic_j = (PetscReal)layer_index * layer_spacing_norm_j + epsilon; global_logic_i = variable_coord; }
388 else { global_logic_j = 1.0 - ((PetscReal)layer_index * layer_spacing_norm_j) - epsilon; global_logic_i = variable_coord; }
391 global_logic_k = 1.0 - (0.5 * layer_spacing_norm_k);
392 if (edge_group == 0) { global_logic_i = (PetscReal)layer_index * layer_spacing_norm_i + epsilon; global_logic_j = variable_coord; }
393 else if (edge_group == 1) { global_logic_i = 1.0 - ((PetscReal)layer_index * layer_spacing_norm_i) - epsilon; global_logic_j = variable_coord; }
394 else if (edge_group == 2) { global_logic_j = (PetscReal)layer_index * layer_spacing_norm_j + epsilon; global_logic_i = variable_coord; }
395 else { global_logic_j = 1.0 - ((PetscReal)layer_index * layer_spacing_norm_j) - epsilon; global_logic_i = variable_coord; }
400 "[Rank %d] Particle %lld assigned to line %d (edge group %d, layer %d) with variable_coord=%.4f.\n"
401 " -> Global logical coords: (i,j,k) = (%.6f, %.6f, %.6f)\n",
402 rank_for_logging, (
long long)particle_global_id, line_index, edge_group, layer_index, variable_coord,
403 global_logic_i, global_logic_j, global_logic_k);
406 PetscReal global_cell_coord_i = global_logic_i * IM_cells_global;
407 PetscInt I_g = (PetscInt)global_cell_coord_i;
408 *xi_metric_logic_out = global_cell_coord_i - I_g;
410 PetscReal global_cell_coord_j = global_logic_j * JM_cells_global;
411 PetscInt J_g = (PetscInt)global_cell_coord_j;
412 *eta_metric_logic_out = global_cell_coord_j - J_g;
414 PetscReal global_cell_coord_k = global_logic_k * KM_cells_global;
415 PetscInt K_g = (PetscInt)global_cell_coord_k;
416 *zta_metric_logic_out = global_cell_coord_k - K_g;
419 if ((I_g >= info->xs && I_g < info->xs + info->xm) &&
420 (J_g >= info->ys && J_g < info->ys + info->ym) &&
421 (K_g >= info->zs && K_g < info->zs + info->zm))
424 *ci_metric_lnode_out = (I_g - info->xs) + xs_gnode_rank;
425 *cj_metric_lnode_out = (J_g - info->ys) + ys_gnode_rank;
426 *ck_metric_lnode_out = (K_g - info->zs) + zs_gnode_rank;
427 *placement_successful_out = PETSC_TRUE;
431 "[Rank %d] Particle %lld placement %s. Local cell origin node: (I,J,K) = (%d,%d,%d), intra-cell logicals: (xi,eta,zta)=(%.6f,%.6f,%.6f)\n",
432 rank_for_logging, (
long long)particle_global_id,
433 (*placement_successful_out ?
"SUCCESSFUL" :
"NOT ON THIS RANK"),
434 *ci_metric_lnode_out, *cj_metric_lnode_out, *ck_metric_lnode_out,
435 *xi_metric_logic_out, *eta_metric_logic_out, *zta_metric_logic_out);
437 PetscFunctionReturn(0);
460 UserCtx *user,
const DMDALocalInfo *info,
461 PetscInt xs_gnode_rank, PetscInt ys_gnode_rank, PetscInt zs_gnode_rank,
462 PetscInt IM_nodes_global, PetscInt JM_nodes_global, PetscInt KM_nodes_global,
463 PetscRandom *rand_logic_i_ptr, PetscRandom *rand_logic_j_ptr, PetscRandom *rand_logic_k_ptr,
464 PetscInt *ci_metric_lnode_out, PetscInt *cj_metric_lnode_out, PetscInt *ck_metric_lnode_out,
465 PetscReal *xi_metric_logic_out, PetscReal *eta_metric_logic_out, PetscReal *zta_metric_logic_out)
467 PetscErrorCode ierr = 0;
468 PetscReal r_val_i_sel, r_val_j_sel, r_val_k_sel;
469 PetscInt local_cell_idx_on_face_dim1 = 0;
470 PetscInt local_cell_idx_on_face_dim2 = 0;
471 PetscMPIInt rank_for_logging;
473 PetscFunctionBeginUser;
477 ierr = MPI_Comm_rank(PETSC_COMM_WORLD, &rank_for_logging); CHKERRQ(ierr);
480 *ci_metric_lnode_out = xs_gnode_rank; *cj_metric_lnode_out = ys_gnode_rank; *ck_metric_lnode_out = zs_gnode_rank;
482 *xi_metric_logic_out = 0.5; *eta_metric_logic_out = 0.5; *zta_metric_logic_out = 0.5;
485 PetscInt owned_start_cell_i, num_owned_cells_on_rank_i;
486 PetscInt owned_start_cell_j, num_owned_cells_on_rank_j;
487 PetscInt owned_start_cell_k, num_owned_cells_on_rank_k;
489 ierr =
GetOwnedCellRange(info, 0, &owned_start_cell_i, &num_owned_cells_on_rank_i); CHKERRQ(ierr);
490 ierr =
GetOwnedCellRange(info, 1, &owned_start_cell_j, &num_owned_cells_on_rank_j); CHKERRQ(ierr);
491 ierr =
GetOwnedCellRange(info, 2, &owned_start_cell_k, &num_owned_cells_on_rank_k); CHKERRQ(ierr);
494 PetscInt last_global_cell_idx_i = (IM_nodes_global > 1) ? (IM_nodes_global - 2) : -1;
495 PetscInt last_global_cell_idx_j = (JM_nodes_global > 1) ? (JM_nodes_global - 2) : -1;
496 PetscInt last_global_cell_idx_k = (KM_nodes_global > 1) ? (KM_nodes_global - 2) : -1;
498 LOG_ALLOW(
LOCAL,
LOG_TRACE,
"Rank %d: Inlet face %s. Owned cells(i,j,k):(%d,%d,%d). GlobNodes(I,J,K):(%d,%d,%d). Rank's DA node starts at (%d,%d,%d).\n",
499 rank_for_logging, user->
identifiedInletBCFace, num_owned_cells_on_rank_i,num_owned_cells_on_rank_j,num_owned_cells_on_rank_k,
500 IM_nodes_global,JM_nodes_global,KM_nodes_global, xs_gnode_rank,ys_gnode_rank,zs_gnode_rank);
507 *ci_metric_lnode_out = xs_gnode_rank;
508 *xi_metric_logic_out = 1.0e-6;
512 ierr = PetscRandomGetValueReal(*rand_logic_j_ptr, &r_val_j_sel); CHKERRQ(ierr);
513 local_cell_idx_on_face_dim1 = (PetscInt)(r_val_j_sel * num_owned_cells_on_rank_j);
514 local_cell_idx_on_face_dim1 = PetscMin(PetscMax(0, local_cell_idx_on_face_dim1), num_owned_cells_on_rank_j - 1);
515 *cj_metric_lnode_out = ys_gnode_rank + local_cell_idx_on_face_dim1;
517 ierr = PetscRandomGetValueReal(*rand_logic_k_ptr, &r_val_k_sel); CHKERRQ(ierr);
518 local_cell_idx_on_face_dim2 = (PetscInt)(r_val_k_sel * num_owned_cells_on_rank_k);
519 local_cell_idx_on_face_dim2 = PetscMin(PetscMax(0, local_cell_idx_on_face_dim2), num_owned_cells_on_rank_k - 1);
520 *ck_metric_lnode_out = zs_gnode_rank + local_cell_idx_on_face_dim2;
522 ierr = PetscRandomGetValueReal(*rand_logic_j_ptr, eta_metric_logic_out); CHKERRQ(ierr);
523 ierr = PetscRandomGetValueReal(*rand_logic_k_ptr, zta_metric_logic_out); CHKERRQ(ierr);
529 *ci_metric_lnode_out = xs_gnode_rank + (last_global_cell_idx_i - info->xs);
530 *xi_metric_logic_out = 1.0 - 1.0e-6;
532 ierr = PetscRandomGetValueReal(*rand_logic_j_ptr, &r_val_j_sel); CHKERRQ(ierr);
533 local_cell_idx_on_face_dim1 = (PetscInt)(r_val_j_sel * num_owned_cells_on_rank_j);
534 local_cell_idx_on_face_dim1 = PetscMin(PetscMax(0, local_cell_idx_on_face_dim1), num_owned_cells_on_rank_j - 1);
535 *cj_metric_lnode_out = ys_gnode_rank + local_cell_idx_on_face_dim1;
537 ierr = PetscRandomGetValueReal(*rand_logic_k_ptr, &r_val_k_sel); CHKERRQ(ierr);
538 local_cell_idx_on_face_dim2 = (PetscInt)(r_val_k_sel * num_owned_cells_on_rank_k);
539 local_cell_idx_on_face_dim2 = PetscMin(PetscMax(0, local_cell_idx_on_face_dim2), num_owned_cells_on_rank_k - 1);
540 *ck_metric_lnode_out = zs_gnode_rank + local_cell_idx_on_face_dim2;
542 ierr = PetscRandomGetValueReal(*rand_logic_j_ptr, eta_metric_logic_out); CHKERRQ(ierr);
543 ierr = PetscRandomGetValueReal(*rand_logic_k_ptr, zta_metric_logic_out); CHKERRQ(ierr);
547 *cj_metric_lnode_out = ys_gnode_rank;
548 *eta_metric_logic_out = 1.0e-6;
549 ierr = PetscRandomGetValueReal(*rand_logic_i_ptr, &r_val_i_sel); CHKERRQ(ierr);
550 local_cell_idx_on_face_dim1 = (PetscInt)(r_val_i_sel * num_owned_cells_on_rank_i);
551 local_cell_idx_on_face_dim1 = PetscMin(PetscMax(0, local_cell_idx_on_face_dim1), num_owned_cells_on_rank_i - 1);
552 *ci_metric_lnode_out = xs_gnode_rank + local_cell_idx_on_face_dim1;
553 ierr = PetscRandomGetValueReal(*rand_logic_k_ptr, &r_val_k_sel); CHKERRQ(ierr);
554 local_cell_idx_on_face_dim2 = (PetscInt)(r_val_k_sel * num_owned_cells_on_rank_k);
555 local_cell_idx_on_face_dim2 = PetscMin(PetscMax(0, local_cell_idx_on_face_dim2), num_owned_cells_on_rank_k - 1);
556 *ck_metric_lnode_out = zs_gnode_rank + local_cell_idx_on_face_dim2;
557 ierr = PetscRandomGetValueReal(*rand_logic_i_ptr, xi_metric_logic_out); CHKERRQ(ierr);
558 ierr = PetscRandomGetValueReal(*rand_logic_k_ptr, zta_metric_logic_out); CHKERRQ(ierr);
561 *cj_metric_lnode_out = ys_gnode_rank + (last_global_cell_idx_j - info->ys);
562 *eta_metric_logic_out = 1.0 - 1.0e-6;
563 ierr = PetscRandomGetValueReal(*rand_logic_i_ptr, &r_val_i_sel); CHKERRQ(ierr);
564 local_cell_idx_on_face_dim1 = (PetscInt)(r_val_i_sel * num_owned_cells_on_rank_i);
565 local_cell_idx_on_face_dim1 = PetscMin(PetscMax(0, local_cell_idx_on_face_dim1), num_owned_cells_on_rank_i - 1);
566 *ci_metric_lnode_out = xs_gnode_rank + local_cell_idx_on_face_dim1;
567 ierr = PetscRandomGetValueReal(*rand_logic_k_ptr, &r_val_k_sel); CHKERRQ(ierr);
568 local_cell_idx_on_face_dim2 = (PetscInt)(r_val_k_sel * num_owned_cells_on_rank_k);
569 local_cell_idx_on_face_dim2 = PetscMin(PetscMax(0, local_cell_idx_on_face_dim2), num_owned_cells_on_rank_k - 1);
570 *ck_metric_lnode_out = zs_gnode_rank + local_cell_idx_on_face_dim2;
571 ierr = PetscRandomGetValueReal(*rand_logic_i_ptr, xi_metric_logic_out); CHKERRQ(ierr);
572 ierr = PetscRandomGetValueReal(*rand_logic_k_ptr, zta_metric_logic_out); CHKERRQ(ierr);
575 *ck_metric_lnode_out = zs_gnode_rank;
576 *zta_metric_logic_out = 1.0e-6;
578 ierr = PetscRandomGetValueReal(*rand_logic_i_ptr, &r_val_i_sel); CHKERRQ(ierr);
579 local_cell_idx_on_face_dim1 = (PetscInt)(r_val_i_sel * num_owned_cells_on_rank_i);
580 local_cell_idx_on_face_dim1 = PetscMin(PetscMax(0, local_cell_idx_on_face_dim1), num_owned_cells_on_rank_i - 1);
581 *ci_metric_lnode_out = xs_gnode_rank + local_cell_idx_on_face_dim1;
583 ierr = PetscRandomGetValueReal(*rand_logic_j_ptr, &r_val_j_sel); CHKERRQ(ierr);
584 local_cell_idx_on_face_dim2 = (PetscInt)(r_val_j_sel * num_owned_cells_on_rank_j);
585 local_cell_idx_on_face_dim2 = PetscMin(PetscMax(0, local_cell_idx_on_face_dim2), num_owned_cells_on_rank_j - 1);
586 *cj_metric_lnode_out = ys_gnode_rank + local_cell_idx_on_face_dim2;
588 ierr = PetscRandomGetValueReal(*rand_logic_i_ptr, xi_metric_logic_out); CHKERRQ(ierr);
589 ierr = PetscRandomGetValueReal(*rand_logic_j_ptr, eta_metric_logic_out); CHKERRQ(ierr);
592 *ck_metric_lnode_out = zs_gnode_rank + (last_global_cell_idx_k - info->zs);
593 *zta_metric_logic_out = 1.0 - 1.0e-6;
594 ierr = PetscRandomGetValueReal(*rand_logic_i_ptr, &r_val_i_sel); CHKERRQ(ierr);
595 local_cell_idx_on_face_dim1 = (PetscInt)(r_val_i_sel * num_owned_cells_on_rank_i);
596 local_cell_idx_on_face_dim1 = PetscMin(PetscMax(0, local_cell_idx_on_face_dim1), num_owned_cells_on_rank_i - 1);
597 *ci_metric_lnode_out = xs_gnode_rank + local_cell_idx_on_face_dim1;
598 ierr = PetscRandomGetValueReal(*rand_logic_j_ptr, &r_val_j_sel); CHKERRQ(ierr);
599 local_cell_idx_on_face_dim2 = (PetscInt)(r_val_j_sel * num_owned_cells_on_rank_j);
600 local_cell_idx_on_face_dim2 = PetscMin(PetscMax(0, local_cell_idx_on_face_dim2), num_owned_cells_on_rank_j - 1);
601 *cj_metric_lnode_out = ys_gnode_rank + local_cell_idx_on_face_dim2;
602 ierr = PetscRandomGetValueReal(*rand_logic_i_ptr, xi_metric_logic_out); CHKERRQ(ierr);
603 ierr = PetscRandomGetValueReal(*rand_logic_j_ptr, eta_metric_logic_out); CHKERRQ(ierr);
606 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG,
"GetRandomCellAndLogicOnInletFace: Invalid user->identifiedInletBCFace %d. \n", user->
identifiedInletBCFace);
609 PetscReal eps = 1.0e-7;
611 *eta_metric_logic_out = PetscMin(PetscMax(0.0, *eta_metric_logic_out), 1.0 - eps);
612 *zta_metric_logic_out = PetscMin(PetscMax(0.0, *zta_metric_logic_out), 1.0 - eps);
614 *xi_metric_logic_out = PetscMin(PetscMax(0.0, *xi_metric_logic_out), 1.0 - eps);
615 *zta_metric_logic_out = PetscMin(PetscMax(0.0, *zta_metric_logic_out), 1.0 - eps);
617 *xi_metric_logic_out = PetscMin(PetscMax(0.0, *xi_metric_logic_out), 1.0 - eps);
618 *eta_metric_logic_out = PetscMin(PetscMax(0.0, *eta_metric_logic_out), 1.0 - eps);
622 rank_for_logging, *ci_metric_lnode_out, *cj_metric_lnode_out, *ck_metric_lnode_out,
623 *xi_metric_logic_out, *eta_metric_logic_out, *zta_metric_logic_out);
627 PetscFunctionReturn(0);
709 PetscReal lFluxIn = 0.0, lAreaIn = 0.0, AreaSumIn;
711 Cmpnts ***ucont, ***ubcs, ***ucat, ***coor, ***csi, ***eta, ***zet, ***cent;
714 DM da = user->
da, fda = user->
fda;
715 DMDALocalInfo info = user->
info;
716 PetscInt xs = info.xs, xe = info.xs + info.xm;
717 PetscInt ys = info.ys, ye = info.ys + info.ym;
718 PetscInt zs = info.zs, ze = info.zs + info.zm;
719 PetscInt mx = info.mx, my = info.my, mz = info.mz;
720 PetscInt lxs, lxe, lys, lye, lzs, lze;
724 PetscReal CMx_c = simCtx->
CMx_c;
725 PetscReal CMy_c = simCtx->
CMy_c;
726 PetscReal CMz_c = simCtx->
CMz_c;
728 PetscFunctionBeginUser;
732 lxs = xs; lxe = xe; lys = ys; lye = ye; lzs = zs; lze = ze;
733 if (xs==0) lxs = xs+1;
if (ys==0) lys = ys+1;
if (zs==0) lzs = zs+1;
734 if (xe==mx) lxe = xe-1;
if (ye==my) lye = ye-1;
if (ze==mz) lze = ze-1;
737 DMGetCoordinatesLocal(da,&lCoor);
738 DMDAVecGetArray(fda, lCoor, &coor);
739 DMDAVecGetArray(fda, user->
Ucont, &ucont);
740 DMDAVecGetArray(fda, user->
Bcs.
Ubcs, &ubcs);
741 DMDAVecGetArray(fda, user->
Ucat, &ucat);
742 DMDAVecGetArray(da, user->
lNvert, &nvert);
743 DMDAVecGetArray(fda, user->
Cent, ¢);
744 DMDAVecGetArray(fda, user->
lCsi, &csi);
745 DMDAVecGetArray(fda, user->
lEta, &eta);
746 DMDAVecGetArray(fda, user->
lZet, &zet);
749 for (PetscInt fn=0; fn<6; fn++) {
757 PetscBool is_on_boundary = ( (fn==0 && xs==0) || (fn==1 && xe==mx) ||
758 (fn==2 && ys==0) || (fn==3 && ye==my) ||
759 (fn==4 && zs==0) || (fn==5 && ze==mz) );
760 if (!is_on_boundary)
continue;
771 for (PetscInt k=lzs; k<lze; k++) {
772 for (PetscInt j=lys; j<lye; j++) {
773 if ( (
sign > 0 && nvert[k][j][i+1] > 0.1) || (
sign < 0 && nvert[k][j][i] > 0.1) )
continue;
775 PetscReal uin_this_point = 0.0;
782 PetscReal umax,diameter=1.0;
787 PetscReal yc = cent[k][j][i + (
sign>0)].y - CMy_c;
788 PetscReal zc = cent[k][j][i + (
sign>0)].z - CMz_c;
789 PetscReal r = sqrt(yc*yc + zc*zc);
790 PetscReal r_norm = 2.0 * r / diameter;
791 uin_this_point = umax * (1.0 - r_norm * r_norm);
792 if (r_norm > 1.0) uin_this_point = 0.0;
797 PetscReal CellArea = sqrt(csi[k][j][i].z*csi[k][j][i].z + csi[k][j][i].y*csi[k][j][i].y + csi[k][j][i].x*csi[k][j][i].x);
799 ucont[k][j][i].
x =
sign * uin_this_point * CellArea;
800 lFluxIn += ucont[k][j][i].
x;
801 ubcs[k][j][i + (
sign < 0)].x =
sign * uin_this_point * csi[k][j][i].x / CellArea;
802 ubcs[k][j][i + (
sign < 0)].y =
sign * uin_this_point * csi[k][j][i].y / CellArea;
803 ubcs[k][j][i + (
sign < 0)].z =
sign * uin_this_point * csi[k][j][i].z / CellArea;
804 ucat[k][j][i + (
sign > 0)] = ubcs[k][j][i + (
sign < 0)];
814 for (PetscInt k=lzs; k<lze; k++) {
815 for (PetscInt i=lxs; i<lxe; i++) {
816 if ( (
sign > 0 && nvert[k][j+1][i] > 0.1) || (
sign < 0 && nvert[k][j][i] > 0.1) )
continue;
818 PetscReal uin_this_point = 0.0;
824 PetscReal umax,diameter=1.0;
829 PetscReal xc = cent[k][j + (
sign>0)][i].x - CMx_c;
830 PetscReal zc = cent[k][j + (
sign>0)][i].z - CMz_c;
831 PetscReal r = sqrt(xc*xc + zc*zc);
832 PetscReal r_norm = 2.0 * r / diameter;
833 uin_this_point = umax * (1.0 - r_norm * r_norm);
834 if (r_norm > 1.0) uin_this_point = 0.0;
838 PetscReal CellArea = sqrt(eta[k][j][i].z*eta[k][j][i].z + eta[k][j][i].y*eta[k][j][i].y + eta[k][j][i].x*eta[k][j][i].x);
840 ucont[k][j][i].
y =
sign * uin_this_point * CellArea;
841 lFluxIn += ucont[k][j][i].
y;
842 ubcs[k][j + (
sign < 0)][i].x =
sign * uin_this_point * eta[k][j][i].x / CellArea;
843 ubcs[k][j + (
sign < 0)][i].y =
sign * uin_this_point * eta[k][j][i].y / CellArea;
844 ubcs[k][j + (
sign < 0)][i].z =
sign * uin_this_point * eta[k][j][i].z / CellArea;
845 ucat[k][j + (
sign > 0)][i] = ubcs[k][j + (
sign < 0)][i];
855 for (PetscInt j=lys; j<lye; j++) {
856 for (PetscInt i=lxs; i<lxe; i++) {
857 if ( (
sign > 0 && nvert[k+1][j][i] > 0.1) || (
sign < 0 && nvert[k][j][i] > 0.1) )
continue;
859 PetscReal uin_this_point = 0.0;
865 PetscReal umax, diameter=1.0;
870 PetscReal xc = cent[k + (
sign>0)][j][i].x - CMx_c;
871 PetscReal yc = cent[k + (
sign>0)][j][i].y - CMy_c;
872 PetscReal r = sqrt(xc*xc + yc*yc);
873 PetscReal r_norm = 2.0 * r / diameter;
874 uin_this_point = umax * (1.0 - r_norm * r_norm);
875 if (r_norm > 1.0) uin_this_point = 0.0;
878 PetscReal CellArea = sqrt(zet[k][j][i].z*zet[k][j][i].z + zet[k][j][i].y*zet[k][j][i].y + zet[k][j][i].x*zet[k][j][i].x);
880 ucont[k][j][i].
z =
sign * uin_this_point * CellArea;
881 lFluxIn += ucont[k][j][i].
z;
882 ubcs[k + (
sign < 0)][j][i].x =
sign * uin_this_point * zet[k][j][i].x / CellArea;
883 ubcs[k + (
sign < 0)][j][i].y =
sign * uin_this_point * zet[k][j][i].y / CellArea;
884 ubcs[k + (
sign < 0)][j][i].z =
sign * uin_this_point * zet[k][j][i].z / CellArea;
885 ucat[k + (
sign > 0)][j][i] = ubcs[k + (
sign < 0)][j][i];
893 ierr = MPI_Allreduce(&lFluxIn, &simCtx->
FluxInSum, 1, MPI_DOUBLE, MPI_SUM, PETSC_COMM_WORLD); CHKERRQ(ierr);
894 ierr = MPI_Allreduce(&lAreaIn, &AreaSumIn, 1, MPI_DOUBLE, MPI_SUM, PETSC_COMM_WORLD); CHKERRQ(ierr);
899 DMDAVecRestoreArray(fda, lCoor, &coor);
900 DMDAVecRestoreArray(fda, user->
Ucont, &ucont);
901 DMDAVecRestoreArray(fda, user->
Bcs.
Ubcs, &ubcs);
902 DMDAVecRestoreArray(fda, user->
Ucat, &ucat);
903 DMDAVecRestoreArray(da, user->
lNvert, &nvert);
904 DMDAVecRestoreArray(fda, user->
Cent, ¢);
905 DMDAVecRestoreArray(fda, user->
lCsi, &csi);
906 DMDAVecRestoreArray(fda, user->
lEta, &eta);
907 DMDAVecRestoreArray(fda, user->
lZet, &zet);
910 DMGlobalToLocalBegin(fda, user->
Ucont, INSERT_VALUES, user->
lUcont);
911 DMGlobalToLocalEnd(fda, user->
Ucont, INSERT_VALUES, user->
lUcont);
915 PetscFunctionReturn(0);
1024 DM da = user->
da, fda = user->
fda;
1025 DMDALocalInfo info = user->
info;
1026 PetscInt xs = info.xs, xe = info.xs + info.xm;
1027 PetscInt ys = info.ys, ye = info.ys + info.ym;
1028 PetscInt zs = info.zs, ze = info.zs + info.zm;
1029 PetscInt mx = info.mx, my = info.my, mz = info.mz;
1030 PetscInt lxs, lxe, lys, lye, lzs, lze;
1033 PetscReal ***nvert,***lnvert;
1035 PetscReal ***p,***lp;
1036 Cmpnts ***ucont, ***ubcs, ***ucat,***lucat, ***csi, ***eta, ***zet;
1037 Cmpnts ***cent,***centx,***centy,***centz,***coor;
1038 PetscScalar FluxIn, FluxOut,ratio;
1039 PetscScalar lArea, AreaSum;
1041 PetscScalar FarFluxIn=0., FarFluxOut=0., FarFluxInSum, FarFluxOutSum;
1042 PetscScalar FarAreaIn=0., FarAreaOut=0., FarAreaInSum, FarAreaOutSum;
1043 PetscScalar FluxDiff, VelDiffIn, VelDiffOut;
1046 PetscReal Un, nx,ny,nz,A;
1054 PetscInt gxs, gxe, gys, gye, gzs, gze;
1056 gxs = info.gxs; gxe = gxs + info.gxm;
1057 gys = info.gys; gye = gys + info.gym;
1058 gzs = info.gzs; gze = gzs + info.gzm;
1060 if (xs==0) lxs = xs+1;
1061 if (ys==0) lys = ys+1;
1062 if (zs==0) lzs = zs+1;
1064 if (xe==mx ) lxe = xe-1;
1065 if (ye==my ) lye = ye-1;
1066 if (ze==mz ) lze = ze-1;
1068 PetscFunctionBeginUser;
1072 DMDAVecGetArray(fda, user->
Bcs.
Ubcs, &ubcs);
1074 DMDAVecGetArray(fda, user->
lCsi, &csi);
1075 DMDAVecGetArray(fda, user->
lEta, &eta);
1076 DMDAVecGetArray(fda, user->
lZet, &zet);
1079 for (ttemp=0; ttemp<3; ttemp++) {
1080 DMDAVecGetArray(da, user->
Nvert, &nvert);
1081 DMDAVecGetArray(fda, user->
lUcat, &ucat);
1082 DMDAVecGetArray(fda, user->
Ucont, &ucont);
1089 FarFluxIn = 0.; FarFluxOut=0.;
1090 FarAreaIn = 0.; FarAreaOut=0.;
1092 PetscReal lFlux_abs=0.0,FluxSum_abs=0.0,ratio=0.0;
1100 if (user->
bctype[0]==6) {
1103 for (k=lzs; k<lze; k++) {
1104 for (j=lys; j<lye; j++) {
1105 ubcs[k][j][i].
x = ucat[k][j][i+1].
x;
1106 ubcs[k][j][i].
y = ucat[k][j][i+1].
y;
1107 ubcs[k][j][i].
z = ucat[k][j][i+1].
z;
1108 ucont[k][j][i].
x = ubcs[k][j][i].
x * csi[k][j][i].
x;
1109 FarFluxIn += ucont[k][j][i].
x;
1110 lFlux_abs += fabs(ucont[k][j][i].x);
1111 FarAreaIn += csi[k][j][i].
x;
1117 if (user->
bctype[1]==6) {
1120 for (k=lzs; k<lze; k++) {
1121 for (j=lys; j<lye; j++) {
1122 ubcs[k][j][i].
x = ucat[k][j][i-1].
x;
1123 ubcs[k][j][i].
y = ucat[k][j][i-1].
y;
1124 ubcs[k][j][i].
z = ucat[k][j][i-1].
z;
1125 ucont[k][j][i-1].
x = ubcs[k][j][i].
x * csi[k][j][i-1].
x;
1126 FarFluxOut += ucont[k][j][i-1].
x;
1127 lFlux_abs += fabs(ucont[k][j][i-1].x);
1128 FarAreaOut += csi[k][j][i-1].
x;
1134 if (user->
bctype[2]==6) {
1137 for (k=lzs; k<lze; k++) {
1138 for (i=lxs; i<lxe; i++) {
1139 ubcs[k][j][i].
x = ucat[k][j+1][i].
x;
1140 ubcs[k][j][i].
y = ucat[k][j+1][i].
y;
1141 ubcs[k][j][i].
z = ucat[k][j+1][i].
z;
1142 ucont[k][j][i].
y = ubcs[k][j][i].
y * eta[k][j][i].
y;
1143 FarFluxIn += ucont[k][j][i].
y;
1144 lFlux_abs += fabs(ucont[k][j][i].y);
1145 FarAreaIn += eta[k][j][i].
y;
1151 if (user->
bctype[3]==6) {
1154 for (k=lzs; k<lze; k++) {
1155 for (i=lxs; i<lxe; i++) {
1156 ubcs[k][j][i].
x = ucat[k][j-1][i].
x;
1157 ubcs[k][j][i].
y = ucat[k][j-1][i].
y;
1158 ubcs[k][j][i].
z = ucat[k][j-1][i].
z;
1159 ucont[k][j-1][i].
y = ubcs[k][j][i].
y * eta[k][j-1][i].
y;
1160 FarFluxOut += ucont[k][j-1][i].
y;
1161 lFlux_abs += fabs(ucont[k][j-1][i].y);
1162 FarAreaOut += eta[k][j-1][i].
y;
1171 for (j=lys; j<lye; j++) {
1172 for (i=lxs; i<lxe; i++) {
1173 ubcs[k][j][i].
x = ucat[k+1][j][i].
x;
1174 ubcs[k][j][i].
y = ucat[k+1][j][i].
y;
1175 ubcs[k][j][i].
z = ucat[k+1][j][i].
z;
1176 ucont[k][j][i].
z = ubcs[k][j][i].
z * zet[k][j][i].
z;
1177 FarFluxIn += ucont[k][j][i].
z;
1178 lFlux_abs += fabs(ucont[k][j][i].z);
1179 FarAreaIn += zet[k][j][i].
z;
1188 for (j=lys; j<lye; j++) {
1189 for (i=lxs; i<lxe; i++) {
1190 ubcs[k][j][i].
x = ucat[k-1][j][i].
x;
1191 ubcs[k][j][i].
y = ucat[k-1][j][i].
y;
1192 ubcs[k][j][i].
z = ucat[k-1][j][i].
z;
1193 ucont[k-1][j][i].
z = ubcs[k][j][i].
z * zet[k-1][j][i].
z;
1194 FarFluxOut += ucont[k-1][j][i].
z;
1195 lFlux_abs += fabs(ucont[k-1][j][i].z);
1196 FarAreaOut += zet[k-1][j][i].
z;
1202 MPI_Allreduce(&FarFluxIn,&FarFluxInSum,1,MPI_DOUBLE,MPI_SUM,PETSC_COMM_WORLD);
1203 MPI_Allreduce(&FarFluxOut,&FarFluxOutSum,1,MPI_DOUBLE,MPI_SUM,PETSC_COMM_WORLD);
1204 MPI_Allreduce(&lFlux_abs,&FluxSum_abs,1,MPI_DOUBLE,MPI_SUM,PETSC_COMM_WORLD);
1205 MPI_Allreduce(&FarAreaIn,&FarAreaInSum,1,MPI_DOUBLE,MPI_SUM,PETSC_COMM_WORLD);
1206 MPI_Allreduce(&FarAreaOut,&FarAreaOutSum,1,MPI_DOUBLE,MPI_SUM,PETSC_COMM_WORLD);
1210 ratio=(FarFluxInSum - FarFluxOutSum)/FluxSum_abs;
1211 if (fabs(FluxSum_abs) <1.e-10) ratio = 0.;
1215 FluxDiff = 0.5*(FarFluxInSum - FarFluxOutSum) ;
1216 VelDiffIn = FluxDiff / FarAreaInSum ;
1218 if (fabs(FarAreaInSum) <1.e-6) VelDiffIn = 0.;
1220 VelDiffOut = FluxDiff / FarAreaOutSum ;
1222 if (fabs(FarAreaOutSum) <1.e-6) VelDiffOut = 0.;
1224 LOG_ALLOW(
GLOBAL,
LOG_DEBUG,
"Far Flux Diff %d %le %le %le %le %le %le %le\n", simCtx->
step, FarFluxInSum, FarFluxOutSum, FluxDiff, FarAreaInSum, FarAreaOutSum, VelDiffIn, VelDiffOut);
1228 if (user->
bctype[5]==10) {
1229 FluxDiff = simCtx->
FluxInSum -( FarFluxOutSum -FarFluxInSum) ;
1230 VelDiffIn = 1/3.*FluxDiff / (FarAreaInSum);
1231 if (fabs(FarAreaInSum) <1.e-6) VelDiffIn = 0.;
1233 VelDiffOut = 2./3.* FluxDiff / (FarAreaOutSum) ;
1235 if (fabs(FarAreaOutSum) <1.e-6) VelDiffOut = 0.;
1237 LOG_ALLOW(
GLOBAL,
LOG_DEBUG,
"Far Flux Diff %d %le %le %le %le %le %le %le\n", simCtx->
step, FarFluxInSum, FarFluxOutSum, FluxDiff, FarAreaInSum, FarAreaOutSum, VelDiffIn, VelDiffOut);
1247 for (j=lys; j<lye; j++) {
1248 for (i=lxs; i<lxe; i++) {
1249 ucont[k-1][j][i].
z += ratio*fabs(ucont[k-1][j][i].z);
1250 ubcs[k][j][i].
z = ucont[k-1][j][i].
z/zet[k-1][j][i].
z;
1258 if (user->
bctype[3]==6) {
1261 for (k=lzs; k<lze; k++) {
1262 for (i=lxs; i<lxe; i++) {
1264 ucont[k][j-1][i].
y +=ratio*fabs(ucont[k][j-1][i].y);
1265 ubcs[k][j][i].
y = ucont[k][j-1][i].
y /eta[k][j-1][i].
y;
1274 if (user->
bctype[1]==6) {
1277 for (k=lzs; k<lze; k++) {
1278 for (j=lys; j<lye; j++) {
1279 ucont[k][j][i-1].
x +=ratio*fabs(ucont[k][j][i-1].x);
1280 ubcs[k][j][i].
x = ucont[k][j][i-1].
x / csi[k][j][i-1].
x ;
1289 if (user->
bctype[0]==6) {
1292 for (k=lzs; k<lze; k++) {
1293 for (j=lys; j<lye; j++) {
1294 ucont[k][j][i].
x -=ratio*fabs(ucont[k][j][i].x);
1295 ubcs[k][j][i].
x = ucont[k][j][i].
x / csi[k][j][i].
x;
1304 if (user->
bctype[2]==6) {
1307 for (k=lzs; k<lze; k++) {
1308 for (i=lxs; i<lxe; i++) {
1309 ucont[k][j][i].
y -=ratio*fabs(ucont[k][j][i].y);
1310 ubcs[k][j][i].
y = ucont[k][j][i].
y / eta[k][j][i].
y;
1322 for (j=lys; j<lye; j++) {
1323 for (i=lxs; i<lxe; i++) {
1324 ucont[k][j][i].
z -=ratio*fabs(ucont[k][j][i].z);
1325 ubcs[k][j][i].
z =ucont[k][j][i].
z / zet[k][j][i].
z;
1339 for (k=lzs; k<lze; k++) {
1340 for (i=lxs; i<lxe; i++) {
1341 A=sqrt(eta[k][j][i].z*eta[k][j][i].z +
1342 eta[k][j][i].y*eta[k][j][i].y +
1343 eta[k][j][i].x*eta[k][j][i].x);
1344 nx=eta[k][j][i].
x/A;
1345 ny=eta[k][j][i].
y/A;
1346 nz=eta[k][j][i].
z/A;
1347 Un=ucat[k][j+1][i].
x*nx+ucat[k][j+1][i].
y*ny+ucat[k][j+1][i].
z*nz;
1348 ubcs[k][j][i].
x = 0.0;
1349 ubcs[k][j][i].
y = 0.0;
1350 ubcs[k][j][i].
z = 0.0;
1351 ucont[k][j][i].
y = 0.;
1369 for (k=lzs; k<lze; k++) {
1370 for (j=lys; j<lye; j++) {
1371 ubcs[k][j][i].
x = 0.0;
1372 ubcs[k][j][i].
y = 0.0;
1373 ubcs[k][j][i].
z = 0.0;
1374 ucont[k][j][i].
x = 0.0;
1384 for (k=lzs; k<lze; k++) {
1385 for (j=lys; j<lye; j++) {
1386 ubcs[k][j][i].
x = 0.0;
1387 ubcs[k][j][i].
y = 0.0;
1388 ubcs[k][j][i].
z = 0.0;
1390 ucont[k][j][i-1].
x = 0.0;
1400 for (k=lzs; k<lze; k++) {
1401 for (i=lxs; i<lxe; i++) {
1402 ubcs[k][j][i].
x = 0.0;
1403 ubcs[k][j][i].
y = 0.0;
1404 ubcs[k][j][i].
z = 0.0;
1405 ucont[k][j][i].
y = 0.0;
1415 for (k=lzs; k<lze; k++) {
1416 for (i=lxs; i<lxe; i++) {
1417 ubcs[k][j][i].
x = 0.0;
1418 ubcs[k][j][i].
y = 0.0;
1419 ubcs[k][j][i].
z = 0.0;
1421 ucont[k][j-1][i].
y = 0.0;
1436 if (user->
bctype[0]==3) {
1440 for (k=lzs; k<lze; k++) {
1441 for (j=lys; j<lye; j++) {
1442 A=sqrt(csi[k][j][i].z*csi[k][j][i].z +
1443 csi[k][j][i].y*csi[k][j][i].y +
1444 csi[k][j][i].x*csi[k][j][i].x);
1445 nx=csi[k][j][i].
x/A;
1446 ny=csi[k][j][i].
y/A;
1447 nz=csi[k][j][i].
z/A;
1448 Un=ucat[k][j][i+1].
x*nx+ucat[k][j][i+1].
y*ny+ucat[k][j][i+1].
z*nz;
1449 ubcs[k][j][i].
x = ucat[k][j][i+1].
x-Un*nx;
1450 ubcs[k][j][i].
y = ucat[k][j][i+1].
y-Un*ny;
1451 ubcs[k][j][i].
z = ucat[k][j][i+1].
z-Un*nz;
1452 ucont[k][j][i].
x = 0.;
1458 if (user->
bctype[1]==3) {
1462 for (k=lzs; k<lze; k++) {
1463 for (j=lys; j<lye; j++) {
1464 A=sqrt(csi[k][j][i-1].z*csi[k][j][i-1].z +
1465 csi[k][j][i-1].y*csi[k][j][i-1].y +
1466 csi[k][j][i-1].x*csi[k][j][i-1].x);
1467 nx=csi[k][j][i-1].
x/A;
1468 ny=csi[k][j][i-1].
y/A;
1469 nz=csi[k][j][i-1].
z/A;
1470 Un=ucat[k][j][i-1].
x*nx+ucat[k][j][i-1].
y*ny+ucat[k][j][i-1].
z*nz;
1471 ubcs[k][j][i].
x = ucat[k][j][i-1].
x-Un*nx;
1472 ubcs[k][j][i].
y = ucat[k][j][i-1].
y-Un*ny;
1473 ubcs[k][j][i].
z = ucat[k][j][i-1].
z-Un*nz;
1474 ucont[k][j][i-1].
x = 0.;
1480 if (user->
bctype[2]==3) {
1484 for (k=lzs; k<lze; k++) {
1485 for (i=lxs; i<lxe; i++) {
1486 A=sqrt(eta[k][j][i].z*eta[k][j][i].z +
1487 eta[k][j][i].y*eta[k][j][i].y +
1488 eta[k][j][i].x*eta[k][j][i].x);
1489 nx=eta[k][j][i].
x/A;
1490 ny=eta[k][j][i].
y/A;
1491 nz=eta[k][j][i].
z/A;
1492 Un=ucat[k][j+1][i].
x*nx+ucat[k][j+1][i].
y*ny+ucat[k][j+1][i].
z*nz;
1493 ubcs[k][j][i].
x = ucat[k][j+1][i].
x-Un*nx;
1494 ubcs[k][j][i].
y = ucat[k][j+1][i].
y-Un*ny;
1495 ubcs[k][j][i].
z = ucat[k][j+1][i].
z-Un*nz;
1496 ucont[k][j][i].
y = 0.;
1502 if (user->
bctype[3]==3) {
1506 for (k=lzs; k<lze; k++) {
1507 for (i=lxs; i<lxe; i++) {
1508 A=sqrt(eta[k][j-1][i].z*eta[k][j-1][i].z +
1509 eta[k][j-1][i].y*eta[k][j-1][i].y +
1510 eta[k][j-1][i].x*eta[k][j-1][i].x);
1511 nx=eta[k][j-1][i].
x/A;
1512 ny=eta[k][j-1][i].
y/A;
1513 nz=eta[k][j-1][i].
z/A;
1514 Un=ucat[k][j-1][i].
x*nx+ucat[k][j-1][i].
y*ny+ucat[k][j-1][i].
z*nz;
1515 ubcs[k][j][i].
x = ucat[k][j-1][i].
x-Un*nx;
1516 ubcs[k][j][i].
y = ucat[k][j-1][i].
y-Un*ny;
1517 ubcs[k][j][i].
z = ucat[k][j-1][i].
z-Un*nz;
1518 ucont[k][j-1][i].
y = 0.;
1525 if (user->
bctype[4]==3) {
1528 for (j=lys; j<lye; j++) {
1529 for (i=lxs; i<lxe; i++) {
1530 A=sqrt(zet[k][j][i].z*zet[k][j][i].z +
1531 zet[k][j][i].y*zet[k][j][i].y +
1532 zet[k][j][i].x*zet[k][j][i].x);
1533 nx=zet[k][j][i].
x/A;
1534 ny=zet[k][j][i].
y/A;
1535 nz=zet[k][j][i].
z/A;
1536 Un=ucat[k+1][j][i].
x*nx+ucat[k+1][j][i].
y*ny+ucat[k+1][j][i].
z*nz;
1537 ubcs[k][j][i].
x = ucat[k+1][j][i].
x-Un*nx;
1538 ubcs[k][j][i].
y = ucat[k+1][j][i].
y-Un*ny;
1539 ubcs[k][j][i].
z = ucat[k+1][j][i].
z-Un*nz;
1540 ucont[k][j][i].
z = 0.;
1546 if (user->
bctype[5]==3) {
1549 for (j=lys; j<lye; j++) {
1550 for (i=lxs; i<lxe; i++) {
1551 A=sqrt(zet[k-1][j][i].z*zet[k-1][j][i].z +
1552 zet[k-1][j][i].y*zet[k-1][j][i].y +
1553 zet[k-1][j][i].x*zet[k-1][j][i].x);
1554 nx=zet[k-1][j][i].
x/A;
1555 ny=zet[k-1][j][i].
y/A;
1556 nz=zet[k-1][j][i].
z/A;
1557 Un=ucat[k-1][j][i].
x*nx+ucat[k-1][j][i].
y*ny+ucat[k-1][j][i].
z*nz;
1558 ubcs[k][j][i].
x = ucat[k-1][j][i].
x-Un*nx;
1559 ubcs[k][j][i].
y = ucat[k-1][j][i].
y-Un*ny;
1560 ubcs[k][j][i].
z = ucat[k-1][j][i].
z-Un*nz;
1561 ucont[k-1][j][i].
z = 0.;
1571 if (user->
bctype[5]==8) {
1575 for (j=lys; j<lye; j++) {
1576 for (i=lxs; i<lxe; i++) {
1577 FluxOut += ucont[k][j][i].
z;
1585 FluxIn = simCtx->
FluxInSum + FarFluxInSum;
1587 MPI_Allreduce(&FluxOut,&simCtx->
FluxOutSum,1,MPI_DOUBLE,MPI_SUM,PETSC_COMM_WORLD);
1592 if (fabs(simCtx->
FluxOutSum) < 1.e-6) ratio = 1.;
1594 if (fabs(FluxIn) <1.e-6) ratio = 0.;
1599 for (j=lys; j<lye; j++) {
1600 for (i=lxs; i<lxe; i++) {
1601 ubcs[k][j][i].
x = ucat[k-1][j][i].
x;
1602 ubcs[k][j][i].
y = ucat[k-1][j][i].
y;
1603 if (simCtx->
step==0 || simCtx->
step==1)
1605 ubcs[k][j][i].
z = -1.;
1606 else if (user->
bctype[4]==6)
1607 ubcs[k][j][i].
z = 0.;
1609 ubcs[k][j][i].
z = 1.;
1612 ucont[k-1][j][i].
z = ucont[k-1][j][i].
z*ratio;
1614 ubcs[k][j][i].
z = ucont[k-1][j][i].
z / zet[k-1][j][i].
z;
1634 for (j=lys; j<lye; j++) {
1635 for (i=lxs; i<lxe; i++) {
1637 if ((nvert[k-1][j][i])<0.1) {
1638 FluxOut += (ucat[k-1][j][i].
x * (zet[k-1][j][i].
x) +
1639 ucat[k-1][j][i].y * (zet[k-1][j][i].y) +
1640 ucat[k-1][j][i].
z * (zet[k-1][j][i].
z));
1642 lArea += sqrt( (zet[k-1][j][i].x) * (zet[k-1][j][i].x) +
1643 (zet[k-1][j][i].y) * (zet[k-1][j][i].y) +
1644 (zet[k-1][j][i].z) * (zet[k-1][j][i].z));
1654 MPI_Allreduce(&FluxOut,&simCtx->
FluxOutSum,1,MPI_DOUBLE,MPI_SUM,PETSC_COMM_WORLD);
1655 MPI_Allreduce(&lArea,&AreaSum,1,MPI_DOUBLE,MPI_SUM,PETSC_COMM_WORLD);
1670 ratio = (FluxIn - simCtx->
FluxOutSum) / AreaSum;
1679 for (j=lys; j<lye; j++) {
1680 for (i=lxs; i<lxe; i++) {
1681 if ((nvert[k-1][j][i])<0.1) {
1683 ubcs[k][j][i].
x = ucat[k-1][j][i].
x;
1684 ubcs[k][j][i].
y = ucat[k-1][j][i].
y;
1685 ubcs[k][j][i].
z = ucat[k-1][j][i].
z;
1689 ucont[k-1][j][i].
z = (ubcs[k][j][i].
x * (zet[k-1][j][i].
x ) +
1690 ubcs[k][j][i].y * (zet[k-1][j][i].y ) +
1691 ubcs[k][j][i].
z * (zet[k-1][j][i].
z ))*ratio;
1694 ucont[k-1][j][i].
z = (ubcs[k][j][i].
x * (zet[k-1][j][i].
x ) +
1695 ubcs[k][j][i].y * (zet[k-1][j][i].y ) +
1696 ubcs[k][j][i].
z * (zet[k-1][j][i].
z ))
1697 + ratio * sqrt( (zet[k-1][j][i].x) * (zet[k-1][j][i].x) +
1698 (zet[k-1][j][i].y) * (zet[k-1][j][i].y) +
1699 (zet[k-1][j][i].z) * (zet[k-1][j][i].z));
1701 FluxOut += ucont[k-1][j][i].
z;
1708 MPI_Allreduce(&FluxOut,&simCtx->
FluxOutSum,1,MPI_DOUBLE,MPI_SUM,PETSC_COMM_WORLD);
1711 }
else if (user->
bctype[5]==2) {
1716 for (j=lys; j<lye; j++) {
1717 for (i=lxs; i<lxe; i++) {
1718 ubcs[k][j][i].
x = 0.;
1719 ubcs[k][j][i].
y = 1;
1720 ubcs[k][j][i].
z = 0.;
1734 for (j=lys; j<lye; j++) {
1735 for (i=lxs; i<lxe; i++) {
1738 FluxOut += ucat[k+1][j][i].
z * zet[k][j][i].
z ;
1740 lArea += zet[k][j][i].
z;
1751 FluxIn = simCtx->
FluxInSum + FarFluxInSum;
1753 MPI_Allreduce(&FluxOut,&simCtx->
FluxOutSum,1,MPI_DOUBLE,MPI_SUM,PETSC_COMM_WORLD);
1754 MPI_Allreduce(&lArea,&AreaSum,1,MPI_DOUBLE,MPI_SUM,PETSC_COMM_WORLD);
1762 for (j=lys; j<lye; j++) {
1763 for (i=lxs; i<lxe; i++) {
1764 ubcs[k][j][i].
x = ucat[k+1][j][i].
x;
1765 ubcs[k][j][i].
y = ucat[k+1][j][i].
y;
1766 ubcs[k][j][i].
z = ucat[k+1][j][i].
z;
1767 ucont[k][j][i].
z = (ubcs[k][j][i].
z+ratio) * zet[k][j][i].z;
1849 Vec Coor; DMGetCoordinatesLocal(da, &Coor);
1850 DMDAVecGetArray(fda,Coor,&coor);
1852 DMDAVecGetArray(fda, user->
Bcs.
Uch, &uch);
1859 double Fluxbcs=0.0, Fluxbcssum,ratiobcs;
1864 for (j=lys; j<lye; j++) {
1865 for (i=lxs; i<lxe; i++) {
1866 if (nvert[k][j][i]<0.1){
1867 Fluxbcs += ucont[k][j][i].
z;
1869 lArea += sqrt((zet[k][j][i].x) * (zet[k][j][i].x) +
1870 (zet[k][j][i].y) * (zet[k][j][i].y) +
1871 (zet[k][j][i].z) * (zet[k][j][i].z));
1880 for (k=zs;k<lze;k++){
1881 for (j=lys; j<lye; j++) {
1882 for (i=lxs; i<lxe; i++) {
1883 if (nvert[k][j][i]<0.1){
1884 FluxIn += ucont[k][j][i].
z /((mz)-1);
1893 MPI_Allreduce(&FluxIn,&simCtx->
Fluxsum,1,MPI_DOUBLE,MPI_SUM,PETSC_COMM_WORLD);
1894 MPI_Allreduce(&lArea,&AreaSum,1,MPI_DOUBLE,MPI_SUM,PETSC_COMM_WORLD);
1895 MPI_Allreduce(&Fluxbcs,&Fluxbcssum,1,MPI_DOUBLE,MPI_SUM,PETSC_COMM_WORLD);
1906 simCtx->
ratio=ratio;
1907 ratiobcs=(simCtx->
FluxInSum-Fluxbcssum)/AreaSum;
1911 for (j=lys; j<lye; j++) {
1912 for (i=lxs; i<lxe; i++) {
1913 if (nvert[k+1][j][i]<0.1){
1915 ucont[k][j][i].
z+=ratiobcs * sqrt( (zet[k+1][j][i].x) * (zet[k+1][j][i].x) +
1916 (zet[k+1][j][i].y) * (zet[k+1][j][i].y) +
1917 (zet[k+1][j][i].z) * (zet[k+1][j][i].z));
1920 uch[k][j][i].
z=ratiobcs * sqrt( (zet[k+1][j][i].x) * (zet[k+1][j][i].x) +
1921 (zet[k+1][j][i].y) * (zet[k+1][j][i].y) +
1922 (zet[k+1][j][i].z) * (zet[k+1][j][i].z));
1930 for (j=lys; j<lye; j++) {
1931 for (i=lxs; i<lxe; i++) {
1932 if (nvert[k-1][j][i]<0.1){
1934 ucont[k-1][j][i].
z+=ratiobcs * sqrt((zet[k-1][j][i].x) * (zet[k-1][j][i].x) +
1935 (zet[k-1][j][i].y) * (zet[k-1][j][i].y) +
1936 (zet[k-1][j][i].z) * (zet[k-1][j][i].z));
1938 uch[k][j][i].
z=ratiobcs * sqrt( (zet[k+1][j][i].x) * (zet[k+1][j][i].x) +
1939 (zet[k+1][j][i].y) * (zet[k+1][j][i].y) +
1940 (zet[k+1][j][i].z) * (zet[k+1][j][i].z));
1945 DMDAVecRestoreArray(fda, user->
Bcs.
Uch, &uch);
1947 DMDAVecRestoreArray(fda,Coor,&coor);
1986 if (user->
bctype[3]==12) {
1991 for (k=lzs; k<lze; k++) {
1992 for (i=lxs; i<lxe; i++) {
1993 ubcs[k][j][i].
x = 0.;
1994 ubcs[k][j][i].
y = 0.;
1995 ubcs[k][j][i].
z = 1.;
2004 DMDAVecGetArray(fda, user->
Cent, ¢);
2005 if (user->
bctype[2]==11) {
2008 for (k=lzs; k<lze; k++) {
2009 for (i=lxs; i<lxe; i++) {
2016 ubcs[k][j][i].
x = cent[k][j+1][i].
y/sqrt(cent[k][j+1][i].x*cent[k][j+1][i].x+cent[k][j+1][i].y*cent[k][j+1][i].y);;
2017 ubcs[k][j][i].
y =-cent[k][j+1][i].
x/sqrt(cent[k][j+1][i].x*cent[k][j+1][i].x+cent[k][j+1][i].y*cent[k][j+1][i].y);
2018 ubcs[k][j][i].
z =0.0;
2032 if (user->
bctype[2]==13){
2035 for (k=lzs; k<lze; k++) {
2036 for (i=lxs; i<lxe; i++) {
2037 ubcs[k][j][i].
x = 0.;
2039 ubcs[k][j][i].
y = 0.;
2040 ubcs[k][j][i].
z = -simCtx->
U_bc;
2046 if (user->
bctype[3]==13){
2049 for (k=lzs; k<lze; k++) {
2050 for (i=lxs; i<lxe; i++) {
2051 ubcs[k][j][i].
x = 0.;
2053 ubcs[k][j][i].
y = 0.;
2054 ubcs[k][j][i].
z = simCtx->
U_bc;
2061 if (user->
bctype[4]==13){
2064 for (j=lys; j<lye; j++) {
2065 for (i=lxs; i<lxe; i++) {
2066 ubcs[k][j][i].
x =-simCtx->
U_bc;
2067 ubcs[k][j][i].
y = 0.;
2068 ubcs[k][j][i].
z = 0.;
2073 if (user->
bctype[5]==13){
2076 for (j=lys; j<lye; j++) {
2077 for (i=lxs; i<lxe; i++) {
2078 ubcs[k][j][i].
x = simCtx->
U_bc;
2079 ubcs[k][j][i].
y = 0.;
2080 ubcs[k][j][i].
z = 0.;
2085 DMDAVecRestoreArray(fda, user->
Cent, ¢);
2086 DMDAVecRestoreArray(fda, user->
lUcat, &ucat);
2087 DMDAVecRestoreArray(fda, user->
Ucont, &ucont);
2088 DMDAVecRestoreArray(da, user->
Nvert, &nvert);
2089 DMGlobalToLocalBegin(fda, user->
Ucont, INSERT_VALUES, user->
lUcont);
2090 DMGlobalToLocalEnd(fda, user->
Ucont, INSERT_VALUES, user->
lUcont);
2101 PetscReal ***ustar, ***aj;
2104 DMDAVecGetArray(fda, user->
Ucat, &ucat);
2105 DMDAVecGetArray(fda, user->
Ucont, &ucont);
2106 DMDAVecGetArray(da, Aj, &aj);
2108 DMDAVecGetArray(da, user->
lUstar, &ustar);
2111 for (k=lzs; k<lze; k++)
2112 for (j=lys; j<lye; j++)
2113 for (i=lxs; i<lxe; i++) {
2115 if( nvert[k][j][i]<1.1 && user->
bctype[2]==-1 && j==1 )
2117 double area = sqrt( eta[k][j][i].x*eta[k][j][i].x + eta[k][j][i].y*eta[k][j][i].y + eta[k][j][i].z*eta[k][j][i].z );
2119 double ni[3], nj[3], nk[3];
2122 Ua.
x = Ua.
y = Ua.
z = 0;
2123 sb = 0.5/aj[k][j][i]/area;
2126 sc = 2*sb + 0.5/aj[k][j+1][i]/area;
2127 Uc = ucat[k][j+1][i];
2133 double AA=sqrt(eta[k][j][i].z*eta[k][j][i].z +
2134 eta[k][j][i].y*eta[k][j][i].y +
2135 eta[k][j][i].x*eta[k][j][i].x);
2136 nj[0]=eta[k][j][i].
x/AA;
2137 nj[1]=eta[k][j][i].
y/AA;
2138 nj[2]=eta[k][j][i].
z/AA;
2139 noslip (user, sc, sb, Ua, Uc, &ucat[k][j][i], nj[0], nj[1], nj[2]);
2140 wall_function_loglaw(user, 1.e-16, sc, sb, Ua, Uc, &ucat[k][j][i], &ustar[k][j][i], nj[0], nj[1], nj[2]);
2151 for (k=lzs; k<lze; k++) {
2152 for (i=lxs; i<lxe; i++) {
2153 ubcs[k][j][i].
x = 0.0;
2154 ubcs[k][j][i].
y = 0.0;
2155 ubcs[k][j][i].
z = 0.0;
2156 ucont[k][j][i].
y = 0.;
2161 DMDAVecRestoreArray(da, Aj, &aj);
2162 DMDAVecRestoreArray(da, user->
lUstar, &ustar);
2163 DMDAVecRestoreArray(fda, user->
Ucat, &ucat);
2164 DMDAVecRestoreArray(fda, user->
Ucont, &ucont);
2169 DMGlobalToLocalBegin(fda, user->
Ucat, INSERT_VALUES, user->
lUcat);
2170 DMGlobalToLocalEnd(fda, user->
Ucat, INSERT_VALUES, user->
lUcat);
2179 DMDAVecGetArray(fda, user->
Ucat, &ucat);
2184 if (xs==0 && user->
bctype[0]!=7) {
2186 for (k=lzs; k<lze; k++) {
2187 for (j=lys; j<lye; j++) {
2188 ucat[k][j][i].
x = 2 * ubcs[k][j][i].
x - ucat[k][j][i+1].
x;
2189 ucat[k][j][i].
y = 2 * ubcs[k][j][i].
y - ucat[k][j][i+1].
y;
2190 ucat[k][j][i].
z = 2 * ubcs[k][j][i].
z - ucat[k][j][i+1].
z;
2195 if (xe==mx && user->
bctype[0]!=7) {
2197 for (k=lzs; k<lze; k++) {
2198 for (j=lys; j<lye; j++) {
2199 ucat[k][j][i].
x = 2 * ubcs[k][j][i].
x - ucat[k][j][i-1].
x;
2200 ucat[k][j][i].
y = 2 * ubcs[k][j][i].
y - ucat[k][j][i-1].
y;
2201 ucat[k][j][i].
z = 2 * ubcs[k][j][i].
z - ucat[k][j][i-1].
z;
2207 if (ys==0 && user->
bctype[2]!=7) {
2209 for (k=lzs; k<lze; k++) {
2210 for (i=lxs; i<lxe; i++) {
2211 ucat[k][j][i].
x = 2 * ubcs[k][j][i].
x - ucat[k][j+1][i].
x;
2212 ucat[k][j][i].
y = 2 * ubcs[k][j][i].
y - ucat[k][j+1][i].
y;
2213 ucat[k][j][i].
z = 2 * ubcs[k][j][i].
z - ucat[k][j+1][i].
z;
2218 if (ye==my && user->
bctype[2]!=7) {
2220 for (k=lzs; k<lze; k++) {
2221 for (i=lxs; i<lxe; i++) {
2222 ucat[k][j][i].
x = 2 * ubcs[k][j][i].
x - ucat[k][j-1][i].
x;
2223 ucat[k][j][i].
y = 2 * ubcs[k][j][i].
y - ucat[k][j-1][i].
y;
2224 ucat[k][j][i].
z = 2 * ubcs[k][j][i].
z - ucat[k][j-1][i].
z;
2229 if (zs==0 && user->
bctype[4]!=7) {
2231 for (j=lys; j<lye; j++) {
2232 for (i=lxs; i<lxe; i++) {
2233 ucat[k][j][i].
x = 2 * ubcs[k][j][i].
x - ucat[k+1][j][i].
x;
2234 ucat[k][j][i].
y = 2 * ubcs[k][j][i].
y - ucat[k+1][j][i].
y;
2235 ucat[k][j][i].
z = 2 * ubcs[k][j][i].
z - ucat[k+1][j][i].
z;
2240 if (ze==mz && user->
bctype[4]!=7) {
2242 for (j=lys; j<lye; j++) {
2243 for (i=lxs; i<lxe; i++) {
2244 ucat[k][j][i].
x = 2 * ubcs[k][j][i].
x - ucat[k-1][j][i].
x;
2245 ucat[k][j][i].
y = 2 * ubcs[k][j][i].
y - ucat[k-1][j][i].
y;
2246 ucat[k][j][i].
z = 2 * ubcs[k][j][i].
z - ucat[k-1][j][i].
z;
2251 DMDAVecRestoreArray(fda, user->
Ucat, &ucat);
2256 DMGlobalToLocalBegin(fda, user->
Ucat, INSERT_VALUES, user->
lUcat);
2257 DMGlobalToLocalEnd(fda, user->
Ucat, INSERT_VALUES, user->
lUcat);
2258 DMGlobalToLocalBegin(da, user->
P, INSERT_VALUES, user->
lP);
2259 DMGlobalToLocalEnd(da, user->
P, INSERT_VALUES, user->
lP);
2263 DMDAVecGetArray(da, user->
lP, &lp);
2264 DMDAVecGetArray(da, user->
lNvert, &lnvert);
2265 DMDAVecGetArray(fda, user->
lUcat, &lucat);
2266 DMDAVecGetArray(da, user->
P, &p);
2267 DMDAVecGetArray(da, user->
Nvert, &nvert);
2268 DMDAVecGetArray(fda, user->
Ucat, &ucat);
2273 for (k=zs; k<ze; k++) {
2274 for (j=ys; j<ye; j++) {
2275 if(j>0 && k>0 && j<user->JM && k<user->KM){
2276 ucat[k][j][i]=lucat[k][j][i-2];
2277 p[k][j][i]=lp[k][j][i-2];
2278 nvert[k][j][i]=lnvert[k][j][i-2];
2287 for (k=zs; k<ze; k++) {
2288 for (i=xs; i<xe; i++) {
2289 if(i>0 && k>0 && i<user->IM && k<user->KM){
2290 ucat[k][j][i]=lucat[k][j-2][i];
2291 p[k][j][i]=lp[k][j-2][i];
2292 nvert[k][j][i]=lnvert[k][j-2][i];
2301 for (j=ys; j<ye; j++) {
2302 for (i=xs; i<xe; i++) {
2303 if(i>0 && j>0 && i<user->IM && j<user->JM){
2304 ucat[k][j][i]=lucat[k-2][j][i];
2305 nvert[k][j][i]=lnvert[k-2][j][i];
2307 p[k][j][i]=lp[k-2][j][i];
2316 for (k=zs; k<ze; k++) {
2317 for (j=ys; j<ye; j++) {
2318 if(j>0 && k>0 && j<user->JM && k<user->KM){
2319 ucat[k][j][i]=lucat[k][j][i+2];
2320 p[k][j][i]=lp[k][j][i+2];
2321 nvert[k][j][i]=lnvert[k][j][i+2];
2330 for (k=zs; k<ze; k++) {
2331 for (i=xs; i<xe; i++) {
2332 if(i>0 && k>0 && i<user->IM && k<user->KM){
2333 ucat[k][j][i]=lucat[k][j+2][i];
2334 p[k][j][i]=lp[k][j+2][i];
2335 nvert[k][j][i]=lnvert[k][j+2][i];
2345 for (j=ys; j<ye; j++) {
2346 for (i=xs; i<xe; i++) {
2347 if(i>0 && j>0 && i<user->IM && j<user->JM){
2348 ucat[k][j][i]=lucat[k+2][j][i];
2349 nvert[k][j][i]=lnvert[k+2][j][i];
2351 p[k][j][i]=lp[k+2][j][i];
2362 DMDAVecRestoreArray(fda, user->
lUcat, &lucat);
2363 DMDAVecRestoreArray(da, user->
lP, &lp);
2364 DMDAVecRestoreArray(da, user->
lNvert, &lnvert);
2365 DMDAVecRestoreArray(fda, user->
Ucat, &ucat);
2366 DMDAVecRestoreArray(da, user->
P, &p);
2367 DMDAVecRestoreArray(da, user->
Nvert, &nvert);
2378 DMGlobalToLocalBegin(fda, user->
Ucat, INSERT_VALUES, user->
lUcat);
2379 DMGlobalToLocalEnd(fda, user->
Ucat, INSERT_VALUES, user->
lUcat);
2381 DMGlobalToLocalBegin(da, user->
P, INSERT_VALUES, user->
lP);
2382 DMGlobalToLocalEnd(da, user->
P, INSERT_VALUES, user->
lP);
2384 DMGlobalToLocalBegin(da, user->
Nvert, INSERT_VALUES, user->
lNvert);
2385 DMGlobalToLocalEnd(da, user->
Nvert, INSERT_VALUES, user->
lNvert);
2389 DMDAVecGetArray(fda, user->
Ucat, &ucat);
2390 DMDAVecGetArray(da, user->
P, &p);
2396 for (j=ys; j<ye; j++) {
2397 ucat[k][j][i].
x = 0.5*(ucat[k+1][j][i].
x+ucat[k][j][i+1].
x);
2398 ucat[k][j][i].
y = 0.5*(ucat[k+1][j][i].
y+ucat[k][j][i+1].
y);
2399 ucat[k][j][i].
z = 0.5*(ucat[k+1][j][i].
z+ucat[k][j][i+1].
z);
2400 p[k][j][i]= 0.5*(p[k+1][j][i]+p[k][j][i+1]);
2405 for (j=ys; j<ye; j++) {
2406 ucat[k][j][i].
x = 0.5*(ucat[k+1][j][i].
x+ucat[k][j][i-1].
x);
2407 ucat[k][j][i].
y = 0.5*(ucat[k+1][j][i].
y+ucat[k][j][i-1].
y);
2408 ucat[k][j][i].
z = 0.5*(ucat[k+1][j][i].
z+ucat[k][j][i-1].
z);
2409 p[k][j][i] = 0.5*(p[k+1][j][i]+p[k][j][i-1]);
2415 for (i=xs; i<xe; i++) {
2416 ucat[k][j][i].
x = 0.5*(ucat[k+1][j][i].
x+ucat[k][j+1][i].
x);
2417 ucat[k][j][i].
y = 0.5*(ucat[k+1][j][i].
y+ucat[k][j+1][i].
y);
2418 ucat[k][j][i].
z = 0.5*(ucat[k+1][j][i].
z+ucat[k][j+1][i].
z);
2419 p[k][j][i] = 0.5*(p[k+1][j][i]+p[k][j+1][i]);
2425 for (i=xs; i<xe; i++) {
2426 ucat[k][j][i].
x = 0.5*(ucat[k+1][j][i].
x+ucat[k][j-1][i].
x);
2427 ucat[k][j][i].
y = 0.5*(ucat[k+1][j][i].
y+ucat[k][j-1][i].
y);
2428 ucat[k][j][i].
z = 0.5*(ucat[k+1][j][i].
z+ucat[k][j-1][i].
z);
2429 p[k][j][i] = 0.5*(p[k+1][j][i]+p[k][j-1][i]);
2438 for (j=ys; j<ye; j++) {
2439 ucat[k][j][i].
x = 0.5*(ucat[k-1][j][i].
x+ucat[k][j][i+1].
x);
2440 ucat[k][j][i].
y = 0.5*(ucat[k-1][j][i].
y+ucat[k][j][i+1].
y);
2441 ucat[k][j][i].
z = 0.5*(ucat[k-1][j][i].
z+ucat[k][j][i+1].
z);
2442 p[k][j][i] = 0.5*(p[k-1][j][i]+p[k][j][i+1]);
2447 for (j=ys; j<ye; j++) {
2448 ucat[k][j][i].
x = 0.5*(ucat[k-1][j][i].
x+ucat[k][j][i-1].
x);
2449 ucat[k][j][i].
y = 0.5*(ucat[k-1][j][i].
y+ucat[k][j][i-1].
y);
2450 ucat[k][j][i].
z = 0.5*(ucat[k-1][j][i].
z+ucat[k][j][i-1].
z);
2451 p[k][j][i] = 0.5*(p[k-1][j][i]+p[k][j][i-1]);
2457 for (i=xs; i<xe; i++) {
2458 ucat[k][j][i].
x = 0.5*(ucat[k-1][j][i].
x+ucat[k][j+1][i].
x);
2459 ucat[k][j][i].
y = 0.5*(ucat[k-1][j][i].
y+ucat[k][j+1][i].
y);
2460 ucat[k][j][i].
z = 0.5*(ucat[k-1][j][i].
z+ucat[k][j+1][i].
z);
2461 p[k][j][i] = 0.5*(p[k-1][j][i]+p[k][j+1][i]);
2467 for (i=xs; i<xe; i++) {
2468 ucat[k][j][i].
x = 0.5*(ucat[k-1][j][i].
x+ucat[k][j-1][i].
x);
2469 ucat[k][j][i].
y = 0.5*(ucat[k-1][j][i].
y+ucat[k][j-1][i].
y);
2470 ucat[k][j][i].
z = 0.5*(ucat[k-1][j][i].
z+ucat[k][j-1][i].
z);
2471 p[k][j][i] = 0.5*(p[k-1][j][i]+p[k][j-1][i]);
2480 for (k=zs; k<ze; k++) {
2481 ucat[k][j][i].
x = 0.5*(ucat[k][j+1][i].
x+ucat[k][j][i+1].
x);
2482 ucat[k][j][i].
y = 0.5*(ucat[k][j+1][i].
y+ucat[k][j][i+1].
y);
2483 ucat[k][j][i].
z = 0.5*(ucat[k][j+1][i].
z+ucat[k][j][i+1].
z);
2484 p[k][j][i]= 0.5*(p[k][j+1][i]+p[k][j][i+1]);
2490 for (k=zs; k<ze; k++) {
2491 ucat[k][j][i].
x = 0.5*(ucat[k][j+1][i].
x+ucat[k][j][i-1].
x);
2492 ucat[k][j][i].
y = 0.5*(ucat[k][j+1][i].
y+ucat[k][j][i-1].
y);
2493 ucat[k][j][i].
z = 0.5*(ucat[k][j+1][i].
z+ucat[k][j][i-1].
z);
2494 p[k][j][i] = 0.5*(p[k][j+1][i]+p[k][j][i-1]);
2503 for (k=zs; k<ze; k++) {
2504 ucat[k][j][i].
x = 0.5*(ucat[k][j-1][i].
x+ucat[k][j][i+1].
x);
2505 ucat[k][j][i].
y = 0.5*(ucat[k][j-1][i].
y+ucat[k][j][i+1].
y);
2506 ucat[k][j][i].
z = 0.5*(ucat[k][j-1][i].
z+ucat[k][j][i+1].
z);
2507 p[k][j][i] = 0.5*(p[k][j-1][i]+p[k][j][i+1]);
2513 for (k=zs; k<ze; k++) {
2514 ucat[k][j][i].
x = 0.5*(ucat[k][j-1][i].
x+ucat[k][j][i-1].
x);
2515 ucat[k][j][i].
y = 0.5*(ucat[k][j-1][i].
y+ucat[k][j][i-1].
y);
2516 ucat[k][j][i].
z = 0.5*(ucat[k][j-1][i].
z+ucat[k][j][i-1].
z);
2517 p[k][j][i] = 0.5*(p[k][j-1][i]+p[k][j][i-1]);
2522 DMDAVecRestoreArray(fda, user->
Ucat, &ucat);
2523 DMDAVecRestoreArray(da, user->
P, &p);
2525 DMGlobalToLocalBegin(fda, user->
Ucat, INSERT_VALUES, user->
lUcat);
2526 DMGlobalToLocalEnd(fda, user->
Ucat, INSERT_VALUES, user->
lUcat);
2528 DMGlobalToLocalBegin(da, user->
P, INSERT_VALUES, user->
lP);
2529 DMGlobalToLocalEnd(da, user->
P, INSERT_VALUES, user->
lP);
2537 DMDAVecGetArray(fda, user->
lUcat, &lucat);
2538 DMDAVecGetArray(da, user->
lP, &lp);
2539 DMDAVecGetArray(da, user->
lNvert, &lnvert);
2540 DMDAVecGetArray(fda, user->
Ucat, &ucat);
2541 DMDAVecGetArray(da, user->
P, &p);
2542 DMDAVecGetArray(da, user->
Nvert, &nvert);
2547 for (k=zs; k<ze; k++) {
2548 for (j=ys; j<ye; j++) {
2549 ucat[k][j][i]=lucat[k][j][i-2];
2550 p[k][j][i]=lp[k][j][i-2];
2551 nvert[k][j][i]=lnvert[k][j][i-2];
2559 for (k=zs; k<ze; k++) {
2560 for (j=ys; j<ye; j++) {
2561 ucat[k][j][i].
x=lucat[k][j][i+2].
x;
2562 p[k][j][i]=lp[k][j][i+2];
2563 nvert[k][j][i]=lnvert[k][j][i+2];
2568 DMDAVecRestoreArray(fda, user->
lUcat, &lucat);
2569 DMDAVecRestoreArray(da, user->
lP, &lp);
2570 DMDAVecRestoreArray(da, user->
lNvert, &lnvert);
2571 DMDAVecRestoreArray(fda, user->
Ucat, &ucat);
2572 DMDAVecRestoreArray(da, user->
P, &p);
2573 DMDAVecRestoreArray(da, user->
Nvert, &nvert);
2584 DMGlobalToLocalBegin(fda, user->
Ucat, INSERT_VALUES, user->
lUcat);
2585 DMGlobalToLocalEnd(fda, user->
Ucat, INSERT_VALUES, user->
lUcat);
2587 DMGlobalToLocalBegin(da, user->
P, INSERT_VALUES, user->
lP);
2588 DMGlobalToLocalEnd(da, user->
P, INSERT_VALUES, user->
lP);
2590 DMGlobalToLocalBegin(da, user->
Nvert, INSERT_VALUES, user->
lNvert);
2591 DMGlobalToLocalEnd(da, user->
Nvert, INSERT_VALUES, user->
lNvert);
2594 DMDAVecGetArray(fda, user->
lUcat, &lucat);
2595 DMDAVecGetArray(da, user->
lP, &lp);
2596 DMDAVecGetArray(da, user->
lNvert, &lnvert);
2597 DMDAVecGetArray(fda, user->
Ucat, &ucat);
2598 DMDAVecGetArray(da, user->
P, &p);
2599 DMDAVecGetArray(da, user->
Nvert, &nvert);
2604 for (k=zs; k<ze; k++) {
2605 for (i=xs; i<xe; i++) {
2606 ucat[k][j][i]=lucat[k][j-2][i];
2607 p[k][j][i]=lp[k][j-2][i];
2608 nvert[k][j][i]=lnvert[k][j-2][i];
2617 for (k=zs; k<ze; k++) {
2618 for (i=xs; i<xe; i++) {
2619 ucat[k][j][i]=lucat[k][j+2][i];
2620 p[k][j][i]=lp[k][j+2][i];
2621 nvert[k][j][i]=lnvert[k][j+2][i];
2627 DMDAVecRestoreArray(fda, user->
lUcat, &lucat);
2628 DMDAVecRestoreArray(da, user->
lP, &lp);
2629 DMDAVecRestoreArray(da, user->
lNvert, &lnvert);
2630 DMDAVecRestoreArray(fda, user->
Ucat, &ucat);
2631 DMDAVecRestoreArray(da, user->
P, &p);
2632 DMDAVecRestoreArray(da, user->
Nvert, &nvert);
2643 DMGlobalToLocalBegin(fda, user->
Ucat, INSERT_VALUES, user->
lUcat);
2644 DMGlobalToLocalEnd(fda, user->
Ucat, INSERT_VALUES, user->
lUcat);
2646 DMGlobalToLocalBegin(da, user->
P, INSERT_VALUES, user->
lP);
2647 DMGlobalToLocalEnd(da, user->
P, INSERT_VALUES, user->
lP);
2649 DMGlobalToLocalBegin(da, user->
Nvert, INSERT_VALUES, user->
lNvert);
2650 DMGlobalToLocalEnd(da, user->
Nvert, INSERT_VALUES, user->
lNvert);
2653 DMDAVecGetArray(fda, user->
lUcat, &lucat);
2654 DMDAVecGetArray(da, user->
lP, &lp);
2655 DMDAVecGetArray(da, user->
lNvert, &lnvert);
2656 DMDAVecGetArray(fda, user->
Ucat, &ucat);
2657 DMDAVecGetArray(da, user->
P, &p);
2658 DMDAVecGetArray(da, user->
Nvert, &nvert);
2663 for (j=ys; j<ye; j++) {
2664 for (i=xs; i<xe; i++) {
2665 ucat[k][j][i]=lucat[k-2][j][i];
2666 nvert[k][j][i]=lnvert[k-2][j][i];
2668 p[k][j][i]=lp[k-2][j][i];
2676 for (j=ys; j<ye; j++) {
2677 for (i=xs; i<xe; i++) {
2678 ucat[k][j][i]=lucat[k+2][j][i];
2679 nvert[k][j][i]=lnvert[k+2][j][i];
2680 p[k][j][i]=lp[k+2][j][i];
2686 DMDAVecRestoreArray(fda, user->
lUcat, &lucat);
2687 DMDAVecRestoreArray(da, user->
lP, &lp);
2688 DMDAVecRestoreArray(da, user->
lNvert, &lnvert);
2689 DMDAVecRestoreArray(fda, user->
Ucat, &ucat);
2690 DMDAVecRestoreArray(da, user->
P, &p);
2691 DMDAVecRestoreArray(da, user->
Nvert, &nvert);
2702 DMGlobalToLocalBegin(fda, user->
Ucat, INSERT_VALUES, user->
lUcat);
2703 DMGlobalToLocalEnd(fda, user->
Ucat, INSERT_VALUES, user->
lUcat);
2705 DMGlobalToLocalBegin(da, user->
P, INSERT_VALUES, user->
lP);
2706 DMGlobalToLocalEnd(da, user->
P, INSERT_VALUES, user->
lP);
2708 DMGlobalToLocalBegin(da, user->
Nvert, INSERT_VALUES, user->
lNvert);
2709 DMGlobalToLocalEnd(da, user->
Nvert, INSERT_VALUES, user->
lNvert);
2715 DMDAVecGetArray(fda, user->
Ucat, &ucat);
2716 DMDAVecGetArray(fda, user->
Ucont, &ucont);
2717 DMDAVecGetArray(fda, user->
Cent, ¢);
2718 DMDAVecGetArray(fda, user->
Centx, ¢x);
2719 DMDAVecGetArray(fda, user->
Centy, ¢y);
2720 DMDAVecGetArray(fda, user->
Centz, ¢z);
2722 if (user->
bctype[0]==9) {
2725 for (k=lzs; k<lze; k++) {
2726 for (j=lys; j<lye; j++) {
2727 ucat[k][j][i].
x=-cos(cent[k][j][i+1].x)*sin(cent[k][j][i+1].y)*exp(-2.0*simCtx->
dt*(simCtx->
step+1)/simCtx->
ren);
2728 ucat[k][j][i].
y=-sin(cent[k][j][i+1].x)*cos(cent[k][j][i+1].y)*exp(-2.0*simCtx->
dt*(simCtx->
step+1)/simCtx->
ren);
2729 ucat[k][j][i].
z =0.0;
2731 ucont[k][j][i].
x =-(cos(centx[k][j][i].x)*sin(centx[k][j][i].y)*csi[k][j][i].
x)*exp(-2.0*simCtx->
dt*(simCtx->
step+1)/simCtx->
ren);
2736 for (k=lzs; k<lze; k++) {
2737 ucat[k][j][i].
x=cos(cent[k][j+1][i+1].x)*sin(cent[k][j+1][i+1].y)*exp(-2.0*simCtx->
dt*(simCtx->
step+1)/simCtx->
ren);
2738 ucat[k][j][i].
y=-sin(cent[k][j+1][i+1].x)*cos(cent[k][j+1][i+1].y)*exp(-2.0*simCtx->
dt*(simCtx->
step+1)/simCtx->
ren);
2739 ucat[k][j][i].
z =0.0;
2744 for (k=lzs; k<lze; k++) {
2745 ucat[k][j][i].
x=cos(cent[k][j-1][i+1].x)*sin(cent[k][j-1][i+1].y)*exp(-2.0*simCtx->
dt*(simCtx->
step+1)/simCtx->
ren);
2746 ucat[k][j][i].
y=-sin(cent[k][j-1][i+1].x)*cos(cent[k][j-1][i+1].y)*exp(-2.0*simCtx->
dt*(simCtx->
step+1)/simCtx->
ren);
2747 ucat[k][j][i].
z =0.0;
2752 if (user->
bctype[1]==9) {
2755 for (k=lzs; k<lze; k++) {
2756 for (j=lys; j<lye; j++) {
2757 ucat[k][j][i].
x=-cos(cent[k][j][i-1].x)*sin(cent[k][j][i-1].y)*exp(-2.0*simCtx->
dt*(simCtx->
step+1)/simCtx->
ren);
2758 ucat[k][j][i].
y=-sin(cent[k][j][i-1].x)*cos(cent[k][j][i-1].y)*exp(-2.0*simCtx->
dt*(simCtx->
step+1)/simCtx->
ren);
2759 ucat[k][j][i].
z =0.0;
2761 ucont[k][j][i-1].
x =(-cos(centx[k][j][i-1].x)*sin(centx[k][j][i-1].y)*csi[k][j][i-1].
x)*exp(-2.0*simCtx->
dt*(simCtx->
step+1)/simCtx->
ren);
2766 for (k=lzs; k<lze; k++) {
2767 ucat[k][j][i].
x=cos(cent[k][j+1][i-1].x)*sin(cent[k][j+1][i-1].y)*exp(-2.0*simCtx->
dt*(simCtx->
step+1)/simCtx->
ren);
2768 ucat[k][j][i].
y=-sin(cent[k][j+1][i-1].x)*cos(cent[k][j+1][i-1].y)*exp(-2.0*simCtx->
dt*(simCtx->
step+1)/simCtx->
ren);
2769 ucat[k][j][i].
z =0.0;
2774 for (k=lzs; k<lze; k++) {
2775 ucat[k][j][i].
x=cos(cent[k][j-1][i-1].x)*sin(cent[k][j-1][i-1].y)*exp(-2.0*simCtx->
dt*(simCtx->
step+1)/simCtx->
ren);
2776 ucat[k][j][i].
y=-sin(cent[k][j-1][i-1].x)*cos(cent[k][j-1][i-1].y)*exp(-2.0*simCtx->
dt*(simCtx->
step+1)/simCtx->
ren);
2777 ucat[k][j][i].
z =0.0;
2783 if (user->
bctype[2]==9) {
2786 for (k=lzs; k<lze; k++) {
2787 for (i=lxs; i<lxe; i++) {
2788 ucat[k][j][i].
x=cos(cent[k][j+1][i].x)*sin(cent[k][j+1][i].y)*exp(-2.0*simCtx->
dt*(simCtx->
step+1)/simCtx->
ren);
2789 ucat[k][j][i].
y=sin(cent[k][j+1][i].x)*cos(cent[k][j+1][i].y)*exp(-2.0*simCtx->
dt*(simCtx->
step+1)/simCtx->
ren);
2790 ucat[k][j][i].
z =0.0;
2792 ucont[k][j][i].
y=(sin(centy[k][j][i].x)*cos(centy[k][j][i].y)*eta[k][j][i].
y)*exp(-2.0*simCtx->
dt*(simCtx->
step+1)/simCtx->
ren);
2799 if (user->
bctype[3]==9) {
2802 for (k=lzs; k<lze; k++) {
2803 for (i=lxs; i<lxe; i++) {
2804 ucat[k][j][i].
x=cos(cent[k][j-1][i].x)*sin(cent[k][j-1][i].y)*exp(-2.0*simCtx->
dt*(simCtx->
step+1)/simCtx->
ren);
2805 ucat[k][j][i].
y=sin(cent[k][j-1][i].x)*cos(cent[k][j-1][i].y)*exp(-2.0*simCtx->
dt*(simCtx->
step+1)/simCtx->
ren);
2806 ucat[k][j][i].
z =0.0;
2808 ucont[k][j-1][i].
y=(sin(centy[k][j-1][i].x)*cos(centy[k][j-1][i].y)*eta[k][j-1][i].
y)*exp(-2.0*simCtx->
dt*(simCtx->
step+1)/simCtx->
ren);
2813 if (user->
bctype[4]==9) {
2816 for (j=ys; j<ye; j++) {
2817 for (i=xs; i<xe; i++) {
2818 ucat[k][j][i].
x=ucat[k+1][j][i].
x;
2819 ucat[k][j][i].
y=ucat[k+1][j][i].
y;
2820 ucat[k][j][i].
z=ucat[k+1][j][i].
z;
2822 ucont[k][j][i].
z=0.0;
2827 if (user->
bctype[5]==9) {
2830 for (j=ys; j<ye; j++) {
2831 for (i=xs; i<xe; i++) {
2832 ucat[k][j][i].
x=ucat[k-1][j][i].
x;
2833 ucat[k][j][i].
y=ucat[k-1][j][i].
y;
2834 ucat[k][j][i].
z=ucat[k-1][j][i].
z;
2836 ucont[k-1][j][i].
z=0.0;
2842 DMDAVecRestoreArray(fda, user->
Cent, ¢);
2843 DMDAVecRestoreArray(fda, user->
Centx, ¢x);
2844 DMDAVecRestoreArray(fda, user->
Centy, ¢y);
2845 DMDAVecRestoreArray(fda, user->
Centz, ¢z);
2847 DMDAVecRestoreArray(fda, user->
Ucat, &ucat);
2848 DMDAVecRestoreArray(fda, user->
Ucont, &ucont);
2853 DMDAVecRestoreArray(fda, user->
Bcs.
Ubcs, &ubcs);
2854 DMDAVecRestoreArray(fda, user->
lCsi, &csi);
2855 DMDAVecRestoreArray(fda, user->
lEta, &eta);
2856 DMDAVecRestoreArray(fda, user->
lZet, &zet);
2858 DMGlobalToLocalBegin(da, user->
P, INSERT_VALUES, user->
lP);
2859 DMGlobalToLocalEnd(da, user->
P, INSERT_VALUES, user->
lP);
2860 DMGlobalToLocalBegin(fda, user->
Ucat, INSERT_VALUES, user->
lUcat);
2861 DMGlobalToLocalEnd(fda, user->
Ucat, INSERT_VALUES, user->
lUcat);
2862 DMGlobalToLocalBegin(fda, user->
Ucont, INSERT_VALUES, user->
lUcont);
2863 DMGlobalToLocalEnd(fda, user->
Ucont, INSERT_VALUES, user->
lUcont);
2867 PetscFunctionReturn(0);