PICurv 0.1.0
A Parallel Particle-In-Cell Solver for Curvilinear LES
 
Loading...
Searching...
No Matches
Functions
test_metric.c File Reference

C unit tests for metric tensors, face geometry, and length-scale helpers. More...

#include "test_support.h"
#include "Metric.h"
Include dependency graph for test_metric.c:

Go to the source code of this file.

Functions

static PetscErrorCode TestInvertCovariantMetricTensorDiagonal (void)
 Tests inversion of a diagonal covariant metric tensor.
 
static PetscErrorCode TestMetricVelocityContravariantIdentity (void)
 Tests contravariant velocity computation for identity metrics.
 
static PetscErrorCode TestMetricVelocityContravariantScaledAxes (void)
 Tests contravariant velocity computation for scaled axes.
 
static PetscErrorCode TestCalculateFaceNormalAndAreaAxisAligned (void)
 Tests face-normal and face-area calculation on an axis-aligned cell.
 
static PetscErrorCode TestComputeCellCharacteristicLengthScaleAxisAligned (void)
 Tests characteristic length-scale computation on an axis-aligned cell.
 
static PetscErrorCode TestComputeCellCharacteristicLengthScaleWallResolvedCell (void)
 Tests the length scales of a wall-resolved cell, whose metrics are tiny.
 
static PetscErrorCode TestDegenerateCellIsRefused (void)
 Tests that a degenerate cell is still refused, and that the refusal propagates.
 
int main (int argc, char **argv)
 Runs the unit-metric PETSc test binary.
 

Detailed Description

C unit tests for metric tensors, face geometry, and length-scale helpers.

Definition in file test_metric.c.

Function Documentation

◆ TestInvertCovariantMetricTensorDiagonal()

static PetscErrorCode TestInvertCovariantMetricTensorDiagonal ( void  )
static

Tests inversion of a diagonal covariant metric tensor.

Definition at line 13 of file test_metric.c.

14{
15 double covariant[3][3] = {
16 {4.0, 0.0, 0.0},
17 {0.0, 9.0, 0.0},
18 {0.0, 0.0, 16.0},
19 };
20 double contravariant[3][3] = {{0.0}};
21
22 PetscFunctionBeginUser;
23 PetscCall(InvertCovariantMetricTensor(covariant, contravariant));
24 PetscCall(PicurvAssertRealNear(0.25, contravariant[0][0], 1.0e-12, "inverse(0,0)"));
25 PetscCall(PicurvAssertRealNear(1.0 / 9.0, contravariant[1][1], 1.0e-12, "inverse(1,1)"));
26 PetscCall(PicurvAssertRealNear(0.0625, contravariant[2][2], 1.0e-12, "inverse(2,2)"));
27 PetscFunctionReturn(0);
28}
PetscErrorCode InvertCovariantMetricTensor(double covariantTensor[3][3], double contravariantTensor[3][3])
Inverts the 3x3 matrix of face-area vectors to obtain the covariant directions.
Definition Metric.c:202
PetscErrorCode PicurvAssertRealNear(PetscReal expected, PetscReal actual, PetscReal tol, const char *context)
Asserts that two real values agree within tolerance.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TestMetricVelocityContravariantIdentity()

static PetscErrorCode TestMetricVelocityContravariantIdentity ( void  )
static

Tests contravariant velocity computation for identity metrics.

Definition at line 33 of file test_metric.c.

