dfnTrans
Code for Particle Tracking simulations in 3D DFN
main.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 
10 
11 
12 /********* Global variables: *******************************/
13 /* nnodes - number of nodes */
14 /* ncells - number of triangles */
15 /* nfract - number of fractures */
16 /* max_neighb - maximum number of edges in Voronoi polygon */
17 /* npart - initial number of particles */
18 /* np - current particle index */
19 /* nzone_in - number of nodes in flow-in zone */
20 /* nodezonein - dynamic array with node's ID in flow-in zone */
21 /* node - node's data structure */
22 /* fracture - fracture's data structure */
23 /* particle - particle's data structure */
24 /* cell - cell's data structure */
25 /* pflotran and fehm are flags on which flow solver is used*/
26 
27 unsigned int pflotran;
28 unsigned int fehm;
29 unsigned int nnodes;
30 unsigned int ncells;
31 unsigned int nfract;
32 unsigned int max_neighb;
33 unsigned int npart;
34 unsigned int np;
35 unsigned int nzone_in;
36 unsigned int *nodezonein;
37 unsigned int *nodezoneout;
38 unsigned int flag_w;
40 struct vertex *node;
41 struct contam *particle;
42 struct element *cell;
43 char maindir[125];
44 char controlfile[120];
45 
46 double porosity;
47 double density;
48 unsigned long int timesteps;
49 double thickness;
50 double saturation;
51 double timeunit;
52 double totalFluxIn;
53 
54 
55 struct inpfile {
56  char filename[120];
57  long int flag;
58  double param;
59 };
66 int main (int argc, char* controlf[]) {
67  if (argc == 2) {
68  strcpy(controlfile, controlf[1]);
69  printf("The input parameters are read from %s control file. \n", controlf[1]);
70  } else if (argc > 2) {
71  printf("Too many arguments \n");
72  exit (1);
73  } else {
74  printf("Provide the name of Input Control File \n");
75  exit(1);
76  }
77 
78  printf("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
79  printf("~~~ Program: DFNWorks / DFNTrans V1.0, C code, Linux ~~~~~~~~~~~~~\n");
80  printf("~~~~~~~~~~~~ April 1st, 2015. LA-CC-14-091 ~~~~~~~~~~~~~~~~~~~~~~~~~\n");
81  printf("\n This program was prepared at Los Alamos National Laboratory (LANL),\n");
82  printf(" Earth and Environmental Sciences Division, Computational Earth \n");
83  printf(" Science Group (EES-16), Subsurface Flow and Transport Team.\n");
84  printf(" All rights in the program are reserved by the DOE and LANL.\n");
85  printf(" Permission is granted to the public to copy and use this software \n");
86  printf(" without charge, provided that this Notice and any statement of \n");
87  printf(" authorship are reproduced on all copies. Neither the U.S. Government \n");
88  printf(" nor LANS makes any warranty, express or implied, or assumes \n");
89  printf(" any liability or responsibility for the use of this software.\n");
90  printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
91  printf("~~~Developers: Nataliia Makedonska, Scott L. Painter, Carl W. Gable\n");
92  printf(" Last update Apr. 1st, 2015, by N. Makedonska (nataliia@lanl.gov)\n");
93  printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
94  /* define time at which program run starts ****/
95  time_t current_time;
96  char* c_time_string;
97  current_time = time(NULL);
98  c_time_string = ctime(&current_time);
99  printf("\n PROGRAM STARTS. current time: %s\n", c_time_string);
100  /**** open control file to read main parameters **************************/
101  int res;
102  unsigned int seed;
103  struct inpfile inputfile;
104  inputfile = Control_Data("seed:\0", 5 );
105 
106  if (inputfile.flag != 0) {
107  srand48(inputfile.flag);
108  } else {
109  seed = time(0);
110  srand48(seed);
111  printf("The random generator uses the value of seed %d \n", seed);
112  }
113 
114  inputfile = Control_Param("density:", 8);
115  density = inputfile.param;
116  inputfile = Control_Param("porosity:", 9);
117  porosity = inputfile.param;
118  inputfile = Control_Param("satur:", 6);
119  saturation = inputfile.param;
120  inputfile = Control_Param("thickness:", 10);
121  thickness = inputfile.param;
122  inputfile = Control_Param("timesteps:", 10 );
123  timesteps = (int)inputfile.param;
124  inputfile = Control_File("time_units:", 11);
125  res = String_Compare(inputfile.filename, "years");
126 
127  if (res == 0) {
128  timeunit = 365.0 * 24.0 * 60.0 * 60.0;
129  } else {
130  res = String_Compare(inputfile.filename, "days");
131 
132  if (res == 0) {
133  timeunit = 24.0 * 60.0 * 60.0;
134  } else {
135  res = String_Compare(inputfile.filename, "hours");
136 
137  if (res == 0) {
138  timeunit = 60.0 * 60.0;
139  } else {
140  res = String_Compare(inputfile.filename, "minutes");
141 
142  if (res == 0) {
143  timeunit = 60.0;
144  } else {
145  res = String_Compare(inputfile.filename, "seconds");
146 
147  if (res == 0) {
148  timeunit = 1.0;
149  } else {
150  timeunit = 1.0;
151  }
152  }
153  }
154  }
155  }
156 
157  printf(" \n Particles velocities are calculated in [m/%s]. \n", inputfile.filename);
158  inputfile = Control_File("out_dir:", 8 );
159  strcpy(maindir, inputfile.filename);
160  mkdir(maindir, 0777);
161  printf("\n All output files will be written in %s/ \n", maindir);
162  /***** open files and read values of global variables, such as total number of
163  nodes, cells, fractures. Memory allocation.******/
164  printf("---------------------GRID DATA READING--------------------------\n");
165  ReadInit();
166  /**** open files and read GRID data FLOW SOLUTION data into structures ****/
167  ReadDataFiles ();
168  printf("\n Data Reading is Done\n");
169  /*** Read nodes with Dirichlet BC **********************/
170  printf("\n---------------------BOUNDARY CONDITIONS----------------------\n");
172  CheckGrid();
173  /*** rotates fractures into xy plane ******/
174  Convertto2d();
175  printf("\n----------------VELOCITY RECONSTRUCTION-----------------------\n");
176  /*** Darcy's velocities reconstraction *******/
177  DarcyVelocity();
178  /*** define time step as function of polygon volume and velocity ******/
179  DefineTimeStep();
180  Convertto3d();
181  /*** Velocity3D creates a file where all velocities are in 3D ******/
182  /* good for visualization of velocity field in 3D domain */
183  inputfile = Control_File("out_3dflow:", 11 );
184  res = String_Compare(inputfile.filename, "yes");
185 
186  if(res == 0) {
187  Velocity3D();
188  }
189 
190  inputfile = Control_File("out_grid:", 9 );
191  res = String_Compare(inputfile.filename, "yes");
192 
193  if(res == 0) {
194  WritingInit();
195  }
196 
197  printf("\n------------------PARTICLE TRACKING---------------------------\n");
198  ParticleTrack ();
199  /**** free memomry that was allocated for data structures *****/
200  free(fracture);
201  free(node);
202  free(cell);
203  free(nodezonein);
204  free(nodezoneout);
205  free(particle);
206  /**** define time at program end ******/
207  current_time = time(NULL);
208  c_time_string = ctime(&current_time);
209  printf("\n PROGRAM ENDS. current time: %s\n", c_time_string);
210  return 0;
211 }
212 
214 
int String_Compare(char string1[], char string2[])
struct inpfile Control_File(char fileobject[], int ctr)
Definition: ReadGridInit.c:998
void ReadInit()
Definition: ReadGridInit.c:16
void Convertto2d()
void ReadDataFiles()
Definition: ReadGridInit.c:155
void DarcyVelocity()
void ParticleTrack()
Definition: TrackingPart.c:66
struct inpfile Control_Param(char fileobject[], int ctr)
struct inpfile Control_Data(char fileobject[], int ctr)
void Velocity3D()
void CheckGrid()
Definition: ReadGridInit.c:965
void Convertto3d()
void ReadBoundaryNodes()
Definition: ReadGridInit.c:526
void DefineTimeStep()
void WritingInit()
Definition: ReadGridInit.c:898
unsigned int nnodes
Definition: main.c:29
unsigned long int timesteps
Definition: main.c:48
double thickness
Definition: main.c:49
struct element * cell
Definition: main.c:42
double porosity
Definition: main.c:46
char maindir[125]
Definition: main.c:43
int main(int argc, char *controlf[])
Definition: main.c:66
unsigned int ncells
Definition: main.c:30
double timeunit
Definition: main.c:51
unsigned int np
Definition: main.c:34
unsigned int nzone_in
Definition: main.c:35
double density
Definition: main.c:47
unsigned int pflotran
Definition: main.c:27
struct contam * particle
Definition: main.c:41
unsigned int fehm
Definition: main.c:28
unsigned int * nodezoneout
Definition: main.c:37
unsigned int max_neighb
Definition: main.c:32
unsigned int npart
Definition: main.c:33
struct vertex * node
Definition: main.c:40
double totalFluxIn
Definition: main.c:52
char controlfile[120]
Definition: main.c:44
struct material * fracture
Definition: main.c:39
unsigned int nfract
Definition: main.c:31
unsigned int flag_w
Definition: main.c:38
unsigned int * nodezonein
Definition: main.c:36
double saturation
Definition: main.c:50
char filename[120]