The FARGO_THORIN code developer's guide
 All Data Structures Files Functions Variables Typedefs Macros
Output.c
Go to the documentation of this file.
1 /** \file Output.c
2 
3 Contains most of the functions that write the output files.
4 In addition to the writing of hydrodynamics files (handled by
5 SendOutput ()), this file also contains the functions that update
6 the planet.dat and bigplanet.dat files, and the functions that
7 seek information about the planets at a restart.
8 
9 @author THORIN modifications by
10 Ondřej Chrenko <chrenko@sirrah.troja.mff.cuni.cz>, Copyright (C) 2017;
11 original code by Frédéric Masset
12 
13 */
14 
15 #include "fargo.h"
16 
18 extern real LostMass, OmegaFrame;
19 extern boolean Write_Density, Write_Velocity, IsDisk;
20 
22 PlanetarySystem *sys;
23 {
24  FILE *output;
25  char name[256];
26  int i, n;
27  n = sys->nb;
28  if (!CPU_Master) return;
29  for (i = 0; i < n; i++) {
30  sprintf (name, "%splanet%d.dat", OUTPUTDIR, i);
31  output = fopenp (name, "w"); /* This empties the file */
32  fclose (output);
33  }
34 }
35 
37 int TimeStep;
38 int n;
39 {
40  FILE *output;
41  char name[256];
42  if (!CPU_Master) return;
43  printf ("Updating 'planet%d.dat'...", n);
44  fflush (stdout);
45  sprintf (name, "%splanet%d.dat", OUTPUTDIR, n);
46  output = fopenp (name, "a");
47  fprintf (output, "%d\t%#.18g\t%#.18g\t%#.18g\t%#.18g\t%#.18g\t%#.18g\t%#.18g\t%#.18g\n",\
49  fclose (output);
50  printf ("done\n");
51  fflush (stdout);
52 }
53 
54 void WritePlanetSystemFile (sys, t)
55 PlanetarySystem *sys;
56 int t;
57 {
58  int i, n;
59  n = sys->nb;
60  for (i = 0; i < n; i++) {
61  Xplanet = sys->x[i];
62  Yplanet = sys->y[i];
63  VXplanet = sys->vx[i];
64  VYplanet = sys->vy[i];
65  MplanetVirtual = sys->mass[i];
66  WritePlanetFile (t, i);
67  }
68 }
69 
70 
72 int TimeStep;
73 int n;
74 {
75  FILE *output;
76  char name[256];
77  if (!CPU_Master) return;
78  sprintf (name, "%sbigplanet%d.dat", OUTPUTDIR, n);
79  output = fopenp (name, "a");
80  fprintf (output, "%d\t%#.18g\t%#.18g\t%#.18g\t%#.18g\t%#.18g\t%#.18g\t%#.18g\t%#.18g\n",\
82  fclose (output);
83 }
84 
86 PlanetarySystem *sys;
87 int t;
88 {
89  int i, n;
90  n = sys->nb;
91  for (i = 0; i < n; i++) {
92  Xplanet = sys->x[i];
93  Yplanet = sys->y[i];
94  VXplanet = sys->vx[i];
95  VYplanet = sys->vy[i];
96  MplanetVirtual = sys->mass[i];
97  WriteBigPlanetFile (t, i);
98  }
99 }
100 
102 int TimeStep, column, n;
103 {
104  FILE *input;
105  char name[256];
106  char testline[256];
107  int time;
108  char *pt;
109  double value;
110  sprintf (name, "%splanet%d.dat", OUTPUTDIR, n);
111  input = fopen (name, "r");
112  if (input == NULL) {
113  mastererr ("Can't read 'planet%d.dat' file. Aborting restart.\n",n);
114  prs_exit (1);
115  }
116  if (column < 2) {
117  mastererr ("Invalid column number in 'planet%d.dat'. Aborting restart.\n",n);
118  prs_exit (1);
119  }
120  do {
121  pt = fgets (testline, 255, input);
122  sscanf (testline, "%d", &time);
123  } while ((time != TimeStep) && (pt != NULL));
124  if (pt == NULL) {
125  mastererr ("Can't read entry %d in 'planet%d.dat' file. Aborting restart.\n", TimeStep,n);
126  prs_exit (1);
127  }
128  fclose (input);
129  pt = testline;
130  while (column > 1) {
131  pt += strspn(pt, "eE0123456789-.");
132  pt += strspn(pt, "\t :=>_");
133  column--;
134  }
135  sscanf (pt, "%lf", &value);
136  return (real)value;
137 }
138 
139 void RestartPlanetarySystem (timestep, sys)
140 PlanetarySystem *sys;
141 int timestep;
142 {
143  int k;
144  for (k = 0; k < sys->nb; k++) {
145  sys->x[k] = GetfromPlanetFile (timestep, 2, k);
146  sys->y[k] = GetfromPlanetFile (timestep, 3, k);
147  sys->vx[k] = GetfromPlanetFile (timestep, 4, k);
148  sys->vy[k] = GetfromPlanetFile (timestep, 5, k);
149  sys->mass[k] = GetfromPlanetFile (timestep, 6, k);
150  }
151 }
152 
153 void WriteDiskPolar(array, number)
154 PolarGrid *array;
155 int number;
156 {
157  int Nr, Ns;
158  FILE *dump;
159  char name[80];
160  real *ptr;
161  ptr = array->Field;
162  if (CPU_Master)
163  sprintf (name, "%s%s%d.dat", OUTPUTDIR, array->Name, number);
164  else
165  sprintf (name, "%s%s%d.dat.%05d", OUTPUTDIR, array->Name, number, CPU_Rank);
166  Nr = array->Nrad;
167  Ns = array->Nsec;
168  dump = fopenp (name, "w");
169  masterprint ("Writing '%s%d.dat'...", array->Name, number);
170  fflush (stdout);
172 /* We strip the first CPUOVERLAP rings if the current CPU is not the
173  innermost one */
174  if (CPU_Rank > 0) {
175  ptr += CPUOVERLAP*Ns;
176  Nr -=CPUOVERLAP ;
177  }
178 /* We strip the last CPUOVERLAP rings if the current CPU is not the outermost
179  one */
180  if (CPU_Rank < CPU_Number-1) {
181  Nr -=CPUOVERLAP;
182  }
183  fwrite (ptr, sizeof(real), Nr*Ns,dump);
184  fclose(dump);
185  fprintf(stdout, "%d/", CPU_Rank);
186  fflush(stdout);
188  masterprint("done\n");
189 }
190 
191 void WriteDim () {
192  char filename[200];
193  FILE *dim;
194  if (!CPU_Master) return;
195  sprintf (filename, "%sdims.dat", OUTPUTDIR);
196  dim = fopenp (filename, "w");
197  fprintf (dim,"%d\t%d\t\t%d\t%d\t%f\t%d\t%d\t%d\n",\
198  0,0,0,0,RMAX, NTOT/NINTERM, GLOBALNRAD, NSEC);
199  fclose (dim);
200 }
201 
202 void SendOutput (index, dens, gasvr, gasvt, gasenerg, label) /* #THORIN */
203 int index;
204 PolarGrid *dens, *gasvr, *gasvt, *gasenerg, *label;
205 {
206  int local_index;
207  if (CPU_Master)
208  printf ("\n*** OUTPUT %d ***\n", index);
209  local_index = index;
210  if (IsDisk == YES) {
211  if (Write_Density == NO) local_index = 0;
212  WriteDiskPolar (dens, local_index);
213  local_index = index;
214  if (Write_Velocity == NO) local_index = 0;
215  WriteDiskPolar (gasvr, local_index);
216  WriteDiskPolar (gasvt, local_index);
217  local_index = index;
218  if (AdvecteLabel == YES) WriteDiskPolar (label, index);
219  /* #THORIN: Following options can create files: gasenergy.dat, gastemper.dat,
220  * gasdivv.dat, gasqplus.dat, gasqbalance.dat, gaspebbledens.dat,
221  * gaspebblevrad.dat, gaspebblevtheta.dat */
222  if (Write_Energy == YES) WriteDiskPolar (gasenerg, index);
225  if (Write_Qplus == YES) WriteDiskPolar (Qplus, index);
226  if (Write_Qbalance == YES) {
228  WriteDiskPolar (Qbalance, index);
229  }
230  if (Pebbles == YES) {
231  WritePebbles (index);
232  }
234  if (Merge && (CPU_Number > 1)) merge (local_index);
235  }
236 }
237 
238 /* #THORIN: 2DO Deprecated and should be discarded */
239 void ActualizeQbalance () /* #THORIN */
240 {
241  int nr, ns, i, j, l;
242  real *qp, *qm, *qb;
243  /* ----- */
244  qp = Qplus->Field;
245  qm = Qminus->Field;
246  qb = Qbalance->Field;
247  nr = Qplus->Nrad;
248  ns = Qminus->Nsec;
249  for (i=0; i<nr; i++) {
250  for (j=0; j<ns; j++) {
251  l = j + i*ns;
252  qb[l] = qp[l] - qm[l];
253  }
254  }
255 }
256 
257 /** Writes the angular velocity of the
258  * coordinate system */
259 void DumpOmegaFrame (TimeStep) /* #THORIN */
260 int TimeStep;
261 {
262  FILE *output;
263  char name[256];
264  if (!CPU_Master) return;
265  printf ("Dumping 'OmegaFrame' ... ");
266  fflush (stdout);
267  sprintf (name, "%somegaframe.dat", OUTPUTDIR);
268  output = fopenp (name, "a");
269  fprintf (output, "%d\t%#.18g\n",\
270  TimeStep, OmegaFrame);
271  fclose (output);
272  printf ("done\n");
273  fflush (stdout);
274 }
275 
276 /** Finds the angular velocity of the
277  * coordinate system in 'omegaframe.dat'
278  * at a given TimeStep */
279 real GetOmegaFrame (TimeStep) /* #THORIN */
280 int TimeStep;
281 {
282  FILE *input;
283  char name[256];
284  char testline[256];
285  int time;
286  char *pt;
287  double value;
288  sprintf (name, "%somegaframe.dat", OUTPUTDIR);
289  input = fopen (name, "r");
290  if (input == NULL) {
291  mastererr ("Can't read 'omegaframe.dat' file. Aborting restart.\n");
292  prs_exit (1);
293  }
294  do {
295  pt = fgets (testline, 255, input);
296  sscanf (testline, "%d", &time);
297  } while ((time != TimeStep) && (pt != NULL));
298  if (pt == NULL) {
299  mastererr ("Can't read entry %d in 'omegaframe.dat' file. Aborting restart.\n", TimeStep);
300  prs_exit (1);
301  }
302  fclose (input);
303  pt = testline;
304  pt += strspn(pt, "eE0123456789-.");
305  pt += strspn(pt, "\t :=>_");
306  sscanf (pt, "%lf", &value);
307  return (real)value;
308 }
309 
void ActualizeQbalance()
Definition: Output.c:239
double real
Definition of the type 'real' used throughout the code.
Definition: types.h:20
real LostMass
PolarGrid * Temperature
Definition: global.h:35
int CPU_Number
Definition: global.h:2
#define YES
Definition: types.h:46
PolarGrid * Qplus
Definition: global.h:35
char OUTPUTDIR[512]
Definition: param_noex.h:11
PolarGrid * Qminus
Definition: global.h:35
real * x
x-coordinate of the planets
Definition: types.h:99
void EmptyPlanetSystemFile(PlanetarySystem *sys)
Definition: Output.c:21
int NINTERM
Definition: param_noex.h:9
real GetOmegaFrame(int TimeStep)
Finds the angular velocity of the coordinate system in 'omegaframe.dat' at a given TimeStep...
Definition: Output.c:279
A structure used to store any scalar fied on the computational domain.
Definition: types.h:37
FILE * fopenp(char *string, char *mode)
Definition: LowTasks.c:163
void MPI_Barrier()
Definition: mpi_dummy.c:64
real * Field
Definition: types.h:40
static real VXplanet
Definition: Output.c:17
int Nrad
Radial size of the grid, in number of zones.
Definition: types.h:38
Contains all the information about a planetary system at a given instant in time. ...
Definition: types.h:96
int nb
Number of planets.
Definition: types.h:97
real PhysicalTime
Definition: global.h:20
static real MplanetVirtual
Definition: Output.c:17
boolean Write_Qplus
Definition: global.h:25
boolean Write_Energy
Definition: global.h:25
void WritePlanetFile(int TimeStep, int n)
Definition: Output.c:36
void WritePebbles(int index)
Outputs the pebble fluid arrays.
Definition: Pebbles.c:743
static real Yplanet
Definition: Output.c:17
boolean Write_Density
Definition: Interpret.c:31
int GLOBALNRAD
Definition: global.h:10
void WriteDim()
Definition: Output.c:191
void WriteBigPlanetFile(int TimeStep, int n)
Definition: Output.c:71
int TimeStep
Definition: global.h:23
void merge(int nb)
Definition: merge.c:15
#define CPUOVERLAP
Definition: fondam.h:13
void SendOutput(int index, PolarGrid *dens, PolarGrid *gasvr, PolarGrid *gasvt, PolarGrid *gasenerg, PolarGrid *label)
Definition: Output.c:202
boolean AdvecteLabel
Definition: global.h:29
int NSEC
Definition: param_noex.h:19
real OmegaFrame
Definition: global.h:20
#define NO
Definition: types.h:47
void RestartPlanetarySystem(int timestep, PlanetarySystem *sys)
Definition: Output.c:139
real RMAX
Definition: param_noex.h:21
boolean Write_Qbalance
Definition: global.h:25
void mastererr(const char *template,...)
Definition: LowTasks.c:49
static real VYplanet
Definition: Output.c:17
real GetfromPlanetFile(int TimeStep, int column, int n)
Definition: Output.c:101
PolarGrid * DivergenceVelocity
Definition: global.h:36
Contains all the include directives requested by the code.
int Nsec
Azimuthal size of the grid, in number of zones.
Definition: types.h:39
boolean Write_Temperature
Definition: global.h:25
boolean Merge
Definition: global.h:29
boolean IsDisk
Definition: Interpret.c:30
int CPU_Rank
Definition: global.h:1
void WritePlanetSystemFile(PlanetarySystem *sys, int t)
Definition: Output.c:54
void DumpOmegaFrame(int TimeStep)
Writes the angular velocity of the coordinate system.
Definition: Output.c:259
static real Xplanet
Definition: Output.c:17
void WriteBigPlanetSystemFile(PlanetarySystem *sys, int t)
Definition: Output.c:85
void WriteDiskPolar(PolarGrid *array, int number)
Definition: Output.c:153
boolean CPU_Master
Definition: global.h:3
boolean Write_Velocity
Definition: Interpret.c:31
int NTOT
Definition: param_noex.h:10
PolarGrid * Qbalance
Definition: global.h:35
#define MPI_COMM_WORLD
Definition: mpi_dummy.h:10
void prs_exit(int numb)
Definition: LowTasks.c:33
void masterprint(const char *template,...)
Definition: LowTasks.c:40
boolean Write_Divergence
Definition: global.h:25
boolean Pebbles
Definition: global.h:27