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"));
95 "ComputeNodalAverage untouched non-physical boundary node"));
96 PetscCall(DMDAVecRestoreArrayRead(user->
da, user->
P_nodal, (
void *)&p_nodal_arr));
99 PetscFunctionReturn(0);
109 PetscInt ref_idx = 0;
110 PetscScalar ref_value = 0.0;
111 PetscReal vmin = 0.0, vmax = 0.0;
113 PetscFunctionBeginUser;
115 PetscCall(PetscCalloc1(1, &simCtx->
pps));
120 PetscCall(VecSet(user->
P, 10.0));
124 PetscCall(VecSetValue(user->
P, ref_idx, 4.0, INSERT_VALUES));
125 PetscCall(VecAssemblyBegin(user->
P));
126 PetscCall(VecAssemblyEnd(user->
P));
130 PetscCall(VecGetValues(user->
P, 1, &ref_idx, &ref_value));
131 PetscCall(
PicurvAssertRealNear(0.0, PetscRealPart(ref_value), 1.0e-12,
"NormalizeRelativeField reference value"));
132 PetscCall(VecMin(user->
P, NULL, &vmin));
133 PetscCall(VecMax(user->
P, NULL, &vmax));
138 PetscFunctionReturn(0);
149 PetscFunctionBeginUser;
153 PetscCall(VecSet(user->
P, 2.0));
158 PetscFunctionReturn(0);
169 PetscFunctionBeginUser;
172 PetscCall(VecSet(user->
Aj, 1.0));
173 PetscCall(DMGlobalToLocalBegin(user->
da, user->
Aj, INSERT_VALUES, user->
lAj));
174 PetscCall(DMGlobalToLocalEnd(user->
da, user->
Aj, INSERT_VALUES, user->
lAj));
176 PetscCall(VecSet(user->
Ucat, 0.0));
177 PetscCall(DMGlobalToLocalBegin(user->
fda, user->
Ucat, INSERT_VALUES, user->
lUcat));
178 PetscCall(DMGlobalToLocalEnd(user->
fda, user->
Ucat, INSERT_VALUES, user->
lUcat));
179 PetscCall(VecSet(user->
Nvert, 0.0));
180 PetscCall(DMGlobalToLocalBegin(user->
da, user->
Nvert, INSERT_VALUES, user->
lNvert));
181 PetscCall(DMGlobalToLocalEnd(user->
da, user->
Nvert, INSERT_VALUES, user->
lNvert));
187 PetscFunctionReturn(0);
205 ierr = PetscInitialize(&argc, &argv, NULL,
"PICurv post-processing tests");
210 ierr =
PicurvRunTests(
"unit-post", cases,
sizeof(cases) /
sizeof(cases[0]));
216 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)
Runs the unit-post PETSc test binary.
static PetscErrorCode TestComputeQCriterionZeroFlow(void)
Tests Q-criterion computation for a quiescent velocity field.
static PetscErrorCode TestComputeSpecificKE(void)
Tests specific turbulent kinetic energy computation on particle data.
static PetscErrorCode TestComputeDisplacement(void)
Tests particle displacement computation against reference positions.
static PetscErrorCode TestDimensionalizePressureField(void)
Tests dimensionalization of pressure data from nondimensional values.
static PetscErrorCode TestComputeNodalAverageScalar(void)
Tests nodal averaging of scalar cell-centered data.
static PetscErrorCode TestNormalizeRelativeField(void)
Tests normalization of one field relative to a reference field.
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 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.
Shared declarations for the PICurv C test fixture and assertion layer.
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.