Exemplo n.º 1
0
def CAOSpy_rundx_noise(tstart,tstop,mc,pdyn,cinf,precTS,particles,leftover,drained,dt_max=1.,splitfac=10,prec_2D=False,maccoat=10.,exfilt_method='Ediss',saveDT=True,vertcalfac=1.,latcalfac=1.,clogswitch=False,infilt_method='MDA',film=True,dynamic_pedo=True,ksnoise=1.):
    if run_from_ipython():
        from IPython import display

    timenow=tstart
    prec_part=0. #precipitation which is less than one particle to accumulate
    acc_mxinf=0. #matrix infiltration may become very small - this shall handle that some particles accumulate to infiltrate
    exfilt_p=0. #exfiltration from the macropores
    s_red=0.
    #loop through time
    while timenow < tstop:
        [thS,npart]=pdyn.gridupdate_thS(particles.lat,particles.z,mc)
        if saveDT==True:
            #define dt as Courant/Neumann criterion
            dt_D=(mc.mgrid.vertfac.values[0])**2 / (6*np.nanmax(mc.D[np.amax(thS),:]))
            dt_ku=-mc.mgrid.vertfac.values[0]/np.nanmax(mc.ku[np.amax(thS),:])
            dt=np.amin([dt_D,dt_ku,dt_max,tstop-timenow])
        else:
            if type(saveDT)==float:
                #define dt as pre-defined
                dt=np.amin([saveDT,tstop-timenow])
            elif type(saveDT)==int:
                #define dt as modified  Corant/Neumann criterion
                dt_D=(mc.mgrid.vertfac.values[0])**2 / (6*np.nanmax(mc.D[np.amax(thS),:]))*saveDT
                dt_ku=-mc.mgrid.vertfac.values[0]/np.nanmax(mc.ku[np.amax(thS),:])*saveDT
                dt=np.amin([dt_D,dt_ku,dt_max,tstop-timenow])
        #INFILTRATION
        [p_inf,prec_part,acc_mxinf]=cinf.pmx_infilt(timenow,precTS,prec_part,acc_mxinf,thS,mc,pdyn,dt,0.,prec_2D,particles.index[-1],infilt_method) #drain all ponding // leftover <-> 0.
        particles=pd.concat([particles,p_inf])
        
        #DIFFUSION
        [particles,thS,npart,phi_mx]=pdyn.part_diffusion_split(particles,npart,thS,mc,dt,False,splitfac,vertcalfac,latcalfac,dynamic_pedo=True,ksnoise=ksnoise)
        #ADVECTION
        if not particles.loc[(particles.flag>0) & (particles.flag<len(mc.maccols)+1)].empty:
            [particles,s_red,exfilt_p]=pdyn.mac_advection(particles,mc,thS,dt,clogswitch,maccoat,exfilt_method,film=film,dynamic_pedo=True,ksnoise=ksnoise)
        #INTERACT
        particles=pdyn.mx_mp_interact_nobulk(particles,npart,thS,mc,dt,dynamic_pedo=True,ksnoise=ksnoise)

        if run_from_ipython():
            display.clear_output()
            display.display_pretty(''.join(['time: ',str(timenow),'s  |  precip: ',str(len(p_inf)),' particles  |  mean v(adv): ',str(particles.loc[particles.flag>0,'advect'].mean()),' m/s  |  exfilt: ',str(int(exfilt_p)),' particles']))
        else:
            print 'time: ',timenow,'s'

        #CLEAN UP DATAFRAME
        drained=drained.append(particles[particles.flag==len(mc.maccols)+1])
        particles=particles[particles.flag!=len(mc.maccols)+1]
        pondparts=(particles.z<0.)
        leftover=np.count_nonzero(-pondparts)
        particles.cell[particles.cell<0]=mc.mgrid.cells.values
        particles=particles[pondparts]
        timenow=timenow+dt

    return(particles,npart,thS,leftover,drained,timenow)
Exemplo n.º 2
0
def CAOSpy_rund_diffonly(tstart,
                         tstop,
                         mc,
                         pdyn,
                         cinf,
                         precTS,
                         particles,
                         leftover,
                         drained,
                         dt_max=1.,
                         splitfac=10,
                         prec_2D=False,
                         saveDT=True,
                         vertcalfac=1.,
                         latcalfac=1.):
    if run_from_ipython():
        from IPython import display

    timenow = tstart
    prec_part = 0.  #precipitation which is less than one particle to accumulate
    acc_mxinf = 0.  #matrix infiltration may become very small - this shall handle that some particles accumulate to infiltrate
    exfilt_p = 0.  #exfiltration from the macropores
    s_red = 0.
    #loop through time
    while timenow < tstop:
        [thS, npart] = pdyn.gridupdate_thS(particles.lat, particles.z, mc)
        if saveDT == True:
            #define dt as Courant/Neumann criterion
            dt_D = (mc.mgrid.vertfac.values[0])**2 / (
                6 * np.nanmax(mc.D[np.amax(thS), :]))
            dt_ku = -mc.mgrid.vertfac.values[0] / np.nanmax(
                mc.ku[np.amax(thS), :])
            dt = np.amin([dt_D, dt_ku, dt_max, tstop - timenow])
        else:
            if type(saveDT) == float:
                #define dt as pre-defined
                dt = np.amin([saveDT, tstop - timenow])
            elif type(saveDT) == int:
                #define dt as modified  Corant/Neumann criterion
                dt_D = (mc.mgrid.vertfac.values[0])**2 / (
                    6 * np.nanmax(mc.D[np.amax(thS), :])) * saveDT
                dt_ku = -mc.mgrid.vertfac.values[0] / np.nanmax(
                    mc.ku[np.amax(thS), :]) * saveDT
                dt = np.amin([dt_D, dt_ku, tstop - timenow])
        #INFILTRATION
        [p_inf, prec_part, acc_mxinf] = cinf.pmx_infilt(
            timenow, precTS, prec_part, acc_mxinf, thS, mc, pdyn, dt, 0.,
            prec_2D,
            particles.index[-1])  #drain all ponding // leftover <-> 0.
        p_inf.flag = 0
        particles = pd.concat([particles, p_inf])

        #DIFFUSION
        [particles, thS, npart,
         phi_mx] = pdyn.part_diffusion_split(particles, npart, thS, mc, dt,
                                             False, splitfac, vertcalfac,
                                             latcalfac)

        if run_from_ipython():
            display.clear_output()
            display.display_pretty(''.join([
                'time: ',
                str(timenow), 's  |  precip: ',
                str(len(p_inf)), ' particles'
            ]))
        else:
            print 'time: ', timenow, 's'

        #CLEAN UP DATAFRAME
        drained = drained.append(particles[particles.flag == len(mc.maccols) +
                                           1])
        particles = particles[particles.flag != len(mc.maccols) + 1]
        pondparts = (particles.z < 0.)
        leftover = np.count_nonzero(-pondparts)
        particles.cell[particles.cell < 0] = mc.mgrid.cells.values
        particles = particles[pondparts]
        timenow = timenow + dt

    return (particles, npart, thS, leftover, drained, timenow)