petsc-3.7.1 2016-05-15
Report Typos and Errors

# VecBoundGradientProjection

Projects vector according to this definition. If XL[i] < X[i] < XU[i], then GP[i] = G[i]; If X[i]<=XL[i], then GP[i] = min(G[i],0); If X[i]>=XU[i], then GP[i] = max(G[i],0);

### Synopsis

    #include "petscvec.h"
    PetscErrorCode VecBoundGradientProjection(Vec G, Vec X, Vec XL, Vec XU, Vec GP)

### Input Parameters

| G | - current gradient vector Many br
| X | - current solution vector Many br
| XL | - lower bounds Many br
| XU | - upper bounds Many br

### Output Parameter

GP -gradient projection vector Many br

Many brC@*/ Many brPetscErrorCode VecBoundGradientProjection(Vec G, Vec X, Vec XL, Vec XU, Vec GP) Many br{ Many br

PetscErrorCode ierr; Many brPetscInt n,i; Many brPetscReal *xptr,*xlptr,*xuptr,*gptr,*gpptr; Many brPetscReal xval,gpval; Many br

/* Project variables at the lower and upper bound */ Many brPetscFunctionBegin; Many brPetscValidHeaderSpecific(G,VEC_CLASSID,1); Many brPetscValidHeaderSpecific(X,VEC_CLASSID,2); Many brPetscValidHeaderSpecific(XL,VEC_CLASSID,3); Many brPetscValidHeaderSpecific(XU,VEC_CLASSID,4); Many brPetscValidHeaderSpecific(GP,VEC_CLASSID,5); Many br

ierr = VecGetLocalSize(X,&n);CHKERRQ(ierr); Many br

ierr=VecGetArray(X,&xptr);CHKERRQ(ierr); Many brierr=VecGetArray(XL,&xlptr);CHKERRQ(ierr); Many brierr=VecGetArray(XU,&xuptr);CHKERRQ(ierr); Many brierr=VecGetArray(G,&gptr);CHKERRQ(ierr); Many brif (G!=GP){ Many brierr=VecGetArray(GP,&gpptr);CHKERRQ(ierr); Many br} else { gpptr=gptr; } Many br

for (i=0; i<n; ++i){ Many brgpval = gptr[i]; xval = xptr[i]; Many br

if (gpval>0 && xval<=xlptr[i]){ Many brgpval = 0; Many br} else if (gpval<0 && xval>=xuptr[i]){ Many brgpval = 0; Many br} Many brgpptr[i] = gpval; Many br} Many br

ierr=VecRestoreArray(X,&xptr);CHKERRQ(ierr); Many brierr=VecRestoreArray(XL,&xlptr);CHKERRQ(ierr); Many brierr=VecRestoreArray(XU,&xuptr);CHKERRQ(ierr); Many brierr=VecRestoreArray(G,&gptr);CHKERRQ(ierr); Many brif (G!=GP){ Many brierr=VecRestoreArray(GP,&gpptr);CHKERRQ(ierr); Many br} Many brPetscFunctionReturn(0); Many br} Many br#endif Many br

#undef __FUNCT__ Many br#define __FUNCT__ "VecStepMaxBounded" Many br/*@ Many brVecStepMaxBounded - See below Many br

Collective on Vec Many br

### Input Parameters

| X | - vector with no negative entries Many br
| XL | - lower bounds Many br
| XU | - upper bounds Many br
| DX | - step direction, can have negative, positive or zero entries Many br

### Output Parameter

stepmax -minimum value so that X[i] + stepmax*DX[i] <= XL[i] or XU[i] <= X[i] + stepmax*DX[i] Many br

Level:advanced
Location:src/vec/vec/utils/projection.c
Index of all Vec routines
Table of Contents for all manual pages
Index of all manual pages