Actual source code: petsctao.h

petsc-3.9.4 2018-09-11
Report Typos and Errors
  1: #ifndef __TAO_H

  4:  #include <petscksp.h>

  6: PetscErrorCode VecFischer(Vec, Vec, Vec, Vec, Vec);
  7: PetscErrorCode VecSFischer(Vec, Vec, Vec, Vec, PetscReal, Vec);
  8: PetscErrorCode MatDFischer(Mat, Vec, Vec, Vec, Vec, Vec, Vec, Vec, Vec);
  9: PetscErrorCode MatDSFischer(Mat, Vec, Vec, Vec, Vec, PetscReal, Vec, Vec, Vec, Vec, Vec);


 12: /*E
 13:   TaoSubsetType - PetscInt representing the way TAO handles active sets

 15: + TAO_SUBSET_SUBVEC - TAO uses PETSc's MatCreateSubMatrix and VecGetSubVector
 16: . TAO_SUBSET_MASK - Matrices are zeroed out corresponding to active set entries
 17: - TAO_SUBSET_MATRIXFREE - Same as TAO_SUBSET_MASK, but can be applied to matrix-free operators

 19:   Options database keys:
 20: . -different_hessian - TAO will use a copy of the hessian operator for masking.  By default
 21:                        TAO will directly alter the hessian operator.
 22:   Level: intermediate

 24: E*/

 26: typedef enum {TAO_SUBSET_SUBVEC,TAO_SUBSET_MASK,TAO_SUBSET_MATRIXFREE} TaoSubsetType;
 27: PETSC_EXTERN const char *const TaoSubsetTypes[];
 28: /*S
 29:      Tao - Abstract PETSc object that manages nonlinear optimization solves

 31:    Level: advanced

 33: .seealso TaoCreate(), TaoDestroy(), TaoSetType(), TaoType
 34: S*/

 36: typedef struct _p_Tao*   Tao;

 38: /*J
 39:         TaoType - String with the name of a TAO method

 41:        Level: beginner

 43: J*/
 44: #define TaoType char*
 45: #define TAOLMVM     "lmvm"
 46: #define TAONLS      "nls"
 47: #define TAONTR      "ntr"
 48: #define TAONTL      "ntl"
 49: #define TAOCG       "cg"
 50: #define TAOPGD      "pgd"
 51: #define TAOTRON     "tron"
 52: #define TAOOWLQN    "owlqn"
 53: #define TAOBMRM     "bmrm"
 54: #define TAOBLMVM    "blmvm"
 55: #define TAOBNCG     "bncg"
 56: #define TAOBQPIP    "bqpip"
 57: #define TAOGPCG     "gpcg"
 58: #define TAONM       "nm"
 59: #define TAOPOUNDERS "pounders"
 60: #define TAOLCL      "lcl"
 61: #define TAOSSILS    "ssils"
 62: #define TAOSSFLS    "ssfls"
 63: #define TAOASILS    "asils"
 64: #define TAOASFLS    "asfls"
 65: #define TAOIPM      "ipm"
 66: #define TAOTEST     "test"

 68: PETSC_EXTERN PetscClassId TAO_CLASSID;
 69: PETSC_EXTERN PetscFunctionList TaoList;

 71: /*E
 72:     TaoConvergedReason - reason a TAO method was said to have converged or diverged

 74:    Level: beginner

 76:    The two most common reasons for divergence are
 77: $   1) an incorrectly coded or computed gradient or Hessian
 78: $   2) failure or lack of convergence in the linear system (in this case we recommend
 79: $      testing with -pc_type lu to eliminate the linear solver as the cause of the problem).

 81:    Developer Notes: this must match petsc/finclude/petsctao.h

 83:        The string versions of these are in TAOConvergedReasons, if you change any value here you must
 84:      also adjust that array.

 86: .seealso: TAOSolve(), TaoGetConvergedReason(), KSPConvergedReason, SNESConvergedReason, TSConvergedReason
 87: E*/
 88: typedef enum {/* converged */
 89:   TAO_CONVERGED_GATOL         =  3, /* ||g(X)|| < gatol */
 90:   TAO_CONVERGED_GRTOL         =  4, /* ||g(X)|| / f(X)  < grtol */
 91:   TAO_CONVERGED_GTTOL         =  5, /* ||g(X)|| / ||g(X0)|| < gttol */
 92:   TAO_CONVERGED_STEPTOL       =  6, /* step size small */
 93:   TAO_CONVERGED_MINF          =  7, /* F < F_min */
 94:   TAO_CONVERGED_USER          =  8, /* User defined */
 95:   /* diverged */
 96:   TAO_DIVERGED_MAXITS         = -2,
 97:   TAO_DIVERGED_NAN            = -4,
 98:   TAO_DIVERGED_MAXFCN         = -5,
 99:   TAO_DIVERGED_LS_FAILURE     = -6,
100:   TAO_DIVERGED_TR_REDUCTION   = -7,
101:   TAO_DIVERGED_USER           = -8, /* User defined */
102:   /* keep going */
103:   TAO_CONTINUE_ITERATING      =  0} TaoConvergedReason;

