Actual source code: petsctao.h
petsc-3.12.4 2020-02-04
Report Typos and Errors

      1: #ifndef PETSCTAO_H
      2: #define PETSCTAO_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);
     10: PETSC_EXTERN PetscErrorCode TaoSoftThreshold(Vec, PetscReal, PetscReal, Vec);

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

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

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

     25: E*/

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

     32:    Level: advanced

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

     37: typedef struct _p_Tao*   Tao;

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

     42:        Level: beginner

     44: J*/
     45: typedef const char *TaoType;
     46: #define TAOLMVM     "lmvm"
     47: #define TAONLS      "nls"
     48: #define TAONTR      "ntr"
     49: #define TAONTL      "ntl"
     50: #define TAOCG       "cg"
     51: #define TAOTRON     "tron"
     52: #define TAOOWLQN    "owlqn"
     53: #define TAOBMRM     "bmrm"
     54: #define TAOBLMVM    "blmvm"
     55: #define TAOBQNLS    "bqnls"
     56: #define TAOBNCG     "bncg"
     57: #define TAOBNLS     "bnls"
     58: #define TAOBNTR     "bntr"
     59: #define TAOBNTL     "bntl"
     60: #define TAOBQNKLS   "bqnkls"
     61: #define TAOBQNKTR   "bqnktr"
     62: #define TAOBQNKTL   "bqnktl"
     63: #define TAOBQPIP    "bqpip"
     64: #define TAOGPCG     "gpcg"
     65: #define TAONM       "nm"
     66: #define TAOPOUNDERS "pounders"
     67: #define TAOBRGN     "brgn"
     68: #define TAOLCL      "lcl"
     69: #define TAOSSILS    "ssils"
     70: #define TAOSSFLS    "ssfls"
     71: #define TAOASILS    "asils"
     72: #define TAOASFLS    "asfls"
     73: #define TAOIPM      "ipm"
     74: #define TAOSHELL    "shell"

     76: PETSC_EXTERN PetscClassId TAO_CLASSID;
     77: PETSC_EXTERN PetscFunctionList TaoList;

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

     82:    Level: beginner

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

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

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

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

    114: PETSC_EXTERN const char **TaoConvergedReasons;

    116: PETSC_EXTERN PetscErrorCode TaoInitializePackage(void);
    117: PETSC_EXTERN PetscErrorCode TaoFinalizePackage(void);
    118: PETSC_EXTERN PetscErrorCode TaoCreate(MPI_Comm,Tao*);
    119: PETSC_EXTERN PetscErrorCode TaoSetFromOptions(Tao);
    120: PETSC_EXTERN PetscErrorCode TaoSetUp(Tao);
    121: PETSC_EXTERN PetscErrorCode TaoSetType(Tao,TaoType);
    122: PETSC_EXTERN PetscErrorCode TaoGetType(Tao,TaoType *);
    123: PETSC_EXTERN PetscErrorCode TaoSetApplicationContext(Tao, void*);
    124: PETSC_EXTERN PetscErrorCode TaoGetApplicationContext(Tao, void*);
    125: PETSC_EXTERN PetscErrorCode TaoDestroy(Tao*);

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

    131: PETSC_EXTERN PetscErrorCode TaoSolve(Tao);

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

    136: PETSC_EXTERN PetscErrorCode TaoGetConvergedReason(Tao,TaoConvergedReason*);
    137: PETSC_EXTERN PetscErrorCode TaoGetSolutionStatus(Tao, PetscInt*, PetscReal*, PetscReal*, PetscReal*, PetscReal*, TaoConvergedReason*);
    138: PETSC_EXTERN PetscErrorCode TaoSetConvergedReason(Tao,TaoConvergedReason);
    139: PETSC_EXTERN PetscErrorCode TaoSetInitialVector(Tao, Vec);
    140: PETSC_EXTERN PetscErrorCode TaoGetSolutionVector(Tao, Vec*);
    141: PETSC_EXTERN PetscErrorCode TaoGetGradientVector(Tao, Vec*);
    142: PETSC_EXTERN PetscErrorCode TaoSetGradientNorm(Tao, Mat);
    143: PETSC_EXTERN PetscErrorCode TaoGetGradientNorm(Tao, Mat*);
    144: PETSC_EXTERN PetscErrorCode TaoGetLMVMMatrix(Tao, Mat*);
    145: PETSC_EXTERN PetscErrorCode TaoLMVMSetH0(Tao, Mat);
    146: PETSC_EXTERN PetscErrorCode TaoLMVMGetH0(Tao, Mat*);
    147: PETSC_EXTERN PetscErrorCode TaoLMVMGetH0KSP(Tao, KSP*);
    148: PETSC_EXTERN PetscErrorCode TaoLMVMRecycle(Tao, PetscBool);
    149: PETSC_EXTERN PetscErrorCode TaoSetObjectiveRoutine(Tao, PetscErrorCode(*)(Tao, Vec, PetscReal*,void*), void*);
    150: PETSC_EXTERN PetscErrorCode TaoSetGradientRoutine(Tao, PetscErrorCode(*)(Tao, Vec, Vec, void*), void*);
    151: PETSC_EXTERN PetscErrorCode TaoSetObjectiveAndGradientRoutine(Tao, PetscErrorCode(*)(Tao, Vec, PetscReal*, Vec, void*), void*);
    152: PETSC_EXTERN PetscErrorCode TaoSetHessianRoutine(Tao,Mat,Mat,PetscErrorCode(*)(Tao,Vec, Mat, Mat, void*), void*);
    153: PETSC_EXTERN PetscErrorCode TaoSetResidualRoutine(Tao, Vec, PetscErrorCode(*)(Tao, Vec, Vec, void*), void*);
    154: PETSC_EXTERN PetscErrorCode TaoSetResidualWeights(Tao, Vec, PetscInt, PetscInt*, PetscInt*, PetscReal*);
    155: PETSC_EXTERN PetscErrorCode TaoSetConstraintsRoutine(Tao, Vec, PetscErrorCode(*)(Tao, Vec, Vec, void*), void*);
    156: PETSC_EXTERN PetscErrorCode TaoSetInequalityConstraintsRoutine(Tao, Vec, PetscErrorCode(*)(Tao, Vec, Vec, void*), void*);
    157: PETSC_EXTERN PetscErrorCode TaoSetEqualityConstraintsRoutine(Tao, Vec, PetscErrorCode(*)(Tao, Vec, Vec, void*), void*);
    158: PETSC_EXTERN PetscErrorCode TaoSetJacobianResidualRoutine(Tao, Mat, Mat, PetscErrorCode(*)(Tao, Vec, Mat, Mat, void*), void*);
    159: PETSC_EXTERN PetscErrorCode TaoSetJacobianRoutine(Tao,Mat,Mat, PetscErrorCode(*)(Tao,Vec, Mat, Mat, void*), void*);
    160: PETSC_EXTERN PetscErrorCode TaoSetJacobianStateRoutine(Tao,Mat,Mat,Mat, PetscErrorCode(*)(Tao,Vec, Mat, Mat, Mat, void*), void*);
    161: PETSC_EXTERN PetscErrorCode TaoSetJacobianDesignRoutine(Tao,Mat,PetscErrorCode(*)(Tao,Vec, Mat, void*), void*);
    162: PETSC_EXTERN PetscErrorCode TaoSetJacobianInequalityRoutine(Tao,Mat,Mat,PetscErrorCode(*)(Tao,Vec, Mat, Mat, void*), void*);
    163: PETSC_EXTERN PetscErrorCode TaoSetJacobianEqualityRoutine(Tao,Mat,Mat,PetscErrorCode(*)(Tao,Vec, Mat, Mat, void*), void*);

    165: PETSC_EXTERN PetscErrorCode TaoShellSetSolve(Tao, PetscErrorCode(*)(Tao));
    166: PETSC_EXTERN PetscErrorCode TaoShellSetContext(Tao, void*);
    167: PETSC_EXTERN PetscErrorCode TaoShellGetContext(Tao, void**);

    169: PETSC_DEPRECATED_FUNCTION("Use TaoSetResidualRoutine() (since version 3.11)") PETSC_STATIC_INLINE PetscErrorCode TaoSetSeparableObjectiveRoutine(Tao tao, Vec res, PetscErrorCode (*func)(Tao, Vec, Vec, void*),void *ctx) {return TaoSetResidualRoutine(tao, res, func, ctx);}
    170: PETSC_DEPRECATED_FUNCTION("Use TaoSetResidualWeights() (since version 3.11)") PETSC_STATIC_INLINE PetscErrorCode TaoSetSeparableObjectiveWeights(Tao tao, Vec sigma_v, PetscInt n, PetscInt *rows, PetscInt *cols, PetscReal *vals) {return TaoSetResidualWeights(tao, sigma_v, n, rows, cols, vals);}

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

    174: PETSC_EXTERN PetscErrorCode TaoComputeObjective(Tao, Vec, PetscReal*);
    175: PETSC_EXTERN PetscErrorCode TaoComputeResidual(Tao, Vec, Vec);
    176: PETSC_EXTERN PetscErrorCode TaoTestGradient(Tao,Vec,Vec);
    177: PETSC_EXTERN PetscErrorCode TaoComputeGradient(Tao, Vec, Vec);
    178: PETSC_EXTERN PetscErrorCode TaoComputeObjectiveAndGradient(Tao, Vec, PetscReal*, Vec);
    179: PETSC_EXTERN PetscErrorCode TaoComputeConstraints(Tao, Vec, Vec);
    180: PETSC_EXTERN PetscErrorCode TaoComputeInequalityConstraints(Tao, Vec, Vec);
    181: PETSC_EXTERN PetscErrorCode TaoComputeEqualityConstraints(Tao, Vec, Vec);
    182: PETSC_EXTERN PetscErrorCode TaoDefaultComputeGradient(Tao, Vec, Vec, void*);
    183: PETSC_EXTERN PetscErrorCode TaoIsObjectiveDefined(Tao,PetscBool*);
    184: PETSC_EXTERN PetscErrorCode TaoIsGradientDefined(Tao,PetscBool*);
    185: PETSC_EXTERN PetscErrorCode TaoIsObjectiveAndGradientDefined(Tao,PetscBool*);

    187: PETSC_DEPRECATED_FUNCTION("Use TaoComputeResidual() (since version 3.11)") PETSC_STATIC_INLINE PetscErrorCode TaoComputeSeparableObjective(Tao tao, Vec X, Vec F) {return TaoComputeResidual(tao, X, F);}

    189: PETSC_EXTERN PetscErrorCode TaoTestHessian(Tao);
    190: PETSC_EXTERN PetscErrorCode TaoComputeHessian(Tao, Vec, Mat, Mat);
    191: PETSC_EXTERN PetscErrorCode TaoComputeResidualJacobian(Tao, Vec, Mat, Mat);
    192: PETSC_EXTERN PetscErrorCode TaoComputeJacobian(Tao, Vec, Mat, Mat);
    193: PETSC_EXTERN PetscErrorCode TaoComputeJacobianState(Tao, Vec, Mat, Mat, Mat);
    194: PETSC_EXTERN PetscErrorCode TaoComputeJacobianEquality(Tao, Vec, Mat, Mat);
    195: PETSC_EXTERN PetscErrorCode TaoComputeJacobianInequality(Tao, Vec, Mat, Mat);
    196: PETSC_EXTERN PetscErrorCode TaoComputeJacobianDesign(Tao, Vec, Mat);

    198: PETSC_EXTERN PetscErrorCode TaoDefaultComputeHessian(Tao, Vec, Mat, Mat, void*);
    199: PETSC_EXTERN PetscErrorCode TaoDefaultComputeHessianColor(Tao, Vec, Mat, Mat, void*);
    200: PETSC_EXTERN PetscErrorCode TaoDefaultComputeHessianMFFD(Tao, Vec, Mat, Mat, void*);
    201: PETSC_EXTERN PetscErrorCode TaoComputeDualVariables(Tao, Vec, Vec);
    202: PETSC_EXTERN PetscErrorCode TaoSetVariableBounds(Tao, Vec, Vec);
    203: PETSC_EXTERN PetscErrorCode TaoGetVariableBounds(Tao, Vec*, Vec*);
    204: PETSC_EXTERN PetscErrorCode TaoGetDualVariables(Tao, Vec*, Vec*);
    205: PETSC_EXTERN PetscErrorCode TaoSetInequalityBounds(Tao, Vec, Vec);
    206: PETSC_EXTERN PetscErrorCode TaoGetInequalityBounds(Tao, Vec*, Vec*);
    207: PETSC_EXTERN PetscErrorCode TaoSetVariableBoundsRoutine(Tao, PetscErrorCode(*)(Tao, Vec, Vec, void*), void*);
    208: PETSC_EXTERN PetscErrorCode TaoComputeVariableBounds(Tao);

    210: PETSC_EXTERN PetscErrorCode TaoGetTolerances(Tao, PetscReal*, PetscReal*, PetscReal*);
    211: PETSC_EXTERN PetscErrorCode TaoSetTolerances(Tao, PetscReal, PetscReal, PetscReal);
    212: PETSC_EXTERN PetscErrorCode TaoGetConstraintTolerances(Tao, PetscReal*, PetscReal*);
    213: PETSC_EXTERN PetscErrorCode TaoSetConstraintTolerances(Tao, PetscReal, PetscReal);
    214: PETSC_EXTERN PetscErrorCode TaoSetFunctionLowerBound(Tao, PetscReal);
    215: PETSC_EXTERN PetscErrorCode TaoSetInitialTrustRegionRadius(Tao, PetscReal);
    216: PETSC_EXTERN PetscErrorCode TaoSetMaximumIterations(Tao, PetscInt);
    217: PETSC_EXTERN PetscErrorCode TaoSetMaximumFunctionEvaluations(Tao, PetscInt);
    218: PETSC_EXTERN PetscErrorCode TaoGetFunctionLowerBound(Tao, PetscReal*);
    219: PETSC_EXTERN PetscErrorCode TaoGetInitialTrustRegionRadius(Tao, PetscReal*);
    220: PETSC_EXTERN PetscErrorCode TaoGetCurrentTrustRegionRadius(Tao, PetscReal*);
    221: PETSC_EXTERN PetscErrorCode TaoGetMaximumIterations(Tao, PetscInt*);
    222: PETSC_EXTERN PetscErrorCode TaoGetCurrentFunctionEvaluations(Tao, PetscInt*);
    223: PETSC_EXTERN PetscErrorCode TaoGetMaximumFunctionEvaluations(Tao, PetscInt*);
    224: PETSC_EXTERN PetscErrorCode TaoGetIterationNumber(Tao, PetscInt*);
    225: PETSC_EXTERN PetscErrorCode TaoSetIterationNumber(Tao, PetscInt);
    226: PETSC_EXTERN PetscErrorCode TaoGetTotalIterationNumber(Tao, PetscInt*);
    227: PETSC_EXTERN PetscErrorCode TaoSetTotalIterationNumber(Tao, PetscInt);
    228: PETSC_EXTERN PetscErrorCode TaoGetResidualNorm(Tao,PetscReal*);
    229: PETSC_EXTERN PetscErrorCode TaoGetObjective(Tao,PetscReal*);

    231: PETSC_EXTERN PetscErrorCode TaoAppendOptionsPrefix(Tao, const char p[]);
    232: PETSC_EXTERN PetscErrorCode TaoGetOptionsPrefix(Tao, const char *p[]);
    233: PETSC_EXTERN PetscErrorCode TaoResetStatistics(Tao);
    234: PETSC_EXTERN PetscErrorCode TaoSetUpdate(Tao, PetscErrorCode(*)(Tao, PetscInt, void*), void*);

    236: PETSC_EXTERN PetscErrorCode TaoGetKSP(Tao, KSP*);
    237: PETSC_EXTERN PetscErrorCode TaoGetLinearSolveIterations(Tao,PetscInt *);

    239:  #include <petsctaolinesearch.h>
    240: PETSC_EXTERN PetscErrorCode TaoLineSearchUseTaoRoutines(TaoLineSearch, Tao);
    241: PETSC_EXTERN PetscErrorCode TaoGetLineSearch(Tao, TaoLineSearch*);

    243: PETSC_EXTERN PetscErrorCode TaoSetConvergenceHistory(Tao,PetscReal*,PetscReal*,PetscReal*,PetscInt*,PetscInt,PetscBool);
    244: PETSC_EXTERN PetscErrorCode TaoGetConvergenceHistory(Tao,PetscReal**,PetscReal**,PetscReal**,PetscInt**,PetscInt*);
    245: PETSC_EXTERN PetscErrorCode TaoSetMonitor(Tao, PetscErrorCode (*)(Tao,void*),void *,PetscErrorCode (*)(void**));
    246: PETSC_EXTERN PetscErrorCode TaoCancelMonitors(Tao);
    247: PETSC_EXTERN PetscErrorCode TaoMonitorDefault(Tao, void*);
    248: PETSC_DEPRECATED_FUNCTION("Use TaoMonitorDefault() (since version 3.9)") PETSC_STATIC_INLINE PetscErrorCode TaoDefaultMonitor(Tao tao, void*ctx) {return TaoMonitorDefault(tao,ctx);}
    249: PETSC_EXTERN PetscErrorCode TaoDefaultGMonitor(Tao, void*);
    250: PETSC_EXTERN PetscErrorCode TaoDefaultSMonitor(Tao, void*);
    251: PETSC_EXTERN PetscErrorCode TaoDefaultCMonitor(Tao, void*);
    252: PETSC_EXTERN PetscErrorCode TaoSolutionMonitor(Tao, void*);
    253: PETSC_EXTERN PetscErrorCode TaoResidualMonitor(Tao, void*);
    254: PETSC_EXTERN PetscErrorCode TaoGradientMonitor(Tao, void*);
    255: PETSC_EXTERN PetscErrorCode TaoStepDirectionMonitor(Tao, void*);
    256: PETSC_EXTERN PetscErrorCode TaoDrawSolutionMonitor(Tao, void*);
    257: PETSC_EXTERN PetscErrorCode TaoDrawStepMonitor(Tao, void*);
    258: PETSC_EXTERN PetscErrorCode TaoDrawGradientMonitor(Tao, void*);
    259: PETSC_EXTERN PetscErrorCode TaoAddLineSearchCounts(Tao);

    261: PETSC_EXTERN PetscErrorCode TaoDefaultConvergenceTest(Tao,void*);
    262: PETSC_EXTERN PetscErrorCode TaoSetConvergenceTest(Tao, PetscErrorCode (*)(Tao, void*),void *);

    264: PETSC_EXTERN PetscErrorCode TaoSQPCONSetStateDesignIS(Tao, IS, IS);
    265: PETSC_EXTERN PetscErrorCode TaoLCLSetStateDesignIS(Tao, IS, IS);
    266: PETSC_EXTERN PetscErrorCode TaoMonitor(Tao, PetscInt, PetscReal, PetscReal, PetscReal, PetscReal);
    267: typedef struct _n_TaoMonitorDrawCtx* TaoMonitorDrawCtx;
    268: PETSC_EXTERN PetscErrorCode TaoMonitorDrawCtxCreate(MPI_Comm,const char[],const char[],int,int,int,int,PetscInt,TaoMonitorDrawCtx*);
    269: PETSC_EXTERN PetscErrorCode TaoMonitorDrawCtxDestroy(TaoMonitorDrawCtx*);

    271: PETSC_EXTERN PetscErrorCode TaoBRGNGetSubsolver(Tao,Tao *);
    272: PETSC_EXTERN PetscErrorCode TaoBRGNSetRegularizerObjectiveAndGradientRoutine(Tao,PetscErrorCode (*)(Tao,Vec,PetscReal*,Vec,void*),void*);
    273: PETSC_EXTERN PetscErrorCode TaoBRGNSetRegularizerHessianRoutine(Tao,Mat,PetscErrorCode (*)(Tao,Vec,Mat,void*),void*);
    274: PETSC_EXTERN PetscErrorCode TaoBRGNSetRegularizerWeight(Tao,PetscReal);
    275: PETSC_EXTERN PetscErrorCode TaoBRGNSetL1SmoothEpsilon(Tao,PetscReal);
    276: PETSC_EXTERN PetscErrorCode TaoBRGNSetDictionaryMatrix(Tao,Mat);
    277: #endif