Skip to content

Commit

Permalink
Merge pull request CEED#1573 from CEED/jrwrigh/fix_fluids_printing
Browse files Browse the repository at this point in the history
fluids: Correct printing of MatTypes
  • Loading branch information
jrwrigh authored May 4, 2024
2 parents f674649 + 7bc7b61 commit 433eda4
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 18 deletions.
5 changes: 1 addition & 4 deletions examples/fluids/navierstokes.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,6 @@ int main(int argc, char **argv) {
PetscCall(SetupICsFromBinary(comm, app_ctx, Q));
}

// Print problem summary
if (app_ctx->test_type == TESTTYPE_NONE) PetscCall(PrintRunInfo(user, phys_ctx, problem, comm));

// -- Zero Q_loc
PetscCall(VecZeroEntries(user->Q_loc));

Expand All @@ -240,7 +237,7 @@ int main(int argc, char **argv) {
// ---------------------------------------------------------------------------
TS ts;
PetscScalar final_time;
PetscCall(TSSolve_NS(dm, user, app_ctx, phys_ctx, &Q, &final_time, &ts));
PetscCall(TSSolve_NS(dm, user, app_ctx, phys_ctx, problem, &Q, &final_time, &ts));

// ---------------------------------------------------------------------------
// Post-processing
Expand Down
4 changes: 2 additions & 2 deletions examples/fluids/navierstokes.h
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ extern PetscErrorCode PRINT_ADVECTION(User user, ProblemData problem, AppCtx app

extern PetscErrorCode PRINT_ADVECTION2D(User user, ProblemData problem, AppCtx app_ctx);

PetscErrorCode PrintRunInfo(User user, Physics phys_ctx, ProblemData problem, MPI_Comm comm);
PetscErrorCode PrintRunInfo(User user, Physics phys_ctx, ProblemData problem, TS ts);

// -----------------------------------------------------------------------------
// libCEED functions
Expand Down Expand Up @@ -363,7 +363,7 @@ PetscErrorCode IFunction_NS(TS ts, PetscReal t, Vec Q, Vec Q_dot, Vec G, void *u
PetscErrorCode TSMonitor_NS(TS ts, PetscInt step_no, PetscReal time, Vec Q, void *ctx);

// TS: Create, setup, and solve
PetscErrorCode TSSolve_NS(DM dm, User user, AppCtx app_ctx, Physics phys, Vec *Q, PetscScalar *f_time, TS *ts);
PetscErrorCode TSSolve_NS(DM dm, User user, AppCtx app_ctx, Physics phys, ProblemData problem, Vec *Q, PetscScalar *f_time, TS *ts);

// Update Boundary Values when time has changed
PetscErrorCode UpdateBoundaryValues(User user, Vec Q_loc, PetscReal t);
Expand Down
43 changes: 33 additions & 10 deletions examples/fluids/src/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,10 @@ PetscErrorCode RegisterLogEvents() {
}

// Print information about the given simulation run
PetscErrorCode PrintRunInfo(User user, Physics phys_ctx, ProblemData problem, MPI_Comm comm) {
Ceed ceed = user->ceed;
PetscErrorCode PrintRunInfo(User user, Physics phys_ctx, ProblemData problem, TS ts) {
Ceed ceed = user->ceed;
MPI_Comm comm = PetscObjectComm((PetscObject)ts);

PetscFunctionBeginUser;
// Header and rank
char host_name[PETSC_MAX_PATH_LEN];
Expand Down Expand Up @@ -421,22 +423,43 @@ PetscErrorCode PrintRunInfo(User user, Physics phys_ctx, ProblemData problem, MP
" libCEED Backend MemType : %s\n",
used_resource, CeedMemTypes[mem_type_backend]));
// PETSc
char box_faces_str[PETSC_MAX_PATH_LEN] = "3,3,3";
VecType vec_type;
char box_faces_str[PETSC_MAX_PATH_LEN] = "3,3,3";
if (problem->dim == 2) box_faces_str[3] = '\0';
PetscCall(PetscOptionsGetString(NULL, NULL, "-dm_plex_box_faces", box_faces_str, sizeof(box_faces_str), NULL));
MatType amat_type = user->app_ctx->amat_type, pmat_type;
VecType vec_type;
PetscCall(DMGetMatType(user->dm, &pmat_type));
if (!amat_type) amat_type = pmat_type;
PetscCall(DMGetVecType(user->dm, &vec_type));
PetscCall(PetscPrintf(comm,
" PETSc:\n"
" Box Faces : %s\n"
" A MatType : %s\n"
" P MatType : %s\n"
" DM VecType : %s\n"
" Time Stepping Scheme : %s\n",
box_faces_str, amat_type, pmat_type, vec_type, phys_ctx->implicit ? "implicit" : "explicit"));
box_faces_str, vec_type, phys_ctx->implicit ? "implicit" : "explicit"));
{
char pmat_type_str[PETSC_MAX_PATH_LEN];
MatType amat_type, pmat_type;
Mat Amat, Pmat;
TSIJacobianFn *ijacob_function;

PetscCall(TSGetIJacobian(ts, &Amat, &Pmat, &ijacob_function, NULL));
PetscCall(MatGetType(Amat, &amat_type));
PetscCall(MatGetType(Pmat, &pmat_type));

PetscCall(PetscStrncpy(pmat_type_str, pmat_type, sizeof(pmat_type_str)));
if (!strcmp(pmat_type, MATCEED)) {
MatType pmat_coo_type;
char pmat_coo_type_str[PETSC_MAX_PATH_LEN];

PetscCall(MatCeedGetCOOMatType(Pmat, &pmat_coo_type));
PetscCall(PetscSNPrintf(pmat_coo_type_str, sizeof(pmat_coo_type_str), " (COO MatType: %s)", pmat_coo_type));
PetscCall(PetscStrlcat(pmat_type_str, pmat_coo_type_str, sizeof(pmat_type_str)));
}
if (ijacob_function) {
PetscCall(PetscPrintf(comm,
" IJacobian A MatType : %s\n"
" IJacobian P MatType : %s\n",
amat_type, pmat_type_str));
}
}
if (user->app_ctx->cont_steps) {
PetscCall(PetscPrintf(comm,
" Continue:\n"
Expand Down
2 changes: 1 addition & 1 deletion examples/fluids/src/petsc_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ PetscErrorCode CreateSolveOperatorsFromMatCeed(KSP ksp, Mat mat_ceed, PetscBool

PetscCall(KSPGetPC(ksp, &pc));
PetscCall(PCGetType(pc, &pc_type));
PetscCall(PetscStrcmpAny(pc_type, &use_matceed_pmat, PCJACOBI, PCVPBJACOBI, PCPBJACOBI, ""));
PetscCall(PetscStrcmpAny(pc_type, &use_matceed_pmat, PCNONE, PCJACOBI, PCVPBJACOBI, PCPBJACOBI, ""));
}

if (use_matceed_pmat) {
Expand Down
4 changes: 3 additions & 1 deletion examples/fluids/src/setupts.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ PetscErrorCode TSMonitor_NS(TS ts, PetscInt step_no, PetscReal time, Vec Q, void
}

// TS: Create, setup, and solve
PetscErrorCode TSSolve_NS(DM dm, User user, AppCtx app_ctx, Physics phys, Vec *Q, PetscScalar *f_time, TS *ts) {
PetscErrorCode TSSolve_NS(DM dm, User user, AppCtx app_ctx, Physics phys, ProblemData problem, Vec *Q, PetscScalar *f_time, TS *ts) {
MPI_Comm comm = user->comm;
TSAdapt adapt;
PetscScalar final_time;
Expand Down Expand Up @@ -377,6 +377,8 @@ PetscErrorCode TSSolve_NS(DM dm, User user, AppCtx app_ctx, Physics phys, Vec *Q
PetscCall(TSMonitorSet(*ts, TSMonitor_SGS_DD_Training, user, NULL));
PetscCall(TSSetPostStep(*ts, TSPostStep_SGS_DD_Training));
}

if (app_ctx->test_type == TESTTYPE_NONE) PetscCall(PrintRunInfo(user, user->phys, problem, *ts));
// Solve
PetscReal start_time;
PetscInt start_step;
Expand Down

0 comments on commit 433eda4

Please sign in to comment.