@@ -92,9 +92,31 @@ PetscErrorCode SNESFormResidual(SNES snes, Vec X, Vec Y, void *ctx_residual) {
9292// -----------------------------------------------------------------------------
9393PetscErrorCode SNESFormJacobian (SNES snes , Vec U , Mat J , Mat J_pre ,
9494 void * ctx_jacobian ) {
95-
95+ OperatorApplyContext ctx = ( OperatorApplyContext ) ctx_jacobian ;
9696 PetscFunctionBeginUser ;
9797
98+ Mat A ;
99+ PetscCall (DMCreateMatrix (ctx -> dm , & A ));
100+ // Assemble matrix analytically
101+ PetscCount num_entries ;
102+ CeedInt * rows , * cols ;
103+ CeedVector coo_values ;
104+ CeedOperatorLinearAssembleSymbolic (ctx -> op_apply , & num_entries , & rows ,
105+ & cols );
106+ PetscCall (MatSetPreallocationCOO (A , num_entries , rows , cols ));
107+ free (rows );
108+ free (cols );
109+ CeedVectorCreate (ctx -> ceed , num_entries , & coo_values );
110+ CeedOperatorLinearAssemble (ctx -> op_apply , coo_values );
111+ const CeedScalar * values ;
112+ CeedVectorGetArrayRead (coo_values , CEED_MEM_HOST , & values );
113+ PetscCall (MatSetValuesCOO (A , values , ADD_VALUES ));
114+ CeedVectorRestoreArrayRead (coo_values , & values );
115+ MatView (A , PETSC_VIEWER_STDOUT_WORLD );
116+ //CeedVectorView(coo_values, "%12.8f", stdout);
117+ CeedVectorDestroy (& coo_values );
118+ PetscCall ( MatDestroy (& A ) );
119+
98120 // J_pre might be AIJ (e.g., when using coloring), so we need to assemble it
99121 PetscCall ( MatAssemblyBegin (J_pre , MAT_FINAL_ASSEMBLY ) );
100122 PetscCall ( MatAssemblyEnd (J_pre , MAT_FINAL_ASSEMBLY ) );
0 commit comments