21 PetscReal expected_max = 0.0;
23 PetscFunctionBeginUser;
26 expected_max = ((PetscReal)(user->
IM - 1) / (PetscReal)user->
IM) + 1.0e-6;
36 PetscFunctionReturn(0);
48 PetscMPIInt rank = 0, size = 1;
50 PetscFunctionBeginUser;
51 PetscCallMPI(MPI_Comm_rank(PETSC_COMM_WORLD, &rank));
52 PetscCallMPI(MPI_Comm_size(PETSC_COMM_WORLD, &size));
59 PetscCall(
PicurvAssertBool((PetscBool)(boxes != NULL),
"root must receive gathered bounding boxes"));
61 PetscCall(
PicurvAssertBool((PetscBool)(boxes == NULL),
"non-root should have NULL pre-broadcast bbox pointer"));
65 PetscCall(
PicurvAssertBool((PetscBool)(boxes != NULL),
"all ranks must have bbox array after broadcast"));
67 for (PetscMPIInt r = 0; r < size; ++r) {
78 PetscFunctionReturn(0);
93 PetscFunctionBeginUser;
96 PetscCall(PetscOptionsSetValue(NULL,
"-im",
"4"));
97 PetscCall(PetscOptionsSetValue(NULL,
"-jm",
"4"));
98 PetscCall(PetscOptionsSetValue(NULL,
"-km",
"4"));
99 PetscCall(PetscOptionsSetValue(NULL,
"-xMins",
"0.0"));
100 PetscCall(PetscOptionsSetValue(NULL,
"-xMaxs",
"0.2"));
101 PetscCall(PetscOptionsSetValue(NULL,
"-yMins",
"0.0"));
102 PetscCall(PetscOptionsSetValue(NULL,
"-yMaxs",
"0.2"));
103 PetscCall(PetscOptionsSetValue(NULL,
"-zMins",
"0.0"));
104 PetscCall(PetscOptionsSetValue(NULL,
"-zMaxs",
"0.4"));
126 PetscErrorCode bad = 0;
129 PetscCall(PetscPushErrorHandler(PetscIgnoreErrorHandler, NULL));
131 PetscCall(PetscPopErrorHandler());
133 "L_ref <= 0 is refused rather than dividing by zero"));
136 PetscCall(PetscOptionsClearValue(NULL,
"-im"));
137 PetscCall(PetscOptionsClearValue(NULL,
"-jm"));
138 PetscCall(PetscOptionsClearValue(NULL,
"-km"));
139 PetscCall(PetscOptionsClearValue(NULL,
"-xMins"));
140 PetscCall(PetscOptionsClearValue(NULL,
"-xMaxs"));
141 PetscCall(PetscOptionsClearValue(NULL,
"-yMins"));
142 PetscCall(PetscOptionsClearValue(NULL,
"-yMaxs"));
143 PetscCall(PetscOptionsClearValue(NULL,
"-zMins"));
144 PetscCall(PetscOptionsClearValue(NULL,
"-zMaxs"));
146 PetscFunctionReturn(0);
158 const PetscInt refined[4] = {9, 8, 8, 9}, unrefined[4] = {25, 25, 25, 24}, one_level[4] = {32, 32, 32, 34};
161 PetscFunctionBeginUser;
163 for (PetscInt r = 0; r < 4; ++r) PetscCall(
PicurvAssertIntEqual(refined[r], l[r],
"3-level coarsest split"));
165 for (PetscInt r = 0; r < 4; ++r) PetscCall(
PicurvAssertIntEqual(unrefined[r], l[r],
"unrefined axis keeps PETSc's split"));
167 for (PetscInt r = 0; r < 4; ++r) PetscCall(
PicurvAssertIntEqual(one_level[r], l[r],
"one level gives the last rank both spare points"));
168 PetscFunctionReturn(0);
178#if defined(PETSC_USE_64BIT_INDICES)
180 PetscFunctionBeginUser;
181 PetscFunctionReturn(0);
184 char tmpdir[PETSC_MAX_PATH_LEN] =
"";
185 PetscErrorCode setup_ierr;
187 PetscFunctionBeginUser;
188 PetscCall(PetscPushErrorHandler(PetscReturnErrorHandler, NULL));
191 PetscCall(PetscPopErrorHandler());
192 PetscCall(
PicurvAssertIntEqual(PETSC_ERR_ARG_OUTOFRANGE, setup_ierr,
"one entry past PETSC_MAX_INT must be refused"));
194 PetscCall(PetscPushErrorHandler(PetscReturnErrorHandler, NULL));
196 &simCtx, NULL, tmpdir,
sizeof(tmpdir));
197 PetscCall(PetscPopErrorHandler());
199 "grid setup must refuse a grid whose fields outgrow 32-bit PetscInt"));
202 PetscCall(PetscOptionsClear(NULL));
203 PetscFunctionReturn(0);
217 {
"read-grid-generation-inputs-nondimensionalizes-bounds",
223 ierr = PetscInitialize(&argc, &argv, NULL,
"PICurv grid tests");
228 ierr =
PicurvRunTests(
"unit-grid", cases,
sizeof(cases) /
sizeof(cases[0]));
234 ierr = PetscFinalize();
Public interface for grid, solver, and metric setup routines.
PetscErrorCode BroadcastAllBoundingBoxes(UserCtx *user, BoundingBox **bboxlist)
Broadcasts the bounding box information collected on rank 0 to all other ranks.
PetscErrorCode BalanceCoarsestOwnership(PetscInt coarse_nodes, PetscInt fine_cells, PetscInt refinements, PetscInt ranks, PetscInt *l)
Split one axis of the coarsest level so the finest level's owned cells balance.
PetscErrorCode ComputeLocalBoundingBox(UserCtx *user, BoundingBox *localBBox)
Computes the local bounding box of the grid on the current process.
PetscErrorCode GatherAllBoundingBoxes(UserCtx *user, BoundingBox **allBBoxes)
Gathers local bounding boxes from all MPI processes to rank 0.
Public interface for data input/output routines.
PetscErrorCode ReadGridGenerationInputs(UserCtx *user)
Parses command-line options for a programmatically generated grid for a SINGLE block.
PetscErrorCode PicurvCheckPetscIntRange(MPI_Comm comm, PetscInt64 entries, const char *object)
Refuse a PETSc object whose global size this build's PetscInt cannot index.
static PetscErrorCode TestOversizedGridIsRefusedOn32BitIndices(void)
Tests that a grid too large for 32-bit PetscInt is refused before its DMs are created.
static PetscErrorCode TestComputeLocalBoundingBoxUniformGrid(void)
Tests local bounding-box construction on a uniform grid.
static PetscErrorCode TestGatherAndBroadcastBoundingBoxes(void)
Tests collective gather and broadcast of rank-local bounding boxes.
int main(int argc, char **argv)
Runs the unit-grid PETSc test binary.
static PetscErrorCode TestReadGridGenerationInputsNonDimensionalizesBounds(void)
Tests that programmatic domain bounds are non-dimensionalized by L_ref.
static PetscErrorCode TestBalanceCoarsestOwnershipBalancesFinestLevel(void)
Tests that the coarsest split puts each refined finest-level boundary nearest its share.
PetscErrorCode PicurvCreateMinimalContexts(SimCtx **simCtx_out, UserCtx **user_out, PetscInt mx, PetscInt my, PetscInt mz)
Builds minimal SimCtx and UserCtx fixtures for C unit tests.
PetscErrorCode PicurvAssertRealNear(PetscReal expected, PetscReal actual, PetscReal tol, const char *context)
Asserts that two real values agree within tolerance.
PetscErrorCode PicurvDestroyMinimalContexts(SimCtx **simCtx_ptr, UserCtx **user_ptr)
Destroys minimal SimCtx/UserCtx fixtures and all owned PETSc objects.
PetscErrorCode PicurvDestroyRuntimeContext(SimCtx **simCtx_ptr)
Finalizes and frees a runtime context built by PicurvBuildTinyRuntimeContext.
PetscErrorCode PicurvRunTests(const char *suite_name, const PicurvTestCase *cases, size_t case_count)
Runs a named C test suite and prints pass/fail progress markers.
PetscErrorCode PicurvBuildTinyRuntimeContextWithOptions(const char *bcs_contents, PetscBool enable_particles, const char *extra_options, SimCtx **simCtx_out, UserCtx **user_out, char *tmpdir, size_t tmpdir_len)
Builds the tiny runtime context with extra control-file options appended.
PetscErrorCode PicurvAssertIntEqual(PetscInt expected, PetscInt actual, const char *context)
Asserts that two integer values are equal.
PetscErrorCode PicurvAssertBool(PetscBool value, const char *context)
Asserts that one boolean condition is true.
PetscErrorCode PicurvRemoveTempDir(const char *path)
Recursively removes a temporary directory created by PicurvMakeTempDir.
Shared declarations for the PICurv C test fixture and assertion layer.
Named test case descriptor consumed by PicurvRunTests.
Cmpnts max_coords
Maximum x, y, z coordinates of the bounding box.
Cmpnts min_coords
Minimum x, y, z coordinates of the bounding box.
Defines a 3D axis-aligned bounding box.
The master context for the entire simulation.
User-defined context containing data specific to a single computational grid level.