@@ -93,27 +93,6 @@ PetscErrorCode SNESFormJacobian(SNES snes, Vec U, Mat J, Mat J_pre, void *ctx_ja
9393 // OperatorApplyContext ctx = (OperatorApplyContext)ctx_jacobian;
9494 PetscFunctionBeginUser ;
9595
96- // Mat A;
97- // PetscCall(DMCreateMatrix(ctx->dm, &A));
98- //// Assemble matrix analytically
99- // PetscCount num_entries;
100- // CeedInt *rows, *cols;
101- // CeedVector coo_values;
102- // CeedOperatorLinearAssembleSymbolic(ctx->op_apply, &num_entries, &rows, &cols);
103- // PetscCall(MatSetPreallocationCOO(A, num_entries, rows, cols));
104- // free(rows);
105- // free(cols);
106- // CeedVectorCreate(ctx->ceed, num_entries, &coo_values);
107- // CeedOperatorLinearAssemble(ctx->op_apply, coo_values);
108- // const CeedScalar *values;
109- // CeedVectorGetArrayRead(coo_values, CEED_MEM_HOST, &values);
110- // PetscCall(MatSetValuesCOO(A, values, ADD_VALUES));
111- // CeedVectorRestoreArrayRead(coo_values, &values);
112- // MatView(A, PETSC_VIEWER_STDOUT_WORLD);
113- //// CeedVectorView(coo_values, "%12.8f", stdout);
114- // CeedVectorDestroy(&coo_values);
115- // PetscCall(MatDestroy(&A));
116-
11796 // J_pre might be AIJ (e.g., when using coloring), so we need to assemble it
11897 PetscCall (MatAssemblyBegin (J_pre , MAT_FINAL_ASSEMBLY ));
11998 PetscCall (MatAssemblyEnd (J_pre , MAT_FINAL_ASSEMBLY ));
@@ -148,6 +127,7 @@ PetscErrorCode PDESolver(CeedData ceed_data, AppCtx app_ctx, SNES snes, KSP ksp,
148127 // -- Form Action of Jacobian on delta_u
149128 PetscCall (MatCreateShell (app_ctx -> comm , U_l_size , U_l_size , U_g_size , U_g_size , app_ctx -> ctx_jacobian , & mat_jacobian ));
150129 PetscCall (MatShellSetOperation (mat_jacobian , MATOP_MULT , (void (* )(void ))ApplyMatOp ));
130+ PetscCall (MatShellSetOperation (mat_jacobian , MATOP_GET_DIAGONAL , (void (* )(void ))GetDiagonal ));
151131 PetscCall (MatShellSetVecType (mat_jacobian , app_ctx -> ctx_jacobian -> vec_type ));
152132
153133 // Set SNES residual evaluation function
@@ -156,8 +136,17 @@ PetscErrorCode PDESolver(CeedData ceed_data, AppCtx app_ctx, SNES snes, KSP ksp,
156136 PetscCall (SNESSetJacobian (snes , mat_jacobian , mat_jacobian , SNESFormJacobian , app_ctx -> ctx_jacobian ));
157137
158138 // Setup KSP
139+ PetscCall (KSPSetType (ksp , KSPGMRES ));
140+ PetscCall (KSPSetNormType (ksp , KSP_NORM_PRECONDITIONED ));
141+ // PC setup
142+ PC pc ;
143+ PetscCall (KSPGetPC (ksp , & pc ));
144+ PetscCall (PCSetType (pc , PCJACOBI ));
145+ PetscCall (PCJacobiSetType (pc , PC_JACOBI_DIAGONAL ));
146+ // Set user options and view
159147 PetscCall (KSPSetFromOptions (ksp ));
160-
148+ PetscCall (KSPViewFromOptions (ksp , NULL , "-ksp_view" ));
149+ PetscCall (PCViewFromOptions (pc , NULL , "-pc_view" ));
161150 // Default to critical-point (CP) line search (related to Wolfe's curvature condition)
162151 SNESLineSearch line_search ;
163152
0 commit comments