Wednesday, January 23, 2019

FFTM: Fourier Spectral Methods in MATLAB


Purpose
  • The library "fftm" provides MatLab functions that are useful for solving ellipitic systems in 1D and 2D with Fourier spectral methods. It works for both complex and real data.

Click Here to Download the Codes


Specifications
  • Name:fftm
  • Author: Chris Chen
  • Version: 2.2
  • Language: MATLAB

Simple Example
  • Equation: \begin{equation} \begin{aligned} &a(x) u - b(x) (\beta_1 u_{xx} + \beta_2 u_{yy}) = f, \quad \Omega = (0,2\pi)^2,\\ &u \text{ is periodic}. \end{aligned} \end{equation}
  • Parameters: \begin{equation} a(x) =-0.1+\sin x + \cos 2y, \quad b(x) = 4 + \cos x + \sin y, \quad \beta_1=2, \quad \beta_2=3. \end{equation}
  • Exact solution and input functions: \begin{equation} u(x,y) = (1+\sin x + 2\cos y)(2+ \cos y), \end{equation} then $f(x,y)$ is calculated accordingly.

Quick Start
  • Compiling and running:
    matlab test_rfft_elliptic_solver_2dv
    
  • Output:
     
    bicgstab converged at iteration 10.5 to a solution with relative residual 8.5e-11.
    
    err =
    
         5.548761450313577e-10
    
  • CPU: Intel(R) Xeon(R) CPU X5550 @2.67GHz.
  • OS: CentOS release 6.4 (Final).
  • Release: MATLAB R2012a.

References
  • Fast Fourier transform in MATLAB. Link.

Core Subroutines
    
    %fftr_modes returns the ordering
    %of the wave number when the input data in 
    %the physical space are real numbers.
    %High dimensional index is the tensor 
    %product of 1-D indices.
    %The orderings are different for odd k 
    %and even k.
    
    %k contains the ordering.
    %m is the highest mode.
    function [lk m] = fftr_modes(n)
    
    
    lk = zeros(n,1); 
    
    m = floor((n-1)/2);
    
    lk(1:m+1) = [0:m]'; 
    
    lk(n:-1:n-m+1) = -[1:m]';
    
    
    
    

No comments:

Post a Comment