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);
78 const Cmpnts v1 = {0.0, 0.0, 0.0};
79 const Cmpnts v2 = {1.0, 0.0, 0.0};
80 const Cmpnts v3 = {1.0, 1.0, 0.0};
81 const Cmpnts v4 = {0.0, 1.0, 0.0};
82 const Cmpnts centroid = {0.5, 0.5, 0.5};
83 const Cmpnts inside_point = {0.5, 0.5, 0.25};
84 const Cmpnts outside_point = {0.5, 0.5, -1.0};
85 PetscReal d_inside = 0.0, d_outside = 0.0;
86 PetscReal distances[
NUM_FACES] = {1.0, 1.0, 0.0, 1.0, 1.0, 1.0};
87 PetscInt result = -99;
89 PetscFunctionBeginUser;
92 PetscCall(
PicurvAssertBool((PetscBool)(d_inside > 0.0),
"inside point should yield positive signed distance"));
93 PetscCall(
PicurvAssertBool((PetscBool)(d_outside < 0.0),
"outside point should yield negative signed distance"));
100 PetscCall(
PicurvAssertIntEqual(-1, result,
"negative face distance should classify as outside"));
101 PetscFunctionReturn(0);
116 ierr = PetscInitialize(&argc, &argv, NULL,
"PICurv geometry tests");
121 ierr =
PicurvRunTests(
"unit-geometry", cases,
sizeof(cases) /
sizeof(cases[0]));
127 ierr = PetscFinalize();
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)
Entry point for this unit-test binary.
static PetscErrorCode TestSignedDistanceAndClassification(void)
Test-local routine.
static PetscErrorCode TestScalarInterpolationConstantField(void)
Test-local routine.
static PetscErrorCode TestVectorInterpolationConstantField(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 PicurvRunTests(const char *suite_name, const PicurvTestCase *cases, size_t case_count)
Shared test-support routine.
PetscErrorCode PicurvAssertIntEqual(PetscInt expected, PetscInt actual, const char *context)
Shared test-support routine.
PetscErrorCode PicurvAssertBool(PetscBool value, const char *context)
Shared test-support routine.
C test module for PICurv.
Named test case descriptor consumed by PicurvRunTests.
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 ComputeSignedDistanceToPlane(const Cmpnts v1, const Cmpnts v2, const Cmpnts v3, const Cmpnts v4, const Cmpnts cell_centroid, const Cmpnts p_target, PetscReal *d_signed, const PetscReal threshold)
Computes the signed distance from a point to the plane approximating a quadrilateral face.
PetscErrorCode DeterminePointPosition(PetscReal *d, PetscInt *result)
Classifies a point based on precomputed face distances.