dfnTrans
Code for Particle Tracking simulations in 3D DFN
output.c
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <search.h>
3 #include <stdlib.h>
4 #include <math.h>
5 #include <string.h>
6 #include "FuncDef.h"
7 #include <unistd.h>
8 #include <time.h>
9 #include<sys/stat.h>
10 #include <stdio.h>
11 
12 struct inpfile {
13  char filename[120];
14  long int flag;
15  double param;
16 };
18 
19 void OutputMarPlumDisp (int currentnum, char path[125])
20 /****** function reads trajectory files and forms output for MARFA, PLUMECALC, ********************/
21 {
22  struct inpfile inputfile;
23  char filename[125], cs;
24  unsigned int marfa = 0, plumec = 0, i, j;
25  double time_days = 0.0;
26  double time_years = 0.0;
27  int res = 0;
28  FILE *plum;
29  FILE *mar;
30  time_years = (365.0 * 24.0 * 60.0 * 60.0) / timeunit; // units for marfa
31  time_days = (24.0 * 60.0 * 60.0) / timeunit; //units for plumecalc
32  inputfile = Control_File("out_marfa:", 10);
33  res = strncmp(inputfile.filename, "yes", 3);
34 
35  if (res == 0) {
36  marfa = 1;
37  sprintf(filename, "%s/trajectories.dat", maindir);
38  mar = OpenFile(filename, "w");
39  fprintf(mar, "! The file produced for MARFA and contains rajectories of particle, simulated using \n");
40  fprintf(mar, "! DFNTrans code: particle tracking code in discrete fracture network.\n");
41  // fprintf(mar,"../../../ PUT A RIGHT PATH TO THE DATA!! \n");
42  fprintf(mar, "/scratch/er/dharp/source/MARFA3.2.3/data/ \n");
43  fprintf(mar, "%05d \n", currentnum);
44  }
45 
46  inputfile = Control_File("out_plumecalc:", 14);
47  res = strncmp(inputfile.filename, "yes", 3);
48 
49  if (res == 0) {
50  plumec = 1;
51  sprintf(filename, "%s/trajout", maindir);
52  plum = OpenFile(filename, "w");
53  fprintf(plum, "! The file produced for PLUMECALC and contains rajectories of particle, simulated using \n");
54  fprintf(plum, "! DFNTrans code: particle tracking code in discrete fracture network.\n");
55  fprintf(plum, "%d \n", currentnum);
56  }
57 
58  int status, traj_o = 0;
59  inputfile = Control_File("out_traj:", 9);
60  res = strncmp(inputfile.filename, "yes", 3);
61 
62  if (res == 0) {
63  traj_o = 1;
64  }
65 
66  double posx = 0.0, posy = 0.0, posz = 0.0, vx = 0.0, vy = 0.0, vz = 0.0, ttime = 0.0, apert = 0.0, beta = 0.0, ntime, bbet = 0.0, pres = 0.0;
67  unsigned int cell, fr, ts, numtimes, inters;
68 
69  // lopp on particles trajectories files
70  for (i = 1; i <= currentnum; i++) {
71  sprintf(filename, "%s/traject_%d", path, i);
72  FILE *tr = OpenFile(filename, "r");
73 
74  if (fscanf(tr, "%d \n", &numtimes) != 1) {
75  printf("Error");
76  }
77 
78  if (plumec == 1) {
79  fprintf(plum, "%d \n", numtimes);
80  }
81 
82  do {
83  cs = fgetc(tr);
84  } while (cs != '\n');
85 
86  // current time step, x-, y-, z- pos., Vx, Vy, Vz at ths positions, # of cell, #of fracture, travel time, aperture , beta, intersect. fracture ID, fluid pressure at particle's positiona
87 
88  for (j = 1; j <= numtimes; j++) {
89  if (fscanf(tr, "%d %lf %lf %lf %lf %lf %lf %d %d %lf %lf %lf %d %lf\n", &ts, &posx, &posy, &posz, &vx, &vy, &vz, &cell, &fr, &ttime, &apert, &beta, &inters, &pres ) != 14) {
90  printf("ErrorTr");
91  }
92 
93  // MARFA output
94  if (marfa == 1) {
95  if (j == 1) {
96  fprintf(mar, "Part%05d %4.4f %4.4f %4.4f \n", i, posx, posy, posz);
97  } else {
98  ntime = ttime / time_years;
99  bbet = ntime / (ttime / beta);
100  fprintf(mar, "%7.4f %7.4f %7.4f rtID %3.8E %3.8E %3.8E \n", posx, posy, posz, ntime, bbet, 0.00);
101  }
102  }
103 
104  //PLUMECALC output
105  if (plumec == 1) {
106  ntime = ttime / time_days;
107  fprintf(plum, "%f %f %f %f \n", ntime, posx, posy, posz);
108  }
109  }
110 
111  fclose(tr);
112 
113  if (traj_o == 0) {
114  status = remove(filename);
115 
116  if( status != 0 ) {
117  printf("Unable to delete the file %s\n", filename);
118  perror("Error");
119  }
120  }
121 
122  if (marfa == 1) {
123  fprintf(mar, " END \n");
124  }
125  } //end loop on particles trajectories files
126 
127  if (marfa == 1) {
128  fclose(mar);
129  }
130 
131  if (plumec == 1) {
132  fclose(plum);
133  }
134 
135  return;
136 }
FILE * OpenFile(char filen[120], char fileopt[2])
Definition: ReadGridInit.c:664
struct element * cell
Definition: main.c:42
struct inpfile Control_File(char fileobject[], int ctr)
Definition: ReadGridInit.c:998
char maindir[125]
Definition: main.c:43
double timeunit
Definition: main.c:51
unsigned int plumec
Definition: TrackingPart.c:31
unsigned int traj_o
Definition: TrackingPart.c:30
unsigned int marfa
Definition: TrackingPart.c:31
void OutputMarPlumDisp(int currentnum, char path[125])
Definition: output.c:19
char filename[120]