# Computation of volume fractions on a variable-resolution grid

This test case is similar to fractions.c but with a refined band in the middle.

``#include "fractions.h"``

The refinement band is defined by this function.

``````int main()
{
origin (-0.5, -0.5);
init_grid (16);

refine (level == 4 && fabs (x) < 0.25);``````

We use a circle of radius 0.3 and initialise the fractions.

``````  vertex scalar φ[];
scalar c[];
c.refine = c.prolongation = fraction_refine;
face vector s[];
foreach_vertex()
φ[] = sq(0.3) - sq(x) - sq(y);
fractions (φ, c, s);``````

Output the reconstruced facets and cells.

``````  output_facets (c, stdout, s);
output_facets (c, stderr);
FILE * fp = fopen ("cells", "w");
output_cells (fp);
fclose (fp);``````

Finally, we reconstruct the interface and display the reconstructed facets only in the “halo cells”. This is a check of the consistency of the boundary conditions applied to $\mathbf{\text{n}}$ and $\alpha$.

``````  vector n[];
scalar α[];
reconstruction (c, n, α);
coord p[2];
for (int l = 0; l < depth(); l++)
foreach_halo (prolongation, l)
foreach_child() {
coord m = {n.x[],n.y[]};
if (facets (m, α[], p) == 2)
fprintf (stderr, "halo %g %g\nhalo %g %g\nhalo\n",
x + p[0].x*Δ, y + p[0].y*Δ,
x + p[1].x*Δ, y + p[1].y*Δ);
}
}``````

This gives this figure where “exact” uses c and s, “VOF” uses only c and “halo” is the halo cell reconstuction.