Subversion Repositories slepc-dev

Rev

Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1376 slepc 1
/*
2
   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1672 slepc 3
   SLEPc - Scalable Library for Eigenvalue Problem Computations
2575 eromero 4
   Copyright (c) 2002-2011, Universitat Politecnica de Valencia, Spain
986 slepc 5
 
1672 slepc 6
   This file is part of SLEPc.
7
 
8
   SLEPc is free software: you can redistribute it and/or modify it under  the
9
   terms of version 3 of the GNU Lesser General Public License as published by
10
   the Free Software Foundation.
11
 
12
   SLEPc  is  distributed in the hope that it will be useful, but WITHOUT  ANY
13
   WARRANTY;  without even the implied warranty of MERCHANTABILITY or  FITNESS
14
   FOR  A  PARTICULAR PURPOSE. See the GNU Lesser General Public  License  for
15
   more details.
16
 
17
   You  should have received a copy of the GNU Lesser General  Public  License
18
   along with SLEPc. If not, see <http://www.gnu.org/licenses/>.
1376 slepc 19
   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
20
*/
21
 
2283 jroman 22
#include <private/fortranimpl.h>
2654 jroman 23
#include <private/epsimpl.h>
986 slepc 24
 
2320 jroman 25
#if defined(PETSC_HAVE_FORTRAN_CAPS)
2310 jroman 26
#define epsdestroy_                 EPSDESTROY
986 slepc 27
#define epsview_                    EPSVIEW
28
#define epssetoptionsprefix_        EPSSETOPTIONSPREFIX
29
#define epsappendoptionsprefix_     EPSAPPENDOPTIONSPREFIX
30
#define epsgetoptionsprefix_        EPSGETOPTIONSPREFIX
31
#define epscreate_                  EPSCREATE
32
#define epssettype_                 EPSSETTYPE          
33
#define epsgettype_                 EPSGETTYPE
2054 eromero 34
#define epsmonitorall_              EPSMONITORALL
1331 slepc 35
#define epsmonitorlg_               EPSMONITORLG
2054 eromero 36
#define epsmonitorlgall_            EPSMONITORLGALL
1331 slepc 37
#define epsmonitorset_              EPSMONITORSET
1781 antodo 38
#define epsmonitorconverged_        EPSMONITORCONVERGED
39
#define epsmonitorfirst_            EPSMONITORFIRST
1021 slepc 40
#define epsgetst_                   EPSGETST
1345 slepc 41
#define epsgetip_                   EPSGETIP
986 slepc 42
#define epsgetwhicheigenpairs_      EPSGETWHICHEIGENPAIRS
43
#define epsgetproblemtype_          EPSGETPROBLEMTYPE
1560 slepc 44
#define epsgetextraction_           EPSGETEXTRACTION
1799 jroman 45
#define epsgetbalance_              EPSGETBALANCE
1021 slepc 46
#define epsgetconvergedreason_      EPSGETCONVERGEDREASON
986 slepc 47
#define epspowergetshifttype_       EPSPOWERGETSHIFTTYPE
1021 slepc 48
#define epslanczosgetreorthog_      EPSLANCZOSGETREORTHOG
2083 eromero 49
#define epsabsoluteconverged_       EPSABSOLUTECONVERGED
50
#define epseigrelativeconverged_    EPSEIGRELATIVECONVERGED
51
#define epsnormrelativeconverged_   EPSNORMRELATIVECONVERGED
52
#define epssetconvergencetestfunction_ EPSSETCONVERGENCETESTFUNCTION
2084 eromero 53
#define epsseteigenvaluecomparison_ EPSSETEIGENVALUECOMPARISON
986 slepc 54
#elif !defined(PETSC_HAVE_FORTRAN_UNDERSCORE)
2310 jroman 55
#define epsdestroy_                 epsdestroy
986 slepc 56
#define epsview_                    epsview
57
#define epssetoptionsprefix_        epssetoptionsprefix
58
#define epsappendoptionsprefix_     epsappendoptionsprefix
59
#define epsgetoptionsprefix_        epsgetoptionsprefix
60
#define epscreate_                  epscreate
61
#define epssettype_                 epssettype          
62
#define epsgettype_                 epsgettype
2041 eromero 63
#define epsmonitorall_              epsmonitorall
1331 slepc 64
#define epsmonitorlg_               epsmonitorlg
2041 eromero 65
#define epsmonitorlgall_            epsmonitorlgall
1331 slepc 66
#define epsmonitorset_              epsmonitorset
1781 antodo 67
#define epsmonitorconverged_        epsmonitorconverged
68
#define epsmonitorfirst_            epsmonitorfirst
1021 slepc 69
#define epsgetst_                   epsgetst
1345 slepc 70
#define epsgetip_                   epsgetip
986 slepc 71
#define epsgetwhicheigenpairs_      epsgetwhicheigenpairs
72
#define epsgetproblemtype_          epsgetproblemtype
1560 slepc 73
#define epsgetextraction_           epsgetextraction
1799 jroman 74
#define epsgetbalance_              epsgetbalance
1021 slepc 75
#define epsgetconvergedreason_      epsgetconvergedreason
986 slepc 76
#define epspowergetshifttype_       epspowergetshifttype
77
#define epslanczosgetreorthog_      epslanczosgetreorthog
2083 eromero 78
#define epsabsoluteconverged_       epsabsoluteconverged
79
#define epseigrelativeconverged_    epseigrelativeconverged
80
#define epsnormrelativeconverged_   epsnormrelativeconverged
81
#define epssetconvergencetestfunction_ epssetconvergencetestfunction
2084 eromero 82
#define epsseteigenvaluecomparison_ epsseteigenvaluecomparison
986 slepc 83
#endif
84
 
