pydfnWorks
python wrapper for dfnWorks
mesh_dfn.py
Go to the documentation of this file.
1 """
2 .. module:: mesh_dfn.py
3  :synopsis: meshing driver for DFN
4 .. moduleauthor:: Jeffrey Hyman <jhyman@lanl.gov>
5 
6 """
7 
8 import os
9 import sys
10 from numpy import genfromtxt, sort
11 # pydfnworks Modules
12 from pydfnworks.dfnGen.meshing import mesh_dfn_helper as mh
13 from pydfnworks.dfnGen.meshing import lagrit_scripts_poisson_disc as lagrit
14 from pydfnworks.dfnGen.meshing import run_meshing as run_mesh
15 from pydfnworks.dfnGen.meshing.poisson_disc.poisson_functions import single_fracture_poisson, dump_poisson_params
16 
17 
18 def mesh_network(self,
19  prune=False,
20  uniform_mesh=False,
21  production_mode=True,
22  coarse_factor=8,
23  slope=0.1,
24  min_dist=1,
25  max_dist=40,
26  concurrent_samples=10,
27  grid_size=10,
28  visual_mode=None,
29  well_flag=False):
30  ''' Mesh fracture network using LaGriT
31 
32  Parameters
33  ----------
34  self : object
35  DFN Class
36  prune : bool
37  If prune is False, mesh entire network. If prune is True, mesh only fractures in self.prune_file
38  uniform_mesh : bool
39  If true, mesh is uniform resolution. If False, mesh is spatially variable
40  production_mode : bool
41  If True, all working files while meshing are cleaned up. If False, then working files will not be deleted
42  visual_mode : None
43  If the user wants to run in a different meshing mode from what is in params.txt,
44  set visual_mode = True/False on command line to override meshing mode
45  coarse_factor: float
46  Maximum resolution of the mesh. Given as a factor of h
47  slope : float
48  slope of variable coarsening resolution.
49  min_dist : float
50  Range of constant min-distance around an intersection (in units of h).
51  max_dist : float
52  Range over which the min-distance between nodes increases (in units of h)
53  concurrent_samples : int
54  number of new candidates sampled around an accepted node at a time.
55  grid_size : float
56  side length of the occupancy grid is given by H/occupancy_factor
57  well_flag : bool
58  If well flag is true, higher resolution around the points in
59 
60  Returns
61  -------
62  None
63 
64  Notes
65  ------
66  1. For uniform resolution mesh, set slope = 0
67  2. All fractures in self.prune_file must intersect at least 1 other fracture
68 
69  '''
70 
71  print('=' * 80)
72  print("Meshing DFN using LaGriT : Starting")
73  print('=' * 80)
74 
75  if uniform_mesh:
76  slope = 0 # Setting slope = 0, results in a uniform mesh
77 
78  if prune:
79  if self.prune_file == "":
80  error = "ERROR!! User requested pruning in meshing but \
81 did not provide file of fractures to keep.\nExiting program.\n"
82 
83  sys.stderr.write(error)
84  sys.exit(1)
85 
86  mh.create_mesh_links(self.path)
87  num_poly, h, params_visual_mode, dudded_points, domain = mh.parse_params_file(
88  )
89  if visual_mode == None:
90  visual_mode = params_visual_mode
91 
92  if visual_mode:
93  print("\n--> Running in Visual Mode\n")
94  print(
95  f"Loading list of fractures to remain in network from {self.prune_file}"
96  )
97  fracture_list = sort(genfromtxt(self.prune_file).astype(int))
98  print(fracture_list)
99  if not visual_mode:
100  lagrit.edit_intersection_files(num_poly, fracture_list, self.path)
101  num_poly = len(fracture_list)
102 
103  else:
104  num_poly, h, params_visual_mode, dudded_points, domain = mh.parse_params_file(
105  )
106  if visual_mode == None:
107  visual_mode = params_visual_mode
108 
109  fracture_list = range(1, num_poly + 1)
110 
111  # if number of fractures is greater than number of CPUS,
112  # only use num_poly CPUs. This change is only made here, so ncpus
113  # is still used in PFLOTRAN
114  ncpu = min(self.ncpu, num_poly)
115 
116  print('=' * 80)
117  if visual_mode:
118  print("\n--> Running in Visual Mode\n")
119  else:
120  print("\n--> Running in Full Meshing Mode\n")
121  print('=' * 80)
122 
123  lagrit.create_parameter_mlgi_file(fracture_list, h, slope=slope)
124  if visual_mode:
125  lagrit.create_lagrit_scripts_reduced_mesh(fracture_list)
126  else:
127 
128  # Check for well points well.
129  if well_flag:
130  if not os.path.isfile("well_points.dat"):
131  error = "ERROR!!! Well flag is set to True in DFN.mesh_network(), but file 'well_points.dat' cannot be found.\nPlease run DFN.find_well_intersection_points() for each well prior to meshing\nOr set well_flag = False\nExiting Program\n"
132  sys.stderr.write(error)
133  sys.exit(1)
134 
135  dump_poisson_params(h, coarse_factor, slope, min_dist, max_dist,
136  concurrent_samples, grid_size, well_flag)
137 
138  lagrit.create_lagrit_scripts_poisson(fracture_list)
139 
143 
144  print('=' * 80)
145 
146  failure = run_mesh.mesh_fractures_header(fracture_list, ncpu, visual_mode,
147  h)
148  if failure:
149  mh.cleanup_dir()
150  error = "One or more fractures failed to mesh properly.\nExiting Program\n"
151  sys.stderr.write(error)
152  sys.exit(1)
153 
154  n_jobs = lagrit.create_merge_poly_files(ncpu, num_poly, fracture_list, h,
155  visual_mode, domain,
156  self.flow_solver)
157 
158  run_mesh.merge_the_meshes(num_poly, ncpu, n_jobs, visual_mode)
159 
160  if (not visual_mode and not prune):
161  if not mh.check_dudded_points(dudded_points):
162  mh.cleanup_dir()
163  error = "ERROR!!! Incorrect Number of dudded points.\nExiting Program\n"
164  sys.stderr.write(error)
165  sys.exit(1)
166 
167  if production_mode:
168  mh.cleanup_dir()
169 
170  if not visual_mode:
171  lagrit.define_zones()
172 
173  if prune:
174  mh.clean_up_files_after_prune(self)
175 
176  mh.output_meshing_report(self.local_jobname, visual_mode)
177  print('=' * 80)
178  print("Meshing DFN using LaGriT : Complete")
179  print('=' * 80)
def mesh_network(self, prune=False, uniform_mesh=False, production_mode=True, coarse_factor=8, slope=0.1, min_dist=1, max_dist=40, concurrent_samples=10, grid_size=10, visual_mode=None, well_flag=False)
Definition: mesh_dfn.py:29