PLUTO
rk_step.c File Reference

Advance equations with Runge Kutta time integrators. More...

#include "pluto.h"
Include dependency graph for rk_step.c:

Go to the source code of this file.

Macros

#define w0   0.5
 
#define wc   0.5
 

Functions

int AdvanceStep (const Data *d, Riemann_Solver *Riemann, Time_Step *Dts, Grid *grid)
 

Detailed Description

Advance equations with Runge Kutta time integrators.

Main driver for RK split/unsplit integrations and finite difference methods (RK3). Time stepping include Euler, RK2 and RK3.

Authors
A. Mignone (migno.nosp@m.ne@p.nosp@m.h.uni.nosp@m.to.i.nosp@m.t)
P. Tzeferacos (petro.nosp@m.s.tz.nosp@m.efera.nosp@m.cos@.nosp@m.ph.un.nosp@m.ito..nosp@m.it)
Date
Dec 18, 2014

Definition in file rk_step.c.

Macro Definition Documentation

#define w0   0.5

Definition at line 20 of file rk_step.c.

#define wc   0.5

Definition at line 21 of file rk_step.c.

Function Documentation

int AdvanceStep ( const Data d,
Riemann_Solver Riemann,
Time_Step Dts,
Grid grid 
)

Advance the equations by a single time step using unsplit integrators based on the method of lines.

Parameters
[in,out]dpointer to Data structure
[in]Riemannpointer to a Riemann solver function
[in,out]Dtspointer to time step structure
[in]gridpointer to array of Grid structures

Definition at line 28 of file rk_step.c.

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 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
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
#define w0
Definition: rk_step.c:20
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
void CT_AverageMagneticField(double ****bf, double ****UU, Grid *grid)
#define ALL_DIR
Definition: pluto.h:196

Here is the call graph for this function:

Here is the caller graph for this function: