|
PICurv 0.1.0
A Parallel Particle-In-Cell Solver for Curvilinear LES
|
Shared C test fixtures, assertions, and PETSc helper utilities. More...
#include "test_support.h"#include "grid.h"#include "io.h"#include "setup.h"#include <errno.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <sys/stat.h>#include <sys/types.h>#include <unistd.h>Go to the source code of this file.
Functions | |
| static PetscErrorCode | DestroyVecIfSet (Vec *vec) |
| Destroys a PETSc vector only when the handle is non-null. | |
| static PetscErrorCode | DestroyDMIfSet (DM *dm) |
| Destroys a PETSc DM only when the handle is non-null. | |
| static PetscErrorCode | DestroyMatIfSet (Mat *mat) |
| Destroys a PETSc matrix only when the handle is non-null. | |
| static PetscErrorCode | DestroyKSPIfSet (KSP *ksp) |
| Destroys a PETSc KSP only when the handle is non-null. | |
| static PetscErrorCode | DestroyNullSpaceIfSet (MatNullSpace *nullsp) |
| Destroys a PETSc nullspace only when the handle is non-null. | |
| static PetscErrorCode | DestroyRandomIfSet (PetscRandom *rand_ctx) |
| Destroys a PETSc random generator only when the handle is non-null. | |
| static PetscErrorCode | RegisterSwarmFieldForTests (DM swarm, const char *field_name, PetscInt field_dim, PetscDataType dtype) |
| Registers one DMSwarm field used by the C test fixtures. | |
| static PetscErrorCode | CreateZeroedGlobalVector (DM dm, Vec *vec) |
| Allocates and zeroes a global vector from the provided DM. | |
| static PetscErrorCode | CreateZeroedLocalVector (DM dm, Vec *vec) |
| Allocates and zeroes a local vector from the provided DM. | |
| static PetscErrorCode | CreateZeroedDuplicate (Vec src, Vec *vec) |
| Duplicates and zeroes a vector. | |
| 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 | PicurvEnsureDir (const char *path) |
| Ensures a directory exists for test output. | |
| PetscErrorCode | PicurvMakeTempDir (char *path, size_t path_len) |
| Creates a unique temporary directory for one test case. | |
| PetscErrorCode | PicurvRemoveTempDir (const char *path) |
| Recursively removes a temporary directory created by PicurvMakeTempDir. | |
| static PetscErrorCode | WriteTextFileForTests (const char *path, const char *contents) |
| Writes one small temporary text file used by the richer runtime fixtures. | |
| static PetscErrorCode | PrepareTinyRuntimeConfig (const char *bcs_contents, PetscBool enable_particles, char *tmpdir, size_t tmpdir_len, char *control_path, size_t control_path_len) |
| Creates a tiny control-file bundle used by richer runtime fixtures built through the setup path. | |
| PetscErrorCode | PicurvCreateMinimalContextsWithPeriodicity (SimCtx **simCtx_out, UserCtx **user_out, PetscInt mx, PetscInt my, PetscInt mz, PetscBool x_periodic, PetscBool y_periodic, PetscBool z_periodic) |
| Builds minimal SimCtx and UserCtx fixtures for C unit tests with configurable periodicity. | |
| 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 | PicurvPopulateUniformCellCenters (UserCtx *user) |
| Populates cell center coordinates for a uniform grid on [0,1]^3. | |
| PetscErrorCode | PicurvPopulateIdentityMetrics (UserCtx *user) |
| Populates identity metric vectors on the minimal grid fixture. | |
| PetscErrorCode | PicurvCreateSwarmPair (UserCtx *user, PetscInt nlocal, const char *post_field_name) |
| Creates matched solver and post-processing swarms for tests. | |
| PetscErrorCode | PicurvBuildTinyRuntimeContext (const char *bcs_contents, PetscBool enable_particles, SimCtx **simCtx_out, UserCtx **user_out, char *tmpdir, size_t tmpdir_len) |
| Builds a tiny runtime context through the real setup path for behavior-level tests. | |
| PetscErrorCode | PicurvDestroyRuntimeContext (SimCtx **simCtx_ptr) |
Finalizes and frees a runtime context built by PicurvBuildTinyRuntimeContext. | |
| PetscErrorCode | PicurvDestroyMinimalContexts (SimCtx **simCtx_ptr, UserCtx **user_ptr) |
| Destroys minimal SimCtx/UserCtx fixtures and all owned PETSc objects. | |
| PetscErrorCode | PicurvAssertRealNear (PetscReal expected, PetscReal actual, PetscReal tol, const char *context) |
| Asserts that two real values agree within tolerance. | |
| 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. | |
| PetscErrorCode | PicurvAssertFileExists (const char *path, const char *context) |
| Asserts that a filesystem path exists as a readable file. | |
| PetscErrorCode | PicurvAssertVecConstant (Vec vec, PetscScalar expected, PetscReal tol, const char *context) |
| Asserts that a PETSc vector is spatially constant within tolerance. | |
Shared C test fixtures, assertions, and PETSc helper utilities.
Definition in file test_support.c.
|
static |
Destroys a PETSc vector only when the handle is non-null.
Definition at line 23 of file test_support.c.
|
static |
Destroys a PETSc DM only when the handle is non-null.
Definition at line 35 of file test_support.c.
|
static |
Destroys a PETSc matrix only when the handle is non-null.
Definition at line 47 of file test_support.c.
|
static |
Destroys a PETSc KSP only when the handle is non-null.
Definition at line 59 of file test_support.c.
|
static |
Destroys a PETSc nullspace only when the handle is non-null.
Definition at line 71 of file test_support.c.
|
static |
Destroys a PETSc random generator only when the handle is non-null.
Definition at line 83 of file test_support.c.
|
static |
Registers one DMSwarm field used by the C test fixtures.
Definition at line 95 of file test_support.c.
|
static |
Allocates and zeroes a global vector from the provided DM.
Definition at line 105 of file test_support.c.
|
static |
Allocates and zeroes a local vector from the provided DM.
Definition at line 116 of file test_support.c.
|
static |
Duplicates and zeroes a vector.
Definition at line 127 of file test_support.c.
| 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.
Executes a table of unit tests and reports aggregated pass/fail status.
Definition at line 138 of file test_support.c.
| PetscErrorCode PicurvEnsureDir | ( | const char * | path | ) |
Ensures a directory exists for test output.
Ensures a directory exists, creating it if required.
Definition at line 156 of file test_support.c.
| PetscErrorCode PicurvMakeTempDir | ( | char * | path, |
| size_t | path_len | ||
| ) |
Creates a unique temporary directory for one test case.
Creates a unique temporary directory path and materializes the directory.
Definition at line 168 of file test_support.c.
| PetscErrorCode PicurvRemoveTempDir | ( | const char * | path | ) |
Recursively removes a temporary directory created by PicurvMakeTempDir.
Definition at line 185 of file test_support.c.
|
static |
Writes one small temporary text file used by the richer runtime fixtures.
Definition at line 206 of file test_support.c.
|
static |
Creates a tiny control-file bundle used by richer runtime fixtures built through the setup path.
Definition at line 221 of file test_support.c.
| PetscErrorCode PicurvCreateMinimalContextsWithPeriodicity | ( | SimCtx ** | simCtx_out, |
| UserCtx ** | user_out, | ||
| PetscInt | mx, | ||
| PetscInt | my, | ||
| PetscInt | mz, | ||
| PetscBool | x_periodic, | ||
| PetscBool | y_periodic, | ||
| PetscBool | z_periodic | ||
| ) |
Builds minimal SimCtx and UserCtx fixtures for C unit tests with configurable periodicity.
Creates minimal PETSc/solver contexts with optional periodic DM boundaries.
Definition at line 325 of file test_support.c.
| PetscErrorCode PicurvCreateMinimalContexts | ( | SimCtx ** | simCtx_out, |
| UserCtx ** | user_out, | ||
| PetscInt | mx, | ||
| PetscInt | my, | ||
| PetscInt | mz | ||
| ) |
Builds minimal SimCtx and UserCtx fixtures for C unit tests.
Creates minimal PETSc/solver contexts used by isolated kernel tests.
Definition at line 530 of file test_support.c.
| PetscErrorCode PicurvPopulateUniformCellCenters | ( | UserCtx * | user | ) |
Populates cell center coordinates for a uniform grid on [0,1]^3.
Uses the shifted-index convention: cell (i,j,k) is stored at array index (i+1, j+1, k+1). For mx cells on [0,1], cell i has center at (i+0.5)/mx.
Definition at line 543 of file test_support.c.
| PetscErrorCode PicurvPopulateIdentityMetrics | ( | UserCtx * | user | ) |
Populates identity metric vectors on the minimal grid fixture.
Fills metric vectors with identity metrics for Cartesian-reference tests.
Definition at line 571 of file test_support.c.
| PetscErrorCode PicurvCreateSwarmPair | ( | UserCtx * | user, |
| PetscInt | nlocal, | ||
| const char * | post_field_name | ||
| ) |
Creates matched solver and post-processing swarms for tests.
Creates paired runtime/post swarms with optional extra post-processing field registration.
Definition at line 698 of file test_support.c.
| PetscErrorCode PicurvBuildTinyRuntimeContext | ( | const char * | bcs_contents, |
| PetscBool | enable_particles, | ||
| SimCtx ** | simCtx_out, | ||
| UserCtx ** | user_out, | ||
| char * | tmpdir, | ||
| size_t | tmpdir_len | ||
| ) |
Builds a tiny runtime context through the real setup path for behavior-level tests.
Definition at line 735 of file test_support.c.
| PetscErrorCode PicurvDestroyRuntimeContext | ( | SimCtx ** | simCtx_ptr | ) |
Finalizes and frees a runtime context built by PicurvBuildTinyRuntimeContext.
Definition at line 768 of file test_support.c.
Destroys minimal SimCtx/UserCtx fixtures and all owned PETSc objects.
Destroys contexts previously created by PicurvCreateMinimalContexts.
Definition at line 783 of file test_support.c.
| PetscErrorCode PicurvAssertRealNear | ( | PetscReal | expected, |
| PetscReal | actual, | ||
| PetscReal | tol, | ||
| const char * | context | ||
| ) |
Asserts that two real values agree within tolerance.
Asserts two real values are within tolerance for test validation.
Definition at line 902 of file test_support.c.
| PetscErrorCode PicurvAssertIntEqual | ( | PetscInt | expected, |
| PetscInt | actual, | ||
| const char * | context | ||
| ) |
Asserts that two integer values are equal.
Asserts two integer values are exactly equal for test validation.
Definition at line 917 of file test_support.c.
| PetscErrorCode PicurvAssertBool | ( | PetscBool | value, |
| const char * | context | ||
| ) |
Asserts that one boolean condition is true.
Asserts a boolean condition is true for test validation.
Definition at line 932 of file test_support.c.
| PetscErrorCode PicurvAssertFileExists | ( | const char * | path, |
| const char * | context | ||
| ) |
Asserts that a filesystem path exists as a readable file.
Asserts a filesystem path exists.
Definition at line 945 of file test_support.c.
| PetscErrorCode PicurvAssertVecConstant | ( | Vec | vec, |
| PetscScalar | expected, | ||
| PetscReal | tol, | ||
| const char * | context | ||
| ) |
Asserts that a PETSc vector is spatially constant within tolerance.
Asserts every entry of a vector equals a constant within tolerance.
Definition at line 961 of file test_support.c.