105: PETSC_EXTERN const char **TaoConvergedReasons;

107: PETSC_EXTERN PetscErrorCode TaoInitializePackage(void);
108: PETSC_EXTERN PetscErrorCode TaoFinalizePackage(void);
109: PETSC_EXTERN PetscErrorCode TaoCreate(MPI_Comm,Tao*);
110: PETSC_EXTERN PetscErrorCode TaoSetFromOptions(Tao);
111: PETSC_EXTERN PetscErrorCode TaoSetUp(Tao);
112: PETSC_EXTERN PetscErrorCode TaoSetType(Tao, const TaoType);
113: PETSC_EXTERN PetscErrorCode TaoGetType(Tao, const TaoType *);
114: PETSC_EXTERN PetscErrorCode TaoSetApplicationContext(Tao, void*);
115: PETSC_EXTERN PetscErrorCode TaoGetApplicationContext(Tao, void*);
116: PETSC_EXTERN PetscErrorCode TaoDestroy(Tao*);

118: PETSC_EXTERN PetscErrorCode TaoSetOptionsPrefix(Tao,const char []);
119: PETSC_EXTERN PetscErrorCode TaoView(Tao, PetscViewer);
120: PETSC_STATIC_INLINE PetscErrorCode TaoViewFromOptions(Tao A,PetscObject obj,const char name[]) {return PetscObjectViewFromOptions((PetscObject)A,obj,name);}

122: PETSC_EXTERN PetscErrorCode TaoSolve(Tao);

124: PETSC_EXTERN PetscErrorCode TaoRegister(const char [],PetscErrorCode (*)(Tao));
125: PETSC_EXTERN PetscErrorCode TaoRegisterDestroy(void);

127: PETSC_EXTERN PetscErrorCode TaoGetConvergedReason(Tao,TaoConvergedReason*);
128: PETSC_EXTERN PetscErrorCode TaoGetSolutionStatus(Tao, PetscInt*, PetscReal*, PetscReal*, PetscReal*, PetscReal*, TaoConvergedReason*);
129: PETSC_EXTERN PetscErrorCode TaoSetConvergedReason(Tao,TaoConvergedReason);
130: PETSC_EXTERN PetscErrorCode TaoSetInitialVector(Tao, Vec);
131: PETSC_EXTERN PetscErrorCode TaoGetSolutionVector(Tao, Vec*);
132: PETSC_EXTERN PetscErrorCode TaoGetGradientVector(Tao, Vec*);
133: PETSC_EXTERN PetscErrorCode TaoSetGradientNorm(Tao, Mat);
134: PETSC_EXTERN PetscErrorCode TaoGetGradientNorm(Tao, Mat*);
135: PETSC_EXTERN PetscErrorCode TaoLMVMSetH0(Tao, Mat);
136: PETSC_EXTERN PetscErrorCode TaoLMVMGetH0(Tao, Mat*);
137: PETSC_EXTERN PetscErrorCode TaoLMVMGetH0KSP(Tao, KSP*);
138: PETSC_EXTERN PetscErrorCode TaoSetObjectiveRoutine(Tao, PetscErrorCode(*)(Tao, Vec, PetscReal*,void*), void*);
139: PETSC_EXTERN PetscErrorCode TaoSetGradientRoutine(Tao, PetscErrorCode(*)(Tao, Vec, Vec, void*), void*);
140: PETSC_EXTERN PetscErrorCode TaoSetObjectiveAndGradientRoutine(Tao, PetscErrorCode(*)(Tao, Vec, PetscReal*, Vec, void*), void*);
141: PETSC_EXTERN PetscErrorCode TaoSetHessianRoutine(Tao,Mat,Mat,PetscErrorCode(*)(Tao,Vec, Mat, Mat, void*), void*);
142: PETSC_EXTERN PetscErrorCode TaoSetSeparableObjectiveRoutine(Tao, Vec, PetscErrorCode(*)(Tao, Vec, Vec, void*), void*);
143: PETSC_EXTERN PetscErrorCode TaoSetSeparableObjectiveWeights(Tao, Vec, PetscInt, PetscInt*, PetscInt*, PetscReal*);
144: PETSC_EXTERN PetscErrorCode TaoSetConstraintsRoutine(Tao, Vec, PetscErrorCode(*)(Tao, Vec, Vec, void*), void*);
145: PETSC_EXTERN PetscErrorCode TaoSetInequalityConstraintsRoutine(Tao, Vec, PetscErrorCode(*)(Tao, Vec, Vec, void*), void*);
146: PETSC_EXTERN PetscErrorCode TaoSetEqualityConstraintsRoutine(Tao, Vec, PetscErrorCode(*)(Tao, Vec, Vec, void*), void*);
147: PETSC_EXTERN PetscErrorCode TaoSetJacobianRoutine(Tao,Mat,Mat, PetscErrorCode(*)(Tao,Vec, Mat, Mat, void*), void*);
148: PETSC_EXTERN PetscErrorCode TaoSetJacobianStateRoutine(Tao,Mat,Mat,Mat, PetscErrorCode(*)(Tao,Vec, Mat, Mat, Mat, void*), void*);
149: PETSC_EXTERN PetscErrorCode TaoSetJacobianDesignRoutine(Tao,Mat,PetscErrorCode(*)(Tao,Vec, Mat, void*), void*);
150: PETSC_EXTERN PetscErrorCode TaoSetJacobianInequalityRoutine(Tao,Mat,Mat,PetscErrorCode(*)(Tao,Vec, Mat, Mat, void*), void*);
151: PETSC_EXTERN PetscErrorCode TaoSetJacobianEqualityRoutine(Tao,Mat,Mat,PetscErrorCode(*)(Tao,Vec, Mat, Mat, void*), void*);

153: PETSC_EXTERN PetscErrorCode TaoSetStateDesignIS(Tao, IS, IS);

155: PETSC_EXTERN PetscErrorCode TaoComputeObjective(Tao, Vec, PetscReal*);
156: PETSC_EXTERN PetscErrorCode TaoComputeSeparableObjective(Tao, Vec, Vec);
157: PETSC_EXTERN PetscErrorCode TaoComputeGradient(Tao, Vec, Vec);
158: PETSC_EXTERN PetscErrorCode TaoComputeObjectiveAndGradient(Tao, Vec, PetscReal*, Vec);
159: PETSC_EXTERN PetscErrorCode TaoComputeConstraints(Tao, Vec, Vec);
160: PETSC_EXTERN PetscErrorCode TaoComputeInequalityConstraints(Tao, Vec, Vec);
161: PETSC_EXTERN PetscErrorCode TaoComputeEqualityConstraints(Tao, Vec, Vec);
162: PETSC_EXTERN PetscErrorCode TaoDefaultComputeGradient(Tao, Vec, Vec, void*);
163: PETSC_EXTERN PetscErrorCode TaoIsObjectiveDefined(Tao,PetscBool*);
164: PETSC_EXTERN PetscErrorCode TaoIsGradientDefined(Tao,PetscBool*);
165: PETSC_EXTERN PetscErrorCode TaoIsObjectiveAndGradientDefined(Tao,PetscBool*);

