25 PetscFunctionBeginUser;
26 PetscCall(DMGlobalToLocalBegin(user->
da, user->
P, INSERT_VALUES, user->
lP));
27 PetscCall(DMGlobalToLocalEnd(user->
da, user->
P, INSERT_VALUES, user->
lP));
28 PetscCall(DMGlobalToLocalBegin(user->
da, user->
Psi, INSERT_VALUES, user->
lPsi));
29 PetscCall(DMGlobalToLocalEnd(user->
da, user->
Psi, INSERT_VALUES, user->
lPsi));
32 PetscCall(DMGlobalToLocalBegin(user->
fda, user->
Ucat, INSERT_VALUES, user->
lUcat));
33 PetscCall(DMGlobalToLocalEnd(user->
fda, user->
Ucat, INSERT_VALUES, user->
lUcat));
34 PetscCall(DMGlobalToLocalBegin(user->
fda, user->
Ucont, INSERT_VALUES, user->
lUcont));
35 PetscCall(DMGlobalToLocalEnd(user->
fda, user->
Ucont, INSERT_VALUES, user->
lUcont));
38 PetscFunctionReturn(0);
54 PetscInt status_value)
56 PetscReal *positions = NULL;
57 PetscReal *weights = NULL;
58 PetscInt *cell_ids = NULL;
59 PetscInt *status = NULL;
61 PetscFunctionBeginUser;
62 PetscCall(DMSwarmGetField(user->
swarm,
"position", NULL, NULL, (
void **)&positions));
63 PetscCall(DMSwarmGetField(user->
swarm,
"weight", NULL, NULL, (
void **)&weights));
64 PetscCall(DMSwarmGetField(user->
swarm,
"DMSwarm_CellID", NULL, NULL, (
void **)&cell_ids));
65 PetscCall(DMSwarmGetField(user->
swarm,
"DMSwarm_location_status", NULL, NULL, (
void **)&status));
76 status[0] = status_value;
78 PetscCall(DMSwarmRestoreField(user->
swarm,
"DMSwarm_location_status", NULL, NULL, (
void **)&status));
79 PetscCall(DMSwarmRestoreField(user->
swarm,
"DMSwarm_CellID", NULL, NULL, (
void **)&cell_ids));
80 PetscCall(DMSwarmRestoreField(user->
swarm,
"weight", NULL, NULL, (
void **)&weights));
81 PetscCall(DMSwarmRestoreField(user->
swarm,
"position", NULL, NULL, (
void **)&positions));
82 PetscFunctionReturn(0);
90 PetscInt particles_per_rank = -1;
91 PetscInt remainder = -1;
93 PetscFunctionBeginUser;
95 PetscCall(
PicurvAssertIntEqual(4, particles_per_rank,
"rank 0 should receive one remainder particle"));
99 PetscCall(
PicurvAssertIntEqual(3, particles_per_rank,
"last rank should receive base particle count"));
100 PetscCall(
PicurvAssertIntEqual(1, remainder,
"remainder should remain unchanged across ranks"));
101 PetscFunctionReturn(0);
112 PetscFunctionBeginUser;
113 PetscCall(PetscMemzero(&bbox,
sizeof(bbox)));
132 PetscFunctionReturn(0);
141 PetscReal distances[
NUM_FACES] = {1.0, 3.0, 2.0, 2.0, 4.0, 1.0};
142 PetscReal clamped[
NUM_FACES] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
144 PetscFunctionBeginUser;
145 PetscCall(PetscMemzero(&particle,
sizeof(particle)));
155 PetscFunctionReturn(0);
167 PetscFunctionBeginUser;
171 PetscCall(PetscMemzero(&particle,
sizeof(particle)));
172 particle.
loc.
x = 1.0;
173 particle.
loc.
y = -2.0;
174 particle.
loc.
z = 3.0;
175 particle.
vel.
x = 0.5;
176 particle.
vel.
y = -1.0;
177 particle.
vel.
z = 2.0;
189 PetscFunctionReturn(0);
201 PetscFunctionBeginUser;
205 PetscCall(PetscMemzero(&particle,
sizeof(particle)));
206 particle.
loc.
x = 0.25;
207 particle.
loc.
y = 0.5;
208 particle.
loc.
z = 0.75;
209 particle.
vel.
x = 0.0;
210 particle.
vel.
y = 0.0;
211 particle.
vel.
z = 0.0;
223 PetscFunctionReturn(0);
232 const PetscReal dt = 0.5;
233 const PetscReal diffusivity = 0.2;
234 const PetscReal mean_val = 3.0;
235 const PetscReal cell_vol = 8.0;
236 const PetscReal c_model = 2.0;
237 PetscReal unchanged = 7.0;
239 PetscFunctionBeginUser;
242 mean_val + (1.0 - mean_val) * PetscExpReal(-(c_model * diffusivity / PetscPowReal(cell_vol, 0.6666667)) * dt),
245 "IEM update should match analytical relaxation"));
248 PetscCall(
PicurvAssertRealNear(7.0, unchanged, 1.0e-12,
"unknown field should remain unchanged"));
249 PetscFunctionReturn(0);
261 PetscFunctionBeginUser;
263 PetscCall(DMDAVecGetArray(user->
fda, user->
Ucat, &ucat));
264 for (PetscInt k = 0; k < 6; k++)
265 for (PetscInt j = 0; j < 6; j++)
266 for (PetscInt i = 0; i < 6; i++)
267 ucat[k][j][i] = (
Cmpnts){(PetscReal)i, 2.0, 3.0};
268 PetscCall(DMDAVecRestoreArray(user->
fda, user->
Ucat, &ucat));
272 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
Ucont, &ucont));
274 "Xi flux uses face-interpolated Ucat"));
276 "Eta flux uses Cartesian y velocity"));
278 "Zeta flux uses Cartesian z velocity"));
279 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
Ucont, &ucont));
282 PetscFunctionReturn(0);
290 PetscFunctionBeginUser;
295 PetscCall(VecSet(user->
Ucat,0.0));
296 PetscCall(DMDAVecGetArray(user->
fda,user->
Ucat,&ucat));
297 for(PetscInt k=1;k<user->
info.mz-1;k++)
for(PetscInt j=1;j<user->
info.my-1;j++)
298 for(PetscInt i=1;i<mx-1;i++) ucat[k][j][i]=(
Cmpnts){10.0+(PetscReal)i,2.0,3.0};
299 ucat[2][2][0]=(
Cmpnts){-1000.0,-1000.0,-1000.0};
300 ucat[2][2][mx-1]=(
Cmpnts){-2000.0,-2000.0,-2000.0};
301 PetscCall(DMDAVecRestoreArray(user->
fda,user->
Ucat,&ucat));
306 PetscCall(DMDAVecGetArrayRead(user->
fda,user->
Ucont,&ucont));
307 PetscCall(
PicurvAssertRealNear(0.5*((10.0+mx-2)+(10.0+1)),ucont[2][2][mx-2].x,1e-12,
"terminal Xi face uses corrected periodic Ucat endpoint"));
308 PetscCall(DMDAVecRestoreArrayRead(user->
fda,user->
Ucont,&ucont));
310 PetscFunctionReturn(0);
321 char tmpdir[PETSC_MAX_PATH_LEN];
323 PetscFunctionBeginUser;
326 PetscCall(VecSet(user->
Ucat, 2.5));
332 PetscCall(VecZeroEntries(user->
Ucat));
333 PetscCall(VecZeroEntries(user->
Ucont));
340 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
Ucont, &ucont));
341 PetscCall(
PicurvAssertRealNear(2.5, ucont[1][1][1].x, 1.0e-12,
"file Ucat IC should populate interior Xi flux"));
342 PetscCall(
PicurvAssertRealNear(2.5, ucont[1][1][1].y, 1.0e-12,
"file Ucat IC should populate interior Eta flux"));
343 PetscCall(
PicurvAssertRealNear(2.5, ucont[1][1][1].z, 1.0e-12,
"file Ucat IC should populate interior Zeta flux"));
344 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
Ucont, &ucont));
347 PetscFunctionReturn(0);
355 char tmpdir[PETSC_MAX_PATH_LEN];
356 char euler_dir[PETSC_MAX_PATH_LEN];
357 char block_dir[PETSC_MAX_PATH_LEN];
359 PetscFunctionBeginUser;
361 &simCtx, &user, 4, 4, 4, PETSC_TRUE, PETSC_TRUE, PETSC_TRUE));
362 PetscCall(DMCreateGlobalVector(user->
da, &user->
CS));
363 PetscCall(DMCreateLocalVector(user->
da, &user->
lCs));
364 PetscCall(DMCreateGlobalVector(user->
da, &user->
Nu_t));
365 PetscCall(DMCreateLocalVector(user->
da, &user->
lNu_t));
366 PetscCall(VecSet(user->
CS, 0.0));
367 PetscCall(VecSet(user->
lCs, 2.5));
368 PetscCall(VecSet(user->
Nu_t, 0.0));
369 PetscCall(VecSet(user->
lNu_t, 7.5));
373 PetscCall(PetscSNPrintf(euler_dir,
sizeof(euler_dir),
"%s/eulerian", tmpdir));
374 PetscCall(PetscSNPrintf(block_dir,
sizeof(block_dir),
"%s/block_0000", euler_dir));
380 "checkpoint output should copy owned periodic lCs values"));
382 "checkpoint output should copy owned periodic lNu_t values"));
386 PetscFunctionReturn(0);
402 PetscReal *max_divergence)
405 Cmpnts ***ucat = NULL, ***ucont = NULL;
406 PetscInt n_x = user->
info.mx - 2, n_y = user->
info.my - 2, n_z = user->
info.mz - 2;
409 PetscFunctionBeginUser;
410 PetscCall(VecZeroEntries(user->
Ucat));
411 PetscCall(DMDAVecGetArray(user->
fda, user->
Ucat, &ucat));
412 for (PetscInt k = 0; k < user->
info.mz; ++k) {
413 for (PetscInt j = 0; j < user->
info.my; ++j) {
414 for (PetscInt i = 0; i < user->
info.mx; ++i) {
415 PetscReal phase = 2.0 * PETSC_PI * (
416 (PetscReal)(mode_x * (i - 1)) / (PetscReal)n_x +
417 (PetscReal)(mode_y * (j - 1)) / (PetscReal)n_y +
418 (PetscReal)(mode_z * (k - 1)) / (PetscReal)n_z);
419 PetscReal wave = PetscCosReal(phase);
420 ucat[k][j][i] = (
Cmpnts){amplitude.
x * wave, amplitude.
y * wave, amplitude.
z * wave};
424 PetscCall(DMDAVecRestoreArray(user->
fda, user->
Ucat, &ucat));
430 PetscCall(VecZeroEntries(user->
Ucat));
431 PetscCall(VecZeroEntries(user->
Ucont));
436 *max_divergence = 0.0;
437 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
lUcont, &ucont));
438 for (PetscInt k = 1; k < user->
info.mz - 1; ++k) {
439 for (PetscInt j = 1; j < user->
info.my - 1; ++j) {
440 for (PetscInt i = 1; i < user->
info.mx - 1; ++i) {
441 PetscReal divergence =
442 ucont[k][j][i].x - ucont[k][j][i - 1].x +
443 ucont[k][j][i].y - ucont[k][j - 1][i].y +
444 ucont[k][j][i].z - ucont[k - 1][j][i].z;
445 *max_divergence = PetscMax(*max_divergence, PetscAbsReal(divergence));
449 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
lUcont, &ucont));
450 PetscFunctionReturn(0);
458 char tmpdir[PETSC_MAX_PATH_LEN];
459 PetscReal max_divergence = 0.0, sx, sy, sz;
462 PetscFunctionBeginUser;
464 &simCtx, &user, 9, 9, 9, PETSC_TRUE, PETSC_TRUE, PETSC_TRUE));
465 for (PetscInt face = 0; face <
NUM_FACES; ++face)
473 user, 1, 0, 0, (
Cmpnts){0.0, 1.0, 0.0}, tmpdir, &max_divergence));
475 "axis-aligned transverse staged mode"));
477 n = user->
info.mx - 2;
478 sx = PetscSinReal(2.0 * PETSC_PI / (PetscReal)n);
479 sy = PetscSinReal(4.0 * PETSC_PI / (PetscReal)n);
480 sz = PetscSinReal(6.0 * PETSC_PI / (PetscReal)n);
482 user, 1, 2, 0, (
Cmpnts){sy, -sx, 0.0}, tmpdir, &max_divergence));
484 "oblique first discrete transverse polarization"));
487 (
Cmpnts){sz * sx, sz * sy, -(sx * sx + sy * sy)},
488 tmpdir, &max_divergence));
490 "oblique second discrete transverse polarization"));
494 PetscFunctionReturn(0);
504 char tmpdir[PETSC_MAX_PATH_LEN];
506 PetscFunctionBeginUser;
509 PetscCall(VecSet(user->
Ucont, 4.5));
515 PetscCall(VecZeroEntries(user->
Ucont));
524 PetscFunctionReturn(0);
535 PetscReal *velocity = NULL;
536 PetscReal *diffusivity = NULL;
537 PetscReal *diffusivity_gradient = NULL;
539 PetscFunctionBeginUser;
542 PetscCall(VecSet(user->
Ucat, 2.0));
546 for (PetscInt k = user->
info.zs; k < user->
info.zs + user->
info.zm; ++k) {
547 for (PetscInt j = user->
info.ys; j < user->
info.ys + user->
info.ym; ++j) {
548 for (PetscInt i = user->
info.xs; i < user->
info.xs + user->
info.xm; ++i) {
549 grad[k][j][i].
x = 0.1;
550 grad[k][j][i].
y = 0.2;
551 grad[k][j][i].
z = 0.3;
557 PetscCall(
SeedSingleParticle(user, 0, 0, 0, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5,
ACTIVE_AND_LOCATED));
561 PetscCall(DMSwarmGetField(user->
swarm,
"velocity", NULL, NULL, (
void **)&velocity));
562 PetscCall(DMSwarmGetField(user->
swarm,
"Diffusivity", NULL, NULL, (
void **)&diffusivity));
563 PetscCall(DMSwarmGetField(user->
swarm,
"DiffusivityGradient", NULL, NULL, (
void **)&diffusivity_gradient));
564 PetscCall(
PicurvAssertRealNear(2.0, velocity[0], 1.0e-12,
"Interpolated velocity x should match constant Eulerian field"));
565 PetscCall(
PicurvAssertRealNear(2.0, velocity[1], 1.0e-12,
"Interpolated velocity y should match constant Eulerian field"));
566 PetscCall(
PicurvAssertRealNear(2.0, velocity[2], 1.0e-12,
"Interpolated velocity z should match constant Eulerian field"));
567 PetscCall(
PicurvAssertRealNear(0.25, diffusivity[0], 1.0e-12,
"Interpolated scalar diffusivity should match constant Eulerian field"));
568 PetscCall(
PicurvAssertRealNear(0.1, diffusivity_gradient[0], 1.0e-12,
"Interpolated diffusivity-gradient x component"));
569 PetscCall(
PicurvAssertRealNear(0.2, diffusivity_gradient[1], 1.0e-12,
"Interpolated diffusivity-gradient y component"));
570 PetscCall(
PicurvAssertRealNear(0.3, diffusivity_gradient[2], 1.0e-12,
"Interpolated diffusivity-gradient z component"));
571 PetscCall(DMSwarmRestoreField(user->
swarm,
"DiffusivityGradient", NULL, NULL, (
void **)&diffusivity_gradient));
572 PetscCall(DMSwarmRestoreField(user->
swarm,
"Diffusivity", NULL, NULL, (
void **)&diffusivity));
573 PetscCall(DMSwarmRestoreField(user->
swarm,
"velocity", NULL, NULL, (
void **)&velocity));
576 PetscFunctionReturn(0);
587 PetscReal *velocity = NULL;
588 PetscReal *diffusivity = NULL;
589 PetscReal *diffusivity_gradient = NULL;
591 PetscFunctionBeginUser;
595 PetscCall(VecSet(user->
Ucat, 2.0));
599 for (PetscInt k = user->
info.zs; k < user->
info.zs + user->
info.zm; ++k) {
600 for (PetscInt j = user->
info.ys; j < user->
info.ys + user->
info.ym; ++j) {
601 for (PetscInt i = user->
info.xs; i < user->
info.xs + user->
info.xm; ++i) {
602 grad[k][j][i].
x = 0.1;
603 grad[k][j][i].
y = 0.2;
604 grad[k][j][i].
z = 0.3;
610 PetscCall(
SeedSingleParticle(user, 0, 0, 0, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5,
ACTIVE_AND_LOCATED));
614 PetscCall(DMSwarmGetField(user->
swarm,
"velocity", NULL, NULL, (
void **)&velocity));
615 PetscCall(DMSwarmGetField(user->
swarm,
"Diffusivity", NULL, NULL, (
void **)&diffusivity));
616 PetscCall(DMSwarmGetField(user->
swarm,
"DiffusivityGradient", NULL, NULL, (
void **)&diffusivity_gradient));
617 PetscCall(
PicurvAssertRealNear(2.0, velocity[0], 1.0e-12,
"CornerAveraged: interpolated velocity x should match constant Eulerian field"));
618 PetscCall(
PicurvAssertRealNear(2.0, velocity[1], 1.0e-12,
"CornerAveraged: interpolated velocity y should match constant Eulerian field"));
619 PetscCall(
PicurvAssertRealNear(2.0, velocity[2], 1.0e-12,
"CornerAveraged: interpolated velocity z should match constant Eulerian field"));
620 PetscCall(
PicurvAssertRealNear(0.25, diffusivity[0], 1.0e-12,
"CornerAveraged: interpolated scalar diffusivity should match constant Eulerian field"));
621 PetscCall(
PicurvAssertRealNear(0.1, diffusivity_gradient[0], 1.0e-12,
"CornerAveraged: interpolated diffusivity-gradient x component"));
622 PetscCall(
PicurvAssertRealNear(0.2, diffusivity_gradient[1], 1.0e-12,
"CornerAveraged: interpolated diffusivity-gradient y component"));
623 PetscCall(
PicurvAssertRealNear(0.3, diffusivity_gradient[2], 1.0e-12,
"CornerAveraged: interpolated diffusivity-gradient z component"));
624 PetscCall(DMSwarmRestoreField(user->
swarm,
"DiffusivityGradient", NULL, NULL, (
void **)&diffusivity_gradient));
625 PetscCall(DMSwarmRestoreField(user->
swarm,
"Diffusivity", NULL, NULL, (
void **)&diffusivity));
626 PetscCall(DMSwarmRestoreField(user->
swarm,
"velocity", NULL, NULL, (
void **)&velocity));
629 PetscFunctionReturn(0);
638 PetscReal *velocity = NULL;
639 PetscReal *diffusivity = NULL;
641 PetscFunctionBeginUser;
645 PetscCall(VecSet(user->
Ucont, 2.0));
646 PetscCall(VecSet(user->
Ucat, -7.0));
649 PetscCall(
SeedSingleParticle(user, 1, 1, 1, 0.5, 0.5, 0.5, 0.2, 0.7, 0.4,
ACTIVE_AND_LOCATED));
653 PetscCall(DMSwarmGetField(user->
swarm,
"velocity", NULL, NULL, (
void **)&velocity));
654 PetscCall(DMSwarmGetField(user->
swarm,
"Diffusivity", NULL, NULL, (
void **)&diffusivity));
655 for (PetscInt c = 0; c < 3; c++)
656 PetscCall(
PicurvAssertRealNear(2.0, velocity[c], 1.0e-12,
"FaceFlux: velocity should come from the constant face fluxes"));
657 PetscCall(
PicurvAssertRealNear(0.25, diffusivity[0], 1.0e-12,
"FaceFlux: diffusivity should still interpolate trilinearly"));
658 PetscCall(DMSwarmRestoreField(user->
swarm,
"Diffusivity", NULL, NULL, (
void **)&diffusivity));
659 PetscCall(DMSwarmRestoreField(user->
swarm,
"velocity", NULL, NULL, (
void **)&velocity));
661 PetscFunctionReturn(0);
675 Cmpnts ***ucont = NULL, ***ucat = NULL;
676 PetscReal *pos = NULL, *wgt = NULL, *vel = NULL;
677 PetscInt *cell = NULL, *status = NULL;
678 const PetscReal d = 0.25, w0[3] = {0.3, 0.6, 0.45};
680 PetscFunctionBeginUser;
683 PetscCall(DMDAVecGetArray(user->
fda, user->
Ucont, &ucont));
684 for (PetscInt k = user->
info.zs; k < user->
info.zs + user->
info.zm; k++)
685 for (PetscInt j = user->
info.ys; j < user->
info.ys + user->
info.ym; j++)
686 for (PetscInt i = user->
info.xs; i < user->
info.xs + user->
info.xm; i++) {
687 const PetscReal psi = (PetscReal)(i * i * j) + 0.3 * j * j;
688 const PetscReal psi_jm = (PetscReal)(i * i * (j - 1)) + 0.3 * (j - 1) * (j - 1);
689 const PetscReal psi_im = (PetscReal)((i - 1) * (i - 1) * j) + 0.3 * j * j;
690 ucont[k][j][i].
x = psi - psi_jm;
691 ucont[k][j][i].
y = -(psi - psi_im);
692 ucont[k][j][i].
z = 0.0;
694 PetscCall(DMDAVecRestoreArray(user->
fda, user->
Ucont, &ucont));
700 PetscCall(DMSwarmGetField(user->
swarm,
"position", NULL, NULL, (
void **)&pos));
701 PetscCall(DMSwarmGetField(user->
swarm,
"weight", NULL, NULL, (
void **)&wgt));
702 PetscCall(DMSwarmGetField(user->
swarm,
"DMSwarm_CellID", NULL, NULL, (
void **)&cell));
703 PetscCall(DMSwarmGetField(user->
swarm,
"DMSwarm_location_status", NULL, NULL, (
void **)&status));
704 for (PetscInt p = 0; p < 6; p++) {
705 for (PetscInt c = 0; c < 3; c++) {
706 wgt[3*p + c] = (p == 4) ? 0.5 : w0[c] + ((p == c + 1) ? d : 0.0);
709 if (p == 5) wgt[3*p + 1] = 0.0;
710 cell[3*p + 0] = 2; cell[3*p + 1] = 0; cell[3*p + 2] = 2;
713 PetscCall(DMSwarmRestoreField(user->
swarm,
"DMSwarm_location_status", NULL, NULL, (
void **)&status));
714 PetscCall(DMSwarmRestoreField(user->
swarm,
"DMSwarm_CellID", NULL, NULL, (
void **)&cell));
715 PetscCall(DMSwarmRestoreField(user->
swarm,
"weight", NULL, NULL, (
void **)&wgt));
716 PetscCall(DMSwarmRestoreField(user->
swarm,
"position", NULL, NULL, (
void **)&pos));
720 PetscCall(DMSwarmGetField(user->
swarm,
"velocity", NULL, NULL, (
void **)&vel));
722 const PetscReal div = (vel[3*1 + 0] - vel[0]) / d + (vel[3*2 + 1] - vel[1]) / d + (vel[3*3 + 2] - vel[2]) / d;
723 const PetscReal scale = PetscAbsReal(vel[3*1 + 0] - vel[0]) / d;
724 PetscCall(
PicurvAssertBool((PetscBool)(scale > 1.0),
"the test field should vary across the cell"));
725 PetscCall(
PicurvAssertRealNear(0.0, div, 1.0e-10 * scale,
"FaceFlux velocity should be divergence-free"));
727 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
Ucat, &ucat));
728 for (PetscInt c = 0; c < 3; c++)
729 PetscCall(
PicurvAssertRealNear((&ucat[3][1][3].x)[c], vel[3*4 + c], 1.0e-12,
"the cell-centre value should be Contra2Cart's"));
730 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
Ucat, &ucat));
731 PetscCall(
PicurvAssertRealNear(0.0, vel[3*5 + 1], 1.0e-12,
"the wall-normal velocity should vanish on the wall face"));
732 PetscCall(DMSwarmRestoreField(user->
swarm,
"velocity", NULL, NULL, (
void **)&vel));
734 PetscFunctionReturn(0);
744 PetscInt *cell_ids = NULL;
745 PetscReal *psi = NULL;
746 PetscReal ***psi_grid = NULL;
748 PetscFunctionBeginUser;
752 PetscCall(DMSwarmGetField(user->
swarm,
"DMSwarm_CellID", NULL, NULL, (
void **)&cell_ids));
753 cell_ids[0] = 0; cell_ids[1] = 0; cell_ids[2] = 0;
754 cell_ids[3] = 0; cell_ids[4] = 0; cell_ids[5] = 0;
755 PetscCall(DMSwarmRestoreField(user->
swarm,
"DMSwarm_CellID", NULL, NULL, (
void **)&cell_ids));
757 PetscCall(DMSwarmGetField(user->
swarm,
"Psi", NULL, NULL, (
void **)&psi));
760 PetscCall(DMSwarmRestoreField(user->
swarm,
"Psi", NULL, NULL, (
void **)&psi));
764 PetscCall(DMDAVecGetArrayRead(user->
da, user->
Psi, &psi_grid));
765 PetscCall(
PicurvAssertRealNear(2.0, psi_grid[1][1][1], 1.0e-12,
"Scatter should average particle Psi values into the owning cell"));
766 PetscCall(DMDAVecRestoreArrayRead(user->
da, user->
Psi, &psi_grid));
769 PetscFunctionReturn(0);
779 PetscInt *cell_ids = NULL;
780 PetscReal ***counts = NULL;
782 PetscFunctionBeginUser;
786 PetscCall(DMSwarmGetField(user->
swarm,
"DMSwarm_CellID", NULL, NULL, (
void **)&cell_ids));
787 cell_ids[0] = 0; cell_ids[1] = 0; cell_ids[2] = 0;
788 cell_ids[3] = 0; cell_ids[4] = 0; cell_ids[5] = 0;
789 cell_ids[6] = 1; cell_ids[7] = 0; cell_ids[8] = 0;
790 PetscCall(DMSwarmRestoreField(user->
swarm,
"DMSwarm_CellID", NULL, NULL, (
void **)&cell_ids));
794 PetscCall(DMDAVecGetArrayRead(user->
da, user->
ParticleCount, &counts));
795 PetscCall(
PicurvAssertRealNear(2.0, counts[1][1][1], 1.0e-12,
"Two particles in cell (0,0,0) should accumulate at shifted index (1,1,1)"));
796 PetscCall(
PicurvAssertRealNear(1.0, counts[1][1][2], 1.0e-12,
"One particle in cell (1,0,0) should accumulate at shifted index (2,1,1)"));
797 PetscCall(DMDAVecRestoreArrayRead(user->
da, user->
ParticleCount, &counts));
800 PetscFunctionReturn(0);
810 PetscInt *status = NULL;
812 PetscFunctionBeginUser;
816 PetscCall(DMSwarmGetField(user->
swarm,
"DMSwarm_location_status", NULL, NULL, (
void **)&status));
820 PetscCall(DMSwarmRestoreField(user->
swarm,
"DMSwarm_location_status", NULL, NULL, (
void **)&status));
824 PetscCall(DMSwarmGetField(user->
swarm,
"DMSwarm_location_status", NULL, NULL, (
void **)&status));
828 PetscCall(DMSwarmRestoreField(user->
swarm,
"DMSwarm_location_status", NULL, NULL, (
void **)&status));
831 PetscFunctionReturn(0);
841 PetscInt *status = NULL;
842 PetscInt removed_local = 0;
843 PetscInt removed_global = 0;
845 PetscReal *psi = NULL;
846 PetscReal removed_psi = 0.0;
847 PetscInt exited_global = 0;
848 PetscReal exited_psi = 0.0;
850 PetscFunctionBeginUser;
853 PetscCall(DMSwarmGetField(user->
swarm,
"Psi", NULL, NULL, (
void **)&psi));
859 PetscCall(DMSwarmRestoreField(user->
swarm,
"Psi", NULL, NULL, (
void **)&psi));
861 PetscCall(DMSwarmGetField(user->
swarm,
"DMSwarm_location_status", NULL, NULL, (
void **)&status));
867 PetscCall(DMSwarmRestoreField(user->
swarm,
"DMSwarm_location_status", NULL, NULL, (
void **)&status));
870 PetscCall(DMSwarmGetLocalSize(user->
swarm, &nlocal));
873 PetscCall(
PicurvAssertIntEqual(1, removed_local,
"One LOST particle should be removed locally"));
874 PetscCall(
PicurvAssertIntEqual(1, removed_global,
"Global LOST-particle removal count should match the local single-rank result"));
880 PetscCall(DMSwarmGetField(user->
swarm,
"Psi", NULL, NULL, (
void **)&psi));
881 PetscCall(
PicurvAssertRealNear(0.5, psi[0], 0.0,
"survivor order must match one-at-a-time removal (slot 0)"));
882 PetscCall(
PicurvAssertRealNear(7.0, psi[1], 0.0,
"survivor order must match one-at-a-time removal (slot 1)"));
883 PetscCall(
PicurvAssertRealNear(11.0, psi[2], 0.0,
"survivor order must match one-at-a-time removal (slot 2)"));
884 PetscCall(DMSwarmRestoreField(user->
swarm,
"Psi", NULL, NULL, (
void **)&psi));
887 PetscFunctionReturn(0);
896 PetscInt *cell = NULL;
897 PetscInt64 *pid = NULL;
898 PetscReal *psi = NULL, *pos = NULL;
901 const PetscInt cells_in[6][3] = {{2, 1, 0}, {1, 0, 0}, {0, 0, 1}, {0, 0, 0}, {-1, -1, -1}, {1, 0, 0}};
902 const PetscInt expected[6] = {3, 1, 5, 0, 2, 4};
904 PetscFunctionBeginUser;
907 PetscCall(DMSwarmGetField(user->
swarm,
"DMSwarm_CellID", NULL, NULL, (
void **)&cell));
908 PetscCall(DMSwarmGetField(user->
swarm,
"DMSwarm_pid", NULL, NULL, (
void **)&pid));
909 PetscCall(DMSwarmGetField(user->
swarm,
"Psi", NULL, NULL, (
void **)&psi));
910 PetscCall(DMSwarmGetField(user->
swarm,
"position", NULL, NULL, (
void **)&pos));
911 for (PetscInt p = 0; p < 6; ++p) {
912 for (
int d = 0; d < 3; ++d) { cell[3 * p + d] = cells_in[p][d]; pos[3 * p + d] = 10.0 * p + d; }
916 PetscCall(DMSwarmRestoreField(user->
swarm,
"position", NULL, NULL, (
void **)&pos));
917 PetscCall(DMSwarmRestoreField(user->
swarm,
"Psi", NULL, NULL, (
void **)&psi));
918 PetscCall(DMSwarmRestoreField(user->
swarm,
"DMSwarm_pid", NULL, NULL, (
void **)&pid));
919 PetscCall(DMSwarmRestoreField(user->
swarm,
"DMSwarm_CellID", NULL, NULL, (
void **)&cell));
923 PetscCall(DMSwarmGetField(user->
swarm,
"DMSwarm_CellID", NULL, NULL, (
void **)&cell));
924 PetscCall(DMSwarmGetField(user->
swarm,
"DMSwarm_pid", NULL, NULL, (
void **)&pid));
925 PetscCall(DMSwarmGetField(user->
swarm,
"Psi", NULL, NULL, (
void **)&psi));
926 PetscCall(DMSwarmGetField(user->
swarm,
"position", NULL, NULL, (
void **)&pos));
927 for (PetscInt q = 0; q < 6; ++q) {
928 const PetscInt p = expected[q];
929 PetscCall(
PicurvAssertIntEqual(100 + p, (PetscInt)pid[q],
"points must come out in (k,j,i) cell order, ties and unlocated points stable"));
931 PetscCall(
PicurvAssertRealNear(10.0 * p + 2, pos[3 * q + 2], 0.0,
"position must move with its point"));
932 PetscCall(
PicurvAssertIntEqual(cells_in[p][0], cell[3 * q],
"CellID must move with its point"));
934 PetscCall(DMSwarmRestoreField(user->
swarm,
"position", NULL, NULL, (
void **)&pos));
935 PetscCall(DMSwarmRestoreField(user->
swarm,
"Psi", NULL, NULL, (
void **)&psi));
936 PetscCall(DMSwarmRestoreField(user->
swarm,
"DMSwarm_pid", NULL, NULL, (
void **)&pid));
937 PetscCall(DMSwarmRestoreField(user->
swarm,
"DMSwarm_CellID", NULL, NULL, (
void **)&cell));
940 PetscFunctionReturn(0);
954 Cmpnts base, again, other_pid, other_step, other_seed, none;
956 PetscFunctionBeginUser;
972 "the same (seed, PID, step) must reproduce the increment after other draws"));
973 PetscCall(
PicurvAssertBool((PetscBool)(base.
x != other_pid.
x && base.
x != other_step.
x && base.
x != other_seed.
x),
974 "a different PID, step or seed must change the increment"));
976 "zero diffusivity must give no increment"));
978 PetscFunctionReturn(0);
990 const PetscInt count = 40000;
991 const PetscReal diffusivity = 0.5;
992 PetscReal sum[3] = {0.0, 0.0, 0.0}, sum_sq[3] = {0.0, 0.0, 0.0}, sum_xy = 0.0, variance;
994 PetscFunctionBeginUser;
999 variance = 2.0 * diffusivity * simCtx->
dt;
1000 for (PetscInt pid = 0; pid < count; ++pid) {
1004 const PetscReal c[3] = {d.
x, d.
y, d.
z};
1005 for (
int a = 0; a < 3; ++a) { sum[a] += c[a]; sum_sq[a] += c[a] * c[a]; }
1006 sum_xy += d.
x * d.
y;
1009 for (
int a = 0; a < 3; ++a) {
1010 PetscCall(
PicurvAssertRealNear(0.0, sum[a] / count, 5.0 * PetscSqrtReal(variance / count),
"Brownian increments must have zero mean"));
1011 PetscCall(
PicurvAssertRealNear(variance, sum_sq[a] / count, 5.0 * PetscSqrtReal(2.0 / count) * variance,
"Brownian increments must have variance 2 D dt"));
1013 PetscCall(
PicurvAssertRealNear(0.0, sum_xy / count, 5.0 * variance / PetscSqrtReal((PetscReal)count),
"Brownian components must be uncorrelated"));
1015 PetscFunctionReturn(0);
1024 PetscReal *positions = NULL;
1025 PetscReal *velocities = NULL;
1026 PetscReal *diffusivity = NULL;
1027 Cmpnts *diffusivity_gradient = NULL;
1028 PetscReal *psi = NULL;
1029 PetscReal *weights = NULL;
1030 PetscInt *cell_ids = NULL;
1031 PetscInt *status = NULL;
1032 PetscInt64 *pid = NULL;
1034 PetscFunctionBeginUser;
1039 PetscCall(DMSwarmGetField(user->
swarm,
"position", NULL, NULL, (
void **)&positions));
1040 PetscCall(DMSwarmGetField(user->
swarm,
"velocity", NULL, NULL, (
void **)&velocities));
1041 PetscCall(DMSwarmGetField(user->
swarm,
"Diffusivity", NULL, NULL, (
void **)&diffusivity));
1042 PetscCall(DMSwarmGetField(user->
swarm,
"DiffusivityGradient", NULL, NULL, (
void **)&diffusivity_gradient));
1043 PetscCall(DMSwarmGetField(user->
swarm,
"Psi", NULL, NULL, (
void **)&psi));
1044 PetscCall(DMSwarmGetField(user->
swarm,
"weight", NULL, NULL, (
void **)&weights));
1045 PetscCall(DMSwarmGetField(user->
swarm,
"DMSwarm_CellID", NULL, NULL, (
void **)&cell_ids));
1046 PetscCall(DMSwarmGetField(user->
swarm,
"DMSwarm_location_status", NULL, NULL, (
void **)&status));
1047 PetscCall(DMSwarmGetField(user->
swarm,
"DMSwarm_pid", NULL, NULL, (
void **)&pid));
1049 positions[0] = 0.20; positions[1] = 0.30; positions[2] = 0.40;
1050 velocities[0] = 0.40; velocities[1] = -0.20; velocities[2] = 0.10;
1051 diffusivity[0] = 0.0;
1052 diffusivity_gradient[0].
x = 0.10;
1053 diffusivity_gradient[0].
y = 0.20;
1054 diffusivity_gradient[0].
z = -0.10;
1056 weights[0] = 0.5; weights[1] = 0.5; weights[2] = 0.5;
1057 cell_ids[0] = 0; cell_ids[1] = 0; cell_ids[2] = 0;
1061 PetscCall(DMSwarmRestoreField(user->
swarm,
"DMSwarm_pid", NULL, NULL, (
void **)&pid));
1062 PetscCall(DMSwarmRestoreField(user->
swarm,
"DMSwarm_location_status", NULL, NULL, (
void **)&status));
1063 PetscCall(DMSwarmRestoreField(user->
swarm,
"DMSwarm_CellID", NULL, NULL, (
void **)&cell_ids));
1064 PetscCall(DMSwarmRestoreField(user->
swarm,
"weight", NULL, NULL, (
void **)&weights));
1065 PetscCall(DMSwarmRestoreField(user->
swarm,
"Psi", NULL, NULL, (
void **)&psi));
1066 PetscCall(DMSwarmRestoreField(user->
swarm,
"DiffusivityGradient", NULL, NULL, (
void **)&diffusivity_gradient));
1067 PetscCall(DMSwarmRestoreField(user->
swarm,
"Diffusivity", NULL, NULL, (
void **)&diffusivity));
1068 PetscCall(DMSwarmRestoreField(user->
swarm,
"velocity", NULL, NULL, (
void **)&velocities));
1069 PetscCall(DMSwarmRestoreField(user->
swarm,
"position", NULL, NULL, (
void **)&positions));
1073 PetscCall(DMSwarmGetField(user->
swarm,
"position", NULL, NULL, (
void **)&positions));
1074 PetscCall(
PicurvAssertRealNear(0.325, positions[0], 1.0e-12,
"UpdateAllParticlePositions should advect x"));
1075 PetscCall(
PicurvAssertRealNear(0.300, positions[1], 1.0e-12,
"UpdateAllParticlePositions should advect y"));
1076 PetscCall(
PicurvAssertRealNear(0.400, positions[2], 1.0e-12,
"UpdateAllParticlePositions should advect z"));
1077 PetscCall(DMSwarmRestoreField(user->
swarm,
"position", NULL, NULL, (
void **)&positions));
1080 PetscFunctionReturn(0);
1089 PetscReal *positions = NULL;
1090 PetscReal *weights = NULL;
1091 PetscInt *cell_ids = NULL;
1092 PetscInt *status = NULL;
1093 PetscInt64 *pid = NULL;
1095 PetscFunctionBeginUser;
1100 PetscCall(DMSwarmGetField(user->
swarm,
"position", NULL, NULL, (
void **)&positions));
1101 PetscCall(DMSwarmGetField(user->
swarm,
"weight", NULL, NULL, (
void **)&weights));
1102 PetscCall(DMSwarmGetField(user->
swarm,
"DMSwarm_CellID", NULL, NULL, (
void **)&cell_ids));
1103 PetscCall(DMSwarmGetField(user->
swarm,
"DMSwarm_location_status", NULL, NULL, (
void **)&status));
1104 PetscCall(DMSwarmGetField(user->
swarm,
"DMSwarm_pid", NULL, NULL, (
void **)&pid));
1105 positions[0] = 0.375; positions[1] = 0.375; positions[2] = 0.375;
1106 weights[0] = 0.5; weights[1] = 0.5; weights[2] = 0.5;
1107 cell_ids[0] = 1; cell_ids[1] = 1; cell_ids[2] = 1;
1110 PetscCall(DMSwarmRestoreField(user->
swarm,
"DMSwarm_pid", NULL, NULL, (
void **)&pid));
1111 PetscCall(DMSwarmRestoreField(user->
swarm,
"DMSwarm_location_status", NULL, NULL, (
void **)&status));
1112 PetscCall(DMSwarmRestoreField(user->
swarm,
"DMSwarm_CellID", NULL, NULL, (
void **)&cell_ids));
1113 PetscCall(DMSwarmRestoreField(user->
swarm,
"weight", NULL, NULL, (
void **)&weights));
1114 PetscCall(DMSwarmRestoreField(user->
swarm,
"position", NULL, NULL, (
void **)&positions));
1118 PetscCall(DMSwarmGetField(user->
swarm,
"DMSwarm_CellID", NULL, NULL, (
void **)&cell_ids));
1119 PetscCall(DMSwarmGetField(user->
swarm,
"DMSwarm_location_status", NULL, NULL, (
void **)&status));
1120 PetscCall(
PicurvAssertIntEqual(1, cell_ids[0],
"prior-cell fast path should preserve the i cell id"));
1121 PetscCall(
PicurvAssertIntEqual(1, cell_ids[1],
"prior-cell fast path should preserve the j cell id"));
1122 PetscCall(
PicurvAssertIntEqual(1, cell_ids[2],
"prior-cell fast path should preserve the k cell id"));
1131 PetscCall(DMSwarmRestoreField(user->
swarm,
"DMSwarm_location_status", NULL, NULL, (
void **)&status));
1132 PetscCall(DMSwarmRestoreField(user->
swarm,
"DMSwarm_CellID", NULL, NULL, (
void **)&cell_ids));
1135 PetscFunctionReturn(0);
1144 PetscReal *positions = NULL;
1145 PetscReal *weights = NULL;
1146 PetscInt *cell_ids = NULL;
1147 PetscInt *status = NULL;
1148 PetscInt64 *pid = NULL;
1150 PetscFunctionBeginUser;
1155 PetscCall(DMSwarmGetField(user->
swarm,
"position", NULL, NULL, (
void **)&positions));
1156 PetscCall(DMSwarmGetField(user->
swarm,
"weight", NULL, NULL, (
void **)&weights));
1157 PetscCall(DMSwarmGetField(user->
swarm,
"DMSwarm_CellID", NULL, NULL, (
void **)&cell_ids));
1158 PetscCall(DMSwarmGetField(user->
swarm,
"DMSwarm_location_status", NULL, NULL, (
void **)&status));
1159 PetscCall(DMSwarmGetField(user->
swarm,
"DMSwarm_pid", NULL, NULL, (
void **)&pid));
1160 positions[0] = 0.625; positions[1] = 0.625; positions[2] = 0.625;
1161 weights[0] = 0.5; weights[1] = 0.5; weights[2] = 0.5;
1162 cell_ids[0] = -1; cell_ids[1] = -1; cell_ids[2] = -1;
1165 PetscCall(DMSwarmRestoreField(user->
swarm,
"DMSwarm_pid", NULL, NULL, (
void **)&pid));
1166 PetscCall(DMSwarmRestoreField(user->
swarm,
"DMSwarm_location_status", NULL, NULL, (
void **)&status));
1167 PetscCall(DMSwarmRestoreField(user->
swarm,
"DMSwarm_CellID", NULL, NULL, (
void **)&cell_ids));
1168 PetscCall(DMSwarmRestoreField(user->
swarm,
"weight", NULL, NULL, (
void **)&weights));
1169 PetscCall(DMSwarmRestoreField(user->
swarm,
"position", NULL, NULL, (
void **)&positions));
1173 PetscCall(DMSwarmGetField(user->
swarm,
"DMSwarm_CellID", NULL, NULL, (
void **)&cell_ids));
1174 PetscCall(DMSwarmGetField(user->
swarm,
"DMSwarm_location_status", NULL, NULL, (
void **)&status));
1175 PetscCall(
PicurvAssertIntEqual(2, cell_ids[0],
"guess-path location should resolve the i cell id"));
1176 PetscCall(
PicurvAssertIntEqual(2, cell_ids[1],
"guess-path location should resolve the j cell id"));
1177 PetscCall(
PicurvAssertIntEqual(2, cell_ids[2],
"guess-path location should resolve the k cell id"));
1186 PetscCall(DMSwarmRestoreField(user->
swarm,
"DMSwarm_location_status", NULL, NULL, (
void **)&status));
1187 PetscCall(DMSwarmRestoreField(user->
swarm,
"DMSwarm_CellID", NULL, NULL, (
void **)&cell_ids));
1190 PetscFunctionReturn(0);
1202 PetscFunctionBeginUser;
1203 PetscCall(PetscMemzero(&particle,
sizeof(particle)));
1209 particle.
cell[0] = 1;
1210 particle.
cell[1] = 1;
1211 particle.
cell[2] = 1;
1212 particle.
loc.
x = 0.375;
1213 particle.
loc.
y = 0.375;
1214 particle.
loc.
z = 0.375;
1227 PetscFunctionReturn(0);
1239 PetscFunctionBeginUser;
1246 PetscCall(PetscMemzero(&particle,
sizeof(particle)));
1248 particle.
cell[0] = 0; particle.
cell[1] = 1; particle.
cell[2] = 1;
1249 particle.
loc.
x = -0.05; particle.
loc.
y = 0.375; particle.
loc.
z = 0.375;
1258 PetscCall(PetscMemzero(&particle,
sizeof(particle)));
1260 particle.
cell[0] = 0; particle.
cell[1] = 1; particle.
cell[2] = 1;
1261 particle.
loc.
x = -0.05; particle.
loc.
y = 0.625; particle.
loc.
z = 0.375;
1265 PetscCall(
PicurvAssertIntEqual(2, particle.
cell[1],
"the reflection happens in the boundary cell that holds the particle tangentially"));
1270 PetscFunctionReturn(0);
1278 const PetscReal expected_smooth_e = PetscExpReal(0.41 * 5.5);
1279 PetscReal e_coeff = 0.0;
1280 PetscReal utau = 0.0;
1281 PetscReal residual = 0.0;
1283 PetscFunctionBeginUser;
1284 e_coeff =
E_coeff(0.1, 0.0, 1.0e-3);
1285 PetscCall(
PicurvAssertRealNear(expected_smooth_e, e_coeff, 1.0e-10,
"smooth-wall E coefficient"));
1288 PetscCall(
PicurvAssertBool((PetscBool)(utau > 0.0),
"friction velocity should remain positive"));
1289 residual =
f_hydset(1.0e-3, 1.0, 1.0e-2, utau, 0.0);
1290 PetscCall(
PicurvAssertBool((PetscBool)(PetscAbsReal(residual) < 1.0e-5),
"Newton solve residual should be small"));
1294 PetscFunctionReturn(0);
1302 const PetscReal kinematic_viscosity = 1.0e-3;
1303 const PetscReal wall_distance = 2.0e-2;
1304 const PetscReal target_velocity = 1.0;
1305 PetscReal utau_werner = 0.0;
1306 PetscReal utau_cabot = 0.0;
1307 PetscReal wall_shear_velocity = 0.0;
1308 PetscReal wall_shear_normal = 0.0;
1310 PetscFunctionBeginUser;
1311 utau_werner =
find_utau_Werner(kinematic_viscosity, target_velocity, wall_distance, 0.1);
1312 PetscCall(
PicurvAssertBool((PetscBool)(utau_werner > 0.0),
"Werner-Wengle friction velocity should remain positive"));
1314 "Werner-Wengle inversion should reconstruct the target velocity"));
1320 const PetscReal yplus[5] = {2.0, 11.0, 11.81, 30.0, 500.0};
1321 const PetscReal u_tau = 0.05;
1322 const PetscReal nu = kinematic_viscosity;
1324 for (PetscInt i = 0; i < 5; ++i) {
1325 const PetscReal y = yplus[i] * nu / u_tau;
1326 const PetscReal u =
u_Werner(nu, y, u_tau);
1328 "find_utau_Werner must invert u_Werner exactly on both branches"));
1335 const PetscReal A = 8.3, Bexp = 1.0 / 7.0;
1336 const PetscReal u_m = 0.5 * kinematic_viscosity / wall_distance *
1337 PetscPowReal(A, 2.0 / (1.0 - Bexp));
1338 const PetscReal samples[2] = {0.25 * u_m, 4.0 * u_m};
1340 for (PetscInt i = 0; i < 2; ++i) {
1341 const PetscReal tau =
taw_Werner(kinematic_viscosity, samples[i], wall_distance);
1344 "the explicit Werner-Wengle stress must be positive"));
1347 1.0e-9 + 1.0e-9 * samples[i],
1348 "the explicit Werner-Wengle pair must round-trip on both branches"));
1355 taw_Werner(kinematic_viscosity, u_m * (1.0 - 1.0e-9), wall_distance),
1356 taw_Werner(kinematic_viscosity, u_m * (1.0 + 1.0e-9), wall_distance), 1.0e-9,
1357 "the Werner-Wengle branches must be continuous at the transition speed"));
1362 const PetscReal tau =
taw_Werner(kinematic_viscosity, 4.0 * u_m, wall_distance);
1367 "a cell nearer the wall must be assigned the slower speed"));
1371 find_utau_Cabot(kinematic_viscosity, target_velocity, wall_distance, 0.1, 0.0, 0.0,
1372 &utau_cabot, &wall_shear_velocity, &wall_shear_normal);
1373 PetscCall(
PicurvAssertBool((PetscBool)(utau_cabot > 0.0),
"Cabot friction velocity should remain positive"));
1374 PetscCall(
PicurvAssertRealNear(target_velocity,
u_Cabot(kinematic_viscosity, wall_distance, utau_cabot, 0.0, wall_shear_velocity), 1.0e-6,
1375 "Cabot inversion should reconstruct the target velocity when pressure gradient is zero"));
1377 "zero normal pressure gradient should keep Cabot normal wall shear at zero"));
1378 PetscFunctionReturn(0);
1390 const double nu = 1.0e-3, y = 1.0e-2;
1391 const double edge = 11.81;
1392 double previous_utau = 0.0;
1394 PetscFunctionBeginUser;
1396 for (
int law = 0; law < 2; ++law) {
1397 double previous = -1.0;
1398 for (
int n = 0; n <= 400; ++n) {
1399 const double yplus = edge - 1.0 + 2.0 * n / 400.0;
1400 const double u_tau = yplus * nu / y;
1402 const double uplus = u / u_tau;
1403 if (previous > 0.0) {
1404 PetscCall(
PicurvAssertBool((PetscBool)(PetscAbsReal(uplus - previous) < 1.0e-2),
1405 law == 0 ?
"the log-law profile must not jump at its sublayer edge"
1406 :
"the Werner-Wengle profile must not jump at its sublayer edge"));
1408 "u+ must not decrease with y+"));
1415 for (
int n = 0; n <= 200; ++n) {
1416 const double U = (130.0 + 15.0 * n / 200.0) * nu / y;
1419 "the log-law friction velocity must reproduce the speed it inverts"));
1420 PetscCall(
PicurvAssertBool((PetscBool)(u_tau > previous_utau),
"the log-law friction velocity must increase with speed"));
1421 previous_utau = u_tau;
1427 const double yplus_samples[] = {100.0, 299.0, 301.0, 500.0, 2000.0};
1428 const double roughness[] = {0.0, 5.0e-3};
1429 for (
int r = 0; r < 2; ++r) {
1430 for (
int n = 0; n < 5; ++n) {
1431 const double u_tau = yplus_samples[n] * nu / y;
1434 "the log-law profile must be a speed at every y+, not a sentinel"));
1436 "the log-law inverse must recover the friction velocity of its profile"));
1440 PetscFunctionReturn(0);
1451 const double nu = 1.0 / 4.0e4;
1452 const double roughness[4] = {1.0e-5, 1.0e-4, 1.0e-3, 1.0e-2};
1453 const double distance[3] = {1.0e-3, 1.0e-2, 3.0e-2};
1454 const double speed[6] = {1.0e-3, 1.0e-2, 0.1, 0.5, 1.0, 2.0};
1456 PetscFunctionBeginUser;
1457 for (
int r = 0; r < 4; ++r)
1458 for (
int d = 0; d < 3; ++d)
1459 for (
int s = 0; s < 6; ++s) {
1460 const double u_tau =
find_utau_hydset(nu, speed[s], distance[d], 1.0e-3, roughness[r]);
1462 "the log-law friction velocity must be positive and finite"));
1464 PetscFunctionReturn(0);
1477 const double nu = 1.0e-3, y = 1.0e-2;
1478 double u_tau = 0.0, stress = 0.0, stress_normal = 0.0;
1480 PetscFunctionBeginUser;
1482 for (
int mode = 0; mode < 2; ++mode) {
1483 const double u_tau_probe = 1000.0 * nu / y;
1484 const int fine = 200000;
1485 double reference_integral = 0.0, y_prev = 0.0, f_prev = 0.0;
1486 for (
int n = 1; n <= fine; ++n) {
1487 const double yy = y * (double)n * (
double)n / ((double)fine * (
double)fine);
1488 const double f = ((mode == 0) ? 1.0 : yy) / ((1.0 +
nu_t(yy * u_tau_probe / nu)) * nu);
1489 if (n == 1) f_prev = ((mode == 0) ? 1.0 : 0.0) / nu;
1490 reference_integral += 0.5 * (f + f_prev) * (yy - y_prev);
1491 y_prev = yy; f_prev = f;
1494 2.0e-3 * PetscAbsReal(reference_integral),
1495 "Cabot's wall-layer integral must match a resolved reference at y+ = 1000"));
1499 find_utau_Cabot(nu, 1.0, 2.0 * y, 0.01, 0.0, 0.0, &u_tau, &stress, &stress_normal);
1501 "with no pressure gradient Cabot's stress opposes the flow"));
1504 find_utau_Cabot(nu, 1.0, 2.0 * y, 0.01, 1.0e3, 0.0, &u_tau, &stress, &stress_normal);
1506 "an adverse gradient that reverses the balance must reverse Cabot's stress"));
1507 PetscFunctionReturn(0);
1519 PetscFunctionBeginUser;
1523 PetscFunctionReturn(0);
1534 PetscInt mx = 0, my = 0, mz = 0;
1536 PetscFunctionBeginUser;
1539 PetscCall(DMDAGetInfo(user->
da, NULL, &mx, &my, &mz, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL));
1547 PetscCall(DMGetCoordinateDM(user->
da, &coord_dm));
1549 "minimal fixture should derive fda from the coordinate-DM path"));
1552 PetscFunctionReturn(0);
1563 void *field_ptr = NULL;
1565 PetscFunctionBeginUser;
1569 PetscCall(DMSwarmGetField(user->
swarm,
"position", &bs, NULL, &field_ptr));
1571 PetscCall(
PicurvAssertBool((PetscBool)(field_ptr != NULL),
"position field should be retrievable"));
1572 PetscCall(DMSwarmRestoreField(user->
swarm,
"position", &bs, NULL, &field_ptr));
1574 PetscCall(DMSwarmGetField(user->
swarm,
"velocity", &bs, NULL, &field_ptr));
1576 PetscCall(DMSwarmRestoreField(user->
swarm,
"velocity", &bs, NULL, &field_ptr));
1578 PetscCall(DMSwarmGetField(user->
swarm,
"DMSwarm_CellID", &bs, NULL, &field_ptr));
1580 PetscCall(DMSwarmRestoreField(user->
swarm,
"DMSwarm_CellID", &bs, NULL, &field_ptr));
1582 PetscCall(DMSwarmGetField(user->
swarm,
"weight", &bs, NULL, &field_ptr));
1584 PetscCall(DMSwarmRestoreField(user->
swarm,
"weight", &bs, NULL, &field_ptr));
1586 PetscCall(DMSwarmGetField(user->
swarm,
"Diffusivity", &bs, NULL, &field_ptr));
1588 PetscCall(DMSwarmRestoreField(user->
swarm,
"Diffusivity", &bs, NULL, &field_ptr));
1590 PetscCall(DMSwarmGetField(user->
swarm,
"DiffusivityGradient", &bs, NULL, &field_ptr));
1591 PetscCall(
PicurvAssertIntEqual(3, bs,
"solver swarm should register particle diffusivity gradients"));
1592 PetscCall(DMSwarmRestoreField(user->
swarm,
"DiffusivityGradient", &bs, NULL, &field_ptr));
1594 PetscCall(DMSwarmGetField(user->
swarm,
"Psi", &bs, NULL, &field_ptr));
1596 PetscCall(DMSwarmRestoreField(user->
swarm,
"Psi", &bs, NULL, &field_ptr));
1598 PetscCall(DMSwarmGetField(user->
swarm,
"DMSwarm_location_status", &bs, NULL, &field_ptr));
1599 PetscCall(
PicurvAssertIntEqual(1, bs,
"solver swarm should register particle location status"));
1600 PetscCall(DMSwarmRestoreField(user->
swarm,
"DMSwarm_location_status", &bs, NULL, &field_ptr));
1603 PetscFunctionReturn(0);
1614 PetscFunctionBeginUser;
1617 PetscCall(VecSet(user->
Ucont, 11.0));
1618 PetscCall(VecSet(user->
Ucont_o, 7.0));
1619 PetscCall(VecSet(user->
Ucont_rm1, 3.0));
1620 PetscCall(VecSet(user->
Ucat, 5.0));
1621 PetscCall(VecSet(user->
Ucat_o, -1.0));
1622 PetscCall(VecSet(user->
P, 9.0));
1623 PetscCall(VecSet(user->
P_o, -2.0));
1635 PetscFunctionReturn(0);
1645 PetscInt xs = -1, ys = -1, zs = -1;
1646 PetscInt xm = -1, ym = -1, zm = -1;
1648 PetscFunctionBeginUser;
1663 PetscFunctionReturn(0);
1674 PetscFunctionBeginUser;
1679 for (PetscInt n = 0; n < 27; ++n) {
1681 "single-rank neighbours should be null except the rank itself"));
1688 for (PetscInt n = 0; n < 27; ++n) {
1692 "x-periodic single-rank neighbours should wrap to the rank along x only"));
1696 PetscFunctionReturn(0);
1704 PetscReal seconds = 0.0;
1706 PetscFunctionBeginUser;
1713 PetscFunctionReturn(0);
1721 PetscReal ewma_fast = 0.0;
1722 PetscReal ewma_slow = 0.0;
1723 PetscReal conservative_fast = 0.0;
1724 PetscReal conservative_slow = 0.0;
1725 PetscReal required_headroom = 0.0;
1727 PetscFunctionBeginUser;
1736 PetscCall(
PicurvAssertRealNear(6.0, conservative_fast, 1.0e-12,
"conservative estimate tracks latest moderate step"));
1737 PetscCall(
PicurvAssertRealNear(12.0, conservative_slow, 1.0e-12,
"conservative estimate tracks newest slow step"));
1738 PetscCall(
PicurvAssertRealNear(24.0, required_headroom, 1.0e-12,
"required headroom scales with conservative estimate"));
1739 PetscFunctionReturn(0);
1747 PetscBool should_trigger = PETSC_FALSE;
1748 PetscReal required_headroom = 0.0;
1750 PetscFunctionBeginUser;
1752 PetscCall(
PicurvAssertBool((PetscBool)!should_trigger,
"guard should not trigger before warmup completes"));
1755 PetscCall(
PicurvAssertBool((PetscBool)!should_trigger,
"guard should not trigger when remaining walltime exceeds required headroom"));
1756 PetscCall(
PicurvAssertRealNear(28.0, required_headroom, 1.0e-12,
"required headroom after warmup"));
1759 PetscCall(
PicurvAssertBool(should_trigger,
"guard should trigger when remaining walltime reaches required headroom"));
1760 PetscCall(
PicurvAssertRealNear(28.0, required_headroom, 1.0e-12,
"required headroom remains unchanged at trigger threshold"));
1761 PetscFunctionReturn(0);
1769 PetscErrorCode ierr;
1815 ierr = PetscInitialize(&argc, &argv, NULL,
"PICurv runtime-kernel tests");
1820 ierr =
PicurvRunTests(
"unit-runtime", cases,
sizeof(cases) /
sizeof(cases[0]));
1826 ierr = PetscFinalize();
PetscErrorCode Validate_DrivenFlowConfiguration(UserCtx *user)
(Private) Validates all consistency rules for a driven flow (channel/pipe) setup.
PetscErrorCode SynchronizePeriodicStaggeredFields(UserCtx *user, PetscInt num_fields, const FieldId field_ids[])
Synchronizes persistent component-staggered vector fields.
PetscErrorCode SynchronizePeriodicCellFields(UserCtx *user, PetscInt num_fields, const FieldId field_ids[])
Synchronizes periodic endpoint cells for a list of cell-centered fields.
Header file for Particle Motion and migration related functions.
PetscErrorCode SortParticlesByCell(DM swarm)
Reorders the local swarm points so that points in the same host cell are contiguous.
PetscErrorCode UpdateAllParticlePositions(UserCtx *user)
Loops over all local particles in the DMSwarm, updating their positions based on velocity and the glo...
PetscErrorCode CalculateParticleCountPerCell(UserCtx *user)
Counts particles in each cell of the DMDA 'da' and stores the result in user->ParticleCount.
PetscErrorCode LocateAllParticlesInGrid(UserCtx *user, BoundingBox *bboxlist)
Orchestrates the complete particle location and migration process for one timestep.
PetscErrorCode CheckAndRemoveLostParticles(UserCtx *user, PetscInt *removedCountLocal, PetscInt *removedCountGlobal, PetscReal *removedScalarSumGlobal, PetscInt *exitedCountGlobal, PetscReal *exitedScalarSumGlobal)
Removes particles that the location algorithm flagged as LOST or EXITED.
PetscErrorCode UpdateParticlePosition(UserCtx *user, Particle *particle)
Updates a particle's position based on its velocity and the timestep dt (stored in user->dt).
PetscErrorCode ResetAllParticleStatuses(UserCtx *user)
Marks all local particles as NEEDS_LOCATION for the next settlement pass.
static PetscBool IsParticleInBox(const BoundingBox *bbox, const Cmpnts *pos)
Whether a position lies in an axis-aligned bounding box, faces included.
PetscErrorCode CalculateBrownianDisplacement(UserCtx *user, PetscInt64 pid, PetscReal diff_eff, Cmpnts *displacement)
Calculates the stochastic displacement vector (Brownian motion) for a single particle.
Header file for Particle related physics modules.
PetscErrorCode UpdateParticleField(ParticleFieldId field_id, PetscReal dt, PetscReal *psi_io, PetscReal diffusivity, PetscReal mean_val, PetscReal delta2, PetscReal C_model)
Updates a single particle's field based on its state and physics model.
Header file for Particle Swarm management functions.
PetscErrorCode UpdateParticleWeights(PetscReal *d, Particle *particle)
Updates a particle's interpolation weights based on distances to cell faces.
PetscErrorCode DistributeParticles(PetscInt numParticles, PetscMPIInt rank, PetscMPIInt size, PetscInt *particlesPerProcess, PetscInt *remainder)
Distributes particles evenly across MPI processes, handling any remainders.
FieldId
Compile-time identity for a catalogued Eulerian field.
PetscErrorCode ScatterAllParticleFieldsToEulerFields(UserCtx *user)
Scatters a predefined set of particle fields to their corresponding Eulerian fields.
PetscErrorCode PopulateInitialUcont(UserCtx *user)
Populate Ucont for one fresh-start block from the initial source (-ic_source_*).
PetscErrorCode InterpolateAllFieldsToSwarm(UserCtx *user)
Interpolates the Eulerian fields the particles carry to every local particle.
PetscErrorCode WriteSimulationFields(UserCtx *user, const char *checkpoint_directory)
Writes simulation fields to files.
PetscErrorCode WriteFieldData(UserCtx *user, const char *field_name, Vec field_vec, const char *ext)
Writes data from a specific PETSc vector to a file.
@ PARTICLE_FIELD_ID_VELOCITY
PetscReal RuntimeWalltimeGuardUpdateEWMA(PetscBool has_previous, PetscReal previous_ewma_seconds, PetscReal latest_step_seconds, PetscReal alpha)
Update an EWMA estimate for timestep wall-clock duration.
PetscReal RuntimeWalltimeGuardConservativeEstimate(PetscReal warmup_average_seconds, PetscReal ewma_seconds, PetscReal latest_step_seconds)
Return the conservative timestep estimate used by the walltime guard.
PetscReal RuntimeWalltimeGuardRequiredHeadroom(PetscReal min_seconds, PetscReal multiplier, PetscReal conservative_estimate_seconds)
Compute the required shutdown headroom from timestep estimate and floor.
PetscBool RuntimeWalltimeGuardShouldTrigger(PetscInt completed_steps, PetscInt warmup_steps, PetscReal remaining_seconds, PetscReal min_seconds, PetscReal multiplier, PetscReal warmup_average_seconds, PetscReal ewma_seconds, PetscReal latest_step_seconds, PetscReal *required_headroom_seconds_out)
Decide whether the runtime walltime guard should stop before another step.
PetscErrorCode UpdateSolverHistoryVectors(UserCtx *user, PetscBool preserve_previous_state)
Copies the current time step's solution fields into history vectors (e.g., U(t_n) -> U_o,...
PetscErrorCode GetOwnedCellRange(const DMDALocalInfo *info_nodes, PetscInt dim, PetscInt *xs_cell_global_out, PetscInt *xm_cell_local_out)
Determines the global starting index and number of CELLS owned by the current processor in a specifie...
PetscErrorCode ComputeAndStoreNeighborRanks(UserCtx *user)
Computes and stores the Cartesian neighbor ranks for the DMDA decomposition.
PetscErrorCode Contra2Cart(UserCtx *user)
Reconstructs Cartesian velocity (Ucat) at cell centers from contravariant velocity (Ucont) defined on...
PetscErrorCode UpdateLocalGhosts(UserCtx *user, FieldId field_id)
Updates the local vector (including ghost points) from its corresponding global vector.
PetscErrorCode Cart2Contra(UserCtx *user)
Convert the ghosted Cartesian velocity field to contravariant face fluxes.
PetscErrorCode SetupDomainCellDecompositionMap(UserCtx *user)
Creates and distributes a map of the domain's cell decomposition to all ranks.
PetscBool RuntimeWalltimeGuardParsePositiveSeconds(const char *text, PetscReal *seconds_out)
Parse a positive floating-point seconds value from runtime metadata.
static PetscErrorCode TestUpdateParticleFieldIEMRelaxation(void)
Tests IEM relaxation updates for particle-carried fields.
static PetscErrorCode TestLogLawFrictionVelocityStaysPositiveOnRoughWalls(void)
Tests that the log law's friction velocity stays positive on a rough wall.
static PetscErrorCode TestMinimalFixtureMirrorsProductionDMLayout(void)
Tests that the shared minimal fixture mirrors the production DA contract.
static PetscErrorCode TestFaceFluxVelocityIsDivergenceFree(void)
FaceFlux: divergence-free fluxes give a divergence-free velocity, zero at a wall face,...
static PetscErrorCode TestUpdateParticlePositionDiffusivityGradientOnly(void)
Tests particle position updates driven only by diffusivity-gradient drift.
static PetscErrorCode TestLocateAllParticlesInGridGuessPathResolvesLocalParticle(void)
Tests the guess-then-verify orchestrator path for a local particle with an unknown prior cell.
static PetscErrorCode TestWallModelVelocityHelpers(void)
Tests closed-form and iterative wall-model velocity helpers against inverse reconstructions.
static PetscErrorCode TestLocateParticleOrFindMigrationTargetCountsReSearch(void)
Verifies that later settlement passes increment re-search metrics.
static PetscErrorCode TestRuntimeWalltimeGuardParsesPositiveSeconds(void)
Tests parsing of positive runtime walltime metadata values.
static PetscErrorCode TestCart2ContraUsesFinalizedPeriodicUcat(void)
Verifies periodic Ucat endpoints are repaired before Cart2Contra terminal faces.
int main(int argc, char **argv)
Runs the unit-runtime PETSc test binary.
static PetscErrorCode TestInterpolateAllFieldsToSwarmConstantFields(void)
Tests direct interpolation from Eulerian fields to one localized swarm particle.
static PetscErrorCode SyncRuntimeFieldGhosts(UserCtx *user)
Synchronizes the minimal runtime fixture's global fields into their persistent local ghosts.
static PetscErrorCode TestStagedUcatFourierModesUsePicurvDiscreteSymbol(void)
Cross-checks selected exact Fourier modes against PICurv's native discrete symbol.
static PetscErrorCode TestCabotSignedStressAndIntegralAccuracy(void)
Tests Cabot's stress sign and its wall-layer integral at large y+.
static PetscErrorCode TestDistributeParticlesRemainderHandling(void)
Tests particle distribution remainder handling across ranks.
static PetscErrorCode TestResetAllParticleStatusesLeavesLostParticlesUntouched(void)
Tests localized particle-status reset behavior for restart of the location workflow.
static PetscErrorCode SeedSingleParticle(UserCtx *user, PetscInt ci, PetscInt cj, PetscInt ck, PetscReal x, PetscReal y, PetscReal z, PetscReal wx, PetscReal wy, PetscReal wz, PetscInt status_value)
Seeds one localized swarm particle with the cell, position, weight, and status data used by runtime t...
static PetscErrorCode TestPopulateInitialUcontLoadsStagedUcat(void)
Tests loading a staged Ucat file IC and converting it to Ucont.
static PetscErrorCode TestPopulateInitialUcontLoadsStagedUcont(void)
Tests loading a staged Ucont file IC without Cartesian conversion.
static PetscErrorCode TestInterpolateAllFieldsToSwarmFaceFluxConstantFields(void)
FaceFlux: constant face fluxes give that velocity; other fields still interpolate trilinearly.
static PetscErrorCode TestInterpolateAllFieldsToSwarmCornerAveragedConstantFields(void)
Tests the corner-averaged (legacy) interpolation path on constant fields.
static PetscErrorCode TestGetOwnedCellRangeSingleRankAccounting(void)
Tests owned-cell range accounting on a single MPI rank.
static PetscErrorCode TestUpdateParticlePositionWithoutBrownianContribution(void)
Tests particle position updates without Brownian forcing.
static PetscErrorCode TestComputeAndStoreNeighborRanksSingleRank(void)
Tests neighbor-rank discovery on a single MPI rank.
static PetscErrorCode TestCalculateParticleCountPerCellCountsGlobalCellIDs(void)
Tests particle counting by geometric cell IDs using the production +1 storage shift.
static PetscErrorCode TestSortParticlesByCellKeepsEachPointWhole(void)
Tests that sorting by host cell orders points k-slowest, keeps ties and every field together,...
static PetscErrorCode TestWriteLESFieldsCopiesOwnedPeriodicValues(void)
Tests LES output staging from local vectors on a multiply periodic DMDA.
static PetscErrorCode TestValidateDrivenFlowConfigurationNoDrivenHandlers(void)
Tests driven-flow validation when no driven handlers are present.
static PetscErrorCode TestMinimalFixtureRegistersProductionSwarmFields(void)
Tests that the shared swarm fixture registers the production field set.
static PetscErrorCode TestLocateAllParticlesInGridPriorCellFastPath(void)
Tests the location orchestrator fast path when a particle already carries a valid prior cell.
static PetscErrorCode TestScatterAllParticleFieldsToEulerFieldsAveragesPsi(void)
Tests particle-to-grid scattering using known cell occupancy and scalar values.
static PetscErrorCode TestBrownianDisplacementMoments(void)
Tests that increments over many particles have zero mean, variance 2 D dt, and uncorrelated component...
static PetscErrorCode TestUpdateSolverHistoryVectorsShiftsStates(void)
Tests solver history-vector shifting between time levels.
static PetscErrorCode TestUpdateParticleWeightsComputesExpectedRatios(void)
Tests particle weight updates against expected ratios.
static PetscErrorCode StagedFourierModeMaxDivergence(UserCtx *user, PetscInt mode_x, PetscInt mode_y, PetscInt mode_z, Cmpnts amplitude, const char *tmpdir, PetscReal *max_divergence)
Stages a real Cartesian Fourier mode through the production file-IC path.
static PetscErrorCode TestWallLawBranchesAreContinuous(void)
Tests that the wall laws' branches meet, so each reference speed has one friction velocity.
static PetscErrorCode TestLocateParticleOrFindMigrationTargetReflectsAtWall(void)
Tests that a particle beyond a reflecting -Xi face is mirrored back and located, including after a ta...
static PetscErrorCode TestCart2ContraConvertsCartesianField(void)
Tests spatially varying Cartesian-field conversion to contravariant fluxes.
static PetscErrorCode TestCheckAndRemoveLostParticlesRemovesLostEntries(void)
Tests removal of LOST and EXITED particles, their separate tallies, and that survivors keep the one-a...
static PetscErrorCode TestRuntimeWalltimeGuardEstimatorHelpers(void)
Tests walltime-guard estimator helper calculations.
static PetscErrorCode TestIsParticleInBoxBasicCases(void)
Tests basic particle-inside-bounding-box classification cases.
static PetscErrorCode TestRuntimeWalltimeGuardTriggerDecision(void)
Tests runtime walltime-guard shutdown trigger decisions.
static PetscErrorCode TestBrownianDisplacementIsKeyedOnSeedParticleAndStep(void)
Tests that a Brownian increment is a function of (seed, PID, step) alone.
static PetscErrorCode TestUpdateAllParticlePositionsMovesSwarmEntries(void)
Tests swarm-wide particle position updates using the same transport path as the runtime loop.
static PetscErrorCode TestWallModelScalarHelpers(void)
Tests wall-model scalar helper kernels.
PetscErrorCode PicurvMakeTempDir(char *path, size_t path_len)
Creates a unique temporary directory for one test case.
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 PicurvEnsureDir(const char *path)
Ensures a directory exists for test output.
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 PicurvCreateSwarmPair(UserCtx *user, PetscInt nlocal, const char *post_field_name)
Creates matched solver and post-processing swarms for tests.
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 PicurvAssertBool(PetscBool value, const char *context)
Asserts that one boolean condition is true.
PetscErrorCode PicurvRemoveTempDir(const char *path)
Recursively removes a temporary directory created by PicurvMakeTempDir.
Shared declarations for the PICurv C test fixture and assertion layer.
Named test case descriptor consumed by PicurvRunTests.
#define RANK_NEIGHBOR_INDEX(di, dj, dk)
Index in RankNeighbors::rank of the neighbour offset (di, dj, dk), each -1, 0 or 1.
BoundaryFaceConfig boundary_faces[6]
PetscInt64 searchLocatedCount
PetscInt64 reflectionCount
PetscInt64 searchLostCount
SimCtx * simCtx
Back-pointer to the master simulation context.
ParticleLocationStatus
Defines the state of a particle with respect to its location and migration status during the iterativ...
@ LOST
The search failed for a particle believed to be inside the domain.
@ EXITED
The particle crossed a domain-boundary face whose particle policy removes it.
@ PARTICLE_BOUNDARY_REFLECT
The particle is mirrored about the face plane and stays.
PetscInt64 traversalStepsSum
Cmpnts max_coords
Maximum x, y, z coordinates of the bounding box.
Cmpnts diffusivitygradient
PetscInt64 searchPopulation
PetscInt currentSettlementPass
Cmpnts min_coords
Minimum x, y, z coordinates of the bounding box.
char * current_io_directory
PetscInt64 bboxGuessFallbackCount
InterpolationMethod interpolationMethod
PetscInt64 bboxGuessSuccessCount
PetscInt64 maxParticlePassDepth
ParticleBoundaryPolicy particle_policy
What a particle crossing this face becomes (BC param particle_policy).
PetscInt particleRandomSeed
Base seed for every particle RNG stream (-particle_random_seed).
char initialConditionDirectory[PETSC_MAX_PATH_LEN]
PetscBool initialConditionStaged
SearchMetricsState searchMetrics
char _io_context_buffer[PETSC_MAX_PATH_LEN]
PetscInt les
Active LES closure; an LESModelType value.
PetscInt64 searchAttempts
InitialConditionField initialConditionField
PetscInt64 reflectionFallbackCount
PetscInt64 maxTraversalFailCount
Defines a 3D axis-aligned bounding box.
A 3D point or vector with PetscScalar components.
Defines a particle's core properties for Lagrangian tracking.
The master context for the entire simulation.
User-defined context containing data specific to a single computational grid level.
Header file for particle location functions using the walking search algorithm.
PetscErrorCode LocateParticleOrFindMigrationTarget(UserCtx *user, const struct FacePlaneArrays *planes, Particle *particle, ParticleLocationStatus *status_out)
double u_Werner(double kinematic_viscosity, double wall_distance, double friction_velocity)
Computes velocity using Werner-Wengle wall function.
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 u_Werner_explicit(double kinematic_viscosity, double wall_distance, double wall_shear_stress)
Wall-parallel velocity at a distance, from the Werner-Wengle wall stress.
double find_utau_hydset(double kinematic_viscosity, double known_velocity, double wall_distance, double initial_guess, double roughness_height)
Solves for friction velocity using Newton-Raphson iteration.
double u_Cabot(double kinematic_viscosity, double wall_distance, double friction_velocity, double pressure_gradient_tangent, double wall_shear_stress)
Computes velocity using Cabot wall function.
void find_utau_Cabot(double kinematic_viscosity, double velocity, double wall_distance, double initial_guess, double pressure_gradient_tangent, double pressure_gradient_normal, double *friction_velocity, double *wall_shear_velocity, double *wall_shear_normal)
Solves for friction velocity using Cabot wall function.
double integrate_1(double kinematic_viscosity, double wall_distance, double friction_velocity, int integration_mode)
Integrates eddy viscosity profile from wall to distance y.
double f_hydset(double kinematic_viscosity, double known_velocity, double wall_distance, double friction_velocity_guess, double roughness_height)
Residual function for friction velocity equation (log-law with roughness)
double E_coeff(double friction_velocity, double roughness_height, double kinematic_viscosity)
Computes roughness-modified log-law coefficient E.
double taw_Werner(double kinematic_viscosity, double velocity, double wall_distance)
Wall shear stress from the cell-integrated Werner-Wengle relation.
double nu_t(double yplus)
Computes turbulent eddy viscosity ratio (ν_t / ν)
double find_utau_Werner(double kinematic_viscosity, double velocity, double wall_distance, double initial_guess)
Friction velocity from a point velocity, inverting u_Werner() exactly.