PLUTO
rk_step.c
Go to the documentation of this file.
1 /* ///////////////////////////////////////////////////////////////////// */
2 /*!
3  \file
4  \brief Advance equations with Runge Kutta time integrators.
5 
6  Main driver for RK split/unsplit integrations and finite difference
7  methods (RK3).
8  Time stepping include Euler, RK2 and RK3.
9 
10  \authors A. Mignone (mignone@ph.unito.it)\n
11  P. Tzeferacos (petros.tzeferacos@ph.unito.it)
12  \date Dec 18, 2014
13 */
14 /* ///////////////////////////////////////////////////////////////////// */
15 #include "pluto.h"
16 
17 /* Weight factor for 2nd stage of RK integrators */
18 
19 #if TIME_STEPPING == RK2
20  #define w0 0.5
21  #define wc 0.5
22 #elif TIME_STEPPING == RK3
23  #define w0 0.75
24  #define wc 0.25
25 #endif
26 
27 /* ********************************************************************* */
28 int AdvanceStep (const Data *d, Riemann_Solver *Riemann,
29  Time_Step *Dts, Grid *grid)
30 /*!
31  * Advance the equations by a single time step using unsplit
32  * integrators based on the method of lines.
33  *
34  * \param [in,out] d pointer to Data structure
35  * \param [in] Riemann pointer to a Riemann solver function
36  * \param [in,out] Dts pointer to time step structure
37  * \param [in] grid pointer to array of Grid structures
38  *
39  *********************************************************************** */
40 {
41  int i, j, k, nv;
42  static double one_third = 1.0/3.0;
43  static Data_Arr U0, Bs0;
44  RBox *box = GetRBox (DOM, CENTER);
45 
46 /* ----------------------------------------------------
47  0. Allocate memory
48  ---------------------------------------------------- */
49 
50  if (U0 == NULL){
51  U0 = ARRAY_4D(NX3_TOT, NX2_TOT, NX1_TOT, NVAR, double);
52  #ifdef STAGGERED_MHD
53  Bs0 = ARRAY_4D(DIMENSIONS, NX3_TOT, NX2_TOT, NX1_TOT, double);
54  #endif
55  }
56 
57 #ifdef FARGO
58  FARGO_SubtractVelocity (d,grid);
59 #endif
60 
61 /* ---------------------------------------------------------------
62  1. Predictor step (EULER, RK2, RK3)
63 
64  After baoundaries have been set we flag zones lying in a
65  shock. This is useful for shock flattening or entropy/energy
66  selective update.
67 
68  Note: when using FARGO, boundary condition must be set on
69  the *total* velocity while the update step is performed on
70  the *residual* velocity.
71  For this reason we add/subtract the mean velocity field
72  immediately before/after setting the boundary conditions.
73  --------------------------------------------------------------- */
74 
75  g_intStage = 1;
76  Boundary (d, ALL_DIR, grid);
77 #if (SHOCK_FLATTENING == MULTID) || (ENTROPY_SWITCH)
78  FlagShock (d, grid);
79 #endif
80 
81 /* -- Convert primitive to conservative, save initial stage -- */
82 
83  PrimToCons3D(d->Vc, d->Uc, box);
84  KDOM_LOOP(k) JDOM_LOOP(j){
85  memcpy ((void *)U0[k][j][IBEG], d->Uc[k][j][IBEG], NX1*NVAR*sizeof(double));
86  }
87 #ifdef STAGGERED_MHD
88  DIM_LOOP(nv) TOT_LOOP(k,j,i) Bs0[nv][k][j][i] = d->Vs[nv][k][j][i];
89 #endif
90 
91  UpdateStage(d, d->Uc, NULL, Riemann, g_dt, Dts, grid);
92 #ifdef STAGGERED_MHD
93  CT_AverageMagneticField (d->Vs, d->Uc, grid);
94 #endif
95  ConsToPrim3D (d->Uc, d->Vc, d->flag, box);
96 
97 /* ----------------------------------------------------
98  2. Corrector step (RK2, RK3)
99  ---------------------------------------------------- */
100 
101 #if (TIME_STEPPING == RK2) || (TIME_STEPPING == RK3)
102 
103  g_intStage = 2;
104  Boundary (d, ALL_DIR, grid);
105 
106 /* -- need an extra conversion if INTERNAL_BOUNDARY is enabled
107  [note: done only with dimensional splitting for backward compat.] -- */
108 
109  #if (INTERNAL_BOUNDARY == YES) && (DIMENSIONAL_SPLITTING == YES)
110  PrimToCons3D (d->Vc, d->Uc, box);
111  #endif
112 
113  UpdateStage(d, d->Uc, NULL, Riemann, g_dt, Dts, grid);
114  DOM_LOOP(k, j, i) VAR_LOOP(nv){
115  d->Uc[k][j][i][nv] = w0*U0[k][j][i][nv] + wc*d->Uc[k][j][i][nv];
116  }
117  #ifdef STAGGERED_MHD
118  DIM_LOOP(nv) TOT_LOOP(k,j,i) {
119  d->Vs[nv][k][j][i] = w0*Bs0[nv][k][j][i] + wc*d->Vs[nv][k][j][i];
120  }
121  CT_AverageMagneticField (d->Vs, d->Uc, grid);
122  #endif
123 
124  #if (defined FARGO) && (TIME_STEPPING == RK2)
125  FARGO_ShiftSolution (d->Uc, d->Vs, grid);
126  #endif
127  ConsToPrim3D (d->Uc, d->Vc, d->flag, box);
128 
129 #endif /* TIME_STEPPING == RK2/RK3 */
130 
131 /* ----------------------------------------------------
132  3. Last corrector step (RK3 only)
133  ---------------------------------------------------- */
134 
135 #if TIME_STEPPING == RK3
136  g_intStage = 3;
137  Boundary (d, ALL_DIR, grid);
138 
139 /* -- need an extra conversion if INTERNAL_BOUNDARY is enabled -- */
140 
141  #if (INTERNAL_BOUNDARY == YES) && (DIMENSIONAL_SPLITTING == YES)
142  PrimToCons3D (d->Vc, d->Uc, box);
143  #endif
144 
145  UpdateStage(d, d->Uc, NULL, Riemann, g_dt, Dts, grid);
146  DOM_LOOP(k,j,i) VAR_LOOP(nv){
147  d->Uc[k][j][i][nv] = one_third*(U0[k][j][i][nv] + 2.0*d->Uc[k][j][i][nv]);
148  }
149  #ifdef STAGGERED_MHD
150  DIM_LOOP(nv) TOT_LOOP(k,j,i){
151  d->Vs[nv][k][j][i] = (Bs0[nv][k][j][i] + 2.0*d->Vs[nv][k][j][i])/3.0;
152  }
153  CT_AverageMagneticField (d->Vs, d->Uc, grid);
154  #endif
155 
156  #ifdef FARGO
157  FARGO_ShiftSolution (d->Uc, d->Vs, grid);
158  #endif
159  ConsToPrim3D (d->Uc, d->Vc, d->flag, box);
160 #endif /* TIME_STEPPING == RK3 */
161 
162 
163 #ifdef FARGO
164  FARGO_AddVelocity (d,grid);
165 #endif
166 
167  return 0; /* -- step has been achieved, return success -- */
168 }
void Boundary(const Data *d, int idim, Grid *grid)
Definition: boundary.c:36
double **** Vs
The main four-index data array used for face-centered staggered magnetic fields.
Definition: structs.h:43
#define KDOM_LOOP(k)
Definition: macros.h:36
double **** Data_Arr
Definition: pluto.h:492
DOM_LOOP(k, j, i)
Definition: analysis.c:22
#define DIM_LOOP(d)
Definition: macros.h:227
RBox * GetRBox(int, int)
Definition: rbox.c:232
long int NX1
Number of interior zones in the X1 directions (boundaries excluded) for the local processor...
Definition: globals.h:48
#define CENTER
Definition: pluto.h:200
void Riemann_Solver(const State_1D *, int, int, double *, Grid *)
Definition: pluto.h:489
void PrimToCons3D(Data_Arr V, Data_Arr U, RBox *box)
Definition: mappers3D.c:86
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
double g_dt
The current integration time step.
Definition: globals.h:118
#define DOM
Computational domain (interior)
Definition: pluto.h:152
void FARGO_ShiftSolution(Data_Arr U, Data_Arr Us, Grid *grid)
Definition: fargo.c:42
void FARGO_AddVelocity(const Data *, Grid *)
unsigned char *** flag
Pointer to a 3D array setting useful integration flags that are retrieved during integration.
Definition: structs.h:55
void ConsToPrim3D(Data_Arr U, Data_Arr V, unsigned char ***flag, RBox *box)
Definition: mappers3D.c:16
#define JDOM_LOOP(j)
Definition: macros.h:35
void FARGO_SubtractVelocity(const Data *, Grid *)
#define VAR_LOOP(n)
Definition: macros.h:226
#define TOT_LOOP(k, j, i)
Definition: macros.h:44
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
#define ARRAY_4D(nx, ny, nz, nv, type)
Definition: prototypes.h:173
int k
Definition: analysis.c:2
PLUTO main header file.
#define w0
Definition: rk_step.c:20
Definition: structs.h:30
int i
Definition: analysis.c:2
#define wc
Definition: rk_step.c:21
double **** Uc
The main four-index data array used for cell-centered conservative variables.
Definition: structs.h:37
void UpdateStage(const Data *, Data_Arr, double **, Riemann_Solver *, double, Time_Step *, Grid *)
Definition: update_stage.c:38
void FlagShock(const Data *, Grid *)
#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
#define DIMENSIONS
Definition: definitions_01.h:2
int AdvanceStep(const Data *d, Riemann_Solver *Riemann, Time_Step *Dts, Grid *grid)
Definition: rk_step.c:28
void CT_AverageMagneticField(double ****bf, double ****UU, Grid *grid)
#define ALL_DIR
Definition: pluto.h:196