34{
35 const PetscReal J[3][3] = {
36 {1.0, 0.0, 0.0},
37 {0.0, 1.0, 0.0},
38 {0.0, 0.0, 1.0},
39 };
40 const PetscReal u[3] = {1.5, -2.0, 4.0};
41 PetscReal uc[3] = {0.0, 0.0, 0.0};
42
43 PetscFunctionBeginUser;
44 PetscCall(MetricVelocityContravariant(J, 1.0, u, uc));
45 PetscCall(PicurvAssertRealNear(1.5, uc[0], 1.0e-12, "identity map uc[0]"));
46 PetscCall(PicurvAssertRealNear(-2.0, uc[1], 1.0e-12, "identity map uc[1]"));
47 PetscCall(PicurvAssertRealNear(4.0, uc[2], 1.0e-12, "identity map uc[2]"));
48 PetscFunctionReturn(0);
49}
PetscErrorCode MetricVelocityContravariant(const PetscReal J[3][3], PetscReal detJ, const PetscReal u[3], PetscReal uc[3])
Converts a Cartesian velocity vector to contravariant logical components.
Definition Metric.c:165
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TestMetricVelocityContravariantScaledAxes()

static PetscErrorCode TestMetricVelocityContravariantScaledAxes ( void  )
static

Tests contravariant velocity computation for scaled axes.

Definition at line 54 of file test_metric.c.

55{
56 const PetscReal J[3][3] = {
57 {2.0, 0.0, 0.0},
58 {0.0, 3.0, 0.0},
59 {0.0, 0.0, 4.0},
60 };
61 const PetscReal u[3] = {2.0, 3.0, 4.0};
62 PetscReal uc[3] = {0.0, 0.0, 0.0};
63
64 PetscFunctionBeginUser;
65 PetscCall(MetricVelocityContravariant(J, 24.0, u, uc));
66 PetscCall(PicurvAssertRealNear(1.0, uc[0], 1.0e-12, "scaled map uc[0]"));
67 PetscCall(PicurvAssertRealNear(1.0, uc[1], 1.0e-12, "scaled map uc[1]"));
68 PetscCall(PicurvAssertRealNear(1.0, uc[2], 1.0e-12, "scaled map uc[2]"));
69 PetscFunctionReturn(0);
70}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TestCalculateFaceNormalAndAreaAxisAligned()

static PetscErrorCode TestCalculateFaceNormalAndAreaAxisAligned ( void  )
static

Tests face-normal and face-area calculation on an axis-aligned cell.

Definition at line 75 of file test_metric.c.

76{
77 const Cmpnts csi = {2.0, 0.0, 0.0};
78 const Cmpnts eta = {0.0, 3.0, 0.0};
79 const Cmpnts zet = {0.0, 0.0, 4.0};
80 double ni[3] = {0.0, 0.0, 0.0};
81 double nj[3] = {0.0, 0.0, 0.0};
82 double nk[3] = {0.0, 0.0, 0.0};
83 double Ai = 0.0, Aj = 0.0, Ak = 0.0;
84
85 PetscFunctionBeginUser;
86 PetscCall(CalculateFaceNormalAndArea(csi, eta, zet, ni, nj, nk, &Ai, &Aj, &Ak));
87 PetscCall(PicurvAssertRealNear(2.0, Ai, 1.0e-12, "Ai"));
88 PetscCall(PicurvAssertRealNear(3.0, Aj, 1.0e-12, "Aj"));
89 PetscCall(PicurvAssertRealNear(4.0, Ak, 1.0e-12, "Ak"));
90 PetscCall(PicurvAssertRealNear(1.0, ni[0], 1.0e-12, "ni.x"));
91 PetscCall(PicurvAssertRealNear(0.0, ni[1], 1.0e-12, "ni.y"));
92 PetscCall(PicurvAssertRealNear(0.0, ni[2], 1.0e-12, "ni.z"));
93 PetscCall(PicurvAssertRealNear(0.0, nj[0], 1.0e-12, "nj.x"));
94 PetscCall(PicurvAssertRealNear(1.0, nj[1], 1.0e-12, "nj.y"));
95 PetscCall(PicurvAssertRealNear(0.0, nj[2], 1.0e-12, "nj.z"));
96 PetscCall(PicurvAssertRealNear(0.0, nk[0], 1.0e-12, "nk.x"));
97 PetscCall(PicurvAssertRealNear(0.0, nk[1], 1.0e-12, "nk.y"));
98 PetscCall(PicurvAssertRealNear(1.0, nk[2], 1.0e-12, "nk.z"));
99 PetscFunctionReturn(0);
100}
PetscErrorCode CalculateFaceNormalAndArea(Cmpnts csi, Cmpnts eta, Cmpnts zet, double ni[3], double nj[3], double nk[3], double *Ai, double *Aj, double *Ak)
Computes the unit normal vectors and areas of the three faces of a computational cell.
Definition Metric.c:251
A 3D point or vector with PetscScalar components.
Definition variables.h:121
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TestComputeCellCharacteristicLengthScaleAxisAligned()

