コード例 #1
0
ファイル: unsplitFluxes.py プロジェクト: jzuhone/pyro2
def unsplitFluxes(my_data, dt):
    """
    unsplitFluxes returns the fluxes through the x and y interfaces by
    doing an unsplit reconstruction of the interface values and then
    solving the Riemann problem through all the interfaces at once
                                                                               
    currently we assume a gamma-law EOS 

    grav is the gravitational acceleration in the y-direction            
    """

    pf = profile.timer("unsplitFluxes")
    pf.begin()
    
    myg = my_data.grid
    rp = my_data.rp

    #=========================================================================
    # compute the primitive variables
    #=========================================================================
    # Q = (rho, u, v, p)

    dens = my_data.get_var("density")
    xmom = my_data.get_var("x-momentum")
    ymom = my_data.get_var("y-momentum")
    ener = my_data.get_var("energy")

    r = dens

    # get the velocities
    u = xmom/dens
    v = ymom/dens

    # get the pressure
    e = (ener - 0.5*(xmom**2 + ymom**2)/dens)/dens

    p = eos.pres(dens, e)

    smallp = 1.e-10
    p = p.clip(smallp)   # apply a floor to the pressure
    

    #=========================================================================
    # compute the flattening coefficients
    #=========================================================================

    # there is a single flattening coefficient (xi) for all directions
    use_flattening = rp.get_param("compressible.use_flattening")

    if use_flattening:
        delta = rp.get_param("compressible.delta")
        z0 = rp.get_param("compressible.z0")
        z1 = rp.get_param("compressible.z1")

        xi_x = reconstruction_f.flatten(1, p, u, myg.qx, myg.qy, myg.ng, smallp, delta, z0, z1)
        xi_y = reconstruction_f.flatten(2, p, v, myg.qx, myg.qy, myg.ng, smallp, delta, z0, z1)

        xi = reconstruction_f.flatten_multid(xi_x, xi_y, p, myg.qx, myg.qy, myg.ng)
    else:
        xi = 1.0


    #=========================================================================
    # x-direction
    #=========================================================================

    # monotonized central differences in x-direction
    pfa = profile.timer("limiting")
    pfa.begin()

    limiter = rp.get_param("compressible.limiter")
    if limiter == 0:
        limitFunc = reconstruction_f.nolimit
    elif limiter == 1:
        limitFunc = reconstruction_f.limit2
    else:
        limitFunc = reconstruction_f.limit4
    
    ldelta_r = xi*limitFunc(1, r, myg.qx, myg.qy, myg.ng)
    ldelta_u = xi*limitFunc(1, u, myg.qx, myg.qy, myg.ng)
    ldelta_v = xi*limitFunc(1, v, myg.qx, myg.qy, myg.ng)
    ldelta_p = xi*limitFunc(1, p, myg.qx, myg.qy, myg.ng)
    
    pfa.end()
    
    # left and right primitive variable states
    pfb = profile.timer("interfaceStates")
    pfb.begin()

    gamma = rp.get_param("eos.gamma")

    V_l = myg.scratch_array(vars.nvar)
    V_r = myg.scratch_array(vars.nvar)

    V_l, V_r = interface_f.states(1, myg.qx, myg.qy, myg.ng, myg.dx, dt,
                                  vars.nvar,
                                  gamma,
                                  r, u, v, p,
                                  ldelta_r, ldelta_u, ldelta_v, ldelta_p) 
    
    pfb.end()
                    

    # transform interface states back into conserved variables
    U_xl = myg.scratch_array(vars.nvar)
    U_xr = myg.scratch_array(vars.nvar)

    U_xl[:,:,vars.idens] = V_l[:,:,vars.irho]
    U_xl[:,:,vars.ixmom] = V_l[:,:,vars.irho]*V_l[:,:,vars.iu]
    U_xl[:,:,vars.iymom] = V_l[:,:,vars.irho]*V_l[:,:,vars.iv]
    U_xl[:,:,vars.iener] = eos.rhoe(V_l[:,:,vars.ip]) + \
        0.5*V_l[:,:,vars.irho]*(V_l[:,:,vars.iu]**2 + V_l[:,:,vars.iv]**2)

    U_xr[:,:,vars.idens] = V_r[:,:,vars.irho]
    U_xr[:,:,vars.ixmom] = V_r[:,:,vars.irho]*V_r[:,:,vars.iu]
    U_xr[:,:,vars.iymom] = V_r[:,:,vars.irho]*V_r[:,:,vars.iv]
    U_xr[:,:,vars.iener] = eos.rhoe(V_r[:,:,vars.ip]) + \
        0.5*V_r[:,:,vars.irho]*(V_r[:,:,vars.iu]**2 + V_r[:,:,vars.iv]**2)



    #=========================================================================
    # y-direction
    #=========================================================================

    # monotonized central differences in y-direction
    pfa.begin()

    ldelta_r = xi*limitFunc(2, r, myg.qx, myg.qy, myg.ng)
    ldelta_u = xi*limitFunc(2, u, myg.qx, myg.qy, myg.ng)
    ldelta_v = xi*limitFunc(2, v, myg.qx, myg.qy, myg.ng)
    ldelta_p = xi*limitFunc(2, p, myg.qx, myg.qy, myg.ng)

    pfa.end()
    
    # left and right primitive variable states
    pfb.begin()

    V_l, V_r = interface_f.states(2, myg.qx, myg.qy, myg.ng, myg.dy, dt,
                                  vars.nvar,
                                  gamma,
                                  r, u, v, p,
                                  ldelta_r, ldelta_u, ldelta_v, ldelta_p)                                    

    pfb.end()


    # transform interface states back into conserved variables
    U_yl = myg.scratch_array(vars.nvar)
    U_yr = myg.scratch_array(vars.nvar)

    U_yl[:,:,vars.idens] = V_l[:,:,vars.irho]
    U_yl[:,:,vars.ixmom] = V_l[:,:,vars.irho]*V_l[:,:,vars.iu]
    U_yl[:,:,vars.iymom] = V_l[:,:,vars.irho]*V_l[:,:,vars.iv]
    U_yl[:,:,vars.iener] = eos.rhoe(V_l[:,:,vars.ip]) + \
        0.5*V_l[:,:,vars.irho]*(V_l[:,:,vars.iu]**2 + V_l[:,:,vars.iv]**2)

    U_yr[:,:,vars.idens] = V_r[:,:,vars.irho]
    U_yr[:,:,vars.ixmom] = V_r[:,:,vars.irho]*V_r[:,:,vars.iu]
    U_yr[:,:,vars.iymom] = V_r[:,:,vars.irho]*V_r[:,:,vars.iv]
    U_yr[:,:,vars.iener] = eos.rhoe(V_r[:,:,vars.ip]) + \
        0.5*V_r[:,:,vars.irho]*(V_r[:,:,vars.iu]**2 + V_r[:,:,vars.iv]**2)


    #=========================================================================
    # apply source terms
    #=========================================================================
    grav = rp.get_param("compressible.grav")

    # ymom_xl[i,j] += 0.5*dt*dens[i-1,j]*grav
    U_xl[myg.ilo-1:myg.ihi+2,myg.jlo-1:myg.jhi+2,vars.iymom] += \
        0.5*dt*dens[myg.ilo-2:myg.ihi+1,myg.jlo-1:myg.jhi+2]*grav

    U_xl[myg.ilo-1:myg.ihi+2,myg.jlo-1:myg.jhi+2,vars.iener] += \
        0.5*dt*ymom[myg.ilo-2:myg.ihi+1,myg.jlo-1:myg.jhi+2]*grav

    # ymom_xr[i,j] += 0.5*dt*dens[i,j]*grav
    U_xr[myg.ilo-1:myg.ihi+2,myg.jlo-1:myg.jhi+2,vars.iymom] += \
        0.5*dt*dens[myg.ilo-1:myg.ihi+2,myg.jlo-1:myg.jhi+2]*grav

    U_xr[myg.ilo-1:myg.ihi+2,myg.jlo-1:myg.jhi+2,vars.iener] += \
        0.5*dt*ymom[myg.ilo-1:myg.ihi+2,myg.jlo-1:myg.jhi+2]*grav

    # ymom_yl[i,j] += 0.5*dt*dens[i,j-1]*grav
    U_yl[myg.ilo-1:myg.ihi+2,myg.jlo-1:myg.jhi+2,vars.iymom] += \
        0.5*dt*dens[myg.ilo-1:myg.ihi+2,myg.jlo-2:myg.jhi+1]*grav

    U_yl[myg.ilo-1:myg.ihi+2,myg.jlo-1:myg.jhi+2,vars.iener] += \
        0.5*dt*ymom[myg.ilo-1:myg.ihi+2,myg.jlo-2:myg.jhi+1]*grav

    # ymom_yr[i,j] += 0.5*dt*dens[i,j]*grav
    U_yr[myg.ilo-1:myg.ihi+2,myg.jlo-1:myg.jhi+2,vars.iymom] += \
        0.5*dt*dens[myg.ilo-1:myg.ihi+2,myg.jlo-1:myg.jhi+2]*grav

    U_yr[myg.ilo-1:myg.ihi+2,myg.jlo-1:myg.jhi+2,vars.iener] += \
        0.5*dt*ymom[myg.ilo-1:myg.ihi+2,myg.jlo-1:myg.jhi+2]*grav


    #=========================================================================
    # compute transverse fluxes
    #=========================================================================
    pfc = profile.timer("riemann")
    pfc.begin()

    riemann = rp.get_param("compressible.riemann")

    if riemann == "HLLC":
        riemannFunc = interface_f.riemann_hllc
    elif riemann == "CGF":
        riemannFunc = interface_f.riemann_cgf
    else:
        msg.fail("ERROR: Riemann solver undefined")


    F_x = riemannFunc(1, myg.qx, myg.qy, myg.ng, 
                      vars.nvar, vars.idens, vars.ixmom, vars.iymom, vars.iener, 
                      gamma, U_xl, U_xr)

    F_y = riemannFunc(2, myg.qx, myg.qy, myg.ng, 
                      vars.nvar, vars.idens, vars.ixmom, vars.iymom, vars.iener, 
                      gamma, U_yl, U_yr)

    pfc.end()

    #=========================================================================
    # construct the interface values of U now
    #=========================================================================

    """
    finally, we can construct the state perpendicular to the interface
    by adding the central difference part to the trasverse flux
    difference.

    The states that we represent by indices i,j are shown below
    (1,2,3,4):
            

      j+3/2--+----------+----------+----------+ 
             |          |          |          | 
             |          |          |          | 
        j+1 -+          |          |          | 
             |          |          |          | 
             |          |          |          |    1: U_xl[i,j,:] = U  
      j+1/2--+----------XXXXXXXXXXXX----------+                      i-1/2,j,L
             |          X          X          | 
             |          X          X          |  
          j -+        1 X 2        X          |    2: U_xr[i,j,:] = U 
             |          X          X          |                      i-1/2,j,R
             |          X    4     X          | 
      j-1/2--+----------XXXXXXXXXXXX----------+  
             |          |    3     |          |    3: U_yl[i,j,:] = U 
             |          |          |          |                      i,j-1/2,L
        j-1 -+          |          |          |   
             |          |          |          |  
             |          |          |          |    4: U_yr[i,j,:] = U 
      j-3/2--+----------+----------+----------+                      i,j-1/2,R
             |    |     |    |     |    |     |  
                 i-1         i         i+1      
           i-3/2      i-1/2      i+1/2      i+3/2 


    remember that the fluxes are stored on the left edge, so 

    F_x[i,j,:] = F_x 
                    i-1/2, j   

    F_y[i,j,:] = F_y   
                    i, j-1/2   
                                       
    """

    pfd = profile.timer("transverse flux addition")
    pfd.begin()

    # U_xl[i,j,:] = U_xl[i,j,:] - 0.5*dt/dy * (F_y[i-1,j+1,:] - F_y[i-1,j,:])
    U_xl[myg.ilo-2:myg.ihi+2,myg.jlo-2:myg.jhi+2,:] += \
        - 0.5*dt/myg.dy * (F_y[myg.ilo-3:myg.ihi+1,myg.jlo-1:myg.jhi+3,:] - \
                           F_y[myg.ilo-3:myg.ihi+1,myg.jlo-2:myg.jhi+2,:])    

    # U_xr[i,j,:] = U_xr[i,j,:] - 0.5*dt/dy * (F_y[i,j+1,:] - F_y[i,j,:])
    U_xr[myg.ilo-2:myg.ihi+2,myg.jlo-2:myg.jhi+2,:] += \
        - 0.5*dt/myg.dy * (F_y[myg.ilo-2:myg.ihi+2,myg.jlo-1:myg.jhi+3,:] - \
                           F_y[myg.ilo-2:myg.ihi+2,myg.jlo-2:myg.jhi+2,:])    

    # U_yl[i,j,:] = U_yl[i,j,:] - 0.5*dt/dx * (F_x[i+1,j-1,:] - F_x[i,j-1,:])
    U_yl[myg.ilo-2:myg.ihi+2,myg.jlo-2:myg.jhi+2,:] += \
        - 0.5*dt/myg.dx * (F_x[myg.ilo-1:myg.ihi+3,myg.jlo-3:myg.jhi+1,:] - \
                           F_x[myg.ilo-2:myg.ihi+2,myg.jlo-3:myg.jhi+1,:])
                
    # U_yr[i,j,:] = U_yr[i,j,:] - 0.5*dt/dx * (F_x[i+1,j,:] - F_x[i,j,:])
    U_yr[myg.ilo-2:myg.ihi+2,myg.jlo-2:myg.jhi+2,:] += \
        - 0.5*dt/myg.dx * (F_x[myg.ilo-1:myg.ihi+3,myg.jlo-2:myg.jhi+2,:] - \
                           F_x[myg.ilo-2:myg.ihi+2,myg.jlo-2:myg.jhi+2,:])

    pfd.end()


    #=========================================================================
    # construct the fluxes normal to the interfaces
    #=========================================================================
    
    # up until now, F_x and F_y stored the transverse fluxes, now we
    # overwrite with the fluxes normal to the interfaces

    pfc.begin()
        
    F_x = riemannFunc(1, myg.qx, myg.qy, myg.ng, 
                      vars.nvar, vars.idens, vars.ixmom, vars.iymom, vars.iener, 
                      gamma, U_xl, U_xr)

    F_y = riemannFunc(2, myg.qx, myg.qy, myg.ng, 
                      vars.nvar, vars.idens, vars.ixmom, vars.iymom, vars.iener, 
                      gamma, U_yl, U_yr)

    pfc.end()

    #=========================================================================
    # apply artificial viscosity
    #=========================================================================
    cvisc = rp.get_param("compressible.cvisc")

    (avisco_x, avisco_y) = interface_f.artificial_viscosity( \
                              myg.qx, myg.qy, myg.ng, myg.dx, myg.dy, \
                              cvisc, u, v)

    # F_x = F_x + avisco_x * (U(i-1,j) - U(i,j))
    F_x[myg.ilo-2:myg.ihi+2,myg.jlo-2:myg.jhi+2,vars.idens] += \
        avisco_x[myg.ilo-2:myg.ihi+2,myg.jlo-2:myg.jhi+2]* \
          (dens[myg.ilo-3:myg.ihi+1,myg.jlo-2:myg.jhi+2] - \
           dens[myg.ilo-2:myg.ihi+2,myg.jlo-2:myg.jhi+2])

    F_x[myg.ilo-2:myg.ihi+2,myg.jlo-2:myg.jhi+2,vars.ixmom] += \
        avisco_x[myg.ilo-2:myg.ihi+2,myg.jlo-2:myg.jhi+2]* \
          (xmom[myg.ilo-3:myg.ihi+1,myg.jlo-2:myg.jhi+2] - \
           xmom[myg.ilo-2:myg.ihi+2,myg.jlo-2:myg.jhi+2])

    F_x[myg.ilo-2:myg.ihi+2,myg.jlo-2:myg.jhi+2,vars.iymom] += \
        avisco_x[myg.ilo-2:myg.ihi+2,myg.jlo-2:myg.jhi+2]* \
          (ymom[myg.ilo-3:myg.ihi+1,myg.jlo-2:myg.jhi+2] - \
           ymom[myg.ilo-2:myg.ihi+2,myg.jlo-2:myg.jhi+2])

    F_x[myg.ilo-2:myg.ihi+2,myg.jlo-2:myg.jhi+2,vars.iener] += \
        avisco_x[myg.ilo-2:myg.ihi+2,myg.jlo-2:myg.jhi+2]* \
          (ener[myg.ilo-3:myg.ihi+1,myg.jlo-2:myg.jhi+2] - \
           ener[myg.ilo-2:myg.ihi+2,myg.jlo-2:myg.jhi+2])


    # F_y = F_y + avisco_y * (U(i,j-1) - U(i,j))
    F_y[myg.ilo-2:myg.ihi+2,myg.jlo-2:myg.jhi+2,vars.idens] += \
        avisco_y[myg.ilo-2:myg.ihi+2,myg.jlo-2:myg.jhi+2]* \
          (dens[myg.ilo-2:myg.ihi+2,myg.jlo-3:myg.jhi+1] - \
           dens[myg.ilo-2:myg.ihi+2,myg.jlo-2:myg.jhi+2])

    F_y[myg.ilo-2:myg.ihi+2,myg.jlo-2:myg.jhi+2,vars.ixmom] += \
        avisco_y[myg.ilo-2:myg.ihi+2,myg.jlo-2:myg.jhi+2]* \
          (xmom[myg.ilo-2:myg.ihi+2,myg.jlo-3:myg.jhi+1] - \
           xmom[myg.ilo-2:myg.ihi+2,myg.jlo-2:myg.jhi+2])

    F_y[myg.ilo-2:myg.ihi+2,myg.jlo-2:myg.jhi+2,vars.iymom] += \
        avisco_y[myg.ilo-2:myg.ihi+2,myg.jlo-2:myg.jhi+2]* \
          (ymom[myg.ilo-2:myg.ihi+2,myg.jlo-3:myg.jhi+1] - \
           ymom[myg.ilo-2:myg.ihi+2,myg.jlo-2:myg.jhi+2])

    F_y[myg.ilo-2:myg.ihi+2,myg.jlo-2:myg.jhi+2,vars.iener] += \
        avisco_y[myg.ilo-2:myg.ihi+2,myg.jlo-2:myg.jhi+2]* \
          (ener[myg.ilo-2:myg.ihi+2,myg.jlo-3:myg.jhi+1] - \
           ener[myg.ilo-2:myg.ihi+2,myg.jlo-2:myg.jhi+2])

    

    pf.end()

    return F_x, F_y