167: PETSC_EXTERN PetscErrorCode TaoComputeHessian(Tao, Vec, Mat, Mat);
168: PETSC_EXTERN PetscErrorCode TaoComputeJacobian(Tao, Vec, Mat, Mat);
169: PETSC_EXTERN PetscErrorCode TaoComputeJacobianState(Tao, Vec, Mat, Mat, Mat);
170: PETSC_EXTERN PetscErrorCode TaoComputeJacobianEquality(Tao, Vec, Mat, Mat);
171: PETSC_EXTERN PetscErrorCode TaoComputeJacobianInequality(Tao, Vec, Mat, Mat);
172: PETSC_EXTERN PetscErrorCode TaoComputeJacobianDesign(Tao, Vec, Mat);

174: PETSC_EXTERN PetscErrorCode TaoDefaultComputeHessian(Tao, Vec, Mat, Mat, void*);
175: PETSC_EXTERN PetscErrorCode TaoDefaultComputeHessianColor(Tao, Vec, Mat, Mat, void*);
176: PETSC_EXTERN PetscErrorCode TaoDefaultComputeHessianMFFD(Tao, Vec, Mat, Mat, void*);
177: PETSC_EXTERN PetscErrorCode TaoComputeDualVariables(Tao, Vec, Vec);
178: PETSC_EXTERN PetscErrorCode TaoSetVariableBounds(Tao, Vec, Vec);
179: PETSC_EXTERN PetscErrorCode TaoGetVariableBounds(Tao, Vec*, Vec*);
180: PETSC_EXTERN PetscErrorCode TaoGetDualVariables(Tao, Vec*, Vec*);
181: PETSC_EXTERN PetscErrorCode TaoSetInequalityBounds(Tao, Vec, Vec);
182: PETSC_EXTERN PetscErrorCode TaoGetInequalityBounds(Tao, Vec*, Vec*);
183: PETSC_EXTERN PetscErrorCode TaoSetVariableBoundsRoutine(Tao, PetscErrorCode(*)(Tao, Vec, Vec, void*), void*);
184: PETSC_EXTERN PetscErrorCode TaoComputeVariableBounds(Tao);

186: PETSC_EXTERN PetscErrorCode TaoGetTolerances(Tao, PetscReal*, PetscReal*, PetscReal*);
187: PETSC_EXTERN PetscErrorCode TaoSetTolerances(Tao, PetscReal, PetscReal, PetscReal);
188: PETSC_EXTERN PetscErrorCode TaoGetConstraintTolerances(Tao, PetscReal*, PetscReal*);
189: PETSC_EXTERN PetscErrorCode TaoSetConstraintTolerances(Tao, PetscReal, PetscReal);
190: PETSC_EXTERN PetscErrorCode TaoSetFunctionLowerBound(Tao, PetscReal);
191: PETSC_EXTERN PetscErrorCode TaoSetInitialTrustRegionRadius(Tao, PetscReal);
192: PETSC_EXTERN PetscErrorCode TaoSetMaximumIterations(Tao, PetscInt);
193: PETSC_EXTERN PetscErrorCode TaoSetMaximumFunctionEvaluations(Tao, PetscInt);
194: PETSC_EXTERN PetscErrorCode TaoGetFunctionLowerBound(Tao, PetscReal*);
195: PETSC_EXTERN PetscErrorCode TaoGetInitialTrustRegionRadius(Tao, PetscReal*);
196: PETSC_EXTERN PetscErrorCode TaoGetCurrentTrustRegionRadius(Tao, PetscReal*);
197: PETSC_EXTERN PetscErrorCode TaoGetMaximumIterations(Tao, PetscInt*);
198: PETSC_EXTERN PetscErrorCode TaoGetCurrentFunctionEvaluations(Tao, PetscInt*);
199: PETSC_EXTERN PetscErrorCode TaoGetMaximumFunctionEvaluations(Tao, PetscInt*);
200: PETSC_EXTERN PetscErrorCode TaoGetIterationNumber(Tao, PetscInt*);
201: PETSC_EXTERN PetscErrorCode TaoSetIterationNumber(Tao, PetscInt);
202: PETSC_EXTERN PetscErrorCode TaoGetTotalIterationNumber(Tao, PetscInt*);
203: PETSC_EXTERN PetscErrorCode TaoSetTotalIterationNumber(Tao, PetscInt);
204: PETSC_EXTERN PetscErrorCode TaoGetResidualNorm(Tao,PetscReal*);
205: PETSC_EXTERN PetscErrorCode TaoGetObjective(Tao,PetscReal*);

