From 7bc7b61f650775c1f4a19293c33952b8958158d6 Mon Sep 17 00:00:00 2001 From: James Wright Date: Wed, 1 May 2024 11:50:04 -0600 Subject: [PATCH] fluids: Print correct Mat Types --- examples/fluids/navierstokes.h | 2 +- examples/fluids/src/misc.c | 43 ++++++++++++++++++++++++++-------- examples/fluids/src/setupts.c | 2 +- 3 files changed, 35 insertions(+), 12 deletions(-) diff --git a/examples/fluids/navierstokes.h b/examples/fluids/navierstokes.h index b0b73260f5..768ff84921 100644 --- a/examples/fluids/navierstokes.h +++ b/examples/fluids/navierstokes.h @@ -325,7 +325,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 diff --git a/examples/fluids/src/misc.c b/examples/fluids/src/misc.c index e73769741c..8fe1484b67 100644 --- a/examples/fluids/src/misc.c +++ b/examples/fluids/src/misc.c @@ -397,8 +397,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]; @@ -427,22 +429,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" diff --git a/examples/fluids/src/setupts.c b/examples/fluids/src/setupts.c index b91344f655..8ed11e10c0 100644 --- a/examples/fluids/src/setupts.c +++ b/examples/fluids/src/setupts.c @@ -378,7 +378,7 @@ PetscErrorCode TSSolve_NS(DM dm, User user, AppCtx app_ctx, Physics phys, Proble PetscCall(TSSetPostStep(*ts, TSPostStep_SGS_DD_Training)); } - if (app_ctx->test_type == TESTTYPE_NONE) PetscCall(PrintRunInfo(user, user->phys, problem, comm)); + if (app_ctx->test_type == TESTTYPE_NONE) PetscCall(PrintRunInfo(user, user->phys, problem, *ts)); // Solve PetscReal start_time; PetscInt start_step;