コード例 #2
0
def unsplitFluxes(myData, dt):
    """
    unsplitFluxes returns the fluxes through the x and y interfaces by
    doing an unsplit reconstruction of the interface values and then
    solving the Riemann problem through all the interfaces at once
                                                                               
    currently we assume a gamma-law EOS 

    grav is the gravitational acceleration in the y-direction            
    """

    pf = profile.timer("unsplitFluxes")
    pf.begin()
    
    myg = myData.grid


    #=========================================================================
    # compute the primitive variables
    #=========================================================================
    # Q = (rho, u, v, p)

    dens = myData.getVarPtr("density")
    xmom = myData.getVarPtr("x-momentum")
    ymom = myData.getVarPtr("y-momentum")
    ener = myData.getVarPtr("energy")

    r = dens

    # get the velocities
    u = xmom/dens
    v = ymom/dens

    # get the pressure
    e = (ener - 0.5*(xmom**2 + ymom**2)/dens)/dens

    p = eos.pres(dens, e)

    smallp = 1.e-10
    p = p.clip(smallp)   # apply a floor to the pressure
    

    #=========================================================================
    # compute the flattening coefficients
    #=========================================================================

    # there is a single flattening coefficient (xi) for all directions
    use_flattening = runparams.getParam("compressible.use_flattening")

    if (use_flattening):
        smallp = 1.e-10

        delta = runparams.getParam("compressible.delta")
        z0 = runparams.getParam("compressible.z0")
        z1 = runparams.getParam("compressible.z1")

        xi_x = reconstruction_f.flatten(1, p, u, myg.qx, myg.qy, myg.ng, smallp, delta, z0, z1)
        xi_y = reconstruction_f.flatten(2, p, v, myg.qx, myg.qy, myg.ng, smallp, delta, z0, z1)

        xi = reconstruction_f.flatten_multid(xi_x, xi_y, p, myg.qx, myg.qy, myg.ng)
    else:
        xi = 1.0


    #=========================================================================
    # x-direction
    #=========================================================================

    # monotonized central differences in x-direction
    pfa = profile.timer("limiting")
    pfa.begin()

    limiter = runparams.getParam("compressible.limiter")
    if (limiter == 0):
        limitFunc = reconstruction_f.nolimit
    elif (limiter == 1):
        limitFunc = reconstruction_f.limit2
    else:
        limitFunc = reconstruction_f.limit4
    
    ldelta_r = xi*limitFunc(1, r, myg.qx, myg.qy, myg.ng)
    ldelta_u = xi*limitFunc(1, u, myg.qx, myg.qy, myg.ng)
    ldelta_v = xi*limitFunc(1, v, myg.qx, myg.qy, myg.ng)
    ldelta_p = xi*limitFunc(1, p, myg.qx, myg.qy, myg.ng)
    
    pfa.end()
    
    # left and right primitive variable states
    pfb = profile.timer("interfaceStates")
    pfb.begin()

    gamma = runparams.getParam("eos.gamma")

    V_l = numpy.zeros((myg.qx, myg.qy, vars.nvar),  dtype=numpy.float64)
    V_r = numpy.zeros((myg.qx, myg.qy, vars.nvar),  dtype=numpy.float64)

    (V_l, V_r) = interface_f.states(1, myg.qx, myg.qy, myg.ng, myg.dx, dt,
                                    vars.nvar,
                                    gamma,
                                    r, u, v, p,
                                    ldelta_r, ldelta_u, ldelta_v, ldelta_p) 
    
    pfb.end()
                    

    # transform interface states back into conserved variables
    U_xl = numpy.zeros((myg.qx, myg.qy, myData.nvar),  dtype=numpy.float64)
    U_xr = numpy.zeros((myg.qx, myg.qy, myData.nvar),  dtype=numpy.float64)

    U_xl[:,:,vars.idens] = V_l[:,:,vars.irho]
    U_xl[:,:,vars.ixmom] = V_l[:,:,vars.irho]*V_l[:,:,vars.iu]
    U_xl[:,:,vars.iymom] = V_l[:,:,vars.irho]*V_l[:,:,vars.iv]
    U_xl[:,:,vars.iener] = eos.rhoe(V_l[:,:,vars.ip]) + \
        0.5*V_l[:,:,vars.irho]*(V_l[:,:,vars.iu]**2 + V_l[:,:,vars.iv]**2)

    U_xr[:,:,vars.idens] = V_r[:,:,vars.irho]
    U_xr[:,:,vars.ixmom] = V_r[:,:,vars.irho]*V_r[:,:,vars.iu]
    U_xr[:,:,vars.iymom] = V_r[:,:,vars.irho]*V_r[:,:,vars.iv]
    U_xr[:,:,vars.iener] = eos.rhoe(V_r[:,:,vars.ip]) + \
        0.5*V_r[:,:,vars.irho]*(V_r[:,:,vars.iu]**2 + V_r[:,:,vars.iv]**2)



    #=========================================================================
    # y-direction
    #=========================================================================

    # monotonized central differences in y-direction
    pfa.begin()

    ldelta_r = xi*limitFunc(2, r, myg.qx, myg.qy, myg.ng)
    ldelta_u = xi*limitFunc(2, u, myg.qx, myg.qy, myg.ng)
    ldelta_v = xi*limitFunc(2, v, myg.qx, myg.qy, myg.ng)
    ldelta_p = xi*limitFunc(2, p, myg.qx, myg.qy, myg.ng)

    pfa.end()
    
    # left and right primitive variable states
    pfb.begin()

    (V_l, V_r) = interface_f.states(2, myg.qx, myg.qy, myg.ng, myg.dy, dt,
                                    vars.nvar,
                                    gamma,
                                    r, u, v, p,
                                    ldelta_r, ldelta_u, ldelta_v, ldelta_p)                                    

    pfb.end()


    # transform interface states back into conserved variables
    U_yl = numpy.zeros((myg.qx, myg.qy, myData.nvar),  dtype=numpy.float64)
    U_yr = numpy.zeros((myg.qx, myg.qy, myData.nvar),  dtype=numpy.float64)

    U_yl[:,:,vars.idens] = V_l[:,:,vars.irho]
    U_yl[:,:,vars.ixmom] = V_l[:,:,vars.irho]*V_l[:,:,vars.iu]
    U_yl[:,:,vars.iymom] = V_l[:,:,vars.irho]*V_l[:,:,vars.iv]
    U_yl[:,:,vars.iener] = eos.rhoe(V_l[:,:,vars.ip]) + \
        0.5*V_l[:,:,vars.irho]*(V_l[:,:,vars.iu]**2 + V_l[:,:,vars.iv]**2)

    U_yr[:,:,vars.idens] = V_r[:,:,vars.irho]
    U_yr[:,:,vars.ixmom] = V_r[:,:,vars.irho]*V_r[:,:,vars.iu]
    U_yr[:,:,vars.iymom] = V_r[:,:,vars.irho]*V_r[:,:,vars.iv]
    U_yr[:,:,vars.iener] = eos.rhoe(V_r[:,:,vars.ip]) + \
        0.5*V_r[:,:,vars.irho]*(V_r[:,:,vars.iu]**2 + V_r[:,:,vars.iv]**2)


    #=========================================================================
    # apply source terms
    #=========================================================================
    grav = runparams.getParam("compressible.grav")

    # ymom_xl[i,j] += 0.5*dt*dens[i-1,j]*grav
    U_xl[myg.ilo-1:myg.ihi+2,myg.jlo-1:myg.jhi+2,vars.iymom] += \
        0.5*dt*dens[myg.ilo-2:myg.ihi+1,myg.jlo-1:myg.jhi+2]*grav

    U_xl[myg.ilo-1:myg.ihi+2,myg.jlo-1:myg.jhi+2,vars.iener] += \
        0.5*dt*ymom[myg.ilo-2:myg.ihi+1,myg.jlo-1:myg.jhi+2]*grav

    # ymom_xr[i,j] += 0.5*dt*dens[i,j]*grav
    U_xr[myg.ilo-1:myg.ihi+2,myg.jlo-1:myg.jhi+2,vars.iymom] += \
        0.5*dt*dens[myg.ilo-1:myg.ihi+2,myg.jlo-1:myg.jhi+2]*grav

    U_xr[myg.ilo-1:myg.ihi+2,myg.jlo-1:myg.jhi+2,vars.iener] += \
        0.5*dt*ymom[myg.ilo-1:myg.ihi+2,myg.jlo-1:myg.jhi+2]*grav

    # ymom_yl[i,j] += 0.5*dt*dens[i,j-1]*grav
    U_yl[myg.ilo-1:myg.ihi+2,myg.jlo-1:myg.jhi+2,vars.iymom] += \
        0.5*dt*dens[myg.ilo-1:myg.ihi+2,myg.jlo-2:myg.jhi+1]*grav

    U_yl[myg.ilo-1:myg.ihi+2,myg.jlo-1:myg.jhi+2,vars.iener] += \
        0.5*dt*ymom[myg.ilo-1:myg.ihi+2,myg.jlo-2:myg.jhi+1]*grav

    # ymom_yr[i,j] += 0.5*dt*dens[i,j]*grav
    U_yr[myg.ilo-1:myg.ihi+2,myg.jlo-1:myg.jhi+2,vars.iymom] += \
        0.5*dt*dens[myg.ilo-1:myg.ihi+2,myg.jlo-1:myg.jhi+2]*grav

    U_yr[myg.ilo-1:myg.ihi+2,myg.jlo-1:myg.jhi+2,vars.iener] += \
        0.5*dt*ymom[myg.ilo-1:myg.ihi+2,myg.jlo-1:myg.jhi+2]*grav


    #=========================================================================
    # compute transverse fluxes
    #=========================================================================
    pfc = profile.timer("riemann")
    pfc.begin()

    riemann = runparams.getParam("compressible.riemann")

    if (riemann == "HLLC"):
        riemannFunc = interface_f.riemann_hllc
    elif (riemann == "CGF"):
        riemannFunc = interface_f.riemann_cgf
    else:
        msg.fail("ERROR: Riemann solver undefined")


    F_x = riemannFunc(1, myg.qx, myg.qy, myg.ng, 
                      vars.nvar, vars.idens, vars.ixmom, vars.iymom, vars.iener, 
                      gamma, U_xl, U_xr)

    F_y = riemannFunc(2, myg.qx, myg.qy, myg.ng, 
                      vars.nvar, vars.idens, vars.ixmom, vars.iymom, vars.iener, 
                      gamma, U_yl, U_yr)

    pfc.end()

    #=========================================================================
    # construct the interface values of U now
    #=========================================================================

    """
    finally, we can construct the state perpendicular to the interface
    by adding the central difference part to the trasverse flux
    difference.

    The states that we represent by indices i,j are shown below
    (1,2,3,4):
            

      j+3/2--+----------+----------+----------+ 
             |          |          |          | 
             |          |          |          | 
        j+1 -+          |          |          | 
             |          |          |          | 
             |          |          |          |    1: U_xl[i,j,:] = U  
      j+1/2--+----------XXXXXXXXXXXX----------+                      i-1/2,j,L
             |          X          X          | 
             |          X          X          |  
          j -+        1 X 2        X          |    2: U_xr[i,j,:] = U 
             |          X          X          |                      i-1/2,j,R
             |          X    4     X          | 
      j-1/2--+----------XXXXXXXXXXXX----------+  
             |          |    3     |          |    3: U_yl[i,j,:] = U 
             |          |          |          |                      i,j-1/2,L
        j-1 -+          |          |          |   
             |          |          |          |  
             |          |          |          |    4: U_yr[i,j,:] = U 
      j-3/2--+----------+----------+----------+                      i,j-1/2,R
             |    |     |    |     |    |     |  
                 i-1         i         i+1      
           i-3/2      i-1/2      i+1/2      i+3/2 


    remember that the fluxes are stored on the left edge, so 

    F_x[i,j,:] = F_x 
                    i-1/2, j   

    F_y[i,j,:] = F_y   
                    i, j-1/2   
                                       
    """

    pfd = profile.timer("transverse flux addition")
    pfd.begin()

    # U_xl[i,j,:] = U_xl[i,j,:] - 0.5*dt/dy * (F_y[i-1,j+1,:] - F_y[i-1,j,:])
    U_xl[myg.ilo-2:myg.ihi+2,myg.jlo-2:myg.jhi+2,:] += \
        - 0.5*dt/myg.dy * (F_y[myg.ilo-3:myg.ihi+1,myg.jlo-1:myg.jhi+3,:] - \
                           F_y[myg.ilo-3:myg.ihi+1,myg.jlo-2:myg.jhi+2,:])    

    # U_xr[i,j,:] = U_xr[i,j,:] - 0.5*dt/dy * (F_y[i,j+1,:] - F_y[i,j,:])
    U_xr[myg.ilo-2:myg.ihi+2,myg.jlo-2:myg.jhi+2,:] += \
        - 0.5*dt/myg.dy * (F_y[myg.ilo-2:myg.ihi+2,myg.jlo-1:myg.jhi+3,:] - \
                           F_y[myg.ilo-2:myg.ihi+2,myg.jlo-2:myg.jhi+2,:])    

    # U_yl[i,j,:] = U_yl[i,j,:] - 0.5*dt/dx * (F_x[i+1,j-1,:] - F_x[i,j-1,:])
    U_yl[myg.ilo-2:myg.ihi+2,myg.jlo-2:myg.jhi+2,:] += \
        - 0.5*dt/myg.dx * (F_x[myg.ilo-1:myg.ihi+3,myg.jlo-3:myg.jhi+1,:] - \
                           F_x[myg.ilo-2:myg.ihi+2,myg.jlo-3:myg.jhi+1,:])
                
    # U_yr[i,j,:] = U_yr[i,j,:] - 0.5*dt/dx * (F_x[i+1,j,:] - F_x[i,j,:])
    U_yr[myg.ilo-2:myg.ihi+2,myg.jlo-2:myg.jhi+2,:] += \
        - 0.5*dt/myg.dx * (F_x[myg.ilo-1:myg.ihi+3,myg.jlo-2:myg.jhi+2,:] - \
                           F_x[myg.ilo-2:myg.ihi+2,myg.jlo-2:myg.jhi+2,:])

    pfd.end()


    #=========================================================================
    # construct the fluxes normal to the interfaces
    #=========================================================================
    
    # up until now, F_x and F_y stored the transverse fluxes, now we
    # overwrite with the fluxes normal to the interfaces

    pfc.begin()
        
    F_x = riemannFunc(1, myg.qx, myg.qy, myg.ng, 
                      vars.nvar, vars.idens, vars.ixmom, vars.iymom, vars.iener, 
                      gamma, U_xl, U_xr)

    F_y = riemannFunc(2, myg.qx, myg.qy, myg.ng, 
                      vars.nvar, vars.idens, vars.ixmom, vars.iymom, vars.iener, 
                      gamma, U_yl, U_yr)

    pfc.end()

    #=========================================================================
    # apply artificial viscosity
    #=========================================================================
    cvisc = runparams.getParam("compressible.cvisc")

    (avisco_x, avisco_y) = interface_f.artificial_viscosity( \
                              myg.qx, myg.qy, myg.ng, myg.dx, myg.dy, \
                              cvisc, u, v)

    # F_x = F_x + avisco_x * (U(i-1,j) - U(i,j))
    F_x[myg.ilo-2:myg.ihi+2,myg.jlo-2:myg.jhi+2,vars.idens] += \
        avisco_x[myg.ilo-2:myg.ihi+2,myg.jlo-2:myg.jhi+2]* \
          (dens[myg.ilo-3:myg.ihi+1,myg.jlo-2:myg.jhi+2] - \
           dens[myg.ilo-2:myg.ihi+2,myg.jlo-2:myg.jhi+2])

    F_x[myg.ilo-2:myg.ihi+2,myg.jlo-2:myg.jhi+2,vars.ixmom] += \
        avisco_x[myg.ilo-2:myg.ihi+2,myg.jlo-2:myg.jhi+2]* \
          (xmom[myg.ilo-3:myg.ihi+1,myg.jlo-2:myg.jhi+2] - \
           xmom[myg.ilo-2:myg.ihi+2,myg.jlo-2:myg.jhi+2])

    F_x[myg.ilo-2:myg.ihi+2,myg.jlo-2:myg.jhi+2,vars.iymom] += \
        avisco_x[myg.ilo-2:myg.ihi+2,myg.jlo-2:myg.jhi+2]* \
          (ymom[myg.ilo-3:myg.ihi+1,myg.jlo-2:myg.jhi+2] - \
           ymom[myg.ilo-2:myg.ihi+2,myg.jlo-2:myg.jhi+2])

    F_x[myg.ilo-2:myg.ihi+2,myg.jlo-2:myg.jhi+2,vars.iener] += \
        avisco_x[myg.ilo-2:myg.ihi+2,myg.jlo-2:myg.jhi+2]* \
          (ener[myg.ilo-3:myg.ihi+1,myg.jlo-2:myg.jhi+2] - \
           ener[myg.ilo-2:myg.ihi+2,myg.jlo-2:myg.jhi+2])


    # F_y = F_y + avisco_y * (U(i,j-1) - U(i,j))
    F_y[myg.ilo-2:myg.ihi+2,myg.jlo-2:myg.jhi+2,vars.idens] += \
        avisco_y[myg.ilo-2:myg.ihi+2,myg.jlo-2:myg.jhi+2]* \
          (dens[myg.ilo-2:myg.ihi+2,myg.jlo-3:myg.jhi+1] - \
           dens[myg.ilo-2:myg.ihi+2,myg.jlo-2:myg.jhi+2])

    F_y[myg.ilo-2:myg.ihi+2,myg.jlo-2:myg.jhi+2,vars.ixmom] += \
        avisco_y[myg.ilo-2:myg.ihi+2,myg.jlo-2:myg.jhi+2]* \
          (xmom[myg.ilo-2:myg.ihi+2,myg.jlo-3:myg.jhi+1] - \
           xmom[myg.ilo-2:myg.ihi+2,myg.jlo-2:myg.jhi+2])

    F_y[myg.ilo-2:myg.ihi+2,myg.jlo-2:myg.jhi+2,vars.iymom] += \
        avisco_y[myg.ilo-2:myg.ihi+2,myg.jlo-2:myg.jhi+2]* \
          (ymom[myg.ilo-2:myg.ihi+2,myg.jlo-3:myg.jhi+1] - \
           ymom[myg.ilo-2:myg.ihi+2,myg.jlo-2:myg.jhi+2])

    F_y[myg.ilo-2:myg.ihi+2,myg.jlo-2:myg.jhi+2,vars.iener] += \
        avisco_y[myg.ilo-2:myg.ihi+2,myg.jlo-2:myg.jhi+2]* \
          (ener[myg.ilo-2:myg.ihi+2,myg.jlo-3:myg.jhi+1] - \
           ener[myg.ilo-2:myg.ihi+2,myg.jlo-2:myg.jhi+2])

    

    pf.end()

    return F_x, F_y
