C unit tests for Poisson, RHS, body-force, and diffusivity helpers. More...
#include "test_support.h"#include "poisson.h"#include "rhs.h"#include "ParticlePhysics.h"#include "setup.h"#include "verification_sources.h"Go to the source code of this file.
Functions | |
| static PetscErrorCode | EnsurePoissonAndRhsVectors (UserCtx *user) |
| Allocates Poisson/RHS support vectors required by the tests. | |
| static PetscErrorCode | TestUpdatePressureAddsPhi (void) |
| Tests that pressure updates add the correction potential. | |
| static PetscErrorCode | TestPoissonRHSZeroDivergence (void) |
| Tests that the Poisson RHS is zero for zero-divergence velocity. | |
| static PetscErrorCode | TestComputeBodyForcesDispatcher (void) |
| Tests the body-force dispatcher across supported source terms. | |
| static PetscErrorCode | TestComputeEulerianDiffusivityMolecularOnly (void) |
| Tests Eulerian diffusivity for the molecular-only configuration. | |
| static PetscErrorCode | TestConvectionZeroField (void) |
| Tests that convection vanishes for a quiescent field. | |
| static PetscErrorCode | TestViscousUniformField (void) |
| Tests that viscous terms vanish for a uniform field. | |
| static PetscErrorCode | TestViscousWallModelledFaceCarriesTheStoredStress (void) |
| Tests that a wall-modelled face carries the stored wall stress and no gradient flux. | |
| static PetscErrorCode | ScaleMinimalMetricsToSpacing (UserCtx *user, PetscReal h) |
| Rescales the minimal fixture's unit metrics to cubic cells of edge h. | |
| static PetscErrorCode | ClarkToMolecularRatioPerX (PetscReal h, PetscInt probe, PetscReal *ratio_per_x) |
| Returns the Clark contribution over the molecular viscous one, per unit x, at one cell. | |
| static PetscErrorCode | TestClarkGradientModelScalesWithFilterWidthSquared (void) |
| Tests that the Clark gradient model scales as the square of the filter width. | |
| static PetscErrorCode | TestComputeRHSZeroFieldNoForcing (void) |
| Tests that the full RHS remains zero without forcing on a quiescent field. | |
| static PetscErrorCode | TestComputeEulerianDiffusivityGradientConstantField (void) |
| Tests diffusivity-gradient computation on a constant field. | |
| static PetscErrorCode | TestComputeEulerianDiffusivityVerificationLinearX (void) |
| Tests verification-driven linear diffusivity override and its gradient. | |
| static PetscErrorCode | TestDiffusivityGradientFillsPeriodicDummyCells (void) |
| Tests that the diffusivity gradient fills its periodic dummy cells. | |
| static PetscErrorCode | TestAssemblePoissonOperatorPopulatesRows (void) |
| Tests that Poisson matrix assembly produces a populated operator on a tiny Cartesian grid. | |
| static PetscErrorCode | RandomizeMinimalFaceMetrics (UserCtx *user) |
| Fills every face metric and Jacobian of the minimal fixture with reproducible random values, so each face gradient carries all of its cross terms. | |
| static PetscErrorCode | TestOperatorAndProjectionShareOneFaceGradient (void) |
| Tests that the operator is exactly the divergence of the projection's gradient. | |
| static PetscErrorCode | TestProjectionZeroPhiLeavesVelocityUnchanged (void) |
| Tests that projection leaves a zero pressure-correction field unchanged. | |
| static PetscErrorCode | TestProjectionLinearPhiCorrectsVelocity (void) |
| Tests that projection applies the expected x-direction correction for a linear pressure field. | |
| static PetscErrorCode | PerturbInteriorFaceFluxes (UserCtx *user, PetscReal amplitude) |
| Adds a smooth divergent perturbation to every interior face flux. | |
| static PetscErrorCode | TestPoissonSolverMultigridProjectsToDivergenceFree (void) |
| Tests that the production multigrid Poisson solve and projection remove a divergence. | |
| static PetscErrorCode | TestPoissonSolverMultigridKeepsThePressureLevel (void) |
| Tests that the multigrid solve returns Phi without a constant, so P keeps its level. | |
| static PetscErrorCode | CountFileOccurrences (const char *path, const char *needle, PetscInt *count) |
Counts the occurrences of needle in a text file; a missing file counts zero. | |
| static PetscErrorCode | TestPoissonSolverMultigridReusesItsSolver (void) |
| Tests that the multigrid solver is built once and reused on later steps. | |
| static PetscErrorCode | TestPoissonSolverMultigridHonoursDistinctSweeps (void) |
| Tests that unequal pre- and post-smoothing counts give two distinct smoothers. | |
| static PetscErrorCode | TestPoissonNullSpaceRemovesTheInteriorMean (void) |
| Tests the null space attached to the operator. | |
| static PetscErrorCode | TestPoissonSolverMultigridRefusesAnOvercoarsenedHierarchy (void) |
| Tests that an over-coarsened hierarchy stops the run at the Poisson solve. | |
| int | main (int argc, char **argv) |
| Runs the unit-poisson-rhs PETSc test binary. | |
C unit tests for Poisson, RHS, body-force, and diffusivity helpers.
Definition in file test_poisson_rhs.c.
|
static |
Allocates Poisson/RHS support vectors required by the tests.
Definition at line 17 of file test_poisson_rhs.c.
|
static |
Tests that pressure updates add the correction potential.
Definition at line 32 of file test_poisson_rhs.c.
|
static |
Tests that the Poisson RHS is zero for zero-divergence velocity.
Definition at line 53 of file test_poisson_rhs.c.
|
static |
Tests the body-force dispatcher across supported source terms.
Definition at line 87 of file test_poisson_rhs.c.
|
static |
Tests Eulerian diffusivity for the molecular-only configuration.
Definition at line 141 of file test_poisson_rhs.c.
|
static |
Tests that convection vanishes for a quiescent field.
Definition at line 168 of file test_poisson_rhs.c.
|
static |
Tests that viscous terms vanish for a uniform field.
Definition at line 195 of file test_poisson_rhs.c.
|
static |
Tests that a wall-modelled face carries the stored wall stress and no gradient flux.
The wall model acts only through this face, so the check is the one that matters: with a resolved velocity whose gradient flux would vanish everywhere, the first cell's viscous term must be exactly minus the stored stress times the face area, and it must vanish again once the wall model is off, when the face reverts to its gradient flux.
Definition at line 226 of file test_poisson_rhs.c.
|
static |
Rescales the minimal fixture's unit metrics to cubic cells of edge h.
Definition at line 280 of file test_poisson_rhs.c.
|
static |
Returns the Clark contribution over the molecular viscous one, per unit x, at one cell.
The field is u_x = x^2 on cubic cells of edge h, so du/dx = 2x and the exact gradient-model stress tau_11 = (h^2/12)(du/dx)^2 varies along x. Both the model's and viscosity's contributions leave ComputeViscous() through the same flux differences, so their ratio does not depend on how ComputeViscous() normalizes its output.
Definition at line 312 of file test_poisson_rhs.c.
|
static |
Tests that the Clark gradient model scales as the square of the filter width.
The gradient-model stress is tau_ij = (Delta_k^2/12) du_i/dx_k du_j/dx_k, so for a fixed physical field its force grows as Delta^2 relative to the molecular viscous force. Halving the spacing must therefore divide the Clark-to-molecular ratio at a given x by four. Fixtures with unit cells hide any error in the power of Delta, which is why the spacing is varied here.
Definition at line 371 of file test_poisson_rhs.c.
|
static |
Tests that the full RHS remains zero without forcing on a quiescent field.
Definition at line 399 of file test_poisson_rhs.c.
|
static |
Tests diffusivity-gradient computation on a constant field.
Definition at line 426 of file test_poisson_rhs.c.
|
static |
Tests verification-driven linear diffusivity override and its gradient.
Definition at line 447 of file test_poisson_rhs.c.
|
static |
Tests that the diffusivity gradient fills its periodic dummy cells.
A particle within half a cell of a periodic seam interpolates across it, so the dummy cells on each side must hold the gradient of the cell they image.
Definition at line 491 of file test_poisson_rhs.c.
|
static |
Tests that Poisson matrix assembly produces a populated operator on a tiny Cartesian grid.
Definition at line 528 of file test_poisson_rhs.c.
|
static |
Fills every face metric and Jacobian of the minimal fixture with reproducible random values, so each face gradient carries all of its cross terms.
Definition at line 564 of file test_poisson_rhs.c.
|
static |
Tests that the operator is exactly the divergence of the projection's gradient.
With random non-orthogonal metrics and one solid cell, projecting a zero flux with a random Phi and forming the right-hand side of the result must reproduce -A Phi on every fluid row. The identity holds for any metric values only if the operator and the projection use the same face gradient, including its one-sided forms beside walls and solid cells.
Definition at line 601 of file test_poisson_rhs.c.
|
static |
Tests that projection leaves a zero pressure-correction field unchanged.
Definition at line 670 of file test_poisson_rhs.c.
|
static |
Tests that projection applies the expected x-direction correction for a linear pressure field.
Definition at line 696 of file test_poisson_rhs.c.
|
static |
Adds a smooth divergent perturbation to every interior face flux.
Boundary faces are left alone, so the inflow still balances the outflow and the Neumann pressure problem stays solvable.
Definition at line 740 of file test_poisson_rhs.c.
|
static |
Tests that the production multigrid Poisson solve and projection remove a divergence.
Runs PoissonSolver_Multigrid through the real setup path with a three-level hierarchy, then the same UpdatePressure/ProjectVelocity pair the time loop uses, and requires the projected field to be divergence-free to the solve tolerance.
Definition at line 767 of file test_poisson_rhs.c.
|
static |
Tests that the multigrid solve returns Phi without a constant, so P keeps its level.
The residual cannot see a constant in Phi, so nothing in the Krylov iteration removes one; near a steady state the iterations at the round-off floor leave one, and P += Phi adds it up. A constant in the initial guess stands in for it here: the returned Phi must still have zero mean over the interior.
Definition at line 807 of file test_poisson_rhs.c.
|
static |
Counts the occurrences of needle in a text file; a missing file counts zero.
Definition at line 846 of file test_poisson_rhs.c.
|
static |
Tests that the multigrid solver is built once and reused on later steps.
Two consecutive solves must use the same Krylov solver and operator, both must converge, and the convergence log must hold one header per step.
Definition at line 867 of file test_poisson_rhs.c.
|
static |
Tests that unequal pre- and post-smoothing counts give two distinct smoothers.
With pre_sweeps 1 and post_sweeps 3 every smoothed level must run one sweep before the coarse correction and three after it, the post-smoother must keep the configured smoother type, and the solve must still remove the divergence. With equal counts the shared smoother runs the configured sweeps.
Definition at line 919 of file test_poisson_rhs.c.
|
static |
Tests the null space attached to the operator.
Removing it from a constant must leave zero everywhere, and from a linear field must leave zero mean over the interior with zero dummy layers.
Definition at line 985 of file test_poisson_rhs.c.
|
static |
Tests that an over-coarsened hierarchy stops the run at the Poisson solve.
Three levels on a 9-node grid leave a coarse operator the preconditioner cannot factor. The solve must return PETSC_ERR_NOT_CONVERGED rather than hand an unsolved Phi to the projection.
Definition at line 1031 of file test_poisson_rhs.c.
| int main | ( | int | argc, |
| char ** | argv | ||
| ) |
Runs the unit-poisson-rhs PETSc test binary.
Definition at line 1062 of file test_poisson_rhs.c.