85
EXTERN_C_BEGIN
1287 slepc 86
 
1027 slepc 87
/*
88
   These are not usually called from Fortran but allow Fortran users
89
   to transparently set these monitors from .F code, hence no STDCALL
90
*/
2041 eromero 91
void epsmonitorall_(EPS *eps,PetscInt *it,PetscInt *nconv,PetscScalar *eigr,PetscScalar *eigi,PetscReal *errest,PetscInt *nest,void *ctx,PetscErrorCode *ierr)
1027 slepc 92
{
2041 eromero 93
  *ierr = EPSMonitorAll(*eps,*it,*nconv,eigr,eigi,errest,*nest,ctx);
1027 slepc 94
}
1287 slepc 95
 
1514 slepc 96
void epsmonitorlg_(EPS *eps,PetscInt *it,PetscInt *nconv,PetscScalar *eigr,PetscScalar *eigi,PetscReal *errest,PetscInt *nest,void *ctx,PetscErrorCode *ierr)
1287 slepc 97
{
1331 slepc 98
  *ierr = EPSMonitorLG(*eps,*it,*nconv,eigr,eigi,errest,*nest,ctx);
1287 slepc 99
}
1781 antodo 100
 
2041 eromero 101
void epsmonitorlgall_(EPS *eps,PetscInt *it,PetscInt *nconv,PetscScalar *eigr,PetscScalar *eigi,PetscReal *errest,PetscInt *nest,void *ctx,PetscErrorCode *ierr)
102
{
103
  *ierr = EPSMonitorLGAll(*eps,*it,*nconv,eigr,eigi,errest,*nest,ctx);
104
}
105
 
1781 antodo 106
void epsmonitorconverged_(EPS *eps,PetscInt *it,PetscInt *nconv,PetscScalar *eigr,PetscScalar *eigi,PetscReal *errest,PetscInt *nest,void *ctx,PetscErrorCode *ierr)
107
{
108
  *ierr = EPSMonitorConverged(*eps,*it,*nconv,eigr,eigi,errest,*nest,ctx);
109
}
110
 
