17 PetscFunctionBeginUser;
21 PetscBool is_driven_flow_active = PETSC_FALSE;
22 char driven_direction =
' ';
23 const char* first_driven_face_name =
"";
25 for (
int i = 0; i < 6; i++) {
30 is_driven_flow_active = PETSC_TRUE;
33 if (i <= 1) driven_direction =
'X';
34 else if (i <= 3) driven_direction =
'Y';
35 else driven_direction =
'Z';
42 if (!is_driven_flow_active) {
44 PetscFunctionReturn(0);
47 LOG_ALLOW(
GLOBAL,
LOG_DEBUG,
" - Driven Flow Handler detected on face %s. Applying driven flow validation rules...\n", first_driven_face_name);
51 for (
int i = 0; i < 6; i++) {
54 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_USER_INPUT,
55 "Configuration Error: A DRIVEN flow handler is active, which is incompatible with the %s boundary condition found on face %s.",
62 LOG_ALLOW(
GLOBAL,
LOG_DEBUG,
" - Validating symmetry and mathematical types for the '%c' direction...\n", driven_direction);
64 PetscInt neg_face_idx = 0, pos_face_idx = 0;
65 if (driven_direction ==
'X') {
67 }
else if (driven_direction ==
'Y') {
78 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_USER_INPUT,
79 "Configuration Error: For a driven flow in the '%c' direction, both the %s and %s faces must be of mathematical_type PERIODIC.",
85 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_USER_INPUT,
86 "Configuration Error: The DRIVEN handlers on the %s and %s faces of the '%c' direction do not match. Both must be the same type (e.g., both CONSTANT_FLUX).",
93 PetscFunctionReturn(0);
98 PetscInt i, PetscInt j, PetscInt k,
125 PetscFunctionBeginUser;
128 PetscCheck(bc, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"BoundaryCondition is NULL");
145 PetscFunctionReturn(0);
152 PetscInt i, PetscInt j, PetscInt k,
155 const Cmpnts rest = {0.0, 0.0, 0.0};
157 (void)self; (void)face_id; (void)i; (void)j; (void)k; (void)metric; (void)sign; (void)interior;
168 PetscFunctionBeginUser;
174 PetscFunctionReturn(0);
199 PetscFunctionBeginUser;
201 PetscCheck(bc, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"BoundaryCondition is NULL");
214 PetscFunctionReturn(0);
227 PetscInt i, PetscInt j, PetscInt k,
230 (void)self; (void)face_id; (void)i; (void)j; (void)k; (void)sign;
239 PetscFunctionBeginUser;
243 PetscFunctionReturn(0);
265 PetscReal *in, PetscReal *out);
268 PetscReal *in, PetscReal *out);
291 PetscInt bracket_frame[2];
300 PetscReal fluct_length[2];
303 PetscReal *kernel[2];
304 PetscReal (*lund)[6];
312 const PetscInt idx[3] = {i, j, k};
327 PetscFunctionBeginUser;
329 PetscCheck(bc, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"BoundaryCondition is NULL");
330 PetscCall(PetscNew(&data));
331 bc->
data = (
void*)data;
340 PetscFunctionReturn(0);
349 PetscFunctionBeginUser;
356 PetscFunctionReturn(0);
363 PetscReal *local_inflow_contribution,
364 PetscReal *local_outflow_contribution)
369 PetscBool can_service;
372 (void)local_outflow_contribution;
374 PetscFunctionBeginUser;
377 DMDALocalInfo *info = &user->
info;
380 PetscInt IM_nodes_global, JM_nodes_global,KM_nodes_global;
382 IM_nodes_global = user->
IM;
383 JM_nodes_global = user->
JM;
384 KM_nodes_global = user->
KM;
386 ierr =
CanRankServiceFace(info,IM_nodes_global,JM_nodes_global,KM_nodes_global,face_id,&can_service); CHKERRQ(ierr);
391 ierr = DMDAVecGetArrayRead(user->
fda, user->
Ucont, (
const Cmpnts***)&ucont); CHKERRQ(ierr);
393 PetscReal local_flux = 0.0;
395 PetscInt xs = info->xs, xe = info->xs + info->xm;
396 PetscInt ys = info->ys, ye = info->ys + info->ym;
397 PetscInt zs = info->zs, ze = info->zs + info->zm;
398 PetscInt mx = info->mx, my = info->my, mz = info->mz;
400 PetscInt lxs = xs, lxe = xe, lys = ys, lye = ye, lzs = zs, lze = ze;
401 if (xs == 0) lxs = xs + 1;
402 if (xe == mx) lxe = xe - 1;
403 if (ys == 0) lys = ys + 1;
404 if (ye == my) lye = ye - 1;
405 if (zs == 0) lzs = zs + 1;
406 if (ze == mz) lze = ze - 1;
413 for (PetscInt k = lzs; k < lze; k++) {
414 for (PetscInt j = lys; j < lye; j++) {
415 local_flux += ucont[k][j][i].
x;
423 for (PetscInt k = lzs; k < lze; k++) {
424 for (PetscInt i = lxs; i < lxe; i++) {
425 local_flux += ucont[k][j][i].
y;
433 for (PetscInt j = lys; j < lye; j++) {
434 for (PetscInt i = lxs; i < lxe; i++) {
435 local_flux += ucont[k][j][i].
z;
441 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
Ucont, (
const Cmpnts***)&ucont); CHKERRQ(ierr);
443 *local_inflow_contribution += local_flux;
446 face_id, local_flux);
449 PetscFunctionReturn(0);
462 PetscInt *n1, PetscInt *n2)
464 PetscFunctionBeginUser;
483 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE,
484 "Unsupported face id %d for inlet profile dimensions.", face_id);
486 if (*n1 <= 0 || *n2 <= 0) {
487 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG,
488 "Invalid inlet profile dimensions (%" PetscInt_FMT
", %" PetscInt_FMT
") for grid (%" PetscInt_FMT
", %" PetscInt_FMT
", %" PetscInt_FMT
").",
489 *n1, *n2, user->
IM, user->
JM, user->
KM);
492 PetscFunctionReturn(0);
512 char magic[32] = {0}, line[256] = {0};
513 PetscInt frame_count = 0, n1 = 0, n2 = 0;
514 PetscInt components = 1;
515 double interval = 0.0;
517 PetscFunctionBeginUser;
519 fd = fopen(source_file,
"r");
520 if (!fd) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_FILE_OPEN,
521 "Cannot open PICSLICE inlet profile file: %s", source_file);
523 if (fscanf(fd,
"%31s", magic) != 1 || strcmp(magic,
"PICSLICE") != 0) {
525 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_FILE_READ,
526 "PICSLICE inlet profile file %s must begin with PICSLICE header.", source_file);
528 if (fscanf(fd,
"%" PetscInt_FMT
" ", &frame_count) != 1) {
530 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_FILE_READ,
531 "PICSLICE inlet profile file %s missing frame count.", source_file);
533 if (!fgets(line,
sizeof(line), fd) ||
534 sscanf(line,
"%" PetscInt_FMT
" %" PetscInt_FMT
" %" PetscInt_FMT
" %le", &n1, &n2, &components, &interval) < 2) {
536 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_FILE_READ,
537 "PICSLICE inlet profile file %s missing slice dimensions.", source_file);
539 if (n1 != expected_n1 || n2 != expected_n2) {
541 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_FILE_UNEXPECTED,
542 "PICSLICE inlet profile dimensions mismatch for %s: expected (%" PetscInt_FMT
", %" PetscInt_FMT
"), found (%" PetscInt_FMT
", %" PetscInt_FMT
").",
543 source_file, expected_n1, expected_n2, n1, n2);
545 if (frame_count < 1 || (components != 1 && components != 3) || (frame_count > 1 && !(interval > 0.0))) {
547 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_FILE_UNEXPECTED,
548 "PICSLICE inlet profile file %s has %" PetscInt_FMT
" frames of %" PetscInt_FMT
" components, %g apart; "
549 "it needs at least one frame, 1 or 3 components, and a positive interval between several frames.",
550 source_file, frame_count, components, interval);
554 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_FILE_READ,
"Cannot record a position in %s.", source_file);
557 data->
frames = frame_count;
563 PetscFunctionReturn(0);
576 PetscFunctionBeginUser;
578 for (PetscInt idx = 0; idx < count; idx++) {
579 PetscReal value = 0.0;
580 if (fscanf(data->
file,
"%le", &value) != 1) {
581 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_FILE_READ,
582 "PICSLICE inlet profile file %s ended early in frame %" PetscInt_FMT
": expected %" PetscInt_FMT
" values.",
585 if (PetscIsInfOrNanReal(value) || (data->
components == 1 && value < 0.0)) {
586 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_FILE_UNEXPECTED,
587 "PICSLICE inlet profile file %s contains invalid speed %.6e at flat index %" PetscInt_FMT
".",
595 if (fscanf(data->
file,
"%63s", extra) == 1) {
596 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_FILE_UNEXPECTED,
597 "PICSLICE inlet profile file %s has extra token after %" PetscInt_FMT
" frames of %" PetscInt_FMT
" values: %s",
602 PetscFunctionReturn(0);
612 PetscInt i, PetscInt j, PetscInt k,
617 Cmpnts velocity = {0.0, 0.0, 0.0};
618 if (!data->
built)
return velocity;
624 velocity.
x = data->
factor * v.
x + staged.
x + fluct.
x;
625 velocity.
y = data->
factor * v.
y + staged.
y + fluct.
y;
626 velocity.
z = data->
factor * v.
z + staged.
z + fluct.
z;
629 const PetscReal area = sqrt(metric.
x * metric.
x + metric.
y * metric.
y + metric.
z * metric.
z);
630 if (area <= 0.0)
return velocity;
631 const PetscReal speed = data->
factor * v.
x + staged.
x;
632 velocity.
x = sign * speed * metric.
x / area + fluct.
x;
633 velocity.
y = sign * speed * metric.
y / area + fluct.
y;
634 velocity.
z = sign * speed * metric.
z / area + fluct.
z;
658 PetscBool can_service;
659 DMDALocalInfo *info = &user->
info;
660 Cmpnts ***ubcs, ***ucont, ***csi, ***eta, ***zet, ***ucat;
663 PetscFunctionBeginUser;
669 PetscCall(DMDAVecGetArray(user->
fda, user->
Bcs.
Ubcs, &ubcs));
670 PetscCall(DMDAVecGetArray(user->
fda, user->
Ucont, &ucont));
671 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
lCsi, (
const Cmpnts***)&csi));
672 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
lEta, (
const Cmpnts***)&eta));
673 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
lZet, (
const Cmpnts***)&zet));
674 PetscCall(DMDAVecGetArrayRead(user->
da, user->
lNvert, (
const PetscReal***)&nvert));
675 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
lUcat, (
const Cmpnts***)&ucat));
677 const PetscInt xs = info->xs, xe = info->xs + info->xm;
678 const PetscInt ys = info->ys, ye = info->ys + info->ym;
679 const PetscInt zs = info->zs, ze = info->zs + info->zm;
680 const PetscInt mx = info->mx, my = info->my, mz = info->mz;
681 PetscInt lxs = xs, lxe = xe, lys = ys, lye = ye, lzs = zs, lze = ze;
692 const PetscReal sign = (face_id ==
BC_FACE_NEG_X) ? 1.0 : -1.0;
694 const PetscInt ib = i + (sign < 0);
695 for (PetscInt k = lzs; k < lze; k++) {
696 for (PetscInt j = lys; j < lye; j++) {
697 if ((sign > 0 && nvert[k][j][i + 1] > 0.1) ||
698 (sign < 0 && nvert[k][j][i] > 0.1))
continue;
699 const Cmpnts metric = csi[k][j][i];
700 const Cmpnts velocity = rule(self, face_id, i, j, k, metric, sign,
701 (sign > 0) ? ucat[k][j][i + 1] : ucat[k][j][i]);
702 ubcs[k][j][ib] = velocity;
703 ucont[k][j][i].
x = velocity.
x * metric.
x + velocity.
y * metric.
y + velocity.
z * metric.
z;
709 const PetscReal sign = (face_id ==
BC_FACE_NEG_Y) ? 1.0 : -1.0;
711 const PetscInt jb = j + (sign < 0);
712 for (PetscInt k = lzs; k < lze; k++) {
713 for (PetscInt i = lxs; i < lxe; i++) {
714 if ((sign > 0 && nvert[k][j + 1][i] > 0.1) ||
715 (sign < 0 && nvert[k][j][i] > 0.1))
continue;
716 const Cmpnts metric = eta[k][j][i];
717 const Cmpnts velocity = rule(self, face_id, i, j, k, metric, sign,
718 (sign > 0) ? ucat[k][j + 1][i] : ucat[k][j][i]);
719 ubcs[k][jb][i] = velocity;
720 ucont[k][j][i].
y = velocity.
x * metric.
x + velocity.
y * metric.
y + velocity.
z * metric.
z;
726 const PetscReal sign = (face_id ==
BC_FACE_NEG_Z) ? 1.0 : -1.0;
728 const PetscInt kb = k + (sign < 0);
729 for (PetscInt j = lys; j < lye; j++) {
730 for (PetscInt i = lxs; i < lxe; i++) {
731 if ((sign > 0 && nvert[k + 1][j][i] > 0.1) ||
732 (sign < 0 && nvert[k][j][i] > 0.1))
continue;
733 const Cmpnts metric = zet[k][j][i];
734 const Cmpnts velocity = rule(self, face_id, i, j, k, metric, sign,
735 (sign > 0) ? ucat[k + 1][j][i] : ucat[k][j][i]);
736 ubcs[kb][j][i] = velocity;
737 ucont[k][j][i].
z = velocity.
x * metric.
x + velocity.
y * metric.
y + velocity.
z * metric.
z;
743 PetscCall(DMDAVecRestoreArray(user->
fda, user->
Bcs.
Ubcs, &ubcs));
744 PetscCall(DMDAVecRestoreArray(user->
fda, user->
Ucont, &ucont));
745 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
lCsi, (
const Cmpnts***)&csi));
746 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
lEta, (
const Cmpnts***)&eta));
747 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
lZet, (
const Cmpnts***)&zet));
748 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
lUcat, (
const Cmpnts***)&ucat));
749 PetscCall(DMDAVecRestoreArrayRead(user->
da, user->
lNvert, (
const PetscReal***)&nvert));
751 PetscFunctionReturn(0);
768 PetscFunctionBeginUser;
772 PetscFunctionReturn(0);
784 PetscFunctionBeginUser;
788 PetscFunctionReturn(0);
802 PetscBool found = PETSC_FALSE;
803 const char *source_file = NULL;
806 PetscFunctionBeginUser;
809 PetscCheck(found &&
id >= 0.0, PETSC_COMM_WORLD, PETSC_ERR_USER_INPUT,
810 "Face %s: the prescribed_velocity inlet needs a source_id parameter.",
BCFaceToString(ctx->
face_id));
812 if (found && source_file && source_file[0] !=
'\0') {
813 PetscCall(PetscStrallocpy(source_file, &data->
source_file));
815 PetscCall(PetscSNPrintf(prefix,
sizeof(prefix),
"face_source_%d", (
int)
id));
819 "Face %s: a profile file and the expressions added to it are in the normal or cartesian frame.",
825 char option[96], stress_prefix[96];
827 PetscCall(PetscSNPrintf(option,
sizeof(option),
"-%s_fluct", prefix));
828 PetscCall(PetscOptionsGetBool(NULL, NULL, option, &data->
fluctuate, NULL));
831 "Face %s adds fluctuations, but -inflow_fluctuations did not allocate their state.",
833 for (PetscInt g = 0; g < 2; ++g) {
834 PetscCall(PetscSNPrintf(stress_prefix,
sizeof(stress_prefix),
"%s_fluct_stress_%d", prefix, (
int)g));
839 PETSC_COMM_WORLD, PETSC_ERR_USER_INPUT,
840 "Face %s: the Reynolds stresses -%s_* must be in the cartesian frame, with no bulk_velocity or flow_rate.",
843 PetscCall(PetscSNPrintf(option,
sizeof(option),
"-%s_fluct_length", prefix));
844 PetscCall(PetscOptionsGetRealArray(NULL, NULL, option, data->
fluct_length, &count, &found));
846 PETSC_COMM_WORLD, PETSC_ERR_USER_INPUT,
"%s needs two positive length scales.", option);
847 PetscCall(PetscSNPrintf(option,
sizeof(option),
"-%s_fluct_time", prefix));
848 PetscCall(PetscOptionsGetReal(NULL, NULL, option, &data->
fluct_time, &found));
849 PetscCheck(found && data->
fluct_time > 0.0, PETSC_COMM_WORLD, PETSC_ERR_USER_INPUT,
850 "%s needs a positive time scale.", option);
864 LOG_ALLOW(
GLOBAL,
LOG_INFO,
"Face %s: synthetic fluctuations, integral lengths %g and %g, time %g (solver units).\n",
869 PetscFunctionReturn(0);
882 const PetscBool negative = (PetscBool)((PetscInt)face_id % 2 == 0);
886 PetscFunctionBeginUser;
888 local[0] = local[1] = local[2] = local[3] = 0.0;
891 const PetscInt cell = negative ? slot + 1 : slot;
892 const Cmpnts ***metric_arr;
893 const PetscReal ***nvert;
894 Vec metric_vec = (normal == 0) ? user->
lCsi : (normal == 1) ? user->
lEta : user->
lZet;
895 PetscCall(DMDAVecGetArrayRead(user->
fda, metric_vec, &metric_arr));
896 PetscCall(DMDAVecGetArrayRead(user->
da, user->
lNvert, &nvert));
897 for (PetscInt q = 0; q < slots->
elements.
n[1]; ++q)
898 for (PetscInt p = 0; p < slots->
elements.
n[0]; ++p) {
899 PetscInt s_idx[3], c_idx[3];
900 s_idx[normal] = slot; s_idx[a] = slots->
elements.
lo[0] + p; s_idx[b] = slots->
elements.
lo[1] + q;
901 c_idx[normal] = cell; c_idx[a] = s_idx[a]; c_idx[b] = s_idx[b];
902 if (nvert[c_idx[2]][c_idx[1]][c_idx[0]] > 0.1)
continue;
903 const Cmpnts m = metric_arr[s_idx[2]][s_idx[1]][s_idx[0]];
905 const PetscReal area = PetscSqrtReal(m.
x * m.
x + m.
y * m.
y + m.
z * m.
z);
906 const PetscReal physical = U_ref * L_ref * L_ref;
908 ? v.
x * area : sign * (v.
x * m.
x + v.
y * m.
y + v.
z * m.
z));
912 ? staged.
x * area : sign * (staged.
x * m.
x + staged.
y * m.
y + staged.
z * m.
z));
914 local[2] += L_ref * L_ref * area;
918 local[3] += physical * sign * (f.
x * m.
x + f.
y * m.
y + f.
z * m.
z);
921 PetscCall(DMDAVecRestoreArrayRead(user->
da, user->
lNvert, &nvert));
922 PetscCall(DMDAVecRestoreArrayRead(user->
fda, metric_vec, &metric_arr));
925 PetscFunctionReturn(0);
932 PetscReal physical_time, PetscReal *factor)
937 PetscFunctionBeginUser;
940 PetscCall(PetscSNPrintf(where,
sizeof(where),
"Face %s",
BCFaceToString(face_id)));
943 PetscFunctionReturn(0);
958 PetscFunctionBeginUser;
960 if (frame < data->next_frame) {
961 PetscCheck(fsetpos(data->
file, &data->
first_frame) == 0, PETSC_COMM_SELF, PETSC_ERR_FILE_READ,
962 "Cannot return to the first frame of %s.", data->
source_file);
967 for (PetscInt q = 0; q < slots->
elements.
n[1]; ++q)
968 for (PetscInt p = 0; p < slots->
elements.
n[0]; ++p) {
972 v->
y = (components == 3) ? value[1] : 0.0;
973 v->
z = (components == 3) ? value[2] : 0.0;
976 PetscFunctionReturn(0);
987 PetscInt n1 = 0, n2 = 0;
989 PetscFunctionBeginUser;
993 PetscCheck(data->
components == (normal ? 1 : 3), PETSC_COMM_WORLD, PETSC_ERR_USER_INPUT,
994 "Face %s: %s holds %" PetscInt_FMT
" component(s) per slot, but the source is in the %s frame.",
1000 PetscCheck(fclose(data->
file) == 0, PETSC_COMM_SELF, PETSC_ERR_FILE_READ,
"Cannot close %s.", data->
source_file);
1004 PetscCall(PetscMalloc1(n_slots, &data->
bracket[0]));
1005 PetscCall(PetscMalloc1(n_slots, &data->
bracket[1]));
1008 LOG_ALLOW(
GLOBAL,
LOG_INFO,
"Face %s: PICSLICE %s, %" PetscInt_FMT
" x %" PetscInt_FMT
", %" PetscInt_FMT
" component(s), %" PetscInt_FMT
" frame(s).\n",
1011 PetscFunctionReturn(0);
1020 const PetscReal position = physical_time / data->
interval;
1021 PetscInt frame[2] = {(PetscInt)PetscFloorReal(position), 0};
1022 PetscReal weight = position - PetscFloorReal(position);
1025 PetscFunctionBeginUser;
1028 frame[0] = frame[0] % data->
frames;
1029 frame[1] = (frame[0] + 1) % data->
frames;
1032 if (frame[0] == data->
frames - 1 && weight < 1.0e-9) { frame[0] = data->
frames - 2; weight = 1.0; }
1033 PetscCheck(frame[0] < data->
frames - 1 && frame[0] >= 0, PETSC_COMM_WORLD, PETSC_ERR_USER_INPUT,
1034 "Face %s: time %g is past the %" PetscInt_FMT
" frames of %s, %g s apart. Set repeat: true to loop them.",
1036 frame[1] = frame[0] + 1;
1038 for (PetscInt f = 0; f < 2; ++f) {
1052 for (PetscInt s = 0; s < n_slots; ++s) {
1053 out[s].
x = (1.0 - weight) * data->
bracket[0][s].
x + weight * data->
bracket[1][s].
x;
1054 out[s].
y = (1.0 - weight) * data->
bracket[0][s].
y + weight * data->
bracket[1][s].
y;
1055 out[s].
z = (1.0 - weight) * data->
bracket[0][s].
z + weight * data->
bracket[1][s].
z;
1058 PetscFunctionReturn(0);
1069 PetscFunctionBeginUser;
1071 for (PetscInt face = 0; face < 6; ++face) {
1073 PetscReal local[4], global[4], physical_time, flow_rate;
1078 if (!data->
built)
continue;
1080 PetscCallMPI(MPI_Allreduce(local, global, 4, MPIU_REAL, MPI_SUM, PETSC_COMM_WORLD));
1081 if (simCtx->
rank != 0 || user->
_this != 0)
continue;
1083 flow_rate = data->
factor * global[0] + global[1];
1085 "step,physical_time,face,area,flow_rate,mean_normal_speed,bulk_factor,"
1086 "fluctuation_flow_rate,applied_flow_rate",
1091 fprintf(file,
"%d,%.10e,%s,%.10e,%.10e,%.10e,%.10e,%.10e,%.10e\n", (
int)simCtx->
step, (
double)physical_time,
1093 (
double)(global[2] > 0.0 ? flow_rate / global[2] : 0.0), (
double)data->
factor,
1094 (double)global[3], (
double)(flow_rate + global[3]));
1095 PetscCheck(fclose(file) == 0, PETSC_COMM_SELF, PETSC_ERR_FILE_WRITE,
"Unable to close the inlet-flow diagnostics file.");
1098 PetscFunctionReturn(0);
1102#define INFLOW_LATTICE_PAD 1048576
1123 PetscReal extent[4] = {0.0, 0.0, -PETSC_MAX_REAL, -PETSC_MAX_REAL};
1125 PetscFunctionBeginUser;
1127 for (PetscInt s = 0; s < count; ++s) {
1128 for (PetscInt d = 0; d < 2; ++d) {
1130 const PetscReal width = PetscSqrtReal(e.
x * e.
x + e.
y * e.
y + e.
z * e.
z);
1131 extent[d] = PetscMax(extent[d], width);
1132 extent[2 + d] = PetscMax(extent[2 + d], -width);
1135 PetscCallMPI(MPI_Allreduce(MPI_IN_PLACE, extent, 4, MPIU_REAL, MPI_MAX, PETSC_COMM_WORLD));
1136 for (PetscInt d = 0; d < 2; ++d) {
1137 const PetscReal h = 0.5 * (extent[d] - extent[2 + d]);
1139 PetscReal norm = 0.0;
1140 data->
half[d] = PetscMax(1, (PetscInt)PetscCeilReal(2.0 * n));
1142 "An inlet's fluctuation length spans %g cells, beyond the %d its draws can reach.",
1144 PetscCall(PetscMalloc1(2 * data->
half[d] + 1, &data->
kernel[d]));
1145 for (PetscInt k = -data->
half[d]; k <= data->
half[d]; ++k) {
1146 data->
kernel[d][k + data->
half[d]] = PetscExpReal(-PETSC_PI * PetscAbsReal((PetscReal)k) / n);
1149 for (PetscInt k = 0; k <= 2 * data->
half[d]; ++k) data->
kernel[d][k] /= PetscSqrtReal(norm);
1151 PetscCall(PetscMalloc2(count, &data->
lund, count, &data->
fluct));
1152 for (PetscInt s = 0; s < count; ++s) {
1158 PetscReal *a = data->
lund[s];
1159 a[0] = PetscSqrtReal(PetscMax(diag.
x / U2, 0.0));
1160 a[1] = (a[0] > 0.0) ? cross.
x / U2 / a[0] : 0.0;
1161 a[2] = PetscSqrtReal(PetscMax(diag.
y / U2 - a[1] * a[1], 0.0));
1162 a[3] = (a[0] > 0.0) ? cross.
y / U2 / a[0] : 0.0;
1163 a[4] = (a[2] > 0.0) ? (cross.
z / U2 - a[1] * a[3]) / a[2] : 0.0;
1164 a[5] = PetscSqrtReal(PetscMax(diag.
z / U2 - a[3] * a[3] - a[4] * a[4], 0.0));
1168 PetscFunctionReturn(0);
1187 const PetscInt w0 = n0 + 2 * h0, w1 = n1 + 2 * h1;
1188 const PetscInt nodes[3] = {user->
info.mx, user->
info.my, user->
info.mz};
1189 const PetscInt cells[2] = {nodes[slots->
elements.
a] - 2, nodes[slots->
elements.
b] - 2};
1190 PetscBool axes_periodic[3];
1192 const PetscBool periodic[2] = {axes_periodic[slots->
elements.
a], axes_periodic[slots->
elements.
b]};
1193 const PetscBool negative = (PetscBool)((PetscInt)face_id % 2 == 0);
1194 const PetscReal decay = PetscExpReal(-PETSC_PI * simCtx->
dt / (2.0 * data->
fluct_time));
1195 const PetscReal gain = PetscSqrtReal(1.0 - decay * decay);
1199 PetscReal *noise = NULL, *rows = NULL, *psi = NULL;
1202 PetscFunctionBeginUser;
1205 PetscCall(PetscMalloc3(w0 * w1, &noise, n0 * w1, &rows, 3 * n0 * n1, &psi));
1206 for (PetscInt c = 0; c < 3 && !restored; ++c) {
1207 for (PetscInt qq = 0; qq < w1; ++qq) {
1208 for (PetscInt pp = 0; pp < w0; ++pp) {
1210 for (PetscInt d = 0; d < 2; ++d)
if (periodic[d]) g[d] = ((g[d] % cells[d]) + cells[d]) % cells[d];
1217 (uint64_t)(3 * user->
_this + c),
id,
1218 (PetscInt64)simCtx->
step));
1221 for (PetscInt qq = 0; qq < w1; ++qq) {
1222 for (PetscInt p = 0; p < n0; ++p) {
1223 PetscReal sum = 0.0;
1224 for (PetscInt k = 0; k <= 2 * h0; ++k) sum += data->
kernel[0][k] * noise[(p + k) + w0 * qq];
1225 rows[p + n0 * qq] = sum;
1228 for (PetscInt q = 0; q < n1; ++q) {
1229 for (PetscInt p = 0; p < n0; ++p) {
1230 PetscReal sum = 0.0;
1231 for (PetscInt k = 0; k <= 2 * h1; ++k) sum += data->
kernel[1][k] * rows[p + n0 * (q + k)];
1232 psi[3 * (p + n0 * q) + c] = sum;
1237 for (PetscInt q = 0; q < n1; ++q) {
1238 for (PetscInt p = 0; p < n0; ++p) {
1239 const PetscInt s = p + n0 * q;
1244 Cmpnts *st = &state[idx[2]][idx[1]][idx[0]];
1245 const PetscReal *f = &psi[3 * s];
1246 if (fresh) { st->
x = f[0]; st->
y = f[1]; st->
z = f[2]; }
1247 else if (!restored) { st->
x = decay * st->
x + gain * f[0]; st->
y = decay * st->
y + gain * f[1]; st->
z = decay * st->
z + gain * f[2]; }
1248 const PetscReal *a = data->
lund[s];
1249 data->
fluct[s].
x = a[0] * st->
x;
1250 data->
fluct[s].
y = a[1] * st->
x + a[2] * st->
y;
1251 data->
fluct[s].
z = a[3] * st->
x + a[4] * st->
y + a[5] * st->
z;
1255 PetscCall(PetscFree3(noise, rows, psi));
1259 PetscFunctionReturn(0);
1267 PetscReal *local_inflow_contribution,
1268 PetscReal *local_outflow_contribution)
1273 PetscReal physical_time;
1275 (void)local_inflow_contribution;
1276 (void)local_outflow_contribution;
1277 PetscFunctionBeginUser;
1282 const PetscBool first = (PetscBool)!data->
built;
1284 Vec fraction, length;
1285 PetscCall(DMCreateGlobalVector(user->
fda, &fraction));
1286 PetscCall(DMCreateGlobalVector(user->
fda, &length));
1289 PetscCall(VecDestroy(&fraction));
1290 PetscCall(VecDestroy(&length));
1295 const PetscBool frames_vary = (PetscBool)(data->
frames > 1);
1302 const PetscInt nodes[3] = {user->
info.mx, user->
info.my, user->
info.mz};
1307 (PetscInt64)simCtx->
step);
1316 const PetscReal speed2 = v.
x * v.
x + v.
y * v.
y + v.
z * v.
z;
1317 const PetscReal through = v.
x * m.
x + v.
y * m.
y + v.
z * m.
z;
1318 PetscCheck(through * through <= 2.5e-3 * speed2 * (m.
x * m.
x + m.
y * m.
y + m.
z * m.
z), PETSC_COMM_SELF, PETSC_ERR_USER_INPUT,
1319 "Face %s: a moving wall's velocity must lie along the wall; (%g, %g, %g) passes through it at (%g, %g, %g).",
1326 data->
built = PETSC_TRUE;
1331 PetscFunctionReturn(0);
1337 PetscFunctionBeginUser;
1339 if (self && self->
data) {
1343 if (data->
file) PetscCheck(fclose(data->
file) == 0, PETSC_COMM_SELF, PETSC_ERR_FILE_READ,
"Cannot close a PICSLICE file.");
1344 PetscCall(PetscFree(data->
profile));
1346 PetscCall(PetscFree(data->
bracket[0]));
1347 PetscCall(PetscFree(data->
bracket[1]));
1349 PetscCall(PetscFree(data->
velocity));
1353 PetscCall(PetscFree(data->
kernel[0]));
1354 PetscCall(PetscFree(data->
kernel[1]));
1355 PetscCall(PetscFree2(data->
lund, data->
fluct));
1357 PetscCall(PetscFree(self->
data));
1360 PetscFunctionReturn(0);
1394 PetscReal *local_inflow_contribution, PetscReal *local_outflow_contribution);
1397 PetscReal *in, PetscReal *out);
1416 PetscFunctionBeginUser;
1419 PetscCheck(bc, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"BoundaryCondition is NULL");
1435 PetscCall(PetscNew(&data));
1437 bc->
data = (
void*)data;
1440 PetscFunctionReturn(0);
1447 PetscReal *local_inflow_contribution, PetscReal *local_outflow_contribution)
1449 PetscErrorCode ierr;
1452 DMDALocalInfo* info = &user->
info;
1453 PetscBool can_service;
1457 (void)local_inflow_contribution;
1459 PetscFunctionBeginUser;
1464 const PetscInt IM_nodes_global = user->
IM;
1465 const PetscInt JM_nodes_global = user->
JM;
1466 const PetscInt KM_nodes_global = user->
KM;
1467 ierr =
CanRankServiceFace(info, IM_nodes_global, JM_nodes_global, KM_nodes_global, face_id, &can_service); CHKERRQ(ierr);
1471 PetscFunctionReturn(0);
1477 Cmpnts ***ucat, ***csi, ***eta, ***zet;
1479 ierr = DMDAVecGetArrayRead(user->
fda, user->
lUcat, (
const Cmpnts***)&ucat); CHKERRQ(ierr);
1480 ierr = DMDAVecGetArrayRead(user->
da, user->
lNvert, (
const PetscReal***)&nvert); CHKERRQ(ierr);
1481 ierr = DMDAVecGetArrayRead(user->
fda, user->
lCsi, (
const Cmpnts***)&csi); CHKERRQ(ierr);
1482 ierr = DMDAVecGetArrayRead(user->
fda, user->
lEta, (
const Cmpnts***)&eta); CHKERRQ(ierr);
1483 ierr = DMDAVecGetArrayRead(user->
fda, user->
lZet, (
const Cmpnts***)&zet); CHKERRQ(ierr);
1485 PetscReal local_flux_out = 0.0;
1486 const PetscInt xs=info->xs, xe=info->xs+info->xm;
1487 const PetscInt ys=info->ys, ye=info->ys+info->ym;
1488 const PetscInt zs=info->zs, ze=info->zs+info->zm;
1489 const PetscInt mx=info->mx, my=info->my, mz=info->mz;
1492 PetscInt lxs = xs;
if (xs == 0) lxs = xs + 1;
1493 PetscInt lxe = xe;
if (xe == mx) lxe = xe - 1;
1494 PetscInt lys = ys;
if (ys == 0) lys = ys + 1;
1495 PetscInt lye = ye;
if (ye == my) lye = ye - 1;
1496 PetscInt lzs = zs;
if (zs == 0) lzs = zs + 1;
1497 PetscInt lze = ze;
if (ze == mz) lze = ze - 1;
1502 const PetscInt i_cell = xs + 1;
1503 const PetscInt i_face = xs;
1504 for (
int k=lzs; k<lze; k++)
for (
int j=lys; j<lye; j++) {
1505 if (nvert[k][j][i_cell] < 0.1) {
1506 local_flux_out += (ucat[k][j][i_cell].
x * csi[k][j][i_face].
x + ucat[k][j][i_cell].
y * csi[k][j][i_face].
y + ucat[k][j][i_cell].
z * csi[k][j][i_face].
z);
1512 const PetscInt i_cell = xe - 2;
1513 const PetscInt i_face = xe - 2;
1514 for (
int k=lzs; k<lze; k++)
for (
int j=lys; j<lye; j++) {
1515 if (nvert[k][j][i_cell] < 0.1) {
1516 local_flux_out += (ucat[k][j][i_cell].
x * csi[k][j][i_face].
x + ucat[k][j][i_cell].
y * csi[k][j][i_face].
y + ucat[k][j][i_cell].
z * csi[k][j][i_face].
z);
1522 const PetscInt j_cell = ys + 1;
1523 const PetscInt j_face = ys;
1524 for (
int k=lzs; k<lze; k++)
for (
int i=lxs; i<lxe; i++) {
1525 if (nvert[k][j_cell][i] < 0.1) {
1526 local_flux_out += (ucat[k][j_cell][i].
x * eta[k][j_face][i].
x + ucat[k][j_cell][i].
y * eta[k][j_face][i].
y + ucat[k][j_cell][i].
z * eta[k][j_face][i].
z);
1532 const PetscInt j_cell = ye - 2;
1533 const PetscInt j_face = ye - 2;
1534 for (
int k=lzs; k<lze; k++)
for (
int i=lxs; i<lxe; i++) {
1535 if (nvert[k][j_cell][i] < 0.1) {
1536 local_flux_out += (ucat[k][j_cell][i].
x * eta[k][j_face][i].
x + ucat[k][j_cell][i].
y * eta[k][j_face][i].
y + ucat[k][j_cell][i].
z * eta[k][j_face][i].
z);
1542 const PetscInt k_cell = zs + 1;
1543 const PetscInt k_face = zs;
1544 for (
int j=lys; j<lye; j++)
for (
int i=lxs; i<lxe; i++) {
1545 if (nvert[k_cell][j][i] < 0.1) {
1546 local_flux_out += (ucat[k_cell][j][i].
x * zet[k_face][j][i].
x + ucat[k_cell][j][i].
y * zet[k_face][j][i].
y + ucat[k_cell][j][i].
z * zet[k_face][j][i].
z);
1552 const PetscInt k_cell = ze - 2;
1553 const PetscInt k_face = ze - 2;
1554 for (
int j=lys; j<lye; j++)
for (
int i=lxs; i<lxe; i++) {
1555 if (nvert[k_cell][j][i] < 0.1) {
1556 local_flux_out += (ucat[k_cell][j][i].
x * zet[k_face][j][i].
x + ucat[k_cell][j][i].
y * zet[k_face][j][i].
y + ucat[k_cell][j][i].
z * zet[k_face][j][i].
z);
1564 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lUcat, (
const Cmpnts***)&ucat); CHKERRQ(ierr);
1565 ierr = DMDAVecRestoreArrayRead(user->
da, user->
lNvert, (
const PetscReal***)&nvert); CHKERRQ(ierr);
1566 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lCsi, (
const Cmpnts***)&csi); CHKERRQ(ierr);
1567 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lEta, (
const Cmpnts***)&eta); CHKERRQ(ierr);
1568 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lZet, (
const Cmpnts***)&zet); CHKERRQ(ierr);
1571 *local_outflow_contribution += local_flux_out;
1574 PetscFunctionReturn(0);
1597 const PetscBool negative = (PetscBool)((PetscInt)face_id % 2 == 0);
1598 const PetscReal outward = negative ? -1.0 : 1.0;
1600 Cmpnts ***ucat, ***metric, ***ubcs = NULL, ***ucont = NULL;
1603 PetscFunctionBeginUser;
1605 sums[0] = sums[1] = sums[2] = 0.0;
1607 const PetscInt count = e.
n[0] * e.
n[1];
1609 PetscCall(PetscFree(data->
clipped));
1610 if (count > 0) PetscCall(PetscCalloc1(count, &data->
clipped));
1616 const PetscInt cell = negative ? e.
layer + 1 : e.
layer;
1617 const PetscInt dummy = negative ? e.
layer : e.
layer + 1;
1619 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
lUcat, (
const Cmpnts***)&ucat));
1620 PetscCall(DMDAVecGetArrayRead(user->
fda, lmetric, (
const Cmpnts***)&metric));
1621 PetscCall(DMDAVecGetArrayRead(user->
da, user->
lNvert, (
const PetscReal***)&nvert));
1623 PetscCall(DMDAVecGetArray(user->
fda, user->
Bcs.
Ubcs, &ubcs));
1624 PetscCall(DMDAVecGetArray(user->
fda, user->
Ucont, &ucont));
1626 for (PetscInt q = 0; q < e.
n[1]; q++)
1627 for (PetscInt p = 0; p < e.
n[0]; p++) {
1628 PetscInt c[3], f[3], d[3];
1630 c[e.
normal] = cell; c[e.
a] = e.
lo[0] + p; c[e.
b] = e.
lo[1] + q;
1631 if (nvert[c[2]][c[1]][c[0]] >= 0.1)
continue;
1632 f[0] = d[0] = c[0]; f[1] = d[1] = c[1]; f[2] = d[2] = c[2];
1636 const PetscInt idx = q * e.
n[0] + p;
1637 const Cmpnts S = metric[f[2]][f[1]][f[0]];
1638 const Cmpnts u = ucat[c[2]][c[1]][c[0]];
1639 const PetscReal flux = u.
x * S.
x + u.
y * S.
y + u.
z * S.
z;
1640 const PetscReal area = PetscSqrtReal(S.
x * S.
x + S.
y * S.
y + S.
z * S.
z);
1644 data->
clipped[idx] = (PetscBool)(outward * flux < 0.0);
1645 if (outward * (flux + correction * area) < 0.0) sums[0] += 1.0;
1646 if (data->
clipped[idx]) sums[1] += 1.0;
1651 if (!data->
clipped[idx]) sums[2] += flux;
1654 Cmpnts *face_flux = &ucont[f[2]][f[1]][f[0]];
1655 PetscReal *normal_flux = (e.
normal == 0) ? &face_flux->
x : (e.
normal == 1) ? &face_flux->
y : &face_flux->
z;
1661 *normal_flux = psi * flux;
1662 ubcs[d[2]][d[1]][d[0]] = u;
1669 PetscCall(DMDAVecRestoreArray(user->
fda, user->
Bcs.
Ubcs, &ubcs));
1670 PetscCall(DMDAVecRestoreArray(user->
fda, user->
Ucont, &ucont));
1672 PetscCall(DMDAVecRestoreArrayRead(user->
da, user->
lNvert, (
const PetscReal***)&nvert));
1673 PetscCall(DMDAVecRestoreArrayRead(user->
fda, lmetric, (
const Cmpnts***)&metric));
1674 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
lUcat, (
const Cmpnts***)&ucat));
1676 PetscFunctionReturn(PETSC_SUCCESS);
1686 PetscReal correction, PetscBool *applied)
1689 const PetscReal outward = ((PetscInt)face_id % 2 == 0) ? -1.0 : 1.0;
1690 PetscReal local[3], global[3];
1691 PetscBool decided_now = PETSC_FALSE;
1692 PetscReal reversed = 0.0, clipped = 0.0;
1694 PetscFunctionBeginUser;
1696 *applied = PETSC_FALSE;
1699 PetscCallMPI(MPI_Allreduce(local, global, 2, MPIU_REAL, MPI_SUM, PETSC_COMM_WORLD));
1700 data->
clipRule = (PetscBool)(global[0] > 0.5);
1702 decided_now = PETSC_TRUE;
1703 reversed = global[0];
1704 clipped = global[1];
1709 PetscCallMPI(MPI_Allreduce(local, global, 3, MPIU_REAL, MPI_SUM, PETSC_COMM_WORLD));
1711 const PetscReal target = global[0] + correction * global[1];
1712 if (!(outward * global[2] > 0.0 && outward * target > 0.0)) {
1714 "Outlet %s, step %" PetscInt_FMT
": nothing left to scale (unclipped flux %.4e, target %.4e); "
1715 "using the uniform correction for this pass.\n",
1718 PetscFunctionReturn(PETSC_SUCCESS);
1720 const PetscReal psi = target / global[2];
1724 "Outlet %s, step %" PetscInt_FMT
": uniform correction would leave %.0f faces reversed; "
1725 "clipped %.0f reversed faces, scaled the rest by psi = %.6f.\n",
1728 *applied = PETSC_TRUE;
1730 PetscFunctionReturn(PETSC_SUCCESS);
1741 PetscErrorCode ierr;
1744 DMDALocalInfo* info = &user->
info;
1745 PetscBool can_service;
1746 PetscBool clip_applied = PETSC_FALSE;
1748 PetscFunctionBeginUser;
1756 PetscReal velocity_correction = (PetscAbsReal(user->
simCtx->
AreaOutSum) > 1e-12)
1766 velocity_correction, &clip_applied); CHKERRQ(ierr);
1769 PetscFunctionReturn(0);
1772 const PetscInt IM_nodes_global = user->
IM;
1773 const PetscInt JM_nodes_global = user->
JM;
1774 const PetscInt KM_nodes_global = user->
KM;
1775 ierr =
CanRankServiceFace(info, IM_nodes_global, JM_nodes_global, KM_nodes_global, face_id, &can_service); CHKERRQ(ierr);
1779 PetscFunctionReturn(0);
1786 Cmpnts ***ubcs, ***ucont, ***csi, ***eta, ***zet, ***ucat;
1788 ierr = DMDAVecGetArray(user->
fda, user->
Bcs.
Ubcs, &ubcs); CHKERRQ(ierr);
1789 ierr = DMDAVecGetArray(user->
fda, user->
Ucont, &ucont); CHKERRQ(ierr);
1790 ierr = DMDAVecGetArrayRead(user->
fda,user->
lUcat, (
const Cmpnts***)&ucat); CHKERRQ(ierr);
1791 ierr = DMDAVecGetArrayRead(user->
fda, user->
lCsi, (
const Cmpnts***)&csi); CHKERRQ(ierr);
1792 ierr = DMDAVecGetArrayRead(user->
fda, user->
lEta, (
const Cmpnts***)&eta); CHKERRQ(ierr);
1793 ierr = DMDAVecGetArrayRead(user->
fda, user->
lZet, (
const Cmpnts***)&zet); CHKERRQ(ierr);
1794 ierr = DMDAVecGetArrayRead(user->
da, user->
lNvert, (
const PetscReal***)&nvert); CHKERRQ(ierr);
1797 PetscInt xs = info->xs, xe = info->xs + info->xm;
1798 PetscInt ys = info->ys, ye = info->ys + info->ym;
1799 PetscInt zs = info->zs, ze = info->zs + info->zm;
1800 PetscInt mx = info->mx, my = info->my, mz = info->mz;
1801 PetscInt lxs = xs, lxe = xe, lys = ys, lye = ye, lzs = zs, lze = ze;
1803 if (xs == 0) lxs = xs + 1;
1804 if (xe == mx) lxe = xe - 1;
1805 if (ys == 0) lys = ys + 1;
1806 if (ye == my) lye = ye - 1;
1807 if (zs == 0) lzs = zs + 1;
1808 if (ze == mz) lze = ze - 1;
1813 const PetscInt i_cell = xs + 1;
1814 const PetscInt i_face = xs;
1815 const PetscInt i_dummy = xs;
1816 for (PetscInt k = lzs; k < lze; k++) {
1817 for (PetscInt j = lys; j < lye; j++) {
1818 if (nvert[k][j][i_cell] < 0.1) {
1820 ubcs[k][j][i_dummy] = ucat[k][j][i_cell];
1823 PetscReal Uncorrected_local_flux = (ubcs[k][j][i_dummy].
x * csi[k][j][i_face].
x) + (ubcs[k][j][i_dummy].y * csi[k][j][i_face].y) + (ubcs[k][j][i_dummy].
z * csi[k][j][i_face].
z);
1825 PetscReal Cell_Area = sqrt((csi[k][j][i_face].x*csi[k][j][i_face].x) + (csi[k][j][i_face].y*csi[k][j][i_face].y) + (csi[k][j][i_face].z*csi[k][j][i_face].z));
1827 PetscReal Correction_flux = velocity_correction*Cell_Area;
1829 ucont[k][j][i_face].
x = Uncorrected_local_flux + Correction_flux;
1836 const PetscInt i_cell = xe - 2;
1837 const PetscInt i_face = xe - 2;
1838 const PetscInt i_dummy = xe - 1;
1839 for(PetscInt k = lzs; k < lze; k++)
for (PetscInt j = lys; j < lye; j++){
1840 if(nvert[k][j][i_cell]<0.1){
1842 ubcs[k][j][i_dummy] = ucat[k][j][i_cell];
1845 PetscReal Uncorrected_local_flux = (ubcs[k][j][i_dummy].
x * csi[k][j][i_face].
x) + (ubcs[k][j][i_dummy].y * csi[k][j][i_face].y) + (ubcs[k][j][i_dummy].
z * csi[k][j][i_face].
z);
1847 PetscReal Cell_Area = sqrt((csi[k][j][i_face].x*csi[k][j][i_face].x) + (csi[k][j][i_face].y*csi[k][j][i_face].y) + (csi[k][j][i_face].z*csi[k][j][i_face].z));
1849 PetscReal Correction_flux = velocity_correction*Cell_Area;
1851 ucont[k][j][i_face].
x = Uncorrected_local_flux + Correction_flux;
1857 const PetscInt j_cell = ys + 1;
1858 const PetscInt j_face = ys;
1859 const PetscInt j_dummy = ys;
1860 for(PetscInt k = lzs; k < lze; k++)
for (PetscInt i = lxs; i < lxe; i++){
1861 if(nvert[k][j_cell][i]<0.1){
1863 ubcs[k][j_dummy][i] = ucat[k][j_cell][i];
1866 PetscReal Uncorrected_local_flux = (ubcs[k][j_dummy][i].
x*eta[k][j_face][i].
x) + (ubcs[k][j_dummy][i].y*eta[k][j_face][i].y) + (ubcs[k][j_dummy][i].
z*eta[k][j_face][i].
z);
1868 PetscReal Cell_Area = sqrt((eta[k][j_face][i].x*eta[k][j_face][i].x)+(eta[k][j_face][i].y*eta[k][j_face][i].y)+(eta[k][j_face][i].z*eta[k][j_face][i].z));
1870 PetscReal Correction_flux = velocity_correction*Cell_Area;
1872 ucont[k][j_face][i].
y = Uncorrected_local_flux + Correction_flux;
1878 const PetscInt j_cell = ye - 2;
1879 const PetscInt j_face = ye - 2;
1880 const PetscInt j_dummy = ye - 1;
1881 for(PetscInt k = lzs; k < lze; k++)
for (PetscInt i = lxs; i < lxe; i++){
1882 if(nvert[k][j_cell][i]<0.1){
1884 ubcs[k][j_dummy][i] = ucat[k][j_cell][i];
1887 PetscReal Uncorrected_local_flux = (ubcs[k][j_dummy][i].
x*eta[k][j_face][i].
x) + (ubcs[k][j_dummy][i].y*eta[k][j_face][i].y) + (ubcs[k][j_dummy][i].
z*eta[k][j_face][i].
z);
1889 PetscReal Cell_Area = sqrt((eta[k][j_face][i].x*eta[k][j_face][i].x)+(eta[k][j_face][i].y*eta[k][j_face][i].y)+(eta[k][j_face][i].z*eta[k][j_face][i].z));
1891 PetscReal Correction_flux = velocity_correction*Cell_Area;
1893 ucont[k][j_face][i].
y = Uncorrected_local_flux + Correction_flux;
1899 const PetscInt k_cell = zs + 1;
1900 const PetscInt k_face = zs;
1901 const PetscInt k_dummy = zs;
1902 for(PetscInt j = lys; j < lye; j++)
for (PetscInt i = lxs; i < lxe; i++){
1903 if(nvert[k_cell][j][i]<0.1){
1905 ubcs[k_dummy][j][i] = ucat[k_cell][j][i];
1908 PetscReal Uncorrected_local_flux = ((ubcs[k_dummy][j][i].
x*zet[k_face][j][i].
x) + (ubcs[k_dummy][j][i].y*zet[k_face][j][i].y) + (ubcs[k_dummy][j][i].
z*zet[k_face][j][i].
z));
1910 PetscReal Cell_Area = sqrt((zet[k_face][j][i].x*zet[k_face][j][i].x)+(zet[k_face][j][i].y*zet[k_face][j][i].y)+(zet[k_face][j][i].z*zet[k_face][j][i].z));
1912 PetscReal Correction_flux = velocity_correction*Cell_Area;
1914 ucont[k_face][j][i].
z = Uncorrected_local_flux + Correction_flux;
1920 const PetscInt k_cell = ze - 2;
1921 const PetscInt k_face = ze - 2;
1922 const PetscInt k_dummy = ze - 1;
1923 for(PetscInt j = lys; j < lye; j++)
for (PetscInt i = lxs; i < lxe; i++){
1924 if(nvert[k_cell][j][i]<0.1){
1926 ubcs[k_dummy][j][i] = ucat[k_cell][j][i];
1929 PetscReal Uncorrected_local_flux = ((ubcs[k_dummy][j][i].
x*zet[k_face][j][i].
x) + (ubcs[k_dummy][j][i].y*zet[k_face][j][i].y) + (ubcs[k_dummy][j][i].
z*zet[k_face][j][i].
z));
1931 PetscReal Cell_Area = sqrt((zet[k_face][j][i].x*zet[k_face][j][i].x)+(zet[k_face][j][i].y*zet[k_face][j][i].y)+(zet[k_face][j][i].z*zet[k_face][j][i].z));
1933 PetscReal Correction_flux = velocity_correction*Cell_Area;
1935 ucont[k_face][j][i].
z = Uncorrected_local_flux + Correction_flux;
1943 ierr = DMDAVecRestoreArray(user->
fda, user->
Bcs.
Ubcs, &ubcs); CHKERRQ(ierr);
1944 ierr = DMDAVecRestoreArray(user->
fda, user->
Ucont, &ucont); CHKERRQ(ierr);
1945 ierr = DMDAVecRestoreArrayRead(user->
fda,user->
lUcat, (
const Cmpnts***)&ucat); CHKERRQ(ierr);
1946 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lCsi, (
const Cmpnts***)&csi); CHKERRQ(ierr);
1947 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lEta, (
const Cmpnts***)&eta); CHKERRQ(ierr);
1948 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lZet, (
const Cmpnts***)&zet); CHKERRQ(ierr);
1949 ierr = DMDAVecRestoreArrayRead(user->
da, user->
lNvert, (
const PetscReal***)&nvert); CHKERRQ(ierr);
1952 PetscFunctionReturn(0);
1959 PetscReal *local_inflow_contribution,
1960 PetscReal *local_outflow_contribution)
1962 PetscErrorCode ierr;
1965 DMDALocalInfo* info = &user->
info;
1966 PetscBool can_service;
1969 (void)local_inflow_contribution;
1971 PetscFunctionBeginUser;
1973 const PetscInt IM_nodes_global = user->
IM;
1974 const PetscInt JM_nodes_global = user->
JM;
1975 const PetscInt KM_nodes_global = user->
KM;
1976 ierr =
CanRankServiceFace(info, IM_nodes_global, JM_nodes_global, KM_nodes_global, face_id, &can_service); CHKERRQ(ierr);
1984 ierr = DMDAVecGetArrayRead(user->
fda, user->
Ucont, (
const Cmpnts***)&ucont); CHKERRQ(ierr);
1985 ierr = DMDAVecGetArrayRead(user->
da, user->
lNvert, (
const PetscReal***)&nvert); CHKERRQ(ierr);
1987 PetscReal local_flux = 0.0;
1989 PetscInt xs = info->xs, xe = info->xs + info->xm;
1990 PetscInt ys = info->ys, ye = info->ys + info->ym;
1991 PetscInt zs = info->zs, ze = info->zs + info->zm;
1992 PetscInt mx = info->mx, my = info->my, mz = info->mz;
1994 PetscInt lxs = xs, lxe = xe, lys = ys, lye = ye, lzs = zs, lze = ze;
1995 if (xs == 0) lxs = xs + 1;
1996 if (xe == mx) lxe = xe - 1;
1997 if (ys == 0) lys = ys + 1;
1998 if (ye == my) lye = ye - 1;
1999 if (zs == 0) lzs = zs + 1;
2000 if (ze == mz) lze = ze - 1;
2005 const PetscInt i_cell = xs + 1;
2006 const PetscInt i_face = xs;
2007 for (PetscInt k = lzs; k < lze; k++) {
2008 for (PetscInt j = lys; j < lye; j++) {
2009 if (nvert[k][j][i_cell] < 0.1) {
2010 local_flux += ucont[k][j][i_face].
x;
2017 const PetscInt i_cell = xe - 2;
2018 const PetscInt i_face = xe - 2;
2019 for (PetscInt k = lzs; k < lze; k++) {
2020 for (PetscInt j = lys; j < lye; j++) {
2021 if (nvert[k][j][i_cell] < 0.1) {
2022 local_flux += ucont[k][j][i_face].
x;
2029 const PetscInt j_cell = ys + 1;
2030 const PetscInt j_face = ys;
2031 for (PetscInt k = lzs; k < lze; k++) {
2032 for (PetscInt i = lxs; i < lxe; i++) {
2033 if (nvert[k][j_cell][i] < 0.1) {
2034 local_flux += ucont[k][j_face][i].
y;
2041 const PetscInt j_cell = ye - 2;
2042 const PetscInt j_face = ye - 2;
2043 for (PetscInt k = lzs; k < lze; k++) {
2044 for (PetscInt i = lxs; i < lxe; i++) {
2045 if (nvert[k][j_cell][i] < 0.1) {
2046 local_flux += ucont[k][j_face][i].
y;
2053 const PetscInt k_cell = zs + 1;
2054 const PetscInt k_face = zs;
2055 for (PetscInt j = lys; j < lye; j++) {
2056 for (PetscInt i = lxs; i < lxe; i++) {
2057 if (nvert[k_cell][j][i] < 0.1) {
2058 local_flux += ucont[k_face][j][i].
z;
2065 const PetscInt k_cell = ze - 2;
2066 const PetscInt k_face = ze - 2;
2067 for (PetscInt j = lys; j < lye; j++) {
2068 for (PetscInt i = lxs; i < lxe; i++) {
2069 if (nvert[k_cell][j][i] < 0.1) {
2070 local_flux += ucont[k_face][j][i].
z;
2078 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
Ucont, (
const Cmpnts***)&ucont); CHKERRQ(ierr);
2079 ierr = DMDAVecRestoreArrayRead(user->
da, user->
lNvert, (
const PetscReal***)&nvert); CHKERRQ(ierr);
2082 *local_outflow_contribution += local_flux;
2085 face_id, local_flux);
2088 PetscFunctionReturn(0);
2096 PetscFunctionBeginUser;
2098 if (self && self->
data) {
2100 PetscCall(PetscFree(data->
clipped));
2101 PetscCall(PetscFree(self->
data));
2104 PetscFunctionReturn(PETSC_SUCCESS);
2116 PetscFunctionBeginUser;
2119 PetscCheck(bc, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"BoundaryCondition is NULL");
2133 PetscFunctionReturn(0);
2156 PetscReal *boundaryFlux,
2157 PetscReal *planarAverageFlux)
2159 PetscErrorCode ierr;
2160 DMDALocalInfo info = user->
info;
2163 PetscFunctionBeginUser;
2169 ierr = DMDAVecGetArrayRead(user->
fda, user->
lUcont, (
const Cmpnts***)&ucont); CHKERRQ(ierr);
2170 ierr = DMDAVecGetArrayRead(user->
da, user->
lNvert, (
const PetscReal***)&nvert); CHKERRQ(ierr);
2173 PetscInt lo[3], hi[3];
2175 PetscInt lxs = lo[0], lys = lo[1], lzs = lo[2], lxe = hi[0], lye = hi[1], lze = hi[2];
2178 PetscReal localCurrentBoundaryFlux = 0.0;
2179 PetscReal localAveragePlanarVolumetricFluxTerm = 0.0;
2182 switch (direction) {
2186 for (k = lzs; k < lze; k++)
for (j = lys; j < lye; j++) {
2187 if (nvert[k][j][i + 1] < 0.1) localCurrentBoundaryFlux += ucont[k][j][i].
x;
2190 for (i = info.xs; i < lxe; i++) {
2191 for (k = lzs; k < lze; k++)
for (j = lys; j < lye; j++) {
2192 if (nvert[k][j][i + 1] < 0.1) localAveragePlanarVolumetricFluxTerm += ucont[k][j][i].
x / (PetscReal)(info.mx - 1);
2199 for (k = lzs; k < lze; k++)
for (i = lxs; i < lxe; i++) {
2200 if (nvert[k][j + 1][i] < 0.1) localCurrentBoundaryFlux += ucont[k][j][i].
y;
2203 for (j = info.ys; j < lye; j++) {
2204 for (k = lzs; k < lze; k++)
for (i = lxs; i < lxe; i++) {
2205 if (nvert[k][j + 1][i] < 0.1) localAveragePlanarVolumetricFluxTerm += ucont[k][j][i].
y / (PetscReal)(info.my - 1);
2212 for (j = lys; j < lye; j++)
for (i = lxs; i < lxe; i++) {
2213 if (nvert[k + 1][j][i] < 0.1) localCurrentBoundaryFlux += ucont[k][j][i].
z;
2216 for (k = info.zs; k < lze; k++) {
2217 for (j = lys; j < lye; j++)
for (i = lxs; i < lxe; i++) {
2218 if (nvert[k + 1][j][i] < 0.1) localAveragePlanarVolumetricFluxTerm += ucont[k][j][i].
z / (PetscReal)(info.mz - 1);
2223 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG,
2224 "MeasureDrivenFluxes received an unknown driven direction '%c'.", direction);
2228 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lUcont, (
const Cmpnts***)&ucont); CHKERRQ(ierr);
2229 ierr = DMDAVecRestoreArrayRead(user->
da, user->
lNvert, (
const PetscReal***)&nvert); CHKERRQ(ierr);
2232 ierr = MPI_Allreduce(&localCurrentBoundaryFlux, boundaryFlux, 1, MPI_DOUBLE, MPI_SUM, PETSC_COMM_WORLD); CHKERRQ(ierr);
2233 ierr = MPI_Allreduce(&localAveragePlanarVolumetricFluxTerm, planarAverageFlux, 1, MPI_DOUBLE, MPI_SUM, PETSC_COMM_WORLD); CHKERRQ(ierr);
2236 PetscFunctionReturn(0);
2280 PetscErrorCode ierr;
2281 PetscFunctionBeginUser;
2284 PetscCheck(bc, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"BoundaryCondition is NULL");
2288 ierr = PetscNew(&data); CHKERRQ(ierr);
2297 bc->
data = (
void*)data;
2315 PetscFunctionReturn(0);
2323 PetscErrorCode ierr;
2328 PetscFunctionBeginUser;
2335 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_USER_INPUT,
2336 "Configuration Error: Handler PERIODIC_DRIVEN_CONSTANT_FLUX on Face %s must be applied to a face with mathematical_type PERIODIC.",
2361 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_USER_INPUT,
2362 "Configuration Error: Handler PERIODIC_DRIVEN_CONSTANT_FLUX on Face %s requires a 'target_flux' parameter in the bcs file (e.g., target_flux=10.0).",
2377 PetscBool trimfound;
2387 PetscFunctionReturn(0);
2394 PetscReal *local_inflow_contribution,
2395 PetscReal *local_outflow_contribution)
2397 PetscErrorCode ierr;
2402 PetscFunctionBeginUser;
2408 PetscFunctionReturn(0);
2414 PetscReal globalCurrentBoundaryFlux, globalAveragePlanarVolumetricFlux;
2416 &globalAveragePlanarVolumetricFlux); CHKERRQ(ierr);
2420 PetscReal globalBoundaryArea;
2446 if (globalBoundaryArea > 1.0e-12) {
2462 LOG_ALLOW(
GLOBAL,
LOG_INFO,
" - Avg Planar Volumetric Flux (Stable): %.6e\n", globalAveragePlanarVolumetricFlux);
2468 (void)local_inflow_contribution;
2469 (void)local_outflow_contribution;
2472 PetscFunctionReturn(0);
2480 PetscErrorCode ierr;
2484 PetscBool can_service;
2486 PetscFunctionBeginUser;
2493 PetscFunctionReturn(0);
2499 PetscFunctionReturn(0);
2505 DMDALocalInfo info = user->
info;
2506 Cmpnts ***ucont, ***uch, ***csi, ***eta, ***zet;
2509 ierr = DMDAVecGetArray(user->
fda, user->
Ucont, &ucont); CHKERRQ(ierr);
2510 ierr = DMDAVecGetArray(user->
fda, user->
Bcs.
Uch, &uch); CHKERRQ(ierr);
2511 ierr = DMDAVecGetArrayRead(user->
fda, user->
lCsi, (
const Cmpnts***)&csi); CHKERRQ(ierr);
2512 ierr = DMDAVecGetArrayRead(user->
fda, user->
lEta, (
const Cmpnts***)&eta); CHKERRQ(ierr);
2513 ierr = DMDAVecGetArrayRead(user->
fda, user->
lZet, (
const Cmpnts***)&zet); CHKERRQ(ierr);
2514 ierr = DMDAVecGetArrayRead(user->
da, user->
lNvert, (
const PetscReal***)&nvert); CHKERRQ(ierr);
2516 PetscInt lo[3], hi[3];
2518 PetscInt lxs = lo[0], lys = lo[1], lzs = lo[2], lxe = hi[0], lye = hi[1], lze = hi[2];
2523 PetscInt i_face = (face_id ==
BC_FACE_NEG_X) ? info.xs : info.mx - 2;
2524 PetscInt i_nvert = (face_id ==
BC_FACE_NEG_X) ? info.xs + 1 : info.mx - 2;
2526 for (PetscInt k = lzs; k < lze; k++)
for (PetscInt j = lys; j < lye; j++) {
2527 if (nvert[k][j][i_nvert] < 0.1) {
2528 PetscReal faceArea = sqrt(csi[k][j][i_face].x*csi[k][j][i_face].x + csi[k][j][i_face].y*csi[k][j][i_face].y + csi[k][j][i_face].z*csi[k][j][i_face].z);
2531 uch[k][j][i_face].
x = fluxTrim;
2537 PetscInt j_face = (face_id ==
BC_FACE_NEG_Y) ? info.ys : info.my - 2;
2538 PetscInt j_nvert = (face_id ==
BC_FACE_NEG_Y) ? info.ys + 1 : info.my - 2;
2540 for (PetscInt k = lzs; k < lze; k++)
for (PetscInt i = lxs; i < lxe; i++) {
2541 if (nvert[k][j_nvert][i] < 0.1) {
2542 PetscReal faceArea = sqrt(eta[k][j_face][i].x*eta[k][j_face][i].x + eta[k][j_face][i].y*eta[k][j_face][i].y + eta[k][j_face][i].z*eta[k][j_face][i].z);
2545 uch[k][j_face][i].
y = fluxTrim;
2551 PetscInt k_face = (face_id ==
BC_FACE_NEG_Z) ? info.zs : info.mz - 2;
2552 PetscInt k_nvert = (face_id ==
BC_FACE_NEG_Z) ? info.zs + 1 : info.mz - 2;
2554 for (PetscInt j = lys; j < lye; j++)
for (PetscInt i = lxs; i < lxe; i++) {
2555 if (nvert[k_nvert][j][i] < 0.1) {
2556 PetscReal faceArea = sqrt(zet[k_face][j][i].x*zet[k_face][j][i].x + zet[k_face][j][i].y*zet[k_face][j][i].y + zet[k_face][j][i].z*zet[k_face][j][i].z);
2559 uch[k_face][j][i].
z = fluxTrim;
2566 ierr = DMDAVecRestoreArray(user->
fda, user->
Ucont, &ucont); CHKERRQ(ierr);
2567 ierr = DMDAVecRestoreArray(user->
fda, user->
Bcs.
Uch, &uch); CHKERRQ(ierr);
2568 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lCsi, (
const Cmpnts***)&csi); CHKERRQ(ierr);
2569 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lEta, (
const Cmpnts***)&eta); CHKERRQ(ierr);
2570 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lZet, (
const Cmpnts***)&zet); CHKERRQ(ierr);
2571 ierr = DMDAVecRestoreArrayRead(user->
da, user->
lNvert, (
const PetscReal***)&nvert); CHKERRQ(ierr);
2574 PetscFunctionReturn(0);
2582 PetscFunctionBeginUser;
2586 if (self && self->
data) {
2588 PetscFree(self->
data);
2598 PetscFunctionReturn(0);
2628 PetscErrorCode ierr;
2629 PetscFunctionBeginUser;
2632 PetscCheck(bc, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"BoundaryCondition is NULL");
2636 ierr = PetscNew(&data); CHKERRQ(ierr);
2645 bc->
data = (
void*)data;
2661 PetscFunctionReturn(0);
2675 PetscErrorCode ierr;
2680 PetscFunctionBeginUser;
2687 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_USER_INPUT,
2688 "Configuration Error: Handler PERIODIC_DRIVEN_INITIAL_FLUX on Face %s must be applied to a face with mathematical_type PERIODIC.",
2705 PetscReal unused_flux;
2712 &unused_flux, &found); CHKERRQ(ierr);
2714 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_USER_INPUT,
2715 "Configuration Error: Handler PERIODIC_DRIVEN_INITIAL_FLUX on Face %s takes no 'target_flux' parameter; "
2716 "it measures the flux of the initial condition and holds that. Use handler 'constant_flux' to prescribe a target.",
2720 LOG_ALLOW(
GLOBAL,
LOG_INFO,
"Driven Flow (Dir %c): target volumetric flux will be latched from the initial state.\n",
2724 PetscBool trimfound;
2734 PetscFunctionReturn(0);
2748 PetscReal *local_inflow_contribution,
2749 PetscReal *local_outflow_contribution)
2751 PetscErrorCode ierr;
2755 PetscFunctionBeginUser;
2760 PetscReal boundaryFlux, planarAverageFlux;
2775 PetscFunctionReturn(0);
2779 &boundaryFlux, &planarAverageFlux); CHKERRQ(ierr);
2785 "Driven Flow (Dir %c): latched initial volumetric flux %.6e as the target.\n",
2794 local_inflow_contribution,
2795 local_outflow_contribution); CHKERRQ(ierr);
2798 PetscFunctionReturn(0);
static Cmpnts EvaluateMovingWallVelocity(const BoundaryCondition *self, BCFace face_id, PetscInt i, PetscInt j, PetscInt k, Cmpnts metric, PetscReal sign, Cmpnts interior)
A moving wall's boundary velocity: the source's, with any part along the face removed,...
PetscInt bracket_frame[2]
PetscBool enforceSeamFlux
static PetscInt PrescribedSlot(const InletPrescribedVelocityData *data, PetscInt i, PetscInt j, PetscInt k)
Index of the owned slot (i, j, k) in a prescribed-velocity inlet's per-slot arrays.
static PetscErrorCode Destroy_OutletConservation(BoundaryCondition *self)
Release the outlet-conservation handler's clip state.
static PetscErrorCode Apply_InletVelocity(BoundaryCondition *self, BCContext *ctx)
Applies the prescribed inlet velocity through the common face-layout path.
static PetscErrorCode Apply_WallNoSlip(BoundaryCondition *self, BCContext *ctx)
Apply no-slip velocity values to wall-adjacent cells for this boundary condition.
static PetscErrorCode OpenPrescribedProfile(InletPrescribedVelocityData *data, UserCtx *user, BCFace face_id)
Open the face's PICSLICE and read a lone frame, as the velocity itself or, under expressions,...
static PetscErrorCode ApplyFaceBoundaryVelocity(BoundaryCondition *self, BCContext *ctx, FaceBoundaryVelocityRule rule)
Sets a handler's boundary velocity and the face flux it implies on one face.
PetscBool isMasterController
static PetscErrorCode GetProfileFileExpectedDims(UserCtx *user, BCFace face_id, PetscInt *n1, PetscInt *n2)
Computes the expected PICSLICE dimensions for an inlet face.
PetscErrorCode Create_WallFreeSlip(BoundaryCondition *bc)
Implementation of Create_WallFreeSlip().
static PetscErrorCode Apply_WallFreeSlip(BoundaryCondition *self, BCContext *ctx)
Apply free-slip boundary values to wall-adjacent cells for this boundary condition.
static PetscErrorCode LoadPrescribedFrame(InletPrescribedVelocityData *data, PetscInt frame, Cmpnts *target)
Read one frame of the face's PICSLICE into this rank's slots, moving the file there.
static PetscErrorCode Apply_WallMoving(BoundaryCondition *self, BCContext *ctx)
Applies a moving wall's velocity through the path every prescribed face shares.
PicurvVelocitySource stress[2]
PetscErrorCode Create_WallMoving(BoundaryCondition *bc)
Implementation of Create_WallMoving().
PetscInt lastBulkCorrectionStep
static PetscErrorCode Apply_OutletConservation(BoundaryCondition *self, BCContext *ctx)
(Handler Action) Applies mass conservation correction to the outlet face.
PicurvSourceFaceSlots slots
PicurvVelocitySource source
static PetscErrorCode Initialize_InletPrescribedVelocity(BoundaryCondition *self, BCContext *ctx)
Compile the source named by the face's source_id parameter, with its bulk velocity or flow rate if an...
static PetscErrorCode PrescribedFaceSums(const InletPrescribedVelocityData *data, UserCtx *user, BCFace face_id, PetscReal local[4])
This rank's area-weighted sums over the face, physical: the source's normal speed,...
static PetscErrorCode Apply_PeriodicDrivenConstant(BoundaryCondition *self, BCContext *ctx)
Apply the configured constant driving term to the periodic boundary.
static PetscErrorCode StepInletFluctuation(InletPrescribedVelocityData *data, UserCtx *user, BCFace face_id)
This step's synthetic fluctuation at every owned slot of an inlet.
OutletClipPassMode
What one OutletClipPass() over the owned outlet elements does.
static Cmpnts EvaluateInletCartesianVelocity(const BoundaryCondition *self, BCFace face_id, PetscInt i, PetscInt j, PetscInt k, Cmpnts metric, PetscReal sign, Cmpnts interior)
Prescribed velocity at one inlet face slot, as a Cartesian vector.
static PetscErrorCode Initialize_PeriodicDrivenConstant(BoundaryCondition *self, BCContext *ctx)
Initialize constant forcing data for a periodically driven boundary.
PetscErrorCode Create_PeriodicGeometric(BoundaryCondition *bc)
Implementation of Create_PeriodicGeometric().
PetscErrorCode Validate_DrivenFlowConfiguration(UserCtx *user)
Implementation of Validate_DrivenFlowConfiguration().
static PetscErrorCode InterpolatePrescribedFrames(InletPrescribedVelocityData *data, BCFace face_id, PetscReal physical_time)
Set the staged data at a time: linear between the two frames around it, the first at t = 0.
Cmpnts(* FaceBoundaryVelocityRule)(const BoundaryCondition *self, BCFace face_id, PetscInt i, PetscInt j, PetscInt k, Cmpnts metric, PetscReal sign, Cmpnts interior)
Cartesian boundary velocity one handler prescribes at one boundary face slot.
#define INFLOW_LATTICE_PAD
Face cells the synthetic-inflow draw lattice extends beyond each edge; a filter half-width may not ex...
PetscReal fluct_length[2]
static PetscErrorCode PostStep_InletFlux(BoundaryCondition *self, BCContext *ctx, PetscReal *in, PetscReal *out)
Adds the inlet face's applied flux, the sum of its normal Ucont, to the inflow.
static PetscErrorCode Initialize_PeriodicDrivenInitial(BoundaryCondition *self, BCContext *ctx)
Initialize forcing data for a periodic boundary driven to its initial flux.
PetscErrorCode Create_PeriodicDrivenInitial(BoundaryCondition *bc)
Implementation of Create_PeriodicDrivenInitial().
static PetscErrorCode Destroy_PeriodicDrivenConstant(BoundaryCondition *self)
Release resources owned by the constant periodic-driving boundary.
PetscErrorCode Create_PeriodicDrivenConstant(BoundaryCondition *bc)
Implementation of Create_PeriodicDrivenConstant().
static PetscErrorCode ReadPicSliceFrame(InletPrescribedVelocityData *data)
Reads the frame at the file's position into file_values, validating every value: finite,...
static PetscErrorCode OpenPicSlice(InletPrescribedVelocityData *data, PetscInt expected_n1, PetscInt expected_n2)
Opens a canonical PICSLICE file and reads its header.
PetscErrorCode Create_InletPrescribedVelocity(BoundaryCondition *bc)
Implementation of Create_InletPrescribedVelocity().
static PetscErrorCode MeasureDrivenFluxes(UserCtx *user, char direction, PetscReal *boundaryFlux, PetscReal *planarAverageFlux)
Measure the two volumetric fluxes the driven-flow controller senses.
static PetscErrorCode Destroy_InletPrescribedVelocity(BoundaryCondition *self)
Release the compiled source and the per-slot arrays.
PetscErrorCode LogPrescribedFlowDiagnostics(UserCtx *user)
Implementation of LogPrescribedFlowDiagnostics().
static Cmpnts WallNoSlipVelocity(const BoundaryCondition *self, BCFace face_id, PetscInt i, PetscInt j, PetscInt k, Cmpnts metric, PetscReal sign, Cmpnts interior)
The no-slip wall's boundary velocity: the wall's own, which is at rest.
static PetscErrorCode PostStep_OutletConservation(BoundaryCondition *self, BCContext *ctx, PetscReal *in, PetscReal *out)
Update outlet-conservation state after a completed solver step.
static PetscErrorCode OutletClipPass(UserCtx *user, BCFace face_id, OutletConservationData *data, OutletClipPassMode mode, PetscReal correction, PetscReal psi, PetscReal sums[3])
One pass over this rank's elements of an outlet face for the backflow clip.
static Cmpnts WallFreeSlipVelocity(const BoundaryCondition *self, BCFace face_id, PetscInt i, PetscInt j, PetscInt k, Cmpnts metric, PetscReal sign, Cmpnts interior)
The free-slip wall's boundary velocity: the adjacent velocity, less its normal part.
static PetscErrorCode BuildInletFluctuation(InletPrescribedVelocityData *data, UserCtx *user)
Prepare an inlet's synthetic fluctuations once its slots exist: filter widths from the face's mean sp...
PetscErrorCode Create_WallNoSlip(BoundaryCondition *bc)
Implementation of Create_WallNoSlip().
static PetscErrorCode PrescribedBulkFactor(InletPrescribedVelocityData *data, UserCtx *user, BCFace face_id, PetscReal physical_time, PetscReal *factor)
Factor that makes the face's mean normal speed or flow rate equal the target.
static PetscErrorCode PreStep_PeriodicDrivenConstant(BoundaryCondition *self, BCContext *ctx, PetscReal *in, PetscReal *out)
Prepare constant periodic-driving data before the solver step.
static PetscErrorCode PreStep_OutletConservation(BoundaryCondition *self, BCContext *ctx, PetscReal *local_inflow_contribution, PetscReal *local_outflow_contribution)
Prepare the outlet-conservation correction before advancing the solver.
PetscErrorCode Create_OutletConservation(BoundaryCondition *bc)
Implementation of Create_OutletConservation().
static PetscErrorCode PreStep_InletPrescribedVelocity(BoundaryCondition *self, BCContext *ctx, PetscReal *in, PetscReal *out)
Refresh the inlet velocity once per step: gather the slots on the first call, then re-evaluate and re...
static PetscErrorCode PreStep_PeriodicDrivenInitial(BoundaryCondition *self, BCContext *ctx, PetscReal *in, PetscReal *out)
Latch the initial-state flux once, then drive to it like a constant target.
PetscReal targetVolumetricFlux
static PetscErrorCode OutletConservationClip(UserCtx *user, BCFace face_id, OutletConservationData *data, PetscReal correction, PetscBool *applied)
Run the backflow clip for one Apply call; see the section comment.
Private data structure shared by both periodic driven-flux handlers.
Private data of the prescribed-velocity inlet: a compiled source or a PICSLICE file,...
Per-face state of the backflow clip; see the section comment above.
PetscErrorCode GetBoundaryFaceElements(UserCtx *user, BCFace face_id, BoundaryFaceElements *elements)
The elements of a boundary face this rank owns, as index ranges.
PetscErrorCode CanRankServiceFace(const DMDALocalInfo *info, PetscInt IM_nodes_global, PetscInt JM_nodes_global, PetscInt KM_nodes_global, BCFace face_id, PetscBool *can_service_out)
Determines if the current MPI rank owns any part of a specified global face.
static Cmpnts RemoveFaceNormalComponent(Cmpnts velocity, Cmpnts metric)
velocity less its component along the face metric metric, which leaves it tangent to the face.
PetscErrorCode ComputeGridLineFractions(UserCtx *user, Vec fraction, Vec length)
Arc-length position of every owned cell centre along its three grid lines.
The expression language shared by every configured field, the keyed hashes its random draws and other...
PetscReal PicurvNormalFromHash(uint64_t hash)
A standard normal deviate from a hash: the first of PicurvNormalPairFromHash()'s pair.
BoundaryFaceElements elements
The owned face elements the slots are.
PicurvExpression * bulk
Target mean speed [m/s] in t, or NULL.
uint64_t PicurvDrawHash(PetscInt64 seed, PicurvDrawSpace space, uint64_t stream, PetscInt64 id, PetscInt64 salt)
Hash that keys a draw: a pure function of its arguments, so a draw does not depend on the rank that m...
PetscBool bulk_time_dependent
PetscErrorCode PicurvVelocitySourceEvaluate(const PicurvVelocitySource *source, const PetscReal *values, const PicurvExpressionDrawKey *key, const Cmpnts edges[3], Cmpnts *value)
Evaluate a source at one point.
@ PICURV_DRAW_SPACE_INFLOW
Synthetic inflow noise: stream per block and component, salt the step.
PetscErrorCode PicurvVelocitySourceCreate(const char *prefix, PetscBool on_face, PetscBool has_data, PetscBool allow_draws, PicurvVelocitySource *source)
Read and compile a velocity source from the options database.
@ PICURV_SOURCE_VAR_T
Physical time [s].
@ PICURV_SOURCE_VAR_Y
Physical y [m].
@ PICURV_SOURCE_VAR_X
Physical x of the point [m].
@ PICURV_SOURCE_VAR_Z
Physical z [m].
PetscErrorCode PicurvVelocitySourceDestroy(PicurvVelocitySource *source)
Free a source's compiled expressions and bulk velocity.
static PicurvExpressionDrawKey PicurvFaceDrawKey(PetscInt64 seed, PetscInt block, const PetscInt nodes[3], BCFace face, PetscInt p, PetscInt q, PetscInt64 step)
Draw key of a boundary face cell at one step, the key of a face source's draws.
PetscErrorCode PicurvVelocitySourceBulkFactor(const PicurvVelocitySource *source, PetscReal physical_time, const PetscReal local[3], const char *where, PetscReal *factor)
Factor on a source's expressions that makes a target's whole mean equal its bulk velocity.
PetscBool time_dependent
Some component reads t or draws, so a face re-evaluates it each step.
PetscErrorCode PicurvSourceFaceSlotsCreate(UserCtx *user, BCFace face_id, Vec fraction, Vec length, PicurvSourceFaceSlots *slots)
Gather each owned slot of a boundary face: face-centre position, the grid-line fractions and lengths ...
PetscReal(* values)[PICURV_SOURCE_VAR_COUNT]
Variables per slot; t is the caller's.
PetscErrorCode PicurvSourceFaceSlotsDestroy(PicurvSourceFaceSlots *slots)
Release what PicurvSourceFaceSlotsCreate() allocated.
Cmpnts(* edges)[3]
Directions per slot, for the curvilinear frame.
@ PICURV_SOURCE_FRAME_NORMAL
One value: the speed into the domain through a face.
@ PICURV_SOURCE_FRAME_CARTESIAN
Three values: x, y, z velocity components.
@ PICURV_SOURCE_FRAME_CURVILINEAR
Three values along the unit xi, eta, zeta grid-line directions.
PetscInt count
1 for the normal frame, otherwise 3; 0 for staged data alone.
What a random draw is keyed on, besides its stream.
What a source reads at each boundary-face slot this rank owns, gathered once.
A prescribed velocity, for any target: one compiled expression per value, the frame they are in,...
PetscErrorCode CalculateFaceCenterAndArea(UserCtx *user, BCFace face_id, Cmpnts *face_center, PetscReal *face_area)
Calculates the geometric center and total area of a specified boundary face.
PetscErrorCode GetBCParamReal(BC_Param *params, const char *key, PetscReal *value_out, PetscBool *found)
Searches a BC_Param linked list for a key and returns its value as a double.
PetscErrorCode GetDrivenSeamFluxFlag(BC_Param *params, PetscBool *value_out, PetscBool *found)
Read the driven-flow seam-flux flag, accepting its deprecated apply_trim spelling.
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.
PetscErrorCode GetBCParamBool(BC_Param *params, const char *key, PetscBool *value_out, PetscBool *found)
Searches a BC_Param linked list for a key and returns its value as a bool.
PetscErrorCode PicurvPhysicalTime(const SimCtx *simCtx, PetscReal solver_time, PetscReal *physical)
Convert a solver time to physical seconds, t * L_ref / U_ref.
#define LOCAL
Logging scope definitions for controlling message output.
#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 * BCTypeToString(BCType type)
Returns the canonical log token for a boundary mathematical type.
@ 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.
#define PROFILE_FUNCTION_BEGIN
Marks the beginning of a profiled function: an always-on aggregate timer.
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...
static void GetPeriodicAxes(const SimCtx *simCtx, PetscBool periodic[3])
Which grid axes are periodic.
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...
const PetscReal * global_outflow_sum
BCType
Defines the general mathematical/physical Category of a boundary.
BoundaryFaceConfig boundary_faces[6]
PetscReal targetVolumetricFlux
SimCtx * simCtx
Back-pointer to the master simulation context.
PetscReal boundaryVelocityCorrection
PetscBool inflowFluctuationsRestored
That state was read from the restart checkpoint.
BCHandlerType
Defines the specific computational "strategy" for a boundary handler.
@ BC_HANDLER_PERIODIC_DRIVEN_INITIAL_FLUX
@ BC_HANDLER_PERIODIC_DRIVEN_CONSTANT_FLUX
@ BC_HANDLER_INLET_PRESCRIBED_VELOCITY
BCHandlerType handler_type
PetscInt layer
Index along the normal of the face's metric and flux.
PetscInt normal
Logical axis of the face normal.
PetscBool drivenFluxTargetLatched
PetscReal bulkVelocityCorrection
Vec Ubcs
Physical Cartesian velocity at boundary faces. Full 3D array but only boundary-face entries are meani...
const PetscReal * global_inflow_sum
char analysis_dir[PETSC_MAX_PATH_LEN]
PetscReal drivenFluxMeasured
const PetscReal * global_farfield_inflow_sum
PetscInt n[2]
Owned elements along a and b; 0 when this rank does not serve the face.
PetscInt sourceRandomSeed
Seed of the draws in velocity and pressure sources (-source_random_seed).
PetscInt lo[2]
First owned indices along a and b.
PetscInt b
The two tangential axes, a < b.
Vec Uch
Characteristic velocity for boundary conditions.
BCFace
Identifies the six logical faces of a structured computational block.
BoundaryCondition * handler
Provides execution context for a boundary condition handler.
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.