Basilisk CFD
Adaptive Cartesian mesh PDE framework
Loading...
Searching...
No Matches
multigrid.h File Reference
#include "foreach_cell.h"
#include "neighbors.h"
#include "multigrid-common.h"
Include dependency graph for multigrid.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  Multigrid
 
struct  _Point
 

Macros

#define GRIDNAME   "Multigrid"
 
#define GHOSTS   2
 
#define ND(i)   ((size_t)(1 << point.level)*((int *)&Dimensions)[i])
 
#define _I   (point.i - GHOSTS)
 
#define _J   (point.j - GHOSTS)
 
#define _K   (point.k - GHOSTS)
 
#define _DELTA   (1./((1 << point.level)*Dimensions_scale))
 
#define multigrid   ((Multigrid *)grid)
 
#define CELL(m, level, i)   (*((Cell *) &m[level][(i)*datasize]))
 
#define SET_DIMENSIONS()
 
#define foreach_edge()   for (int _i = 0; _i < _N; _i++) /* foreach_face */
 
#define for   (int _i = 0; _i < _N; _i++) /* foreach_cell */ foreach_cell_restore()
 Similarly, on trees we need prolongation functions which also follow this definition.
 

Typedefs

typedef double real
 

Functions

undef val def val (a, k, l, m)(((real *)((Multigrid *) grid) -> d)[point.j+(l)+(point.i+(k)) *(((size_t)(1<< point.level) *((int *)&Dimensions)[1])+2 *2)+((Multigrid *) grid) ->shift[point.level]+_index(a, m) *((Multigrid *) grid) ->shift[depth()+1]]) @ @define allocated(...) true @def allocated_child(k, l, m)(level< depth() &&point.i > 0 &&point.i<=((size_t)(1<< point.level) *((int *)&Dimensions)[0])+2 &&point.j > 0 &&point.j<=((size_t)(1<< point.level) *((int *)&Dimensions)[1])+2) @ @define depth()(grid->depth) @def fine(a, k, l, m)(((real *)((Multigrid *) grid) ->d)[2 *point.j - 2+(l)+(2 *point.i - 2+(k)) *(((size_t)(1<< point.level) *((int *)&Dimensions)[1]) *2+2 *2)+((Multigrid *) grid) ->shift[point.level+1]+_index(a, m) *((Multigrid *) grid) ->shift[depth()+1]]) @ @def coarse(a, k, l, m)(((real *)((Multigrid *) grid) ->d)[(point.j+2)/2+(l)+((point.i+2)/2+(k)) *(((size_t)(1<< point.level) *((int *)&Dimensions)[1])/2+2 *2)+((Multigrid *) grid) ->shift[point.level - 1]+_index(a, m) *((Multigrid *) grid) ->shift[depth()+1]]) @ macro POINT_VARIABLES(Point point=point)
 
macro2 foreach (char flags=0, Reduce reductions=None)
 
