PLUTO
analysis.c
Go to the documentation of this file.
1 {
2  int i,j,k;
3  static int n = 1;
4  double ***divB, dB;
5  double tot[2048], max;
6  double atot, gtot, gmax;
7  FILE *fp;
8 
9  divB = GLM_GetDivB();
10  if (divB == NULL) {
11  if (prank == 0){
12  fp = fopen("divb.dat","w");
13  fprintf (fp,"# \n");
14  fprintf (fp,"# time tot(t) av_tot(t) max\n");
15  fprintf (fp,"# ------------------------------------\n");
16  fclose(fp);
17  }
18  return;
19  }
20  tot[n] = 0.0;
21  max = 0.0;
22  DOM_LOOP(k,j,i){
23  dB = fabs(divB[k][j][i]);
24  tot[n] += dB;
25  max = MAX(dB, max);
26  }
28  tot[n] /= (double)grid[IDIR].np_int_glob; ,
29  tot[n] /= (double)grid[JDIR].np_int_glob; ,
30  tot[n] /= (double)grid[KDIR].np_int_glob;
31  )
32 
33  #ifdef PARALLEL
34  MPI_Allreduce (tot + n, &gtot, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
35  MPI_Allreduce (&max, &gmax, 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD);
36  tot[n] = gtot;
37  max = gmax;
38  #endif
39 
40 /* -- compute average total -- */
41 
42  atot = 0.0;
43  for (i = 1; i <= n; i++) atot += tot[i];
44  atot /= (double)n;
45 
46 /* -- write to file -- */
47 
48  if (prank == 0){
49  printf ("> writing divB to disk (%d)\n",n);
50  fp = fopen("divb.dat","a");
51  fprintf (fp, "%f %f %f %f\n",g_time, tot[n], atot, max);
52  fclose(fp);
53  }
54  n++;
55 
56 }
57 
58 -----------------------------------------------------------
59 #! /bin/sh
60 
61 for xx in "0.1" "0.2" "0.4" "0.8" "1.6" "3.2"
62 do
63  echo "Doing $xx"
64  ./pluto -par $xx > out.log
65  /bin/cp divb.dat divb.$xx.dat
66 done
67 
68 
#define MAX(a, b)
Definition: macros.h:101
double gmax
Definition: analysis.c:6
DOM_LOOP(k, j, i)
Definition: analysis.c:22
static int n
Definition: analysis.c:3
double dB
Definition: analysis.c:4
int prank
Processor rank.
Definition: globals.h:33
#define KDIR
Definition: pluto.h:195
double atot
Definition: analysis.c:6
#define IDIR
Definition: pluto.h:193
int j
Definition: analysis.c:2
int k
Definition: analysis.c:2
double *** divB
Definition: analysis.c:4
double gtot
Definition: analysis.c:6
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
double *** GLM_GetDivB(void)
Definition: glm.c:445
int i
Definition: analysis.c:2
double g_time
The current integration time.
Definition: globals.h:117
FILE * fp
Definition: analysis.c:7
#define JDIR
Definition: pluto.h:194
double tot[2048]
Definition: analysis.c:5
double max
Definition: analysis.c:5