111
void epsmonitorfirst_(EPS *eps,PetscInt *it,PetscInt *nconv,PetscScalar *eigr,PetscScalar *eigi,PetscReal *errest,PetscInt *nest,void *ctx,PetscErrorCode *ierr)
112
{
113
  *ierr = EPSMonitorFirst(*eps,*it,*nconv,eigr,eigi,errest,*nest,ctx);
114
}
115
 
1027 slepc 116
EXTERN_C_END
117
 
118
/* These are not extern C because they are passed into non-extern C user level functions */
1514 slepc 119
static PetscErrorCode ourmonitor(EPS eps,PetscInt i,PetscInt nc,PetscScalar *er,PetscScalar *ei,PetscReal *d,PetscInt l,void* ctx)
1027 slepc 120
{
1287 slepc 121
  PetscErrorCode ierr = 0;
1781 antodo 122
  void           *mctx = (void*) ((PetscObject)eps)->fortran_func_pointers[1];
123
  (*(void (PETSC_STDCALL *)(EPS*,PetscInt*,PetscInt*,PetscScalar*,PetscScalar*,PetscReal*,PetscInt*,void*,PetscErrorCode*))
124
    (((PetscObject)eps)->fortran_func_pointers[0]))(&eps,&i,&nc,er,ei,d,&l,mctx,&ierr);CHKERRQ(ierr);
1027 slepc 125
  return 0;
126
}
986 slepc 127
 
2351 jroman 128
static PetscErrorCode ourdestroy(void** ctx)
1287 slepc 129
{
130
  PetscErrorCode ierr = 0;
2351 jroman 131
  EPS            eps = *(EPS*)ctx;
1781 antodo 132
  void           *mctx = (void*) ((PetscObject)eps)->fortran_func_pointers[1];
133
  (*(void (PETSC_STDCALL *)(void*,PetscErrorCode*))(((PetscObject)eps)->fortran_func_pointers[2]))(mctx,&ierr);CHKERRQ(ierr);
1287 slepc 134
  return 0;
135
}
136
 
1027 slepc 137
EXTERN_C_BEGIN
138
 
2310 jroman 139
void PETSC_STDCALL epsdestroy_(EPS *eps, PetscErrorCode *ierr)
140
{
141
  *ierr = EPSDestroy(eps);
142
}
143
 
986 slepc 144
void PETSC_STDCALL epsview_(EPS *eps,PetscViewer *viewer, PetscErrorCode *ierr)
145
{
146
  PetscViewer v;
147
  PetscPatchDefaultViewers_Fortran(viewer,v);
148
  *ierr = EPSView(*eps,v);
149
}
150
 
151
void PETSC_STDCALL epssettype_(EPS *eps,CHAR type PETSC_MIXED_LEN(len),PetscErrorCode *ierr PETSC_END_LEN(len))
152
{
153
  char *t;
154
 
155
  FIXCHAR(type,len,t);
156
  *ierr = EPSSetType(*eps,t);
157
  FREECHAR(type,t);
158
}
159
 
160
void PETSC_STDCALL epsgettype_(EPS *eps,CHAR name PETSC_MIXED_LEN(len),PetscErrorCode *ierr PETSC_END_LEN(len))
161
{
1507 slepc 162
  const EPSType tname;
986 slepc 163
 
164
  *ierr = EPSGetType(*eps,&tname);if (*ierr) return;
165
  *ierr = PetscStrncpy(name,tname,len);
1421 slepc 166
  FIXRETURNCHAR(PETSC_TRUE,name,len);
986 slepc 167
}
168
 
1027 slepc 169
void PETSC_STDCALL epssetoptionsprefix_(EPS *eps,CHAR prefix PETSC_MIXED_LEN(len),PetscErrorCode *ierr PETSC_END_LEN(len))
986 slepc 170
{
171
  char *t;
172
 
173
  FIXCHAR(prefix,len,t);
174
  *ierr = EPSSetOptionsPrefix(*eps,t);
175
  FREECHAR(prefix,t);
176
}
177
 
