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

C unit tests for boundary factories, inlet ownership, and face helpers. More...

#include "test_support.h"
#include <sys/stat.h>
#include "Boundaries.h"
#include "wallfunction.h"
Include dependency graph for test_boundaries.c:

Go to the source code of this file.

Functions

static PetscErrorCode AppendBCParam (BC_Param **head, const char *key, const char *value)
 Appends one key/value pair to a linked list of boundary-condition parameters.
 
static PetscErrorCode DestroyBoundaryHandler (BoundaryCondition **bc_ptr)
 Destroys one boundary-condition handler allocated by a boundary test.
 
static PetscInt InteriorSampleIndex (PetscInt nodes)
 Chooses a stable interior node index for face-sample assertions on tiny test grids.
 
static PetscReal GetFaceNormalComponent (Cmpnts value, BCFace face)
 Extracts the velocity component aligned with the supplied boundary-face normal.
 
static PetscReal GetFaceOrientationSign (BCFace face)
 Returns the sign convention used for face-normal flux expectations.
 
static PetscErrorCode ConfigureNormalSourceInlet (UserCtx *user, BCFace face, const char *speed)
 Configures face as a prescribed-velocity inlet with source 0 in the normal frame.
 
static PetscReal GetFaceInteriorPointCount (const UserCtx *user, BCFace face)
 Computes the number of face-interior sample points for a given boundary face.
 
static PetscErrorCode GetRepresentativeFaceSlots (const UserCtx *user, BCFace face, PetscInt *ucont_k, PetscInt *ucont_j, PetscInt *ucont_i, PetscInt *ubcs_k, PetscInt *ubcs_j, PetscInt *ubcs_i)
 Selects representative Ucont and Ubcs slots for face-matrix assertions.
 
static PetscErrorCode GetParabolicSampleSlots (const UserCtx *user, BCFace face, PetscInt *center_k, PetscInt *center_j, PetscInt *center_i, PetscInt *off_k, PetscInt *off_j, PetscInt *off_i, PetscInt *wall_k, PetscInt *wall_j, PetscInt *wall_i, PetscInt *ubcs_center_k, PetscInt *ubcs_center_j, PetscInt *ubcs_center_i)
 Selects center, off-center, and wall-adjacent slots for parabolic-face checks.
 
static void ResetBoundaryFaceConfig (BoundaryFaceConfig *cfg)
 Resets one boundary-face configuration entry to a neutral test-local baseline.
 
static PetscErrorCode TestCanRankServiceFaceMatchesInletWhenDefined (void)
 Tests that face-service detection matches a defined inlet face.
 
static PetscErrorCode TestBoundaryConditionFactoryAssignments (void)
 Tests the boundary-condition factory assignments for representative handlers.
 
static PetscErrorCode ApplyInletAcrossFirstSteps (BoundaryCondition *bc, BCContext *ctx)
 Reapplies a static inlet through the first three time-step contexts.
 
static PetscErrorCode TestBoundaryConditionFactoryImplementedHandlerMatrix (void)
 Tests the implemented-handler matrix exposed by the factory.
 
static PetscErrorCode WritePicSliceForTests (const char *path, PetscInt n1, PetscInt n2, PetscReal base)
 Writes a tiny canonical PICSLICE profile for boundary handler tests.
 
static PetscErrorCode TestInletPicSliceSourceBehavior (void)
 Tests a prescribed-velocity inlet loading and applying one Z-face PICSLICE profile.
 
static PetscErrorCode TestInletSourceAddsToPicSlice (void)
 Tests expressions added to a profile file: a bulk velocity scales the expressions and leaves the file's data as measured, as it does a generator's field in the interior.
 
static PetscErrorCode TestBoundaryConditionFactoryRejectsUnsupportedHandler (void)
 Tests that unsupported handler types are rejected by the factory.
 
static PetscErrorCode TestInletNormalSourceBehavior (void)
 Tests a constant normal-speed source's face writes and flux on a Z inlet.
 
static PetscErrorCode TestInletCommonApplicationCurvilinearMetric (void)
 Verifies curvilinear projection and Cartesian dummy reflection for the shared inlet path.
 
static PetscErrorCode TestWallNoSlipHandlerFaceMatrix (void)
 Tests wall no-slip application across the full face matrix.
 
static PetscErrorCode SetUniformCartesian (Vec v, PetscReal x, PetscReal y, PetscReal z)
 Sets every entry of a three-component vector to one Cartesian value.
 
static PetscErrorCode TestWallFreeSlipHandlerFaceMatrix (void)
 Tests the free-slip wall across the full face matrix on a Cartesian grid.
 
static PetscErrorCode TestWallFreeSlipCurvilinearNormal (void)
 Tests the free-slip wall against a face whose normal is not a grid axis.
 
static PetscErrorCode TestFreeSlipWallExertsNoShear (void)
 Tests which faces exert shear, and that only a free-slip wall mirrors the eddy viscosity.
 
static PetscErrorCode TestInletNormalSourceFaceMatrix (void)
 Tests a constant normal-speed source's flux accounting and face writes across all faces.
 
static PetscErrorCode TestInletParabolicSourceBehavior (void)
 Tests a parabola written in the arc-length fractions on a tiny Z-face.
 
static PetscErrorCode TestInletOneAxisSourceIsUniformAlongTheOther (void)
 Tests that a profile in one fraction is uniform along the other tangential axis.
 
static PetscErrorCode TestInletParabolicSourceFaceMatrix (void)
 Tests a parabola in each face's two tangential fractions across all faces: its centreline, wall-adjacent value, and flux.
 
static PetscErrorCode TestInletSourceFollowsTimeAndBulkVelocity (void)
 Tests that a source in t is re-evaluated once per step, and that a bulk velocity rescales the face to its target mean normal speed each step.
 
static PetscErrorCode ApplyHandlerAtTime (BoundaryCondition *bc, BCContext *ctx, PetscInt step, PetscReal physical_time)
 Runs the handler at one time as a new step of its own.
 
static PetscErrorCode TestInletRecordingOfCartesianVelocities (void)
 Tests a recording of Cartesian velocities: every component reaches the boundary, reversed flow is allowed, frames interpolate linearly in time, and past the end they repeat when asked and are refused when not.
 
static PetscErrorCode TestInletFlowRateAndFaceRadius (void)
 Tests that a flow-rate target sets the face's total flux, whatever its area, and that r is the distance from the face's centre.
 
static PetscErrorCode TestWallMovingAlongItself (void)
 Tests a moving wall on both a - and a + face: its velocity along the wall reaches the boundary value and the face stays closed, a slight tilt is removed, and a velocity through the wall is refused.
 
static PetscErrorCode TestOutletConservationHandlerBehavior (void)
 Tests outlet conservation handler correction and post-step flux accounting.
 
static PetscErrorCode TestOutletConservationHandlerFaceMatrix (void)
 Tests outlet-conservation correction and flux accounting across all outlet faces.
 
static PetscErrorCode SetCellNormalVelocity (UserCtx *user, BCFace face, PetscInt k, PetscInt j, PetscInt i, PetscReal value)
 Sets the face-normal Ucat component of one cell and refreshes lUcat.
 
static PetscErrorCode ApplyOutletAndMeasure (BoundaryCondition *bc, BCContext *ctx, BCFace face, PetscReal inflow, PetscReal outflow_measured, PetscReal *sample_flux, Cmpnts *sample_ubcs, PetscReal *total)
 Runs one outlet Apply with the given sums and returns the face's sample flux and total.
 
static PetscErrorCode TestOutletConservationBackflowClip (void)
 Tests the conservation outlet's backflow clip on +X, +Y, +Z and on -X, -Z.
 
static PetscErrorCode TestOutletConservationClipFrozenPerStep (void)
 Tests that the backflow clip's rule and clipped set are frozen within a time step.
 
static PetscErrorCode TestFinalizePostProjectionCellFieldsNonPeriodic (void)
 Tests non-periodic cell-field finalization without modifying Ucont.
 
static PetscErrorCode TestEnforceRHSBoundaryConditionsMatchesRowClassification (void)
 EnforceRHSBoundaryConditions() must zero a row exactly when it is not an unknown.
 
static PetscErrorCode SeedWallFrictionVelocityStorage (UserCtx *user)
 Allocates the wall-model storage the way production allocates it.
 
static PetscErrorCode SeedWallFunctionFixture (UserCtx *user, Cmpnts velocity)
 Seeds the fields ApplyWallFunction() reads, for walls on xi and eta faces.
 
static PetscErrorCode TestApplyWallFunctionMatchesTheLogLawItDispatches (void)
 Tests that the wall-function integration reproduces the model it dispatches to.
 
static PetscErrorCode TestWallFunctionModelSelectorChoosesTheLaw (void)
 Tests that the model selector actually changes which law is applied.
 
static PetscErrorCode TestApplyWallFunctionSkipsNonWallFaces (void)
 Tests that a face which is not a wall is left alone by the wall function.
 
static PetscErrorCode TestApplyWallFunctionSkipsFreeSlipWalls (void)
 Tests that the wall model leaves a free-slip wall alone.
 
static PetscErrorCode TestWallModelFrictionVelocityRespondsToTheFlow (void)
 Tests that every wall law's friction velocity responds to the flow it is given.
 
static PetscErrorCode TestWallFrictionVelocityStorageMatchesTheCatalog (void)
 Tests that the friction-velocity storage matches what the field catalog declares.
 
static PetscErrorCode TestWallModelEdgeCellHasOneStressPerWall (void)
 Tests that a cell beside two walls gets one independent stress per wall face.
 
static PetscErrorCode TestWallModelDiagnosticsRecordTheCorrectedCells (void)
 Tests that the wall pass records the statistics its diagnostics report.
 
static PetscErrorCode TestDummyCellsFollowEachFieldsBoundaryRule (void)
 Checks each cell-centred field's dummy-cell rule, faces then edges.
 
int main (int argc, char **argv)
 Runs the unit-boundaries PETSc test binary.
 

Detailed Description

C unit tests for boundary factories, inlet ownership, and face helpers.

Definition in file test_boundaries.c.

Function Documentation

◆ AppendBCParam()

static PetscErrorCode AppendBCParam ( BC_Param **  head,
const char *  key,
const char *  value 
)
static

Appends one key/value pair to a linked list of boundary-condition parameters.

Definition at line 15 of file test_boundaries.c.

16{
17 BC_Param *node = NULL;
18 BC_Param **cursor = head;
19
20 PetscFunctionBeginUser;
21 PetscCheck(head != NULL, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL, "BC param list head cannot be NULL.");
22 PetscCall(PetscCalloc1(1, &node));
23 PetscCall(PetscStrallocpy(key, &node->key));
24 PetscCall(PetscStrallocpy(value, &node->value));
25 while (*cursor) {
26 cursor = &(*cursor)->next;
27 }
28 *cursor = node;
29 PetscFunctionReturn(0);
30}
struct BC_Param_s * next
Definition variables.h:375
A node in a linked list for storing key-value parameters from the bcs.dat file.
Definition variables.h:372
A generic C-style linked list node for integers.
Definition variables.h:498
Here is the caller graph for this function:

◆ DestroyBoundaryHandler()

static PetscErrorCode DestroyBoundaryHandler ( BoundaryCondition **  bc_ptr)
static

Destroys one boundary-condition handler allocated by a boundary test.

Definition at line 35 of file test_boundaries.c.

36{
37 BoundaryCondition *bc = NULL;
38 PetscFunctionBeginUser;
39 if (!bc_ptr || !*bc_ptr) PetscFunctionReturn(0);
40
41 bc = *bc_ptr;
42 if (bc->Destroy) {
43 PetscCall(bc->Destroy(bc));
44 }
45 PetscCall(PetscFree(bc));
46 *bc_ptr = NULL;
47 PetscFunctionReturn(0);
48}
The "virtual table" struct for a boundary condition handler object.
Definition variables.h:389
PetscErrorCode(* Destroy)(BoundaryCondition *self)
Definition variables.h:398
Here is the caller graph for this function:

◆ InteriorSampleIndex()

static PetscInt InteriorSampleIndex ( PetscInt  nodes)
static

Chooses a stable interior node index for face-sample assertions on tiny test grids.

Definition at line 53 of file test_boundaries.c.

54{
55 PetscInt index = 3;
56
57 if (index >= nodes - 1) {
58 index = nodes - 2;
59 }
60 if (index < 1) {
61 index = 1;
62 }
63 return index;
64}
Here is the caller graph for this function:

◆ GetFaceNormalComponent()

static PetscReal GetFaceNormalComponent ( Cmpnts  value,
BCFace  face 
)
static

Extracts the velocity component aligned with the supplied boundary-face normal.

Definition at line 69 of file test_boundaries.c.

70{
71 switch (face) {
72 case BC_FACE_NEG_X:
73 case BC_FACE_POS_X:
74 return value.x;
75 case BC_FACE_NEG_Y:
76 case BC_FACE_POS_Y:
77 return value.y;
78 case BC_FACE_NEG_Z:
79 case BC_FACE_POS_Z:
80 return value.z;
81 }
82 return 0.0;
83}
PetscScalar x
Definition variables.h:145
PetscScalar z
Definition variables.h:145
PetscScalar y
Definition variables.h:145
@ BC_FACE_NEG_X
Definition variables.h:309
@ BC_FACE_POS_Z
Definition variables.h:311
@ BC_FACE_POS_Y
Definition variables.h:310
@ BC_FACE_NEG_Z
Definition variables.h:311
@ BC_FACE_POS_X
Definition variables.h:309
@ BC_FACE_NEG_Y
Definition variables.h:310
Here is the caller graph for this function:

◆ GetFaceOrientationSign()

static PetscReal GetFaceOrientationSign ( BCFace  face)
static

Returns the sign convention used for face-normal flux expectations.

Definition at line 88 of file test_boundaries.c.

89{
90 switch (face) {
91 case BC_FACE_NEG_X:
92 case BC_FACE_NEG_Y:
93 case BC_FACE_NEG_Z:
94 return 1.0;
95 case BC_FACE_POS_X:
96 case BC_FACE_POS_Y:
97 case BC_FACE_POS_Z:
98 return -1.0;
99 }
100 return 0.0;
101}
Here is the caller graph for this function:

◆ ConfigureNormalSourceInlet()

static PetscErrorCode ConfigureNormalSourceInlet ( UserCtx *  user,
BCFace  face,
const char *  speed 
)
static

Configures face as a prescribed-velocity inlet with source 0 in the normal frame.

The source's options live in the global database, so each call replaces the last.

Definition at line 107 of file test_boundaries.c.

108{
109 PetscFunctionBeginUser;
110 user->boundary_faces[face].face_id = face;
113 PetscCall(AppendBCParam(&user->boundary_faces[face].params, "source_id", "0"));
114 PetscCall(PetscOptionsSetValue(NULL, "-face_source_0_frame", "normal"));
115 PetscCall(PetscOptionsSetValue(NULL, "-face_source_0_expr_0", speed));
116 PetscFunctionReturn(0);
117}
static PetscErrorCode AppendBCParam(BC_Param **head, const char *key, const char *value)
Appends one key/value pair to a linked list of boundary-condition parameters.
@ INLET
Definition variables.h:323
BoundaryFaceConfig boundary_faces[6]
Definition variables.h:1182
@ BC_HANDLER_INLET_PRESCRIBED_VELOCITY
Definition variables.h:348
BCHandlerType handler_type
Definition variables.h:427
BC_Param * params
Definition variables.h:429
BCType mathematical_type
Definition variables.h:426
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetFaceInteriorPointCount()

static PetscReal GetFaceInteriorPointCount ( const UserCtx *  user,
BCFace  face 
)
static

Computes the number of face-interior sample points for a given boundary face.

Definition at line 122 of file test_boundaries.c.

123{
124 switch (face) {
125 case BC_FACE_NEG_X:
126 case BC_FACE_POS_X:
127 return (PetscReal)(user->info.my - 2) * (PetscReal)(user->info.mz - 2);
128 case BC_FACE_NEG_Y:
129 case BC_FACE_POS_Y:
130 return (PetscReal)(user->info.mx - 2) * (PetscReal)(user->info.mz - 2);
131 case BC_FACE_NEG_Z:
132 case BC_FACE_POS_Z:
133 return (PetscReal)(user->info.mx - 2) * (PetscReal)(user->info.my - 2);
134 }
135 return 0.0;
136}
DMDALocalInfo info
Definition variables.h:1169
Here is the caller graph for this function:

◆ GetRepresentativeFaceSlots()

static PetscErrorCode GetRepresentativeFaceSlots ( const UserCtx *  user,
BCFace  face,
PetscInt *  ucont_k,
PetscInt *  ucont_j,
PetscInt *  ucont_i,
PetscInt *  ubcs_k,
PetscInt *  ubcs_j,
PetscInt *  ubcs_i 
)
static

Selects representative Ucont and Ubcs slots for face-matrix assertions.

Definition at line 141 of file test_boundaries.c.

149{
150 const PetscInt sample_i = InteriorSampleIndex(user->info.mx);
151 const PetscInt sample_j = InteriorSampleIndex(user->info.my);
152 const PetscInt sample_k = InteriorSampleIndex(user->info.mz);
153
154 PetscFunctionBeginUser;
155 switch (face) {
156 case BC_FACE_NEG_X:
157 *ucont_k = sample_k; *ucont_j = sample_j; *ucont_i = 0;
158 *ubcs_k = sample_k; *ubcs_j = sample_j; *ubcs_i = 0;
159 break;
160 case BC_FACE_POS_X:
161 *ucont_k = sample_k; *ucont_j = sample_j; *ucont_i = user->info.mx - 2;
162 *ubcs_k = sample_k; *ubcs_j = sample_j; *ubcs_i = user->info.mx - 1;
163 break;
164 case BC_FACE_NEG_Y:
165 *ucont_k = sample_k; *ucont_j = 0; *ucont_i = sample_i;
166 *ubcs_k = sample_k; *ubcs_j = 0; *ubcs_i = sample_i;
167 break;
168 case BC_FACE_POS_Y:
169 *ucont_k = sample_k; *ucont_j = user->info.my - 2; *ucont_i = sample_i;
170 *ubcs_k = sample_k; *ubcs_j = user->info.my - 1; *ubcs_i = sample_i;
171 break;
172 case BC_FACE_NEG_Z:
173 *ucont_k = 0; *ucont_j = sample_j; *ucont_i = sample_i;
174 *ubcs_k = 0; *ubcs_j = sample_j; *ubcs_i = sample_i;
175 break;
176 case BC_FACE_POS_Z:
177 *ucont_k = user->info.mz - 2; *ucont_j = sample_j; *ucont_i = sample_i;
178 *ubcs_k = user->info.mz - 1; *ubcs_j = sample_j; *ubcs_i = sample_i;
179 break;
180 }
181 PetscFunctionReturn(0);
182}
static PetscInt InteriorSampleIndex(PetscInt nodes)
Chooses a stable interior node index for face-sample assertions on tiny test grids.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetParabolicSampleSlots()

static PetscErrorCode GetParabolicSampleSlots ( const UserCtx *  user,
BCFace  face,
PetscInt *  center_k,
PetscInt *  center_j,
PetscInt *  center_i,
PetscInt *  off_k,
PetscInt *  off_j,
PetscInt *  off_i,
PetscInt *  wall_k,
PetscInt *  wall_j,
PetscInt *  wall_i,
PetscInt *  ubcs_center_k,
PetscInt *  ubcs_center_j,
PetscInt *  ubcs_center_i 
)
static

Selects center, off-center, and wall-adjacent slots for parabolic-face checks.

Definition at line 187 of file test_boundaries.c.

201{
202 PetscFunctionBeginUser;
203 switch (face) {
204 case BC_FACE_NEG_X:
205 *center_k = 3; *center_j = 3; *center_i = 0;
206 *off_k = 2; *off_j = 2; *off_i = 0;
207 *wall_k = 1; *wall_j = 1; *wall_i = 0;
208 *ubcs_center_k = 3; *ubcs_center_j = 3; *ubcs_center_i = 0;
209 break;
210 case BC_FACE_POS_X:
211 *center_k = 3; *center_j = 3; *center_i = user->info.mx - 2;
212 *off_k = 2; *off_j = 2; *off_i = user->info.mx - 2;
213 *wall_k = 1; *wall_j = 1; *wall_i = user->info.mx - 2;
214 *ubcs_center_k = 3; *ubcs_center_j = 3; *ubcs_center_i = user->info.mx - 1;
215 break;
216 case BC_FACE_NEG_Y:
217 *center_k = 3; *center_j = 0; *center_i = 3;
218 *off_k = 2; *off_j = 0; *off_i = 2;
219 *wall_k = 1; *wall_j = 0; *wall_i = 1;
220 *ubcs_center_k = 3; *ubcs_center_j = 0; *ubcs_center_i = 3;
221 break;
222 case BC_FACE_POS_Y:
223 *center_k = 3; *center_j = user->info.my - 2; *center_i = 3;
224 *off_k = 2; *off_j = user->info.my - 2; *off_i = 2;
225 *wall_k = 1; *wall_j = user->info.my - 2; *wall_i = 1;
226 *ubcs_center_k = 3; *ubcs_center_j = user->info.my - 1; *ubcs_center_i = 3;
227 break;
228 case BC_FACE_NEG_Z:
229 *center_k = 0; *center_j = 3; *center_i = 3;
230 *off_k = 0; *off_j = 2; *off_i = 2;
231 *wall_k = 0; *wall_j = 1; *wall_i = 1;
232 *ubcs_center_k = 0; *ubcs_center_j = 3; *ubcs_center_i = 3;
233 break;
234 case BC_FACE_POS_Z:
235 *center_k = user->info.mz - 2; *center_j = 3; *center_i = 3;
236 *off_k = user->info.mz - 2; *off_j = 2; *off_i = 2;
237 *wall_k = user->info.mz - 2; *wall_j = 1; *wall_i = 1;
238 *ubcs_center_k = user->info.mz - 1; *ubcs_center_j = 3; *ubcs_center_i = 3;
239 break;
240 default:
241 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Unknown boundary face %d.", (int)face);
242 }
243 PetscFunctionReturn(0);
244}
Here is the caller graph for this function:

◆ ResetBoundaryFaceConfig()

static void ResetBoundaryFaceConfig ( BoundaryFaceConfig *  cfg)
static

Resets one boundary-face configuration entry to a neutral test-local baseline.

Definition at line 249 of file test_boundaries.c.

250{
253 cfg->face_id = BC_FACE_NEG_X;
254 if (cfg->params) {
256 cfg->params = NULL;
257 }
258}
void FreeBC_ParamList(BC_Param *head)
Frees an entire linked list of boundary-condition parameters.
Definition io.c:719
@ INTERFACE
Definition variables.h:318
@ BC_HANDLER_UNDEFINED
Definition variables.h:344
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TestCanRankServiceFaceMatchesInletWhenDefined()

static PetscErrorCode TestCanRankServiceFaceMatchesInletWhenDefined ( void  )
static

Tests that face-service detection matches a defined inlet face.

Definition at line 263 of file test_boundaries.c.

