Tests coordinate extraction with interior-grid subsampling.
17{
20 PetscScalar *coords = NULL;
21 PetscInt nx = 0, ny = 0, nz = 0, npoints = 0, local_start[3], local_size[3];
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->
size == 1) {
36 "One rank should hold the whole output grid"));
37 PetscCall(
PicurvAssertBool((PetscBool)(coords != NULL),
"PrepareOutputCoordinates should allocate this rank's coordinates"));
38 PetscCall(
PicurvAssertRealNear(0.0, PetscRealPart(coords[0]), 1.0e-12,
"First coordinate x should be 0"));
39 PetscCall(
PicurvAssertRealNear(0.0, PetscRealPart(coords[1]), 1.0e-12,
"First coordinate y should be 0"));
40 PetscCall(
PicurvAssertRealNear(0.0, PetscRealPart(coords[2]), 1.0e-12,
"First coordinate z should be 0"));
41
42 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"));
43 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"));
44 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"));
45 }
46 PetscCall(PetscFree(coords));
47
49 PetscFunctionReturn(0);
50}
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, PetscInt local_start[3], PetscInt local_size[3])
Copies this rank's part of the output grid's coordinates.