207: PETSC_EXTERN PetscErrorCode TaoAppendOptionsPrefix(Tao, const char p[]);
208: PETSC_EXTERN PetscErrorCode TaoGetOptionsPrefix(Tao, const char *p[]);
209: PETSC_EXTERN PetscErrorCode TaoResetStatistics(Tao);

211: PETSC_EXTERN PetscErrorCode TaoGetKSP(Tao, KSP*);
212: PETSC_EXTERN PetscErrorCode TaoGetLinearSolveIterations(Tao,PetscInt *);

214:  #include <petsctaolinesearch.h>
215: PETSC_EXTERN PetscErrorCode TaoLineSearchUseTaoRoutines(TaoLineSearch, Tao);
216: PETSC_EXTERN PetscErrorCode TaoGetLineSearch(Tao, TaoLineSearch*);

218: PETSC_EXTERN PetscErrorCode TaoSetConvergenceHistory(Tao,PetscReal*,PetscReal*,PetscReal*,PetscInt*,PetscInt,PetscBool);
219: PETSC_EXTERN PetscErrorCode TaoGetConvergenceHistory(Tao,PetscReal**,PetscReal**,PetscReal**,PetscInt**,PetscInt*);
220: PETSC_EXTERN PetscErrorCode TaoSetMonitor(Tao, PetscErrorCode (*)(Tao,void*),void *,PetscErrorCode (*)(void**));
221: PETSC_EXTERN PetscErrorCode TaoCancelMonitors(Tao);
222: PETSC_EXTERN PetscErrorCode TaoMonitorDefault(Tao, void*);
223: PETSC_DEPRECATED ("Use TaoMonitorDefault()") PETSC_STATIC_INLINE PetscErrorCode TaoDefaultMonitor(Tao tao, void*ctx) {return TaoMonitorDefault(tao,ctx);}
224: PETSC_EXTERN PetscErrorCode TaoDefaultSMonitor(Tao, void*);
225: PETSC_EXTERN PetscErrorCode TaoDefaultCMonitor(Tao, void*);
226: PETSC_EXTERN PetscErrorCode TaoSolutionMonitor(Tao, void*);
227: PETSC_EXTERN PetscErrorCode TaoSeparableObjectiveMonitor(Tao, void*);
228: PETSC_EXTERN PetscErrorCode TaoGradientMonitor(Tao, void*);
229: PETSC_EXTERN PetscErrorCode TaoStepDirectionMonitor(Tao, void*);
230: PETSC_EXTERN PetscErrorCode TaoDrawSolutionMonitor(Tao, void*);
231: PETSC_EXTERN PetscErrorCode TaoDrawStepMonitor(Tao, void*);
232: PETSC_EXTERN PetscErrorCode TaoDrawGradientMonitor(Tao, void*);
233: PETSC_EXTERN PetscErrorCode TaoAddLineSearchCounts(Tao);

235: PETSC_EXTERN PetscErrorCode TaoDefaultConvergenceTest(Tao,void*);
236: PETSC_EXTERN PetscErrorCode TaoSetConvergenceTest(Tao, PetscErrorCode (*)(Tao, void*),void *);

238: PETSC_EXTERN PetscErrorCode TaoSQPCONSetStateDesignIS(Tao, IS, IS);
239: PETSC_EXTERN PetscErrorCode TaoLCLSetStateDesignIS(Tao, IS, IS);
240: PETSC_EXTERN PetscErrorCode TaoMonitor(Tao, PetscInt, PetscReal, PetscReal, PetscReal, PetscReal);
241: typedef struct _n_TaoMonitorDrawCtx* TaoMonitorDrawCtx;
242: PETSC_EXTERN PetscErrorCode TaoMonitorDrawCtxCreate(MPI_Comm,const char[],const char[],int,int,int,int,PetscInt,TaoMonitorDrawCtx*);
243: PETSC_EXTERN PetscErrorCode TaoMonitorDrawCtxDestroy(TaoMonitorDrawCtx*);
244: #endif