Tests coordinate extraction with interior-grid subsampling.
17{
20 PetscScalar *coords = NULL;
21 PetscInt nx = 0, ny = 0, nz = 0, npoints = 0;
22 PetscReal expected_last_coord = 0.0;
23
24 PetscFunctionBeginUser;
26 expected_last_coord = (PetscReal)(user->
IM - 1) / (PetscReal)user->
IM;
27
29 PetscCall(
PicurvAssertIntEqual(4, nx,
"PrepareOutputCoordinates should output nx based on the production IM+1 DA"));
30 PetscCall(
PicurvAssertIntEqual(4, ny,
"PrepareOutputCoordinates should output ny based on the production JM+1 DA"));
31 PetscCall(
PicurvAssertIntEqual(4, nz,
"PrepareOutputCoordinates should output nz based on the production KM+1 DA"));
32 PetscCall(
PicurvAssertIntEqual(64, npoints,
"PrepareOutputCoordinates should output the full physical-node lattice"));
33
34 if (simCtx->
rank == 0) {
35 PetscCall(
PicurvAssertBool((PetscBool)(coords != NULL),
"PrepareOutputCoordinates should allocate coordinates on rank 0"));
36 PetscCall(
PicurvAssertRealNear(0.0, PetscRealPart(coords[0]), 1.0e-12,
"First coordinate x should be 0"));
37 PetscCall(
PicurvAssertRealNear(0.0, PetscRealPart(coords[1]), 1.0e-12,
"First coordinate y should be 0"));
38 PetscCall(
PicurvAssertRealNear(0.0, PetscRealPart(coords[2]), 1.0e-12,
"First coordinate z should be 0"));
39
40 PetscCall(
PicurvAssertRealNear(expected_last_coord, PetscRealPart(coords[3 * (npoints - 1) + 0]), 1.0e-12,
"Last output coordinate x should be the normalized physical-node domain end"));
41 PetscCall(
PicurvAssertRealNear(expected_last_coord, PetscRealPart(coords[3 * (npoints - 1) + 1]), 1.0e-12,
"Last output coordinate y should be the normalized physical-node domain end"));
42 PetscCall(
PicurvAssertRealNear(expected_last_coord, PetscRealPart(coords[3 * (npoints - 1) + 2]), 1.0e-12,
"Last output coordinate z should be the normalized physical-node domain end"));
43
44 PetscCall(PetscFree(coords));
45 }
46
48 PetscFunctionReturn(0);
49}
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 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.
The master context for the entire simulation.
User-defined context containing data specific to a single computational grid level.
PetscErrorCode PrepareOutputCoordinates(UserCtx *user, PetscScalar **out_coords, PetscInt *out_nx, PetscInt *out_ny, PetscInt *out_nz, PetscInt *out_npoints)
Creates a C array of coordinates corresponding to a subsampled (legacy-style) grid.