Lines Matching refs:tao

38 static PetscErrorCode TaoSolve_NLS(Tao tao)  in TaoSolve_NLS()  argument
40 TAO_NLS *nlsP = (TAO_NLS *)tao->data; in TaoSolve_NLS()
63 …if (tao->XL || tao->XU || tao->ops->computebounds) PetscCall(PetscInfo(tao, "WARNING: Variable bou… in TaoSolve_NLS()
81 PetscCall(KSPGetType(tao->ksp, &ksp_type)); in TaoSolve_NLS()
86 PetscCall(KSPCGSetRadius(tao->ksp, nlsP->max_radius)); in TaoSolve_NLS()
89 …PetscCheck(tao->trust0 >= 0.0, PetscObjectComm((PetscObject)tao), PETSC_ERR_ARG_OUTOFRANGE, "Initi… in TaoSolve_NLS()
90 tao->trust = tao->trust0; in TaoSolve_NLS()
91 tao->trust = PetscMax(tao->trust, nlsP->min_radius); in TaoSolve_NLS()
92 tao->trust = PetscMin(tao->trust, nlsP->max_radius); in TaoSolve_NLS()
96 PetscCall(TaoComputeObjectiveAndGradient(tao, tao->solution, &f, tao->gradient)); in TaoSolve_NLS()
97 PetscCall(TaoGradientNorm(tao, tao->gradient, NORM_2, &gnorm)); in TaoSolve_NLS()
98 …fOrNanReal(f) && !PetscIsInfOrNanReal(gnorm), PetscObjectComm((PetscObject)tao), PETSC_ERR_USER, "… in TaoSolve_NLS()
100 tao->reason = TAO_CONTINUE_ITERATING; in TaoSolve_NLS()
101 PetscCall(TaoLogConvergenceHistory(tao, f, gnorm, 0.0, tao->ksp_its)); in TaoSolve_NLS()
102 PetscCall(TaoMonitor(tao, tao->niter, f, gnorm, 0.0, step)); in TaoSolve_NLS()
103 PetscUseTypeMethod(tao, convergencetest, tao->cnvP); in TaoSolve_NLS()
104 if (tao->reason != TAO_CONTINUE_ITERATING) PetscFunctionReturn(PETSC_SUCCESS); in TaoSolve_NLS()
107 PetscCall(KSPGetPC(tao->ksp, &pc)); in TaoSolve_NLS()
113 PetscCall(VecGetLocalSize(tao->solution, &n)); in TaoSolve_NLS()
114 PetscCall(VecGetSize(tao->solution, &N)); in TaoSolve_NLS()
116 PetscCall(MatLMVMAllocate(nlsP->M, tao->solution, tao->gradient)); in TaoSolve_NLS()
118 …PetscCheck(sym_set && is_symmetric, PetscObjectComm((PetscObject)tao), PETSC_ERR_ARG_INCOMP, "LMVM… in TaoSolve_NLS()
138 PetscCall(TaoComputeHessian(tao, tao->solution, tao->hessian, tao->hessian_pre)); in TaoSolve_NLS()
143 PetscCall(VecCopy(tao->solution, nlsP->W)); in TaoSolve_NLS()
144 PetscCall(VecAXPY(nlsP->W, -tao->trust / gnorm, tao->gradient)); in TaoSolve_NLS()
145 PetscCall(TaoComputeObjective(tao, nlsP->W, &ftrial)); in TaoSolve_NLS()
151 sigma = -tao->trust / gnorm; in TaoSolve_NLS()
154 PetscCall(MatMult(tao->hessian, tao->gradient, nlsP->D)); in TaoSolve_NLS()
155 PetscCall(VecDot(tao->gradient, nlsP->D, &prered)); in TaoSolve_NLS()
157 prered = tao->trust * (gnorm - 0.5 * tao->trust * prered / (gnorm * gnorm)); in TaoSolve_NLS()
165 …tau_1 = nlsP->theta_i * gnorm * tao->trust / (nlsP->theta_i * gnorm * tao->trust + (1.0 - nlsP->… in TaoSolve_NLS()
166 …tau_2 = nlsP->theta_i * gnorm * tao->trust / (nlsP->theta_i * gnorm * tao->trust - (1.0 + nlsP->… in TaoSolve_NLS()
172 max_radius = PetscMax(max_radius, tao->trust); in TaoSolve_NLS()
187 max_radius = PetscMax(max_radius, tao->trust); in TaoSolve_NLS()
213 tao->trust = tau * tao->trust; in TaoSolve_NLS()
218 PetscCall(VecAXPY(tao->solution, sigma, tao->gradient)); in TaoSolve_NLS()
219 PetscCall(TaoComputeGradient(tao, tao->solution, tao->gradient)); in TaoSolve_NLS()
221 PetscCall(TaoGradientNorm(tao, tao->gradient, NORM_2, &gnorm)); in TaoSolve_NLS()
222 …PetscCheck(!PetscIsInfOrNanReal(gnorm), PetscObjectComm((PetscObject)tao), PETSC_ERR_USER, "User p… in TaoSolve_NLS()
225 PetscCall(TaoLogConvergenceHistory(tao, f, gnorm, 0.0, tao->ksp_its)); in TaoSolve_NLS()
226 PetscCall(TaoMonitor(tao, tao->niter, f, gnorm, 0.0, step)); in TaoSolve_NLS()
227 PetscUseTypeMethod(tao, convergencetest, tao->cnvP); in TaoSolve_NLS()
228 if (tao->reason != TAO_CONTINUE_ITERATING) PetscFunctionReturn(PETSC_SUCCESS); in TaoSolve_NLS()
231 tao->trust = PetscMax(tao->trust, max_radius); in TaoSolve_NLS()
234 tao->trust = PetscMax(tao->trust, nlsP->min_radius); in TaoSolve_NLS()
235 tao->trust = PetscMin(tao->trust, nlsP->max_radius); in TaoSolve_NLS()
240 tao->trust = 0.0; in TaoSolve_NLS()
251 while (tao->reason == TAO_CONTINUE_ITERATING) { in TaoSolve_NLS()
253 if (tao->ops->update) { in TaoSolve_NLS()
254 PetscUseTypeMethod(tao, update, tao->niter, tao->user_update); in TaoSolve_NLS()
255 PetscCall(TaoComputeObjective(tao, tao->solution, &f)); in TaoSolve_NLS()
257 ++tao->niter; in TaoSolve_NLS()
258 tao->ksp_its = 0; in TaoSolve_NLS()
261 if (needH) PetscCall(TaoComputeHessian(tao, tao->solution, tao->hessian, tao->hessian_pre)); in TaoSolve_NLS()
265 PetscCall(MatShift(tao->hessian, pert)); in TaoSolve_NLS()
266 if (tao->hessian != tao->hessian_pre) PetscCall(MatShift(tao->hessian_pre, pert)); in TaoSolve_NLS()
270 PetscCall(MatLMVMUpdate(nlsP->M, tao->solution, tao->gradient)); in TaoSolve_NLS()
275 PetscCall(KSPSetOperators(tao->ksp, tao->hessian, tao->hessian_pre)); in TaoSolve_NLS()
277 PetscCall(KSPCGSetRadius(tao->ksp, nlsP->max_radius)); in TaoSolve_NLS()
278 PetscCall(KSPSolve(tao->ksp, tao->gradient, nlsP->D)); in TaoSolve_NLS()
279 PetscCall(KSPGetIterationNumber(tao->ksp, &kspits)); in TaoSolve_NLS()
280 tao->ksp_its += kspits; in TaoSolve_NLS()
281 tao->ksp_tot_its += kspits; in TaoSolve_NLS()
282 PetscCall(KSPCGGetNormD(tao->ksp, &norm_d)); in TaoSolve_NLS()
284 if (0.0 == tao->trust) { in TaoSolve_NLS()
287 tao->trust = norm_d; in TaoSolve_NLS()
290 tao->trust = PetscMax(tao->trust, nlsP->min_radius); in TaoSolve_NLS()
291 tao->trust = PetscMin(tao->trust, nlsP->max_radius); in TaoSolve_NLS()
295 tao->trust = tao->trust0; in TaoSolve_NLS()
298 tao->trust = PetscMax(tao->trust, nlsP->min_radius); in TaoSolve_NLS()
299 tao->trust = PetscMin(tao->trust, nlsP->max_radius); in TaoSolve_NLS()
301 PetscCall(KSPCGSetRadius(tao->ksp, nlsP->max_radius)); in TaoSolve_NLS()
302 PetscCall(KSPSolve(tao->ksp, tao->gradient, nlsP->D)); in TaoSolve_NLS()
303 PetscCall(KSPGetIterationNumber(tao->ksp, &kspits)); in TaoSolve_NLS()
304 tao->ksp_its += kspits; in TaoSolve_NLS()
305 tao->ksp_tot_its += kspits; in TaoSolve_NLS()
306 PetscCall(KSPCGGetNormD(tao->ksp, &norm_d)); in TaoSolve_NLS()
312 PetscCall(KSPSolve(tao->ksp, tao->gradient, nlsP->D)); in TaoSolve_NLS()
313 PetscCall(KSPGetIterationNumber(tao->ksp, &kspits)); in TaoSolve_NLS()
314 tao->ksp_its += kspits; in TaoSolve_NLS()
315 tao->ksp_tot_its += kspits; in TaoSolve_NLS()
318 PetscCall(KSPGetConvergedReason(tao->ksp, &ksp_reason)); in TaoSolve_NLS()
323 PetscCall(MatLMVMUpdate(nlsP->M, tao->solution, tao->gradient)); in TaoSolve_NLS()
344 PetscCall(VecDot(nlsP->D, tao->gradient, &gdx)); in TaoSolve_NLS()
352 PetscCall(KSPGLTRGetMinEig(tao->ksp, &e_min)); in TaoSolve_NLS()
363 PetscCall(VecCopy(tao->gradient, nlsP->D)); in TaoSolve_NLS()
369 PetscCall(MatSolve(nlsP->M, tao->gradient, nlsP->D)); in TaoSolve_NLS()
373 PetscCall(VecDot(tao->gradient, nlsP->D, &gdx)); in TaoSolve_NLS()
382 PetscCall(MatLMVMUpdate(nlsP->M, tao->solution, tao->gradient)); in TaoSolve_NLS()
383 PetscCall(MatSolve(nlsP->M, tao->gradient, nlsP->D)); in TaoSolve_NLS()
414 PetscCall(KSPGLTRGetMinEig(tao->ksp, &e_min)); in TaoSolve_NLS()
436 PetscCall(VecCopy(tao->solution, nlsP->Xold)); in TaoSolve_NLS()
437 PetscCall(VecCopy(tao->gradient, nlsP->Gold)); in TaoSolve_NLS()
439 …PetscCall(TaoLineSearchApply(tao->linesearch, tao->solution, &f, tao->gradient, nlsP->D, &step, &l… in TaoSolve_NLS()
440 PetscCall(TaoAddLineSearchCounts(tao)); in TaoSolve_NLS()
444 PetscCall(VecCopy(nlsP->Xold, tao->solution)); in TaoSolve_NLS()
445 PetscCall(VecCopy(nlsP->Gold, tao->gradient)); in TaoSolve_NLS()
455 PetscCall(KSPGLTRGetMinEig(tao->ksp, &e_min)); in TaoSolve_NLS()
466 PetscCall(VecCopy(tao->gradient, nlsP->D)); in TaoSolve_NLS()
471 PetscCall(MatSolve(nlsP->M, tao->gradient, nlsP->D)); in TaoSolve_NLS()
473 PetscCall(VecDot(tao->gradient, nlsP->D, &gdx)); in TaoSolve_NLS()
479 PetscCall(MatLMVMUpdate(nlsP->M, tao->solution, tao->gradient)); in TaoSolve_NLS()
480 PetscCall(MatSolve(nlsP->M, tao->gradient, nlsP->D)); in TaoSolve_NLS()
503 PetscCall(MatLMVMUpdate(nlsP->M, tao->solution, tao->gradient)); in TaoSolve_NLS()
504 PetscCall(MatSolve(nlsP->M, tao->gradient, nlsP->D)); in TaoSolve_NLS()
513 …PetscCall(TaoLineSearchApply(tao->linesearch, tao->solution, &f, tao->gradient, nlsP->D, &step, &l… in TaoSolve_NLS()
514 PetscCall(TaoLineSearchGetFullStepObjective(tao->linesearch, &f_full)); in TaoSolve_NLS()
515 PetscCall(TaoAddLineSearchCounts(tao)); in TaoSolve_NLS()
521 PetscCall(VecCopy(nlsP->Xold, tao->solution)); in TaoSolve_NLS()
522 PetscCall(VecCopy(nlsP->Gold, tao->gradient)); in TaoSolve_NLS()
524 tao->reason = TAO_DIVERGED_LS_FAILURE; in TaoSolve_NLS()
535 tao->trust = nlsP->omega1 * PetscMin(norm_d, tao->trust); in TaoSolve_NLS()
538 tao->trust = nlsP->omega2 * PetscMin(norm_d, tao->trust); in TaoSolve_NLS()
542 tao->trust = nlsP->omega3 * PetscMin(norm_d, tao->trust); in TaoSolve_NLS()
544 tao->trust = PetscMax(nlsP->omega3 * norm_d, tao->trust); in TaoSolve_NLS()
548 tao->trust = PetscMax(nlsP->omega4 * norm_d, tao->trust); in TaoSolve_NLS()
551 tao->trust = PetscMax(nlsP->omega5 * norm_d, tao->trust); in TaoSolve_NLS()
555 tao->trust = nlsP->omega1 * PetscMin(norm_d, tao->trust); in TaoSolve_NLS()
563 PetscCall(KSPCGGetObjFcn(tao->ksp, &prered)); in TaoSolve_NLS()
568 tao->trust = nlsP->alpha1 * PetscMin(tao->trust, norm_d); in TaoSolve_NLS()
571 tao->trust = nlsP->alpha1 * PetscMin(tao->trust, norm_d); in TaoSolve_NLS()
585 tao->trust = nlsP->alpha1 * PetscMin(tao->trust, norm_d); in TaoSolve_NLS()
588 tao->trust = nlsP->alpha2 * PetscMin(tao->trust, norm_d); in TaoSolve_NLS()
592 tao->trust = nlsP->alpha3 * PetscMin(norm_d, tao->trust); in TaoSolve_NLS()
594 tao->trust = PetscMax(nlsP->alpha3 * norm_d, tao->trust); in TaoSolve_NLS()
598 tao->trust = PetscMax(nlsP->alpha4 * norm_d, tao->trust); in TaoSolve_NLS()
601 tao->trust = PetscMax(nlsP->alpha5 * norm_d, tao->trust); in TaoSolve_NLS()
607 tao->trust = nlsP->alpha1 * PetscMin(norm_d, tao->trust); in TaoSolve_NLS()
613 PetscCall(KSPCGGetObjFcn(tao->ksp, &prered)); in TaoSolve_NLS()
618 tao->trust = nlsP->gamma1 * PetscMin(tao->trust, norm_d); in TaoSolve_NLS()
621 tao->trust = nlsP->gamma1 * PetscMin(tao->trust, norm_d); in TaoSolve_NLS()
639 tao->trust = PetscMax(tao->trust, nlsP->gamma3 * norm_d); in TaoSolve_NLS()
641 tao->trust = PetscMax(tao->trust, nlsP->gamma4 * norm_d); in TaoSolve_NLS()
643 tao->trust = PetscMax(tao->trust, tau_max * norm_d); in TaoSolve_NLS()
649 tao->trust = nlsP->gamma2 * PetscMin(tao->trust, norm_d); in TaoSolve_NLS()
651 tao->trust = PetscMax(tao->trust, nlsP->gamma3 * norm_d); in TaoSolve_NLS()
653 tao->trust = tau_max * PetscMin(tao->trust, norm_d); in TaoSolve_NLS()
655 tao->trust = PetscMax(tao->trust, tau_max * norm_d); in TaoSolve_NLS()
660 tao->trust = nlsP->gamma2 * PetscMin(tao->trust, norm_d); in TaoSolve_NLS()
662 tao->trust = nlsP->gamma1 * PetscMin(tao->trust, norm_d); in TaoSolve_NLS()
664 tao->trust = nlsP->gamma1 * PetscMin(tao->trust, norm_d); in TaoSolve_NLS()
666 tao->trust = tau_1 * PetscMin(tao->trust, norm_d); in TaoSolve_NLS()
668 tao->trust = tau_2 * PetscMin(tao->trust, norm_d); in TaoSolve_NLS()
670 tao->trust = tau_max * PetscMin(tao->trust, norm_d); in TaoSolve_NLS()
677 tao->trust = nlsP->gamma1 * PetscMin(norm_d, tao->trust); in TaoSolve_NLS()
683 tao->trust = PetscMin(tao->trust, nlsP->max_radius); in TaoSolve_NLS()
687 PetscCall(TaoGradientNorm(tao, tao->gradient, NORM_2, &gnorm)); in TaoSolve_NLS()
688 …fOrNanReal(f) && !PetscIsInfOrNanReal(gnorm), PetscObjectComm((PetscObject)tao), PETSC_ERR_USER, "… in TaoSolve_NLS()
690 PetscCall(TaoLogConvergenceHistory(tao, f, gnorm, 0.0, tao->ksp_its)); in TaoSolve_NLS()
691 PetscCall(TaoMonitor(tao, tao->niter, f, gnorm, 0.0, step)); in TaoSolve_NLS()
692 PetscUseTypeMethod(tao, convergencetest, tao->cnvP); in TaoSolve_NLS()
697 static PetscErrorCode TaoSetUp_NLS(Tao tao) in TaoSetUp_NLS() argument
699 TAO_NLS *nlsP = (TAO_NLS *)tao->data; in TaoSetUp_NLS()
702 if (!tao->gradient) PetscCall(VecDuplicate(tao->solution, &tao->gradient)); in TaoSetUp_NLS()
703 if (!tao->stepdirection) PetscCall(VecDuplicate(tao->solution, &tao->stepdirection)); in TaoSetUp_NLS()
704 if (!nlsP->W) PetscCall(VecDuplicate(tao->solution, &nlsP->W)); in TaoSetUp_NLS()
705 if (!nlsP->D) PetscCall(VecDuplicate(tao->solution, &nlsP->D)); in TaoSetUp_NLS()
706 if (!nlsP->Xold) PetscCall(VecDuplicate(tao->solution, &nlsP->Xold)); in TaoSetUp_NLS()
707 if (!nlsP->Gold) PetscCall(VecDuplicate(tao->solution, &nlsP->Gold)); in TaoSetUp_NLS()
713 static PetscErrorCode TaoDestroy_NLS(Tao tao) in TaoDestroy_NLS() argument
715 TAO_NLS *nlsP = (TAO_NLS *)tao->data; in TaoDestroy_NLS()
718 if (tao->setupcalled) { in TaoDestroy_NLS()
724 PetscCall(KSPDestroy(&tao->ksp)); in TaoDestroy_NLS()
725 PetscCall(PetscFree(tao->data)); in TaoDestroy_NLS()
729 static PetscErrorCode TaoSetFromOptions_NLS(Tao tao, PetscOptionItems PetscOptionsObject) in TaoSetFromOptions_NLS() argument
731 TAO_NLS *nlsP = (TAO_NLS *)tao->data; in TaoSetFromOptions_NLS()
783 PetscCall(TaoLineSearchSetFromOptions(tao->linesearch)); in TaoSetFromOptions_NLS()
784 PetscCall(KSPSetFromOptions(tao->ksp)); in TaoSetFromOptions_NLS()
788 static PetscErrorCode TaoView_NLS(Tao tao, PetscViewer viewer) in TaoView_NLS() argument
790 TAO_NLS *nlsP = (TAO_NLS *)tao->data; in TaoView_NLS()
867 PETSC_EXTERN PetscErrorCode TaoCreate_NLS(Tao tao) in TaoCreate_NLS() argument
875 tao->ops->setup = TaoSetUp_NLS; in TaoCreate_NLS()
876 tao->ops->solve = TaoSolve_NLS; in TaoCreate_NLS()
877 tao->ops->view = TaoView_NLS; in TaoCreate_NLS()
878 tao->ops->setfromoptions = TaoSetFromOptions_NLS; in TaoCreate_NLS()
879 tao->ops->destroy = TaoDestroy_NLS; in TaoCreate_NLS()
882 PetscCall(TaoParametersInitialize(tao)); in TaoCreate_NLS()
883 PetscObjectParameterSetDefault(tao, max_it, 50); in TaoCreate_NLS()
884 PetscObjectParameterSetDefault(tao, trust0, 100.0); in TaoCreate_NLS()
886 tao->data = (void *)nlsP; in TaoCreate_NLS()
954 PetscCall(TaoLineSearchCreate(((PetscObject)tao)->comm, &tao->linesearch)); in TaoCreate_NLS()
955 PetscCall(PetscObjectIncrementTabLevel((PetscObject)tao->linesearch, (PetscObject)tao, 1)); in TaoCreate_NLS()
956 PetscCall(TaoLineSearchSetType(tao->linesearch, morethuente_type)); in TaoCreate_NLS()
957 PetscCall(TaoLineSearchUseTaoRoutines(tao->linesearch, tao)); in TaoCreate_NLS()
958 PetscCall(TaoLineSearchSetOptionsPrefix(tao->linesearch, tao->hdr.prefix)); in TaoCreate_NLS()
961 PetscCall(KSPCreate(((PetscObject)tao)->comm, &tao->ksp)); in TaoCreate_NLS()
962 PetscCall(PetscObjectIncrementTabLevel((PetscObject)tao->ksp, (PetscObject)tao, 1)); in TaoCreate_NLS()
963 PetscCall(KSPSetOptionsPrefix(tao->ksp, tao->hdr.prefix)); in TaoCreate_NLS()
964 PetscCall(KSPAppendOptionsPrefix(tao->ksp, "tao_nls_")); in TaoCreate_NLS()
965 PetscCall(KSPSetType(tao->ksp, KSPSTCG)); in TaoCreate_NLS()