18 Vec input = NULL, output = NULL;
19 PetscReal ***in_arr = NULL, ***out_arr = NULL;
21 PetscFunctionBeginUser;
23 PetscCall(VecDuplicate(user->
P, &input));
24 PetscCall(VecDuplicate(user->
P, &output));
25 PetscCall(VecSet(input, 8.0));
26 PetscCall(VecSet(output, 0.0));
28 PetscCall(DMDAVecGetArrayRead(user->
da, input, &in_arr));
29 PetscCall(DMDAVecGetArray(user->
da, output, &out_arr));
31 PetscCall(
PicurvAssertRealNear(8.0, out_arr[1][1][1], 1.0e-12,
"scalar corner->center preserves constants"));
32 PetscCall(DMDAVecRestoreArrayRead(user->
da, input, &in_arr));
33 PetscCall(DMDAVecRestoreArray(user->
da, output, &out_arr));
35 PetscCall(VecDestroy(&input));
36 PetscCall(VecDestroy(&output));
38 PetscFunctionReturn(0);
48 Vec input = NULL, output = NULL;
49 Cmpnts ***in_arr = NULL, ***out_arr = NULL;
51 PetscFunctionBeginUser;
53 PetscCall(VecDuplicate(user->
Ucat, &input));
54 PetscCall(VecDuplicate(user->
Ucat, &output));
55 PetscCall(VecSet(input, 3.5));
56 PetscCall(VecSet(output, 0.0));
58 PetscCall(DMDAVecGetArrayRead(user->
fda, input, &in_arr));
59 PetscCall(DMDAVecGetArray(user->
fda, output, &out_arr));
61 PetscCall(
PicurvAssertRealNear(3.5, out_arr[1][1][1].x, 1.0e-12,
"vector corner->center x preserves constants"));
62 PetscCall(
PicurvAssertRealNear(3.5, out_arr[1][1][1].y, 1.0e-12,
"vector corner->center y preserves constants"));
63 PetscCall(
PicurvAssertRealNear(3.5, out_arr[1][1][1].z, 1.0e-12,
"vector corner->center z preserves constants"));
64 PetscCall(DMDAVecRestoreArrayRead(user->
fda, input, &in_arr));
65 PetscCall(DMDAVecRestoreArray(user->
fda, output, &out_arr));
67 PetscCall(VecDestroy(&input));
68 PetscCall(VecDestroy(&output));
70 PetscFunctionReturn(0);
79 const PetscReal corner[8][3] = {{0, 0, 0}, {1, 0, 0}, {1, 1, 0}, {0, 1, 0},
80 {0, 1, 1}, {1, 1, 1}, {1, 0, 1}, {0, 0, 1}};
81 const Cmpnts inside_point = {0.5, 0.5, 0.25};
82 const Cmpnts outside_point = {0.5, 0.5, -1.0};
86 PetscReal distances[
NUM_FACES] = {1.0, 1.0, 0.0, 1.0, 1.0, 1.0};
87 PetscInt result = -99;
89 PetscFunctionBeginUser;
90 for (
int v = 0; v < 8; ++v) {
96 PetscCall(
PicurvAssertRealNear(0.25, d_inside[
BACK], 1.0e-14,
"inside point should yield its positive distance to the face"));
97 PetscCall(
PicurvAssertRealNear(-1.0, d_outside[
BACK], 1.0e-14,
"outside point should yield its negative distance to the face"));
100 PetscCall(
PicurvAssertIntEqual(1, result,
"one zero face distance should classify as on-face"));
104 PetscCall(
PicurvAssertIntEqual(-1, result,
"negative face distance should classify as outside"));
105 PetscFunctionReturn(0);
120 ierr = PetscInitialize(&argc, &argv, NULL,
"PICurv geometry tests");
125 ierr =
PicurvRunTests(
"unit-geometry", cases,
sizeof(cases) /
sizeof(cases[0]));
131 ierr = PetscFinalize();
void MetricBuildCellFacePlanes(const Cell *cell, CellFacePlanes *planes)
Builds the six face planes of a hexahedron, as the particle search tests them.
PetscErrorCode InterpolateFieldFromCornerToCenter_Vector(Cmpnts ***field_arr, Cmpnts ***centfield_arr, UserCtx *user)
Safely interpolate a vector field from corner nodes (from the coordinate DM) to cell centers (from th...
PetscErrorCode InterpolateFieldFromCornerToCenter_Scalar(PetscReal ***field_arr, PetscReal ***centfield_arr, UserCtx *user)
Safely interpolate a scalar field from corner nodes (from the coordinate DM) to cell centers (from th...
int main(int argc, char **argv)
Runs the unit-geometry PETSc test binary.
static PetscErrorCode TestSignedDistanceAndClassification(void)
Tests signed-distance computation and inside/outside classification.
static PetscErrorCode TestScalarInterpolationConstantField(void)
Tests scalar interpolation on a constant field.
static PetscErrorCode TestVectorInterpolationConstantField(void)
Tests vector interpolation on a constant 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 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 PicurvAssertIntEqual(PetscInt expected, PetscInt actual, const char *context)
Asserts that two integer values are equal.
Shared declarations for the PICurv C test fixture and assertion layer.
Named test case descriptor consumed by PicurvRunTests.
Cmpnts vertices[8]
Coordinates of the eight vertices of the cell.
Defines the vertices of a single hexahedral grid cell.
The six face planes of one hexahedron, indexed by Face, and its characteristic size.
A 3D point or vector with PetscScalar components.
The master context for the entire simulation.
User-defined context containing data specific to a single computational grid level.
Header file for particle location functions using the walking search algorithm.
PetscErrorCode CalculateDistancesToCellFacePlanes(const Cmpnts p, const CellFacePlanes *planes, PetscReal *d, const PetscReal threshold, Cmpnts *normals)
Signed distances from a point to precomputed cell face planes.
PetscErrorCode DeterminePointPosition(PetscReal *d, PetscInt *result)
Classifies a point based on precomputed face distances.