⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 arpack.c

📁 cfd求解器使用与gmsh网格的求解
💻 C
📖 第 1 页 / 共 2 页
字号:
#define RCSID "$Id: Arpack.c,v 1.29 2006/02/26 00:42:54 geuzaine Exp $"/* * Copyright (C) 1997-2006 P. Dular, C. Geuzaine * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA. * * Please report all bugs and problems to <getdp@geuz.org>. * * Contributor(s): *   Alexandru Mustatea *   Andre Nicolet */#include "GetDP.h"#include "DofData.h"#include "CurrentData.h"#include "Numeric.h"#include "EigenPar.h"#if !defined(HAVE_ARPACK) || !defined(HAVE_BLAS_LAPACK)void EigenSolve (struct DofData * DofData_P, int NumEigenvalues, 		 double shift_r, double shift_i){  Msg(GERROR, "EigenSolve not available without BLAS, LAPACK and ARPACK");}#else#include "Arpack_F.h"/* This routine uses Arpack to solve Generalized Complex Non-Hermitian   eigenvalue problems. We don't use the "Generalized" Arpack mode   (bmat=='G') since it requires M to be Hermitian. Instead, we use   the regular mode (bmat='I') and apply the shift "by hand", which   allows us to use arbitrary matrices K and M. */static void Arpack2GetDP(int N, complex_16 *in, gVector *out){  int i, j;  double re, im;  for(i = 0; i < N; i++){    re = in[i].re;    im = in[i].im;    j = i * gCOMPLEX_INCREMENT;    LinAlg_SetComplexInVector(re, im, out, j, j+1);  }}static void Arpack2GetDPSplit(int N, complex_16 *in, gVector *out1, gVector *out2){  int i, j;  double re, im;  for(i = 0; i < N/2; i++){    j = i * gCOMPLEX_INCREMENT;    re = in[i].re;    im = in[i].im;    LinAlg_SetComplexInVector(re, im, out1, j, j+1);    re = in[N/2+i].re;    im = in[N/2+i].im;    LinAlg_SetComplexInVector(re, im, out2, j, j+1);  }}static void GetDP2Arpack(gVector *in, complex_16 *out){  int i, N;  double re, im;  LinAlg_GetVectorSize(in, &N);  for(i = 0; i < N; i += gCOMPLEX_INCREMENT){    LinAlg_GetComplexInVector(&re, &im, in, i, i+1);    out[i/gCOMPLEX_INCREMENT].re = re;    out[i/gCOMPLEX_INCREMENT].im = im;  }}static void GetDP2ArpackMerge(gVector *in1, gVector *in2, complex_16 *out){  int i, N;  double re, im;  LinAlg_GetVectorSize(in1, &N);  for(i = 0; i < N; i += gCOMPLEX_INCREMENT){    LinAlg_GetComplexInVector(&re, &im, in1, i, i+1);    out[i/gCOMPLEX_INCREMENT].re = re;    out[i/gCOMPLEX_INCREMENT].im = im;    LinAlg_GetComplexInVector(&re, &im, in2, i, i+1);    out[N/gCOMPLEX_INCREMENT + i/gCOMPLEX_INCREMENT].re = re;    out[N/gCOMPLEX_INCREMENT + i/gCOMPLEX_INCREMENT].im = im;  }}void EigenSolve (struct DofData * DofData_P, int NumEigenvalues, 		 double shift_r, double shift_i){  struct EigenPar eigenpar;  struct Solution Solution_S;  gVector v1, v2, w1, w2, x, y;  int n, j, k, l, newsol, quad_evp = 0;  double tmp, d1, d2, abs, arg;  complex_16 f, omega, omega2;  gMatrix *K = &DofData_P->M1; /* matrix associated with terms with no Dt nor DtDt */  gMatrix *L = &DofData_P->M2; /* matrix associated with Dt terms */  gMatrix *M = &DofData_P->M3; /* matrix associated with DtDt terms */  gMatrix D; /* temp matrix for quadratic eigenvalue problem */  /* Arpack parameters: see below for explanation */  int ido, nev, ncv, ldv, iparam[11], ipntr[14], lworkl, info, ldz;  char bmat, *which, howmny;  double tol, *rwork;  unsigned int rvec, *select;  complex_16 *resid, *v, *workd, *workl, *d, *z, sigma, *workev;  GetDP_Begin("EigenSolve");  /* Bail out if we are not in harmonic regime: it's much easier this     way (since, for real, non-symmetric matrices we would get complex     eigenvectors we could not easily store) */  if(Current.NbrHar != 2)    Msg(GERROR, "EigenSolve requires system defined with \"Type Complex\"");  /* Sanity checks */  if(!DofData_P->Flag_Init[1] || !DofData_P->Flag_Init[3])    Msg(GERROR, "No System available for EigenSolve: check 'DtDt' and 'GenerateSeparate'");  /* Check if we have a "quadratic" evp (- w^2 M x + i w L x + K x = 0) */  if(DofData_P->Flag_Init[2])    quad_evp = 1;    /* Get eigenproblem parameters */  EigenPar("eigen.par", &eigenpar);  n = DofData_P->NbrDof / gCOMPLEX_INCREMENT; /* size of the system */    if(quad_evp)    n *= 2;  ido = 0;  /* Reverse communication flag.  IDO must be zero on the first      call to znaupd.  IDO will be set internally to     indicate the type of operation to be performed.  Control is     then given back to the calling routine which has the     responsibility to carry out the requested operation and call     znaupd with the result.  The operand is given in     WORKD(IPNTR(1)), the result must be put in WORKD(IPNTR(2)).     -------------------------------------------------------------     IDO =  0: first call to the reverse communication interface     IDO = -1: compute  Y = OP * X  where               IPNTR(1) is the pointer into WORKD for X,               IPNTR(2) is the pointer into WORKD for Y.               This is for the initialization phase to force the               starting vector into the range of OP.     IDO =  1: compute  Y = OP * X  where               IPNTR(1) is the pointer into WORKD for X,               IPNTR(2) is the pointer into WORKD for Y.               In mode 3, the vector B * X is already               available in WORKD(ipntr(3)).  It does not               need to be recomputed in forming OP * X.     IDO =  2: compute  Y = M * X  where               IPNTR(1) is the pointer into WORKD for X,               IPNTR(2) is the pointer into WORKD for Y.     IDO =  3: compute and return the shifts in the first                NP locations of WORKL.     IDO = 99: done     -------------------------------------------------------------     After the initialization phase, when the routine is used in      the "shift-and-invert" mode, the vector M * X is already      available and does not need to be recomputed in forming OP*X. */  bmat = 'I';  /* BMAT specifies the type of the matrix B that defines the     semi-inner product for the operator OP.     BMAT = 'I' -> standard eigenvalue problem A*x = lambda*x     BMAT = 'G' -> generalized eigenvalue problem A*x = lambda*M*x */    which = "LM";  /* Which eigenvalues we want:     SM = smallest magnitude ( magnitude = absolute value )     LM = largest magnitude     SR = smallest real part     LR = largest real part     SI = smallest imaginary part     LI = largest imaginary part */    nev = NumEigenvalues;  /* Number of eigenvalues of OP to be computed. 0 < NEV < N-1.     Therefore, you'll be able to compute AT MOST n-2 eigenvalues! */  /* sanity check */  if(nev >= n-1){    Msg(WARNING, "NumEigenvalues too large (%d < %d): setting to %d", nev, n-1, n-2);    nev = n-2;  }  tol = eigenpar.prec; /* 1.e-4; */  /* Stopping criteria: the relative accuracy of the Ritz value      is considered acceptable if BOUNDS(I) .LE. TOL*ABS(RITZ(I))     where ABS(RITZ(I)) is the magnitude when RITZ(I) is complex.     DEFAULT = dlamch('EPS')  (machine precision as computed           by the LAPACK auxiliary subroutine dlamch). */    resid = (complex_16*)Malloc(n * sizeof(complex_16));  /* On INPUT:      If INFO .EQ. 0, a random initial residual vector is used.     If INFO .NE. 0, RESID contains the initial residual vector,                     possibly from a previous run.     On OUTPUT:     RESID contains the final residual vector. */    ncv = eigenpar.size; /* Rule of thumb: NumEigenvalues * 2; */  /* Number of columns of the matrix V. NCV must satisfy the two     inequalities 1 <= NCV-NEV and NCV <= N.     This will indicate how many Arnoldi vectors are generated      at each iteration.  After the startup phase in which NEV      Arnoldi vectors are generated, the algorithm generates      approximately NCV-NEV Arnoldi vectors at each subsequent update      iteration. Most of the cost in generating each Arnoldi vector is      in the matrix-vector operation OP*x. */    /* sanity checks */  if(ncv <= nev){    Msg(WARNING, "Krylov space size too small (%d <= %d), setting to %d", ncv, nev, nev*2);    ncv = nev * 2;  }  if(ncv > n){    Msg(WARNING, "Krylov space size too large (%d > %d), setting to %d", ncv, n, n);    ncv = n;  }  v = (complex_16*)Malloc(n * ncv * sizeof(complex_16));  /* At the end of calculations, here will be stored the Arnoldi basis     vectors */    ldv = n;  /* Leading dimension of "v". In our case, the number of lines of     "v". */    iparam[0] = 1;  iparam[1] = 0;  iparam[2] = 10000;  iparam[3] = 1;  iparam[4] = 0;  iparam[5] = 0;  iparam[6] = 1;  iparam[7] = 0;  iparam[8] = 0;  iparam[9] = 0;  iparam[10] = 0;  /* IPARAM(1) = ISHIFT: method for selecting the implicit shifts.     The shifts selected at each iteration are used to filter out     the components of the unwanted eigenvector.     -------------------------------------------------------------     ISHIFT = 0: the shifts are to be provided by the user via                 reverse communication.  The NCV eigenvalues of                  the Hessenberg matrix H are returned in the part                 of WORKL array corresponding to RITZ.     ISHIFT = 1: exact shifts with respect to the current                 Hessenberg matrix H.  This is equivalent to                  restarting the iteration from the beginning                  after updating the starting vector with a linear                 combination of Ritz vectors associated with the                  "wanted" eigenvalues.     ISHIFT = 2: other choice of internal shift to be defined.     -------------------------------------------------------------     IPARAM(2) = No longer referenced      IPARAM(3) = MXITER     On INPUT:  maximum number of Arnoldi update iterations allowed.      On OUTPUT: actual number of Arnoldi update iterations taken.      IPARAM(4) = NB: blocksize to be used in the recurrence.     The code currently works only for NB = 1.     IPARAM(5) = NCONV: number of "converged" Ritz values.     This represents the number of Ritz values that satisfy     the convergence criterion.     IPARAM(6) = IUPD     No longer referenced. Implicit restarting is ALWAYS used.       IPARAM(7) = MODE     On INPUT determines what type of eigenproblem is being solved.     Must be 1,2,3; See under \Description of znaupd for the      four modes available.     IPARAM(8) = NP     When ido = 3 and the user provides shifts through reverse     communication (IPARAM(1)=0), _naupd returns NP, the number     of shifts the user is to provide. 0 < NP < NCV-NEV.     IPARAM(9) = NUMOP, IPARAM(10) = NUMOPB, IPARAM(11) = NUMREO,     OUTPUT: NUMOP  = total number of OP*x operations,             NUMOPB = total number of B*x operations if BMAT='G',             NUMREO = total number of steps of re-orthogonalization. */    ipntr[0] = 0;  /* Pointer to mark the starting locations in the WORKD and WORKL     arrays for matrices/vectors used by the Arnoldi iteration.     -------------------------------------------------------------     IPNTR(1): pointer to the current operand vector X in WORKD.     IPNTR(2): pointer to the current result vector Y in WORKD.     IPNTR(3): pointer to the vector B * X in WORKD when used in                the shift-and-invert mode.     IPNTR(4): pointer to the next available location in WORKL               that is untouched by the program.     IPNTR(5): pointer to the NCV by NCV upper Hessenberg               matrix H in WORKL.     IPNTR(6): pointer to the  ritz value array  RITZ     IPNTR(7): pointer to the (projected) ritz vector array Q     IPNTR(8): pointer to the error BOUNDS array in WORKL.     IPNTR(14): pointer to the NP shifts in WORKL. See Remark 5 below.     Note: IPNTR(9:13) is only referenced by zneupd. See Remark 2 below.     IPNTR(9): pointer to the NCV RITZ values of the                original system.     IPNTR(10): Not Used     IPNTR(11): pointer to the NCV corresponding error bounds.     IPNTR(12): pointer to the NCV by NCV upper triangular                Schur matrix for H.     IPNTR(13): pointer to the NCV by NCV matrix of eigenvectors                of the upper Hessenberg matrix H. Only referenced by                zneupd if RVEC = .TRUE. See Remark 2 below. */   workd = (complex_16*)Malloc(3 * n * sizeof(complex_16));  /* Distributed array to be used in the basic Arnoldi iteration

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -