pydfnWorks
python wrapper for dfnWorks
dfnworks.py
Go to the documentation of this file.
1 __author__ = "Jeffrey Hyman and Satish Karra"
2 __version__ = "2.3"
3 __maintainer__ = "Jeffrey Hyman and Satish Karra"
4 __email__ = "jhyman@lanl.gov"
5 """
6 DFN object class.
7 """
8 
9 import os
10 import sys
11 import ntpath
12 from time import time
13 from pydfnworks.general.dfntools import *
14 
15 
17  '''
18  Class for DFN Generation and meshing
19 
20  Attributes:
21  * jobname: name of job, also the folder where output files are stored
22  * ncpu: number of CPUs used in the job
23  * dfnGen file: the name of the dfnGen input file
24  * dfnFlow file: the name of the dfnFlow input file
25  * dfnTrans file: the name of the dfnFlow input file
26  * local prefix: indicates that the name contains only the most local directory
27  * vtk_file: the name of the VTK file
28  * inp_file: the name of the INP file
29  * uge_file: the name of the UGE file
30  * mesh_type: the type of mesh
31  * perm_file: the name of the file containing permeabilities
32  * aper_file: the name of the file containing apertures
33  * perm_cell file: the name of the file containing cell permeabilities
34  * aper_cell_file: the name of the file containing cell apertures
35  * freeze: indicates whether the class attributes can be modified
36  * h : FRAM length scale
37 '''
38  # general functions
39  from pydfnworks.general.legal import legal
40  from pydfnworks.general.paths import define_paths
41  from pydfnworks.general.general_functions import dump_time, print_run_time
42 
43  # dfnGen functions
44  import pydfnworks.dfnGen
45 
46  from pydfnworks.dfnGen.generation.gen_input import check_input
47  from pydfnworks.dfnGen.generation.generator import dfn_gen, make_working_directory, create_network
49  from pydfnworks.dfnGen.generation.hydraulic_properties import generate_hydraulic_values, dump_hydraulic_values
50 
51 
52  from pydfnworks.dfnGen.meshing.mesh_dfn import mesh_network
53  from pydfnworks.dfnGen.meshing.mesh_dfn_helper import inp2gmv, create_mesh_links, inp2vtk_python
54  from pydfnworks.dfnGen.meshing.add_attribute_to_mesh import add_variable_to_mesh
55 
56  from pydfnworks.dfnGen.meshing.udfm.map2continuum import map_to_continuum
57  from pydfnworks.dfnGen.meshing.udfm.upscale import upscale
58  from pydfnworks.dfnGen.meshing.udfm.false_connections import check_false_connections
59 
60  from pydfnworks.dfnGen.well_package.wells import tag_well_in_mesh, find_well_intersection_points, combine_well_boundary_zones, cleanup_wells
61 
62 
63  # dfnFlow
64  import pydfnworks.dfnFlow
65  from pydfnworks.dfnFlow.flow import dfn_flow, create_dfn_flow_links, set_flow_solver
66  from pydfnworks.dfnFlow.pflotran import lagrit2pflotran, pflotran, parse_pflotran_vtk_python, pflotran_cleanup, write_perms_and_correct_volumes_areas, zone2ex
67  from pydfnworks.dfnFlow.fehm import correct_stor_file, fehm
68  from pydfnworks.dfnFlow.mass_balance import effective_perm
69 
70  # dfnTrans
71  import pydfnworks.dfnTrans
72  from pydfnworks.dfnTrans.transport import dfn_trans, copy_dfn_trans_files, run_dfn_trans, create_dfn_trans_links, check_dfn_trans_run_files
73 
74  # dfnGraph
75  import pydfnworks.dfnGraph
76  from pydfnworks.dfnGraph.dfn2graph import create_graph, k_shortest_paths_backbone, dump_json_graph, load_json_graph, plot_graph, greedy_edge_disjoint, dump_fractures, add_fracture_source, add_fracture_target
77  from pydfnworks.dfnGraph.graph_flow import run_graph_flow
78  from pydfnworks.dfnGraph.graph_transport import run_graph_transport
79 
80  def __init__(self,
81  jobname='',
82  ncpu='',
83  local_jobname='',
84  dfnGen_file='',
85  output_file='',
86  local_dfnGen_file='',
87  dfnFlow_file='',
88  local_dfnFlow_file='',
89  dfnTrans_file='',
90  path='',
91  prune_file='',
92  flow_solver="PFLOTRAN",
93  inp_file='full_mesh.inp',
94  uge_file='',
95  stor_file='',
96  vtk_file='',
97  mesh_type='dfn',
98  perm_file='',
99  aper_file='',
100  perm_cell_file='',
101  aper_cell_file='',
102  dfnTrans_version='',
103  num_frac='',
104  h=''):
105 
106  self.jobnamejobname = jobname
107  self.ncpuncpu = ncpu
108  self.local_jobnamelocal_jobname = ntpath.basename(self.jobnamejobname)
109 
110  self.dfnGen_filedfnGen_file = dfnGen_file
111  self.local_dfnGen_filelocal_dfnGen_file = ntpath.basename(self.dfnGen_filedfnGen_file)
112 
113 
114  self.output_fileoutput_file = ntpath.basename(self.dfnGen_filedfnGen_file)
115 
116  self.dfnFlow_filedfnFlow_file = dfnFlow_file
117  self.local_dfnFlow_filelocal_dfnFlow_file = ntpath.basename(self.dfnFlow_filedfnFlow_file)
118 
119  self.dfnTrans_filedfnTrans_file = dfnTrans_file
120  self.local_dfnTrans_filelocal_dfnTrans_file = ntpath.basename(self.dfnTrans_filedfnTrans_file)
121 
122  self.vtk_filevtk_file = vtk_file
123  self.inp_fileinp_file = inp_file
124  self.uge_fileuge_file = uge_file
125  self.mesh_typemesh_type = mesh_type
126  self.perm_fileperm_file = perm_file
127  self.aper_fileaper_file = aper_file
128  self.stor_filestor_file = stor_file
129  self.perm_cell_fileperm_cell_file = perm_cell_file
130  self.aper_cell_fileaper_cell_file = aper_cell_file
131  self.flow_solverflow_solver = flow_solver
132 
133  self.hh = ""
134 
135  self.dfnTrans_versiondfnTrans_version = 2.2
136  self.freezefreeze = False
137  self.legal()
138  #options = create_dfn.commandline_options()
139 
140 
142  """Read command lines for use in dfnWorks.
143 
144  Parameters
145  ----------
146  None
147 
148  Returns
149  ---------
150  options : argparse function
151  command line options
152 
153  Notes
154  ---------
155  Options:
156  -name : string
157  Path to working directory (Mandatory)
158  -ncpu : int
159  Number of CPUS (Optional, default=4)
160  -input : string
161  Input file with paths to run files (Mandatory if the next three options are not specified)
162  -prune_file : string
163  Absolute path to the prune Input File
164  -path : string
165  Path to another DFN run that you want to base the current run from
166  -cell : bool
167  True/False Set True for use with cell based aperture and permeabuility (Optional, default=False)
168  """
169 
170  import argparse
171 
172  parser = argparse.ArgumentParser(
173  description="Command Line Arguments for dfnWorks")
174  parser.add_argument("-name",
175  "--jobname",
176  default="",
177  type=str,
178  help="jobname")
179  parser.add_argument("-ncpu",
180  "--ncpu",
181  default=4,
182  type=int,
183  help="Number of CPUs")
184  parser.add_argument("-input",
185  "--input_file",
186  default="",
187  type=str,
188  help="input file with paths to run files")
189  parser.add_argument("-path",
190  "--path",
191  default="",
192  type=str,
193  help="Path to directory for sub-network runs")
194  parser.add_argument("-cell",
195  "--cell",
196  default=False,
197  action="store_true",
198  help="Binary For Cell Based Apereture / Perm")
199  parser.add_argument("-prune_file",
200  "--prune_file",
201  default="",
202  type=str,
203  help="Path to prune DFN list file")
204  options = parser.parse_args()
205  if options.jobname == "":
206  error = "Error: Jobname is required. Exiting.\n"
207  sys.stderr.write(error)
208  sys.exit(1)
209  return options
210 
211 
213  '''Parse command line inputs and input files to create and populate dfnworks class
214 
215  Parameters
216  ----------
217  None
218 
219  Returns
220  -------
221  DFN : object
222  DFN class object populated with information parsed from the command line. Information about DFN class is in dfnworks.py
223 
224  Notes
225  -----
226  None
227  '''
228 
229  options = commandline_options()
230  print("Command Line Inputs:")
231  print(options)
232  print("\n-->Creating DFN class\n")
233  DFN = DFNWORKS(jobname=options.jobname, ncpu=options.ncpu)
234 
235  print("=" * 80 + "\n")
236  print("\n--> Creating DFN class")
237  print('--> Jobname: ', DFN.jobname)
238  print('--> Number of cpus requested: ', DFN.ncpu)
239 
240  if options.input_file == "":
241  error = "ERROR!!! Input file must be provided.\n"
242  sys.stderr.write(error)
243  sys.exit(1)
244  else:
245  print("--> Reading Input from " + options.input_file)
246 
247  with open(options.input_file, "r") as f:
248  for line in f.readlines():
249  line = line.rstrip('\n')
250  line = line.split()
251  if "dfnGen" in line:
252  DFN.dfnGen_file = line[1]
253  print('--> dfnGen input file: ', DFN.dfnGen_file)
254  DFN.local_dfnGen_file = line[1].split('/')[-1]
255  elif "dfnFlow" in line:
256  DFN.dfnFlow_file = line[1]
257  print('--> dfnFlow input file: ', DFN.dfnFlow_file)
258  DFN.local_dfnFlow_file = line[1].split('/')[-1]
259  elif "dfnTrans" in line:
260  DFN.dfnTrans_file = line[1]
261  print('--> dfnTrans input file: ', DFN.dfnTrans_file)
262  DFN.local_dfnTrans_file = line[1].split('/')[-1]
263  else:
264  error = "ERROR Reading Input File\nUnknown line: %s\n" % line
265  sys.stderr.write(error)
266  sys.exit(1)
267 
268  if options.path != "":
269  if not options.path.endswith('/'):
270  options.path += os.sep
271  DFN.path = options.path
272  print('--> DFN Path: ', DFN.path)
273  else:
274  DFN.path = ""
275 
276  if options.prune_file != "":
277  DFN.prune_file = options.prune_file
278  print('--> DFN Prune File: ', DFN.prune_file)
279  else:
280  DFN.prune_file = ""
281 
282  if options.cell is True:
283  print('--> Expecting Cell Based Aperture and Permeability')
284  DFN.aper_cell_file = 'aper_node.dat'
285  DFN.perm_cell_file = 'perm_node.dat'
286  else:
287  DFN.aper_file = 'aperture.dat'
288  DFN.perm_file = 'perm.dat'
289 
290  print("\n--> Creating DFN class: Complete")
291  print("=" * 80 + "\n")
292  return DFN
def __init__(self, jobname='', ncpu='', local_jobname='', dfnGen_file='', output_file='', local_dfnGen_file='', dfnFlow_file='', local_dfnFlow_file='', dfnTrans_file='', path='', prune_file='', flow_solver="PFLOTRAN", inp_file='full_mesh.inp', uge_file='', stor_file='', vtk_file='', mesh_type='dfn', perm_file='', aper_file='', perm_cell_file='', aper_cell_file='', dfnTrans_version='', num_frac='', h='')
Definition: dfnworks.py:104