URI:
       tboundary.c - ns2dfd - 2D finite difference Navier Stokes solver for fluid dynamics
  HTML git clone git://src.adamsgaard.dk/ns2dfd
   DIR Log
   DIR Files
   DIR Refs
   DIR LICENSE
       ---
       tboundary.c (2521B)
       ---
            1 #define BC_FREE_SLIP 1
            2 #define BC_NO_SLIP 2
            3 #define BC_OUTFLOW 3
            4 #define BC_PERIODIC 4
            5 
            6 /* Set boundary values of u, v and p according to the boundary conditions.
            7  * The BC flags are as follows:
            8  *   1: Free-slip condition
            9  *   2: No-slip condition
           10  *   3: Outflow condition
           11  *   4: Periodic condition
           12  */
           13 void set_boundary_conditions(int w_left, int w_right, int w_top, int w_bottom,
           14         double **P, double **U, double **V, int nx, int ny)
           15 {
           16     int i, j;
           17 
           18     /* vertical boundaries (left and right) */
           19     for (j=1; j<ny+1; j++) {
           20 
           21         if (w_left == BC_FREE_SLIP) {
           22             U[0][j] = 0.0;
           23             V[0][j] = V[1][j];
           24         } else if (w_left == BC_NO_SLIP) {
           25             U[0][j] = 0.0;
           26             V[0][j] = -1.0*V[1][j];
           27         } else if (w_left == BC_OUTFLOW) {
           28             U[0][j] = U[1][j];
           29             V[0][j] = V[1][j];
           30         } else if (w_left == BC_PERIODIC) {
           31             U[0][j] = U[nx-1][j];
           32             V[0][j] = V[nx-1][j];
           33             V[1][j] = V[nx][j];
           34             P[1][j] = P[nx][j];
           35         }
           36 
           37         if (w_right == BC_FREE_SLIP) {
           38             U[nx][j] = 0.0;
           39             V[nx+1][j] = V[nx][j];
           40         } else if (w_right == BC_NO_SLIP) {
           41             U[nx][j] = 0.0;
           42             V[nx+1][j] = -1.0*V[nx][j];
           43         } else if (w_right == BC_OUTFLOW) {
           44             U[nx][j] = U[nx-1][j];
           45             V[nx+1][j] = V[nx][j];
           46         } else if (w_right == BC_PERIODIC) {
           47             U[nx][j] = U[1][j];
           48             V[nx+1][j] = V[2][j];
           49         }
           50     }
           51 
           52     /* horizontal boundaries (bottom and top) */
           53     for (i=1; i<nx+1; i++) {
           54 
           55         if (w_bottom == BC_FREE_SLIP) {
           56             U[i][0] = U[i][1];
           57             V[i][0] = 0.0;
           58         } else if (w_bottom == BC_NO_SLIP) {
           59             U[i][0] = -1.0*U[i][1];
           60             V[i][0] = 0.0;
           61         } else if (w_bottom == BC_OUTFLOW) {
           62             U[i][0] = U[i][1];
           63             V[i][0] = V[i][1];
           64         } else if (w_bottom == BC_PERIODIC) {
           65             U[i][0] = U[i][ny-1];
           66             U[i][1] = U[i][nx-1];
           67             V[i][0] = V[i][ny-1];
           68             P[i][1] = P[i][ny];
           69         }
           70 
           71         if (w_top == BC_FREE_SLIP) {
           72             U[i][ny+1] = U[i][ny];
           73             V[i][ny] = 0.0;
           74         } else if (w_top == BC_NO_SLIP) {
           75             U[i][ny+1] = -1.0*U[i][ny];
           76             V[i][ny] = 0.0;
           77         } else if (w_top == BC_OUTFLOW) {
           78             U[i][ny+1] = U[i][ny];
           79             V[i][ny] = V[i][ny-1];
           80         } else if (w_top == BC_PERIODIC) {
           81             U[i][ny+1] = U[i][2];
           82             V[i][ny] = V[i][1];
           83         }
           84     }
           85 }