1027 slepc 178
void PETSC_STDCALL epsappendoptionsprefix_(EPS *eps,CHAR prefix PETSC_MIXED_LEN(len),PetscErrorCode *ierr PETSC_END_LEN(len))
986 slepc 179
{
180
  char *t;
181
 
182
  FIXCHAR(prefix,len,t);
183
  *ierr = EPSAppendOptionsPrefix(*eps,t);
184
  FREECHAR(prefix,t);
185
}
186
 
1334 slepc 187
void PETSC_STDCALL epscreate_(MPI_Fint *comm,EPS *eps,PetscErrorCode *ierr)
188
{
189
  *ierr = EPSCreate(MPI_Comm_f2c(*(comm)),eps);
986 slepc 190
}
191
 
1514 slepc 192
void PETSC_STDCALL epsmonitorset_(EPS *eps,void (PETSC_STDCALL *monitor)(EPS*,PetscInt*,PetscInt*,PetscScalar*,PetscScalar*,PetscReal*,PetscInt*,void*,PetscErrorCode*),
1287 slepc 193
                                  void *mctx,void (PETSC_STDCALL *monitordestroy)(void *,PetscErrorCode *),PetscErrorCode *ierr)
986 slepc 194
{
2670 jroman 195
  SlepcConvMonitor ctx;
1781 antodo 196
  CHKFORTRANNULLFUNCTION(monitordestroy);
197
  PetscObjectAllocateFortranPointers(*eps,3);
2041 eromero 198
  if ((PetscVoidFunction)monitor == (PetscVoidFunction)epsmonitorall_) {
199
    *ierr = EPSMonitorSet(*eps,EPSMonitorAll,0,0);
1781 antodo 200
  } else if ((PetscVoidFunction)monitor == (PetscVoidFunction)epsmonitorlg_) {
1331 slepc 201
    *ierr = EPSMonitorSet(*eps,EPSMonitorLG,0,0);
2041 eromero 202
  } else if ((PetscVoidFunction)monitor == (PetscVoidFunction)epsmonitorlgall_) {
203
    *ierr = EPSMonitorSet(*eps,EPSMonitorLGAll,0,0);
1781 antodo 204
  } else if ((PetscVoidFunction)monitor == (PetscVoidFunction)epsmonitorconverged_) {
2670 jroman 205
    if (!FORTRANNULLOBJECT(mctx)) { PetscError(((PetscObject)*eps)->comm,__LINE__,"epsmonitorset_",__FILE__,__SDIR__,PETSC_ERR_ARG_WRONG,PETSC_ERROR_INITIAL,"Must provide PETSC_NULL_OBJECT as a context in the Fortran interface to EPSMonitorSet"); *ierr = 1; return; }
206
    *ierr = PetscNew(struct _n_SlepcConvMonitor,&ctx);
207
    if (*ierr) return;
208
    ctx->viewer = PETSC_NULL;
209
    *ierr = EPSMonitorSet(*eps,EPSMonitorConverged,ctx,(PetscErrorCode (*)(void**))SlepcConvMonitorDestroy);
1781 antodo 210
  } else if ((PetscVoidFunction)monitor == (PetscVoidFunction)epsmonitorfirst_) {
211
    *ierr = EPSMonitorSet(*eps,EPSMonitorFirst,0,0);
986 slepc 212
  } else {
1781 antodo 213
    ((PetscObject)*eps)->fortran_func_pointers[0] = (PetscVoidFunction)monitor;
214
    ((PetscObject)*eps)->fortran_func_pointers[1] = (PetscVoidFunction)mctx;
2670 jroman 215
    if (!monitordestroy) {
1781 antodo 216
      *ierr = EPSMonitorSet(*eps,ourmonitor,*eps,0);
986 slepc 217
    } else {
1781 antodo 218
      ((PetscObject)*eps)->fortran_func_pointers[2] = (PetscVoidFunction)monitordestroy;
219
      *ierr = EPSMonitorSet(*eps,ourmonitor,*eps,ourdestroy);
986 slepc 220
    }
221
  }
222
}
223
 
