pydfnWorks
python wrapper for dfnWorks
fehm.py
Go to the documentation of this file.
1 import os
2 import subprocess
3 import sys
4 import glob
5 import shutil
6 from time import time
7 import numpy as np
8 """
9 Functions for using FEHM in dfnWorks
10 """
11 
12 
14  """Corrects volumes in stor file to account for apertures
15 
16  Parameters
17  ----------
18  self : object
19  DFN Class
20 
21  Returns
22  --------
23  None
24 
25  Notes
26  --------
27  Currently does not work with cell based aperture
28  """
29  # Make input file for C Stor converter
30  if self.flow_solver != "FEHM":
31  error = "ERROR! Wrong flow solver requested\n"
32  sys.stderr.write(error)
33  sys.exit(1)
34 
35  self.stor_file = self.inp_file[:-4] + '.stor'
36  self.mat_file = self.inp_file[:-4] + '_material.zone'
37  f = open("convert_stor_params.txt", "w")
38  f.write("%s\n" % self.mat_file)
39  f.write("%s\n" % self.stor_file)
40  f.write("%s" % (self.stor_file[:-5] + '_vol_area.stor\n'))
41  f.write("%s\n" % self.aper_file)
42  f.close()
43 
44  t = time()
45  cmd = os.environ['CORRECT_STOR_EXE'] + ' convert_stor_params.txt'
46  failure = subprocess.call(cmd, shell=True)
47  if failure > 0:
48  error = 'ERROR: stor conversion failed\nExiting Program\n'
49  sys.stderr.write(error)
50  sys.exit(1)
51  elapsed = time() - t
52  print('--> Time elapsed for STOR file conversion: %0.3f seconds\n' %
53  elapsed)
54 
55 
57  """ FEHM wants an empty line at the end of the perm file
58  This functions adds that line return
59 
60  Parameters
61  ----------
62  None
63 
64  Returns
65  ---------
66  None
67 
68  Notes
69  ------------
70  Only adds a new line if the last line is not empty
71  """
72  fp = open("perm.dat")
73  lines = fp.readlines()
74  fp.close()
75  # Check if the last line of file is just a new line
76  # If it is not, then add a new line at the end of the file
77  if len(lines[-1].split()) != 0:
78  print("--> Adding line to perm.dat")
79  fp = open("perm.dat", "a")
80  fp.write("\n")
81  fp.close()
82 
83 
84 def fehm(self):
85  """Run FEHM
86 
87  Parameters
88  ----------
89  self : object
90  DFN Class
91 
92  Returns
93  -------
94  None
95 
96  Notes
97  -----
98  See https://fehm.lanl.gov/ for details about FEHM
99 
100  """
101  print("--> Running FEHM")
102  if self.flow_solver != "FEHM":
103  error = "ERROR! Wrong flow solver requested\n"
104  sys.stderr.write(error)
105  sys.exit(1)
106 
107  try:
108  shutil.copy(self.dfnFlow_file, os.getcwd())
109  except:
110  error = "-->ERROR copying FEHM run file: %s" % self.dfnFlow_file
111  std.stderr.write(error)
112  sys.exit(1)
113 
114  path = self.dfnFlow_file.strip(self.local_dfnFlow_file)
115  fp = open(self.local_dfnFlow_file)
116  line = fp.readline()
117  fehm_input = line.split()[-1]
118  fp.close()
119  try:
120  shutil.copy(path + fehm_input, os.getcwd())
121  except:
122  error = "-->ERROR copying FEHM input file:\n" % fehm_input
123  sys.stderr.write(error)
124  sys.exit(1)
125 
127  tic = time()
128  subprocess.call(os.environ["FEHM_EXE"] + " " + self.local_dfnFlow_file,
129  shell=True)
130  print('=' * 80)
131  print("FEHM Complete")
132  print("Time Required %0.2f Seconds" % (time() - tic))
133  print('=' * 80)
def correct_perm_for_fehm()
Definition: fehm.py:56
def correct_stor_file(self)
Definition: fehm.py:13
def fehm(self)
Definition: fehm.py:84