PLUTO
init.c
Go to the documentation of this file.
1 /* ///////////////////////////////////////////////////////////////////// */
2 /*!
3  \file
4  \brief Rayleigh-Taylor instability setup for hydro or MHD.
5 
6  Sets the initial condition for a Rayleigh-Taylor instability
7  problem in 2 or 3 dimensions.
8  The initial condition consists of an interface separating two
9  fluids with different densities in hydrostatic balance:
10  \f[
11  \rho(y) = \left\{\begin{array}{ll}
12  1 & \quad{\rm for} \quad y \le 0 \\ \noalign{\medskip}
13  \eta & \quad{\rm for} \quad y > 0
14  \end{array}\right.
15  \,,\qquad
16  p = p_0 + \rho y g
17  \f]
18  where \f$ \eta \f$ is the density of the fluid on top, \c g is the
19  (constant) gravity pointing in the negative \c y direction.
20  The value of the pressure at the interface (\c p0) is chosen in such
21  a way that the sound speed in the light fluid is 1.
22  Likewise, density is normalized to the value in the light fluid.
23  The horizontal extent of the computational domain defines the unit length:
24  \c Lx=1.
25 
26  For magnetized setups, the magnetic field is purely horizontal:
27  \f[
28  \vec{B} = \chi B_c\hvec{i} \,,\qquad
29  B_c \equiv \sqrt{(\rho_{\rm hi} - \rho_{\rm lo})L|g|}\quad \to\quad
30  \sqrt{(\eta - 1.0)|g|}
31  \f]
32  where \c Bc is the critical magnetic field above which perturbations
33  parallel to the magnetic field are suppressed (see Boyd
34  & Sanderson, page 99) while the value of \f$\chi\f$ is user-supplied
35  (note that a factor \f$ 1/\sqrt{4\pi} \f$ needs to be incorporated
36  when initializing \c B in code units).
37 
38  The system is destabilized by perturbing the vertical velocity in
39  proximity of the interface using a single mode (in 2D) or a Gaussian
40  perturbation (in 3D).
41  Aleternatively, a random perturbation can be used by setting
42  \c USE_RANDOM_PERTURBATION to \c YES in your \c definitions.h.
43  The runtime parameters that are read from \c pluto.ini are
44  - <tt>g_inputParam[ETA]</tt>: sets the density of the upper fluid;
45  - <tt>g_inputParam[GRAV]</tt>: sets gravity (must be < 0);
46  - <tt>g_inputParam[CHI]</tt>: sets the magnetic field strength in unit
47  of the critical magnetic field \c Bc;
48 
49  \note Increasing the value of \c p0 by a factor \c q^2 is equivalent
50  to increase gravity of the same factor and decrease velocity
51  and time by a factor \c q.
52 
53  The Rayleigh-Taylor setup has been tested with the following
54  configurations:
55 
56  <CENTER>
57  Conf.|PHYSICS| GEOMETRY |DIM| T. STEP.|INTERP. |divB| Notes
58  -----|-------|----------|---|---------| --------|----|----------
59  #01 | HD |CARTESIAN | 2 | HANCOCK |LINEAR | - | -
60  #02 | HD |CARTESIAN | 2 | RK3 |MP5_FD | - | -
61  #03 | HD |CARTESIAN | 2 | RK3 |PARABOLIC| - | -
62  #04 | HD |CARTESIAN | 2 | RK2 |LINEAR | - | (*)
63  #05 | MHD |CARTESIAN | 2 | HANCOCK |LINEAR | CT | -
64  #06 | MHD |CARTESIAN | 2 | RK3 |MP5_FD |GLM | -
65  #07 | MHD |CARTESIAN | 2 | RK3 |PARABOLIC| CT | -
66  #08 | MHD |CARTESIAN | 2 | ChTr |PARABOLIC|GLM | (*)
67  #09 | MHD |CARTESIAN | 3 | RK2 |LINEAR |GLM | -
68  #10 | MHD |CARTESIAN | 3 | HANCOCK |LINEAR |GLM | [Mig12](*)
69  </CENTER>
70 
71  (*) Setups for AMR-Chombo
72 
73  \image html mhd_rt.01.jpg "Density plot at the end of configuration #01"
74 
75  \author A. Mignone (mignone@ph.unito.it)
76  \date July 06, 2014
77 
78  \b References: \n
79  - [Mig12]: Section 5.5 of Mignone et al., ApJS (2012) 198:7 \n
80  - [SG07]: Stone & Gardiner, Physics of Fluids (2007), 19
81 */
82 /* ///////////////////////////////////////////////////////////////////// */
83 #include "pluto.h"
84 
85 /* ********************************************************************* */
86 void Init (double *v, double x1, double x2, double x3)
87 /*
88  *
89  *********************************************************************** */
90 {
91  double x=x1, y=x2, z=x3;
92  double rnd, Bc, g;
93 
94  g = g_inputParam[GRAV];
95 
96  if (y < 0.0) v[RHO] = 1.0;
97  else v[RHO] = g_inputParam[ETA];
98 
99  v[PRS] = 1.0/g_gamma + v[RHO]*g*y; /* Hydrostatic balance */
100  v[VX1] = v[VX2] = v[VX3] = 0.0;
101 
102 /* -----------------------------------
103  Add perturbation
104  ----------------------------------- */
105 
106  #if USE_RANDOM_PERTURBATION == YES
107  rnd = RandomNumber();
108  v[VX2] = 1.e-2*rnd*exp(-y*y*200.0);
109  #else
110  #if DIMENSIONS == 2
111  v[VX2] = -1.e-2*(1.0 + cos(2.0*CONST_PI*x))*exp(-y*y*200.0);
112  #elif DIMENSIONS == 3
113  rnd = sqrt(x*x + z*z);
114  v[VX2] = -1.e-2*exp(-rnd*rnd/(0.2*0.2))/cosh(y*y/(0.1*0.1));
115  #endif
116  #endif
117 
118 /* -----------------------------------
119  Set magnetic field in units of Bc
120  ----------------------------------- */
121 
122  #if PHYSICS == MHD
123  Bc = sqrt((g_inputParam[ETA] - 1.0)*fabs(g)); /* Critical field */
124  v[BX1] = g_inputParam[CHI]*Bc/sqrt(4.0*CONST_PI);
125  v[BX2] = 0.0;
126  v[BX3] = 0.0;
127  v[AX1] = v[AX2] = 0.0;
128  v[AX3] = y*v[BX1];
129  #endif
130 
131 }
132 /* ********************************************************************* */
133 void Analysis (const Data *d, Grid *grid)
134 /*
135  *
136  *
137  *********************************************************************** */
138 {
139 
140 }
141 
142 /* ********************************************************************* */
143 void UserDefBoundary (const Data *d, RBox *box, int side, Grid *grid)
144 /*
145  *
146  *
147  *********************************************************************** */
148 {
149 }
150 
151 #if (BODY_FORCE & VECTOR)
152 /* ************************************************************************ */
153 void BodyForceVector(double *v, double *g, double x1, double x2, double x3)
154 /*
155  *
156  *
157  *************************************************************************** */
158 {
159  g[IDIR] = 0.0;
160  g[JDIR] = g_inputParam[GRAV];
161  g[KDIR] = 0.0;
162  #ifdef CTU
163  if (x2 > g_domEnd[JDIR]) g[JDIR] *= -1.0;
164  else if (x2 < g_domBeg[JDIR]) g[JDIR] *= -1.0;
165  #endif
166 }
167 #endif
168 
169 #if (BODY_FORCE & POTENTIAL)
170 /* ************************************************************************ */
171 double BodyForcePotential(double x1, double x2, double x3)
172 /*
173  *
174  *
175  *************************************************************************** */
176 {
177  #ifdef CTU
178  if (x2 < g_domBeg[JDIR]) x2 = 2.0*g_domBeg[JDIR] - x2;
179  else if (x2 > g_domEnd[JDIR]) x2 = 2.0*g_domEnd[JDIR] - x2;
180  #endif
181 
182  return -g_inputParam[GRAV]*x2;
183 }
184 #endif
double g_gamma
Definition: globals.h:112
void UserDefBoundary(const Data *d, RBox *box, int side, Grid *grid)
Definition: init.c:98
#define VX2
Definition: mod_defs.h:29
double RandomNumber(double rmin, double rmax)
Definition: math_misc.c:209
#define RHO
Definition: mod_defs.h:19
#define AX2
Definition: mod_defs.h:86
#define VX1
Definition: mod_defs.h:28
#define KDIR
Definition: pluto.h:195
#define IDIR
Definition: pluto.h:193
Definition: structs.h:78
#define AX3
Definition: mod_defs.h:87
double g_inputParam[32]
Array containing the user-defined parameters.
Definition: globals.h:131
#define GRAV
double g_domBeg[3]
Lower limits of the computational domain.
Definition: globals.h:125
#define BX3
Definition: mod_defs.h:27
PLUTO main header file.
Definition: structs.h:30
double BodyForcePotential(double x, double y, double z)
Definition: init.c:479
#define ETA
#define AX1
Definition: mod_defs.h:85
#define BX1
Definition: mod_defs.h:25
#define VX3
Definition: mod_defs.h:30
#define CHI
#define CONST_PI
.
Definition: pluto.h:269
#define BX2
Definition: mod_defs.h:26
double g_domEnd[3]
Upper limits of the computational domain.
Definition: globals.h:126
#define JDIR
Definition: pluto.h:194
Definition: structs.h:346
void Analysis(const Data *d, Grid *grid)
Definition: init.c:66
void Init(double *v, double x1, double x2, double x3)
Definition: init.c:17
void BodyForceVector(double *v, double *g, double x, double y, double z)
Definition: init.c:441