define is_active() cell (true) @define is_leaf(cell)(point.level
 
static double periodic_bc (Point point, Point neighbor, scalar s, bool *data)
 
define neighborp (k, l, o) neighbor(k
 
define static o void box_boundary_level (const Boundary *b, scalar *scalars, int l)
 
 for (int _s=0;_s< 1;_s++) if(!is_constant(s) &&s.block > 0)
 
 if (!list1) return
 
 if (l==0)
 
 OMP_PARALLEL ()
 
 free (list1)
 
undef VT void free_grid (void)
 
int log_base2 (int n)
 
void init_grid (int n)
 
void realloc_scalar (int size)
 
Point locate (double xp=0, double yp=0, double zp=0)
 
ivec dimensions (int nx=0, int ny=0, int nz=0)
 

Variables

int Dimensions_scale = 1
 
static Point last_point
 
define l
 
define VT _attribute[s.i] v y scalarlist
 

Macro Definition Documentation

◆ _DELTA

#define _DELTA   (1./((1 << point.level)*Dimensions_scale))

Definition at line 32 of file multigrid.h.

◆ _I

#define _I   (point.i - GHOSTS)

Definition at line 27 of file multigrid.h.

◆ _J

#define _J   (point.j - GHOSTS)

Definition at line 28 of file multigrid.h.

◆ _K

#define _K   (point.k - GHOSTS)

Definition at line 29 of file multigrid.h.

◆ CELL

#define CELL (   m,
  level,
  i 
)    (*((Cell *) &m[level][(i)*datasize]))

Definition at line 70 of file multigrid.h.

◆ for

for   (int _i = 0; _i < _N; _i++) /* foreach_cell */ foreach_cell_restore()

Similarly, on trees we need prolongation functions which also follow this definition.

Once we have computed the fluxes on all faces, we can update the volume fraction field according to the one-dimensional advection equation.

Position of an interface

This is similar to curvature but this time for the position of the interface, defined as

\[ pos = \mathbf{G}\cdot(\mathbf{x} - \mathbf{Z}) \]

with \(\mathbf{G}\) and \(\mathbf{Z}\) two vectors and \(\mathbf{x}\) the coordinates of the interface.

This is defined only in interfacial cells. In all the other cells it takes the value nodata.

We first need a function to compute the position \(\mathbf{x}\) of an interface. For accuracy, we first try to use height functions.

Refinement/prolongation of face-centered velocity

This function is modelled on refine_face_x() and is typically used to refine the values of the face-centered velocity field uf. It uses linear interpolation, taking into account the weighting by the embedded fractions fs.

One-dimensional advection

The simplest way to implement a multi-dimensional VOF advection scheme is to use dimension-splitting i.e. advect the field along each dimension successively using a one-dimensional scheme.

We implement the one-dimensional scheme along the x-dimension and use the for (int _d = 0; _d < dimension; _d++) operator to automatically derive the corresponding functions along the other dimensions.

\[ \partial_tc = -\nabla_x\cdot(\mathbf{u}_f c) + c\nabla_x\cdot\mathbf{u}_f \]

The first term is computed using the fluxes. The second term – which is non-zero for the one-dimensional velocity field – is approximated using a centered volume fraction field cc which will be defined below.

For tracers, the corresponding one-dimensional update is

\[ \partial_tt_j = -\nabla_x\cdot(\mathbf{u}_f t_j) + t_j\nabla_x\cdot\mathbf{u}_f \]

The compressive second-term can be removed by defining the NO_1D_COMPRESSION macro.

To compute the volume fraction flux, we check the sign of the velocity component normal to the face and compute the index i of the corresponding upwind cell (either 0 or -1).

We also check that we are not violating the CFL condition.

If we assume that un is negative i.e. s is -1 and i is 0, the volume fraction flux through the face of the cell is given by the dark area in the figure below. The corresponding volume fraction can be computed using the rectangle_fraction() function.

Volume fraction flux

When the upwind cell is entirely full or empty we can avoid this computation.

Once we have the upwind volume fraction cf, the volume fraction flux through the face is simply:

If we are transporting tracers, we compute their flux using the upwind volume fraction cf and a tracer value upwinded using the Bell–Collela–Glaz scheme and the gradient computed above.

Definition at line 246 of file multigrid.h.

◆ foreach_edge

#define foreach_edge ( )    for (int _i = 0; _i < _N; _i++) /* foreach_face */

◆ GHOSTS

#define GHOSTS   2

Definition at line 12 of file multigrid.h.

◆ GRIDNAME

#define GRIDNAME   "Multigrid"

Definition at line 10 of file multigrid.h.

◆ multigrid

#define multigrid   ((Multigrid *)grid)

Definition at line 69 of file multigrid.h.

◆ ND

#define ND (   i)    ((size_t)(1 << point.level)*((int *)&Dimensions)[i])

Definition at line 24 of file multigrid.h.

◆ SET_DIMENSIONS

#define SET_DIMENSIONS ( )
Value:
point.n.x = (1 << point.level)*Dimensions.x, \
point.n.y = (1 << point.level)*Dimensions.y
ivec Dimensions
Definition common.h:173
Point point
Definition conserving.h:86
int level
Definition linear.h:23
int y
Definition common.h:142
int x
Definition common.h:140

Definition at line 235 of file multigrid.h.

Typedef Documentation

◆ real

Definition at line 6 of file multigrid.h.

Function Documentation

◆ box_boundary_level()

define static o void box_boundary_level ( const Boundary b,
scalar scalars,
int  l 
)
static

Definition at line 594 of file multigrid.h.

References BGHOSTS, d, default_scalar_bc, dimension, enable_fpe(), foreach_boundary_dir(), free(), scalar::i, is_vertex_scalar(), j, l, list, list_append(), neighborp(), periodic_bc(), point, s, v, and x.

Referenced by init_grid().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cell()

◆ dimensions()

ivec dimensions ( int  nx = 0,
int  ny = 0,
int  nz = 0 
)

Definition at line 938 of file multigrid.h.

References Dimensions, Dimensions_scale, max, x, ivec::x, and ivec::y.

◆ for()

for ( ) &&

Definition at line 712 of file multigrid.h.

References list_add(), periodic_bc(), periodic_bc(), right, s, and x.

Here is the call graph for this function:

◆ foreach()

macro2 foreach ( char  flags = 0,
Reduce  reductions = None 
)

Definition at line 267 of file multigrid.h.

References _k, depth, dimension, GHOSTS, Point::i, Point::level, OMP_PARALLEL(), point, reductions, SET_DIMENSIONS, and x.

Here is the call graph for this function:

◆ free()

free ( list1  )

Referenced by box_boundary_level(), free_grid(), and if().

Here is the caller graph for this function:

◆ free_grid()

undef VT void free_grid ( void  )

Definition at line 788 of file multigrid.h.

References free(), free_boundaries(), grid, m(), multigrid, and x.

Referenced by init_grid().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ if() [1/2]

if ( list1)

◆ if() [2/2]

if ( l  = = 0)

Definition at line 725 of file multigrid.h.

References b, free(), scalar::i, s, v, and x.

Here is the call graph for this function:

◆ init_grid()

void init_grid ( int  n)

Definition at line 807 of file multigrid.h.

References add_boundary(), all, b, box_boundary_level(), datasize, Grid::depth, depth, dimension, Dimensions, free_grid(), GHOSTS, grid, l, Point::level, log_base2(), m(), Grid::maxdepth, mpi_boundary_new(), Grid::n, N, n, periodic_boundary_level_x(), point, qcalloc, qmalloc, reset, SET_DIMENSIONS, size, Grid::tn, x, and ivec::x.

Here is the call graph for this function:

◆ locate()

Point locate ( double  xp = 0,
double  yp = 0,
double  zp = 0 
)

Definition at line 869 of file multigrid.h.

References depth, Dimensions, GHOSTS, Point::i, L0, Point::level, point, SET_DIMENSIONS, x, ivec::x, X0, Y0, and Z0.

◆ log_base2()

int log_base2 ( int  n)

Definition at line 800 of file multigrid.h.

References m(), and n.

Referenced by init_grid().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ neighborp()

define neighborp ( k  ,
l  ,
o   
)

Referenced by box_boundary_level().

Here is the caller graph for this function:

◆ OMP_PARALLEL()

OMP_PARALLEL ( )

Definition at line 738 of file multigrid.h.

References b, depth, GHOSTS, scalar::i, i, j, k, l, Point::level, point, s, SET_DIMENSIONS, and x.

Referenced by foreach().

Here is the caller graph for this function:

◆ periodic_bc()

static double periodic_bc ( Point  point,
Point  neighbor,
scalar  s,
bool data 
)
static

Referenced by box_boundary_level(), and for().

Here is the caller graph for this function:

◆ realloc_scalar()

void realloc_scalar ( int  size)

Definition at line 852 of file multigrid.h.

References datasize, depth, multigrid, p, size, and x.

◆ val()

undef val def val ( a  ,
k  ,
l  ,
m   
) -> d)[point.j + (l) + (point.i + (k))*(((size_t)(1 << point.level)*((int *)&Dimensions)[ 1 ]) + 2* 2 ) + ((Multigrid *)grid) ->shift[point.level] + _index(a,m)* ((Multigrid *)grid) ->shift[depth() + 1]]) @ @define allocated(...) true @def allocated_child(k,l,m) (level < depth() && point.i > 0 && point.i <= ((size_t)(1 << point.level)*((int *)&Dimensions)[ 0 ]) + 2 && point.j > 0 && point.j <= ((size_t)(1 << point.level)*((int *)&Dimensions)[ 1 ]) + 2) @ @define depth() (grid->depth) @def fine(a,k,l,m) (((real *) ((Multigrid *)grid) ->d)[2*point.j - 2 + (l) + (2*point.i - 2 + (k))*(((size_t)(1 << point.level)*((int *)&Dimensions)[ 1 ])*2 + 2* 2 ) + ((Multigrid *)grid) ->shift[point.level + 1] + _index(a,m)* ((Multigrid *)grid) ->shift[depth() + 1]]) @ @def coarse(a,k,l,m) (((real *) ((Multigrid *)grid) ->d)[(point.j + 2 )/2 + (l) + ((point.i + 2 )/2 + (k))*(((size_t)(1 << point.level)*((int *)&Dimensions)[ 1 ])/2 + 2* 2 ) + ((Multigrid *)grid) ->shift[point.level - 1] + _index(a,m)* ((Multigrid *)grid) ->shift[depth() + 1]]) @ macro POINT_VARIABLES (Point point = point)

Definition at line 81 of file multigrid.h.

References GHOSTS, Point::i, Point::level, level, point, VARIABLES(), and x.

Here is the call graph for this function:

Variable Documentation

◆ Dimensions_scale

int Dimensions_scale = 1

Definition at line 31 of file multigrid.h.

Referenced by dimensions().

◆ l

Initial value:
{
int x
Definition common.h:76

Definition at line 592 of file multigrid.h.

Referenced by box_boundary_level(), init_grid(), and OMP_PARALLEL().

◆ last_point

Point last_point
static

Definition at line 63 of file multigrid.h.

◆ list

Definition at line 709 of file multigrid.h.

Referenced by box_boundary_level().