Actual source code: stset.c
2: /*
3: Routines to set ST methods and options.
4: */
6: #include src/st/stimpl.h
7: #include "petscsys.h"
9: PetscTruth STRegisterAllCalled = PETSC_FALSE;
10: /*
11: Contains the list of registered EPS routines
12: */
13: PetscFList STList = 0;
17: /*@C
18: STSetType - Builds ST for a particular spectral transformation.
20: Collective on ST
22: Input Parameter:
23: + st - the spectral transformation context.
24: - type - a known type
26: Options Database Key:
27: . -st_type <type> - Sets ST type
29: Use -help for a list of available transformations
31: Notes:
32: See "slepc/include/slepcst.h" for available transformations
34: Normally, it is best to use the EPSSetFromOptions() command and
35: then set the ST type from the options database rather than by using
36: this routine. Using the options database provides the user with
37: maximum flexibility in evaluating the many different transformations.
39: Level: intermediate
41: .seealso: EPSSetType()
43: @*/
44: int STSetType(ST st,STType type)
45: {
46: int ierr,(*r)(ST);
47: PetscTruth match;
53: PetscTypeCompare((PetscObject)st,type,&match);
54: if (match) return(0);
56: if (st->ops->destroy) { (*st->ops->destroy)(st);}
57: PetscFListDestroy(&st->qlist);
58: st->data = 0;
59: st->setupcalled = 0;
60: st->ksp = 0;
62: /* Get the function pointers for the method requested */
63: if (!STRegisterAllCalled) {STRegisterAll(0); }
65: /* Determine the STCreateXXX routine for a particular type */
66: PetscFListFind(st->comm, STList, type,(void (**)(void)) &r );
67: if (!r) SETERRQ1(1,"Unable to find requested ST type %s",type);
68: if (st->data) {PetscFree(st->data);}
70: st->ops->destroy = (int (*)(ST )) 0;
71: st->ops->view = (int (*)(ST,PetscViewer) ) 0;
72: st->ops->apply = (int (*)(ST,Vec,Vec) ) 0;
73: st->ops->applyB = STDefaultApplyB;
74: st->ops->applynoB = (int (*)(ST,Vec,Vec) ) 0;
75: st->ops->setup = (int (*)(ST) ) 0;
76: st->ops->setfromoptions = (int (*)(ST) ) 0;
77: st->ops->presolve = (int (*)(ST) ) 0;
78: st->ops->postsolve = (int (*)(ST) ) 0;
79: st->ops->backtr = (int (*)(ST,PetscScalar*,PetscScalar*) ) 0;
81: /* Call the STCreateXXX routine for this particular type */
82: (*r)(st);
84: PetscObjectChangeTypeName((PetscObject)st,type);
85: return(0);
86: }
90: /*@C
91: STRegisterDestroy - Frees the list of spectral transformations that were
92: registered by STRegisterDynamic().
94: Not Collective
96: Level: advanced
98: .seealso: STRegisterAll(), STRegisterAll()
100: @*/
101: int STRegisterDestroy(void)
102: {
106: if (STList) {
107: PetscFListDestroy(&STList);
108: STList = 0;
109: }
110: STRegisterAllCalled = PETSC_FALSE;
111: return(0);
112: }
116: /*@C
117: STGetType - Gets the ST type name (as a string) from the ST context.
119: Not Collective
121: Input Parameter:
122: . st - the spectral transformation context
124: Output Parameter:
125: . name - name of the spectral transformation
127: Level: intermediate
129: .seealso: STSetType()
131: @*/
132: int STGetType(ST st,STType *meth)
133: {
135: *meth = (STType) st->type_name;
136: return(0);
137: }
141: /*@
142: STSetFromOptions - Sets ST options from the options database.
143: This routine must be called before STSetUp() if the user is to be
144: allowed to set the type of transformation.
146: Collective on ST
148: Input Parameter:
149: . st - the spectral transformation context
151: Level: beginner
153: .seealso:
155: @*/
156: int STSetFromOptions(ST st)
157: {
158: int ierr;
159: char type[256];
160: PetscTruth flg;
165: if (!STRegisterAllCalled) {STRegisterAll(PETSC_NULL);}
166: PetscOptionsBegin(st->comm,st->prefix,"Spectral Transformation (ST) Options","ST");
167: PetscOptionsList("-st_type","Spectral Transformation type","STSetType",STList,(char*)(st->type_name?st->type_name:STSHIFT),type,256,&flg);
168: if (flg) {
169: STSetType(st,type);
170: }
171: /*
172: Set the type if it was never set.
173: */
174: if (!st->type_name) {
175: STSetType(st,STSHIFT);
176: }
178: if (st->numberofshifts>0) {
179: PetscOptionsScalar("-st_shift","Value of the shift","STSetShift",st->sigma,&st->sigma,PETSC_NULL);
180: }
182: if (st->ops->setfromoptions) {
183: (*st->ops->setfromoptions)(st);
184: }
186: PetscOptionsEnd();
187: if (st->ksp) { KSPSetFromOptions(st->ksp); }
189: return(0);
190: }