Poisson solver

Name

Poisson solver -- 

Synopsis


#include <gfs.h>


            GfsMultilevelParams;

void        gfs_multilevel_params_init      (GfsMultilevelParams *par);
void        gfs_multilevel_params_read      (GfsMultilevelParams *par,
                                             GtsFile *fp);
void        gfs_multilevel_params_write     (GfsMultilevelParams *par,
                                             FILE *fp);

void        gfs_relax                       (GfsDomain *domain,
                                             guint d,
                                             gint max_depth,
                                             GfsVariable *u,
                                             GfsVariable *rhs,
                                             GfsVariable *dia);
void        gfs_residual                    (GfsDomain *domain,
                                             guint d,
                                             FttTraverseFlags flags,
                                             gint max_depth,
                                             GfsVariable *u,
                                             GfsVariable *rhs,
                                             GfsVariable *dia,
                                             GfsVariable *res);
void        gfs_poisson_coefficients        (GfsDomain *domain,
                                             GfsFunction *alpha);
void        gfs_poisson_cycle               (GfsDomain *domain,
                                             GfsMultilevelParams *p,
                                             GfsVariable *u,
                                             GfsVariable *rhs,
                                             GfsVariable *dia,
                                             GfsVariable *res);

void        gfs_correct_normal_velocities   (GfsDomain *domain,
                                             guint dimension,
                                             GfsVariable *p,
                                             GfsVariable **g,
                                             gdouble dt,
                                             GfsVariable *w);
void        gfs_mac_projection              (GfsDomain *domain,
                                             GfsMultilevelParams *par,
                                             GfsAdvectionParams *apar,
                                             GfsVariable *p,
                                             GfsFunction *alpha,
                                             GfsVariable **g);
void        gfs_approximate_projection      (GfsDomain *domain,
                                             GfsMultilevelParams *par,
                                             GfsAdvectionParams *apar,
                                             GfsVariable *p,
                                             GfsFunction *alpha,
                                             GfsVariable *res);
GfsNorm     gfs_domain_norm_residual        (GfsDomain *domain,
                                             FttTraverseFlags flags,
                                             gint max_depth,
                                             gdouble dt,
                                             GfsVariable *res);

Description

Details

GfsMultilevelParams

typedef struct {
  gdouble tolerance;
  guint nrelax, erelax;
  guint minlevel;
  guint nitermax, nitermin;

  guint dimension;
  guint niter;
  guint depth;
  gboolean weighted;
  gdouble beta;
  GfsNorm residual_before, residual;
} GfsMultilevelParams;


gfs_multilevel_params_init ()

void        gfs_multilevel_params_init      (GfsMultilevelParams *par);

par :


gfs_multilevel_params_read ()

void        gfs_multilevel_params_read      (GfsMultilevelParams *par,
                                             GtsFile *fp);

par :

fp :


gfs_multilevel_params_write ()

void        gfs_multilevel_params_write     (GfsMultilevelParams *par,
                                             FILE *fp);

Writes in fp a text representation of the multilevel parameters par.

par :

the multilevel parameters.

fp :

a file pointer.


gfs_relax ()

void        gfs_relax                       (GfsDomain *domain,
                                             guint d,
                                             gint max_depth,
                                             GfsVariable *u,
                                             GfsVariable *rhs,
                                             GfsVariable *dia);

Apply one pass of a Jacobi relaxation to all the leaf cells of domain with a level inferior or equal to max_depth and to all the cells at level max_depth. The relaxation should converge (if the right-hand-side rhs verifies the solvability conditions) toward the solution of a Poisson equation for u at the maximum depth.

domain :

the domain to relax.

d :

number of dimensions (2 or 3).

max_depth :

the maximum depth of the domain to relax.

u :

the variable to use as left-hand side.

rhs :

the variable to use as right-hand side.

dia :

the diagonal weight.


gfs_residual ()

void        gfs_residual                    (GfsDomain *domain,
                                             guint d,
                                             FttTraverseFlags flags,
                                             gint max_depth,
                                             GfsVariable *u,
                                             GfsVariable *rhs,
                                             GfsVariable *dia,
                                             GfsVariable *res);

For each cell of domain, computes the sum of the residual over the volume of the cell for a Poisson equation with u as left-hand-side and rhs as right-hand-side. Stores the result in res.

domain :

a domain.

d :

number of dimensions (2 or 3).

flags :

which types of cells are to be visited.

max_depth :

maximum depth of the traversal.

u :

the variable to use as left-hand side.

rhs :

the variable to use as right-hand side.

dia :

the diagonal weight.

res :

the variable to use to store the residual.


gfs_poisson_coefficients ()

