Ejemplo n.º 1
0
plt.close('all')
#%%
os.chdir('C:/Users/glbjch/Local Documents/Work/Modelling/Cotapaxi')


basemod='Cota20150811_1_m2'
mod=basemod+'_ptb4'
print mod
if not os.path.exists(mod):
    os.makedirs(mod)
    
dat=t2data(basemod+'/flow2.inp')
geo=mulgrid(basemod+'/grd.dat')
grid=dat.grid
width=geo.bounds[1][1]-geo.bounds[0][1]
ptg.makeradial(geo,None,width) #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

yrsec=365.25*3600*24    
# INCON
# change initial conditions from base model SAVE file
dat.incon.clear()
inc=t2incon(basemod + '/flow2.sav')
for blk in inc.blocklist:
    dat.incon[blk]=[None,inc[blk][0:]]
dat.parameter['option'][12]= 0
dat.parameter['timestep']=[1.0, 1.0E3,8.6400e+04]
dat.output_times['time']=[1.0]
dat.output_times['time_increment']= 10*yrsec

dat.output_times['num_times_specified']=len(dat.output_times['time'])
dat.output_times['num_times']=200
Ejemplo n.º 2
0
basemod=args.base
number=args.number
mod=basemod+'_var'+number
pseudo_topsurf=args.topsurf_flag
if args.pseudo_elev is not None:
    pseudo_elev=float(args.pseudo_elev)
else:
    pseudo_elev=None
if not os.path.exists(mod):
    os.makedirs(mod)

# read template file    
dat=t2data('flow2.inp')
geo=mulgrid('grd.dat')
grid=dat.grid
ptg.makeradial(geo,None,width=10.)
# INCON
# change initial conditions from base model SAVE file
dat.incon.clear()
# Read from existing file
inc=t2incon('flow2.sav')
inc.write(mod+'/flow2.inc')

#%% update T2 params
dat.parameter['max_timestep']=2.0e6
dat.parameter['print_interval']=50
dat.parameter['timestep']=[1.0]
dat.output_times['time_increment']=3*28.*3600*24
dat.output_times['time']=[1.0]
dat.output_times['num_times_specified']=len(dat.output_times['time'])
dat.output_times['num_times']=500
Ejemplo n.º 3
0
    ecol = []  # set boundary columns to none

grid = ipt.icegrid(
    geo,
    dat,
    rtypes,
    ecol,
    infax=False,
    radial=radial,
    hpregion={
        'hp   ': [[0, 0, 3000], [250, 0, 6000]],
        'hp2  ': [[250, 0, 5250], [2000, 0, 6000]],
        'hp3  ': [[0, 0, 5250], [250, 0, 6000]]
    }
)  #, 'hp2  ':[[720,0,3000],[780,0,6000]]})#[[0,0,3000],[250,0,5250]],'hp2  ':[[250,0,5250],[2000,0,6000]],'hp3  ':[[0,0,5250],[250,0,6000]]})#,heatsource=[[0,0,3000],[1500,0,3050]])
if radial: ptg.makeradial(geo, grid, width=width)

## Create TOUGH input file ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#%%
#~ Create sources and sinks GENER block in TOUGH input file.
#tflux=0.09 # J/m2/s example heat flux

# additional output parameters
dat.parameter['max_timestep'] = 10 * yrsec  # maximum timstep length
dat.parameter['print_interval'] = 100  # print (output) frequency to flow.out
dat.parameter['timestep'] = [1.0]  #[1.0,1000.0] # initial timestep?
dat.parameter['upstream_weight'] = 1.0
dat.parameter['option'][
    11] = 0  #mobilities are upstream weighted, permeability is harmonic weighted
