PLUTO
jet_domain.c
Go to the documentation of this file.
1 /* ///////////////////////////////////////////////////////////////////// */
2 /*!
3  \file
4  \brief Adjust the effective domain size when the -xNjet option is given.
5 
6  The SetJetDomain() function shortens the domain integration index in the
7  direction specified by either '\c -x1jet', '\c -x2jet' or '\c -x3jet' to save
8  computational time.
9  This is done by setting the final integration index in the direction
10  of jet propagation to that of the first zone (counting from the top) with
11  non-zero pressure gradient (GetRightmostIndex()).
12  The function UnsetJetDomain() restores the initial computational domain
13  size.
14  Useful for problems involving jet propagation.
15 
16  \note In parallel, the domain is \e not decomposed along the
17  propagation direction (see ParseCmdLineArgs()).
18 
19  \author A. Mignone (mignone@ph.unito.it)
20  \date Dec 24, 2014
21 */
22 /* ///////////////////////////////////////////////////////////////////// */
23 #include "pluto.h"
24 
26 static int GetRightmostIndex(int, double ***);
27 
28 /* ********************************************************************* */
29 void SetJetDomain (const Data *d, int dir, int log_freq, Grid *grid)
30 /*!
31  *
32  * Adjust the size of computational domain by reducing the final
33  * computationa index in the direction of propagation.
34  *
35  * \param [in] d pointer to Data structure
36  * \param [in] dir the direction of propagation
37  * \param [in] log_freq the output log frequency
38  * \param [in,out] grid pointer to array of Grid structures
39  *
40  *********************************************************************** */
41 {
42  int i, j, k, ngh;
43  int n, n_glob;
44  static int first_call = 1;
45  double ***pr, ***dn, dp;
46 
47  dn = d->Vc[RHO];
48  #if HAVE_ENERGY
49  pr = d->Vc[PRS];
50  #else
51  pr = d->Vc[RHO];
52  #endif
53 
54  ngh = grid[dir].nghost;
55 
56 /* -- save original domain offsets
57  and return for the first time -- */
58 
59  if (first_call){
60  if (dir == IDIR) {
61  jd_nbeg = IBEG; jd_nend = IEND;
63  }else if (dir == JDIR){
64  jd_nbeg = JBEG; jd_nend = JEND;
66  }else if (dir == KDIR){
67  jd_nbeg = KBEG; jd_nend = KEND;
69  }
70 
71  rbound = grid[dir].rbound;
72  first_call = 0;
73  return;
74  }
75 
76 /* --------------------------------------
77  find where grad(p) is not zero and
78  add safety guard cells
79  -------------------------------------- */
80 
81  n = GetRightmostIndex(dir, pr) + 2*ngh;
82 
83  if (n < jd_nbeg + ngh) n = jd_nbeg + ngh;
84  if (n > jd_nend) n = jd_nend;
85 
86  #ifdef PARALLEL
87  MPI_Allreduce (&n, &n_glob, 1, MPI_INT, MPI_MAX, MPI_COMM_WORLD);
88  n = n_glob;
89  #endif
90 
91  if (g_stepNumber%log_freq==0){
92 /* print1 ("- SetJetDomain: index %d / %d\n",n,jd_nend); */
93  }
94 
95 /* ------------------------------------------------------------------
96  Change global integer variables giving the rightmost integration
97  indexes. Also, suppress the rightmost physics boundary (rbound)
98  if solution has not yet reached it.
99  ------------------------------------------------------------------ */
100 
101  if (dir == IDIR) {
102  IEND = grid[IDIR].lend = n;
103  NX1_TOT = IEND + ngh;
104  NX1 = IEND - ngh;
105 
106  grid[IDIR].rbound = rbound;
107  if (jd_nend != IEND) grid[IDIR].rbound = 0;
108 
109  } else if (dir == JDIR){
110 
111  JEND = grid[JDIR].lend = n;
112  NX2_TOT = JEND + ngh;
113  NX2 = JEND - ngh;
114  grid[JDIR].rbound = rbound;
115  if (jd_nend != JEND) grid[JDIR].rbound = 0;
116 
117  }else if (dir == KDIR){
118 
119  KEND = grid[KDIR].lend = n;
120  NX3_TOT = KEND + ngh;
121  NX3 = KEND - ngh;
122 
123  grid[KDIR].rbound = rbound;
124  if (jd_nend != KEND) grid[KDIR].rbound = 0;
125  }
126 
127 /* ------------------------------------------------------
128  Recompute RBox(es) after indices have been changed
129  ------------------------------------------------------ */
130 
131  SetRBox();
132 
133 /*
134  print1 ("Box = %d/%d\n", n, jd_nend);
135  {
136  double t0, t1, i0, i1;
137  FILE *fp;
138  t0 = g_time;
139  t1 = t0 + g_dt;
140  i0 = (int)(t0/0.5);
141  i1 = (int)(t1/0.5);
142 
143  if (i0 != i1){
144  fp = fopen("box.out","w");
145  fprintf (fp,"%f %f %f %f\n",0.0, grid[IDIR].x[IEND],
146  0.0, grid[JDIR].x[JEND]);
147  fclose(fp);
148  }
149  }
150 */
151 }
152 
153 /* ********************************************************************* */
154 void UnsetJetDomain (const Data *d, int dir, Grid *grid)
155 /*!
156  * Restore original (full domain) indexes.
157  *
158  *********************************************************************** */
159 {
160 
161  if (dir == IDIR){
162  IBEG = grid[IDIR].lbeg = jd_nbeg;
163  IEND = grid[IDIR].lend = jd_nend;
164  NX1_TOT = jd_ntot;
165  NX1 = jd_npt;
166  grid[IDIR].rbound = rbound;
167  }
168 
169  if (dir == JDIR){
170  JBEG = grid[JDIR].lbeg = jd_nbeg;
171  JEND = grid[JDIR].lend = jd_nend;
172  NX2_TOT = jd_ntot;
173  NX2 = jd_npt;
174  grid[JDIR].rbound = rbound;
175  }
176 
177  if (dir == KDIR){
178  KBEG = grid[KDIR].lbeg = jd_nbeg;
179  KEND = grid[KDIR].lend = jd_nend;
180  NX3_TOT = jd_ntot;
181  NX3 = jd_npt;
182  grid[KDIR].rbound = rbound;
183  }
184 
185 /* ------------------------------------------------------
186  Recompute RBox(es) after indices have been changed
187  ------------------------------------------------------ */
188 
189  SetRBox();
190 
191 }
192 
193 /* ********************************************************************* */
194 int GetRightmostIndex (int dir, double ***q)
195 /*!
196  *
197  * Find the local index j where grad(p) exceeds
198  * a ceratin threshold
199  *
200  *********************************************************************** */
201 {
202  int i, j, k;
203  double dp;
204 
205 /* -- backward sweep on x-axis -- */
206 
207  if (dir == IDIR){
208  for (i = jd_nend; i >= jd_nbeg; i--){
209  KDOM_LOOP(k){
210  JDOM_LOOP(j){
211 
212  dp = q[k][j][i+1] - q[k][j][i-1];
213  dp /= q[k][j][i+1] + q[k][j][i-1];
214 
215  if (fabs(dp) > 1.e-5) return(i);
216  }}}
217  }
218 
219 /* -- backward sweep on y-axis -- */
220 
221  if (dir == JDIR){
222  for (j = jd_nend; j >= jd_nbeg; j--){
223  KDOM_LOOP(k){
224  IDOM_LOOP(i){
225 
226  dp = q[k][j+1][i] - q[k][j-1][i];
227  dp /= q[k][j+1][i] + q[k][j-1][i];
228 
229  if (fabs(dp) > 1.e-5) return(j);
230  }}}
231  }
232 
233 /* -- backward sweep on z-axis -- */
234 
235  if (dir == KDIR){
236  for (k = jd_nend; k >= jd_nbeg; k--){
237  JDOM_LOOP(j){
238  IDOM_LOOP(i){
239 
240  dp = q[k+1][j][i] - q[k-1][j][i];
241  dp /= q[k+1][j][i] + q[k-1][j][i];
242 
243  if (fabs(dp) > 1.e-5) return(k);
244  }}}
245  }
246 
247  return(-1);
248 }
static int jd_ntot
Definition: jet_domain.c:25
static int jd_npt
Definition: jet_domain.c:25
#define KDOM_LOOP(k)
Definition: macros.h:36
static int n
Definition: analysis.c:3
static int rbound
Definition: jet_domain.c:25
long int NX1
Number of interior zones in the X1 directions (boundaries excluded) for the local processor...
Definition: globals.h:48
#define RHO
Definition: mod_defs.h:19
int rbound
Same as lbound, but for the right edge of the grid.
Definition: structs.h:112
long int NX2_TOT
Total number of zones in the X2 direction (boundaries included) for the local processor.
Definition: globals.h:57
double **** Vc
The main four-index data array used for cell-centered primitive variables.
Definition: structs.h:31
int lend
Local end index for the local array.
Definition: structs.h:118
int lbeg
Local start index for the local array.
Definition: structs.h:117
#define KDIR
Definition: pluto.h:195
#define JDOM_LOOP(j)
Definition: macros.h:35
long int g_stepNumber
Gives the current integration step number.
Definition: globals.h:97
long int NX2
Number of interior zones in the X2 directions (boundaries excluded) for the local processor...
Definition: globals.h:50
void UnsetJetDomain(const Data *d, int dir, Grid *grid)
Definition: jet_domain.c:154
#define IDIR
Definition: pluto.h:193
static int GetRightmostIndex(int, double ***)
Definition: jet_domain.c:194
static int jd_nend
Definition: jet_domain.c:25
Definition: structs.h:78
long int NX3_TOT
Total number of zones in the X3 direction (boundaries included) for the local processor.
Definition: globals.h:59
int j
Definition: analysis.c:2
int nghost
Number of ghost zones.
Definition: structs.h:104
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
void SetRBox(void)
Definition: rbox.c:33
PLUTO main header file.
Definition: structs.h:30
int i
Definition: analysis.c:2
static int jd_nbeg
Definition: jet_domain.c:25
void SetJetDomain(const Data *d, int dir, int log_freq, Grid *grid)
Definition: jet_domain.c:29
long int KBEG
Lower grid index of the computational domain in the the X3 direction for the local processor...
Definition: globals.h:43
long int KEND
Upper grid index of the computational domain in the the X3 direction for the local processor...
Definition: globals.h:45
#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
static Runtime q
#define IDOM_LOOP(i)
Definition: macros.h:34
long int JEND
Upper grid index of the computational domain in the the X2 direction for the local processor...
Definition: globals.h:41
long int NX1_TOT
Total number of zones in the X1 direction (boundaries included) for the local processor.
Definition: globals.h:55
long int NX3
Number of interior zones in the X3 directions (boundaries excluded) for the local processor...
Definition: globals.h:52
long int IBEG
Lower grid index of the computational domain in the the X1 direction for the local processor...
Definition: globals.h:35