Date: 2025-03-29T05:58:49+00:00

Actual source code: tscreate.c

      1: #include <petsc/private/tsimpl.h>

      3: const char *const TSConvergedReasons_Shifted[] = {"ADJOINT_DIVERGED_LINEAR_SOLVE", "FORWARD_DIVERGED_LINEAR_SOLVE", "DIVERGED_STEP_REJECTED", "DIVERGED_NONLINEAR_SOLVE", "CONVERGED_ITERATING", "CONVERGED_TIME", "CONVERGED_ITS", "CONVERGED_USER", "CONVERGED_EVENT", "CONVERGED_PSEUDO_FATOL", "CONVERGED_PSEUDO_FATOL", "TSConvergedReason", "TS_", NULL};
      4: const char *const *TSConvergedReasons = TSConvergedReasons_Shifted + 4;

      6: /*@
      7:   TSCreate - This function creates an empty timestepper. The problem type can then be set with `TSSetProblemType()` and the
      8:   type of solver can then be set with `TSSetType()`.

     10:   Collective

     12:   Input Parameter:
     13: . comm - The communicator

     15:   Output Parameter:
     16: . ts - The `TS`

     18:   Level: beginner

     20:   Developer Notes:
     21:   `TS` essentially always creates a `SNES` object even though explicit methods do not use it. This is
     22:   unfortunate and should be fixed at some point. The flag snes->usessnes indicates if the
     23:   particular method does use SNES and regulates if the information about the `SNES` is printed
     24:   in `TSView()`. `TSSetFromOptions(`) does call `SNESSetFromOptions()` which can lead to users being confused
     25:   by help messages about meaningless `SNES` options.

     27: .seealso: [](ch_ts), `TS`, `SNES`, `TSSetType()`, `TSSetUp()`, `TSDestroy()`, `TSSetProblemType()`
     28: @*/
     29: PetscErrorCode TSCreate(MPI_Comm comm, TS *ts)
     30: {
     31:   TS t;

     33:   PetscFunctionBegin;
     34:   PetscAssertPointer(ts, 2);
     35:   PetscCall(TSInitializePackage());

     37:   PetscCall(PetscHeaderCreate(t, TS_CLASSID, "TS", "Time stepping", "TS", comm, TSDestroy, TSView));

     39:   /* General TS description */
     40:   t->problem_type  = TS_NONLINEAR;
     41:   t->equation_type = TS_EQ_UNSPECIFIED;

     43:   t->ptime            = 0.0;
     44:   t->time_step        = 0.1;
     45:   t->max_time         = PETSC_MAX_REAL;
     46:   t->exact_final_time = TS_EXACTFINALTIME_UNSPECIFIED;
     47:   t->steps            = 0;
     48:   t->max_steps        = PETSC_INT_MAX;
     49:   t->steprestart      = PETSC_TRUE;

     51:   t->max_snes_failures = 1;
     52:   t->max_reject        = 10;
     53:   t->errorifstepfailed = PETSC_TRUE;

     55:   t->rhsjacobian.time  = PETSC_MIN_REAL;
     56:   t->rhsjacobian.scale = 1.0;
     57:   t->ijacobian.shift   = 1.0;

     59:   /* All methods that do adaptivity should specify
     60:    * its preferred adapt type in their constructor */
     61:   t->default_adapt_type = TSADAPTNONE;
     62:   t->atol               = 1e-4;
     63:   t->rtol               = 1e-4;
     64:   t->cfltime            = PETSC_MAX_REAL;
     65:   t->cfltime_local      = PETSC_MAX_REAL;

     67:   t->num_rhs_splits = 0;

     69:   t->axpy_pattern = UNKNOWN_NONZERO_PATTERN;
     70:   *ts             = t;
     71:   PetscFunctionReturn(PETSC_SUCCESS);
     72: }