PLUTO
init.c
Go to the documentation of this file.
1 /* ///////////////////////////////////////////////////////////////////// */
2 /*!
3  \file
4  \brief Hydrostatic atmosphere in a smoothed gravitational potential.
5 
6  Set initial conditions for an hydrostatic atmosphere in cylindrical
7  coordinates.
8  Gravity is given as
9  \f[
10  g = \left\{\begin{array}{ll}
11  -1/R^2 & \quad{\rm for} \quad R > 1 \\ \noalign{\medskip}
12  aR + bR^2 + cR^3 & \quad{\rm for} \quad R < 1
13  \end{array}\right.\,,
14  \f]
15  where \f$R = \sqrt{r^2 + z^2}\f$ is the spherical radius. The coefficients
16  \f$a\f$, \f$b\f$ and \f$c\f$ are chosen to guarantee continuity of \f$g\f$,
17  its first and second derivative (optionally).
18  Density and pressure are tied by the isothermal condition
19  \f$P = \rho/a\f$ so that the hydrostatic condition is
20  \f[
21  \frac{1}{\rho} \frac{d\rho}{dr} = ag\,,
22  \f]
23  with the normalization \f$\rho = 1\f$ at \f$R = 1\f$.
24 
25  The runtime parameters that are read from \c pluto.ini are
26  - <tt>g_inputParam[ALPHA]</tt>: sets the value of \f$a\f$;
27 
28  Configurations:
29  - #1-4: 2D cylindrical
30  - #5: 3D cartesian
31 
32  \b References:
33 
34  \author A. Mignone (mignone@ph.unito.it)
35  \date July 09, 2014
36 */
37 /* ///////////////////////////////////////////////////////////////////// */
38 #include "pluto.h"
39 
40 static real acf, bcf, ccf; /* polynomial coefficient for g when r < 1 */
41 
42 /* ********************************************************************* */
43 void Init (double *us, double x1, double x2, double x3)
44 /*
45  *
46  *
47  *
48  *********************************************************************** */
49 {
50  double rs, scrh;
51 
52 /* ------------------------------------------
53  with this choice g, g' and g''
54  will be continuous at R = 1
55  ----------------------------------------- */
56 
57  acf = -10.0;
58  bcf = 15.0;
59  ccf = -6.0;
60 
61 /* -----------------------------------
62  with this choice g and g'
63  will be continuous
64  ---------------------------------- */
65 
66  acf = -3.0;
67  bcf = 2.0;
68  ccf = 0.0;
69 
70  #if GEOMETRY == CARTESIAN
71  rs = sqrt(x1*x1 + x2*x2 + x3*x3);
72  #elif GEOMETRY == CYLINDRICAL
73  rs = sqrt(x1*x1 + x2*x2);
74  #elif GEOMETRY == SPHERICAL
75  rs = sqrt(x1*x1);
76  #endif
77 
78  if (rs > 1.0){
79  us[RHO] = exp(g_inputParam[ALPHA]*(1.0/rs - 1.0));
80  }else{
81  scrh = 0.5*acf*(rs*rs - 1.0) + 1.0/3.0*bcf*(rs*rs*rs - 1.0)
82  + 0.25*ccf*(rs*rs*rs*rs - 1.0);
83  us[RHO] = exp(scrh*g_inputParam[ALPHA]);
84  }
85 
86  us[VX1] = 0.0;
87  us[VX2] = 0.0;
88  us[VX3] = 0.0;
89  us[PRS] = us[RHO]/g_inputParam[ALPHA];
90  us[TRC] = 0.0;
91 }
92 /* ********************************************************************* */
93 void Analysis (const Data *d, Grid *grid)
94 /*
95  *
96  *
97  *********************************************************************** */
98 {
99 
100 }
101 /* ********************************************************************* */
102 void UserDefBoundary (const Data *d, RBox *box, int side, Grid *grid)
103 /*
104  *
105  *********************************************************************** */
106 {
107  int i, j, k;
108  double *x1, *x2, *x3;
109  double rs;
110 
111  x1 = grid[IDIR].xgc;
112  x2 = grid[JDIR].xgc;
113  x3 = grid[KDIR].xgc;
114 
115  if (side == X1_END) {
116 
117  X1_END_LOOP(k,j,i){
118  #if GEOMETRY == CARTESIAN
119  rs = sqrt(x1[i]*x1[i] + x2[j]*x2[j] + x3[k]*x3[k]);
120  #elif GEOMETRY == CYLINDRICAL
121  rs = sqrt(x1[i]*x1[i] + x2[j]*x2[j]);
122  #elif GEOMETRY == SPHERICAL
123  rs = sqrt(x1[i]*x1[i]);
124  #endif
125  d->Vc[RHO][k][j][i] = exp(g_inputParam[ALPHA]*(1.0/rs - 1.0));
126  EXPAND(d->Vc[VX1][k][j][i] = 0.0; ,
127  d->Vc[VX2][k][j][i] = 0.0; ,
128  d->Vc[VX3][k][j][i] = 0.0;)
129  d->Vc[PRS][k][j][i] = exp(g_inputParam[ALPHA]*(1.0/rs - 1.0))/g_inputParam[ALPHA];
130  }
131 
132  } else if (side == X2_END) {
133 
134  X2_END_LOOP(k,j,i){
135  #if GEOMETRY == CARTESIAN
136  rs = sqrt(x1[i]*x1[i] + x2[j]*x2[j] + x3[k]*x3[k]);
137  #elif GEOMETRY == CYLINDRICAL
138  rs = sqrt(x1[i]*x1[i] + x2[j]*x2[j]);
139  #elif GEOMETRY == SPHERICAL
140  rs = sqrt(x1[i]*x1[i]);
141  #endif
142  d->Vc[RHO][k][j][i] = exp(g_inputParam[ALPHA]*(1.0/rs - 1.0));
143  EXPAND(d->Vc[VX1][k][j][i] = 0.0; ,
144  d->Vc[VX2][k][j][i] = 0.0; ,
145  d->Vc[VX3][k][j][i] = 0.0;)
146  d->Vc[PRS][k][j][i] = exp(g_inputParam[ALPHA]*(1.0/rs - 1.0))/g_inputParam[ALPHA];
147  }
148 
149  } else if (side == X3_END) { /* Only Cartesian */
150 
151  X3_END_LOOP(k,j,i){
152  rs = sqrt(x1[i]*x1[i] + x2[j]*x2[j] + x3[k]*x3[k]);
153  d->Vc[RHO][k][j][i] = exp(g_inputParam[ALPHA]*(1.0/rs - 1.0));
154  EXPAND(d->Vc[VX1][k][j][i] = 0.0; ,
155  d->Vc[VX2][k][j][i] = 0.0; ,
156  d->Vc[VX3][k][j][i] = 0.0;)
157  d->Vc[PRS][k][j][i] = exp(g_inputParam[ALPHA]*(1.0/rs - 1.0))/g_inputParam[ALPHA];
158  }
159  }
160 }
161 
162 #if (BODY_FORCE & VECTOR)
163 /* ************************************************************************ */
164 void BodyForceVector(double *v, double *g, double x1, double x2, double x3)
165 /*
166  *
167  *
168  *
169  *************************************************************************** */
170 {
171  double gs, rs;
172  double acf, bcf, ccf;
173 
174  acf = -3.0;
175  bcf = 2.0;
176  ccf = 0.0;
177  #if GEOMETRY == CARTESIAN
178  rs = sqrt(x1*x1 + x2*x2 + x3*x3);
179  #elif GEOMETRY == CYLINDRICAL
180  rs = sqrt(x1*x1 + x2*x2);
181  #endif
182 
183  if (rs > 1.0) gs = -1.0/rs/rs;
184  else gs = rs*(acf + rs*(bcf + rs*ccf));
185 
186  #if GEOMETRY == CARTESIAN
187  g[IDIR] = gs*x1/rs;
188  g[JDIR] = gs*x2/rs;
189  g[KDIR] = gs*x3/rs;
190  #elif GEOMETRY == CYLINDRICAL
191  g[IDIR] = gs*x1/rs;
192  g[JDIR] = gs*x2/rs;
193  g[KDIR] = 0.0;
194  #endif
195 
196 }
197 #endif
198 
199 #if (BODY_FORCE & POTENTIAL)
200 /* ************************************************************************ */
201 double BodyForcePotential(double x1, double x2, double x3)
202 /*
203  *
204  *
205  *
206  *************************************************************************** */
207 {
208  double rs, phi;
209  double acf, bcf, ccf, C;
210 
211  acf = -3.0;
212  bcf = 2.0;
213  ccf = 0.0;
214 
215  #if GEOMETRY == CARTESIAN
216  rs = sqrt(x1*x1 + x2*x2 + x3*x3);
217  #elif GEOMETRY == CYLINDRICAL
218  rs = sqrt(x1*x1 + x2*x2);
219  #endif
220 
221  C = (0.5*acf + bcf/3.0 + ccf*0.25); /* integration constant to make phi continuous */
222  if (rs > 1.0) phi = -1.0/rs;
223  else phi = -rs*rs*(0.5*acf + rs*(bcf/3.0 + rs*ccf*0.25)) + C - 1.0;
224 
225  return phi;
226 }
227 #endif
void UserDefBoundary(const Data *d, RBox *box, int side, Grid *grid)
Definition: init.c:98
#define VX2
Definition: mod_defs.h:29
double real
Definition: pluto.h:488
#define RHO
Definition: mod_defs.h:19
tuple scrh
Definition: configure.py:200
double **** Vc
The main four-index data array used for cell-centered primitive variables.
Definition: structs.h:31
#define X3_END_LOOP(k, j, i)
Definition: macros.h:52
#define TRC
Definition: pluto.h:581
#define X1_END
Boundary region at X1 end.
Definition: pluto.h:147
#define VX1
Definition: mod_defs.h:28
static real ccf
Definition: init.c:40
#define KDIR
Definition: pluto.h:195
#define X2_END_LOOP(k, j, i)
Definition: macros.h:51
#define IDIR
Definition: pluto.h:193
#define X2_END
Boundary region at X2 end.
Definition: pluto.h:149
Definition: structs.h:78
double g_inputParam[32]
Array containing the user-defined parameters.
Definition: globals.h:131
static real bcf
Definition: init.c:40
int j
Definition: analysis.c:2
int k
Definition: analysis.c:2
#define X1_END_LOOP(k, j, i)
Definition: macros.h:50
double * xgc
Cell volumetric centroid (!= x when geometry != CARTESIAN).
Definition: structs.h:84
#define ALPHA
#define X3_END
Boundary region at X3 end.
Definition: pluto.h:151
PLUTO main header file.
Definition: structs.h:30
static real acf
Definition: init.c:40
int i
Definition: analysis.c:2
double BodyForcePotential(double x, double y, double z)
Definition: init.c:479
#define VX3
Definition: mod_defs.h:30
#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