264{
265 SimCtx *simCtx = NULL;
266 UserCtx *user = NULL;
267 PetscBool generic_face = PETSC_FALSE;
268 PetscBool any_face_serviceable = PETSC_FALSE;
269
270 PetscFunctionBeginUser;
271 PetscCall(PicurvCreateMinimalContexts(&simCtx, &user, 4, 4, 4));
272
273 for (BCFace face = BC_FACE_NEG_X; face <= BC_FACE_POS_Z; face++) {
274 PetscCall(CanRankServiceFace(&user->info, user->IM, user->JM, user->KM, face, &generic_face));
275 if (generic_face) {
276 any_face_serviceable = PETSC_TRUE;
277 }
278
279 }
280 PetscCall(PicurvAssertBool(any_face_serviceable, "at least one global face should be serviceable in a non-degenerate domain"));
281
282 PetscCall(PicurvDestroyMinimalContexts(&simCtx, &user));
283 PetscFunctionReturn(0);
284}
PetscErrorCode CanRankServiceFace(const DMDALocalInfo *info, PetscInt IM_nodes_global, PetscInt JM_nodes_global, PetscInt KM_nodes_global, BCFace face_id, PetscBool *can_service_out)
Determines if the current MPI rank owns any part of a specified global face.
Definition Boundaries.c:22
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 PicurvDestroyMinimalContexts(SimCtx **simCtx_ptr, UserCtx **user_ptr)
Destroys minimal SimCtx/UserCtx fixtures and all owned PETSc objects.
PetscErrorCode PicurvAssertBool(PetscBool value, const char *context)
Asserts that one boolean condition is true.
PetscInt KM
Definition variables.h:1171
PetscInt JM
Definition variables.h:1171
PetscInt IM
Definition variables.h:1171
BCFace
Identifies the six logical faces of a structured computational block.
Definition variables.h:308
The master context for the entire simulation.
Definition variables.h:916
User-defined context containing data specific to a single computational grid level.
Definition variables.h:1157
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TestBoundaryConditionFactoryAssignments()

static PetscErrorCode TestBoundaryConditionFactoryAssignments ( void  )
static

Tests the boundary-condition factory assignments for representative handlers.

Definition at line 289 of file test_boundaries.c.

290{
291 BoundaryCondition *wall = NULL;
292 BoundaryCondition *inlet = NULL;
293
294 PetscFunctionBeginUser;
296 PetscCall(PicurvAssertBool((PetscBool)(wall != NULL), "factory should return wall handler"));
297 PetscCall(PicurvAssertIntEqual(BC_PRIORITY_WALL, wall->priority, "wall handler priority"));
298 PetscCall(PicurvAssertBool((PetscBool)(wall->Apply != NULL), "wall handler should expose Apply"));
299 PetscCall(PicurvAssertBool((PetscBool)(wall->Destroy == NULL), "wall handler should not require destroy hook"));
300 PetscCall(DestroyBoundaryHandler(&wall));
301
303 PetscCall(PicurvAssertBool((PetscBool)(inlet != NULL), "factory should return inlet handler"));
304 PetscCall(PicurvAssertIntEqual(BC_PRIORITY_INLET, inlet->priority, "inlet handler priority"));
305 PetscCall(PicurvAssertBool((PetscBool)(inlet->Initialize != NULL), "inlet handler should expose Initialize"));
306 PetscCall(PicurvAssertBool((PetscBool)(inlet->Apply != NULL), "inlet handler should expose Apply"));
307 PetscCall(PicurvAssertBool((PetscBool)(inlet->Destroy != NULL), "inlet handler should expose its destroy hook"));
308 PetscCall(DestroyBoundaryHandler(&inlet));
309
310 PetscFunctionReturn(0);
311}
PetscErrorCode BoundaryCondition_Create(BCHandlerType handler_type, BoundaryCondition **new_bc_ptr)
(Private) Creates and configures a specific BoundaryCondition handler object.
Definition Boundaries.c:265
PetscErrorCode(* Initialize)(BoundaryCondition *self, BCContext *ctx)
Definition variables.h:393
PetscErrorCode(* Apply)(BoundaryCondition *self, BCContext *ctx)
Definition variables.h:395
BCPriorityType priority
Definition variables.h:391
static PetscErrorCode DestroyBoundaryHandler(BoundaryCondition **bc_ptr)
Destroys one boundary-condition handler allocated by a boundary test.
PetscErrorCode PicurvAssertIntEqual(PetscInt expected, PetscInt actual, const char *context)
Asserts that two integer values are equal.
@ BC_HANDLER_WALL_NOSLIP
Definition variables.h:345
@ BC_PRIORITY_WALL
Definition variables.h:363
@ BC_PRIORITY_INLET
Definition variables.h:361
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ApplyInletAcrossFirstSteps()

static PetscErrorCode ApplyInletAcrossFirstSteps ( BoundaryCondition *  bc,
BCContext *  ctx 
)
static

Reapplies a static inlet through the first three time-step contexts.

Definition at line 316 of file test_boundaries.c.

317{
318 PetscFunctionBeginUser;
319 for (PetscInt step = 0; step < 3; step++) {
320 PetscReal local_inflow = 0.0, local_outflow = 0.0;
321 ctx->user->simCtx->step = step;
322 ctx->user->simCtx->ti = 0.1 * (PetscReal)step;
323 PetscCall(VecSet(ctx->user->Ucont, -91.0));
324 PetscCall(VecSet(ctx->user->Bcs.Ubcs, -92.0));
325 PetscCall(bc->PreStep(bc, ctx, &local_inflow, &local_outflow));
326 PetscCall(bc->Apply(bc, ctx));
327 }
328 PetscFunctionReturn(0);
329}
PetscErrorCode(* PreStep)(BoundaryCondition *self, BCContext *ctx, PetscReal *local_inflow, PetscReal *local_outflow)
Definition variables.h:394
SimCtx * simCtx
Back-pointer to the master simulation context.
Definition variables.h:1160
Vec Ucont
Definition variables.h:1197
Vec Ubcs
Physical Cartesian velocity at boundary faces. Full 3D array but only boundary-face entries are meani...
Definition variables.h:172
UserCtx * user
Definition variables.h:380
PetscInt step
Definition variables.h:924
PetscReal ti
Definition variables.h:925
Here is the caller graph for this function:

◆ TestBoundaryConditionFactoryImplementedHandlerMatrix()

static PetscErrorCode TestBoundaryConditionFactoryImplementedHandlerMatrix ( void  )
static

Tests the implemented-handler matrix exposed by the factory.

Definition at line 334 of file test_boundaries.c.

335{
336 struct HandlerExpectation {
337 BCHandlerType handler;
338 BCPriorityType priority;
339 PetscBool expect_apply;
340 PetscBool expect_initialize;
341 };
342 const struct HandlerExpectation expectations[] = {
343 {BC_HANDLER_WALL_NOSLIP, BC_PRIORITY_WALL, PETSC_TRUE, PETSC_FALSE},
344 {BC_HANDLER_WALL_FREE_SLIP, BC_PRIORITY_WALL, PETSC_TRUE, PETSC_FALSE},
346 {BC_HANDLER_OUTLET_CONSERVATION, BC_PRIORITY_OUTLET, PETSC_TRUE, PETSC_FALSE},
347 };
348
349 PetscFunctionBeginUser;
350 for (size_t i = 0; i < sizeof(expectations) / sizeof(expectations[0]); ++i) {
351 BoundaryCondition *bc = NULL;
352 PetscCall(BoundaryCondition_Create(expectations[i].handler, &bc));
353 PetscCall(PicurvAssertBool((PetscBool)(bc != NULL), "factory should allocate a handler object"));
354 PetscCall(PicurvAssertIntEqual(expectations[i].priority, bc->priority, "handler priority should match expectation"));
355 PetscCall(PicurvAssertBool((PetscBool)((bc->Apply != NULL) == expectations[i].expect_apply), "Apply hook expectation mismatch"));
356 PetscCall(PicurvAssertBool((PetscBool)((bc->Initialize != NULL) == expectations[i].expect_initialize), "Initialize hook expectation mismatch"));
357 PetscCall(DestroyBoundaryHandler(&bc));
358 }
359 PetscFunctionReturn(0);
360}
BCHandlerType
Defines the specific computational "strategy" for a boundary handler.
Definition variables.h:343
@ BC_HANDLER_OUTLET_CONSERVATION
Definition variables.h:350
@ BC_HANDLER_WALL_FREE_SLIP
Definition variables.h:347
BCPriorityType
Definition variables.h:359
@ BC_PRIORITY_OUTLET
Definition variables.h:364
Here is the call graph for this function:
Here is the caller graph for this function:

◆ WritePicSliceForTests()

static PetscErrorCode WritePicSliceForTests ( const char *  path,
PetscInt  n1,
PetscInt  n2,
PetscReal  base 
)
static

Writes a tiny canonical PICSLICE profile for boundary handler tests.

Definition at line 365 of file test_boundaries.c.

366{
367 FILE *fd = NULL;
368
369 PetscFunctionBeginUser;
370 fd = fopen(path, "w");
371 PetscCheck(fd != NULL, PETSC_COMM_SELF, PETSC_ERR_FILE_OPEN, "Could not open %s for writing.", path);
372 PetscCheck(fprintf(fd, "PICSLICE\n1\n%d %d\n", (int)n1, (int)n2) >= 0,
373 PETSC_COMM_SELF, PETSC_ERR_FILE_WRITE, "Could not write PICSLICE header.");
374 for (PetscInt a = 0; a < n1; a++) {
375 for (PetscInt b = 0; b < n2; b++) {
376 PetscReal value = base + (PetscReal)(10 * a + b);
377 PetscCheck(fprintf(fd, "%.16e\n", (double)value) >= 0,
378 PETSC_COMM_SELF, PETSC_ERR_FILE_WRITE, "Could not write PICSLICE value.");
379 }
380 }
381 fclose(fd);
382 PetscFunctionReturn(0);
383}
Here is the caller graph for this function:

◆ TestInletPicSliceSourceBehavior()

static PetscErrorCode TestInletPicSliceSourceBehavior ( void  )
static

Tests a prescribed-velocity inlet loading and applying one Z-face PICSLICE profile.

Definition at line 388 of file test_boundaries.c.

389{
390 SimCtx *simCtx = NULL;
391 UserCtx *user = NULL;
392 BoundaryCondition *bc = NULL;
393 BCContext ctx;
394 Cmpnts ***ucont = NULL;
395 Cmpnts ***ubcs = NULL;
396 char profile_path[PETSC_MAX_PATH_LEN];
397 PetscReal local_inflow = 0.0;
398 PetscReal local_outflow = 0.0;
399
400 PetscFunctionBeginUser;
401 PetscCall(PetscMemzero(&ctx, sizeof(ctx)));
402 PetscCall(PicurvCreateMinimalContexts(&simCtx, &user, 5, 5, 5));
403 PetscCall(PicurvPopulateIdentityMetrics(user));
404
405 PetscCall(PetscSNPrintf(profile_path, sizeof(profile_path), "/tmp/picurv_unit_profile_%d.picslice", (int)getpid()));
406 PetscCall(WritePicSliceForTests(profile_path, user->JM - 1, user->IM - 1, 2.0));
407
411 PetscCall(AppendBCParam(&user->boundary_faces[BC_FACE_NEG_Z].params, "source_id", "7"));
412 PetscCall(AppendBCParam(&user->boundary_faces[BC_FACE_NEG_Z].params, "source_file", profile_path));
413
414 PetscCall(VecSet(user->Ucont, 0.0));
415 PetscCall(VecSet(user->Bcs.Ubcs, 0.0));
416
417 ctx.user = user;
420 PetscCall(bc->Initialize(bc, &ctx));
421 PetscCall(ApplyInletAcrossFirstSteps(bc, &ctx));
422 PetscCall(bc->PostStep(bc, &ctx, &local_inflow, &local_outflow));
423
424 PetscCall(DMDAVecGetArrayRead(user->fda, user->Ucont, &ucont));
425 PetscCall(DMDAVecGetArrayRead(user->fda, user->Bcs.Ubcs, &ubcs));
426 PetscCall(PicurvAssertRealNear(2.0, ucont[0][1][1].z, 1.0e-12, "profile inlet should apply first scalar speed"));
427 PetscCall(PicurvAssertRealNear(13.0, ucont[0][2][2].z, 1.0e-12, "profile inlet should preserve PICSLICE ordering"));
428 PetscCall(PicurvAssertRealNear(24.0, ubcs[0][3][3].z, 1.0e-12, "profile inlet should write boundary velocity"));
429 PetscCall(PicurvAssertRealNear(35.0, ucont[0][4][4].z, 1.0e-12, "profile inlet should consume the last face-cell slot"));
430 PetscCall(PicurvAssertRealNear(35.0, ubcs[0][4][4].z, 1.0e-12, "profile inlet should write the last face-cell boundary value"));
431 PetscCall(DMDAVecRestoreArrayRead(user->fda, user->Ucont, &ucont));
432 PetscCall(DMDAVecRestoreArrayRead(user->fda, user->Bcs.Ubcs, &ubcs));
433 PetscCall(PicurvAssertBool((PetscBool)(local_inflow > 0.0), "profile inlet PostStep should accumulate positive negative-face flux"));
434 PetscCall(PicurvAssertRealNear(0.0, local_outflow, 1.0e-12, "profile inlet should not add to outflow"));
435
436 PetscCall(DestroyBoundaryHandler(&bc));
438 user->boundary_faces[BC_FACE_NEG_Z].params = NULL;
439 remove(profile_path);
440 PetscCall(PicurvDestroyMinimalContexts(&simCtx, &user));
441 PetscFunctionReturn(0);
442}
PetscErrorCode(* PostStep)(BoundaryCondition *self, BCContext *ctx, PetscReal *local_inflow, PetscReal *local_outflow)
Definition variables.h:396
static PetscErrorCode ApplyInletAcrossFirstSteps(BoundaryCondition *bc, BCContext *ctx)
Reapplies a static inlet through the first three time-step contexts.
static PetscErrorCode WritePicSliceForTests(const char *path, PetscInt n1, PetscInt n2, PetscReal base)
Writes a tiny canonical PICSLICE profile for boundary handler tests.
PetscErrorCode PicurvAssertRealNear(PetscReal expected, PetscReal actual, PetscReal tol, const char *context)
Asserts that two real values agree within tolerance.
PetscErrorCode PicurvPopulateIdentityMetrics(UserCtx *user)
Populates identity metric vectors on the minimal grid fixture.
BCFace face_id
Definition variables.h:381
Provides execution context for a boundary condition handler.
Definition variables.h:379
A 3D point or vector with PetscScalar components.
Definition variables.h:144
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TestInletSourceAddsToPicSlice()

static PetscErrorCode TestInletSourceAddsToPicSlice ( void  )
static

Tests expressions added to a profile file: a bulk velocity scales the expressions and leaves the file's data as measured, as it does a generator's field in the interior.

Definition at line 448 of file test_boundaries.c.

449{
450 SimCtx *simCtx = NULL;
451 UserCtx *user = NULL;
452 BoundaryCondition *bc = NULL;
453 BCContext ctx;
454 Cmpnts ***ucont = NULL;
455 char profile_path[PETSC_MAX_PATH_LEN];
456
457 PetscFunctionBeginUser;
458 PetscCall(PetscMemzero(&ctx, sizeof(ctx)));
459 PetscCall(PicurvCreateMinimalContexts(&simCtx, &user, 5, 5, 5));
460 PetscCall(PicurvPopulateIdentityMetrics(user));
461 PetscCall(PetscSNPrintf(profile_path, sizeof(profile_path), "/tmp/picurv_unit_sum_%d.picslice", (int)getpid()));
462 PetscCall(WritePicSliceForTests(profile_path, user->JM - 1, user->IM - 1, 2.0));
463 PetscCall(ConfigureNormalSourceInlet(user, BC_FACE_NEG_Z, "1.0"));
464 PetscCall(AppendBCParam(&user->boundary_faces[BC_FACE_NEG_Z].params, "source_file", profile_path));
465 PetscCall(VecSet(user->Ucont, 0.0));
466 PetscCall(VecSet(user->Bcs.Ubcs, 0.0));
467 ctx.user = user;
470 PetscCall(bc->Initialize(bc, &ctx));
471 PetscCall(ApplyInletAcrossFirstSteps(bc, &ctx));
472 PetscCall(DMDAVecGetArrayRead(user->fda, user->Ucont, &ucont));
473 PetscCall(PicurvAssertRealNear(3.0, ucont[0][1][1].z, 1.0e-12, "the expression adds to the file's first speed"));
474 PetscCall(PicurvAssertRealNear(36.0, ucont[0][4][4].z, 1.0e-12, "the expression adds to the file's last speed"));
475 PetscCall(DMDAVecRestoreArrayRead(user->fda, user->Ucont, &ucont));
476 PetscCall(DestroyBoundaryHandler(&bc));
477
478 /* A bulk of the file's mean plus 2 asks the expression, of value 1, for a factor of 2. */
479 {
480 PetscReal mean = 0.0;
481 PetscInt slots = 0;
482 PetscCall(DMDAVecGetArrayRead(user->fda, user->Ucont, &ucont));
483 for (PetscInt j = 1; j < user->JM; ++j) for (PetscInt i = 1; i < user->IM; ++i) { mean += ucont[0][j][i].z - 1.0; ++slots; }
484 PetscCall(DMDAVecRestoreArrayRead(user->fda, user->Ucont, &ucont));
485 mean /= (PetscReal)slots;
486 char bulk[64];
487 PetscCall(PetscSNPrintf(bulk, sizeof(bulk), "%.17g", (double)(mean + 2.0)));
488 PetscCall(PetscOptionsSetValue(NULL, "-face_source_0_bulk_velocity", bulk));
489 }
490 PetscCall(VecSet(user->Ucont, 0.0));
492 PetscCall(bc->Initialize(bc, &ctx));
493 PetscCall(ApplyInletAcrossFirstSteps(bc, &ctx));
494 PetscCall(DMDAVecGetArrayRead(user->fda, user->Ucont, &ucont));
495 PetscCall(PicurvAssertRealNear(4.0, ucont[0][1][1].z, 1.0e-10, "a bulk velocity scales the expression, not the file"));
496 PetscCall(PicurvAssertRealNear(37.0, ucont[0][4][4].z, 1.0e-10, "the file's speeds keep their measured differences"));
497 PetscCall(DMDAVecRestoreArrayRead(user->fda, user->Ucont, &ucont));
498 PetscCall(DestroyBoundaryHandler(&bc));
499 PetscCall(PetscOptionsClearValue(NULL, "-face_source_0_bulk_velocity"));
500 PetscCall(PetscOptionsClearValue(NULL, "-face_source_0_frame"));
501 PetscCall(PetscOptionsClearValue(NULL, "-face_source_0_expr_0"));
503 user->boundary_faces[BC_FACE_NEG_Z].params = NULL;
504 remove(profile_path);
505 PetscCall(PicurvDestroyMinimalContexts(&simCtx, &user));
506 PetscFunctionReturn(0);
507}
static PetscErrorCode ConfigureNormalSourceInlet(UserCtx *user, BCFace face, const char *speed)
Configures face as a prescribed-velocity inlet with source 0 in the normal frame.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TestBoundaryConditionFactoryRejectsUnsupportedHandler()

static PetscErrorCode TestBoundaryConditionFactoryRejectsUnsupportedHandler ( void  )
static

Tests that unsupported handler types are rejected by the factory.

Definition at line 512 of file test_boundaries.c.

513{
514 BoundaryCondition *bc = NULL;
515 PetscErrorCode ierr_create;
516
517 PetscFunctionBeginUser;
518 PetscCall(PetscPushErrorHandler(PetscIgnoreErrorHandler, NULL));
520 PetscCall(PetscPopErrorHandler());
521
522 PetscCall(PicurvAssertBool((PetscBool)(ierr_create != 0), "unsupported handler should return a non-zero error code"));
523 if (bc) {
524 PetscCall(PetscFree(bc));
525 }
526 PetscFunctionReturn(0);
527}
@ BC_HANDLER_OUTLET_PRESSURE
Definition variables.h:351
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TestInletNormalSourceBehavior()

static PetscErrorCode TestInletNormalSourceBehavior ( void  )
static

Tests a constant normal-speed source's face writes and flux on a Z inlet.

Definition at line 532 of file test_boundaries.c.

533{
534 SimCtx *simCtx = NULL;
535 UserCtx *user = NULL;
536 BoundaryCondition *bc = NULL;
537 BCContext ctx;
538 Cmpnts ***ucont = NULL;
539 Cmpnts ***ubcs = NULL;
540 PetscReal local_inflow = 0.0;
541 PetscReal local_outflow = 0.0;
542 PetscReal expected_flux = 0.0;
543
544 PetscFunctionBeginUser;
545 PetscCall(PetscMemzero(&ctx, sizeof(ctx)));
546 PetscCall(PicurvCreateMinimalContexts(&simCtx, &user, 6, 6, 6));
547 PetscCall(VecSet(user->Ucont, 0.0));
548 PetscCall(VecSet(user->Bcs.Ubcs, 0.0));
549 PetscCall(PicurvPopulateIdentityMetrics(user));
550
551 PetscCall(ConfigureNormalSourceInlet(user, BC_FACE_NEG_Z, "2.5"));
552
553 ctx.user = user;
556 PetscCall(bc->Initialize(bc, &ctx));
557 PetscCall(ApplyInletAcrossFirstSteps(bc, &ctx));
558 PetscCall(bc->PostStep(bc, &ctx, &local_inflow, &local_outflow));
559
560 PetscCall(DMDAVecGetArrayRead(user->fda, user->Ucont, &ucont));
561 PetscCall(DMDAVecGetArrayRead(user->fda, user->Bcs.Ubcs, &ubcs));
562 PetscCall(PicurvAssertRealNear(2.5, ucont[0][3][3].z, 1.0e-12, "constant inlet should set Ucont normal component"));
563 PetscCall(PicurvAssertRealNear(2.5, ubcs[0][3][3].z, 1.0e-12, "constant inlet should set Ubcs normal component"));
564 PetscCall(DMDAVecRestoreArrayRead(user->fda, user->Ucont, &ucont));
565 PetscCall(DMDAVecRestoreArrayRead(user->fda, user->Bcs.Ubcs, &ubcs));
566
567 expected_flux = (PetscReal)(user->info.mx - 2) * (PetscReal)(user->info.my - 2) * 2.5;
568 PetscCall(PicurvAssertRealNear(expected_flux, local_inflow, 1.0e-12, "constant inlet PostStep should sum the face flux"));
569 PetscCall(PicurvAssertRealNear(0.0, local_outflow, 1.0e-12, "constant inlet should not contribute to outflow accumulation"));
570
571 PetscCall(DestroyBoundaryHandler(&bc));
573 user->boundary_faces[BC_FACE_NEG_Z].params = NULL;
574 PetscCall(PicurvDestroyMinimalContexts(&simCtx, &user));
575 PetscFunctionReturn(0);
576}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TestInletCommonApplicationCurvilinearMetric()

static PetscErrorCode TestInletCommonApplicationCurvilinearMetric ( void  )
static

Verifies curvilinear projection and Cartesian dummy reflection for the shared inlet path.

Definition at line 581 of file test_boundaries.c.

