PLUTO
init.c
Go to the documentation of this file.
1 /* ///////////////////////////////////////////////////////////////////// */
2 /*!
3  \file
4  \brief Contains basic functions for problem initialization.
5 
6  The init.c file collects most of the user-supplied functions useful
7  for problem configuration.
8  It is automatically searched for by the makefile.
9 
10  \author A. Mignone (mignone@ph.unito.it)
11  \date Sept 10, 2012
12 */
13 /* ///////////////////////////////////////////////////////////////////// */
14 #include "pluto.h"
15 
16 /* ********************************************************************* */
17 void Init (double *v, double x1, double x2, double x3)
18 /*!
19  * The Init() function can be used to assign initial conditions as
20  * as a function of spatial position.
21  *
22  * \param [out] v a pointer to a vector of primitive variables
23  * \param [in] x1 coordinate point in the 1st dimension
24  * \param [in] x2 coordinate point in the 2nd dimension
25  * \param [in] x3 coordinate point in the 3rdt dimension
26  *
27  * The meaning of x1, x2 and x3 depends on the geometry:
28  * \f[ \begin{array}{cccl}
29  * x_1 & x_2 & x_3 & \mathrm{Geometry} \\ \noalign{\medskip}
30  * \hline
31  * x & y & z & \mathrm{Cartesian} \\ \noalign{\medskip}
32  * R & z & - & \mathrm{cylindrical} \\ \noalign{\medskip}
33  * R & \phi & z & \mathrm{polar} \\ \noalign{\medskip}
34  * r & \theta & \phi & \mathrm{spherical}
35  * \end{array}
36  * \f]
37  *
38  * Variable names are accessed by means of an index v[nv], where
39  * nv = RHO is density, nv = PRS is pressure, nv = (VX1, VX2, VX3) are
40  * the three components of velocity, and so forth.
41  *
42  *********************************************************************** */
43 {
44  v[RHO] = 1.0;
45  v[VX1] = 0.0;
46  v[VX2] = 0.0;
47  v[VX3] = 0.0;
48  #if HAVE_ENERGY
49  v[PRS] = 1.0;
50  #endif
51  v[TRC] = 0.0;
52 
53  #if PHYSICS == MHD || PHYSICS == RMHD
54 
55  v[BX1] = 0.0;
56  v[BX2] = 0.0;
57  v[BX3] = 0.0;
58 
59  v[AX1] = 0.0;
60  v[AX2] = 0.0;
61  v[AX3] = 0.0;
62 
63  #endif
64 }
65 /* ********************************************************************* */
66 void Analysis (const Data *d, Grid *grid)
67 /*!
68  * Perform runtime data analysis.
69  *
70  * \param [in] d the PLUTO Data structure
71  * \param [in] grid pointer to array of Grid structures
72  *
73  *********************************************************************** */
74 {
75 
76 }
77 #if PHYSICS == MHD
78 /* ********************************************************************* */
79 void BackgroundField (double x1, double x2, double x3, double *B0)
80 /*!
81  * Define the component of a static, curl-free background
82  * magnetic field.
83  *
84  * \param [in] x1 position in the 1st coordinate direction \f$x_1\f$
85  * \param [in] x2 position in the 2nd coordinate direction \f$x_2\f$
86  * \param [in] x3 position in the 3rd coordinate direction \f$x_3\f$
87  * \param [out] B0 array containing the vector componens of the background
88  * magnetic field
89  *********************************************************************** */
90 {
91  B0[0] = 0.0;
92  B0[1] = 0.0;
93  B0[2] = 0.0;
94 }
95 #endif
96 
97 /* ********************************************************************* */
98 void UserDefBoundary (const Data *d, RBox *box, int side, Grid *grid)
99 /*!
100  * Assign user-defined boundary conditions.
101  *
102  * \param [in,out] d pointer to the PLUTO data structure containing
103  * cell-centered primitive quantities (d->Vc) and
104  * staggered magnetic fields (d->Vs, when used) to
105  * be filled.
106  * \param [in] box pointer to a RBox structure containing the lower
107  * and upper indices of the ghost zone-centers/nodes
108  * or edges at which data values should be assigned.
109  * \param [in] side specifies the boundary side where ghost zones need
110  * to be filled. It can assume the following
111  * pre-definite values: X1_BEG, X1_END,
112  * X2_BEG, X2_END,
113  * X3_BEG, X3_END.
114  * The special value side == 0 is used to control
115  * a region inside the computational domain.
116  * \param [in] grid pointer to an array of Grid structures.
117  *
118  *********************************************************************** */
119 {
120  int i, j, k, nv;
121  double *x1, *x2, *x3;
122 
123  x1 = grid[IDIR].x;
124  x2 = grid[JDIR].x;
125  x3 = grid[KDIR].x;
126 
127  if (side == 0) { /* -- check solution inside domain -- */
128  DOM_LOOP(k,j,i){};
129  }
130 
131  if (side == X1_BEG){ /* -- X1_BEG boundary -- */
132  if (box->vpos == CENTER) {
133  BOX_LOOP(box,k,j,i){ }
134  }else if (box->vpos == X1FACE){
135  BOX_LOOP(box,k,j,i){ }
136  }else if (box->vpos == X2FACE){
137  BOX_LOOP(box,k,j,i){ }
138  }else if (box->vpos == X3FACE){
139  BOX_LOOP(box,k,j,i){ }
140  }
141  }
142 
143  if (side == X1_END){ /* -- X1_END boundary -- */
144  if (box->vpos == CENTER) {
145  BOX_LOOP(box,k,j,i){ }
146  }else if (box->vpos == X1FACE){
147  BOX_LOOP(box,k,j,i){ }
148  }else if (box->vpos == X2FACE){
149  BOX_LOOP(box,k,j,i){ }
150  }else if (box->vpos == X3FACE){
151  BOX_LOOP(box,k,j,i){ }
152  }
153  }
154 
155  if (side == X2_BEG){ /* -- X2_BEG boundary -- */
156  if (box->vpos == CENTER) {
157  BOX_LOOP(box,k,j,i){ }
158  }else if (box->vpos == X1FACE){
159  BOX_LOOP(box,k,j,i){ }
160  }else if (box->vpos == X2FACE){
161  BOX_LOOP(box,k,j,i){ }
162  }else if (box->vpos == X3FACE){
163  BOX_LOOP(box,k,j,i){ }
164  }
165  }
166 
167  if (side == X2_END){ /* -- X2_END boundary -- */
168  if (box->vpos == CENTER) {
169  BOX_LOOP(box,k,j,i){ }
170  }else if (box->vpos == X1FACE){
171  BOX_LOOP(box,k,j,i){ }
172  }else if (box->vpos == X2FACE){
173  BOX_LOOP(box,k,j,i){ }
174  }else if (box->vpos == X3FACE){
175  BOX_LOOP(box,k,j,i){ }
176  }
177  }
178 
179  if (side == X3_BEG){ /* -- X3_BEG boundary -- */
180  if (box->vpos == CENTER) {
181  BOX_LOOP(box,k,j,i){ }
182  }else if (box->vpos == X1FACE){
183  BOX_LOOP(box,k,j,i){ }
184  }else if (box->vpos == X2FACE){
185  BOX_LOOP(box,k,j,i){ }
186  }else if (box->vpos == X3FACE){
187  BOX_LOOP(box,k,j,i){ }
188  }
189  }
190 
191  if (side == X3_END){ /* -- X3_END boundary -- */
192  if (box->vpos == CENTER) {
193  BOX_LOOP(box,k,j,i){ }
194  }else if (box->vpos == X1FACE){
195  BOX_LOOP(box,k,j,i){ }
196  }else if (box->vpos == X2FACE){
197  BOX_LOOP(box,k,j,i){ }
198  }else if (box->vpos == X3FACE){
199  BOX_LOOP(box,k,j,i){ }
200  }
201  }
202 }
203 
204 #if BODY_FORCE != NO
205 /* ********************************************************************* */
206 void BodyForceVector(double *v, double *g, double x1, double x2, double x3)
207 /*!
208  * Prescribe the acceleration vector as a function of the coordinates
209  * and the vector of primitive variables *v.
210  *
211  * \param [in] v pointer to a cell-centered vector of primitive
212  * variables
213  * \param [out] g acceleration vector
214  * \param [in] x1 position in the 1st coordinate direction \f$x_1\f$
215  * \param [in] x2 position in the 2nd coordinate direction \f$x_2\f$
216  * \param [in] x3 position in the 3rd coordinate direction \f$x_3\f$
217  *
218  *********************************************************************** */
219 {
220  g[IDIR] = 0.0;
221  g[JDIR] = 0.0;
222  g[KDIR] = 0.0;
223 }
224 /* ********************************************************************* */
225 double BodyForcePotential(double x1, double x2, double x3)
226 /*!
227  * Return the gravitational potential as function of the coordinates.
228  *
229  * \param [in] x1 position in the 1st coordinate direction \f$x_1\f$
230  * \param [in] x2 position in the 2nd coordinate direction \f$x_2\f$
231  * \param [in] x3 position in the 3rd coordinate direction \f$x_3\f$
232  *
233  * \return The body force potential \f$ \Phi(x_1,x_2,x_3) \f$.
234  *
235  *********************************************************************** */
236 {
237  return 0.0;
238 }
239 #endif
#define X3_BEG
Boundary region at X3 beg.
Definition: pluto.h:150
#define X1_BEG
Boundary region at X1 beg.
Definition: pluto.h:146
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 CENTER
Definition: pluto.h:200
int vpos
Location of the variable inside the cell.
Definition: structs.h:359
void BackgroundField(double x1, double x2, double x3, double *B0)
Definition: init.c:79
#define RHO
Definition: mod_defs.h:19
#define X3FACE
Definition: pluto.h:203
#define BOX_LOOP(B, k, j, i)
Definition: macros.h:70
#define AX2
Definition: mod_defs.h:86
#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
#define KDIR
Definition: pluto.h:195
#define X1FACE
Definition: pluto.h:201
#define IDIR
Definition: pluto.h:193
#define X2_END
Boundary region at X2 end.
Definition: pluto.h:149
Definition: structs.h:78
#define AX3
Definition: mod_defs.h:87
int j
Definition: analysis.c:2
int k
Definition: analysis.c:2
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 BodyForcePotential(double x, double y, double z)
Definition: init.c:479
#define AX1
Definition: mod_defs.h:85
#define BX1
Definition: mod_defs.h:25
#define VX3
Definition: mod_defs.h:30
#define X2_BEG
Boundary region at X2 beg.
Definition: pluto.h:148
#define BX2
Definition: mod_defs.h:26
#define JDIR
Definition: pluto.h:194
Definition: structs.h:346
#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
void BodyForceVector(double *v, double *g, double x, double y, double z)
Definition: init.c:441