Lines Matching refs:ts

32 static PetscErrorCode TSEvaluateStep_EIMEX(TS ts, PetscInt order, Vec X, PetscBool *done)  in TSEvaluateStep_EIMEX()  argument
34 TS_EIMEX *ext = (TS_EIMEX *)ts->data; in TSEvaluateStep_EIMEX()
42 static PetscErrorCode TSStage_EIMEX(TS ts, PetscInt istage) in TSStage_EIMEX() argument
44 TS_EIMEX *ext = (TS_EIMEX *)ts->data; in TSStage_EIMEX()
53 PetscCall(TSGetSNES(ts, &snes)); in TSStage_EIMEX()
54 h = ts->time_step / ext->N[istage]; /* step size for the istage-th stage */ in TSStage_EIMEX()
60 ext->ctime = ts->ptime + h * i; in TSStage_EIMEX()
65 ts->snes_its += its; in TSStage_EIMEX()
66 ts->ksp_its += lits; in TSStage_EIMEX()
67 PetscCall(TSGetAdapt(ts, &adapt)); in TSStage_EIMEX()
68 PetscCall(TSAdaptCheckStage(adapt, ts, ext->ctime, Y, &accept)); in TSStage_EIMEX()
73 static PetscErrorCode TSStep_EIMEX(TS ts) in TSStep_EIMEX() argument
75 TS_EIMEX *ext = (TS_EIMEX *)ts->data; in TSStep_EIMEX()
84 PetscCall(TSGetSNES(ts, &snes)); in TSStep_EIMEX()
88 PetscCall(VecCopy(ts->vec_sol, ext->VecSolPrev)); in TSStep_EIMEX()
92 PetscCall(TSStage_EIMEX(ts, j)); in TSStep_EIMEX()
105 PetscCall(TSEvaluateStep(ts, ns, ts->vec_sol, NULL)); /*update ts solution */ in TSStep_EIMEX()
110 …PetscCall(TSErrorWeightedNorm(ts, ts->vec_sol, T[Map(ext->nstages - 1, ext->nstages - 2, ext->nsta… in TSStep_EIMEX()
114 PetscCall(TSStage_EIMEX(ts, ext->nstages)); in TSStep_EIMEX()
119 PetscCall(VecDuplicateVecs(ts->vec_sol, (1 + ext->nstages) * ext->nstages / 2, &ext->T)); in TSStep_EIMEX()
135 PetscCall(TSEvaluateStep(ts, ext->nstages, ts->vec_sol, NULL)); in TSStep_EIMEX()
139 … if (ext->nstages == ext->max_rows) PetscCall(PetscInfo(ts, "Max number of rows has been used\n")); in TSStep_EIMEX()
141 ts->ptime += ts->time_step; in TSStep_EIMEX()
144 if (ext->status != TS_STEP_COMPLETE && !ts->reason) ts->reason = TS_DIVERGED_STEP_REJECTED; in TSStep_EIMEX()
149 static PetscErrorCode TSInterpolate_EIMEX(TS ts, PetscReal itime, Vec X) in TSInterpolate_EIMEX() argument
151 TS_EIMEX *ext = (TS_EIMEX *)ts->data; in TSInterpolate_EIMEX()
154 const PetscReal h = ts->ptime - ts->ptime_prev; in TSInterpolate_EIMEX()
157 t = (itime - ts->ptime + h) / h; in TSInterpolate_EIMEX()
161 PetscCall(TSComputeIFunction(ts, ts->ptime - h, Y0, Ydot, YdotI, PETSC_FALSE)); in TSInterpolate_EIMEX()
167 PetscCall(TSComputeIFunction(ts, ts->ptime, Y1, Ydot, YdotI, PETSC_FALSE)); in TSInterpolate_EIMEX()
174 static PetscErrorCode TSReset_EIMEX(TS ts) in TSReset_EIMEX() argument
176 TS_EIMEX *ext = (TS_EIMEX *)ts->data; in TSReset_EIMEX()
192 static PetscErrorCode TSDestroy_EIMEX(TS ts) in TSDestroy_EIMEX() argument
195 PetscCall(TSReset_EIMEX(ts)); in TSDestroy_EIMEX()
196 PetscCall(PetscFree(ts->data)); in TSDestroy_EIMEX()
197 PetscCall(PetscObjectComposeFunction((PetscObject)ts, "TSEIMEXSetMaxRows_C", NULL)); in TSDestroy_EIMEX()
198 PetscCall(PetscObjectComposeFunction((PetscObject)ts, "TSEIMEXSetRowCol_C", NULL)); in TSDestroy_EIMEX()
199 PetscCall(PetscObjectComposeFunction((PetscObject)ts, "TSEIMEXSetOrdAdapt_C", NULL)); in TSDestroy_EIMEX()
203 static PetscErrorCode TSEIMEXGetVecs(TS ts, DM dm, Vec *Z, Vec *Ydot, Vec *YdotI, Vec *YdotRHS) in TSEIMEXGetVecs() argument
205 TS_EIMEX *ext = (TS_EIMEX *)ts->data; in TSEIMEXGetVecs()
209 if (dm && dm != ts->dm) PetscCall(DMGetNamedGlobalVector(dm, "TSEIMEX_Z", Z)); in TSEIMEXGetVecs()
213 if (dm && dm != ts->dm) PetscCall(DMGetNamedGlobalVector(dm, "TSEIMEX_Ydot", Ydot)); in TSEIMEXGetVecs()
217 if (dm && dm != ts->dm) PetscCall(DMGetNamedGlobalVector(dm, "TSEIMEX_YdotI", YdotI)); in TSEIMEXGetVecs()
221 if (dm && dm != ts->dm) PetscCall(DMGetNamedGlobalVector(dm, "TSEIMEX_YdotRHS", YdotRHS)); in TSEIMEXGetVecs()
227 static PetscErrorCode TSEIMEXRestoreVecs(TS ts, DM dm, Vec *Z, Vec *Ydot, Vec *YdotI, Vec *YdotRHS) in TSEIMEXRestoreVecs() argument
231 if (dm && dm != ts->dm) PetscCall(DMRestoreNamedGlobalVector(dm, "TSEIMEX_Z", Z)); in TSEIMEXRestoreVecs()
234 if (dm && dm != ts->dm) PetscCall(DMRestoreNamedGlobalVector(dm, "TSEIMEX_Ydot", Ydot)); in TSEIMEXRestoreVecs()
237 if (dm && dm != ts->dm) PetscCall(DMRestoreNamedGlobalVector(dm, "TSEIMEX_YdotI", YdotI)); in TSEIMEXRestoreVecs()
240 if (dm && dm != ts->dm) PetscCall(DMRestoreNamedGlobalVector(dm, "TSEIMEX_YdotRHS", YdotRHS)); in TSEIMEXRestoreVecs()
251 static PetscErrorCode SNESTSFormFunction_EIMEX(SNES snes, Vec X, Vec G, TS ts) in SNESTSFormFunction_EIMEX() argument
253 TS_EIMEX *ext = (TS_EIMEX *)ts->data; in SNESTSFormFunction_EIMEX()
261 PetscCall(TSEIMEXGetVecs(ts, dm, &Z, &Ydot, NULL, NULL)); in SNESTSFormFunction_EIMEX()
263 dmsave = ts->dm; in SNESTSFormFunction_EIMEX()
264 ts->dm = dm; in SNESTSFormFunction_EIMEX()
265 PetscCall(TSComputeIFunction(ts, ext->ctime, X, Ydot, G, PETSC_FALSE)); in SNESTSFormFunction_EIMEX()
268 ts->dm = dmsave; in SNESTSFormFunction_EIMEX()
269 PetscCall(TSEIMEXRestoreVecs(ts, dm, &Z, &Ydot, NULL, NULL)); in SNESTSFormFunction_EIMEX()
276 static PetscErrorCode SNESTSFormJacobian_EIMEX(SNES snes, Vec X, Mat A, Mat B, TS ts) in SNESTSFormJacobian_EIMEX() argument
278 TS_EIMEX *ext = (TS_EIMEX *)ts->data; in SNESTSFormJacobian_EIMEX()
284 PetscCall(TSEIMEXGetVecs(ts, dm, NULL, &Ydot, NULL, NULL)); in SNESTSFormJacobian_EIMEX()
287 dmsave = ts->dm; in SNESTSFormJacobian_EIMEX()
288 ts->dm = dm; in SNESTSFormJacobian_EIMEX()
289 PetscCall(TSComputeIJacobian(ts, ts->ptime, X, Ydot, ext->shift, A, B, PETSC_TRUE)); in SNESTSFormJacobian_EIMEX()
290 ts->dm = dmsave; in SNESTSFormJacobian_EIMEX()
291 PetscCall(TSEIMEXRestoreVecs(ts, dm, NULL, &Ydot, NULL, NULL)); in SNESTSFormJacobian_EIMEX()
303 TS ts = (TS)ctx; in DMRestrictHook_TSEIMEX() local
307 PetscCall(TSEIMEXGetVecs(ts, fine, &Z, NULL, NULL, NULL)); in DMRestrictHook_TSEIMEX()
308 PetscCall(TSEIMEXGetVecs(ts, coarse, &Z_c, NULL, NULL, NULL)); in DMRestrictHook_TSEIMEX()
311 PetscCall(TSEIMEXRestoreVecs(ts, fine, &Z, NULL, NULL, NULL)); in DMRestrictHook_TSEIMEX()
312 PetscCall(TSEIMEXRestoreVecs(ts, coarse, &Z_c, NULL, NULL, NULL)); in DMRestrictHook_TSEIMEX()
316 static PetscErrorCode TSSetUp_EIMEX(TS ts) in TSSetUp_EIMEX() argument
318 TS_EIMEX *ext = (TS_EIMEX *)ts->data; in TSSetUp_EIMEX()
323 PetscCall(TSEIMEXSetMaxRows(ts, TSEIMEXDefault)); in TSSetUp_EIMEX()
326 PetscCall(TSEIMEXSetRowCol(ts, ext->max_rows, ext->max_rows)); in TSSetUp_EIMEX()
328 …if (ext->ord_adapt) PetscCall(PetscInfo(ts, "Order adaptivity is enabled and TSEIMEXSetRowCol or -… in TSSetUp_EIMEX()
333 PetscCall(TSEIMEXSetRowCol(ts, ext->nstages, ext->nstages)); in TSSetUp_EIMEX()
338 PetscCall(TSGetAdapt(ts, &ts->adapt)); in TSSetUp_EIMEX()
340 …PetscCall(VecDuplicateVecs(ts->vec_sol, (1 + ext->nstages) * ext->nstages / 2, &ext->T)); /* full … in TSSetUp_EIMEX()
341 PetscCall(VecDuplicate(ts->vec_sol, &ext->YdotI)); in TSSetUp_EIMEX()
342 PetscCall(VecDuplicate(ts->vec_sol, &ext->YdotRHS)); in TSSetUp_EIMEX()
343 PetscCall(VecDuplicate(ts->vec_sol, &ext->Ydot)); in TSSetUp_EIMEX()
344 PetscCall(VecDuplicate(ts->vec_sol, &ext->VecSolPrev)); in TSSetUp_EIMEX()
345 PetscCall(VecDuplicate(ts->vec_sol, &ext->Y)); in TSSetUp_EIMEX()
346 PetscCall(VecDuplicate(ts->vec_sol, &ext->Z)); in TSSetUp_EIMEX()
347 PetscCall(TSGetDM(ts, &dm)); in TSSetUp_EIMEX()
348 if (dm) PetscCall(DMCoarsenHookAdd(dm, DMCoarsenHook_TSEIMEX, DMRestrictHook_TSEIMEX, ts)); in TSSetUp_EIMEX()
352 static PetscErrorCode TSSetFromOptions_EIMEX(TS ts, PetscOptionItems PetscOptionsObject) in TSSetFromOptions_EIMEX() argument
354 TS_EIMEX *ext = (TS_EIMEX *)ts->data; in TSSetFromOptions_EIMEX()
365 if (flg) PetscCall(TSEIMEXSetMaxRows(ts, nrows)); in TSSetFromOptions_EIMEX()
367 if (flg) PetscCall(TSEIMEXSetRowCol(ts, tindex[0], tindex[1])); in TSSetFromOptions_EIMEX()
374 static PetscErrorCode TSView_EIMEX(TS ts, PetscViewer viewer) in TSView_EIMEX() argument
393 PetscErrorCode TSEIMEXSetMaxRows(TS ts, PetscInt nrows) in TSEIMEXSetMaxRows() argument
396 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSEIMEXSetMaxRows()
397 PetscTryMethod(ts, "TSEIMEXSetMaxRows_C", (TS, PetscInt), (ts, nrows)); in TSEIMEXSetMaxRows()
415 PetscErrorCode TSEIMEXSetRowCol(TS ts, PetscInt row, PetscInt col) in TSEIMEXSetRowCol() argument
418 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSEIMEXSetRowCol()
419 PetscTryMethod(ts, "TSEIMEXSetRowCol_C", (TS, PetscInt, PetscInt), (ts, row, col)); in TSEIMEXSetRowCol()
436 PetscErrorCode TSEIMEXSetOrdAdapt(TS ts, PetscBool flg) in TSEIMEXSetOrdAdapt() argument
439 PetscValidHeaderSpecific(ts, TS_CLASSID, 1); in TSEIMEXSetOrdAdapt()
440 PetscTryMethod(ts, "TSEIMEXSetOrdAdapt_C", (TS, PetscBool), (ts, flg)); in TSEIMEXSetOrdAdapt()
444 static PetscErrorCode TSEIMEXSetMaxRows_EIMEX(TS ts, PetscInt nrows) in TSEIMEXSetMaxRows_EIMEX() argument
446 TS_EIMEX *ext = (TS_EIMEX *)ts->data; in TSEIMEXSetMaxRows_EIMEX()
450 …PetscCheck(nrows >= 0 && nrows <= 100, ((PetscObject)ts)->comm, PETSC_ERR_ARG_OUTOFRANGE, "Max num… in TSEIMEXSetMaxRows_EIMEX()
458 static PetscErrorCode TSEIMEXSetRowCol_EIMEX(TS ts, PetscInt row, PetscInt col) in TSEIMEXSetRowCol_EIMEX() argument
460 TS_EIMEX *ext = (TS_EIMEX *)ts->data; in TSEIMEXSetRowCol_EIMEX()
463 …PetscCheck(row >= 1 && col >= 1, ((PetscObject)ts)->comm, PETSC_ERR_ARG_OUTOFRANGE, "The row or co… in TSEIMEXSetRowCol_EIMEX()
464 …PetscCheck(row <= ext->max_rows && col <= ext->max_rows, ((PetscObject)ts)->comm, PETSC_ERR_ARG_OU… in TSEIMEXSetRowCol_EIMEX()
466 …PetscCheck(col <= row, ((PetscObject)ts)->comm, PETSC_ERR_ARG_OUTOFRANGE, "The column index (%" Pe… in TSEIMEXSetRowCol_EIMEX()
473 static PetscErrorCode TSEIMEXSetOrdAdapt_EIMEX(TS ts, PetscBool flg) in TSEIMEXSetOrdAdapt_EIMEX() argument
475 TS_EIMEX *ext = (TS_EIMEX *)ts->data; in TSEIMEXSetOrdAdapt_EIMEX()
520 PETSC_EXTERN PetscErrorCode TSCreate_EIMEX(TS ts) in TSCreate_EIMEX() argument
525 ts->ops->reset = TSReset_EIMEX; in TSCreate_EIMEX()
526 ts->ops->destroy = TSDestroy_EIMEX; in TSCreate_EIMEX()
527 ts->ops->view = TSView_EIMEX; in TSCreate_EIMEX()
528 ts->ops->setup = TSSetUp_EIMEX; in TSCreate_EIMEX()
529 ts->ops->step = TSStep_EIMEX; in TSCreate_EIMEX()
530 ts->ops->interpolate = TSInterpolate_EIMEX; in TSCreate_EIMEX()
531 ts->ops->evaluatestep = TSEvaluateStep_EIMEX; in TSCreate_EIMEX()
532 ts->ops->setfromoptions = TSSetFromOptions_EIMEX; in TSCreate_EIMEX()
533 ts->ops->snesfunction = SNESTSFormFunction_EIMEX; in TSCreate_EIMEX()
534 ts->ops->snesjacobian = SNESTSFormJacobian_EIMEX; in TSCreate_EIMEX()
535 ts->default_adapt_type = TSADAPTNONE; in TSCreate_EIMEX()
537 ts->usessnes = PETSC_TRUE; in TSCreate_EIMEX()
540 ts->data = (void *)ext; in TSCreate_EIMEX()
548 …PetscCall(PetscObjectComposeFunction((PetscObject)ts, "TSEIMEXSetMaxRows_C", TSEIMEXSetMaxRows_EIM… in TSCreate_EIMEX()
549 …PetscCall(PetscObjectComposeFunction((PetscObject)ts, "TSEIMEXSetRowCol_C", TSEIMEXSetRowCol_EIMEX… in TSCreate_EIMEX()
550 …PetscCall(PetscObjectComposeFunction((PetscObject)ts, "TSEIMEXSetOrdAdapt_C", TSEIMEXSetOrdAdapt_E… in TSCreate_EIMEX()