Actual source code: taoappobject.c

      1: #include "taoappobject.h"     /*I "tao_solver.h"  I*/
      2: #include "tao_general.h"
     3:  #include taovec.h

      8: /*@C
      9:    EvaluateObjectiveFunction - Evaluate the objective function
     10:    at the point x.

     12:    Collective on TAO_SOLVER

     14:    Input Parameters:
     15: .  xx - the point at which to evaluate the obective function

     17:    Output Parameters:
     18: .  ff - objective function value

     20: .seealso TaoSetPetscGradient(), EvaluateObjectiveFunction(), EvaluateObjectiveAndGradientFunction()

     22:    Level: intermediate

     24: .keywords: application, context

     26: @*/
     27: int TaoApplication::EvaluateObjectiveFunction(TaoVec *xx, double *ff){
     28:   TaoFunctionBegin;
     29:   SETERRQ(56,"Operation not defined");
     30:   //  TaoFunctionReturn(0);
     31: }

     35: /*@C
     36:    EvaluateGradient - Evaluate the gradient of the
     37:    objective function at the point x.

     39:    Collective on TAO_SOLVER

     41:    Input Parameters:
     42: .  xx - the point at which to evaluate the gradient

     44:    Output Parameters:
     45: .  gg - the gradient vector

     47: .seealso TaoSetPetscGradient(), EvaluateObjectiveFunction(), EvaluateObjectiveAndGradientFunction()

     49:    Level: intermediate

     51: .keywords: application, context

     53: @*/
     54: int TaoApplication::EvaluateGradient(TaoVec *xx, TaoVec *gg){
     55:   TaoFunctionBegin;
     56:   SETERRQ(56,"Operation not defined");
     57:   //  TaoFunctionReturn(0);
     58: }

     63: /*@C
     64:    EvaluateObjectiveAndGradient - Evaluate the objective function
     65:    and its gradient at the point x.

     67:    Collective on TAO_SOLVER

     69:    Input Parameters:
     70: .  xx - the point at which to evaluate the gradient

     72:    Output Parameters:
     73: +  ff - the objective value
     74: -  gg - the gradient vector

     76: .seealso TaoSetPetscFunctionGradient(), EvaluateGradient(), EvaluateObjectiveFunction()

     78:    Level: intermediate

     80: .keywords: application, gradient

     82: @*/
     83: int TaoApplication::EvaluateObjectiveAndGradient(TaoVec *xx, double *ff, TaoVec *gg){
     84:   int info;
     85:   TaoFunctionBegin;
     86:   info=this->EvaluateObjectiveFunction(xx,ff);CHKERRQ(info);
     87:   info=this->EvaluateGradient(xx,gg);CHKERRQ(info);
     88:   TaoFunctionReturn(0);
     89: }

     93: /*@C
     94:    EvaluateHessian - Evaluate the Hessian of the objective function
     95:    at the point x.

     97:    Collective on TAO_SOLVER

     99:    Input Parameters:
    100: .  xx - the point at which to evaluate the gradient

    102:    Output Parameters:
    103: .  HH - the Hessian matrix

    105: .seealso TaoSetPetscHessian()
    106:    Level: intermediate

    108: .keywords: application, hessian

    110: @*/
    111: int TaoApplication::EvaluateHessian(TaoVec *xx, TaoMat *HH){
    112:   TaoFunctionBegin;
    113:   SETERRQ(56,"Operation not defined");
    114:   //  TaoFunctionReturn(0);
    115: }

    119: /*@C
    120:    HessianSolve - Solve a linear system involving the Hessian
    121: matrix, or apply an inverse Hessian operator to a vector.

    123:    Collective on TAO_SOLVER

    125:    Input Parameters:
    126: .  rhs - the right-hand side

    128:    Output Parameters:
    129: +  vv - the solution
    130: -  success - flag states whether solution was found.

    132: .seealso TaoSetMethod(), TaoLMVMSetSize(), EvaluateHessian()

    134:    Level: intermediate

    136: .keywords: application, Hessian, LMVM

    138: @*/
    139: int TaoApplication::HessianSolve(TaoVec *rhs, TaoVec*vv, TaoTruth *success){
    140:   int info;
    141:   TaoFunctionBegin;
    142:   info=vv->CopyFrom(rhs);CHKERRQ(info);
    143:   *success=TAO_TRUE;
    144:   TaoFunctionReturn(0);
    145: }

    150: /*@C
    151:    EvaluateConstraints - Evaluate the constraint functions
    152:    at the point x.

    154:    Collective on TAO_SOLVER

    156:    Input Parameters:
    157: .  xx - the point at which to evaluate the gradient

    159:    Output Parameters:
    160: .  RR - the constraint vector

    162: .seealso TaoSetPetscConstraintsFunction()
    163:    Level: intermediate

    165: .keywords: application, constraints

    167: @*/
    168: int TaoApplication::EvaluateConstraints(TaoVec *xx, TaoVec *RR){
    169:   TaoFunctionBegin;
    170:   SETERRQ(56,"Operation not defined");
    171:   //  TaoFunctionReturn(0);
    172: }

    176: /*@C
    177:    EvaluateJacobian - Evaluate the Jacobian of the constraint functions
    178:    at the point x.

    180:    Collective on TAO_SOLVER

    182:    Input Parameters:
    183: .  xx - the point at which to evaluate the gradient

    185:    Output Parameters:
    186: .  JJ - the Jacobian matrix

    188: .seealso TaoSetPetscJacobian()

    190:    Level: intermediate

    192: .keywords: application, constraints

    194: @*/
    195: int TaoApplication::EvaluateJacobian(TaoVec *xx, TaoMat *JJ){
    196:   TaoFunctionBegin;
    197:   SETERRQ(56,"Operation not defined");
    198:   //  TaoFunctionReturn(0);
    199: }

    203: /*@C
    204:    InitializeVariables - Initialize the variables for the optimization
    205:    solver.  Set an initial point.

    208:    Collective on TAO_SOLVER

    210:    Input Parameters:
    211: .  xx - the variable vector

    213:    Level: intermediate

    215: .keywords: application, constraints

    217: @*/
    218: int TaoApplication::InitializeVariables(TaoVec *xx){
    219:   int info;
    220:   TaoFunctionBegin;
    221:   info=xx->SetToZero();CHKERRQ(info);
    222:   TaoFunctionReturn(0);
    223: }

    227: /*@C
    228:    GetVariableVector - Sets the pointer to a vector that will
    229:    be used to store the variables.

    231:    Collective on TAO_SOLVER

    233:    Output Parameters:
    234: .  xx - vector to the variable vector

    236:    Level: intermediate

    238: .keywords: application, variables

    240: @*/
    241: int TaoApplication::GetVariableVector(TaoVec **xx){
    242:   TaoFunctionBegin;
    243:   *xx=0;
    244:   TaoFunctionReturn(0);
    245: }

    250: /*@C
    251:    EvaluateVariableBounds - Set these vectors equal to the lower
    252:    and upper bounds on the variables.

    254:    Collective on TAO_SOLVER

    256:    Input Parameters:
    257: +  xxll - vector vector of lower bounds
    258: -  xxuu - vector vector of upper bounds

    260:    Level: intermediate

    262: .keywords: application, bounds

    264: @*/
    265: int TaoApplication::EvaluateVariableBounds(TaoVec *xxll, TaoVec *xxuu){
    266:   int info;
    267:   double dd;
    268:   TaoFunctionBegin;
    269:   if (xxll){
    270:     dd=-TAO_INFINITY;
    271:     info=xxll->SetToConstant(dd); CHKERRQ(info);
    272:   }
    273:   if (xxuu){
    274:     dd=TAO_INFINITY;
    275:     info=xxuu->SetToConstant(dd); CHKERRQ(info);
    276:   }
    277:   TaoFunctionReturn(0);
    278: }

    283: /*@C
    284:    GetHessianMatrix - Sets the pointer to a matrix that will
    285:    be used to store the Hessian of the objective function.

    287:    Collective on TAO_SOLVER

    289:    Output Parameters:
    290: .  HH - vector to the Hessian

    292:    Level: intermediate

    294: .keywords: application, gradient

    296: @*/
    297: int TaoApplication::GetHessianMatrix(TaoMat **HH){
    298:   TaoFunctionBegin;
    299:   *HH=0;
    300:   TaoFunctionReturn(0);
    301: }

    305: /*@C
    306:    GetJacobianMatrix - Sets the pointer to a matrix that will
    307:    be used to store the Jacobian

    309:    Collective on TAO_SOLVER

    311:    Output Parameters:
    312: .  JJ - matrix to the Jacobian

    314:    Level: intermediate

    316: .keywords: application, gradient

    318: @*/
    319: int TaoApplication::GetJacobianMatrix(TaoMat **JJ){
    320:   TaoFunctionBegin;
    321:   *JJ=0;
    322:   TaoFunctionReturn(0);
    323: }

    325: int TaoApplication::GetConstraintVector(TaoVec **rr){
    326:   TaoFunctionBegin;
    327:   *rr=0;
    328:   TaoFunctionReturn(0);
    329: }

    334: int TaoApplication::GetInequalityConstraints(TaoVec**ll, TaoMat **AA, TaoVec **uu){
    335:   TaoFunctionBegin;
    336:   *ll=0;
    337:   *AA=0;
    338:   *uu=0;
    339:   TaoFunctionReturn(0);
    340: }

    345: /*@C
    346:   CreateATDAMatrix - Creates a new matrix of the for A^T D A, where A=this.

    348:    Input Parameter:
    349: +  A - matrix A
    350: .  D -  a TaoVec in the column space of this matrix that will represent a diagonal matrix
    351: -  X -  a vector in the rowspace of this matrix

    353:    Output Parameter:
    354: .  M - the new matrix

    356:    Note:
    357:    The operation M->Multiply(X,D) must be well defined

    359: .seealso TaoMat::SetReducedMatrix()

    361:    Level: intermediate
    362: @*/
    363: int TaoApplication::CreateATDAMatrix(TaoMat*A, TaoVec* D,TaoVec* X, TaoMat** M){
    364:   TaoFunctionBegin;
    365:   SETERRQ(56,"Operation not defined");
    366:   /* TaoFunctionReturn(1); */
    367: }

    373: /*@C
    374:    Monitor - Monitor the current solution

    376:    Collective on TAO_SOLVER

    378:    Level: intermediate

    380:    Note: This routine is called after each iteration

    382: .keywords: application, monitor

    384: @*/
    385: int TaoApplication::Monitor(){
    386:   TaoFunctionBegin;
    387:   TaoFunctionReturn(0);
    388: }

    392: /*@C
    393:    Monitor2 -

    395:    Collective on TAO_SOLVER

    397:    Input Parameters:
    398: .  xx - the current solution
    399: .  gl - the gradient of the Lagrangian function
    400: .  dx - the step direction

    402:    Output Parameters:
    403: .  *term - TAO_TRUE if the solver should stop iterating and TAO_FALSE if the solver should continue;

    405: .seealso TaoSetPetscGradient(),

    407:    Level: intermediate

    409: .keywords: application, context

    411: @*/
    412: int TaoApplication::Monitor2(TaoVec *xx, TaoVec *gg, TaoVec *ff, TaoTruth *term){
    413:   TaoFunctionBegin;
    414:   *term=TAO_FALSE;
    415:   TaoFunctionReturn(0);
    416: }

    422: /*@C
    423:    GetLinearSolver - Create and a linear solver used to solve this matrix

    425:    Collective on TAO_SOLVER

    427:    input Parameters:
    428: +  H - the operator to be used to solve
    429: -  flag - indicates properties solver must have

    431:    Output Parameters:
    432: .  tksp - the linear solver

    434:    Types of linear solvers are:
    435: +  100 - Solver for any square matrix
    436: .  110 - GMRES
    437: .  200 - Any symmetric matrix
    438: .  210 - MINRES
    439: .  220 - CG with Trust  Region
    440: .  300 - Any symmetric positive definite
    441: -  310 - Conjugate Gradient

    443:    Level: intermediate

    445: .keywords: application, linear solver

    447: @*/
    448: int TaoApplication::GetLinearSolver(TaoMat *H, int flag, TaoLinearSolver **tksp){
    449:   TaoFunctionBegin;
    450:   SETERRQ(56,"Operation not defined");
    451: }

    455: /*@
    456:    TaoDestroyApplication - Destroys the TAO application

    458:    Collective on TAO_APPLICATION

    460:    Input Parameters:
    461: .  myapp - pointer to the TaoApplication object (TaoApplication*),

    464:    Level: developer

    466: .keywords: application

    468: @*/
    469: int TaoDestroyApplication(TaoApplication *myapp){
    470:   TaoFunctionBegin;
    471:   delete myapp;
    472:   TaoFunctionReturn(0);
    473: }