コード例 #3
0
ファイル: BC.py プロジェクト: jzuhone/pyro2
def user(bcName, bcEdge, variable, my_data):

    dens = my_data.get_var("density")
    xmom = my_data.get_var("x-momentum")
    ymom = my_data.get_var("y-momentum")
    ener = my_data.get_var("energy")

    grav = my_data.rp.get_param("compressible.grav")

    myg = my_data.grid

    if (bcName == "hse"):

        if (bcEdge == "ylb"):

            # lower y boundary

            # we will take the density to be constant, the velocity to
            # be outflow, and the pressure to be in HSE
            if variable == "density":
                j = myg.jlo - 1
                while (j >= 0):
                    dens[:, j] = dens[:, myg.jlo]
                    j -= 1

            elif variable == "x-momentum":
                j = myg.jlo - 1
                while (j >= 0):
                    xmom[:, j] = xmom[:, myg.jlo]
                    j -= 1

            elif variable == "y-momentum":
                j = myg.jlo - 1
                while (j >= 0):
                    ymom[:, j] = ymom[:, myg.jlo]
                    j -= 1

            elif variable == "energy":
                dens_base = dens[:, myg.jlo]
                ke_base = 0.5*(xmom[:,myg.jlo]**2 + ymom[:,myg.jlo]**2) / \
                    dens[:,myg.jlo]

                eint_base = (ener[:, myg.jlo] - ke_base) / dens[:, myg.jlo]
                pres_base = eos.pres(dens_base, eint_base)

                # we are assuming that the density is constant in this
                # formulation of HSE, so the pressure comes simply from
                # differencing the HSE equation
                j = myg.jlo - 1
                while (j >= 0):
                    pres_below = pres_base - grav * dens_base * myg.dy
                    rhoe = eos.rhoe(pres_below)

                    ener[:, j] = rhoe + ke_base

                    pres_base = pres_below.copy()

                    j -= 1

            else:
                msg.fail("error: variable not defined")

        elif (bcEdge == "yrb"):

            # upper y boundary

            # we will take the density to be constant, the velocity to
            # be outflow, and the pressure to be in HSE
            if variable == "density":
                j = myg.jhi + 1
                while (j <= myg.jhi + myg.ng):
                    dens[:, j] = dens[:, myg.jhi]
                    j += 1

            elif variable == "x-momentum":
                j = myg.jhi + 1
                while (j <= myg.jhi + myg.ng):
                    xmom[:, j] = xmom[:, myg.jhi]
                    j += 1

            elif variable == "y-momentum":
                j = myg.jhi + 1
                while (j <= myg.jhi + myg.ng):
                    ymom[:, j] = ymom[:, myg.jhi]
                    j += 1

            elif variable == "energy":
                dens_base = dens[:, myg.jhi]
                ke_base = 0.5*(xmom[:,myg.jhi]**2 + ymom[:,myg.jhi]**2) / \
                    dens[:,myg.jhi]

                eint_base = (ener[:, myg.jhi] - ke_base) / dens[:, myg.jhi]
                pres_base = eos.pres(dens_base, eint_base)

                # we are assuming that the density is constant in this
                # formulation of HSE, so the pressure comes simply from
                # differencing the HSE equation
                j = myg.jhi + 1
                while (j <= myg.jhi + myg.ng):
                    pres_above = pres_base + grav * dens_base * myg.dy
                    rhoe = eos.rhoe(pres_above)

                    ener[:, j] = rhoe + ke_base

                    pres_base = pres_above.copy()

                    j += 1

            else:
                msg.fail("error: variable not defined")

        else:
            msg.fail("error: hse BC not supported for xlb or xrb")

    else:
        msg.fail("error: bc type %s not supported" % (bcName))
