xref: /petsc/src/ts/interface/tsreg.c (revision ca90a50798d8c9dc72aff46126a49670b03a2421)
18b1af7b3SBarry Smith 
23f3760d9SBarry Smith #ifndef lint
3*ca90a507SBarry Smith static char vcid[] = "$Id: tsreg.c,v 1.2 1996/01/31 03:59:25 bsmith Exp bsmith $";
43f3760d9SBarry Smith #endif
53f3760d9SBarry Smith 
68b1af7b3SBarry 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 
118b1af7b3SBarry Smith static NRList *__TSList = 0;
123f3760d9SBarry Smith 
133f3760d9SBarry Smith /*@
148b1af7b3SBarry Smith    TSSetType - Sets the method for the nonlinear solver.
153f3760d9SBarry Smith 
163f3760d9SBarry Smith    Input Parameters:
178b1af7b3SBarry Smith .  ts - the TS context
183f3760d9SBarry Smith .  method - a known method
193f3760d9SBarry Smith 
203f3760d9SBarry Smith    Notes:
218b1af7b3SBarry Smith    See "petsc/include/ts.h" for available methods (for instance)
228b1af7b3SBarry Smith $   TS_EULER
23*ca90a507SBarry Smith $   TS_BEULER
24*ca90a507SBarry Smith $   TS_PSEUDO
253f3760d9SBarry Smith 
263f3760d9SBarry Smith   Options Database Command:
278b1af7b3SBarry Smith $ -ts_type  <method>
283f3760d9SBarry Smith $    Use -help for a list of available methods
298b1af7b3SBarry Smith $    (for instance, euler)
303f3760d9SBarry Smith 
318b1af7b3SBarry Smith .keysords: TS, set, method
323f3760d9SBarry Smith @*/
338b1af7b3SBarry Smith int TSSetType(TS ts,TSType method)
343f3760d9SBarry Smith {
358b1af7b3SBarry Smith   int (*r)(TS);
368b1af7b3SBarry Smith 
378b1af7b3SBarry Smith   PETSCVALIDHEADERSPECIFIC(ts,TS_COOKIE);
388b1af7b3SBarry Smith   /* Get the function pointers for the method requested */
398b1af7b3SBarry Smith   if (!__TSList) {TSRegisterAll();}
408b1af7b3SBarry Smith   if (!__TSList) {SETERRQ(1,"TSSetType:Could not get methods");}
418b1af7b3SBarry Smith   r =  (int (*)(TS))NRFindRoutine( __TSList, (int)method, (char *)0 );
428b1af7b3SBarry Smith   if (!r) {SETERRQ(1,"TSSetType:Unknown method");}
438b1af7b3SBarry Smith   if (ts->data) PetscFree(ts->data);
448b1af7b3SBarry Smith   return (*r)(ts);
453f3760d9SBarry Smith }
463f3760d9SBarry Smith 
473f3760d9SBarry Smith /* --------------------------------------------------------------------- */
483f3760d9SBarry Smith /*@C
498b1af7b3SBarry Smith    TSRegister - Adds the method to the nonlinear solver package, given
508b1af7b3SBarry Smith    a function pointer and a nonlinear solver name of the type TSType.
513f3760d9SBarry Smith 
523f3760d9SBarry Smith    Input Parameters:
538b1af7b3SBarry Smith .  name - for instance TS_EQ_NLS, TS_EQ_NTR, ...
543f3760d9SBarry Smith .  sname - corfunPonding string for name
553f3760d9SBarry Smith .  create - routine to create method context
563f3760d9SBarry Smith 
578b1af7b3SBarry Smith .keywords: TS, nonlinear, register
583f3760d9SBarry Smith 
598b1af7b3SBarry Smith .seealso: TSRegisterAll(), TSRegisterDestroy()
603f3760d9SBarry Smith @*/
618b1af7b3SBarry Smith int TSRegister(int name, char *sname, int (*create)(TS))
623f3760d9SBarry Smith {
633f3760d9SBarry Smith   int ierr;
648b1af7b3SBarry Smith   if (!__TSList) {ierr = NRCreate(&__TSList); CHKERRQ(ierr);}
658b1af7b3SBarry Smith   NRRegister( __TSList, name, sname, (int (*)(void*))create );
663f3760d9SBarry Smith   return 0;
673f3760d9SBarry Smith }
683f3760d9SBarry Smith /* --------------------------------------------------------------------- */
693f3760d9SBarry Smith /*@C
708b1af7b3SBarry Smith    TSRegisterDestroy - Frees the list of nonlinear solvers that were
718b1af7b3SBarry Smith    registered by TSRegister().
723f3760d9SBarry Smith 
738b1af7b3SBarry Smith .keywords: TS, nonlinear, register, destroy
743f3760d9SBarry Smith 
758b1af7b3SBarry Smith .seealso: TSRegisterAll(), TSRegisterAll()
763f3760d9SBarry Smith @*/
778b1af7b3SBarry Smith int TSRegisterDestroy()
783f3760d9SBarry Smith {
798b1af7b3SBarry Smith   if (__TSList) {
808b1af7b3SBarry Smith     NRDestroy( __TSList );
818b1af7b3SBarry Smith     __TSList = 0;
823f3760d9SBarry Smith   }
833f3760d9SBarry Smith   return 0;
843f3760d9SBarry Smith }
853f3760d9SBarry Smith 
863f3760d9SBarry Smith /*@C
878b1af7b3SBarry Smith    TSGetType - Gets the TS method type and name (as a string).
883f3760d9SBarry Smith 
893f3760d9SBarry Smith    Input Parameter:
908b1af7b3SBarry Smith .  ts - nonlinear solver context
913f3760d9SBarry Smith 
923f3760d9SBarry Smith    Output Parameter:
938b1af7b3SBarry Smith .  method - TS method (or use PETSC_NULL)
948b1af7b3SBarry Smith .  name - name of TS method (or use PETSC_NULL)
953f3760d9SBarry Smith 
968b1af7b3SBarry Smith .keywords: TS, nonlinear, get, method, name
973f3760d9SBarry Smith @*/
988b1af7b3SBarry Smith int TSGetType(TS ts, TSType *method,char **name)
993f3760d9SBarry Smith {
1003f3760d9SBarry Smith   int ierr;
1018b1af7b3SBarry Smith   if (!__TSList) {ierr = TSRegisterAll(); CHKERRQ(ierr);}
1028b1af7b3SBarry Smith   if (method) *method = (TSType) ts->type;
1038b1af7b3SBarry Smith   if (name)  *name = NRFindName( __TSList, (int) ts->type );
1043f3760d9SBarry Smith   return 0;
1053f3760d9SBarry Smith }
1063f3760d9SBarry Smith 
1073f3760d9SBarry Smith #include <stdio.h>
1083f3760d9SBarry Smith /*
1098b1af7b3SBarry Smith    TSPrintTypes_Private - Prints the TS methods available from the
1103f3760d9SBarry Smith    options database.
1113f3760d9SBarry Smith 
1123f3760d9SBarry Smith    Input Parameters:
1133f3760d9SBarry Smith .  prefix - prefix (usually "-")
1148b1af7b3SBarry Smith .  name - the options database name (by default "ts_type")
1153f3760d9SBarry Smith */
1168b1af7b3SBarry Smith int TSPrintTypes_Private(char* prefix,char *name)
1173f3760d9SBarry Smith {
1183f3760d9SBarry Smith   FuncList *entry;
1198b1af7b3SBarry Smith   if (!__TSList) {TSRegisterAll();}
1208b1af7b3SBarry Smith   entry = __TSList->head;
1213f3760d9SBarry Smith   fprintf(stderr," %s%s (one of)",prefix,name);
1223f3760d9SBarry Smith   while (entry) {
1233f3760d9SBarry Smith     fprintf(stderr," %s",entry->name);
1243f3760d9SBarry Smith     entry = entry->next;
1253f3760d9SBarry Smith   }
1263f3760d9SBarry Smith   fprintf(stderr,"\n");
1273f3760d9SBarry Smith   return 0;
1283f3760d9SBarry Smith }
1293f3760d9SBarry Smith 
1308b1af7b3SBarry Smith 
1318b1af7b3SBarry Smith /*
1328b1af7b3SBarry Smith    TSGetTypeFromOptions_Private - Sets the selected method from the
1338b1af7b3SBarry Smith    options database.
1343f3760d9SBarry Smith 
1353f3760d9SBarry Smith    Input Parameter:
1368b1af7b3SBarry Smith .  ctx - the TS context
1373f3760d9SBarry Smith 
1383f3760d9SBarry Smith    Output Parameter:
1398b1af7b3SBarry Smith .  method -  solver method
1403f3760d9SBarry Smith 
1418b1af7b3SBarry Smith    Returns:
1428b1af7b3SBarry Smith    Returns 1 if the method is found; 0 otherwise.
1433f3760d9SBarry Smith 
1448b1af7b3SBarry Smith    Options Database Key:
1458b1af7b3SBarry Smith $  -ts_type  method
1468b1af7b3SBarry Smith */
1478b1af7b3SBarry Smith int TSGetTypeFromOptions_Private(TS ctx,TSType *method,int *flg)
1483f3760d9SBarry Smith {
1498b1af7b3SBarry Smith   int ierr;
1508b1af7b3SBarry Smith   char sbuf[50];
1518b1af7b3SBarry Smith   ierr = OptionsGetString(ctx->prefix,"-ts_type", sbuf, 50, flg); CHKERRQ(ierr);
1528b1af7b3SBarry Smith   if (*flg) {
1538b1af7b3SBarry Smith     if (!__TSList) {ierr = TSRegisterAll(); CHKERRQ(ierr);}
1548b1af7b3SBarry Smith     *method = (TSType)NRFindID( __TSList, sbuf );
1558b1af7b3SBarry Smith   }
1563f3760d9SBarry Smith   return 0;
1573f3760d9SBarry Smith }
158