22PetscErrorCode
CanRankServiceFace(
const DMDALocalInfo *info, PetscInt IM_nodes_global, PetscInt JM_nodes_global, PetscInt KM_nodes_global,
23 BCFace face_id, PetscBool *can_service_out)
26 PetscMPIInt rank_for_logging;
27 PetscFunctionBeginUser;
31 rank_for_logging = PetscGlobalRank;
33 *can_service_out = PETSC_FALSE;
36 PetscInt owned_start_cell_i, num_owned_cells_on_rank_i;
37 PetscInt owned_start_cell_j, num_owned_cells_on_rank_j;
38 PetscInt owned_start_cell_k, num_owned_cells_on_rank_k;
39 ierr =
GetOwnedCellRange(info, 0, &owned_start_cell_i, &num_owned_cells_on_rank_i); CHKERRQ(ierr);
40 ierr =
GetOwnedCellRange(info, 1, &owned_start_cell_j, &num_owned_cells_on_rank_j); CHKERRQ(ierr);
41 ierr =
GetOwnedCellRange(info, 2, &owned_start_cell_k, &num_owned_cells_on_rank_k); CHKERRQ(ierr);
44 PetscInt last_global_cell_idx_i = (IM_nodes_global > 1) ? (IM_nodes_global - 2) : -1;
45 PetscInt last_global_cell_idx_j = (JM_nodes_global > 1) ? (JM_nodes_global - 2) : -1;
46 PetscInt last_global_cell_idx_k = (KM_nodes_global > 1) ? (KM_nodes_global - 2) : -1;
50 if (info->xs == 0 && num_owned_cells_on_rank_i > 0 &&
51 num_owned_cells_on_rank_j > 0 && num_owned_cells_on_rank_k > 0) {
52 *can_service_out = PETSC_TRUE;
56 if (last_global_cell_idx_i >= 0 &&
57 (owned_start_cell_i + num_owned_cells_on_rank_i - 1) == last_global_cell_idx_i &&
58 num_owned_cells_on_rank_j > 0 && num_owned_cells_on_rank_k > 0) {
59 *can_service_out = PETSC_TRUE;
63 if (info->ys == 0 && num_owned_cells_on_rank_j > 0 &&
64 num_owned_cells_on_rank_i > 0 && num_owned_cells_on_rank_k > 0) {
65 *can_service_out = PETSC_TRUE;
69 if (last_global_cell_idx_j >= 0 &&
70 (owned_start_cell_j + num_owned_cells_on_rank_j - 1) == last_global_cell_idx_j &&
71 num_owned_cells_on_rank_i > 0 && num_owned_cells_on_rank_k > 0) {
72 *can_service_out = PETSC_TRUE;
76 if (info->zs == 0 && num_owned_cells_on_rank_k > 0 &&
77 num_owned_cells_on_rank_i > 0 && num_owned_cells_on_rank_j > 0) {
78 *can_service_out = PETSC_TRUE;
82 if (last_global_cell_idx_k >= 0 &&
83 (owned_start_cell_k + num_owned_cells_on_rank_k - 1) == last_global_cell_idx_k &&
84 num_owned_cells_on_rank_i > 0 && num_owned_cells_on_rank_j > 0) {
85 *can_service_out = PETSC_TRUE;
98 PetscFunctionReturn(0);
107 const DMDALocalInfo *info = &user->
info;
108 const PetscInt nodes[3] = {info->mx, info->my, info->mz};
109 const PetscBool negative = (PetscBool)((PetscInt)face_id % 2 == 0);
110 PetscBool can_service = PETSC_FALSE;
111 PetscInt lo[3], hi[3];
113 PetscFunctionBeginUser;
115 elements->
normal = (PetscInt)face_id / 2;
116 elements->
a = (elements->
normal == 0) ? 1 : 0;
117 elements->
b = (elements->
normal == 2) ? 1 : 2;
118 elements->
layer = negative ? 0 : nodes[elements->
normal] - 2;
121 elements->
lo[0] = lo[elements->
a];
122 elements->
lo[1] = lo[elements->
b];
123 elements->
n[0] = can_service ? hi[elements->
a] - lo[elements->
a] : 0;
124 elements->
n[1] = can_service ? hi[elements->
b] - lo[elements->
b] : 0;
126 PetscFunctionReturn(PETSC_SUCCESS);
140 PetscInt component, PetscInt *ri, PetscInt *rj, PetscInt *rk)
142 const PetscInt mx = user->
info.mx, my = user->
info.my, mz = user->
info.mz;
143 const PetscInt coord[3] = {i, j, k};
144 const PetscInt size[3] = {mx, my, mz};
145 PetscBool periodic[3], periodic_duplicate = PETSC_FALSE;
146 PetscBool residual_zeroed = PETSC_FALSE, conditioned = PETSC_FALSE;
148 *ri = i; *rj = j; *rk = k;
150 for (PetscInt axis = 0; axis < 3; ++axis) {
151 if (periodic[axis] && coord[axis] == 0) {
152 periodic_duplicate = PETSC_TRUE;
153 if (axis == 0) *ri = -2;
154 else if (axis == 1) *rj = -2;
157 if (periodic[axis] && coord[axis] == size[axis] - 1) {
158 periodic_duplicate = PETSC_TRUE;
159 if (axis == 0) *ri = mx + 1;
160 else if (axis == 1) *rj = my + 1;
164 if (!periodic[axis] && coord[axis] == 0) residual_zeroed = PETSC_TRUE;
165 if (coord[axis] == size[axis] - 1) residual_zeroed = PETSC_TRUE;
166 if (!periodic[axis] && coord[axis] == size[axis] - 2 && component == axis)
167 residual_zeroed = PETSC_TRUE;
170 if (!periodic[component] &&
171 (coord[component] == 0 || coord[component] == size[component] - 2)) {
172 PetscBool tangential_interior = PETSC_TRUE;
173 for (PetscInt axis = 0; axis < 3; ++axis) {
174 if (axis == component)
continue;
175 if (coord[axis] < 1 || coord[axis] > size[axis] - 2)
176 tangential_interior = PETSC_FALSE;
178 conditioned = tangential_interior;
194 PetscInt k, PetscInt component)
198 const PetscReal threshold = 0.1;
227 DMDALocalInfo info = user->
info;
230 PetscFunctionBeginUser;
234 ierr = DMDAVecGetArray(user->
fda, user->
Rhs, &rhs); CHKERRQ(ierr);
236 for (PetscInt k = info.zs; k < info.zs + info.zm; k++) {
237 for (PetscInt j = info.ys; j < info.ys + info.ym; j++) {
238 for (PetscInt i = info.xs; i < info.xs + info.xm; i++) {
239 PetscScalar *row = &rhs[k][j][i].
x;
240 for (PetscInt component = 0; component < 3; component++) {
243 row[component] = 0.0;
250 ierr = DMDAVecRestoreArray(user->
fda, user->
Rhs, &rhs); CHKERRQ(ierr);
257 PetscFunctionReturn(0);
268 PetscFunctionBeginUser;
274 ierr = PetscMalloc1(1, new_bc_ptr); CHKERRQ(ierr);
277 bc->
type = handler_type;
290 switch (handler_type) {
335 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_UNKNOWN_TYPE,
"Boundary handler type %d (%s) not recognized in factory.\n", handler_type, handler_name);
339 LOG_ALLOW(
GLOBAL,
LOG_ERROR,
"Handler type %d (%s) did not set a valid priority during creation.\n", handler_type, handler_name);
340 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_UNKNOWN_TYPE,
"Boundary handler type %d (%s) did not set a valid priority during creation.\n", handler_type, handler_name);
345 PetscFunctionReturn(0);
357 const char axis_names[3] = {
'X',
'Y',
'Z'};
358 DMBoundaryType bx, by, bz;
359 PetscBool dm_periodic[3];
360 PetscFunctionBeginUser;
364 bx = user->
info.bx; by = user->
info.by; bz = user->
info.bz;
365 dm_periodic[0] = (PetscBool)(bx == DM_BOUNDARY_PERIODIC);
366 dm_periodic[1] = (PetscBool)(by == DM_BOUNDARY_PERIODIC);
367 dm_periodic[2] = (PetscBool)(bz == DM_BOUNDARY_PERIODIC);
370 for (PetscInt axis = 0; axis < 3; axis++) {
371 const PetscBool neg_periodic =
373 const PetscBool pos_periodic =
376 PetscCheck(neg_periodic == pos_periodic, PETSC_COMM_WORLD, PETSC_ERR_USER_INPUT,
377 "Configuration Error: Periodic boundaries in the %c direction must be paired; "
378 "%s is %s while %s is %s.",
380 BCFaceToString(neg_faces[axis]), neg_periodic ?
"PERIODIC" :
"not periodic",
381 BCFaceToString(pos_faces[axis]), pos_periodic ?
"PERIODIC" :
"not periodic");
382 PetscCheck(dm_periodic[axis] == neg_periodic, PETSC_COMM_WORLD, PETSC_ERR_USER_INPUT,
383 "Configuration Error: The %c-direction DM periodic flag (%d) does not match "
384 "the paired boundary configuration (%s).",
385 axis_names[axis], (
int)dm_periodic[axis], neg_periodic ?
"PERIODIC" :
"not periodic");
398 PetscFunctionReturn(0);
415 PetscFunctionBeginUser;
424 for (
int i = 0; i < 6; i++) {
431 ierr = PetscFree(face_cfg->
handler); CHKERRQ(ierr);
454 for (
int i = 0; i < 6; i++) {
456 const char *policy = NULL;
459 if (!found || strcasecmp(policy,
"remove") == 0) {
466 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG,
"Face %s (%s): particle_policy '%s' is not supported; use 'remove' or '%s'.",
475 for (
int i = 0; i < 6; i++) {
482 LOG_ALLOW(
LOCAL,
LOG_DEBUG,
"Creating handler for Face %s with Type %s and handler '%s'.\n", face_name, type_name,handler_name);
492 LOG_ALLOW(
LOCAL,
LOG_DEBUG,
"Calling Initialize() method for handler %s(%s) on Face %s.\n",type_name,handler_name,face_name);
506 LOG_ALLOW(
LOCAL,
LOG_DEBUG,
"Handler %s(%s) for Face %s has no Initialize() method, skipping.\n", type_name,handler_name,face_name);
522 PetscFunctionReturn(0);
535 PetscFunctionBeginUser;
541 for (PetscInt level = usermg->
mglevels - 2; level >= 0; level--) {
542 for (PetscInt bi = 0; bi < simCtx->
block_number; bi++) {
546 LOG_ALLOW_SYNC(
LOCAL,
LOG_DEBUG,
"Rank %d: Copying BC config from level %" PetscInt_FMT
" to level %" PetscInt_FMT
", block %" PetscInt_FMT
"\n",
547 simCtx->
rank, level + 1, level, bi);
550 for (
int face_i = 0; face_i < 6; face_i++) {
563 ierr = PetscMalloc1(1, &new_param); CHKERRQ(ierr);
564 ierr = PetscStrallocpy(src->key, &new_param->
key); CHKERRQ(ierr);
565 ierr = PetscStrallocpy(src->value, &new_param->
value); CHKERRQ(ierr);
566 new_param->
next = NULL;
567 *dst_next = new_param;
568 dst_next = &new_param->
next;
585 PetscFunctionReturn(0);
603 PetscFunctionBeginUser;
612 PetscReal local_inflow_pre = 0.0;
613 PetscReal local_inflow_post = 0.0;
614 PetscReal global_inflow_pre = 0.0;
615 PetscReal global_inflow_post = 0.0;
616 PetscInt num_handlers[3] = {0,0,0};
621 for (
int i = 0; i < 6; i++) {
624 if (!handler->
PreStep)
continue;
630 .global_inflow_sum = NULL,
631 .global_outflow_sum = NULL,
637 ierr = handler->
PreStep(handler, &ctx, &local_inflow_pre, NULL); CHKERRQ(ierr);
641 if (local_inflow_pre != 0.0) {
642 ierr = MPI_Allreduce(&local_inflow_pre, &global_inflow_pre, 1, MPIU_REAL,
643 MPI_SUM, PETSC_COMM_WORLD); CHKERRQ(ierr);
648 for (
int i = 0; i < 6; i++) {
651 if(!handler->
Apply)
continue;
658 .global_inflow_sum = NULL,
659 .global_outflow_sum = NULL,
665 ierr = handler->
Apply(handler, &ctx); CHKERRQ(ierr);
669 for (
int i = 0; i < 6; i++) {
679 .global_inflow_sum = NULL,
680 .global_outflow_sum = NULL,
686 ierr = handler->
PostStep(handler, &ctx, &local_inflow_post, NULL); CHKERRQ(ierr);
690 ierr = MPI_Allreduce(&local_inflow_post, &global_inflow_post, 1, MPIU_REAL,
691 MPI_SUM, PETSC_COMM_WORLD); CHKERRQ(ierr);
697 " (INLETS): %" PetscInt_FMT
" Prestep(s), %" PetscInt_FMT
" Application(s), %" PetscInt_FMT
" Poststep(s), FluxInSum = %.6e\n",
698 num_handlers[0],num_handlers[1],num_handlers[2], global_inflow_post);
704 PetscReal local_farfield_in_pre = 0.0;
705 PetscReal local_farfield_out_pre = 0.0;
706 PetscReal local_farfield_in_post = 0.0;
707 PetscReal local_farfield_out_post = 0.0;
708 PetscReal global_farfield_in_pre = 0.0;
709 PetscReal global_farfield_out_pre = 0.0;
710 PetscReal global_farfield_in_post = 0.0;
711 PetscReal global_farfield_out_post = 0.0;
712 memset(num_handlers,0,
sizeof(num_handlers));
717 for (
int i = 0; i < 6; i++) {
720 if (!handler->
PreStep)
continue;
727 .global_outflow_sum = NULL,
733 ierr = handler->
PreStep(handler, &ctx, &local_farfield_in_pre, &local_farfield_out_pre);
738 if (local_farfield_in_pre != 0.0 || local_farfield_out_pre != 0.0) {
739 ierr = MPI_Allreduce(&local_farfield_in_pre, &global_farfield_in_pre, 1, MPIU_REAL,
740 MPI_SUM, PETSC_COMM_WORLD); CHKERRQ(ierr);
741 ierr = MPI_Allreduce(&local_farfield_out_pre, &global_farfield_out_pre, 1, MPIU_REAL,
742 MPI_SUM, PETSC_COMM_WORLD); CHKERRQ(ierr);
745 " Farfield pre-analysis: In=%.6e, Out=%.6e\n",
746 global_farfield_in_pre, global_farfield_out_pre);
750 for (
int i = 0; i < 6; i++) {
753 if(!handler->
Apply)
continue;
761 .global_outflow_sum = NULL,
767 ierr = handler->
Apply(handler, &ctx); CHKERRQ(ierr);
771 for (
int i = 0; i < 6; i++) {
782 .global_outflow_sum = NULL,
788 ierr = handler->
PostStep(handler, &ctx, &local_farfield_in_post, &local_farfield_out_post);
793 if (num_handlers > 0) {
794 ierr = MPI_Allreduce(&local_farfield_in_post, &global_farfield_in_post, 1, MPIU_REAL,
795 MPI_SUM, PETSC_COMM_WORLD); CHKERRQ(ierr);
796 ierr = MPI_Allreduce(&local_farfield_out_post, &global_farfield_out_post, 1, MPIU_REAL,
797 MPI_SUM, PETSC_COMM_WORLD); CHKERRQ(ierr);
804 " (FARFIELD): %" PetscInt_FMT
" Prestep(s), %" PetscInt_FMT
" Application(s), %" PetscInt_FMT
" Poststep(s) , InFlux=%.6e, OutFlux=%.6e\n",
805 num_handlers[0],num_handlers[1],num_handlers[2], global_farfield_in_post, global_farfield_out_post);
817 memset(num_handlers,0,
sizeof(num_handlers));
822 for (
int i = 0; i < 6; i++) {
825 if (!handler->
PreStep)
continue;
832 .global_outflow_sum = NULL,
838 ierr = handler->
PreStep(handler, &ctx, NULL, NULL); CHKERRQ(ierr);
844 for (
int i = 0; i < 6; i++) {
847 if(!handler->
Apply)
continue;
855 .global_outflow_sum = NULL,
861 ierr = handler->
Apply(handler, &ctx); CHKERRQ(ierr);
865 for (
int i = 0; i < 6; i++) {
876 .global_outflow_sum = NULL,
882 ierr = handler->
PostStep(handler, &ctx, NULL, NULL); CHKERRQ(ierr);
887 LOG_ALLOW(
GLOBAL,
LOG_INFO,
" (WALLS): %" PetscInt_FMT
" Prestep(s), %" PetscInt_FMT
" Application(s), %" PetscInt_FMT
" Poststep(s) applied.\n",
888 num_handlers[0],num_handlers[1],num_handlers[2]);
895 PetscReal local_outflow_pre = 0.0;
896 PetscReal local_outflow_post = 0.0;
897 PetscReal global_outflow_pre = 0.0;
898 PetscReal global_outflow_post = 0.0;
899 memset(num_handlers,0,
sizeof(num_handlers));
904 for (
int i = 0; i < 6; i++) {
907 if (!handler->
PreStep)
continue;
914 .global_outflow_sum = NULL,
920 ierr = handler->
PreStep(handler, &ctx, NULL, &local_outflow_pre); CHKERRQ(ierr);
924 ierr = MPI_Allreduce(&local_outflow_pre, &global_outflow_pre, 1, MPIU_REAL,
925 MPI_SUM, PETSC_COMM_WORLD); CHKERRQ(ierr);
931 " Uncorrected outflow: %.6e, Total inflow: %.6e (Inlet: %.6e + Farfield: %.6e)\n",
936 for (
int i = 0; i < 6; i++) {
939 if(!handler->
Apply)
continue;
947 .global_outflow_sum = &global_outflow_pre,
953 ierr = handler->
Apply(handler, &ctx); CHKERRQ(ierr);
957 for (
int i = 0; i < 6; i++) {
968 .global_outflow_sum = &global_outflow_pre,
974 ierr = handler->
PostStep(handler, &ctx, NULL, &local_outflow_post); CHKERRQ(ierr);
978 ierr = MPI_Allreduce(&local_outflow_post, &global_outflow_post, 1, MPIU_REAL,
979 MPI_SUM, PETSC_COMM_WORLD); CHKERRQ(ierr);
986 PetscReal flux_error = PetscAbsReal(total_outflow - total_inflow);
987 PetscReal relative_error = (total_inflow > 1e-16) ?
988 flux_error / total_inflow : flux_error;
991 " (OUTLETS): %" PetscInt_FMT
" Prestep(s), %" PetscInt_FMT
" Application(s), %" PetscInt_FMT
" Poststep(s), FluxOutSum = %.6e\n",
992 num_handlers[0],num_handlers[1],num_handlers[2], global_outflow_post);
994 " Conservation: Total In=%.6e, Total Out=%.6e, Error=%.3e (%.2e)%%)\n",
995 total_inflow, total_outflow, flux_error, relative_error * 100.0);
997 if (relative_error > 1e-6) {
999 " WARNING: Large mass conservation error (%.2e%%)!\n",
1000 relative_error * 100.0);
1007 PetscFunctionReturn(0);
1022 PetscErrorCode ierr;
1023 PetscFunctionBeginUser;
1029 for (
int i = 0; i < 6; i++) {
1044 .global_inflow_sum = NULL,
1045 .global_outflow_sum = NULL,
1046 .global_farfield_inflow_sum = NULL,
1047 .global_farfield_outflow_sum = NULL
1051 ierr = handler->
UpdateUbcs(handler, &ctx); CHKERRQ(ierr);
1056 PetscFunctionReturn(0);
1072 PetscErrorCode ierr;
1073 PetscFunctionBeginUser;
1080 for (
int i = 0; i < 6; i++) {
1103 ierr = PetscFree(face_cfg->
handler); CHKERRQ(ierr);
1110 PetscFunctionReturn(0);
1119 PetscErrorCode ierr;
1120 DMDALocalInfo info = user->
info;
1121 PetscInt xs = info.xs, xe = info.xs + info.xm;
1122 PetscInt ys = info.ys, ye = info.ys + info.ym;
1123 PetscInt zs = info.zs, ze = info.zs + info.zm;
1124 PetscInt mx = info.mx, my = info.my, mz = info.mz;
1132 PetscFunctionBeginUser;
1136 PETSC_COMM_SELF, PETSC_ERR_SUP,
1137 "Field '%s' is not registered for periodic cell synchronization.",
1146 PetscReal ***g_array, ***l_array;
1147 ierr = DMDAVecGetArray(dm, global_vec, &g_array); CHKERRQ(ierr);
1148 ierr = DMDAVecGetArrayRead(dm, local_vec, (
void*)&l_array); CHKERRQ(ierr);
1150 switch (direction) {
1163 default: SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG,
"Invalid direction '%c'", direction);
1165 ierr = DMDAVecRestoreArray(dm, global_vec, &g_array); CHKERRQ(ierr);
1166 ierr = DMDAVecRestoreArrayRead(dm, local_vec, (
void*)&l_array); CHKERRQ(ierr);
1168 }
else if (dof == 3) {
1169 Cmpnts ***g_array, ***l_array;
1170 ierr = DMDAVecGetArray(dm, global_vec, &g_array); CHKERRQ(ierr);
1171 ierr = DMDAVecGetArrayRead(dm, local_vec, (
void*)&l_array); CHKERRQ(ierr);
1173 switch (direction) {
1186 default: SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG,
"Invalid direction '%c'", direction);
1188 ierr = DMDAVecRestoreArray(dm, global_vec, &g_array); CHKERRQ(ierr);
1189 ierr = DMDAVecRestoreArrayRead(dm, local_vec, (
void*)&l_array); CHKERRQ(ierr);
1193 PetscFunctionReturn(0);
1211 const PetscScalar *expected, *actual;
1213 PetscInt64 differing = 0, total = 0;
1215 PetscFunctionBeginUser;
1219 PetscCall(VecDuplicate(view.
local_vec, &full));
1220 PetscCall(DMGlobalToLocalBegin(view.
dm, view.
global_vec, INSERT_VALUES, full));
1221 PetscCall(DMGlobalToLocalEnd(view.
dm, view.
global_vec, INSERT_VALUES, full));
1223 PetscCall(VecGetLocalSize(full, &n));
1224 PetscCall(VecGetArrayRead(full, &expected));
1225 PetscCall(VecGetArrayRead(view.
local_vec, &actual));
1226 for (PetscInt entry = 0; entry < n; entry++) {
1227 if (memcmp(&expected[entry], &actual[entry],
sizeof(PetscScalar))) differing++;
1229 PetscCall(VecRestoreArrayRead(view.
local_vec, &actual));
1230 PetscCall(VecRestoreArrayRead(full, &expected));
1231 PetscCall(VecDestroy(&full));
1232 PetscCallMPI(MPI_Allreduce(&differing, &total, 1, MPIU_INT64, MPI_SUM, PetscObjectComm((PetscObject)view.
dm)));
1233 PetscCheck(total == 0, PetscObjectComm((PetscObject)view.
dm), PETSC_ERR_PLIB,
1234 "Ghost-update verification failed for '%s' %s: %" PetscInt64_FMT
" local entries differ from a full update.",
1237 PetscFunctionReturn(0);
1251 PetscFunctionBeginUser;
1254 for (
size_t f = 0; f <
sizeof(fields) /
sizeof(fields[0]); f++) {
1256 PetscReal global_norm, local_norm;
1258 PetscCall(VecNorm(view.
global_vec, NORM_1, &global_norm));
1259 PetscCall(VecNorm(view.
local_vec, NORM_1, &local_norm));
1260 PetscCheck(PetscIsNormalReal(global_norm) || global_norm == 0.0, PetscObjectComm((PetscObject)view.
dm), PETSC_ERR_PLIB,
1261 "Ghost-update verification failed: '%s' is not finite after the boundary pass; a stale local vector was read.",
1263 PetscCheck(PetscIsNormalReal(local_norm) || local_norm == 0.0, PetscObjectComm((PetscObject)view.
dm), PETSC_ERR_PLIB,
1264 "Ghost-update verification failed: local '%s' is not finite after the boundary pass; a stale local vector was left.",
1268 PetscFunctionReturn(0);
1284 PetscFunctionBeginUser;
1288 PetscCall(VecSet(view.
local_vec, (PetscScalar)NAN));
1290 PetscFunctionReturn(0);
1307 const PetscInt axis = direction -
'i';
1308 char key[] =
"PICurvPeriodicPlaneScatter_?";
1309 PetscObject cached = NULL;
1310 DMBoundaryType boundary[3];
1311 PetscInt size[3], dof, gs[3], gm[3], nleaves, maxleaf, nselected = 0, *selected = NULL;
1312 const PetscInt *ilocal;
1313 VecScatter gtol, embedded;
1314 PetscBool per_point;
1316 PetscFunctionBeginUser;
1318 PetscCheck(axis >= 0 && axis < 3, PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG,
"Invalid direction '%c'", direction);
1320 PetscCall(DMDAGetInfo(dm, NULL, &size[0], &size[1], &size[2], NULL, NULL, NULL, &dof, NULL,
1321 &boundary[0], &boundary[1], &boundary[2], NULL));
1322 if (boundary[axis] != DM_BOUNDARY_PERIODIC) {
PROFILE_HELPER_END; PetscFunctionReturn(0); }
1323 key[
sizeof(key) - 2] = direction;
1324 PetscCall(PetscObjectQuery((PetscObject)dm, key, &cached));
1325 if (cached) { *plane = (VecScatter)cached;
PROFILE_HELPER_END; PetscFunctionReturn(0); }
1327 PetscCall(DMDAGetGhostCorners(dm, &gs[0], &gs[1], &gs[2], &gm[0], &gm[1], &gm[2]));
1328 PetscCall(DMDAGetScatter(dm, >ol, NULL));
1329 PetscCall(PetscSFGetGraph(gtol, NULL, &nleaves, &ilocal, NULL));
1330 PetscCall(PetscSFGetLeafRange(gtol, NULL, &maxleaf));
1332 per_point = (PetscBool)(dof == 1 || maxleaf < gm[0] * gm[1] * gm[2]);
1333 PetscCall(PetscMalloc1(nleaves, &selected));
1334 for (PetscInt edge = 0; edge < nleaves; edge++) {
1335 const PetscInt leaf = ilocal ? ilocal[edge] : edge;
1336 const PetscInt point = per_point ? leaf : leaf / dof;
1337 const PetscInt index[3] = {gs[0] + point % gm[0], gs[1] + (point / gm[0]) % gm[1], gs[2] + point / (gm[0] * gm[1])};
1338 const PetscInt wrapped = ((index[axis] % size[axis]) + size[axis]) % size[axis];
1339 if (wrapped == 0 || wrapped == size[axis] - 1) selected[nselected++] = edge;
1341 PetscCall(PetscSFCreateEmbeddedLeafSF(gtol, nselected, selected, &embedded));
1342 PetscCall(PetscFree(selected));
1343 PetscCall(PetscObjectCompose((PetscObject)dm, key, (PetscObject)embedded));
1344 PetscCall(PetscSFDestroy(&embedded));
1345 PetscCall(PetscObjectQuery((PetscObject)dm, key, &cached));
1346 *plane = (VecScatter)cached;
1348 PetscFunctionReturn(0);
1368 PetscFunctionBeginUser;
1375 PetscCall(VecScatterBegin(plane, view.
global_vec, view.
local_vec, INSERT_VALUES, SCATTER_FORWARD));
1376 PetscCall(VecScatterEnd(plane, view.
global_vec, view.
local_vec, INSERT_VALUES, SCATTER_FORWARD));
1381 PetscFunctionReturn(0);
1403 PetscBool locals_current,
1404 PetscBool final_update)
1406 PetscErrorCode ierr;
1407 PetscBool periodic_i;
1408 PetscBool periodic_j;
1409 PetscBool periodic_k;
1411 PetscFunctionBeginUser;
1414 PetscCheck(num_fields >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE,
1415 "Number of cell fields cannot be negative.");
1417 PetscCheck(field_ids != NULL, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
1418 "Cell field-ID array cannot be NULL.");
1421 PetscBool periodic[3];
1423 periodic_i = periodic[0]; periodic_j = periodic[1]; periodic_k = periodic[2];
1426 if (!periodic_i && !periodic_j && !periodic_k) {
PROFILE_HELPER_END; PetscFunctionReturn(0); }
1428 for (PetscInt field = 0; field < num_fields; field++) {
1429 if (locals_current) { ierr =
VerifyLocalGhostsCurrent(user, field_ids[field],
"claimed current by the caller"); CHKERRQ(ierr); }
1436 for (PetscInt field = 0; field < num_fields; field++) {
1439 for (PetscInt field = 0; (final_update || periodic_j || periodic_k) && field < num_fields; field++) {
1445 for (PetscInt field = 0; field < num_fields; field++) {
1448 for (PetscInt field = 0; (final_update || periodic_k) && field < num_fields; field++) {
1454 for (PetscInt field = 0; field < num_fields; field++) {
1457 for (PetscInt field = 0; final_update && field < num_fields; field++) {
1461 for (PetscInt field = 0; !final_update && field < num_fields; field++) {
1466 PetscFunctionReturn(0);
1476 PetscErrorCode ierr;
1478 PetscFunctionBeginUser;
1482 PetscFunctionReturn(0);
1489 char face_direction, DM *dm,
1490 Vec *global_vec, Vec *local_vec,
1496 PetscFunctionBeginUser;
1498 PetscCheck(face_direction ==
'i' || face_direction ==
'j' || face_direction ==
'k',
1499 PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG,
1500 "Invalid face direction '%c'; expected 'i', 'j', or 'k'.", face_direction);
1507 PETSC_COMM_SELF, PETSC_ERR_SUP,
1508 "Field '%s' is not registered for %c-face periodic synchronization.",
1511 *dm = field_view.
dm;
1516 PetscFunctionReturn(0);
1526 PetscFunctionBeginUser;
1528 PetscCheck(is_coordinate != NULL, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
1529 "Face-coordinate result cannot be NULL.");
1533 PetscFunctionReturn(0);
1543 PetscBool periodic[3];
1545 PetscFunctionBeginUser;
1548 PetscCall(DMDAVecGetArray(user->
fda, local_vec, &array));
1551 for (PetscInt axis = 0; axis < 3; axis++) {
1552 const PetscBool active = periodic[axis];
1555 if (!active)
continue;
1557 "Periodic face-center synchronization requires validated %c-direction geometry.",
1561 for (PetscInt k = info.gzs; k < info.gzs + info.gzm; k++) {
1562 for (PetscInt j = info.gys; j < info.gys + info.gym; j++) {
1563 for (PetscInt i = info.gxs; i < info.gxs + info.gxm; i++) {
1564 PetscReal scale = 0.0;
1565 const PetscInt index = axis == 0 ? i : (axis == 1 ? j : k);
1566 const PetscInt size = axis == 0 ? info.mx : (axis == 1 ? info.my : info.mz);
1567 if (index < 0) scale = -1.0;
1568 else if (index >= size) scale = 1.0;
1569 if (scale == 0.0)
continue;
1570 array[k][j][i].
x += scale * translation.
x;
1571 array[k][j][i].
y += scale * translation.
y;
1572 array[k][j][i].
z += scale * translation.
z;
1578 PetscCall(DMDAVecRestoreArray(user->
fda, local_vec, &array));
1580 PetscFunctionReturn(0);
1585 char face_direction,
char periodic_direction)
1587 PetscErrorCode ierr;
1588 DMDALocalInfo info = user->
info;
1589 PetscInt xs = info.xs, xe = info.xs + info.xm;
1590 PetscInt ys = info.ys, ye = info.ys + info.ym;
1591 PetscInt zs = info.zs, ze = info.zs + info.zm;
1592 PetscInt mx = info.mx, my = info.my, mz = info.mz;
1594 Vec global_vec, local_vec;
1597 PetscFunctionBeginUser;
1599 PetscCheck(periodic_direction ==
'i' || periodic_direction ==
'j' || periodic_direction ==
'k',
1600 PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG,
1601 "Invalid periodic direction '%c'; expected 'i', 'j', or 'k'.", periodic_direction);
1605 PetscReal ***global_array, ***local_array;
1606 ierr = DMDAVecGetArray(dm, global_vec, &global_array); CHKERRQ(ierr);
1607 ierr = DMDAVecGetArrayRead(dm, local_vec, &local_array); CHKERRQ(ierr);
1609 if (periodic_direction ==
'i') {
1611 for (PetscInt k=zs; k<ze; k++)
for (PetscInt j=ys; j<ye; j++) global_array[k][j][0] = local_array[k][j][-2];
1613 for (PetscInt k=zs; k<ze; k++)
for (PetscInt j=ys; j<ye; j++) global_array[k][j][mx-1] = local_array[k][j][mx+1];
1614 }
else if (periodic_direction ==
'j') {
1616 for (PetscInt k=zs; k<ze; k++)
for (PetscInt i=xs; i<xe; i++) global_array[k][0][i] = local_array[k][-2][i];
1618 for (PetscInt k=zs; k<ze; k++)
for (PetscInt i=xs; i<xe; i++) global_array[k][my-1][i] = local_array[k][my+1][i];
1621 for (PetscInt j=ys; j<ye; j++)
for (PetscInt i=xs; i<xe; i++) global_array[0][j][i] = local_array[-2][j][i];
1623 for (PetscInt j=ys; j<ye; j++)
for (PetscInt i=xs; i<xe; i++) global_array[mz-1][j][i] = local_array[mz+1][j][i];
1625 ierr = DMDAVecRestoreArrayRead(dm, local_vec, &local_array); CHKERRQ(ierr);
1626 ierr = DMDAVecRestoreArray(dm, global_vec, &global_array); CHKERRQ(ierr);
1628 Cmpnts ***global_array, ***local_array;
1629 ierr = DMDAVecGetArray(dm, global_vec, &global_array); CHKERRQ(ierr);
1630 ierr = DMDAVecGetArrayRead(dm, local_vec, &local_array); CHKERRQ(ierr);
1632 if (periodic_direction ==
'i') {
1634 for (PetscInt k=zs; k<ze; k++)
for (PetscInt j=ys; j<ye; j++) global_array[k][j][0] = local_array[k][j][-2];
1636 for (PetscInt k=zs; k<ze; k++)
for (PetscInt j=ys; j<ye; j++) global_array[k][j][mx-1] = local_array[k][j][mx+1];
1637 }
else if (periodic_direction ==
'j') {
1639 for (PetscInt k=zs; k<ze; k++)
for (PetscInt i=xs; i<xe; i++) global_array[k][0][i] = local_array[k][-2][i];
1641 for (PetscInt k=zs; k<ze; k++)
for (PetscInt i=xs; i<xe; i++) global_array[k][my-1][i] = local_array[k][my+1][i];
1644 for (PetscInt j=ys; j<ye; j++)
for (PetscInt i=xs; i<xe; i++) global_array[0][j][i] = local_array[-2][j][i];
1646 for (PetscInt j=ys; j<ye; j++)
for (PetscInt i=xs; i<xe; i++) global_array[mz-1][j][i] = local_array[mz+1][j][i];
1648 ierr = DMDAVecRestoreArrayRead(dm, local_vec, &local_array); CHKERRQ(ierr);
1649 ierr = DMDAVecRestoreArray(dm, global_vec, &global_array); CHKERRQ(ierr);
1653 PetscFunctionReturn(0);
1659 PetscInt num_fields,
const FieldId field_ids[])
1661 PetscErrorCode ierr;
1662 const char periodic_directions[3] = {
'i',
'j',
'k'};
1666 PetscFunctionBeginUser;
1668 PetscCheck(num_fields >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE,
1669 "Number of face fields cannot be negative.");
1671 PetscCheck(field_ids != NULL, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
1672 "Face field-ID array cannot be NULL.");
1674 for (PetscInt field = 0; field < num_fields; field++) {
1676 Vec global_vec, local_vec;
1678 PetscBool is_coordinate;
1680 &dm, &global_vec, &local_vec, &dof));
1683 if (is_coordinate) {
1688 for (PetscInt direction = 0; direction < 3; direction++) {
1689 const PetscBool active =
1692 if (!active)
continue;
1694 for (PetscInt field = 0; field < num_fields; field++) {
1696 periodic_directions[direction]); CHKERRQ(ierr);
1698 for (PetscInt field = 0; field < num_fields; field++) {
1700 Vec global_vec, local_vec;
1702 PetscBool is_coordinate;
1705 if (is_coordinate) {
1707 &dm, &global_vec, &local_vec, &dof));
1714 PetscFunctionReturn(0);
1721 DM *dm, Vec *global_vec, Vec *local_vec)
1725 PetscFunctionBeginUser;
1730 PETSC_COMM_SELF, PETSC_ERR_SUP,
1731 "Field '%s' is not registered for component-staggered periodic synchronization.",
1733 *dm = field_view.
dm;
1737 PetscFunctionReturn(0);
1744 char periodic_direction)
1746 PetscErrorCode ierr;
1747 DMDALocalInfo info = user->
info;
1748 PetscInt xs = info.xs, xe = info.xs + info.xm;
1749 PetscInt ys = info.ys, ye = info.ys + info.ym;
1750 PetscInt zs = info.zs, ze = info.zs + info.zm;
1751 PetscInt mx = info.mx, my = info.my, mz = info.mz;
1753 Vec global_vec, local_vec;
1754 Cmpnts ***global_array, ***local_array;
1756 PetscFunctionBeginUser;
1758 PetscCheck(periodic_direction ==
'i' || periodic_direction ==
'j' || periodic_direction ==
'k',
1759 PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG,
1760 "Invalid periodic direction '%c'; expected 'i', 'j', or 'k'.", periodic_direction);
1763 ierr = DMDAVecGetArray(dm, global_vec, &global_array); CHKERRQ(ierr);
1764 ierr = DMDAVecGetArrayRead(dm, local_vec, &local_array); CHKERRQ(ierr);
1766 if (periodic_direction ==
'i') {
1768 for (PetscInt k=zs; k<ze; k++)
for (PetscInt j=ys; j<ye; j++) global_array[k][j][0] = local_array[k][j][-2];
1770 for (PetscInt k=zs; k<ze; k++)
for (PetscInt j=ys; j<ye; j++) global_array[k][j][mx-1] = local_array[k][j][mx+1];
1771 }
else if (periodic_direction ==
'j') {
1773 for (PetscInt k=zs; k<ze; k++)
for (PetscInt i=xs; i<xe; i++) global_array[k][0][i] = local_array[k][-2][i];
1775 for (PetscInt k=zs; k<ze; k++)
for (PetscInt i=xs; i<xe; i++) global_array[k][my-1][i] = local_array[k][my+1][i];
1778 for (PetscInt j=ys; j<ye; j++)
for (PetscInt i=xs; i<xe; i++) global_array[0][j][i] = local_array[-2][j][i];
1780 for (PetscInt j=ys; j<ye; j++)
for (PetscInt i=xs; i<xe; i++) global_array[mz-1][j][i] = local_array[mz+1][j][i];
1783 ierr = DMDAVecRestoreArrayRead(dm, local_vec, &local_array); CHKERRQ(ierr);
1784 ierr = DMDAVecRestoreArray(dm, global_vec, &global_array); CHKERRQ(ierr);
1786 PetscFunctionReturn(0);
1803 PetscBool locals_current)
1805 PetscErrorCode ierr;
1806 const char periodic_directions[3] = {
'i',
'j',
'k'};
1810 PetscFunctionBeginUser;
1812 PetscCheck(num_fields >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE,
1813 "Number of staggered fields cannot be negative.");
1815 PetscCheck(field_ids != NULL, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
1816 "Staggered field-ID array cannot be NULL.");
1818 for (PetscInt field = 0; field < num_fields; field++) {
1820 Vec global_vec, local_vec;
1822 if (locals_current) { ierr =
VerifyLocalGhostsCurrent(user, field_ids[field],
"claimed current by the caller"); CHKERRQ(ierr); }
1826 for (PetscInt direction = 0; direction < 3; direction++) {
1827 const PetscBool active =
1830 if (!active)
continue;
1832 for (PetscInt field = 0; field < num_fields; field++) {
1834 periodic_directions[direction]); CHKERRQ(ierr);
1838 for (PetscInt field = 0; field < num_fields; field++) {
1844 PetscFunctionReturn(0);
1853 PetscErrorCode ierr;
1855 PetscFunctionBeginUser;
1859 PetscFunctionReturn(0);
1866 Vec local_scalar_field)
1868 DMDALocalInfo info = user->
info;
1870 PetscReal ***scalar_array;
1871 const PetscInt xs = info.xs, xe = info.xs + info.xm;
1872 const PetscInt ys = info.ys, ye = info.ys + info.ym;
1873 const PetscInt zs = info.zs, ze = info.zs + info.zm;
1874 const PetscInt gxs = info.gxs, gxe = info.gxs + info.gxm;
1875 const PetscInt gys = info.gys, gye = info.gys + info.gym;
1876 const PetscInt gzs = info.gzs, gze = info.gzs + info.gzm;
1878 PetscFunctionBeginUser;
1880 PetscCheck(local_vector_field && local_scalar_field, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
1881 "QUICK stencil repair requires both local vector and scalar fields.");
1882 PetscCall(DMDAVecGetArray(user->
fda, local_vector_field, &vector_array));
1883 PetscCall(DMDAVecGetArray(user->
da, local_scalar_field, &scalar_array));
1886 for (PetscInt k = gzs; k < gze; k++)
for (PetscInt j = gys; j < gye; j++) {
1887 vector_array[k][j][-1] = vector_array[k][j][-3];
1888 scalar_array[k][j][-1] = scalar_array[k][j][-3];
1892 for (PetscInt k = gzs; k < gze; k++)
for (PetscInt j = gys; j < gye; j++) {
1893 vector_array[k][j][info.mx] = vector_array[k][j][info.mx + 2];
1894 scalar_array[k][j][info.mx] = scalar_array[k][j][info.mx + 2];
1898 for (PetscInt k = gzs; k < gze; k++)
for (PetscInt i = gxs; i < gxe; i++) {
1899 vector_array[k][-1][i] = vector_array[k][-3][i];
1900 scalar_array[k][-1][i] = scalar_array[k][-3][i];
1904 for (PetscInt k = gzs; k < gze; k++)
for (PetscInt i = gxs; i < gxe; i++) {
1905 vector_array[k][info.my][i] = vector_array[k][info.my + 2][i];
1906 scalar_array[k][info.my][i] = scalar_array[k][info.my + 2][i];
1910 for (PetscInt j = gys; j < gye; j++)
for (PetscInt i = gxs; i < gxe; i++) {
1911 vector_array[-1][j][i] = vector_array[-3][j][i];
1912 scalar_array[-1][j][i] = scalar_array[-3][j][i];
1916 for (PetscInt j = gys; j < gye; j++)
for (PetscInt i = gxs; i < gxe; i++) {
1917 vector_array[info.mz][j][i] = vector_array[info.mz + 2][j][i];
1918 scalar_array[info.mz][j][i] = scalar_array[info.mz + 2][j][i];
1922 PetscCall(DMDAVecRestoreArray(user->
da, local_scalar_field, &scalar_array));
1923 PetscCall(DMDAVecRestoreArray(user->
fda, local_vector_field, &vector_array));
1925 PetscFunctionReturn(0);
1933 DMDALocalInfo info = user->
info;
1935 const PetscInt xs = info.xs, xe = info.xs + info.xm;
1936 const PetscInt ys = info.ys, ye = info.ys + info.ym;
1937 const PetscInt zs = info.zs, ze = info.zs + info.zm;
1939 PetscFunctionBeginUser;
1941 PetscCheck(local_field, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
1942 "Local staggered field cannot be NULL.");
1943 PetscCall(DMLocalToLocalBegin(user->
fda, local_field, INSERT_VALUES, local_field));
1944 PetscCall(DMLocalToLocalEnd(user->
fda, local_field, INSERT_VALUES, local_field));
1945 PetscCall(DMDAVecGetArray(user->
fda, local_field, &array));
1948 for (PetscInt k = zs; k < ze; k++)
for (PetscInt j = ys; j < ye; j++) array[k][j][0].x = array[k][j][-2].x;
1950 for (PetscInt k = zs; k < ze; k++)
for (PetscInt j = ys; j < ye; j++) array[k][j][info.mx - 1].
x = array[k][j][info.mx + 1].
x;
1952 for (PetscInt k = zs; k < ze; k++)
for (PetscInt i = xs; i < xe; i++) array[k][0][i].y = array[k][-2][i].y;
1954 for (PetscInt k = zs; k < ze; k++)
for (PetscInt i = xs; i < xe; i++) array[k][info.my - 1][i].
y = array[k][info.my + 1][i].
y;
1956 for (PetscInt j = ys; j < ye; j++)
for (PetscInt i = xs; i < xe; i++) array[0][j][i].z = array[-2][j][i].z;
1958 for (PetscInt j = ys; j < ye; j++)
for (PetscInt i = xs; i < xe; i++) array[info.mz - 1][j][i].
z = array[info.mz + 1][j][i].
z;
1960 PetscCall(DMDAVecRestoreArray(user->
fda, local_field, &array));
1961 PetscCall(DMLocalToLocalBegin(user->
fda, local_field, INSERT_VALUES, local_field));
1962 PetscCall(DMLocalToLocalEnd(user->
fda, local_field, INSERT_VALUES, local_field));
1964 PetscFunctionReturn(0);
1973 PetscErrorCode ierr;
1974 PetscFunctionBeginUser;
1991 PetscFunctionReturn(0);
2000 PetscErrorCode ierr;
2001 PetscBool periodic[3], is_any_periodic;
2003 PetscFunctionBeginUser;
2008 is_any_periodic = (PetscBool)(periodic[0] || periodic[1] || periodic[2]);
2010 if (!is_any_periodic) {
2013 PetscFunctionReturn(0);
2028 PetscFunctionReturn(0);
2039 DMDALocalInfo info = user->
info;
2040 PetscInt xs = info.xs, xe = info.xs + info.xm;
2041 PetscInt ys = info.ys, ye = info.ys + info.ym;
2042 PetscInt zs = info.zs, ze = info.zs + info.zm;
2043 PetscInt mx = info.mx, my = info.my, mz = info.mz;
2045 PetscScalar ****field = NULL, ****ubcs = NULL;
2047 PetscBool from_boundary_value, fills[6];
2050 PetscInt lxs = (xs == 0) ? xs + 1 : xs, lxe = (xe == mx) ? xe - 1 : xe;
2051 PetscInt lys = (ys == 0) ? ys + 1 : ys, lye = (ye == my) ? ye - 1 : ye;
2052 PetscInt lzs = (zs == 0) ? zs + 1 : zs, lze = (ze == mz) ? ze - 1 : ze;
2054 PetscFunctionBeginUser;
2067 PETSC_COMM_SELF, PETSC_ERR_SUP,
2068 "UpdateDummyCells has no boundary rule for '%s'; one must be chosen for the quantity "
2070 from_boundary_value = (PetscBool)(field_id ==
FIELD_ID_UCAT);
2071 for (PetscInt face = 0; face < 6; ++face) {
2080 PetscCall(DMDAVecGetArrayDOF(view.
dm, view.
global_vec, &field));
2081 if (from_boundary_value) PetscCall(DMDAVecGetArrayDOF(user->
fda, user->
Bcs.
Ubcs, &ubcs));
2085 for (PetscInt k = lzs; k < lze; k++)
for (PetscInt j = lys; j < lye; j++)
for (PetscInt c = 0; c < dof; c++)
2086 field[k][j][xs][c] = from_boundary_value ? 2.0 * ubcs[k][j][xs][c] - field[k][j][xs + 1][c]
2087 : field[k][j][xs + 1][c];
2091 for (PetscInt k = lzs; k < lze; k++)
for (PetscInt j = lys; j < lye; j++)
for (PetscInt c = 0; c < dof; c++)
2092 field[k][j][xe-1][c] = from_boundary_value ? 2.0 * ubcs[k][j][xe-1][c] - field[k][j][xe - 2][c]
2093 : field[k][j][xe - 2][c];
2097 for (PetscInt k = lzs; k < lze; k++)
for (PetscInt i = lxs; i < lxe; i++)
for (PetscInt c = 0; c < dof; c++)
2098 field[k][ys][i][c] = from_boundary_value ? 2.0 * ubcs[k][ys][i][c] - field[k][ys + 1][i][c]
2099 : field[k][ys + 1][i][c];
2103 for (PetscInt k = lzs; k < lze; k++)
for (PetscInt i = lxs; i < lxe; i++)
for (PetscInt c = 0; c < dof; c++)
2104 field[k][ye-1][i][c] = from_boundary_value ? 2.0 * ubcs[k][ye-1][i][c] - field[k][ye-2][i][c]
2105 : field[k][ye-2][i][c];
2109 for (PetscInt j = lys; j < lye; j++)
for (PetscInt i = lxs; i < lxe; i++)
for (PetscInt c = 0; c < dof; c++)
2110 field[zs][j][i][c] = from_boundary_value ? 2.0 * ubcs[zs][j][i][c] - field[zs + 1][j][i][c]
2111 : field[zs + 1][j][i][c];
2115 for (PetscInt j = lys; j < lye; j++)
for (PetscInt i = lxs; i < lxe; i++)
for (PetscInt c = 0; c < dof; c++)
2116 field[ze-1][j][i][c] = from_boundary_value ? 2.0 * ubcs[ze-1][j][i][c] - field[ze-2][j][i][c]
2117 : field[ze-2][j][i][c];
2120 if (from_boundary_value) PetscCall(DMDAVecRestoreArrayDOF(user->
fda, user->
Bcs.
Ubcs, &ubcs));
2121 PetscCall(DMDAVecRestoreArrayDOF(view.
dm, view.
global_vec, &field));
2123 PetscFunctionReturn(0);
2132 PetscInt nk, PetscInt nj, PetscInt ni)
2148static void FillEdgeCell(PetscScalar ****f, PetscInt dof,
const PetscBool free_slip[6],
2149 Cmpnts ***
const metric[3],
2150 PetscInt tk, PetscInt tj, PetscInt ti,
2151 PetscInt ak, PetscInt aj, PetscInt ai,
2152 PetscInt bk, PetscInt bj, PetscInt bi)
2156 PetscInt sk = ak, sj = aj, si = ai;
2159 if (!free_slip[face_a] && !free_slip[face_b]) {
2160 for (PetscInt c = 0; c < dof; c++) f[tk][tj][ti][c] = 0.5 * (f[ak][aj][ai][c] + f[bk][bj][bi][c]);
2163 if (!free_slip[face_a]) { sk = bk; sj = bj; si = bi; mirror = face_b; }
2164 for (PetscInt c = 0; c < dof; c++) f[tk][tj][ti][c] = f[sk][sj][si][c];
2166 const Cmpnts n = metric[mirror / 2][sk][sj][si];
2167 const PetscReal area_sq = n.
x * n.
x + n.
y * n.
y + n.
z * n.
z;
2168 const PetscReal normal = (area_sq > 0.0)
2169 ? (f[sk][sj][si][0] * n.
x + f[sk][sj][si][1] * n.
y + f[sk][sj][si][2] * n.
z) / area_sq : 0.0;
2171 f[tk][tj][ti][0] -= 2.0 * normal * n.
x;
2172 f[tk][tj][ti][1] -= 2.0 * normal * n.
y;
2173 f[tk][tj][ti][2] -= 2.0 * normal * n.
z;
2185 DMDALocalInfo info = user->
info;
2186 PetscInt xs = info.xs, xe = info.xs + info.xm;
2187 PetscInt ys = info.ys, ye = info.ys + info.ym;
2188 PetscInt zs = info.zs, ze = info.zs + info.zm;
2189 PetscInt mx = info.mx, my = info.my, mz = info.mz;
2191 PetscScalar ****f = NULL;
2193 PetscBool free_slip[6], any_free_slip = PETSC_FALSE;
2194 Cmpnts ***metric[3] = {NULL, NULL, NULL};
2196 PetscFunctionBeginUser;
2202 for (PetscInt face = 0; face < 6; ++face) {
2206 any_free_slip = (PetscBool)(any_free_slip || free_slip[face]);
2208 PetscCall(DMDAVecGetArrayDOF(view.
dm, view.
global_vec, &f));
2210 if (any_free_slip && dof == 3) {
2211 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
lCsi, (
const Cmpnts ***)&metric[0]));
2212 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
lEta, (
const Cmpnts ***)&metric[1]));
2213 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
lZet, (
const Cmpnts ***)&metric[2]));
2216#define EDGE_FILL(tk, tj, ti, ak, aj, ai, bk, bj, bi) \
2217 FillEdgeCell(f, dof, free_slip, metric, tk, tj, ti, ak, aj, ai, bk, bj, bi)
2224 if (xs == 0)
for (PetscInt j = ys; j < ye; j++) {
EDGE_FILL(zs, j, xs, zs+1, j, xs, zs, j, xs+1); }
2225 if (xe == mx)
for (PetscInt j = ys; j < ye; j++) {
EDGE_FILL(zs, j, mx-1, zs+1, j, mx-1, zs, j, mx-2); }
2226 if (ys == 0)
for (PetscInt i = xs; i < xe; i++) {
EDGE_FILL(zs, ys, i, zs+1, ys, i, zs, ys+1, i); }
2227 if (ye == my)
for (PetscInt i = xs; i < xe; i++) {
EDGE_FILL(zs, my-1, i, zs+1, my-1, i, zs, my-2, i); }
2231 if (xs == 0)
for (PetscInt j = ys; j < ye; j++) {
EDGE_FILL(mz-1, j, xs, mz-2, j, xs, mz-1, j, xs+1); }
2232 if (xe == mx)
for (PetscInt j = ys; j < ye; j++) {
EDGE_FILL(mz-1, j, mx-1, mz-2, j, mx-1, mz-1, j, mx-2); }
2233 if (ys == 0)
for (PetscInt i = xs; i < xe; i++) {
EDGE_FILL(mz-1, ys, i, mz-2, ys, i, mz-1, ys+1, i); }
2234 if (ye == my)
for (PetscInt i = xs; i < xe; i++) {
EDGE_FILL(mz-1, my-1, i, mz-2, my-1, i, mz-1, my-2, i); }
2238 if (xs == 0)
for (PetscInt k = zs; k < ze; k++) {
EDGE_FILL(k, ys, xs, k, ys+1, xs, k, ys, xs+1); }
2239 if (xe == mx)
for (PetscInt k = zs; k < ze; k++) {
EDGE_FILL(k, ys, mx-1, k, ys+1, mx-1, k, ys, mx-2); }
2242 if (xs == 0)
for (PetscInt k = zs; k < ze; k++) {
EDGE_FILL(k, my-1, xs, k, my-2, xs, k, my-1, xs+1); }
2243 if (xe == mx)
for (PetscInt k = zs; k < ze; k++) {
EDGE_FILL(k, my-1, mx-1, k, my-2, mx-1, k, my-1, mx-2); }
2247 if (any_free_slip && dof == 3) {
2248 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
lZet, (
const Cmpnts ***)&metric[2]));
2249 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
lEta, (
const Cmpnts ***)&metric[1]));
2250 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
lCsi, (
const Cmpnts ***)&metric[0]));
2252 PetscCall(DMDAVecRestoreArrayDOF(view.
dm, view.
global_vec, &f));
2254 PetscFunctionReturn(0);
2269 PetscInt i, PetscInt j, PetscInt k,
2270 PetscReal roughness_height, PetscReal distance_reference,
2271 Cmpnts tangent, PetscReal tangent_speed,
2272 PetscReal *friction_velocity)
2274 const PetscReal kinematic_viscosity = 1.0 / user->
simCtx->
ren;
2276 PetscFunctionBeginUser;
2280 *friction_velocity =
find_utau_Werner(kinematic_viscosity, tangent_speed, distance_reference, 0.0);
2283 Cmpnts gradient = {0.0, 0.0, 0.0};
2284 PetscReal gradient_along = 0.0, u_tau = 0.0, stress = 0.0, stress_normal = 0.0;
2287 if (tangent_speed > 1.0e-10) {
2288 gradient_along = (gradient.
x * tangent.
x + gradient.
y * tangent.
y + gradient.
z * tangent.
z) / tangent_speed;
2290 find_utau_Cabot(kinematic_viscosity, tangent_speed, distance_reference, 0.01, gradient_along, 0.0,
2291 &u_tau, &stress, &stress_normal);
2292 *friction_velocity = (stress < 0.0) ? -u_tau : u_tau;
2297 *friction_velocity =
find_utau_hydset(kinematic_viscosity, tangent_speed, distance_reference, 0.001,
2302 PetscCheck(PetscIsInfOrNanReal(*friction_velocity) == PETSC_FALSE, PETSC_COMM_SELF, PETSC_ERR_FP,
2303 "Wall model (%s) returned a non-finite friction velocity at cell (%" PetscInt_FMT
", %" PetscInt_FMT
2304 ", %" PetscInt_FMT
").",
2307 PetscFunctionReturn(PETSC_SUCCESS);
2317 const DMDALocalInfo *info = &user->
info;
2318 const PetscInt start[3] = {info->xs, info->ys, info->zs};
2319 const PetscInt end[3] = {info->xs + info->xm, info->ys + info->ym, info->zs + info->zm};
2320 const PetscInt size[3] = {info->mx, info->my, info->mz};
2321 const PetscReal molecular = 1.0 / simCtx->
ren;
2323 const Cmpnts ***ucat, ***ubcs, ***metric[3];
2324 const PetscReal ***nvert, ***aj, ***pressure;
2325 Cmpnts ***ucont, ***stress;
2326 PetscReal ***friction_velocity;
2327 PetscInt wall_faces_at[3][2];
2329 PetscFunctionBeginUser;
2342 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
Ucat, (
void *)&ucat));
2343 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
Bcs.
Ubcs, (
void *)&ubcs));
2344 PetscCall(DMDAVecGetArray(user->
fda, user->
Ucont, &ucont));
2345 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
lCsi, (
void *)&metric[0]));
2346 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
lEta, (
void *)&metric[1]));
2347 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
lZet, (
void *)&metric[2]));
2348 PetscCall(DMDAVecGetArrayRead(user->
da, user->
lNvert, (
void *)&nvert));
2349 PetscCall(DMDAVecGetArrayRead(user->
da, user->
lAj, (
void *)&aj));
2351 PetscCall(DMDAVecGetArrayRead(user->
da, user->
lP, (
void *)&pressure));
2352 PetscCall(DMDAVecGetArray(user->
fda, user->
Wall_Stress, &stress));
2355 for (PetscInt axis = 0; axis < 3; axis++) {
2363 for (PetscInt face = 0; face < 6; face++) {
2364 const PetscInt axis = face / 2;
2365 const PetscBool negative = (PetscBool)(face % 2 == 0);
2366 const PetscReal side = negative ? 1.0 : -1.0;
2369 if (!wall_faces_at[axis][negative ? 0 : 1])
continue;
2371 if (elements.
n[0] * elements.
n[1] == 0)
continue;
2373 const PetscInt face_at = elements.
layer;
2374 const PetscInt cell = negative ? face_at + 1 : face_at;
2375 const PetscInt reference = negative ? face_at + 2 : face_at - 1;
2376 const PetscInt dummy = negative ? face_at : face_at + 1;
2379 PetscCheck(reference >= start[axis] && reference < end[axis], PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE,
2380 "Wall model on face %s: this rank owns indices %" PetscInt_FMT
"-%" PetscInt_FMT
2381 " normal to the wall, which does not reach the reference cell %" PetscInt_FMT
2382 ". Use a layout with at least three nodes per rank normal to every wall.",
2385 for (PetscInt q = 0; q < elements.
n[1]; q++)
2386 for (PetscInt p = 0; p < elements.
n[0]; p++) {
2389 c[axis] = cell; c[elements.
a] = elements.
lo[0] + p; c[elements.
b] = elements.
lo[1] + q;
2390 const PetscInt i = c[0], j = c[1], k = c[2];
2391 PetscInt c_ref[3] = {i, j, k}, c_dummy[3] = {i, j, k}, c_face[3] = {i, j, k};
2392 PetscReal signed_u_tau = 0.0, u_tau;
2394 if (nvert[k][j][i] > 0.1)
continue;
2395 c_ref[axis] = reference;
2396 c_dummy[axis] = dummy;
2397 c_face[axis] = face_at;
2399 const Cmpnts area_vector = metric[axis][c_face[2]][c_face[1]][c_face[0]];
2400 const PetscReal area = PetscSqrtReal(area_vector.
x * area_vector.
x + area_vector.
y * area_vector.
y +
2401 area_vector.
z * area_vector.
z);
2404 const PetscReal distance_boundary = 0.5 / aj[k][j][i] / area;
2405 const PetscReal distance_reference = 2.0 * distance_boundary +
2406 0.5 / aj[c_ref[2]][c_ref[1]][c_ref[0]] / area;
2407 const Cmpnts velocity_wall = ubcs[c_dummy[2]][c_dummy[1]][c_dummy[0]];
2408 const Cmpnts velocity_reference = ucat[c_ref[2]][c_ref[1]][c_ref[0]];
2409 const Cmpnts relative_reference = {velocity_reference.
x - velocity_wall.
x,
2410 velocity_reference.
y - velocity_wall.
y,
2411 velocity_reference.
z - velocity_wall.
z};
2413 const PetscReal tangent_speed = PetscSqrtReal(tangent.
x * tangent.
x + tangent.
y * tangent.
y +
2414 tangent.
z * tangent.
z);
2417 tangent, tangent_speed, &signed_u_tau));
2418 u_tau = PetscAbsReal(signed_u_tau);
2424 if (tangent_speed > 1.0e-12) {
2425 const PetscReal scale = side * signed_u_tau * u_tau / tangent_speed;
2426 stress[c_dummy[2]][c_dummy[1]][c_dummy[0]].
x = scale * tangent.
x;
2427 stress[c_dummy[2]][c_dummy[1]][c_dummy[0]].
y = scale * tangent.
y;
2428 stress[c_dummy[2]][c_dummy[1]][c_dummy[0]].
z = scale * tangent.
z;
2431 if (axis == 0) ucont[c_face[2]][c_face[1]][c_face[0]].
x = 0.0;
2432 else if (axis == 1) ucont[c_face[2]][c_face[1]][c_face[0]].
y = 0.0;
2433 else ucont[c_face[2]][c_face[1]][c_face[0]].
z = 0.0;
2437 friction_velocity[k][j][i] += u_tau * u_tau;
2441 const PetscReal y_plus = u_tau * distance_boundary / molecular;
2442 const Cmpnts first = ucat[k][j][i];
2443 const Cmpnts relative_first = {first.
x - velocity_wall.
x, first.
y - velocity_wall.
y,
2444 first.
z - velocity_wall.
z};
2446 const PetscReal first_speed = PetscSqrtReal(first_tangent.
x * first_tangent.
x +
2447 first_tangent.
y * first_tangent.
y +
2448 first_tangent.
z * first_tangent.
z);
2452 if (first_speed > 1.0e-10) {
2453 diagnostics->
wall_viscosity_sum += PetscMax(u_tau * u_tau * distance_boundary / first_speed - molecular, 0.0);
2455 if (diagnostics->
cells == 0) {
2478 diagnostics->
cells += 1;
2486 for (PetscInt face = 0; face < 6; face++) {
2487 const PetscInt axis = face / 2;
2490 if (!wall_faces_at[axis][face % 2])
continue;
2492 for (PetscInt q = 0; q < elements.
n[1]; q++)
2493 for (PetscInt p = 0; p < elements.
n[0]; p++) {
2495 PetscInt faces = 0, first_face = -1;
2497 c[axis] = (face % 2 == 0) ? elements.
layer + 1 : elements.
layer;
2498 c[elements.
a] = elements.
lo[0] + p;
2499 c[elements.
b] = elements.
lo[1] + q;
2500 const PetscInt i = c[0], j = c[1], k = c[2];
2502 if (friction_velocity[k][j][i] <= 0.0)
continue;
2503 for (PetscInt other = 0; other < 6; other++) {
2504 const PetscInt other_axis = other / 2;
2505 const PetscInt beside = (other % 2 == 0) ? 1 : size[other_axis] - 2;
2506 if (wall_faces_at[other_axis][other % 2] && c[other_axis] == beside) {
2508 if (first_face < 0) first_face = other;
2511 if (first_face != face)
continue;
2512 friction_velocity[k][j][i] = PetscSqrtReal(friction_velocity[k][j][i] / (PetscReal)faces);
2517 PetscCall(DMDAVecRestoreArray(user->
fda, user->
Wall_Stress, &stress));
2518 PetscCall(DMDAVecRestoreArrayRead(user->
da, user->
lP, (
void *)&pressure));
2519 PetscCall(DMDAVecRestoreArrayRead(user->
da, user->
lAj, (
void *)&aj));
2520 PetscCall(DMDAVecRestoreArrayRead(user->
da, user->
lNvert, (
void *)&nvert));
2521 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
lZet, (
void *)&metric[2]));
2522 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
lEta, (
void *)&metric[1]));
2523 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
lCsi, (
void *)&metric[0]));
2524 PetscCall(DMDAVecRestoreArray(user->
fda, user->
Ucont, &ucont));
2525 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
Bcs.
Ubcs, (
void *)&ubcs));
2526 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
Ucat, (
void *)&ucat));
2533 PetscFunctionReturn(PETSC_SUCCESS);
2549 PetscReal local_sum[6], global_sum[6];
2550 PetscReal global_max[2];
2551 PetscReal local_min, global_min;
2555 struct {
double value;
int rank; } local_max[2], owner_max[2];
2556 PetscInt local_at[8], global_at[8];
2558 PetscFunctionBeginUser;
2563 PetscCall(PetscObjectGetComm((PetscObject)user->
da, &comm));
2565 local_sum[0] = (PetscReal)state->
cells;
2573 local_max[1].value = (state->
cells > 0) ? (
double)state->
y_plus_max : -1.0;
2574 local_max[0].rank = local_max[1].rank = (int)simCtx->
rank;
2579 PetscCallMPI(MPI_Allreduce(local_sum, global_sum, 6, MPIU_REAL, MPI_SUM, comm));
2580 PetscCallMPI(MPI_Allreduce(local_max, owner_max, 2, MPI_DOUBLE_INT, MPI_MAXLOC, comm));
2581 PetscCallMPI(MPI_Allreduce(&local_min, &global_min, 1, MPIU_REAL, MPI_MIN, comm));
2582 global_max[0] = (PetscReal)owner_max[0].value;
2583 global_max[1] = (PetscReal)owner_max[1].value;
2584 for (PetscInt n = 0; n < 4; n++) {
2586 local_at[4 + n] = (owner_max[1].rank == (int)simCtx->
rank) ? state->
y_plus_max_at[n] : 0;
2588 PetscCallMPI(MPI_Allreduce(local_at, global_at, 8, MPIU_INT, MPI_SUM, comm));
2590 if (simCtx->
rank == 0) {
2591 const PetscReal cells = global_sum[0];
2593 PetscReal mean, mean_square, variance;
2600 "Wall model is enabled but no WALL face was reached this step; "
2601 "no diagnostics written.\n");
2603 PetscFunctionReturn(0);
2606 mean = global_sum[1] / cells;
2607 mean_square = global_sum[2] / cells;
2608 variance = PetscMax(mean_square - mean * mean, 0.0);
2611 "step,time,wall_cells,u_tau_mean,u_tau_rms,"
2612 "u_tau_min,u_tau_max,y_plus_mean,y_plus_max,"
2613 "wall_distance_mean,nu_wall_over_nu_mean,physical_time,"
2614 "u_tau_max_face,u_tau_max_i,u_tau_max_j,u_tau_max_k,"
2615 "y_plus_max_face,y_plus_max_i,y_plus_max_j,y_plus_max_k", &file));
2616 PetscReal physical_time = 0.0;
2619 "%d,%.6e,%d,%.6e,%.6e,%.6e,%.6e,%.6e,%.6e,%.6e,%.6e,%.6e,%s,%d,%d,%d,%s,%d,%d,%d\n",
2620 (
int)simCtx->
step, (
double)simCtx->
ti, (
int)cells,
2621 (
double)mean, (
double)PetscSqrtReal(variance),
2622 (
double)global_min, (
double)global_max[0],
2623 (
double)(global_sum[3] / cells), (
double)global_max[1],
2624 (
double)(global_sum[4] / cells),
2625 (
double)(global_sum[5] / cells * simCtx->
ren), (
double)physical_time,
2627 BCFaceToString((
BCFace)global_at[4]), (
int)global_at[5], (
int)global_at[6], (
int)global_at[7]);
2628 PetscCheck(fclose(file) == 0, PETSC_COMM_SELF, PETSC_ERR_FILE_WRITE,
2629 "Unable to close the wall-model diagnostics file.");
2632 " Wall model (%s): u_tau=%.4e (max %.4e on %s at %d,%d,%d), y+ (mean)=%.2f, "
2633 "y+ (max)=%.2f over %d cell(s)\n",
2636 (
int)global_at[1], (
int)global_at[2], (
int)global_at[3],
2637 (
double)(global_sum[3] / cells), (
double)global_max[1], (
int)cells);
2649 const PetscInt PICURV_WALL_YPLUS_GRACE_SAMPLES = 10;
2650 const PetscReal y_plus_mean = (global_sum[0] > 0.0) ? global_sum[3] / global_sum[0] : 0.0;
2651 PetscReal lower = 0.0, upper = 300.0;
2652 const char *range_reason = NULL;
2661 range_reason =
"the logarithmic region the law describes";
2668 range_reason =
"the region the power law describes";
2676 range_reason =
"the wall layer the model integrates over";
2680 if (global_sum[0] > 0.0 && (y_plus_mean < lower || y_plus_mean > upper)) {
2683 "Wall model (%s): first-cell y+ is %.2f, outside %s (%.0f to %.0f). "
2684 "The stress it reports is not one the law supports here. Sample %d "
2685 "of %d before this run is stopped.\n",
2687 (
double)y_plus_mean, range_reason, (
double)lower, (
double)upper,
2689 (
int)PICURV_WALL_YPLUS_GRACE_SAMPLES);
2692 PETSC_COMM_WORLD, PETSC_ERR_ARG_OUTOFRANGE,
2693 "Wall model (%s): first-cell y+ has been outside %s (%.0f to %.0f) "
2694 "for %d consecutive samples, most recently %.2f. Refine or coarsen "
2695 "the wall-normal spacing so the first cell lands in range, or "
2696 "resolve the wall and disable the wall function. Stopping now "
2697 "rather than spending the run producing a stress the law cannot "
2700 range_reason, (
double)lower, (
double)upper,
2713 "Wall model (%s): first-cell y+ reaches %.2f on face %s at cell (%d, %d, %d), above %s "
2714 "(up to %.0f), although the wall-face mean %.2f is in range. Reported once; "
2715 "wall_model.csv tracks the maximum and its location every step.\n",
2718 (
int)global_at[6], (
int)global_at[7], range_reason, (
double)upper, (
double)y_plus_mean);
2723 PetscFunctionReturn(0);
2734 PetscReal local[12] = {0.0}, global[12];
2735 PetscBool selected[6] = {PETSC_FALSE};
2736 PetscInt n_selected = 0;
2738 PetscFunctionBeginUser;
2740 for (PetscInt face = 0; face < 6; face++) {
2742 selected[face] = (PetscBool)(type ==
INLET || type ==
OUTLET);
2743 n_selected += selected[face] ? 1 : 0;
2748 const PetscReal ***pressure, ***nvert;
2749 const Cmpnts ***metric[3];
2751 PetscCall(DMDAVecGetArrayRead(user->
da, user->
P, (
void *)&pressure));
2752 PetscCall(DMDAVecGetArrayRead(user->
da, user->
lNvert, (
void *)&nvert));
2753 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
lCsi, (
void *)&metric[0]));
2754 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
lEta, (
void *)&metric[1]));
2755 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
lZet, (
void *)&metric[2]));
2756 for (PetscInt face = 0; face < 6; face++) {
2759 if (!selected[face])
continue;
2762 const PetscInt axis = elements.
normal;
2763 const PetscInt cell = (face % 2 == 0) ? elements.
layer + 1 : elements.
layer;
2764 for (PetscInt q = 0; q < elements.
n[1]; q++)
2765 for (PetscInt p = 0; p < elements.
n[0]; p++) {
2766 PetscInt c[3], f[3];
2767 c[axis] = cell; c[elements.
a] = elements.
lo[0] + p; c[elements.
b] = elements.
lo[1] + q;
2768 const PetscInt i = c[0], j = c[1], k = c[2];
2769 if (nvert[k][j][i] > 0.1)
continue;
2770 f[0] = i; f[1] = j; f[2] = k;
2771 f[axis] = elements.
layer;
2772 const Cmpnts m = metric[axis][f[2]][f[1]][f[0]];
2773 const PetscReal area = PetscSqrtReal(m.
x * m.
x + m.
y * m.
y + m.
z * m.
z);
2774 local[2 * face] += pressure[k][j][i] * area;
2775 local[2 * face + 1] += area;
2778 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
lZet, (
void *)&metric[2]));
2779 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
lEta, (
void *)&metric[1]));
2780 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
lCsi, (
void *)&metric[0]));
2781 PetscCall(DMDAVecRestoreArrayRead(user->
da, user->
lNvert, (
void *)&nvert));
2782 PetscCall(DMDAVecRestoreArrayRead(user->
da, user->
P, (
void *)&pressure));
2784 PetscCallMPI(MPI_Allreduce(local, global, 12, MPIU_REAL, MPI_SUM, PETSC_COMM_WORLD));
2787 if (simCtx->
rank == 0 && user->
_this == 0) {
2789 PetscReal physical_time = 0.0;
2794 "step,physical_time,face,type,area,mean_pressure", &file));
2795 for (PetscInt face = 0; face < 6; face++) {
2796 if (!selected[face] || global[2 * face + 1] <= 0.0)
continue;
2797 fprintf(file,
"%d,%.10e,%s,%s,%.10e,%.10e\n", (
int)simCtx->
step, (
double)physical_time,
2799 (
double)(global[2 * face + 1] * L_ref * L_ref),
2800 (
double)(global[2 * face] / global[2 * face + 1] * P_ref));
2802 PetscCheck(fclose(file) == 0, PETSC_COMM_SELF, PETSC_ERR_FILE_WRITE,
2803 "Unable to close the boundary-pressure diagnostics file.");
2806 PetscFunctionReturn(0);
2816 PetscErrorCode ierr;
2818 PetscFunctionBeginUser;
2830 PetscFunctionReturn(0);
2839 PetscErrorCode ierr;
2842 PetscFunctionBeginUser;
2859 PetscBool periodic[3];
2861 if (!periodic[0] && !periodic[1] && !periodic[2]) {
2871 PetscFunctionReturn(0);
2881 PetscErrorCode ierr;
2884 PetscFunctionBeginUser;
2937 if (!any_periodic) {
2951 PetscFunctionReturn(0);
2964 const char *names[4] = {
"Ucont",
"Ucat",
"P",
"Ubcs"};
2966 PetscFunctionBeginUser;
2969 for (
int f = 0; f < 4; ++f) {
2970 PetscCall(VecDuplicate(fields[f], &saved[f]));
2971 PetscCall(VecCopy(fields[f], saved[f]));
2973 for (
int pass = 1; pass < 3; ++pass) PetscCall(
ApplyBoundaryPass(user, any_periodic));
2974 for (
int f = 0; f < 4; ++f) {
2976 PetscCall(VecEqual(fields[f], saved[f], &equal));
2977 PetscCheck(equal, PETSC_COMM_WORLD, PETSC_ERR_PLIB,
2978 "A further boundary pass changed %s after a single-pass call: some face's handler reads "
2979 "state the pass changes but does not set needs_repeat_pass.", names[f]);
2980 PetscCall(VecDestroy(&saved[f]));
2983 PetscFunctionReturn(0);
2994 PetscErrorCode ierr;
2996 PetscBool periodic[3], any_periodic;
2998 PetscFunctionBeginUser;
3004 any_periodic = (PetscBool)(periodic[0] || periodic[1] || periodic[2]);
3005 for (
int face = 0; face < 6; face++) {
3012 for (PetscInt iter = 0; iter < passes; iter++) {
3027 PetscFunctionReturn(0);
PetscErrorCode Create_WallFreeSlip(BoundaryCondition *bc)
Configures a BoundaryCondition object to behave as a free-slip wall.
PetscErrorCode Create_WallMoving(BoundaryCondition *bc)
Creates a wall moving along itself at a velocity source, the prescribed inlet's without its flux.
PetscErrorCode Create_PeriodicGeometric(BoundaryCondition *bc)
Configures a BoundaryCondition object for geometric periodic coupling.
PetscErrorCode Validate_DrivenFlowConfiguration(UserCtx *user)
(Private) Validates all consistency rules for a driven flow (channel/pipe) setup.
PetscErrorCode Create_PeriodicDrivenInitial(BoundaryCondition *bc)
Configures a BoundaryCondition object for initial-flux periodic driving.
PetscErrorCode Create_PeriodicDrivenConstant(BoundaryCondition *bc)
Configures a BoundaryCondition object for periodic driven-flow forcing.
PetscErrorCode Create_InletPrescribedVelocity(BoundaryCondition *bc)
Configures a BoundaryCondition object as an inlet whose velocity is a configured source: expressions ...
PetscErrorCode Create_WallNoSlip(BoundaryCondition *bc)
Configures a BoundaryCondition object to behave as a no-slip, stationary wall.
PetscErrorCode Create_OutletConservation(BoundaryCondition *bc)
Configures a BoundaryCondition object for conservative outlet treatment.
static void FillEdgeCell(PetscScalar ****f, PetscInt dof, const PetscBool free_slip[6], Cmpnts ***const metric[3], PetscInt tk, PetscInt tj, PetscInt ti, PetscInt ak, PetscInt aj, PetscInt ai, PetscInt bk, PetscInt bj, PetscInt bi)
Internal helper: fills one edge dummy cell from its two face-adjacent dummy cells.
PetscErrorCode FinalizeCellFieldsFromBoundaryValues(UserCtx *user)
Implementation of FinalizeCellFieldsFromBoundaryValues().
PetscErrorCode PreparePeriodicQuickStencilFields(UserCtx *user, Vec local_vector_field, Vec local_scalar_field)
Implementation of PreparePeriodicQuickStencilFields().
PetscErrorCode BoundarySystem_Initialize(UserCtx *user, const char *bcs_filename)
Implementation of BoundarySystem_Initialize().
static PetscErrorCode VerifySinglePassIsFinal(UserCtx *user, PetscBool any_periodic)
In verify mode, checks that the passes a single-pass call skipped would change nothing.
static PetscErrorCode TransferPeriodicFieldByDirection(UserCtx *user, FieldId field_id, char direction)
Copies one cell field's wrapped local values onto the owned periodic duplicate plane.
static BCFace EdgeSeparatingFace(PetscInt tk, PetscInt tj, PetscInt ti, PetscInt nk, PetscInt nj, PetscInt ni)
Internal helper: the face separating an edge dummy cell from one neighbour.
PetscErrorCode ApplyWallFunction(UserCtx *user)
Implementation of ApplyWallFunction().
static PetscErrorCode GetPersistentFaceField(UserCtx *user, FieldId field_id, char face_direction, DM *dm, Vec *global_vec, Vec *local_vec, PetscInt *dof)
Resolves one registered persistent single-face-family field.
static PetscErrorCode RefreshPeriodicPlaneGhosts(UserCtx *user, FieldId field_id, char direction)
Brings a field's local vector up to date after a periodic transfer along one direction.
static PetscErrorCode PoisonStaleLocalGhosts(UserCtx *user, FieldId field_id)
Fills a field's local vector with NaN, when -picurv_verify_ghost_updates is set.
MomentumRowType ClassifyMomentumRow(UserCtx *user, PetscInt i, PetscInt j, PetscInt k, PetscInt component, PetscInt *ri, PetscInt *rj, PetscInt *rk)
Implementation of ClassifyMomentumRow().
PetscErrorCode PropagateBoundaryConfigToCoarserLevels(SimCtx *simCtx)
Implementation of PropagateBoundaryConfigToCoarserLevels().
PetscBool BoundaryFaceHasWallShear(const BoundaryFaceConfig *face)
Implementation of BoundaryFaceHasWallShear().
static PetscErrorCode GetPersistentStaggeredField(UserCtx *user, FieldId field_id, DM *dm, Vec *global_vec, Vec *local_vec)
Resolves one registered persistent component-staggered field.
PetscErrorCode ApplyMetricsPeriodicBCs(UserCtx *user)
Implementation of ApplyMetricsPeriodicBCs().
PetscErrorCode EnforceRHSBoundaryConditions(UserCtx *user)
Implementation of EnforceRHSBoundaryConditions().
PetscErrorCode UpdateDummyCells(UserCtx *user, FieldId field_id)
Implementation of UpdateDummyCells().
static PetscErrorCode VerifyLocalGhostsCurrent(UserCtx *user, FieldId field_id, const char *where)
Requires a field's local vector to equal a full ghost update, when -picurv_verify_ghost_updates is se...
static PetscErrorCode VerifyBoundaryPassFinite(UserCtx *user)
Requires the boundary pass's fields to be finite, when -picurv_verify_ghost_updates is set.
PetscErrorCode LogWallModelDiagnostics(UserCtx *user)
Implementation of LogWallModelDiagnostics().
static PetscErrorCode WallModelFrictionVelocity(UserCtx *user, const PetscReal ***pressure, PetscInt i, PetscInt j, PetscInt k, PetscReal roughness_height, PetscReal distance_reference, Cmpnts tangent, PetscReal tangent_speed, PetscReal *friction_velocity)
The signed friction velocity the configured wall law gives for one wall-face element.
static PetscErrorCode TransferPeriodicStaggeredFieldByDirection(UserCtx *user, FieldId field_id, char periodic_direction)
Transfers one component-staggered field along one periodic axis.
PetscErrorCode BoundarySystem_RefreshUbcs(UserCtx *user)
Implementation of BoundarySystem_RefreshUbcs().
#define EDGE_FILL(tk, tj, ti, ak, aj, ai, bk, bj, bi)
PetscErrorCode SynchronizePeriodicLocalStaggeredField(UserCtx *user, Vec local_field)
Implementation of SynchronizePeriodicLocalStaggeredField().
PetscBool MomentumRowIsSolidMasked(const PetscReal ***nvert, PetscInt i, PetscInt j, PetscInt k, PetscInt component)
Implementation of MomentumRowIsSolidMasked().
static PetscErrorCode TranslatePeriodicFaceCenterGhosts(UserCtx *user, Vec local_vec)
Applies geometric translations to wrapped face-center ghost coordinates.
PetscErrorCode BoundarySystem_Validate(UserCtx *user)
Implementation of BoundarySystem_Validate().
PetscErrorCode LogBoundaryPressureDiagnostics(UserCtx *user)
Implementation of LogBoundaryPressureDiagnostics().
PetscErrorCode GetBoundaryFaceElements(UserCtx *user, BCFace face_id, BoundaryFaceElements *elements)
Implementation of GetBoundaryFaceElements().
PetscErrorCode BoundaryCondition_Create(BCHandlerType handler_type, BoundaryCondition **new_bc_ptr)
Implementation of BoundaryCondition_Create().
static PetscErrorCode IsFaceCenterCoordinateField(FieldId field_id, PetscBool *is_coordinate)
Returns whether a registered face field stores physical coordinates.
PetscErrorCode SynchronizePeriodicStaggeredFields(UserCtx *user, PetscInt num_fields, const FieldId field_ids[])
Implementation of SynchronizePeriodicStaggeredFields().
static PetscErrorCode SynchronizePeriodicCellFieldsFrom(UserCtx *user, PetscInt num_fields, const FieldId field_ids[], PetscBool locals_current, PetscBool final_update)
Body of SynchronizePeriodicCellFields(), optionally without its first or last ghost update.
PetscErrorCode ApplyBoundaryConditions(UserCtx *user)
Implementation of ApplyBoundaryConditions().
PetscErrorCode FinalizePostProjectionCellFields(UserCtx *user)
Implementation of FinalizePostProjectionCellFields().
PetscErrorCode UpdateCornerNodes(UserCtx *user, FieldId field_id)
Implementation of UpdateCornerNodes().
static PetscErrorCode TransferPeriodicFaceFieldByDirection(UserCtx *user, FieldId field_id, char face_direction, char periodic_direction)
Transfers one registered face-family field along one periodic axis.
PetscErrorCode CanRankServiceFace(const DMDALocalInfo *info, PetscInt IM_nodes_global, PetscInt JM_nodes_global, PetscInt KM_nodes_global, BCFace face_id, PetscBool *can_service_out)
Implementation of CanRankServiceFace().
PetscErrorCode BoundarySystem_ExecuteStep(UserCtx *user)
Implementation of BoundarySystem_ExecuteStep().
PetscErrorCode SynchronizePeriodicFaceFields(UserCtx *user, char face_direction, PetscInt num_fields, const FieldId field_ids[])
Synchronizes persistent fields belonging to one face family.
static PetscErrorCode GetPeriodicPlaneScatter(DM dm, char direction, VecScatter *plane)
The scatter that refreshes only the local entries mirroring a DM's two end planes in one direction.
static PetscErrorCode SynchronizePeriodicStaggeredFieldsFrom(UserCtx *user, PetscInt num_fields, const FieldId field_ids[], PetscBool locals_current)
Body of SynchronizePeriodicStaggeredFields(), optionally without its leading ghost update.
PetscErrorCode BoundarySystem_Destroy(UserCtx *user)
Implementation of BoundarySystem_Destroy().
PetscErrorCode SynchronizePeriodicCellFields(UserCtx *user, PetscInt num_fields, const FieldId field_ids[])
Implementation of SynchronizePeriodicCellFields().
static PetscErrorCode ApplyBoundaryPass(UserCtx *user, PetscBool any_periodic)
One boundary pass: the handlers, Contra2Cart, the wall function, the dummy, periodic and corner updat...
PetscErrorCode ApplyPeriodicBCs(UserCtx *user, PetscBool final_cell_update)
Implementation of ApplyPeriodicBCs().
MomentumRowType
Classification of one staggered momentum row (location + component).
@ MOM_ROW_FIXED_HOMOGENEOUS
Dummy/tangential row carrying no unknown at all.
@ MOM_ROW_PHYSICAL
Independent unknown governed by the momentum equation.
@ MOM_ROW_PERIODIC_DUPLICATE
Duplicate of a wrapped representative row (see ri, rj, rk).
@ MOM_ROW_FIXED_CONDITIONED
Strong Dirichlet row; the value comes from ApplyBoundaryConditions().
static PetscBool BoundaryFaceIsFreeSlipWall(const BoundaryFaceConfig *face)
Reports whether a boundary face is a free-slip wall: impenetrable, exerting no shear,...
static Cmpnts RemoveFaceNormalComponent(Cmpnts velocity, Cmpnts metric)
velocity less its component along the face metric metric, which leaves it tangent to the face.
@ FIELD_CAPABILITY_PERIODIC_GEOMETRY_SHIFT
@ FIELD_CAPABILITY_PERIODIC_CELL_SYNC
@ FIELD_CAPABILITY_PERIODIC_FACE_SYNC
@ FIELD_CAPABILITY_PERIODIC_STAGGERED_SYNC
unsigned int capabilities
const FieldDescriptor * descriptor
PetscErrorCode FieldGetView(UserCtx *user, FieldId field_id, FieldView *view)
Resolve the existing DM and global/local vectors for one field.
FieldLayout
Logical storage topology of a field.
@ FIELD_LAYOUT_CELL_CENTERED
@ FIELD_LAYOUT_COMPONENT_STAGGERED
const char * canonical_name
PetscErrorCode FieldGetDescriptor(FieldId field_id, const FieldDescriptor **descriptor)
Return immutable metadata for a valid field identifier.
FieldId
Compile-time identity for a catalogued Eulerian field.
Immutable metadata for one field identity.
Non-owning runtime objects resolved for one field and UserCtx.
PetscErrorCode ParseAllBoundaryConditions(UserCtx *user, const char *bcs_input_filename)
Parses the boundary conditions file to configure the type, handler, and any associated parameters for...
PetscErrorCode GetBCParamString(BC_Param *params, const char *key, const char **value_out, PetscBool *found)
Searches a BC_Param linked list for a key and returns its value as a string.
void FreeBC_ParamList(BC_Param *head)
Frees an entire linked list of boundary-condition parameters.
PetscErrorCode PicurvPhysicalTime(const SimCtx *simCtx, PetscReal solver_time, PetscReal *physical)
Convert a solver time to physical seconds, t * L_ref / U_ref.
const char * BCHandlerTypeToString(BCHandlerType handler_type)
Converts a BCHandlerType enum to its string representation.
#define LOG_ALLOW_SYNC(scope, level, fmt,...)
Synchronized logging macro that checks both the log level and whether the calling function is in the ...
#define LOCAL
Logging scope definitions for controlling message output.
const char * ParticleBoundaryPolicyToString(ParticleBoundaryPolicy policy)
Returns the configuration token for a particle boundary policy.
#define GLOBAL
Scope for global logging across all processes.
const char * BCFaceToString(BCFace face)
Returns the canonical log token for a boundary-face enum value.
static PetscErrorCode PicurvOpenDiagnosticsCsv(SimCtx *simCtx, const char *dir, const char *filename, const char *header, FILE **file)
Opens a per-step diagnostics CSV: PicurvOpenRunCsv() with the common settings.
#define LOG_ALLOW(scope, level, fmt,...)
Logging macro that checks both the log level and whether the calling function is in the allowed-funct...
#define PROFILE_HELPER_BEGIN
Marks the beginning of a profiled helper: timed only when enabled by name.
#define PROFILE_HELPER_END
Alias of PROFILE_FUNCTION_END for a function that began with PROFILE_HELPER_BEGIN.
#define PROFILE_FUNCTION_END
Marks the end of a profiled code block.
const char * WallFunctionModelToString(WallFunctionModel model)
Returns the user-facing name of a wall-function model.
const char * BCTypeToString(BCType type)
Returns the canonical log token for a boundary mathematical type.
@ LOG_ERROR
Critical errors that may halt the program.
@ LOG_TRACE
Very fine-grained tracing information for in-depth debugging.
@ LOG_INFO
Informational messages about program execution.
@ LOG_WARNING
Non-critical issues that warrant attention.
@ LOG_DEBUG
Detailed debugging information.
@ LOG_VERBOSE
Extremely detailed logs, typically for development use only.
#define PROFILE_FUNCTION_BEGIN
Marks the beginning of a profiled function: an always-on aggregate timer.
PetscErrorCode GetOwnedCellRange(const DMDALocalInfo *info_nodes, PetscInt dim, PetscInt *xs_cell_global_out, PetscInt *xm_cell_local_out)
Determines the global starting index and number of CELLS owned by the current processor in a specifie...
static void GetOwnedInteriorCellBounds(const DMDALocalInfo *info, PetscInt lo[3], PetscInt hi[3])
Index bounds of the interior cells this rank owns in the solver's cell-centred layout: the owned rang...
PetscErrorCode Contra2Cart(UserCtx *user)
Reconstructs Cartesian velocity (Ucat) at cell centers from contravariant velocity (Ucont) defined on...
PetscErrorCode ComputeScalarFieldDerivatives(UserCtx *user, PetscInt i, PetscInt j, PetscInt k, PetscReal ***field_data, Cmpnts *grad)
Computes the gradient of a cell-centered SCALAR field at a specific grid point.
PetscErrorCode UpdateLocalGhosts(UserCtx *user, FieldId field_id)
Updates the local vector (including ghost points) from its corresponding global vector.
static void GetPeriodicAxes(const SimCtx *simCtx, PetscBool periodic[3])
Which grid axes are periodic.
PetscErrorCode RepairPeriodicFieldGhosts(UserCtx *user, const FieldView *view, Vec local_vec)
Applies a catalogued field's periodic normal-face ghost repair to a local vector.
The "virtual table" struct for a boundary condition handler object.
PetscErrorCode(* PostStep)(BoundaryCondition *self, BCContext *ctx, PetscReal *local_inflow, PetscReal *local_outflow)
PetscErrorCode(* PreStep)(BoundaryCondition *self, BCContext *ctx, PetscReal *local_inflow, PetscReal *local_outflow)
PetscErrorCode(* Destroy)(BoundaryCondition *self)
PetscErrorCode(* Initialize)(BoundaryCondition *self, BCContext *ctx)
PetscErrorCode(* UpdateUbcs)(BoundaryCondition *self, BCContext *ctx)
PetscErrorCode(* Apply)(BoundaryCondition *self, BCContext *ctx)
PetscBool needs_repeat_pass
Apply() reads state its own boundary pass changes after it runs (the interior Ucat that Contra2Cart r...
BCType
Defines the general mathematical/physical Category of a boundary.
PetscBool inletFaceDefined
PetscReal wall_viscosity_sum
Sum of the equivalent eddy viscosity u_tau^2 y/|U_1| - nu (diagnostic only).
PetscBool verifyGhostUpdates
-picurv_verify_ghost_updates: test-only cross-checks of skipped or partial ghost updates,...
BoundaryFaceConfig boundary_faces[6]
BCFace identifiedInletBCFace
SimCtx * simCtx
Back-pointer to the master simulation context.
@ PARTICLE_BOUNDARY_REMOVE
The particle leaves the domain (EXITED) and is removed.
@ PARTICLE_BOUNDARY_REFLECT
The particle is mirrored about the face plane and stays.
@ PARTICLE_BOUNDARY_WRAP
Periodic faces: the particle re-enters through the paired face.
PetscInt wall_yplus_excursions
Consecutive diagnostic samples with the first cell outside the selected law's valid y+ range.
BCHandlerType
Defines the specific computational "strategy" for a boundary handler.
@ BC_HANDLER_PERIODIC_GEOMETRIC
@ BC_HANDLER_PERIODIC_DRIVEN_INITIAL_FLUX
@ BC_HANDLER_PERIODIC_DRIVEN_CONSTANT_FLUX
@ BC_HANDLER_INLET_PRESCRIBED_VELOCITY
@ BC_HANDLER_OUTLET_CONSERVATION
@ BC_HANDLER_WALL_FREE_SLIP
PetscReal friction_velocity_sq
Sum of u_tau^2, for the RMS.
BCHandlerType handler_type
PetscInt layer
Index along the normal of the face's metric and flux.
PetscInt normal
Logical axis of the face normal.
WallFunctionModel
Selects the wall model applied on WALL faces.
Vec Ubcs
Physical Cartesian velocity at boundary faces. Full 3D array but only boundary-face entries are meani...
PetscInt friction_velocity_max_at[4]
Wall face (BCFace) and global cell i, j, k of friction_velocity_max.
PetscReal wall_distance_sum
Sum of the first-cell wall distance.
PetscReal friction_velocity_min
Smallest u_tau this rank corrected.
char analysis_dir[PETSC_MAX_PATH_LEN]
PetscReal friction_velocity_max
Largest u_tau this rank corrected.
ParticleBoundaryPolicy particle_policy
What a particle crossing this face becomes (BC param particle_policy).
PetscReal y_plus_sum
Sum of u_tau * y / nu over corrected cells.
PetscReal wall_roughness_height
PetscReal friction_velocity_sum
Sum of u_tau over corrected cells.
PetscInt wallfunction
Enable wall functions on WALL faces.
PetscInt y_plus_max_at[4]
Wall face (BCFace) and global cell i, j, k of y_plus_max.
PetscInt cells
Number of cells this rank corrected.
PetscInt n[2]
Owned elements along a and b; 0 when this rank does not serve the face.
PetscReal y_plus_max
Largest first-cell y+ this rank corrected.
Cmpnts periodic_translation[3]
PetscBool periodic_translation_valid[3]
PetscBool wall_yplus_max_reported
The local y+ maximum has already been reported above the law's range.
PetscInt lo[2]
First owned indices along a and b.
PetscInt b
The two tangential axes, a < b.
BCFace
Identifies the six logical faces of a structured computational block.
WallModelDiagnosticsState wall_diagnostics
Near-wall statistics from the last wall-model pass.
BoundaryCondition * handler
Provides execution context for a boundary condition handler.
A node in a linked list for storing key-value parameters from the bcs.dat file.
Holds the complete configuration for one of the six boundary faces.
The elements of one boundary face that this rank owns: one per interior cell beside the face,...
A 3D point or vector with PetscScalar components.
The master context for the entire simulation.
User-defined context containing data specific to a single computational grid level.
User-level context for managing the entire multigrid hierarchy.
Near-wall statistics captured by one wall-model pass.
double find_utau_hydset(double kinematic_viscosity, double known_velocity, double wall_distance, double initial_guess, double roughness_height)
Solves for friction velocity using Newton-Raphson iteration.
void find_utau_Cabot(double kinematic_viscosity, double velocity, double wall_distance, double initial_guess, double pressure_gradient_tangent, double pressure_gradient_normal, double *friction_velocity, double *wall_shear_velocity, double *wall_shear_normal)
Solves for friction velocity using Cabot wall function.
double find_utau_Werner(double kinematic_viscosity, double velocity, double wall_distance, double initial_guess)
Friction velocity from a point velocity, inverting u_Werner() exactly.