void        gfs_poisson_coefficients        (GfsDomain *domain,
                                             GfsFunction *alpha);

Initializes the face coefficients for the Poisson equation $\nabla\cdot\alpha\nabla p=\dots$.

If alpha is NULL, it is taken to be unity.

domain :

a GfsDomain.

alpha :

the inverse of density or NULL.


gfs_poisson_cycle ()

void        gfs_poisson_cycle               (GfsDomain *domain,
                                             GfsMultilevelParams *p,
                                             GfsVariable *u,
                                             GfsVariable *rhs,
                                             GfsVariable *dia,
                                             GfsVariable *res);

Apply one multigrid iteration to the Poisson equation defined by u and rhs.

The initial value of res on the leaves of root must be set to the residual of the Poisson equation (using gfs_residual()).

The face coefficients must be set using gfs_poisson_coefficients().

The values of u on the leaf cells are updated as well as the values of res (i.e. the cell tree is ready for another iteration).

domain :

the domain on which to solve the Poisson equation.

p :

the GfsMultilevelParams.

u :

the variable to use as left-hand side.

rhs :

the variable to use as right-hand side.

dia :

the diagonal weight.

res :

the residual.


gfs_correct_normal_velocities ()

void        gfs_correct_normal_velocities   (GfsDomain *domain,
                                             guint dimension,
                                             GfsVariable *p,
                                             GfsVariable **g,
                                             gdouble dt,
                                             GfsVariable *w);

Corrects the normal velocity field of domain using p and and dt.

Also allocates the g variables (if g is not NULL) and fills them with the centered gradient of p.

domain :

a GfsDomain.

dimension :

the number of dimensions (2 or 3).

p :

the pressure field.

g :

where to store the pressure gradient or NULL.

dt :

the timestep.

w :

an optional weight to apply to the correction.


gfs_mac_projection ()

void        gfs_mac_projection              (GfsDomain *domain,
                                             GfsMultilevelParams *par,
                                             GfsAdvectionParams *apar,
                                             GfsVariable *p,
                                             GfsFunction *alpha,
                                             GfsVariable **g);

Corrects the face-centered velocity field (MAC field) on the leaf level of domain using an exact (MAC) projection. The resulting face-centered velocity field is (almost) exactly divergence free. The (potential) pressure field is also obtained as a by-product as well as its gradient at the center of the leaf cells of the domain. The gradient is stored in newly-allocated g[] variables and is obtained by simple averaging from the face values to the center. The newly-allocated g[] variables should be freed when not needed anymore.

The residual field of the par projection parameters is set to the norm of the residual after the projection. The niter field of the par projection parameters is set to the number of iterations performed to solve the Poisson equation. The other projection parameters are not modified.

domain :

a GfsDomain.

par :

the projection control parameters.

apar :

the advection parameters.

p :

the pressure.

alpha :

the Poisson equation gradient weight.

g :

where to store the pressure gradient.


gfs_approximate_projection ()

void        gfs_approximate_projection      (GfsDomain *domain,
                                             GfsMultilevelParams *par,
                                             GfsAdvectionParams *apar,
                                             GfsVariable *p,
                                             GfsFunction *alpha,
                                             GfsVariable *res);

Corrects the centered velocity field on the leaf level of domain using an approximate projection. The resulting centered velocity field is approximately divergence free. The (potential) pressure field is also obtained as a by-product.

The residual field of the par projection parameters is set to the norm of the residual (on the MAC grid) after the projection. The niter field of the par projection parameters is set to the number of iterations performed to solve the Poisson equation. The other projection parameters are not modified.

The Poisson equation for the pressure is first solved on a MAC grid where the MAC velocities are obtained from the centered velocities by simple averaging. The resulting pressure gradients (defined on the faces) are then averaged down on the center of the cells to correct the centered velocity.

domain :

a GfsDomain.

par :

the projection control parameters.

apar :

the advection parameters.

p :

the pressure.

alpha :

the Poisson equation gradient weight.

res :

the residual or NULL.


gfs_domain_norm_residual ()

GfsNorm     gfs_domain_norm_residual        (GfsDomain *domain,
                                             FttTraverseFlags flags,
                                             gint max_depth,
                                             gdouble dt,
                                             GfsVariable *res);

Traverses the domain defined by domain using gfs_domain_cell_traverse() and gathers norm statistics about the volume weighted relative residual (i.e. the sum of the residual over the volume defined by each cell divided by the total volume of the cell).

domain :

the domain to obtain the norm from.

flags :

which types of cells are to be visited.

max_depth :

maximum depth of the traversal.

dt :

the time step.

res :

the residual.

Returns :

a GfsNorm containing the norm statistics about the volume weighted relative residual.