17 PetscReal (*vel_arr)[3] = NULL;
18 PetscScalar *ske_arr = NULL;
20 PetscFunctionBeginUser;
24 PetscCall(DMSwarmGetField(user->
swarm,
"velocity", NULL, NULL, (
void *)&vel_arr));
31 PetscCall(DMSwarmRestoreField(user->
swarm,
"velocity", NULL, NULL, (
void *)&vel_arr));
34 PetscCall(DMSwarmGetField(user->
post_swarm,
"ske", NULL, NULL, (
void *)&ske_arr));
37 PetscCall(DMSwarmRestoreField(user->
post_swarm,
"ske", NULL, NULL, (
void *)&ske_arr));
40 PetscFunctionReturn(0);
50 PetscReal (*pos_arr)[3] = NULL;
51 PetscScalar *disp_arr = NULL;
53 PetscFunctionBeginUser;
61 PetscCall(DMSwarmGetField(user->
swarm,
"position", NULL, NULL, (
void *)&pos_arr));
62 pos_arr[0][0] = 1.0; pos_arr[0][1] = 2.0; pos_arr[0][2] = 3.0;
63 pos_arr[1][0] = 4.0; pos_arr[1][1] = 6.0; pos_arr[1][2] = 3.0;
64 PetscCall(DMSwarmRestoreField(user->
swarm,
"position", NULL, NULL, (
void *)&pos_arr));
67 PetscCall(DMSwarmGetField(user->
post_swarm,
"disp", NULL, NULL, (
void *)&disp_arr));
68 PetscCall(
PicurvAssertRealNear(0.0, PetscRealPart(disp_arr[0]), 1.0e-12,
"ComputeDisplacement first particle"));
69 PetscCall(
PicurvAssertRealNear(5.0, PetscRealPart(disp_arr[1]), 1.0e-12,
"ComputeDisplacement second particle"));
70 PetscCall(DMSwarmRestoreField(user->
post_swarm,
"disp", NULL, NULL, (
void *)&disp_arr));
73 PetscFunctionReturn(0);
83 const PetscScalar ***p_nodal_arr = NULL;
85 PetscFunctionBeginUser;
87 PetscCall(VecSet(user->
P, 7.0));
88 PetscCall(VecSet(user->
P_nodal, -1.0));
92 PetscCall(DMDAVecGetArrayRead(user->
da, user->
P_nodal, (
void *)&p_nodal_arr));
93 PetscCall(
PicurvAssertRealNear(7.0, PetscRealPart(p_nodal_arr[0][0][0]), 1.0e-12,
"ComputeNodalAverage interior node"));
94 PetscCall(
PicurvAssertRealNear(-1.0, PetscRealPart(p_nodal_arr[3][3][3]), 1.0e-12,
"ComputeNodalAverage untouched boundary node"));
95 PetscCall(DMDAVecRestoreArrayRead(user->
da, user->
P_nodal, (
void *)&p_nodal_arr));
98 PetscFunctionReturn(0);
108 PetscInt ref_idx = 0;
109 PetscScalar ref_value = 0.0;
110 PetscReal vmin = 0.0, vmax = 0.0;
112 PetscFunctionBeginUser;
114 PetscCall(PetscCalloc1(1, &simCtx->
pps));
119 PetscCall(VecSet(user->
P, 10.0));
123 PetscCall(VecSetValue(user->
P, ref_idx, 4.0, INSERT_VALUES));
124 PetscCall(VecAssemblyBegin(user->
P));
125 PetscCall(VecAssemblyEnd(user->
P));
129 PetscCall(VecGetValues(user->
P, 1, &ref_idx, &ref_value));
130 PetscCall(
PicurvAssertRealNear(0.0, PetscRealPart(ref_value), 1.0e-12,
"NormalizeRelativeField reference value"));
131 PetscCall(VecMin(user->
P, NULL, &vmin));
132 PetscCall(VecMax(user->
P, NULL, &vmax));
137 PetscFunctionReturn(0);
148 PetscFunctionBeginUser;
152 PetscCall(VecSet(user->
P, 2.0));
157 PetscFunctionReturn(0);
168 PetscFunctionBeginUser;
171 PetscCall(VecDuplicate(user->
P, &user->
Aj));
172 PetscCall(VecDuplicate(user->
lP, &user->
lAj));
173 PetscCall(VecSet(user->
Aj, 1.0));
174 PetscCall(DMGlobalToLocalBegin(user->
da, user->
Aj, INSERT_VALUES, user->
lAj));
175 PetscCall(DMGlobalToLocalEnd(user->
da, user->
Aj, INSERT_VALUES, user->
lAj));
177 PetscCall(VecSet(user->
Ucat, 0.0));
178 PetscCall(DMGlobalToLocalBegin(user->
fda, user->
Ucat, INSERT_VALUES, user->
lUcat));
179 PetscCall(DMGlobalToLocalEnd(user->
fda, user->
Ucat, INSERT_VALUES, user->
lUcat));
180 PetscCall(VecSet(user->
Nvert, 0.0));
181 PetscCall(DMGlobalToLocalBegin(user->
da, user->
Nvert, INSERT_VALUES, user->
lNvert));
182 PetscCall(DMGlobalToLocalEnd(user->
da, user->
Nvert, INSERT_VALUES, user->
lNvert));
188 PetscFunctionReturn(0);
206 ierr = PetscInitialize(&argc, &argv, NULL,
"PICurv post-processing tests");
211 ierr =
PicurvRunTests(
"unit-post", cases,
sizeof(cases) /
sizeof(cases[0]));
217 ierr = PetscFinalize();
PetscErrorCode ComputeQCriterion(UserCtx *user)
Computes the Q-criterion diagnostic from the local velocity-gradient tensor.
PetscErrorCode ComputeSpecificKE(UserCtx *user, const char *velocity_field, const char *ske_field)
Computes the specific kinetic energy (KE per unit mass) for each particle.
PetscErrorCode ComputeDisplacement(UserCtx *user, const char *disp_field)
Computes the displacement magnitude |r_i - r_0| for each particle (per-particle VTK kernel).
PetscErrorCode NormalizeRelativeField(UserCtx *user, const char *relative_field_name)
Normalizes a relative scalar field using the configured reference pressure scale.
PetscErrorCode DimensionalizeField(UserCtx *user, const char *field_name)
Scales a specified field from non-dimensional to dimensional units in-place.
PetscErrorCode ComputeNodalAverage(UserCtx *user, const char *in_field_name, const char *out_field_name)
Interpolates a cell-centered field to nodal locations using local stencil averaging.
int main(int argc, char **argv)
Entry point for this unit-test binary.
static PetscErrorCode TestComputeQCriterionZeroFlow(void)
Test-local routine.
static PetscErrorCode TestComputeSpecificKE(void)
Test-local routine.
static PetscErrorCode TestComputeDisplacement(void)
Test-local routine.
static PetscErrorCode TestDimensionalizePressureField(void)
Test-local routine.
static PetscErrorCode TestComputeNodalAverageScalar(void)
Test-local routine.
static PetscErrorCode TestNormalizeRelativeField(void)
Test-local routine.
PetscErrorCode PicurvCreateMinimalContexts(SimCtx **simCtx_out, UserCtx **user_out, PetscInt mx, PetscInt my, PetscInt mz)
Shared test-support routine.
PetscErrorCode PicurvAssertRealNear(PetscReal expected, PetscReal actual, PetscReal tol, const char *context)
Shared test-support routine.
PetscErrorCode PicurvDestroyMinimalContexts(SimCtx **simCtx_ptr, UserCtx **user_ptr)
Shared test-support routine.
PetscErrorCode PicurvCreateSwarmPair(UserCtx *user, PetscInt nlocal, const char *post_field_name)
Shared test-support routine.
PetscErrorCode PicurvRunTests(const char *suite_name, const PicurvTestCase *cases, size_t case_count)
Shared test-support routine.
PetscErrorCode PicurvAssertVecConstant(Vec vec, PetscScalar expected, PetscReal tol, const char *context)
Shared test-support routine.
C test module for PICurv.
Named test case descriptor consumed by PicurvRunTests.
PetscReal psrc_z
Point source location for PARTICLE_INIT_POINT_SOURCE.
The master context for the entire simulation.
User-defined context containing data specific to a single computational grid level.