Lines Matching refs:ts

89 PetscErrorCode TSSetFromOptions(TS ts)  in TSSetFromOptions()  argument
102 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSSetFromOptions()
105 PetscCall(TSGetIFunction(ts, NULL, &ifun, NULL)); in TSSetFromOptions()
107 PetscObjectOptionsBegin((PetscObject)ts); in TSSetFromOptions()
108 if (((PetscObject)ts)->type_name) defaultType = ((PetscObject)ts)->type_name; in TSSetFromOptions()
111 if (opt) PetscCall(TSSetType(ts, typeName)); in TSSetFromOptions()
112 else PetscCall(TSSetType(ts, defaultType)); in TSSetFromOptions()
116 …tionsReal("-ts_max_time", "Maximum time to run to", "TSSetMaxTime", ts->max_time, &ts->max_time, N… in TSSetFromOptions()
118 if (flg) PetscCall(TSSetTimeSpan(ts, num_eval_times, eval_times)); in TSSetFromOptions()
121 …PetscCheck(flg != opt || (!flg && !opt), PetscObjectComm((PetscObject)ts), PETSC_ERR_ARG_WRONG, "M… in TSSetFromOptions()
122 if (opt) PetscCall(TSSetEvaluationTimes(ts, num_eval_times, eval_times)); in TSSetFromOptions()
123 …cute to (possibly with non-zero starting value)", "TSSetMaxSteps", ts->max_steps, &ts->max_steps, … in TSSetFromOptions()
124 …of time steps to take on each call to TSSolve()", "TSSetRunSteps", ts->run_steps, &ts->run_steps, … in TSSetFromOptions()
125 …PetscCall(PetscOptionsReal("-ts_init_time", "Initial time", "TSSetTime", ts->ptime, &ts->ptime, NU… in TSSetFromOptions()
127 …PetscCall(PetscOptionsReal("-ts_time_step", "Initial time step", "TSSetTimeStep", ts->time_step, &… in TSSetFromOptions()
128 if (flg) PetscCall(TSSetTimeStep(ts, time_step)); in TSSetFromOptions()
129 …nal time step", "TSSetExactFinalTime", TSExactFinalTimeOptions, (PetscEnum)ts->exact_final_time, (… in TSSetFromOptions()
130 if (flg) PetscCall(TSSetExactFinalTime(ts, eftopt)); in TSSetFromOptions()
131 …m number of nonlinear solve failures", "TSSetMaxSNESFailures", ts->max_snes_failures, &ts->max_sne… in TSSetFromOptions()
132 if (flg) PetscCall(TSSetMaxSNESFailures(ts, ts->max_snes_failures)); in TSSetFromOptions()
134 …r of step rejections before step fails", "TSSetMaxStepRejections", ts->max_reject, &ts->max_reject… in TSSetFromOptions()
135 if (flg) PetscCall(TSSetMaxStepRejections(ts, ts->max_reject)); in TSSetFromOptions()
136 …_fails", "Error if no step succeeds", "TSSetErrorIfStepFails", ts->errorifstepfailed, &ts->errorif… in TSSetFromOptions()
137 …, "Relative tolerance for local truncation error", "TSSetTolerances", ts->rtol, &ts->rtol, NULL, 0… in TSSetFromOptions()
138 …, "Absolute tolerance for local truncation error", "TSSetTolerances", ts->atol, &ts->atol, NULL, 0… in TSSetFromOptions()
140 …he RHS Jacobian for consistency with RHS at each solve ", "None", ts->testjacobian, &ts->testjacob… in TSSetFromOptions()
141 … transpose for consistency with RHS at each solve ", "None", ts->testjacobiantranspose, &ts->testj… in TSSetFromOptions()
142 …function for multirate solvers ", "TSSetUseSplitRHSFunction", ts->use_splitrhsfunction, &ts->use_s… in TSSetFromOptions()
147 …s memory snooper at end of TSSolve", "PetscObjectSAWsBlock", ((PetscObject)ts)->amspublishblock, &… in TSSetFromOptions()
148 if (set) PetscCall(PetscObjectSAWsSetBlock((PetscObject)ts, flg)); in TSSetFromOptions()
154 …PetscCall(TSMonitorSetFromOptions(ts, "-ts_monitor", "Monitor time and timestep size", "TSMonitorD… in TSSetFromOptions()
155 …PetscCall(TSMonitorSetFromOptions(ts, "-ts_monitor_wall_clock_time", "Monitor wall-clock time, KSP… in TSSetFromOptions()
156 …PetscCall(TSMonitorSetFromOptions(ts, "-ts_monitor_extreme", "Monitor extreme values of the soluti… in TSSetFromOptions()
157 …PetscCall(TSMonitorSetFromOptions(ts, "-ts_monitor_solution", "View the solution at each timestep"… in TSSetFromOptions()
158 …PetscCall(TSMonitorSetFromOptions(ts, "-ts_dmswarm_monitor_moments", "Monitor moments of particle … in TSSetFromOptions()
160 if (flg) PetscCall(PetscPythonMonitorSet((PetscObject)ts, monfilename)); in TSSetFromOptions()
169 PetscCall(TSGetDM(ts, &dm)); in TSSetFromOptions()
173 …PetscCall(TSMonitorLGCtxNetworkCreate(ts, NULL, NULL, PETSC_DECIDE, PETSC_DECIDE, 600, 400, howoft… in TSSetFromOptions()
174 …PetscCall(TSMonitorSet(ts, TSMonitorLGCtxNetworkSolution, ctx, (PetscCtxDestroyFn *)TSMonitorLGCtx… in TSSetFromOptions()
179 … PetscCall(TSMonitorSet(ts, TSMonitorLGSolution, ctx, (PetscCtxDestroyFn *)TSMonitorLGCtxDestroy)); in TSSetFromOptions()
190 PetscCall(TSMonitorSet(ts, TSMonitorLGError, ctx, (PetscCtxDestroyFn *)TSMonitorLGCtxDestroy)); in TSSetFromOptions()
192 …PetscCall(TSMonitorSetFromOptions(ts, "-ts_monitor_error", "View the error at each timestep", "TSM… in TSSetFromOptions()
200 …PetscCall(TSMonitorLGCtxCreate(PetscObjectComm((PetscObject)ts), NULL, NULL, PETSC_DECIDE, PETSC_D… in TSSetFromOptions()
201 … PetscCall(TSMonitorSet(ts, TSMonitorLGTimeStep, ctx, (PetscCtxDestroyFn *)TSMonitorLGCtxDestroy)); in TSSetFromOptions()
209 …PetscCall(TSMonitorLGCtxCreate(PetscObjectComm((PetscObject)ts), NULL, NULL, PETSC_DECIDE, PETSC_D… in TSSetFromOptions()
210 … PetscCall(TSMonitorSet(ts, TSMonitorLGTimeStep, ctx, (PetscCtxDestroyFn *)TSMonitorLGCtxDestroy)); in TSSetFromOptions()
220 …PetscCall(TSMonitorLGCtxCreate(PetscObjectComm((PetscObject)ts), NULL, NULL, PETSC_DECIDE, PETSC_D… in TSSetFromOptions()
221 …PetscCall(TSMonitorSet(ts, TSMonitorLGSNESIterations, ctx, (PetscCtxDestroyFn *)TSMonitorLGCtxDest… in TSSetFromOptions()
229 …PetscCall(TSMonitorLGCtxCreate(PetscObjectComm((PetscObject)ts), NULL, NULL, PETSC_DECIDE, PETSC_D… in TSSetFromOptions()
230 …PetscCall(TSMonitorSet(ts, TSMonitorLGKSPIterations, ctx, (PetscCtxDestroyFn *)TSMonitorLGCtxDestr… in TSSetFromOptions()
239 PetscCall(TSMonitorSet(ts, TSMonitorSPEig, ctx, (PetscCtxDestroyFn *)TSMonitorSPEigCtxDestroy)); in TSSetFromOptions()
247 for (PetscInt i = 0; i < ts->numbermonitors; ++i) in TSSetFromOptions()
248 if (ts->monitor[i] == TSMonitorSPSwarmSolution) { in TSSetFromOptions()
257 …PetscCall(TSMonitorSPCtxCreate(PetscObjectComm((PetscObject)ts), NULL, NULL, PETSC_DECIDE, PETSC_D… in TSSetFromOptions()
258 …PetscCall(TSMonitorSet(ts, TSMonitorSPSwarmSolution, ctx, (PetscCtxDestroyFn *)TSMonitorSPCtxDestr… in TSSetFromOptions()
267 for (PetscInt i = 0; i < ts->numbermonitors; ++i) in TSSetFromOptions()
268 if (ts->monitor[i] == TSMonitorHGSwarmSolution) { in TSSetFromOptions()
276 PetscCall(TSGetDM(ts, &sw)); in TSSetFromOptions()
284 …PetscCall(TSMonitorHGCtxCreate(PetscObjectComm((PetscObject)ts), NULL, NULL, PETSC_DECIDE, PETSC_D… in TSSetFromOptions()
285 …PetscCall(TSMonitorSet(ts, TSMonitorHGSwarmSolution, ctx, (PetscCtxDestroyFn *)TSMonitorHGCtxDestr… in TSSetFromOptions()
295 …PetscCall(TSMonitorDrawCtxCreate(PetscObjectComm((PetscObject)ts), NULL, "Computed Solution", PETS… in TSSetFromOptions()
296 …PetscCall(TSMonitorSet(ts, TSMonitorDrawSolution, ctx, (PetscCtxDestroyFn *)TSMonitorDrawCtxDestro… in TSSetFromOptions()
308 …PetscCheck(n == 4, PetscObjectComm((PetscObject)ts), PETSC_ERR_ARG_WRONG, "Must provide bounding b… in TSSetFromOptions()
309 …PetscCall(TSMonitorDrawCtxCreate(PetscObjectComm((PetscObject)ts), NULL, NULL, PETSC_DECIDE, PETSC… in TSSetFromOptions()
314 …PetscCall(TSMonitorSet(ts, TSMonitorDrawSolutionPhase, ctx, (PetscCtxDestroyFn *)TSMonitorDrawCtxD… in TSSetFromOptions()
323 …PetscCall(TSMonitorDrawCtxCreate(PetscObjectComm((PetscObject)ts), NULL, "Error", PETSC_DECIDE, PE… in TSSetFromOptions()
324 …PetscCall(TSMonitorSet(ts, TSMonitorDrawError, ctx, (PetscCtxDestroyFn *)TSMonitorDrawCtxDestroy)); in TSSetFromOptions()
333 …PetscCall(TSMonitorDrawCtxCreate(PetscObjectComm((PetscObject)ts), NULL, "Solution provided by use… in TSSetFromOptions()
334 …PetscCall(TSMonitorSet(ts, TSMonitorDrawSolutionFunction, ctx, (PetscCtxDestroyFn *)TSMonitorDrawC… in TSSetFromOptions()
344 …PetscCall(TSMonitorSet(ts, (PetscErrorCode (*)(TS, PetscInt, PetscReal, Vec, PetscCtx))TSMonitorSo… in TSSetFromOptions()
355 …PetscCheck(dir[1] == '=', PetscObjectComm((PetscObject)ts), PETSC_ERR_ARG_WRONG, "Unknown ray %s",… in TSSetFromOptions()
358 else SETERRQ(PetscObjectComm((PetscObject)ts), PETSC_ERR_ARG_WRONG, "Unknown ray %s", dir); in TSSetFromOptions()
361 PetscCall(PetscInfo(ts, "Displaying DMDA ray %c = %d\n", dir[0], ray)); in TSSetFromOptions()
363 PetscCall(TSGetDM(ts, &da)); in TSSetFromOptions()
365 PetscCallMPI(MPI_Comm_rank(PetscObjectComm((PetscObject)ts), &rank)); in TSSetFromOptions()
368 PetscCall(TSMonitorSet(ts, TSMonitorDMDARay, rayctx, TSMonitorDMDARayDestroy)); in TSSetFromOptions()
378 …PetscCheck(dir[1] == '=', PetscObjectComm((PetscObject)ts), PETSC_ERR_ARG_WRONG, "Malformed ray %s… in TSSetFromOptions()
381 …else SETERRQ(PetscObjectComm((PetscObject)ts), PETSC_ERR_ARG_WRONG, "Unknown ray direction %s", di… in TSSetFromOptions()
384 PetscCall(PetscInfo(ts, "Displaying LG DMDA ray %c = %d\n", dir[0], ray)); in TSSetFromOptions()
386 PetscCall(TSGetDM(ts, &da)); in TSSetFromOptions()
389 PetscCall(TSMonitorSet(ts, TSMonitorLGDMDARay, rayctx, TSMonitorDMDARayDestroy)); in TSSetFromOptions()
396 PetscCall(TSMonitorEnvelopeCtxCreate(ts, &ctx)); in TSSetFromOptions()
397 …PetscCall(TSMonitorSet(ts, TSMonitorEnvelope, ctx, (PetscCtxDestroyFn *)TSMonitorEnvelopeCtxDestro… in TSSetFromOptions()
401 if (opt && flg) PetscCall(TSMonitorCancel(ts)); in TSSetFromOptions()
408 PetscCall(TSGetDM(ts, &dm)); in TSSetFromOptions()
410 PetscCall(TSSetIJacobian(ts, NULL, NULL, TSComputeIJacobianDefaultColor, NULL)); in TSSetFromOptions()
411 PetscCall(PetscInfo(ts, "Setting default finite difference coloring Jacobian matrix\n")); in TSSetFromOptions()
415 PetscTryTypeMethod(ts, setfromoptions, PetscOptionsObject); in TSSetFromOptions()
418 PetscCall(TSGetAdapt(ts, &ts->adapt)); in TSSetFromOptions()
419 PetscCall(TSAdaptSetDefaultType(ts->adapt, ts->default_adapt_type)); in TSSetFromOptions()
420 PetscCall(TSAdaptSetFromOptions(ts->adapt, PetscOptionsObject)); in TSSetFromOptions()
423 tflg = ts->trajectory ? PETSC_TRUE : PETSC_FALSE; in TSSetFromOptions()
425 if (tflg) PetscCall(TSSetSaveTrajectory(ts)); in TSSetFromOptions()
427 PetscCall(TSAdjointSetFromOptions(ts, PetscOptionsObject)); in TSSetFromOptions()
430 PetscCall(PetscObjectProcessOptionsHandlers((PetscObject)ts, PetscOptionsObject)); in TSSetFromOptions()
433 if (ts->trajectory) PetscCall(TSTrajectorySetFromOptions(ts->trajectory, ts)); in TSSetFromOptions()
436 PetscCall(TSGetSNES(ts, &ts->snes)); in TSSetFromOptions()
437 if (ts->problem_type == TS_LINEAR) { in TSSetFromOptions()
438 …PetscCall(PetscObjectTypeCompareAny((PetscObject)ts->snes, &flg, SNESKSPONLY, SNESKSPTRANSPOSEONLY… in TSSetFromOptions()
439 if (!flg) PetscCall(SNESSetType(ts->snes, SNESKSPONLY)); in TSSetFromOptions()
441 PetscCall(SNESSetFromOptions(ts->snes)); in TSSetFromOptions()
463 PetscErrorCode TSGetTrajectory(TS ts, TSTrajectory *tr) in TSGetTrajectory() argument
466 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSGetTrajectory()
467 *tr = ts->trajectory; in TSGetTrajectory()
493 PetscErrorCode TSSetSaveTrajectory(TS ts) in TSSetSaveTrajectory() argument
496 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSSetSaveTrajectory()
497 …if (!ts->trajectory) PetscCall(TSTrajectoryCreate(PetscObjectComm((PetscObject)ts), &ts->trajector… in TSSetSaveTrajectory()
513 PetscErrorCode TSResetTrajectory(TS ts) in TSResetTrajectory() argument
516 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSResetTrajectory()
517 if (ts->trajectory) { in TSResetTrajectory()
518 PetscCall(TSTrajectoryDestroy(&ts->trajectory)); in TSResetTrajectory()
519 PetscCall(TSTrajectoryCreate(PetscObjectComm((PetscObject)ts), &ts->trajectory)); in TSResetTrajectory()
536 PetscErrorCode TSRemoveTrajectory(TS ts) in TSRemoveTrajectory() argument
539 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSRemoveTrajectory()
540 if (ts->trajectory) PetscCall(TSTrajectoryDestroy(&ts->trajectory)); in TSRemoveTrajectory()
567 PetscErrorCode TSComputeRHSJacobian(TS ts, PetscReal t, Vec U, Mat A, Mat B) in TSComputeRHSJacobian() argument
578 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSComputeRHSJacobian()
580 PetscCheckSameComm(ts, 1, U, 3); in TSComputeRHSJacobian()
581 PetscCall(TSGetDM(ts, &dm)); in TSComputeRHSJacobian()
588 …if (ts->rhsjacobian.time == t && (ts->problem_type == TS_LINEAR || (ts->rhsjacobian.Xid == Uid && in TSComputeRHSJacobian()
590ts->rhsjacobian.shift == 0.0 || !ts->rhsjacobian.reuse, PetscObjectComm((PetscObject)ts), PETSC_ER… in TSComputeRHSJacobian()
592 PetscCall(PetscLogEventBegin(TS_JacobianEval, U, ts, A, B)); in TSComputeRHSJacobian()
593 PetscCallBack("TS callback Jacobian", (*rhsjacobianfunc)(ts, t, U, A, B, ctx)); in TSComputeRHSJacobian()
594 ts->rhsjacs++; in TSComputeRHSJacobian()
595 PetscCall(PetscLogEventEnd(TS_JacobianEval, U, ts, A, B)); in TSComputeRHSJacobian()
600 ts->rhsjacobian.time = t; in TSComputeRHSJacobian()
601 ts->rhsjacobian.shift = 0; in TSComputeRHSJacobian()
602 ts->rhsjacobian.scale = 1.; in TSComputeRHSJacobian()
603 PetscCall(PetscObjectGetId((PetscObject)U, &ts->rhsjacobian.Xid)); in TSComputeRHSJacobian()
604 PetscCall(PetscObjectStateGet((PetscObject)U, &ts->rhsjacobian.Xstate)); in TSComputeRHSJacobian()
629 PetscErrorCode TSComputeRHSFunction(TS ts, PetscReal t, Vec U, Vec y) in TSComputeRHSFunction() argument
637 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSComputeRHSFunction()
640 PetscCall(TSGetDM(ts, &dm)); in TSComputeRHSFunction()
644 …PetscCheck(rhsfunction || ifunction, PetscObjectComm((PetscObject)ts), PETSC_ERR_USER, "Must call … in TSComputeRHSFunction()
647 PetscCall(PetscLogEventBegin(TS_FunctionEval, U, ts, y, 0)); in TSComputeRHSFunction()
649 PetscCallBack("TS callback right-hand-side", (*rhsfunction)(ts, t, U, y, ctx)); in TSComputeRHSFunction()
651 ts->rhsfuncs++; in TSComputeRHSFunction()
652 PetscCall(PetscLogEventEnd(TS_FunctionEval, U, ts, y, 0)); in TSComputeRHSFunction()
673 PetscErrorCode TSComputeSolutionFunction(TS ts, PetscReal t, Vec U) in TSComputeSolutionFunction() argument
680 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSComputeSolutionFunction()
682 PetscCall(TSGetDM(ts, &dm)); in TSComputeSolutionFunction()
684 if (solutionfunction) PetscCallBack("TS callback solution", (*solutionfunction)(ts, t, U, ctx)); in TSComputeSolutionFunction()
703 PetscErrorCode TSComputeForcingFunction(TS ts, PetscReal t, Vec U) in TSComputeForcingFunction() argument
710 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSComputeForcingFunction()
712 PetscCall(TSGetDM(ts, &dm)); in TSComputeForcingFunction()
715 if (forcing) PetscCallBack("TS callback forcing function", (*forcing)(ts, t, U, ctx)); in TSComputeForcingFunction()
719 PetscErrorCode TSGetRHSMats_Private(TS ts, Mat *Arhs, Mat *Brhs) in TSGetRHSMats_Private() argument
727 PetscCall(TSGetIJacobian(ts, &A, &B, &ijacobian, NULL)); in TSGetRHSMats_Private()
729 if (!ts->Arhs) { in TSGetRHSMats_Private()
731 PetscCall(MatDuplicate(A, MAT_DO_NOT_COPY_VALUES, &ts->Arhs)); in TSGetRHSMats_Private()
732 PetscCall(TSSetMatStructure(ts, SAME_NONZERO_PATTERN)); in TSGetRHSMats_Private()
734 ts->Arhs = A; in TSGetRHSMats_Private()
739 PetscCall(SNESGetUseMatrixFree(ts->snes, NULL, &flg)); in TSGetRHSMats_Private()
741 if (flg && !ijacobian && ts->Arhs == ts->Brhs) { in TSGetRHSMats_Private()
742 PetscCall(PetscObjectDereference((PetscObject)ts->Arhs)); in TSGetRHSMats_Private()
743 ts->Arhs = A; in TSGetRHSMats_Private()
747 *Arhs = ts->Arhs; in TSGetRHSMats_Private()
750 if (!ts->Brhs) { in TSGetRHSMats_Private()
753 PetscCall(MatDuplicate(B, MAT_DO_NOT_COPY_VALUES, &ts->Brhs)); in TSGetRHSMats_Private()
755 ts->Brhs = B; in TSGetRHSMats_Private()
759 PetscCall(PetscObjectReference((PetscObject)ts->Arhs)); in TSGetRHSMats_Private()
760 ts->Brhs = ts->Arhs; in TSGetRHSMats_Private()
763 *Brhs = ts->Brhs; in TSGetRHSMats_Private()
794 PetscErrorCode TSComputeIFunction(TS ts, PetscReal t, Vec U, Vec Udot, Vec Y, PetscBool imex) in TSComputeIFunction() argument
802 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSComputeIFunction()
807 PetscCall(TSGetDM(ts, &dm)); in TSComputeIFunction()
811 …PetscCheck(rhsfunction || ifunction, PetscObjectComm((PetscObject)ts), PETSC_ERR_USER, "Must call … in TSComputeIFunction()
813 PetscCall(PetscLogEventBegin(TS_FunctionEval, U, ts, Udot, Y)); in TSComputeIFunction()
815 PetscCallBack("TS callback implicit function", (*ifunction)(ts, t, U, Udot, Y, ctx)); in TSComputeIFunction()
816 ts->ifuncs++; in TSComputeIFunction()
825 PetscCall(TSComputeRHSFunction(ts, t, U, Frhs)); in TSComputeIFunction()
829 PetscCall(TSComputeRHSFunction(ts, t, U, Y)); in TSComputeIFunction()
833 PetscCall(PetscLogEventEnd(TS_FunctionEval, U, ts, Udot, Y)); in TSComputeIFunction()
844 static PetscErrorCode TSRecoverRHSJacobian(TS ts, Mat A, Mat B) in TSRecoverRHSJacobian() argument
847 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSRecoverRHSJacobian()
848 PetscCheck(A == ts->Arhs, PetscObjectComm((PetscObject)ts), PETSC_ERR_SUP, "Invalid Amat"); in TSRecoverRHSJacobian()
849 PetscCheck(B == ts->Brhs, PetscObjectComm((PetscObject)ts), PETSC_ERR_SUP, "Invalid Bmat"); in TSRecoverRHSJacobian()
851 if (ts->rhsjacobian.shift) PetscCall(MatShift(A, -ts->rhsjacobian.shift)); in TSRecoverRHSJacobian()
852 if (ts->rhsjacobian.scale == -1.) PetscCall(MatScale(A, -1)); in TSRecoverRHSJacobian()
853 if (B && B == ts->Brhs && A != B) { in TSRecoverRHSJacobian()
854 if (ts->rhsjacobian.shift) PetscCall(MatShift(B, -ts->rhsjacobian.shift)); in TSRecoverRHSJacobian()
855 if (ts->rhsjacobian.scale == -1.) PetscCall(MatScale(B, -1)); in TSRecoverRHSJacobian()
857 ts->rhsjacobian.shift = 0; in TSRecoverRHSJacobian()
858 ts->rhsjacobian.scale = 1.; in TSRecoverRHSJacobian()
891 PetscErrorCode TSComputeIJacobian(TS ts, PetscReal t, Vec U, Vec Udot, PetscReal shift, Mat A, Mat … in TSComputeIJacobian() argument
899 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSComputeIJacobian()
905 PetscCall(TSGetDM(ts, &dm)); in TSComputeIJacobian()
909 …PetscCheck(rhsjacobian || ijacobian, PetscObjectComm((PetscObject)ts), PETSC_ERR_USER, "Must call … in TSComputeIJacobian()
911 PetscCall(PetscLogEventBegin(TS_JacobianEval, U, ts, A, B)); in TSComputeIJacobian()
913 PetscCallBack("TS callback implicit Jacobian", (*ijacobian)(ts, t, U, Udot, shift, A, B, ctx)); in TSComputeIJacobian()
914 ts->ijacs++; in TSComputeIJacobian()
921 PetscCall(TSGetRHSMats_Private(ts, &Arhs, NULL)); in TSComputeIJacobian()
923 …PetscCheck(rhsjacobian != TSComputeRHSJacobianConstant, PetscObjectComm((PetscObject)ts), PETSC_ER… in TSComputeIJacobian()
924 ts->rhsjacobian.time = PETSC_MIN_REAL; in TSComputeIJacobian()
948 if (rhsjacobian) PetscCall(TSGetRHSMats_Private(ts, &Arhs, &Brhs)); in TSComputeIJacobian()
957 …puteRHSJacobianConstant || (ts->rhsjacobian.time == t && (ts->problem_type == TS_LINEAR || (ts->rh… in TSComputeIJacobian()
958ts->rhsjacobian.scale == -1.) { /* No need to recompute RHSJacobian */ in TSComputeIJacobian()
959 …PetscCall(MatShift(A, shift - ts->rhsjacobian.shift)); /* revert the old shift and add the new shi… in TSComputeIJacobian()
960 if (A != B) PetscCall(MatShift(B, shift - ts->rhsjacobian.shift)); in TSComputeIJacobian()
964 if (ts->rhsjacobian.reuse) { /* Undo the damage */ in TSComputeIJacobian()
968 PetscCall(TSRecoverRHSJacobian(ts, A, B)); in TSComputeIJacobian()
970 PetscCall(TSComputeRHSJacobian(ts, t, U, A, B)); in TSComputeIJacobian()
971 PetscCall(SNESGetUseMatrixFree(ts->snes, NULL, &flg)); in TSComputeIJacobian()
982 ts->rhsjacobian.scale = -1; in TSComputeIJacobian()
983 ts->rhsjacobian.shift = shift; in TSComputeIJacobian()
993 PetscCall(TSComputeRHSJacobian(ts, t, U, Arhs, Brhs)); in TSComputeIJacobian()
994 PetscCall(MatAXPY(A, -1, Arhs, ts->axpy_pattern)); in TSComputeIJacobian()
995 if (A != B) PetscCall(MatAXPY(B, -1, Brhs, ts->axpy_pattern)); in TSComputeIJacobian()
998 PetscCall(PetscLogEventEnd(TS_JacobianEval, U, ts, A, B)); in TSComputeIJacobian()
1021 PetscErrorCode TSSetRHSFunction(TS ts, Vec r, TSRHSFunctionFn *f, PetscCtx ctx) in TSSetRHSFunction() argument
1028 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSSetRHSFunction()
1031 PetscCall(TSGetDM(ts, &dm)); in TSSetRHSFunction()
1033 PetscCall(TSGetSNES(ts, &snes)); in TSSetRHSFunction()
1034 if (!r && !ts->dm && ts->vec_sol) { in TSSetRHSFunction()
1035 PetscCall(VecDuplicate(ts->vec_sol, &ralloc)); in TSSetRHSFunction()
1038 PetscCall(SNESSetFunction(snes, r, SNESTSFormFunction, ts)); in TSSetRHSFunction()
1069 PetscErrorCode TSSetSolutionFunction(TS ts, TSSolutionFn *f, PetscCtx ctx) in TSSetSolutionFunction() argument
1074 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSSetSolutionFunction()
1075 PetscCall(TSGetDM(ts, &dm)); in TSSetSolutionFunction()
1108 PetscErrorCode TSSetForcingFunction(TS ts, TSForcingFn *func, PetscCtx ctx) in TSSetForcingFunction() argument
1113 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSSetForcingFunction()
1114 PetscCall(TSGetDM(ts, &dm)); in TSSetForcingFunction()
1143 PetscErrorCode TSSetRHSJacobian(TS ts, Mat Amat, Mat Pmat, TSRHSJacobianFn *f, PetscCtx ctx) in TSSetRHSJacobian() argument
1150 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSSetRHSJacobian()
1153 if (Amat) PetscCheckSameComm(ts, 1, Amat, 2); in TSSetRHSJacobian()
1154 if (Pmat) PetscCheckSameComm(ts, 1, Pmat, 3); in TSSetRHSJacobian()
1156 PetscCall(TSGetDM(ts, &dm)); in TSSetRHSJacobian()
1159 PetscCall(TSGetSNES(ts, &snes)); in TSSetRHSJacobian()
1160 if (!ijacobian) PetscCall(SNESSetJacobian(snes, Amat, Pmat, SNESTSFormJacobian, ts)); in TSSetRHSJacobian()
1163 PetscCall(MatDestroy(&ts->Arhs)); in TSSetRHSJacobian()
1164 ts->Arhs = Amat; in TSSetRHSJacobian()
1168 PetscCall(MatDestroy(&ts->Brhs)); in TSSetRHSJacobian()
1169 ts->Brhs = Pmat; in TSSetRHSJacobian()
1193 PetscErrorCode TSSetIFunction(TS ts, Vec r, TSIFunctionFn *f, PetscCtx ctx) in TSSetIFunction() argument
1200 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSSetIFunction()
1203 PetscCall(TSGetDM(ts, &dm)); in TSSetIFunction()
1206 PetscCall(TSGetSNES(ts, &snes)); in TSSetIFunction()
1207 if (!r && !ts->dm && ts->vec_sol) { in TSSetIFunction()
1208 PetscCall(VecDuplicate(ts->vec_sol, &ralloc)); in TSSetIFunction()
1211 PetscCall(SNESSetFunction(snes, r, SNESTSFormFunction, ts)); in TSSetIFunction()
1233 PetscErrorCode TSGetIFunction(TS ts, Vec *r, TSIFunctionFn **func, PetscCtxRt ctx) in TSGetIFunction() argument
1239 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSGetIFunction()
1240 PetscCall(TSGetSNES(ts, &snes)); in TSGetIFunction()
1242 PetscCall(TSGetDM(ts, &dm)); in TSGetIFunction()
1264 PetscErrorCode TSGetRHSFunction(TS ts, Vec *r, TSRHSFunctionFn **func, PetscCtxRt ctx) in TSGetRHSFunction() argument
1270 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSGetRHSFunction()
1271 PetscCall(TSGetSNES(ts, &snes)); in TSGetRHSFunction()
1273 PetscCall(TSGetDM(ts, &dm)); in TSGetRHSFunction()
1317 PetscErrorCode TSSetIJacobian(TS ts, Mat Amat, Mat Pmat, TSIJacobianFn *f, PetscCtx ctx) in TSSetIJacobian() argument
1323 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSSetIJacobian()
1326 if (Amat) PetscCheckSameComm(ts, 1, Amat, 2); in TSSetIJacobian()
1327 if (Pmat) PetscCheckSameComm(ts, 1, Pmat, 3); in TSSetIJacobian()
1329 PetscCall(TSGetDM(ts, &dm)); in TSSetIJacobian()
1332 PetscCall(TSGetSNES(ts, &snes)); in TSSetIJacobian()
1333 PetscCall(SNESSetJacobian(snes, Amat, Pmat, SNESTSFormJacobian, ts)); in TSSetIJacobian()
1356 PetscErrorCode TSRHSJacobianSetReuse(TS ts, PetscBool reuse) in TSRHSJacobianSetReuse() argument
1359 ts->rhsjacobian.reuse = reuse; in TSRHSJacobianSetReuse()
1379 PetscErrorCode TSSetI2Function(TS ts, Vec F, TSI2FunctionFn *fun, PetscCtx ctx) in TSSetI2Function() argument
1384 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSSetI2Function()
1386 PetscCall(TSSetIFunction(ts, F, NULL, NULL)); in TSSetI2Function()
1387 PetscCall(TSGetDM(ts, &dm)); in TSSetI2Function()
1409 PetscErrorCode TSGetI2Function(TS ts, Vec *r, TSI2FunctionFn **fun, PetscCtxRt ctx) in TSGetI2Function() argument
1415 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSGetI2Function()
1416 PetscCall(TSGetSNES(ts, &snes)); in TSGetI2Function()
1418 PetscCall(TSGetDM(ts, &dm)); in TSGetI2Function()
1448 PetscErrorCode TSSetI2Jacobian(TS ts, Mat J, Mat P, TSI2JacobianFn *jac, PetscCtx ctx) in TSSetI2Jacobian() argument
1453 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSSetI2Jacobian()
1456 PetscCall(TSSetIJacobian(ts, J, P, NULL, NULL)); in TSSetI2Jacobian()
1457 PetscCall(TSGetDM(ts, &dm)); in TSSetI2Jacobian()
1483 PetscErrorCode TSGetI2Jacobian(TS ts, Mat *J, Mat *P, TSI2JacobianFn **jac, PetscCtxRt ctx) in TSGetI2Jacobian() argument
1489 PetscCall(TSGetSNES(ts, &snes)); in TSGetI2Jacobian()
1492 PetscCall(TSGetDM(ts, &dm)); in TSGetI2Jacobian()
1520 PetscErrorCode TSComputeI2Function(TS ts, PetscReal t, Vec U, Vec V, Vec A, Vec F) in TSComputeI2Function() argument
1528 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSComputeI2Function()
1534 PetscCall(TSGetDM(ts, &dm)); in TSComputeI2Function()
1539 PetscCall(TSComputeIFunction(ts, t, U, A, F, PETSC_FALSE)); in TSComputeI2Function()
1543 PetscCall(PetscLogEventBegin(TS_FunctionEval, U, ts, V, F)); in TSComputeI2Function()
1545 PetscCallBack("TS callback implicit function", I2Function(ts, t, U, V, A, F, ctx)); in TSComputeI2Function()
1551 PetscCall(TSComputeRHSFunction(ts, t, U, Frhs)); in TSComputeI2Function()
1556 PetscCall(PetscLogEventEnd(TS_FunctionEval, U, ts, V, F)); in TSComputeI2Function()
1592 PetscErrorCode TSComputeI2Jacobian(TS ts, PetscReal t, Vec U, Vec V, Vec A, PetscReal shiftV, Petsc… in TSComputeI2Jacobian() argument
1600 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSComputeI2Jacobian()
1607 PetscCall(TSGetDM(ts, &dm)); in TSComputeI2Jacobian()
1612 PetscCall(TSComputeIJacobian(ts, t, U, A, shiftA, J, P, PETSC_FALSE)); in TSComputeI2Jacobian()
1616 PetscCall(PetscLogEventBegin(TS_JacobianEval, U, ts, J, P)); in TSComputeI2Jacobian()
1617 …PetscCallBack("TS callback implicit Jacobian", I2Jacobian(ts, t, U, V, A, shiftV, shiftA, J, P, ct… in TSComputeI2Jacobian()
1620 PetscCall(TSGetRHSMats_Private(ts, &Jrhs, &Prhs)); in TSComputeI2Jacobian()
1621 PetscCall(TSComputeRHSJacobian(ts, t, U, Jrhs, Prhs)); in TSComputeI2Jacobian()
1622 PetscCall(MatAXPY(J, -1, Jrhs, ts->axpy_pattern)); in TSComputeI2Jacobian()
1623 if (P != J) PetscCall(MatAXPY(P, -1, Prhs, ts->axpy_pattern)); in TSComputeI2Jacobian()
1626 PetscCall(PetscLogEventEnd(TS_JacobianEval, U, ts, J, P)); in TSComputeI2Jacobian()
1654 PetscErrorCode TSSetTransientVariable(TS ts, TSTransientVariableFn *tvar, PetscCtx ctx) in TSSetTransientVariable() argument
1659 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSSetTransientVariable()
1660 PetscCall(TSGetDM(ts, &dm)); in TSSetTransientVariable()
1686 PetscErrorCode TSComputeTransientVariable(TS ts, Vec U, Vec C) in TSComputeTransientVariable() argument
1692 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSComputeTransientVariable()
1694 PetscCall(TSGetDM(ts, &dm)); in TSComputeTransientVariable()
1698 PetscCall((*dmts->ops->transientvar)(ts, U, C, dmts->transientvarctx)); in TSComputeTransientVariable()
1718 PetscErrorCode TSHasTransientVariable(TS ts, PetscBool *has) in TSHasTransientVariable() argument
1724 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSHasTransientVariable()
1725 PetscCall(TSGetDM(ts, &dm)); in TSHasTransientVariable()
1746 PetscErrorCode TS2SetSolution(TS ts, Vec u, Vec v) in TS2SetSolution() argument
1749 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TS2SetSolution()
1752 PetscCall(TSSetSolution(ts, u)); in TS2SetSolution()
1754 PetscCall(VecDestroy(&ts->vec_dot)); in TS2SetSolution()
1755 ts->vec_dot = v; in TS2SetSolution()
1781 PetscErrorCode TS2GetSolution(TS ts, Vec *u, Vec *v) in TS2GetSolution() argument
1784 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TS2GetSolution()
1787 if (u) *u = ts->vec_sol; in TS2GetSolution()
1788 if (v) *v = ts->vec_dot; in TS2GetSolution()
1809 PetscErrorCode TSLoad(TS ts, PetscViewer viewer) in TSLoad() argument
1818 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSLoad()
1824 …PetscCheck(classid == TS_FILE_CLASSID, PetscObjectComm((PetscObject)ts), PETSC_ERR_ARG_WRONG, "Not… in TSLoad()
1826 PetscCall(TSSetType(ts, type)); in TSLoad()
1827 PetscTryTypeMethod(ts, load, viewer); in TSLoad()
1828 PetscCall(DMCreate(PetscObjectComm((PetscObject)ts), &dm)); in TSLoad()
1830 PetscCall(TSSetDM(ts, dm)); in TSLoad()
1831 PetscCall(DMCreateGlobalVector(ts->dm, &ts->vec_sol)); in TSLoad()
1832 PetscCall(VecLoad(ts->vec_sol, viewer)); in TSLoad()
1833 PetscCall(DMGetDMTS(ts->dm, &sdm)); in TSLoad()
1857 PetscErrorCode TSViewFromOptions(TS ts, PetscObject obj, const char name[]) in TSViewFromOptions() argument
1860 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSViewFromOptions()
1861 PetscCall(PetscObjectViewFromOptions((PetscObject)ts, obj, name)); in TSViewFromOptions()
1896 PetscErrorCode TSView(TS ts, PetscViewer viewer) in TSView() argument
1906 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSView()
1907 if (!viewer) PetscCall(PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject)ts), &viewer)); in TSView()
1909 PetscCheckSameComm(ts, 1, viewer, 2); in TSView()
1919 PetscCall(PetscObjectPrintClassNamePrefixType((PetscObject)ts, viewer)); in TSView()
1920 if (ts->ops->view) { in TSView()
1922 PetscUseTypeMethod(ts, view, viewer); in TSView()
1925 …PetscCall(PetscViewerASCIIPrintf(viewer, " initial time step=%g\n", (double)ts->initial_time_step… in TSView()
1926 …if (ts->max_steps < PETSC_INT_MAX) PetscCall(PetscViewerASCIIPrintf(viewer, " maximum steps=%" Pe… in TSView()
1927 …if (ts->run_steps < PETSC_INT_MAX) PetscCall(PetscViewerASCIIPrintf(viewer, " run steps=%" PetscI… in TSView()
1928 …if (ts->max_time < PETSC_MAX_REAL) PetscCall(PetscViewerASCIIPrintf(viewer, " maximum time=%g\n",… in TSView()
1929 …if (ts->max_reject != PETSC_UNLIMITED) PetscCall(PetscViewerASCIIPrintf(viewer, " maximum number … in TSView()
1930 …(ts->max_snes_failures != PETSC_UNLIMITED) PetscCall(PetscViewerASCIIPrintf(viewer, " maximum num… in TSView()
1931 …if (ts->ifuncs) PetscCall(PetscViewerASCIIPrintf(viewer, " total number of I function evaluations… in TSView()
1932 …if (ts->ijacs) PetscCall(PetscViewerASCIIPrintf(viewer, " total number of I Jacobian evaluations=… in TSView()
1933 …if (ts->rhsfuncs) PetscCall(PetscViewerASCIIPrintf(viewer, " total number of RHS function evaluat… in TSView()
1934 …if (ts->rhsjacs) PetscCall(PetscViewerASCIIPrintf(viewer, " total number of RHS Jacobian evaluati… in TSView()
1935 if (ts->usessnes) { in TSView()
1937 …f (ts->problem_type == TS_NONLINEAR) PetscCall(PetscViewerASCIIPrintf(viewer, " total number of n… in TSView()
1938 …SCIIPrintf(viewer, " total number of linear solver iterations=%" PetscInt_FMT "\n", ts->ksp_its)); in TSView()
1939 …PetscCall(PetscObjectTypeCompareAny((PetscObject)ts->snes, &lin, SNESKSPONLY, SNESKSPTRANSPOSEONLY… in TSView()
1940 … number of %slinear solve failures=%" PetscInt_FMT "\n", lin ? "" : "non", ts->num_snes_failures)); in TSView()
1942 …etscViewerASCIIPrintf(viewer, " total number of rejected steps=%" PetscInt_FMT "\n", ts->reject)); in TSView()
1943 …if (ts->vrtol) PetscCall(PetscViewerASCIIPrintf(viewer, " using vector of relative error toleranc… in TSView()
1944 …Call(PetscViewerASCIIPrintf(viewer, " using relative error tolerance of %g, ", (double)ts->rtol)); in TSView()
1945 …if (ts->vatol) PetscCall(PetscViewerASCIIPrintf(viewer, "using vector of absolute error tolerances… in TSView()
1946 …scCall(PetscViewerASCIIPrintf(viewer, "using absolute error tolerance of %g\n", (double)ts->atol)); in TSView()
1948 PetscCall(TSAdaptView(ts->adapt, viewer)); in TSView()
1951 PetscCall(TSGetType(ts, &type)); in TSView()
1953 PetscTryTypeMethod(ts, view, viewer); in TSView()
1960 PetscCall(PetscObjectGetComm((PetscObject)ts, &comm)); in TSView()
1964 PetscCall(PetscStrncpy(type, ((PetscObject)ts)->type_name, 256)); in TSView()
1967 PetscTryTypeMethod(ts, view, viewer); in TSView()
1968 if (ts->adapt) PetscCall(TSAdaptView(ts->adapt, viewer)); in TSView()
1969 PetscCall(DMView(ts->dm, viewer)); in TSView()
1970 PetscCall(VecView(ts->vec_sol, viewer)); in TSView()
1971 PetscCall(DMGetDMTS(ts->dm, &sdm)); in TSView()
1981 PetscCall(PetscStrlcat(str, ((PetscObject)ts)->type_name, sizeof(str))); in TSView()
1985 PetscTryTypeMethod(ts, view, viewer); in TSView()
1986 if (ts->adapt) PetscCall(TSAdaptView(ts->adapt, viewer)); in TSView()
1987 if (ts->snes) PetscCall(SNESView(ts->snes, viewer)); in TSView()
1994 PetscCall(PetscObjectGetName((PetscObject)ts, &name)); in TSView()
1996 if (!((PetscObject)ts)->amsmem && rank == 0) { in TSView()
1999 PetscCall(PetscObjectViewSAWs((PetscObject)ts, viewer)); in TSView()
2001 PetscCallSAWs(SAWs_Register, (dir, &ts->steps, 1, SAWs_READ, SAWs_INT)); in TSView()
2003 PetscCallSAWs(SAWs_Register, (dir, &ts->ptime, 1, SAWs_READ, SAWs_DOUBLE)); in TSView()
2005 PetscTryTypeMethod(ts, view, viewer); in TSView()
2008 if (ts->snes && ts->usessnes) { in TSView()
2010 PetscCall(SNESView(ts->snes, viewer)); in TSView()
2013 PetscCall(DMGetDMTS(ts->dm, &sdm)); in TSView()
2017 PetscCall(PetscObjectTypeCompare((PetscObject)ts, TSSUNDIALS, &issundials)); in TSView()
2041 PetscErrorCode TSSetApplicationContext(TS ts, PetscCtx ctx) in TSSetApplicationContext() argument
2044 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSSetApplicationContext()
2045 ts->ctx = ctx; in TSSetApplicationContext()
2071 PetscErrorCode TSGetApplicationContext(TS ts, PetscCtxRt ctx) in TSGetApplicationContext() argument
2074 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSGetApplicationContext()
2075 *(void **)ctx = ts->ctx; in TSGetApplicationContext()
2094 PetscErrorCode TSGetStepNumber(TS ts, PetscInt *steps) in TSGetStepNumber() argument
2097 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSGetStepNumber()
2099 *steps = ts->steps; in TSGetStepNumber()
2126 PetscErrorCode TSSetStepNumber(TS ts, PetscInt steps) in TSSetStepNumber() argument
2129 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSSetStepNumber()
2130 PetscValidLogicalCollectiveInt(ts, steps, 2); in TSSetStepNumber()
2131 …PetscCheck(steps >= 0, PetscObjectComm((PetscObject)ts), PETSC_ERR_ARG_OUTOFRANGE, "Step number mu… in TSSetStepNumber()
2132 ts->steps = steps; in TSSetStepNumber()
2157 PetscErrorCode TSSetTimeStep(TS ts, PetscReal time_step) in TSSetTimeStep() argument
2160 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSSetTimeStep()
2161 PetscValidLogicalCollectiveReal(ts, time_step, 2); in TSSetTimeStep()
2162 ts->time_step = time_step; in TSSetTimeStep()
2163 if (ts->setupcalled == PETSC_FALSE) ts->initial_time_step = time_step; in TSSetTimeStep()
2195 PetscErrorCode TSSetExactFinalTime(TS ts, TSExactFinalTimeOption eftopt) in TSSetExactFinalTime() argument
2198 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSSetExactFinalTime()
2199 PetscValidLogicalCollectiveEnum(ts, eftopt, 2); in TSSetExactFinalTime()
2200 ts->exact_final_time = eftopt; in TSSetExactFinalTime()
2219 PetscErrorCode TSGetExactFinalTime(TS ts, TSExactFinalTimeOption *eftopt) in TSGetExactFinalTime() argument
2222 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSGetExactFinalTime()
2224 *eftopt = ts->exact_final_time; in TSGetExactFinalTime()
2243 PetscErrorCode TSGetTimeStep(TS ts, PetscReal *dt) in TSGetTimeStep() argument
2246 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSGetTimeStep()
2248 *dt = ts->time_step; in TSGetTimeStep()
2274 PetscErrorCode TSGetSolution(TS ts, Vec *v) in TSGetSolution() argument
2277 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSGetSolution()
2279 *v = ts->vec_sol; in TSGetSolution()
2304 PetscErrorCode TSGetSolutionComponents(TS ts, PetscInt *n, Vec *v) in TSGetSolutionComponents() argument
2307 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSGetSolutionComponents()
2308 if (!ts->ops->getsolutioncomponents) *n = 0; in TSGetSolutionComponents()
2309 else PetscUseTypeMethod(ts, getsolutioncomponents, n, v); in TSGetSolutionComponents()
2327 PetscErrorCode TSGetAuxSolution(TS ts, Vec *v) in TSGetAuxSolution() argument
2330 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSGetAuxSolution()
2331 if (ts->ops->getauxsolution) PetscUseTypeMethod(ts, getauxsolution, v); in TSGetAuxSolution()
2354 PetscErrorCode TSGetTimeError(TS ts, PetscInt n, Vec *v) in TSGetTimeError() argument
2357 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSGetTimeError()
2358 if (ts->ops->gettimeerror) PetscUseTypeMethod(ts, gettimeerror, n, v); in TSGetTimeError()
2378 PetscErrorCode TSSetTimeError(TS ts, Vec v) in TSSetTimeError() argument
2381 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSSetTimeError()
2382 …PetscCheck(ts->setupcalled, PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE, "Must call TSSetUp() first"… in TSSetTimeError()
2383 PetscTryTypeMethod(ts, settimeerror, v); in TSSetTimeError()
2406 PetscErrorCode TSSetProblemType(TS ts, TSProblemType type) in TSSetProblemType() argument
2409 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSSetProblemType()
2410 ts->problem_type = type; in TSSetProblemType()
2413 PetscCall(TSGetSNES(ts, &snes)); in TSSetProblemType()
2439 PetscErrorCode TSGetProblemType(TS ts, TSProblemType *type) in TSGetProblemType() argument
2442 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSGetProblemType()
2444 *type = ts->problem_type; in TSGetProblemType()
2451 static PetscErrorCode TSSetExactFinalTimeDefault(TS ts) in TSSetExactFinalTimeDefault() argument
2456 PetscCall(TSGetAdapt(ts, &ts->adapt)); in TSSetExactFinalTimeDefault()
2457 PetscCall(TSAdaptSetDefaultType(ts->adapt, ts->default_adapt_type)); in TSSetExactFinalTimeDefault()
2459 PetscCall(PetscObjectTypeCompare((PetscObject)ts->adapt, TSADAPTNONE, &isnone)); in TSSetExactFinalTimeDefault()
2460 …if (!isnone && ts->exact_final_time == TS_EXACTFINALTIME_UNSPECIFIED) ts->exact_final_time = TS_EX… in TSSetExactFinalTimeDefault()
2461 …else if (ts->exact_final_time == TS_EXACTFINALTIME_UNSPECIFIED) ts->exact_final_time = TS_EXACTFIN… in TSSetExactFinalTimeDefault()
2484 PetscErrorCode TSSetUp(TS ts) in TSSetUp() argument
2495 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSSetUp()
2496 if (ts->setupcalled) PetscFunctionReturn(PETSC_SUCCESS); in TSSetUp()
2498 if (!((PetscObject)ts)->type_name) { in TSSetUp()
2499 PetscCall(TSGetIFunction(ts, NULL, &ifun, NULL)); in TSSetUp()
2500 PetscCall(TSSetType(ts, ifun ? TSBEULER : TSEULER)); in TSSetUp()
2503 if (!ts->vec_sol) { in TSSetUp()
2504 … PetscCheck(ts->dm, PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE, "Must call TSSetSolution() first"); in TSSetUp()
2505 PetscCall(DMCreateGlobalVector(ts->dm, &ts->vec_sol)); in TSSetUp()
2508 …if (!ts->Jacp && ts->Jacprhs) { /* IJacobianP shares the same matrix with RHSJacobianP if only RHS… in TSSetUp()
2509 PetscCall(PetscObjectReference((PetscObject)ts->Jacprhs)); in TSSetUp()
2510 ts->Jacp = ts->Jacprhs; in TSSetUp()
2513 if (ts->quadraturets) { in TSSetUp()
2514 PetscCall(TSSetUp(ts->quadraturets)); in TSSetUp()
2515 PetscCall(VecDestroy(&ts->vec_costintegrand)); in TSSetUp()
2516 PetscCall(VecDuplicate(ts->quadraturets->vec_sol, &ts->vec_costintegrand)); in TSSetUp()
2519 PetscCall(TSGetRHSJacobian(ts, NULL, NULL, &rhsjac, NULL)); in TSSetUp()
2523 PetscCall(TSGetSNES(ts, &snes)); in TSSetUp()
2527 if (Amat && Amat == ts->Arhs) { in TSSetUp()
2529 PetscCall(MatDuplicate(ts->Arhs, MAT_COPY_VALUES, &Amat)); in TSSetUp()
2533 if (Pmat && Pmat == ts->Brhs) { in TSSetUp()
2534 PetscCall(MatDuplicate(ts->Brhs, MAT_COPY_VALUES, &Pmat)); in TSSetUp()
2540 PetscCall(TSGetAdapt(ts, &ts->adapt)); in TSSetUp()
2541 PetscCall(TSAdaptSetDefaultType(ts->adapt, ts->default_adapt_type)); in TSSetUp()
2543 PetscTryTypeMethod(ts, setup); in TSSetUp()
2545 PetscCall(TSSetExactFinalTimeDefault(ts)); in TSSetUp()
2550 PetscCall(TSGetDM(ts, &dm)); in TSSetUp()
2552 if (!func) PetscCall(DMSNESSetFunction(dm, SNESTSFormFunction, ts)); in TSSetUp()
2561 if (!jac && (ijac || i2jac || rhsjac)) PetscCall(DMSNESSetJacobian(dm, SNESTSFormJacobian, ts)); in TSSetUp()
2564 PetscTryTypeMethod(ts, startingmethod); in TSSetUp()
2566 ts->setupcalled = PETSC_TRUE; in TSSetUp()
2587 PetscErrorCode TSReset(TS ts) in TSReset() argument
2589 TS_RHSSplitLink ilink = ts->tsrhssplit, next; in TSReset()
2592 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSReset()
2594 PetscTryTypeMethod(ts, reset); in TSReset()
2595 if (ts->snes) PetscCall(SNESReset(ts->snes)); in TSReset()
2596 if (ts->adapt) PetscCall(TSAdaptReset(ts->adapt)); in TSReset()
2598 PetscCall(MatDestroy(&ts->Arhs)); in TSReset()
2599 PetscCall(MatDestroy(&ts->Brhs)); in TSReset()
2600 PetscCall(VecDestroy(&ts->Frhs)); in TSReset()
2601 PetscCall(VecDestroy(&ts->vec_sol)); in TSReset()
2602 PetscCall(VecDestroy(&ts->vec_sol0)); in TSReset()
2603 PetscCall(VecDestroy(&ts->vec_dot)); in TSReset()
2604 PetscCall(VecDestroy(&ts->vatol)); in TSReset()
2605 PetscCall(VecDestroy(&ts->vrtol)); in TSReset()
2606 PetscCall(VecDestroyVecs(ts->nwork, &ts->work)); in TSReset()
2608 PetscCall(MatDestroy(&ts->Jacprhs)); in TSReset()
2609 PetscCall(MatDestroy(&ts->Jacp)); in TSReset()
2610 if (ts->forward_solve) PetscCall(TSForwardReset(ts)); in TSReset()
2611 if (ts->quadraturets) { in TSReset()
2612 PetscCall(TSReset(ts->quadraturets)); in TSReset()
2613 PetscCall(VecDestroy(&ts->vec_costintegrand)); in TSReset()
2617 PetscCall(TSDestroy(&ilink->ts)); in TSReset()
2623 ts->tsrhssplit = NULL; in TSReset()
2624 ts->num_rhs_splits = 0; in TSReset()
2625 if (ts->eval_times) { in TSReset()
2626 PetscCall(PetscFree(ts->eval_times->time_points)); in TSReset()
2627 PetscCall(PetscFree(ts->eval_times->sol_times)); in TSReset()
2628 PetscCall(VecDestroyVecs(ts->eval_times->num_time_points, &ts->eval_times->sol_vecs)); in TSReset()
2629 PetscCall(PetscFree(ts->eval_times)); in TSReset()
2631 ts->rhsjacobian.time = PETSC_MIN_REAL; in TSReset()
2632 ts->rhsjacobian.scale = 1.0; in TSReset()
2633 ts->ijacobian.shift = 1.0; in TSReset()
2634 ts->setupcalled = PETSC_FALSE; in TSReset()
2653 PetscErrorCode TSDestroy(TS *ts) in TSDestroy() argument
2656 if (!*ts) PetscFunctionReturn(PETSC_SUCCESS); in TSDestroy()
2657 PetscValidHeaderSpecific(*ts, TS_CLASSID, 1); in TSDestroy()
2658 if (--((PetscObject)*ts)->refct > 0) { in TSDestroy()
2659 *ts = NULL; in TSDestroy()
2663 PetscCall(TSReset(*ts)); in TSDestroy()
2664 PetscCall(TSAdjointReset(*ts)); in TSDestroy()
2665 if ((*ts)->forward_solve) PetscCall(TSForwardReset(*ts)); in TSDestroy()
2666 PetscCall(TSResizeReset(*ts)); in TSDestroy()
2669 PetscCall(PetscObjectSAWsViewOff((PetscObject)*ts)); in TSDestroy()
2670 PetscTryTypeMethod(*ts, destroy); in TSDestroy()
2672 PetscCall(TSTrajectoryDestroy(&(*ts)->trajectory)); in TSDestroy()
2674 PetscCall(TSAdaptDestroy(&(*ts)->adapt)); in TSDestroy()
2675 PetscCall(TSEventDestroy(&(*ts)->event)); in TSDestroy()
2677 PetscCall(SNESDestroy(&(*ts)->snes)); in TSDestroy()
2678 PetscCall(SNESDestroy(&(*ts)->snesrhssplit)); in TSDestroy()
2679 PetscCall(DMDestroy(&(*ts)->dm)); in TSDestroy()
2680 PetscCall(TSMonitorCancel(*ts)); in TSDestroy()
2681 PetscCall(TSAdjointMonitorCancel(*ts)); in TSDestroy()
2683 PetscCall(TSDestroy(&(*ts)->quadraturets)); in TSDestroy()
2684 PetscCall(PetscHeaderDestroy(ts)); in TSDestroy()
2712 PetscErrorCode TSGetSNES(TS ts, SNES *snes) in TSGetSNES() argument
2715 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSGetSNES()
2717 if (!ts->snes) { in TSGetSNES()
2718 PetscCall(SNESCreate(PetscObjectComm((PetscObject)ts), &ts->snes)); in TSGetSNES()
2719 PetscCall(PetscObjectSetOptions((PetscObject)ts->snes, ((PetscObject)ts)->options)); in TSGetSNES()
2720 PetscCall(SNESSetFunction(ts->snes, NULL, SNESTSFormFunction, ts)); in TSGetSNES()
2721 PetscCall(PetscObjectIncrementTabLevel((PetscObject)ts->snes, (PetscObject)ts, 1)); in TSGetSNES()
2722 if (ts->dm) PetscCall(SNESSetDM(ts->snes, ts->dm)); in TSGetSNES()
2723 if (ts->problem_type == TS_LINEAR) PetscCall(SNESSetType(ts->snes, SNESKSPONLY)); in TSGetSNES()
2725 *snes = ts->snes; in TSGetSNES()
2745 PetscErrorCode TSSetSNES(TS ts, SNES snes) in TSSetSNES() argument
2750 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSSetSNES()
2753 PetscCall(SNESDestroy(&ts->snes)); in TSSetSNES()
2755 ts->snes = snes; in TSSetSNES()
2757 PetscCall(SNESSetFunction(ts->snes, NULL, SNESTSFormFunction, ts)); in TSSetSNES()
2758 PetscCall(SNESGetJacobian(ts->snes, NULL, NULL, &func, NULL)); in TSSetSNES()
2759 …func == SNESTSFormJacobian) PetscCall(SNESSetJacobian(ts->snes, NULL, NULL, SNESTSFormJacobian, ts in TSSetSNES()
2787 PetscErrorCode TSGetKSP(TS ts, KSP *ksp) in TSGetKSP() argument
2792 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSGetKSP()
2794 …PetscCheck(((PetscObject)ts)->type_name, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL, "KSP is not created … in TSGetKSP()
2795 …PetscCheck(ts->problem_type == TS_LINEAR, PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "Linear only; use … in TSGetKSP()
2796 PetscCall(TSGetSNES(ts, &snes)); in TSGetKSP()
2827 PetscErrorCode TSSetMaxSteps(TS ts, PetscInt maxsteps) in TSSetMaxSteps() argument
2830 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSSetMaxSteps()
2831 PetscValidLogicalCollectiveInt(ts, maxsteps, 2); in TSSetMaxSteps()
2833 ts->max_steps = ts->default_max_steps; in TSSetMaxSteps()
2835 …PetscCheck(maxsteps >= 0, PetscObjectComm((PetscObject)ts), PETSC_ERR_ARG_OUTOFRANGE, "Maximum num… in TSSetMaxSteps()
2836 ts->max_steps = maxsteps; in TSSetMaxSteps()
2856 PetscErrorCode TSGetMaxSteps(TS ts, PetscInt *maxsteps) in TSGetMaxSteps() argument
2859 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSGetMaxSteps()
2861 *maxsteps = ts->max_steps; in TSGetMaxSteps()
2888 PetscErrorCode TSSetRunSteps(TS ts, PetscInt runsteps) in TSSetRunSteps() argument
2891 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSSetRunSteps()
2892 PetscValidLogicalCollectiveInt(ts, runsteps, 2); in TSSetRunSteps()
2894 ts->run_steps = PETSC_UNLIMITED; in TSSetRunSteps()
2896 …PetscCheck(runsteps >= 0, PetscObjectComm((PetscObject)ts), PETSC_ERR_ARG_OUTOFRANGE, "Max number … in TSSetRunSteps()
2897 ts->run_steps = runsteps; in TSSetRunSteps()
2917 PetscErrorCode TSGetRunSteps(TS ts, PetscInt *runsteps) in TSGetRunSteps() argument
2920 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSGetRunSteps()
2922 *runsteps = ts->run_steps; in TSGetRunSteps()
2950 PetscErrorCode TSSetMaxTime(TS ts, PetscReal maxtime) in TSSetMaxTime() argument
2953 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSSetMaxTime()
2954 PetscValidLogicalCollectiveReal(ts, maxtime, 2); in TSSetMaxTime()
2956 ts->max_time = ts->default_max_time; in TSSetMaxTime()
2958 ts->max_time = maxtime; in TSSetMaxTime()
2978 PetscErrorCode TSGetMaxTime(TS ts, PetscReal *maxtime) in TSGetMaxTime() argument
2981 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSGetMaxTime()
2983 *maxtime = ts->max_time; in TSGetMaxTime()
2994 PetscErrorCode TSSetInitialTimeStep(TS ts, PetscReal initial_time, PetscReal time_step) in TSSetInitialTimeStep() argument
2997 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSSetInitialTimeStep()
2998 PetscCall(TSSetTime(ts, initial_time)); in TSSetInitialTimeStep()
2999 PetscCall(TSSetTimeStep(ts, time_step)); in TSSetInitialTimeStep()
3010 PetscErrorCode TSGetDuration(TS ts, PetscInt *maxsteps, PetscReal *maxtime) in TSGetDuration() argument
3013 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSGetDuration()
3016 *maxsteps = ts->max_steps; in TSGetDuration()
3020 *maxtime = ts->max_time; in TSGetDuration()
3032 PetscErrorCode TSSetDuration(TS ts, PetscInt maxsteps, PetscReal maxtime) in TSSetDuration() argument
3035 if (maxsteps != PETSC_CURRENT) PetscCall(TSSetMaxSteps(ts, maxsteps)); in TSSetDuration()
3036 if (maxtime != (PetscReal)PETSC_CURRENT) PetscCall(TSSetMaxTime(ts, maxtime)); in TSSetDuration()
3047 PetscErrorCode TSGetTimeStepNumber(TS ts, PetscInt *steps) in TSGetTimeStepNumber() argument
3049 return TSGetStepNumber(ts, steps); in TSGetTimeStepNumber()
3059 PetscErrorCode TSGetTotalSteps(TS ts, PetscInt *steps) in TSGetTotalSteps() argument
3061 return TSGetStepNumber(ts, steps); in TSGetTotalSteps()
3078 PetscErrorCode TSSetSolution(TS ts, Vec u) in TSSetSolution() argument
3083 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSSetSolution()
3086 PetscCall(VecDestroy(&ts->vec_sol)); in TSSetSolution()
3087 ts->vec_sol = u; in TSSetSolution()
3089 PetscCall(TSGetDM(ts, &dm)); in TSSetSolution()
3111 PetscErrorCode TSSetPreStep(TS ts, PetscErrorCode (*func)(TS ts)) in TSSetPreStep() argument
3114 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSSetPreStep()
3115 ts->prestep = func; in TSSetPreStep()
3135 PetscErrorCode TSPreStep(TS ts) in TSPreStep() argument
3138 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSPreStep()
3139 if (ts->prestep) { in TSPreStep()
3145 PetscCall(TSGetSolution(ts, &U)); in TSPreStep()
3148 PetscCallBack("TS callback preset", (*ts->prestep)(ts)); in TSPreStep()
3149 PetscCall(TSGetSolution(ts, &U)); in TSPreStep()
3152 if (!sameObject || sprev != spost) PetscCall(TSRestartStep(ts)); in TSPreStep()
3180 PetscErrorCode TSSetPreStage(TS ts, PetscErrorCode (*func)(TS ts, PetscReal stagetime)) in TSSetPreStage() argument
3183 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSSetPreStage()
3184 ts->prestage = func; in TSSetPreStage()
3213 PetscErrorCode TSSetPostStage(TS ts, PetscErrorCode (*func)(TS ts, PetscReal stagetime, PetscInt st… in TSSetPostStage() argument
3216 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSSetPostStage()
3217 ts->poststage = func; in TSSetPostStage()
3259 PetscErrorCode TSSetPostEvaluate(TS ts, PetscErrorCode (*func)(TS ts)) in TSSetPostEvaluate() argument
3262 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSSetPostEvaluate()
3263 ts->postevaluate = func; in TSSetPostEvaluate()
3284 PetscErrorCode TSPreStage(TS ts, PetscReal stagetime) in TSPreStage() argument
3287 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSPreStage()
3288 if (ts->prestage) PetscCallBack("TS callback prestage", (*ts->prestage)(ts, stagetime)); in TSPreStage()
3311 PetscErrorCode TSPostStage(TS ts, PetscReal stagetime, PetscInt stageindex, Vec Y[]) in TSPostStage() argument
3314 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSPostStage()
3315 …if (ts->poststage) PetscCallBack("TS callback poststage", (*ts->poststage)(ts, stagetime, stageind… in TSPostStage()
3335 PetscErrorCode TSPostEvaluate(TS ts) in TSPostEvaluate() argument
3338 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSPostEvaluate()
3339 if (ts->postevaluate) { in TSPostEvaluate()
3343 PetscCall(TSGetSolution(ts, &U)); in TSPostEvaluate()
3345 PetscCallBack("TS callback postevaluate", (*ts->postevaluate)(ts)); in TSPostEvaluate()
3347 if (sprev != spost) PetscCall(TSRestartStep(ts)); in TSPostEvaluate()
3389 PetscErrorCode TSSetPostStep(TS ts, PetscErrorCode (*func)(TS ts)) in TSSetPostStep() argument
3392 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSSetPostStep()
3393 ts->poststep = func; in TSSetPostStep()
3413 PetscErrorCode TSPostStep(TS ts) in TSPostStep() argument
3416 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSPostStep()
3417 if (ts->poststep) { in TSPostStep()
3423 PetscCall(TSGetSolution(ts, &U)); in TSPostStep()
3426 PetscCallBack("TS callback poststep", (*ts->poststep)(ts)); in TSPostStep()
3427 PetscCall(TSGetSolution(ts, &U)); in TSPostStep()
3430 if (!sameObject || sprev != spost) PetscCall(TSRestartStep(ts)); in TSPostStep()
3454 PetscErrorCode TSInterpolate(TS ts, PetscReal t, Vec U) in TSInterpolate() argument
3457 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSInterpolate()
3459ts->ptime_prev && t <= ts->ptime, PetscObjectComm((PetscObject)ts), PETSC_ERR_ARG_OUTOFRANGE, "Req… in TSInterpolate()
3460 PetscUseTypeMethod(ts, interpolate, t, U); in TSInterpolate()
3485 PetscErrorCode TSStep(TS ts) in TSStep() argument
3491 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSStep()
3500 PetscCall(TSSetUp(ts)); in TSStep()
3501 PetscCall(TSTrajectorySetUp(ts->trajectory, ts)); in TSStep()
3502 if (ts->eval_times) in TSStep()
3503ts->eval_times->worktol = 0; /* In each step of TSSolve() 'eval_times->worktol' will be meaningful… in TSStep()
3506 …PetscCheck(ts->max_time < PETSC_MAX_REAL || ts->run_steps != PETSC_INT_MAX || ts->max_steps != PET… in TSStep()
3507 …PetscCheck(ts->exact_final_time != TS_EXACTFINALTIME_UNSPECIFIED, PetscObjectComm((PetscObject)ts)… in TSStep()
3508 …PetscCheck(ts->exact_final_time != TS_EXACTFINALTIME_MATCHSTEP || ts->adapt, PetscObjectComm((Pets… in TSStep()
3510 if (!ts->vec_sol0) PetscCall(VecDuplicate(ts->vec_sol, &ts->vec_sol0)); in TSStep()
3511 PetscCall(VecCopy(ts->vec_sol, ts->vec_sol0)); in TSStep()
3512 ts->time_step0 = ts->time_step; in TSStep()
3514 if (!ts->steps) ts->ptime_prev = ts->ptime; in TSStep()
3515 ptime = ts->ptime; in TSStep()
3517 ts->ptime_prev_rollback = ts->ptime_prev; in TSStep()
3518 ts->reason = TS_CONVERGED_ITERATING; in TSStep()
3520 PetscCall(PetscLogEventBegin(TS_Step, ts, 0, 0, 0)); in TSStep()
3521 PetscUseTypeMethod(ts, step); in TSStep()
3522 PetscCall(PetscLogEventEnd(TS_Step, ts, 0, 0, 0)); in TSStep()
3524 if (ts->reason >= 0) { in TSStep()
3525 ts->ptime_prev = ptime; in TSStep()
3526 ts->steps++; in TSStep()
3527 ts->steprollback = PETSC_FALSE; in TSStep()
3528 ts->steprestart = PETSC_FALSE; in TSStep()
3529 ts->stepresize = PETSC_FALSE; in TSStep()
3532 if (ts->reason < 0 && ts->errorifstepfailed) { in TSStep()
3533 PetscCall(TSMonitorCancel(ts)); in TSStep()
3534 if (ts->usessnes && ts->snes) PetscCall(SNESMonitorCancel(ts->snes)); in TSStep()
3535ts->reason != TS_DIVERGED_NONLINEAR_SOLVE, PetscObjectComm((PetscObject)ts), PETSC_ERR_NOT_CONVERG… in TSStep()
3536 …TERRQ(PetscObjectComm((PetscObject)ts), PETSC_ERR_NOT_CONVERGED, "TSStep has failed due to %s", TS… in TSStep()
3567 PetscErrorCode TSEvaluateWLTE(TS ts, NormType wnormtype, PetscInt *order, PetscReal *wlte) in TSEvaluateWLTE() argument
3570 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSEvaluateWLTE()
3571 PetscValidType(ts, 1); in TSEvaluateWLTE()
3572 PetscValidLogicalCollectiveEnum(ts, wnormtype, 2); in TSEvaluateWLTE()
3574 if (order) PetscValidLogicalCollectiveInt(ts, *order, 3); in TSEvaluateWLTE()
3576 …PetscCheck(wnormtype == NORM_2 || wnormtype == NORM_INFINITY, PetscObjectComm((PetscObject)ts), PE… in TSEvaluateWLTE()
3577 PetscUseTypeMethod(ts, evaluatewlte, wnormtype, order, wlte); in TSEvaluateWLTE()
3603 PetscErrorCode TSEvaluateStep(TS ts, PetscInt order, Vec U, PetscBool *done) in TSEvaluateStep() argument
3606 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSEvaluateStep()
3607 PetscValidType(ts, 1); in TSEvaluateStep()
3609 PetscUseTypeMethod(ts, evaluatestep, order, U, done); in TSEvaluateStep()
3632 PetscErrorCode TSGetComputeInitialCondition(TS ts, PetscErrorCode (**initCondition)(TS ts, Vec u)) in TSGetComputeInitialCondition() argument
3635 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSGetComputeInitialCondition()
3637 *initCondition = ts->ops->initcondition; in TSGetComputeInitialCondition()
3658 PetscErrorCode TSSetComputeInitialCondition(TS ts, PetscErrorCode (*initCondition)(TS ts, Vec e)) in TSSetComputeInitialCondition() argument
3661 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSSetComputeInitialCondition()
3663 ts->ops->initcondition = initCondition; in TSSetComputeInitialCondition()
3680 PetscErrorCode TSComputeInitialCondition(TS ts, Vec u) in TSComputeInitialCondition() argument
3683 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSComputeInitialCondition()
3685 PetscTryTypeMethod(ts, initcondition, u); in TSComputeInitialCondition()
3709 PetscErrorCode TSGetComputeExactError(TS ts, PetscErrorCode (**exactError)(TS ts, Vec u, Vec e)) in TSGetComputeExactError() argument
3712 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSGetComputeExactError()
3714 *exactError = ts->ops->exacterror; in TSGetComputeExactError()
3736 PetscErrorCode TSSetComputeExactError(TS ts, PetscErrorCode (*exactError)(TS ts, Vec u, Vec e)) in TSSetComputeExactError() argument
3739 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSSetComputeExactError()
3741 ts->ops->exacterror = exactError; in TSSetComputeExactError()
3759 PetscErrorCode TSComputeExactError(TS ts, Vec u, Vec e) in TSComputeExactError() argument
3762 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSComputeExactError()
3765 PetscTryTypeMethod(ts, exacterror, u, e); in TSComputeExactError()
3816ts, PetscBool rollback, PetscErrorCode (*setup)(TS ts, PetscInt step, PetscReal time, Vec state, P… in TSSetResize() argument
3819 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSSetResize()
3820 ts->resizerollback = rollback; in TSSetResize()
3821 ts->resizesetup = setup; in TSSetResize()
3822 ts->resizetransfer = transfer; in TSSetResize()
3823 ts->resizectx = ctx; in TSSetResize()
3845 static PetscErrorCode TSResizeRegisterOrRetrieve(TS ts, PetscBool flg) in TSResizeRegisterOrRetrieve() argument
3848 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSResizeRegisterOrRetrieve()
3849 PetscTryTypeMethod(ts, resizeregister, flg); in TSResizeRegisterOrRetrieve()
3854 static PetscErrorCode TSResizeReset(TS ts) in TSResizeReset() argument
3857 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSResizeReset()
3858 PetscCall(PetscObjectListDestroy(&ts->resizetransferobjs)); in TSResizeReset()
3862 static PetscErrorCode TSResizeTransferVecs(TS ts, PetscInt cnt, Vec vecsin[], Vec vecsout[]) in TSResizeTransferVecs() argument
3865 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSResizeTransferVecs()
3866 PetscValidLogicalCollectiveInt(ts, cnt, 2); in TSResizeTransferVecs()
3868 if (ts->resizetransfer) { in TSResizeTransferVecs()
3869 PetscCall(PetscInfo(ts, "Transferring %" PetscInt_FMT " vectors\n", cnt)); in TSResizeTransferVecs()
3870 …PetscCallBack("TS callback resize transfer", (*ts->resizetransfer)(ts, cnt, vecsin, vecsout, ts->r… in TSResizeTransferVecs()
3894 PetscErrorCode TSResizeRegisterVec(TS ts, const char name[], Vec vec) in TSResizeRegisterVec() argument
3897 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSResizeRegisterVec()
3900 PetscCall(PetscObjectListAdd(&ts->resizetransferobjs, name, (PetscObject)vec)); in TSResizeRegisterVec()
3922 PetscErrorCode TSResizeRetrieveVec(TS ts, const char name[], Vec *vec) in TSResizeRetrieveVec() argument
3925 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSResizeRetrieveVec()
3928 PetscCall(PetscObjectListFind(ts->resizetransferobjs, name, (PetscObject *)vec)); in TSResizeRetrieveVec()
3932 static PetscErrorCode TSResizeGetVecArray(TS ts, PetscInt *nv, const char **names[], Vec *vecs[]) in TSResizeGetVecArray() argument
3940 for (tmp = ts->resizetransferobjs, cnt = 0; tmp; tmp = tmp->next) in TSResizeGetVecArray()
3944 for (tmp = ts->resizetransferobjs, cnt = 0; tmp; tmp = tmp->next) { in TSResizeGetVecArray()
3973 PetscErrorCode TSResize(TS ts) in TSResize() argument
3981 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSResize()
3982 if (!ts->resizesetup) PetscFunctionReturn(PETSC_SUCCESS); in TSResize()
3983 if (ts->resizesetup) { in TSResize()
3984 PetscCall(VecLockReadPush(ts->vec_sol)); in TSResize()
3985 …CallBack("TS callback resize setup", (*ts->resizesetup)(ts, ts->steps, ts->ptime, ts->vec_sol, &ts in TSResize()
3986 PetscCall(VecLockReadPop(ts->vec_sol)); in TSResize()
3987 if (ts->stepresize) { in TSResize()
3988 if (ts->resizerollback) { in TSResize()
3989 PetscCall(TSRollBack(ts)); in TSResize()
3990 ts->time_step = ts->time_step0; in TSResize()
3992 PetscCall(TSResizeRegisterVec(ts, solname, ts->vec_sol)); in TSResize()
3993 …PetscCall(TSResizeRegisterOrRetrieve(ts, PETSC_TRUE)); /* specific impls register their own object… in TSResize()
3997 PetscCall(TSResizeGetVecArray(ts, &nv, &names, &vecsin)); in TSResize()
4002 PetscCall(TSReset(ts)); in TSResize()
4006 PetscCall(TSResizeTransferVecs(ts, nv, vecsin, vecsout)); in TSResize()
4013 PetscCall(TSResizeRegisterVec(ts, names[i], vecsout[i])); in TSResize()
4019 …PetscCall(TSResizeRegisterOrRetrieve(ts, PETSC_FALSE)); /* specific impls import the transferred o… in TSResize()
4021 PetscCall(TSResizeRetrieveVec(ts, solname, &vecsol)); in TSResize()
4022 if (vecsol) PetscCall(TSSetSolution(ts, vecsol)); in TSResize()
4023 …PetscAssert(ts->vec_sol, PetscObjectComm((PetscObject)ts), PETSC_ERR_ARG_NULL, "Missing TS solutio… in TSResize()
4028 PetscCall(TSResizeReset(ts)); in TSResize()
4051 PetscErrorCode TSSolve(TS ts, Vec u) in TSSolve() argument
4056 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSSolve()
4059 PetscCall(TSSetExactFinalTimeDefault(ts)); in TSSolve()
4060 …if (ts->exact_final_time == TS_EXACTFINALTIME_INTERPOLATE && u) { /* Need ts->vec_sol to be distin… in TSSolve()
4061 if (!ts->vec_sol || u == ts->vec_sol) { in TSSolve()
4063 PetscCall(TSSetSolution(ts, solution)); in TSSolve()
4066 PetscCall(VecCopy(u, ts->vec_sol)); in TSSolve()
4067 …PetscCheck(!ts->forward_solve, PetscObjectComm((PetscObject)ts), PETSC_ERR_SUP, "Sensitivity analy… in TSSolve()
4068 } else if (u) PetscCall(TSSetSolution(ts, u)); in TSSolve()
4069 PetscCall(TSSetUp(ts)); in TSSolve()
4070 PetscCall(TSTrajectorySetUp(ts->trajectory, ts)); in TSSolve()
4072 …PetscCheck(ts->max_time < PETSC_MAX_REAL || ts->run_steps != PETSC_INT_MAX || ts->max_steps != PET… in TSSolve()
4073 …PetscCheck(ts->exact_final_time != TS_EXACTFINALTIME_UNSPECIFIED, PetscObjectComm((PetscObject)ts)… in TSSolve()
4074 …PetscCheck(ts->exact_final_time != TS_EXACTFINALTIME_MATCHSTEP || ts->adapt, PetscObjectComm((Pets… in TSSolve()
4075 …PetscCheck(!(ts->eval_times && ts->exact_final_time != TS_EXACTFINALTIME_MATCHSTEP), PetscObjectCo… in TSSolve()
4077 if (ts->eval_times) { in TSSolve()
4078 …if (!ts->eval_times->sol_vecs) PetscCall(VecDuplicateVecs(ts->vec_sol, ts->eval_times->num_time_po… in TSSolve()
4079 for (PetscInt i = 0; i < ts->eval_times->num_time_points; i++) { in TSSolve()
4080 …ool is_close = PetscIsCloseAtTol(ts->ptime, ts->eval_times->time_points[i], ts->eval_times->reltol… in TSSolve()
4081 if (ts->ptime <= ts->eval_times->time_points[i] || is_close) { in TSSolve()
4082 ts->eval_times->time_point_idx = i; in TSSolve()
4085ts->eval_times->sol_idx > 0) is_ptime_in_sol_times = PetscIsCloseAtTol(ts->ptime, ts->eval_times->… in TSSolve()
4087 PetscCall(VecCopy(ts->vec_sol, ts->eval_times->sol_vecs[ts->eval_times->sol_idx])); in TSSolve()
4088 ts->eval_times->sol_times[ts->eval_times->sol_idx] = ts->ptime; in TSSolve()
4089 ts->eval_times->sol_idx++; in TSSolve()
4090 ts->eval_times->time_point_idx++; in TSSolve()
4097 if (ts->forward_solve) PetscCall(TSForwardSetUp(ts)); in TSSolve()
4104 if (!ts->steps) { in TSSolve()
4105 ts->ksp_its = 0; in TSSolve()
4106 ts->snes_its = 0; in TSSolve()
4107 ts->num_snes_failures = 0; in TSSolve()
4108 ts->reject = 0; in TSSolve()
4109 ts->steprestart = PETSC_TRUE; in TSSolve()
4110 ts->steprollback = PETSC_FALSE; in TSSolve()
4111 ts->stepresize = PETSC_FALSE; in TSSolve()
4112 ts->rhsjacobian.time = PETSC_MIN_REAL; in TSSolve()
4116 if (ts->exact_final_time == TS_EXACTFINALTIME_MATCHSTEP) { in TSSolve()
4118 PetscReal dt = ts->time_step; in TSSolve()
4120 …if (ts->eval_times) maxdt = ts->eval_times->time_points[ts->eval_times->time_point_idx] - ts->ptim… in TSSolve()
4121 else maxdt = ts->max_time - ts->ptime; in TSSolve()
4122ts->time_step = dt >= maxdt ? maxdt : (PetscIsCloseAtTol(dt, maxdt, 10 * PETSC_MACHINE_EPSILON, 0)… in TSSolve()
4124 ts->reason = TS_CONVERGED_ITERATING; in TSSolve()
4134 …tscOptionsCreateViewer(PetscObjectComm((PetscObject)ts), ((PetscObject)ts)->options, ((PetscObject… in TSSolve()
4143 …PetscCall(PetscOptionsGetBool(((PetscObject)ts)->options, ((PetscObject)ts)->prefix, "-ts_converge… in TSSolve()
4144 PetscCall(TSGetDM(ts, &dm)); in TSSolve()
4147 PetscCall(PetscConvEstCreate(PetscObjectComm((PetscObject)ts), &conv)); in TSSolve()
4149 PetscCall(PetscConvEstSetSolver(conv, (PetscObject)ts)); in TSSolve()
4164 PetscCall(TSViewFromOptions(ts, NULL, "-ts_view_pre")); in TSSolve()
4166 …if (ts->ops->solve) { /* This private interface is transitional and should be removed when all imp… in TSSolve()
4167 PetscUseTypeMethod(ts, solve); in TSSolve()
4168 if (u) PetscCall(VecCopy(ts->vec_sol, u)); in TSSolve()
4169 ts->solvetime = ts->ptime; in TSSolve()
4170 solution = ts->vec_sol; in TSSolve()
4172 if (ts->steps >= ts->max_steps) ts->reason = TS_CONVERGED_ITS; in TSSolve()
4173 else if (ts->ptime >= ts->max_time) ts->reason = TS_CONVERGED_TIME; in TSSolve()
4175 if (!ts->steps) { in TSSolve()
4176 PetscCall(TSTrajectorySet(ts->trajectory, ts, ts->steps, ts->ptime, ts->vec_sol)); in TSSolve()
4177 PetscCall(TSEventInitialize(ts->event, ts, ts->ptime, ts->vec_sol)); in TSSolve()
4180 ts->start_step = ts->steps; // records starting step in TSSolve()
4181 while (!ts->reason) { in TSSolve()
4182 PetscCall(TSMonitor(ts, ts->steps, ts->ptime, ts->vec_sol)); in TSSolve()
4183 if (!ts->steprollback || (ts->stepresize && ts->resizerollback)) PetscCall(TSPreStep(ts)); in TSSolve()
4184 PetscCall(TSStep(ts)); in TSSolve()
4185 if (ts->testjacobian) PetscCall(TSRHSJacobianTest(ts, NULL)); in TSSolve()
4186 if (ts->testjacobiantranspose) PetscCall(TSRHSJacobianTestTranspose(ts, NULL)); in TSSolve()
4187 …if (ts->quadraturets && ts->costintegralfwd) { /* Must evaluate the cost integral before event is … in TSSolve()
4188 … if (ts->reason >= 0) ts->steps--; /* Revert the step number changed by TSStep() */ in TSSolve()
4189 PetscCall(TSForwardCostIntegral(ts)); in TSSolve()
4190 if (ts->reason >= 0) ts->steps++; in TSSolve()
4192 …if (ts->forward_solve) { /* compute forward sensitivities before event handling because… in TSSolve()
4193 if (ts->reason >= 0) ts->steps--; /* Revert the step number changed by TSStep() */ in TSSolve()
4194 PetscCall(TSForwardStep(ts)); in TSSolve()
4195 if (ts->reason >= 0) ts->steps++; in TSSolve()
4197 PetscCall(TSPostEvaluate(ts)); in TSSolve()
4198 …PetscCall(TSEventHandler(ts)); /* The right-hand side may be changed due to event. Be careful with… in TSSolve()
4199 if (ts->steprollback) PetscCall(TSPostEvaluate(ts)); in TSSolve()
4200 if (!ts->steprollback && ts->resizerollback) PetscCall(TSResize(ts)); in TSSolve()
4202 if (!ts->reason) { in TSSolve()
4203 if ((ts->steps - ts->start_step) >= ts->run_steps) ts->reason = TS_CONVERGED_ITS; in TSSolve()
4204 else if (ts->steps >= ts->max_steps) ts->reason = TS_CONVERGED_ITS; in TSSolve()
4205 else if (ts->ptime >= ts->max_time) ts->reason = TS_CONVERGED_TIME; in TSSolve()
4207 if (!ts->steprollback) { in TSSolve()
4208 PetscCall(TSTrajectorySet(ts->trajectory, ts, ts->steps, ts->ptime, ts->vec_sol)); in TSSolve()
4209 PetscCall(TSPostStep(ts)); in TSSolve()
4210 if (!ts->resizerollback) PetscCall(TSResize(ts)); in TSSolve()
4212 …if (ts->eval_times && ts->eval_times->time_point_idx < ts->eval_times->num_time_points && ts->reas… in TSSolve()
4213 …PetscCheck(ts->eval_times->worktol > 0, PetscObjectComm((PetscObject)ts), PETSC_ERR_PLIB, "Unexpec… in TSSolve()
4214 …if (PetscIsCloseAtTol(ts->ptime, ts->eval_times->time_points[ts->eval_times->time_point_idx], ts->… in TSSolve()
4215 ts->eval_times->sol_times[ts->eval_times->sol_idx] = ts->ptime; in TSSolve()
4216 PetscCall(VecCopy(ts->vec_sol, ts->eval_times->sol_vecs[ts->eval_times->sol_idx])); in TSSolve()
4217 ts->eval_times->sol_idx++; in TSSolve()
4218 ts->eval_times->time_point_idx++; in TSSolve()
4223 PetscCall(TSMonitor(ts, ts->steps, ts->ptime, ts->vec_sol)); in TSSolve()
4225 if (ts->exact_final_time == TS_EXACTFINALTIME_INTERPOLATE && ts->ptime > ts->max_time) { in TSSolve()
4226 if (!u) u = ts->vec_sol; in TSSolve()
4227 PetscCall(TSInterpolate(ts, ts->max_time, u)); in TSSolve()
4228 ts->solvetime = ts->max_time; in TSSolve()
4230 PetscCall(TSMonitor(ts, -1, ts->solvetime, solution)); in TSSolve()
4232 if (u) PetscCall(VecCopy(ts->vec_sol, u)); in TSSolve()
4233 ts->solvetime = ts->ptime; in TSSolve()
4234 solution = ts->vec_sol; in TSSolve()
4238 PetscCall(TSViewFromOptions(ts, NULL, "-ts_view")); in TSSolve()
4239 PetscCall(VecViewFromOptions(solution, (PetscObject)ts, "-ts_view_solution")); in TSSolve()
4240 PetscCall(PetscObjectSAWsBlock((PetscObject)ts)); in TSSolve()
4241 if (ts->adjoint_solve) PetscCall(TSAdjointSolve(ts)); in TSSolve()
4264 PetscErrorCode TSGetTime(TS ts, PetscReal *t) in TSGetTime() argument
4267 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSGetTime()
4269 *t = ts->ptime; in TSGetTime()
4288 PetscErrorCode TSGetPrevTime(TS ts, PetscReal *t) in TSGetPrevTime() argument
4291 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSGetPrevTime()
4293 *t = ts->ptime_prev; in TSGetPrevTime()
4310 PetscErrorCode TSSetTime(TS ts, PetscReal t) in TSSetTime() argument
4313 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSSetTime()
4314 PetscValidLogicalCollectiveReal(ts, t, 2); in TSSetTime()
4315 ts->ptime = t; in TSSetTime()
4338 PetscErrorCode TSSetOptionsPrefix(TS ts, const char prefix[]) in TSSetOptionsPrefix() argument
4343 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSSetOptionsPrefix()
4344 PetscCall(PetscObjectSetOptionsPrefix((PetscObject)ts, prefix)); in TSSetOptionsPrefix()
4345 PetscCall(TSGetSNES(ts, &snes)); in TSSetOptionsPrefix()
4369 PetscErrorCode TSAppendOptionsPrefix(TS ts, const char prefix[]) in TSAppendOptionsPrefix() argument
4374 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSAppendOptionsPrefix()
4375 PetscCall(PetscObjectAppendOptionsPrefix((PetscObject)ts, prefix)); in TSAppendOptionsPrefix()
4376 PetscCall(TSGetSNES(ts, &snes)); in TSAppendOptionsPrefix()
4397 PetscErrorCode TSGetOptionsPrefix(TS ts, const char *prefix[]) in TSGetOptionsPrefix() argument
4400 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSGetOptionsPrefix()
4402 PetscCall(PetscObjectGetOptionsPrefix((PetscObject)ts, prefix)); in TSGetOptionsPrefix()
4428 PetscErrorCode TSGetRHSJacobian(TS ts, Mat *Amat, Mat *Pmat, TSRHSJacobianFn **func, PetscCtxRt ctx) in TSGetRHSJacobian() argument
4435 PetscCall(TSGetSNES(ts, &snes)); in TSGetRHSJacobian()
4439 PetscCall(TSGetDM(ts, &dm)); in TSGetRHSJacobian()
4465 PetscErrorCode TSGetIJacobian(TS ts, Mat *Amat, Mat *Pmat, TSIJacobianFn **f, PetscCtxRt ctx) in TSGetIJacobian() argument
4472 PetscCall(TSGetSNES(ts, &snes)); in TSGetIJacobian()
4476 PetscCall(TSGetDM(ts, &dm)); in TSGetIJacobian()
4500 PetscErrorCode TSSetDM(TS ts, DM dm) in TSSetDM() argument
4506 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSSetDM()
4509 if (ts->dm) { /* Move the DMTS context over to the new DM unless the new DM already has one */ in TSSetDM()
4510 if (ts->dm->dmts && !dm->dmts) { in TSSetDM()
4511 PetscCall(DMCopyDMTS(ts->dm, dm)); in TSSetDM()
4512 PetscCall(DMGetDMTS(ts->dm, &tsdm)); in TSSetDM()
4514 if (tsdm->originaldm == ts->dm) tsdm->originaldm = dm; in TSSetDM()
4516 PetscCall(DMDestroy(&ts->dm)); in TSSetDM()
4518 ts->dm = dm; in TSSetDM()
4520 PetscCall(TSGetSNES(ts, &snes)); in TSSetDM()
4540 PetscErrorCode TSGetDM(TS ts, DM *dm) in TSGetDM() argument
4543 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSGetDM()
4544 if (!ts->dm) { in TSGetDM()
4545 PetscCall(DMShellCreate(PetscObjectComm((PetscObject)ts), &ts->dm)); in TSGetDM()
4546 if (ts->snes) PetscCall(SNESSetDM(ts->snes, ts->dm)); in TSGetDM()
4548 *dm = ts->dm; in TSGetDM()
4575 TS ts = (TS)ctx; in SNESTSFormFunction() local
4581 PetscValidHeaderSpecific(ts, TS_CLASSID, 4); in SNESTSFormFunction()
4582 …etscCheck(ts->ops->snesfunction, PetscObjectComm((PetscObject)ts), PETSC_ERR_SUP, "No method snesf… in SNESTSFormFunction()
4583 PetscCall((*ts->ops->snesfunction)(snes, U, F, ts)); in SNESTSFormFunction()
4610 TS ts = (TS)ctx; in SNESTSFormJacobian() local
4617 PetscValidHeaderSpecific(ts, TS_CLASSID, 5); in SNESTSFormJacobian()
4618 …etscCheck(ts->ops->snesjacobian, PetscObjectComm((PetscObject)ts), PETSC_ERR_SUP, "No method snesj… in SNESTSFormJacobian()
4619 PetscCall((*ts->ops->snesjacobian)(snes, U, A, B, ts)); in SNESTSFormJacobian()
4645 PetscErrorCode TSComputeRHSFunctionLinear(TS ts, PetscReal t, Vec U, Vec F, PetscCtx ctx) in TSComputeRHSFunctionLinear() argument
4650 PetscCall(TSGetRHSMats_Private(ts, &Arhs, &Brhs)); in TSComputeRHSFunctionLinear()
4652 PetscCall(TSRecoverRHSJacobian(ts, Arhs, Brhs)); in TSComputeRHSFunctionLinear()
4653 PetscCall(TSComputeRHSJacobian(ts, t, U, Arhs, Brhs)); in TSComputeRHSFunctionLinear()
4680 PetscErrorCode TSComputeRHSJacobianConstant(TS ts, PetscReal t, Vec U, Mat A, Mat B, PetscCtx ctx) in TSComputeRHSJacobianConstant() argument
4713 PetscErrorCode TSComputeIFunctionLinear(TS ts, PetscReal t, Vec U, Vec Udot, Vec F, PetscCtx ctx) in TSComputeIFunctionLinear() argument
4718 PetscCall(TSGetIJacobian(ts, &A, &B, NULL, NULL)); in TSComputeIFunctionLinear()
4719 PetscCall(TSComputeIJacobian(ts, t, U, Udot, 1.0, A, B, PETSC_TRUE)); in TSComputeIFunctionLinear()
4765 PetscErrorCode TSComputeIJacobianConstant(TS ts, PetscReal t, Vec U, Vec Udot, PetscReal shift, Mat… in TSComputeIJacobianConstant() argument
4768 PetscCall(MatScale(A, shift / ts->ijacobian.shift)); in TSComputeIJacobianConstant()
4769 ts->ijacobian.shift = shift; in TSComputeIJacobianConstant()
4788 PetscErrorCode TSGetEquationType(TS ts, TSEquationType *equation_type) in TSGetEquationType() argument
4791 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSGetEquationType()
4793 *equation_type = ts->equation_type; in TSGetEquationType()
4810 PetscErrorCode TSSetEquationType(TS ts, TSEquationType equation_type) in TSSetEquationType() argument
4813 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSSetEquationType()
4814 ts->equation_type = equation_type; in TSSetEquationType()
4837 PetscErrorCode TSGetConvergedReason(TS ts, TSConvergedReason *reason) in TSGetConvergedReason() argument
4840 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSGetConvergedReason()
4842 *reason = ts->reason; in TSGetConvergedReason()
4863 PetscErrorCode TSSetConvergedReason(TS ts, TSConvergedReason reason) in TSSetConvergedReason() argument
4866 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSSetConvergedReason()
4867 ts->reason = reason; in TSSetConvergedReason()
4889 PetscErrorCode TSGetSolveTime(TS ts, PetscReal *ftime) in TSGetSolveTime() argument
4892 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSGetSolveTime()
4894 *ftime = ts->solvetime; in TSGetSolveTime()
4917 PetscErrorCode TSGetSNESIterations(TS ts, PetscInt *nits) in TSGetSNESIterations() argument
4920 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSGetSNESIterations()
4922 *nits = ts->snes_its; in TSGetSNESIterations()
4945 PetscErrorCode TSGetKSPIterations(TS ts, PetscInt *lits) in TSGetKSPIterations() argument
4948 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSGetKSPIterations()
4950 *lits = ts->ksp_its; in TSGetKSPIterations()
4972 PetscErrorCode TSGetStepRejections(TS ts, PetscInt *rejects) in TSGetStepRejections() argument
4975 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSGetStepRejections()
4977 *rejects = ts->reject; in TSGetStepRejections()
4999 PetscErrorCode TSGetSNESFailures(TS ts, PetscInt *fails) in TSGetSNESFailures() argument
5002 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSGetSNESFailures()
5004 *fails = ts->num_snes_failures; in TSGetSNESFailures()
5028 PetscErrorCode TSSetMaxStepRejections(TS ts, PetscInt rejects) in TSSetMaxStepRejections() argument
5031 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSSetMaxStepRejections()
5033 ts->max_reject = PETSC_UNLIMITED; in TSSetMaxStepRejections()
5035 …PetscCheck(rejects >= 0, PetscObjectComm((PetscObject)ts), PETSC_ERR_ARG_OUTOFRANGE, "Cannot have … in TSSetMaxStepRejections()
5036 ts->max_reject = rejects; in TSSetMaxStepRejections()
5058 PetscErrorCode TSSetMaxSNESFailures(TS ts, PetscInt fails) in TSSetMaxSNESFailures() argument
5061 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSSetMaxSNESFailures()
5063 ts->max_snes_failures = PETSC_UNLIMITED; in TSSetMaxSNESFailures()
5065 …PetscCheck(fails >= 0, PetscObjectComm((PetscObject)ts), PETSC_ERR_ARG_OUTOFRANGE, "Cannot have a … in TSSetMaxSNESFailures()
5066 ts->max_snes_failures = fails; in TSSetMaxSNESFailures()
5087 PetscErrorCode TSSetErrorIfStepFails(TS ts, PetscBool err) in TSSetErrorIfStepFails() argument
5090 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSSetErrorIfStepFails()
5091 ts->errorifstepfailed = err; in TSSetErrorIfStepFails()
5110 PetscErrorCode TSGetAdapt(TS ts, TSAdapt *adapt) in TSGetAdapt() argument
5113 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSGetAdapt()
5115 if (!ts->adapt) { in TSGetAdapt()
5116 PetscCall(TSAdaptCreate(PetscObjectComm((PetscObject)ts), &ts->adapt)); in TSGetAdapt()
5117 PetscCall(PetscObjectIncrementTabLevel((PetscObject)ts->adapt, (PetscObject)ts, 1)); in TSGetAdapt()
5119 *adapt = ts->adapt; in TSGetAdapt()
5157 PetscErrorCode TSSetTolerances(TS ts, PetscReal atol, Vec vatol, PetscReal rtol, Vec vrtol) in TSSetTolerances() argument
5161 ts->atol = ts->default_atol; in TSSetTolerances()
5163 …PetscCheck(atol >= 0.0, PetscObjectComm((PetscObject)ts), PETSC_ERR_ARG_OUTOFRANGE, "Absolute tole… in TSSetTolerances()
5164 ts->atol = atol; in TSSetTolerances()
5169 PetscCall(VecDestroy(&ts->vatol)); in TSSetTolerances()
5170 ts->vatol = vatol; in TSSetTolerances()
5174 ts->rtol = ts->default_rtol; in TSSetTolerances()
5176 …PetscCheck(rtol >= 0.0, PetscObjectComm((PetscObject)ts), PETSC_ERR_ARG_OUTOFRANGE, "Relative tole… in TSSetTolerances()
5177 ts->rtol = rtol; in TSSetTolerances()
5182 PetscCall(VecDestroy(&ts->vrtol)); in TSSetTolerances()
5183 ts->vrtol = vrtol; in TSSetTolerances()
5206 PetscErrorCode TSGetTolerances(TS ts, PetscReal *atol, Vec *vatol, PetscReal *rtol, Vec *vrtol) in TSGetTolerances() argument
5209 if (atol) *atol = ts->atol; in TSGetTolerances()
5210 if (vatol) *vatol = ts->vatol; in TSGetTolerances()
5211 if (rtol) *rtol = ts->rtol; in TSGetTolerances()
5212 if (vrtol) *vrtol = ts->vrtol; in TSGetTolerances()
5239 PetscErrorCode TSErrorWeightedNorm(TS ts, Vec U, Vec Y, NormType wnormtype, PetscReal *norm, PetscR… in TSErrorWeightedNorm() argument
5244 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSErrorWeightedNorm()
5247 PetscValidLogicalCollectiveEnum(ts, wnormtype, 4); in TSErrorWeightedNorm()
5251 …etscCall(VecErrorWeightedNorms(U, Y, NULL, wnormtype, ts->atol, ts->vatol, ts->rtol, ts->vrtol, ts in TSErrorWeightedNorm()
5257 …PetscCheck(!PetscIsInfOrNanScalar(*norm), PetscObjectComm((PetscObject)ts), PETSC_ERR_FP, "Infinit… in TSErrorWeightedNorm()
5258 …PetscCheck(!PetscIsInfOrNanScalar(*norma), PetscObjectComm((PetscObject)ts), PETSC_ERR_FP, "Infini… in TSErrorWeightedNorm()
5259 …PetscCheck(!PetscIsInfOrNanScalar(*normr), PetscObjectComm((PetscObject)ts), PETSC_ERR_FP, "Infini… in TSErrorWeightedNorm()
5287 PetscErrorCode TSErrorWeightedENorm(TS ts, Vec E, Vec U, Vec Y, NormType wnormtype, PetscReal *norm… in TSErrorWeightedENorm() argument
5292 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSErrorWeightedENorm()
5293 …PetscCall(VecErrorWeightedNorms(U, Y, E, wnormtype, ts->atol, ts->vatol, ts->rtol, ts->vrtol, ts->… in TSErrorWeightedENorm()
5299 …PetscCheck(!PetscIsInfOrNanScalar(*norm), PetscObjectComm((PetscObject)ts), PETSC_ERR_FP, "Infinit… in TSErrorWeightedENorm()
5300 …PetscCheck(!PetscIsInfOrNanScalar(*norma), PetscObjectComm((PetscObject)ts), PETSC_ERR_FP, "Infini… in TSErrorWeightedENorm()
5301 …PetscCheck(!PetscIsInfOrNanScalar(*normr), PetscObjectComm((PetscObject)ts), PETSC_ERR_FP, "Infini… in TSErrorWeightedENorm()
5321 PetscErrorCode TSSetCFLTimeLocal(TS ts, PetscReal cfltime) in TSSetCFLTimeLocal() argument
5324 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSSetCFLTimeLocal()
5325 ts->cfltime_local = cfltime; in TSSetCFLTimeLocal()
5326 ts->cfltime = -1.; in TSSetCFLTimeLocal()
5345 PetscErrorCode TSGetCFLTime(TS ts, PetscReal *cfltime) in TSGetCFLTime() argument
5348 …if (ts->cfltime < 0) PetscCallMPI(MPIU_Allreduce(&ts->cfltime_local, &ts->cfltime, 1, MPIU_REAL, M… in TSGetCFLTime()
5349 *cfltime = ts->cfltime; in TSGetCFLTime()
5369 PetscErrorCode TSVISetVariableBounds(TS ts, Vec xl, Vec xu) in TSVISetVariableBounds() argument
5374 PetscCall(TSGetSNES(ts, &snes)); in TSVISetVariableBounds()
5397 PetscErrorCode TSComputeLinearStability(TS ts, PetscReal xr, PetscReal xi, PetscReal *yr, PetscReal… in TSComputeLinearStability() argument
5400 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSComputeLinearStability()
5401 PetscUseTypeMethod(ts, linearstability, xr, xi, yr, yi); in TSComputeLinearStability()
5425 PetscErrorCode TSRestartStep(TS ts) in TSRestartStep() argument
5428 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSRestartStep()
5429 ts->steprestart = PETSC_TRUE; in TSRestartStep()
5445 PetscErrorCode TSRollBack(TS ts) in TSRollBack() argument
5448 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSRollBack()
5449 …PetscCheck(!ts->steprollback, PetscObjectComm((PetscObject)ts), PETSC_ERR_ARG_WRONGSTATE, "TSRollB… in TSRollBack()
5450 PetscTryTypeMethod(ts, rollback); in TSRollBack()
5451 PetscCall(VecCopy(ts->vec_sol0, ts->vec_sol)); in TSRollBack()
5452 ts->time_step = ts->ptime - ts->ptime_prev; in TSRollBack()
5453 ts->ptime = ts->ptime_prev; in TSRollBack()
5454 ts->ptime_prev = ts->ptime_prev_rollback; in TSRollBack()
5455 ts->steps--; in TSRollBack()
5456 ts->steprollback = PETSC_TRUE; in TSRollBack()
5475 PetscErrorCode TSGetStepRollBack(TS ts, PetscBool *flg) in TSGetStepRollBack() argument
5478 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSGetStepRollBack()
5480 *flg = ts->steprollback; in TSGetStepRollBack()
5499 PetscErrorCode TSGetStepResize(TS ts, PetscBool *flg) in TSGetStepResize() argument
5502 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSGetStepResize()
5504 *flg = ts->stepresize; in TSGetStepResize()
5525 PetscErrorCode TSGetStages(TS ts, PetscInt *ns, Vec **Y) in TSGetStages() argument
5528 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSGetStages()
5531 if (!ts->ops->getstages) { in TSGetStages()
5534 } else PetscUseTypeMethod(ts, getstages, ns, Y); in TSGetStages()
5571 PetscErrorCode TSComputeIJacobianDefaultColor(TS ts, PetscReal t, Vec U, Vec Udot, PetscReal shift,… in TSComputeIJacobianDefaultColor() argument
5578 …PetscCall(PetscOptionsGetBool(((PetscObject)ts)->options, ((PetscObject)ts)->prefix, "-ts_fd_color… in TSComputeIJacobianDefaultColor()
5584 PetscCall(TSGetDM(ts, &dm)); in TSComputeIJacobianDefaultColor()
5589 PetscCall(MatFDColoringSetFunction(color, (MatFDColoringFn *)SNESTSFormFunction, (void *)ts)); in TSComputeIJacobianDefaultColor()
5603 PetscCall(MatFDColoringSetFunction(color, (MatFDColoringFn *)SNESTSFormFunction, (void *)ts)); in TSComputeIJacobianDefaultColor()
5611 PetscCall(TSGetSNES(ts, &snes)); in TSComputeIJacobianDefaultColor()
5650 PetscErrorCode TSSetFunctionDomainError(TS ts, PetscErrorCode (*func)(TS ts, PetscReal time, Vec st… in TSSetFunctionDomainError() argument
5653 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSSetFunctionDomainError()
5654 ts->functiondomainerror = func; in TSSetFunctionDomainError()
5679 PetscErrorCode TSFunctionDomainError(TS ts, PetscReal stagetime, Vec Y, PetscBool *accept) in TSFunctionDomainError() argument
5682 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSFunctionDomainError()
5683 PetscValidLogicalCollectiveReal(ts, stagetime, 2); in TSFunctionDomainError()
5687 if (ts->functiondomainerror) PetscCall((*ts->functiondomainerror)(ts, stagetime, Y, accept)); in TSFunctionDomainError()
5791 TS ts = (TS)ctx; in RHSWrapperFunction_TSRHSJacobianTest() local
5794 PetscCall(TSComputeRHSFunction(ts, 0, x, y)); in RHSWrapperFunction_TSRHSJacobianTest()
5819 PetscErrorCode TSRHSJacobianTest(TS ts, PetscBool *flg) in TSRHSJacobianTest() argument
5826 PetscCall(TSGetRHSJacobian(ts, &J, &B, &func, &ctx)); in TSRHSJacobianTest()
5827 PetscCall((*func)(ts, 0.0, ts->vec_sol, J, B, ctx)); in TSRHSJacobianTest()
5828 PetscCall(MatShellTestMult(J, RHSWrapperFunction_TSRHSJacobianTest, ts->vec_sol, ts, flg)); in TSRHSJacobianTest()
5853 PetscErrorCode TSRHSJacobianTestTranspose(TS ts, PetscBool *flg) in TSRHSJacobianTestTranspose() argument
5860 PetscCall(TSGetRHSJacobian(ts, &J, &B, &func, &ctx)); in TSRHSJacobianTestTranspose()
5861 PetscCall((*func)(ts, 0.0, ts->vec_sol, J, B, ctx)); in TSRHSJacobianTestTranspose()
5862 …PetscCall(MatShellTestMultTranspose(J, RHSWrapperFunction_TSRHSJacobianTest, ts->vec_sol, ts, flg)… in TSRHSJacobianTestTranspose()
5885 PetscErrorCode TSSetUseSplitRHSFunction(TS ts, PetscBool use_splitrhsfunction) in TSSetUseSplitRHSFunction() argument
5888 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSSetUseSplitRHSFunction()
5889 ts->use_splitrhsfunction = use_splitrhsfunction; in TSSetUseSplitRHSFunction()
5908 PetscErrorCode TSGetUseSplitRHSFunction(TS ts, PetscBool *use_splitrhsfunction) in TSGetUseSplitRHSFunction() argument
5911 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSGetUseSplitRHSFunction()
5912 *use_splitrhsfunction = ts->use_splitrhsfunction; in TSGetUseSplitRHSFunction()
5932 PetscErrorCode TSSetMatStructure(TS ts, MatStructure str) in TSSetMatStructure() argument
5935 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSSetMatStructure()
5936 ts->axpy_pattern = str; in TSSetMatStructure()
5965 PetscErrorCode TSSetEvaluationTimes(TS ts, PetscInt n, PetscReal time_points[]) in TSSetEvaluationTimes() argument
5970 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSSetEvaluationTimes()
5971 if (ts->eval_times) { // Reset eval_times in TSSetEvaluationTimes()
5972 ts->eval_times->sol_idx = 0; in TSSetEvaluationTimes()
5973 ts->eval_times->time_point_idx = 0; in TSSetEvaluationTimes()
5974 if (n != ts->eval_times->num_time_points) { in TSSetEvaluationTimes()
5975 PetscCall(PetscFree(ts->eval_times->time_points)); in TSSetEvaluationTimes()
5976 PetscCall(PetscFree(ts->eval_times->sol_times)); in TSSetEvaluationTimes()
5977 PetscCall(VecDestroyVecs(ts->eval_times->num_time_points, &ts->eval_times->sol_vecs)); in TSSetEvaluationTimes()
5979 PetscCall(PetscArrayzero(ts->eval_times->sol_times, n)); in TSSetEvaluationTimes()
5980 for (PetscInt i = 0; i < n; i++) PetscCall(VecZeroEntries(ts->eval_times->sol_vecs[i])); in TSSetEvaluationTimes()
5990 ts->eval_times = eval_times; in TSSetEvaluationTimes()
5992 ts->eval_times->num_time_points = n; in TSSetEvaluationTimes()
5994 …PetscCheck(is_sorted, PetscObjectComm((PetscObject)ts), PETSC_ERR_ARG_WRONG, "time_points array mu… in TSSetEvaluationTimes()
5995 PetscCall(PetscArraycpy(ts->eval_times->time_points, time_points, n)); in TSSetEvaluationTimes()
6023 PetscErrorCode TSGetEvaluationTimes(TS ts, PetscInt *n, const PetscReal *time_points[]) in TSGetEvaluationTimes() argument
6026 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSGetEvaluationTimes()
6029 if (!ts->eval_times) { in TSGetEvaluationTimes()
6033 if (n) *n = ts->eval_times->num_time_points; in TSGetEvaluationTimes()
6034 if (time_points) *time_points = ts->eval_times->time_points; in TSGetEvaluationTimes()
6062 PetscErrorCode TSGetEvaluationSolutions(TS ts, PetscInt *nsol, const PetscReal *sol_times[], Vec *S… in TSGetEvaluationSolutions() argument
6065 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSGetEvaluationSolutions()
6069 if (!ts->eval_times) { in TSGetEvaluationSolutions()
6074 if (nsol) *nsol = ts->eval_times->sol_idx; in TSGetEvaluationSolutions()
6075 if (sol_times) *sol_times = ts->eval_times->sol_times; in TSGetEvaluationSolutions()
6076 if (Sols) *Sols = ts->eval_times->sol_vecs; in TSGetEvaluationSolutions()
6108 PetscErrorCode TSSetTimeSpan(TS ts, PetscInt n, PetscReal span_times[]) in TSSetTimeSpan() argument
6111 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSSetTimeSpan()
6112 …PetscCheck(n >= 2, PetscObjectComm((PetscObject)ts), PETSC_ERR_ARG_WRONG, "Minimum time span size … in TSSetTimeSpan()
6113 PetscCall(TSSetEvaluationTimes(ts, n, span_times)); in TSSetTimeSpan()
6114 PetscCall(TSSetTime(ts, span_times[0])); in TSSetTimeSpan()
6115 PetscCall(TSSetMaxTime(ts, span_times[n - 1])); in TSSetTimeSpan()
6143 PetscErrorCode TSPruneIJacobianColor(TS ts, Mat J, Mat B) in TSPruneIJacobianColor() argument
6160 …scCall(MatFDColoringSetFunction(matfdcoloring, (MatFDColoringFn *)SNESTSFormFunction, (void *)ts)); in TSPruneIJacobianColor()