コード例 #4
0
ファイル: BC.py プロジェクト: jzuhone/pyro2
def user(bcName, bcEdge, variable, my_data):

    dens = my_data.get_var("density")
    xmom = my_data.get_var("x-momentum")
    ymom = my_data.get_var("y-momentum")
    ener = my_data.get_var("energy")

    grav = my_data.rp.get_param("compressible.grav")

    myg = my_data.grid

    if (bcName == "hse"):
        
        if (bcEdge == "ylb"):

            # lower y boundary
            
            # we will take the density to be constant, the velocity to
            # be outflow, and the pressure to be in HSE
            if variable == "density":
                j = myg.jlo-1
                while (j >= 0):
                    dens[:,j] = dens[:,myg.jlo]
                    j -= 1

            elif variable == "x-momentum":
                j = myg.jlo-1
                while (j >= 0):
                    xmom[:,j] = xmom[:,myg.jlo]                
                    j -= 1

            elif variable == "y-momentum":
                j = myg.jlo-1
                while (j >= 0):
                    ymom[:,j] = ymom[:,myg.jlo]                
                    j -= 1

            elif variable == "energy":
                dens_base = dens[:,myg.jlo]
                ke_base = 0.5*(xmom[:,myg.jlo]**2 + ymom[:,myg.jlo]**2) / \
                    dens[:,myg.jlo]

                eint_base = (ener[:,myg.jlo] - ke_base)/dens[:,myg.jlo]
                pres_base = eos.pres(dens_base, eint_base)
                
                # we are assuming that the density is constant in this
                # formulation of HSE, so the pressure comes simply from
                # differencing the HSE equation
                j = myg.jlo-1
                while (j >= 0):
                    pres_below = pres_base - grav*dens_base*myg.dy
                    rhoe = eos.rhoe(pres_below)

                    ener[:,j] = rhoe + ke_base

                    pres_base = pres_below.copy()

                    j -= 1

            else:
                msg.fail("error: variable not defined")


        elif (bcEdge == "yrb"):

            # upper y boundary
            
            # we will take the density to be constant, the velocity to
            # be outflow, and the pressure to be in HSE
            if variable == "density":
                j = myg.jhi+1
                while (j <= myg.jhi+myg.ng):
                    dens[:,j] = dens[:,myg.jhi]
                    j += 1

            elif variable == "x-momentum":
                j = myg.jhi+1
                while (j <= myg.jhi+myg.ng):
                    xmom[:,j] = xmom[:,myg.jhi]                
                    j += 1

            elif variable == "y-momentum":
                j = myg.jhi+1
                while (j <= myg.jhi+myg.ng):
                    ymom[:,j] = ymom[:,myg.jhi]                
                    j += 1

            elif variable == "energy":
                dens_base = dens[:,myg.jhi]
                ke_base = 0.5*(xmom[:,myg.jhi]**2 + ymom[:,myg.jhi]**2) / \
                    dens[:,myg.jhi]

                eint_base = (ener[:,myg.jhi] - ke_base)/dens[:,myg.jhi]
                pres_base = eos.pres(dens_base, eint_base)
                
                # we are assuming that the density is constant in this
                # formulation of HSE, so the pressure comes simply from
                # differencing the HSE equation
                j = myg.jhi+1
                while (j <= myg.jhi+myg.ng):
                    pres_above = pres_base + grav*dens_base*myg.dy
                    rhoe = eos.rhoe(pres_above)

                    ener[:,j] = rhoe + ke_base

                    pres_base = pres_above.copy()

                    j += 1

            else:
                msg.fail("error: variable not defined")


        else:
            msg.fail("error: hse BC not supported for xlb or xrb")


    else:
        msg.fail("error: bc type %s not supported" % (bcName) )