582{
583 SimCtx *simCtx = NULL;
584 UserCtx *user = NULL;
585 BoundaryCondition *bc = NULL;
586 BCContext ctx;
587 Cmpnts ***zet = NULL, ***ucont = NULL, ***ubcs = NULL, ***ucat = NULL;
588
589 PetscFunctionBeginUser;
590 PetscCall(PetscMemzero(&ctx, sizeof(ctx)));
591 PetscCall(PicurvCreateMinimalContexts(&simCtx, &user, 6, 6, 6));
592 PetscCall(PicurvPopulateIdentityMetrics(user));
593 PetscCall(DMDAVecGetArray(user->fda, user->lZet, &zet));
594 zet[0][3][3].x = 0.0;
595 zet[0][3][3].y = 3.0;
596 zet[0][3][3].z = 4.0;
597 PetscCall(DMDAVecRestoreArray(user->fda, user->lZet, &zet));
598
599 PetscCall(ConfigureNormalSourceInlet(user, BC_FACE_NEG_Z, "2.0"));
600 ctx.user = user;
603 PetscCall(bc->Initialize(bc, &ctx));
604 PetscCall(ApplyInletAcrossFirstSteps(bc, &ctx));
605
606 PetscCall(DMDAVecGetArrayRead(user->fda, user->Ucont, &ucont));
607 PetscCall(DMDAVecGetArrayRead(user->fda, user->Bcs.Ubcs, &ubcs));
608 PetscCall(PicurvAssertRealNear(10.0, ucont[0][3][3].z, 1.0e-12,
609 "Ucont should be the Cartesian inlet velocity dotted with the face metric"));
610 PetscCall(PicurvAssertRealNear(0.0, ubcs[0][3][3].x, 1.0e-12,
611 "curvilinear normal velocity should preserve its Cartesian x component"));
612 PetscCall(PicurvAssertRealNear(1.2, ubcs[0][3][3].y, 1.0e-12,
613 "curvilinear normal velocity should include Cartesian y"));
614 PetscCall(PicurvAssertRealNear(1.6, ubcs[0][3][3].z, 1.0e-12,
615 "curvilinear normal velocity should include Cartesian z"));
616 PetscCall(DMDAVecRestoreArrayRead(user->fda, user->Ucont, &ucont));
617 PetscCall(DMDAVecRestoreArrayRead(user->fda, user->Bcs.Ubcs, &ubcs));
618
619 PetscCall(VecSet(user->Ucat, 1.0));
620 PetscCall(UpdateDummyCells(user, FIELD_ID_UCAT));
621 PetscCall(DMDAVecGetArrayRead(user->fda, user->Ucat, &ucat));
622 PetscCall(PicurvAssertRealNear(-1.0, ucat[0][3][3].x, 1.0e-12,
623 "dummy reflection should act on Cartesian x"));
624 PetscCall(PicurvAssertRealNear(1.4, ucat[0][3][3].y, 1.0e-12,
625 "dummy reflection should act on Cartesian y"));
626 PetscCall(PicurvAssertRealNear(2.2, ucat[0][3][3].z, 1.0e-12,
627 "dummy reflection should act on Cartesian z"));
628 PetscCall(PicurvAssertRealNear(1.0, ucat[1][3][3].y, 1.0e-12,
629 "dummy reflection should not overwrite the adjacent interior value"));
630 PetscCall(DMDAVecRestoreArrayRead(user->fda, user->Ucat, &ucat));
631
632 PetscCall(DestroyBoundaryHandler(&bc));
634 PetscCall(PicurvDestroyMinimalContexts(&simCtx, &user));
635 PetscFunctionReturn(0);
636}
PetscErrorCode UpdateDummyCells(UserCtx *user, FieldId field_id)
Fills the dummy cells on the non-periodic faces of one cell-centred field.
@ FIELD_ID_UCAT
static void ResetBoundaryFaceConfig(BoundaryFaceConfig *cfg)
Resets one boundary-face configuration entry to a neutral test-local baseline.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TestWallNoSlipHandlerFaceMatrix()

static PetscErrorCode TestWallNoSlipHandlerFaceMatrix ( void  )
static

Tests wall no-slip application across the full face matrix.

Definition at line 641 of file test_boundaries.c.

642{
643 SimCtx *simCtx = NULL;
644 UserCtx *user = NULL;
645 BoundaryCondition *bc = NULL;
646 BCContext ctx;
647 Cmpnts ***ucont = NULL;
648 Cmpnts ***ubcs = NULL;
649 const BCFace faces[] = {
653 };
654
655 PetscFunctionBeginUser;
656 PetscCall(PetscMemzero(&ctx, sizeof(ctx)));
657 PetscCall(PicurvCreateMinimalContexts(&simCtx, &user, 6, 6, 6));
659
660 for (size_t n = 0; n < sizeof(faces) / sizeof(faces[0]); ++n) {
661 const BCFace face = faces[n];
662 PetscInt ucont_k, ucont_j, ucont_i, ubcs_k, ubcs_j, ubcs_i;
663
664 PetscCall(VecSet(user->Ucont, 5.0));
665 PetscCall(VecSet(user->Bcs.Ubcs, 7.0));
666 ctx.user = user;
667 ctx.face_id = face;
668 PetscCall(bc->Apply(bc, &ctx));
669
670 PetscCall(GetRepresentativeFaceSlots(user, face, &ucont_k, &ucont_j, &ucont_i, &ubcs_k, &ubcs_j, &ubcs_i));
671 PetscCall(DMDAVecGetArrayRead(user->fda, user->Ucont, &ucont));
672 PetscCall(DMDAVecGetArrayRead(user->fda, user->Bcs.Ubcs, &ubcs));
673 PetscCall(PicurvAssertRealNear(0.0, GetFaceNormalComponent(ucont[ucont_k][ucont_j][ucont_i], face), 1.0e-12, "wall no-slip should zero the normal flux component"));
674 PetscCall(PicurvAssertRealNear(0.0, ubcs[ubcs_k][ubcs_j][ubcs_i].x, 1.0e-12, "wall no-slip should zero Ubcs.x"));
675 PetscCall(PicurvAssertRealNear(0.0, ubcs[ubcs_k][ubcs_j][ubcs_i].y, 1.0e-12, "wall no-slip should zero Ubcs.y"));
676 PetscCall(PicurvAssertRealNear(0.0, ubcs[ubcs_k][ubcs_j][ubcs_i].z, 1.0e-12, "wall no-slip should zero Ubcs.z"));
677 PetscCall(DMDAVecRestoreArrayRead(user->fda, user->Ucont, &ucont));
678 PetscCall(DMDAVecRestoreArrayRead(user->fda, user->Bcs.Ubcs, &ubcs));
679 }
680
681 PetscCall(DestroyBoundaryHandler(&bc));
682 PetscCall(PicurvDestroyMinimalContexts(&simCtx, &user));
683 PetscFunctionReturn(0);
684}
static PetscReal GetFaceNormalComponent(Cmpnts value, BCFace face)
Extracts the velocity component aligned with the supplied boundary-face normal.
static PetscErrorCode GetRepresentativeFaceSlots(const UserCtx *user, BCFace face, PetscInt *ucont_k, PetscInt *ucont_j, PetscInt *ucont_i, PetscInt *ubcs_k, PetscInt *ubcs_j, PetscInt *ubcs_i)
Selects representative Ucont and Ubcs slots for face-matrix assertions.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetUniformCartesian()

static PetscErrorCode SetUniformCartesian ( Vec  v,
PetscReal  x,
PetscReal  y,
PetscReal  z 
)
static

Sets every entry of a three-component vector to one Cartesian value.

Definition at line 687 of file test_boundaries.c.

688{
689 PetscFunctionBeginUser;
690 PetscCall(VecStrideSet(v, 0, x));
691 PetscCall(VecStrideSet(v, 1, y));
692 PetscCall(VecStrideSet(v, 2, z));
693 PetscFunctionReturn(0);
694}
Here is the caller graph for this function:

◆ TestWallFreeSlipHandlerFaceMatrix()

static PetscErrorCode TestWallFreeSlipHandlerFaceMatrix ( void  )
static

Tests the free-slip wall across the full face matrix on a Cartesian grid.

With an adjacent velocity of (1, 2, 3) the boundary value is that velocity less its component normal to the face, the normal flux vanishes, and the dummy cell mirrors the interior: the normal component reversed, the tangential ones kept. That mirror is the symmetry-plane condition.

Definition at line 704 of file test_boundaries.c.

705{
706 SimCtx *simCtx = NULL;
707 UserCtx *user = NULL;
708 BoundaryCondition *bc = NULL;
709 BCContext ctx;
710 Cmpnts ***ucont = NULL, ***ubcs = NULL, ***ucat = NULL;
713 const PetscReal interior[3] = {1.0, 2.0, 3.0};
714
715 PetscFunctionBeginUser;
716 PetscCall(PetscMemzero(&ctx, sizeof(ctx)));
717 PetscCall(PicurvCreateMinimalContexts(&simCtx, &user, 6, 6, 6));
718 PetscCall(PicurvPopulateIdentityMetrics(user));
720 PetscCall(PicurvAssertBool((PetscBool)(bc->UpdateUbcs != NULL),
721 "a free-slip wall refreshes its boundary value with the flow"));
722
723 for (size_t n = 0; n < sizeof(faces) / sizeof(faces[0]); ++n) {
724 const BCFace face = faces[n];
725 const PetscInt axis = (PetscInt)face / 2;
726 PetscInt ucont_k, ucont_j, ucont_i, ubcs_k, ubcs_j, ubcs_i;
727
728 for (PetscInt f = 0; f < 6; ++f) user->boundary_faces[f].mathematical_type = WALL;
729 PetscCall(VecSet(user->Ucont, 5.0));
730 PetscCall(VecSet(user->Bcs.Ubcs, 7.0));
731 PetscCall(SetUniformCartesian(user->Ucat, interior[0], interior[1], interior[2]));
732 PetscCall(SetUniformCartesian(user->lUcat, interior[0], interior[1], interior[2]));
733 ctx.user = user;
734 ctx.face_id = face;
735 PetscCall(bc->Apply(bc, &ctx));
736 PetscCall(UpdateDummyCells(user, FIELD_ID_UCAT));
737
738 PetscCall(GetRepresentativeFaceSlots(user, face, &ucont_k, &ucont_j, &ucont_i, &ubcs_k, &ubcs_j, &ubcs_i));
739 PetscCall(DMDAVecGetArrayRead(user->fda, user->Ucont, &ucont));
740 PetscCall(DMDAVecGetArrayRead(user->fda, user->Bcs.Ubcs, &ubcs));
741 PetscCall(DMDAVecGetArrayRead(user->fda, user->Ucat, &ucat));
742 PetscCall(PicurvAssertRealNear(0.0, GetFaceNormalComponent(ucont[ucont_k][ucont_j][ucont_i], face), 1.0e-12,
743 "a free-slip wall closes the face"));
744 for (PetscInt c = 0; c < 3; ++c) {
745 const PetscReal boundary = (&ubcs[ubcs_k][ubcs_j][ubcs_i].x)[c];
746 const PetscReal dummy = (&ucat[ubcs_k][ubcs_j][ubcs_i].x)[c];
747
748 PetscCall(PicurvAssertRealNear(c == axis ? 0.0 : interior[c], boundary, 1.0e-12,
749 "the boundary value is the adjacent velocity less its normal part"));
750 PetscCall(PicurvAssertRealNear(c == axis ? -interior[c] : interior[c], dummy, 1.0e-12,
751 "the dummy cell is the mirror image of the interior one"));
752 }
753 PetscCall(DMDAVecRestoreArrayRead(user->fda, user->Ucat, &ucat));
754 PetscCall(DMDAVecRestoreArrayRead(user->fda, user->Bcs.Ubcs, &ubcs));
755 PetscCall(DMDAVecRestoreArrayRead(user->fda, user->Ucont, &ucont));
756 }
757
758 PetscCall(DestroyBoundaryHandler(&bc));
759 PetscCall(PicurvDestroyMinimalContexts(&simCtx, &user));
760 PetscFunctionReturn(0);
761}
PetscErrorCode(* UpdateUbcs)(BoundaryCondition *self, BCContext *ctx)
Definition variables.h:397
static PetscErrorCode SetUniformCartesian(Vec v, PetscReal x, PetscReal y, PetscReal z)
Sets every entry of a three-component vector to one Cartesian value.
@ WALL
Definition variables.h:319
Vec lUcat
Definition variables.h:1197
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TestWallFreeSlipCurvilinearNormal()

static PetscErrorCode TestWallFreeSlipCurvilinearNormal ( void  )
static

Tests the free-slip wall against a face whose normal is not a grid axis.

The -Zeta face metric is (0, 3, 4), so the unit normal is (0, 0.6, 0.8). An adjacent velocity (1, 1, 1) has normal part 1.4 along it, leaving (1, 0.16, -0.12), whose flux through the face is zero.

Definition at line 770 of file test_boundaries.c.

771{
772 SimCtx *simCtx = NULL;
773 UserCtx *user = NULL;
774 BoundaryCondition *bc = NULL;
775 BCContext ctx;
776 Cmpnts ***zet = NULL, ***ucont = NULL, ***ubcs = NULL;
777
778 PetscFunctionBeginUser;
779 PetscCall(PetscMemzero(&ctx, sizeof(ctx)));
780 PetscCall(PicurvCreateMinimalContexts(&simCtx, &user, 6, 6, 6));
781 PetscCall(PicurvPopulateIdentityMetrics(user));
782 PetscCall(DMDAVecGetArray(user->fda, user->lZet, &zet));
783 zet[0][3][3].x = 0.0;
784 zet[0][3][3].y = 3.0;
785 zet[0][3][3].z = 4.0;
786 PetscCall(DMDAVecRestoreArray(user->fda, user->lZet, &zet));
787 PetscCall(SetUniformCartesian(user->lUcat, 1.0, 1.0, 1.0));
789 ctx.user = user;
791 PetscCall(bc->Apply(bc, &ctx));
792
793 PetscCall(DMDAVecGetArrayRead(user->fda, user->Ucont, &ucont));
794 PetscCall(DMDAVecGetArrayRead(user->fda, user->Bcs.Ubcs, &ubcs));
795 PetscCall(PicurvAssertRealNear(0.0, ucont[0][3][3].z, 1.0e-12, "no flux through a tilted free-slip face"));
796 PetscCall(PicurvAssertRealNear(1.0, ubcs[0][3][3].x, 1.0e-12, "the tangential x component is kept"));
797 PetscCall(PicurvAssertRealNear(0.16, ubcs[0][3][3].y, 1.0e-12, "the normal part is removed from y"));
798 PetscCall(PicurvAssertRealNear(-0.12, ubcs[0][3][3].z, 1.0e-12, "the normal part is removed from z"));
799 PetscCall(DMDAVecRestoreArrayRead(user->fda, user->Bcs.Ubcs, &ubcs));
800 PetscCall(DMDAVecRestoreArrayRead(user->fda, user->Ucont, &ucont));
801
802 PetscCall(DestroyBoundaryHandler(&bc));
803 PetscCall(PicurvDestroyMinimalContexts(&simCtx, &user));
804 PetscFunctionReturn(0);
805}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TestFreeSlipWallExertsNoShear()

static PetscErrorCode TestFreeSlipWallExertsNoShear ( void  )
static

Tests which faces exert shear, and that only a free-slip wall mirrors the eddy viscosity.

Definition at line 810 of file test_boundaries.c.

811{
812 SimCtx *simCtx = NULL;
813 UserCtx *user = NULL;
814 PetscReal ***nu_t = NULL;
815 const PetscInt mid = 3;
816
817 PetscFunctionBeginUser;
818 PetscCall(PicurvCreateMinimalContexts(&simCtx, &user, 6, 6, 6));
826 "a no-slip wall exerts shear"));
828 "a free-slip wall exerts none"));
830 "an inlet is not a wall"));
831
832 /* The minimal context carries no turbulence storage; this test owns its Nu_t. */
833 PetscCall(DMCreateGlobalVector(user->da, &user->Nu_t));
834 PetscCall(DMCreateLocalVector(user->da, &user->lNu_t));
835 PetscCall(VecSet(user->Nu_t, 0.0));
836 PetscCall(DMDAVecGetArray(user->da, user->Nu_t, &nu_t));
837 for (PetscInt k = user->info.zs; k < user->info.zs + user->info.zm; ++k)
838 for (PetscInt j = user->info.ys; j < user->info.ys + user->info.ym; ++j)
839 for (PetscInt i = 1; i < user->info.mx - 1; ++i) nu_t[k][j][i] = 0.01 * i;
840 PetscCall(DMDAVecRestoreArray(user->da, user->Nu_t, &nu_t));
841 PetscCall(UpdateDummyCells(user, FIELD_ID_NU_T));
842 PetscCall(DMDAVecGetArrayRead(user->da, user->Nu_t, &nu_t));
843 PetscCall(PicurvAssertRealNear(0.01 * (user->info.mx - 2), nu_t[mid][mid][user->info.mx - 1], 0.0,
844 "the eddy viscosity mirrors across a free-slip wall"));
845 PetscCall(PicurvAssertRealNear(0.0, nu_t[mid][mid][0], 0.0,
846 "a no-slip wall replaces the face value, so its dummy is not written"));
847 PetscCall(DMDAVecRestoreArrayRead(user->da, user->Nu_t, &nu_t));
848 PetscCall(VecDestroy(&user->Nu_t));
849 PetscCall(VecDestroy(&user->lNu_t));
850 PetscCall(PicurvDestroyMinimalContexts(&simCtx, &user));
851 PetscFunctionReturn(0);
852}
PetscBool BoundaryFaceHasWallShear(const BoundaryFaceConfig *face)
Reports whether a boundary face is a wall that exerts shear on the flow.
Definition Boundaries.c:9
@ FIELD_ID_NU_T
Vec lNu_t
Definition variables.h:1259
double nu_t(double yplus)
Computes turbulent eddy viscosity ratio (ν_t / ν)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TestInletNormalSourceFaceMatrix()

static PetscErrorCode TestInletNormalSourceFaceMatrix ( void  )
static

Tests a constant normal-speed source's flux accounting and face writes across all faces.

Definition at line 857 of file test_boundaries.c.

858{
859 struct ConstantInletCase {
860 BCFace face;
861 PetscReal velocity;
862 const char *value_text;
863 };
864 const struct ConstantInletCase cases[] = {
865 {BC_FACE_NEG_X, 1.5, "1.5"},
866 {BC_FACE_POS_X, 2.0, "2.0"},
867 {BC_FACE_NEG_Y, 2.5, "2.5"},
868 {BC_FACE_POS_Y, 3.0, "3.0"},
869 {BC_FACE_NEG_Z, 3.5, "3.5"},
870 {BC_FACE_POS_Z, 4.0, "4.0"},
871 };
872 SimCtx *simCtx = NULL;
873 UserCtx *user = NULL;
874 BCContext ctx;
875 Cmpnts ***ucont = NULL;
876 Cmpnts ***ubcs = NULL;
877
878 PetscFunctionBeginUser;
879 PetscCall(PetscMemzero(&ctx, sizeof(ctx)));
880 PetscCall(PicurvCreateMinimalContexts(&simCtx, &user, 6, 6, 6));
881 PetscCall(PicurvPopulateIdentityMetrics(user));
882
883 for (size_t n = 0; n < sizeof(cases) / sizeof(cases[0]); ++n) {
884 const struct ConstantInletCase *test_case = &cases[n];
885 BoundaryCondition *bc = NULL;
886 PetscReal local_inflow = 0.0;
887 PetscReal local_outflow = 0.0;
888 PetscInt ucont_k, ucont_j, ucont_i, ubcs_k, ubcs_j, ubcs_i;
889 const PetscReal expected_value = GetFaceOrientationSign(test_case->face) * test_case->velocity;
890 const PetscReal expected_flux = GetFaceInteriorPointCount(user, test_case->face) * expected_value;
891
892 PetscCall(VecSet(user->Ucont, 0.0));
893 PetscCall(VecSet(user->Bcs.Ubcs, 0.0));
894 ResetBoundaryFaceConfig(&user->boundary_faces[test_case->face]);
895 PetscCall(ConfigureNormalSourceInlet(user, test_case->face, test_case->value_text));
896
897 ctx.user = user;
898 ctx.face_id = test_case->face;
900 PetscCall(bc->Initialize(bc, &ctx));
901 PetscCall(bc->PreStep(bc, &ctx, &local_inflow, &local_outflow));
902 PetscCall(PicurvAssertRealNear(0.0, local_inflow, 1.0e-12, "constant inlet PreStep should leave inflow unchanged"));
903 PetscCall(PicurvAssertRealNear(0.0, local_outflow, 1.0e-12, "constant inlet PreStep should leave outflow unchanged"));
904 PetscCall(bc->Apply(bc, &ctx));
905 PetscCall(bc->PostStep(bc, &ctx, &local_inflow, &local_outflow));
906
907 PetscCall(GetRepresentativeFaceSlots(user, test_case->face, &ucont_k, &ucont_j, &ucont_i, &ubcs_k, &ubcs_j, &ubcs_i));
908 PetscCall(DMDAVecGetArrayRead(user->fda, user->Ucont, &ucont));
909 PetscCall(DMDAVecGetArrayRead(user->fda, user->Bcs.Ubcs, &ubcs));
910 PetscCall(PicurvAssertRealNear(expected_value, GetFaceNormalComponent(ucont[ucont_k][ucont_j][ucont_i], test_case->face), 1.0e-12, "constant inlet should set the face-normal Ucont component"));
911 PetscCall(PicurvAssertRealNear(expected_value, GetFaceNormalComponent(ubcs[ubcs_k][ubcs_j][ubcs_i], test_case->face), 1.0e-12, "constant inlet should set the face-normal Ubcs component"));
912 PetscCall(PicurvAssertRealNear((test_case->face == BC_FACE_NEG_X || test_case->face == BC_FACE_POS_X) ? expected_value : 0.0, ubcs[ubcs_k][ubcs_j][ubcs_i].x, 1.0e-12, "constant inlet should only set the expected Ubcs axis"));
913 PetscCall(PicurvAssertRealNear((test_case->face == BC_FACE_NEG_Y || test_case->face == BC_FACE_POS_Y) ? expected_value : 0.0, ubcs[ubcs_k][ubcs_j][ubcs_i].y, 1.0e-12, "constant inlet should only set the expected Ubcs axis"));
914 PetscCall(PicurvAssertRealNear((test_case->face == BC_FACE_NEG_Z || test_case->face == BC_FACE_POS_Z) ? expected_value : 0.0, ubcs[ubcs_k][ubcs_j][ubcs_i].z, 1.0e-12, "constant inlet should only set the expected Ubcs axis"));
915 PetscCall(DMDAVecRestoreArrayRead(user->fda, user->Ucont, &ucont));
916 PetscCall(DMDAVecRestoreArrayRead(user->fda, user->Bcs.Ubcs, &ubcs));
917 PetscCall(PicurvAssertRealNear(expected_flux, local_inflow, 1.0e-12, "constant inlet PostStep should integrate the face flux with orientation"));
918 PetscCall(PicurvAssertRealNear(0.0, local_outflow, 1.0e-12, "constant inlet should not add to outflow"));
919
920 PetscCall(DestroyBoundaryHandler(&bc));
921 ResetBoundaryFaceConfig(&user->boundary_faces[test_case->face]);
922 }
923
924 PetscCall(PicurvDestroyMinimalContexts(&simCtx, &user));
925 PetscFunctionReturn(0);
926}
static PetscReal GetFaceInteriorPointCount(const UserCtx *user, BCFace face)
Computes the number of face-interior sample points for a given boundary face.
static PetscReal GetFaceOrientationSign(BCFace face)
Returns the sign convention used for face-normal flux expectations.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TestInletParabolicSourceBehavior()

static PetscErrorCode TestInletParabolicSourceBehavior ( void  )
static

Tests a parabola written in the arc-length fractions on a tiny Z-face.

Definition at line 931 of file test_boundaries.c.

