Lines Matching refs:ts
65 PetscErrorCode TSAlpha2SetPredictor(TS ts, TSAlpha2PredictorFn *predictor, PetscCtx ctx) in TSAlpha2SetPredictor() argument
67 TS_Alpha *th = (TS_Alpha *)ts->data; in TSAlpha2SetPredictor()
75 static PetscErrorCode TSAlpha_ApplyPredictor(TS ts, Vec X1) in TSAlpha_ApplyPredictor() argument
78 TS_Alpha *th = (TS_Alpha *)ts->data; in TSAlpha_ApplyPredictor()
81 if (th->predictor) PetscCall(th->predictor(ts, th->X0, th->V0, th->A0, X1, th->predictor_ctx)); in TSAlpha_ApplyPredictor()
86 static PetscErrorCode TSAlpha_StageTime(TS ts) in TSAlpha_StageTime() argument
88 TS_Alpha *th = (TS_Alpha *)ts->data; in TSAlpha_StageTime()
89 PetscReal t = ts->ptime; in TSAlpha_StageTime()
90 PetscReal dt = ts->time_step; in TSAlpha_StageTime()
104 static PetscErrorCode TSAlpha_StageVecs(TS ts, Vec X) in TSAlpha_StageVecs() argument
106 TS_Alpha *th = (TS_Alpha *)ts->data; in TSAlpha_StageVecs()
110 PetscReal dt = ts->time_step; in TSAlpha_StageVecs()
136 static PetscErrorCode TSAlpha_SNESSolve(TS ts, Vec b, Vec x) in TSAlpha_SNESSolve() argument
141 PetscCall(SNESSolve(ts->snes, b, x)); in TSAlpha_SNESSolve()
142 PetscCall(SNESGetIterationNumber(ts->snes, &nits)); in TSAlpha_SNESSolve()
143 PetscCall(SNESGetLinearSolveIterations(ts->snes, &lits)); in TSAlpha_SNESSolve()
144 ts->snes_its += nits; in TSAlpha_SNESSolve()
145 ts->ksp_its += lits; in TSAlpha_SNESSolve()
155 static PetscErrorCode TSAlpha_Restart(TS ts, PetscBool *initok) in TSAlpha_Restart() argument
157 TS_Alpha *th = (TS_Alpha *)ts->data; in TSAlpha_Restart()
160 Vec X0 = ts->vec_sol, X1, X2 = th->X1; in TSAlpha_Restart()
161 Vec V0 = ts->vec_dot, V1, V2 = th->V1; in TSAlpha_Restart()
169 PetscCall(TSAlpha2GetParams(ts, &alpha_m, &alpha_f, &gamma, &beta)); in TSAlpha_Restart()
170 PetscCall(TSAlpha2SetParams(ts, 1, 1, 1, 0.5)); in TSAlpha_Restart()
171 PetscCall(TSGetTimeStep(ts, &time_step)); in TSAlpha_Restart()
172 ts->time_step = time_step / 2; in TSAlpha_Restart()
173 PetscCall(TSAlpha_StageTime(ts)); in TSAlpha_Restart()
174 th->stage_time = ts->ptime; in TSAlpha_Restart()
178 th->stage_time += ts->time_step; in TSAlpha_Restart()
181 PetscCall(TSPreStage(ts, th->stage_time)); in TSAlpha_Restart()
182 PetscCall(TSAlpha_ApplyPredictor(ts, X1)); in TSAlpha_Restart()
183 PetscCall(TSAlpha_SNESSolve(ts, NULL, X1)); in TSAlpha_Restart()
185 PetscCall(TSPostStage(ts, th->stage_time, 0, &X1)); in TSAlpha_Restart()
186 PetscCall(TSAdaptCheckStage(ts->adapt, ts, th->stage_time, X1, &stageok)); in TSAlpha_Restart()
190 th->stage_time += ts->time_step; in TSAlpha_Restart()
193 PetscCall(TSPreStage(ts, th->stage_time)); in TSAlpha_Restart()
194 PetscCall(TSAlpha_ApplyPredictor(ts, X2)); in TSAlpha_Restart()
195 PetscCall(TSAlpha_SNESSolve(ts, NULL, X2)); in TSAlpha_Restart()
197 PetscCall(TSPostStage(ts, th->stage_time, 0, &X2)); in TSAlpha_Restart()
198 PetscCall(TSAdaptCheckStage(ts->adapt, ts, th->stage_time, X2, &stageok)); in TSAlpha_Restart()
225 PetscCall(TSSetTimeStep(ts, 2 * ts->time_step)); in TSAlpha_Restart()
226 PetscCall(TSAlpha2SetParams(ts, alpha_m, alpha_f, gamma, beta)); in TSAlpha_Restart()
227 PetscCall(VecCopy(ts->vec_sol, th->X0)); in TSAlpha_Restart()
228 PetscCall(VecCopy(ts->vec_dot, th->V0)); in TSAlpha_Restart()
235 static PetscErrorCode TSStep_Alpha(TS ts) in TSStep_Alpha() argument
237 TS_Alpha *th = (TS_Alpha *)ts->data; in TSStep_Alpha()
240 PetscReal next_time_step = ts->time_step; in TSStep_Alpha()
245 if (!ts->steprollback) { in TSStep_Alpha()
248 PetscCall(VecCopy(ts->vec_sol, th->X0)); in TSStep_Alpha()
249 PetscCall(VecCopy(ts->vec_dot, th->V0)); in TSStep_Alpha()
254 while (!ts->reason && th->status != TS_STEP_COMPLETE) { in TSStep_Alpha()
255 if (ts->steprestart) { in TSStep_Alpha()
256 PetscCall(TSAlpha_Restart(ts, &stageok)); in TSStep_Alpha()
260 PetscCall(TSAlpha_StageTime(ts)); in TSStep_Alpha()
261 PetscCall(TSAlpha_ApplyPredictor(ts, th->X1)); in TSStep_Alpha()
262 PetscCall(TSPreStage(ts, th->stage_time)); in TSStep_Alpha()
263 PetscCall(TSAlpha_SNESSolve(ts, NULL, th->X1)); in TSStep_Alpha()
264 PetscCall(TSPostStage(ts, th->stage_time, 0, &th->Xa)); in TSStep_Alpha()
265 PetscCall(TSAdaptCheckStage(ts->adapt, ts, th->stage_time, th->Xa, &stageok)); in TSStep_Alpha()
269 PetscCall(VecCopy(th->X1, ts->vec_sol)); in TSStep_Alpha()
270 PetscCall(VecCopy(th->V1, ts->vec_dot)); in TSStep_Alpha()
271 PetscCall(TSAdaptChoose(ts->adapt, ts, ts->time_step, NULL, &next_time_step, &accept)); in TSStep_Alpha()
274 PetscCall(VecCopy(th->X0, ts->vec_sol)); in TSStep_Alpha()
275 PetscCall(VecCopy(th->V0, ts->vec_dot)); in TSStep_Alpha()
276 ts->time_step = next_time_step; in TSStep_Alpha()
280 ts->ptime += ts->time_step; in TSStep_Alpha()
281 ts->time_step = next_time_step; in TSStep_Alpha()
285 ts->reject++; in TSStep_Alpha()
287 if (!ts->reason && ++rejections > ts->max_reject && ts->max_reject >= 0) { in TSStep_Alpha()
288 ts->reason = TS_DIVERGED_STEP_REJECTED; in TSStep_Alpha()
289 …tscCall(PetscInfo(ts, "Step=%" PetscInt_FMT ", step rejections %" PetscInt_FMT " greater than curr… in TSStep_Alpha()
295 static PetscErrorCode TSEvaluateWLTE_Alpha(TS ts, NormType wnormtype, PetscInt *order, PetscReal *w… in TSEvaluateWLTE_Alpha() argument
297 TS_Alpha *th = (TS_Alpha *)ts->data; in TSEvaluateWLTE_Alpha()
321 if (ts->steprestart) { in TSEvaluateWLTE_Alpha()
327 PetscReal h = ts->time_step, h_prev = ts->ptime - ts->ptime_prev; in TSEvaluateWLTE_Alpha()
346 PetscCall(TSErrorWeightedNorm(ts, X, Y, wnormtype, &enormX, &enormXa, &enormXr)); in TSEvaluateWLTE_Alpha()
347 PetscCall(TSErrorWeightedNorm(ts, V, Z, wnormtype, &enormV, &enormVa, &enormVr)); in TSEvaluateWLTE_Alpha()
354 static PetscErrorCode TSRollBack_Alpha(TS ts) in TSRollBack_Alpha() argument
356 TS_Alpha *th = (TS_Alpha *)ts->data; in TSRollBack_Alpha()
359 PetscCall(VecCopy(th->X0, ts->vec_sol)); in TSRollBack_Alpha()
360 PetscCall(VecCopy(th->V0, ts->vec_dot)); in TSRollBack_Alpha()
382 static PetscErrorCode SNESTSFormFunction_Alpha(PETSC_UNUSED SNES snes, Vec X, Vec F, TS ts) in SNESTSFormFunction_Alpha() argument
384 TS_Alpha *th = (TS_Alpha *)ts->data; in SNESTSFormFunction_Alpha()
389 PetscCall(TSAlpha_StageVecs(ts, X)); in SNESTSFormFunction_Alpha()
391 PetscCall(TSComputeI2Function(ts, ta, Xa, Va, Aa, F)); in SNESTSFormFunction_Alpha()
396 …ErrorCode SNESTSFormJacobian_Alpha(PETSC_UNUSED SNES snes, PETSC_UNUSED Vec X, Mat J, Mat P, TS ts) in SNESTSFormJacobian_Alpha() argument
398 TS_Alpha *th = (TS_Alpha *)ts->data; in SNESTSFormJacobian_Alpha()
405 PetscCall(TSComputeI2Jacobian(ts, ta, Xa, Va, Aa, dVdX, dAdX, J, P)); in SNESTSFormJacobian_Alpha()
409 static PetscErrorCode TSReset_Alpha(TS ts) in TSReset_Alpha() argument
411 TS_Alpha *th = (TS_Alpha *)ts->data; in TSReset_Alpha()
430 static PetscErrorCode TSDestroy_Alpha(TS ts) in TSDestroy_Alpha() argument
433 PetscCall(TSReset_Alpha(ts)); in TSDestroy_Alpha()
434 PetscCall(PetscFree(ts->data)); in TSDestroy_Alpha()
436 PetscCall(PetscObjectComposeFunction((PetscObject)ts, "TSAlpha2SetRadius_C", NULL)); in TSDestroy_Alpha()
437 PetscCall(PetscObjectComposeFunction((PetscObject)ts, "TSAlpha2SetParams_C", NULL)); in TSDestroy_Alpha()
438 PetscCall(PetscObjectComposeFunction((PetscObject)ts, "TSAlpha2GetParams_C", NULL)); in TSDestroy_Alpha()
442 static PetscErrorCode TSSetUp_Alpha(TS ts) in TSSetUp_Alpha() argument
444 TS_Alpha *th = (TS_Alpha *)ts->data; in TSSetUp_Alpha()
448 PetscCall(VecDuplicate(ts->vec_sol, &th->X0)); in TSSetUp_Alpha()
449 PetscCall(VecDuplicate(ts->vec_sol, &th->Xa)); in TSSetUp_Alpha()
450 PetscCall(VecDuplicate(ts->vec_sol, &th->X1)); in TSSetUp_Alpha()
451 PetscCall(VecDuplicate(ts->vec_sol, &th->V0)); in TSSetUp_Alpha()
452 PetscCall(VecDuplicate(ts->vec_sol, &th->Va)); in TSSetUp_Alpha()
453 PetscCall(VecDuplicate(ts->vec_sol, &th->V1)); in TSSetUp_Alpha()
454 PetscCall(VecDuplicate(ts->vec_sol, &th->A0)); in TSSetUp_Alpha()
455 PetscCall(VecDuplicate(ts->vec_sol, &th->Aa)); in TSSetUp_Alpha()
456 PetscCall(VecDuplicate(ts->vec_sol, &th->A1)); in TSSetUp_Alpha()
458 PetscCall(TSGetAdapt(ts, &ts->adapt)); in TSSetUp_Alpha()
459 PetscCall(TSAdaptCandidatesClear(ts->adapt)); in TSSetUp_Alpha()
460 PetscCall(PetscObjectTypeCompare((PetscObject)ts->adapt, TSADAPTNONE, &match)); in TSSetUp_Alpha()
462 PetscCall(VecDuplicate(ts->vec_sol, &th->vec_sol_prev)); in TSSetUp_Alpha()
463 PetscCall(VecDuplicate(ts->vec_sol, &th->vec_dot_prev)); in TSSetUp_Alpha()
464 PetscCall(VecDuplicate(ts->vec_sol, &th->vec_lte_work[0])); in TSSetUp_Alpha()
465 PetscCall(VecDuplicate(ts->vec_sol, &th->vec_lte_work[1])); in TSSetUp_Alpha()
468 PetscCall(TSGetSNES(ts, &ts->snes)); in TSSetUp_Alpha()
472 static PetscErrorCode TSSetFromOptions_Alpha(TS ts, PetscOptionItems PetscOptionsObject) in TSSetFromOptions_Alpha() argument
474 TS_Alpha *th = (TS_Alpha *)ts->data; in TSSetFromOptions_Alpha()
482 if (flg) PetscCall(TSAlpha2SetRadius(ts, radius)); in TSSetFromOptions_Alpha()
487 PetscCall(TSAlpha2SetParams(ts, th->Alpha_m, th->Alpha_f, th->Gamma, th->Beta)); in TSSetFromOptions_Alpha()
493 static PetscErrorCode TSView_Alpha(TS ts, PetscViewer viewer) in TSView_Alpha() argument
495 TS_Alpha *th = (TS_Alpha *)ts->data; in TSView_Alpha()
504 static PetscErrorCode TSAlpha2SetRadius_Alpha(TS ts, PetscReal radius) in TSAlpha2SetRadius_Alpha() argument
509 …PetscCheck(radius >= 0 && radius <= 1, PetscObjectComm((PetscObject)ts), PETSC_ERR_ARG_OUTOFRANGE,… in TSAlpha2SetRadius_Alpha()
515 PetscCall(TSAlpha2SetParams(ts, alpha_m, alpha_f, gamma, beta)); in TSAlpha2SetRadius_Alpha()
519 static PetscErrorCode TSAlpha2SetParams_Alpha(TS ts, PetscReal alpha_m, PetscReal alpha_f, PetscRea… in TSAlpha2SetParams_Alpha() argument
521 TS_Alpha *th = (TS_Alpha *)ts->data; in TSAlpha2SetParams_Alpha()
534 static PetscErrorCode TSAlpha2GetParams_Alpha(TS ts, PetscReal *alpha_m, PetscReal *alpha_f, PetscR… in TSAlpha2GetParams_Alpha() argument
536 TS_Alpha *th = (TS_Alpha *)ts->data; in TSAlpha2GetParams_Alpha()
553 PETSC_EXTERN PetscErrorCode TSCreate_Alpha2(TS ts) in TSCreate_Alpha2() argument
558 ts->ops->reset = TSReset_Alpha; in TSCreate_Alpha2()
559 ts->ops->destroy = TSDestroy_Alpha; in TSCreate_Alpha2()
560 ts->ops->view = TSView_Alpha; in TSCreate_Alpha2()
561 ts->ops->setup = TSSetUp_Alpha; in TSCreate_Alpha2()
562 ts->ops->setfromoptions = TSSetFromOptions_Alpha; in TSCreate_Alpha2()
563 ts->ops->step = TSStep_Alpha; in TSCreate_Alpha2()
564 ts->ops->evaluatewlte = TSEvaluateWLTE_Alpha; in TSCreate_Alpha2()
565 ts->ops->rollback = TSRollBack_Alpha; in TSCreate_Alpha2()
567 ts->ops->snesfunction = SNESTSFormFunction_Alpha; in TSCreate_Alpha2()
568 ts->ops->snesjacobian = SNESTSFormJacobian_Alpha; in TSCreate_Alpha2()
569 ts->default_adapt_type = TSADAPTNONE; in TSCreate_Alpha2()
571 ts->usessnes = PETSC_TRUE; in TSCreate_Alpha2()
574 ts->data = (void *)th; in TSCreate_Alpha2()
585 …PetscCall(PetscObjectComposeFunction((PetscObject)ts, "TSAlpha2SetRadius_C", TSAlpha2SetRadius_Alp… in TSCreate_Alpha2()
586 …PetscCall(PetscObjectComposeFunction((PetscObject)ts, "TSAlpha2SetParams_C", TSAlpha2SetParams_Alp… in TSCreate_Alpha2()
587 …PetscCall(PetscObjectComposeFunction((PetscObject)ts, "TSAlpha2GetParams_C", TSAlpha2GetParams_Alp… in TSCreate_Alpha2()
621 PetscErrorCode TSAlpha2SetRadius(TS ts, PetscReal radius) in TSAlpha2SetRadius() argument
624 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSAlpha2SetRadius()
625 PetscValidLogicalCollectiveReal(ts, radius, 2); in TSAlpha2SetRadius()
626 …PetscCheck(radius >= 0 && radius <= 1, ((PetscObject)ts)->comm, PETSC_ERR_ARG_OUTOFRANGE, "Radius … in TSAlpha2SetRadius()
627 PetscTryMethod(ts, "TSAlpha2SetRadius_C", (TS, PetscReal), (ts, radius)); in TSAlpha2SetRadius()
673 PetscErrorCode TSAlpha2SetParams(TS ts, PetscReal alpha_m, PetscReal alpha_f, PetscReal gamma, Pets… in TSAlpha2SetParams() argument
676 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSAlpha2SetParams()
677 PetscValidLogicalCollectiveReal(ts, alpha_m, 2); in TSAlpha2SetParams()
678 PetscValidLogicalCollectiveReal(ts, alpha_f, 3); in TSAlpha2SetParams()
679 PetscValidLogicalCollectiveReal(ts, gamma, 4); in TSAlpha2SetParams()
680 PetscValidLogicalCollectiveReal(ts, beta, 5); in TSAlpha2SetParams()
681 …PetscTryMethod(ts, "TSAlpha2SetParams_C", (TS, PetscReal, PetscReal, PetscReal, PetscReal), (ts, a… in TSAlpha2SetParams()
708 PetscErrorCode TSAlpha2GetParams(TS ts, PetscReal *alpha_m, PetscReal *alpha_f, PetscReal *gamma, P… in TSAlpha2GetParams() argument
711 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSAlpha2GetParams()
716 …PetscUseMethod(ts, "TSAlpha2GetParams_C", (TS, PetscReal *, PetscReal *, PetscReal *, PetscReal *)… in TSAlpha2GetParams()