xref: /petsc/src/ts/interface/tsreg.c (revision b5f69acf6552de892c35e8bfc4ce7b6348c5c775)
18b1af7b3SBarry Smith 
23f3760d9SBarry Smith #ifndef lint
3*b5f69acfSSatish Balay static char vcid[] = "$Id: tsreg.c,v 1.3 1996/03/07 20:28:24 bsmith Exp balay $";
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
23ca90a507SBarry Smith $   TS_BEULER
24ca90a507SBarry 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:
113*b5f69acfSSatish Balay .  comm   - The communicator ( usually MPI_COMM_WORLD)
1143f3760d9SBarry Smith .  prefix - prefix (usually "-")
1158b1af7b3SBarry Smith .  name   - the options database name (by default "ts_type")
1163f3760d9SBarry Smith */
117*b5f69acfSSatish Balay int TSPrintTypes_Private(MPI_Comm comm,char* prefix,char *name)
1183f3760d9SBarry Smith {
1193f3760d9SBarry Smith   FuncList *entry;
1208b1af7b3SBarry Smith   if (!__TSList) {TSRegisterAll();}
1218b1af7b3SBarry Smith   entry = __TSList->head;
122*b5f69acfSSatish Balay   MPIU_printf(comm," %s%s (one of)",prefix,name);
1233f3760d9SBarry Smith   while (entry) {
124*b5f69acfSSatish Balay     MPIU_printf(comm," %s",entry->name);
1253f3760d9SBarry Smith     entry = entry->next;
1263f3760d9SBarry Smith   }
127*b5f69acfSSatish Balay   MPIU_printf(comm,"\n");
1283f3760d9SBarry Smith   return 0;
1293f3760d9SBarry Smith }
1303f3760d9SBarry Smith 
1318b1af7b3SBarry Smith 
1328b1af7b3SBarry Smith /*
1338b1af7b3SBarry Smith    TSGetTypeFromOptions_Private - Sets the selected method from the
1348b1af7b3SBarry Smith    options database.
1353f3760d9SBarry Smith 
1363f3760d9SBarry Smith    Input Parameter:
1378b1af7b3SBarry Smith .  ctx - the TS context
1383f3760d9SBarry Smith 
1393f3760d9SBarry Smith    Output Parameter:
1408b1af7b3SBarry Smith .  method -  solver method
1413f3760d9SBarry Smith 
1428b1af7b3SBarry Smith    Returns:
1438b1af7b3SBarry Smith    Returns 1 if the method is found; 0 otherwise.
1443f3760d9SBarry Smith 
1458b1af7b3SBarry Smith    Options Database Key:
1468b1af7b3SBarry Smith $  -ts_type  method
1478b1af7b3SBarry Smith */
1488b1af7b3SBarry Smith int TSGetTypeFromOptions_Private(TS ctx,TSType *method,int *flg)
1493f3760d9SBarry Smith {
1508b1af7b3SBarry Smith   int ierr;
1518b1af7b3SBarry Smith   char sbuf[50];
1528b1af7b3SBarry Smith   ierr = OptionsGetString(ctx->prefix,"-ts_type", sbuf, 50, flg); CHKERRQ(ierr);
1538b1af7b3SBarry Smith   if (*flg) {
1548b1af7b3SBarry Smith     if (!__TSList) {ierr = TSRegisterAll(); CHKERRQ(ierr);}
1558b1af7b3SBarry Smith     *method = (TSType)NRFindID( __TSList, sbuf );
1568b1af7b3SBarry Smith   }
1573f3760d9SBarry Smith   return 0;
1583f3760d9SBarry Smith }
159