PLUTO
set_output.c
Go to the documentation of this file.
1 /* ///////////////////////////////////////////////////////////////////// */
2 /*!
3  \file
4  \brief Set/retrieve output data attributes.
5 
6  The function SetOutput() sets, for each output data type (DBL, FLT,
7  VTK etc..) the default attributes of the corresponding ::Output structures.
8  These include the variable name, a pointer to the actual
9  3D array, the centering of the variable (center/staggered), a
10  conditional inclusion flag (telling if the corresponding variable has
11  to be written in the specified format), and so on.
12 
13  The function SetDumpVar() can be used to include or exclude a given
14  variable to be written using a particular output format.
15 
16  The function GetUserVar() returns the memory address to a
17  user-defined 3D array.
18 
19  \note Starting with PLUTO 4.1 velocity and magnetic field components
20  will be saved as scalars when writing VTK output.
21  If this is not what you want and prefer to save them as vector
22  fields (VTK VECTOR attribute), set VTK_VECTOR_DUMP to YES
23  in your definitions.h.
24 
25  \authors A. Mignone (mignone@ph.unito.it)
26  \date Aug 24, 2015
27 */
28 /* ///////////////////////////////////////////////////////////////////// */
29 #include "pluto.h"
30 
31 #ifndef VTK_VECTOR_DUMP
32  #define VTK_VECTOR_DUMP NO
33 #endif
34 
36 /* ********************************************************************* */
37 void SetOutput (Data *d, Runtime *runtime)
38 /*!
39  * Set default attributes (variable names, pointers to data structures,
40  * filename extensions, etc...) of the output structures.
41  *
42  * \param [in] d pointer to Data structure
43  * \param [in] runtime pointer to Runtime structure
44  *
45  *********************************************************************** */
46 {
47  int nv, i, k;
48  Output *output;
49 
50  if (runtime->user_var > 0)
51  d->Vuser = ARRAY_4D(runtime->user_var, NX3_TOT, NX2_TOT, NX1_TOT, double);
52  else
53  d->Vuser = NULL;
54 
55  all_outputs = runtime->output;
56 
57 /* ---------------------------------------------
58  Loop on output types
59  --------------------------------------------- */
60 
61  for (k = 0; k < MAX_OUTPUT_TYPES; k++){
62  output = runtime->output + k;
63  output->var_name = ARRAY_2D(64,128,char);
64  output->stag_var = ARRAY_1D(64, int);
65  output->dump_var = ARRAY_1D(64, int);
66  strcpy(output->dir, runtime->output_dir); /* output directory is the same */
67  /* for all outputs (easy to change) */
68  output->nfile = -1;
69 
70  /* -- set variables names -- */
71 
72  SetDefaultVarNames(output);
73 
74  /* -- Set array pointers -- */
75 
76  for (nv = 0; nv < NVAR; nv++){
77  output->V[nv] = d->Vc[nv];
78  output->stag_var[nv] = -1; /* -- means cell centered -- */
79  }
80  nv = NVAR;
81  #ifdef STAGGERED_MHD
82  D_EXPAND(
83  output->var_name[nv] = "bx1s";
84  output->V[nv] = d->Vs[BX1s];
85  output->stag_var[nv++] = 0; ,
86 
87  output->var_name[nv] = "bx2s";
88  output->V[nv] = d->Vs[BX2s];
89  output->stag_var[nv++] = 1; ,
90 
91  output->var_name[nv] = "bx3s";
92  output->V[nv] = d->Vs[BX3s];
93  output->stag_var[nv++] = 2;
94  )
95  #endif
96 
97  #if UPDATE_VECTOR_POTENTIAL == YES
98  #if DIMENSIONS == 3
99  output->var_name[nv] = "Ax1";
100  output->V[nv] = d->Ax1;
101  output->stag_var[nv++] = -1; /* -- vector potential is
102  computed at cell center -- */
103 
104  output->var_name[nv] = "Ax2";
105  output->V[nv] = d->Ax2;
106  output->stag_var[nv++] = -1;
107  #endif
108  output->var_name[nv] = "Ax3";
109  output->V[nv] = d->Ax3;
110  output->stag_var[nv++] = -1;
111  #endif
112  output->nvar = nv;
113 
114  /* -- repeat for user defined vars -- */
115 
116  for (i = 0; i < runtime->user_var; i++){
117  sprintf (output->var_name[i + nv], "%s", runtime->user_var_name[i]);
118  output->V[i + nv] = d->Vuser[i];
119  output->stag_var[i + nv] = -1; /* -- assume cell-centered -- */
120  }
121 
122  /* -- add user vars to total number of variables -- */
123 
124  output->nvar += runtime->user_var;
125 
126  /* -- select which variables are going to be dumped to disk -- */
127 
128  for (nv = output->nvar; nv--; ) output->dump_var[nv] = YES;
129  #if ENTROPY_SWITCH
130  output->dump_var[ENTR] = NO;
131  #endif
132 
133  switch (output->type){
134  case DBL_OUTPUT: /* -- dump ALL variables -- */
135  sprintf (output->ext,"dbl");
136  break;
137  case FLT_OUTPUT: /* -- do not dump staggered fields (below)-- */
138  sprintf (output->ext,"flt");
139  break;
140  case DBL_H5_OUTPUT: /* -- dump ALL variables -- */
141  sprintf (output->ext,"dbl.h5");
142  break;
143  case FLT_H5_OUTPUT: /* -- do not dump staggered fields (below)-- */
144  sprintf (output->ext,"flt.h5");
145  break;
146  case VTK_OUTPUT: /* -- do not dump staggered fields (below) -- */
147  sprintf (output->ext,"vtk");
148  #if VTK_VECTOR_DUMP == YES
149  D_EXPAND(output->dump_var[VX1] = VTK_VECTOR; ,
150  output->dump_var[VX2] = NO; ,
151  output->dump_var[VX3] = NO;)
152  #if PHYSICS == MHD || PHYSICS == RMHD
153  D_EXPAND(output->dump_var[BX1] = VTK_VECTOR; ,
154  output->dump_var[BX2] = NO; ,
155  output->dump_var[BX3] = NO;)
156  #endif
157  #endif
158  break;
159  case TAB_OUTPUT: /* -- do not dump staggered fields -- */
160  sprintf (output->ext,"tab");
161  break;
162  case PPM_OUTPUT: /* -- dump density only -- */
163  sprintf (output->ext,"ppm");
164  for (nv = output->nvar; nv--; ) output->dump_var[nv] = NO;
165  break;
166  case PNG_OUTPUT: /* -- dump density only -- */
167  sprintf (output->ext,"png");
168  for (nv = output->nvar; nv--; ) output->dump_var[nv] = NO;
169  break;
170  }
171 
172  /* ---------------------------------------------------------------
173  for divergence cleaning never dump the scalar psi unless
174  the output type can be potentially used for restart
175  --------------------------------------------------------------- */
176 
177  #ifdef GLM_MHD
178  if (output->type == DBL_OUTPUT || output->type == DBL_H5_OUTPUT)
179  output->dump_var[PSI_GLM] = YES;
180  else
181  output->dump_var[PSI_GLM] = NO;
182  #endif
183  }
184 
185 /* -- exclude stag components from all output except .dbl -- */
186 
187  #ifdef STAGGERED_MHD
188  D_EXPAND( SetDumpVar ("bx1s", VTK_OUTPUT, NO); ,
189  SetDumpVar ("bx2s", VTK_OUTPUT, NO); ,
190  SetDumpVar ("bx3s", VTK_OUTPUT, NO);)
191  D_EXPAND( SetDumpVar ("bx1s", FLT_OUTPUT, NO); ,
192  SetDumpVar ("bx2s", FLT_OUTPUT, NO); ,
193  SetDumpVar ("bx3s", FLT_OUTPUT, NO);)
194  D_EXPAND( SetDumpVar ("bx1s", FLT_H5_OUTPUT, NO); ,
195  SetDumpVar ("bx2s", FLT_H5_OUTPUT, NO); ,
196  SetDumpVar ("bx3s", FLT_H5_OUTPUT, NO);)
197  D_EXPAND( SetDumpVar ("bx1s", TAB_OUTPUT, NO); ,
198  SetDumpVar ("bx2s", TAB_OUTPUT, NO); ,
199  SetDumpVar ("bx3s", TAB_OUTPUT, NO);)
200  #endif
201 
202 /* -- defaults: dump density only in ppm and png formats -- */
203 
204  SetDumpVar ("rho", PPM_OUTPUT, YES);
205  SetDumpVar ("rho", PNG_OUTPUT, YES);
206 
207  ChangeDumpVar();
208 }
209 
210 /* ********************************************************************* */
211 int SetDumpVar (char *var_name, int out_type, int flag)
212 /*!
213  * Include ('flag == YES') or exclude ('flag == NO') the
214  * variable associated to 'var_name' in or from the output
215  * type 'out_type'.
216  * If 'out_type' corresponds to an image (ppm or png), create
217  * a correspdonding Image structure.
218  *
219  * \param [in] var_name the name of the variable (e.g. "rho", "vx1",...)
220  * \param [in] out_type select the output type (e.g., DBL_OUTPUT,
221  * VTK_OUTPUT, and so forth)
222  * \param [in] flag an integer values (YES/NO).
223  *********************************************************************** */
224 {
225  int k, nv;
226  Output *output;
227 
228  for (k = 0; k < MAX_OUTPUT_TYPES; k++){
229  output = all_outputs + k;
230  if (output->type == out_type) break;
231  }
232 
233  for (nv = output->nvar; nv--; ) {
234  if (strcmp(output->var_name[nv], var_name) == 0) {
235  output->dump_var[nv] = flag;
236  if (flag == YES){
237  if (out_type == PPM_OUTPUT || out_type == PNG_OUTPUT){
238  CreateImage (var_name);
239  }
240  }
241  return(0);
242  }
243  }
244 
245  print1 ("! var_name '%s' cannot be set/unset for writing\n",var_name);
246  return(1);
247 
248 }
249 
250 /* ********************************************************************* */
251 double ***GetUserVar (char *var_name)
252 /*!
253  * return a pointer to the 3D array associated with the
254  * variable named 'var_name'.
255  *
256  *********************************************************************** */
257 {
258  int indx = -1;
259 
260  while (strcmp(all_outputs->var_name[++indx], var_name)){
261  if (all_outputs->V[indx] == NULL){
262  print1 ("! Error: uservar '%s' is not allocated\n");
263  QUIT_PLUTO(1);
264  }
265  }
266  return (all_outputs->V[indx]);
267 }
int user_var
The number of additional user-variables being held in memory and written to disk. ...
Definition: structs.h:264
double **** Vs
The main four-index data array used for face-centered staggered magnetic fields.
Definition: structs.h:43
double *** GetUserVar(char *var_name)
Definition: set_output.c:251
#define VX2
Definition: mod_defs.h:29
#define FLT_H5_OUTPUT
Definition: pluto.h:83
#define PPM_OUTPUT
Definition: pluto.h:85
double *** V[64]
pointer to arrays being written - same for all
Definition: structs.h:247
#define VTK_VECTOR
Definition: pluto.h:88
Output output[MAX_OUTPUT_TYPES]
Definition: structs.h:272
void print1(const char *fmt,...)
Definition: amrPluto.cpp:511
int nfile
current number being saved - one per output
Definition: structs.h:237
char output_dir[256]
The name of the output directory (output_dir for static PLUTO, Output_dir for PLUTO-Chombo) ...
Definition: structs.h:269
#define YES
Definition: pluto.h:25
void SetDefaultVarNames(Output *)
Definition: var_names.c:4
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
char user_var_name[128][128]
Definition: structs.h:268
double *** Ax3
Vector potential component in the direction.
Definition: structs.h:53
#define PSI_GLM
Definition: mod_defs.h:34
char dir[256]
output directory name
Definition: structs.h:244
#define BX3s
Definition: ct.h:29
#define VX1
Definition: mod_defs.h:28
char ext[8]
output extension
Definition: structs.h:243
#define VTK_OUTPUT
Definition: pluto.h:81
#define DBL_H5_OUTPUT
Definition: pluto.h:82
long int NX3_TOT
Total number of zones in the X3 direction (boundaries included) for the local processor.
Definition: globals.h:59
#define ARRAY_4D(nx, ny, nz, nv, type)
Definition: prototypes.h:173
int k
Definition: analysis.c:2
void CreateImage(char *)
Definition: set_image.c:8
int nvar
tot.
Definition: structs.h:234
static Output * all_outputs
Definition: set_output.c:35
#define BX1s
Definition: ct.h:27
#define MAX_OUTPUT_TYPES
Definition: pluto.h:95
int * dump_var
select vars being written - one per output
Definition: structs.h:240
#define TAB_OUTPUT
Definition: pluto.h:84
#define FLT_OUTPUT
Definition: pluto.h:80
#define BX3
Definition: mod_defs.h:27
PLUTO main header file.
#define ARRAY_1D(nx, type)
Definition: prototypes.h:170
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
#define DBL_OUTPUT
Definition: pluto.h:79
#define BX1
Definition: mod_defs.h:25
#define VX3
Definition: mod_defs.h:30
int type
output format (DBL, FLT, ...) - one per output
Definition: structs.h:233
int * stag_var
centered or staggered variable - same for all
Definition: structs.h:239
#define BX2s
Definition: ct.h:28
void SetOutput(Data *d, Runtime *runtime)
Definition: set_output.c:37
#define ARRAY_2D(nx, ny, type)
Definition: prototypes.h:171
#define BX2
Definition: mod_defs.h:26
double *** Ax1
Vector potential component in the direction.
Definition: structs.h:51
double **** Vuser
Array storing user-defined supplementary variables written to disk.
Definition: structs.h:49
void ChangeDumpVar()
#define NVAR
Definition: pluto.h:609
#define QUIT_PLUTO(e_code)
Definition: macros.h:125
double *** Ax2
Vector potential component in the direction.
Definition: structs.h:52
#define PNG_OUTPUT
Definition: pluto.h:86
long int NX1_TOT
Total number of zones in the X1 direction (boundaries included) for the local processor.
Definition: globals.h:55
char ** var_name
variable names - same for all
Definition: structs.h:242
#define NO
Definition: pluto.h:26
int SetDumpVar(char *var_name, int out_type, int flag)
Definition: set_output.c:211