@@ -93,27 +93,6 @@ PetscErrorCode SNESFormJacobian(SNES snes, Vec U, Mat J, Mat J_pre, void *ctx_ja
93
93
// OperatorApplyContext ctx = (OperatorApplyContext)ctx_jacobian;
94
94
PetscFunctionBeginUser ;
95
95
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
-
117
96
// J_pre might be AIJ (e.g., when using coloring), so we need to assemble it
118
97
PetscCall (MatAssemblyBegin (J_pre , MAT_FINAL_ASSEMBLY ));
119
98
PetscCall (MatAssemblyEnd (J_pre , MAT_FINAL_ASSEMBLY ));
@@ -148,6 +127,7 @@ PetscErrorCode PDESolver(CeedData ceed_data, AppCtx app_ctx, SNES snes, KSP ksp,
148
127
// -- Form Action of Jacobian on delta_u
149
128
PetscCall (MatCreateShell (app_ctx -> comm , U_l_size , U_l_size , U_g_size , U_g_size , app_ctx -> ctx_jacobian , & mat_jacobian ));
150
129
PetscCall (MatShellSetOperation (mat_jacobian , MATOP_MULT , (void (* )(void ))ApplyMatOp ));
130
+ PetscCall (MatShellSetOperation (mat_jacobian , MATOP_GET_DIAGONAL , (void (* )(void ))GetDiagonal ));
151
131
PetscCall (MatShellSetVecType (mat_jacobian , app_ctx -> ctx_jacobian -> vec_type ));
152
132
153
133
// Set SNES residual evaluation function
@@ -156,8 +136,17 @@ PetscErrorCode PDESolver(CeedData ceed_data, AppCtx app_ctx, SNES snes, KSP ksp,
156
136
PetscCall (SNESSetJacobian (snes , mat_jacobian , mat_jacobian , SNESFormJacobian , app_ctx -> ctx_jacobian ));
157
137
158
138
// 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
159
147
PetscCall (KSPSetFromOptions (ksp ));
160
-
148
+ PetscCall (KSPViewFromOptions (ksp , NULL , "-ksp_view" ));
149
+ PetscCall (PCViewFromOptions (pc , NULL , "-pc_view" ));
161
150
// Default to critical-point (CP) line search (related to Wolfe's curvature condition)
162
151
SNESLineSearch line_search ;
163
152
0 commit comments