xref: /petsc/src/ts/interface/tscreate.c (revision 9371c9d470a9602b6d10a8bf50c9b2280a79e45a)
1af0996ceSBarry Smith #include <petsc/private/tsimpl.h> /*I "petscts.h"  I*/
2bdad233fSMatthew Knepley 
3*9371c9d4SSatish Balay 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};
422b60d99SBarry Smith const char *const *TSConvergedReasons           = TSConvergedReasons_Shifted + 4;
5193ac0bcSJed Brown 
660893bc3SSatish Balay /*@C
7bd6a702fSBarry Smith   TSCreate - This function creates an empty timestepper. The problem type can then be set with TSSetProblemType() and the
8bd6a702fSBarry Smith        type of solver can then be set with TSSetType().
9bdad233fSMatthew Knepley 
10d083f849SBarry Smith   Collective
11bdad233fSMatthew Knepley 
12bdad233fSMatthew Knepley   Input Parameter:
13bdad233fSMatthew Knepley . comm - The communicator
14bdad233fSMatthew Knepley 
15bdad233fSMatthew Knepley   Output Parameter:
16bdad233fSMatthew Knepley . ts   - The TS
17bdad233fSMatthew Knepley 
18bdad233fSMatthew Knepley   Level: beginner
19bdad233fSMatthew Knepley 
2095452b02SPatrick Sanan   Developer Notes:
2195452b02SPatrick Sanan     TS essentially always creates a SNES object even though explicit methods do not use it. This is
22efd4aadfSBarry Smith                     unfortunate and should be fixed at some point. The flag snes->usessnes indicates if the
23efd4aadfSBarry Smith                     particular method does use SNES and regulates if the information about the SNES is printed
24efd4aadfSBarry Smith                     in TSView(). TSSetFromOptions() does call SNESSetFromOptions() which can lead to users being confused
25efd4aadfSBarry Smith                     by help messages about meaningless SNES options.
26efd4aadfSBarry Smith 
27db781477SPatrick Sanan .seealso: `TSSetType()`, `TSSetUp()`, `TSDestroy()`, `TSSetProblemType()`
28bdad233fSMatthew Knepley @*/
29*9371c9d4SSatish Balay PetscErrorCode TSCreate(MPI_Comm comm, TS *ts) {
30bdad233fSMatthew Knepley   TS t;
31bdad233fSMatthew Knepley 
32bdad233fSMatthew Knepley   PetscFunctionBegin;
33064a246eSJacob Faibussowitsch   PetscValidPointer(ts, 2);
340298fd71SBarry Smith   *ts = NULL;
359566063dSJacob Faibussowitsch   PetscCall(TSInitializePackage());
36bdad233fSMatthew Knepley 
379566063dSJacob Faibussowitsch   PetscCall(PetscHeaderCreate(t, TS_CLASSID, "TS", "Time stepping", "TS", comm, TSDestroy, TSView));
38bdad233fSMatthew Knepley 
39bdad233fSMatthew Knepley   /* General TS description */
40089b2837SJed Brown   t->problem_type  = TS_NONLINEAR;
41ef85077eSLisandro Dalcin   t->equation_type = TS_EQ_UNSPECIFIED;
42ef85077eSLisandro Dalcin 
43cdbf8f93SLisandro Dalcin   t->ptime            = 0.0;
44cdbf8f93SLisandro Dalcin   t->time_step        = 0.1;
45ef85077eSLisandro Dalcin   t->max_time         = PETSC_MAX_REAL;
46ef85077eSLisandro Dalcin   t->exact_final_time = TS_EXACTFINALTIME_UNSPECIFIED;
47bdad233fSMatthew Knepley   t->steps            = 0;
48ef85077eSLisandro Dalcin   t->max_steps        = PETSC_MAX_INT;
49ef85077eSLisandro Dalcin   t->steprestart      = PETSC_TRUE;
50ef85077eSLisandro Dalcin 
51193ac0bcSJed Brown   t->max_snes_failures = 1;
52193ac0bcSJed Brown   t->max_reject        = 10;
53193ac0bcSJed Brown   t->errorifstepfailed = PETSC_TRUE;
54bdad233fSMatthew Knepley 
55ef85077eSLisandro Dalcin   t->rhsjacobian.time  = PETSC_MIN_REAL;
56ef85077eSLisandro Dalcin   t->rhsjacobian.scale = 1.0;
57ef85077eSLisandro Dalcin   t->ijacobian.shift   = 1.0;
5868bece0bSHong Zhang 
59b92453a8SLisandro Dalcin   /* All methods that do adaptivity should specify
60b92453a8SLisandro Dalcin    * its preferred adapt type in their constructor */
61b92453a8SLisandro Dalcin   t->default_adapt_type = TSADAPTNONE;
62ef85077eSLisandro Dalcin   t->atol               = 1e-4;
63ef85077eSLisandro Dalcin   t->rtol               = 1e-4;
64ef85077eSLisandro Dalcin   t->cfltime            = PETSC_MAX_REAL;
65ef85077eSLisandro Dalcin   t->cfltime_local      = PETSC_MAX_REAL;
66715f1b00SHong Zhang 
6787f4e208SHong Zhang   t->num_rhs_splits = 0;
6887f4e208SHong Zhang 
69d60b7d5cSBarry Smith   t->axpy_pattern = UNKNOWN_NONZERO_PATTERN;
70bdad233fSMatthew Knepley   *ts             = t;
71bdad233fSMatthew Knepley   PetscFunctionReturn(0);
72bdad233fSMatthew Knepley }
73