PLUTO
init.c
Go to the documentation of this file.
1 #include "pluto.h"
2 
3 /* ********************************************************************* */
4 void Init (double *us, double x1, double x2, double x3)
5 /*
6  *
7  *
8  *
9  *********************************************************************** */
10 {
11  static int first_call = 1;
12  double rnd;
13  double x, y, z = 0.0, r2;
14  double kp, mu;
15  double dvx, dvy, dBx, dBy, arg;
16 
17  g_gamma = 5./3.;
18 
19  if (first_call == 1){
20  srand(time(NULL) + prank);
21  first_call = 0;
22  }
23  rnd = (double)(rand())/((double)RAND_MAX + 1.0);
24 
25  D_EXPAND(x = x1;, y = x2;, z = x3;)
26 
27  kp = g_inputParam[KPAR];
28  mu = g_inputParam[MUPAR];
29  r2 = x*x + y*y + z*z;
30  arg = (1.0 - r2);
31 
32  dvx = -y*kp*exp(0.5*arg);
33  dvy = x*kp*exp(0.5*arg);
34 
35  dBx = -y*mu*exp(0.5*arg);
36  dBy = x*mu*exp(0.5*arg);
37 
38  us[RHO] = 1.0; // mu*mu/(kp*kp);
39 
40  us[VX1] = dvx + g_inputParam[PERT_AMPL]*(rnd-0.5)*exp(-x1*x1/4.0);
41  us[VX2] = dvy + 0.5*g_inputParam[MACH]*tanh(x1);
42  us[VX3] = 0.0;
43  #if DIMENSIONS == 3
44  us[VX3] = 0.1*sin(2.0*CONST_PI*x3/10.0);
45  #endif
46 
47  us[PRS] = 1.0/g_gamma + exp(arg)*(mu*mu*(1.0 - r2 + z*z) - us[RHO]*kp*kp)*0.5;
48 
49  #if PHYSICS == MHD
50  us[BX1] = dBx;
51  us[BX2] = dBy;
52  us[BX3] = 0.0;
53 
54  #ifdef STAGGERED_MHD
55  us[AX1] = us[AX2] = 0.0;
56  us[AX3] = mu*exp(0.5*arg);
57  #endif
58  #endif
59 
60 }
61 /* ********************************************************************* */
62 void Analysis (const Data *d, Grid *grid)
63 /*
64  *
65  *
66  *********************************************************************** */
67 {
68  int i,j,k;
69  double rhoe, pm, kin, my, E, BxBy, vol;
70  double pm0, kinx, kiny;
71  FILE *fp;
72 
73 /* --------------------------------------------------------
74  compute volume averages
75  -------------------------------------------------------- */
76 
77  rhoe = pm = kin = my = E = BxBy = 0.0;
78  DOM_LOOP(k,j,i){
79  #if PHYSICS == MHD
80  pm0 = 0.5*( d->Vc[BX1][k][j][i]*d->Vc[BX1][k][j][i]
81  + d->Vc[BX2][k][j][i]*d->Vc[BX2][k][j][i]);
82  #endif
83  kinx = 0.5*d->Vc[RHO][k][j][i]*d->Vc[VX1][k][j][i]*d->Vc[VX1][k][j][i];
84  kiny = 0.5*d->Vc[RHO][k][j][i]*d->Vc[VX2][k][j][i]*d->Vc[VX2][k][j][i];
85 
86  pm += pm0;
87  kin += kinx;
88 
89  rhoe += d->Vc[PRS][k][j][i]/(g_gamma - 1.0);
90  my += d->Vc[RHO][k][j][i]*d->Vc[VX2][k][j][i];
91  E += d->Vc[PRS][k][j][i]/(g_gamma - 1.0) + kinx + kiny + pm0;
92  #if PHYSICS == MHD
93  BxBy += d->Vc[BX1][k][j][i]*d->Vc[BX2][k][j][i];
94  #endif
95  }
96 
97  vol = grid[IDIR].dx[IBEG]*grid[JDIR].dx[JBEG];
98  vol /= (g_domEnd[IDIR] - g_domBeg[IDIR])*(g_domEnd[JDIR] - g_domBeg[JDIR]);
99 
100  rhoe *= vol;
101  pm *= vol;
102  kin *= vol;
103  my *= vol;
104  E *= vol;
105  BxBy *= vol;
106 
107  #ifdef PARALLEL
108  MPI_Allreduce (&rhoe, &vol, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
109  rhoe = vol;
110 
111  MPI_Allreduce (&pm, &vol, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
112  pm = vol;
113 
114  MPI_Allreduce (&kin, &vol, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
115  kin = vol;
116 
117  MPI_Allreduce (&my, &vol, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
118  my = vol;
119 
120  MPI_Allreduce (&E, &vol, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
121  E = vol;
122 
123  MPI_Allreduce (&BxBy, &vol, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
124  BxBy = vol;
125 
126  MPI_Barrier (MPI_COMM_WORLD);
127  #endif
128 
129 /* -----------------------------------------------------
130  processor #0 does the actual writing
131  ----------------------------------------------------- */
132 
133  if (prank == 0){
134  static int first_call = 1;
135  if (first_call){
136  fp = fopen("averages.dat","w");
137  fprintf (fp,"# t\t\t dt\t <rhoe>\t <B^2>/2\t <rho*vx^2/2>\t <rho*vy>\t <E>\t <BxBy>\n");
138 // fprintf (fp,"# %12c %12c %12c\n",'t','delta_t', '<kin>');
139  }else{
140  fp = fopen("averages.dat","a");
141  }
142  fprintf (fp, "%12.6e %12.6e %12.6e %12.6e %12.6e %12.6e %12.6e %12.6e\n",
143  g_time, g_dt, rhoe, pm, kin, my, E, BxBy);
144  fclose(fp);
145  first_call = 0;
146  }
147 }
148 
149 /* ********************************************************************* */
150 void UserDefBoundary (const Data *d, RBox *box, int side, Grid *grid)
151 /*!
152  * Assign user-defined boundary conditions.
153  *
154  * \param [in/out] d pointer to the PLUTO data structure containing
155  * cell-centered primitive quantities (d->Vc) and
156  * staggered magnetic fields (d->Vs, when used) to
157  * be filled.
158  * \param [in] box pointer to a RBox structure containing the lower
159  * and upper indices of the ghost zone-centers/nodes
160  * or edges at which data values should be assigned.
161  * \param [in] side specifies on which side boundary conditions need
162  * to be assigned. side can assume the following
163  * pre-definite values: X1_BEG, X1_END,
164  * X2_BEG, X2_END,
165  * X3_BEG, X3_END.
166  * The special value side == 0 is used to control
167  * a region inside the computational domain.
168  * \param [in] grid pointer to an array of Grid structures.
169  *
170  *********************************************************************** */
171 { }
172 
173 
#define MUPAR
double g_gamma
Definition: globals.h:112
#define MACH
void UserDefBoundary(const Data *d, RBox *box, int side, Grid *grid)
Definition: init.c:98
DOM_LOOP(k, j, i)
Definition: analysis.c:22
#define VX2
Definition: mod_defs.h:29
#define RHO
Definition: mod_defs.h:19
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 AX2
Definition: mod_defs.h:86
double * dx
Definition: structs.h:83
int prank
Processor rank.
Definition: globals.h:33
#define VX1
Definition: mod_defs.h:28
#define KPAR
#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
int j
Definition: analysis.c:2
int k
Definition: analysis.c:2
double g_domBeg[3]
Lower limits of the computational domain.
Definition: globals.h:125
#define PERT_AMPL
#define BX3
Definition: mod_defs.h:27
PLUTO main header file.
D_EXPAND(tot/[n]=(double) grid[IDIR].np_int_glob;, tot/[n]=(double) grid[JDIR].np_int_glob;, tot/[n]=(double) grid[KDIR].np_int_glob;)
Definition: analysis.c:27
Definition: structs.h:30
int i
Definition: analysis.c:2
double g_time
The current integration time.
Definition: globals.h:117
#define AX1
Definition: mod_defs.h:85
FILE * fp
Definition: analysis.c:7
#define BX1
Definition: mod_defs.h:25
#define VX3
Definition: mod_defs.h:30
#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
long int JBEG
Lower grid index of the computational domain in the the X2 direction for the local processor...
Definition: globals.h:39
Definition: structs.h:346
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