sandbox/bugs/tagBug.c

There is a bug in the tag function. It’s detecting more liquid phase than it should.

#include "navier-stokes/centered.h"
#include "two-phase.h"
#include "tension.h"
#include "tag.h"

#define LEVEL 10
#define Σ 1.

int main()
{
  init_grid(1<<9);
  rho1 = 1., mu1 = 1;
  rho2 = 1./998., mu2 = 1/55;
  f.σ = Σ;

  run();
}

We initiate a liquid field with 2 half droplet. If the tag function is working properly, then it should detect 2 phases.

There is 2 half circles. A big one, and a small one.

double geom (double x, double y) {
  double C1 = sq(x-0.2)+ sq(y) -sq(0.1);
  double C2 = sq(x-0.8)+sq(y)-sq(0.01);

  double C1C2 = min(C1, C2);
  return -C1C2;
}

double intemax = 0.005;
double uemax = 0.2;

We set on the adaptative mesh. Note that adapting the mesh at the initial steps instead of starting adapting the mesh on the first steps is not changing the bug issue.

If we turn off the adaptativity, the tag function behave normaly

event init (t = 0) {
  double iteration = 0;
  do {
    iteration++;
    fraction(f, geom(x,y));
  } while( adapt_wavelet({f,u}, (double []){intemax,0.2,0.2,0.2},
     maxlevel = LEVEL, 5).nf != 0 && iteration <= 10);
}

event adapt( i++) {
  adapt_wavelet ({f,u}, (double []){intemax,uemax,uemax,uemax},
     maxlevel = LEVEL, 5);
}

event bug (i++; t<=0.1) {

We tag our 2 droplets. The tag function should return n = 2

  scalar m[];
  foreach()
    m[] = f[] > 1.e-3;
  int n = tag(m);

We add a few information in the out file

  printf("%i %f %i\n", i, t, n);
  fflush (stdout);

If n is above 2, then we stop the simulation. We output 2 images, showing the tag problem.

The first one is the general tag of the simulation.

The second one is a zoom on the small droplet.

  if (n > 2) {
    output_ppm (m, file = "final.png", 512, min = 0, max = 3);
    output_ppm (m, file = "finalZoom.png", 512, min = 0, max = 3, box = {{0.75,0},{0.85,0.1}});
    return 1;
  }
}
General view of the tag scalar field

General view of the tag scalar field

Zoom on the small droplet

Zoom on the small droplet