10#define __FUNCT__ "Validate_DrivenFlowConfiguration"
17 PetscFunctionBeginUser;
20 PetscBool is_driven_flow_active = PETSC_FALSE;
21 char driven_direction =
' ';
22 const char* first_driven_face_name =
"";
24 for (
int i = 0; i < 6; i++) {
29 is_driven_flow_active = PETSC_TRUE;
32 if (i <= 1) driven_direction =
'X';
33 else if (i <= 3) driven_direction =
'Y';
34 else driven_direction =
'Z';
41 if (!is_driven_flow_active) {
42 PetscFunctionReturn(0);
45 LOG_ALLOW(
GLOBAL,
LOG_DEBUG,
" - Driven Flow Handler detected on face %s. Applying driven flow validation rules...\n", first_driven_face_name);
49 for (
int i = 0; i < 6; i++) {
52 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_USER_INPUT,
53 "Configuration Error: A DRIVEN flow handler is active, which is incompatible with the %s boundary condition found on face %s.",
60 LOG_ALLOW(
GLOBAL,
LOG_DEBUG,
" - Validating symmetry and mathematical types for the '%c' direction...\n", driven_direction);
62 PetscInt neg_face_idx = 0, pos_face_idx = 0;
63 if (driven_direction ==
'X') {
65 }
else if (driven_direction ==
'Y') {
76 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_USER_INPUT,
77 "Configuration Error: For a driven flow in the '%c' direction, both the %s and %s faces must be of mathematical_type PERIODIC.",
83 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_USER_INPUT,
84 "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).",
90 PetscFunctionReturn(0);
107#define __FUNCT__ "Create_WallNoSlip"
116 PetscFunctionBeginUser;
118 if (!bc) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
119 "Input BoundaryCondition object is NULL in Create_WallNoSlip");
135 PetscFunctionReturn(0);
139#define __FUNCT__ "Apply_WallNoSlip"
149 PetscBool can_service;
153 PetscFunctionBeginUser;
154 DMDALocalInfo *info = &user->
info;
156 PetscInt IM_nodes_global, JM_nodes_global,KM_nodes_global;
158 IM_nodes_global = user->
IM;
159 JM_nodes_global = user->
JM;
160 KM_nodes_global = user->
KM;
162 ierr =
CanRankServiceFace(info,IM_nodes_global,JM_nodes_global,KM_nodes_global,face_id,&can_service); CHKERRQ(ierr);
164 if (!can_service) PetscFunctionReturn(0);
171 ierr = DMDAVecGetArray(user->
fda, user->
Bcs.
Ubcs, &ubcs); CHKERRQ(ierr);
172 ierr = DMDAVecGetArray(user->
fda, user->
Ucont, &ucont); CHKERRQ(ierr);
174 PetscInt xs = info->xs, xe = info->xs + info->xm;
175 PetscInt ys = info->ys, ye = info->ys + info->ym;
176 PetscInt zs = info->zs, ze = info->zs + info->zm;
177 PetscInt mx = info->mx, my = info->my, mz = info->mz;
180 PetscInt lxs = xs, lxe = xe, lys = ys, lye = ye, lzs = zs, lze = ze;
181 if (xs == 0) lxs = xs + 1;
182 if (xe == mx) lxe = xe - 1;
183 if (ys == 0) lys = ys + 1;
184 if (ye == my) lye = ye - 1;
185 if (zs == 0) lzs = zs + 1;
186 if (ze == mz) lze = ze - 1;
192 for (PetscInt k = lzs; k < lze; k++) {
193 for (PetscInt j = lys; j < lye; j++) {
195 ucont[k][j][i].
x = 0.0;
198 ubcs[k][j][i].
x = 0.0;
199 ubcs[k][j][i].
y = 0.0;
200 ubcs[k][j][i].
z = 0.0;
210 for (PetscInt k = lzs; k < lze; k++) {
211 for (PetscInt j = lys; j < lye; j++) {
212 ucont[k][j][i-1].
x = 0.0;
214 ubcs[k][j][i].
x = 0.0;
215 ubcs[k][j][i].
y = 0.0;
216 ubcs[k][j][i].
z = 0.0;
225 for (PetscInt k = lzs; k < lze; k++) {
226 for (PetscInt i = lxs; i < lxe; i++) {
227 ucont[k][j][i].
y = 0.0;
229 ubcs[k][j][i].
x = 0.0;
230 ubcs[k][j][i].
y = 0.0;
231 ubcs[k][j][i].
z = 0.0;
240 for (PetscInt k = lzs; k < lze; k++) {
241 for (PetscInt i = lxs; i < lxe; i++) {
242 ucont[k][j-1][i].
y = 0.0;
244 ubcs[k][j][i].
x = 0.0;
245 ubcs[k][j][i].
y = 0.0;
246 ubcs[k][j][i].
z = 0.0;
255 for (PetscInt j = lys; j < lye; j++) {
256 for (PetscInt i = lxs; i < lxe; i++) {
257 ucont[k][j][i].
z = 0.0;
259 ubcs[k][j][i].
x = 0.0;
260 ubcs[k][j][i].
y = 0.0;
261 ubcs[k][j][i].
z = 0.0;
270 for (PetscInt j = lys; j < lye; j++) {
271 for (PetscInt i = lxs; i < lxe; i++) {
272 ucont[k-1][j][i].
z = 0.0;
274 ubcs[k][j][i].
x = 0.0;
275 ubcs[k][j][i].
y = 0.0;
276 ubcs[k][j][i].
z = 0.0;
284 ierr = DMDAVecRestoreArray(user->
fda, user->
Bcs.
Ubcs, &ubcs); CHKERRQ(ierr);
285 ierr = DMDAVecRestoreArray(user->
fda, user->
Ucont, &ucont); CHKERRQ(ierr);
287 PetscFunctionReturn(0);
302 PetscReal *in, PetscReal *out);
305 PetscReal *in, PetscReal *out);
316#define __FUNCT__ "Create_InletConstantVelocity"
326 PetscFunctionBeginUser;
328 if (!bc) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"BoundaryCondition is NULL");
331 ierr = PetscMalloc1(1, &data); CHKERRQ(ierr);
332 bc->
data = (
void*)data;
342 PetscFunctionReturn(0);
347#define __FUNCT__ "Initialize_InletConstantVelocity"
360 PetscFunctionBeginUser;
361 LOG_ALLOW(
LOCAL,
LOG_DEBUG,
"Initialize_InletConstantVelocity: Initializing handler for Face %d. \n", face_id);
393 PetscFunctionReturn(0);
397#define __FUNCT__ "PreStep_InletConstantVelocity"
403 PetscReal *local_inflow_contribution,
404 PetscReal *local_outflow_contribution)
412 (void)local_inflow_contribution;
413 (void)local_outflow_contribution;
415 PetscFunctionBeginUser;
416 PetscFunctionReturn(0);
420#define __FUNCT__ "Apply_InletConstantVelocity"
431 PetscBool can_service;
433 PetscFunctionBeginUser;
435 DMDALocalInfo *info = &user->
info;
436 Cmpnts ***ubcs, ***ucont, ***csi, ***eta, ***zet;
438 PetscInt IM_nodes_global, JM_nodes_global,KM_nodes_global;
440 IM_nodes_global = user->
IM;
441 JM_nodes_global = user->
JM;
442 KM_nodes_global = user->
KM;
444 ierr =
CanRankServiceFace(info,IM_nodes_global,JM_nodes_global,KM_nodes_global,face_id,&can_service); CHKERRQ(ierr);
446 if (!can_service) PetscFunctionReturn(0);
450 ierr = DMDAVecGetArray(user->
fda, user->
Bcs.
Ubcs, &ubcs); CHKERRQ(ierr);
451 ierr = DMDAVecGetArray(user->
fda, user->
Ucont, &ucont); CHKERRQ(ierr);
452 ierr = DMDAVecGetArrayRead(user->
fda, user->
lCsi, (
const Cmpnts***)&csi); CHKERRQ(ierr);
453 ierr = DMDAVecGetArrayRead(user->
fda, user->
lEta, (
const Cmpnts***)&eta); CHKERRQ(ierr);
454 ierr = DMDAVecGetArrayRead(user->
fda, user->
lZet, (
const Cmpnts***)&zet); CHKERRQ(ierr);
455 ierr = DMDAVecGetArrayRead(user->
da, user->
lNvert, (
const PetscReal***)&nvert); CHKERRQ(ierr);
460 PetscInt xs = info->xs, xe = info->xs + info->xm;
461 PetscInt ys = info->ys, ye = info->ys + info->ym;
462 PetscInt zs = info->zs, ze = info->zs + info->zm;
463 PetscInt mx = info->mx, my = info->my, mz = info->mz;
465 PetscInt lxs = xs, lxe = xe, lys = ys, lye = ye, lzs = zs, lze = ze;
466 if (xs == 0) lxs = xs + 1;
467 if (xe == mx) lxe = xe - 1;
468 if (ys == 0) lys = ys + 1;
469 if (ye == my) lye = ye - 1;
470 if (zs == 0) lzs = zs + 1;
471 if (ze == mz) lze = ze - 1;
479 for (PetscInt k = lzs; k < lze; k++) {
480 for (PetscInt j = lys; j < lye; j++) {
481 if ((sign > 0 && nvert[k][j][i+1] > 0.1) ||
482 (sign < 0 && nvert[k][j][i] > 0.1))
continue;
484 PetscReal CellArea = sqrt(csi[k][j][i].x * csi[k][j][i].x +
485 csi[k][j][i].y * csi[k][j][i].y +
486 csi[k][j][i].z * csi[k][j][i].z);
488 ucont[k][j][i].
x = sign * uin_this_point * CellArea;
490 ubcs[k][j][i + (sign < 0)].x = sign * uin_this_point * csi[k][j][i].x / CellArea;
491 ubcs[k][j][i + (sign < 0)].y = sign * uin_this_point * csi[k][j][i].y / CellArea;
492 ubcs[k][j][i + (sign < 0)].z = sign * uin_this_point * csi[k][j][i].z / CellArea;
502 for (PetscInt k = lzs; k < lze; k++) {
503 for (PetscInt i = lxs; i < lxe; i++) {
504 if ((sign > 0 && nvert[k][j+1][i] > 0.1) ||
505 (sign < 0 && nvert[k][j][i] > 0.1))
continue;
507 PetscReal CellArea = sqrt(eta[k][j][i].x * eta[k][j][i].x +
508 eta[k][j][i].y * eta[k][j][i].y +
509 eta[k][j][i].z * eta[k][j][i].z);
511 ucont[k][j][i].
y = sign * uin_this_point * CellArea;
513 ubcs[k][j + (sign < 0)][i].x = sign * uin_this_point * eta[k][j][i].x / CellArea;
514 ubcs[k][j + (sign < 0)][i].y = sign * uin_this_point * eta[k][j][i].y / CellArea;
515 ubcs[k][j + (sign < 0)][i].z = sign * uin_this_point * eta[k][j][i].z / CellArea;
525 for (PetscInt j = lys; j < lye; j++) {
526 for (PetscInt i = lxs; i < lxe; i++) {
527 if ((sign > 0 && nvert[k+1][j][i] > 0.1) ||
528 (sign < 0 && nvert[k][j][i] > 0.1))
continue;
530 PetscReal CellArea = sqrt(zet[k][j][i].x * zet[k][j][i].x +
531 zet[k][j][i].y * zet[k][j][i].y +
532 zet[k][j][i].z * zet[k][j][i].z);
534 ucont[k][j][i].
z = sign * uin_this_point * CellArea;
536 ubcs[k + (sign < 0)][j][i].x = sign * uin_this_point * zet[k][j][i].x / CellArea;
537 ubcs[k + (sign < 0)][j][i].y = sign * uin_this_point * zet[k][j][i].y / CellArea;
538 ubcs[k + (sign < 0)][j][i].z = sign * uin_this_point * zet[k][j][i].z / CellArea;
545 ierr = DMDAVecRestoreArray(user->
fda, user->
Bcs.
Ubcs, &ubcs); CHKERRQ(ierr);
546 ierr = DMDAVecRestoreArray(user->
fda, user->
Ucont, &ucont); CHKERRQ(ierr);
547 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lCsi, (
const Cmpnts***)&csi); CHKERRQ(ierr);
548 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lEta, (
const Cmpnts***)&eta); CHKERRQ(ierr);
549 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lZet, (
const Cmpnts***)&zet); CHKERRQ(ierr);
550 ierr = DMDAVecRestoreArrayRead(user->
da, user->
lNvert, (
const PetscReal***)&nvert); CHKERRQ(ierr);
552 PetscFunctionReturn(0);
556#define __FUNCT__ "PostStep_InletConstantVelocity"
562 PetscReal *local_inflow_contribution,
563 PetscReal *local_outflow_contribution)
568 PetscBool can_service;
571 (void)local_outflow_contribution;
573 PetscFunctionBeginUser;
575 DMDALocalInfo *info = &user->
info;
578 PetscInt IM_nodes_global, JM_nodes_global,KM_nodes_global;
580 IM_nodes_global = user->
IM;
581 JM_nodes_global = user->
JM;
582 KM_nodes_global = user->
KM;
584 ierr =
CanRankServiceFace(info,IM_nodes_global,JM_nodes_global,KM_nodes_global,face_id,&can_service); CHKERRQ(ierr);
587 if (!can_service) PetscFunctionReturn(0);
589 ierr = DMDAVecGetArrayRead(user->
fda, user->
Ucont, (
const Cmpnts***)&ucont); CHKERRQ(ierr);
591 PetscReal local_flux = 0.0;
593 PetscInt xs = info->xs, xe = info->xs + info->xm;
594 PetscInt ys = info->ys, ye = info->ys + info->ym;
595 PetscInt zs = info->zs, ze = info->zs + info->zm;
596 PetscInt mx = info->mx, my = info->my, mz = info->mz;
598 PetscInt lxs = xs, lxe = xe, lys = ys, lye = ye, lzs = zs, lze = ze;
599 if (xs == 0) lxs = xs + 1;
600 if (xe == mx) lxe = xe - 1;
601 if (ys == 0) lys = ys + 1;
602 if (ye == my) lye = ye - 1;
603 if (zs == 0) lzs = zs + 1;
604 if (ze == mz) lze = ze - 1;
611 for (PetscInt k = lzs; k < lze; k++) {
612 for (PetscInt j = lys; j < lye; j++) {
613 local_flux += ucont[k][j][i].
x;
621 for (PetscInt k = lzs; k < lze; k++) {
622 for (PetscInt i = lxs; i < lxe; i++) {
623 local_flux += ucont[k][j][i].
y;
631 for (PetscInt j = lys; j < lye; j++) {
632 for (PetscInt i = lxs; i < lxe; i++) {
633 local_flux += ucont[k][j][i].
z;
639 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
Ucont, (
const Cmpnts***)&ucont); CHKERRQ(ierr);
641 *local_inflow_contribution += local_flux;
644 face_id, local_flux);
646 PetscFunctionReturn(0);
651#define __FUNCT__ "Destroy_InletConstantVelocity"
658 PetscFunctionBeginUser;
659 if (self && self->
data) {
660 PetscFree(self->
data);
663 PetscFunctionReturn(0);
693 PetscReal *in, PetscReal *out);
696 PetscReal *in, PetscReal *out);
714#define __FUNCT__ "Create_InletParabolicProfile"
724 PetscFunctionBeginUser;
726 if (!bc) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"BoundaryCondition is NULL");
729 ierr = PetscMalloc1(1, &data); CHKERRQ(ierr);
730 bc->
data = (
void*)data;
740 PetscFunctionReturn(0);
745#define __FUNCT__ "Initialize_InletParabolicProfile"
758 PetscFunctionBeginUser;
764 &data->
v_max, &found); CHKERRQ(ierr);
766 LOG_ALLOW(
GLOBAL,
LOG_WARNING,
"Initialize_InletParabolicProfile: 'v_max' not found in params for face %d. Defaulting to 0.0.\n", face_id);
770 PetscReal cs1_dim, cs2_dim;
774 cs1_dim = (PetscReal)user->
JM;
775 cs2_dim = (PetscReal)user->
KM;
779 cs1_dim = (PetscReal)user->
IM;
780 cs2_dim = (PetscReal)user->
KM;
785 cs1_dim = (PetscReal)user->
IM;
786 cs2_dim = (PetscReal)user->
JM;
791 PetscReal cs1_width = cs1_dim - 2.0;
792 PetscReal cs2_width = cs2_dim - 2.0;
806 PetscFunctionReturn(0);
811#define __FUNCT__ "PreStep_InletParabolicProfile"
817 PetscReal *local_inflow_contribution,
818 PetscReal *local_outflow_contribution)
822 (void)local_inflow_contribution;
823 (void)local_outflow_contribution;
825 PetscFunctionBeginUser;
826 PetscFunctionReturn(0);
831#define __FUNCT__ "Apply_InletParabolicProfile"
842 PetscBool can_service;
844 PetscFunctionBeginUser;
846 DMDALocalInfo *info = &user->
info;
847 Cmpnts ***ubcs, ***ucont, ***csi, ***eta, ***zet;
849 PetscInt IM_nodes_global, JM_nodes_global, KM_nodes_global;
851 IM_nodes_global = user->
IM;
852 JM_nodes_global = user->
JM;
853 KM_nodes_global = user->
KM;
856 face_id, &can_service); CHKERRQ(ierr);
858 if (!can_service) PetscFunctionReturn(0);
861 ierr = DMDAVecGetArray(user->
fda, user->
Bcs.
Ubcs, &ubcs); CHKERRQ(ierr);
862 ierr = DMDAVecGetArray(user->
fda, user->
Ucont, &ucont); CHKERRQ(ierr);
863 ierr = DMDAVecGetArrayRead(user->
fda, user->
lCsi, (
const Cmpnts***)&csi); CHKERRQ(ierr);
864 ierr = DMDAVecGetArrayRead(user->
fda, user->
lEta, (
const Cmpnts***)&eta); CHKERRQ(ierr);
865 ierr = DMDAVecGetArrayRead(user->
fda, user->
lZet, (
const Cmpnts***)&zet); CHKERRQ(ierr);
866 ierr = DMDAVecGetArrayRead(user->
da, user->
lNvert, (
const PetscReal***)&nvert); CHKERRQ(ierr);
868 PetscInt xs = info->xs, xe = info->xs + info->xm;
869 PetscInt ys = info->ys, ye = info->ys + info->ym;
870 PetscInt zs = info->zs, ze = info->zs + info->zm;
871 PetscInt mx = info->mx, my = info->my, mz = info->mz;
873 PetscInt lxs = xs, lxe = xe, lys = ys, lye = ye, lzs = zs, lze = ze;
874 if (xs == 0) lxs = xs + 1;
875 if (xe == mx) lxe = xe - 1;
876 if (ys == 0) lys = ys + 1;
877 if (ye == my) lye = ye - 1;
878 if (zs == 0) lzs = zs + 1;
879 if (ze == mz) lze = ze - 1;
888 for (PetscInt k = lzs; k < lze; k++) {
889 for (PetscInt j = lys; j < lye; j++) {
890 if ((sign > 0 && nvert[k][j][i+1] > 0.1) ||
891 (sign < 0 && nvert[k][j][i] > 0.1))
continue;
896 PetscReal profile = PetscMax(0.0, 1.0 - cs1_norm * cs1_norm)
897 * PetscMax(0.0, 1.0 - cs2_norm * cs2_norm);
898 PetscReal uin_local = data->
v_max * profile;
900 PetscReal CellArea = sqrt(csi[k][j][i].x * csi[k][j][i].x +
901 csi[k][j][i].y * csi[k][j][i].y +
902 csi[k][j][i].z * csi[k][j][i].z);
904 ucont[k][j][i].
x = sign * uin_local * CellArea;
906 ubcs[k][j][i + (sign < 0)].x = sign * uin_local * csi[k][j][i].x / CellArea;
907 ubcs[k][j][i + (sign < 0)].y = sign * uin_local * csi[k][j][i].y / CellArea;
908 ubcs[k][j][i + (sign < 0)].z = sign * uin_local * csi[k][j][i].z / CellArea;
919 for (PetscInt k = lzs; k < lze; k++) {
920 for (PetscInt i = lxs; i < lxe; i++) {
921 if ((sign > 0 && nvert[k][j+1][i] > 0.1) ||
922 (sign < 0 && nvert[k][j][i] > 0.1))
continue;
927 PetscReal profile = PetscMax(0.0, 1.0 - cs1_norm * cs1_norm)
928 * PetscMax(0.0, 1.0 - cs2_norm * cs2_norm);
929 PetscReal uin_local = data->
v_max * profile;
931 PetscReal CellArea = sqrt(eta[k][j][i].x * eta[k][j][i].x +
932 eta[k][j][i].y * eta[k][j][i].y +
933 eta[k][j][i].z * eta[k][j][i].z);
935 ucont[k][j][i].
y = sign * uin_local * CellArea;
937 ubcs[k][j + (sign < 0)][i].x = sign * uin_local * eta[k][j][i].x / CellArea;
938 ubcs[k][j + (sign < 0)][i].y = sign * uin_local * eta[k][j][i].y / CellArea;
939 ubcs[k][j + (sign < 0)][i].z = sign * uin_local * eta[k][j][i].z / CellArea;
950 for (PetscInt j = lys; j < lye; j++) {
951 for (PetscInt i = lxs; i < lxe; i++) {
952 if ((sign > 0 && nvert[k+1][j][i] > 0.1) ||
953 (sign < 0 && nvert[k][j][i] > 0.1))
continue;
958 PetscReal profile = PetscMax(0.0, 1.0 - cs1_norm * cs1_norm)
959 * PetscMax(0.0, 1.0 - cs2_norm * cs2_norm);
960 PetscReal uin_local = data->
v_max * profile;
962 PetscReal CellArea = sqrt(zet[k][j][i].x * zet[k][j][i].x +
963 zet[k][j][i].y * zet[k][j][i].y +
964 zet[k][j][i].z * zet[k][j][i].z);
966 ucont[k][j][i].
z = sign * uin_local * CellArea;
968 ubcs[k + (sign < 0)][j][i].x = sign * uin_local * zet[k][j][i].x / CellArea;
969 ubcs[k + (sign < 0)][j][i].y = sign * uin_local * zet[k][j][i].y / CellArea;
970 ubcs[k + (sign < 0)][j][i].z = sign * uin_local * zet[k][j][i].z / CellArea;
977 ierr = DMDAVecRestoreArray(user->
fda, user->
Bcs.
Ubcs, &ubcs); CHKERRQ(ierr);
978 ierr = DMDAVecRestoreArray(user->
fda, user->
Ucont, &ucont); CHKERRQ(ierr);
979 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lCsi, (
const Cmpnts***)&csi); CHKERRQ(ierr);
980 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lEta, (
const Cmpnts***)&eta); CHKERRQ(ierr);
981 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lZet, (
const Cmpnts***)&zet); CHKERRQ(ierr);
982 ierr = DMDAVecRestoreArrayRead(user->
da, user->
lNvert, (
const PetscReal***)&nvert); CHKERRQ(ierr);
984 PetscFunctionReturn(0);
989#define __FUNCT__ "PostStep_InletParabolicProfile"
995 PetscReal *local_inflow_contribution,
996 PetscReal *local_outflow_contribution)
1001 PetscBool can_service;
1004 (void)local_outflow_contribution;
1006 PetscFunctionBeginUser;
1008 DMDALocalInfo *info = &user->
info;
1011 PetscInt IM_nodes_global, JM_nodes_global, KM_nodes_global;
1013 IM_nodes_global = user->
IM;
1014 JM_nodes_global = user->
JM;
1015 KM_nodes_global = user->
KM;
1018 face_id, &can_service); CHKERRQ(ierr);
1020 if (!can_service) PetscFunctionReturn(0);
1022 ierr = DMDAVecGetArrayRead(user->
fda, user->
Ucont, (
const Cmpnts***)&ucont); CHKERRQ(ierr);
1024 PetscReal local_flux = 0.0;
1026 PetscInt xs = info->xs, xe = info->xs + info->xm;
1027 PetscInt ys = info->ys, ye = info->ys + info->ym;
1028 PetscInt zs = info->zs, ze = info->zs + info->zm;
1029 PetscInt mx = info->mx, my = info->my, mz = info->mz;
1031 PetscInt lxs = xs, lxe = xe, lys = ys, lye = ye, lzs = zs, lze = ze;
1032 if (xs == 0) lxs = xs + 1;
1033 if (xe == mx) lxe = xe - 1;
1034 if (ys == 0) lys = ys + 1;
1035 if (ye == my) lye = ye - 1;
1036 if (zs == 0) lzs = zs + 1;
1037 if (ze == mz) lze = ze - 1;
1043 for (PetscInt k = lzs; k < lze; k++) {
1044 for (PetscInt j = lys; j < lye; j++) {
1045 local_flux += ucont[k][j][i].
x;
1053 for (PetscInt k = lzs; k < lze; k++) {
1054 for (PetscInt i = lxs; i < lxe; i++) {
1055 local_flux += ucont[k][j][i].
y;
1063 for (PetscInt j = lys; j < lye; j++) {
1064 for (PetscInt i = lxs; i < lxe; i++) {
1065 local_flux += ucont[k][j][i].
z;
1071 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
Ucont, (
const Cmpnts***)&ucont); CHKERRQ(ierr);
1073 *local_inflow_contribution += local_flux;
1076 face_id, local_flux);
1078 PetscFunctionReturn(0);
1083#define __FUNCT__ "Destroy_InletParabolicProfile"
1090 PetscFunctionBeginUser;
1091 if (self && self->
data) {
1092 PetscFree(self->
data);
1095 PetscFunctionReturn(0);
1116 PetscReal *local_inflow_contribution, PetscReal *local_outflow_contribution);
1119 PetscReal *in, PetscReal *out);
1122#define __FUNCT__ "Create_OutletConservation"
1131 PetscFunctionBeginUser;
1133 if (!bc) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"Input BoundaryCondition is NULL");
1149 PetscFunctionReturn(0);
1153#define __FUNCT__ "PreStep_OutletConservation"
1159 PetscReal *local_inflow_contribution, PetscReal *local_outflow_contribution)
1161 PetscErrorCode ierr;
1164 DMDALocalInfo* info = &user->
info;
1165 PetscBool can_service;
1169 (void)local_inflow_contribution;
1171 PetscFunctionBeginUser;
1175 const PetscInt IM_nodes_global = user->
IM;
1176 const PetscInt JM_nodes_global = user->
JM;
1177 const PetscInt KM_nodes_global = user->
KM;
1178 ierr =
CanRankServiceFace(info, IM_nodes_global, JM_nodes_global, KM_nodes_global, face_id, &can_service); CHKERRQ(ierr);
1181 PetscFunctionReturn(0);
1187 Cmpnts ***ucat, ***csi, ***eta, ***zet;
1189 ierr = DMDAVecGetArrayRead(user->
fda, user->
lUcat, (
const Cmpnts***)&ucat); CHKERRQ(ierr);
1190 ierr = DMDAVecGetArrayRead(user->
da, user->
lNvert, (
const PetscReal***)&nvert); CHKERRQ(ierr);
1191 ierr = DMDAVecGetArrayRead(user->
fda, user->
lCsi, (
const Cmpnts***)&csi); CHKERRQ(ierr);
1192 ierr = DMDAVecGetArrayRead(user->
fda, user->
lEta, (
const Cmpnts***)&eta); CHKERRQ(ierr);
1193 ierr = DMDAVecGetArrayRead(user->
fda, user->
lZet, (
const Cmpnts***)&zet); CHKERRQ(ierr);
1195 PetscReal local_flux_out = 0.0;
1196 const PetscInt xs=info->xs, xe=info->xs+info->xm;
1197 const PetscInt ys=info->ys, ye=info->ys+info->ym;
1198 const PetscInt zs=info->zs, ze=info->zs+info->zm;
1199 const PetscInt mx=info->mx, my=info->my, mz=info->mz;
1202 PetscInt lxs = xs;
if (xs == 0) lxs = xs + 1;
1203 PetscInt lxe = xe;
if (xe == mx) lxe = xe - 1;
1204 PetscInt lys = ys;
if (ys == 0) lys = ys + 1;
1205 PetscInt lye = ye;
if (ye == my) lye = ye - 1;
1206 PetscInt lzs = zs;
if (zs == 0) lzs = zs + 1;
1207 PetscInt lze = ze;
if (ze == mz) lze = ze - 1;
1212 const PetscInt i_cell = xs + 1;
1213 const PetscInt i_face = xs;
1214 for (
int k=lzs; k<lze; k++)
for (
int j=lys; j<lye; j++) {
1215 if (nvert[k][j][i_cell] < 0.1) {
1216 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);
1222 const PetscInt i_cell = xe - 2;
1223 const PetscInt i_face = xe - 2;
1224 for (
int k=lzs; k<lze; k++)
for (
int j=lys; j<lye; j++) {
1225 if (nvert[k][j][i_cell] < 0.1) {
1226 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);
1232 const PetscInt j_cell = ys + 1;
1233 const PetscInt j_face = ys;
1234 for (
int k=lzs; k<lze; k++)
for (
int i=lxs; i<lxe; i++) {
1235 if (nvert[k][j_cell][i] < 0.1) {
1236 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);
1242 const PetscInt j_cell = ye - 2;
1243 const PetscInt j_face = ye - 2;
1244 for (
int k=lzs; k<lze; k++)
for (
int i=lxs; i<lxe; i++) {
1245 if (nvert[k][j_cell][i] < 0.1) {
1246 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);
1252 const PetscInt k_cell = zs + 1;
1253 const PetscInt k_face = zs;
1254 for (
int j=lys; j<lye; j++)
for (
int i=lxs; i<lxe; i++) {
1255 if (nvert[k_cell][j][i] < 0.1) {
1256 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);
1262 const PetscInt k_cell = ze - 2;
1263 const PetscInt k_face = ze - 2;
1264 for (
int j=lys; j<lye; j++)
for (
int i=lxs; i<lxe; i++) {
1265 if (nvert[k_cell][j][i] < 0.1) {
1266 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);
1274 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lUcat, (
const Cmpnts***)&ucat); CHKERRQ(ierr);
1275 ierr = DMDAVecRestoreArrayRead(user->
da, user->
lNvert, (
const PetscReal***)&nvert); CHKERRQ(ierr);
1276 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lCsi, (
const Cmpnts***)&csi); CHKERRQ(ierr);
1277 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lEta, (
const Cmpnts***)&eta); CHKERRQ(ierr);
1278 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lZet, (
const Cmpnts***)&zet); CHKERRQ(ierr);
1281 *local_outflow_contribution += local_flux_out;
1283 PetscFunctionReturn(0);
1287#define __FUNCT__ "Apply_OutletConservation"
1296 PetscErrorCode ierr;
1300 DMDALocalInfo* info = &user->
info;
1301 PetscBool can_service;
1303 PetscFunctionBeginUser;
1306 const PetscInt IM_nodes_global = user->
IM;
1307 const PetscInt JM_nodes_global = user->
JM;
1308 const PetscInt KM_nodes_global = user->
KM;
1309 ierr =
CanRankServiceFace(info, IM_nodes_global, JM_nodes_global, KM_nodes_global, face_id, &can_service); CHKERRQ(ierr);
1313 PetscFunctionReturn(0);
1321 PetscReal velocity_correction = (PetscAbsReal(user->
simCtx->
AreaOutSum) > 1e-12)
1332 Cmpnts ***ubcs, ***ucont, ***csi, ***eta, ***zet, ***ucat;
1334 ierr = DMDAVecGetArray(user->
fda, user->
Bcs.
Ubcs, &ubcs); CHKERRQ(ierr);
1335 ierr = DMDAVecGetArray(user->
fda, user->
Ucont, &ucont); CHKERRQ(ierr);
1336 ierr = DMDAVecGetArrayRead(user->
fda,user->
lUcat, (
const Cmpnts***)&ucat); CHKERRQ(ierr);
1337 ierr = DMDAVecGetArrayRead(user->
fda, user->
lCsi, (
const Cmpnts***)&csi); CHKERRQ(ierr);
1338 ierr = DMDAVecGetArrayRead(user->
fda, user->
lEta, (
const Cmpnts***)&eta); CHKERRQ(ierr);
1339 ierr = DMDAVecGetArrayRead(user->
fda, user->
lZet, (
const Cmpnts***)&zet); CHKERRQ(ierr);
1340 ierr = DMDAVecGetArrayRead(user->
da, user->
lNvert, (
const PetscReal***)&nvert); CHKERRQ(ierr);
1343 PetscInt xs = info->xs, xe = info->xs + info->xm;
1344 PetscInt ys = info->ys, ye = info->ys + info->ym;
1345 PetscInt zs = info->zs, ze = info->zs + info->zm;
1346 PetscInt mx = info->mx, my = info->my, mz = info->mz;
1347 PetscInt lxs = xs, lxe = xe, lys = ys, lye = ye, lzs = zs, lze = ze;
1349 if (xs == 0) lxs = xs + 1;
1350 if (xe == mx) lxe = xe - 1;
1351 if (ys == 0) lys = ys + 1;
1352 if (ye == my) lye = ye - 1;
1353 if (zs == 0) lzs = zs + 1;
1354 if (ze == mz) lze = ze - 1;
1359 const PetscInt i_cell = xs + 1;
1360 const PetscInt i_face = xs;
1361 const PetscInt i_dummy = xs;
1362 for (PetscInt k = lzs; k < lze; k++) {
1363 for (PetscInt j = lys; j < lye; j++) {
1364 if (nvert[k][j][i_cell] < 0.1) {
1366 ubcs[k][j][i_dummy] = ucat[k][j][i_cell];
1369 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);
1371 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));
1373 PetscReal Correction_flux = velocity_correction*Cell_Area;
1375 ucont[k][j][i_face].
x = Uncorrected_local_flux + Correction_flux;
1382 const PetscInt i_cell = xe - 2;
1383 const PetscInt i_face = xe - 2;
1384 const PetscInt i_dummy = xe - 1;
1385 for(PetscInt k = lzs; k < lze; k++)
for (PetscInt j = lys; j < lye; j++){
1386 if(nvert[k][j][i_cell]<0.1){
1388 ubcs[k][j][i_dummy] = ucat[k][j][i_cell];
1391 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);
1393 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));
1395 PetscReal Correction_flux = velocity_correction*Cell_Area;
1397 ucont[k][j][i_face].
x = Uncorrected_local_flux + Correction_flux;
1403 const PetscInt j_cell = ys + 1;
1404 const PetscInt j_face = ys;
1405 const PetscInt j_dummy = ys;
1406 for(PetscInt k = lzs; k < lze; k++)
for (PetscInt i = lxs; i < lxe; i++){
1407 if(nvert[k][j_cell][i]<0.1){
1409 ubcs[k][j_dummy][i] = ucat[k][j_cell][i];
1412 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);
1414 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));
1416 PetscReal Correction_flux = velocity_correction*Cell_Area;
1418 ucont[k][j_face][i].
y = Uncorrected_local_flux + Correction_flux;
1424 const PetscInt j_cell = ye - 2;
1425 const PetscInt j_face = ye - 2;
1426 const PetscInt j_dummy = ye - 1;
1427 for(PetscInt k = lzs; k < lze; k++)
for (PetscInt i = lxs; i < lxe; i++){
1428 if(nvert[k][j_cell][i]<0.1){
1430 ubcs[k][j_dummy][i] = ucat[k][j_cell][i];
1433 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);
1435 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));
1437 PetscReal Correction_flux = velocity_correction*Cell_Area;
1439 ucont[k][j_face][i].
y = Uncorrected_local_flux + Correction_flux;
1445 const PetscInt k_cell = zs + 1;
1446 const PetscInt k_face = zs;
1447 const PetscInt k_dummy = zs;
1448 for(PetscInt j = lys; j < lye; j++)
for (PetscInt i = lxs; i < lxe; i++){
1449 if(nvert[k_cell][j][i]<0.1){
1451 ubcs[k_dummy][j][i] = ucat[k_cell][j][i];
1454 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));
1456 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));
1458 PetscReal Correction_flux = velocity_correction*Cell_Area;
1460 ucont[k_face][j][i].
z = Uncorrected_local_flux + Correction_flux;
1466 const PetscInt k_cell = ze - 2;
1467 const PetscInt k_face = ze - 2;
1468 const PetscInt k_dummy = ze - 1;
1469 for(PetscInt j = lys; j < lye; j++)
for (PetscInt i = lxs; i < lxe; i++){
1470 if(nvert[k_cell][j][i]<0.1){
1472 ubcs[k_dummy][j][i] = ucat[k_cell][j][i];
1475 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));
1477 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));
1479 PetscReal Correction_flux = velocity_correction*Cell_Area;
1481 ucont[k_face][j][i].
z = Uncorrected_local_flux + Correction_flux;
1489 ierr = DMDAVecRestoreArray(user->
fda, user->
Bcs.
Ubcs, &ubcs); CHKERRQ(ierr);
1490 ierr = DMDAVecRestoreArray(user->
fda, user->
Ucont, &ucont); CHKERRQ(ierr);
1491 ierr = DMDAVecRestoreArrayRead(user->
fda,user->
lUcat, (
const Cmpnts***)&ucat); CHKERRQ(ierr);
1492 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lCsi, (
const Cmpnts***)&csi); CHKERRQ(ierr);
1493 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lEta, (
const Cmpnts***)&eta); CHKERRQ(ierr);
1494 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lZet, (
const Cmpnts***)&zet); CHKERRQ(ierr);
1495 ierr = DMDAVecRestoreArrayRead(user->
da, user->
lNvert, (
const PetscReal***)&nvert); CHKERRQ(ierr);
1498 PetscFunctionReturn(0);
1502#define __FUNCT__ "PostStep_OutletConservation"
1508 PetscReal *local_inflow_contribution,
1509 PetscReal *local_outflow_contribution)
1511 PetscErrorCode ierr;
1514 DMDALocalInfo* info = &user->
info;
1515 PetscBool can_service;
1518 (void)local_inflow_contribution;
1520 PetscFunctionBeginUser;
1521 const PetscInt IM_nodes_global = user->
IM;
1522 const PetscInt JM_nodes_global = user->
JM;
1523 const PetscInt KM_nodes_global = user->
KM;
1524 ierr =
CanRankServiceFace(info, IM_nodes_global, JM_nodes_global, KM_nodes_global, face_id, &can_service); CHKERRQ(ierr);
1526 if (!can_service) PetscFunctionReturn(0);
1532 ierr = DMDAVecGetArrayRead(user->
fda, user->
Ucont, (
const Cmpnts***)&ucont); CHKERRQ(ierr);
1533 ierr = DMDAVecGetArrayRead(user->
da, user->
lNvert, (
const PetscReal***)&nvert); CHKERRQ(ierr);
1535 PetscReal local_flux = 0.0;
1537 PetscInt xs = info->xs, xe = info->xs + info->xm;
1538 PetscInt ys = info->ys, ye = info->ys + info->ym;
1539 PetscInt zs = info->zs, ze = info->zs + info->zm;
1540 PetscInt mx = info->mx, my = info->my, mz = info->mz;
1542 PetscInt lxs = xs, lxe = xe, lys = ys, lye = ye, lzs = zs, lze = ze;
1543 if (xs == 0) lxs = xs + 1;
1544 if (xe == mx) lxe = xe - 1;
1545 if (ys == 0) lys = ys + 1;
1546 if (ye == my) lye = ye - 1;
1547 if (zs == 0) lzs = zs + 1;
1548 if (ze == mz) lze = ze - 1;
1553 const PetscInt i_cell = xs + 1;
1554 const PetscInt i_face = xs;
1555 for (PetscInt k = lzs; k < lze; k++) {
1556 for (PetscInt j = lys; j < lye; j++) {
1557 if (nvert[k][j][i_cell] < 0.1) {
1558 local_flux += ucont[k][j][i_face].
x;
1565 const PetscInt i_cell = xe - 2;
1566 const PetscInt i_face = xe - 2;
1567 for (PetscInt k = lzs; k < lze; k++) {
1568 for (PetscInt j = lys; j < lye; j++) {
1569 if (nvert[k][j][i_cell] < 0.1) {
1570 local_flux += ucont[k][j][i_face].
x;
1577 const PetscInt j_cell = ys + 1;
1578 const PetscInt j_face = ys;
1579 for (PetscInt k = lzs; k < lze; k++) {
1580 for (PetscInt i = lxs; i < lxe; i++) {
1581 if (nvert[k][j_cell][i] < 0.1) {
1582 local_flux += ucont[k][j_face][i].
y;
1589 const PetscInt j_cell = ye - 2;
1590 const PetscInt j_face = ye - 2;
1591 for (PetscInt k = lzs; k < lze; k++) {
1592 for (PetscInt i = lxs; i < lxe; i++) {
1593 if (nvert[k][j_cell][i] < 0.1) {
1594 local_flux += ucont[k][j_face][i].
y;
1601 const PetscInt k_cell = zs + 1;
1602 const PetscInt k_face = zs;
1603 for (PetscInt j = lys; j < lye; j++) {
1604 for (PetscInt i = lxs; i < lxe; i++) {
1605 if (nvert[k_cell][j][i] < 0.1) {
1606 local_flux += ucont[k_face][j][i].
z;
1613 const PetscInt k_cell = ze - 2;
1614 const PetscInt k_face = ze - 2;
1615 for (PetscInt j = lys; j < lye; j++) {
1616 for (PetscInt i = lxs; i < lxe; i++) {
1617 if (nvert[k_cell][j][i] < 0.1) {
1618 local_flux += ucont[k_face][j][i].
z;
1626 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
Ucont, (
const Cmpnts***)&ucont); CHKERRQ(ierr);
1627 ierr = DMDAVecRestoreArrayRead(user->
da, user->
lNvert, (
const PetscReal***)&nvert); CHKERRQ(ierr);
1630 *local_outflow_contribution += local_flux;
1633 face_id, local_flux);
1635 PetscFunctionReturn(0);
1647 PetscFunctionBeginUser;
1649 if (!bc) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"Input BoundaryCondition is NULL");
1662 PetscFunctionReturn(0);
1694#define __FUNCT__ "Create_PeriodicDrivenConstant"
1701 PetscErrorCode ierr;
1702 PetscFunctionBeginUser;
1704 if (!bc) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"Input BoundaryCondition object is NULL in Create_PeriodicDrivenConstantFlux");
1708 ierr = PetscNew(&data); CHKERRQ(ierr);
1717 bc->
data = (
void*)data;
1734 PetscFunctionReturn(0);
1738#define __FUNCT__ "Initialize_PeriodicDrivenConstant"
1745 PetscErrorCode ierr;
1750 PetscFunctionBeginUser;
1756 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_USER_INPUT,
1757 "Configuration Error: Handler PERIODIC_DRIVEN_CONSTANT_FLUX on Face %s must be applied to a face with mathematical_type PERIODIC.",
1782 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_USER_INPUT,
1783 "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).",
1795 PetscBool trimfound;
1802 PetscFunctionReturn(0);
1806#define __FUNCT__ "PreStep_PeriodicDrivenConstant"
1812 PetscReal *local_inflow_contribution,
1813 PetscReal *local_outflow_contribution)
1815 PetscErrorCode ierr;
1820 PetscFunctionBeginUser;
1824 PetscFunctionReturn(0);
1829 DMDALocalInfo info = user->
info;
1835 ierr = DMDAVecGetArrayRead(user->
fda, user->
lUcont, (
const Cmpnts***)&ucont); CHKERRQ(ierr);
1836 ierr = DMDAVecGetArrayRead(user->
da, user->
lNvert, (
const PetscReal***)&nvert); CHKERRQ(ierr);
1839 PetscInt lxs = (info.xs == 0) ? 1 : info.xs;
1840 PetscInt lys = (info.ys == 0) ? 1 : info.ys;
1841 PetscInt lzs = (info.zs == 0) ? 1 : info.zs;
1842 PetscInt lxe = (info.xs + info.xm == info.mx) ? info.mx - 1 : info.xs + info.xm;
1843 PetscInt lye = (info.ys + info.ym == info.my) ? info.my - 1 : info.ys + info.ym;
1844 PetscInt lze = (info.zs + info.zm == info.mz) ? info.mz - 1 : info.zs + info.zm;
1900 PetscReal localCurrentBoundaryFlux = 0.0;
1901 PetscReal localAveragePlanarVolumetricFluxTerm = 0.0;
1904 switch (direction) {
1908 for (k = lzs; k < lze; k++)
for (j = lys; j < lye; j++) {
1909 if (nvert[k][j][i + 1] < 0.1) localCurrentBoundaryFlux += ucont[k][j][i].
x;
1912 for (i = info.xs; i < lxe; i++) {
1913 for (k = lzs; k < lze; k++)
for (j = lys; j < lye; j++) {
1914 if (nvert[k][j][i + 1] < 0.1) localAveragePlanarVolumetricFluxTerm += ucont[k][j][i].
x / (PetscReal)(info.mx - 1);
1921 for (k = lzs; k < lze; k++)
for (i = lxs; i < lxe; i++) {
1922 if (nvert[k][j + 1][i] < 0.1) localCurrentBoundaryFlux += ucont[k][j][i].
y;
1925 for (j = info.ys; j < lye; j++) {
1926 for (k = lzs; k < lze; k++)
for (i = lxs; i < lxe; i++) {
1927 if (nvert[k][j + 1][i] < 0.1) localAveragePlanarVolumetricFluxTerm += ucont[k][j][i].
y / (PetscReal)(info.my - 1);
1934 for (j = lys; j < lye; j++)
for (i = lxs; i < lxe; i++) {
1935 if (nvert[k + 1][j][i] < 0.1) localCurrentBoundaryFlux += ucont[k][j][i].
z;
1938 for (k = info.zs; k < lze; k++) {
1939 for (j = lys; j < lye; j++)
for (i = lxs; i < lxe; i++) {
1940 if (nvert[k + 1][j][i] < 0.1) localAveragePlanarVolumetricFluxTerm += ucont[k][j][i].
z / (PetscReal)(info.mz - 1);
1947 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lUcont, (
const Cmpnts***)&ucont); CHKERRQ(ierr);
1948 ierr = DMDAVecRestoreArrayRead(user->
da, user->
lNvert, (
const PetscReal***)&nvert); CHKERRQ(ierr);
1952 PetscReal globalBoundaryArea;
1957 PetscReal globalCurrentBoundaryFlux, globalAveragePlanarVolumetricFlux;
1958 ierr = MPI_Allreduce(&localCurrentBoundaryFlux, &globalCurrentBoundaryFlux, 1, MPI_DOUBLE, MPI_SUM, PETSC_COMM_WORLD); CHKERRQ(ierr);
1959 ierr = MPI_Allreduce(&localAveragePlanarVolumetricFluxTerm, &globalAveragePlanarVolumetricFlux, 1, MPI_DOUBLE, MPI_SUM, PETSC_COMM_WORLD); CHKERRQ(ierr);
1962 if (globalBoundaryArea > 1.0e-12) {
1975 LOG_ALLOW(
GLOBAL,
LOG_INFO,
" - Avg Planar Volumetric Flux (Stable): %.6e\n", globalAveragePlanarVolumetricFlux);
1981 (void)local_inflow_contribution;
1982 (void)local_outflow_contribution;
1984 PetscFunctionReturn(0);
1988#define __FUNCT__ "Apply_PeriodicDrivenConstant"
1995 PetscErrorCode ierr;
1999 PetscBool can_service;
2001 PetscFunctionBeginUser;
2006 PetscFunctionReturn(0);
2011 PetscFunctionReturn(0);
2017 DMDALocalInfo info = user->
info;
2018 Cmpnts ***ucont, ***uch, ***csi, ***eta, ***zet;
2021 ierr = DMDAVecGetArray(user->
fda, user->
lUcont, &ucont); CHKERRQ(ierr);
2022 ierr = DMDAVecGetArray(user->
fda, user->
Bcs.
Uch, &uch); CHKERRQ(ierr);
2023 ierr = DMDAVecGetArrayRead(user->
fda, user->
lCsi, (
const Cmpnts***)&csi); CHKERRQ(ierr);
2024 ierr = DMDAVecGetArrayRead(user->
fda, user->
lEta, (
const Cmpnts***)&eta); CHKERRQ(ierr);
2025 ierr = DMDAVecGetArrayRead(user->
fda, user->
lZet, (
const Cmpnts***)&zet); CHKERRQ(ierr);
2026 ierr = DMDAVecGetArrayRead(user->
da, user->
lNvert, (
const PetscReal***)&nvert); CHKERRQ(ierr);
2028 PetscInt lxs = (info.xs == 0) ? 1 : info.xs;
2029 PetscInt lys = (info.ys == 0) ? 1 : info.ys;
2030 PetscInt lzs = (info.zs == 0) ? 1 : info.zs;
2031 PetscInt lxe = (info.xs + info.xm == info.mx) ? info.mx - 1 : info.xs + info.xm;
2032 PetscInt lye = (info.ys + info.ym == info.my) ? info.my - 1 : info.ys + info.ym;
2033 PetscInt lze = (info.zs + info.zm == info.mz) ? info.mz - 1 : info.zs + info.zm;
2038 PetscInt i_face = (face_id ==
BC_FACE_NEG_X) ? info.xs : info.mx - 2;
2039 PetscInt i_nvert = (face_id ==
BC_FACE_NEG_X) ? info.xs + 1 : info.mx - 2;
2041 for (PetscInt k = lzs; k < lze; k++)
for (PetscInt j = lys; j < lye; j++) {
2042 if (nvert[k][j][i_nvert] < 0.1) {
2043 PetscReal faceArea = sqrt(csi[k][j][i_face].x*csi[k][j][i_nvert].x + csi[k][j][i_nvert].y*csi[k][j][i_nvert].y + csi[k][j][i_face].z*csi[k][j][i_face].z);
2046 uch[k][j][i_face].
x = fluxTrim;
2052 PetscInt j_face = (face_id ==
BC_FACE_NEG_Y) ? info.ys : info.my - 2;
2053 PetscInt j_nvert = (face_id ==
BC_FACE_NEG_Y) ? info.ys + 1 : info.my - 2;
2055 for (PetscInt k = lzs; k < lze; k++)
for (PetscInt i = lxs; i < lxe; i++) {
2056 if (nvert[k][j_nvert][i] < 0.1) {
2057 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);
2060 uch[k][j_face][i].
y = fluxTrim;
2066 PetscInt k_face = (face_id ==
BC_FACE_NEG_Z) ? info.zs : info.mz - 2;
2067 PetscInt k_nvert = (face_id ==
BC_FACE_NEG_Z) ? info.zs + 1 : info.mz - 2;
2069 for (PetscInt j = lys; j < lye; j++)
for (PetscInt i = lxs; i < lxe; i++) {
2070 if (nvert[k_nvert][j][i] < 0.1) {
2071 PetscReal faceArea = sqrt(zet[k_nvert][j][i].x*zet[k_nvert][j][i].x + zet[k_nvert][j][i].y*zet[k_nvert][j][i].y + zet[k_nvert][j][i].z*zet[k_nvert][j][i].z);
2074 uch[k_face][j][i].
z = fluxTrim;
2081 ierr = DMDAVecRestoreArray(user->
fda, user->
lUcont, &ucont); CHKERRQ(ierr);
2082 ierr = DMDAVecRestoreArray(user->
fda, user->
Bcs.
Uch, &uch); CHKERRQ(ierr);
2083 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lCsi, (
const Cmpnts***)&csi); CHKERRQ(ierr);
2084 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lEta, (
const Cmpnts***)&eta); CHKERRQ(ierr);
2085 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lZet, (
const Cmpnts***)&zet); CHKERRQ(ierr);
2086 ierr = DMDAVecRestoreArrayRead(user->
da, user->
lNvert, (
const PetscReal***)&nvert); CHKERRQ(ierr);
2088 PetscFunctionReturn(0);
2092#define __FUNCT__ "Destroy_PeriodicDrivenConstant"
2099 PetscFunctionBeginUser;
2102 if (self && self->
data) {
2104 PetscFree(self->
data);
2113 PetscFunctionReturn(0);
PetscReal cs2_half
Half-width (in index space) in cross-stream direction 2.
PetscErrorCode Create_InletConstantVelocity(BoundaryCondition *bc)
Implementation of Create_InletConstantVelocity().
static PetscErrorCode Apply_WallNoSlip(BoundaryCondition *self, BCContext *ctx)
Internal helper implementation: Apply_WallNoSlip().
PetscBool applyBoundaryTrim
static PetscErrorCode Initialize_InletParabolicProfile(BoundaryCondition *self, BCContext *ctx)
Internal helper implementation: Initialize_InletParabolicProfile().
static PetscErrorCode PreStep_InletConstantVelocity(BoundaryCondition *self, BCContext *ctx, PetscReal *in, PetscReal *out)
Internal helper implementation: PreStep_InletConstantVelocity().
static PetscErrorCode Apply_InletConstantVelocity(BoundaryCondition *self, BCContext *ctx)
Internal helper implementation: Apply_InletConstantVelocity().
PetscReal cs2_center
Center index in cross-stream direction 2.
static PetscErrorCode Apply_OutletConservation(BoundaryCondition *self, BCContext *ctx)
(Handler Action) Applies mass conservation correction to the outlet face.
static PetscErrorCode Apply_InletParabolicProfile(BoundaryCondition *self, BCContext *ctx)
Internal helper implementation: Apply_InletParabolicProfile().
static PetscErrorCode PostStep_InletParabolicProfile(BoundaryCondition *self, BCContext *ctx, PetscReal *in, PetscReal *out)
Internal helper implementation: PostStep_InletParabolicProfile().
PetscReal targetVolumetricFlux
PetscBool isMasterController
static PetscErrorCode Apply_PeriodicDrivenConstant(BoundaryCondition *self, BCContext *ctx)
Internal helper implementation: Apply_PeriodicDrivenConstant().
static PetscErrorCode Initialize_PeriodicDrivenConstant(BoundaryCondition *self, BCContext *ctx)
Internal helper implementation: Initialize_PeriodicDrivenConstant().
PetscErrorCode Create_PeriodicGeometric(BoundaryCondition *bc)
Implementation of Create_PeriodicGeometric().
PetscReal v_max
Peak centerline velocity (from user params).
PetscErrorCode Validate_DrivenFlowConfiguration(UserCtx *user)
Internal helper implementation: Validate_DrivenFlowConfiguration().
PetscErrorCode Create_InletParabolicProfile(BoundaryCondition *bc)
Implementation of Create_InletParabolicProfile().
static PetscErrorCode Destroy_InletConstantVelocity(BoundaryCondition *self)
Internal helper implementation: Destroy_InletConstantVelocity().
static PetscErrorCode Destroy_PeriodicDrivenConstant(BoundaryCondition *self)
Internal helper implementation: Destroy_PeriodicDrivenConstant().
PetscErrorCode Create_PeriodicDrivenConstant(BoundaryCondition *bc)
Internal helper implementation: Create_PeriodicDrivenConstant().
static PetscErrorCode PreStep_InletParabolicProfile(BoundaryCondition *self, BCContext *ctx, PetscReal *in, PetscReal *out)
Internal helper implementation: PreStep_InletParabolicProfile().
static PetscErrorCode PostStep_OutletConservation(BoundaryCondition *self, BCContext *ctx, PetscReal *in, PetscReal *out)
Internal helper implementation: PostStep_OutletConservation().
PetscReal normal_velocity
static PetscErrorCode Destroy_InletParabolicProfile(BoundaryCondition *self)
Internal helper implementation: Destroy_InletParabolicProfile().
static PetscErrorCode Initialize_InletConstantVelocity(BoundaryCondition *self, BCContext *ctx)
Internal helper implementation: Initialize_InletConstantVelocity().
PetscErrorCode Create_WallNoSlip(BoundaryCondition *bc)
Implementation of Create_WallNoSlip().
static PetscErrorCode PreStep_PeriodicDrivenConstant(BoundaryCondition *self, BCContext *ctx, PetscReal *in, PetscReal *out)
Internal helper implementation: PreStep_PeriodicDrivenConstant().
static PetscErrorCode PostStep_InletConstantVelocity(BoundaryCondition *self, BCContext *ctx, PetscReal *in, PetscReal *out)
Internal helper implementation: PostStep_InletConstantVelocity().
static PetscErrorCode PreStep_OutletConservation(BoundaryCondition *self, BCContext *ctx, PetscReal *local_inflow_contribution, PetscReal *local_outflow_contribution)
Internal helper implementation: PreStep_OutletConservation().
PetscReal boundaryVelocityCorrection
PetscErrorCode Create_OutletConservation(BoundaryCondition *bc)
Implementation of Create_OutletConservation().
PetscReal cs1_half
Half-width (in index space) in cross-stream direction 1.
PetscReal cs1_center
Center index in cross-stream direction 1.
Private data structure for the handler.
Private data structure for the Constant Velocity Inlet handler.
Private data structure for the Parabolic Velocity Inlet handler.
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.
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 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.
#define LOCAL
Logging scope definitions for controlling message output.
#define GLOBAL
Scope for global logging across all processes.
const char * BCFaceToString(BCFace face)
Helper function to convert BCFace enum to a string representation.
#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_FUNCTION_END
Marks the end of a profiled code block.
const char * BCTypeToString(BCType type)
Helper function to convert BCType enum to a string representation.
@ 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 code block (typically a function).
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)
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.
BCHandlerType
Defines the specific computational "strategy" for a boundary handler.
@ BC_HANDLER_PERIODIC_DRIVEN_INITIAL_FLUX
@ BC_HANDLER_PERIODIC_DRIVEN_CONSTANT_FLUX
BCHandlerType handler_type
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
const PetscReal * global_farfield_inflow_sum
Vec Uch
Characteristic velocity for boundary conditions.
BCFace
Identifies the six logical faces of a structured computational block.
Provides execution context for a boundary condition handler.
Holds the complete configuration for one of the six boundary faces.
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.