static PetscErrorCode TestComputeCellCharacteristicLengthScaleAxisAligned ( void  )
static

Tests characteristic length-scale computation on an axis-aligned cell.

Definition at line 105 of file test_metric.c.

106{
107 const Cmpnts csi = {2.0, 0.0, 0.0};
108 const Cmpnts eta = {0.0, 3.0, 0.0};
109 const Cmpnts zet = {0.0, 0.0, 4.0};
110 double dx = 0.0, dy = 0.0, dz = 0.0;
111
112 PetscFunctionBeginUser;
113 PetscCall(ComputeCellCharacteristicLengthScale(1.0, csi, eta, zet, &dx, &dy, &dz));
114 PetscCall(PicurvAssertRealNear(0.5, dx, 1.0e-12, "dx"));
115 PetscCall(PicurvAssertRealNear(1.0 / 3.0, dy, 1.0e-12, "dy"));
116 PetscCall(PicurvAssertRealNear(0.25, dz, 1.0e-12, "dz"));
117 PetscFunctionReturn(0);
118}
PetscErrorCode ComputeCellCharacteristicLengthScale(PetscReal ajc, Cmpnts csi, Cmpnts eta, Cmpnts zet, double *dx, double *dy, double *dz)
Computes characteristic length scales (dx, dy, dz) for a curvilinear cell.
Definition Metric.c:297
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TestComputeCellCharacteristicLengthScaleWallResolvedCell()

static PetscErrorCode TestComputeCellCharacteristicLengthScaleWallResolvedCell ( void  )
static

Tests the length scales of a wall-resolved cell, whose metrics are tiny.

The determinant of the face-area vectors is the square of the cell volume for an orthogonal cell, so it falls as the sixth power of the spacing. The cell here is one from the Humphrey wall-resolved grid: 4.73e-4 x 4.73e-4 x 3.05e-2, whose determinant is about 4.7e-17. An absolute singularity floor rejected it and left the length scales uninitialized, which reached the solver as a NaN eddy viscosity rather than as an error.

Definition at line 129 of file test_metric.c.

130{
131 const double wall_normal = 4.73e-4, streamwise = 3.049381e-2;
132 const Cmpnts csi = {wall_normal * streamwise, 0.0, 0.0};
133 const Cmpnts eta = {0.0, wall_normal * streamwise, 0.0};
134 const Cmpnts zet = {0.0, 0.0, wall_normal * wall_normal};
135 const double volume = wall_normal * wall_normal * streamwise;
136 double dx = 0.0, dy = 0.0, dz = 0.0;
137
138 PetscFunctionBeginUser;
139 PetscCall(ComputeCellCharacteristicLengthScale(1.0 / volume, csi, eta, zet, &dx, &dy, &dz));
140 PetscCall(PicurvAssertRealNear(wall_normal, dx, 1.0e-15, "dx of a wall-resolved cell"));
141 PetscCall(PicurvAssertRealNear(wall_normal, dy, 1.0e-15, "dy of a wall-resolved cell"));
142 PetscCall(PicurvAssertRealNear(streamwise, dz, 1.0e-15, "dz of a wall-resolved cell"));
143 PetscFunctionReturn(0);
144}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TestDegenerateCellIsRefused()

static PetscErrorCode TestDegenerateCellIsRefused ( void  )
static

Tests that a degenerate cell is still refused, and that the refusal propagates.

Definition at line 149 of file test_metric.c.

150{
151 const Cmpnts csi = {2.0, 0.0, 0.0};
152 const Cmpnts eta = {4.0, 0.0, 0.0}; /* parallel to csi: the rows are coplanar */
153 const Cmpnts zet = {0.0, 0.0, 3.0};
154 double dx = 0.0, dy = 0.0, dz = 0.0;
155 PetscErrorCode refused = 0;
156
157 PetscFunctionBeginUser;
158 PetscCall(PetscPushErrorHandler(PetscIgnoreErrorHandler, NULL));
159 refused = ComputeCellCharacteristicLengthScale(1.0, csi, eta, zet, &dx, &dy, &dz);
160 PetscCall(PetscPopErrorHandler());
161 PetscCall(PicurvAssertIntEqual(PETSC_ERR_MAT_LU_ZRPVT, refused,
162 "a coplanar cell is refused, and the caller is told"));
163 PetscFunctionReturn(0);
164}
PetscErrorCode PicurvAssertIntEqual(PetscInt expected, PetscInt actual, const char *context)
Asserts that two integer values are equal.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char **  argv 
)

Runs the unit-metric PETSc test binary.

Definition at line 169 of file test_metric.c.

170{
171 PetscErrorCode ierr;
172 const PicurvTestCase cases[] = {
173 {"invert-covariant-metric-diagonal", TestInvertCovariantMetricTensorDiagonal},
174 {"metric-velocity-contravariant-identity", TestMetricVelocityContravariantIdentity},
175 {"metric-velocity-contravariant-scaled-axes", TestMetricVelocityContravariantScaledAxes},
176 {"face-normal-and-area-axis-aligned", TestCalculateFaceNormalAndAreaAxisAligned},
177 {"characteristic-length-scale-axis-aligned", TestComputeCellCharacteristicLengthScaleAxisAligned},
178 {"characteristic-length-scale-wall-resolved-cell", TestComputeCellCharacteristicLengthScaleWallResolvedCell},
179 {"degenerate-cell-is-refused", TestDegenerateCellIsRefused},
180 };
181
182 ierr = PetscInitialize(&argc, &argv, NULL, "PICurv metric tests");
183 if (ierr) {
184 return (int)ierr;
185 }
186
187 ierr = PicurvRunTests("unit-metric", cases, sizeof(cases) / sizeof(cases[0]));
188 if (ierr) {
189 PetscFinalize();
190 return (int)ierr;
191 }
192
193 ierr = PetscFinalize();
194 return (int)ierr;
195}
static PetscErrorCode TestMetricVelocityContravariantScaledAxes(void)
Tests contravariant velocity computation for scaled axes.
Definition test_metric.c:54
static PetscErrorCode TestInvertCovariantMetricTensorDiagonal(void)
Tests inversion of a diagonal covariant metric tensor.
Definition test_metric.c:13
static PetscErrorCode TestMetricVelocityContravariantIdentity(void)
Tests contravariant velocity computation for identity metrics.
Definition test_metric.c:33
static PetscErrorCode TestCalculateFaceNormalAndAreaAxisAligned(void)
Tests face-normal and face-area calculation on an axis-aligned cell.
Definition test_metric.c:75
static PetscErrorCode TestComputeCellCharacteristicLengthScaleAxisAligned(void)
Tests characteristic length-scale computation on an axis-aligned cell.
static PetscErrorCode TestComputeCellCharacteristicLengthScaleWallResolvedCell(void)
Tests the length scales of a wall-resolved cell, whose metrics are tiny.
static PetscErrorCode TestDegenerateCellIsRefused(void)
Tests that a degenerate cell is still refused, and that the refusal propagates.
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.
Named test case descriptor consumed by PicurvRunTests.
Here is the call graph for this function: