Actual source code: fft.c
petsc-3.10.5 2019-03-28
Report Typos and Errors

      2: /*
      3:     Provides an interface to the FFT packages.
      4: */

      6:  #include <../src/mat/impls/fft/fft.h>

      8: PetscErrorCode MatDestroy_FFT(Mat A)
      9: {
     11:   Mat_FFT        *fft = (Mat_FFT*)A->data;

     14:   if (fft->matdestroy) {
     15:     (fft->matdestroy)(A);
     16:   }
     17:   PetscFree(fft->dim);
     18:   PetscFree(A->data);
     19:   PetscObjectChangeTypeName((PetscObject)A,0);
     20:   return(0);
     21: }

     23: /*@C
     24:       MatCreateFFT - Creates a matrix object that provides FFT via an external package

     26:    Collective on MPI_Comm

     28:    Input Parameter:
     29: +   comm - MPI communicator
     30: .   ndim - the ndim-dimensional transform
     31: .   dim - array of size ndim, dim[i] contains the vector length in the i-dimension
     32: -   type - package type, e.g., FFTW or FFTCU

     34:    Output Parameter:
     35: .   A  - the matrix

     37:   Options Database Keys:
     38: + -mat_fft_type - set FFT type

     40:    Level: intermediate

     42: @*/
     43: PetscErrorCode MatCreateFFT(MPI_Comm comm,PetscInt ndim,const PetscInt dim[],MatType mattype,Mat *A)
     44: {
     46:   PetscMPIInt    size;
     47:   Mat            FFT;
     48:   PetscInt       N,i;
     49:   Mat_FFT        *fft;

     52:   if (ndim < 1) SETERRQ1(comm,PETSC_ERR_USER,"ndim %d must be > 0",ndim);
     53:   MPI_Comm_size(comm, &size);

     55:   MatCreate(comm,&FFT);
     56:   PetscNewLog(FFT,&fft);
     57:   FFT->data = (void*)fft;
     58:   N         = 1;
     59:   for (i=0; i<ndim; i++) {
     60:     if (dim[i] < 1) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_USER,"dim[%d]=%d must be > 0",i,dim[i]);
     61:     N *= dim[i];
     62:   }

     64:   PetscMalloc1(ndim,&fft->dim);
     65:   PetscMemcpy(fft->dim,dim,ndim*sizeof(PetscInt));

     67:   fft->ndim = ndim;
     68:   fft->n    = PETSC_DECIDE;
     69:   fft->N    = N;
     70:   fft->data = NULL;

     72:   MatSetType(FFT,mattype);

     74:   FFT->ops->destroy = MatDestroy_FFT;

     76:   /* get runtime options */
     77:   PetscOptionsBegin(PetscObjectComm((PetscObject)FFT),((PetscObject)FFT)->prefix,"FFT Options","Mat");
     78:   PetscOptionsEnd();

     80:   *A = FFT;
     81:   return(0);
     82: }