PLUTO
sb_boundary.c
Go to the documentation of this file.
1 /* ///////////////////////////////////////////////////////////////////// */
2 /*!
3  \file
4  \brief Wrapper function to assign shearing-box boundary conditions.
5 
6  SB_Boundary() is a wrapper function used to assign shearing-box
7  boundary conditions on both cell-centered and staggered variables at
8  the X1_BEG and X1_END boundaries.
9  It is called as a regular boundary condition after periodic boundary
10  conditions have already been imposed on the solution arrays.\n
11  The function defines, for each type of variable (centered or staggered),
12  the corresponding boundary region where shearing conditions must be
13  applied using the RBox structure.
14  The actual boundary condition is imposed by calling SB_SetBoundaryVar()
15  with the desired array and its box layout.
16 
17  \authors A. Mignone (mignone@ph.unito.it)\n
18  G. Muscianisi (g.muscianisi@cineca.it)
19  \date Jan 31, 2014
20 */
21 /* ///////////////////////////////////////////////////////////////////// */
22 #include "pluto.h"
23 
24 double sb_vy;
25 
26 /* ********************************************************************* */
27 void SB_Boundary (const Data *d, int side, Grid *grid)
28 /*!
29  * Main wrapper function used to assign shearing-box boundary conditions
30  * on flow variables.
31  *
32  * \param d pointer to the PLUTO Data structure
33  * \param side the side of the computational domain (X1_BEG or X1_END)
34  * \param grid pointer to an array of Grid structures
35  *
36  * \return This function has no return value.
37  *
38  * \todo Check if sb_vy needs to be global.
39  *********************************************************************** */
40 {
41  int i, j, k, nv;
42  double t, Lx;
43  RBox box;
44 
45  Lx = g_domEnd[IDIR] - g_domBeg[IDIR];
46  sb_vy = fabs(2.0*SB_A*Lx);
47 
48 {
49 t = g_time;
50 #if TIME_STEPPING == RK2
51  if (g_intStage == 2) t += g_dt;
52 #elif TIME_STEPPING == RK3
53  if (g_intStage == 2) t += 0.5*g_dt;
54  if (g_intStage == 3) t += g_dt;
55 #endif
56 #ifdef CTU
57  if (g_intStage == 2) t += 0.5*g_dt;
58 #endif
59 }
60 
61 /* -------------------------------------------------
62  X1 Beg Boundary
63  ------------------------------------------------- */
64 
65  if (side == X1_BEG){
66 
67  /* ---- loop on cell-centered variables ---- */
68 
69  box.ib = 0; box.ie = IBEG-1;
70  box.jb = 0; box.je = NX2_TOT-1;
71  box.kb = 0; box.ke = NX3_TOT-1;
72  for (nv = 0; nv < NVAR; nv++){
73 
74  #ifdef STAGGERED_MHD
75  D_EXPAND(if (nv == BX) continue; ,
76  if (nv == BY) continue; ,
77  if (nv == BZ) continue;)
78  #endif
79 
80  SB_SetBoundaryVar(d->Vc[nv], &box, side, t, grid);
81  if (nv == VY) {
82  X1_BEG_LOOP(k,j,i) d->Vc[nv][k][j][i] += sb_vy;
83  }
84  } /* -- end loop on cell-centered variables -- */
85 
86  #ifdef STAGGERED_MHD
87  box.ib = 0; box.ie = IBEG-1;
88  box.jb = -1; box.je = NX2_TOT-1;
89  box.kb = 0; box.ke = NX3_TOT-1;
90  SB_SetBoundaryVar(d->Vs[BX2s], &box, side, t, grid);
91  #if DIMENSIONS == 3
92  box.ib = 0; box.ie = IBEG-1;
93  box.jb = 0; box.je = NX2_TOT-1;
94  box.kb = -1; box.ke = NX3_TOT-1;
95  SB_SetBoundaryVar(d->Vs[BX3s], &box, side, t, grid);
96  #endif
97  #endif /* STAGGERED_MHD */
98  } /* -- END side X1_BEG -- */
99 
100 /* -------------------------------------------------
101  X1 End Boundary
102  ------------------------------------------------- */
103 
104  if (side == X1_END){
105 
106  /* ---- loop on cell-centered variables ---- */
107 
108  box.ib = IEND+1; box.ie = NX1_TOT-1;
109  box.jb = 0; box.je = NX2_TOT-1;
110  box.kb = 0; box.ke = NX3_TOT-1;
111  for (nv = 0; nv < NVAR; nv++){
112 
113  #ifdef STAGGERED_MHD
114  D_EXPAND(if (nv == BX) continue; ,
115  if (nv == BY) continue; ,
116  if (nv == BZ) continue;)
117  #endif
118 
119  SB_SetBoundaryVar(d->Vc[nv], &box, side, t, grid);
120  if (nv == VY){
121  X1_END_LOOP(k,j,i) d->Vc[nv][k][j][i] -= sb_vy;
122  }
123  } /* -- end loop on cell-centered variables -- */
124 
125  #ifdef STAGGERED_MHD
126  box.ib = IEND+1; box.ie = NX1_TOT-1;
127  box.jb = -1; box.je = NX2_TOT-1;
128  box.kb = 0; box.ke = NX3_TOT-1;
129  SB_SetBoundaryVar(d->Vs[BX2s], &box, side, t, grid);
130  #if DIMENSIONS == 3
131  box.ib = IEND+1; box.ie = NX1_TOT-1;
132  box.jb = 0; box.je = NX2_TOT-1;
133  box.kb = -1; box.ke = NX3_TOT-1;
134  SB_SetBoundaryVar(d->Vs[BX3s], &box, side, t, grid);
135  #endif /* DIMENSIONS == 3 */
136  #endif /* STAGGERED_MHD */
137  }
138 }
#define BY
Definition: mod_defs.h:109
#define X1_BEG
Boundary region at X1 beg.
Definition: pluto.h:146
double **** Vs
The main four-index data array used for face-centered staggered magnetic fields.
Definition: structs.h:43
int jb
Lower corner index in the x2 direction.
Definition: structs.h:349
void SB_Boundary(const Data *d, int side, Grid *grid)
Definition: sb_boundary.c:27
#define BZ
Definition: mod_defs.h:110
long int NX2_TOT
Total number of zones in the X2 direction (boundaries included) for the local processor.
Definition: globals.h:57
int g_intStage
Gives the current integration stage of the time stepping method (predictor = 0, 1st corrector = 1...
Definition: globals.h:98
double **** Vc
The main four-index data array used for cell-centered primitive variables.
Definition: structs.h:31
int kb
Lower corner index in the x3 direction.
Definition: structs.h:351
double g_dt
The current integration time step.
Definition: globals.h:118
#define VY
Definition: mod_defs.h:101
#define BX3s
Definition: ct.h:29
#define X1_END
Boundary region at X1 end.
Definition: pluto.h:147
int ib
Lower corner index in the x1 direction.
Definition: structs.h:347
#define BX
Definition: mod_defs.h:108
#define IDIR
Definition: pluto.h:193
Definition: structs.h:78
long int NX3_TOT
Total number of zones in the X3 direction (boundaries included) for the local processor.
Definition: globals.h:59
int j
Definition: analysis.c:2
long int IEND
Upper grid index of the computational domain in the the X1 direction for the local processor...
Definition: globals.h:37
int k
Definition: analysis.c:2
double sb_vy
Velocity offset (>0), in SB_Boundary().
Definition: sb_boundary.c:24
double g_domBeg[3]
Lower limits of the computational domain.
Definition: globals.h:125
void SB_SetBoundaryVar(double ***U, RBox *box, int side, double t, Grid *grid)
Definition: sb_tools.c:36
#define X1_END_LOOP(k, j, i)
Definition: macros.h:50
PLUTO main header file.
D_EXPAND(tot/[n]=(double) grid[IDIR].np_int_glob;, tot/[n]=(double) grid[JDIR].np_int_glob;, tot/[n]=(double) grid[KDIR].np_int_glob;)
Definition: analysis.c:27
#define X1_BEG_LOOP(k, j, i)
Definition: macros.h:46
Definition: structs.h:30
int i
Definition: analysis.c:2
double g_time
The current integration time.
Definition: globals.h:117
int ie
Upper corner index in the x1 direction.
Definition: structs.h:348
int ke
Upper corner index in the x3 direction.
Definition: structs.h:352
int je
Upper corner index in the x2 direction.
Definition: structs.h:350
#define SB_A
Short-hand definition for the Oort constant .
Definition: shearingbox.h:96
#define BX2s
Definition: ct.h:28
double g_domEnd[3]
Upper limits of the computational domain.
Definition: globals.h:126
#define NVAR
Definition: pluto.h:609
Definition: structs.h:346
long int NX1_TOT
Total number of zones in the X1 direction (boundaries included) for the local processor.
Definition: globals.h:55
long int IBEG
Lower grid index of the computational domain in the the X1 direction for the local processor...
Definition: globals.h:35