21 double values[3][3][3];
22 double weights[3][3][3];
24 PetscFunctionBeginUser;
25 for (PetscInt k = 0; k < 3; ++k) {
26 for (PetscInt j = 0; j < 3; ++j) {
27 for (PetscInt i = 0; i < 3; ++i) {
28 values[k][j][i] = 2.0;
29 weights[k][j][i] = 1.0;
35 "Simpson-rule filter should preserve a constant field"));
38 "box filter should preserve a constant field"));
40 for (PetscInt k = 0; k < 3; ++k) {
41 for (PetscInt j = 0; j < 3; ++j) {
42 for (PetscInt i = 0; i < 3; ++i) {
43 weights[k][j][i] = 0.0;
48 "box filter should return zero when all weights are zero"));
49 PetscFunctionReturn(0);
61 PetscReal value = 0.0;
62 PetscReal ***target_arr = NULL;
63 PetscReal *positions = NULL;
64 PetscReal *psi = NULL;
66 PetscFunctionBeginUser;
71 point.
x = 0.2; point.
y = 0.3; point.
z = 0.4;
74 "constant scalar profile should evaluate to the configured value"));
76 PetscCall(DMSwarmGetField(user->
swarm,
"position", NULL, NULL, (
void **)&positions));
77 positions[0] = 0.1; positions[1] = 0.2; positions[2] = 0.3;
78 positions[3] = 0.8; positions[4] = 0.6; positions[5] = 0.4;
79 PetscCall(DMSwarmRestoreField(user->
swarm,
"position", NULL, NULL, (
void **)&positions));
82 PetscCall(DMSwarmGetField(user->
swarm,
"Psi", NULL, NULL, (
void **)&psi));
84 "SetVerificationScalarOnParticles should overwrite the first particle scalar"));
86 "SetVerificationScalarOnParticles should overwrite the second particle scalar"));
87 PetscCall(DMSwarmRestoreField(user->
swarm,
"Psi", NULL, NULL, (
void **)&psi));
90 point.
x = 0.25; point.
y = 0.0; point.
z = 0.0;
93 "linear-x scalar profile should evaluate phi0 + slope_x * x"));
95 PetscCall(VecDuplicate(user->
Psi, &target));
97 PetscCall(DMDAVecGetArrayRead(user->
da, target, &target_arr));
99 "cell-center scalar fill should use the physical x center coordinate"));
100 PetscCall(DMDAVecRestoreArrayRead(user->
da, target, &target_arr));
101 PetscCall(VecDestroy(&target));
104 point.
x = 0.5; point.
y = 0.5; point.
z = 0.5;
107 "sin-product scalar profile should peak at pi/2 in each coordinate"));
110 PetscFunctionReturn(0);
117 PetscFunctionBeginUser;
119 PetscCall(PetscOptionsSetValue(NULL,
"-ic_source_frame",
"cartesian"));
120 PetscCall(PetscOptionsSetValue(NULL,
"-ic_source_expr_0", u));
121 PetscCall(PetscOptionsSetValue(NULL,
"-ic_source_expr_1", v));
122 PetscCall(PetscOptionsSetValue(NULL,
"-ic_source_expr_2", w));
123 PetscCall(PetscOptionsClearValue(NULL,
"-ic_source_pressure"));
124 if (pressure) PetscCall(PetscOptionsSetValue(NULL,
"-ic_source_pressure", pressure));
125 PetscFunctionReturn(0);
136 Cmpnts ***ucat = NULL, ***ucont = NULL, ***ubcs = NULL;
138 PetscFunctionBeginUser;
141 PetscCall(VecSet(user->
Ucat, 3.0));
142 PetscCall(VecSet(user->
P, 5.0));
143 PetscCall(VecSet(user->
Bcs.
Ubcs, 7.0));
149 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
Bcs.
Ubcs, &ubcs));
150 PetscCall(
PicurvAssertRealNear(0.0, ubcs[0][1][1].z, 1.0e-12,
"a zero source should zero the boundary values"));
151 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
Bcs.
Ubcs, &ubcs));
153 "a uniform field has no interpolation error to measure"));
157 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
Ucat, &ucat));
158 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
Ucont, &ucont));
159 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
Bcs.
Ubcs, &ubcs));
160 PetscCall(
PicurvAssertRealNear(1.25, ucat[1][1][1].x, 1.0e-12,
"the source should set the interior x velocity"));
161 PetscCall(
PicurvAssertRealNear(-0.5, ucat[1][1][1].y, 1.0e-12,
"the source should set the interior y velocity"));
162 PetscCall(
PicurvAssertRealNear(0.75, ucat[1][1][1].z, 1.0e-12,
"the source should set the interior z velocity"));
163 PetscCall(
PicurvAssertRealNear(1.25, ucont[1][1][1].x, 1.0e-12,
"the source should set the xi flux"));
164 PetscCall(
PicurvAssertRealNear(-0.5, ucont[1][1][1].y, 1.0e-12,
"the source should set the eta flux"));
165 PetscCall(
PicurvAssertRealNear(0.75, ucont[1][1][1].z, 1.0e-12,
"the source should set the zeta flux"));
166 PetscCall(
PicurvAssertRealNear(0.75, ucont[0][1][1].z, 1.0e-12,
"the source should set the boundary face's flux"));
167 PetscCall(
PicurvAssertRealNear(1.25, ubcs[0][1][1].x, 1.0e-12,
"the source should set the boundary x velocity"));
168 PetscCall(
PicurvAssertRealNear(0.75, ubcs[0][1][1].z, 1.0e-12,
"the source should set the boundary z velocity"));
169 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
Bcs.
Ubcs, &ubcs));
170 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
Ucont, &ucont));
171 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
Ucat, &ucat));
174 PetscCall(VecSet(user->
P, 9.0));
180 PetscCall(PetscOptionsSetValue(NULL,
"-ic_source_bulk_velocity",
"2"));
182 PetscCall(PetscOptionsClearValue(NULL,
"-ic_source_bulk_velocity"));
183 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
Ucat, &ucat));
184 PetscCall(
PicurvAssertRealNear(2.0, ucat[1][1][1].z, 1.0e-12,
"the source should reach its bulk velocity"));
185 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
Ucat, &ucat));
189 PetscFunctionReturn(0);
204 PetscReal ***p = NULL;
205 const PetscReal vel_decay = PetscExpReal(-0.5);
207 PetscFunctionBeginUser;
211 PetscCall(
UseAnalyticalSource(simCtx,
"sin(x)*cos(y)*cos(z)*exp(-2*0.5*t)",
"(-cos(x)*sin(y)*cos(z)*exp(-2*0.5*t))",
"0",
212 "0.25*(cos(2*x) + cos(2*y))*exp(-4*0.5*t)"));
214 PetscCall(DMDAVecGetArray(user->
fda, user->
Cent, ¢));
215 PetscCall(DMDAVecGetArray(user->
fda, user->
lCentx, ¢_x));
216 PetscCall(DMDAVecGetArray(user->
fda, user->
lCenty, ¢_y));
217 PetscCall(DMDAVecGetArray(user->
fda, user->
lCentz, ¢_z));
218 for (PetscInt k = user->
info.zs; k < user->
info.zs + user->
info.zm; ++k) {
219 for (PetscInt j = user->
info.ys; j < user->
info.ys + user->
info.ym; ++j) {
220 for (PetscInt i = user->
info.xs; i < user->
info.xs + user->
info.xm; ++i) {
221 cent[k][j][i].
x = 0.0;
222 cent[k][j][i].
y = 0.0;
223 cent[k][j][i].
z = 0.0;
224 cent_x[k][j][i] = cent[k][j][i];
225 cent_y[k][j][i] = cent[k][j][i];
226 cent_z[k][j][i] = cent[k][j][i];
230 cent[1][1][1].
x = 0.5 * PETSC_PI;
231 cent[1][1][1].
y = 0.0;
232 cent[1][1][1].
z = 0.0;
233 cent[1][2][1].
x = 0.0;
234 cent[1][2][1].
y = 0.5 * PETSC_PI;
235 cent[1][2][1].
z = 0.0;
236 cent_z[0][1][1].
x = 0.5 * PETSC_PI;
237 cent_z[0][1][1].
y = 0.0;
238 cent_z[0][1][1].
z = 0.0;
239 PetscCall(DMDAVecRestoreArray(user->
fda, user->
lCentz, ¢_z));
240 PetscCall(DMDAVecRestoreArray(user->
fda, user->
lCenty, ¢_y));
241 PetscCall(DMDAVecRestoreArray(user->
fda, user->
lCentx, ¢_x));
242 PetscCall(DMDAVecRestoreArray(user->
fda, user->
Cent, ¢));
246 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
Ucat, &ucat));
247 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
Bcs.
Ubcs, &ubcs));
248 PetscCall(DMDAVecGetArrayRead(user->
da, user->
P, &p));
249 PetscCall(
PicurvAssertRealNear(vel_decay, ucat[1][1][1].x, 1.0e-12,
"TGV sample should set the expected interior x velocity"));
250 PetscCall(
PicurvAssertRealNear(0.0, ucat[1][1][1].y, 1.0e-12,
"TGV sample should keep the paired interior y velocity at zero"));
251 PetscCall(
PicurvAssertRealNear(-vel_decay, ucat[1][2][1].y, 1.0e-12,
"TGV sample should set the expected interior y velocity"));
252 PetscCall(
PicurvAssertRealNear(0.0, p[1][1][1], 1.0e-12,
"Chosen TGV sample should produce zero pressure"));
253 PetscCall(
PicurvAssertRealNear(vel_decay, ubcs[0][1][1].x, 1.0e-12,
"TGV sample should set the expected boundary x velocity"));
254 PetscCall(
PicurvAssertRealNear(0.0, ubcs[0][1][1].y, 1.0e-12,
"TGV boundary sample should keep the paired y velocity at zero"));
255 PetscCall(DMDAVecRestoreArrayRead(user->
da, user->
P, &p));
256 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
Bcs.
Ubcs, &ubcs));
257 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
Ucat, &ucat));
261 PetscFunctionReturn(0);
271 Cmpnts ***cent_x = NULL, ***ubcs = NULL, ***ucat = NULL;
273 PetscFunctionBeginUser;
276 const PetscInt mx = user->
info.mx;
278 PetscCall(DMDAVecGetArray(user->
fda, user->
lCentx, ¢_x));
279 cent_x[1][1][0].
x = 0.25;
280 cent_x[1][1][mx - 2].
x = 2.0;
281 cent_x[1][1][mx - 1].
x = -7.0;
282 PetscCall(DMDAVecRestoreArray(user->
fda, user->
lCentx, ¢_x));
286 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
Bcs.
Ubcs, &ubcs));
287 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
Ucat, &ucat));
288 PetscCall(
PicurvAssertRealNear(0.25, ubcs[1][1][0].x, 1.0e-12,
"the - face's value should be the source at its centre"));
289 PetscCall(
PicurvAssertRealNear(2.0, ubcs[1][1][mx - 1].x, 1.0e-12,
"the + face's value should be the source at its centre"));
290 PetscCall(
PicurvAssertRealNear(2.0, 0.5 * (ucat[1][1][mx - 1].x + ucat[1][1][mx - 2].x), 1.0e-12,
291 "the dummy and last cell should average to the + face's value"));
292 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
Ucat, &ucat));
293 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
Bcs.
Ubcs, &ubcs));
295 PetscFunctionReturn(0);
306 PetscReal *data = NULL;
307 PetscErrorCode ierr_uniform;
308 const PetscReal vel_decay = PetscExpReal(-0.5);
310 PetscFunctionBeginUser;
314 PetscCall(
UseAnalyticalSource(simCtx,
"sin(x)*cos(y)*cos(z)*exp(-2*0.5*t)",
"(-cos(x)*sin(y)*cos(z)*exp(-2*0.5*t))",
"0", NULL));
317 "a source in x, y, z and t can be compared at particles"));
319 PetscCall(VecCreateSeq(PETSC_COMM_SELF, 6, &tempVec));
320 PetscCall(VecGetArray(tempVec, &data));
321 data[0] = 0.5 * PETSC_PI; data[1] = 0.0; data[2] = 0.0;
322 data[3] = 0.0; data[4] = 0.5 * PETSC_PI; data[5] = 0.0;
323 PetscCall(VecRestoreArray(tempVec, &data));
325 PetscCall(VecGetArray(tempVec, &data));
330 PetscCall(VecRestoreArray(tempVec, &data));
335 "a source in grid-line fractions cannot be evaluated at a point"));
336 PetscCall(PetscPushErrorHandler(PetscIgnoreErrorHandler, NULL));
338 PetscCall(PetscPopErrorHandler());
339 PetscCall(
PicurvAssertBool((PetscBool)(ierr_uniform != 0),
"evaluating such a source at particles should fail"));
341 PetscCall(VecDestroy(&tempVec));
344 PetscFunctionReturn(0);
355 PetscReal ***
nu_t = NULL;
359 const PetscReal coefficient = 0.25;
360 const PetscReal expected_nu_t = 0.25 * PetscSqrtReal(2.0);
362 PetscFunctionBeginUser;
365 PetscCall(DMCreateGlobalVector(user->
da, &user->
Nu_t));
366 PetscCall(DMCreateLocalVector(user->
da, &user->
lNu_t));
367 PetscCall(DMCreateGlobalVector(user->
da, &user->
CS));
368 PetscCall(DMCreateLocalVector(user->
da, &user->
lCs));
370 PetscCall(VecSet(user->
Aj, 1.0));
371 PetscCall(VecSet(user->
Nu_t, 0.0));
372 PetscCall(VecSet(user->
CS, coefficient));
373 PetscCall(DMDAVecGetArray(user->
fda, user->
Ucat, &ucat));
374 for (PetscInt k = user->
info.zs; k < user->
info.zs + user->
info.zm; ++k) {
375 for (PetscInt j = user->
info.ys; j < user->
info.ys + user->
info.ym; ++j) {
376 for (PetscInt i = user->
info.xs; i < user->
info.xs + user->
info.xm; ++i) {
377 ucat[k][j][i].
x = (PetscReal)i;
378 ucat[k][j][i].
y = 0.0;
379 ucat[k][j][i].
z = 0.0;
383 PetscCall(DMDAVecRestoreArray(user->
fda, user->
Ucat, &ucat));
384 PetscCall(DMGlobalToLocalBegin(user->
fda, user->
Ucat, INSERT_VALUES, user->
lUcat));
385 PetscCall(DMGlobalToLocalEnd(user->
fda, user->
Ucat, INSERT_VALUES, user->
lUcat));
386 PetscCall(DMGlobalToLocalBegin(user->
da, user->
Aj, INSERT_VALUES, user->
lAj));
387 PetscCall(DMGlobalToLocalEnd(user->
da, user->
Aj, INSERT_VALUES, user->
lAj));
388 PetscCall(DMGlobalToLocalBegin(user->
da, user->
CS, INSERT_VALUES, user->
lCs));
389 PetscCall(DMGlobalToLocalEnd(user->
da, user->
CS, INSERT_VALUES, user->
lCs));
392 PetscCall(DMDAVecGetArrayRead(user->
da, user->
Nu_t, &
nu_t));
394 "linear velocity field should yield deterministic LES eddy viscosity"));
396 "boundary cells should remain untouched by the interior LES loop"));
397 PetscCall(DMDAVecRestoreArrayRead(user->
da, user->
Nu_t, &
nu_t));
399 PetscCall(VecDestroy(&user->
CS));
400 PetscCall(VecDestroy(&user->
lCs));
402 PetscFunctionReturn(0);
412 PetscErrorCode ierr_flow = 0;
414 PetscFunctionBeginUser;
418 PetscCall(PetscPushErrorHandler(PetscIgnoreErrorHandler, NULL));
420 PetscCall(PetscPopErrorHandler());
422 "FlowSolver should reject unsupported momentum solver selectors"));
425 PetscFunctionReturn(0);
441 PetscFunctionBeginUser;
443 PetscCall(VecDuplicate(user->
Ucont, &rct));
444 PetscCall(VecZeroEntries(rct));
456 PetscCall(VecSet(user->
Nvert, 0.0));
457 PetscCall(DMGlobalToLocalBegin(user->
da, user->
Nvert, INSERT_VALUES, user->
lNvert));
458 PetscCall(DMGlobalToLocalEnd(user->
da, user->
Nvert, INSERT_VALUES, user->
lNvert));
459 PetscCall(DMDAVecGetArray(user->
fda, user->
lCsi, &l_csi));
460 PetscCall(DMDAVecGetArray(user->
fda, user->
lEta, &l_eta));
461 PetscCall(DMDAVecGetArray(user->
fda, user->
lZet, &l_zet));
462 l_csi[1][1][1].
x = 1.0; l_csi[1][1][1].
y = 0.0; l_csi[1][1][1].
z = 0.0;
463 l_eta[1][1][1].
x = 0.0; l_eta[1][1][1].
y = 1.0; l_eta[1][1][1].
z = 0.0;
464 l_zet[1][1][1].
x = 0.0; l_zet[1][1][1].
y = 0.0; l_zet[1][1][1].
z = 1.0;
465 PetscCall(DMDAVecRestoreArray(user->
fda, user->
lZet, &l_zet));
466 PetscCall(DMDAVecRestoreArray(user->
fda, user->
lEta, &l_eta));
467 PetscCall(DMDAVecRestoreArray(user->
fda, user->
lCsi, &l_csi));
470 PetscCall(DMDAVecGetArrayRead(user->
fda, rct, &rct_arr));
472 "driven flow source should update the controller magnitude"));
474 "driven flow source should leave the y component unchanged"));
476 "driven flow source should leave the z component unchanged"));
477 PetscCall(DMDAVecRestoreArrayRead(user->
fda, rct, &rct_arr));
479 PetscCall(VecDestroy(&rct));
481 PetscFunctionReturn(0);
500 PetscInt gxs, gys, gzs, gxm, gym, gzm;
501 PetscFunctionBeginUser;
502 PetscCall(DMDAGetGhostCorners(fda, &gxs, &gys, &gzs, &gxm, &gym, &gzm));
503 PetscCall(DMDAVecGetArray(fda, lvec, &a));
504 for (PetscInt k = gzs; k < gzs+gzm; ++k)
505 for (PetscInt j = gys; j < gys+gym; ++j)
506 for (PetscInt i = gxs; i < gxs+gxm; ++i) { a[k][j][i].
x = x; a[k][j][i].
y = y; a[k][j][i].
z = z; }
507 PetscCall(DMDAVecRestoreArray(fda, lvec, &a));
508 PetscFunctionReturn(0);
521 PetscInt gxs, gys, gzs, gxm, gym, gzm;
522 PetscFunctionBeginUser;
523 PetscCall(DMDAGetGhostCorners(da, &gxs, &gys, &gzs, &gxm, &gym, &gzm));
524 PetscCall(DMDAVecGetArray(da, lvec, &a));
525 for (PetscInt k = gzs; k < gzs+gzm; ++k)
526 for (PetscInt j = gys; j < gys+gym; ++j)
527 for (PetscInt i = gxs; i < gxs+gxm; ++i) a[k][j][i] = v;
528 PetscCall(DMDAVecRestoreArray(da, lvec, &a));
529 PetscFunctionReturn(0);
543 PetscInt gxs, gys, gzs, gxm, gym, gzm;
544 PetscFunctionBeginUser;
545 PetscCall(DMDAGetGhostCorners(da, &gxs, &gys, &gzs, &gxm, &gym, &gzm));
546 PetscCall(DMDAVecGetArray(da, lvec, &a));
548 if (ci >= gxs && ci < gxs+gxm && cj >= gys && cj < gys+gym && ck >= gzs && ck < gzs+gzm)
550 PetscCall(DMDAVecRestoreArray(da, lvec, &a));
551 PetscFunctionReturn(0);
559 PetscFunctionBeginUser;
576 "restored history enables BDF2 at restart setup"));
579 "restored history enables BDF2 on first restart solve"));
581 PetscFunctionReturn(0);
588 PetscBool px, PetscBool py, PetscBool pz,
BCType bc)
590 PetscFunctionBeginUser;
598 (*simCtx)->dt = 0.1; (*simCtx)->step = 1; (*simCtx)->StartStep = 0;
599 (*simCtx)->ren = 1.0; (*simCtx)->les = 0;
600 (*simCtx)->central = 0; (*simCtx)->invicid = 0; (*simCtx)->block_number = 1;
601 (*simCtx)->TwoD = 0; (*simCtx)->les_gradient_model = 0;
604 if (!(*user)->lNu_t) PetscCall(DMCreateLocalVector((*user)->da, &(*user)->lNu_t));
609 PetscFunctionReturn(0);
615 const PetscBool p = (PetscBool)(bc ==
PERIODIC);
616 PetscFunctionBeginUser;
618 PetscFunctionReturn(0);
625 PetscFunctionBeginUser;
636 PetscFunctionReturn(0);
643 PetscFunctionBeginUser;
651 PetscFunctionReturn(0);
658 PetscFunctionBeginUser;
666 PetscFunctionReturn(0);
673 PetscFunctionBeginUser;
681 PetscFunctionReturn(0);
688 PetscFunctionBeginUser;
694 PetscFunctionReturn(0);
701 PetscFunctionBeginUser;
708 PetscFunctionReturn(0);
715 PetscFunctionBeginUser;
725 PetscFunctionReturn(0);
732 PetscReal n_ucont_0, n_ucat_0, n_nvert_0, n_ucont_1, n_ucat_1, n_nvert_1;
733 PetscFunctionBeginUser;
738 PetscCall(VecNorm(user->
lUcont, NORM_2, &n_ucont_0));
739 PetscCall(VecNorm(user->
lUcat, NORM_2, &n_ucat_0));
740 PetscCall(VecNorm(user->
lNvert, NORM_2, &n_nvert_0));
742 PetscCall(VecNorm(user->
lUcont, NORM_2, &n_ucont_1));
743 PetscCall(VecNorm(user->
lUcat, NORM_2, &n_ucat_1));
744 PetscCall(VecNorm(user->
lNvert, NORM_2, &n_nvert_1));
750 PetscFunctionReturn(0);
761 const PetscReal sx = dy*dz, sy = dx*dz, sz = dx*dy, aj = 1.0/(dx*dy*dz);
766 PetscFunctionBeginUser;
767 for (
int t = 0; t < 4; ++t) {
773 PetscFunctionReturn(0);
786 PetscInt gxs, gys, gzs, gxm, gym, gzm;
787 PetscFunctionBeginUser;
788 PetscCall(DMDAGetGhostCorners(fda, &gxs, &gys, &gzs, &gxm, &gym, &gzm));
789 PetscCall(DMDAVecGetArray(fda, lvec, &a));
790 for (PetscInt k = gzs; k < gzs+gzm; ++k)
791 for (PetscInt j = gys; j < gys+gym; ++j)
792 for (PetscInt i = gxs; i < gxs+gxm; ++i) { a[k][j][i].
x = slope*i; a[k][j][i].
y = 0; a[k][j][i].
z = 0; }
793 PetscCall(DMDAVecRestoreArray(fda, lvec, &a));
794 PetscFunctionReturn(0);
807 PetscInt gxs, gys, gzs, gxm, gym, gzm;
808 PetscFunctionBeginUser;
809 PetscCall(DMDAGetGhostCorners(fda, &gxs, &gys, &gzs, &gxm, &gym, &gzm));
810 PetscCall(DMDAVecGetArray(fda, lvec, &a));
811 for (PetscInt k = gzs; k < gzs+gzm; ++k)
812 for (PetscInt j = gys; j < gys+gym; ++j)
813 for (PetscInt i = gxs; i < gxs+gxm; ++i) { a[k][j][i].
x = gamma*j; a[k][j][i].
y = 0; a[k][j][i].
z = 0; }
814 PetscCall(DMDAVecRestoreArray(fda, lvec, &a));
815 PetscFunctionReturn(0);
823 PetscFunctionBeginUser;
830 PetscFunctionReturn(0);
837 PetscFunctionBeginUser;
845 PetscFunctionReturn(0);
852 const PetscInt offs[3][3] = {{1,0,0},{0,1,0},{0,0,1}};
853 PetscFunctionBeginUser;
854 for (
int d = 0; d < 3; ++d) {
858 4+offs[d][0], 4+offs[d][1], 4+offs[d][2], 1.0));
872 PetscFunctionReturn(0);
880 PetscFunctionBeginUser;
897 PetscFunctionReturn(0);
904 PetscErrorCode e1 = 0, e2 = 0;
905 PetscFunctionBeginUser;
909 PetscCall(PetscPushErrorHandler(PetscIgnoreErrorHandler, NULL));
911 PetscCall(PetscPopErrorHandler());
912 PetscCall(
PicurvAssertBool((PetscBool)(e1 != 0),
"block_number<=0 rejected"));
915 PetscCall(PetscPushErrorHandler(PetscIgnoreErrorHandler, NULL));
917 PetscCall(PetscPopErrorHandler());
918 PetscCall(
PicurvAssertBool((PetscBool)(e2 != 0),
"non-finite inverse-Jacobian rejected"));
921 PetscFunctionReturn(0);
928 PetscFunctionBeginUser;
936 PetscFunctionReturn(0);
943 PetscFunctionBeginUser;
957 PetscFunctionReturn(0);
964 PetscFunctionBeginUser;
974 PetscFunctionReturn(0);
981 Vec ucont0, ucat0, nvert0, nut0, aj0;
983 PetscFunctionBeginUser;
989 PetscCall(VecDuplicate(user->
lUcont, &ucont0)); PetscCall(VecCopy(user->
lUcont, ucont0));
990 PetscCall(VecDuplicate(user->
lUcat, &ucat0)); PetscCall(VecCopy(user->
lUcat, ucat0));
991 PetscCall(VecDuplicate(user->
lNvert, &nvert0)); PetscCall(VecCopy(user->
lNvert, nvert0));
992 PetscCall(VecDuplicate(user->
lNu_t, &nut0)); PetscCall(VecCopy(user->
lNu_t, nut0));
993 PetscCall(VecDuplicate(user->
lAj, &aj0)); PetscCall(VecCopy(user->
lAj, aj0));
996 PetscCall(VecEqual(user->
lUcat, ucat0, &eq)); PetscCall(
PicurvAssertBool(eq,
"lUcat bit-identical"));
999 PetscCall(VecEqual(user->
lAj, aj0, &eq)); PetscCall(
PicurvAssertBool(eq,
"lAj bit-identical"));
1000 PetscCall(VecDestroy(&ucont0)); PetscCall(VecDestroy(&ucat0)); PetscCall(VecDestroy(&nvert0));
1001 PetscCall(VecDestroy(&nut0)); PetscCall(VecDestroy(&aj0));
1003 PetscFunctionReturn(0);
1012 const PetscInt mx = 9, my = 9, mz = 9;
1013 PetscFunctionBeginUser;
1015 PetscCall(DMDAVecGetArray(user->
da, user->
lNvert, &nvert));
1017 PetscCall(
PicurvAssertIntEqual(0x7,
MomCellActiveRows(nvert,4,4,4,mx,my,mz,PETSC_FALSE,PETSC_FALSE,PETSC_FALSE,0),
"all rows active (periodic interior)"));
1018 PetscCall(
PicurvAssertIntEqual(0x6,
MomCellActiveRows(nvert,4,4,4,mx,my,mz,PETSC_FALSE,PETSC_FALSE,PETSC_FALSE,1),
"TwoD=1 clears xi row"));
1019 PetscCall(
PicurvAssertIntEqual(0x5,
MomCellActiveRows(nvert,4,4,4,mx,my,mz,PETSC_FALSE,PETSC_FALSE,PETSC_FALSE,2),
"TwoD=2 clears eta row"));
1020 PetscCall(
PicurvAssertIntEqual(0x3,
MomCellActiveRows(nvert,4,4,4,mx,my,mz,PETSC_FALSE,PETSC_FALSE,PETSC_FALSE,3),
"TwoD=3 clears zeta row"));
1022 PetscCall(
PicurvAssertIntEqual(0x6,
MomCellActiveRows(nvert,4,4,mx-2,mx,my,mz,PETSC_TRUE,PETSC_FALSE,PETSC_FALSE,0),
"pos non-periodic xi face clears xi row"));
1025 PetscCall(DMDAVecRestoreArray(user->
da, user->
lNvert, &nvert));
1026 PetscCall(DMDAVecGetArray(user->
da, user->
lNvert, &nvert));
1027 PetscCall(
PicurvAssertIntEqual(0,
MomCellActiveRows(nvert,4,4,4,mx,my,mz,PETSC_FALSE,PETSC_FALSE,PETSC_FALSE,0),
"solid cell -> all rows inactive"));
1028 PetscCall(DMDAVecRestoreArray(user->
da, user->
lNvert, &nvert));
1030 PetscFunctionReturn(0);
1037 PetscErrorCode e_bad = 0; PetscBool eq;
1039 PetscFunctionBeginUser;
1042 PetscCall(VecDuplicate(user->
lAj, &aj_good)); PetscCall(VecCopy(user->
lAj, aj_good));
1045 PetscCall(PetscPushErrorHandler(PetscIgnoreErrorHandler, NULL));
1047 PetscCall(PetscPopErrorHandler());
1048 PetscCall(
PicurvAssertBool((PetscBool)(e_bad != 0),
"bad metric triggers error"));
1051 PetscCall(VecCopy(aj_good, user->
lAj));
1052 PetscCall(VecEqual(user->
lAj, aj_good, &eq));
1053 PetscCall(
PicurvAssertBool(eq,
"lAj usable after error (arrays were restored)"));
1058 PetscCall(VecDestroy(&aj_good));
1060 PetscFunctionReturn(0);
1068 Vec Rhs, ref; PetscReal dt, nrm;
1069 PetscFunctionBeginUser;
1072 PetscCall(VecSet(user->
Ucont, 2.0));
1073 PetscCall(VecSet(user->
Ucont_o, 1.0));
1074 PetscCall(VecSet(user->
Ucont_rm1, 0.5));
1075 PetscCall(VecDuplicate(user->
Ucont, &Rhs));
1076 PetscCall(VecDuplicate(user->
Ucont, &ref));
1083 PetscCall(VecSet(Rhs, 3.0));
1084 PetscCall(VecAXPY(Rhs, -a0/dt, user->
Ucont));
1085 PetscCall(VecAXPY(Rhs, +2.0/dt, user->
Ucont_o));
1086 PetscCall(VecAXPY(Rhs, -0.5/dt, user->
Ucont_rm1));
1088 PetscCall(VecSet(ref, -9.5));
1089 PetscCall(VecAXPY(ref, -1.0, Rhs)); PetscCall(VecNorm(ref, NORM_INFINITY, &nrm));
1097 PetscCall(VecSet(Rhs, 3.0));
1098 PetscCall(VecAXPY(Rhs, -a0/dt, user->
Ucont));
1099 PetscCall(VecAXPY(Rhs, +1.0/dt, user->
Ucont_o));
1101 PetscCall(VecSet(ref, -7.0));
1102 PetscCall(VecAXPY(ref, -1.0, Rhs)); PetscCall(VecNorm(ref, NORM_INFINITY, &nrm));
1105 PetscCall(VecDestroy(&Rhs)); PetscCall(VecDestroy(&ref));
1107 PetscFunctionReturn(0);
1116 PetscErrorCode ierr;
1150 ierr = PetscInitialize(&argc, &argv, NULL,
"PICurv solver utility tests");
1155 ierr =
PicurvRunTests(
"unit-solver", cases,
sizeof(cases) /
sizeof(cases[0]));
1161 ierr = PetscFinalize();
PetscErrorCode AnalyticalFieldDestroy(SimCtx *simCtx)
Release what AnalyticalSolutionEngine() keeps from step to step, if anything.
PetscErrorCode AnalyticalSolutionEngine(SimCtx *simCtx)
Sets the Eulerian fields from the case's source (-ic_source_*) at the step's time.
PetscBool AnalyticalFieldSupportsInterpolationError(const SimCtx *simCtx)
Reports whether the analytical field can be compared with interpolated particle velocities.
PetscErrorCode SetAnalyticalSolutionForParticles(Vec tempVec, SimCtx *simCtx)
Evaluates the analytical velocity at particle positions.
Momentum source terms added to the contravariant RHS.
PetscErrorCode ComputeDrivenChannelFlowSource(UserCtx *user, Vec Rct)
Applies a momentum source term to drive flow in a periodic channel or pipe.
double ApplyLESTestFilter(LESTestFilterKernel kernel, double values[3][3][3], double weights[3][3][3])
Applies a numerical "test filter" to a 3x3x3 stencil of data points.
PetscErrorCode ComputeEddyViscosityLES(UserCtx *user)
Computes the turbulent eddy viscosity for one block.
@ MOM_STAB_LIMITER_VISCOSITY
PetscBool MomentumUsesBDF2(SimCtx *simCtx)
Returns whether the current physical step uses the BDF2 discretization.
PetscReal MomentumBDFCoefficient(SimCtx *simCtx)
Returns the BDF physical-time coefficient a0 for the current step.
PetscInt MomCellActiveRows(PetscReal ***nvert, PetscInt k, PetscInt j, PetscInt i, PetscInt mx, PetscInt my, PetscInt mz, PetscBool np_x1, PetscBool np_y1, PetscBool np_z1, PetscInt twoD)
Active staggered-momentum row mask for a cell (exposed for unit testing).
PetscErrorCode ComputeMomentumStabilityEstimate(UserCtx *user, PetscInt block_number, PetscReal dt, MomStabCandidate candidate, MomStabilityReport *rep)
Compute the momentum pseudo-time stability estimate (shadow/diagnostic).
Diagnostic report produced by ComputeMomentumStabilityEstimate().
PetscErrorCode FlowSolver(SimCtx *simCtx)
Orchestrates a single time step of the Eulerian fluid solver.
static PetscErrorCode TestAnalyticalSolutionEngineTaylorGreenSamples(void)
Tests exact Taylor-Green samples on selected Eulerian interior and boundary points.
static PetscErrorCode TestMomentumStabilityWallSuppression(void)
static PetscErrorCode TestAnalyticalBoundaryValuesAreAtFaceCentres(void)
Tests that a boundary value is the source at its own face's centre on both sides: a + face's value li...
static PetscErrorCode MomSetLocalScalarCell(DM da, Vec lvec, PetscInt ci, PetscInt cj, PetscInt ck, PetscReal v)
Sets a single local-scalar cell value (e.g.
static PetscErrorCode TestMomentumActiveRowsHelper(void)
static PetscErrorCode TestComputeEddyViscosityLESDeterministicField(void)
Tests deterministic LES eddy-viscosity computation on a linear velocity field.
static PetscErrorCode TestFlowSolverRejectsUnsupportedMomentumSolverType(void)
Tests FlowSolver guardrails for unsupported momentum solver selections.
static PetscErrorCode TestMomentumStabilityOneSidedDirections(void)
int main(int argc, char **argv)
Runs the unit-solver PETSc test binary.
static PetscErrorCode UseAnalyticalSource(SimCtx *simCtx, const char *u, const char *v, const char *w, const char *pressure)
Selects an analytical field: the options a case's source becomes.
static PetscErrorCode TestMomentumStabilityReadOnly(void)
static PetscErrorCode TestMomentumStabilityOneSidedViscous(void)
static PetscErrorCode MomSetCartesianMetrics(UserCtx *user, PetscReal dx, PetscReal dy, PetscReal dz)
Sets uniform Cartesian metrics for spacing (dx,dy,dz) on all cell and face arrays.
static PetscErrorCode TestAnalyticalScalarVerificationHelpers(void)
Tests analytical scalar verification helper routines.
static PetscErrorCode TestMomentumStabilityReadOnlyExact(void)
static PetscErrorCode TestAnalyticalSolutionEngineFollowsItsSource(void)
Tests that the field is the source: zero, then uniform with its face fluxes and boundary values,...
static PetscErrorCode TestMomentumStabilityErrorReentry(void)
static PetscErrorCode TestMomentumStabilityActiveRowMask(void)
static PetscErrorCode TestMomentumStabilityCandidateDShear(void)
static PetscErrorCode TestMomentumStabilityViscousLongitudinal(void)
static PetscErrorCode MomMakeUnitGrid(SimCtx **simCtx, UserCtx **user, PetscInt n, BCType bc)
static PetscErrorCode TestMomentumStabilityCandidateBCDivergence(void)
static PetscErrorCode TestDrivenChannelFlowSource(void)
Tests driven-channel flow source-term evaluation.
static PetscErrorCode MomFillLocalCmpnts(DM fda, Vec lvec, PetscReal x, PetscReal y, PetscReal z)
Fills a local Cmpnts vector (ghosts included) with a uniform vector value.
static PetscErrorCode TestMomentumStabilityViscousScalesWithNu(void)
static PetscErrorCode TestMomentumStabilityAnisotropicViscous(void)
static PetscErrorCode TestAnalyticalSolutionForParticlesEvaluatesTheSource(void)
Tests the source evaluated at particle positions, and the fields it cannot be evaluated for.
static PetscErrorCode TestMomentumBDFCoefficient(void)
static PetscErrorCode TestMomentumStabilityCenteredConvection(void)
static PetscErrorCode TestMomentumStabilityDirectionalQuick(void)
static PetscErrorCode MomMakeUnitGridP(SimCtx **simCtx, UserCtx **user, PetscInt n, PetscBool px, PetscBool py, PetscBool pz, BCType bc)
static PetscErrorCode TestMomentumBDFResidualCombination(void)
static PetscErrorCode MomFillLocalScalar(DM da, Vec lvec, PetscReal v)
Fills a local scalar vector (ghosts included) with a uniform value.
static PetscErrorCode TestLESTestFilterPaths(void)
Tests LES test-filter helper paths for representative cases.
static PetscErrorCode MomFillUcatShearY(DM fda, Vec lvec, PetscReal gamma)
Fills lUcat as a linear shear u=(gamma*j,0,0) so |grad u|_inf = gamma.
static PetscErrorCode TestMomentumStabilityQuickBoundary(void)
static PetscErrorCode TestMomentumStabilityLESEddyViscosity(void)
static PetscErrorCode TestMomentumStabilityQuickInterior(void)
static PetscErrorCode MomFillUcontXRamp(DM fda, Vec lvec, PetscReal slope)
Fills lUcont.x as a linear ramp slope*i (nonzero discrete contravariant divergence).
static PetscErrorCode TestMomentumStabilityValidation(void)
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 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 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.
BCType
Defines the general mathematical/physical Category of a boundary.
BoundaryFaceConfig boundary_faces[6]
PetscReal forceScalingFactor
@ BC_HANDLER_PERIODIC_DRIVEN_CONSTANT_FLUX
BCHandlerType handler_type
PetscReal bulkVelocityCorrection
@ LES_TEST_FILTER_SIMPSON_IK
@ LES_TEST_FILTER_VOLUME_WEIGHTED_BOX
Vec Ubcs
Physical Cartesian velocity at boundary faces. Full 3D array but only boundary-face entries are meani...
MomentumSolverType
Enumerator to identify the implemented momentum solver strategies.
PetscInt les
Active LES closure; an LESModelType value.
PetscBool restartHistoryAvailable
MomentumSolverType mom_solver_type
VerificationFieldConfig verificationScalar
PetscReal drivingForceMagnitude
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.
PetscErrorCode VerificationFieldCompile(const char *text, VerificationFieldConfig *field)
Compiles a verification field's expression, in physical x, y, z and t, and enables the field.
PetscErrorCode SetVerificationScalarOnParticles(UserCtx *user, ParticleFieldId particle_field_id)
Writes the configured verification scalar profile onto a particle swarm scalar field.
PetscErrorCode VerificationFieldEvaluate(const SimCtx *simCtx, const VerificationFieldConfig *field, Cmpnts point, PetscReal solver_time, PetscReal *value)
Evaluates a verification field at a point.
PetscErrorCode SetVerificationScalarAtCellCenters(UserCtx *user, Vec targetVec)
Writes the configured verification scalar profile at physical cell centers into a scalar Vec.
double nu_t(double yplus)
Computes turbulent eddy viscosity ratio (ν_t / ν)