PLUTO
init.c
Go to the documentation of this file.
1 /* ///////////////////////////////////////////////////////////////////// */
2 /*!
3  \file
4  \brief Magnetic field diffusion in 2D and 3D.
5 
6  Sets the initial conditions for a magnetic field diffusion problem
7  in 2 or 3 dimensions.
8  This is a useful test to check the ability of the code to solve
9  standard diffusion problems.
10  The magnetic field has initially a Gaussian profile, and an anisotropic
11  resistivity is possible.
12  This problem has an analytical solution given, in 2D, by
13  \f[
14  B_x(y,t) = \exp(-y^2/4\eta_zt)/\sqrt{t}
15  \quad\quad\quad
16  B_y(x,t) = \exp(-x^2/4\eta_zt)/\sqrt{t}
17  \quad\quad\quad
18  B_z(x,y,t) = \exp(-x^2/4\eta_yt)\exp(-y^2/4\eta_xt)/t
19  \f]
20  and in 3D by
21  \f[
22  \begin{array}{lcl}
23  B_x(y,z,t) &=& \exp(-y^2/4\eta_zt)\exp(-z^2/4\eta_yt)/t \\ \noalign{\medskip}
24  B_y(x,z,t) &=& \exp(-x^2/4\eta_zt)\exp(-z^2/4\eta_xt)/t \\ \noalign{\medskip}
25  B_z(x,y,t) &=& \exp(-x^2/4\eta_yt)\exp(-y^2/4\eta_xt)/t
26  \end{array}
27  \f]
28  The initial condition is simply set using the previous profiles
29  with \c t=1.
30  In order to solve only the parabolic term in the induction equation
31  (\f$ \nabla\times\vec{J}=\nabla\times(\eta\nabla\times\vec{B})\f$)
32  we give to the fluid a very large intertia using a high density
33  value.
34  Moreover, to avoid any fluid motion, the velocity is reset to zero
35  at each time step by using the \c INTERNAL_BOUNDARY.
36 
37  The runtime parameters that are read from \c pluto.ini are
38  - <tt>g_inputParam[ETAX]</tt>: sets the resistivity along the \f$x\f$ direction;
39  - <tt>g_inputParam[ETAY]</tt>: sets the resistivity along the \f$y\f$ direction;
40  - <tt>g_inputParam[ETAZ]</tt>: sets the resistivity along the \f$z\f$ direction;
41 
42  \image html 3D-cart-0.jpg "Initial and final profiles of the numerical (points) and analytical (lines) solutions for a component of the magnetic field."
43 
44  The configurations use both \c EXPLICIT and \c STS time integrators and
45  different geometries are explored:
46 
47  <CENTER>
48  Conf.|GEOMETRY |DIM|T.STEPPING |divB|RESISTIVITY
49  -----|----------|---|-----------|----| ----------
50  #01 |CARTESIAN | 3 | RK2 | 8W | EXPLICIT
51  #02 |CARTESIAN | 3 | HANCOCK | GLM| STS
52  #03 |CARTESIAN | 3 | RK3 | CT | EXPLICIT
53  #04 |CARTESIAN | 3 | HANCOCK | GLM| EXPLICIT
54  #05 |POLAR | 3 | RK2 | 8W | EXPLICIT
55  #06 |POLAR | 3 | RK2 | 8W | STS
56  #07 |SPHERICAL | 3 | RK2 | 8W | EXPLICIT
57  #08 |SPHERICAL | 3 | RK2 | 8W | STS
58  #09 |SPHERICAL | 3 | RK3 | CT | EXPLICIT
59  #10 |CARTESIAN | 2 | HANCOCK | CT | EXPLICIT
60  #11 |CARTESIAN | 3 | HANCOCK | CT | EXPLICIT
61  #12 |CARTESIAN | 2 | HANCOCK | CT | STS
62  #13 |SPHERICAL | 3 | RK2 | CT | STS
63  </CENTER>
64 
65  \authors A. Mignone (mignone@ph.unito.it) \n
66  T. Matsakos (titos@oddjob.uchicago.edu)
67  \date Sept 17, 2014
68 */
69 /* ///////////////////////////////////////////////////////////////////// */
70 #include "pluto.h"
71 
72 void BoundValues (double *v, double x1, double x2, double x3, double t);
73 
74 /* ********************************************************************* */
75 void Init (double *us, double x1, double x2, double x3)
76 /*
77  *
78  *********************************************************************** */
79 {
80  BoundValues(us, x1, x2, x3, 1.0);
81 }
82 
83 /* ********************************************************************* */
84 void Analysis (const Data *d, Grid *grid)
85 /*
86  *
87  *********************************************************************** */
88 {}
89 
90 /* ********************************************************************* */
91 void UserDefBoundary (const Data *d, RBox *box, int side, Grid *grid)
92 /*
93  *
94  *********************************************************************** */
95 {
96  int i, j, k, nv;
97  double *x, *y, *z;
98  double *xp, *yp, *zp;
99  double t, dt, vb[256];
100 
101  if (side == 0){
102  #if GEOMETRY == CARTESIAN
103  TOT_LOOP(k,j,i){
104  EXPAND(d->Vc[VX1][k][j][i] = 0.0; ,
105  d->Vc[VX2][k][j][i] = 0.0; ,
106  d->Vc[VX3][k][j][i] = 0.0;)
107  #if ENTROPY_SWITCH == YES
108  d->flag[k][j][i] |= FLAG_ENTROPY;
109  #endif
110  }
111  #endif
112  }
113 
114  t = g_time + 1.0;
115 
116  x = grid[IDIR].x; xp = grid[IDIR].xr;
117  y = grid[JDIR].x; yp = grid[JDIR].xr;
118  z = grid[KDIR].x; zp = grid[KDIR].xr;
119 
120  if (side == X1_BEG || side == X2_BEG || side == X3_BEG ||
121  side == X1_END || side == X2_END || side == X3_END){ /* -- All Boundaries -- */
122  if (box->vpos == CENTER) {
123  BOX_LOOP(box,k,j,i){
124  BoundValues (vb, x[i], y[j], z[k], t);
125  for (nv = NVAR; nv--; ) d->Vc[nv][k][j][i] = vb[nv];
126  }
127  }else if (box->vpos == X1FACE){
128  #ifdef STAGGERED_MHD
129  if (side == X1_BEG || side == X1_END) return;
130  BOX_LOOP(box,k,j,i){
131  BoundValues (vb, xp[i], y[j], z[k], t);
132  d->Vs[BX1s][k][j][i] = vb[BX1];
133  }
134  #endif
135  }else if (box->vpos == X2FACE){
136  if (side == X2_BEG || side == X2_END) return;
137  #ifdef STAGGERED_MHD
138  BOX_LOOP(box,k,j,i){
139  BoundValues (vb, x[i], yp[j], z[k], t);
140  d->Vs[BX2s][k][j][i] = vb[BX2];
141  }
142  #endif
143 
144  }else if (box->vpos == X3FACE){
145  if (side == X3_BEG || side == X3_END) return;
146  #ifdef STAGGERED_MHD
147  BOX_LOOP(box,k,j,i) {
148  BoundValues (vb, x[i], y[j], zp[k], t);
149  d->Vs[BX3s][k][j][i] = vb[BX3];
150  }
151  #endif
152 
153  }
154  }
155 }
156 
157 /* ******************************************************************* */
158 void BoundValues (double *v, double x1, double x2, double x3, double t)
159 /*
160  *
161  * Time-dependent exact solution
162  *
163  ********************************************************************* */
164 {
165  double Bx, By, Bz;
166  double x, y, z;
167  double eta_x, eta_y, eta_z, st;
168 
169  eta_x = g_inputParam[ETAX];
170  eta_y = g_inputParam[ETAY];
171  eta_z = g_inputParam[ETAZ];
172 
173 /* -- find Cartesian coordinates from (x1,x2,x3) -- */
174 
175  #if GEOMETRY == CARTESIAN
176  x = x1; y = x2; z = x3;
177  #elif GEOMETRY == POLAR
178  x = x1*cos(x2) - 5.0;
179  y = x1*sin(x2) - 5.0;
180  z = x3 - 5.0;
181  #elif GEOMETRY == SPHERICAL
182  x = x1*cos(x3)*sin(x2) - 5.0;
183  y = x1*sin(x3)*sin(x2) - 5.0;
184  z = x1*cos(x2) - 5.0;
185  #else
186  #error geometry not valid
187  #endif
188 
189  v[RHO] = 1.0e9;
190  v[VX1] = 0.0;
191  v[VX2] = 0.0;
192  v[VX3] = 0.0;
193  #if EOS != ISOTHERMAL
194  v[PRS] = 1.0;
195  #endif
196  #ifdef GLM_MHD
197  v[PSI_GLM] = 0.0;
198  #endif
199 
200 /* -- find Cartesian components of magnetic field -- */
201 /*
202  Bx = exp(-0.25*(y*y)/g_inputParam[ETAZ]/t)*exp(-0.25*(z*z)/g_inputParam[ETAY]/t)/t;
203  By = exp(-0.25*(x*x)/g_inputParam[ETAZ]/t)*exp(-0.25*(z*z)/g_inputParam[ETAX]/t)/t;
204  Bz = exp(-0.25*(x*x)/g_inputParam[ETAY]/t)*exp(-0.25*(y*y)/g_inputParam[ETAX]/t)/t;
205 */
206 
207  #if DIMENSIONS == 2
208  st = sqrt(t);
209 
210  Bx = exp(-0.25*y*y/(eta_z*t))/st;
211  By = exp(-0.25*x*x/(eta_z*t))/st;
212  Bz = exp(-0.25*x*x/(eta_y*t))*exp(-0.25*y*y/(eta_x*t))/t;
213  #elif DIMENSIONS == 3
214  Bx = exp(-0.25*y*y/(eta_z*t))*exp(-0.25*z*z/(eta_y*t))/t;
215  By = exp(-0.25*x*x/(eta_z*t))*exp(-0.25*z*z/(eta_x*t))/t;
216  Bz = exp(-0.25*x*x/(eta_y*t))*exp(-0.25*y*y/(eta_x*t))/t;
217  #endif
218 
219 /* -----------------------------------------------------------
220  Transform back to original coordinate system
221  ----------------------------------------------------------- */
222 
223  #if GEOMETRY == CARTESIAN
224  v[BX1] = Bx;
225  v[BX2] = By;
226  v[BX3] = Bz;
227  #elif GEOMETRY == POLAR
228  v[BX1] = cos(x2)*Bx + sin(x2)*By;
229  v[BX2] = -sin(x2)*Bx + cos(x2)*By;
230  v[BX3] = Bz;
231  #elif GEOMETRY == SPHERICAL
232  v[BX1] = cos(x3)*sin(x2)*Bx + sin(x3)*sin(x2)*By + cos(x2)*Bz;
233  v[BX2] = cos(x3)*cos(x2)*Bx + sin(x3)*cos(x2)*By - sin(x2)*Bz;
234  v[BX3] = -sin(x3)*Bx + cos(x3)*By;
235  #else
236  print1 ("! BoundValues: GEOMETRY not defined\n");
237  QUIT_PLUTO(1);
238  #endif
239 
240 }
#define X3_BEG
Boundary region at X3 beg.
Definition: pluto.h:150
#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
void UserDefBoundary(const Data *d, RBox *box, int side, Grid *grid)
Definition: init.c:98
#define VX2
Definition: mod_defs.h:29
#define CENTER
Definition: pluto.h:200
void print1(const char *fmt,...)
Definition: amrPluto.cpp:511
int vpos
Location of the variable inside the cell.
Definition: structs.h:359
void BoundValues(double *v, double x1, double x2, double x3, double t)
Definition: init.c:158
double * xr
Definition: structs.h:81
#define RHO
Definition: mod_defs.h:19
#define X3FACE
Definition: pluto.h:203
#define BOX_LOOP(B, k, j, i)
Definition: macros.h:70
double **** Vc
The main four-index data array used for cell-centered primitive variables.
Definition: structs.h:31
#define PSI_GLM
Definition: mod_defs.h:34
#define BX3s
Definition: ct.h:29
#define X1_END
Boundary region at X1 end.
Definition: pluto.h:147
#define ETAY
#define VX1
Definition: mod_defs.h:28
#define KDIR
Definition: pluto.h:195
unsigned char *** flag
Pointer to a 3D array setting useful integration flags that are retrieved during integration.
Definition: structs.h:55
#define X1FACE
Definition: pluto.h:201
#define TOT_LOOP(k, j, i)
Definition: macros.h:44
#define FLAG_ENTROPY
Update pressure using entropy equation.
Definition: pluto.h:182
#define IDIR
Definition: pluto.h:193
#define X2_END
Boundary region at X2 end.
Definition: pluto.h:149
Definition: structs.h:78
static double Bx
Definition: hlld.c:62
double g_inputParam[32]
Array containing the user-defined parameters.
Definition: globals.h:131
int j
Definition: analysis.c:2
int k
Definition: analysis.c:2
#define BX1s
Definition: ct.h:27
double * x
Definition: structs.h:80
#define BX3
Definition: mod_defs.h:27
#define X3_END
Boundary region at X3 end.
Definition: pluto.h:151
PLUTO main header file.
Definition: structs.h:30
int i
Definition: analysis.c:2
double g_time
The current integration time.
Definition: globals.h:117
#define ETAX
#define BX1
Definition: mod_defs.h:25
#define VX3
Definition: mod_defs.h:30
#define BX2s
Definition: ct.h:28
#define X2_BEG
Boundary region at X2 beg.
Definition: pluto.h:148
#define BX2
Definition: mod_defs.h:26
#define ETAZ
#define JDIR
Definition: pluto.h:194
#define NVAR
Definition: pluto.h:609
Definition: structs.h:346
#define QUIT_PLUTO(e_code)
Definition: macros.h:125
#define X2FACE
Definition: pluto.h:202
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