PICurv 0.1.0
A Parallel Particle-In-Cell Solver for Curvilinear LES
Loading...
Searching...
No Matches
test_solver_kernels.c
Go to the documentation of this file.
1/**
2 * @file test_solver_kernels.c
3 * @brief C test module for PICurv.
4 */
5
6#include "test_support.h"
7
9#include "BodyForces.h"
10#include "Filter.h"
11/**
12 * @brief Test-local routine.
13 */
14
15static PetscErrorCode TestLESTestFilterPaths(void)
16{
17 SimCtx simCtx;
18 double values[3][3][3];
19 double weights[3][3][3];
20
21 PetscFunctionBeginUser;
22 PetscCall(PetscMemzero(&simCtx, sizeof(simCtx)));
23 for (PetscInt k = 0; k < 3; ++k) {
24 for (PetscInt j = 0; j < 3; ++j) {
25 for (PetscInt i = 0; i < 3; ++i) {
26 values[k][j][i] = 2.0;
27 weights[k][j][i] = 1.0;
28 }
29 }
30 }
31
32 simCtx.testfilter_ik = 1;
33 PetscCall(PicurvAssertRealNear(2.0, ApplyLESTestFilter(&simCtx, values, weights), 1.0e-12,
34 "Simpson-rule filter should preserve a constant field"));
35
36 simCtx.testfilter_ik = 0;
37 PetscCall(PicurvAssertRealNear(2.0, ApplyLESTestFilter(&simCtx, values, weights), 1.0e-12,
38 "box filter should preserve a constant field"));
39
40 for (PetscInt k = 0; k < 3; ++k) {
41 for (PetscInt j = 0; j < 3; ++j) {
42 for (PetscInt i = 0; i < 3; ++i) {
43 weights[k][j][i] = 0.0;
44 }
45 }
46 }
47 PetscCall(PicurvAssertRealNear(0.0, ApplyLESTestFilter(&simCtx, values, weights), 1.0e-12,
48 "box filter should return zero when all weights are zero"));
49 PetscFunctionReturn(0);
50}
51/**
52 * @brief Test-local routine.
53 */
54
55static PetscErrorCode TestAnalyticalGeometrySelection(void)
56{
57 SimCtx *simCtx = NULL;
58 UserCtx *user = NULL;
59
60 PetscFunctionBeginUser;
61 PetscCall(PicurvCreateMinimalContexts(&simCtx, &user, 8, 8, 8));
63 "TGV3D should require custom geometry"));
64 PetscCall(PicurvAssertBool((PetscBool)!AnalyticalTypeRequiresCustomGeometry("ZERO_FLOW"),
65 "ZERO_FLOW should not require custom geometry"));
66
67 PetscCall(PetscStrncpy(simCtx->AnalyticalSolutionType, "TGV3D", sizeof(simCtx->AnalyticalSolutionType)));
68 simCtx->block_number = 1;
69 PetscCall(SetAnalyticalGridInfo(user));
70 PetscCall(PicurvAssertRealNear(0.0, user->Min_X, 1.0e-12, "TGV3D single-block xmin"));
71 PetscCall(PicurvAssertRealNear(2.0 * PETSC_PI, user->Max_X, 1.0e-12, "TGV3D single-block xmax"));
72
73 PetscCall(PicurvDestroyMinimalContexts(&simCtx, &user));
74 PetscFunctionReturn(0);
75}
76/**
77 * @brief Test-local routine.
78 */
79
80static PetscErrorCode TestDrivenChannelFlowSource(void)
81{
82 SimCtx *simCtx = NULL;
83 UserCtx *user = NULL;
84 Vec rct = NULL;
85 Cmpnts ***rct_arr = NULL;
86
87 PetscFunctionBeginUser;
88 PetscCall(PicurvCreateMinimalContexts(&simCtx, &user, 4, 4, 4));
89 PetscCall(VecDuplicate(user->Ucont, &rct));
90 PetscCall(VecZeroEntries(rct));
91
94 simCtx->bulkVelocityCorrection = 2.0;
95 simCtx->dt = 1.0;
96 simCtx->forceScalingFactor = 1.0;
97 simCtx->drivingForceMagnitude = 0.0;
98
99 PetscCall(ComputeDrivenChannelFlowSource(user, rct));
100 PetscCall(DMDAVecGetArrayRead(user->fda, rct, &rct_arr));
101 PetscCall(PicurvAssertRealNear(1.5, rct_arr[1][1][1].x, 1.0e-12,
102 "driven flow source should update the x component"));
103 PetscCall(PicurvAssertRealNear(0.0, rct_arr[1][1][1].y, 1.0e-12,
104 "driven flow source should leave the y component unchanged"));
105 PetscCall(PicurvAssertRealNear(0.0, rct_arr[1][1][1].z, 1.0e-12,
106 "driven flow source should leave the z component unchanged"));
107 PetscCall(DMDAVecRestoreArrayRead(user->fda, rct, &rct_arr));
108
109 PetscCall(VecDestroy(&rct));
110 PetscCall(PicurvDestroyMinimalContexts(&simCtx, &user));
111 PetscFunctionReturn(0);
112}
113/**
114 * @brief Entry point for this unit-test binary.
115 */
116
117int main(int argc, char **argv)
118{
119 PetscErrorCode ierr;
120 const PicurvTestCase cases[] = {
121 {"les-filter-paths", TestLESTestFilterPaths},
122 {"analytical-geometry-selection", TestAnalyticalGeometrySelection},
123 {"driven-channel-flow-source", TestDrivenChannelFlowSource},
124 };
125
126 ierr = PetscInitialize(&argc, &argv, NULL, "PICurv solver utility tests");
127 if (ierr) {
128 return (int)ierr;
129 }
130
131 ierr = PicurvRunTests("unit-solver", cases, sizeof(cases) / sizeof(cases[0]));
132 if (ierr) {
133 PetscFinalize();
134 return (int)ierr;
135 }
136
137 ierr = PetscFinalize();
138 return (int)ierr;
139}
PetscBool AnalyticalTypeRequiresCustomGeometry(const char *analytical_type)
Reports whether an analytical type requires custom geometry/decomposition logic.
PetscErrorCode SetAnalyticalGridInfo(UserCtx *user)
Sets the grid domain and resolution for analytical solution cases.
PetscErrorCode ComputeDrivenChannelFlowSource(UserCtx *user, Vec Rct)
Applies a momentum source term to drive flow in a periodic channel or pipe.
Definition BodyForces.c:14
double ApplyLESTestFilter(const SimCtx *simCtx, double values[3][3][3], double weights[3][3][3])
Applies a numerical "test filter" to a 3x3x3 stencil of data points.
Definition Filter.c:123
int main(int argc, char **argv)
Entry point for this unit-test binary.
static PetscErrorCode TestDrivenChannelFlowSource(void)
Test-local routine.
static PetscErrorCode TestAnalyticalGeometrySelection(void)
Test-local routine.
static PetscErrorCode TestLESTestFilterPaths(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 PicurvAssertBool(PetscBool value, const char *context)
Shared test-support routine.
C test module for PICurv.
Named test case descriptor consumed by PicurvRunTests.
BoundaryFaceConfig boundary_faces[6]
Definition variables.h:756
PetscInt block_number
Definition variables.h:656
PetscReal forceScalingFactor
Definition variables.h:667
PetscReal Min_X
Definition variables.h:748
@ BC_HANDLER_PERIODIC_DRIVEN_CONSTANT_FLUX
Definition variables.h:245
BCHandlerType handler_type
Definition variables.h:296
PetscReal dt
Definition variables.h:606
PetscReal bulkVelocityCorrection
Definition variables.h:669
Vec Ucont
Definition variables.h:764
char AnalyticalSolutionType[PETSC_MAX_PATH_LEN]
Definition variables.h:623
PetscReal Max_X
Definition variables.h:748
PetscInt testfilter_ik
Definition variables.h:679
PetscReal drivingForceMagnitude
Definition variables.h:667
@ BC_FACE_NEG_X
Definition variables.h:204
A 3D point or vector with PetscScalar components.
Definition variables.h:100
The master context for the entire simulation.
Definition variables.h:591
User-defined context containing data specific to a single computational grid level.
Definition variables.h:738