Actual source code: tao_app_util.c

      1: #include "taoapp.h"  /*I  "tao.h"  I*/

      6: /*@C
      7:    TaoApplicationFreeMemory - Calls PetscFree() the argument.

      9:    Collective on TAO_APPLICATION

     11:    Input Parameters:
     12: .  ctx - pointer to structure created by PetscMalloc().

     14:    Level: intermediate

     16:    Note:
     17:    A pointer to this routine can be passed into TaoApp functions which will
     18:    call this routine at a later time.

     20: .keywords: destroy

     22: .seealso: TaoAppSetDestroyRoutine(), PetscFree()
     23: @*/
     24: int TaoApplicationFreeMemory(void*ctx){
     25:   int info;
     27:   info=PetscFree(ctx); CHKERRQ(info);
     28:   return(0);
     29: }

     32: typedef struct {
     33:   Vec xl,xu;
     34: } TaoVBDCtx;

     38: static int TaoPetscApplicationCopyBounds(TAO_APPLICATION taoapp, Vec XL, Vec XU, void*ctx){
     39:   int info;
     40:   TaoVBDCtx* vbctx = (TaoVBDCtx*)ctx;
     42:   info=VecCopy(vbctx->xl,XL);CHKERRQ(info);
     43:   info=VecCopy(vbctx->xu,XU);CHKERRQ(info);
     44:   return(0);
     45: }

     50: /*@
     51:    TaoAppSetVariableBounds - Set bounds on the variables.

     53:    Collective on TAO_APPLICATION

     55:    Input Parameters:
     56: +  taoapp - the TAO_APPLICATION context
     57: .  XL - vector of lower bounds upon the solution vector
     58: -  XU - vector of upper bounds upon the solution vector

     60:    Note:
     61:    This routine should be called before TaoSetApplicationSolver()

     63:    Level: beginner

     65: .keywords: bounds

     67: .seealso: TaoGetVariableBoundVecs(), TaoAppSetVariableBoundsRoutine()
     68: @*/
     69: int TaoAppSetVariableBounds(TAO_APPLICATION taoapp, Vec XL, Vec XU){
     70:   int info;
     71:   TaoVBDCtx* vbctx;
     76:   PetscNew(TaoVBDCtx,&vbctx);
     77:   vbctx->xl=XL;
     78:   vbctx->xu=XU;
     79:   info=TaoAppSetVariableBoundsRoutine(taoapp,TaoPetscApplicationCopyBounds,(void*)vbctx);
     80:   info=TaoAppSetDestroyRoutine(taoapp,TaoApplicationFreeMemory, (void*)vbctx); CHKERRQ(info);
     81:   return(0);
     82: }