PLUTO
init.c
Go to the documentation of this file.
1 /* ///////////////////////////////////////////////////////////////////// */
2 /*!
3  \file
4  \brief Disk-Planet interaction problem.
5 
6  Simulate the interaction of a planet embedded in a disk as described
7  in section 3.4 of Mignone et al., A&A (2012) 545, A152.
8  This test is a nice benchmark for the FARGO module and the
9  \c ROTATING_FRAME switch.
10  For testing-purposes no viscosity is used here.
11  The initial condition consists of a locally isothermal configuration
12  with temperature profile \f$\propto T^{-1}\f$ yielding a disk vertical
13  height to radius of \c 0.05.
14  The gravitational potential due to the presence of the star and the
15  planet is defined in BodyForcePotential() function.
16 
17  The conventions used throught the implementation are the following:
18 
19  - \c r = spherical radius
20  - \c R = cylindrical radius
21  - \c z = cylindrical height
22  - \c th = meridional angle
23 
24  The test can be carried out in polar (2D or 3D) or spherical (3D)
25  coordinates and the following parameters determine the initial configuration:
26 
27  -# <tt>g_inputParam[Mstar]</tt>: controls the star mass (in solar masses)
28  -# <tt>g_inputParam[Mdisk]</tt>: controls the disk mass (in solar masses)
29  -# <tt>g_inputParam[Mplanet]</tt>: sets the planet mass (in earth masses)
30  -# <tt>g_inputParam[Viscosity]</tt>: sets the amount of viscosity
31 
32 
33  Computation can be carried in the rotating or in the observer's frame
34  of reference (\c ROTATING_FRAME to \c YES or \c NO, respectively).
35  In particular:
36 
37  - Configurations #01 and #02 are in 2D polar coordinates without and with
38  FARGO, in the rotating frame.
39  - Configurations #03, #04 and #05 are in spherical 3D coordinates with
40  and without FARGO in the rotating frame
41  - Configurations #06 and #07 are in 2D polar coordinates but in the
42  observer's frame
43  - Configuration #08 employs static AMR (grid levels are spatial
44  dependent but not dependent on time) in the rotating frame.
45 
46 
47  \image html hd_disk_planet.08.png "Density map for configuration #08 using AMR" width=1cm
48 
49  \author A. Mignone (mignone@ph.unito.it)
50  \date Aug 16, 2012
51 
52  \b References:
53  - "A Conservative orbital advection scheme for simulations
54  of magnetized shear flows with the PLUTO Code"
55  Mignone et al, A&A (2012)
56 */
57 /* ///////////////////////////////////////////////////////////////////// */
58 #include "pluto.h"
59 
60 #define MIN_DENSITY 1e-8
61 
62 static void NormalizeDensity (const Data *d, Grid *g);
63 #if ROTATING_FRAME == NO
64  #define g_OmegaZ 0.0
65 #endif
66 
67 /* ********************************************************************* */
68 void Init (double *us, double x1, double x2, double x3)
69 /*
70  *
71  *
72  *
73  *********************************************************************** */
74 {
75  double r, th, R, z, H, OmegaK, cs;
76  double scrh;
77 
78  #if EOS == IDEAL
79  g_gamma = 1.01;
80  #endif
81 
82  #if ROTATING_FRAME == YES
84  g_OmegaZ *= 2.0*CONST_PI;
85  #endif
86 
87  #if GEOMETRY == POLAR
88  R = x1;
89  #if DIMENSIONS == 2
90  z = 0.0;
91  r = R;
92  th = 0.5*CONST_PI;
93  #else
94  z = x3;
95  r = sqrt(R*R + z*z);
96  th = atan2(R,z);
97  #endif
98  #elif GEOMETRY == SPHERICAL
99  r = x1;
100  th = x2;
101  R = r*sin(th);
102  z = r*cos(th);
103  #endif
104 
105  H = 0.05*R;
106  OmegaK = 2.0*CONST_PI/(R*sqrt(R));
107  cs = H*OmegaK;
108 
109  scrh = (0.5*CONST_PI - th)*r/H;
110  us[RHO] = 1.0/(R*sqrt(R))*exp(-0.5*scrh*scrh);
111  us[VX1] = us[VX2] = us[VX3] = 0.0;
112 
113  us[iVPHI] = R*(OmegaK - g_OmegaZ);
114  #if EOS == IDEAL
115  us[PRS] = us[RHO]*cs*cs;
116  #elif EOS == ISOTHERMAL
117 // g_isoSoundSpeed = cs;
118  g_isoSoundSpeed = CONST_PI*0.1;
119  #endif
120 
121 #if DUST == YES
122  us[RHO_D] = 1.e-4;
123  us[VX1_D] = us[VX2_D] = us[VX3_D] = 0.0;
124  us[VX2_D] = us[iVPHI];
125 #endif
126 }
127 /* ********************************************************************* */
128 void Analysis (const Data *d, Grid *grid)
129 /*
130  *
131  *
132  *********************************************************************** */
133 {
134 
135 }
136 /* ********************************************************************* */
137 void UserDefBoundary (const Data *d, RBox *box, int side, Grid *grid)
138 /*
139  *
140  *********************************************************************** */
141 {
142  int i, j, k, nv;
143  double *x1, *x2, *x3, R, OmegaK, v[256];
144  static int do_once = 1;
145 
146  x1 = grid[IDIR].x;
147  x2 = grid[JDIR].x;
148  x3 = grid[KDIR].x;
149 
150  #if DIMENSIONS == 3
151  if (side == 0){
152  if (do_once){
153  NormalizeDensity(d, grid);
154  do_once = 0;
155  }
156  }
157  #endif
158 
159  if (side == X1_BEG){
160  X1_BEG_LOOP(k,j,i){
161  NVAR_LOOP(nv) d->Vc[nv][k][j][i] = d->Vc[nv][k][j][2*IBEG - i - 1];
162  d->Vc[VX1][k][j][i] *= -1.0;
163  #if GEOMETRY == POLAR
164  R = x1[i];
165  #elif GEOMETRY == SPHERICAL
166  R = x1[i]*sin(x2[j]);
167  #endif
168  OmegaK = 2.0*CONST_PI/(R*sqrt(R));
169  d->Vc[iVPHI][k][j][i] = R*(OmegaK - g_OmegaZ);
170 #if DUST == YES
171 // NDUST_LOOP(nv) d->Vc[nv][k][j][i] = 0.0;
172  d->Vc[VX2_D][k][j][i] = d->Vc[iVPHI][k][j][i];
173 #endif
174  }
175  }
176 
177  if (side == X1_END){
178  X1_END_LOOP(k,j,i){
179  NVAR_LOOP(nv) d->Vc[nv][k][j][i] = d->Vc[nv][k][j][IEND];
180  #if GEOMETRY == POLAR
181  R = x1[i];
182 // d->Vc[iVR][k][j][i] = 0.0;
183  #elif GEOMETRY == SPHERICAL
184  R = x1[i]*sin(x2[j]);
185  d->Vc[iVR][k][j][i] = 0.0;
186  d->Vc[iVTH][k][j][i] = 0.0;
187  #endif
188  OmegaK = 2.0*CONST_PI/(R*sqrt(R));
189  d->Vc[iVPHI][k][j][i] = R*(OmegaK - g_OmegaZ);
190 #if DUST == YES
191  d->Vc[VX2_D][k][j][i] = d->Vc[iVPHI][k][j][i];
192 #endif
193 
194  }
195  }
196 }
197 
198 /* ************************************************************** */
199 void NormalizeDensity (const Data *d, Grid *grid)
200 /*
201  *
202  * Normalize density and pressure as rho -> K*rho, where
203  *
204  * K = M/(\sum rho*dV)
205  *
206  **************************************************************** */
207 {
208  int i, j, k;
209  double mc;
210 
211  mc = 0.5*g_inputParam[Mdisk]*CONST_Msun;
213  DOM_LOOP(k,j,i){
214  d->Vc[RHO][k][j][i] *= mc;
215  #if EOS == IDEAL
216  d->Vc[PRS][k][j][i] *= mc;
217  #endif
218  }
219 }
220 
221 #if (BODY_FORCE & VECTOR)
222 /* ************************************************************************ */
223 void BodyForceVector(double *v, double *g, double x1, double x2, double x3)
224 /*
225  *
226  *
227  *
228  *************************************************************************** */
229 {
230  g[IDIR] = 0.0;
231  g[JDIR] = 0.0;
232  g[KDIR] = 0.0;
233 }
234 #endif
235 
236 #if (BODY_FORCE & POTENTIAL)
237 /* ************************************************************************ */
238 double BodyForcePotential(double x1, double x2, double x3)
239 /*
240  *
241  *
242  *
243  *************************************************************************** */
244 {
245  double d, R, r, z, th, x, y, phiplanet, rsm;
246  double xp, yp, t, phi;
247 
248  #if GEOMETRY == POLAR
249  R = x1;
250  #if DIMENSIONS == 2
251  z = 0.0;
252  r = R;
253  th = 0.5*CONST_PI;
254  #else
255  z = x3;
256  r = sqrt(R*R + z*z);
257  th = atan2(R,z);
258  #endif
259  x = R*cos(x2);
260  y = R*sin(x2);
261  #elif (GEOMETRY == SPHERICAL)
262  r = x1;
263  th = x2;
264  R = r*sin(th);
265  z = r*cos(th);
266  x = r*sin(th)*cos(x3);
267  y = r*sin(th)*sin(x3);
268  #endif
269 
270 /* ---------------------------------------------
271  planet position
272  --------------------------------------------- */
273 
274  #if ROTATING_FRAME == NO
275  double OmegaZ;
276  t = g_time;
277  if (g_stepNumber == 2) t += g_dt;
279  OmegaZ *= 2.0*CONST_PI;
280 
281  xp = cos(OmegaZ*t);
282  yp = sin(OmegaZ*t);
283  #else
284  xp = 1.0/sqrt(2.0); /* initial planet position */
285  yp = 1.0/sqrt(2.0);
286  #endif
287 
288  d = sqrt((x-xp)*(x-xp) + (y-yp)*(y-yp) + z*z);
289  rsm = 0.03*R;
290  if (d > rsm) phiplanet = g_inputParam[Mplanet]/d;
291  else phiplanet = g_inputParam[Mplanet]/d*(pow(d/rsm,4.)-2.*pow(d/rsm,3.)+2.*d/rsm);
292 
293  phi = - 4.0*CONST_PI*CONST_PI/g_inputParam[Mstar];
294  phi *= (g_inputParam[Mstar]/r + phiplanet*CONST_Mearth/CONST_Msun);
295 
296  return phi;
297 }
298 #endif
#define X1_BEG
Boundary region at X1 beg.
Definition: pluto.h:146
double g_gamma
Definition: globals.h:112
void UserDefBoundary(const Data *d, RBox *box, int side, Grid *grid)
Definition: init.c:98
#define UNIT_DENSITY
Unit density in gr/cm^3.
Definition: pluto.h:369
DOM_LOOP(k, j, i)
Definition: analysis.c:22
#define VX2
Definition: mod_defs.h:29
static void NormalizeDensity(const Data *d, Grid *g)
Definition: init.c:199
#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
double g_dt
The current integration time step.
Definition: globals.h:118
#define iVPHI
Definition: mod_defs.h:67
#define g_OmegaZ
Definition: init.c:64
#define Mstar
#define X1_END
Boundary region at X1 end.
Definition: pluto.h:147
#define VX1
Definition: mod_defs.h:28
#define KDIR
Definition: pluto.h:195
#define CONST_Msun
Solar Mass.
Definition: pluto.h:265
long int g_stepNumber
Gives the current integration step number.
Definition: globals.h:97
#define iVR
Definition: mod_defs.h:65
#define IDIR
Definition: pluto.h:193
#define NVAR_LOOP(n)
Definition: pluto.h:618
#define UNIT_LENGTH
Unit Length in cm.
Definition: pluto.h:373
Definition: structs.h:78
double g_inputParam[32]
Array containing the user-defined parameters.
Definition: globals.h:131
int j
Definition: analysis.c:2
#define iVTH
Definition: mod_defs.h:66
long int IEND
Upper grid index of the computational domain in the the X1 direction for the local processor...
Definition: globals.h:37
int k
Definition: analysis.c:2
double * x
Definition: structs.h:80
#define X1_END_LOOP(k, j, i)
Definition: macros.h:50
#define CONST_Mearth
Earth Mass.
Definition: pluto.h:266
PLUTO main header file.
#define X1_BEG_LOOP(k, j, i)
Definition: macros.h:46
Definition: structs.h:30
int i
Definition: analysis.c:2
double g_time
The current integration time.
Definition: globals.h:117
double BodyForcePotential(double x, double y, double z)
Definition: init.c:479
#define Mdisk
#define VX3
Definition: mod_defs.h:30
#define CONST_PI
.
Definition: pluto.h:269
#define JDIR
Definition: pluto.h:194
Definition: structs.h:346
#define Mplanet
long int IBEG
Lower grid index of the computational domain in the the X1 direction for the local processor...
Definition: globals.h:35
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