xref: /petsc/src/ts/interface/tsreg.c (revision 8b1af7b3d7ce1298a43af33cb6c2e0c485b769e8)
1*8b1af7b3SBarry Smith 
23f3760d9SBarry Smith #ifndef lint
3*8b1af7b3SBarry Smith static char vcid[] = "$Id: tsreg.c,v 1.1 1996/01/06 16:45:30 bsmith Exp bsmith $";
43f3760d9SBarry Smith #endif
53f3760d9SBarry Smith 
6*8b1af7b3SBarry Smith #include "tsimpl.h"      /*I "ts.h"  I*/
73f3760d9SBarry Smith #include "sys/nreg.h"
83f3760d9SBarry Smith #include "pinclude/pviewer.h"
93f3760d9SBarry Smith #include <math.h>
103f3760d9SBarry Smith 
11*8b1af7b3SBarry Smith static NRList *__TSList = 0;
123f3760d9SBarry Smith 
133f3760d9SBarry Smith /*@
14*8b1af7b3SBarry Smith    TSSetType - Sets the method for the nonlinear solver.
153f3760d9SBarry Smith 
163f3760d9SBarry Smith    Input Parameters:
17*8b1af7b3SBarry Smith .  ts - the TS context
183f3760d9SBarry Smith .  method - a known method
193f3760d9SBarry Smith 
203f3760d9SBarry Smith    Notes:
21*8b1af7b3SBarry Smith    See "petsc/include/ts.h" for available methods (for instance)
22*8b1af7b3SBarry Smith $   TS_EULER
233f3760d9SBarry Smith 
243f3760d9SBarry Smith   Options Database Command:
25*8b1af7b3SBarry Smith $ -ts_type  <method>
263f3760d9SBarry Smith $    Use -help for a list of available methods
27*8b1af7b3SBarry Smith $    (for instance, euler)
283f3760d9SBarry Smith 
29*8b1af7b3SBarry Smith .keysords: TS, set, method
303f3760d9SBarry Smith @*/
31*8b1af7b3SBarry Smith int TSSetType(TS ts,TSType method)
323f3760d9SBarry Smith {
33*8b1af7b3SBarry Smith   int (*r)(TS);
34*8b1af7b3SBarry Smith 
35*8b1af7b3SBarry Smith   PETSCVALIDHEADERSPECIFIC(ts,TS_COOKIE);
36*8b1af7b3SBarry Smith   /* Get the function pointers for the method requested */
37*8b1af7b3SBarry Smith   if (!__TSList) {TSRegisterAll();}
38*8b1af7b3SBarry Smith   if (!__TSList) {SETERRQ(1,"TSSetType:Could not get methods");}
39*8b1af7b3SBarry Smith   r =  (int (*)(TS))NRFindRoutine( __TSList, (int)method, (char *)0 );
40*8b1af7b3SBarry Smith   if (!r) {SETERRQ(1,"TSSetType:Unknown method");}
41*8b1af7b3SBarry Smith   if (ts->data) PetscFree(ts->data);
42*8b1af7b3SBarry Smith   return (*r)(ts);
433f3760d9SBarry Smith }
443f3760d9SBarry Smith 
453f3760d9SBarry Smith /* --------------------------------------------------------------------- */
463f3760d9SBarry Smith /*@C
47*8b1af7b3SBarry Smith    TSRegister - Adds the method to the nonlinear solver package, given
48*8b1af7b3SBarry Smith    a function pointer and a nonlinear solver name of the type TSType.
493f3760d9SBarry Smith 
503f3760d9SBarry Smith    Input Parameters:
51*8b1af7b3SBarry Smith .  name - for instance TS_EQ_NLS, TS_EQ_NTR, ...
523f3760d9SBarry Smith .  sname - corfunPonding string for name
533f3760d9SBarry Smith .  create - routine to create method context
543f3760d9SBarry Smith 
55*8b1af7b3SBarry Smith .keywords: TS, nonlinear, register
563f3760d9SBarry Smith 
57*8b1af7b3SBarry Smith .seealso: TSRegisterAll(), TSRegisterDestroy()
583f3760d9SBarry Smith @*/
59*8b1af7b3SBarry Smith int TSRegister(int name, char *sname, int (*create)(TS))
603f3760d9SBarry Smith {
613f3760d9SBarry Smith   int ierr;
62*8b1af7b3SBarry Smith   if (!__TSList) {ierr = NRCreate(&__TSList); CHKERRQ(ierr);}
63*8b1af7b3SBarry Smith   NRRegister( __TSList, name, sname, (int (*)(void*))create );
643f3760d9SBarry Smith   return 0;
653f3760d9SBarry Smith }
663f3760d9SBarry Smith /* --------------------------------------------------------------------- */
673f3760d9SBarry Smith /*@C
68*8b1af7b3SBarry Smith    TSRegisterDestroy - Frees the list of nonlinear solvers that were
69*8b1af7b3SBarry Smith    registered by TSRegister().
703f3760d9SBarry Smith 
71*8b1af7b3SBarry Smith .keywords: TS, nonlinear, register, destroy
723f3760d9SBarry Smith 
73*8b1af7b3SBarry Smith .seealso: TSRegisterAll(), TSRegisterAll()
743f3760d9SBarry Smith @*/
75*8b1af7b3SBarry Smith int TSRegisterDestroy()
763f3760d9SBarry Smith {
77*8b1af7b3SBarry Smith   if (__TSList) {
78*8b1af7b3SBarry Smith     NRDestroy( __TSList );
79*8b1af7b3SBarry Smith     __TSList = 0;
803f3760d9SBarry Smith   }
813f3760d9SBarry Smith   return 0;
823f3760d9SBarry Smith }
833f3760d9SBarry Smith 
843f3760d9SBarry Smith /*@C
85*8b1af7b3SBarry Smith    TSGetType - Gets the TS method type and name (as a string).
863f3760d9SBarry Smith 
873f3760d9SBarry Smith    Input Parameter:
88*8b1af7b3SBarry Smith .  ts - nonlinear solver context
893f3760d9SBarry Smith 
903f3760d9SBarry Smith    Output Parameter:
91*8b1af7b3SBarry Smith .  method - TS method (or use PETSC_NULL)
92*8b1af7b3SBarry Smith .  name - name of TS method (or use PETSC_NULL)
933f3760d9SBarry Smith 
94*8b1af7b3SBarry Smith .keywords: TS, nonlinear, get, method, name
953f3760d9SBarry Smith @*/
96*8b1af7b3SBarry Smith int TSGetType(TS ts, TSType *method,char **name)
973f3760d9SBarry Smith {
983f3760d9SBarry Smith   int ierr;
99*8b1af7b3SBarry Smith   if (!__TSList) {ierr = TSRegisterAll(); CHKERRQ(ierr);}
100*8b1af7b3SBarry Smith   if (method) *method = (TSType) ts->type;
101*8b1af7b3SBarry Smith   if (name)  *name = NRFindName( __TSList, (int) ts->type );
1023f3760d9SBarry Smith   return 0;
1033f3760d9SBarry Smith }
1043f3760d9SBarry Smith 
1053f3760d9SBarry Smith #include <stdio.h>
1063f3760d9SBarry Smith /*
107*8b1af7b3SBarry Smith    TSPrintTypes_Private - Prints the TS methods available from the
1083f3760d9SBarry Smith    options database.
1093f3760d9SBarry Smith 
1103f3760d9SBarry Smith    Input Parameters:
1113f3760d9SBarry Smith .  prefix - prefix (usually "-")
112*8b1af7b3SBarry Smith .  name - the options database name (by default "ts_type")
1133f3760d9SBarry Smith */
114*8b1af7b3SBarry Smith int TSPrintTypes_Private(char* prefix,char *name)
1153f3760d9SBarry Smith {
1163f3760d9SBarry Smith   FuncList *entry;
117*8b1af7b3SBarry Smith   if (!__TSList) {TSRegisterAll();}
118*8b1af7b3SBarry Smith   entry = __TSList->head;
1193f3760d9SBarry Smith   fprintf(stderr," %s%s (one of)",prefix,name);
1203f3760d9SBarry Smith   while (entry) {
1213f3760d9SBarry Smith     fprintf(stderr," %s",entry->name);
1223f3760d9SBarry Smith     entry = entry->next;
1233f3760d9SBarry Smith   }
1243f3760d9SBarry Smith   fprintf(stderr,"\n");
1253f3760d9SBarry Smith   return 0;
1263f3760d9SBarry Smith }
1273f3760d9SBarry Smith 
128*8b1af7b3SBarry Smith 
129*8b1af7b3SBarry Smith /*
130*8b1af7b3SBarry Smith    TSGetTypeFromOptions_Private - Sets the selected method from the
131*8b1af7b3SBarry Smith    options database.
1323f3760d9SBarry Smith 
1333f3760d9SBarry Smith    Input Parameter:
134*8b1af7b3SBarry Smith .  ctx - the TS context
1353f3760d9SBarry Smith 
1363f3760d9SBarry Smith    Output Parameter:
137*8b1af7b3SBarry Smith .  method -  solver method
1383f3760d9SBarry Smith 
139*8b1af7b3SBarry Smith    Returns:
140*8b1af7b3SBarry Smith    Returns 1 if the method is found; 0 otherwise.
1413f3760d9SBarry Smith 
142*8b1af7b3SBarry Smith    Options Database Key:
143*8b1af7b3SBarry Smith $  -ts_type  method
144*8b1af7b3SBarry Smith */
145*8b1af7b3SBarry Smith int TSGetTypeFromOptions_Private(TS ctx,TSType *method,int *flg)
1463f3760d9SBarry Smith {
147*8b1af7b3SBarry Smith   int ierr;
148*8b1af7b3SBarry Smith   char sbuf[50];
149*8b1af7b3SBarry Smith   ierr = OptionsGetString(ctx->prefix,"-ts_type", sbuf, 50, flg); CHKERRQ(ierr);
150*8b1af7b3SBarry Smith   if (*flg) {
151*8b1af7b3SBarry Smith     if (!__TSList) {ierr = TSRegisterAll(); CHKERRQ(ierr);}
152*8b1af7b3SBarry Smith     *method = (TSType)NRFindID( __TSList, sbuf );
153*8b1af7b3SBarry Smith   }
1543f3760d9SBarry Smith   return 0;
1553f3760d9SBarry Smith }
156