C test module for PICurv.
More...
#include "test_support.h"
#include "poisson.h"
#include "rhs.h"
Go to the source code of this file.
C test module for PICurv.
Definition in file test_poisson_rhs.c.
◆ EnsurePoissonAndRhsVectors()
| static PetscErrorCode EnsurePoissonAndRhsVectors |
( |
UserCtx * |
user | ) |
|
|
static |
Test-local routine.
Definition at line 14 of file test_poisson_rhs.c.
15{
16 PetscFunctionBeginUser;
17 if (!user->
Phi) PetscCall(DMCreateGlobalVector(user->
da, &user->
Phi));
18 if (!user->
lPhi) PetscCall(DMCreateLocalVector(user->
da, &user->
lPhi));
19 if (!user->
Aj) PetscCall(DMCreateGlobalVector(user->
da, &user->
Aj));
20 if (!user->
lAj) PetscCall(DMCreateLocalVector(user->
da, &user->
lAj));
23 PetscFunctionReturn(0);
24}
◆ TestUpdatePressureAddsPhi()
| static PetscErrorCode TestUpdatePressureAddsPhi |
( |
void |
| ) |
|
|
static |
Test-local routine.
Definition at line 29 of file test_poisson_rhs.c.
30{
33
34 PetscFunctionBeginUser;
37 PetscCall(VecSet(user->
P, 1.0));
38 PetscCall(VecSet(user->
Phi, 0.25));
39
42
44 PetscFunctionReturn(0);
45}
PetscErrorCode UpdatePressure(UserCtx *user)
Updates the pressure field P with the pressure correction Phi computed by the Poisson solver.
static PetscErrorCode EnsurePoissonAndRhsVectors(UserCtx *user)
Test-local routine.
PetscErrorCode PicurvCreateMinimalContexts(SimCtx **simCtx_out, UserCtx **user_out, PetscInt mx, PetscInt my, PetscInt mz)
Shared test-support routine.
PetscErrorCode PicurvDestroyMinimalContexts(SimCtx **simCtx_ptr, UserCtx **user_ptr)
Shared test-support routine.
PetscErrorCode PicurvAssertVecConstant(Vec vec, PetscScalar expected, PetscReal tol, const char *context)
Shared test-support routine.
The master context for the entire simulation.
User-defined context containing data specific to a single computational grid level.
◆ TestPoissonRHSZeroDivergence()
| static PetscErrorCode TestPoissonRHSZeroDivergence |
( |
void |
| ) |
|
|
static |
Test-local routine.
Definition at line 50 of file test_poisson_rhs.c.
51{
54 Vec B = NULL;
55
56 PetscFunctionBeginUser;
59
61 PetscCall(VecSet(user->
Ucont, 0.0));
62 PetscCall(VecSet(user->
Nvert, 0.0));
63 PetscCall(VecSet(user->
Aj, 1.0));
64 PetscCall(DMGlobalToLocalBegin(user->
fda, user->
Ucont, INSERT_VALUES, user->
lUcont));
65 PetscCall(DMGlobalToLocalEnd(user->
fda, user->
Ucont, INSERT_VALUES, user->
lUcont));
66 PetscCall(DMGlobalToLocalBegin(user->
da, user->
Nvert, INSERT_VALUES, user->
lNvert));
67 PetscCall(DMGlobalToLocalEnd(user->
da, user->
Nvert, INSERT_VALUES, user->
lNvert));
68 PetscCall(DMGlobalToLocalBegin(user->
da, user->
Aj, INSERT_VALUES, user->
lAj));
69 PetscCall(DMGlobalToLocalEnd(user->
da, user->
Aj, INSERT_VALUES, user->
lAj));
70
71 PetscCall(VecDuplicate(user->
P, &B));
73 PetscCall(
PicurvAssertVecConstant(B, 0.0, 1.0e-12,
"zero velocity divergence should produce zero Poisson RHS"));
75
76 PetscCall(VecDestroy(&B));
78 PetscFunctionReturn(0);
79}
PetscErrorCode PoissonRHS(UserCtx *user, Vec B)
Computes the Right-Hand-Side (RHS) of the Poisson equation, which is the divergence of the intermedia...
PetscErrorCode PicurvAssertRealNear(PetscReal expected, PetscReal actual, PetscReal tol, const char *context)
Shared test-support routine.
◆ TestComputeBodyForcesDispatcher()
| static PetscErrorCode TestComputeBodyForcesDispatcher |
( |
void |
| ) |
|
|
static |
Test-local routine.
Definition at line 84 of file test_poisson_rhs.c.
85{
88 Vec rct = NULL;
90
91 PetscFunctionBeginUser;
93 PetscCall(VecDuplicate(user->
Ucont, &rct));
94 PetscCall(VecZeroEntries(rct));
95
102
104 PetscCall(DMDAVecGetArrayRead(user->
fda, rct, &rct_arr));
105 PetscCall(
PicurvAssertRealNear(1.5, rct_arr[1][1][1].x, 1.0e-12,
"ComputeBodyForces should apply driven-channel source"));
106 PetscCall(
PicurvAssertRealNear(0.0, rct_arr[1][1][1].y, 1.0e-12,
"ComputeBodyForces should keep y unchanged"));
107 PetscCall(
PicurvAssertRealNear(0.0, rct_arr[1][1][1].z, 1.0e-12,
"ComputeBodyForces should keep z unchanged"));
108 PetscCall(DMDAVecRestoreArrayRead(user->
fda, rct, &rct_arr));
109
110 PetscCall(VecDestroy(&rct));
112 PetscFunctionReturn(0);
113}
PetscErrorCode ComputeBodyForces(UserCtx *user, Vec Rct)
General dispatcher for applying all active body forces (momentum sources).
BoundaryFaceConfig boundary_faces[6]
PetscReal forceScalingFactor
@ BC_HANDLER_PERIODIC_DRIVEN_CONSTANT_FLUX
BCHandlerType handler_type
PetscReal bulkVelocityCorrection
PetscReal drivingForceMagnitude
A 3D point or vector with PetscScalar components.
◆ TestComputeEulerianDiffusivityMolecularOnly()
| static PetscErrorCode TestComputeEulerianDiffusivityMolecularOnly |
( |
void |
| ) |
|
|
static |
Test-local routine.
Definition at line 118 of file test_poisson_rhs.c.
119{
122 PetscReal ***diff_arr = NULL;
123
124 PetscFunctionBeginUser;
127
130 simCtx->
les = PETSC_FALSE;
131 simCtx->
rans = PETSC_FALSE;
133
135 PetscCall(DMDAVecGetArrayRead(user->
da, user->
Diffusivity, &diff_arr));
136 PetscCall(
PicurvAssertRealNear(0.125, diff_arr[1][1][1], 1.0e-12,
"molecular diffusivity interior value"));
137 PetscCall(DMDAVecRestoreArrayRead(user->
da, user->
Diffusivity, &diff_arr));
138
140 PetscFunctionReturn(0);
141}
PetscErrorCode ComputeEulerianDiffusivity(UserCtx *user)
Computes the effective diffusivity scalar field (Gamma_eff) on the Eulerian grid.
◆ main()
| int main |
( |
int |
argc, |
|
|
char ** |
argv |
|
) |
| |
Entry point for this unit-test binary.
Definition at line 146 of file test_poisson_rhs.c.
147{
148 PetscErrorCode ierr;
154 };
155
156 ierr = PetscInitialize(&argc, &argv, NULL, "PICurv Poisson/RHS tests");
157 if (ierr) {
158 return (int)ierr;
159 }
160
161 ierr =
PicurvRunTests(
"unit-poisson-rhs", cases,
sizeof(cases) /
sizeof(cases[0]));
162 if (ierr) {
163 PetscFinalize();
164 return (int)ierr;
165 }
166
167 ierr = PetscFinalize();
168 return (int)ierr;
169}
static PetscErrorCode TestComputeEulerianDiffusivityMolecularOnly(void)
Test-local routine.
static PetscErrorCode TestComputeBodyForcesDispatcher(void)
Test-local routine.
static PetscErrorCode TestUpdatePressureAddsPhi(void)
Test-local routine.
static PetscErrorCode TestPoissonRHSZeroDivergence(void)
Test-local routine.
PetscErrorCode PicurvRunTests(const char *suite_name, const PicurvTestCase *cases, size_t case_count)
Shared test-support routine.
Named test case descriptor consumed by PicurvRunTests.