Subversion Repositories slepc-dev

Rev

Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
6 dsic.upv.es!jroman 1
 
2
/*
3
    Routines to set ST methods and options.
4
*/
5
 
6
#include "src/st/stimpl.h"      /*I "slepcst.h" I*/
7
#include "petscsys.h"
8
 
9
PetscTruth STRegisterAllCalled = PETSC_FALSE;
10
/*
11
   Contains the list of registered EPS routines
12
*/
13
PetscFList STList = 0;
14
 
15
#undef __FUNCT__  
16
#define __FUNCT__ "STSetType"
17
/*@C
18
   STSetType - Builds ST for a particular spectral transformation.
19
 
20
   Collective on ST
21
 
22
   Input Parameter:
23
+  st   - the spectral transformation context.
24
-  type - a known type
25
 
26
   Options Database Key:
27
.  -st_type <type> - Sets ST type
28
 
29
   Use -help for a list of available methods
30
 
31
   Notes:
32
   See "slepc/include/slepcst.h" for available methods
33
 
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.
38
 
39
   Level: intermediate
40
 
41
.seealso: EPSSetType()
42
 
43
@*/
44
int STSetType(ST st,STType type)
45
{
46
  int ierr,(*r)(ST);
47
  PetscTruth match;
48
 
49
  PetscFunctionBegin;
50
  PetscValidHeaderSpecific(st,ST_COOKIE);
51
  PetscValidCharPointer(type);
52
 
53
  ierr = PetscTypeCompare((PetscObject)st,type,&match);CHKERRQ(ierr);
54
  if (match) PetscFunctionReturn(0);
55
 
56
  if (st->ops->destroy) {ierr =  (*st->ops->destroy)(st);CHKERRQ(ierr);}
57
  ierr = PetscFListDestroy(&st->qlist);CHKERRQ(ierr);
58
  st->data        = 0;
59
  st->setupcalled = 0;
60
  st->sles        = 0;
61
 
62
  /* Get the function pointers for the method requested */
63
  if (!STRegisterAllCalled) {ierr = STRegisterAll(0); CHKERRQ(ierr);}
64
 
65
  /* Determine the STCreateXXX routine for a particular type */
66
  ierr =  PetscFListFind(st->comm, STList, type,(void (**)(void)) &r );CHKERRQ(ierr);
67
  if (!r) SETERRQ1(1,"Unable to find requested ST type %s",type);
68
  if (st->data) {ierr = PetscFree(st->data);CHKERRQ(ierr);}
69
 
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;
80
 
81
  /* Call the STCreateXXX routine for this particular type */
82
  ierr = (*r)(st);CHKERRQ(ierr);
83
 
84
  ierr = PetscObjectChangeTypeName((PetscObject)st,type);CHKERRQ(ierr);
85
  PetscFunctionReturn(0);
86
}
87
 
88
#undef __FUNCT__  
89
#define __FUNCT__ "STRegisterDestroy"
90
/*@C
91
   STRegisterDestroy - Frees the list of spectral transformations that were
92
   registered by STRegisterDynamic().
93
 
94
   Not Collective
95
 
96
   Level: advanced
97
 
98
.seealso: STRegisterAll(), STRegisterAll()
99
 
100
@*/
101
int STRegisterDestroy(void)
102
{
103
  int ierr;
104
 
105
  PetscFunctionBegin;
106
  if (STList) {
107
    ierr = PetscFListDestroy(&STList);CHKERRQ(ierr);
108
    STList = 0;
109
  }
110
  STRegisterAllCalled = PETSC_FALSE;
111
  PetscFunctionReturn(0);
112
}
113
 
114
#undef __FUNCT__  
115
#define __FUNCT__ "STGetType"
116
/*@C
117
   STGetType - Gets the ST method type and name (as a string) from the ST
118
   context.
119
 
120
   Not Collective
121
 
122
   Input Parameter:
123
.  st - the spectral transformation context
124
 
125
   Output Parameter:
126
.  name - name of the spectral transformation
127
 
128
   Level: intermediate
129
 
130
.seealso: STSetType()
131
 
132
@*/
133
int STGetType(ST st,STType *meth)
134
{
135
  PetscFunctionBegin;
136
  *meth = (STType) st->type_name;
137
  PetscFunctionReturn(0);
138
}
139
 
140
#undef __FUNCT__  
141
#define __FUNCT__ "STSetFromOptions"
142
/*@
143
   STSetFromOptions - Sets ST options from the options database.
144
   This routine must be called before STSetUp() if the user is to be
145
   allowed to set the type of transformation.
146
 
147
   Collective on ST
148
 
149
   Input Parameter:
150
.  st - the spectral transformation context
151
 
152
   Level: beginner
153
 
154
.seealso:
155
 
156
@*/
157
int STSetFromOptions(ST st)
158
{
159
  int        ierr;
160
  char       type[256];
161
  PetscTruth flg;
162
 
163
  PetscFunctionBegin;
164
  PetscValidHeaderSpecific(st,ST_COOKIE);
165
 
166
  if (!STRegisterAllCalled) {ierr = STRegisterAll(PETSC_NULL);CHKERRQ(ierr);}
167
  ierr = PetscOptionsBegin(st->comm,st->prefix,"Spectral Transformation (ST) Options","ST");CHKERRQ(ierr);
168
    ierr = PetscOptionsList("-st_type","Spectral Transformation type","STSetType",STList,(char*)(st->type_name?st->type_name:STNONE),type,256,&flg);CHKERRQ(ierr);
169
    if (flg) {
170
      ierr = STSetType(st,type);CHKERRQ(ierr);
171
    }
172
    /*
173
      Set the type if it was never set.
174
    */
175
    if (!st->type_name) {
176
      ierr = STSetType(st,STNONE);CHKERRQ(ierr);
177
    }
178
 
179
    if (st->numberofshifts>0) {
180
      ierr = PetscOptionsScalar("-st_shift","Value of the shift","STSetShift",st->sigma,&st->sigma,PETSC_NULL); CHKERRQ(ierr);
181
    }
182
 
183
    if (st->ops->setfromoptions) {
184
      ierr = (*st->ops->setfromoptions)(st);CHKERRQ(ierr);
185
    }
186
    if (st->sles) {
187
      ierr = PetscOptionsHead("Associated Linear Solver options ------------");CHKERRQ(ierr);
188
      ierr = SLESSetFromOptions(st->sles);CHKERRQ(ierr);
189
      ierr = PetscOptionsTail();CHKERRQ(ierr);
190
    }
191
 
192
  ierr = PetscOptionsEnd();CHKERRQ(ierr);
193
  PetscFunctionReturn(0);
194
}
195