# src/examples/ginzburg-landau.c

# The complex Ginzburg–Landau equation

The complex Ginzburg–Landau equation $${\partial}_{t}A=A+(1+i\alpha ){\nabla}^{2}A-(1+i\beta ){\mid A\mid}^{2}A$$ with $A$ a complex number, is a classical model for phenomena exhibiting Hopf bifurcations such as Rayleigh-Bénard convection or superconductivity.

Posing ${A}_{r}=Re(A)$ and ${A}_{i}=Im(A)$ one gets the coupled reaction–diffusion equations. $${\partial}_{t}{A}_{r}={\nabla}^{2}{A}_{r}+{A}_{r}(1-{\mid A\mid}^{2})-\alpha {\nabla}^{2}{A}_{i}+{\mid A\mid}^{2}\beta {A}_{i}$$ $${\partial}_{t}{A}_{i}={\nabla}^{2}{A}_{i}+{A}_{i}(1-{\mid A\mid}^{2})+\alpha {\nabla}^{2}{A}_{r}-{\mid A\mid}^{2}\beta {A}_{r}$$

This system can be solved with the reaction–diffusion solver.

```
#include "grid/multigrid.h"
#include "run.h"
#include "diffusion.h"
scalar Ar[], Ai[], A2[];
```

In this example, we only consider the case when $\alpha =0$.

`double β;`

The generic time loop needs a timestep. We will store the statistics on the diffusion solvers in `mgd1`

and `mgd2`

.

```
double dt;
mgstats mgd1, mgd2;
```

## Parameters

We change the size of the domain `L0`

.

```
int main() {
β = 1.5;
size (100);
init_grid (256);
run();
}
```

## Initial conditions

We use a white noise in $[-{10}^{-4}:{10}^{-4}]$ for both components.

```
event init (i = 0) {
foreach() {
Ar[] = 1e-4*noise();
Ai[] = 1e-4*noise();
}
boundary ({Ar,Ai});
}
```

## Time integration

`event integration (i++) {`

We first set the timestep according to the timing of upcoming events. We choose a maximum timestep of 0.05 which ensures the stability of the reactive terms for this example.

` dt = dtnext (0.05);`

We compute $\mid A{\mid}^{2}$.

```
foreach()
A2[] = sq(Ar[]) + sq(Ai[]);
boundary ({A2});
```

We use the diffusion solver (twice) to advance the system from $t$ to $t+dt$.

```
scalar r[], λ[];
foreach() {
r[] = A2[]*β*Ai[];
λ[] = 1. - A2[];
}
mgd1 = diffusion (Ar, dt, r = r, β = λ);
foreach() {
r[] = - A2[]*β*Ar[];
λ[] = 1. - A2[];
}
mgd1 = diffusion (Ai, dt, r = r, β = λ);
}
```

## Outputs

Here we create MP4 animations for both components. The `spread`

parameter sets the color scale to $\pm $ twice the standard deviation.

```
event movies (i += 3; t <= 150) {
fprintf (ferr, "%g %g\n", t, sqrt(normf(A2).max));
output_ppm (Ai, spread = 2, linear = true, file = "Ai.mp4");
output_ppm (A2, spread = 2, linear = true, file = "A2.mp4");
}
```

For the value of $\beta $ we chose, we get a typical “frozen state” composed of “cellular structures” for $\mid A{\mid}^{2}$ and stationary spirals for ${A}_{i}$.

$\mid A{\mid}^{2}$ | ${A}_{i}$ |