932{
933 SimCtx *simCtx = NULL;
934 UserCtx *user = NULL;
935 BoundaryCondition *bc = NULL;
936 BCContext ctx;
937 Cmpnts ***ucont = NULL;
938
939 PetscFunctionBeginUser;
940 PetscCall(PetscMemzero(&ctx, sizeof(ctx)));
941 PetscCall(PicurvCreateMinimalContexts(&simCtx, &user, 6, 6, 6));
942 PetscCall(PicurvPopulateIdentityMetrics(user));
943
944 PetscCall(ConfigureNormalSourceInlet(user, BC_FACE_NEG_Z, "16*4.0*xi*(1-xi)*eta*(1-eta)"));
945
946 ctx.user = user;
949 PetscCall(bc->Initialize(bc, &ctx));
950 PetscCall(ApplyInletAcrossFirstSteps(bc, &ctx));
951
952 PetscCall(DMDAVecGetArrayRead(user->fda, user->Ucont, &ucont));
953 PetscCall(PicurvAssertRealNear(4.0, ucont[0][3][3].z, 1.0e-12, "parabolic inlet should peak at the face centerline"));
954 /* Five cells per axis: the wall-adjacent centre sits at xi = 0.1, so each factor is 0.36. */
955 PetscCall(PicurvAssertRealNear(4.0 * 0.36 * 0.36, ucont[0][1][1].z, 1.0e-12,
956 "parabolic inlet should vanish on the wall, not at the wall-adjacent centre"));
957 PetscCall(PicurvAssertBool((PetscBool)(ucont[0][3][3].z > ucont[0][2][2].z), "parabolic inlet centerline should exceed off-center velocity"));
958 PetscCall(DMDAVecRestoreArrayRead(user->fda, user->Ucont, &ucont));
959
960 PetscCall(DestroyBoundaryHandler(&bc));
962 user->boundary_faces[BC_FACE_NEG_Z].params = NULL;
963 PetscCall(PicurvDestroyMinimalContexts(&simCtx, &user));
964 PetscFunctionReturn(0);
965}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TestInletOneAxisSourceIsUniformAlongTheOther()

static PetscErrorCode TestInletOneAxisSourceIsUniformAlongTheOther ( void  )
static

Tests that a profile in one fraction is uniform along the other tangential axis.

A channel periodic in i has walls only in j, so its inlet is the parabola in eta.

Definition at line 971 of file test_boundaries.c.

972{
973 SimCtx *simCtx = NULL;
974 UserCtx *user = NULL;
975 BoundaryCondition *bc = NULL;
976 BCContext ctx;
977 Cmpnts ***ucont = NULL;
978
979 PetscFunctionBeginUser;
980 PetscCall(PetscMemzero(&ctx, sizeof(ctx)));
981 PetscCall(PicurvCreateMinimalContexts(&simCtx, &user, 6, 6, 6));
982 PetscCall(PicurvPopulateIdentityMetrics(user));
983 PetscCall(ConfigureNormalSourceInlet(user, BC_FACE_NEG_Z, "4*4.0*eta*(1-eta)"));
984 ctx.user = user;
987 PetscCall(bc->Initialize(bc, &ctx));
988 PetscCall(ApplyInletAcrossFirstSteps(bc, &ctx));
989
990 PetscCall(DMDAVecGetArrayRead(user->fda, user->Ucont, &ucont));
991 PetscCall(PicurvAssertRealNear(4.0, ucont[0][3][1].z, 1.0e-12, "the xi axis carries no parabola factor"));
992 PetscCall(PicurvAssertRealNear(ucont[0][3][1].z, ucont[0][3][4].z, 1.0e-12, "profile is uniform along xi"));
993 PetscCall(PicurvAssertRealNear(4.0 * 0.36, ucont[0][1][3].z, 1.0e-12, "wall-bounded axis keeps its parabola"));
994 PetscCall(DMDAVecRestoreArrayRead(user->fda, user->Ucont, &ucont));
995
996 PetscCall(DestroyBoundaryHandler(&bc));
998 user->boundary_faces[BC_FACE_NEG_Z].params = NULL;
999 PetscCall(PicurvDestroyMinimalContexts(&simCtx, &user));
1000 PetscFunctionReturn(0);
1001}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TestInletParabolicSourceFaceMatrix()

static PetscErrorCode TestInletParabolicSourceFaceMatrix ( void  )
static

Tests a parabola in each face's two tangential fractions across all faces: its centreline, wall-adjacent value, and flux.

Definition at line 1007 of file test_boundaries.c.

1008{
1009 const BCFace faces[] = {
1013 };
1014 SimCtx *simCtx = NULL;
1015 UserCtx *user = NULL;
1016 BCContext ctx;
1017 Cmpnts ***ucont = NULL;
1018 Cmpnts ***ubcs = NULL;
1019
1020 PetscFunctionBeginUser;
1021 PetscCall(PetscMemzero(&ctx, sizeof(ctx)));
1022 PetscCall(PicurvCreateMinimalContexts(&simCtx, &user, 6, 6, 6));
1023 PetscCall(PicurvPopulateIdentityMetrics(user));
1024
1025 for (size_t n = 0; n < sizeof(faces) / sizeof(faces[0]); ++n) {
1026 const BCFace face = faces[n];
1027 BoundaryCondition *bc = NULL;
1028 PetscReal local_inflow = 0.0;
1029 PetscReal local_outflow = 0.0;
1030 PetscInt center_k, center_j, center_i;
1031 PetscInt off_k, off_j, off_i;
1032 PetscInt wall_k, wall_j, wall_i;
1033 PetscInt ubcs_center_k, ubcs_center_j, ubcs_center_i;
1034 const PetscReal expected_center = GetFaceOrientationSign(face) * 4.0;
1035
1036 PetscCall(VecSet(user->Ucont, 0.0));
1037 PetscCall(VecSet(user->Bcs.Ubcs, 0.0));
1039 const char *profile = (face == BC_FACE_NEG_X || face == BC_FACE_POS_X) ? "16*4.0*eta*(1-eta)*zeta*(1-zeta)"
1040 : (face == BC_FACE_NEG_Y || face == BC_FACE_POS_Y) ? "16*4.0*xi*(1-xi)*zeta*(1-zeta)"
1041 : "16*4.0*xi*(1-xi)*eta*(1-eta)";
1042 PetscCall(ConfigureNormalSourceInlet(user, face, profile));
1043
1044 ctx.user = user;
1045 ctx.face_id = face;
1047 PetscCall(bc->Initialize(bc, &ctx));
1048 PetscCall(bc->PreStep(bc, &ctx, &local_inflow, &local_outflow));
1049 PetscCall(PicurvAssertRealNear(0.0, local_inflow, 1.0e-12, "parabolic inlet PreStep should leave inflow unchanged"));
1050 PetscCall(PicurvAssertRealNear(0.0, local_outflow, 1.0e-12, "parabolic inlet PreStep should leave outflow unchanged"));
1051 PetscCall(bc->Apply(bc, &ctx));
1052 PetscCall(bc->PostStep(bc, &ctx, &local_inflow, &local_outflow));
1053
1054 PetscCall(GetParabolicSampleSlots(user, face,
1055 &center_k, &center_j, &center_i,
1056 &off_k, &off_j, &off_i,
1057 &wall_k, &wall_j, &wall_i,
1058 &ubcs_center_k, &ubcs_center_j, &ubcs_center_i));
1059 PetscCall(DMDAVecGetArrayRead(user->fda, user->Ucont, &ucont));
1060 PetscCall(DMDAVecGetArrayRead(user->fda, user->Bcs.Ubcs, &ubcs));
1061 PetscCall(PicurvAssertRealNear(expected_center, GetFaceNormalComponent(ucont[center_k][center_j][center_i], face), 1.0e-12, "parabolic inlet should peak at the face centerline"));
1062 PetscCall(PicurvAssertRealNear(expected_center, GetFaceNormalComponent(ubcs[ubcs_center_k][ubcs_center_j][ubcs_center_i], face), 1.0e-12, "parabolic inlet should write the centerline boundary velocity"));
1063 PetscCall(PicurvAssertRealNear(expected_center * 0.36 * 0.36, GetFaceNormalComponent(ucont[wall_k][wall_j][wall_i], face), 1.0e-12,
1064 "parabolic inlet should take its wall-adjacent value, vanishing only on the wall"));
1065 PetscCall(PicurvAssertBool((PetscBool)(PetscAbsReal(GetFaceNormalComponent(ucont[center_k][center_j][center_i], face)) >
1066 PetscAbsReal(GetFaceNormalComponent(ucont[off_k][off_j][off_i], face))),
1067 "parabolic inlet centerline magnitude should exceed the off-center magnitude"));
1068 PetscCall(DMDAVecRestoreArrayRead(user->fda, user->Ucont, &ucont));
1069 PetscCall(DMDAVecRestoreArrayRead(user->fda, user->Bcs.Ubcs, &ubcs));
1070 PetscCall(PicurvAssertBool((PetscBool)(PetscAbsReal(local_inflow) > 0.0), "parabolic inlet PostStep should accumulate a non-zero flux"));
1071 PetscCall(PicurvAssertBool((PetscBool)((local_inflow > 0.0) == (GetFaceOrientationSign(face) > 0.0)),
1072 "parabolic inlet PostStep should preserve the face orientation"));
1073 PetscCall(PicurvAssertRealNear(0.0, local_outflow, 1.0e-12, "parabolic inlet should not add to outflow"));
1074
1075 PetscCall(DestroyBoundaryHandler(&bc));
1077 }
1078
1079 PetscCall(PicurvDestroyMinimalContexts(&simCtx, &user));
1080 PetscFunctionReturn(0);
1081}
static PetscErrorCode GetParabolicSampleSlots(const UserCtx *user, BCFace face, PetscInt *center_k, PetscInt *center_j, PetscInt *center_i, PetscInt *off_k, PetscInt *off_j, PetscInt *off_i, PetscInt *wall_k, PetscInt *wall_j, PetscInt *wall_i, PetscInt *ubcs_center_k, PetscInt *ubcs_center_j, PetscInt *ubcs_center_i)
Selects center, off-center, and wall-adjacent slots for parabolic-face checks.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TestInletSourceFollowsTimeAndBulkVelocity()

static PetscErrorCode TestInletSourceFollowsTimeAndBulkVelocity ( void  )
static

Tests that a source in t is re-evaluated once per step, and that a bulk velocity rescales the face to its target mean normal speed each step.

Definition at line 1086 of file test_boundaries.c.

1087{
1088 SimCtx *simCtx = NULL;
1089 UserCtx *user = NULL;
1090 BoundaryCondition *bc = NULL;
1091 BCContext ctx;
1092 Cmpnts ***ucont = NULL;
1093 PetscReal local_inflow = 0.0, local_outflow = 0.0, physical_time = 0.0;
1094
1095 PetscFunctionBeginUser;
1096 PetscCall(PetscMemzero(&ctx, sizeof(ctx)));
1097 PetscCall(PicurvCreateMinimalContexts(&simCtx, &user, 6, 6, 6));
1098 PetscCall(PicurvPopulateIdentityMetrics(user));
1099 PetscCall(ConfigureNormalSourceInlet(user, BC_FACE_NEG_Z, "1 + 10*t"));
1100 ctx.user = user;
1101 ctx.face_id = BC_FACE_NEG_Z;
1103 PetscCall(bc->Initialize(bc, &ctx));
1104 PetscCall(ApplyInletAcrossFirstSteps(bc, &ctx));
1105 PetscCall(PicurvPhysicalTime(simCtx, simCtx->ti, &physical_time));
1106 /* A second pass in the same step, at a later stage time, keeps the step's value. */
1107 simCtx->ti += 0.05;
1108 PetscCall(bc->PreStep(bc, &ctx, &local_inflow, &local_outflow));
1109 PetscCall(bc->Apply(bc, &ctx));
1110 PetscCall(DMDAVecGetArrayRead(user->fda, user->Ucont, &ucont));
1111 PetscCall(PicurvAssertRealNear((1.0 + 10.0 * physical_time) / simCtx->scaling.U_ref, ucont[0][3][3].z, 1.0e-12,
1112 "a source in t takes the value at the step's time"));
1113 PetscCall(DMDAVecRestoreArrayRead(user->fda, user->Ucont, &ucont));
1114 PetscCall(DestroyBoundaryHandler(&bc));
1115
1116 /* A shape in xi rescaled to a bulk velocity of 3: on a uniform face the mean of xi is 1/2. */
1117 PetscCall(PetscOptionsSetValue(NULL, "-face_source_0_expr_0", "xi"));
1118 PetscCall(PetscOptionsSetValue(NULL, "-face_source_0_bulk_velocity", "3.0"));
1120 PetscCall(bc->Initialize(bc, &ctx));
1121 PetscCall(ApplyInletAcrossFirstSteps(bc, &ctx));
1122 local_inflow = 0.0;
1123 PetscCall(bc->PostStep(bc, &ctx, &local_inflow, &local_outflow));
1125 local_inflow, 1.0e-10, "the face flux is the bulk velocity times the open area"));
1126 PetscCall(DMDAVecGetArrayRead(user->fda, user->Ucont, &ucont));
1127 PetscCall(PicurvAssertRealNear(2.0 * 3.0 * 0.1 / simCtx->scaling.U_ref, ucont[0][3][1].z, 1.0e-12,
1128 "the shape keeps its form: twice the bulk times xi"));
1129 PetscCall(DMDAVecRestoreArrayRead(user->fda, user->Ucont, &ucont));
1130 PetscCall(PetscOptionsClearValue(NULL, "-face_source_0_bulk_velocity"));
1131
1132 PetscCall(DestroyBoundaryHandler(&bc));
1134 PetscCall(PicurvDestroyMinimalContexts(&simCtx, &user));
1135 PetscFunctionReturn(0);
1136}
PetscErrorCode PicurvPhysicalTime(const SimCtx *simCtx, PetscReal solver_time, PetscReal *physical)
Convert a solver time to physical seconds, t * L_ref / U_ref.
Definition io.c:2986
ScalingCtx scaling
Definition variables.h:1003
PetscReal U_ref
Definition variables.h:899
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ApplyHandlerAtTime()

static PetscErrorCode ApplyHandlerAtTime ( BoundaryCondition *  bc,
BCContext *  ctx,
PetscInt  step,
PetscReal  physical_time 
)
static

Runs the handler at one time as a new step of its own.

Definition at line 1141 of file test_boundaries.c.

1142{
1143 SimCtx *simCtx = ctx->user->simCtx;
1144
1145 PetscFunctionBeginUser;
1146 simCtx->step = step;
1147 simCtx->ti = physical_time * simCtx->scaling.L_ref / simCtx->scaling.U_ref;
1148 PetscCall(bc->PreStep(bc, ctx, NULL, NULL));
1149 PetscCall(bc->Apply(bc, ctx));
1150 PetscFunctionReturn(0);
1151}
PetscReal L_ref
Definition variables.h:898
Here is the caller graph for this function:

◆ TestInletRecordingOfCartesianVelocities()

static PetscErrorCode TestInletRecordingOfCartesianVelocities ( void  )
static

Tests a recording of Cartesian velocities: every component reaches the boundary, reversed flow is allowed, frames interpolate linearly in time, and past the end they repeat when asked and are refused when not.

Definition at line 1158 of file test_boundaries.c.

1159{
1160 SimCtx *simCtx = NULL;
1161 UserCtx *user = NULL;
1162 BoundaryCondition *bc = NULL;
1163 BCContext ctx;
1164 Cmpnts ***ucont = NULL, ***ubcs = NULL;
1165 char path[PETSC_MAX_PATH_LEN];
1166 FILE *fd = NULL;
1167 const PetscReal w_of_frame[3] = {-1.0, 3.0, 5.0};
1168
1169 PetscFunctionBeginUser;
1170 PetscCall(PetscMemzero(&ctx, sizeof(ctx)));
1171 PetscCall(PicurvCreateMinimalContexts(&simCtx, &user, 5, 5, 5));
1172 PetscCall(PicurvPopulateIdentityMetrics(user));
1173 PetscCall(PetscSNPrintf(path, sizeof(path), "/tmp/picurv_unit_recording_%d.picslice", (int)getpid()));
1174 fd = fopen(path, "w");
1175 PetscCheck(fd, PETSC_COMM_SELF, PETSC_ERR_FILE_OPEN, "Could not open %s.", path);
1176 fprintf(fd, "PICSLICE\n3\n%d %d 3 0.1\n", (int)(user->JM - 1), (int)(user->IM - 1));
1177 for (PetscInt frame = 0; frame < 3; ++frame)
1178 for (PetscInt a = 0; a < user->JM - 1; ++a)
1179 for (PetscInt b = 0; b < user->IM - 1; ++b) fprintf(fd, "%.16e 7.0 %.16e\n", (double)(10 * a + b), (double)w_of_frame[frame]);
1180 fclose(fd);
1181
1185 PetscCall(AppendBCParam(&user->boundary_faces[BC_FACE_NEG_Z].params, "source_id", "0"));
1186 PetscCall(AppendBCParam(&user->boundary_faces[BC_FACE_NEG_Z].params, "source_file", path));
1187 PetscCall(AppendBCParam(&user->boundary_faces[BC_FACE_NEG_Z].params, "source_repeat", "true"));
1188 PetscCall(PetscOptionsSetValue(NULL, "-face_source_0_frame", "cartesian"));
1189 PetscCall(PetscOptionsClearValue(NULL, "-face_source_0_expr_0"));
1190 ctx.user = user;
1191 ctx.face_id = BC_FACE_NEG_Z;
1193 PetscCall(bc->Initialize(bc, &ctx));
1194
1195 PetscCall(ApplyHandlerAtTime(bc, &ctx, 1, 0.05));
1196 PetscCall(DMDAVecGetArrayRead(user->fda, user->Ucont, &ucont));
1197 PetscCall(DMDAVecGetArrayRead(user->fda, user->Bcs.Ubcs, &ubcs));
1198 PetscCall(PicurvAssertRealNear(1.0, ucont[0][1][1].z, 1.0e-12, "halfway between frames is their mean"));
1199 PetscCall(PicurvAssertRealNear(11.0, ubcs[0][2][2].x, 1.0e-12, "the file's first component is x, in row order"));
1200 PetscCall(PicurvAssertRealNear(7.0, ubcs[0][2][2].y, 1.0e-12, "the file's second component is y"));
1201 PetscCall(DMDAVecRestoreArrayRead(user->fda, user->Bcs.Ubcs, &ubcs));
1202 PetscCall(DMDAVecRestoreArrayRead(user->fda, user->Ucont, &ucont));
1203
1204 PetscCall(ApplyHandlerAtTime(bc, &ctx, 2, 0.0));
1205 PetscCall(DMDAVecGetArrayRead(user->fda, user->Ucont, &ucont));
1206 PetscCall(PicurvAssertRealNear(-1.0, ucont[0][1][1].z, 1.0e-12, "a frame may reverse the flow"));
1207 PetscCall(DMDAVecRestoreArrayRead(user->fda, user->Ucont, &ucont));
1208
1209 /* Three frames 0.1 apart repeat every 0.3, the last blending back into the first. */
1210 PetscCall(ApplyHandlerAtTime(bc, &ctx, 3, 0.25));
1211 PetscCall(DMDAVecGetArrayRead(user->fda, user->Ucont, &ucont));
1212 PetscCall(PicurvAssertRealNear(2.0, ucont[0][1][1].z, 1.0e-12, "past the last frame it blends into the first"));
1213 PetscCall(DMDAVecRestoreArrayRead(user->fda, user->Ucont, &ucont));
1214 PetscCall(ApplyHandlerAtTime(bc, &ctx, 4, 0.35));
1215 PetscCall(DMDAVecGetArrayRead(user->fda, user->Ucont, &ucont));
1216 PetscCall(PicurvAssertRealNear(1.0, ucont[0][1][1].z, 1.0e-12, "a repeat starts again from the first frame"));
1217 PetscCall(DMDAVecRestoreArrayRead(user->fda, user->Ucont, &ucont));
1218 PetscCall(DestroyBoundaryHandler(&bc));
1219
1220 /* Without repeat the recording's end is a time the source does not define. */
1222 user->boundary_faces[BC_FACE_NEG_Z].params = NULL;
1223 PetscCall(AppendBCParam(&user->boundary_faces[BC_FACE_NEG_Z].params, "source_id", "0"));
1224 PetscCall(AppendBCParam(&user->boundary_faces[BC_FACE_NEG_Z].params, "source_file", path));
1226 PetscCall(bc->Initialize(bc, &ctx));
1227 PetscCall(ApplyHandlerAtTime(bc, &ctx, 5, 0.2));
1228 PetscCall(DMDAVecGetArrayRead(user->fda, user->Ucont, &ucont));
1229 PetscCall(PicurvAssertRealNear(5.0, ucont[0][1][1].z, 1.0e-12, "the last frame's own time is defined"));
1230 PetscCall(DMDAVecRestoreArrayRead(user->fda, user->Ucont, &ucont));
1231 simCtx->step = 6;
1232 simCtx->ti = 0.21 * simCtx->scaling.L_ref / simCtx->scaling.U_ref;
1233 PetscCall(PetscPushErrorHandler(PetscIgnoreErrorHandler, NULL));
1234 {
1235 PetscErrorCode past = bc->PreStep(bc, &ctx, NULL, NULL);
1236 PetscCall(PetscPopErrorHandler());
1237 PetscCall(PicurvAssertBool((PetscBool)(past != 0), "past the last frame without repeat is refused"));
1238 }
1239 PetscCall(DestroyBoundaryHandler(&bc));
1240
1241 PetscCall(PetscOptionsClearValue(NULL, "-face_source_0_frame"));
1243 user->boundary_faces[BC_FACE_NEG_Z].params = NULL;
1244 remove(path);
1245 PetscCall(PicurvDestroyMinimalContexts(&simCtx, &user));
1246 PetscFunctionReturn(0);
1247}
static PetscErrorCode ApplyHandlerAtTime(BoundaryCondition *bc, BCContext *ctx, PetscInt step, PetscReal physical_time)
Runs the handler at one time as a new step of its own.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TestInletFlowRateAndFaceRadius()

static PetscErrorCode TestInletFlowRateAndFaceRadius ( void  )
static

Tests that a flow-rate target sets the face's total flux, whatever its area, and that r is the distance from the face's centre.

Definition at line 1253 of file test_boundaries.c.