#dat.momop['option'][10]=1
dat.output_times['time'] = [
Ejemplo n.º 4
0
t0=time.clock()
plt.close('all')
#%%
os.chdir('C:/Users/glbjch/Local Documents/Work/Modelling/Cotapaxi')


basemod='Cota20150612_1_ptb'
mod=basemod.replace('_ptb','_rtn')
if not os.path.exists(mod):
    os.makedirs(mod)
    
dat=t2data(basemod+'/flow2.inp')
geo=mulgrid(basemod+'/grd.dat')
grid=dat.grid
width=geo.bounds[1][1]-geo.bounds[0][1]
ptg.makeradial(geo,None,width)

yrsec=365.25*3600*24    
# INCON
# change initial conditions from base model SAVE file
dat.incon.clear()
inc=t2incon(basemod + '/flow2.sav')

# additional output parameters 
dat.parameter['max_timestep']=3.1558e+09 # maximum timstep length
dat.parameter['print_interval']=20 # print (output) frequency to flow.out
dat.parameter['timestep']=[1.0E3,8.6400e+04,3.1558e+08] # initial timestep?
dat.parameter['tstop']=None
dat.output_times['time']=[1000.0,3600.0,8.6400e+04,3.1558e+07,3.1558e+08,3.1558e+09] # predefined output times
dat.output_times['num_times_specified']=len(dat.output_times['time'])
dat.output_times['num_times']=150
Ejemplo n.º 5
0
main.conductivity = b.conductivity = source.conductivity = top.conductivity = hp.conductivity = conds  # reset all conductivities
#%%

if np.size(
        geo.columnlist
) > 1:  # can be used to find lateral boundaries in a 2D model - NOTE: WILL NOT WORK FOR 3D
    newlist = np.array([(col, col.centre[0]) for col in geo.columnlist])
    ecol = [newlist[newlist[:, 1].argsort()][-1, 0]]
    print ecol
else:  # if the column list length is only 1 then there can be no lateral boundary.
    ecol = []  # set boundary columns to none

grid = icegrid(
    geo, dat, rtypes, ecol, satelev=5300.
)  #, hpregion={'hpr1':[[0,0,3000],[50,0,6000]],'hpr2':[[200,0,3000],[250,0,6000]]})#,heatsource=[[0,0,3000],[1500,0,3050]])
ptg.makeradial(geo, grid, width=width)

## Create TOUGH input file ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#%%
#~ Create sources and sinks GENER block in TOUGH input file.
#tflux=0.09 # J/m2/s example heat flux

# additional output parameters
dat.parameter['max_timestep'] = 1000 * yrsec  # maximum timstep length
dat.parameter['print_interval'] = 50  # print (output) frequency to flow.out
dat.parameter['timestep'] = [1.0]  #[1.0,1000.0] # initial timestep?
dat.parameter['upstream_weight'] = 1.0
dat.parameter['option'][
    11] = 0  #mobilities are upstream weighted, permeability is harmonic weighted
dat.parameter['relative_error'] = 1.0e-6
dat.parameter['absolute_error'] = 1.0e-1
Ejemplo n.º 6
0
def icepost(modelname,
            save=False,
            radial=True,
            savevtk=False,
            geom_data=None,
            tough2_input=None,
            results=None,
            times={},
            fall=None,
            flows={
                'FLOH': {},
                'FLOF': {}
            },
            logt=False):
    """ Function to calculated surface heat flow from pytough results
    """
    if type(tough2_input) is not t2data and tough2_input is not None:
        raise TypeError('data needs to be type t2data. Type ' +
                        str(type(tough2_input)) + ' found. You idiot')
    elif tough2_input is None:
        raise TypeError(
            'data needs to be type t2data. Currently None found. You idiot')
    else:
        dat = tough2_input
    if type(geom_data) is not mulgrid and geom_data is not None:
        raise TypeError('data needs to be type mulgrid. Type ' +
                        str(type(geom_data)) + ' found. You idiot')
    elif geom_data is None:
        raise TypeError(
            'data needs to be type mulgrid. Currently None found. You idiot')
    else:
        geo = geom_data
    if type(results) is not t2listing and results is not None:
        raise TypeError('results needs to be type t2listing. Type ' +
                        str(type(results)) + ' found. You idiot')
    elif results is None:
        print('No Results files (flow.out) passed. please read flow2.out')
    results = results
    width = geo.bounds[1][1] - geo.bounds[0][1]
    yrsec = 365.25 * 3600 * 24
    mod = modelname
    if radial and not geo.radial:
        ptg.makeradial(geo, None, width)
    # find atmosphere blocks
    grid = dat.grid  # define input grid
    grid2 = t2grid().fromgeo(
        geo
    )  # grid saved in flow2.inp does not contain atmos information required.
    atmos = []
    atmosconn = []
    for flow in flows:
        t0 = time.clock()
        if flows[flow] == {}:
            if atmos == []:
                atmos = grid2.atmosphere_blocks
                # find atmosphere connections
                atmosconn = [
                    cell.connection_name for cell in atmos
                ]  # returns a list of sets - !!!! sets are not ordered so cannot be indexed !!!
            flows[flow], times = surfaceflow(atmos,
                                             atmosconn,
                                             results=results,
                                             grid=grid2,
                                             flow=flow)
        tq = times
        X = []
        qts = []
        Area = []
        for x, a, q in flows[flow].values():
            X.append(x)
            qts.append(q)
            Area.append(a)
        inds = np.array(X).argsort()
        X = np.array(X)[inds]
        qts = np.array(qts)[inds]  # J/s/m2 or kg/s/m2
        Area = np.array(Area)[inds]
        totq = np.sum(np.multiply(qts.T, Area), axis=1)

        if flow == 'FLOH' or flow == 'FHEAT':  # calculate meltrate etc.
            unit = 'W'
            meltratematrix = (qts.T / 3.335E5)  # kg/s/m2
            # but negative meltrate cant exist....
            # where heatflow is negative and meltrate is negative set meltrate=0
            #tempdel=np.array([tstep-meltratematrix[0] for tstep in meltratematrix]) # kg/s/m2 ~ mm/s
            meltratematrix[meltratematrix < 0] = 0  # kg/s/m2
            # change in meltrate
            deltameltrate = np.array([
                tstep - meltratematrix[0] for tstep in meltratematrix
            ])  # kg/s/m2 ~ mm/s
            #meltrate just within glacier
            glacmeltrate = meltratematrix.T[X < 2500].T  # kg/s/m2 ~ mm/s
            print np.max(glacmeltrate)
            #change in meltrate within glacier
            deltaglacmeltrate = deltameltrate.T[X < 2500].T  # kg/s/m2 ~ mm/s
            i = 0
            meltrate = np.zeros(len(tq))
            for t in tq:
                for x, A, r in zip(X, Area, meltratematrix[i]):
                    if r > 0 and x < 2500:
                        meltrate[i] = meltrate[i] + (r * A)  # kg/s
                i = i + 1
            meltrate_mmpyr = (meltrate * yrsec) / (np.pi * (2500**2)
                                                   )  # kg/yr/m2 ~ mm/yr
        else:
            unit = 'kg/s'

        # plottings
        tscale = tq / yrsec
        if logt:
            tscale = np.log10(tscale)
        ## a quick plot of flows into atmosphere at X and time.
        plt.figure()
        plt.pcolormesh(X, tscale, qts.T, rasterized=True,
                       cmap='rainbow')  #W or (ks/s) /m2
        cbar = plt.colorbar(format='%.1e')
        cbar.set_label(flow + r' out of the model (' + unit + r'/m$^{2}$)')
        #plt.xlim(0,2500)
        plt.ylim(tscale.min(), tscale.max())
        plt.title('Flow (' + flow + ') out of the model')
        plt.xlabel('Distance from axial centre (m)')
        plt.ylabel('Time (yrs)')
        plt.tight_layout()
        if save:
            plt.savefig('results/' + mod + '_' + flow + '_.pdf', dpi=400)

        qout = np.ma.masked_array(
            qts,
            [qts < 0])  # mask where flow is negative (i.e. in to the model)
        qin = np.ma.masked_array(
            qts,
            [qts > 0])  # mask where flow is positive (i.e. out of the model)
        delqout = np.array([tstep - qts.T[0]
                            for tstep in qout.T])  # kg/s/m2 ~ mm/s
        delqin = np.array([qts.T[0] - tstep for tstep in qin.T])

        plt.figure()
        plt.pcolormesh(X, tscale, delqout, rasterized=True,
                       cmap='rainbow')  #W or (ks/s) /m2
        cbar = plt.colorbar(format='%.1e')
        cbar.set_label('Change in ' + flow + r' out of the model (' + unit +
                       r'/m$^{2}$)')
        #plt.xlim(0,2500)
        plt.ylim(tscale.min(), tscale.max())
        plt.title('Change in flow (' + flow + ') out of the model')
        plt.xlabel('Distance from centre axis (m)')
        plt.ylabel('Time (yrs)')
        plt.tight_layout()
        if save:
            plt.savefig('results/' + mod + '_delout_' + flow + '_.pdf',
                        dpi=400)

        plt.figure()
        plt.pcolormesh(X, tscale, delqin, rasterized=True,
                       cmap='rainbow')  #W or (ks/s) /m2
        cbar = plt.colorbar(format='%.1e')
        cbar.set_label('Change in ' + flow + r' in to the model (' + unit +
                       r'/m$^{2}$)')
        #plt.xlim(0,2500)
        plt.ylim(tscale.min(), tscale.max())
        plt.title('Change in flow (' + flow + ') in to the model')
        plt.xlabel('Distance from centre axis (m)')
        plt.ylabel('Time (yrs)')
        plt.tight_layout()
        if save:
            plt.savefig('results/' + mod + '_delin_' + flow + '_.pdf', dpi=400)


#        plt.figure()
#        plt.plot(tscale,totq)
#        #plt.xlim(0, 30000)
#        plt.xlabel('Time (years)')
#        plt.ylabel('Net flow ('+unit+')')
#        plt.title('Net flow in/out of surface')

        if save:
            if os.path.isfile('results/' + flow + '.pkl'):
                print(flow + ' flow alreay pickled')
            else:
                ptg.save_obj(flows[flow], 'results/' + flow + '.pkl')
            if os.path.isfile('results/time.pkl'):
                print('time alreay pickled')
            else:
                ptg.save_obj(tq, 'results/time.pkl')
        t1 = time.clock()
        print 'time for flow=', (t1 - t0)

    if savevtk and os.path.isfile('results/' + mod + '_output.vtk') is False:
        os.chdir('results')
        results.write_vtk(geo, mod + '_output.vtk', grid=grid, flows=True)
        os.chdir('..')

    plt.figure()
    plt.pcolormesh(X, tscale, meltratematrix, rasterized=True,
                   cmap='rainbow')  # mm/s
    cbar = plt.colorbar(format='%.1e')
    cbar.set_label(r'Melt rate (kg/s/m$^{2}$)')
    #plt.xlim((0,2500))
    plt.ylim(tscale.min(), tscale.max())
    plt.xlabel('Distance from centre axis (m)')
    plt.ylabel('Time (yrs)')
    plt.title('Melt rate')
    plt.tight_layout()
    if save:
        plt.savefig('results/' + mod + '_meltrate_.pdf', dpi=400)

    plt.figure()
    plt.pcolormesh(X[X < 2500],
                   tscale,
                   glacmeltrate,
                   rasterized=True,
                   cmap='rainbow')  #, vmax=3.2e-4) # mm/s
    cbar = plt.colorbar(format='%.1e')
    cbar.set_label(r'Glacial melt rate (kg/s/m$^{2}$)')
    #plt.xlim((0,250))
    plt.ylim(tscale.min(), tscale.max())
    plt.xlabel('Distance from centre axis (m)')
    plt.ylabel('Time (yrs)')
    plt.title('Melt rate')
    plt.tight_layout()
    if save:
        plt.savefig('results/' + mod + '_glac_meltrate_.pdf', dpi=400)

    plt.figure()
    plt.pcolormesh(X, tscale, deltameltrate, rasterized=True,
                   cmap='rainbow')  # mm/s
    cbar = plt.colorbar(format='%.1e')
    cbar.set_label(r'Change in melt rate (kg/s/m$^{2}$)')
    #plt.xlim((0,2500))
    plt.ylim(tscale.min(), tscale.max())
    plt.xlabel('Distance from centre axis (m)')
    plt.ylabel('Time (yrs)')
    plt.title('Change in melt rate')
    plt.tight_layout()
    if save:
        plt.savefig('results/' + mod + '_meltrate_delta_.pdf', dpi=400)

    plt.figure()
    plt.pcolormesh(X[X < 2500],
                   tscale,
                   deltaglacmeltrate,
                   rasterized=True,
                   cmap='rainbow')  # mm/s
    cbar = plt.colorbar(format='%.1e')
    cbar.set_label(r'Change in melt rate (kg/s/m$^{2}$)')
    plt.xlim((0, 2500))
    plt.ylim(tscale.min(), tscale.max())
    plt.title('Change in glacial melt rate')
    plt.tight_layout()
    if save:
        plt.savefig('results/' + mod + '_glacmeltrate_delta_.pdf', dpi=400)

    #############

    #np.savetxt("melt_time.txt", np.vstack(([tq], [meltrate],[meltrate_mpyr])).T)

    plt.figure()
    plt.plot(tscale, meltrate_mmpyr)
    #plt.xlim(0, 30000)
    plt.xlabel('Time (yrs)')
    plt.ylabel('Average melt rate at glacial base (mm/yr)')
    plt.title('Average basal meltrate')
    plt.tight_layout()
    if save:
        plt.savefig('results/' + mod + '_basalmelt.pdf')
Ejemplo n.º 7
0
import os
import pytoughgrav as ptg
import matplotlib.pyplot as plt
import matplotlib.colors as mcols

plt.close('all')
os.chdir('/Users/briochh/Documents/Workhere/testing')
mod='topoRAD_4_0__0_24surfperm_1E-14_FLATTOP' # define model name
os.chdir(mod)
if not os.path.exists('results'): 
    os.makedirs('results')   
    
dat=t2data('flow2.inp')
grid=dat.grid
geo=mulgrid('grd.dat')
ptg.makeradial(geo,None,1.0)
#results=t2listing('flow2.out')   # comment out if results has already been loaded........
os.chdir('results')
if not os.path.exists('surfaceflow_test'):
    os.makedirs('surfaceflow_test')

# find atmosphere blocks
grid2=t2grid().fromgeo(geo) # grid saved in flow2.inp does not contain atmos information required.
atmos=grid2.atmosphere_blocks
# find atmosphere connections
atmosconn=[cell.connection_name for cell in atmos] # returns a list of sets - !!!! sets are not ordered so cannot be indexed !!! 

flowH={} # if was we to record flow by connection in a dictionary 
flowF={}
totqh=glac_toqh=totqf=glac_toqf=np.zeros(results.num_times) # arrays for adding total flows at each timstep