20 PetscFunctionBeginUser;
21 PetscCheck(head != NULL, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"BC param list head cannot be NULL.");
22 PetscCall(PetscCalloc1(1, &
node));
23 PetscCall(PetscStrallocpy(key, &
node->key));
24 PetscCall(PetscStrallocpy(value, &
node->value));
26 cursor = &(*cursor)->
next;
29 PetscFunctionReturn(0);
38 PetscFunctionBeginUser;
39 if (!bc_ptr || !*bc_ptr) PetscFunctionReturn(0);
45 PetscCall(PetscFree(bc));
47 PetscFunctionReturn(0);
57 if (index >= nodes - 1) {
109 PetscFunctionBeginUser;
114 PetscCall(PetscOptionsSetValue(NULL,
"-face_source_0_frame",
"normal"));
115 PetscCall(PetscOptionsSetValue(NULL,
"-face_source_0_expr_0", speed));
116 PetscFunctionReturn(0);
127 return (PetscReal)(user->
info.my - 2) * (PetscReal)(user->
info.mz - 2);
130 return (PetscReal)(user->
info.mx - 2) * (PetscReal)(user->
info.mz - 2);
133 return (PetscReal)(user->
info.mx - 2) * (PetscReal)(user->
info.my - 2);
154 PetscFunctionBeginUser;
157 *ucont_k = sample_k; *ucont_j = sample_j; *ucont_i = 0;
158 *ubcs_k = sample_k; *ubcs_j = sample_j; *ubcs_i = 0;
161 *ucont_k = sample_k; *ucont_j = sample_j; *ucont_i = user->
info.mx - 2;
162 *ubcs_k = sample_k; *ubcs_j = sample_j; *ubcs_i = user->
info.mx - 1;
165 *ucont_k = sample_k; *ucont_j = 0; *ucont_i = sample_i;
166 *ubcs_k = sample_k; *ubcs_j = 0; *ubcs_i = sample_i;
169 *ucont_k = sample_k; *ucont_j = user->
info.my - 2; *ucont_i = sample_i;
170 *ubcs_k = sample_k; *ubcs_j = user->
info.my - 1; *ubcs_i = sample_i;
173 *ucont_k = 0; *ucont_j = sample_j; *ucont_i = sample_i;
174 *ubcs_k = 0; *ubcs_j = sample_j; *ubcs_i = sample_i;
177 *ucont_k = user->
info.mz - 2; *ucont_j = sample_j; *ucont_i = sample_i;
178 *ubcs_k = user->
info.mz - 1; *ubcs_j = sample_j; *ubcs_i = sample_i;
181 PetscFunctionReturn(0);
198 PetscInt *ubcs_center_k,
199 PetscInt *ubcs_center_j,
200 PetscInt *ubcs_center_i)
202 PetscFunctionBeginUser;
205 *center_k = 3; *center_j = 3; *center_i = 0;
206 *off_k = 2; *off_j = 2; *off_i = 0;
207 *wall_k = 1; *wall_j = 1; *wall_i = 0;
208 *ubcs_center_k = 3; *ubcs_center_j = 3; *ubcs_center_i = 0;
211 *center_k = 3; *center_j = 3; *center_i = user->
info.mx - 2;
212 *off_k = 2; *off_j = 2; *off_i = user->
info.mx - 2;
213 *wall_k = 1; *wall_j = 1; *wall_i = user->
info.mx - 2;
214 *ubcs_center_k = 3; *ubcs_center_j = 3; *ubcs_center_i = user->
info.mx - 1;
217 *center_k = 3; *center_j = 0; *center_i = 3;
218 *off_k = 2; *off_j = 0; *off_i = 2;
219 *wall_k = 1; *wall_j = 0; *wall_i = 1;
220 *ubcs_center_k = 3; *ubcs_center_j = 0; *ubcs_center_i = 3;
223 *center_k = 3; *center_j = user->
info.my - 2; *center_i = 3;
224 *off_k = 2; *off_j = user->
info.my - 2; *off_i = 2;
225 *wall_k = 1; *wall_j = user->
info.my - 2; *wall_i = 1;
226 *ubcs_center_k = 3; *ubcs_center_j = user->
info.my - 1; *ubcs_center_i = 3;
229 *center_k = 0; *center_j = 3; *center_i = 3;
230 *off_k = 0; *off_j = 2; *off_i = 2;
231 *wall_k = 0; *wall_j = 1; *wall_i = 1;
232 *ubcs_center_k = 0; *ubcs_center_j = 3; *ubcs_center_i = 3;
235 *center_k = user->
info.mz - 2; *center_j = 3; *center_i = 3;
236 *off_k = user->
info.mz - 2; *off_j = 2; *off_i = 2;
237 *wall_k = user->
info.mz - 2; *wall_j = 1; *wall_i = 1;
238 *ubcs_center_k = user->
info.mz - 1; *ubcs_center_j = 3; *ubcs_center_i = 3;
241 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE,
"Unknown boundary face %d.", (
int)face);
243 PetscFunctionReturn(0);
267 PetscBool generic_face = PETSC_FALSE;
268 PetscBool any_face_serviceable = PETSC_FALSE;
270 PetscFunctionBeginUser;
276 any_face_serviceable = PETSC_TRUE;
280 PetscCall(
PicurvAssertBool(any_face_serviceable,
"at least one global face should be serviceable in a non-degenerate domain"));
283 PetscFunctionReturn(0);
294 PetscFunctionBeginUser;
296 PetscCall(
PicurvAssertBool((PetscBool)(wall != NULL),
"factory should return wall handler"));
299 PetscCall(
PicurvAssertBool((PetscBool)(wall->
Destroy == NULL),
"wall handler should not require destroy hook"));
303 PetscCall(
PicurvAssertBool((PetscBool)(inlet != NULL),
"factory should return inlet handler"));
307 PetscCall(
PicurvAssertBool((PetscBool)(inlet->
Destroy != NULL),
"inlet handler should expose its destroy hook"));
310 PetscFunctionReturn(0);
318 PetscFunctionBeginUser;
319 for (PetscInt step = 0; step < 3; step++) {
320 PetscReal local_inflow = 0.0, local_outflow = 0.0;
323 PetscCall(VecSet(ctx->
user->
Ucont, -91.0));
325 PetscCall(bc->
PreStep(bc, ctx, &local_inflow, &local_outflow));
326 PetscCall(bc->
Apply(bc, ctx));
328 PetscFunctionReturn(0);
336 struct HandlerExpectation {
339 PetscBool expect_apply;
340 PetscBool expect_initialize;
342 const struct HandlerExpectation expectations[] = {
349 PetscFunctionBeginUser;
350 for (
size_t i = 0; i <
sizeof(expectations) /
sizeof(expectations[0]); ++i) {
353 PetscCall(
PicurvAssertBool((PetscBool)(bc != NULL),
"factory should allocate a handler object"));
355 PetscCall(
PicurvAssertBool((PetscBool)((bc->
Apply != NULL) == expectations[i].expect_apply),
"Apply hook expectation mismatch"));
356 PetscCall(
PicurvAssertBool((PetscBool)((bc->
Initialize != NULL) == expectations[i].expect_initialize),
"Initialize hook expectation mismatch"));
359 PetscFunctionReturn(0);
369 PetscFunctionBeginUser;
370 fd = fopen(path,
"w");
371 PetscCheck(fd != NULL, PETSC_COMM_SELF, PETSC_ERR_FILE_OPEN,
"Could not open %s for writing.", path);
372 PetscCheck(fprintf(fd,
"PICSLICE\n1\n%d %d\n", (
int)n1, (
int)n2) >= 0,
373 PETSC_COMM_SELF, PETSC_ERR_FILE_WRITE,
"Could not write PICSLICE header.");
374 for (PetscInt a = 0; a < n1; a++) {
375 for (PetscInt b = 0; b < n2; b++) {
376 PetscReal value = base + (PetscReal)(10 * a + b);
377 PetscCheck(fprintf(fd,
"%.16e\n", (
double)value) >= 0,
378 PETSC_COMM_SELF, PETSC_ERR_FILE_WRITE,
"Could not write PICSLICE value.");
382 PetscFunctionReturn(0);
396 char profile_path[PETSC_MAX_PATH_LEN];
397 PetscReal local_inflow = 0.0;
398 PetscReal local_outflow = 0.0;
400 PetscFunctionBeginUser;
401 PetscCall(PetscMemzero(&ctx,
sizeof(ctx)));
405 PetscCall(PetscSNPrintf(profile_path,
sizeof(profile_path),
"/tmp/picurv_unit_profile_%d.picslice", (
int)getpid()));
414 PetscCall(VecSet(user->
Ucont, 0.0));
415 PetscCall(VecSet(user->
Bcs.
Ubcs, 0.0));
422 PetscCall(bc->
PostStep(bc, &ctx, &local_inflow, &local_outflow));
424 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
Ucont, &ucont));
425 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
Bcs.
Ubcs, &ubcs));
426 PetscCall(
PicurvAssertRealNear(2.0, ucont[0][1][1].z, 1.0e-12,
"profile inlet should apply first scalar speed"));
427 PetscCall(
PicurvAssertRealNear(13.0, ucont[0][2][2].z, 1.0e-12,
"profile inlet should preserve PICSLICE ordering"));
428 PetscCall(
PicurvAssertRealNear(24.0, ubcs[0][3][3].z, 1.0e-12,
"profile inlet should write boundary velocity"));
429 PetscCall(
PicurvAssertRealNear(35.0, ucont[0][4][4].z, 1.0e-12,
"profile inlet should consume the last face-cell slot"));
430 PetscCall(
PicurvAssertRealNear(35.0, ubcs[0][4][4].z, 1.0e-12,
"profile inlet should write the last face-cell boundary value"));
431 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
Ucont, &ucont));
432 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
Bcs.
Ubcs, &ubcs));
433 PetscCall(
PicurvAssertBool((PetscBool)(local_inflow > 0.0),
"profile inlet PostStep should accumulate positive negative-face flux"));
434 PetscCall(
PicurvAssertRealNear(0.0, local_outflow, 1.0e-12,
"profile inlet should not add to outflow"));
439 remove(profile_path);
441 PetscFunctionReturn(0);
455 char profile_path[PETSC_MAX_PATH_LEN];
457 PetscFunctionBeginUser;
458 PetscCall(PetscMemzero(&ctx,
sizeof(ctx)));
461 PetscCall(PetscSNPrintf(profile_path,
sizeof(profile_path),
"/tmp/picurv_unit_sum_%d.picslice", (
int)getpid()));
465 PetscCall(VecSet(user->
Ucont, 0.0));
466 PetscCall(VecSet(user->
Bcs.
Ubcs, 0.0));
472 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
Ucont, &ucont));
473 PetscCall(
PicurvAssertRealNear(3.0, ucont[0][1][1].z, 1.0e-12,
"the expression adds to the file's first speed"));
474 PetscCall(
PicurvAssertRealNear(36.0, ucont[0][4][4].z, 1.0e-12,
"the expression adds to the file's last speed"));
475 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
Ucont, &ucont));
480 PetscReal mean = 0.0;
482 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
Ucont, &ucont));
483 for (PetscInt j = 1; j < user->
JM; ++j)
for (PetscInt i = 1; i < user->
IM; ++i) { mean += ucont[0][j][i].
z - 1.0; ++slots; }
484 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
Ucont, &ucont));
485 mean /= (PetscReal)slots;
487 PetscCall(PetscSNPrintf(bulk,
sizeof(bulk),
"%.17g", (
double)(mean + 2.0)));
488 PetscCall(PetscOptionsSetValue(NULL,
"-face_source_0_bulk_velocity", bulk));
490 PetscCall(VecSet(user->
Ucont, 0.0));
494 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
Ucont, &ucont));
495 PetscCall(
PicurvAssertRealNear(4.0, ucont[0][1][1].z, 1.0e-10,
"a bulk velocity scales the expression, not the file"));
496 PetscCall(
PicurvAssertRealNear(37.0, ucont[0][4][4].z, 1.0e-10,
"the file's speeds keep their measured differences"));
497 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
Ucont, &ucont));
499 PetscCall(PetscOptionsClearValue(NULL,
"-face_source_0_bulk_velocity"));
500 PetscCall(PetscOptionsClearValue(NULL,
"-face_source_0_frame"));
501 PetscCall(PetscOptionsClearValue(NULL,
"-face_source_0_expr_0"));
504 remove(profile_path);
506 PetscFunctionReturn(0);
515 PetscErrorCode ierr_create;
517 PetscFunctionBeginUser;
518 PetscCall(PetscPushErrorHandler(PetscIgnoreErrorHandler, NULL));
520 PetscCall(PetscPopErrorHandler());
522 PetscCall(
PicurvAssertBool((PetscBool)(ierr_create != 0),
"unsupported handler should return a non-zero error code"));
524 PetscCall(PetscFree(bc));
526 PetscFunctionReturn(0);
540 PetscReal local_inflow = 0.0;
541 PetscReal local_outflow = 0.0;
542 PetscReal expected_flux = 0.0;
544 PetscFunctionBeginUser;
545 PetscCall(PetscMemzero(&ctx,
sizeof(ctx)));
547 PetscCall(VecSet(user->
Ucont, 0.0));
548 PetscCall(VecSet(user->
Bcs.
Ubcs, 0.0));
558 PetscCall(bc->
PostStep(bc, &ctx, &local_inflow, &local_outflow));
560 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
Ucont, &ucont));
561 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
Bcs.
Ubcs, &ubcs));
562 PetscCall(
PicurvAssertRealNear(2.5, ucont[0][3][3].z, 1.0e-12,
"constant inlet should set Ucont normal component"));
563 PetscCall(
PicurvAssertRealNear(2.5, ubcs[0][3][3].z, 1.0e-12,
"constant inlet should set Ubcs normal component"));
564 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
Ucont, &ucont));
565 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
Bcs.
Ubcs, &ubcs));
567 expected_flux = (PetscReal)(user->
info.mx - 2) * (PetscReal)(user->
info.my - 2) * 2.5;
568 PetscCall(
PicurvAssertRealNear(expected_flux, local_inflow, 1.0e-12,
"constant inlet PostStep should sum the face flux"));
569 PetscCall(
PicurvAssertRealNear(0.0, local_outflow, 1.0e-12,
"constant inlet should not contribute to outflow accumulation"));
575 PetscFunctionReturn(0);
587 Cmpnts ***zet = NULL, ***ucont = NULL, ***ubcs = NULL, ***ucat = NULL;
589 PetscFunctionBeginUser;
590 PetscCall(PetscMemzero(&ctx,
sizeof(ctx)));
593 PetscCall(DMDAVecGetArray(user->
fda, user->
lZet, &zet));
594 zet[0][3][3].
x = 0.0;
595 zet[0][3][3].
y = 3.0;
596 zet[0][3][3].
z = 4.0;
597 PetscCall(DMDAVecRestoreArray(user->
fda, user->
lZet, &zet));
606 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
Ucont, &ucont));
607 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
Bcs.
Ubcs, &ubcs));
609 "Ucont should be the Cartesian inlet velocity dotted with the face metric"));
611 "curvilinear normal velocity should preserve its Cartesian x component"));
613 "curvilinear normal velocity should include Cartesian y"));
615 "curvilinear normal velocity should include Cartesian z"));
616 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
Ucont, &ucont));
617 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
Bcs.
Ubcs, &ubcs));
619 PetscCall(VecSet(user->
Ucat, 1.0));
621 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
Ucat, &ucat));
623 "dummy reflection should act on Cartesian x"));
625 "dummy reflection should act on Cartesian y"));
627 "dummy reflection should act on Cartesian z"));
629 "dummy reflection should not overwrite the adjacent interior value"));
630 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
Ucat, &ucat));
635 PetscFunctionReturn(0);
655 PetscFunctionBeginUser;
656 PetscCall(PetscMemzero(&ctx,
sizeof(ctx)));
660 for (
size_t n = 0; n <
sizeof(faces) /
sizeof(faces[0]); ++n) {
661 const BCFace face = faces[n];
662 PetscInt ucont_k, ucont_j, ucont_i, ubcs_k, ubcs_j, ubcs_i;
664 PetscCall(VecSet(user->
Ucont, 5.0));
665 PetscCall(VecSet(user->
Bcs.
Ubcs, 7.0));
668 PetscCall(bc->
Apply(bc, &ctx));
671 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
Ucont, &ucont));
672 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
Bcs.
Ubcs, &ubcs));
674 PetscCall(
PicurvAssertRealNear(0.0, ubcs[ubcs_k][ubcs_j][ubcs_i].x, 1.0e-12,
"wall no-slip should zero Ubcs.x"));
675 PetscCall(
PicurvAssertRealNear(0.0, ubcs[ubcs_k][ubcs_j][ubcs_i].y, 1.0e-12,
"wall no-slip should zero Ubcs.y"));
676 PetscCall(
PicurvAssertRealNear(0.0, ubcs[ubcs_k][ubcs_j][ubcs_i].z, 1.0e-12,
"wall no-slip should zero Ubcs.z"));
677 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
Ucont, &ucont));
678 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
Bcs.
Ubcs, &ubcs));
683 PetscFunctionReturn(0);
689 PetscFunctionBeginUser;
690 PetscCall(VecStrideSet(v, 0, x));
691 PetscCall(VecStrideSet(v, 1, y));
692 PetscCall(VecStrideSet(v, 2, z));
693 PetscFunctionReturn(0);
710 Cmpnts ***ucont = NULL, ***ubcs = NULL, ***ucat = NULL;
713 const PetscReal interior[3] = {1.0, 2.0, 3.0};
715 PetscFunctionBeginUser;
716 PetscCall(PetscMemzero(&ctx,
sizeof(ctx)));
721 "a free-slip wall refreshes its boundary value with the flow"));
723 for (
size_t n = 0; n <
sizeof(faces) /
sizeof(faces[0]); ++n) {
724 const BCFace face = faces[n];
725 const PetscInt axis = (PetscInt)face / 2;
726 PetscInt ucont_k, ucont_j, ucont_i, ubcs_k, ubcs_j, ubcs_i;
729 PetscCall(VecSet(user->
Ucont, 5.0));
730 PetscCall(VecSet(user->
Bcs.
Ubcs, 7.0));
735 PetscCall(bc->
Apply(bc, &ctx));
739 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
Ucont, &ucont));
740 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
Bcs.
Ubcs, &ubcs));
741 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
Ucat, &ucat));
743 "a free-slip wall closes the face"));
744 for (PetscInt c = 0; c < 3; ++c) {
745 const PetscReal boundary = (&ubcs[ubcs_k][ubcs_j][ubcs_i].x)[c];
746 const PetscReal dummy = (&ucat[ubcs_k][ubcs_j][ubcs_i].x)[c];
749 "the boundary value is the adjacent velocity less its normal part"));
751 "the dummy cell is the mirror image of the interior one"));
753 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
Ucat, &ucat));
754 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
Bcs.
Ubcs, &ubcs));
755 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
Ucont, &ucont));
760 PetscFunctionReturn(0);
776 Cmpnts ***zet = NULL, ***ucont = NULL, ***ubcs = NULL;
778 PetscFunctionBeginUser;
779 PetscCall(PetscMemzero(&ctx,
sizeof(ctx)));
782 PetscCall(DMDAVecGetArray(user->
fda, user->
lZet, &zet));
783 zet[0][3][3].
x = 0.0;
784 zet[0][3][3].
y = 3.0;
785 zet[0][3][3].
z = 4.0;
786 PetscCall(DMDAVecRestoreArray(user->
fda, user->
lZet, &zet));
791 PetscCall(bc->
Apply(bc, &ctx));
793 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
Ucont, &ucont));
794 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
Bcs.
Ubcs, &ubcs));
795 PetscCall(
PicurvAssertRealNear(0.0, ucont[0][3][3].z, 1.0e-12,
"no flux through a tilted free-slip face"));
796 PetscCall(
PicurvAssertRealNear(1.0, ubcs[0][3][3].x, 1.0e-12,
"the tangential x component is kept"));
797 PetscCall(
PicurvAssertRealNear(0.16, ubcs[0][3][3].y, 1.0e-12,
"the normal part is removed from y"));
798 PetscCall(
PicurvAssertRealNear(-0.12, ubcs[0][3][3].z, 1.0e-12,
"the normal part is removed from z"));
799 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
Bcs.
Ubcs, &ubcs));
800 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
Ucont, &ucont));
804 PetscFunctionReturn(0);
814 PetscReal ***
nu_t = NULL;
815 const PetscInt mid = 3;
817 PetscFunctionBeginUser;
826 "a no-slip wall exerts shear"));
828 "a free-slip wall exerts none"));
830 "an inlet is not a wall"));
833 PetscCall(DMCreateGlobalVector(user->
da, &user->
Nu_t));
834 PetscCall(DMCreateLocalVector(user->
da, &user->
lNu_t));
835 PetscCall(VecSet(user->
Nu_t, 0.0));
836 PetscCall(DMDAVecGetArray(user->
da, user->
Nu_t, &
nu_t));
837 for (PetscInt k = user->
info.zs; k < user->
info.zs + user->
info.zm; ++k)
838 for (PetscInt j = user->
info.ys; j < user->
info.ys + user->
info.ym; ++j)
839 for (PetscInt i = 1; i < user->
info.mx - 1; ++i)
nu_t[k][j][i] = 0.01 * i;
840 PetscCall(DMDAVecRestoreArray(user->
da, user->
Nu_t, &
nu_t));
842 PetscCall(DMDAVecGetArrayRead(user->
da, user->
Nu_t, &
nu_t));
844 "the eddy viscosity mirrors across a free-slip wall"));
846 "a no-slip wall replaces the face value, so its dummy is not written"));
847 PetscCall(DMDAVecRestoreArrayRead(user->
da, user->
Nu_t, &
nu_t));
848 PetscCall(VecDestroy(&user->
Nu_t));
849 PetscCall(VecDestroy(&user->
lNu_t));
851 PetscFunctionReturn(0);
859 struct ConstantInletCase {
862 const char *value_text;
864 const struct ConstantInletCase cases[] = {
878 PetscFunctionBeginUser;
879 PetscCall(PetscMemzero(&ctx,
sizeof(ctx)));
883 for (
size_t n = 0; n <
sizeof(cases) /
sizeof(cases[0]); ++n) {
884 const struct ConstantInletCase *test_case = &cases[n];
886 PetscReal local_inflow = 0.0;
887 PetscReal local_outflow = 0.0;
888 PetscInt ucont_k, ucont_j, ucont_i, ubcs_k, ubcs_j, ubcs_i;
892 PetscCall(VecSet(user->
Ucont, 0.0));
893 PetscCall(VecSet(user->
Bcs.
Ubcs, 0.0));
901 PetscCall(bc->
PreStep(bc, &ctx, &local_inflow, &local_outflow));
902 PetscCall(
PicurvAssertRealNear(0.0, local_inflow, 1.0e-12,
"constant inlet PreStep should leave inflow unchanged"));
903 PetscCall(
PicurvAssertRealNear(0.0, local_outflow, 1.0e-12,
"constant inlet PreStep should leave outflow unchanged"));
904 PetscCall(bc->
Apply(bc, &ctx));
905 PetscCall(bc->
PostStep(bc, &ctx, &local_inflow, &local_outflow));
908 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
Ucont, &ucont));
909 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
Bcs.
Ubcs, &ubcs));
915 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
Ucont, &ucont));
916 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
Bcs.
Ubcs, &ubcs));
917 PetscCall(
PicurvAssertRealNear(expected_flux, local_inflow, 1.0e-12,
"constant inlet PostStep should integrate the face flux with orientation"));
918 PetscCall(
PicurvAssertRealNear(0.0, local_outflow, 1.0e-12,
"constant inlet should not add to outflow"));
925 PetscFunctionReturn(0);
939 PetscFunctionBeginUser;
940 PetscCall(PetscMemzero(&ctx,
sizeof(ctx)));
952 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
Ucont, &ucont));
953 PetscCall(
PicurvAssertRealNear(4.0, ucont[0][3][3].z, 1.0e-12,
"parabolic inlet should peak at the face centerline"));
956 "parabolic inlet should vanish on the wall, not at the wall-adjacent centre"));
957 PetscCall(
PicurvAssertBool((PetscBool)(ucont[0][3][3].z > ucont[0][2][2].z),
"parabolic inlet centerline should exceed off-center velocity"));
958 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
Ucont, &ucont));
964 PetscFunctionReturn(0);
979 PetscFunctionBeginUser;
980 PetscCall(PetscMemzero(&ctx,
sizeof(ctx)));
990 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
Ucont, &ucont));
991 PetscCall(
PicurvAssertRealNear(4.0, ucont[0][3][1].z, 1.0e-12,
"the xi axis carries no parabola factor"));
992 PetscCall(
PicurvAssertRealNear(ucont[0][3][1].z, ucont[0][3][4].z, 1.0e-12,
"profile is uniform along xi"));
993 PetscCall(
PicurvAssertRealNear(4.0 * 0.36, ucont[0][1][3].z, 1.0e-12,
"wall-bounded axis keeps its parabola"));
994 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
Ucont, &ucont));
1000 PetscFunctionReturn(0);
1020 PetscFunctionBeginUser;
1021 PetscCall(PetscMemzero(&ctx,
sizeof(ctx)));
1025 for (
size_t n = 0; n <
sizeof(faces) /
sizeof(faces[0]); ++n) {
1026 const BCFace face = faces[n];
1028 PetscReal local_inflow = 0.0;
1029 PetscReal local_outflow = 0.0;
1030 PetscInt center_k, center_j, center_i;
1031 PetscInt off_k, off_j, off_i;
1032 PetscInt wall_k, wall_j, wall_i;
1033 PetscInt ubcs_center_k, ubcs_center_j, ubcs_center_i;
1036 PetscCall(VecSet(user->
Ucont, 0.0));
1037 PetscCall(VecSet(user->
Bcs.
Ubcs, 0.0));
1041 :
"16*4.0*xi*(1-xi)*eta*(1-eta)";
1048 PetscCall(bc->
PreStep(bc, &ctx, &local_inflow, &local_outflow));
1049 PetscCall(
PicurvAssertRealNear(0.0, local_inflow, 1.0e-12,
"parabolic inlet PreStep should leave inflow unchanged"));
1050 PetscCall(
PicurvAssertRealNear(0.0, local_outflow, 1.0e-12,
"parabolic inlet PreStep should leave outflow unchanged"));
1051 PetscCall(bc->
Apply(bc, &ctx));
1052 PetscCall(bc->
PostStep(bc, &ctx, &local_inflow, &local_outflow));
1055 ¢er_k, ¢er_j, ¢er_i,
1056 &off_k, &off_j, &off_i,
1057 &wall_k, &wall_j, &wall_i,
1058 &ubcs_center_k, &ubcs_center_j, &ubcs_center_i));
1059 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
Ucont, &ucont));
1060 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
Bcs.
Ubcs, &ubcs));
1064 "parabolic inlet should take its wall-adjacent value, vanishing only on the wall"));
1067 "parabolic inlet centerline magnitude should exceed the off-center magnitude"));
1068 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
Ucont, &ucont));
1069 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
Bcs.
Ubcs, &ubcs));
1070 PetscCall(
PicurvAssertBool((PetscBool)(PetscAbsReal(local_inflow) > 0.0),
"parabolic inlet PostStep should accumulate a non-zero flux"));
1072 "parabolic inlet PostStep should preserve the face orientation"));
1073 PetscCall(
PicurvAssertRealNear(0.0, local_outflow, 1.0e-12,
"parabolic inlet should not add to outflow"));
1080 PetscFunctionReturn(0);
1093 PetscReal local_inflow = 0.0, local_outflow = 0.0, physical_time = 0.0;
1095 PetscFunctionBeginUser;
1096 PetscCall(PetscMemzero(&ctx,
sizeof(ctx)));
1108 PetscCall(bc->
PreStep(bc, &ctx, &local_inflow, &local_outflow));
1109 PetscCall(bc->
Apply(bc, &ctx));
1110 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
Ucont, &ucont));
1112 "a source in t takes the value at the step's time"));
1113 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
Ucont, &ucont));
1117 PetscCall(PetscOptionsSetValue(NULL,
"-face_source_0_expr_0",
"xi"));
1118 PetscCall(PetscOptionsSetValue(NULL,
"-face_source_0_bulk_velocity",
"3.0"));
1123 PetscCall(bc->
PostStep(bc, &ctx, &local_inflow, &local_outflow));
1125 local_inflow, 1.0e-10,
"the face flux is the bulk velocity times the open area"));
1126 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
Ucont, &ucont));
1128 "the shape keeps its form: twice the bulk times xi"));
1129 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
Ucont, &ucont));
1130 PetscCall(PetscOptionsClearValue(NULL,
"-face_source_0_bulk_velocity"));
1135 PetscFunctionReturn(0);
1145 PetscFunctionBeginUser;
1146 simCtx->
step = step;
1148 PetscCall(bc->
PreStep(bc, ctx, NULL, NULL));
1149 PetscCall(bc->
Apply(bc, ctx));
1150 PetscFunctionReturn(0);
1164 Cmpnts ***ucont = NULL, ***ubcs = NULL;
1165 char path[PETSC_MAX_PATH_LEN];
1167 const PetscReal w_of_frame[3] = {-1.0, 3.0, 5.0};
1169 PetscFunctionBeginUser;
1170 PetscCall(PetscMemzero(&ctx,
sizeof(ctx)));
1173 PetscCall(PetscSNPrintf(path,
sizeof(path),
"/tmp/picurv_unit_recording_%d.picslice", (
int)getpid()));
1174 fd = fopen(path,
"w");
1175 PetscCheck(fd, PETSC_COMM_SELF, PETSC_ERR_FILE_OPEN,
"Could not open %s.", path);
1176 fprintf(fd,
"PICSLICE\n3\n%d %d 3 0.1\n", (
int)(user->
JM - 1), (
int)(user->
IM - 1));
1177 for (PetscInt frame = 0; frame < 3; ++frame)
1178 for (PetscInt a = 0; a < user->
JM - 1; ++a)
1179 for (PetscInt b = 0; b < user->
IM - 1; ++b) fprintf(fd,
"%.16e 7.0 %.16e\n", (
double)(10 * a + b), (
double)w_of_frame[frame]);
1188 PetscCall(PetscOptionsSetValue(NULL,
"-face_source_0_frame",
"cartesian"));
1189 PetscCall(PetscOptionsClearValue(NULL,
"-face_source_0_expr_0"));
1196 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
Ucont, &ucont));
1197 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
Bcs.
Ubcs, &ubcs));
1198 PetscCall(
PicurvAssertRealNear(1.0, ucont[0][1][1].z, 1.0e-12,
"halfway between frames is their mean"));
1199 PetscCall(
PicurvAssertRealNear(11.0, ubcs[0][2][2].x, 1.0e-12,
"the file's first component is x, in row order"));
1200 PetscCall(
PicurvAssertRealNear(7.0, ubcs[0][2][2].y, 1.0e-12,
"the file's second component is y"));
1201 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
Bcs.
Ubcs, &ubcs));
1202 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
Ucont, &ucont));
1205 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
Ucont, &ucont));
1206 PetscCall(
PicurvAssertRealNear(-1.0, ucont[0][1][1].z, 1.0e-12,
"a frame may reverse the flow"));
1207 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
Ucont, &ucont));
1211 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
Ucont, &ucont));
1212 PetscCall(
PicurvAssertRealNear(2.0, ucont[0][1][1].z, 1.0e-12,
"past the last frame it blends into the first"));
1213 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
Ucont, &ucont));
1215 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
Ucont, &ucont));
1216 PetscCall(
PicurvAssertRealNear(1.0, ucont[0][1][1].z, 1.0e-12,
"a repeat starts again from the first frame"));
1217 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
Ucont, &ucont));
1228 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
Ucont, &ucont));
1229 PetscCall(
PicurvAssertRealNear(5.0, ucont[0][1][1].z, 1.0e-12,
"the last frame's own time is defined"));
1230 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
Ucont, &ucont));
1233 PetscCall(PetscPushErrorHandler(PetscIgnoreErrorHandler, NULL));
1235 PetscErrorCode past = bc->
PreStep(bc, &ctx, NULL, NULL);
1236 PetscCall(PetscPopErrorHandler());
1237 PetscCall(
PicurvAssertBool((PetscBool)(past != 0),
"past the last frame without repeat is refused"));
1241 PetscCall(PetscOptionsClearValue(NULL,
"-face_source_0_frame"));
1246 PetscFunctionReturn(0);
1259 Cmpnts ***ucont = NULL, ***cent = NULL, centre;
1260 PetscReal local_inflow = 0.0, local_outflow = 0.0, area = 0.0;
1262 PetscFunctionBeginUser;
1263 PetscCall(PetscMemzero(&ctx,
sizeof(ctx)));
1267 PetscCall(PetscOptionsSetValue(NULL,
"-face_source_0_flow_rate",
"8.0"));
1273 PetscCall(bc->
PostStep(bc, &ctx, &local_inflow, &local_outflow));
1276 "the face's flux is the flow rate"));
1279 char row[256] = {0}, path[PETSC_MAX_PATH_LEN + 16];
1280 FILE *record = NULL;
1281 double time = 0.0, face_area = 0.0, rate = 0.0;
1283 char face[32] = {0};
1284 PetscCall(PetscSNPrintf(simCtx->
analysis_dir,
sizeof(simCtx->
analysis_dir),
"/tmp/picurv_unit_inlet_%d", (
int)getpid()));
1285 PetscCheck(mkdir(simCtx->
analysis_dir, 0700) == 0, PETSC_COMM_SELF, PETSC_ERR_FILE_OPEN,
"Could not make the record's directory.");
1289 PetscCall(PetscSNPrintf(path,
sizeof(path),
"%s/inlet_flow.csv", simCtx->
analysis_dir));
1290 record = fopen(path,
"r");
1291 PetscCheck(record, PETSC_COMM_SELF, PETSC_ERR_FILE_OPEN,
"The inlet-flow record was not written.");
1292 PetscCheck(fgets(row,
sizeof(row), record) && fgets(row,
sizeof(row), record), PETSC_COMM_SELF, PETSC_ERR_FILE_READ,
"No inlet-flow row.");
1294 PetscCheck(sscanf(row,
"%d,%le,%31[^,],%le,%le", &step, &time, face, &face_area, &rate) == 5, PETSC_COMM_SELF, PETSC_ERR_FILE_READ,
"Bad row: %s", row);
1300 PetscCall(PetscOptionsClearValue(NULL,
"-face_source_0_flow_rate"));
1302 PetscCall(PetscOptionsSetValue(NULL,
"-face_source_0_expr_0",
"r"));
1304 PetscCall(DMDAVecGetArray(user->
fda, user->
lCentz, ¢));
1305 cent[0][2][2].x = centre.x + 3.0;
1306 cent[0][2][2].y = centre.y + 4.0;
1307 cent[0][2][2].z = centre.z;
1308 PetscCall(DMDAVecRestoreArray(user->
fda, user->
lCentz, ¢));
1312 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
Ucont, &ucont));
1314 "r is the slot's distance from the face's centre"));
1315 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
Ucont, &ucont));
1317 PetscCall(PetscOptionsClearValue(NULL,
"-face_source_0_frame"));
1318 PetscCall(PetscOptionsClearValue(NULL,
"-face_source_0_expr_0"));
1321 PetscFunctionReturn(0);
1335 Cmpnts ***ucont = NULL, ***ubcs = NULL;
1338 PetscFunctionBeginUser;
1339 PetscCall(PetscMemzero(&ctx,
sizeof(ctx)));
1342 PetscCall(PetscOptionsSetValue(NULL,
"-face_source_0_frame",
"cartesian"));
1343 PetscCall(PetscOptionsSetValue(NULL,
"-face_source_0_expr_0",
"2.0"));
1344 PetscCall(PetscOptionsSetValue(NULL,
"-face_source_0_expr_1",
"0.02"));
1345 PetscCall(PetscOptionsSetValue(NULL,
"-face_source_0_expr_2",
"3.0"));
1347 for (PetscInt f = 0; f < 2; ++f) {
1348 const BCFace face = faces[f];
1356 PetscCall(VecSet(user->
Ucont, 9.0));
1361 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
Ucont, &ucont));
1362 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
Bcs.
Ubcs, &ubcs));
1363 PetscCall(
PicurvAssertRealNear(0.0, ucont[2][layer][2].y, 1.0e-12,
"a moving wall closes its face"));
1365 PetscCall(
PicurvAssertRealNear(0.0, ubcs[2][boundary][2].y, 1.0e-12,
"a slight tilt through the wall is removed"));
1367 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
Bcs.
Ubcs, &ubcs));
1368 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
Ucont, &ucont));
1371 PetscCall(PetscOptionsSetValue(NULL,
"-face_source_0_expr_1",
"1.0"));
1376 PetscCall(PetscPushErrorHandler(PetscIgnoreErrorHandler, NULL));
1378 PetscErrorCode through = bc->
PreStep(bc, &ctx, NULL, NULL);
1379 PetscCall(PetscPopErrorHandler());
1380 PetscCall(
PicurvAssertBool((PetscBool)(through != 0),
"a velocity through the wall is refused"));
1383 for (PetscInt c = 0; c < 3; ++c) {
1385 PetscCall(PetscSNPrintf(option,
sizeof(option),
"-face_source_0_expr_%d", (
int)c));
1386 PetscCall(PetscOptionsClearValue(NULL, option));
1388 PetscCall(PetscOptionsClearValue(NULL,
"-face_source_0_frame"));
1391 PetscFunctionReturn(0);
1404 PetscReal global_inflow = 30.0;
1405 PetscReal global_farfield_in = 0.0;
1406 PetscReal global_farfield_out = 0.0;
1407 PetscReal global_outflow = 25.0;
1408 PetscReal local_inflow = 0.0;
1409 PetscReal local_outflow = 0.0;
1413 PetscFunctionBeginUser;
1414 PetscCall(PetscMemzero(&ctx,
sizeof(ctx)));
1417 PetscCall(VecSet(user->
Ucat, 1.0));
1418 PetscCall(DMGlobalToLocalBegin(user->
fda, user->
Ucat, INSERT_VALUES, user->
lUcat));
1419 PetscCall(DMGlobalToLocalEnd(user->
fda, user->
Ucat, INSERT_VALUES, user->
lUcat));
1420 simCtx->
AreaOutSum = (PetscReal)(user->
info.mx - 2) * (PetscReal)(user->
info.my - 2);
1434 PetscCall(bc->
Apply(bc, &ctx));
1435 PetscCall(bc->
PostStep(bc, &ctx, &local_inflow, &local_outflow));
1437 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
Ucont, &ucont));
1438 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
lUcat, &ucat));
1439 PetscCall(
PicurvAssertRealNear(1.2, ucont[5][3][3].z, 1.0e-12,
"outlet correction should add the expected flux trim"));
1440 PetscCall(
PicurvAssertRealNear(1.0, ucat[5][3][3].z, 1.0e-12,
"outlet handler should preserve the interior Ucat reference"));
1441 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
Ucont, &ucont));
1442 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
lUcat, &ucat));
1444 PetscCall(
PicurvAssertRealNear(30.0, local_outflow, 1.0e-12,
"outlet PostStep should report corrected flux"));
1445 PetscCall(
PicurvAssertRealNear(0.0, local_inflow, 1.0e-12,
"outlet handler should not accumulate inflow"));
1449 PetscFunctionReturn(0);
1468 PetscFunctionBeginUser;
1469 PetscCall(PetscMemzero(&ctx,
sizeof(ctx)));
1472 PetscCall(VecSet(user->
Ucat, 1.0));
1473 PetscCall(DMGlobalToLocalBegin(user->
fda, user->
Ucat, INSERT_VALUES, user->
lUcat));
1474 PetscCall(DMGlobalToLocalEnd(user->
fda, user->
Ucat, INSERT_VALUES, user->
lUcat));
1476 for (
size_t n = 0; n <
sizeof(faces) /
sizeof(faces[0]); ++n) {
1477 const BCFace face = faces[n];
1479 PetscReal global_inflow = 0.0;
1480 PetscReal global_farfield_in = 0.0;
1481 PetscReal global_farfield_out = 0.0;
1482 PetscReal global_outflow = 0.0;
1483 PetscReal local_inflow = 0.0;
1484 PetscReal local_outflow = 0.0;
1486 PetscInt ucont_k, ucont_j, ucont_i, ubcs_k, ubcs_j, ubcs_i;
1488 PetscCall(VecSet(user->
Ucont, 0.0));
1489 PetscCall(VecSet(user->
Bcs.
Ubcs, 0.0));
1504 PetscCall(bc->
PreStep(bc, &ctx, &local_inflow, &local_outflow));
1505 PetscCall(
PicurvAssertRealNear(area, local_outflow, 1.0e-12,
"outlet PreStep should measure the uncorrected face flux"));
1507 global_inflow = area + 0.2 * area;
1508 global_outflow = local_outflow;
1509 local_outflow = 0.0;
1510 PetscCall(bc->
Apply(bc, &ctx));
1511 PetscCall(bc->
PostStep(bc, &ctx, &local_inflow, &local_outflow));
1514 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
Ucont, &ucont));
1515 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
Bcs.
Ubcs, &ubcs));
1517 PetscCall(
PicurvAssertRealNear(1.0, ubcs[ubcs_k][ubcs_j][ubcs_i].x, 1.0e-12,
"outlet handler should copy Ucat into Ubcs.x"));
1518 PetscCall(
PicurvAssertRealNear(1.0, ubcs[ubcs_k][ubcs_j][ubcs_i].y, 1.0e-12,
"outlet handler should copy Ucat into Ubcs.y"));
1519 PetscCall(
PicurvAssertRealNear(1.0, ubcs[ubcs_k][ubcs_j][ubcs_i].z, 1.0e-12,
"outlet handler should copy Ucat into Ubcs.z"));
1520 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
Ucont, &ucont));
1521 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
Bcs.
Ubcs, &ubcs));
1522 PetscCall(
PicurvAssertRealNear(0.0, local_inflow, 1.0e-12,
"outlet handler should not add to inflow"));
1523 PetscCall(
PicurvAssertRealNear(1.2 * area, local_outflow, 1.0e-12,
"outlet PostStep should report the corrected flux"));
1530 PetscFunctionReturn(0);
1540 PetscFunctionBeginUser;
1541 PetscCall(DMDAVecGetArray(user->
fda, user->
Ucat, &ucat));
1544 else ucat[k][j][i].
z = value;
1545 PetscCall(DMDAVecRestoreArray(user->
fda, user->
Ucat, &ucat));
1546 PetscCall(DMGlobalToLocalBegin(user->
fda, user->
Ucat, INSERT_VALUES, user->
lUcat));
1547 PetscCall(DMGlobalToLocalEnd(user->
fda, user->
Ucat, INSERT_VALUES, user->
lUcat));
1548 PetscFunctionReturn(0);
1555 PetscReal inflow, PetscReal outflow_measured,
1556 PetscReal *sample_flux,
Cmpnts *sample_ubcs, PetscReal *total)
1558 PetscReal global_farfield = 0.0, local_inflow = 0.0, local_outflow = 0.0;
1559 PetscInt ck, cj, ci, bk, bj, bi;
1560 Cmpnts ***ucont = NULL, ***ubcs = NULL;
1562 PetscFunctionBeginUser;
1567 PetscCall(bc->
Apply(bc, ctx));
1568 PetscCall(bc->
PostStep(bc, ctx, &local_inflow, &local_outflow));
1573 *sample_ubcs = ubcs[bk][bj][bi];
1574 PetscCall(DMDAVecRestoreArrayRead(ctx->
user->
fda, ctx->
user->
Ucont, &ucont));
1576 *total = local_outflow;
1579 PetscFunctionReturn(0);
1604 PetscFunctionBeginUser;
1605 PetscCall(PetscMemzero(&ctx,
sizeof(ctx)));
1610 for (
size_t n = 0; n <
sizeof(faces) /
sizeof(faces[0]); ++n) {
1611 const BCFace face = faces[n];
1612 const PetscReal s = ((PetscInt)face % 2 == 0) ? -1.0 : 1.0;
1614 PetscInt ck, cj, ci, bk, bj, bi;
1615 PetscReal flux, total;
1632 PetscCall(VecSet(user->
Ucat, s));
1634 PetscCall(VecSet(user->
Ucont, 0.0));
1638 PetscCall(
PicurvAssertRealNear(0.0, flux, 1.0e-14,
"a reversed outlet face is clipped to zero flux"));
1640 "a clipped face's Ubcs has no normal component"));
1642 "a clipped face's Ubcs keeps both tangential components"));
1650 const PetscReal measured = s * ((area - 1.0) + 0.1);
1651 const PetscReal inflow = measured - s * 0.5 * area;
1652 PetscCall(VecSet(user->
Ucat, s));
1658 "a slow face is scaled, not reversed, when the correction would reverse it"));
1660 "an unclipped face keeps the copied Ubcs"));
1661 PetscCall(
PicurvAssertRealNear(inflow, total, 1.0e-12,
"the ratio rule conserves the inflow"));
1668 const PetscReal correction = -0.2;
1669 PetscCall(VecSet(user->
Ucat, s));
1670 PetscCall(DMGlobalToLocalBegin(user->
fda, user->
Ucat, INSERT_VALUES, user->
lUcat));
1671 PetscCall(DMGlobalToLocalEnd(user->
fda, user->
Ucat, INSERT_VALUES, user->
lUcat));
1674 PetscCall(
ApplyOutletAndMeasure(bc, &ctx, face, s * (area + correction * area), s * area, &flux, &ubcs, &total));
1675 PetscCheck(flux == s + ((s * (area + correction * area)) - s * area) / area * 1.0, PETSC_COMM_SELF, PETSC_ERR_PLIB,
1676 "an outlet with nothing reversed must keep the uniform correction exactly");
1683 PetscFunctionReturn(0);
1701 PetscInt ck, cj, ci, bk, bj, bi;
1702 PetscReal flux, total, area;
1705 PetscFunctionBeginUser;
1706 PetscCall(PetscMemzero(&ctx,
sizeof(ctx)));
1721 PetscCall(VecSet(user->
Ucat, 1.0));
1729 PetscCall(
PicurvAssertRealNear(0.0, flux, 1.0e-14,
"the clipped set is frozen within the step"));
1730 PetscCall(
PicurvAssertRealNear(area, total, 1.0e-12,
"a frozen clip still conserves the inflow"));
1740 PetscCall(
PicurvAssertRealNear(-0.5 + 1.5 / area, flux, 1.0e-14,
"the uniform rule is frozen within the step"));
1741 PetscCall(
PicurvAssertRealNear(area, total, 1.0e-12,
"the uniform rule conserves the inflow"));
1745 PetscCall(
PicurvAssertRealNear(0.0, flux, 1.0e-14,
"the next step clips the face that reversed"));
1750 PetscFunctionReturn(0);
1763 PetscFunctionBeginUser;
1765 PetscCall(VecSet(user->
Ucat, 4.0));
1766 PetscCall(VecSet(user->
Bcs.
Ubcs, 1.0));
1767 PetscCall(VecSet(user->
P, 3.0));
1768 PetscCall(VecSet(user->
Ucont, 7.0));
1773 "post-projection cell finalization must preserve non-periodic Ucont"));
1775 "constant pressure should remain unchanged during cell finalization"));
1777 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
Ucat, &ucat));
1778 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
lUcat, &lucat));
1780 "non-periodic Ucat dummy face should use Ubcs extrapolation"));
1782 "non-periodic local Ucat should contain the finalized dummy face"));
1783 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
Ucat, &ucat));
1784 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
lUcat, &lucat));
1787 PetscFunctionReturn(0);
1804 PetscBool x_periodic, y_periodic, z_periodic;
1806 {
"non-periodic", PETSC_FALSE, PETSC_FALSE, PETSC_FALSE},
1807 {
"xi-periodic", PETSC_TRUE, PETSC_FALSE, PETSC_FALSE},
1808 {
"fully-periodic", PETSC_TRUE, PETSC_TRUE, PETSC_TRUE },
1810 const PetscScalar sentinel = 7.0;
1812 PetscFunctionBeginUser;
1813 for (
size_t c = 0; c <
sizeof(configs) /
sizeof(configs[0]); ++c) {
1817 const PetscBool periodic[3] = {configs[c].x_periodic, configs[c].y_periodic, configs[c].z_periodic};
1822 configs[c].x_periodic,
1823 configs[c].y_periodic,
1824 configs[c].z_periodic));
1825 for (PetscInt axis = 0; axis < 3; ++axis) {
1831 PetscCall(VecDuplicate(user->
Ucont, &user->
Rhs));
1832 PetscCall(VecSet(user->
Rhs, sentinel));
1835 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
Rhs, &rhs));
1836 for (PetscInt k = user->
info.zs; k < user->
info.zs + user->
info.zm; ++k) {
1837 for (PetscInt j = user->
info.ys; j < user->
info.ys + user->
info.ym; ++j) {
1838 for (PetscInt i = user->
info.xs; i < user->
info.xs + user->
info.xm; ++i) {
1839 const PetscScalar *row = &rhs[k][j][i].
x;
1840 for (PetscInt component = 0; component < 3; ++component) {
1841 PetscInt ri, rj, rk;
1847 PetscCall(PetscSNPrintf(context,
sizeof(context),
1848 "%s: row (i=%d,j=%d,k=%d,c=%d) classified %d must be %s",
1849 configs[c].label, (
int)i, (
int)j, (
int)k, (
int)component, (
int)type,
1857 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
Rhs, &rhs));
1859 PetscCall(VecDestroy(&user->
Rhs));
1862 PetscFunctionReturn(0);
1878 PetscFunctionBeginUser;
1887 PetscFunctionReturn(0);
1899 Cmpnts ***ucat = NULL, ***csi = NULL, ***eta = NULL;
1900 PetscReal ***aj = NULL;
1901 DMDALocalInfo info = user->
info;
1903 PetscFunctionBeginUser;
1904 PetscCall(VecSet(user->
Aj, 1.0));
1905 PetscCall(DMDAVecGetArray(user->
fda, user->
Ucat, &ucat));
1906 PetscCall(DMDAVecGetArray(user->
fda, user->
Csi, &csi));
1907 PetscCall(DMDAVecGetArray(user->
fda, user->
Eta, &eta));
1908 PetscCall(DMDAVecGetArray(user->
da, user->
Aj, &aj));
1909 for (PetscInt k = info.zs; k < info.zs + info.zm; ++k)
1910 for (PetscInt j = info.ys; j < info.ys + info.ym; ++j)
1911 for (PetscInt i = info.xs; i < info.xs + info.xm; ++i) {
1912 ucat[k][j][i] = velocity;
1913 csi[k][j][i] = (
Cmpnts){.
x = 1.0, .y = 0.0, .z = 0.0};
1914 eta[k][j][i] = (
Cmpnts){.x = 0.0, .y = 1.0, .z = 0.0};
1917 PetscCall(DMDAVecRestoreArray(user->
da, user->
Aj, &aj));
1918 PetscCall(DMDAVecRestoreArray(user->
fda, user->
Eta, &eta));
1919 PetscCall(DMDAVecRestoreArray(user->
fda, user->
Csi, &csi));
1920 PetscCall(DMDAVecRestoreArray(user->
fda, user->
Ucat, &ucat));
1921 PetscCall(DMGlobalToLocalBegin(user->
da, user->
Aj, INSERT_VALUES, user->
lAj));
1922 PetscCall(DMGlobalToLocalEnd(user->
da, user->
Aj, INSERT_VALUES, user->
lAj));
1923 PetscCall(DMGlobalToLocalBegin(user->
fda, user->
Csi, INSERT_VALUES, user->
lCsi));
1924 PetscCall(DMGlobalToLocalEnd(user->
fda, user->
Csi, INSERT_VALUES, user->
lCsi));
1925 PetscCall(DMGlobalToLocalBegin(user->
fda, user->
Eta, INSERT_VALUES, user->
lEta));
1926 PetscCall(DMGlobalToLocalEnd(user->
fda, user->
Eta, INSERT_VALUES, user->
lEta));
1927 PetscFunctionReturn(PETSC_SUCCESS);
1945 Cmpnts ***ucat = NULL, ***ubcs = NULL;
1946 PetscReal ***utau = NULL;
1947 const PetscReal speed = 1.0;
1948 const PetscReal roughness = 1.0e-16;
1949 PetscReal kinematic_viscosity, distance_first, distance_second;
1950 PetscReal stored_utau, reference_check, first_speed, stored_stress;
1952 PetscReal untouched_before = 0.0, untouched_after = 0.0;
1954 PetscFunctionBeginUser;
1956 simCtx->
ren = 1000.0;
1958 kinematic_viscosity = 1.0 / simCtx->
ren;
1968 distance_first = 0.5;
1969 distance_second = 2.0 * distance_first + 0.5;
1973 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
Ucat, (
const Cmpnts ***)&ucat));
1974 untouched_before = ucat[2][2][1].
y;
1975 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
Ucat, (
const Cmpnts ***)&ucat));
1977 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
Ucat, (
const Cmpnts ***)&ucat));
1978 untouched_after = ucat[2][2][1].
y;
1979 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
Ucat, (
const Cmpnts ***)&ucat));
1981 "a disabled wall function must leave the velocity untouched"));
1987 PetscCall(DMDAVecGetArrayRead(user->
da, user->
Friction_Velocity, (
const PetscReal ***)&utau));
1988 stored_utau = utau[2][2][1];
1989 PetscCall(DMDAVecRestoreArrayRead(user->
da, user->
Friction_Velocity, (
const PetscReal ***)&utau));
1991 "the integration must store a positive friction velocity"));
1997 stored_utau, roughness);
1999 "the friction velocity must invert the log law at the "
2000 "reference cell's distance"));
2002 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
Ucat, (
const Cmpnts ***)&ucat));
2003 first_speed = ucat[2][2][1].
y;
2004 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
Ucat, (
const Cmpnts ***)&ucat));
2006 "the wall model must leave the resolved first-cell velocity untouched"));
2011 stored_stress = stress[2][2][0].
y;
2012 PetscCall(
PicurvAssertRealNear(0.0, stress[2][2][0].x, 0.0,
"the stress has no wall-normal part"));
2013 PetscCall(
PicurvAssertRealNear(0.0, stress[2][2][0].z, 0.0,
"the stress follows the flow direction"));
2016 "the stored stress must be u_tau^2 along the flow"));
2017 (void)distance_first;
2020 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
Bcs.
Ubcs, (
const Cmpnts ***)&ubcs));
2022 "the wall ghost row must carry a zero boundary velocity"));
2023 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
Bcs.
Ubcs, (
const Cmpnts ***)&ubcs));
2030 PetscFunctionReturn(0);
2044 PetscReal ***utau = NULL;
2045 PetscReal corrected[4] = {0.0, 0.0, 0.0, 0.0};
2048 PetscFunctionBeginUser;
2050 simCtx->
ren = 1000.0;
2055 for (PetscInt m = 0; m < 3; ++m) {
2059 PetscCall(DMDAVecGetArrayRead(user->
da, user->
Friction_Velocity, (
const PetscReal ***)&utau));
2060 corrected[m] = utau[2][2][1];
2061 PetscCall(DMDAVecRestoreArrayRead(user->
da, user->
Friction_Velocity, (
const PetscReal ***)&utau));
2062 PetscCall(
PicurvAssertBool((PetscBool)(corrected[m] > 0.0 && corrected[m] < 1.0),
2063 "every wall model must report a friction velocity below the flow speed"));
2067 PetscCall(
PicurvAssertBool((PetscBool)(PetscAbsReal(corrected[0] - corrected[1]) > 1.0e-9),
2068 "the Werner-Wengle model must differ from the log law"));
2069 PetscCall(
PicurvAssertBool((PetscBool)(PetscAbsReal(corrected[0] - corrected[2]) > 1.0e-9),
2070 "the Cabot model must differ from the log law"));
2077 PetscFunctionReturn(0);
2088 PetscReal before = 0.0, after = 0.0;
2090 PetscFunctionBeginUser;
2092 simCtx->
ren = 1000.0;
2099 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
Ucat, (
const Cmpnts ***)&ucat));
2100 before = ucat[2][2][1].
y;
2101 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
Ucat, (
const Cmpnts ***)&ucat));
2103 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
Ucat, (
const Cmpnts ***)&ucat));
2104 after = ucat[2][2][1].
y;
2105 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
Ucat, (
const Cmpnts ***)&ucat));
2108 "a face that is not a wall must not be corrected"));
2110 PetscReal stress_norm = 0.0;
2111 PetscCall(VecNorm(user->
Wall_Stress, NORM_INFINITY, &stress_norm));
2112 PetscCall(
PicurvAssertRealNear(0.0, stress_norm, 0.0,
"a face that is not a wall carries no wall stress"));
2120 PetscFunctionReturn(0);
2131 PetscReal before = 0.0, after = 0.0;
2133 PetscFunctionBeginUser;
2135 simCtx->
ren = 1000.0;
2143 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
Ucat, (
const Cmpnts ***)&ucat));
2144 before = ucat[2][2][1].
y;
2145 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
Ucat, (
const Cmpnts ***)&ucat));
2147 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
Ucat, (
const Cmpnts ***)&ucat));
2148 after = ucat[2][2][1].
y;
2149 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
Ucat, (
const Cmpnts ***)&ucat));
2152 PetscReal stress_norm = 0.0;
2153 PetscCall(VecNorm(user->
Wall_Stress, NORM_INFINITY, &stress_norm));
2154 PetscCall(
PicurvAssertRealNear(0.0, stress_norm, 0.0,
"a free-slip wall carries no wall stress"));
2162 PetscFunctionReturn(0);
2182 PetscReal ***utau = NULL;
2185 const char *names[3] = {
"the log law must respond to the flow it is given",
2186 "Werner-Wengle must respond to the flow it is given",
2187 "Cabot must respond to the flow it is given"};
2188 const PetscReal speeds[2] = {0.5, 2.0};
2190 PetscFunctionBeginUser;
2192 simCtx->
ren = 1000.0;
2197 for (PetscInt m = 0; m < 3; ++m) {
2198 PetscReal stored[2] = {0.0, 0.0};
2201 for (PetscInt s = 0; s < 2; ++s) {
2205 (
const PetscReal ***)&utau));
2206 stored[s] = utau[2][2][1];
2208 (
const PetscReal ***)&utau));
2210 "a wall law must report a positive friction velocity"));
2224 PetscFunctionReturn(0);
2242 PetscInt global_size = 0, local_size = 0;
2243 PetscInt xm = 0, ym = 0, zm = 0, gxm = 0, gym = 0, gzm = 0;
2244 PetscReal ***utau = NULL;
2246 PetscFunctionBeginUser;
2252 "the friction velocity is one scalar per cell"));
2254 "a scalar cell field belongs on the dof-1 DM"));
2259 "the catalog must resolve to the vectors setup allocated"));
2262 PetscCall(DMDAGetCorners(user->
da, NULL, NULL, NULL, &xm, &ym, &zm));
2263 PetscCall(DMDAGetGhostCorners(user->
da, NULL, NULL, NULL, &gxm, &gym, &gzm));
2267 "the global friction velocity must match the owned extent"));
2269 "the local friction velocity must match the ghosted extent"));
2278 "the wall stress is a vector on the dof-3 DM"));
2282 "the catalog must resolve to the wall-stress vectors setup allocated"));
2285 PetscCall(DMDAVecGetArray(user->
fda, user->
Wall_Stress, &stress));
2286 PetscCall(DMDAVecRestoreArray(user->
fda, user->
Wall_Stress, &stress));
2294 PetscFunctionReturn(0);
2310 Cmpnts ***ucat = NULL, ***stress = NULL;
2311 PetscReal ***utau = NULL;
2312 const PetscReal speed = 1.0;
2315 PetscFunctionBeginUser;
2317 simCtx->
ren = 1000.0;
2330 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
Ucat, (
const Cmpnts ***)&ucat));
2331 PetscCall(
PicurvAssertRealNear(speed, ucat[2][1][1].z, 0.0,
"the edge cell's resolved velocity must not move"));
2332 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
Ucat, (
const Cmpnts ***)&ucat));
2335 PetscCall(DMDAVecGetArrayRead(user->
da, user->
Friction_Velocity, (
const PetscReal ***)&utau));
2339 const PetscReal x_wall = stress[2][1][0].z;
2340 const PetscReal y_wall = stress[2][0][1].z;
2342 "both wall faces of the edge cell must carry a stress along the flow"));
2344 "each face must read its own unmodified reference, so the two agree"));
2346 "the edge cell's friction velocity is the RMS over its wall faces"));
2348 "the edge cell's -Xi stress must equal a mid-face element's"));
2350 PetscCall(DMDAVecRestoreArrayRead(user->
da, user->
Friction_Velocity, (
const PetscReal ***)&utau));
2355 (info.my - 2) * (info.mz - 2) + (info.mx - 2) * (info.mz - 2)),
2356 "each wall-face element must count once in the diagnostics"));
2363 PetscFunctionReturn(0);
2378 PetscReal kinematic_viscosity = 0.0;
2379 PetscReal expected_y_plus = 0.0;
2380 const PetscReal distance_first = 0.5;
2382 PetscFunctionBeginUser;
2384 simCtx->
ren = 1000.0;
2386 kinematic_viscosity = 1.0 / simCtx->
ren;
2395 "a disabled wall model must record no corrected cells"));
2400 "an enabled wall model must record the cells it corrected"));
2409 expected_y_plus, 1.0e-9,
2410 "y+ must be formed from the same distance the "
2411 "correction used"));
2414 distance_first, 1.0e-9,
2415 "the recorded wall distance must be the first cell's"));
2418 "the recorded extrema must bracket each other"));
2426 "each pass must replace the previous pass's sample set"));
2434 PetscFunctionReturn(0);
2451 PetscFunctionBeginUser;
2453 const DMDALocalInfo info = user->
info;
2454 const PetscInt mx = info.mx, my = info.my, mz = info.mz;
2455 PetscCall(VecSet(user->
Bcs.
Ubcs, 0.0));
2457 PetscReal ***p = NULL, ***psi = NULL;
2458 Cmpnts ***ucat = NULL, ***ubcs = NULL;
2460 PetscCall(DMDAVecGetArray(user->
da, user->
P, &p));
2461 PetscCall(DMDAVecGetArray(user->
da, user->
Psi, &psi));
2462 PetscCall(DMDAVecGetArray(user->
fda, user->
Ucat, &ucat));
2463 PetscCall(DMDAVecGetArray(user->
fda, user->
Bcs.
Ubcs, &ubcs));
2464 for (PetscInt k = info.zs; k < info.zs + info.zm; k++)
2465 for (PetscInt j = info.ys; j < info.ys + info.ym; j++)
2466 for (PetscInt i = info.xs; i < info.xs + info.xm; i++) {
2467 const PetscBool interior = (PetscBool)(i > 0 && i < mx - 1 && j > 0 && j < my - 1 && k > 0 && k < mz - 1);
2468 const PetscReal sentinel = 100.0 * k + 10.0 * j + i;
2470 p[k][j][i] = interior ? sentinel : -999.0;
2471 psi[k][j][i] = interior ? -sentinel : -999.0;
2472 ucat[k][j][i].
x = interior ? sentinel : -999.0;
2473 ucat[k][j][i].
y = interior ? 2.0 * sentinel : -999.0;
2474 ucat[k][j][i].
z = interior ? 3.0 * sentinel : -999.0;
2475 ubcs[k][j][i] = (
Cmpnts){1.0, 2.0, 3.0};
2477 PetscCall(DMDAVecRestoreArray(user->
fda, user->
Bcs.
Ubcs, &ubcs));
2478 PetscCall(DMDAVecRestoreArray(user->
fda, user->
Ucat, &ucat));
2479 PetscCall(DMDAVecRestoreArray(user->
da, user->
Psi, &psi));
2480 PetscCall(DMDAVecRestoreArray(user->
da, user->
P, &p));
2485 for (
size_t n = 0; n <
sizeof(scalars) /
sizeof(scalars[0]); ++n) {
2490 for (
size_t n = 0; n <
sizeof(scalars) /
sizeof(scalars[0]); ++n) {
2492 PetscReal ***f = NULL;
2495 PetscCall(DMDAVecGetArrayRead(user->
da, view.
global_vec, &f));
2496 for (PetscInt k = 1; k < mz - 1; k++)
for (PetscInt j = 1; j < my - 1; j++) {
2497 PetscCall(
PicurvAssertRealNear(f[k][j][1], f[k][j][0], 0.0,
"-x dummy copies the adjacent cell"));
2498 PetscCall(
PicurvAssertRealNear(f[k][j][mx - 2], f[k][j][mx - 1], 0.0,
"+x dummy copies the adjacent cell"));
2500 for (PetscInt k = 1; k < mz - 1; k++)
for (PetscInt i = 1; i < mx - 1; i++) {
2501 PetscCall(
PicurvAssertRealNear(f[k][1][i], f[k][0][i], 0.0,
"-y dummy copies the adjacent cell"));
2502 PetscCall(
PicurvAssertRealNear(f[k][my - 2][i], f[k][my - 1][i], 0.0,
"+y dummy copies the adjacent cell"));
2504 for (PetscInt j = 1; j < my - 1; j++)
for (PetscInt i = 1; i < mx - 1; i++) {
2505 PetscCall(
PicurvAssertRealNear(f[1][j][i], f[0][j][i], 0.0,
"-z dummy copies the adjacent cell"));
2506 PetscCall(
PicurvAssertRealNear(f[mz - 2][j][i], f[mz - 1][j][i], 0.0,
"+z dummy copies the adjacent cell"));
2508 for (PetscInt j = 0; j < my; j++) {
2510 "a (-z,-x) edge dummy is the mean of its face neighbours"));
2512 PetscCall(
PicurvAssertBool((PetscBool)(f[0][0][0] != -999.0 && f[mz - 1][my - 1][mx - 1] != -999.0),
2513 "corner dummies are written"));
2514 PetscCall(DMDAVecRestoreArrayRead(user->
da, view.
global_vec, &f));
2517 const Cmpnts ***ucat = NULL;
2519 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
Ucat, &ucat));
2520 for (PetscInt k = 1; k < mz - 1; k++)
for (PetscInt j = 1; j < my - 1; j++) {
2522 "a velocity dummy puts the face average on Ubcs"));
2523 PetscCall(
PicurvAssertRealNear(3.0, 0.5 * (ucat[k][j][mx - 1].z + ucat[k][j][mx - 2].z), 1.0e-12,
2524 "a velocity dummy puts the face average on Ubcs"));
2526 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
Ucat, &ucat));
2530 PetscErrorCode refused;
2532 PetscCall(PetscPushErrorHandler(PetscIgnoreErrorHandler, NULL));
2534 PetscCall(PetscPopErrorHandler());
2535 PetscCall(
PicurvAssertIntEqual(PETSC_ERR_SUP, refused,
"a field with no boundary rule is refused"));
2536 PetscCall(PetscPushErrorHandler(PetscIgnoreErrorHandler, NULL));
2538 PetscCall(PetscPopErrorHandler());
2539 PetscCall(
PicurvAssertIntEqual(PETSC_ERR_ARG_WRONG, refused,
"a field that is not cell-centred is refused"));
2543 PetscFunctionReturn(0);
2552 PetscErrorCode ierr;
2591 ierr = PetscInitialize(&argc, &argv, NULL,
"PICurv boundary tests");
2596 ierr =
PicurvRunTests(
"unit-boundaries", cases,
sizeof(cases) /
sizeof(cases[0]));
2602 ierr = PetscFinalize();
PetscErrorCode LogPrescribedFlowDiagnostics(UserCtx *user)
Appends each prescribed-velocity inlet's flow rate and mean normal speed this step to inlet_flow....
MomentumRowType
Classification of one staggered momentum row (location + component).
@ MOM_ROW_PHYSICAL
Independent unknown governed by the momentum equation.
PetscErrorCode ApplyWallFunction(UserCtx *user)
Evaluates the selected wall law on every wall-face element and stores the wall stress.
MomentumRowType ClassifyMomentumRow(UserCtx *user, PetscInt i, PetscInt j, PetscInt k, PetscInt component, PetscInt *ri, PetscInt *rj, PetscInt *rk)
Single source of truth for "which staggered momentum rows are unknowns".
PetscBool BoundaryFaceHasWallShear(const BoundaryFaceConfig *face)
Reports whether a boundary face is a wall that exerts shear on the flow.
PetscErrorCode EnforceRHSBoundaryConditions(UserCtx *user)
Zeroes every momentum RHS row that does not carry an independent unknown.
PetscErrorCode UpdateDummyCells(UserCtx *user, FieldId field_id)
Fills the dummy cells on the non-periodic faces of one cell-centred field.
PetscErrorCode BoundaryCondition_Create(BCHandlerType handler_type, BoundaryCondition **new_bc_ptr)
(Private) Creates and configures a specific BoundaryCondition handler object.
PetscErrorCode FinalizePostProjectionCellFields(UserCtx *user)
Finalizes cell-centered fields after the projection step.
PetscErrorCode UpdateCornerNodes(UserCtx *user, FieldId field_id)
Fills the edge and corner dummy cells of one cell-centred field.
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 FieldGetView(UserCtx *user, FieldId field_id, FieldView *view)
Resolve the existing DM and global/local vectors for one field.
PetscErrorCode FieldGetDescriptor(FieldId field_id, const FieldDescriptor **descriptor)
Return immutable metadata for a valid field identifier.
FieldId
Compile-time identity for a catalogued Eulerian field.
Immutable metadata for one field identity.
Non-owning runtime objects resolved for one field and UserCtx.
PetscErrorCode CalculateFaceCenterAndArea(UserCtx *user, BCFace face_id, Cmpnts *face_center, PetscReal *face_area)
Calculates the geometric center and total area of a specified boundary face.
void FreeBC_ParamList(BC_Param *head)
Frees an entire linked list of boundary-condition parameters.
PetscErrorCode PicurvPhysicalTime(const SimCtx *simCtx, PetscReal solver_time, PetscReal *physical)
Convert a solver time to physical seconds, t * L_ref / U_ref.
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)
static PetscErrorCode TestOutletConservationHandlerFaceMatrix(void)
Tests outlet-conservation correction and flux accounting across all outlet faces.
static PetscErrorCode TestCanRankServiceFaceMatchesInletWhenDefined(void)
Tests that face-service detection matches a defined inlet face.
static PetscErrorCode TestInletCommonApplicationCurvilinearMetric(void)
Verifies curvilinear projection and Cartesian dummy reflection for the shared inlet path.
static PetscErrorCode TestInletNormalSourceBehavior(void)
Tests a constant normal-speed source's face writes and flux on a Z inlet.
static PetscErrorCode ConfigureNormalSourceInlet(UserCtx *user, BCFace face, const char *speed)
Configures face as a prescribed-velocity inlet with source 0 in the normal frame.
static PetscErrorCode ApplyInletAcrossFirstSteps(BoundaryCondition *bc, BCContext *ctx)
Reapplies a static inlet through the first three time-step contexts.
static PetscErrorCode TestBoundaryConditionFactoryAssignments(void)
Tests the boundary-condition factory assignments for representative handlers.
static PetscErrorCode AppendBCParam(BC_Param **head, const char *key, const char *value)
Appends one key/value pair to a linked list of boundary-condition parameters.
static PetscErrorCode TestApplyWallFunctionMatchesTheLogLawItDispatches(void)
Tests that the wall-function integration reproduces the model it dispatches to.
static PetscReal GetFaceInteriorPointCount(const UserCtx *user, BCFace face)
Computes the number of face-interior sample points for a given boundary face.
static PetscErrorCode TestWallMovingAlongItself(void)
Tests a moving wall on both a - and a + face: its velocity along the wall reaches the boundary value ...
static PetscErrorCode TestDummyCellsFollowEachFieldsBoundaryRule(void)
Checks each cell-centred field's dummy-cell rule, faces then edges.
int main(int argc, char **argv)
Runs the unit-boundaries PETSc test binary.
static PetscErrorCode TestInletSourceAddsToPicSlice(void)
Tests expressions added to a profile file: a bulk velocity scales the expressions and leaves the file...
static PetscErrorCode TestWallModelDiagnosticsRecordTheCorrectedCells(void)
Tests that the wall pass records the statistics its diagnostics report.
static PetscErrorCode TestInletSourceFollowsTimeAndBulkVelocity(void)
Tests that a source in t is re-evaluated once per step, and that a bulk velocity rescales the face to...
static PetscReal GetFaceOrientationSign(BCFace face)
Returns the sign convention used for face-normal flux expectations.
static PetscErrorCode TestInletParabolicSourceBehavior(void)
Tests a parabola written in the arc-length fractions on a tiny Z-face.
static PetscErrorCode SeedWallFrictionVelocityStorage(UserCtx *user)
Allocates the wall-model storage the way production allocates it.
static PetscErrorCode TestOutletConservationBackflowClip(void)
Tests the conservation outlet's backflow clip on +X, +Y, +Z and on -X, -Z.
static PetscErrorCode TestOutletConservationClipFrozenPerStep(void)
Tests that the backflow clip's rule and clipped set are frozen within a time step.
static PetscErrorCode TestInletRecordingOfCartesianVelocities(void)
Tests a recording of Cartesian velocities: every component reaches the boundary, reversed flow is all...
static PetscErrorCode TestBoundaryConditionFactoryRejectsUnsupportedHandler(void)
Tests that unsupported handler types are rejected by the factory.
static PetscErrorCode TestApplyWallFunctionSkipsFreeSlipWalls(void)
Tests that the wall model leaves a free-slip wall alone.
static PetscErrorCode TestInletFlowRateAndFaceRadius(void)
Tests that a flow-rate target sets the face's total flux, whatever its area, and that r is the distan...
static PetscErrorCode TestWallFunctionModelSelectorChoosesTheLaw(void)
Tests that the model selector actually changes which law is applied.
static PetscErrorCode TestFreeSlipWallExertsNoShear(void)
Tests which faces exert shear, and that only a free-slip wall mirrors the eddy viscosity.
static PetscErrorCode TestBoundaryConditionFactoryImplementedHandlerMatrix(void)
Tests the implemented-handler matrix exposed by the factory.
static PetscErrorCode WritePicSliceForTests(const char *path, PetscInt n1, PetscInt n2, PetscReal base)
Writes a tiny canonical PICSLICE profile for boundary handler tests.
static PetscErrorCode TestWallFreeSlipHandlerFaceMatrix(void)
Tests the free-slip wall across the full face matrix on a Cartesian grid.
static PetscErrorCode TestInletPicSliceSourceBehavior(void)
Tests a prescribed-velocity inlet loading and applying one Z-face PICSLICE profile.
static PetscErrorCode TestWallNoSlipHandlerFaceMatrix(void)
Tests wall no-slip application across the full face matrix.
static PetscErrorCode TestWallModelEdgeCellHasOneStressPerWall(void)
Tests that a cell beside two walls gets one independent stress per wall face.
static PetscErrorCode SeedWallFunctionFixture(UserCtx *user, Cmpnts velocity)
Seeds the fields ApplyWallFunction() reads, for walls on xi and eta faces.
static PetscErrorCode TestFinalizePostProjectionCellFieldsNonPeriodic(void)
Tests non-periodic cell-field finalization without modifying Ucont.
static PetscErrorCode ApplyHandlerAtTime(BoundaryCondition *bc, BCContext *ctx, PetscInt step, PetscReal physical_time)
Runs the handler at one time as a new step of its own.
static PetscErrorCode TestWallModelFrictionVelocityRespondsToTheFlow(void)
Tests that every wall law's friction velocity responds to the flow it is given.
static PetscErrorCode TestWallFreeSlipCurvilinearNormal(void)
Tests the free-slip wall against a face whose normal is not a grid axis.
static PetscErrorCode DestroyBoundaryHandler(BoundaryCondition **bc_ptr)
Destroys one boundary-condition handler allocated by a boundary test.
static PetscErrorCode TestInletOneAxisSourceIsUniformAlongTheOther(void)
Tests that a profile in one fraction is uniform along the other tangential axis.
static PetscErrorCode TestApplyWallFunctionSkipsNonWallFaces(void)
Tests that a face which is not a wall is left alone by the wall function.
static PetscErrorCode TestOutletConservationHandlerBehavior(void)
Tests outlet conservation handler correction and post-step flux accounting.
static PetscErrorCode TestInletNormalSourceFaceMatrix(void)
Tests a constant normal-speed source's flux accounting and face writes across all faces.
static void ResetBoundaryFaceConfig(BoundaryFaceConfig *cfg)
Resets one boundary-face configuration entry to a neutral test-local baseline.
static PetscErrorCode SetCellNormalVelocity(UserCtx *user, BCFace face, PetscInt k, PetscInt j, PetscInt i, PetscReal value)
Sets the face-normal Ucat component of one cell and refreshes lUcat.
static PetscErrorCode SetUniformCartesian(Vec v, PetscReal x, PetscReal y, PetscReal z)
Sets every entry of a three-component vector to one Cartesian value.
static PetscErrorCode TestInletParabolicSourceFaceMatrix(void)
Tests a parabola in each face's two tangential fractions across all faces: its centreline,...
static PetscReal GetFaceNormalComponent(Cmpnts value, BCFace face)
Extracts the velocity component aligned with the supplied boundary-face normal.
static PetscInt InteriorSampleIndex(PetscInt nodes)
Chooses a stable interior node index for face-sample assertions on tiny test grids.
static PetscErrorCode TestEnforceRHSBoundaryConditionsMatchesRowClassification(void)
EnforceRHSBoundaryConditions() must zero a row exactly when it is not an unknown.
static PetscErrorCode ApplyOutletAndMeasure(BoundaryCondition *bc, BCContext *ctx, BCFace face, PetscReal inflow, PetscReal outflow_measured, PetscReal *sample_flux, Cmpnts *sample_ubcs, PetscReal *total)
Runs one outlet Apply with the given sums and returns the face's sample flux and total.
static PetscErrorCode GetRepresentativeFaceSlots(const UserCtx *user, BCFace face, PetscInt *ucont_k, PetscInt *ucont_j, PetscInt *ucont_i, PetscInt *ubcs_k, PetscInt *ubcs_j, PetscInt *ubcs_i)
Selects representative Ucont and Ubcs slots for face-matrix assertions.
static PetscErrorCode TestWallFrictionVelocityStorageMatchesTheCatalog(void)
Tests that the friction-velocity storage matches what the field catalog declares.
static PetscErrorCode GetParabolicSampleSlots(const UserCtx *user, BCFace face, PetscInt *center_k, PetscInt *center_j, PetscInt *center_i, PetscInt *off_k, PetscInt *off_j, PetscInt *off_i, PetscInt *wall_k, PetscInt *wall_j, PetscInt *wall_i, PetscInt *ubcs_center_k, PetscInt *ubcs_center_j, PetscInt *ubcs_center_i)
Selects center, off-center, and wall-adjacent slots for parabolic-face checks.
PetscErrorCode PicurvCreateMinimalContexts(SimCtx **simCtx_out, UserCtx **user_out, PetscInt mx, PetscInt my, PetscInt mz)
Builds minimal SimCtx and UserCtx fixtures for C unit tests.
PetscErrorCode PicurvAssertRealNear(PetscReal expected, PetscReal actual, PetscReal tol, const char *context)
Asserts that two real values agree within tolerance.
PetscErrorCode PicurvDestroyMinimalContexts(SimCtx **simCtx_ptr, UserCtx **user_ptr)
Destroys minimal SimCtx/UserCtx fixtures and all owned PETSc objects.
PetscErrorCode PicurvCreateMinimalContextsWithPeriodicity(SimCtx **simCtx_out, UserCtx **user_out, PetscInt mx, PetscInt my, PetscInt mz, PetscBool x_periodic, PetscBool y_periodic, PetscBool z_periodic)
Builds minimal SimCtx and UserCtx fixtures for C unit tests with configurable periodicity.
PetscErrorCode PicurvRunTests(const char *suite_name, const PicurvTestCase *cases, size_t case_count)
Runs a named C test suite and prints pass/fail progress markers.
PetscErrorCode PicurvAssertVecConstant(Vec vec, PetscScalar expected, PetscReal tol, const char *context)
Asserts that a PETSc vector is spatially constant within tolerance.
PetscErrorCode PicurvAssertIntEqual(PetscInt expected, PetscInt actual, const char *context)
Asserts that two integer values are equal.
PetscErrorCode PicurvPopulateIdentityMetrics(UserCtx *user)
Populates identity metric vectors on the minimal grid fixture.
PetscErrorCode PicurvAssertBool(PetscBool value, const char *context)
Asserts that one boolean condition is true.
Shared declarations for the PICurv C test fixture and assertion layer.
Named test case descriptor consumed by PicurvRunTests.
const PetscReal * global_outflow_sum
BCType
Defines the general mathematical/physical Category of a boundary.
BoundaryFaceConfig boundary_faces[6]
SimCtx * simCtx
Back-pointer to the master simulation context.
BCHandlerType
Defines the specific computational "strategy" for a boundary handler.
@ BC_HANDLER_INLET_PRESCRIBED_VELOCITY
@ BC_HANDLER_OUTLET_CONSERVATION
@ BC_HANDLER_WALL_FREE_SLIP
@ BC_HANDLER_OUTLET_PRESSURE
BCHandlerType handler_type
const PetscReal * global_farfield_outflow_sum
Vec Ubcs
Physical Cartesian velocity at boundary faces. Full 3D array but only boundary-face entries are meani...
PetscReal wall_distance_sum
Sum of the first-cell wall distance.
PetscReal friction_velocity_min
Smallest u_tau this rank corrected.
const PetscReal * global_inflow_sum
char analysis_dir[PETSC_MAX_PATH_LEN]
PetscReal friction_velocity_max
Largest u_tau this rank corrected.
PetscReal y_plus_sum
Sum of u_tau * y / nu over corrected cells.
PetscReal wall_roughness_height
PetscReal friction_velocity_sum
Sum of u_tau over corrected cells.
PetscInt wallfunction
Enable wall functions on WALL faces.
const PetscReal * global_farfield_inflow_sum
PetscInt cells
Number of cells this rank corrected.
BCFace
Identifies the six logical faces of a structured computational block.
WallModelDiagnosticsState wall_diagnostics
Near-wall statistics from the last wall-model pass.
BoundaryCondition * handler
Provides execution context for a boundary condition handler.
A node in a linked list for storing key-value parameters from the bcs.dat file.
Holds the complete configuration for one of the six boundary faces.
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.
A generic C-style linked list node for integers.
double u_hydset_roughness(double kinematic_viscosity, double wall_distance, double friction_velocity, double roughness_height)
Computes velocity from log-law for rough walls.
double nu_t(double yplus)
Computes turbulent eddy viscosity ratio (ν_t / ν)