Skip to content

Commit

Permalink
fluids: Use 32bit integer for file token
Browse files Browse the repository at this point in the history
- Also code into the token whether PETSc was coded using 32 or 64 bit
  integers
  • Loading branch information
jrwrigh committed Jun 27, 2023
1 parent 5023bc1 commit 302f2ac
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
4 changes: 3 additions & 1 deletion examples/fluids/navierstokes.h
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,9 @@ PetscErrorCode SetupICsFromBinary(MPI_Comm comm, AppCtx app_ctx, Vec Q);
PetscErrorCode SetBCsFromICs_NS(DM dm, Vec Q, Vec Q_loc);

// Versioning token for binary checkpoints
extern const PetscInt FLUIDS_FILE_TOKEN;
extern const PetscInt32 FLUIDS_FILE_TOKEN; // for backwards compatibility
extern const PetscInt32 FLUIDS_FILE_TOKEN_32;
extern const PetscInt32 FLUIDS_FILE_TOKEN_64;

// Create appropriate mass qfunction based on number of components N
PetscErrorCode CreateMassQFunction(Ceed ceed, CeedInt N, CeedInt q_data_size, CeedQFunction *qf);
Expand Down
15 changes: 9 additions & 6 deletions examples/fluids/src/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,15 @@ PetscErrorCode DMPlexInsertBoundaryValues_NS(DM dm, PetscBool insert_essential,

// @brief Load vector from binary file, possibly with embedded solution time and step number
PetscErrorCode LoadFluidsBinaryVec(MPI_Comm comm, PetscViewer viewer, Vec Q, PetscReal *time, PetscInt *step_number) {
PetscInt token, file_step_number;
PetscReal file_time;
PetscInt file_step_number;
PetscInt32 token;
PetscReal file_time;
PetscFunctionBeginUser;

// Attempt
PetscCall(PetscViewerBinaryRead(viewer, &token, 1, NULL, PETSC_INT));
if (token == FLUIDS_FILE_TOKEN) { // New style format; we're reading a file with step number and time in the header
PetscCall(PetscViewerBinaryRead(viewer, &token, 1, NULL, PETSC_INT32));
if (token == FLUIDS_FILE_TOKEN_32 || token == FLUIDS_FILE_TOKEN_64 ||
token == FLUIDS_FILE_TOKEN) { // New style format; we're reading a file with step number and time in the header
PetscCall(PetscViewerBinaryRead(viewer, &file_step_number, 1, NULL, PETSC_INT));
PetscCall(PetscViewerBinaryRead(viewer, &file_time, 1, NULL, PETSC_REAL));
if (time) *time = file_time;
Expand Down Expand Up @@ -204,11 +206,12 @@ PetscErrorCode PostProcess_NS(TS ts, CeedData ceed_data, DM dm, ProblemData *pro
if (user->app_ctx->test_type == TESTTYPE_SOLVER) {
PetscCall(RegressionTests_NS(user->app_ctx, Q));
}

PetscFunctionReturn(0);
}

const PetscInt FLUIDS_FILE_TOKEN = 0xceedf00;
const PetscInt32 FLUIDS_FILE_TOKEN = 0xceedf00; // for backwards compatibility
const PetscInt32 FLUIDS_FILE_TOKEN_32 = 0xceedf32;
const PetscInt32 FLUIDS_FILE_TOKEN_64 = 0xceedf64;

// Gather initial Q values in case of continuation of simulation
PetscErrorCode SetupICsFromBinary(MPI_Comm comm, AppCtx app_ctx, Vec Q) {
Expand Down
4 changes: 2 additions & 2 deletions examples/fluids/src/setupts.c
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,8 @@ PetscErrorCode WriteOutput(User user, Vec Q, PetscInt step_no, PetscScalar time)
}
PetscCall(PetscViewerBinaryOpen(user->comm, file_path, FILE_MODE_WRITE, &viewer));

PetscInt token = FLUIDS_FILE_TOKEN;
PetscCall(PetscViewerBinaryWrite(viewer, &token, 1, PETSC_INT));
PetscInt32 token = PetscDefined(USE_64BIT_INDICES) ? FLUIDS_FILE_TOKEN_64 : FLUIDS_FILE_TOKEN_32;
PetscCall(PetscViewerBinaryWrite(viewer, &token, 1, PETSC_INT32));
PetscCall(PetscViewerBinaryWrite(viewer, &step_no, 1, PETSC_INT));
time /= user->units->second; // Dimensionalize time back
PetscCall(PetscViewerBinaryWrite(viewer, &time, 1, PETSC_REAL));
Expand Down

0 comments on commit 302f2ac

Please sign in to comment.