/* FormHessian - Evaluates the Hessian matrix. Input Parameters: . tao - the Tao context . x - input vector . ptr - optional user-defined context, as set by TaoSetHessian() Output Parameters: . H - Hessian matrix . Hpre - optionally different preconditioning matrix . flg - flag indicating matrix structure */ PetscErrorCode FormHessian(Tao tao,Vec X,Mat H, Mat Hpre, void *ptr) { PetscErrorCode ierr; AppCtx *user = (AppCtx *) ptr; /* Evaluate the Hessian entries*/ ierr = QuadraticH(user,X,H);CHKERRQ(ierr); return 0; }
/* FormHessian - Evaluates Hessian matrix. Input Parameters: . taoapp - the TAO_APPLICATION context . x - input vector . ptr - optional user-defined context, as set by TaoSetHessian() Output Parameters: . H - Hessian matrix . Hpre - optionally different preconditioning matrix . flg - flag indicating matrix structure */ int FormHessian(TAO_APPLICATION taoapp,Vec X,Mat *H, Mat *Hpre, MatStructure *flg, void *ptr) { int info; AppCtx *user = (AppCtx *) ptr; /* Evaluate the Hessian entries*/ info = QuadraticH(user,X,*H); CHKERRQ(info); /* Indicate that this matrix has the same sparsity pattern during successive iterations; setting this flag can save significant work in computing the preconditioner for some methods. */ *flg=SAME_NONZERO_PATTERN; return 0; }