1254{
1255 SimCtx *simCtx = NULL;
1256 UserCtx *user = NULL;
1257 BoundaryCondition *bc = NULL;
1258 BCContext ctx;
1259 Cmpnts ***ucont = NULL, ***cent = NULL, centre;
1260 PetscReal local_inflow = 0.0, local_outflow = 0.0, area = 0.0;
1261
1262 PetscFunctionBeginUser;
1263 PetscCall(PetscMemzero(&ctx, sizeof(ctx)));
1264 PetscCall(PicurvCreateMinimalContexts(&simCtx, &user, 5, 5, 5));
1265 PetscCall(PicurvPopulateIdentityMetrics(user));
1266 PetscCall(ConfigureNormalSourceInlet(user, BC_FACE_NEG_Z, "2.0"));
1267 PetscCall(PetscOptionsSetValue(NULL, "-face_source_0_flow_rate", "8.0"));
1268 ctx.user = user;
1269 ctx.face_id = BC_FACE_NEG_Z;
1271 PetscCall(bc->Initialize(bc, &ctx));
1272 PetscCall(ApplyInletAcrossFirstSteps(bc, &ctx));
1273 PetscCall(bc->PostStep(bc, &ctx, &local_inflow, &local_outflow));
1274 /* Each identity slot has unit solver area, so L_ref^2 physical. */
1275 PetscCall(PicurvAssertRealNear(8.0 / (simCtx->scaling.U_ref * simCtx->scaling.L_ref * simCtx->scaling.L_ref), local_inflow, 1.0e-10,
1276 "the face's flux is the flow rate"));
1277 /* The per-step record reads back the flow rate and its mean over the open area. */
1278 {
1279 char row[256] = {0}, path[PETSC_MAX_PATH_LEN + 16];
1280 FILE *record = NULL;
1281 double time = 0.0, face_area = 0.0, rate = 0.0;
1282 int step = 0;
1283 char face[32] = {0};
1284 PetscCall(PetscSNPrintf(simCtx->analysis_dir, sizeof(simCtx->analysis_dir), "/tmp/picurv_unit_inlet_%d", (int)getpid()));
1285 PetscCheck(mkdir(simCtx->analysis_dir, 0700) == 0, PETSC_COMM_SELF, PETSC_ERR_FILE_OPEN, "Could not make the record's directory.");
1287 PetscCall(LogPrescribedFlowDiagnostics(user));
1288 user->boundary_faces[BC_FACE_NEG_Z].handler = NULL;
1289 PetscCall(PetscSNPrintf(path, sizeof(path), "%s/inlet_flow.csv", simCtx->analysis_dir));
1290 record = fopen(path, "r");
1291 PetscCheck(record, PETSC_COMM_SELF, PETSC_ERR_FILE_OPEN, "The inlet-flow record was not written.");
1292 PetscCheck(fgets(row, sizeof(row), record) && fgets(row, sizeof(row), record), PETSC_COMM_SELF, PETSC_ERR_FILE_READ, "No inlet-flow row.");
1293 fclose(record);
1294 PetscCheck(sscanf(row, "%d,%le,%31[^,],%le,%le", &step, &time, face, &face_area, &rate) == 5, PETSC_COMM_SELF, PETSC_ERR_FILE_READ, "Bad row: %s", row);
1295 PetscCall(PicurvAssertRealNear(8.0, rate, 1.0e-8, "the record's flow rate is the target"));
1296 remove(path);
1297 rmdir(simCtx->analysis_dir);
1298 }
1299 PetscCall(DestroyBoundaryHandler(&bc));
1300 PetscCall(PetscOptionsClearValue(NULL, "-face_source_0_flow_rate"));
1301
1302 PetscCall(PetscOptionsSetValue(NULL, "-face_source_0_expr_0", "r"));
1303 PetscCall(CalculateFaceCenterAndArea(user, BC_FACE_NEG_Z, &centre, &area));
1304 PetscCall(DMDAVecGetArray(user->fda, user->lCentz, &cent));
1305 cent[0][2][2].x = centre.x + 3.0;
1306 cent[0][2][2].y = centre.y + 4.0;
1307 cent[0][2][2].z = centre.z;
1308 PetscCall(DMDAVecRestoreArray(user->fda, user->lCentz, &cent));
1310 PetscCall(bc->Initialize(bc, &ctx));
1311 PetscCall(ApplyInletAcrossFirstSteps(bc, &ctx));
1312 PetscCall(DMDAVecGetArrayRead(user->fda, user->Ucont, &ucont));
1313 PetscCall(PicurvAssertRealNear(5.0 * simCtx->scaling.L_ref / simCtx->scaling.U_ref, ucont[0][2][2].z, 1.0e-12,
1314 "r is the slot's distance from the face's centre"));
1315 PetscCall(DMDAVecRestoreArrayRead(user->fda, user->Ucont, &ucont));
1316 PetscCall(DestroyBoundaryHandler(&bc));
1317 PetscCall(PetscOptionsClearValue(NULL, "-face_source_0_frame"));
1318 PetscCall(PetscOptionsClearValue(NULL, "-face_source_0_expr_0"));
1320 PetscCall(PicurvDestroyMinimalContexts(&simCtx, &user));
1321 PetscFunctionReturn(0);
1322}
PetscErrorCode LogPrescribedFlowDiagnostics(UserCtx *user)
Appends each prescribed-velocity inlet's flow rate and mean normal speed this step to inlet_flow....
PetscErrorCode CalculateFaceCenterAndArea(UserCtx *user, BCFace face_id, Cmpnts *face_center, PetscReal *face_area)
Calculates the geometric center and total area of a specified boundary face.
Definition grid.c:1211
char analysis_dir[PETSC_MAX_PATH_LEN]
Definition variables.h:942
Vec lCentz
Definition variables.h:1253
BoundaryCondition * handler
Definition variables.h:430
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TestWallMovingAlongItself()

static PetscErrorCode TestWallMovingAlongItself ( void  )
static

Tests a moving wall on both a - and a + face: its velocity along the wall reaches the boundary value and the face stays closed, a slight tilt is removed, and a velocity through the wall is refused.

Definition at line 1329 of file test_boundaries.c.

1330{
1331 SimCtx *simCtx = NULL;
1332 UserCtx *user = NULL;
1333 BoundaryCondition *bc = NULL;
1334 BCContext ctx;
1335 Cmpnts ***ucont = NULL, ***ubcs = NULL;
1336 const BCFace faces[2] = {BC_FACE_NEG_Y, BC_FACE_POS_Y};
1337
1338 PetscFunctionBeginUser;
1339 PetscCall(PetscMemzero(&ctx, sizeof(ctx)));
1340 PetscCall(PicurvCreateMinimalContexts(&simCtx, &user, 5, 5, 5));
1341 PetscCall(PicurvPopulateIdentityMetrics(user));
1342 PetscCall(PetscOptionsSetValue(NULL, "-face_source_0_frame", "cartesian"));
1343 PetscCall(PetscOptionsSetValue(NULL, "-face_source_0_expr_0", "2.0"));
1344 PetscCall(PetscOptionsSetValue(NULL, "-face_source_0_expr_1", "0.02"));
1345 PetscCall(PetscOptionsSetValue(NULL, "-face_source_0_expr_2", "3.0"));
1346 ctx.user = user;
1347 for (PetscInt f = 0; f < 2; ++f) {
1348 const BCFace face = faces[f];
1349 const PetscInt layer = (face == BC_FACE_NEG_Y) ? 0 : user->info.my - 2;
1350 const PetscInt boundary = (face == BC_FACE_NEG_Y) ? 0 : user->info.my - 1;
1351 user->boundary_faces[face].face_id = face;
1354 PetscCall(AppendBCParam(&user->boundary_faces[face].params, "source_id", "0"));
1355 ctx.face_id = face;
1356 PetscCall(VecSet(user->Ucont, 9.0));
1358 PetscCall(PicurvAssertBool((PetscBool)(bc->priority == BC_PRIORITY_WALL), "a moving wall runs with the walls"));
1359 PetscCall(bc->Initialize(bc, &ctx));
1360 PetscCall(ApplyHandlerAtTime(bc, &ctx, 1 + f, 0.0));
1361 PetscCall(DMDAVecGetArrayRead(user->fda, user->Ucont, &ucont));
1362 PetscCall(DMDAVecGetArrayRead(user->fda, user->Bcs.Ubcs, &ubcs));
1363 PetscCall(PicurvAssertRealNear(0.0, ucont[2][layer][2].y, 1.0e-12, "a moving wall closes its face"));
1364 PetscCall(PicurvAssertRealNear(2.0 / simCtx->scaling.U_ref, ubcs[2][boundary][2].x, 1.0e-12, "the wall moves in x"));
1365 PetscCall(PicurvAssertRealNear(0.0, ubcs[2][boundary][2].y, 1.0e-12, "a slight tilt through the wall is removed"));
1366 PetscCall(PicurvAssertRealNear(3.0 / simCtx->scaling.U_ref, ubcs[2][boundary][2].z, 1.0e-12, "the wall moves in z"));
1367 PetscCall(DMDAVecRestoreArrayRead(user->fda, user->Bcs.Ubcs, &ubcs));
1368 PetscCall(DMDAVecRestoreArrayRead(user->fda, user->Ucont, &ucont));
1369 PetscCall(DestroyBoundaryHandler(&bc));
1370 }
1371 PetscCall(PetscOptionsSetValue(NULL, "-face_source_0_expr_1", "1.0"));
1372 user->GridOrientation = 1;
1373 ctx.face_id = BC_FACE_NEG_Y;
1375 PetscCall(bc->Initialize(bc, &ctx));
1376 PetscCall(PetscPushErrorHandler(PetscIgnoreErrorHandler, NULL));
1377 {
1378 PetscErrorCode through = bc->PreStep(bc, &ctx, NULL, NULL);
1379 PetscCall(PetscPopErrorHandler());
1380 PetscCall(PicurvAssertBool((PetscBool)(through != 0), "a velocity through the wall is refused"));
1381 }
1382 PetscCall(DestroyBoundaryHandler(&bc));
1383 for (PetscInt c = 0; c < 3; ++c) {
1384 char option[64];
1385 PetscCall(PetscSNPrintf(option, sizeof(option), "-face_source_0_expr_%d", (int)c));
1386 PetscCall(PetscOptionsClearValue(NULL, option));
1387 }
1388 PetscCall(PetscOptionsClearValue(NULL, "-face_source_0_frame"));
1389 for (PetscInt f = 0; f < 2; ++f) ResetBoundaryFaceConfig(&user->boundary_faces[faces[f]]);
1390 PetscCall(PicurvDestroyMinimalContexts(&simCtx, &user));
1391 PetscFunctionReturn(0);
1392}
@ BC_HANDLER_WALL_MOVING
Definition variables.h:346
PetscInt GridOrientation
Definition variables.h:1175
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TestOutletConservationHandlerBehavior()

static PetscErrorCode TestOutletConservationHandlerBehavior ( void  )
static

Tests outlet conservation handler correction and post-step flux accounting.

Definition at line 1398 of file test_boundaries.c.

1399{
1400 SimCtx *simCtx = NULL;
1401 UserCtx *user = NULL;
1402 BoundaryCondition *bc = NULL;
1403 BCContext ctx;
1404 PetscReal global_inflow = 30.0;
1405 PetscReal global_farfield_in = 0.0;
1406 PetscReal global_farfield_out = 0.0;
1407 PetscReal global_outflow = 25.0;
1408 PetscReal local_inflow = 0.0;
1409 PetscReal local_outflow = 0.0;
1410 Cmpnts ***ucont = NULL;
1411 Cmpnts ***ucat = NULL;
1412
1413 PetscFunctionBeginUser;
1414 PetscCall(PetscMemzero(&ctx, sizeof(ctx)));
1415 PetscCall(PicurvCreateMinimalContexts(&simCtx, &user, 6, 6, 6));
1416 PetscCall(PicurvPopulateIdentityMetrics(user));
1417 PetscCall(VecSet(user->Ucat, 1.0));
1418 PetscCall(DMGlobalToLocalBegin(user->fda, user->Ucat, INSERT_VALUES, user->lUcat));
1419 PetscCall(DMGlobalToLocalEnd(user->fda, user->Ucat, INSERT_VALUES, user->lUcat));
1420 simCtx->AreaOutSum = (PetscReal)(user->info.mx - 2) * (PetscReal)(user->info.my - 2);
1421
1425
1426 ctx.user = user;
1427 ctx.face_id = BC_FACE_POS_Z;
1428 ctx.global_inflow_sum = &global_inflow;
1429 ctx.global_farfield_inflow_sum = &global_farfield_in;
1430 ctx.global_farfield_outflow_sum = &global_farfield_out;
1431 ctx.global_outflow_sum = &global_outflow;
1432
1434 PetscCall(bc->Apply(bc, &ctx));
1435 PetscCall(bc->PostStep(bc, &ctx, &local_inflow, &local_outflow));
1436
1437 PetscCall(DMDAVecGetArrayRead(user->fda, user->Ucont, &ucont));
1438 PetscCall(DMDAVecGetArrayRead(user->fda, user->lUcat, &ucat));
1439 PetscCall(PicurvAssertRealNear(1.2, ucont[5][3][3].z, 1.0e-12, "outlet correction should add the expected flux trim"));
1440 PetscCall(PicurvAssertRealNear(1.0, ucat[5][3][3].z, 1.0e-12, "outlet handler should preserve the interior Ucat reference"));
1441 PetscCall(DMDAVecRestoreArrayRead(user->fda, user->Ucont, &ucont));
1442 PetscCall(DMDAVecRestoreArrayRead(user->fda, user->lUcat, &ucat));
1443
1444 PetscCall(PicurvAssertRealNear(30.0, local_outflow, 1.0e-12, "outlet PostStep should report corrected flux"));
1445 PetscCall(PicurvAssertRealNear(0.0, local_inflow, 1.0e-12, "outlet handler should not accumulate inflow"));
1446
1447 PetscCall(DestroyBoundaryHandler(&bc));
1448 PetscCall(PicurvDestroyMinimalContexts(&simCtx, &user));
1449 PetscFunctionReturn(0);
1450}
const PetscReal * global_outflow_sum
Definition variables.h:385
@ OUTLET
Definition variables.h:322
const PetscReal * global_farfield_outflow_sum
Definition variables.h:384
const PetscReal * global_inflow_sum
Definition variables.h:382
const PetscReal * global_farfield_inflow_sum
Definition variables.h:383
PetscReal AreaOutSum
Definition variables.h:1036
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TestOutletConservationHandlerFaceMatrix()

static PetscErrorCode TestOutletConservationHandlerFaceMatrix ( void  )
static

Tests outlet-conservation correction and flux accounting across all outlet faces.

Definition at line 1455 of file test_boundaries.c.

1456{
1457 const BCFace faces[] = {
1461 };
1462 SimCtx *simCtx = NULL;
1463 UserCtx *user = NULL;
1464 BCContext ctx;
1465 Cmpnts ***ucont = NULL;
1466 Cmpnts ***ubcs = NULL;
1467
1468 PetscFunctionBeginUser;
1469 PetscCall(PetscMemzero(&ctx, sizeof(ctx)));
1470 PetscCall(PicurvCreateMinimalContexts(&simCtx, &user, 6, 6, 6));
1471 PetscCall(PicurvPopulateIdentityMetrics(user));
1472 PetscCall(VecSet(user->Ucat, 1.0));
1473 PetscCall(DMGlobalToLocalBegin(user->fda, user->Ucat, INSERT_VALUES, user->lUcat));
1474 PetscCall(DMGlobalToLocalEnd(user->fda, user->Ucat, INSERT_VALUES, user->lUcat));
1475
1476 for (size_t n = 0; n < sizeof(faces) / sizeof(faces[0]); ++n) {
1477 const BCFace face = faces[n];
1478 BoundaryCondition *bc = NULL;
1479 PetscReal global_inflow = 0.0;
1480 PetscReal global_farfield_in = 0.0;
1481 PetscReal global_farfield_out = 0.0;
1482 PetscReal global_outflow = 0.0;
1483 PetscReal local_inflow = 0.0;
1484 PetscReal local_outflow = 0.0;
1485 PetscReal area = GetFaceInteriorPointCount(user, face);
1486 PetscInt ucont_k, ucont_j, ucont_i, ubcs_k, ubcs_j, ubcs_i;
1487
1488 PetscCall(VecSet(user->Ucont, 0.0));
1489 PetscCall(VecSet(user->Bcs.Ubcs, 0.0));
1491 user->boundary_faces[face].face_id = face;
1494 user->simCtx->AreaOutSum = area;
1495
1496 ctx.user = user;
1497 ctx.face_id = face;
1498 ctx.global_inflow_sum = &global_inflow;
1499 ctx.global_farfield_inflow_sum = &global_farfield_in;
1500 ctx.global_farfield_outflow_sum = &global_farfield_out;
1501 ctx.global_outflow_sum = &global_outflow;
1502
1504 PetscCall(bc->PreStep(bc, &ctx, &local_inflow, &local_outflow));
1505 PetscCall(PicurvAssertRealNear(area, local_outflow, 1.0e-12, "outlet PreStep should measure the uncorrected face flux"));
1506
1507 global_inflow = area + 0.2 * area;
1508 global_outflow = local_outflow;
1509 local_outflow = 0.0;
1510 PetscCall(bc->Apply(bc, &ctx));
1511 PetscCall(bc->PostStep(bc, &ctx, &local_inflow, &local_outflow));
1512
1513 PetscCall(GetRepresentativeFaceSlots(user, face, &ucont_k, &ucont_j, &ucont_i, &ubcs_k, &ubcs_j, &ubcs_i));
1514 PetscCall(DMDAVecGetArrayRead(user->fda, user->Ucont, &ucont));
1515 PetscCall(DMDAVecGetArrayRead(user->fda, user->Bcs.Ubcs, &ubcs));
1516 PetscCall(PicurvAssertRealNear(1.2, GetFaceNormalComponent(ucont[ucont_k][ucont_j][ucont_i], face), 1.0e-12, "outlet correction should add the configured flux trim"));
1517 PetscCall(PicurvAssertRealNear(1.0, ubcs[ubcs_k][ubcs_j][ubcs_i].x, 1.0e-12, "outlet handler should copy Ucat into Ubcs.x"));
1518 PetscCall(PicurvAssertRealNear(1.0, ubcs[ubcs_k][ubcs_j][ubcs_i].y, 1.0e-12, "outlet handler should copy Ucat into Ubcs.y"));
1519 PetscCall(PicurvAssertRealNear(1.0, ubcs[ubcs_k][ubcs_j][ubcs_i].z, 1.0e-12, "outlet handler should copy Ucat into Ubcs.z"));
1520 PetscCall(DMDAVecRestoreArrayRead(user->fda, user->Ucont, &ucont));
1521 PetscCall(DMDAVecRestoreArrayRead(user->fda, user->Bcs.Ubcs, &ubcs));
1522 PetscCall(PicurvAssertRealNear(0.0, local_inflow, 1.0e-12, "outlet handler should not add to inflow"));
1523 PetscCall(PicurvAssertRealNear(1.2 * area, local_outflow, 1.0e-12, "outlet PostStep should report the corrected flux"));
1524
1525 PetscCall(DestroyBoundaryHandler(&bc));
1527 }
1528
1529 PetscCall(PicurvDestroyMinimalContexts(&simCtx, &user));
1530 PetscFunctionReturn(0);
1531}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetCellNormalVelocity()

static PetscErrorCode SetCellNormalVelocity ( UserCtx *  user,
BCFace  face,
PetscInt  k,
PetscInt  j,
PetscInt  i,
PetscReal  value 
)
static

Sets the face-normal Ucat component of one cell and refreshes lUcat.

Definition at line 1536 of file test_boundaries.c.

1537{
1538 Cmpnts ***ucat = NULL;
1539
1540 PetscFunctionBeginUser;
1541 PetscCall(DMDAVecGetArray(user->fda, user->Ucat, &ucat));
1542 if (face == BC_FACE_POS_X || face == BC_FACE_NEG_X) ucat[k][j][i].x = value;
1543 else if (face == BC_FACE_POS_Y || face == BC_FACE_NEG_Y) ucat[k][j][i].y = value;
1544 else ucat[k][j][i].z = value;
1545 PetscCall(DMDAVecRestoreArray(user->fda, user->Ucat, &ucat));
1546 PetscCall(DMGlobalToLocalBegin(user->fda, user->Ucat, INSERT_VALUES, user->lUcat));
1547 PetscCall(DMGlobalToLocalEnd(user->fda, user->Ucat, INSERT_VALUES, user->lUcat));
1548 PetscFunctionReturn(0);
1549}
Here is the caller graph for this function:

◆ ApplyOutletAndMeasure()

static PetscErrorCode ApplyOutletAndMeasure ( BoundaryCondition *  bc,
BCContext *  ctx,
BCFace  face,
PetscReal  inflow,
PetscReal  outflow_measured,
PetscReal *  sample_flux,
Cmpnts *  sample_ubcs,
PetscReal *  total 
)
static

Runs one outlet Apply with the given sums and returns the face's sample flux and total.

Definition at line 1554 of file test_boundaries.c.

1557{
1558 PetscReal global_farfield = 0.0, local_inflow = 0.0, local_outflow = 0.0;
1559 PetscInt ck, cj, ci, bk, bj, bi;
1560 Cmpnts ***ucont = NULL, ***ubcs = NULL;
1561
1562 PetscFunctionBeginUser;
1563 ctx->global_inflow_sum = &inflow;
1564 ctx->global_outflow_sum = &outflow_measured;
1565 ctx->global_farfield_inflow_sum = &global_farfield;
1566 ctx->global_farfield_outflow_sum = &global_farfield;
1567 PetscCall(bc->Apply(bc, ctx));
1568 PetscCall(bc->PostStep(bc, ctx, &local_inflow, &local_outflow));
1569 PetscCall(GetRepresentativeFaceSlots(ctx->user, face, &ck, &cj, &ci, &bk, &bj, &bi));
1570 PetscCall(DMDAVecGetArrayRead(ctx->user->fda, ctx->user->Ucont, &ucont));
1571 PetscCall(DMDAVecGetArrayRead(ctx->user->fda, ctx->user->Bcs.Ubcs, &ubcs));
1572 *sample_flux = GetFaceNormalComponent(ucont[ck][cj][ci], face);
1573 *sample_ubcs = ubcs[bk][bj][bi];
1574 PetscCall(DMDAVecRestoreArrayRead(ctx->user->fda, ctx->user->Ucont, &ucont));
1575 PetscCall(DMDAVecRestoreArrayRead(ctx->user->fda, ctx->user->Bcs.Ubcs, &ubcs));
1576 *total = local_outflow;
1577 ctx->global_inflow_sum = NULL;
1578 ctx->global_outflow_sum = NULL;
1579 PetscFunctionReturn(0);
1580}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TestOutletConservationBackflowClip()

static PetscErrorCode TestOutletConservationBackflowClip ( void  )
static

Tests the conservation outlet's backflow clip on +X, +Y, +Z and on -X, -Z.

Fluxes are signed along +xi, so outflow is F > 0 on a positive face and F < 0 on a negative one (an outlet there pairs with an inlet on the positive side); every value below is multiplied by that outward sign s. On a 4 x 4 outlet with Ucat = s (1,1,1), one sample cell is set per case:

  • reversed (normal -0.5): the clip zeroes that face's flux and the normal Ubcs component, keeps the tangential ones, and scales the other faces so the total equals the inflow;
  • slow but outflowing (0.1) with a negative uniform correction that would reverse it: the ratio rule keeps it positive without clipping, total still the inflow;
  • control, nothing reversed: the uniform rule's value F + c*A exactly. Fails if the trigger tests F instead of F + c*A, if psi is not re-normalised to the inflow, if Ubcs keeps the reversed normal component, or if the clip touches an outlet it should not.

Definition at line 1597 of file test_boundaries.c.

1598{
1600 SimCtx *simCtx = NULL;
1601 UserCtx *user = NULL;
1602 BCContext ctx;
1603
1604 PetscFunctionBeginUser;
1605 PetscCall(PetscMemzero(&ctx, sizeof(ctx)));
1606 PetscCall(PicurvCreateMinimalContexts(&simCtx, &user, 6, 6, 6));
1607 PetscCall(PicurvPopulateIdentityMetrics(user));
1608 ctx.user = user;
1609
1610 for (size_t n = 0; n < sizeof(faces) / sizeof(faces[0]); ++n) {
1611 const BCFace face = faces[n];
1612 const PetscReal s = ((PetscInt)face % 2 == 0) ? -1.0 : 1.0;
1613 const PetscReal area = GetFaceInteriorPointCount(user, face);
1614 PetscInt ck, cj, ci, bk, bj, bi;
1615 PetscReal flux, total;
1616 Cmpnts ubcs;
1617
1618 /* The flux slot of a positive face is its cell's index; a negative face's cell is 1. */
1619 PetscCall(GetRepresentativeFaceSlots(user, face, &ck, &cj, &ci, &bk, &bj, &bi));
1620 if (face == BC_FACE_NEG_X) ci = 1;
1621 if (face == BC_FACE_NEG_Z) ck = 1;
1623 user->boundary_faces[face].face_id = face;
1626 simCtx->AreaOutSum = area;
1627 ctx.face_id = face;
1628
1629 /* Reversed face: clipped, the rest scaled by area / (area - 1). */
1630 {
1631 BoundaryCondition *bc = NULL;
1632 PetscCall(VecSet(user->Ucat, s));
1633 PetscCall(SetCellNormalVelocity(user, face, ck, cj, ci, -0.5 * s));
1634 PetscCall(VecSet(user->Ucont, 0.0));
1635 simCtx->step = 1;
1637 PetscCall(ApplyOutletAndMeasure(bc, &ctx, face, s * area, s * (area - 1.5), &flux, &ubcs, &total));
1638 PetscCall(PicurvAssertRealNear(0.0, flux, 1.0e-14, "a reversed outlet face is clipped to zero flux"));
1639 PetscCall(PicurvAssertRealNear(0.0, GetFaceNormalComponent(ubcs, face), 1.0e-14,
1640 "a clipped face's Ubcs has no normal component"));
1641 PetscCall(PicurvAssertRealNear(2.0 * s, ubcs.x + ubcs.y + ubcs.z, 1.0e-14,
1642 "a clipped face's Ubcs keeps both tangential components"));
1643 PetscCall(PicurvAssertRealNear(s * area, total, 1.0e-12, "the clip conserves the inflow"));
1644 PetscCall(DestroyBoundaryHandler(&bc));
1645 }
1646
1647 /* Slow face pushed negative by the correction: ratio rule, nothing clipped. */
1648 {
1649 BoundaryCondition *bc = NULL;
1650 const PetscReal measured = s * ((area - 1.0) + 0.1);
1651 const PetscReal inflow = measured - s * 0.5 * area; /* c = -0.5 s, against the outflow */
1652 PetscCall(VecSet(user->Ucat, s));
1653 PetscCall(SetCellNormalVelocity(user, face, ck, cj, ci, 0.1 * s));
1654 simCtx->step = 1;
1656 PetscCall(ApplyOutletAndMeasure(bc, &ctx, face, inflow, measured, &flux, &ubcs, &total));
1657 PetscCall(PicurvAssertRealNear(0.1 * s * inflow / measured, flux, 1.0e-12,
1658 "a slow face is scaled, not reversed, when the correction would reverse it"));
1659 PetscCall(PicurvAssertRealNear(0.1 * s, GetFaceNormalComponent(ubcs, face), 1.0e-14,
1660 "an unclipped face keeps the copied Ubcs"));
1661 PetscCall(PicurvAssertRealNear(inflow, total, 1.0e-12, "the ratio rule conserves the inflow"));
1662 PetscCall(DestroyBoundaryHandler(&bc));
1663 }
1664
1665 /* Control: nothing reversed, uniform rule to the bit. */
1666 {
1667 BoundaryCondition *bc = NULL;
1668 const PetscReal correction = -0.2;
1669 PetscCall(VecSet(user->Ucat, s));
1670 PetscCall(DMGlobalToLocalBegin(user->fda, user->Ucat, INSERT_VALUES, user->lUcat));
1671 PetscCall(DMGlobalToLocalEnd(user->fda, user->Ucat, INSERT_VALUES, user->lUcat));
1672 simCtx->step = 1;
1674 PetscCall(ApplyOutletAndMeasure(bc, &ctx, face, s * (area + correction * area), s * area, &flux, &ubcs, &total));
1675 PetscCheck(flux == s + ((s * (area + correction * area)) - s * area) / area * 1.0, PETSC_COMM_SELF, PETSC_ERR_PLIB,
1676 "an outlet with nothing reversed must keep the uniform correction exactly");
1677 PetscCall(DestroyBoundaryHandler(&bc));
1678 }
1680 }
1681
1682 PetscCall(PicurvDestroyMinimalContexts(&simCtx, &user));
1683 PetscFunctionReturn(0);
1684}
static PetscErrorCode SetCellNormalVelocity(UserCtx *user, BCFace face, PetscInt k, PetscInt j, PetscInt i, PetscReal value)
Sets the face-normal Ucat component of one cell and refreshes lUcat.
static PetscErrorCode ApplyOutletAndMeasure(BoundaryCondition *bc, BCContext *ctx, BCFace face, PetscReal inflow, PetscReal outflow_measured, PetscReal *sample_flux, Cmpnts *sample_ubcs, PetscReal *total)
Runs one outlet Apply with the given sums and returns the face's sample flux and total.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TestOutletConservationClipFrozenPerStep()

static PetscErrorCode TestOutletConservationClipFrozenPerStep ( void  )
static

Tests that the backflow clip's rule and clipped set are frozen within a time step.

The decision is taken at the step's first Apply and held: a reversed face that recovers mid-step stays clipped, and a face that reverses mid-step after a no-clip decision keeps the uniform rule; both are re-decided when the step advances. Fails if the decision is re-taken on every Apply (which would make the Newton residual jump) or never re-taken.

Definition at line 1694 of file test_boundaries.c.

1695{
1696 const BCFace face = BC_FACE_POS_Z;
1697 SimCtx *simCtx = NULL;
1698 UserCtx *user = NULL;
1699 BoundaryCondition *bc = NULL;
1700 BCContext ctx;
1701 PetscInt ck, cj, ci, bk, bj, bi;
1702 PetscReal flux, total, area;
1703 Cmpnts ubcs;
1704
1705 PetscFunctionBeginUser;
1706 PetscCall(PetscMemzero(&ctx, sizeof(ctx)));
1707 PetscCall(PicurvCreateMinimalContexts(&simCtx, &user, 6, 6, 6));
1708 PetscCall(PicurvPopulateIdentityMetrics(user));
1709 area = GetFaceInteriorPointCount(user, face);
1710 simCtx->AreaOutSum = area;
1711 user->boundary_faces[face].face_id = face;
1714 ctx.user = user;
1715 ctx.face_id = face;
1716 PetscCall(GetRepresentativeFaceSlots(user, face, &ck, &cj, &ci, &bk, &bj, &bi));
1718
1719 /* Step 3 decides with a reversed face. */
1720 simCtx->step = 3;
1721 PetscCall(VecSet(user->Ucat, 1.0));
1722 PetscCall(SetCellNormalVelocity(user, face, ck, cj, ci, -0.5));
1723 PetscCall(ApplyOutletAndMeasure(bc, &ctx, face, area, area - 1.5, &flux, &ubcs, &total));
1724 PetscCall(PicurvAssertRealNear(0.0, flux, 1.0e-14, "step 3 clips the reversed face"));
1725
1726 /* Same step, the face recovers: still clipped, total still conserved. */
1727 PetscCall(SetCellNormalVelocity(user, face, ck, cj, ci, 1.0));
1728 PetscCall(ApplyOutletAndMeasure(bc, &ctx, face, area, area, &flux, &ubcs, &total));
1729 PetscCall(PicurvAssertRealNear(0.0, flux, 1.0e-14, "the clipped set is frozen within the step"));
1730 PetscCall(PicurvAssertRealNear(area, total, 1.0e-12, "a frozen clip still conserves the inflow"));
1731
1732 /* Step 4 re-decides: nothing reversed, uniform. */
1733 simCtx->step = 4;
1734 PetscCall(ApplyOutletAndMeasure(bc, &ctx, face, area, area, &flux, &ubcs, &total));
1735 PetscCall(PicurvAssertRealNear(1.0, flux, 1.0e-14, "a new step re-decides the rule"));
1736
1737 /* Same step, the face reverses: the uniform rule holds until the next step. */
1738 PetscCall(SetCellNormalVelocity(user, face, ck, cj, ci, -0.5));
1739 PetscCall(ApplyOutletAndMeasure(bc, &ctx, face, area, area - 1.5, &flux, &ubcs, &total));
1740 PetscCall(PicurvAssertRealNear(-0.5 + 1.5 / area, flux, 1.0e-14, "the uniform rule is frozen within the step"));
1741 PetscCall(PicurvAssertRealNear(area, total, 1.0e-12, "the uniform rule conserves the inflow"));
1742
1743 simCtx->step = 5;
1744 PetscCall(ApplyOutletAndMeasure(bc, &ctx, face, area, area - 1.5, &flux, &ubcs, &total));
1745 PetscCall(PicurvAssertRealNear(0.0, flux, 1.0e-14, "the next step clips the face that reversed"));
1746
1747 PetscCall(DestroyBoundaryHandler(&bc));
1749 PetscCall(PicurvDestroyMinimalContexts(&simCtx, &user));
1750 PetscFunctionReturn(0);
1751}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TestFinalizePostProjectionCellFieldsNonPeriodic()

static PetscErrorCode TestFinalizePostProjectionCellFieldsNonPeriodic ( void  )
static

Tests non-periodic cell-field finalization without modifying Ucont.

Definition at line 1756 of file test_boundaries.c.

1757{
1758 SimCtx *simCtx = NULL;
1759 UserCtx *user = NULL;
1760 Cmpnts ***ucat = NULL;
1761 Cmpnts ***lucat = NULL;
1762
1763 PetscFunctionBeginUser;
1764 PetscCall(PicurvCreateMinimalContexts(&simCtx, &user, 4, 4, 4));
1765 PetscCall(VecSet(user->Ucat, 4.0));
1766 PetscCall(VecSet(user->Bcs.Ubcs, 1.0));
1767 PetscCall(VecSet(user->P, 3.0));
1768 PetscCall(VecSet(user->Ucont, 7.0));
1769
1770 PetscCall(FinalizePostProjectionCellFields(user));
1771
1772 PetscCall(PicurvAssertVecConstant(user->Ucont, 7.0, 1.0e-12,
1773 "post-projection cell finalization must preserve non-periodic Ucont"));
1774 PetscCall(PicurvAssertVecConstant(user->P, 3.0, 1.0e-12,
1775 "constant pressure should remain unchanged during cell finalization"));
1776
1777 PetscCall(DMDAVecGetArrayRead(user->fda, user->Ucat, &ucat));
1778 PetscCall(DMDAVecGetArrayRead(user->fda, user->lUcat, &lucat));
1779 PetscCall(PicurvAssertRealNear(-2.0, ucat[2][2][0].x, 1.0e-12,
1780 "non-periodic Ucat dummy face should use Ubcs extrapolation"));
1781 PetscCall(PicurvAssertRealNear(-2.0, lucat[2][2][0].x, 1.0e-12,
1782 "non-periodic local Ucat should contain the finalized dummy face"));
1783 PetscCall(DMDAVecRestoreArrayRead(user->fda, user->Ucat, &ucat));
1784 PetscCall(DMDAVecRestoreArrayRead(user->fda, user->lUcat, &lucat));
1785
1786 PetscCall(PicurvDestroyMinimalContexts(&simCtx, &user));
1787 PetscFunctionReturn(0);
1788}
PetscErrorCode FinalizePostProjectionCellFields(UserCtx *user)
Finalizes cell-centered fields after the projection step.
PetscErrorCode PicurvAssertVecConstant(Vec vec, PetscScalar expected, PetscReal tol, const char *context)
Asserts that a PETSc vector is spatially constant within tolerance.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TestEnforceRHSBoundaryConditionsMatchesRowClassification()

static PetscErrorCode TestEnforceRHSBoundaryConditionsMatchesRowClassification ( void  )
static

EnforceRHSBoundaryConditions() must zero a row exactly when it is not an unknown.

This is the invariant that ties the residual path to ClassifyMomentumRow(). It is checked across a non-periodic, a singly-periodic and a fully-periodic configuration because the defect it guards against was visible only when an axis was periodic: the duplicate column at index 0 was left unzeroed, so ComputeTotalResidual()'s BDF term accumulated there on every call and the residual norm stopped describing the state. A sentinel fill makes an untouched row detectable rather than accidentally correct.

Definition at line 1800 of file test_boundaries.c.

1801{
1802 const struct {
1803 const char *label;
1804 PetscBool x_periodic, y_periodic, z_periodic;
1805 } configs[] = {
1806 {"non-periodic", PETSC_FALSE, PETSC_FALSE, PETSC_FALSE},
1807 {"xi-periodic", PETSC_TRUE, PETSC_FALSE, PETSC_FALSE},
1808 {"fully-periodic", PETSC_TRUE, PETSC_TRUE, PETSC_TRUE },
1809 };
1810 const PetscScalar sentinel = 7.0;
1811
1812 PetscFunctionBeginUser;
1813 for (size_t c = 0; c < sizeof(configs) / sizeof(configs[0]); ++c) {
1814 SimCtx *simCtx = NULL;
1815 UserCtx *user = NULL;
1816 Cmpnts ***rhs = NULL;
1817 const PetscBool periodic[3] = {configs[c].x_periodic, configs[c].y_periodic, configs[c].z_periodic};
1818 const BCFace neg_face[3] = {BC_FACE_NEG_X, BC_FACE_NEG_Y, BC_FACE_NEG_Z};
1819 const BCFace pos_face[3] = {BC_FACE_POS_X, BC_FACE_POS_Y, BC_FACE_POS_Z};
1820
1821 PetscCall(PicurvCreateMinimalContextsWithPeriodicity(&simCtx, &user, 6, 6, 6,
1822 configs[c].x_periodic,
1823 configs[c].y_periodic,
1824 configs[c].z_periodic));
1825 for (PetscInt axis = 0; axis < 3; ++axis) {
1826 const BCType type = periodic[axis] ? PERIODIC : WALL;
1827 user->boundary_faces[neg_face[axis]].mathematical_type = type;
1828 user->boundary_faces[pos_face[axis]].mathematical_type = type;
1829 }
1830
1831 PetscCall(VecDuplicate(user->Ucont, &user->Rhs));
1832 PetscCall(VecSet(user->Rhs, sentinel));
1833 PetscCall(EnforceRHSBoundaryConditions(user));
1834
1835 PetscCall(DMDAVecGetArrayRead(user->fda, user->Rhs, &rhs));
1836 for (PetscInt k = user->info.zs; k < user->info.zs + user->info.zm; ++k) {
1837 for (PetscInt j = user->info.ys; j < user->info.ys + user->info.ym; ++j) {
1838 for (PetscInt i = user->info.xs; i < user->info.xs + user->info.xm; ++i) {
1839 const PetscScalar *row = &rhs[k][j][i].x;
1840 for (PetscInt component = 0; component < 3; ++component) {
1841 PetscInt ri, rj, rk;
1842 const MomentumRowType type =
1843 ClassifyMomentumRow(user, i, j, k, component, &ri, &rj, &rk);
1844 const PetscScalar expected = (type == MOM_ROW_PHYSICAL) ? sentinel : 0.0;
1845 char context[192];
1846
1847 PetscCall(PetscSNPrintf(context, sizeof(context),
1848 "%s: row (i=%d,j=%d,k=%d,c=%d) classified %d must be %s",
1849 configs[c].label, (int)i, (int)j, (int)k, (int)component, (int)type,
1850 (type == MOM_ROW_PHYSICAL) ? "left untouched" : "zeroed"));
1851 PetscCall(PicurvAssertRealNear((PetscReal)expected, (PetscReal)row[component],
1852 1.0e-14, context));
1853 }
1854 }
1855 }
1856 }
1857 PetscCall(DMDAVecRestoreArrayRead(user->fda, user->Rhs, &rhs));
1858
1859 PetscCall(VecDestroy(&user->Rhs));
1860 PetscCall(PicurvDestroyMinimalContexts(&simCtx, &user));
1861 }
1862 PetscFunctionReturn(0);
1863}
MomentumRowType
Classification of one staggered momentum row (location + component).
Definition Boundaries.h:191
@ MOM_ROW_PHYSICAL
Independent unknown governed by the momentum equation.
Definition Boundaries.h:192
MomentumRowType ClassifyMomentumRow(UserCtx *user, PetscInt i, PetscInt j, PetscInt k, PetscInt component, PetscInt *ri, PetscInt *rj, PetscInt *rk)
Single source of truth for "which staggered momentum rows are unknowns".
Definition Boundaries.c:139
PetscErrorCode EnforceRHSBoundaryConditions(UserCtx *user)
Zeroes every momentum RHS row that does not carry an independent unknown.
Definition Boundaries.c:224
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.
BCType
Defines the general mathematical/physical Category of a boundary.
Definition variables.h:316
@ PERIODIC
Definition variables.h:325
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SeedWallFrictionVelocityStorage()

static PetscErrorCode SeedWallFrictionVelocityStorage ( UserCtx *  user)
static

Allocates the wall-model storage the way production allocates it.

Production creates each global on da and ghosts it into the local view. A fixture that allocates differently - a different DM, only one of a pair, or only one of the fields the same block creates - tests a layout the solver never uses, which is how a DM/dof mismatch survived in ApplyWallFunction while these cases passed. The wall eddy viscosity is allocated in that same block and cleared at the top of every pass, so a fixture omitting it dereferences a null vector before reaching any assertion. Every wall case routes through here so the two cannot drift.

Definition at line 1876 of file test_boundaries.c.

1877{
1878 PetscFunctionBeginUser;
1879 PetscCall(DMCreateGlobalVector(user->da, &user->Friction_Velocity));
1880 PetscCall(VecSet(user->Friction_Velocity, 0.0));
1881 PetscCall(DMCreateLocalVector(user->da, &user->lFriction_Velocity));
1882 PetscCall(VecSet(user->lFriction_Velocity, 0.0));
1883 PetscCall(DMCreateGlobalVector(user->fda, &user->Wall_Stress));
1884 PetscCall(VecSet(user->Wall_Stress, 0.0));
1885 PetscCall(DMCreateLocalVector(user->fda, &user->lWall_Stress));
1886 PetscCall(VecSet(user->lWall_Stress, 0.0));
1887 PetscFunctionReturn(0);
1888}
Vec lFriction_Velocity
Definition variables.h:1189
Vec Wall_Stress
Definition variables.h:1193
Vec lWall_Stress
Definition variables.h:1193
Vec Friction_Velocity
Definition variables.h:1189
Here is the caller graph for this function:

◆ SeedWallFunctionFixture()

static PetscErrorCode SeedWallFunctionFixture ( UserCtx *  user,
Cmpnts  velocity 
)
static

Seeds the fields ApplyWallFunction() reads, for walls on xi and eta faces.

A uniform velocity and unit metrics on both wall orientations make the wall distances and face normals analytically known, so the test can reproduce the model's own arithmetic without copying the integration's index choices.

Definition at line 1897 of file test_boundaries.c.

1898{
1899 Cmpnts ***ucat = NULL, ***csi = NULL, ***eta = NULL;
1900 PetscReal ***aj = NULL;
1901 DMDALocalInfo info = user->info;
1902
1903 PetscFunctionBeginUser;
1904 PetscCall(VecSet(user->Aj, 1.0));
1905 PetscCall(DMDAVecGetArray(user->fda, user->Ucat, &ucat));
1906 PetscCall(DMDAVecGetArray(user->fda, user->Csi, &csi));
1907 PetscCall(DMDAVecGetArray(user->fda, user->Eta, &eta));
1908 PetscCall(DMDAVecGetArray(user->da, user->Aj, &aj));
1909 for (PetscInt k = info.zs; k < info.zs + info.zm; ++k)
1910 for (PetscInt j = info.ys; j < info.ys + info.ym; ++j)
1911 for (PetscInt i = info.xs; i < info.xs + info.xm; ++i) {
1912 ucat[k][j][i] = velocity;
1913 csi[k][j][i] = (Cmpnts){.x = 1.0, .y = 0.0, .z = 0.0};
1914 eta[k][j][i] = (Cmpnts){.x = 0.0, .y = 1.0, .z = 0.0};
1915 aj[k][j][i] = 1.0;
1916 }
1917 PetscCall(DMDAVecRestoreArray(user->da, user->Aj, &aj));
1918 PetscCall(DMDAVecRestoreArray(user->fda, user->Eta, &eta));
1919 PetscCall(DMDAVecRestoreArray(user->fda, user->Csi, &csi));
1920 PetscCall(DMDAVecRestoreArray(user->fda, user->Ucat, &ucat));
1921 PetscCall(DMGlobalToLocalBegin(user->da, user->Aj, INSERT_VALUES, user->lAj));
1922 PetscCall(DMGlobalToLocalEnd(user->da, user->Aj, INSERT_VALUES, user->lAj));
1923 PetscCall(DMGlobalToLocalBegin(user->fda, user->Csi, INSERT_VALUES, user->lCsi));
1924 PetscCall(DMGlobalToLocalEnd(user->fda, user->Csi, INSERT_VALUES, user->lCsi));
1925 PetscCall(DMGlobalToLocalBegin(user->fda, user->Eta, INSERT_VALUES, user->lEta));
1926 PetscCall(DMGlobalToLocalEnd(user->fda, user->Eta, INSERT_VALUES, user->lEta));
1927 PetscFunctionReturn(PETSC_SUCCESS);
1928}
Here is the caller graph for this function:

◆ TestApplyWallFunctionMatchesTheLogLawItDispatches()

static PetscErrorCode TestApplyWallFunctionMatchesTheLogLawItDispatches ( void  )
static

Tests that the wall-function integration reproduces the model it dispatches to.

The kernels are covered separately; what is unverified without this is the wiring around them, where the plausible failures are silent. Feeding the reference and boundary wall distances in the wrong order, taking the reference velocity from the wrong cell, or orienting the stress wrongly all still produce a plausible-looking stress. The checks here: the stored friction velocity inverts the log law at the reference cell's distance; the stored stress is u_tau^2 along the flow, in the face's dummy cell; and the resolved velocity is left exactly as it was.

Definition at line 1941 of file test_boundaries.c.

1942{
1943 SimCtx *simCtx = NULL;
1944 UserCtx *user = NULL;
1945 Cmpnts ***ucat = NULL, ***ubcs = NULL;
1946 PetscReal ***utau = NULL;
1947 const PetscReal speed = 1.0;
1948 const PetscReal roughness = 1.0e-16; /* smooth wall */
1949 PetscReal kinematic_viscosity, distance_first, distance_second;
1950 PetscReal stored_utau, reference_check, first_speed, stored_stress;
1951 Cmpnts ***stress = NULL;
1952 PetscReal untouched_before = 0.0, untouched_after = 0.0;
1953
1954 PetscFunctionBeginUser;
1955 PetscCall(PicurvCreateMinimalContexts(&simCtx, &user, 6, 6, 6));
1956 simCtx->ren = 1000.0;
1957 simCtx->wall_roughness_height = roughness;
1958 kinematic_viscosity = 1.0 / simCtx->ren;
1959
1960 PetscCall(SeedWallFrictionVelocityStorage(user));
1962 PetscCall(SeedWallFunctionFixture(user, (Cmpnts){.x = 0.0, .y = speed, .z = 0.0}));
1963
1964 /* With unit Jacobians and a unit face area the model's distances are exact:
1965 the first cell centre sits half a cell from the wall, the second one and a
1966 half. Reproducing them here rather than reading them back is what makes a
1967 swapped-distance wiring error detectable. */
1968 distance_first = 0.5;
1969 distance_second = 2.0 * distance_first + 0.5;
1970
1971 /* Disabled: the routine must not touch the field at all. */
1972 simCtx->wallfunction = 0;
1973 PetscCall(DMDAVecGetArrayRead(user->fda, user->Ucat, (const Cmpnts ***)&ucat));
1974 untouched_before = ucat[2][2][1].y;
1975 PetscCall(DMDAVecRestoreArrayRead(user->fda, user->Ucat, (const Cmpnts ***)&ucat));
1976 PetscCall(ApplyWallFunction(user));
1977 PetscCall(DMDAVecGetArrayRead(user->fda, user->Ucat, (const Cmpnts ***)&ucat));
1978 untouched_after = ucat[2][2][1].y;
1979 PetscCall(DMDAVecRestoreArrayRead(user->fda, user->Ucat, (const Cmpnts ***)&ucat));
1980 PetscCall(PicurvAssertRealNear(untouched_before, untouched_after, 0.0,
1981 "a disabled wall function must leave the velocity untouched"));
1982
1983 /* Enabled: the law is evaluated and its stress stored; the velocity is not modified. */
1984 simCtx->wallfunction = 1;
1985 PetscCall(ApplyWallFunction(user));
1986
1987 PetscCall(DMDAVecGetArrayRead(user->da, user->Friction_Velocity, (const PetscReal ***)&utau));
1988 stored_utau = utau[2][2][1];
1989 PetscCall(DMDAVecRestoreArrayRead(user->da, user->Friction_Velocity, (const PetscReal ***)&utau));
1990 PetscCall(PicurvAssertBool((PetscBool)(stored_utau > 0.0),
1991 "the integration must store a positive friction velocity"));
1992
1993 /* The stored friction velocity must be the one that reproduces the *reference*
1994 cell's speed at the *reference* distance. Swapping the two distances passes the
1995 next check but fails this one. */
1996 reference_check = u_hydset_roughness(kinematic_viscosity, distance_second,
1997 stored_utau, roughness);
1998 PetscCall(PicurvAssertRealNear(speed, reference_check, 1.0e-6,
1999 "the friction velocity must invert the log law at the "
2000 "reference cell's distance"));
2001
2002 PetscCall(DMDAVecGetArrayRead(user->fda, user->Ucat, (const Cmpnts ***)&ucat));
2003 first_speed = ucat[2][2][1].y;
2004 PetscCall(DMDAVecRestoreArrayRead(user->fda, user->Ucat, (const Cmpnts ***)&ucat));
2005 PetscCall(PicurvAssertRealNear(speed, first_speed, 0.0,
2006 "the wall model must leave the resolved first-cell velocity untouched"));
2007
2008 /* The -Xi face's dummy cell holds the stress, oriented as that face's flux: +u_tau^2
2009 along the flow (the first cell's term is minus it, a drag). */
2010 PetscCall(DMDAVecGetArrayRead(user->fda, user->Wall_Stress, (const Cmpnts ***)&stress));
2011 stored_stress = stress[2][2][0].y;
2012 PetscCall(PicurvAssertRealNear(0.0, stress[2][2][0].x, 0.0, "the stress has no wall-normal part"));
2013 PetscCall(PicurvAssertRealNear(0.0, stress[2][2][0].z, 0.0, "the stress follows the flow direction"));
2014 PetscCall(DMDAVecRestoreArrayRead(user->fda, user->Wall_Stress, (const Cmpnts ***)&stress));
2015 PetscCall(PicurvAssertRealNear(stored_utau * stored_utau, stored_stress, 1.0e-12,
2016 "the stored stress must be u_tau^2 along the flow"));
2017 (void)distance_first;
2018
2019 /* The ghost row carries no boundary velocity of its own. */
2020 PetscCall(DMDAVecGetArrayRead(user->fda, user->Bcs.Ubcs, (const Cmpnts ***)&ubcs));
2021 PetscCall(PicurvAssertRealNear(0.0, ubcs[2][2][0].y, 0.0,
2022 "the wall ghost row must carry a zero boundary velocity"));
2023 PetscCall(DMDAVecRestoreArrayRead(user->fda, user->Bcs.Ubcs, (const Cmpnts ***)&ubcs));
2024
2025 PetscCall(VecDestroy(&user->Friction_Velocity));
2026 PetscCall(VecDestroy(&user->lFriction_Velocity));
2027 PetscCall(VecDestroy(&user->Wall_Stress));
2028 PetscCall(VecDestroy(&user->lWall_Stress));
2029 PetscCall(PicurvDestroyMinimalContexts(&simCtx, &user));
2030 PetscFunctionReturn(0);
2031}
PetscErrorCode ApplyWallFunction(UserCtx *user)
Evaluates the selected wall law on every wall-face element and stores the wall stress.
static PetscErrorCode SeedWallFrictionVelocityStorage(UserCtx *user)
Allocates the wall-model storage the way production allocates it.
static PetscErrorCode SeedWallFunctionFixture(UserCtx *user, Cmpnts velocity)
Seeds the fields ApplyWallFunction() reads, for walls on xi and eta faces.
PetscReal ren
Definition variables.h:965
PetscReal wall_roughness_height
Definition variables.h:1004
PetscInt wallfunction
Enable wall functions on WALL faces.
Definition variables.h:1042
double u_hydset_roughness(double kinematic_viscosity, double wall_distance, double friction_velocity, double roughness_height)
Computes velocity from log-law for rough walls.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TestWallFunctionModelSelectorChoosesTheLaw()

static PetscErrorCode TestWallFunctionModelSelectorChoosesTheLaw ( void  )
static

Tests that the model selector actually changes which law is applied.

The selector was previously validated in the configuration layer and then dropped, so every case ran the log law whatever it asked for. Distinct laws must produce distinct friction velocities from identical inputs, or the selector is decorative again.

Definition at line 2040 of file test_boundaries.c.

2041{
2042 SimCtx *simCtx = NULL;
2043 UserCtx *user = NULL;
2044 PetscReal ***utau = NULL;
2045 PetscReal corrected[4] = {0.0, 0.0, 0.0, 0.0};
2046 const PetscInt models[3] = {WALL_FUNCTION_LOG_LAW, WALL_FUNCTION_WERNER, WALL_FUNCTION_CABOT};
2047
2048 PetscFunctionBeginUser;
2049 PetscCall(PicurvCreateMinimalContexts(&simCtx, &user, 6, 6, 6));
2050 simCtx->ren = 1000.0;
2051 simCtx->wall_roughness_height = 1.0e-16;
2052 PetscCall(SeedWallFrictionVelocityStorage(user));
2054
2055 for (PetscInt m = 0; m < 3; ++m) {
2056 PetscCall(SeedWallFunctionFixture(user, (Cmpnts){.x = 0.0, .y = 1.0, .z = 0.0}));
2057 simCtx->wallfunction = models[m];
2058 PetscCall(ApplyWallFunction(user));
2059 PetscCall(DMDAVecGetArrayRead(user->da, user->Friction_Velocity, (const PetscReal ***)&utau));
2060 corrected[m] = utau[2][2][1];
2061 PetscCall(DMDAVecRestoreArrayRead(user->da, user->Friction_Velocity, (const PetscReal ***)&utau));
2062 PetscCall(PicurvAssertBool((PetscBool)(corrected[m] > 0.0 && corrected[m] < 1.0),
2063 "every wall model must report a friction velocity below the flow speed"));
2064 }
2065
2066 /* Each law has its own profile, so no two may coincide. */
2067 PetscCall(PicurvAssertBool((PetscBool)(PetscAbsReal(corrected[0] - corrected[1]) > 1.0e-9),
2068 "the Werner-Wengle model must differ from the log law"));
2069 PetscCall(PicurvAssertBool((PetscBool)(PetscAbsReal(corrected[0] - corrected[2]) > 1.0e-9),
2070 "the Cabot model must differ from the log law"));
2071
2072 PetscCall(VecDestroy(&user->Friction_Velocity));
2073 PetscCall(VecDestroy(&user->lFriction_Velocity));
2074 PetscCall(VecDestroy(&user->Wall_Stress));
2075 PetscCall(VecDestroy(&user->lWall_Stress));
2076 PetscCall(PicurvDestroyMinimalContexts(&simCtx, &user));
2077 PetscFunctionReturn(0);
2078}
@ WALL_FUNCTION_CABOT
Definition variables.h:604
@ WALL_FUNCTION_LOG_LAW
Definition variables.h:602
@ WALL_FUNCTION_WERNER
Definition variables.h:603
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TestApplyWallFunctionSkipsNonWallFaces()

static PetscErrorCode TestApplyWallFunctionSkipsNonWallFaces ( void  )
static

Tests that a face which is not a wall is left alone by the wall function.

Definition at line 2083 of file test_boundaries.c.

2084{
2085 SimCtx *simCtx = NULL;
2086 UserCtx *user = NULL;
2087 Cmpnts ***ucat = NULL;
2088 PetscReal before = 0.0, after = 0.0;
2089
2090 PetscFunctionBeginUser;
2091 PetscCall(PicurvCreateMinimalContexts(&simCtx, &user, 6, 6, 6));
2092 simCtx->ren = 1000.0;
2093 simCtx->wallfunction = 1;
2094 simCtx->wall_roughness_height = 1.0e-16;
2095 PetscCall(SeedWallFrictionVelocityStorage(user));
2096 /* Every face left at its default, so none is a wall. */
2097 PetscCall(SeedWallFunctionFixture(user, (Cmpnts){.x = 0.0, .y = 1.0, .z = 0.0}));
2098
2099 PetscCall(DMDAVecGetArrayRead(user->fda, user->Ucat, (const Cmpnts ***)&ucat));
2100 before = ucat[2][2][1].y;
2101 PetscCall(DMDAVecRestoreArrayRead(user->fda, user->Ucat, (const Cmpnts ***)&ucat));
2102 PetscCall(ApplyWallFunction(user));
2103 PetscCall(DMDAVecGetArrayRead(user->fda, user->Ucat, (const Cmpnts ***)&ucat));
2104 after = ucat[2][2][1].y;
2105 PetscCall(DMDAVecRestoreArrayRead(user->fda, user->Ucat, (const Cmpnts ***)&ucat));
2106
2107 PetscCall(PicurvAssertRealNear(before, after, 0.0,
2108 "a face that is not a wall must not be corrected"));
2109 {
2110 PetscReal stress_norm = 0.0;
2111 PetscCall(VecNorm(user->Wall_Stress, NORM_INFINITY, &stress_norm));
2112 PetscCall(PicurvAssertRealNear(0.0, stress_norm, 0.0, "a face that is not a wall carries no wall stress"));
2113 }
2114
2115 PetscCall(VecDestroy(&user->Friction_Velocity));
2116 PetscCall(VecDestroy(&user->lFriction_Velocity));
2117 PetscCall(VecDestroy(&user->Wall_Stress));
2118 PetscCall(VecDestroy(&user->lWall_Stress));
2119 PetscCall(PicurvDestroyMinimalContexts(&simCtx, &user));
2120 PetscFunctionReturn(0);
2121}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TestApplyWallFunctionSkipsFreeSlipWalls()

static PetscErrorCode TestApplyWallFunctionSkipsFreeSlipWalls ( void  )
static

Tests that the wall model leaves a free-slip wall alone.

Definition at line 2126 of file test_boundaries.c.

2127{
2128 SimCtx *simCtx = NULL;
2129 UserCtx *user = NULL;
2130 Cmpnts ***ucat = NULL;
2131 PetscReal before = 0.0, after = 0.0;
2132
2133 PetscFunctionBeginUser;
2134 PetscCall(PicurvCreateMinimalContexts(&simCtx, &user, 6, 6, 6));
2135 simCtx->ren = 1000.0;
2136 simCtx->wallfunction = 1;
2137 simCtx->wall_roughness_height = 1.0e-16;
2138 PetscCall(SeedWallFrictionVelocityStorage(user));
2141 PetscCall(SeedWallFunctionFixture(user, (Cmpnts){.x = 0.0, .y = 1.0, .z = 0.0}));
2142
2143 PetscCall(DMDAVecGetArrayRead(user->fda, user->Ucat, (const Cmpnts ***)&ucat));
2144 before = ucat[2][2][1].y;
2145 PetscCall(DMDAVecRestoreArrayRead(user->fda, user->Ucat, (const Cmpnts ***)&ucat));
2146 PetscCall(ApplyWallFunction(user));
2147 PetscCall(DMDAVecGetArrayRead(user->fda, user->Ucat, (const Cmpnts ***)&ucat));
2148 after = ucat[2][2][1].y;
2149 PetscCall(DMDAVecRestoreArrayRead(user->fda, user->Ucat, (const Cmpnts ***)&ucat));
2150 PetscCall(PicurvAssertRealNear(before, after, 0.0, "a free-slip wall carries no wall model"));
2151 {
2152 PetscReal stress_norm = 0.0;
2153 PetscCall(VecNorm(user->Wall_Stress, NORM_INFINITY, &stress_norm));
2154 PetscCall(PicurvAssertRealNear(0.0, stress_norm, 0.0, "a free-slip wall carries no wall stress"));
2155 }
2156
2157 PetscCall(VecDestroy(&user->Friction_Velocity));
2158 PetscCall(VecDestroy(&user->lFriction_Velocity));
2159 PetscCall(VecDestroy(&user->Wall_Stress));
2160 PetscCall(VecDestroy(&user->lWall_Stress));
2161 PetscCall(PicurvDestroyMinimalContexts(&simCtx, &user));
2162 PetscFunctionReturn(0);
2163}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TestWallModelFrictionVelocityRespondsToTheFlow()

static PetscErrorCode TestWallModelFrictionVelocityRespondsToTheFlow ( void  )
static

Tests that every wall law's friction velocity responds to the flow it is given.

A law that ignores the resolved velocity and reports a fixed number still slows the first cell and still differs from the other laws, so the selector test above passes over it. Driving a law at two different speeds and requiring the friction velocity to follow is what distinguishes a model from a constant.

All three laws are covered. Werner-Wengle is the reason this case exists: it used to report its Newton initial guess rather than solving, so every wall cell in a run carried the same u_tau while still slowing the cell and still differing from the other laws, which is everything the selector test above checks.

Definition at line 2178 of file test_boundaries.c.

2179{
2180 SimCtx *simCtx = NULL;
2181 UserCtx *user = NULL;
2182 PetscReal ***utau = NULL;
2183 const PetscInt models[3] = {WALL_FUNCTION_LOG_LAW, WALL_FUNCTION_WERNER,
2185 const char *names[3] = {"the log law must respond to the flow it is given",
2186 "Werner-Wengle must respond to the flow it is given",
2187 "Cabot must respond to the flow it is given"};
2188 const PetscReal speeds[2] = {0.5, 2.0};
2189
2190 PetscFunctionBeginUser;
2191 PetscCall(PicurvCreateMinimalContexts(&simCtx, &user, 6, 6, 6));
2192 simCtx->ren = 1000.0;
2193 simCtx->wall_roughness_height = 1.0e-16;
2194 PetscCall(SeedWallFrictionVelocityStorage(user));
2196
2197 for (PetscInt m = 0; m < 3; ++m) {
2198 PetscReal stored[2] = {0.0, 0.0};
2199
2200 simCtx->wallfunction = models[m];
2201 for (PetscInt s = 0; s < 2; ++s) {
2202 PetscCall(SeedWallFunctionFixture(user, (Cmpnts){.x = 0.0, .y = speeds[s], .z = 0.0}));
2203 PetscCall(ApplyWallFunction(user));
2204 PetscCall(DMDAVecGetArrayRead(user->da, user->Friction_Velocity,
2205 (const PetscReal ***)&utau));
2206 stored[s] = utau[2][2][1];
2207 PetscCall(DMDAVecRestoreArrayRead(user->da, user->Friction_Velocity,
2208 (const PetscReal ***)&utau));
2209 PetscCall(PicurvAssertBool((PetscBool)(stored[s] > 0.0),
2210 "a wall law must report a positive friction velocity"));
2211 }
2212
2213 /* Faster flow, more wall stress. Any law that reports its initial guess, or any
2214 other constant, fails here whatever that constant is. */
2215 PetscCall(PicurvAssertBool((PetscBool)(stored[1] > stored[0] * 1.05),
2216 names[m]));
2217 }
2218
2219 PetscCall(VecDestroy(&user->Friction_Velocity));
2220 PetscCall(VecDestroy(&user->lFriction_Velocity));
2221 PetscCall(VecDestroy(&user->Wall_Stress));
2222 PetscCall(VecDestroy(&user->lWall_Stress));
2223 PetscCall(PicurvDestroyMinimalContexts(&simCtx, &user));
2224 PetscFunctionReturn(0);
2225}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TestWallFrictionVelocityStorageMatchesTheCatalog()

static PetscErrorCode TestWallFrictionVelocityStorageMatchesTheCatalog ( void  )
static

Tests that the friction-velocity storage matches what the field catalog declares.

The wall model reaches its storage through a DM, and PETSc only rejects a mismatched DM/vector pairing at the moment of access - inside a branch that runs only when wall functions are enabled on a case that has a WALL face. That is how storage created from a dof-3 DM and read through a dof-1 one stayed latent. Comparing the allocation against the catalog descriptor turns that into a failure here.

Definition at line 2236 of file test_boundaries.c.

2237{
2238 SimCtx *simCtx = NULL;
2239 UserCtx *user = NULL;
2240 const FieldDescriptor *descriptor = NULL;
2241 FieldView view;
2242 PetscInt global_size = 0, local_size = 0;
2243 PetscInt xm = 0, ym = 0, zm = 0, gxm = 0, gym = 0, gzm = 0;
2244 PetscReal ***utau = NULL;
2245
2246 PetscFunctionBeginUser;
2247 PetscCall(PicurvCreateMinimalContexts(&simCtx, &user, 6, 6, 6));
2248 PetscCall(SeedWallFrictionVelocityStorage(user));
2249
2250 PetscCall(FieldGetDescriptor(FIELD_ID_U_TAU, &descriptor));
2251 PetscCall(PicurvAssertBool((PetscBool)(descriptor->dof == 1),
2252 "the friction velocity is one scalar per cell"));
2253 PetscCall(PicurvAssertBool((PetscBool)(descriptor->dm_kind == FIELD_DM_DA),
2254 "a scalar cell field belongs on the dof-1 DM"));
2255
2256 PetscCall(FieldGetView(user, FIELD_ID_U_TAU, &view));
2257 PetscCall(PicurvAssertBool((PetscBool)(view.global_vec == user->Friction_Velocity &&
2258 view.local_vec == user->lFriction_Velocity),
2259 "the catalog must resolve to the vectors setup allocated"));
2260
2261 /* The sizes the DM implies, against the sizes the vectors actually have. */
2262 PetscCall(DMDAGetCorners(user->da, NULL, NULL, NULL, &xm, &ym, &zm));
2263 PetscCall(DMDAGetGhostCorners(user->da, NULL, NULL, NULL, &gxm, &gym, &gzm));
2264 PetscCall(VecGetLocalSize(user->Friction_Velocity, &global_size));
2265 PetscCall(VecGetLocalSize(user->lFriction_Velocity, &local_size));
2266 PetscCall(PicurvAssertBool((PetscBool)(global_size == xm * ym * zm * descriptor->dof),
2267 "the global friction velocity must match the owned extent"));
2268 PetscCall(PicurvAssertBool((PetscBool)(local_size == gxm * gym * gzm * descriptor->dof),
2269 "the local friction velocity must match the ghosted extent"));
2270
2271 /* The access the wall model itself performs. A mismatched pairing fails right here. */
2272 PetscCall(DMDAVecGetArray(user->da, user->Friction_Velocity, &utau));
2273 PetscCall(DMDAVecRestoreArray(user->da, user->Friction_Velocity, &utau));
2274
2275 /* The wall stress is a vector per wall-face element, on the dof-3 DM. */
2276 PetscCall(FieldGetDescriptor(FIELD_ID_WALL_STRESS, &descriptor));
2277 PetscCall(PicurvAssertBool((PetscBool)(descriptor->dof == 3 && descriptor->dm_kind == FIELD_DM_FDA),
2278 "the wall stress is a vector on the dof-3 DM"));
2279 PetscCall(FieldGetView(user, FIELD_ID_WALL_STRESS, &view));
2280 PetscCall(PicurvAssertBool((PetscBool)(view.global_vec == user->Wall_Stress &&
2281 view.local_vec == user->lWall_Stress),
2282 "the catalog must resolve to the wall-stress vectors setup allocated"));
2283 {
2284 Cmpnts ***stress = NULL;
2285 PetscCall(DMDAVecGetArray(user->fda, user->Wall_Stress, &stress));
2286 PetscCall(DMDAVecRestoreArray(user->fda, user->Wall_Stress, &stress));
2287 }
2288
2289 PetscCall(VecDestroy(&user->Friction_Velocity));
2290 PetscCall(VecDestroy(&user->lFriction_Velocity));
2291 PetscCall(VecDestroy(&user->Wall_Stress));
2292 PetscCall(VecDestroy(&user->lWall_Stress));
2293 PetscCall(PicurvDestroyMinimalContexts(&simCtx, &user));
2294 PetscFunctionReturn(0);
2295}
PetscErrorCode FieldGetView(UserCtx *user, FieldId field_id, FieldView *view)
Resolve the existing DM and global/local vectors for one field.
FieldDMKind dm_kind
PetscErrorCode FieldGetDescriptor(FieldId field_id, const FieldDescriptor **descriptor)
Return immutable metadata for a valid field identifier.
@ FIELD_DM_FDA
@ FIELD_DM_DA
@ FIELD_ID_U_TAU
@ FIELD_ID_WALL_STRESS
Immutable metadata for one field identity.
Non-owning runtime objects resolved for one field and UserCtx.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TestWallModelEdgeCellHasOneStressPerWall()

static PetscErrorCode TestWallModelEdgeCellHasOneStressPerWall ( void  )
static

Tests that a cell beside two walls gets one independent stress per wall face.

The edge cell is where the previous design overwrote one velocity twice, the second wall reading the first wall's output as its reference. Here each face must store its own stress in its own dummy cell from its own reference cell, the resolved velocity must not move, the cell's friction velocity must be the RMS over its two faces, and each face element must count once in the diagnostics.

Definition at line 2306 of file test_boundaries.c.

2307{
2308 SimCtx *simCtx = NULL;
2309 UserCtx *user = NULL;
2310 Cmpnts ***ucat = NULL, ***stress = NULL;
2311 PetscReal ***utau = NULL;
2312 const PetscReal speed = 1.0;
2313 DMDALocalInfo info;
2314
2315 PetscFunctionBeginUser;
2316 PetscCall(PicurvCreateMinimalContexts(&simCtx, &user, 6, 6, 6));
2317 simCtx->ren = 1000.0;
2318 simCtx->wall_roughness_height = 1.0e-16;
2320 PetscCall(SeedWallFrictionVelocityStorage(user));
2323 info = user->info;
2324
2325 /* Flow along zeta, tangential to both walls. */
2326 PetscCall(SeedWallFunctionFixture(user, (Cmpnts){.x = 0.0, .y = 0.0, .z = speed}));
2327
2328 PetscCall(ApplyWallFunction(user));
2329
2330 PetscCall(DMDAVecGetArrayRead(user->fda, user->Ucat, (const Cmpnts ***)&ucat));
2331 PetscCall(PicurvAssertRealNear(speed, ucat[2][1][1].z, 0.0, "the edge cell's resolved velocity must not move"));
2332 PetscCall(DMDAVecRestoreArrayRead(user->fda, user->Ucat, (const Cmpnts ***)&ucat));
2333
2334 PetscCall(DMDAVecGetArrayRead(user->fda, user->Wall_Stress, (const Cmpnts ***)&stress));
2335 PetscCall(DMDAVecGetArrayRead(user->da, user->Friction_Velocity, (const PetscReal ***)&utau));
2336 {
2337 /* Uniform flow: both walls see the same reference speed at the same distance, so
2338 each stores the same stress, and the cell's RMS equals either face's u_tau. */
2339 const PetscReal x_wall = stress[2][1][0].z; /* -Xi face of cell (i=1, j=1) */
2340 const PetscReal y_wall = stress[2][0][1].z; /* -Eta face of the same cell */
2341 PetscCall(PicurvAssertBool((PetscBool)(x_wall > 0.0 && y_wall > 0.0),
2342 "both wall faces of the edge cell must carry a stress along the flow"));
2343 PetscCall(PicurvAssertRealNear(x_wall, y_wall, 1.0e-12,
2344 "each face must read its own unmodified reference, so the two agree"));
2345 PetscCall(PicurvAssertRealNear(PetscSqrtReal(x_wall), utau[2][1][1], 1.0e-12,
2346 "the edge cell's friction velocity is the RMS over its wall faces"));
2347 PetscCall(PicurvAssertRealNear(x_wall, stress[2][2][0].z, 1.0e-12,
2348 "the edge cell's -Xi stress must equal a mid-face element's"));
2349 }
2350 PetscCall(DMDAVecRestoreArrayRead(user->da, user->Friction_Velocity, (const PetscReal ***)&utau));
2351 PetscCall(DMDAVecRestoreArrayRead(user->fda, user->Wall_Stress, (const Cmpnts ***)&stress));
2352
2353 /* (my-2)(mz-2) elements on the -Xi face and (mx-2)(mz-2) on the -Eta face. */
2354 PetscCall(PicurvAssertBool((PetscBool)(user->wall_diagnostics.cells ==
2355 (info.my - 2) * (info.mz - 2) + (info.mx - 2) * (info.mz - 2)),
2356 "each wall-face element must count once in the diagnostics"));
2357
2358 PetscCall(VecDestroy(&user->Friction_Velocity));
2359 PetscCall(VecDestroy(&user->lFriction_Velocity));
2360 PetscCall(VecDestroy(&user->Wall_Stress));
2361 PetscCall(VecDestroy(&user->lWall_Stress));
2362 PetscCall(PicurvDestroyMinimalContexts(&simCtx, &user));
2363 PetscFunctionReturn(0);
2364}
PetscInt cells
Number of cells this rank corrected.
Definition variables.h:718
WallModelDiagnosticsState wall_diagnostics
Near-wall statistics from the last wall-model pass.
Definition variables.h:1261
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TestWallModelDiagnosticsRecordTheCorrectedCells()

static PetscErrorCode TestWallModelDiagnosticsRecordTheCorrectedCells ( void  )
static

Tests that the wall pass records the statistics its diagnostics report.

y+ cannot be recovered downstream, so it is formed where the wall distance is still in hand. This checks that what is accumulated there is the same quantity the reported column claims to be, and that a pass over no wall face records nothing rather than recording zeros.

Definition at line 2374 of file test_boundaries.c.

2375{
2376 SimCtx *simCtx = NULL;
2377 UserCtx *user = NULL;
2378 PetscReal kinematic_viscosity = 0.0;
2379 PetscReal expected_y_plus = 0.0;
2380 const PetscReal distance_first = 0.5;
2381
2382 PetscFunctionBeginUser;
2383 PetscCall(PicurvCreateMinimalContexts(&simCtx, &user, 6, 6, 6));
2384 simCtx->ren = 1000.0;
2385 simCtx->wall_roughness_height = 1.0e-16;
2386 kinematic_viscosity = 1.0 / simCtx->ren;
2387 PetscCall(SeedWallFrictionVelocityStorage(user));
2389 PetscCall(SeedWallFunctionFixture(user, (Cmpnts){.x = 0.0, .y = 1.0, .z = 0.0}));
2390
2391 /* Disabled: nothing is corrected, so nothing is recorded. */
2392 simCtx->wallfunction = 0;
2393 PetscCall(ApplyWallFunction(user));
2394 PetscCall(PicurvAssertBool((PetscBool)(user->wall_diagnostics.cells == 0),
2395 "a disabled wall model must record no corrected cells"));
2396
2397 simCtx->wallfunction = 1;
2398 PetscCall(ApplyWallFunction(user));
2399 PetscCall(PicurvAssertBool((PetscBool)(user->wall_diagnostics.cells > 0),
2400 "an enabled wall model must record the cells it corrected"));
2401
2402 /* One face, so the sums are one cell's values and y+ is exactly u_tau * y / nu.
2403 Reproducing it from the stored friction velocity is what makes a wrong distance
2404 or a wrong viscosity in the accumulation visible. */
2405 expected_y_plus = user->wall_diagnostics.friction_velocity_sum * distance_first /
2406 kinematic_viscosity / (PetscReal)user->wall_diagnostics.cells;
2408 (PetscReal)user->wall_diagnostics.cells,
2409 expected_y_plus, 1.0e-9,
2410 "y+ must be formed from the same distance the "
2411 "correction used"));
2413 (PetscReal)user->wall_diagnostics.cells,
2414 distance_first, 1.0e-9,
2415 "the recorded wall distance must be the first cell's"));
2416 PetscCall(PicurvAssertBool((PetscBool)(user->wall_diagnostics.friction_velocity_min <=
2418 "the recorded extrema must bracket each other"));
2419
2420 /* A second pass must describe that pass alone, not both. */
2421 {
2422 const PetscInt first_pass_cells = user->wall_diagnostics.cells;
2423
2424 PetscCall(ApplyWallFunction(user));
2425 PetscCall(PicurvAssertBool((PetscBool)(user->wall_diagnostics.cells == first_pass_cells),
2426 "each pass must replace the previous pass's sample set"));
2427 }
2428
2429 PetscCall(VecDestroy(&user->Friction_Velocity));
2430 PetscCall(VecDestroy(&user->lFriction_Velocity));
2431 PetscCall(VecDestroy(&user->Wall_Stress));
2432 PetscCall(VecDestroy(&user->lWall_Stress));
2433 PetscCall(PicurvDestroyMinimalContexts(&simCtx, &user));
2434 PetscFunctionReturn(0);
2435}
PetscReal wall_distance_sum
Sum of the first-cell wall distance.
Definition variables.h:712
PetscReal friction_velocity_min
Smallest u_tau this rank corrected.
Definition variables.h:710
PetscReal friction_velocity_max
Largest u_tau this rank corrected.
Definition variables.h:711
PetscReal y_plus_sum
Sum of u_tau * y / nu over corrected cells.
Definition variables.h:713
PetscReal friction_velocity_sum
Sum of u_tau over corrected cells.
Definition variables.h:708
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TestDummyCellsFollowEachFieldsBoundaryRule()

static PetscErrorCode TestDummyCellsFollowEachFieldsBoundaryRule ( void  )
static

Checks each cell-centred field's dummy-cell rule, faces then edges.

Interior cells carry index-unique sentinels and every dummy cell starts poisoned, so a wrong offset or a missed face shows. Velocity dummies must put the face average on Ubcs; pressure and the particle scalar copy the adjacent cell (zero normal gradient); each edge dummy is the mean of its two face neighbours; and a field with no rule, or one that is not cell-centred, is refused.

Definition at line 2445 of file test_boundaries.c.

2446{
2447 SimCtx *simCtx = NULL;
2448 UserCtx *user = NULL;
2449 const FieldId scalars[] = {FIELD_ID_P, FIELD_ID_PSI};
2450
2451 PetscFunctionBeginUser;
2452 PetscCall(PicurvCreateMinimalContexts(&simCtx, &user, 5, 6, 7));
2453 const DMDALocalInfo info = user->info;
2454 const PetscInt mx = info.mx, my = info.my, mz = info.mz;
2455 PetscCall(VecSet(user->Bcs.Ubcs, 0.0));
2456 {
2457 PetscReal ***p = NULL, ***psi = NULL;
2458 Cmpnts ***ucat = NULL, ***ubcs = NULL;
2459
2460 PetscCall(DMDAVecGetArray(user->da, user->P, &p));
2461 PetscCall(DMDAVecGetArray(user->da, user->Psi, &psi));
2462 PetscCall(DMDAVecGetArray(user->fda, user->Ucat, &ucat));
2463 PetscCall(DMDAVecGetArray(user->fda, user->Bcs.Ubcs, &ubcs));
2464 for (PetscInt k = info.zs; k < info.zs + info.zm; k++)
2465 for (PetscInt j = info.ys; j < info.ys + info.ym; j++)
2466 for (PetscInt i = info.xs; i < info.xs + info.xm; i++) {
2467 const PetscBool interior = (PetscBool)(i > 0 && i < mx - 1 && j > 0 && j < my - 1 && k > 0 && k < mz - 1);
2468 const PetscReal sentinel = 100.0 * k + 10.0 * j + i;
2469
2470 p[k][j][i] = interior ? sentinel : -999.0;
2471 psi[k][j][i] = interior ? -sentinel : -999.0;
2472 ucat[k][j][i].x = interior ? sentinel : -999.0;
2473 ucat[k][j][i].y = interior ? 2.0 * sentinel : -999.0;
2474 ucat[k][j][i].z = interior ? 3.0 * sentinel : -999.0;
2475 ubcs[k][j][i] = (Cmpnts){1.0, 2.0, 3.0};
2476 }
2477 PetscCall(DMDAVecRestoreArray(user->fda, user->Bcs.Ubcs, &ubcs));
2478 PetscCall(DMDAVecRestoreArray(user->fda, user->Ucat, &ucat));
2479 PetscCall(DMDAVecRestoreArray(user->da, user->Psi, &psi));
2480 PetscCall(DMDAVecRestoreArray(user->da, user->P, &p));
2481 }
2482
2483 PetscCall(UpdateDummyCells(user, FIELD_ID_UCAT));
2484 PetscCall(UpdateCornerNodes(user, FIELD_ID_UCAT));
2485 for (size_t n = 0; n < sizeof(scalars) / sizeof(scalars[0]); ++n) {
2486 PetscCall(UpdateDummyCells(user, scalars[n]));
2487 PetscCall(UpdateCornerNodes(user, scalars[n]));
2488 }
2489
2490 for (size_t n = 0; n < sizeof(scalars) / sizeof(scalars[0]); ++n) {
2491 FieldView view;
2492 PetscReal ***f = NULL;
2493
2494 PetscCall(FieldGetView(user, scalars[n], &view));
2495 PetscCall(DMDAVecGetArrayRead(user->da, view.global_vec, &f));
2496 for (PetscInt k = 1; k < mz - 1; k++) for (PetscInt j = 1; j < my - 1; j++) {
2497 PetscCall(PicurvAssertRealNear(f[k][j][1], f[k][j][0], 0.0, "-x dummy copies the adjacent cell"));
2498 PetscCall(PicurvAssertRealNear(f[k][j][mx - 2], f[k][j][mx - 1], 0.0, "+x dummy copies the adjacent cell"));
2499 }
2500 for (PetscInt k = 1; k < mz - 1; k++) for (PetscInt i = 1; i < mx - 1; i++) {
2501 PetscCall(PicurvAssertRealNear(f[k][1][i], f[k][0][i], 0.0, "-y dummy copies the adjacent cell"));
2502 PetscCall(PicurvAssertRealNear(f[k][my - 2][i], f[k][my - 1][i], 0.0, "+y dummy copies the adjacent cell"));
2503 }
2504 for (PetscInt j = 1; j < my - 1; j++) for (PetscInt i = 1; i < mx - 1; i++) {
2505 PetscCall(PicurvAssertRealNear(f[1][j][i], f[0][j][i], 0.0, "-z dummy copies the adjacent cell"));
2506 PetscCall(PicurvAssertRealNear(f[mz - 2][j][i], f[mz - 1][j][i], 0.0, "+z dummy copies the adjacent cell"));
2507 }
2508 for (PetscInt j = 0; j < my; j++) {
2509 PetscCall(PicurvAssertRealNear(0.5 * (f[1][j][0] + f[0][j][1]), f[0][j][0], 0.0,
2510 "a (-z,-x) edge dummy is the mean of its face neighbours"));
2511 }
2512 PetscCall(PicurvAssertBool((PetscBool)(f[0][0][0] != -999.0 && f[mz - 1][my - 1][mx - 1] != -999.0),
2513 "corner dummies are written"));
2514 PetscCall(DMDAVecRestoreArrayRead(user->da, view.global_vec, &f));
2515 }
2516 {
2517 const Cmpnts ***ucat = NULL;
2518
2519 PetscCall(DMDAVecGetArrayRead(user->fda, user->Ucat, &ucat));
2520 for (PetscInt k = 1; k < mz - 1; k++) for (PetscInt j = 1; j < my - 1; j++) {
2521 PetscCall(PicurvAssertRealNear(1.0, 0.5 * (ucat[k][j][0].x + ucat[k][j][1].x), 1.0e-12,
2522 "a velocity dummy puts the face average on Ubcs"));
2523 PetscCall(PicurvAssertRealNear(3.0, 0.5 * (ucat[k][j][mx - 1].z + ucat[k][j][mx - 2].z), 1.0e-12,
2524 "a velocity dummy puts the face average on Ubcs"));
2525 }
2526 PetscCall(DMDAVecRestoreArrayRead(user->fda, user->Ucat, &ucat));
2527 }
2528
2529 {
2530 PetscErrorCode refused;
2531
2532 PetscCall(PetscPushErrorHandler(PetscIgnoreErrorHandler, NULL));
2533 refused = UpdateDummyCells(user, FIELD_ID_NVERT);
2534 PetscCall(PetscPopErrorHandler());
2535 PetscCall(PicurvAssertIntEqual(PETSC_ERR_SUP, refused, "a field with no boundary rule is refused"));
2536 PetscCall(PetscPushErrorHandler(PetscIgnoreErrorHandler, NULL));
2537 refused = UpdateDummyCells(user, FIELD_ID_COORDINATES);
2538 PetscCall(PetscPopErrorHandler());
2539 PetscCall(PicurvAssertIntEqual(PETSC_ERR_ARG_WRONG, refused, "a field that is not cell-centred is refused"));
2540 }
2541
2542 PetscCall(PicurvDestroyMinimalContexts(&simCtx, &user));
2543 PetscFunctionReturn(0);
2544}
PetscErrorCode UpdateCornerNodes(UserCtx *user, FieldId field_id)
Fills the edge and corner dummy cells of one cell-centred field.
FieldId
Compile-time identity for a catalogued Eulerian field.
@ FIELD_ID_PSI
@ FIELD_ID_NVERT
@ FIELD_ID_COORDINATES
@ FIELD_ID_P
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-boundaries PETSc test binary.

Definition at line 2550 of file test_boundaries.c.

2551{
2552 PetscErrorCode ierr;
2553 const PicurvTestCase cases[] = {
2554 {"can-rank-service-face-matches-inlet-when-defined", TestCanRankServiceFaceMatchesInletWhenDefined},
2555 {"boundary-condition-factory-assignments", TestBoundaryConditionFactoryAssignments},
2556 {"boundary-condition-factory-implemented-handler-matrix", TestBoundaryConditionFactoryImplementedHandlerMatrix},
2557 {"boundary-condition-factory-rejects-unsupported-handler", TestBoundaryConditionFactoryRejectsUnsupportedHandler},
2558 {"wall-no-slip-handler-face-matrix", TestWallNoSlipHandlerFaceMatrix},
2559 {"wall-free-slip-handler-face-matrix", TestWallFreeSlipHandlerFaceMatrix},
2560 {"wall-free-slip-curvilinear-normal", TestWallFreeSlipCurvilinearNormal},
2561 {"free-slip-wall-exerts-no-shear", TestFreeSlipWallExertsNoShear},
2562 {"dummy-cells-follow-each-fields-boundary-rule", TestDummyCellsFollowEachFieldsBoundaryRule},
2563 {"inlet-normal-source-behavior", TestInletNormalSourceBehavior},
2564 {"inlet-common-application-curvilinear-metric", TestInletCommonApplicationCurvilinearMetric},
2565 {"inlet-normal-source-face-matrix", TestInletNormalSourceFaceMatrix},
2566 {"inlet-parabolic-source-behavior", TestInletParabolicSourceBehavior},
2567 {"inlet-parabolic-source-face-matrix", TestInletParabolicSourceFaceMatrix},
2568 {"inlet-one-axis-source-uniform-along-the-other", TestInletOneAxisSourceIsUniformAlongTheOther},
2569 {"inlet-picslice-source-behavior", TestInletPicSliceSourceBehavior},
2570 {"inlet-source-adds-to-picslice", TestInletSourceAddsToPicSlice},
2571 {"inlet-source-follows-time-and-bulk-velocity", TestInletSourceFollowsTimeAndBulkVelocity},
2572 {"inlet-recording-of-cartesian-velocities", TestInletRecordingOfCartesianVelocities},
2573 {"inlet-flow-rate-and-face-radius", TestInletFlowRateAndFaceRadius},
2574 {"wall-moving-along-itself", TestWallMovingAlongItself},
2575 {"outlet-conservation-handler-behavior", TestOutletConservationHandlerBehavior},
2576 {"outlet-conservation-handler-face-matrix", TestOutletConservationHandlerFaceMatrix},
2577 {"outlet-conservation-backflow-clip", TestOutletConservationBackflowClip},
2578 {"outlet-conservation-clip-frozen-per-step", TestOutletConservationClipFrozenPerStep},
2579 {"finalize-post-projection-cell-fields-non-periodic", TestFinalizePostProjectionCellFieldsNonPeriodic},
2580 {"enforce-rhs-bcs-matches-row-classification", TestEnforceRHSBoundaryConditionsMatchesRowClassification},
2581 {"apply-wall-function-matches-the-log-law", TestApplyWallFunctionMatchesTheLogLawItDispatches},
2582 {"apply-wall-function-skips-non-wall-faces", TestApplyWallFunctionSkipsNonWallFaces},
2583 {"apply-wall-function-skips-free-slip-walls", TestApplyWallFunctionSkipsFreeSlipWalls},
2584 {"wall-model-edge-cell-has-one-stress-per-wall", TestWallModelEdgeCellHasOneStressPerWall},
2585 {"wall-function-model-selector-chooses-the-law", TestWallFunctionModelSelectorChoosesTheLaw},
2586 {"wall-model-friction-velocity-responds-to-the-flow", TestWallModelFrictionVelocityRespondsToTheFlow},
2587 {"wall-friction-velocity-storage-matches-the-catalog", TestWallFrictionVelocityStorageMatchesTheCatalog},
2588 {"wall-model-diagnostics-record-the-corrected-cells", TestWallModelDiagnosticsRecordTheCorrectedCells},
2589 };
2590
2591 ierr = PetscInitialize(&argc, &argv, NULL, "PICurv boundary tests");
2592 if (ierr) {
2593 return (int)ierr;
2594 }
2595
2596 ierr = PicurvRunTests("unit-boundaries", cases, sizeof(cases) / sizeof(cases[0]));
2597 if (ierr) {
2598 PetscFinalize();
2599 return (int)ierr;
2600 }
2601
2602 ierr = PetscFinalize();
2603 return (int)ierr;
2604}
static PetscErrorCode TestOutletConservationHandlerFaceMatrix(void)
Tests outlet-conservation correction and flux accounting across all outlet faces.
static PetscErrorCode TestCanRankServiceFaceMatchesInletWhenDefined(void)
Tests that face-service detection matches a defined inlet face.
static PetscErrorCode TestInletCommonApplicationCurvilinearMetric(void)
Verifies curvilinear projection and Cartesian dummy reflection for the shared inlet path.
static PetscErrorCode TestInletNormalSourceBehavior(void)
Tests a constant normal-speed source's face writes and flux on a Z inlet.
static PetscErrorCode TestBoundaryConditionFactoryAssignments(void)
Tests the boundary-condition factory assignments for representative handlers.
static PetscErrorCode TestApplyWallFunctionMatchesTheLogLawItDispatches(void)
Tests that the wall-function integration reproduces the model it dispatches to.
static PetscErrorCode TestWallMovingAlongItself(void)
Tests a moving wall on both a - and a + face: its velocity along the wall reaches the boundary value ...
static PetscErrorCode TestDummyCellsFollowEachFieldsBoundaryRule(void)
Checks each cell-centred field's dummy-cell rule, faces then edges.
static PetscErrorCode TestInletSourceAddsToPicSlice(void)
Tests expressions added to a profile file: a bulk velocity scales the expressions and leaves the file...
static PetscErrorCode TestWallModelDiagnosticsRecordTheCorrectedCells(void)
Tests that the wall pass records the statistics its diagnostics report.
static PetscErrorCode TestInletSourceFollowsTimeAndBulkVelocity(void)
Tests that a source in t is re-evaluated once per step, and that a bulk velocity rescales the face to...
static PetscErrorCode TestInletParabolicSourceBehavior(void)
Tests a parabola written in the arc-length fractions on a tiny Z-face.
static PetscErrorCode TestOutletConservationBackflowClip(void)
Tests the conservation outlet's backflow clip on +X, +Y, +Z and on -X, -Z.
static PetscErrorCode TestOutletConservationClipFrozenPerStep(void)
Tests that the backflow clip's rule and clipped set are frozen within a time step.
static PetscErrorCode TestInletRecordingOfCartesianVelocities(void)
Tests a recording of Cartesian velocities: every component reaches the boundary, reversed flow is all...
static PetscErrorCode TestBoundaryConditionFactoryRejectsUnsupportedHandler(void)
Tests that unsupported handler types are rejected by the factory.
static PetscErrorCode TestApplyWallFunctionSkipsFreeSlipWalls(void)
Tests that the wall model leaves a free-slip wall alone.
static PetscErrorCode TestInletFlowRateAndFaceRadius(void)
Tests that a flow-rate target sets the face's total flux, whatever its area, and that r is the distan...
static PetscErrorCode TestWallFunctionModelSelectorChoosesTheLaw(void)
Tests that the model selector actually changes which law is applied.
static PetscErrorCode TestFreeSlipWallExertsNoShear(void)
Tests which faces exert shear, and that only a free-slip wall mirrors the eddy viscosity.
static PetscErrorCode TestBoundaryConditionFactoryImplementedHandlerMatrix(void)
Tests the implemented-handler matrix exposed by the factory.
static PetscErrorCode TestWallFreeSlipHandlerFaceMatrix(void)
Tests the free-slip wall across the full face matrix on a Cartesian grid.
static PetscErrorCode TestInletPicSliceSourceBehavior(void)
Tests a prescribed-velocity inlet loading and applying one Z-face PICSLICE profile.
static PetscErrorCode TestWallNoSlipHandlerFaceMatrix(void)
Tests wall no-slip application across the full face matrix.
static PetscErrorCode TestWallModelEdgeCellHasOneStressPerWall(void)
Tests that a cell beside two walls gets one independent stress per wall face.
static PetscErrorCode TestFinalizePostProjectionCellFieldsNonPeriodic(void)
Tests non-periodic cell-field finalization without modifying Ucont.
static PetscErrorCode TestWallModelFrictionVelocityRespondsToTheFlow(void)
Tests that every wall law's friction velocity responds to the flow it is given.
static PetscErrorCode TestWallFreeSlipCurvilinearNormal(void)
Tests the free-slip wall against a face whose normal is not a grid axis.
static PetscErrorCode TestInletOneAxisSourceIsUniformAlongTheOther(void)
Tests that a profile in one fraction is uniform along the other tangential axis.
static PetscErrorCode TestApplyWallFunctionSkipsNonWallFaces(void)
Tests that a face which is not a wall is left alone by the wall function.
static PetscErrorCode TestOutletConservationHandlerBehavior(void)
Tests outlet conservation handler correction and post-step flux accounting.
static PetscErrorCode TestInletNormalSourceFaceMatrix(void)
Tests a constant normal-speed source's flux accounting and face writes across all faces.
static PetscErrorCode TestInletParabolicSourceFaceMatrix(void)
Tests a parabola in each face's two tangential fractions across all faces: its centreline,...
static PetscErrorCode TestEnforceRHSBoundaryConditionsMatchesRowClassification(void)
EnforceRHSBoundaryConditions() must zero a row exactly when it is not an unknown.
static PetscErrorCode TestWallFrictionVelocityStorageMatchesTheCatalog(void)
Tests that the friction-velocity storage matches what the field catalog declares.
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: