15 double covariant[3][3] = {
20 double contravariant[3][3] = {{0.0}};
22 PetscFunctionBeginUser;
27 PetscFunctionReturn(0);
35 const PetscReal J[3][3] = {
40 const PetscReal u[3] = {1.5, -2.0, 4.0};
41 PetscReal uc[3] = {0.0, 0.0, 0.0};
43 PetscFunctionBeginUser;
48 PetscFunctionReturn(0);
56 const PetscReal J[3][3] = {
61 const PetscReal u[3] = {2.0, 3.0, 4.0};
62 PetscReal uc[3] = {0.0, 0.0, 0.0};
64 PetscFunctionBeginUser;
69 PetscFunctionReturn(0);
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;
85 PetscFunctionBeginUser;
99 PetscFunctionReturn(0);
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;
112 PetscFunctionBeginUser;
117 PetscFunctionReturn(0);
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;
138 PetscFunctionBeginUser;
143 PetscFunctionReturn(0);
150 const PetscReal a = 0.5, b = 2.0, c = 3.0, shear = 0.7;
151 Cmpnts nodes[2][2][2], *rows[2][2], **planes[2];
152 PetscReal J[3][3], detJ;
154 PetscFunctionBeginUser;
155 for (PetscInt k = 0; k < 2; ++k) {
156 for (PetscInt j = 0; j < 2; ++j) {
157 for (PetscInt i = 0; i < 2; ++i) {
158 nodes[k][j][i].
x = a * i + shear * k;
159 nodes[k][j][i].
y = b * j;
160 nodes[k][j][i].
z = c * k;
162 rows[k][j] = nodes[k][j];
167 PetscCall(
PicurvAssertRealNear(a * b * c, detJ, 1.0e-14,
"detJ of a parallelepiped is its volume"));
171 PetscFunctionReturn(0);
179 const Cmpnts csi = {2.0, 0.0, 0.0};
180 const Cmpnts eta = {4.0, 0.0, 0.0};
181 const Cmpnts zet = {0.0, 0.0, 3.0};
182 double dx = 0.0, dy = 0.0, dz = 0.0;
183 PetscErrorCode refused = 0;
185 PetscFunctionBeginUser;
186 PetscCall(PetscPushErrorHandler(PetscIgnoreErrorHandler, NULL));
188 PetscCall(PetscPopErrorHandler());
190 "a coplanar cell is refused, and the caller is told"));
191 PetscFunctionReturn(0);
207 const Cmpnts p = {0.31, 0.47, 0.52};
208 const Cmpnts ***cent = NULL;
210 PetscFunctionBeginUser;
215 for (PetscInt c = 0; c < 3; ++c) {
228 PetscCall(DMDAVecGetArrayRead(user->
fda, user->
lCent, (
void *)¢));
229 for (PetscInt c = 1; c < 4; ++c) {
230 const PetscInt i = c, j = 2, k = 4 - c;
232 cell.
vertices[2] = cent[k][j + 1][i + 1]; cell.
vertices[3] = cent[k][j + 1][i];
233 cell.
vertices[4] = cent[k + 1][j + 1][i]; cell.
vertices[5] = cent[k + 1][j + 1][i + 1];
234 cell.
vertices[6] = cent[k + 1][j][i + 1]; cell.
vertices[7] = cent[k + 1][j][i];
240 PetscCall(DMDAVecRestoreArrayRead(user->
fda, user->
lCent, (
void *)¢));
246 PetscFunctionReturn(0);
268 ierr = PetscInitialize(&argc, &argv, NULL,
"PICurv metric tests");
273 ierr =
PicurvRunTests(
"unit-metric", cases,
sizeof(cases) /
sizeof(cases[0]));
279 ierr = PetscFinalize();
PetscErrorCode MetricRestoreFacePlaneArrays(UserCtx *user, FacePlaneArrays *arrays)
Closes arrays opened by MetricGetFacePlaneArrays().
PetscErrorCode MetricJacobian(UserCtx *user, const Cmpnts ***X, PetscInt i, PetscInt j, PetscInt k, PetscReal xi, PetscReal eta, PetscReal zta, PetscReal J[3][3], PetscReal *detJ)
Evaluates the trilinear mapping Jacobian and its determinant in one cell.
PetscErrorCode InvertCovariantMetricTensor(double covariantTensor[3][3], double contravariantTensor[3][3])
Inverts the 3x3 matrix of face-area vectors to obtain the covariant directions.
void MetricGatherCellFacePlanes(const FacePlaneArrays *arrays, const DMDALocalInfo *info, PetscInt i, PetscInt j, PetscInt k, CellFacePlanes *planes)
Assembles one cell's six outward face planes from the shared per-face planes.
PetscErrorCode MetricComputeFacePlanes(UserCtx *user)
Builds the block's particle face planes once, as catalogued per-face fields.
PetscErrorCode MetricGetFacePlaneArrays(UserCtx *user, PetscBool dual, FacePlaneArrays *arrays)
Opens a family's face-plane arrays for reading; MetricComputeFacePlanes() must have run.
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.
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.
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.
Read-only flat arrays of one family of face planes (grid cells or dual cells).
@ FIELD_ID_PLANE_NORMAL_I
@ FIELD_ID_DUAL_PLANE_CENTROID_K
PetscErrorCode LOG_FIELD_MIN_MAX(UserCtx *user, FieldId field_id)
Computes and logs the local and global min/max values of a 3-component vector field.
PetscErrorCode LOG_FIELD_ANATOMY(UserCtx *user, FieldId field_id, const char *stage_name)
Logs the anatomy of a specified field at key boundary locations, respecting the solver's specific gri...
static PetscErrorCode TestMetricVelocityContravariantScaledAxes(void)
Tests contravariant velocity computation for scaled axes.
int main(int argc, char **argv)
Runs the unit-metric PETSc test binary.
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 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 TestMetricJacobianIsCellVolumeForParallelepiped(void)
Tests that MetricJacobian returns the physical Jacobian of a sheared, scaled cell,...
static PetscErrorCode TestFacePlanesMatchPerCellPlanes(void)
Tests that the shared per-face planes reproduce each cell's own planes and are observable.
static PetscErrorCode TestDegenerateCellIsRefused(void)
Tests that a degenerate cell is still refused, and that the refusal propagates.
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 PicurvAssertRealNear(PetscReal expected, PetscReal actual, PetscReal tol, const char *context)
Asserts that two real values agree within tolerance.
PetscErrorCode PicurvDestroyMinimalContexts(SimCtx **simCtx_ptr, UserCtx **user_ptr)
Destroys minimal SimCtx/UserCtx fixtures and all owned PETSc objects.
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 PicurvAssertIntEqual(PetscInt expected, PetscInt actual, const char *context)
Asserts that two integer values are equal.
Shared declarations for the PICurv C test fixture and assertion layer.
Named test case descriptor consumed by PicurvRunTests.
PetscReal size
Mean edge length (GetCellCharacteristicSize()); 0 where unused.
PetscInt degenerate
Bit f set when face f's normal magnitude is below 1e-12.
Cmpnts vertices[8]
Coordinates of the eight vertices of the cell.
Defines the vertices of a single hexahedral grid cell.
The six face planes of one hexahedron, indexed by Face, and its characteristic size.
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.
PetscErrorCode CalculateDistancesToCellFacePlanes(const Cmpnts p, const CellFacePlanes *planes, PetscReal *d, const PetscReal threshold, Cmpnts *normals)
Signed distances from a point to precomputed cell face planes.
PetscErrorCode CalculateDistancesToCellFaces(const Cmpnts p, const Cell *cell, PetscReal *d, const PetscReal threshold, Cmpnts *normals)
Computes the signed distances from a point to each face of a cubic cell.
PetscErrorCode GetCellCharacteristicSize(const Cell *cell, PetscReal *cellSize)
Estimates a characteristic length of the cell for threshold scaling.
PetscErrorCode RetrieveCurrentCell(UserCtx *user, PetscInt idx, PetscInt idy, PetscInt idz, Cell *cell)
Retrieves the coordinates of the eight vertices of the current cell.