# src/test/stream.c

# Merging of two vertices

Studying the interaction of two incompressible vortices is interesting for example as a basic model of two-dimensional turbulence. Here we solve the incompressible 2D Euler equations using a vorticity–streamfunction formulation.

```
#include "navier-stokes/stream.h"
```

The domain is centered on $(0,0)$ and the maximum level of refinement is 8 i.e. the initial grid has $N={2}^{8}=256$ grid points per dimension.

```
#define MAXLEVEL 8
int main()
{
origin (-0.5, -0.5);
init_grid (1 << MAXLEVEL);
run();
}
```

The initial vorticity field is composed of two Gaussian vortices separated by twice *dd* and with caracteristic radii *dd/10*.

```
event init (i = 0)
{
double dd = 0.1;
foreach()
ω[] = (exp(-(sq(x - dd) + sq(y))/(dd/10.)) +
exp(-(sq(x + dd) + sq(y))/(dd/10.)));
}
```

We output some statistics on the vorticity field and Poisson solver at the start and end of the simulation.

```
event logfile (t = {0,30}) {
stats s = statsf (ω);
fprintf (stderr, "%g %d %g %g %d\n", t, i, dt, s.sum, mgpsi.i);
}
```

We output the vorticity and level fields at regular intervals in a format compatible with gnuplot.

```
event output (t += 5) {
static int nf = 0;
char name[80];
sprintf (name, "omega-%d", nf);
FILE * fp = fopen (name, "w");
output_field ({ω}, fp, linear = true);
fclose (fp);
scalar l[];
foreach()
l[] = level;
sprintf (name, "level-%d", nf);
fp = fopen (name, "w");
output_field ({l}, fp);
fclose (fp);
nf++;
}
```

If we are using a quadtree grid, it is adapted using wavelet error control on $\omega $.

```
#if TREE
event adapt (i++) {
adapt_wavelet ({ω}, (double[]){1e-2}, MAXLEVEL, list = {ω, ψ});
}
#endif
```

## Results

After running and processing by gnuplot we get: