184 lines
7.1 KiB
Python
184 lines
7.1 KiB
Python
import pickle
|
|
import math
|
|
import traceback
|
|
from os import listdir
|
|
from os.path import isfile, join
|
|
import Tkinter
|
|
|
|
|
|
wt_per_foot = {
|
|
'steel': {
|
|
# diameter: lbs/ft
|
|
2.000: 10.70,
|
|
1.750: 8.200,
|
|
1.650: 7.000,
|
|
1.500: 6.000,
|
|
1.375: 5.000,
|
|
1.250: 4.172,
|
|
1.125: 3.676,
|
|
1.000: 2.904,
|
|
0.875: 2.224,
|
|
0.750: 1.634,
|
|
0.625: 1.130,
|
|
0.500: 0.720
|
|
},
|
|
'fiberglass': {
|
|
# diameter: lbs/ft
|
|
1.250: 1.2879,
|
|
1.125: 1.0900,
|
|
1.000: 0.8188,
|
|
0.875: 0.6108,
|
|
0.750: 0.4840
|
|
}
|
|
}
|
|
|
|
youngs_modulus = {
|
|
'steel': 30.5,
|
|
'fiberglass': 7.2
|
|
}
|
|
|
|
configfile = ""
|
|
|
|
|
|
def get_setup():
|
|
global youngs_modulus, wt_per_ft, configfile
|
|
well_setup = {}
|
|
create_new = True
|
|
pickled_configs = filter(lambda x: x[-2:] == ".p", [f for f in listdir('wellconfigs') if isfile(join('wellconfigs', f))])
|
|
if len(pickled_configs) > 0:
|
|
pickled_configs.append("...New file")
|
|
|
|
master = Tkinter.Tk()
|
|
var = Tkinter.StringVar(master)
|
|
var.set(pickled_configs[0]) # initial value
|
|
|
|
w = apply(Tkinter.OptionMenu, (master, var) + tuple(pickled_configs))
|
|
w.pack()
|
|
|
|
def ok():
|
|
global configfile
|
|
configfile = var.get()
|
|
master.quit()
|
|
master.destroy()
|
|
|
|
button = Tkinter.Button(master, text="OK", command=ok)
|
|
button.pack()
|
|
Tkinter.mainloop()
|
|
fpath = 'wellconfigs/' + configfile
|
|
print(fpath)
|
|
if isfile(fpath):
|
|
with open(fpath, 'rb') as well_config_file:
|
|
well_setup = pickle.load(well_config_file)
|
|
reuse = str(raw_input("Do you want to use the last settings for {}? (y/n): ".format(well_setup['well_name']))).lower()
|
|
create_new = (reuse == 'n')
|
|
try:
|
|
if create_new:
|
|
well_setup = {}
|
|
well_setup['c'] = [0.0]
|
|
well_setup['rod_length_data'] = [0.0]
|
|
well_setup['rod_diameter_data'] = [0.0]
|
|
well_setup['rod_material'] = ['']
|
|
well_setup['rod_youngs_modulus_data'] = [0.0]
|
|
well_setup['rod_weight_data'] = [0.0]
|
|
|
|
ask_num_tapers = int(raw_input("How many tapers to configure (1-10): "))
|
|
if (ask_num_tapers > 0) and (ask_num_tapers <= 10):
|
|
well_setup['num_tapers'] = ask_num_tapers
|
|
for i in range(1, ask_num_tapers + 1):
|
|
print("================")
|
|
print("== TAPER {} ==".format(i))
|
|
print("================")
|
|
ask_length = float(raw_input("Enter Taper Length in feet: "))
|
|
if ask_length > 0.0:
|
|
well_setup['rod_length_data'].append(ask_length)
|
|
else:
|
|
raise Exception("Invalid length {} for taper {}".format(ask_length, i))
|
|
|
|
ask_diameter = float(raw_input("Enter Rod Diameter in inches: "))
|
|
if ask_diameter > 0.0:
|
|
well_setup['rod_diameter_data'].append(ask_diameter)
|
|
else:
|
|
raise Exception("Invalid diameter {} for taper {}".format(ask_diameter, i))
|
|
|
|
ask_material = str(raw_input("Enter material type (steel or fiberglass): ")).lower()
|
|
if (ask_material == 'fiberglass') or (ask_material == 'steel'):
|
|
well_setup['rod_material'].append(ask_material)
|
|
else:
|
|
raise Exception("Invalid material {} for taper {}".format(ask_material, i))
|
|
|
|
ask_c = float(raw_input("Enter Damping Factor(0.0 - 1.0): "))
|
|
if (ask_c >= 0.0) and (ask_c <= 1.0):
|
|
well_setup['c'].append(ask_c)
|
|
else:
|
|
raise Exception("Invalid Daming Factor {} for taper {}".format(ask_c, i))
|
|
|
|
for j in range(1, ask_num_tapers + 1):
|
|
well_setup['rod_youngs_modulus_data'].append(youngs_modulus[well_setup['rod_material'][j]])
|
|
well_setup['rod_weight_data'].append(wt_per_foot[well_setup['rod_material'][i]][well_setup['rod_diameter_data'][j]])
|
|
|
|
ask_thp = float(raw_input("Enter Tubing Head Pressure in PSI: "))
|
|
if ask_length > 0.0:
|
|
well_setup['tubing_head_pressure'] = ask_thp
|
|
else:
|
|
raise Exception("Invalid Tubing Head Pressure: {} PSI".format(ask_length))
|
|
|
|
ask_fluid_gradient = float(raw_input("Enter Fluid Gradient in PSI/ft: "))
|
|
if ask_fluid_gradient > 0.0:
|
|
well_setup['fluid_gradient'] = ask_fluid_gradient
|
|
else:
|
|
raise Exception("Invalid Fluid Gradient: {} PSI/ft".format(ask_fluid_gradient))
|
|
|
|
ask_sbf = float(raw_input("Enter Stuffing Box Friction in lbs: "))
|
|
if ask_sbf > 0.0:
|
|
well_setup['stuffing_box_friction'] = ask_sbf
|
|
else:
|
|
raise Exception("Invalid Stuffing Box Friction: {} PSI/ft".format(ask_sbf))
|
|
|
|
ask_dt = float(raw_input("Enter delta t in seconds: "))
|
|
if ask_dt > 0.0:
|
|
well_setup['dt'] = ask_dt
|
|
else:
|
|
raise Exception("Invalid delta t: {} sec".format(ask_dt))
|
|
|
|
ask_tubingID = float(raw_input("Enter Tubing ID in inches: "))
|
|
if ask_tubingID > 0.0:
|
|
well_setup['tubing_id'] = ask_tubingID
|
|
else:
|
|
raise Exception("Invalid Tubing ID: {} in".format(ask_tubingID))
|
|
|
|
ask_tubingOD = float(raw_input("Enter Tubing OD in inches: "))
|
|
if ask_tubingOD > 0.0:
|
|
well_setup['tubing_od'] = ask_tubingOD
|
|
else:
|
|
raise Exception("Invalid Tubing OD: {} in".format(ask_tubingOD))
|
|
|
|
ask_TAC = float(raw_input("Enter Tubing Anchor Depth in feet: "))
|
|
if ask_TAC > 0.0:
|
|
well_setup['anchor_depth'] = ask_TAC
|
|
else:
|
|
raise Exception("Invalid Tubing Anchor Depth: {} ft".format(ask_TAC))
|
|
|
|
ask_pump_diameter = float(raw_input("Enter Pump Diameter in inches: "))
|
|
if ask_pump_diameter > 0.0:
|
|
well_setup['pump_diameter'] = ask_pump_diameter
|
|
well_setup['pump_area'] = (well_setup['pump_diameter']**2) * math.pi
|
|
else:
|
|
raise Exception("Invalid Pump Diameter: {} in".format(ask_pump_diameter))
|
|
|
|
well_setup['well_name'] = str(raw_input("Enter Well Name: "))
|
|
|
|
else:
|
|
raise Exception("Invalid taper count")
|
|
|
|
with open('wellconfigs/' + well_setup['well_name'].replace(" ", "") + '.p', 'wb') as well_config_file:
|
|
pickle.dump(well_setup, well_config_file)
|
|
return well_setup
|
|
|
|
except Exception as e:
|
|
traceback.print_exc()
|
|
print e
|
|
return False
|
|
|
|
if __name__ == '__main__':
|
|
get_setup()
|