xref: /petsc/src/ts/interface/tsreg.c (revision 5615d1e584023db9367fb782d85b1b4ebbb8df18)
18b1af7b3SBarry Smith 
2fae171e0SBarry Smith 
33f3760d9SBarry Smith #ifndef lint
4*5615d1e5SSatish Balay static char vcid[] = "$Id: tsreg.c,v 1.14 1997/01/01 03:39:55 bsmith Exp balay $";
53f3760d9SBarry Smith #endif
63f3760d9SBarry Smith 
770f55243SBarry Smith #include "src/ts/tsimpl.h"      /*I "ts.h"  I*/
8f5eb4b81SSatish Balay #include "src/sys/nreg.h"
93f3760d9SBarry Smith #include "pinclude/pviewer.h"
103f3760d9SBarry Smith #include <math.h>
113f3760d9SBarry Smith 
128b1af7b3SBarry Smith static NRList *__TSList = 0;
133f3760d9SBarry Smith 
14*5615d1e5SSatish Balay #undef __FUNC__
15*5615d1e5SSatish Balay #define __FUNC__ "TSSetType"
163f3760d9SBarry Smith /*@
17ae12b187SLois Curfman McInnes    TSSetType - Sets the method for the timestepping solver.
183f3760d9SBarry Smith 
193f3760d9SBarry Smith    Input Parameters:
208b1af7b3SBarry Smith .  ts - the TS context
213f3760d9SBarry Smith .  method - a known method
223f3760d9SBarry Smith 
23ae12b187SLois Curfman McInnes   Options Database Command:
24ae12b187SLois Curfman McInnes $ -ts_type  <method>
25ae12b187SLois Curfman McInnes $    Use -help for a list of available methods
26ae12b187SLois Curfman McInnes $    (for instance, euler)
27ae12b187SLois Curfman McInnes 
283f3760d9SBarry Smith    Notes:
298b1af7b3SBarry Smith    See "petsc/include/ts.h" for available methods (for instance)
308b1af7b3SBarry Smith $   TS_EULER
31ca90a507SBarry Smith $   TS_BEULER
32ca90a507SBarry Smith $   TS_PSEUDO
333f3760d9SBarry Smith 
34ae12b187SLois Curfman McInnes   Normally, it is best to use the TSSetFromOptions() command and
35ae12b187SLois Curfman McInnes   then set the TS type from the options database rather than by using
36ae12b187SLois Curfman McInnes   this routine.  Using the options database provides the user with
37ae12b187SLois Curfman McInnes   maximum flexibility in evaluating the many different solvers.
38ae12b187SLois Curfman McInnes   The TSSetType() routine is provided for those situations where it
39ae12b187SLois Curfman McInnes   is necessary to set the timestepping solver independently of the
40ae12b187SLois Curfman McInnes   command line or options database.  This might be the case, for example,
41ae12b187SLois Curfman McInnes   when the choice of solver changes during the execution of the
42ae12b187SLois Curfman McInnes   program, and the user's application is taking responsibility for
43ae12b187SLois Curfman McInnes   choosing the appropriate method.  In other words, this routine is
44ae12b187SLois Curfman McInnes   for the advanced user.
453f3760d9SBarry Smith 
46ae12b187SLois Curfman McInnes .keywords: TS, set, type
473f3760d9SBarry Smith @*/
488b1af7b3SBarry Smith int TSSetType(TS ts,TSType method)
493f3760d9SBarry Smith {
508b1af7b3SBarry Smith   int (*r)(TS);
518b1af7b3SBarry Smith 
52c3e30b67SBarry Smith   PetscValidHeaderSpecific(ts,TS_COOKIE);
538b1af7b3SBarry Smith   /* Get the function pointers for the method requested */
548b1af7b3SBarry Smith   if (!__TSList) {TSRegisterAll();}
55e3372554SBarry Smith   if (!__TSList) {SETERRQ(1,0,"Could not get methods");}
568b1af7b3SBarry Smith   r =  (int (*)(TS))NRFindRoutine( __TSList, (int)method, (char *)0 );
57e3372554SBarry Smith   if (!r) {SETERRQ(1,0,"Unknown method");}
588b1af7b3SBarry Smith   if (ts->data) PetscFree(ts->data);
598b1af7b3SBarry Smith   return (*r)(ts);
603f3760d9SBarry Smith }
613f3760d9SBarry Smith 
623f3760d9SBarry Smith /* --------------------------------------------------------------------- */
63*5615d1e5SSatish Balay #undef __FUNC__
64*5615d1e5SSatish Balay #define __FUNC__ "TSRegister"
653f3760d9SBarry Smith /*@C
668b1af7b3SBarry Smith    TSRegister - Adds the method to the nonlinear solver package, given
678b1af7b3SBarry Smith    a function pointer and a nonlinear solver name of the type TSType.
683f3760d9SBarry Smith 
693f3760d9SBarry Smith    Input Parameters:
708b1af7b3SBarry Smith .  name - for instance TS_EQ_NLS, TS_EQ_NTR, ...
713f3760d9SBarry Smith .  sname - corfunPonding string for name
723f3760d9SBarry Smith .  create - routine to create method context
733f3760d9SBarry Smith 
748b1af7b3SBarry Smith .keywords: TS, nonlinear, register
753f3760d9SBarry Smith 
768b1af7b3SBarry Smith .seealso: TSRegisterAll(), TSRegisterDestroy()
773f3760d9SBarry Smith @*/
788b1af7b3SBarry Smith int TSRegister(int name, char *sname, int (*create)(TS))
793f3760d9SBarry Smith {
803f3760d9SBarry Smith   int ierr;
818b1af7b3SBarry Smith   if (!__TSList) {ierr = NRCreate(&__TSList); CHKERRQ(ierr);}
828b1af7b3SBarry Smith   NRRegister( __TSList, name, sname, (int (*)(void*))create );
833f3760d9SBarry Smith   return 0;
843f3760d9SBarry Smith }
853f3760d9SBarry Smith /* --------------------------------------------------------------------- */
86*5615d1e5SSatish Balay #undef __FUNC__
87*5615d1e5SSatish Balay #define __FUNC__ "TSRegisterDestroy"
883f3760d9SBarry Smith /*@C
898b1af7b3SBarry Smith    TSRegisterDestroy - Frees the list of nonlinear solvers that were
908b1af7b3SBarry Smith    registered by TSRegister().
913f3760d9SBarry Smith 
928b1af7b3SBarry Smith .keywords: TS, nonlinear, register, destroy
933f3760d9SBarry Smith 
948b1af7b3SBarry Smith .seealso: TSRegisterAll(), TSRegisterAll()
953f3760d9SBarry Smith @*/
968b1af7b3SBarry Smith int TSRegisterDestroy()
973f3760d9SBarry Smith {
988b1af7b3SBarry Smith   if (__TSList) {
998b1af7b3SBarry Smith     NRDestroy( __TSList );
1008b1af7b3SBarry Smith     __TSList = 0;
1013f3760d9SBarry Smith   }
1023f3760d9SBarry Smith   return 0;
1033f3760d9SBarry Smith }
1043f3760d9SBarry Smith 
105*5615d1e5SSatish Balay #undef __FUNC__
106*5615d1e5SSatish Balay #define __FUNC__ "TSGetType"
1073f3760d9SBarry Smith /*@C
1088b1af7b3SBarry Smith    TSGetType - Gets the TS method type and name (as a string).
1093f3760d9SBarry Smith 
1103f3760d9SBarry Smith    Input Parameter:
1118b1af7b3SBarry Smith .  ts - nonlinear solver context
1123f3760d9SBarry Smith 
1133f3760d9SBarry Smith    Output Parameter:
1148b1af7b3SBarry Smith .  method - TS method (or use PETSC_NULL)
1158b1af7b3SBarry Smith .  name - name of TS method (or use PETSC_NULL)
1163f3760d9SBarry Smith 
1178b1af7b3SBarry Smith .keywords: TS, nonlinear, get, method, name
1183f3760d9SBarry Smith @*/
1198b1af7b3SBarry Smith int TSGetType(TS ts, TSType *method,char **name)
1203f3760d9SBarry Smith {
1213f3760d9SBarry Smith   int ierr;
1228b1af7b3SBarry Smith   if (!__TSList) {ierr = TSRegisterAll(); CHKERRQ(ierr);}
1238b1af7b3SBarry Smith   if (method) *method = (TSType) ts->type;
1248b1af7b3SBarry Smith   if (name)  *name = NRFindName( __TSList, (int) ts->type );
1253f3760d9SBarry Smith   return 0;
1263f3760d9SBarry Smith }
1273f3760d9SBarry Smith 
1283f3760d9SBarry Smith #include <stdio.h>
129*5615d1e5SSatish Balay #undef __FUNC__
130*5615d1e5SSatish Balay #define __FUNC__ "TSPrintTypes_Private"
1313f3760d9SBarry Smith /*
1328b1af7b3SBarry Smith    TSPrintTypes_Private - Prints the TS methods available from the
1333f3760d9SBarry Smith    options database.
1343f3760d9SBarry Smith 
1353f3760d9SBarry Smith    Input Parameters:
136b5f69acfSSatish Balay .  comm   - The communicator (usually MPI_COMM_WORLD)
1373f3760d9SBarry Smith .  prefix - prefix (usually "-")
1388b1af7b3SBarry Smith .  name   - the options database name (by default "ts_type")
1393f3760d9SBarry Smith */
140b5f69acfSSatish Balay int TSPrintTypes_Private(MPI_Comm comm,char* prefix,char *name)
1413f3760d9SBarry Smith {
1423f3760d9SBarry Smith   FuncList *entry;
1438b1af7b3SBarry Smith   if (!__TSList) {TSRegisterAll();}
1448b1af7b3SBarry Smith   entry = __TSList->head;
145c3e30b67SBarry Smith   PetscPrintf(comm," %s%s (one of)",prefix,name);
1463f3760d9SBarry Smith   while (entry) {
147c3e30b67SBarry Smith     PetscPrintf(comm," %s",entry->name);
1483f3760d9SBarry Smith     entry = entry->next;
1493f3760d9SBarry Smith   }
150c3e30b67SBarry Smith   PetscPrintf(comm,"\n");
1513f3760d9SBarry Smith   return 0;
1523f3760d9SBarry Smith }
1533f3760d9SBarry Smith 
1548b1af7b3SBarry Smith 
155*5615d1e5SSatish Balay #undef __FUNC__
156*5615d1e5SSatish Balay #define __FUNC__ "TSGetTypeFromOptions_Private"
1578b1af7b3SBarry Smith /*
1588b1af7b3SBarry Smith    TSGetTypeFromOptions_Private - Sets the selected method from the
1598b1af7b3SBarry Smith    options database.
1603f3760d9SBarry Smith 
1613f3760d9SBarry Smith    Input Parameter:
1628b1af7b3SBarry Smith .  ctx - the TS context
1633f3760d9SBarry Smith 
1643f3760d9SBarry Smith    Output Parameter:
1658b1af7b3SBarry Smith .  method -  solver method
1663f3760d9SBarry Smith 
1678b1af7b3SBarry Smith    Returns:
1688b1af7b3SBarry Smith    Returns 1 if the method is found; 0 otherwise.
1693f3760d9SBarry Smith 
1708b1af7b3SBarry Smith    Options Database Key:
1718b1af7b3SBarry Smith $  -ts_type  method
1728b1af7b3SBarry Smith */
1738b1af7b3SBarry Smith int TSGetTypeFromOptions_Private(TS ctx,TSType *method,int *flg)
1743f3760d9SBarry Smith {
1758b1af7b3SBarry Smith   int ierr;
1768b1af7b3SBarry Smith   char sbuf[50];
1778b1af7b3SBarry Smith   ierr = OptionsGetString(ctx->prefix,"-ts_type", sbuf, 50, flg); CHKERRQ(ierr);
1788b1af7b3SBarry Smith   if (*flg) {
1798b1af7b3SBarry Smith     if (!__TSList) {ierr = TSRegisterAll(); CHKERRQ(ierr);}
1808b1af7b3SBarry Smith     *method = (TSType)NRFindID( __TSList, sbuf );
1818b1af7b3SBarry Smith   }
1823f3760d9SBarry Smith   return 0;
1833f3760d9SBarry Smith }
184