sandbox/aberny/test3D.c
This simulation is the bursting of a bubble on a water-air interface, in 3D
#define dimension 3
#include "grid/octree.h"
#include "navier-stokes/centered.h"
#include "two-phase.h"
#include "tension.h"
#include "tag.h"
// #include "distance.h"
#include "view.h"
#define TETRA 1
Numerical Parameters
LEVEL stand for the maximum refinement of the grid
L0 is for the size of the simulation domain
int LEVEL = 10;
#define L0 4.
int main(int argc, char const *argv[]) {
(L0);
size // origin (-L0/2.,-L0/2.,-L0/2.);
(1 << (4));
init_grid
run();
}
#if TETRA
The coordinate of my tetrahedron
= {0.1, 0.1, 0.1};
coord A = {0.9, 0.1, 0.1};
coord B = {0.1, 0.9, 0.1};
coord C = {0.1, 0.1, 0.9};
coord D #else
The coordinate of 4 points of my plane
= {0, 0, 0.5};
coord A = {0.8, 0, 0};
coord B = {0.8, 1, 0};
coord C = {0, 1, 0.5};
coord D #endif
Generation of the array with the triangles coordinate. This function is based on the input_stl function
* inputTest(void) {
coord * h = array_new(); Array
First triangle
{
= {A.x, A.y, A.z};
coord toto (h, &toto, sizeof(coord));
array_append}
{
= {B.x, B.y, B.z};
coord toto (h, &toto, sizeof(coord));
array_append}
{
= {C.x, C.y, C.z};
coord toto (h, &toto, sizeof(coord));
array_append}
Second triangle
{
= {A.x, A.y, A.z};
coord toto (h, &toto, sizeof(coord));
array_append}
{
= {C.x, C.y, C.z};
coord toto (h, &toto, sizeof(coord));
array_append}
{
= {D.x, D.y, D.z};
coord toto (h, &toto, sizeof(coord));
array_append}
#if TETRA
Instead of a plane, we can generate a tetrahedron
Third triangle
{
= {A.x, A.y, A.z};
coord toto (h, &toto, sizeof(coord));
array_append}
{
= {D.x, D.y, D.z};
coord toto (h, &toto, sizeof(coord));
array_append}
{
= {B.x, B.y, B.z};
coord toto (h, &toto, sizeof(coord));
array_append}
Fourth triangle
{
= {B.x, B.y, B.z};
coord toto (h, &toto, sizeof(coord));
array_append}
{
= {D.x, D.y, D.z};
coord toto (h, &toto, sizeof(coord));
array_append}
{
= {C.x, C.y, C.z};
coord toto (h, &toto, sizeof(coord));
array_append}
#endif
= {nodata};
coord p (h, &p, sizeof(coord));
array_append
return (coord *) array_shrink(h);
}
We can play with Antoon tric to display an isosurface. We base it on the distance field obtain with its new function distance_to_surface.
#include "../Antoonvh/frac-dist.h"
#include "output_stl.h"
event init (t = 0) {
* h = inputTest();
coord
scalar d[];
distance (d, h);
while (adapt_wavelet ({d}, (double[]){0.01}, LEVEL).nf);
vertex scalar phi[];
foreach_vertex()
[] = -(d[] + d[-1] + d[0,-1] + d[-1,-1] +
phi[0,0,-1] + d[-1,0,-1] + d[0,-1,-1] + d[-1,-1,-1])/8.;
dface vector s[];
fractions (phi, f, s);
scalar dist[];
distance_to_surface(c = f, d = dist);
dump("initial");
clear();
view (fov = 33.2344, quat = {0.206574,0.0297392,-0.0399921,0.977161}, tx = -0.370845, ty = -0.692088, bg = {0.3,0.4,0.6}, width = 600, height = 600, samples = 1);
draw_vof("f");
box();
save(file = "vof.png");
stl_output_binary(f, "3D.stl");
// output_stl_binary(f);
clear();
view (fov = 28.5561, quat = {0.0297249,-0.905678,-0.289561,0.308253},
= 0.148153, ty = -0.393888, bg = {0.3,0.4,0.6},
tx = 600, height = 600, samples = 4);
width isosurface("dist", 0);
save("isosurface.png");
clear();
view (fov = 40.2904, quat = {-0.260473,0.358927,0.116761,0.888649},
= -0.0447443, ty = 0.0754991, bg = {0.3,0.4,0.6},
tx = 600, height = 600, samples = 4);
width squares("dist", min = -0.1, max = 0.1);
box();
squares("dist", min = -0.1, max = 0.1, n = {1,0,0});
squares("dist", min = -0.1, max = 0.1, n = {0,1,0});
cells();
// cells(n={1,0,0});
// cells(n={0,1,0});
save("dist.png");
}
Our interface looks like:

We can observe the isosurface:

We can also observe the distance field to reconstruct the isosurface on the box
