Ejemplo n.º 1
0
def CAOSpy_run(tstart,tstop,mc,pdyn,particles,leftover,drained):
    timenow=tstart
    #loop through time
    while timenow < tstop:
        print 'time:',timenow
        [thS,npart]=pdyn.gridupdate_thS(particles.lat,particles.z,mc)
        #define dt as Curant criterion
        dt_D=(mc.mgrid.vertfac.values[0])**2 / (2*np.amax(mc.D[np.amax(thS),:]))
        dt_ku=-mc.mgrid.vertfac.values[0]/np.amax(mc.ku[np.amax(thS),:])
        dt=np.amin([dt_D,dt_ku])
        #INFILT
        p_inf=cinf.pmx_infilt(timenow,precTS,mc,dt,leftover)
        #print timenow
        #print p_inf
        particlesnow=pd.concat([particles,p_inf])
        #p_backup=particlesnow.copy()
        #DIFFUSION
        [particlesnow,thS,npart,phi_mx]=pdyn.part_diffusion_split(particlesnow,npart,thS,mc,dt,True,10)
        #ADVECTION
        particlesnow=pdyn.mac_advection(particlesnow,mc,thS,dt)
        #drained particles
        drained=drained.append(particlesnow[particlesnow.flag==len(mc.maccols)+1])
        particlesnow=particlesnow[particlesnow.flag!=len(mc.maccols)+1]
        #MX-MAC-INTERACTION
        pdyn.mx_mp_interact(particlesnow,npart,thS,mc,dt)
        pondparts=(particlesnow.z<0.)
        leftover=np.count_nonzero(-pondparts)
        particles=particlesnow[pondparts]
        timenow=timenow+dt

    return(particles,npart,thS,leftover,drained,timenow)
Ejemplo n.º 2
0
def CAOSpy_run(tstart,tstop,dt,mc,pdyn,particles,leftover,drained):
    xstart=np.int64(tstart/dt)
    xstop=np.int64(tstop/dt)
    #loop through time
    for t in np.arange(xstop-xstart)+xstart:
        timenow=t*dt
        print 'time:',timenow
        [thS,npart]=pdyn.gridupdate_thS(particles.lat,particles.z,mc)  
        #INFILT
        p_inf=cinf.pmx_infilt(timenow,precTS,mc,dt,leftover)
        #print timenow
        #print p_inf
        particlesnow=pd.concat([particles,p_inf])
        #p_backup=particlesnow.copy()
        #DIFFUSION
        [particlesnow,thS,npart,phi_mx]=pdyn.part_diffusion_split(particlesnow,npart,thS,mc,dt,True,10)
        #ADVECTION
        #particlesnow=pdyn.mac_advection(particlesnow,mc,thS,dt)
        #drained particles
        drained=drained.append(particlesnow[particlesnow.flag==len(mc.maccols)+1])
        particlesnow=particlesnow[particlesnow.flag!=len(mc.maccols)+1]
        #MX-MAC-INTERACTION
        pdyn.mx_mp_interact(particlesnow,npart,thS,mc,dt)
        pondparts=(particlesnow.z<0.)
        leftover=np.count_nonzero(-pondparts)
        particles=particlesnow[pondparts]
        
    return(particles,npart,thS,leftover,drained,timenow)
Ejemplo n.º 3
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)
Ejemplo n.º 4
0
def CAOSpy_rundx1(tstart,
                  tstop,
                  mc,
                  pdyn,
                  cinf,
                  precTS,
                  particles,
                  leftover=0,
                  drained=0.1,
                  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,
                  infiltscale=False,
                  dynamic_pedo=False,
                  counteractpow=3):
    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.
    mc.splitfac = splitfac
    mc.counteract_pow = counteractpow

    if type(drained) == float:
        drained = pd.DataFrame(np.array([]))
    #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.amax(mc.D[particles.LTEbin.max(), :]))
            dt_ku = -mc.mgrid.vertfac.values[0] / np.amax(
                mc.ku[particles.LTEbin.max(), :])
            dt = np.amin([dt_D, dt_ku, dt_max, tstop - timenow])
            dt = np.amax([dt, 0.5])
            mc.dt = dt
        else:
            if type(saveDT) == float:
                #define dt as pre-defined
                dt = np.amin([saveDT, tstop - timenow])
                mc.dt = dt
            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])
                mc.dt = dt

        pcount = len(particles)
        #INFILTRATION (new version with binned)
        [p_inf, prec_part, acc_mxinf
         ] = cinf.pmx_infilt(timenow, precTS, prec_part, acc_mxinf, thS, mc,
                             pdyn, mc.dt, leftover, prec_2D,
                             particles.index[-1], infilt_method, infiltscale,
                             npart)  #drain all ponding // leftover <-> 0.
        particles = pd.concat([particles, p_inf])

        #DEBUG:
        #if len(particles)<100000:
        #    particles.to_pickle('DEBUG_particlesX.pic')
        #    assert False
        #particles.to_pickle('DEBUG_particles.pic')
        #particles=particles.groupby('cell').apply(pdyn.binupdate_pd,mc)
        #particles.loc[particles.LTEbin>(len(mc.ku)-1),'LTEbin']=len(mc.ku)-1
        #plot_mac(particles,'./results/Mtest'+str(np.round(timenow,2)))

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

        [particles, thS, npart,
         phi_mx] = pdyn.part_diffusion_binned_pd(particles, npart, thS, mc)

        #ADVECTION
        if not particles.loc[(particles.flag > 0)
                             & (particles.flag < len(mc.maccols) + 1)].empty:
            [particles, s_red, exfilt_p,
             mc] = pdyn.mac_advectionX(particles,
                                       mc,
                                       thS,
                                       mc.dt,
                                       clogswitch,
                                       maccoat,
                                       exfilt_method,
                                       film=film,
                                       dynamic_pedo=dynamic_pedo,
                                       npart=npart,
                                       fc_check=False)

        #INTERACT
        particles = pdyn.mx_mp_interact_nobulk(particles, npart, thS, mc,
                                               mc.dt, dynamic_pedo)

        #CLEAN UP DATAFRAME
        drained = drained.append(particles[particles.flag == len(mc.maccols) +
                                           1])
        particles = particles.loc[particles.flag != len(mc.maccols) + 1]
        #leftover+=np.intp((particles.z>=0.).sum())
        leftover = particles.z[particles.z >= 0.].count()
        particles = particles.loc[
            particles.z < 0.]  #drop all leftover back to infilt routine

        if run_from_ipython():
            display.clear_output()
            display.display_pretty(''.join([
                'time: ',
                str(timenow), 's  |  n_particles: ',
                str(pcount), '  |  precip: ',
                str(len(p_inf)), '  |  advect: ',
                str(
                    np.sum(((particles.flag > 0) &
                            (particles.flag <= len(mc.maccols))))),
                '  |  exfilt: ',
                str(int(exfilt_p)), '  |  mean v(adv): ',
                str(particles.loc[((particles.flag > 0) &
                                   (particles.flag <= len(mc.maccols))),
                                  'advect'].mean())[:7] +
                str(particles.loc[((particles.flag > 0) &
                                   (particles.flag <= len(mc.maccols))),
                                  'advect'].mean())[-4:], ' m/s'
            ]))
            display.display_pretty(''.join([
                'time: ',
                str(timenow), 's  |  n_particles now: ',
                str(len(particles)), '  |  leftover: ',
                str(leftover)
            ]))
        else:
            print('time: ', timenow, 's')

        #particles.loc[particles.cell<0,'cell']=mc.mgrid.cells.values
        #particles=particles[pondparts]
        timenow = timenow + mc.dt

    return (particles, npart, thS, leftover, drained, timenow)
Ejemplo n.º 5
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)