Lines Matching refs:ts

28 PetscErrorCode TSSetRHSJacobianP(TS ts, Mat Amat, TSRHSJacobianPFn *func, PetscCtx ctx)  in TSSetRHSJacobianP()  argument
31 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSSetRHSJacobianP()
34 ts->rhsjacobianp = func; in TSSetRHSJacobianP()
35 ts->rhsjacobianpctx = ctx; in TSSetRHSJacobianP()
38 PetscCall(MatDestroy(&ts->Jacprhs)); in TSSetRHSJacobianP()
39 ts->Jacprhs = Amat; in TSSetRHSJacobianP()
64 PetscErrorCode TSGetRHSJacobianP(TS ts, Mat *Amat, TSRHSJacobianPFn **func, PetscCtxRt ctx) in TSGetRHSJacobianP() argument
67 if (func) *func = ts->rhsjacobianp; in TSGetRHSJacobianP()
68 if (ctx) *(void **)ctx = ts->rhsjacobianpctx; in TSGetRHSJacobianP()
69 if (Amat) *Amat = ts->Jacprhs; in TSGetRHSJacobianP()
90 PetscErrorCode TSComputeRHSJacobianP(TS ts, PetscReal t, Vec U, Mat Amat) in TSComputeRHSJacobianP() argument
94 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSComputeRHSJacobianP()
97 …if (ts->rhsjacobianp) PetscCallBack("TS callback JacobianP for sensitivity analysis", (*ts->rhsjac… in TSComputeRHSJacobianP()
137 PetscErrorCode TSSetIJacobianP(TS ts, Mat Amat, PetscErrorCode (*func)(TS ts, PetscReal t, Vec U, V… in TSSetIJacobianP() argument
140 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSSetIJacobianP()
143 ts->ijacobianp = func; in TSSetIJacobianP()
144 ts->ijacobianpctx = ctx; in TSSetIJacobianP()
147 PetscCall(MatDestroy(&ts->Jacp)); in TSSetIJacobianP()
148 ts->Jacp = Amat; in TSSetIJacobianP()
182 PetscErrorCode TSGetIJacobianP(TS ts, Mat *Amat, PetscErrorCode (**func)(TS ts, PetscReal t, Vec U,… in TSGetIJacobianP() argument
185 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSGetIJacobianP()
187 if (func) *func = ts->ijacobianp; in TSGetIJacobianP()
188 if (ctx) *(void **)ctx = ts->ijacobianpctx; in TSGetIJacobianP()
189 if (Amat) *Amat = ts->Jacp; in TSGetIJacobianP()
213 PetscErrorCode TSComputeIJacobianP(TS ts, PetscReal t, Vec U, Vec Udot, PetscReal shift, Mat Amat, … in TSComputeIJacobianP() argument
217 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSComputeIJacobianP()
221 PetscCall(PetscLogEventBegin(TS_JacobianPEval, ts, U, Amat, 0)); in TSComputeIJacobianP()
222 …if (ts->ijacobianp) PetscCallBack("TS callback JacobianP for sensitivity analysis", (*ts->ijacobia… in TSComputeIJacobianP()
224 if (!ts->ijacobianp) { /* system was written as Udot = G(t,U) */ in TSComputeIJacobianP()
234 if (ts->rhsjacobianp) PetscCall(TSComputeRHSJacobianP(ts, t, U, ts->Jacprhs)); in TSComputeIJacobianP()
235 if (ts->Jacprhs == Amat) { /* No IJacobian, so we only have the RHS matrix */ in TSComputeIJacobianP()
237 } else if (ts->Jacprhs) { /* Both IJacobian and RHSJacobian */ in TSComputeIJacobianP()
239 if (!ts->ijacobianp) { /* No IJacobianp provided, but we have a separate RHS matrix */ in TSComputeIJacobianP()
242 PetscCall(MatAXPY(Amat, -1, ts->Jacprhs, axpy)); in TSComputeIJacobianP()
245 PetscCall(PetscLogEventEnd(TS_JacobianPEval, ts, U, Amat, 0)); in TSComputeIJacobianP()
295ts, PetscInt numcost, Vec costintegral, PetscErrorCode (*rf)(TS ts, PetscReal t, Vec U, Vec F, Pet… in TSSetCostIntegrand() argument
298 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSSetCostIntegrand()
300 …PetscCheck(!ts->numcost || ts->numcost == numcost, PetscObjectComm((PetscObject)ts), PETSC_ERR_USE… in TSSetCostIntegrand()
301 if (!ts->numcost) ts->numcost = numcost; in TSSetCostIntegrand()
305 PetscCall(VecDestroy(&ts->vec_costintegral)); in TSSetCostIntegrand()
306 ts->vec_costintegral = costintegral; in TSSetCostIntegrand()
308 if (!ts->vec_costintegral) { /* Create a seq vec if user does not provide one */ in TSSetCostIntegrand()
309 PetscCall(VecCreateSeq(PETSC_COMM_SELF, numcost, &ts->vec_costintegral)); in TSSetCostIntegrand()
311 PetscCall(VecSet(ts->vec_costintegral, 0.0)); in TSSetCostIntegrand()
314 if (!ts->vec_costintegrand) { in TSSetCostIntegrand()
315 PetscCall(VecDuplicate(ts->vec_costintegral, &ts->vec_costintegrand)); in TSSetCostIntegrand()
317 PetscCall(VecSet(ts->vec_costintegrand, 0.0)); in TSSetCostIntegrand()
319 ts->costintegralfwd = fwd; /* Evaluate the cost integral in forward run if fwd is true */ in TSSetCostIntegrand()
320 ts->costintegrand = rf; in TSSetCostIntegrand()
321 ts->costintegrandctx = ctx; in TSSetCostIntegrand()
322 ts->drdufunction = drduf; in TSSetCostIntegrand()
323 ts->drdpfunction = drdpf; in TSSetCostIntegrand()
343 PetscErrorCode TSGetCostIntegral(TS ts, Vec *v) in TSGetCostIntegral() argument
348 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSGetCostIntegral()
350 PetscCall(TSGetQuadratureTS(ts, NULL, &quadts)); in TSGetCostIntegral()
374 PetscErrorCode TSComputeCostIntegrand(TS ts, PetscReal t, Vec U, Vec Q) in TSComputeCostIntegrand() argument
377 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSComputeCostIntegrand()
381 PetscCall(PetscLogEventBegin(TS_FunctionEval, ts, U, Q, 0)); in TSComputeCostIntegrand()
382 …if (ts->costintegrand) PetscCallBack("TS callback integrand in the cost function", (*ts->costinteg… in TSComputeCostIntegrand()
384 PetscCall(PetscLogEventEnd(TS_FunctionEval, ts, U, Q, 0)); in TSComputeCostIntegrand()
395 PetscErrorCode TSComputeDRDUFunction(TS ts, PetscReal t, Vec U, Vec *DRDU) in TSComputeDRDUFunction() argument
399 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSComputeDRDUFunction()
402 …PetscCallBack("TS callback DRDU for sensitivity analysis", (*ts->drdufunction)(ts, t, U, DRDU, ts-… in TSComputeDRDUFunction()
413 PetscErrorCode TSComputeDRDPFunction(TS ts, PetscReal t, Vec U, Vec *DRDP) in TSComputeDRDPFunction() argument
417 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSComputeDRDPFunction()
420 …PetscCallBack("TS callback DRDP for sensitivity analysis", (*ts->drdpfunction)(ts, t, U, DRDP, ts-… in TSComputeDRDPFunction()
469 PetscErrorCode TSSetIHessianProduct(TS ts, Vec *ihp1, PetscErrorCode (*ihessianproductfunc1)(TS ts,… in TSSetIHessianProduct() argument
472 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSSetIHessianProduct()
475 ts->ihessianproductctx = ctx; in TSSetIHessianProduct()
476 if (ihp1) ts->vecs_fuu = ihp1; in TSSetIHessianProduct()
477 if (ihp2) ts->vecs_fup = ihp2; in TSSetIHessianProduct()
478 if (ihp3) ts->vecs_fpu = ihp3; in TSSetIHessianProduct()
479 if (ihp4) ts->vecs_fpp = ihp4; in TSSetIHessianProduct()
480 ts->ihessianproduct_fuu = ihessianproductfunc1; in TSSetIHessianProduct()
481 ts->ihessianproduct_fup = ihessianproductfunc2; in TSSetIHessianProduct()
482 ts->ihessianproduct_fpu = ihessianproductfunc3; in TSSetIHessianProduct()
483 ts->ihessianproduct_fpp = ihessianproductfunc4; in TSSetIHessianProduct()
510 PetscErrorCode TSComputeIHessianProductFunctionUU(TS ts, PetscReal t, Vec U, Vec Vl[], Vec Vr, Vec … in TSComputeIHessianProductFunctionUU() argument
514 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSComputeIHessianProductFunctionUU()
517 … (ts->ihessianproduct_fuu) PetscCallBack("TS callback IHessianProduct 1 for sensitivity analysis",… in TSComputeIHessianProductFunctionUU()
520 if (ts->rhshessianproduct_guu) { in TSComputeIHessianProductFunctionUU()
522 PetscCall(TSComputeRHSHessianProductFunctionUU(ts, t, U, Vl, Vr, VHV)); in TSComputeIHessianProductFunctionUU()
523 for (nadj = 0; nadj < ts->numcost; nadj++) PetscCall(VecScale(VHV[nadj], -1)); in TSComputeIHessianProductFunctionUU()
551 PetscErrorCode TSComputeIHessianProductFunctionUP(TS ts, PetscReal t, Vec U, Vec Vl[], Vec Vr, Vec … in TSComputeIHessianProductFunctionUP() argument
555 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSComputeIHessianProductFunctionUP()
558 … (ts->ihessianproduct_fup) PetscCallBack("TS callback IHessianProduct 2 for sensitivity analysis",… in TSComputeIHessianProductFunctionUP()
561 if (ts->rhshessianproduct_gup) { in TSComputeIHessianProductFunctionUP()
563 PetscCall(TSComputeRHSHessianProductFunctionUP(ts, t, U, Vl, Vr, VHV)); in TSComputeIHessianProductFunctionUP()
564 for (nadj = 0; nadj < ts->numcost; nadj++) PetscCall(VecScale(VHV[nadj], -1)); in TSComputeIHessianProductFunctionUP()
592 PetscErrorCode TSComputeIHessianProductFunctionPU(TS ts, PetscReal t, Vec U, Vec Vl[], Vec Vr, Vec … in TSComputeIHessianProductFunctionPU() argument
596 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSComputeIHessianProductFunctionPU()
599 … (ts->ihessianproduct_fpu) PetscCallBack("TS callback IHessianProduct 3 for sensitivity analysis",… in TSComputeIHessianProductFunctionPU()
602 if (ts->rhshessianproduct_gpu) { in TSComputeIHessianProductFunctionPU()
604 PetscCall(TSComputeRHSHessianProductFunctionPU(ts, t, U, Vl, Vr, VHV)); in TSComputeIHessianProductFunctionPU()
605 for (nadj = 0; nadj < ts->numcost; nadj++) PetscCall(VecScale(VHV[nadj], -1)); in TSComputeIHessianProductFunctionPU()
633 PetscErrorCode TSComputeIHessianProductFunctionPP(TS ts, PetscReal t, Vec U, Vec Vl[], Vec Vr, Vec … in TSComputeIHessianProductFunctionPP() argument
637 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSComputeIHessianProductFunctionPP()
640 … (ts->ihessianproduct_fpp) PetscCallBack("TS callback IHessianProduct 3 for sensitivity analysis",… in TSComputeIHessianProductFunctionPP()
643 if (ts->rhshessianproduct_gpp) { in TSComputeIHessianProductFunctionPP()
645 PetscCall(TSComputeRHSHessianProductFunctionPP(ts, t, U, Vl, Vr, VHV)); in TSComputeIHessianProductFunctionPP()
646 for (nadj = 0; nadj < ts->numcost; nadj++) PetscCall(VecScale(VHV[nadj], -1)); in TSComputeIHessianProductFunctionPP()
700 PetscErrorCode TSSetRHSHessianProduct(TS ts, Vec rhshp1[], PetscErrorCode (*rhshessianproductfunc1)… in TSSetRHSHessianProduct() argument
703 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSSetRHSHessianProduct()
706 ts->rhshessianproductctx = ctx; in TSSetRHSHessianProduct()
707 if (rhshp1) ts->vecs_guu = rhshp1; in TSSetRHSHessianProduct()
708 if (rhshp2) ts->vecs_gup = rhshp2; in TSSetRHSHessianProduct()
709 if (rhshp3) ts->vecs_gpu = rhshp3; in TSSetRHSHessianProduct()
710 if (rhshp4) ts->vecs_gpp = rhshp4; in TSSetRHSHessianProduct()
711 ts->rhshessianproduct_guu = rhshessianproductfunc1; in TSSetRHSHessianProduct()
712 ts->rhshessianproduct_gup = rhshessianproductfunc2; in TSSetRHSHessianProduct()
713 ts->rhshessianproduct_gpu = rhshessianproductfunc3; in TSSetRHSHessianProduct()
714 ts->rhshessianproduct_gpp = rhshessianproductfunc4; in TSSetRHSHessianProduct()
741 PetscErrorCode TSComputeRHSHessianProductFunctionUU(TS ts, PetscReal t, Vec U, Vec Vl[], Vec Vr, Ve… in TSComputeRHSHessianProductFunctionUU() argument
745 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSComputeRHSHessianProductFunctionUU()
748 … RHSHessianProduct 1 for sensitivity analysis", (*ts->rhshessianproduct_guu)(ts, t, U, Vl, Vr, VHV… in TSComputeRHSHessianProductFunctionUU()
775 PetscErrorCode TSComputeRHSHessianProductFunctionUP(TS ts, PetscReal t, Vec U, Vec Vl[], Vec Vr, Ve… in TSComputeRHSHessianProductFunctionUP() argument
779 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSComputeRHSHessianProductFunctionUP()
782 … RHSHessianProduct 2 for sensitivity analysis", (*ts->rhshessianproduct_gup)(ts, t, U, Vl, Vr, VHV… in TSComputeRHSHessianProductFunctionUP()
809 PetscErrorCode TSComputeRHSHessianProductFunctionPU(TS ts, PetscReal t, Vec U, Vec Vl[], Vec Vr, Ve… in TSComputeRHSHessianProductFunctionPU() argument
813 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSComputeRHSHessianProductFunctionPU()
816 … RHSHessianProduct 3 for sensitivity analysis", (*ts->rhshessianproduct_gpu)(ts, t, U, Vl, Vr, VHV… in TSComputeRHSHessianProductFunctionPU()
843 PetscErrorCode TSComputeRHSHessianProductFunctionPP(TS ts, PetscReal t, Vec U, Vec Vl[], Vec Vr, Ve… in TSComputeRHSHessianProductFunctionPP() argument
847 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSComputeRHSHessianProductFunctionPP()
850 … RHSHessianProduct 3 for sensitivity analysis", (*ts->rhshessianproduct_gpp)(ts, t, U, Vl, Vr, VHV… in TSComputeRHSHessianProductFunctionPP()
877 PetscErrorCode TSSetCostGradients(TS ts, PetscInt numcost, Vec lambda[], Vec mu[]) in TSSetCostGradients() argument
880 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSSetCostGradients()
882 ts->vecs_sensi = lambda; in TSSetCostGradients()
883 ts->vecs_sensip = mu; in TSSetCostGradients()
884 …PetscCheck(!ts->numcost || ts->numcost == numcost, PetscObjectComm((PetscObject)ts), PETSC_ERR_USE… in TSSetCostGradients()
885 ts->numcost = numcost; in TSSetCostGradients()
906 PetscErrorCode TSGetCostGradients(TS ts, PetscInt *numcost, Vec *lambda[], Vec *mu[]) in TSGetCostGradients() argument
909 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSGetCostGradients()
910 if (numcost) *numcost = ts->numcost; in TSGetCostGradients()
911 if (lambda) *lambda = ts->vecs_sensi; in TSGetCostGradients()
912 if (mu) *mu = ts->vecs_sensip; in TSGetCostGradients()
942 PetscErrorCode TSSetCostHessianProducts(TS ts, PetscInt numcost, Vec lambda2[], Vec mu2[], Vec dir) in TSSetCostHessianProducts() argument
945 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSSetCostHessianProducts()
946 …PetscCheck(!ts->numcost || ts->numcost == numcost, PetscObjectComm((PetscObject)ts), PETSC_ERR_USE… in TSSetCostHessianProducts()
947 ts->numcost = numcost; in TSSetCostHessianProducts()
948 ts->vecs_sensi2 = lambda2; in TSSetCostHessianProducts()
949 ts->vecs_sensi2p = mu2; in TSSetCostHessianProducts()
950 ts->vec_dir = dir; in TSSetCostHessianProducts()
972 PetscErrorCode TSGetCostHessianProducts(TS ts, PetscInt *numcost, Vec *lambda2[], Vec *mu2[], Vec *… in TSGetCostHessianProducts() argument
975 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSGetCostHessianProducts()
976 if (numcost) *numcost = ts->numcost; in TSGetCostHessianProducts()
977 if (lambda2) *lambda2 = ts->vecs_sensi2; in TSGetCostHessianProducts()
978 if (mu2) *mu2 = ts->vecs_sensi2p; in TSGetCostHessianProducts()
979 if (dir) *dir = ts->vec_dir; in TSGetCostHessianProducts()
1000 PetscErrorCode TSAdjointSetForward(TS ts, Mat didp) in TSAdjointSetForward() argument
1008 ts->forward_solve = PETSC_TRUE; /* turn on tangent linear mode */ in TSAdjointSetForward()
1009 …PetscCheck(ts->vecs_sensi2, PetscObjectComm((PetscObject)ts), PETSC_ERR_USER, "Must call TSSetCost… in TSAdjointSetForward()
1010 …PetscCheck(ts->vec_dir, PetscObjectComm((PetscObject)ts), PETSC_ERR_USER, "Directional vector is m… in TSAdjointSetForward()
1012 PetscCall(VecGetLocalSize(ts->vec_sol, &lsize)); in TSAdjointSetForward()
1013 …PetscCall(MatCreateDense(PetscObjectComm((PetscObject)ts), lsize, PETSC_DECIDE, PETSC_DECIDE, 1, N… in TSAdjointSetForward()
1015 PetscCall(VecDuplicate(ts->vec_sol, &sp)); in TSAdjointSetForward()
1018 if (ts->vecs_sensi2p) { /* tangent linear variable initialized as 2*dIdP*dir */ in TSAdjointSetForward()
1020 PetscCall(MatMult(didp, ts->vec_dir, sp)); in TSAdjointSetForward()
1026 PetscCall(VecCopy(ts->vec_dir, sp)); in TSAdjointSetForward()
1032 …PetscCall(TSForwardSetInitialSensitivities(ts, A)); /* if didp is NULL, identity matrix is assumed… in TSAdjointSetForward()
1050 PetscErrorCode TSAdjointResetForward(TS ts) in TSAdjointResetForward() argument
1053 ts->forward_solve = PETSC_FALSE; /* turn off tangent linear mode */ in TSAdjointResetForward()
1054 PetscCall(TSForwardReset(ts)); in TSAdjointResetForward()
1071 PetscErrorCode TSAdjointSetUp(TS ts) in TSAdjointSetUp() argument
1077 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSAdjointSetUp()
1078 if (ts->adjointsetupcalled) PetscFunctionReturn(PETSC_SUCCESS); in TSAdjointSetUp()
1079 …PetscCheck(ts->vecs_sensi, PetscObjectComm((PetscObject)ts), PETSC_ERR_ARG_WRONGSTATE, "Must call … in TSAdjointSetUp()
1080 …PetscCheck(!ts->vecs_sensip || ts->Jacp || ts->Jacprhs, PetscObjectComm((PetscObject)ts), PETSC_ER… in TSAdjointSetUp()
1081 PetscCall(TSGetTrajectory(ts, &tj)); in TSAdjointSetUp()
1086 …PetscCheck(!solution_only, PetscObjectComm((PetscObject)ts), PETSC_ERR_USER, "TSAdjoint cannot use… in TSAdjointSetUp()
1090 if (ts->quadraturets) { /* if there is integral in the cost function */ in TSAdjointSetUp()
1091 PetscCall(VecDuplicate(ts->vecs_sensi[0], &ts->vec_drdu_col)); in TSAdjointSetUp()
1092 if (ts->vecs_sensip) PetscCall(VecDuplicate(ts->vecs_sensip[0], &ts->vec_drdp_col)); in TSAdjointSetUp()
1095 PetscTryTypeMethod(ts, adjointsetup); in TSAdjointSetUp()
1096 ts->adjointsetupcalled = PETSC_TRUE; in TSAdjointSetUp()
1112 PetscErrorCode TSAdjointReset(TS ts) in TSAdjointReset() argument
1115 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSAdjointReset()
1116 PetscTryTypeMethod(ts, adjointreset); in TSAdjointReset()
1117 if (ts->quadraturets) { /* if there is integral in the cost function */ in TSAdjointReset()
1118 PetscCall(VecDestroy(&ts->vec_drdu_col)); in TSAdjointReset()
1119 if (ts->vecs_sensip) PetscCall(VecDestroy(&ts->vec_drdp_col)); in TSAdjointReset()
1121 ts->vecs_sensi = NULL; in TSAdjointReset()
1122 ts->vecs_sensip = NULL; in TSAdjointReset()
1123 ts->vecs_sensi2 = NULL; in TSAdjointReset()
1124 ts->vecs_sensi2p = NULL; in TSAdjointReset()
1125 ts->vec_dir = NULL; in TSAdjointReset()
1126 ts->adjointsetupcalled = PETSC_FALSE; in TSAdjointReset()
1147 PetscErrorCode TSAdjointSetSteps(TS ts, PetscInt steps) in TSAdjointSetSteps() argument
1150 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSAdjointSetSteps()
1151 PetscValidLogicalCollectiveInt(ts, steps, 2); in TSAdjointSetSteps()
1152 …PetscCheck(steps >= 0, PetscObjectComm((PetscObject)ts), PETSC_ERR_ARG_OUTOFRANGE, "Cannot step ba… in TSAdjointSetSteps()
1153 …PetscCheck(steps <= ts->steps, PetscObjectComm((PetscObject)ts), PETSC_ERR_ARG_OUTOFRANGE, "Cannot… in TSAdjointSetSteps()
1154 ts->adjoint_max_steps = steps; in TSAdjointSetSteps()
1164 PetscErrorCode TSAdjointSetRHSJacobian(TS ts, Mat Amat, PetscErrorCode (*func)(TS, PetscReal, Vec, … in TSAdjointSetRHSJacobian() argument
1167 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSAdjointSetRHSJacobian()
1170 ts->rhsjacobianp = func; in TSAdjointSetRHSJacobian()
1171 ts->rhsjacobianpctx = ctx; in TSAdjointSetRHSJacobian()
1174 PetscCall(MatDestroy(&ts->Jacp)); in TSAdjointSetRHSJacobian()
1175 ts->Jacp = Amat; in TSAdjointSetRHSJacobian()
1186 PetscErrorCode TSAdjointComputeRHSJacobian(TS ts, PetscReal t, Vec U, Mat Amat) in TSAdjointComputeRHSJacobian() argument
1189 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSAdjointComputeRHSJacobian()
1193 …lBack("TS callback JacobianP for sensitivity analysis", (*ts->rhsjacobianp)(ts, t, U, Amat, ts->rh… in TSAdjointComputeRHSJacobian()
1203 PetscErrorCode TSAdjointComputeDRDYFunction(TS ts, PetscReal t, Vec U, Vec *DRDU) in TSAdjointComputeDRDYFunction() argument
1206 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSAdjointComputeDRDYFunction()
1209 …PetscCallBack("TS callback DRDY for sensitivity analysis", (*ts->drdufunction)(ts, t, U, DRDU, ts-… in TSAdjointComputeDRDYFunction()
1219 PetscErrorCode TSAdjointComputeDRDPFunction(TS ts, PetscReal t, Vec U, Vec *DRDP) in TSAdjointComputeDRDPFunction() argument
1222 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSAdjointComputeDRDPFunction()
1225 …PetscCallBack("TS callback DRDP for sensitivity analysis", (*ts->drdpfunction)(ts, t, U, DRDP, ts-… in TSAdjointComputeDRDPFunction()
1237 static PetscErrorCode TSAdjointMonitorSensi(TS ts, PetscInt step, PetscReal ptime, Vec v, PetscInt … in TSAdjointMonitorSensi() argument
1272 PetscErrorCode TSAdjointMonitorSetFromOptions(TS ts, const char name[], const char help[], const ch… in TSAdjointMonitorSetFromOptions() argument
1279 …tscOptionsCreateViewer(PetscObjectComm((PetscObject)ts), ((PetscObject)ts)->options, ((PetscObject… in TSAdjointMonitorSetFromOptions()
1284 if (monitorsetup) PetscCall((*monitorsetup)(ts, vf)); in TSAdjointMonitorSetFromOptions()
1285 …PetscCall(TSAdjointMonitorSet(ts, (PetscErrorCode (*)(TS, PetscInt, PetscReal, Vec, PetscInt, Vec … in TSAdjointMonitorSetFromOptions()
1325 PetscErrorCode TSAdjointMonitorSet(TS ts, PetscErrorCode (*adjointmonitor)(TS ts, PetscInt steps, P… in TSAdjointMonitorSet() argument
1328 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSAdjointMonitorSet()
1329 for (PetscInt i = 0; i < ts->numbermonitors; i++) { in TSAdjointMonitorSet()
1332 …estroy, (PetscErrorCode (*)(void))(PetscVoidFn *)ts->adjointmonitor[i], ts->adjointmonitorcontext[… in TSAdjointMonitorSet()
1335 …PetscCheck(ts->numberadjointmonitors < MAXTSMONITORS, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "… in TSAdjointMonitorSet()
1336 ts->adjointmonitor[ts->numberadjointmonitors] = adjointmonitor; in TSAdjointMonitorSet()
1337 ts->adjointmonitordestroy[ts->numberadjointmonitors] = adjointmdestroy; in TSAdjointMonitorSet()
1338 ts->adjointmonitorcontext[ts->numberadjointmonitors++] = adjointmctx; in TSAdjointMonitorSet()
1357 PetscErrorCode TSAdjointMonitorCancel(TS ts) in TSAdjointMonitorCancel() argument
1362 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSAdjointMonitorCancel()
1363 for (i = 0; i < ts->numberadjointmonitors; i++) { in TSAdjointMonitorCancel()
1364 …if (ts->adjointmonitordestroy[i]) PetscCall((*ts->adjointmonitordestroy[i])(&ts->adjointmonitorcon… in TSAdjointMonitorCancel()
1366 ts->numberadjointmonitors = 0; in TSAdjointMonitorCancel()
1388 PetscErrorCode TSAdjointMonitorDefault(TS ts, PetscInt step, PetscReal time, Vec v, PetscInt numcos… in TSAdjointMonitorDefault() argument
1399 PetscCall(PetscViewerASCIIAddTab(viewer, ((PetscObject)ts)->tablevel)); in TSAdjointMonitorDefault()
1400 …iewer, "%" PetscInt_FMT " TS dt %g time %g%s", step, (double)ts->time_step, (double)time, ts->step… in TSAdjointMonitorDefault()
1401 PetscCall(PetscViewerASCIISubtractTab(viewer, ((PetscObject)ts)->tablevel)); in TSAdjointMonitorDefault()
1426 PetscErrorCode TSAdjointMonitorDrawSensi(TS ts, PetscInt step, PetscReal ptime, Vec u, PetscInt num… in TSAdjointMonitorDrawSensi() argument
1434 …if (!(((ictx->howoften > 0) && (!(step % ictx->howoften))) || ((ictx->howoften == -1) && ts->reaso… in TSAdjointMonitorDrawSensi()
1467 PetscErrorCode TSAdjointSetFromOptions(TS ts, PetscOptionItems PetscOptionsObject) in TSAdjointSetFromOptions() argument
1472 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSAdjointSetFromOptions()
1474 tflg = ts->adjoint_solve ? PETSC_TRUE : PETSC_FALSE; in TSAdjointSetFromOptions()
1477 PetscCall(TSSetSaveTrajectory(ts)); in TSAdjointSetFromOptions()
1478 ts->adjoint_solve = tflg; in TSAdjointSetFromOptions()
1480 …PetscCall(TSAdjointMonitorSetFromOptions(ts, "-ts_adjoint_monitor", "Monitor adjoint timestep size… in TSAdjointSetFromOptions()
1481 …PetscCall(TSAdjointMonitorSetFromOptions(ts, "-ts_adjoint_monitor_sensi", "Monitor sensitivity in … in TSAdjointSetFromOptions()
1489 …PetscCall(TSMonitorDrawCtxCreate(PetscObjectComm((PetscObject)ts), NULL, NULL, PETSC_DECIDE, PETSC… in TSAdjointSetFromOptions()
1490 …PetscCall(TSAdjointMonitorSet(ts, TSAdjointMonitorDrawSensi, ctx, (PetscCtxDestroyFn *)TSMonitorDr… in TSAdjointSetFromOptions()
1507 PetscErrorCode TSAdjointStep(TS ts) in TSAdjointStep() argument
1512 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSAdjointStep()
1513 PetscCall(TSGetDM(ts, &dm)); in TSAdjointStep()
1514 PetscCall(TSAdjointSetUp(ts)); in TSAdjointStep()
1515 ts->steps--; /* must decrease the step index before the adjoint step is taken. */ in TSAdjointStep()
1517 ts->reason = TS_CONVERGED_ITERATING; in TSAdjointStep()
1518 ts->ptime_prev = ts->ptime; in TSAdjointStep()
1519 PetscCall(PetscLogEventBegin(TS_AdjointStep, ts, 0, 0, 0)); in TSAdjointStep()
1520 PetscUseTypeMethod(ts, adjointstep); in TSAdjointStep()
1521 PetscCall(PetscLogEventEnd(TS_AdjointStep, ts, 0, 0, 0)); in TSAdjointStep()
1522 ts->adjoint_steps++; in TSAdjointStep()
1524 if (ts->reason < 0) { in TSAdjointStep()
1525 …heck(!ts->errorifstepfailed, PetscObjectComm((PetscObject)ts), PETSC_ERR_NOT_CONVERGED, "TSAdjoint… in TSAdjointStep()
1526 } else if (!ts->reason) { in TSAdjointStep()
1527 if (ts->adjoint_steps >= ts->adjoint_max_steps) ts->reason = TS_CONVERGED_ITS; in TSAdjointStep()
1553 PetscErrorCode TSAdjointSolve(TS ts) in TSAdjointSolve() argument
1561 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSAdjointSolve()
1576 PetscCall(TSAdjointSetUp(ts)); in TSAdjointSolve()
1579 ts->adjoint_steps = 0; in TSAdjointSolve()
1580 ts->ksp_its = 0; in TSAdjointSolve()
1581 ts->snes_its = 0; in TSAdjointSolve()
1582 ts->num_snes_failures = 0; in TSAdjointSolve()
1583 ts->reject = 0; in TSAdjointSolve()
1584 ts->reason = TS_CONVERGED_ITERATING; in TSAdjointSolve()
1586 if (!ts->adjoint_max_steps) ts->adjoint_max_steps = ts->steps; in TSAdjointSolve()
1587 if (ts->adjoint_steps >= ts->adjoint_max_steps) ts->reason = TS_CONVERGED_ITS; in TSAdjointSolve()
1589 while (!ts->reason) { in TSAdjointSolve()
1590 PetscCall(TSTrajectoryGet(ts->trajectory, ts, ts->steps, &ts->ptime)); in TSAdjointSolve()
1591 …PetscCall(TSAdjointMonitor(ts, ts->steps, ts->ptime, ts->vec_sol, ts->numcost, ts->vecs_sensi, ts-… in TSAdjointSolve()
1592 PetscCall(TSAdjointEventHandler(ts)); in TSAdjointSolve()
1593 PetscCall(TSAdjointStep(ts)); in TSAdjointSolve()
1594 …if ((ts->vec_costintegral || ts->quadraturets) && !ts->costintegralfwd) PetscCall(TSAdjointCostInt… in TSAdjointSolve()
1596 if (!ts->steps) { in TSAdjointSolve()
1597 PetscCall(TSTrajectoryGet(ts->trajectory, ts, ts->steps, &ts->ptime)); in TSAdjointSolve()
1598 …PetscCall(TSAdjointMonitor(ts, ts->steps, ts->ptime, ts->vec_sol, ts->numcost, ts->vecs_sensi, ts-… in TSAdjointSolve()
1600 ts->solvetime = ts->ptime; in TSAdjointSolve()
1601 PetscCall(TSTrajectoryViewFromOptions(ts->trajectory, NULL, "-ts_trajectory_view")); in TSAdjointSolve()
1602 PetscCall(VecViewFromOptions(ts->vecs_sensi[0], (PetscObject)ts, "-ts_adjoint_view_solution")); in TSAdjointSolve()
1603 ts->adjoint_max_steps = 0; in TSAdjointSolve()
1632 PetscErrorCode TSAdjointMonitor(TS ts, PetscInt step, PetscReal ptime, Vec u, PetscInt numcost, Vec… in TSAdjointMonitor() argument
1634 PetscInt i, n = ts->numberadjointmonitors; in TSAdjointMonitor()
1637 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSAdjointMonitor()
1640 …for (i = 0; i < n; i++) PetscCall((*ts->adjointmonitor[i])(ts, step, ptime, u, numcost, lambda, mu… in TSAdjointMonitor()
1660 PetscErrorCode TSAdjointCostIntegral(TS ts) in TSAdjointCostIntegral() argument
1663 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSAdjointCostIntegral()
1664 PetscUseTypeMethod(ts, adjointintegral); in TSAdjointCostIntegral()
1683 PetscErrorCode TSForwardSetUp(TS ts) in TSForwardSetUp() argument
1686 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSForwardSetUp()
1687 if (ts->forwardsetupcalled) PetscFunctionReturn(PETSC_SUCCESS); in TSForwardSetUp()
1688 PetscTryTypeMethod(ts, forwardsetup); in TSForwardSetUp()
1689 PetscCall(VecDuplicate(ts->vec_sol, &ts->vec_sensip_col)); in TSForwardSetUp()
1690 ts->forwardsetupcalled = PETSC_TRUE; in TSForwardSetUp()
1706 PetscErrorCode TSForwardReset(TS ts) in TSForwardReset() argument
1708 TS quadts = ts->quadraturets; in TSForwardReset()
1711 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSForwardReset()
1712 PetscTryTypeMethod(ts, forwardreset); in TSForwardReset()
1713 PetscCall(MatDestroy(&ts->mat_sensip)); in TSForwardReset()
1715 PetscCall(VecDestroy(&ts->vec_sensip_col)); in TSForwardReset()
1716 ts->forward_solve = PETSC_FALSE; in TSForwardReset()
1717 ts->forwardsetupcalled = PETSC_FALSE; in TSForwardReset()
1733 PetscErrorCode TSForwardSetIntegralGradients(TS ts, PetscInt numfwdint, Vec vp[]) in TSForwardSetIntegralGradients() argument
1736 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSForwardSetIntegralGradients()
1737 …PetscCheck(!ts->numcost || ts->numcost == numfwdint, PetscObjectComm((PetscObject)ts), PETSC_ERR_U… in TSForwardSetIntegralGradients()
1738 if (!ts->numcost) ts->numcost = numfwdint; in TSForwardSetIntegralGradients()
1740 ts->vecs_integral_sensip = vp; in TSForwardSetIntegralGradients()
1758 PetscErrorCode TSForwardGetIntegralGradients(TS ts, PetscInt *numfwdint, Vec *vp[]) in TSForwardGetIntegralGradients() argument
1761 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSForwardGetIntegralGradients()
1763 if (numfwdint) *numfwdint = ts->numcost; in TSForwardGetIntegralGradients()
1764 if (vp) *vp = ts->vecs_integral_sensip; in TSForwardGetIntegralGradients()
1783 PetscErrorCode TSForwardStep(TS ts) in TSForwardStep() argument
1786 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSForwardStep()
1787 PetscCall(PetscLogEventBegin(TS_ForwardStep, ts, 0, 0, 0)); in TSForwardStep()
1788 PetscUseTypeMethod(ts, forwardstep); in TSForwardStep()
1789 PetscCall(PetscLogEventEnd(TS_ForwardStep, ts, 0, 0, 0)); in TSForwardStep()
1790ts->reason >= 0 || !ts->errorifstepfailed, PetscObjectComm((PetscObject)ts), PETSC_ERR_NOT_CONVERG… in TSForwardStep()
1816 PetscErrorCode TSForwardSetSensitivities(TS ts, PetscInt nump, Mat Smat) in TSForwardSetSensitivities() argument
1819 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSForwardSetSensitivities()
1821 ts->forward_solve = PETSC_TRUE; in TSForwardSetSensitivities()
1822 …if (nump == PETSC_DEFAULT || nump == PETSC_DETERMINE) PetscCall(MatGetSize(Smat, NULL, &ts->num_pa… in TSForwardSetSensitivities()
1823 else ts->num_parameters = nump; in TSForwardSetSensitivities()
1825 PetscCall(MatDestroy(&ts->mat_sensip)); in TSForwardSetSensitivities()
1826 ts->mat_sensip = Smat; in TSForwardSetSensitivities()
1844 PetscErrorCode TSForwardGetSensitivities(TS ts, PetscInt *nump, Mat *Smat) in TSForwardGetSensitivities() argument
1847 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSForwardGetSensitivities()
1848 if (nump) *nump = ts->num_parameters; in TSForwardGetSensitivities()
1849 if (Smat) *Smat = ts->mat_sensip; in TSForwardGetSensitivities()
1868 PetscErrorCode TSForwardCostIntegral(TS ts) in TSForwardCostIntegral() argument
1871 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSForwardCostIntegral()
1872 PetscUseTypeMethod(ts, forwardintegral); in TSForwardCostIntegral()
1893 PetscErrorCode TSForwardSetInitialSensitivities(TS ts, Mat didp) in TSForwardSetInitialSensitivities() argument
1896 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSForwardSetInitialSensitivities()
1898 if (!ts->mat_sensip) PetscCall(TSForwardSetSensitivities(ts, PETSC_DETERMINE, didp)); in TSForwardSetInitialSensitivities()
1916 PetscErrorCode TSForwardGetStages(TS ts, PetscInt *ns, Mat **S) in TSForwardGetStages() argument
1919 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSForwardGetStages()
1921 if (!ts->ops->getstages) *S = NULL; in TSForwardGetStages()
1922 else PetscUseTypeMethod(ts, forwardgetstages, ns, S); in TSForwardGetStages()
1940 PetscErrorCode TSCreateQuadratureTS(TS ts, PetscBool fwd, TS *quadts) in TSCreateQuadratureTS() argument
1945 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSCreateQuadratureTS()
1947 PetscCall(TSDestroy(&ts->quadraturets)); in TSCreateQuadratureTS()
1948 PetscCall(TSCreate(PetscObjectComm((PetscObject)ts), &ts->quadraturets)); in TSCreateQuadratureTS()
1949 PetscCall(PetscObjectIncrementTabLevel((PetscObject)ts->quadraturets, (PetscObject)ts, 1)); in TSCreateQuadratureTS()
1950 …tscSNPrintf(prefix, sizeof(prefix), "%squad_", ((PetscObject)ts)->prefix ? ((PetscObject)ts)->pref… in TSCreateQuadratureTS()
1951 PetscCall(TSSetOptionsPrefix(ts->quadraturets, prefix)); in TSCreateQuadratureTS()
1952 *quadts = ts->quadraturets; in TSCreateQuadratureTS()
1954 if (ts->numcost) { in TSCreateQuadratureTS()
1955 PetscCall(VecCreateSeq(PETSC_COMM_SELF, ts->numcost, &(*quadts)->vec_sol)); in TSCreateQuadratureTS()
1959 ts->costintegralfwd = fwd; in TSCreateQuadratureTS()
1977 PetscErrorCode TSGetQuadratureTS(TS ts, PetscBool *fwd, TS *quadts) in TSGetQuadratureTS() argument
1980 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSGetQuadratureTS()
1981 if (fwd) *fwd = ts->costintegralfwd; in TSGetQuadratureTS()
1982 if (quadts) *quadts = ts->quadraturets; in TSGetQuadratureTS()
2006 PetscErrorCode TSComputeSNESJacobian(TS ts, Vec x, Mat J, Mat Jpre) in TSComputeSNESJacobian() argument
2008 SNES snes = ts->snes; in TSComputeSNESJacobian()