xref: /petsc/include/petsc/private/taolinesearchimpl.h (revision 6d8694c4fbab79f9439f1ad13c0386ba7ee1ca4b)
1 #pragma once
2 #include <petscvec.h>
3 #include <petsc/private/petscimpl.h>
4 #include <petsctaolinesearch.h>
5 
6 typedef struct _TaoLineSearchOps *TaoLineSearchOps;
7 struct _TaoLineSearchOps {
8   PetscErrorCode (*computeobjective)(TaoLineSearch, Vec, PetscReal *, void *);
9   PetscErrorCode (*computegradient)(TaoLineSearch, Vec, Vec, void *);
10   PetscErrorCode (*computeobjectiveandgradient)(TaoLineSearch, Vec, PetscReal *, Vec, void *);
11   PetscErrorCode (*computeobjectiveandgts)(TaoLineSearch, Vec, Vec, PetscReal *, PetscReal *, void *);
12   PetscErrorCode (*setup)(TaoLineSearch);
13   PetscErrorCode (*apply)(TaoLineSearch, Vec, PetscReal *, Vec, Vec);
14   PetscErrorCode (*view)(TaoLineSearch, PetscViewer);
15   PetscErrorCode (*setfromoptions)(TaoLineSearch, PetscOptionItems);
16   PetscErrorCode (*reset)(TaoLineSearch);
17   PetscErrorCode (*destroy)(TaoLineSearch);
18   PetscErrorCode (*monitor)(TaoLineSearch);
19 };
20 
21 struct _p_TaoLineSearch {
22   PETSCHEADER(struct _TaoLineSearchOps);
23   void       *userctx_func;
24   void       *userctx_grad;
25   void       *userctx_funcgrad;
26   void       *userctx_funcgts;
27   PetscBool   usemonitor;
28   PetscViewer viewer;
29 
30   PetscBool setupcalled;
31   PetscBool usegts;
32   PetscBool usetaoroutines;
33   PetscBool hasobjective;
34   PetscBool hasgradient;
35   PetscBool hasobjectiveandgradient;
36   void     *data;
37 
38   /* bounds used for some line searches */
39   Vec       lower;
40   Vec       upper;
41   PetscBool bounded;
42 
43   Vec       start_x;
44   Vec       stepdirection;
45   PetscReal f_fullstep;
46   PetscReal new_f;
47   Vec       new_x;
48   Vec       new_g;
49 
50   PetscReal step;
51   PetscReal initstep;
52 
53   PetscInt                     max_funcs;
54   PetscInt                     nfeval;
55   PetscInt                     ngeval;
56   PetscInt                     nfgeval;
57   TaoLineSearchConvergedReason reason;
58 
59   PetscReal rtol;    /* relative tol for acceptable step (rtol>0) */
60   PetscReal ftol;    /* tol for sufficient decr. condition (ftol>0) */
61   PetscReal gtol;    /* tol for curvature condition (gtol>0)*/
62   PetscReal stepmin; /* lower bound for step */
63   PetscReal stepmax; /* upper bound for step */
64 
65   Tao tao;
66 };
67 
68 PETSC_EXTERN PetscLogEvent TAOLINESEARCH_Apply;
69 PETSC_EXTERN PetscLogEvent TAOLINESEARCH_Eval;
70