PetscErrorCode FormHessian(Tao tao, Vec x, Mat H, Mat Hpre, void *ctx) { Vec DE,DI; const PetscScalar *de, *di; PetscInt zero=0,one=1; PetscScalar two=2.0; PetscScalar val; PetscErrorCode ierr; PetscFunctionBegin; ierr = TaoGetDualVariables(tao,&DE,&DI); CHKERRQ(ierr); ierr = VecGetArrayRead(DE,&de); CHKERRQ(ierr); ierr = VecGetArrayRead(DI,&di); CHKERRQ(ierr); val=2.0 * (1 + de[0] + di[0] - di[1]); ierr = VecRestoreArrayRead(DE,&de); CHKERRQ(ierr); ierr = VecRestoreArrayRead(DI,&di); CHKERRQ(ierr); ierr = MatSetValues(H,1,&zero,1,&zero,&val,INSERT_VALUES); CHKERRQ(ierr); ierr = MatSetValues(H,1,&one,1,&one,&two,INSERT_VALUES); CHKERRQ(ierr); ierr = MatAssemblyBegin(H,MAT_FINAL_ASSEMBLY); CHKERRQ(ierr); ierr = MatAssemblyEnd(H,MAT_FINAL_ASSEMBLY); CHKERRQ(ierr); PetscFunctionReturn(0); }
/*@ TaoCopyDualsOfVariableBounds - Copy the current dual variables corresponding the lower and upper bounds on the variables. Input Parameters: . tao - the solver Output Parameter: + DXL - the lower bounds - DXU - the upper bounds Level: intermediate Note: Existing vectors of commensurate distribution to the variable bounds should be passed into this routine. Note: These variables may have to be computed. It may not be efficient to call this routine in a Monitor. Note: These variables can be interpreted as the sensitivity of the objective value with respect to the bounds on the variables. .keywords: Application, bounds, duals .seealso: TaoAppGetGradientVec(), TaoAppGetSolutionVec(), TaoAppSetVariableBoundsRoutine() @*/ int TaoCopyDualsOfVariableBounds(TAO_SOLVER tao, Vec DXL, Vec DXU){ int info; TaoVecPetsc *ddxl,*ddxu; PetscFunctionBegin; PetscValidHeaderSpecific(tao,TAO_COOKIE,1); info = TaoWrapPetscVec(DXL,&ddxl); CHKERRQ(info); info = TaoWrapPetscVec(DXU,&ddxu); CHKERRQ(info); info = TaoGetDualVariables(tao, ddxl, ddxu); CHKERRQ(info); info = TaoVecDestroy(ddxl); CHKERRQ(info); info = TaoVecDestroy(ddxu); CHKERRQ(info); PetscFunctionReturn(0); }
void TaoOptimizationSolver<T>::get_dual_variables() { LOG_SCOPE("get_dual_variables()", "TaoOptimizationSolver"); PetscVector<T> * lambda_eq_petsc = cast_ptr<PetscVector<T> *>(this->system().lambda_eq.get()); PetscVector<T> * lambda_ineq_petsc = cast_ptr<PetscVector<T> *>(this->system().lambda_ineq.get()); Vec lambda_eq_petsc_vec = lambda_eq_petsc->vec(); Vec lambda_ineq_petsc_vec = lambda_ineq_petsc->vec(); PetscErrorCode ierr = 0; ierr = TaoGetDualVariables(_tao, &lambda_eq_petsc_vec, &lambda_ineq_petsc_vec); LIBMESH_CHKERR(ierr); }
PETSC_EXTERN void PETSC_STDCALL taogetdualvariables_(Tao tao,Vec *DE,Vec *DI, int *__ierr ){ *__ierr = TaoGetDualVariables( (Tao)PetscToPointer((tao) ),DE,DI); }