xref: /petsc/src/ts/interface/tsreg.c (revision ec7429eab6e231810adac0f010b269bd5bae4496)
1 #include <petsc-private/tsimpl.h>      /*I "petscts.h"  I*/
2 
3 PetscFunctionList TSList              = NULL;
4 PetscBool         TSRegisterAllCalled = PETSC_FALSE;
5 
6 #undef __FUNCT__
7 #define __FUNCT__ "TSSetType"
8 /*@C
9   TSSetType - Sets the method for the timestepping solver.
10 
11   Collective on TS
12 
13   Input Parameters:
14 + ts   - The TS context
15 - type - A known method
16 
17   Options Database Command:
18 . -ts_type <type> - Sets the method; use -help for a list of available methods (for instance, euler)
19 
20    Notes:
21    See "petsc/include/petscts.h" for available methods (for instance)
22 +  TSEULER - Euler
23 .  TSSUNDIALS - SUNDIALS interface
24 .  TSBEULER - Backward Euler
25 -  TSPSEUDO - Pseudo-timestepping
26 
27    Normally, it is best to use the TSSetFromOptions() command and
28    then set the TS type from the options database rather than by using
29    this routine.  Using the options database provides the user with
30    maximum flexibility in evaluating the many different solvers.
31    The TSSetType() routine is provided for those situations where it
32    is necessary to set the timestepping solver independently of the
33    command line or options database.  This might be the case, for example,
34    when the choice of solver changes during the execution of the
35    program, and the user's application is taking responsibility for
36    choosing the appropriate method.  In other words, this routine is
37    not for beginners.
38 
39    Level: intermediate
40 
41 .keywords: TS, set, type
42 
43 @*/
44 PetscErrorCode  TSSetType(TS ts,TSType type)
45 {
46   PetscErrorCode (*r)(TS);
47   PetscBool      match;
48   PetscErrorCode ierr;
49 
50   PetscFunctionBegin;
51   PetscValidHeaderSpecific(ts, TS_CLASSID,1);
52   ierr = PetscObjectTypeCompare((PetscObject) ts, type, &match);CHKERRQ(ierr);
53   if (match) PetscFunctionReturn(0);
54 
55   ierr = PetscFunctionListFind(PetscObjectComm((PetscObject)ts),TSList, type,PETSC_TRUE, (void (**)(void)) &r);CHKERRQ(ierr);
56   if (!r) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_UNKNOWN_TYPE, "Unknown TS type: %s", type);
57   if (ts->ops->destroy) {
58     ierr = (*(ts)->ops->destroy)(ts);CHKERRQ(ierr);
59 
60     ts->ops->destroy = NULL;
61   }
62   ierr = PetscMemzero(ts->ops,sizeof(*ts->ops));CHKERRQ(ierr);
63 
64   ts->setupcalled = PETSC_FALSE;
65 
66   ierr = PetscObjectChangeTypeName((PetscObject)ts, type);CHKERRQ(ierr);
67   ierr = (*r)(ts);CHKERRQ(ierr);
68   if (PetscAMSPublishAll) {
69     ierr = PetscObjectAMSPublish((PetscObject)ts);CHKERRQ(ierr);
70   }
71   PetscFunctionReturn(0);
72 }
73 
74 #undef __FUNCT__
75 #define __FUNCT__ "TSGetType"
76 /*@C
77   TSGetType - Gets the TS method type (as a string).
78 
79   Not Collective
80 
81   Input Parameter:
82 . ts - The TS
83 
84   Output Parameter:
85 . type - The name of TS method
86 
87   Level: intermediate
88 
89 .keywords: TS, timestepper, get, type, name
90 .seealso TSSetType()
91 @*/
92 PetscErrorCode  TSGetType(TS ts, TSType *type)
93 {
94   PetscFunctionBegin;
95   PetscValidHeaderSpecific(ts,TS_CLASSID,1);
96   PetscValidPointer(type,2);
97   *type = ((PetscObject)ts)->type_name;
98   PetscFunctionReturn(0);
99 }
100 
101 /*--------------------------------------------------------------------------------------------------------------------*/
102 
103 #undef __FUNCT__
104 #define __FUNCT__ "TSRegister"
105 /*@C
106   TSRegister - See TSRegisterDynamic()
107 
108   Level: advanced
109 @*/
110 PetscErrorCode  TSRegister(const char sname[], const char path[], const char name[], PetscErrorCode (*function)(TS))
111 {
112   char           fullname[PETSC_MAX_PATH_LEN];
113   PetscErrorCode ierr;
114 
115   PetscFunctionBegin;
116   ierr = PetscStrcpy(fullname, path);CHKERRQ(ierr);
117   ierr = PetscStrcat(fullname, ":");CHKERRQ(ierr);
118   ierr = PetscStrcat(fullname, name);CHKERRQ(ierr);
119   ierr = PetscFunctionListAdd(PETSC_COMM_WORLD,&TSList, sname, fullname, (void (*)(void))function);CHKERRQ(ierr);
120   PetscFunctionReturn(0);
121 }
122 
123 /*-------------------------------------------------------------------------------------------------------------------*/
124 #undef __FUNCT__
125 #define __FUNCT__ "TSRegisterDestroy"
126 /*@C
127    TSRegisterDestroy - Frees the list of timestepping routines that were registered by TSRegister()/TSRegisterDynamic().
128 
129    Not Collective
130 
131    Level: advanced
132 
133 .keywords: TS, timestepper, register, destroy
134 .seealso: TSRegister(), TSRegisterAll(), TSRegisterDynamic()
135 @*/
136 PetscErrorCode  TSRegisterDestroy(void)
137 {
138   PetscErrorCode ierr;
139 
140   PetscFunctionBegin;
141   ierr = PetscFunctionListDestroy(&TSList);CHKERRQ(ierr);
142   TSRegisterAllCalled = PETSC_FALSE;
143   PetscFunctionReturn(0);
144 }
145