Define DIAMETER 0.2
Define EPSILON 0.05
Define VAR(T,min,max)   (min + CLAMP(T,0,1)*(max - min))
Define RHO(T)            VAR(T, 1., 1e-3)
Define RADIUS(x,y)      (DIAMETER/2.*(1. + EPSILON*cos (2.*atan2 (y, x))))

1 0 GfsSimulation GfsBox GfsGEdge {} {
    Time { end = 1 }

    Refine LEVEL
 
    VariableTracerVOF T
    VariableFiltered T1 T 1
    InitFraction T ({ x += 0.5; y += 0.5; return x*x + y*y - RADIUS(x,y)*RADIUS(x,y); })

    PhysicalParams { alpha = 1./RHO(T1) }
    VariableCurvature K T
    SourceTension T 1. K

    # fixme: A small amount of viscosity seems to be necessary to
    # obtain a non-increasing kinetic energy at high-resolution (8
    # levels).
    SourceViscosityExplicit 7e-5*RHO(T1)

    AdaptFunction { istep = 1 } {
        cmax = 0.01
        maxlevel = LEVEL
    } (T > 0 && T < 1 ? 1. : fabs (Vorticity)*ftt_cell_size (cell))

    OutputScalarSum { istep = 1 } k-LEVEL {
        v = RHO(T1)*Velocity2
    }

    EventScript { start = end } {
        cat <<EOF | gnuplot 2>&1 | awk '{if ($1 == "result:") print LEVEL,$2,$3,$4;}'
           k(t)=a*exp(-b*t)*(cos(c*t+3.14159265359)+1.)
           a = 3e-4
           b = 1.5
           c = 153
           fit k(x) 'k-LEVEL' u 3:5 via a,b,c
           print "result: ", a, b, c       
EOF
        rm -f fit.log
    }
}
GfsBox {
    left = Boundary
    bottom = Boundary
}