sandbox/qmagdelaine/my_functions.h
Few functions that I often use.
A function to rescale normals so that they are unit vectors w.r.t. the 2-norm (by default, the 1-norm is adopted for efficiency purposes).
normal (Point point, scalar c) {
coord = mycs (point, c);
coord n double nn = 0.;
foreach_dimension()
+= sq(n.x);
nn = sqrt(nn);
nn foreach_dimension()
.x /= nn;
nreturn n;
}
A function to compute 2-norm normal in every cell.
void compute_normal (scalar f, vector normal_vector) {
foreach() {
= normal (point, f);
coord n foreach_dimension()
.x[] = n.x;
normal_vector}
boundary((scalar*){normal_vector});
}
A function to suppress glitches after an advection.
void magnet (scalar f, double error) {
foreach() {
[] = clamp(f[], 0., 1.);
f[] = (f[] < error ? 0. : (f[] > 1. - error ? 1. : f[]));
f}
boundary ({f});
}
A function to compute in each point the divergence of a gradient based flux.
void my_laplacian (scalar f, scalar l, face vector D) {
boundary({f, D});
foreach() {
[] = 0.;
lforeach_dimension()
[] += (f[1] - f[0])*D.x[1] - (f[] - f[-1])*D.x[];
l[] /= sq(Delta);
l}
boundary({l});
}
A function to mesure the length of the interface in the cell. Warning: the length is normalised by the size of the cell. To get the real interface length you have to multiplie it by the cell size \Delta.
double interface_length (Point point, scalar c)
{
= mycs (point, c);
coord n double alpha = line_alpha (c[], n);
= {0, 0};
coord coord_centroid return line_length_center(n, alpha, &coord_centroid);
}