224
void PETSC_STDCALL epsgetoptionsprefix_(EPS *eps,CHAR prefix PETSC_MIXED_LEN(len),PetscErrorCode *ierr PETSC_END_LEN(len))
225
{
226
  const char *tname;
227
 
1847 antodo 228
  *ierr = EPSGetOptionsPrefix(*eps,&tname); if (*ierr) return;
229
  *ierr = PetscStrncpy(prefix,tname,len);
986 slepc 230
}
231
 
1509 slepc 232
void PETSC_STDCALL epsgetst_(EPS *eps,ST *st,PetscErrorCode *ierr)
986 slepc 233
{
234
  *ierr = EPSGetST(*eps,st);
235
}
236
 
1509 slepc 237
void PETSC_STDCALL epsgetip_(EPS *eps,IP *ip,PetscErrorCode *ierr)
1345 slepc 238
{
239
  *ierr = EPSGetIP(*eps,ip);
240
}
241
 
1509 slepc 242
void PETSC_STDCALL epsgetwhicheigenpairs_(EPS *eps,EPSWhich *which,PetscErrorCode *ierr)
986 slepc 243
{
244
  *ierr = EPSGetWhichEigenpairs(*eps,which);
245
}
246
 
1509 slepc 247
void PETSC_STDCALL epsgetproblemtype_(EPS *eps,EPSProblemType *type,PetscErrorCode *ierr)
986 slepc 248
{
249
  *ierr = EPSGetProblemType(*eps,type);
250
}
251
 
1560 slepc 252
void PETSC_STDCALL epsgetextraction_(EPS *eps,EPSExtraction *proj,PetscErrorCode *ierr)
1426 slepc 253
{
1560 slepc 254
  *ierr = EPSGetExtraction(*eps,proj);
1426 slepc 255
}
256
 
1509 slepc 257
void PETSC_STDCALL epsgetconvergedreason_(EPS *eps,EPSConvergedReason *reason,PetscErrorCode *ierr)
1021 slepc 258
{
259
  *ierr = EPSGetConvergedReason(*eps,reason);
260
}
261
 
1509 slepc 262
void PETSC_STDCALL epspowergetshifttype_(EPS *eps,EPSPowerShiftType *shift,PetscErrorCode *ierr)
986 slepc 263
{
264
  *ierr = EPSPowerGetShiftType(*eps,shift);
265
}
266
 
1509 slepc 267
void PETSC_STDCALL epslanczosgetreorthog_(EPS *eps,EPSLanczosReorthogType *reorthog,PetscErrorCode *ierr)
986 slepc 268
{
269
  *ierr = EPSLanczosGetReorthog(*eps,reorthog);
270
}
2083 eromero 271
 
272
void PETSC_STDCALL epsabsoluteconverged_(EPS *eps,PetscScalar *eigr,PetscScalar *eigi,PetscReal *res,PetscReal *errest,void *ctx,PetscErrorCode *ierr)
273
{
274
  *ierr = EPSAbsoluteConverged(*eps,*eigr,*eigi,*res,errest,ctx);
275
}
276
 
277
void PETSC_STDCALL epseigrelativeconverged_(EPS *eps,PetscScalar *eigr,PetscScalar *eigi,PetscReal *res,PetscReal *errest,void *ctx,PetscErrorCode *ierr)
278
{
279
  *ierr = EPSEigRelativeConverged(*eps,*eigr,*eigi,*res,errest,ctx);
280
}
281
 
282
void PETSC_STDCALL epsnormrelativeconverged_(EPS *eps,PetscScalar *eigr,PetscScalar *eigi,PetscReal *res,PetscReal *errest,void *ctx,PetscErrorCode *ierr)
283
{
284
  *ierr = EPSNormRelativeConverged(*eps,*eigr,*eigi,*res,errest,ctx);
285
}
286
 
986 slepc 287
EXTERN_C_END
288
 
