src/test/wind-driven.c

Wind-driven lake

This is a simple test case of a wind-driven lake where we can compare results with an analytical solution. For the bottom of the domain we impose no-slip condition (that is the default), for the top we impose a Neumann condition (see viscous friction between layers for details).

#include "grid/cartesian1D.h"
#include "saint-venant.h"

int main() {
  L0 = 1.;
  G = 100.;
  N = 64;
  ν = 1.;
  dut = unity;

We vary the number of layers.

  for (nl = 4; nl <= 32; nl *= 2)
    run();
}

We set the initial water level to 1 and we allocate a scalar field uc to check the convergence of the velocity in the first layer.

scalar uc[];

event init (i = 0) {
  vector u0 = ul[0];
  foreach() {
    h[] = 1.;
    uc[] = u0.x[];
  }
}

We check for convergence.

event logfile (t += 0.1; i <= 100000) {
  vector u0 = ul[0];
  double du = change (u0.x, uc);
  if (i > 0 && du < 1e-5)
    return 1;
}

We compute the error between the numerical solution and the analytical solution.

#define uan(z)  ((z)/4.*(3.*(z) - 2.))

event error (t = end) {
  int i = 0;
  foreach() {
    if (i++ == N/2) {
      double sumh = zb[], emax = 0.;
      int l = 0;
      for (vector u in ul) {
	double z = sumh + h[]*layer[l]/2.;
	double e = fabs(u.x[] - uan (z));
	if (e > emax) 
	  emax = e;
	sumh += h[]*layer[l++];
      }
      fprintf (stderr, "%d %g\n", nl, emax);
    }
  }
}

We save the horizontal velocity profile at the center of the domain and the two components of the velocity field for the case with 32 layers.

event output (t = end) {
  char name[80];
  sprintf (name, "uprof-%d", nl);
  FILE * fp = fopen (name, "w");
  int i = 0;
  foreach() {
    if (i++ == N/2) {
      int l = 0;
      double z = zb[] + h[]*layer[l]/2.;
      for (vector u in ul)
	fprintf (fp, "%g %g\n", z, u.x[]), z += h[]*layer[l];
    }
    if (nl == 32) {
      double sumh = zb[];
      int l = 0;
      scalar w;
      vector u;
      for (w,u in wl,ul) {
	double z = sumh + h[]*layer[l]/2.;
	printf ("%g %g %g %g\n", x, z, u.x[], w[]);
	sumh += layer[l++]*h[];
      }
      printf ("\n");
    }
  }
  fclose (fp);
}

Results

Numerical and analytical velocity profiles at the center of the lake.

Numerical and analytical velocity profiles at the center of the lake.

Convergence of the error between the numerical and analytical solution with the number of layers.

Convergence of the error between the numerical and analytical solution with the number of layers.

Velocity field (32 layers).

Velocity field (32 layers).

See also