In this step you will become familiar with different spectral operators that is implemented in AccFFT. These include gradient, laplace, divergence, and biharmonic operators.

## Introduction

An important strength of spectral methods is that spatial derivatives can be computed easily by a Hadamard product in frequency domain. This is the result of the following identity:

Here is the Fourier transform of the x derivative of f, which is a function of (i.e. wave numbers in x direction). So given the function f, one can simply compute its Fourier transform and scale it with the corresponding , and then apply an inverse Fourier transform to get the derivative. Using the same argument you can compute higher order derivatives.

Some of the common operators are hard coded into AccFFT utility library. You simply pass in the function is the spatial domain and it computes the application of that operators and gives you the output. This comes handy for people who use spectral methods to solve PDEs. In the next step, you will see how a diffusion equation can be solved using these operators. Here I will explain the interface of the utility operators and how they should be used. The code for this step applies each of the operators and then computes the error by comparing the results to an analytical expression for the results.

**Gradient**

The gradient of a real function in 3D is a vector field in x,y, and z directions.

These components can be computed by calling accfft_grad(f) function for CPU and accfft_grad_gpu(f) for GPU. Note that the suffix f is when you want the operation to be done in single precision. The user needs to create a real-to-complex plan, and allocate the derivative fields on the CPU/GPU. The function takes care of the Hadamard product and the Fourier transforms. For details of the arguments that you need to pass please see the doxygen reference 1 2 3 4 .

**Laplace**

Laplacian of a real function is a real field given by:

This can be computed by calling accfft_laplace(f) or accfft_laplace_gpu(f) for CPU and GPU implementations. The user is responsible for creating the correct R2C plan, and allocating enough memory for the results. For detailed information on the parameteres that you need to pass please see the doxygen reference 1 2 3 4 .

**Divergence**

Divergence is an operator that acts on a vector field and returns the result in the real field give by computing the dot product of the gradient with the vector field:

This can be computed by calling accfft_divergence(f) and accfft_divergence_gpu(f) for CPU/GPU. Again the user is responsible for creating an R2C plan and allocating enough memory to store the results. For details please see 1 2 3 4 .

**Biharmonic**

Biharmonic of a real function is a real field given by:

This can be computed by calling accfft_biharmonic(f) or accfft_biharmonic_gpu(f) for CPU and GPU implementations. The user is responsible for creating the correct R2C plan, and allocating enough memory for the results. For detailed information on the parameteres that you need to pass please see the doxygen reference 1 2 3 4 .

## Code Explanation

The source code for this step implements all of these operators both in single and double precisions for CPU and GPU.
The code is self explanatory and if you have already read the previous steps you should be able to easy follow the code.
Note that all the GPU functions have a *_gpu* suffix and single precision routines have a *f* suffix. To make the code go
to the step5 in your build directory and execute the make command. This will create four executables:

- step5: CPU, double precision
- step5f: CPU, single precision
- step5_gpu: GPU, double precision
- step5_gpuf: GPU, single precision