xref: /petsc/src/ts/interface/tsreg.c (revision ae12b18718ad3e20fb6569b404a25d60538e6441)
18b1af7b3SBarry Smith 
2fae171e0SBarry Smith 
33f3760d9SBarry Smith #ifndef lint
4*ae12b187SLois Curfman McInnes static char vcid[] = "$Id: tsreg.c,v 1.10 1996/10/15 18:48:05 balay Exp curfman $";
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 
143f3760d9SBarry Smith /*@
15*ae12b187SLois Curfman McInnes    TSSetType - Sets the method for the timestepping solver.
163f3760d9SBarry Smith 
173f3760d9SBarry Smith    Input Parameters:
188b1af7b3SBarry Smith .  ts - the TS context
193f3760d9SBarry Smith .  method - a known method
203f3760d9SBarry Smith 
21*ae12b187SLois Curfman McInnes   Options Database Command:
22*ae12b187SLois Curfman McInnes $ -ts_type  <method>
23*ae12b187SLois Curfman McInnes $    Use -help for a list of available methods
24*ae12b187SLois Curfman McInnes $    (for instance, euler)
25*ae12b187SLois Curfman McInnes 
263f3760d9SBarry Smith    Notes:
278b1af7b3SBarry Smith    See "petsc/include/ts.h" for available methods (for instance)
288b1af7b3SBarry Smith $   TS_EULER
29ca90a507SBarry Smith $   TS_BEULER
30ca90a507SBarry Smith $   TS_PSEUDO
313f3760d9SBarry Smith 
32*ae12b187SLois Curfman McInnes   Normally, it is best to use the TSSetFromOptions() command and
33*ae12b187SLois Curfman McInnes   then set the TS type from the options database rather than by using
34*ae12b187SLois Curfman McInnes   this routine.  Using the options database provides the user with
35*ae12b187SLois Curfman McInnes   maximum flexibility in evaluating the many different solvers.
36*ae12b187SLois Curfman McInnes   The TSSetType() routine is provided for those situations where it
37*ae12b187SLois Curfman McInnes   is necessary to set the timestepping solver independently of the
38*ae12b187SLois Curfman McInnes   command line or options database.  This might be the case, for example,
39*ae12b187SLois Curfman McInnes   when the choice of solver changes during the execution of the
40*ae12b187SLois Curfman McInnes   program, and the user's application is taking responsibility for
41*ae12b187SLois Curfman McInnes   choosing the appropriate method.  In other words, this routine is
42*ae12b187SLois Curfman McInnes   for the advanced user.
433f3760d9SBarry Smith 
44*ae12b187SLois Curfman McInnes .keywords: TS, set, type
453f3760d9SBarry Smith @*/
468b1af7b3SBarry Smith int TSSetType(TS ts,TSType method)
473f3760d9SBarry Smith {
488b1af7b3SBarry Smith   int (*r)(TS);
498b1af7b3SBarry Smith 
50c3e30b67SBarry Smith   PetscValidHeaderSpecific(ts,TS_COOKIE);
518b1af7b3SBarry Smith   /* Get the function pointers for the method requested */
528b1af7b3SBarry Smith   if (!__TSList) {TSRegisterAll();}
538b1af7b3SBarry Smith   if (!__TSList) {SETERRQ(1,"TSSetType:Could not get methods");}
548b1af7b3SBarry Smith   r =  (int (*)(TS))NRFindRoutine( __TSList, (int)method, (char *)0 );
558b1af7b3SBarry Smith   if (!r) {SETERRQ(1,"TSSetType:Unknown method");}
568b1af7b3SBarry Smith   if (ts->data) PetscFree(ts->data);
578b1af7b3SBarry Smith   return (*r)(ts);
583f3760d9SBarry Smith }
593f3760d9SBarry Smith 
603f3760d9SBarry Smith /* --------------------------------------------------------------------- */
613f3760d9SBarry Smith /*@C
628b1af7b3SBarry Smith    TSRegister - Adds the method to the nonlinear solver package, given
638b1af7b3SBarry Smith    a function pointer and a nonlinear solver name of the type TSType.
643f3760d9SBarry Smith 
653f3760d9SBarry Smith    Input Parameters:
668b1af7b3SBarry Smith .  name - for instance TS_EQ_NLS, TS_EQ_NTR, ...
673f3760d9SBarry Smith .  sname - corfunPonding string for name
683f3760d9SBarry Smith .  create - routine to create method context
693f3760d9SBarry Smith 
708b1af7b3SBarry Smith .keywords: TS, nonlinear, register
713f3760d9SBarry Smith 
728b1af7b3SBarry Smith .seealso: TSRegisterAll(), TSRegisterDestroy()
733f3760d9SBarry Smith @*/
748b1af7b3SBarry Smith int TSRegister(int name, char *sname, int (*create)(TS))
753f3760d9SBarry Smith {
763f3760d9SBarry Smith   int ierr;
778b1af7b3SBarry Smith   if (!__TSList) {ierr = NRCreate(&__TSList); CHKERRQ(ierr);}
788b1af7b3SBarry Smith   NRRegister( __TSList, name, sname, (int (*)(void*))create );
793f3760d9SBarry Smith   return 0;
803f3760d9SBarry Smith }
813f3760d9SBarry Smith /* --------------------------------------------------------------------- */
823f3760d9SBarry Smith /*@C
838b1af7b3SBarry Smith    TSRegisterDestroy - Frees the list of nonlinear solvers that were
848b1af7b3SBarry Smith    registered by TSRegister().
853f3760d9SBarry Smith 
868b1af7b3SBarry Smith .keywords: TS, nonlinear, register, destroy
873f3760d9SBarry Smith 
888b1af7b3SBarry Smith .seealso: TSRegisterAll(), TSRegisterAll()
893f3760d9SBarry Smith @*/
908b1af7b3SBarry Smith int TSRegisterDestroy()
913f3760d9SBarry Smith {
928b1af7b3SBarry Smith   if (__TSList) {
938b1af7b3SBarry Smith     NRDestroy( __TSList );
948b1af7b3SBarry Smith     __TSList = 0;
953f3760d9SBarry Smith   }
963f3760d9SBarry Smith   return 0;
973f3760d9SBarry Smith }
983f3760d9SBarry Smith 
993f3760d9SBarry Smith /*@C
1008b1af7b3SBarry Smith    TSGetType - Gets the TS method type and name (as a string).
1013f3760d9SBarry Smith 
1023f3760d9SBarry Smith    Input Parameter:
1038b1af7b3SBarry Smith .  ts - nonlinear solver context
1043f3760d9SBarry Smith 
1053f3760d9SBarry Smith    Output Parameter:
1068b1af7b3SBarry Smith .  method - TS method (or use PETSC_NULL)
1078b1af7b3SBarry Smith .  name - name of TS method (or use PETSC_NULL)
1083f3760d9SBarry Smith 
1098b1af7b3SBarry Smith .keywords: TS, nonlinear, get, method, name
1103f3760d9SBarry Smith @*/
1118b1af7b3SBarry Smith int TSGetType(TS ts, TSType *method,char **name)
1123f3760d9SBarry Smith {
1133f3760d9SBarry Smith   int ierr;
1148b1af7b3SBarry Smith   if (!__TSList) {ierr = TSRegisterAll(); CHKERRQ(ierr);}
1158b1af7b3SBarry Smith   if (method) *method = (TSType) ts->type;
1168b1af7b3SBarry Smith   if (name)  *name = NRFindName( __TSList, (int) ts->type );
1173f3760d9SBarry Smith   return 0;
1183f3760d9SBarry Smith }
1193f3760d9SBarry Smith 
1203f3760d9SBarry Smith #include <stdio.h>
1213f3760d9SBarry Smith /*
1228b1af7b3SBarry Smith    TSPrintTypes_Private - Prints the TS methods available from the
1233f3760d9SBarry Smith    options database.
1243f3760d9SBarry Smith 
1253f3760d9SBarry Smith    Input Parameters:
126b5f69acfSSatish Balay .  comm   - The communicator (usually MPI_COMM_WORLD)
1273f3760d9SBarry Smith .  prefix - prefix (usually "-")
1288b1af7b3SBarry Smith .  name   - the options database name (by default "ts_type")
1293f3760d9SBarry Smith */
130b5f69acfSSatish Balay int TSPrintTypes_Private(MPI_Comm comm,char* prefix,char *name)
1313f3760d9SBarry Smith {
1323f3760d9SBarry Smith   FuncList *entry;
1338b1af7b3SBarry Smith   if (!__TSList) {TSRegisterAll();}
1348b1af7b3SBarry Smith   entry = __TSList->head;
135c3e30b67SBarry Smith   PetscPrintf(comm," %s%s (one of)",prefix,name);
1363f3760d9SBarry Smith   while (entry) {
137c3e30b67SBarry Smith     PetscPrintf(comm," %s",entry->name);
1383f3760d9SBarry Smith     entry = entry->next;
1393f3760d9SBarry Smith   }
140c3e30b67SBarry Smith   PetscPrintf(comm,"\n");
1413f3760d9SBarry Smith   return 0;
1423f3760d9SBarry Smith }
1433f3760d9SBarry Smith 
1448b1af7b3SBarry Smith 
1458b1af7b3SBarry Smith /*
1468b1af7b3SBarry Smith    TSGetTypeFromOptions_Private - Sets the selected method from the
1478b1af7b3SBarry Smith    options database.
1483f3760d9SBarry Smith 
1493f3760d9SBarry Smith    Input Parameter:
1508b1af7b3SBarry Smith .  ctx - the TS context
1513f3760d9SBarry Smith 
1523f3760d9SBarry Smith    Output Parameter:
1538b1af7b3SBarry Smith .  method -  solver method
1543f3760d9SBarry Smith 
1558b1af7b3SBarry Smith    Returns:
1568b1af7b3SBarry Smith    Returns 1 if the method is found; 0 otherwise.
1573f3760d9SBarry Smith 
1588b1af7b3SBarry Smith    Options Database Key:
1598b1af7b3SBarry Smith $  -ts_type  method
1608b1af7b3SBarry Smith */
1618b1af7b3SBarry Smith int TSGetTypeFromOptions_Private(TS ctx,TSType *method,int *flg)
1623f3760d9SBarry Smith {
1638b1af7b3SBarry Smith   int ierr;
1648b1af7b3SBarry Smith   char sbuf[50];
1658b1af7b3SBarry Smith   ierr = OptionsGetString(ctx->prefix,"-ts_type", sbuf, 50, flg); CHKERRQ(ierr);
1668b1af7b3SBarry Smith   if (*flg) {
1678b1af7b3SBarry Smith     if (!__TSList) {ierr = TSRegisterAll(); CHKERRQ(ierr);}
1688b1af7b3SBarry Smith     *method = (TSType)NRFindID( __TSList, sbuf );
1698b1af7b3SBarry Smith   }
1703f3760d9SBarry Smith   return 0;
1713f3760d9SBarry Smith }
172