def get_sep_pres(unit_data): PE_server=ut.PE.Initialize() ut.showinterface(PE_server,0) units=["KPC MP A","UN3 - TR1","UN2 - Slug01"] units_simple=["kpc","u3","u2"] for idx,unit in enumerate(units): unit_data[units_simple[idx]]["sep"]["sep_pres"]=float(ut.PE.DoGet(PE_server,"GAP.MOD[{PROD}].SEP[{" + units[idx] + "}].SolverPres[0]")) # sep={} # sep["kpc_sep_pres"]=float(ut.PE.DoGet(PE_server,"GAP.MOD[{PROD}].SEP[{" + units[0] + "}].SolverPres[0]")) # sep["u3_train1_sep_pres"]=float(ut.PE.DoGet(PE_server,"GAP.MOD[{PROD}].SEP[{" + units[1] + "}].SolverPres[0]")) # sep["u2_sep_pres"]=float(ut.PE.DoGet(PE_server,"GAP.MOD[{PROD}].SEP[{" + units[2] + "}].SolverPres[0]")) # temporarily all 4 trains at U3 set equal unit_data["u3tr2"]["sep"]["sep_pres"]=unit_data["u3"]["sep"]["sep_pres"] unit_data["u3tr3"]["sep"]["sep_pres"]=unit_data["u3"]["sep"]["sep_pres"] unit_data["u3tr4"]["sep"]["sep_pres"]=unit_data["u3"]["sep"]["sep_pres"] ut.showinterface(PE_server,1) PE_server=ut.PE.Stop() return unit_data
def route_optimization(session_json): combinations = generate_comb(session_json) session_json_copy = session_json PE_server = ut.PE.Initialize() ut.showinterface( PE_server, 0 ) # don't update GAP interface, this is used to speed up GAP calculations start = datetime.datetime.now() for cnt, comb in enumerate(combinations): session_json_copy = session_json emit( "progress", { "data": "-----> Performing routing combination: %s out of %s" % (cnt, len(combinations)) }) sleep(0.1) for well, val in session_json_copy["well_data"].items( ): # additional step to pre calculate required qgas_max equivalent to target FWHP if "target_fwhp" in val: if val["target_fwhp"] > 0: pc_fwhp = session_json_copy["well_data"][well]["pc"][ "thps"] pc_qgas = session_json_copy["well_data"][well]["pc"][ "qgas"] session_json_copy["well_data"][well][ "qgas_max"] = np.interp(val["target_fwhp"], pc_fwhp, pc_qgas) for c in comb: session_json_copy["well_data"][ c["well"]]["selected_route"] = c["route_name"] st.set_unit_routes( session_json_copy["well_data"]) # set well routes as per state run_optimization(session_json_copy, PE_server) ut.showinterface( PE_server, 1) # update GAP calculations after solving all combinations PE_server = ut.PE.Stop() dt = datetime.datetime.now() - start emit( "progress", { "data": "Calculations complete. Go to Results. <br> Time spent: %s" % dt, "finish": 1 }) sleep(1) return "None"
def adjust_wct_swing(PE_server, last_well_idx, well_dataset_wct_ranked, session_json, unit_constraints_af, unit, unit_prod, oil_constraint, unit_idx, unit_names): # SOLVE SWING ############################################################################################ swing_well = well_dataset_wct_ranked[last_well_idx][0] while session_json["well_data"][swing_well][ "fixed"] == 1: # find next well that is not fixed swing_well = well_dataset_wct_ranked[last_well_idx][0] last_well_idx += 1 delta_qwat_max = unit_constraints_af[unit]["qwat_max"] - unit_prod[ "qwat"] # calculate by how much Qgas should be reduced # qwat_max -> wct -> qoil_max -> gor -> qgas_max -> THP (in GAP) delta_qoil_max_from_qwat = delta_qwat_max * ( 1 - session_json["well_data"][swing_well]["wct"] / 100) / ( session_json["well_data"][swing_well]["wct"] / 100) delta_qgas_max_from_qoil = delta_qoil_max_from_qwat * session_json[ "well_data"][swing_well]["gor"] / 1000.0 delta_qgas_max = delta_qgas_max_from_qoil # using + because of negative values from delta (constr-unit prod) unit_prod["qwat"] += delta_qwat_max unit_prod["qoil"] += delta_qoil_max_from_qwat unit_prod["qgas"] += delta_qgas_max_from_qoil #take current swing well qgasmax from GAP swing_qgas_max = session_json["well_data"][swing_well]["qgas_max"] #then apply delta to it so that unit constraint is met swing_qgas_max2gap = swing_qgas_max + delta_qgas_max if swing_qgas_max2gap > 10.0: #check if well can sustain this flow ut.PE.DoSet(PE_server, "GAP.MOD[{PROD}].WELL[{" + swing_well + "}].MaxQgas", swing_qgas_max2gap) session_json["well_data"][swing_well]["qgas_max"] = swing_qgas_max2gap emit( "progress", { "data": "%s: Water Swing well %s**" % (unit_names["label"][unit_idx], swing_well) }) else: # if not, SI the well so that GAP solves faster ut.shut_well(PE_server, swing_well) emit( "progress", { "data": "%s: Unstable water swing well %s shut" % (unit_names["label"][unit_idx], swing_well) }) sleep(0.1) return session_json, unit_prod
def adjust_gor_swing(PE_server, last_well_idx, well_dataset_gor_ranked, session_json, unit_constraints_af, unit, unit_prod, oil_constraint, unit_idx, unit_names): # SOLVE SWING ############################################################################################ swing_well = well_dataset_gor_ranked[last_well_idx][0] while session_json["well_data"][swing_well][ "fixed"] == 1: # find next well that is not fixed swing_well = well_dataset_gor_ranked[last_well_idx][0] last_well_idx += 1 delta_qgas_max = unit_constraints_af[unit]["qgas_max"] - unit_prod[ "qgas"] # calculate by how much Qgas should be reduced delta_qoil_max = unit_constraints_af[unit]["qoil_max"] - unit_prod[ "qoil"] # calculate by how much Qoil should be reduced # see if qoil_max is closer, if yes, then convert to qgas_max using swing well gor and apply as well constraint oil_constraint[unit_idx] = 0 delta_qgas_max_from_qoil = delta_qoil_max * session_json["well_data"][ swing_well]["gor"] / 1000.0 if delta_qgas_max_from_qoil < delta_qgas_max: delta_qgas_max = delta_qgas_max_from_qoil oil_constraint[u] = 1 #take current swing well qgasmax from GAP swing_qgas_max = session_json["well_data"][swing_well]["qgas_max"] #then apply delta to it so that unit constraint is met swing_qgas_max2gap = swing_qgas_max + delta_qgas_max if swing_qgas_max2gap > 10.0: #check if well can sustain this flow ut.PE.DoSet(PE_server, "GAP.MOD[{PROD}].WELL[{" + swing_well + "}].MaxQgas", swing_qgas_max2gap) session_json["well_data"][swing_well]["qgas_max"] = swing_qgas_max2gap emit( "progress", { "data": "%s: Swing well %s**" % (unit_names["label"][unit_idx], swing_well) }) else: # if not, SI the well so that GAP solves faster ut.shut_well(PE_server, swing_well) emit( "progress", { "data": "%s: Unstable swing well %s shut" % (unit_names["label"][unit_idx], swing_well) }) sleep(0.1) return session_json, oil_constraint
def get_gap_wells(): PE_server=ut.PE.Initialize() status=ut.get_all(PE_server,"GAP.MOD[{PROD}].WELL[$].MASKFLAG") wellname=ut.get_filtermasked(PE_server,"GAP.MOD[{PROD}].WELL[$].Label",status,"string") PE_server=ut.PE.Stop() print(wellname) # status=nsut.get_all("wells","maskflag") # wellname=nsut.get_filtermasked("wells","label",status,"string") well_data={} for well in wellname: well_data[well]={} return well_data
def kill_wells_by_wct(PE_server, unit_idx, unit, unit_prod, unit_constraints_af, well_dataset_wct_ranked, unit_names, session_json): optimized = 1 #this flag is used to decide if resolving network is needed or not i = 0 while unit_prod["qwat"] - well_dataset_wct_ranked[i][ 5] > unit_constraints_af[unit][ "qwat_max"]: # SI wells one by one with GOR ranking logic well = well_dataset_wct_ranked[i][0] if session_json["well_data"][well]["fixed"] == 0: unit_prod["qgas"] -= well_dataset_wct_ranked[i][3] unit_prod["qoil"] -= well_dataset_wct_ranked[i][4] unit_prod["qwat"] -= well_dataset_wct_ranked[i][5] ut.shut_well(PE_server, well) emit( "progress", { "data": "%s: SI well %s - Watercut=%.1f" % ( unit_names["label"][unit_idx], well, # wellname from data_unit well_dataset_wct_ranked[i][2] # gor from data_unit ) }) else: emit( "progress", { "data": "%s: Skipped fixed well %s - Watercut=%.1f ^^" % (unit_names["label"][unit_idx], well, well_dataset_wct_ranked[i][2]) }) sleep(0.1) i += 1 return i, optimized, unit_prod
def get_well_data(PE_server, well_data, afs): status = ut.get_all(PE_server, "GAP.MOD[{PROD}].WELL[$].MASKFLAG") wellname = ut.get_filtermasked(PE_server, "GAP.MOD[{PROD}].WELL[$].Label", status, "string") # gor=ut.get_filtermasked(PE_server,"GAP.MOD[{PROD}].WELL[$].IPR[0].GOR",status,"float") qoil = ut.get_filtermasked( PE_server, "GAP.MOD[{PROD}].WELL[$].SolverResults[0].OilRate", status, "float") qgas = ut.get_filtermasked( PE_server, "GAP.MOD[{PROD}].WELL[$].SolverResults[0].GasRate", status, "float") qwat = ut.get_filtermasked( PE_server, "GAP.MOD[{PROD}].WELL[$].SolverResults[0].WatRate", status, "float") fwhp = ut.get_filtermasked( PE_server, "GAP.MOD[{PROD}].WELL[$].SolverResults[0].FWHP", status, "float") dp = ut.get_filtermasked( PE_server, "GAP.MOD[{PROD}].WELL[$].SolverResults[0].PControlResult", status, "float") for d, w in enumerate(wellname): ###################### FLOWLINE PRESSURE ############################# if well_data[w]["selected_route"]: for i, r in enumerate(well_data[w]["connection"]["routes"]): # wd_route=str(r["unit"])+"--"+str(r["rms"])+"--"+str(r["tl"])+"--slot "+str(r["slot"]) wd_route = r["route_name"] if wd_route == well_data[w]["selected_route"]: fl_pipe_os = r["fl_pipe_os"] else: fl_pipe_os = well_data[w]["connection"]["routes"][0][ "fl_pipe_os"] # take first row for well, no other option if fl_pipe_os: slotpres = ut.PE.DoGet( PE_server, "GAP.MOD[{PROD}].PIPE[{" + fl_pipe_os + "}].SolverResults[0].PresOut") slotpres = float(slotpres) else: slotpres = 0 ###################################################################### well_data[w]["qoil"] = qoil[d] * afs[well_data[w]["unit_id"]][ 0] # oil rate multiplied by af_oil well_data[w]["qgas"] = qgas[d] * afs[well_data[w]["unit_id"]][ 1] # gas rate multiplied by af_gas well_data[w]["qwat"] = qwat[d] * afs[well_data[w]["unit_id"]][ 2] # water rate multiplied by af_wat well_data[w]["fwhp"] = fwhp[d] well_data[w]["dp"] = dp[d] well_data[w]["slotpres"] = slotpres return well_data
def get_all_well_data(well_data,PE_server,mode): if mode!=2: PE_server=ut.PE.Initialize() ut.showinterface(PE_server,0) """ SEQUENCE OF UNITS ====================================== """ units=["KPC MP A","UN3 - TR1","UN2 - Slug01"] units_simple=["kpc","u3","u2"] # well_data=[] for idx,unit in enumerate(units): well_data=get_well_data(PE_server,unit,idx,well_data) # well_data.append(data) # set masked 1 to well masked in GAP for well,val in well_data.items(): if not "masked" in val: well_data[well]["masked"]=1 """ UNMASK ALL UNITS ====================================== """ ut.unmask_all_units(PE_server) if mode!=2: ut.showinterface(PE_server,1) PE_server=ut.PE.Stop() return well_data
def set_sep_pres(unit_data): PE_server=ut.PE.Initialize() ut.showinterface(PE_server,0) units=["KPC MP A","UN3 - TR1","UN2 - Slug01"] units_simple=["kpc","u3","u2"] for idx,unit in enumerate(units): ut.PE.DoSet(PE_server,"GAP.MOD[{PROD}].SEP[{" + units[idx] + "}].SolverPres[0]",unit_data[units_simple[idx]]["sep"]["sep_pres"]) # if sep["kpc_sep_pres"]: # ut.PE.DoSet(PE_server,"GAP.MOD[{PROD}].SEP[{" + units[0] + "}].SolverPres[0]",sep["kpc_sep_pres"]) # if sep["u3_train1_sep_pres"]: # ut.PE.DoSet(PE_server,"GAP.MOD[{PROD}].SEP[{" + units[1] + "}].SolverPres[0]",sep["u3_train1_sep_pres"]) # if sep["u2_sep_pres"]: # ut.PE.DoSet(PE_server,"GAP.MOD[{PROD}].SEP[{" + units[2] + "}].SolverPres[0]",sep["u2_sep_pres"]) ut.showinterface(PE_server,1) PE_server=ut.PE.Stop() return None
def get_well_data(PE_server,unit,unit_id,well_data): ut.choose_unit(PE_server,unit) status=ut.get_all(PE_server,"GAP.MOD[{PROD}].WELL[$].MASKFLAG") wellname=ut.get_filtermasked(PE_server,"GAP.MOD[{PROD}].WELL[$].Label",status,"string") gor=ut.get_filtermasked(PE_server,"GAP.MOD[{PROD}].WELL[$].IPR[0].GOR",status,"float") wct=ut.get_filtermasked(PE_server,"GAP.MOD[{PROD}].WELL[$].IPR[0].WCT",status,"float") # dd_lim=ut.get_filtermasked(PE_server,"GAP.MOD[{PROD}].WELL[$].MaxDrawdown",status,"float") # qliq_lim=ut.get_filtermasked(PE_server,"GAP.MOD[{PROD}].WELL[$].MaxQliq",status,"float") pipe_status=ut.get_all(PE_server,"GAP.MOD[{PROD}].PIPE[$].MASKFLAG") pipes=ut.get_filtermasked(PE_server,"GAP.MOD[{PROD}].PIPE[$].Label",pipe_status,"string") # wells_from_conn=list(well_data.keys()) for d,w in enumerate(wellname): this_route=-1 route_cnt=0 for ri,r in enumerate(well_data[w]["connection"]["routes"]): if r["os"]: route_os=r["os"].split(",") if len(route_os)>1: if route_os[0] in pipes and route_os[1] in pipes: this_route=ri route_cnt+=1 # break else: if route_os[0] in pipes: this_route=ri route_cnt+=1 # break well_data[w]["gor"]=gor[d] well_data[w]["wct"]=wct[d] well_data[w]["unit_id"]=unit_id well_data[w]["curr_route"]=this_route well_data[w]["route_cnt"]=route_cnt well_data[w]["masked"]=0 # set masked 0 to well unmasked(active) in GAP return well_data
def set_qgas_max(PE_server, wellname, status, well_data, qgas_max_orig): qgas_max = [] # qgas_max values per well to set for well in wellname: if "target_fwhp" in well_data[well]: if well_data[well]["target_fwhp"] > 0.0: qgas_max.append(well_data[well]["qgas_max"]) else: ut.shut_well(PE_server, well) qgas_max.append("") else: ut.shut_well(PE_server, well) qgas_max.append("") qgas_max2gap = ut.updatepar(qgas_max_orig, qgas_max, status) qgas_max2gap = ut.list2gapstr(qgas_max2gap) ut.PE.DoSet(PE_server, "GAP.MOD[{PROD}].WELL[$].MaxQgas", qgas_max2gap) return None
def report_results(PE_server, unit_names, unit_data, oil_constraint, unit_constraints_af): conv = 0.0 # convergence value tot_qoil = 0.0 tot_qgas = 0.0 tot_qwat = 0.0 for unit_idx, unit in enumerate(unit_names["simple"]): unit_qgas = ut.get_unit_qgas( PE_server, unit_names["sep"][unit_idx]) # get directly from GAP separators unit_qoil = ut.get_unit_qoil( PE_server, unit_names["sep"][unit_idx]) # get directly from GAP separators unit_qwat = ut.get_unit_qwat( PE_server, unit_names["sep"][unit_idx]) # get directly from GAP separators tot_qoil += unit_qoil tot_qgas += unit_qgas tot_qwat += unit_qwat # reporting if unit_qgas > unit_constraints_af[unit]["qgas_max"]: emit("progress",{"data":"<mark>Qgas=%.1f, Qgas max=%.1f </mark>" % (\ unit_qgas*unit_data[unit]["af"]["af_gas"],\ unit_constraints_af[unit]["qgas_max"]*unit_data[unit]["af"]["af_gas"])}) else: emit("progress",{"data":"Qgas=%.1f, Qgas max=%.1f" % (\ unit_qgas*unit_data[unit]["af"]["af_gas"],\ unit_constraints_af[unit]["qgas_max"]*unit_data[unit]["af"]["af_gas"])}) if unit_qoil > unit_constraints_af[unit]["qoil_max"]: emit("progress",{"data":"<mark>Qoil=%.1f, Qoil max=%.1f </mark>" % (\ unit_qoil*unit_data[unit]["af"]["af_oil"],\ unit_constraints_af[unit]["qoil_max"]*unit_data[unit]["af"]["af_oil"])}) else: emit("progress",{"data":"Qoil=%.1f, Qoil max=%.1f" % (\ unit_qoil*unit_data[unit]["af"]["af_oil"],\ unit_constraints_af[unit]["qoil_max"]*unit_data[unit]["af"]["af_oil"])}) if unit_qwat > unit_constraints_af[unit]["qwat_max"]: emit("progress",{"data":"<mark style='background-color:#cce6ff;'>Qwater=%.1f, Qwater max=%.1f </mark>" % (\ unit_qwat*unit_data[unit]["af"]["af_wat"],\ unit_constraints_af[unit]["qwat_max"]*unit_data[unit]["af"]["af_wat"])}) else: emit("progress",{"data":"Qwater=%.1f, Qwater max=%.1f" % (\ unit_qwat*unit_data[unit]["af"]["af_wat"],\ unit_constraints_af[unit]["qwat_max"]*unit_data[unit]["af"]["af_wat"])}) emit( "progress", { "data": "%s -----------------------------------------" % unit_names["label"][unit_idx] }) sleep(0.1) if oil_constraint[unit_idx] == 1: if unit_qoil > unit_constraints_af[unit]["qoil_max"] * 1.0001: conv += abs(unit_constraints_af[unit]["qoil_max"] - unit_qoil) else: if unit_qgas > unit_constraints_af[unit]["qgas_max"] * 1.0001: conv += abs(unit_constraints_af[unit]["qgas_max"] - unit_qgas) return conv, tot_qoil, tot_qgas, tot_qwat
def run_optimization(session_json, PE_server, mode): if mode == 1: # mode 1 is just optimization, if mode=2, then higher level routing optimization is taking place, then no need to initialize, PE_server is initialized from routing opt function PE_server = ut.PE.Initialize() start = datetime.datetime.now() emit("progress", {"data": "Applying Target FWHPs.."}) status = ut.get_all(PE_server, "GAP.MOD[{PROD}].WELL[$].MASKFLAG") wellname = ut.get_filtermasked(PE_server, "GAP.MOD[{PROD}].WELL[$].Label", status, "string") qgas_max_orig = ut.get_all( PE_server, "GAP.MOD[{PROD}].WELL[$].MaxQgas" ) # qgas_max is the main tool for GAP rule based optimizer # set all qgas max per well. This is to translate all target THPs to wells via qgasmax set_qgas_max(PE_server, wellname, status, session_json["well_data"], qgas_max_orig) emit("progress", {"data": "Solving Network..."}) emit("progress", {"data": "------------------------------"}) sleep(0.1) ut.solve_network_rb(PE_server) # solve network as a first pass unit_data = session_json["fb_data"]["unit_data"] unit_constraints_af = {} for unit_idx, unit in enumerate( unit_names["simple"]): # calc AF constraints unit_constraints_af[unit] = {} unit_constraints_af[unit]["qgas_max"] = unit_data[unit]["constraints"][ "qgas_max"] / unit_data[unit]["af"]["af_gas"] unit_constraints_af[unit]["qoil_max"] = unit_data[unit]["constraints"][ "qoil_max"] / unit_data[unit]["af"]["af_oil"] unit_constraints_af[unit]["qwat_max"] = unit_data[unit]["constraints"][ "qwat_max"] / unit_data[unit]["af"]["af_wat"] # ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ # OPTIMIZATION +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ tol = 0.5 conv = 1000.0 # set initial high values to enter while loop iter_num = 0 while conv > tol and iter_num < 10: # main loop, repeats until convergence is met or number of iteration exceed 10 if iter_num > 0: # don't report reiteration the first time emit( "progress", { "data": "Repeat iteration to converge.. Iteration:%s ---------" % iter_num }) sleep(0.1) well_prod = {} well_prod["qgas"] = ut.get_filtermasked( PE_server, "GAP.MOD[{PROD}].WELL[$].SolverResults[0].GasRate", status, "float") well_prod["qoil"] = ut.get_filtermasked( PE_server, "GAP.MOD[{PROD}].WELL[$].SolverResults[0].OilRate", status, "float") well_prod["qwat"] = ut.get_filtermasked( PE_server, "GAP.MOD[{PROD}].WELL[$].SolverResults[0].WatRate", status, "float") oil_constraint = [ 0, 0, 0 ] # this is used as array flag for each unit to say if unit is oil constrained qgas max for swing well will be set from oil difference rather than gas optimized = 0 # this flag is used to decide if resolving network is needed or not for unit_idx, unit in enumerate( unit_names["simple"]): # solve every unit # this SI all unnesesary wells, finds swing well and chokes it back to set unit rates to unit constraints session_json, optimized, oil_constraint = solve_unit( PE_server, wellname, session_json, well_prod, unit_idx, oil_constraint, optimized, unit_data, unit_constraints_af) if optimized == 1: #this flag is used to decide if resolving network is needed or not emit("progress", {"data": "Solving Network.."}) sleep(0.1) ut.solve_network_rb( PE_server ) # repeat solve networ if any well was SI during unit optimization # report results of optimization and calculate covergence conv, tot_qoil, tot_qgas, tot_qwat = report_results( PE_server, unit_names, unit_data, oil_constraint, unit_constraints_af) iter_num += 1 # ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ # ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ if iter_num > 9: emit("progress", {"data": "Number of iterations exceeded!!!"}) ut.set_chokes_calculated( PE_server ) # after finishing calculations set back all well chokes to calculated state. This is required for the next calculations. res = { "tot_qoil": round(tot_qoil, 1), "tot_qgas": round(tot_qgas, 1), "tot_qwat": round(tot_qwat, 1) } dt = datetime.datetime.now() - start if mode == 1: # ut.showinterface(PE_server,1) PE_server = ut.PE.Stop() emit( "progress", { "data": "Calculations complete. Go to Results. <br> Time spent: %s" % dt, "finish": 1 }) elif mode == 2: emit( "progress", { "data": "Calculations complete. Switching to next State... <br> Time spent: %s" % dt }) sleep(0.1) return res
def load_pcs2gap(well_pcs): PE_server=ut.PE.Initialize() ut.showinterface(PE_server,0) wells=sorted(well_pcs.keys()) status=ut.get_all(PE_server,"GAP.MOD[{PROD}].WELL[$].MASKFLAG") # get status of wells in GAP model gap_wellnames=ut.get_filtermasked(PE_server,"GAP.MOD[{PROD}].WELL[$].Label",status,"string") # get wellnames of unmasked wells print(wells) for well in wells: if well in gap_wellnames: # make sure well exists in GAP model print(well) welltype=ut.PE.DoGet(PE_server,"GAP.MOD[{PROD}].WELL[{"+well+"}].TypeWell") zero_arr=np.zeros(20)+1.1 zero_arr=ut.list2gapstr(zero_arr) ut.PE.DoSet(PE_server,"GAP.MOD[{PROD}].WELL[{"+well+"}].MANIPRES[0:19]",zero_arr) if welltype=="CondensateProducer": ut.PE.DoSet(PE_server,"GAP.MOD[{PROD}].WELL[{"+well+"}].PCDATA[0][11][0:19]",zero_arr) #gasrate ut.PE.DoSet(PE_server,"GAP.MOD[{PROD}].WELL[{"+well+"}].PCDATA[0][12][0:19]",zero_arr) #wgr else: ut.PE.DoSet(PE_server,"GAP.MOD[{PROD}].WELL[{"+well+"}].PCDATA[0][0][0:19]",zero_arr) #liqrate ut.PE.DoSet(PE_server,"GAP.MOD[{PROD}].WELL[{"+well+"}].PCDATA[0][1][0:19]",zero_arr) #wc ut.PE.DoSet(PE_server,"GAP.MOD[{PROD}].WELL[{"+well+"}].PCDATA[0][2][0:19]",zero_arr) ut.PE.DoSet(PE_server,"GAP.MOD[{PROD}].WELL[{"+well+"}].PCDATA[0][3][0:19]",zero_arr) ut.PE.DoSet(PE_server,"GAP.MOD[{PROD}].WELL[{"+well+"}].PCDATA[0][7][0:19]",zero_arr) thps=ut.list2gapstr(well_pcs[well]["pc"]["thps"]) qliqs=ut.list2gapstr(well_pcs[well]["pc"]["qliqs"]) qgas=ut.list2gapstr(well_pcs[well]["pc"]["qgas"]) wcs=ut.list2gapstr(np.zeros(20)+well_pcs[well]["wct"]*100.0) wgrs=ut.list2gapstr(np.zeros(20)+well_pcs[well]["wgr"]) gors=ut.list2gapstr(np.zeros(20)+well_pcs[well]["gor"]) fbhps=ut.list2gapstr(well_pcs[well]["pc"]["fbhps"]) temps=ut.list2gapstr(well_pcs[well]["pc"]["temps"]) ut.PE.DoSet(PE_server,"GAP.MOD[{PROD}].WELL[{"+well+"}].MANIPRES[0:19]",thps) if welltype=="CondensateProducer": ut.PE.DoSet(PE_server,"GAP.MOD[{PROD}].WELL[{"+well+"}].PCDATA[0][11][0:19]",qgas) ut.PE.DoSet(PE_server,"GAP.MOD[{PROD}].WELL[{"+well+"}].PCDATA[0][12][0:19]",wgrs) else: ut.PE.DoSet(PE_server,"GAP.MOD[{PROD}].WELL[{"+well+"}].PCDATA[0][0][0:19]",qliqs) ut.PE.DoSet(PE_server,"GAP.MOD[{PROD}].WELL[{"+well+"}].PCDATA[0][1][0:19]",wcs) ut.PE.DoSet(PE_server,"GAP.MOD[{PROD}].WELL[{"+well+"}].PCDATA[0][2][0:19]",gors) ut.PE.DoSet(PE_server,"GAP.MOD[{PROD}].WELL[{"+well+"}].PCDATA[0][3][0:19]",fbhps) ut.PE.DoSet(PE_server,"GAP.MOD[{PROD}].WELL[{"+well+"}].PCDATA[0][7][0:19]",temps) ut.PE.DoSet(PE_server,"GAP.MOD[{PROD}].WELL[{"+well+"}].IPR[0].ResPres",well_pcs[well]["sbhp"]) ut.PE.DoSet(PE_server,"GAP.MOD[{PROD}].WELL[{"+well+"}].IPR[0].GOR",well_pcs[well]["gor"]) if welltype=="CondensateProducer": ut.PE.DoSet(PE_server,"GAP.MOD[{PROD}].WELL[{"+well+"}].IPR[0].WGR",well_pcs[well]["wgr"]) else: ut.PE.DoSet(PE_server,"GAP.MOD[{PROD}].WELL[{"+well+"}].IPR[0].WCT",well_pcs[well]["wct"]*100.0) emit("load_progress",{"data":"Loaded PCs to GAP for well %s, GOR=%.1f sm3/sm3, Watercut=%.1f %%, MAP=%.1f bar" % (well,well_pcs[well]["gor"],well_pcs[well]["wct"]*100.0,well_pcs[well]["map"])}) sleep(0.1) ut.showinterface(PE_server,1) PE_server=ut.PE.Stop() return None
def set_unit_routes(well_data,PE_server,mode): if mode!=2: PE_server=ut.PE.Initialize() ut.showinterface(PE_server,0) pipe_status=ut.get_all(PE_server,"GAP.MOD[{PROD}].PIPE[$].MASKFLAG") pipes=ut.get_filtermasked(PE_server,"GAP.MOD[{PROD}].PIPE[$].Label",pipe_status,"string") for well,val in well_data.items(): # if well is not masked then check and set routing if val["masked"]==0: # map selected_route to OS string route_open="" for i,r in enumerate(val["connection"]["routes"]): route=r["route_name"] print(well,route) if route==val["selected_route"]: route_open=r["os"] # check if setting mask/unmask is needed by looking at maskflag of the pipes toset=0 if route_open: route_open_arr=route_open.split(",") if len(route_open_arr)>1: if not route_open_arr[0] in pipes or not route_open_arr[1] in pipes: toset=1 else: if not route_open_arr[0] in pipes: toset=1 # required to be mask/unmask pipes if toset==1: # first close all route pipes for i,r in enumerate(val["connection"]["routes"]): if r["os"]!=route_open: # only first pipe closest to the well can be closed to stop it from the route # above is required so that does not interfere with (close) pipes of comingled wells to that route # temporary logic, more suitable steps to be done if len(r["os"].split(","))>1: if r["os"].split(",")[0]==route_open_arr[0]: ut.close_pipes(PE_server,r["os"].split(",")) else: ut.close_pipes(PE_server,[r["os"].split(",")[0]]) else: ut.close_pipes(PE_server,[r["os"].split(",")[0]]) # then open required route pipes for i,r in enumerate(val["connection"]["routes"]): if r["os"]==route_open: ut.open_pipes(PE_server,r["os"].split(",")) if mode!=2: ut.showinterface(PE_server,1) PE_server=ut.PE.Stop()