2083 eromero 289
/* These are not extern C because they are passed into non-extern C user level functions */
290
static PetscErrorCode ourconvergence(EPS eps,PetscScalar eigr,PetscScalar eigi,PetscReal res,PetscReal *errest,void *ctx)
291
{
292
  PetscErrorCode ierr = 0;
293
  void           *mctx = (void*) ((PetscObject)eps)->fortran_func_pointers[4];
294
  (*(void (PETSC_STDCALL *)(EPS*,PetscScalar*,PetscScalar*,PetscReal*,PetscReal*,void*,PetscErrorCode*))
295
   (((PetscObject)eps)->fortran_func_pointers[3]))(&eps,&eigr,&eigi,&res,errest,mctx,&ierr);CHKERRQ(ierr);
296
  return 0;
297
}
298
 
299
EXTERN_C_BEGIN
300
 
301
void PETSC_STDCALL epssetconvergencetestfunction_(EPS *eps,void (PETSC_STDCALL *func)(EPS*,PetscScalar*,PetscScalar*,PetscReal*,PetscReal*,void*,PetscErrorCode*),void* ctx,PetscErrorCode *ierr)
302
{
303
  PetscObjectAllocateFortranPointers(*eps,5);
304
  if ((PetscVoidFunction)func == (PetscVoidFunction)epsabsoluteconverged_) {
305
    *ierr = EPSSetConvergenceTest(*eps,EPS_CONV_ABS);
306
  } else if ((PetscVoidFunction)func == (PetscVoidFunction)epseigrelativeconverged_) {
307
    *ierr = EPSSetConvergenceTest(*eps,EPS_CONV_EIG);
308
  } else if ((PetscVoidFunction)func == (PetscVoidFunction)epsnormrelativeconverged_) {
309
    *ierr = EPSSetConvergenceTest(*eps,EPS_CONV_NORM);
310
  } else {
311
    ((PetscObject)*eps)->fortran_func_pointers[3] = (PetscVoidFunction)func;
312
    ((PetscObject)*eps)->fortran_func_pointers[4] = (PetscVoidFunction)ctx;
313
    *ierr = EPSSetConvergenceTestFunction(*eps,ourconvergence,PETSC_NULL);
314
  }
315
}
316
 
317
EXTERN_C_END
2084 eromero 318
 
319
/* These are not extern C because they are passed into non-extern C user level functions */
320
static PetscErrorCode oureigenvaluecomparison(EPS eps,PetscScalar ar,PetscScalar ai,PetscScalar br,PetscScalar bi,PetscInt *r,void *ctx)
321
{
322
  PetscErrorCode ierr = 0;
323
  void           *mctx = (void*) ((PetscObject)eps)->fortran_func_pointers[6];
324
  (*(void (PETSC_STDCALL *)(EPS*,PetscScalar*,PetscScalar*,PetscScalar*,PetscScalar*,PetscInt*,void*,PetscErrorCode*))
325
   (((PetscObject)eps)->fortran_func_pointers[5]))(&eps,&ar,&ai,&br,&bi,r,mctx,&ierr);CHKERRQ(ierr);
326
  return 0;
327
}
328
 
329
EXTERN_C_BEGIN
330
 
331
void PETSC_STDCALL epsseteigenvaluecomparison_(EPS *eps,void (PETSC_STDCALL *func)(EPS*,PetscScalar*,PetscScalar*,PetscScalar*,PetscScalar*,PetscInt*,void*),void* ctx,PetscErrorCode *ierr)
332
{
333
  PetscObjectAllocateFortranPointers(*eps,7);
334
  ((PetscObject)*eps)->fortran_func_pointers[5] = (PetscVoidFunction)func;
335
  ((PetscObject)*eps)->fortran_func_pointers[6] = (PetscVoidFunction)ctx;
336
  *ierr = EPSSetEigenvalueComparison(*eps,oureigenvaluecomparison,PETSC_NULL);
337
}
338
 
339
EXTERN_C_END