# Implementing semi-implicit Fourier spectral method

**URL:** <https://discourse.julialang.org/t/implementing-semi-implicit-fourier-spectral-method/109686>\
**Category:** Numerics\
**Tags:** sciml, differentialequation\
**Created:** [February 3, 2024, 10:01pm UTC](https://discourse.julialang.org/t/implementing-semi-implicit-fourier-spectral-method/109686 "2024-02-03T22:01:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![yhchang96](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yhchang96/32/36499_2.png) [@yhchang96](https://discourse.julialang.org/u/yhchang96)\
**Post date:** [February 3, 2024, 10:01pm UTC](https://discourse.julialang.org/t/implementing-semi-implicit-fourier-spectral-method/109686/1 "2024-02-03T22:01:20Z")

</div>

I’m trying to implement the semi-implicit Fourier spectral method described [here](https://doi.org/10.1103/PhysRevE.60.3564). It is basically a fourth-order phase-field equation, the linear fourth order operator is treated implicitly and the nonlinear operator term explicitly. I’d like to get some hints on how to implement it using the available solvers and packages in Julia and particularly `DifferentialEquations.jl`.

When I was solving similar problems using finite difference, I just need to define the RHS of the equation and choose the appropriate solver and I didn’t really need to care about implicit vs explicit method when defining the RHS. What about a semi-implicit scheme? The closest example I can find is [this](https://docs.sciml.ai/DiffEqDocs/stable/examples/diffusion_implicit_heat_equation/) one. Do I just define a `SplitODEProblem` as in the example?

And then what about the Fourier spectral method? I have tried creating a pre-plan using `FFTW.jl` and passing it inside the parameter struct to do the Fourier transform inside the RHS function, but then I ran into issues with the automatic differentiation. Is `ApproxFun.jl` of any use in this case? I have found two examples in the SciML benchmark on [Allen-Cahn](https://docs.sciml.ai/SciMLBenchmarksOutput/stable/SimpleHandwrittenPDE/allen_cahn_spectral_wpd/) and [Burger’s equation](https://docs.sciml.ai/SciMLBenchmarksOutput/stable/SimpleHandwrittenPDE/burgers_spectral_wpd/) on ‘pseudospectral method’ but I’m not sure if they are up-to-date and they don’t have much documentation.

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [February 10, 2024, 7:40pm UTC](https://discourse.julialang.org/t/implementing-semi-implicit-fourier-spectral-method/109686/2 "2024-02-10T19:40:44Z")

</div>

> [@yhchang96](#):
>
> What about a semi-implicit scheme? The closest example I can find is [this](https://docs.sciml.ai/DiffEqDocs/stable/examples/diffusion_implicit_heat_equation/) one. Do I just define a `SplitODEProblem` as in the example?

Yes, that example is doing the same semi-implicit (i.e. IMEX) scheme.

> [@yhchang96](#):
>
> And then what about the Fourier spectral method?

Just discretize to an ODE via Fourier decomposition, no difference on the solver part.

> [@yhchang96](#):
>
> I have tried creating a pre-plan using `FFTW.jl` and passing it inside the parameter struct to do the Fourier transform inside the RHS function, but then I ran into issues with the automatic differentiation.

PreallocationTools.jl will be helpful here. Just use the LazyBufferCache for the discretization. If your discretization isn’t changing then you can instead just solve in Fourier space and cut down on the work.

> [@yhchang96](#):
>
> Is `ApproxFun.jl` of any use in this case? I have found two examples in the SciML benchmark on [Allen-Cahn](https://docs.sciml.ai/SciMLBenchmarksOutput/stable/SimpleHandwrittenPDE/allen_cahn_spectral_wpd/) and [Burger’s equation](https://docs.sciml.ai/SciMLBenchmarksOutput/stable/SimpleHandwrittenPDE/burgers_spectral_wpd/) on ‘pseudospectral method’ but I’m not sure if they are up-to-date and they don’t have much documentation.

ApproxFun is useful and those examples should do “fine”, though I plan on updating them a bit they should serve as useful background for how to do this.
