xref: /petsc/src/ts/interface/tscreate.c (revision 9371c9d470a9602b6d10a8bf50c9b2280a79e45a)
1 #include <petsc/private/tsimpl.h> /*I "petscts.h"  I*/
2 
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;
5 
6 /*@C
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().
9 
10   Collective
11 
12   Input Parameter:
13 . comm - The communicator
14 
15   Output Parameter:
16 . ts   - The TS
17 
18   Level: beginner
19 
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.
26 
27 .seealso: `TSSetType()`, `TSSetUp()`, `TSDestroy()`, `TSSetProblemType()`
28 @*/
29 PetscErrorCode TSCreate(MPI_Comm comm, TS *ts) {
30   TS t;
31 
32   PetscFunctionBegin;
33   PetscValidPointer(ts, 2);
34   *ts = NULL;
35   PetscCall(TSInitializePackage());
36 
37   PetscCall(PetscHeaderCreate(t, TS_CLASSID, "TS", "Time stepping", "TS", comm, TSDestroy, TSView));
38 
39   /* General TS description */
40   t->problem_type  = TS_NONLINEAR;
41   t->equation_type = TS_EQ_UNSPECIFIED;
42 
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_MAX_INT;
49   t->steprestart      = PETSC_TRUE;
50 
51   t->max_snes_failures = 1;
52   t->max_reject        = 10;
53   t->errorifstepfailed = PETSC_TRUE;
54 
55   t->rhsjacobian.time  = PETSC_MIN_REAL;
56   t->rhsjacobian.scale = 1.0;
57   t->ijacobian.shift   = 1.0;
58 
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;
66 
67   t->num_rhs_splits = 0;
68 
69   t->axpy_pattern = UNKNOWN_NONZERO_PATTERN;
70   *ts             = t;
71   PetscFunctionReturn(0);
72 }
73