コード例 #1
0
ファイル: rhs_terms.py プロジェクト: pencil-code/pencil-code
 def visc_heat(src, dst, key, par, gd, l1, l2, m1, m2, n1, n2, nghost):
     if key == "hvisc":
         th1 = 1./3
         n1shift,n2shift,m1shift,m2shift,l1shift,l2shift=der_limits(
                                                  n1,n2,m1,m2,l1,l2,nghost)
         uu = np.array([
                       src["data/ux"][n1shift:n2shift,m1shift:m2shift,l1shift:l2shift],
                       src["data/uy"][n1shift:n2shift,m1shift:m2shift,l1shift:l2shift],
                       src["data/uz"][n1shift:n2shift,m1shift:m2shift,l1shift:l2shift]
                       ])
         tmp0 = grad(uu[0],grid.dx,grid.dy,grid.dz,x=grid.x[l1shift:l2shift],y=grid.y[m1shift:m2shift],coordinate_system=param.coord_system)
         tmp1 = grad(uu[1],grid.dx,grid.dy,grid.dz,x=grid.x[l1shift:l2shift],y=grid.y[m1shift:m2shift],coordinate_system=param.coord_system)
         tmp2 = grad(uu[2],grid.dx,grid.dy,grid.dz,x=grid.x[l1shift:l2shift],y=grid.y[m1shift:m2shift],coordinate_system=param.coord_system)
         var  = tmp0[1]**2
         var += tmp0[2]**2
         var += tmp1[2]**2
         if "tt" in dst["data"].keys():
             tt = dst["tt"][n1shift:n2shift,m1shift:m2shift,l1shift:l2shift]
         else:
             calc_derived_data(src["data"], dst["data"], "tt", par,
                                 gd, l1, l2, m1, m2, n1, n2, nghost)
             tt = dst["data/tt"][n1shift:n2shift,m1shift:m2shift,l1shift:l2shift]
         var *= 2*par.nu*var/tt
         n1r,m1r,l1r = under_limits(n1,m1,l1,n1shift,m1shift,l1shift,nghost)
         return var[n1r:n2-n1+n1r,m1r:m2-m1+m1r,l1r:l2-l1+l1r]
コード例 #2
0
ファイル: rhs_terms.py プロジェクト: pencil-code/pencil-code
 def heatcond(src, dst, key, par, gd, l1, l2, m1, m2, n1, n2, nghost):
     if key == "hcond":
         n1shift,n2shift,m1shift,m2shift,l1shift,l2shift=der_limits(
                                                  n1,n2,m1,m2,l1,l2,nghost)
         if "tt" in dst["data"].keys():
             tt = dst["data/tt"][n1shift,n2shift,m1shift,m2shift,l1shift,l2shift]
         else:
             calc_derived_data(src["data"], dst["data"], "tt", par,
                                 gd, l1, l2, m1, m2, n1, n2, nghost)
             tt = dst["data/tt"][n1shift,n2shift,m1shift,m2shift,l1shift,l2shift]
             lntt = np.log(dst["data/tt"][n1shift,n2shift,m1shift,m2shift,l1shift,l2shift])
             gradlnT = grad(lntt,grid.dx,grid.dy,grid.dz,x=grid.x[l1shift:l2shift],y=grid.y[m1shift:m2shift],coordinate_system=param.coord_system)
             del2T = del2(tt,grid.dx,grid.dy,grid.dz,x=grid.x[l1shift:l2shift],y=grid.y[m1shift:m2shift],coordinate_system=param.coord_system)
         if "rho" in src["data"].keys():
             lnrho = np.log(src["rho"][n1shift,n2shift,m1shift,m2shift,l1shift,l2shift])
             gradlnrho = grad(lnrho,grid.dx,grid.dy,grid.dz,x=grid.x[l1shift:l2shift],y=grid.y[m1shift:m2shift],coordinate_system=param.coord_system)
             lrho = True
         elif "lnrho" in src["data"].keys():
             lnrho = src["lnrho"][n1shift,n2shift,m1shift,m2shift,l1shift,l2shift]
             gradlnrho = grad(lnrho,grid.dx,grid.dy,grid.dz,x=grid.x[l1shift:l2shift],y=grid.y[m1shift:m2shift],coordinate_system=param.coord_system)
             lrho = True
         else:
             lrho = False
         var = par.cp*par.chi*del2T/tt
         if lrho:
             var += par.cp*par.chi*dot(gradlnrho,gradlnT)
         n1r,m1r,l1r = under_limits(n1,m1,l1,n1shift,m1shift,l1shift,nghost)
         return var[n1r:n2-n1+n1r,m1r:m2-m1+m1r,l1r:l2-l1+l1r]
コード例 #3
0
ファイル: rhs_terms.py プロジェクト: pencil-code/pencil-code
 def rostrain(src, dst, key, par, gd, l1, l2, m1, m2, n1, n2, nghost):
     if key == "fvisc":
         n1shift,n2shift,m1shift,m2shift,l1shift,l2shift=der_limits(
                                                  n1,n2,m1,m2,l1,l2,nghost)
         if par.nu > 0:
             uu = np.array([
                           src["data/ux"][n1shift:n2shift,m1shift:m2shift,l1shift:l2shift],
                           src["data/uy"][n1shift:n2shift,m1shift:m2shift,l1shift:l2shift],
                           src["data/uz"][n1shift:n2shift,m1shift:m2shift,l1shift:l2shift]
                           ])
             #viscous forces
             th2 = 2./3
             th1 = 1./3
             fvisc = np.zeros_like(uu)
             del2u = np.zeros_like(uu)
             for j in range(0,3):
                 del2u[j] = del2(uu[j],gd.dx,gd.dy,gd.dz,x=gd.x[l1shift:l2shift],y=gd.y[m1shift:m2shift],coordinate_system=par.coord_system)
             fvisc += param.nu*del2u
             del(del2u)
             divu = div(uu,grid.dx,grid.dy,grid.dz,x=grid.x[l1shift:l2shift],y=grid.y[m1shift:m2shift],coordinate_system=param.coord_system)
             graddivu = grad(divu,grid.dx,grid.dy,grid.dz,x=grid.x[l1shift:l2shift],y=grid.y[m1shift:m2shift],coordinate_system=param.coord_system)
             fvisc += th1*par.nu*graddivu
             del(graddivu)
             if "rho" in src["data"].keys():
                 lnrho = np.log(src["data/rho"][n1shift:n2shift,m1shift:m2shift,l1shift:l2shift])
                 lrho = True
             elif "lnrho" in src["data"].keys():
                 lnrho = src["data/lnrho"][n1shift:n2shift,m1shift:m2shift,l1shift:l2shift]
                 lrho = True
             else:
                 lrho = False
             if lrho:
                 tmp0 = grad(uu[0],grid.dx,grid.dy,grid.dz,x=grid.x[l1shift:l2shift],y=grid.y[m1shift:m2shift],coordinate_system=param.coord_system)
                 tmp1 = grad(uu[1],grid.dx,grid.dy,grid.dz,x=grid.x[l1shift:l2shift],y=grid.y[m1shift:m2shift],coordinate_system=param.coord_system)
                 tmp2 = grad(uu[2],grid.dx,grid.dy,grid.dz,x=grid.x[l1shift:l2shift],y=grid.y[m1shift:m2shift],coordinate_system=param.coord_system)
                 gradlnrho = grad(lnrho,grid.dx,grid.dy,grid.dz,x=grid.x[l1shift:l2shift],y=grid.y[m1shift:m2shift],coordinate_system=param.coord_system)
                 Sglnrho = np.zeros_like(uu)
                 Sglnrho[0] = dot(tmp0,gradlnrho) +\
                                 (tmp0[0]+tmp1[0]+tmp2[0]-th2*divu)*gradlnrho[0]
                 Sglnrho[1] = dot(tmp1,gradlnrho) +\
                                 (tmp0[1]+tmp1[1]+tmp2[1]-th2*divu)*gradlnrho[1]
                 Sglnrho[2] = dot(tmp2,gradlnrho) +\
                                 (tmp0[2]+tmp1[2]+tmp2[2]-th2*divu)*gradlnrho[2]
                 fvisc += par.nu*Sglnrho
                 del(gradlnrho,Sglnrho)
             del(divu)
         n1r,m1r,l1r = under_limits(n1,m1,l1,n1shift,m1shift,l1shift,nghost)
         return fvisc[:,n1r:n2-n1+n1r,m1r:m2-m1+m1r,l1r:l2-l1+l1r]
コード例 #4
0
ファイル: rhs_terms.py プロジェクト: pencil-code/pencil-code
 def advec_heat(src, dst, key, par, gd, l1, l2, m1, m2, n1, n2, nghost):
     if key == "hadvec":
         n1shift,n2shift,m1shift,m2shift,l1shift,l2shift=der_limits(
                                                  n1,n2,m1,m2,l1,l2,nghost)
         uu = np.array([
                           src["data/ux"][n1shift:n2shift,m1shift:m2shift,l1shift:l2shift],
                           src["data/uy"][n1shift:n2shift,m1shift:m2shift,l1shift:l2shift],
                           src["data/uz"][n1shift:n2shift,m1shift:m2shift,l1shift:l2shift]
                           ])
         if "ss" in dst["data"].keys():
             ss = src["ss"][n1shift:n2shift,m1shift:m2shift,l1shift:l2shift]
         sgrad = grad(ss,grid.dx,grid.dy,grid.dz,x=grid.x[l1shift:l2shift],y=grid.y[m1shift:m2shift],coordinate_system=param.coord_system)
         if "tt" in dst["data"].keys():
             tt = dst["tt"][n1shift:n2shift,m1shift:m2shift,l1shift:l2shift]
         else:
             calc_derived_data(src["data"], dst["data"], "tt", par,
                                 gd, l1, l2, m1, m2, n1, n2, nghost)
             tt = dst["data/tt"][n1shift:n2shift,m1shift:m2shift,l1shift:l2shift]
         if "rho" in dst["data"].keys():
             rho = src["data/rho"][n1shift:n2shift,m1shift:m2shift,l1shift:l2shift]
         elif "lnrho" in dst["data"].keys():
             rho = np.exp(src["data/lnrho"][n1shift:n2shift,m1shift:m2shift,l1shift:l2shift])
         else:
             rho=1
         advec = -dot(uu,sgrad)/(rho*tt)
         n1r,m1r,l1r = under_limits(n1,m1,l1,n1shift,m1shift,l1shift,nghost)
         return advec[n1r:n2-n1+n1r,m1r:m2-m1+m1r,l1r:l2-l1+l1r]
コード例 #5
0
ファイル: rhs_terms.py プロジェクト: pencil-code/pencil-code
 def advec_force(src, dst, key, par, gd, l1, l2, m1, m2, n1, n2, nghost):
     if key == "uadvec":
         n1shift,n2shift,m1shift,m2shift,l1shift,l2shift=der_limits(
                                                  n1,n2,m1,m2,l1,l2,nghost)
         uu = np.array([
                           src["data/ux"][n1shift:n2shift,m1shift:m2shift,l1shift:l2shift],
                           src["data/uy"][n1shift:n2shift,m1shift:m2shift,l1shift:l2shift],
                           src["data/uz"][n1shift:n2shift,m1shift:m2shift,l1shift:l2shift]
                           ])
         tmp0 = grad(uu[0],grid.dx,grid.dy,grid.dz,x=grid.x[l1shift:l2shift],y=grid.y[m1shift:m2shift],coordinate_system=param.coord_system)
         tmp1 = grad(uu[1],grid.dx,grid.dy,grid.dz,x=grid.x[l1shift:l2shift],y=grid.y[m1shift:m2shift],coordinate_system=param.coord_system)
         tmp2 = grad(uu[2],grid.dx,grid.dy,grid.dz,x=grid.x[l1shift:l2shift],y=grid.y[m1shift:m2shift],coordinate_system=param.coord_system)
         advec = np.zeros_like(uu)
         advec[0] = -dot(uu,tmp0)
         advec[1] = -dot(uu,tmp1)
         advec[2] = -dot(uu,tmp2)
         del(tmp0,tmp1,tmp2)
         n1r,m1r,l1r = under_limits(n1,m1,l1,n1shift,m1shift,l1shift,nghost)
         return advec[:,n1r:n2-n1+n1r,m1r:m2-m1+m1r,l1r:l2-l1+l1r]
コード例 #6
0
ファイル: rhs_terms.py プロジェクト: pencil-code/pencil-code
 def gradp(src, dst, key, par, gd, l1, l2, m1, m2, n1, n2, nghost):
     if key == "gradp":
         n1shift,n2shift,m1shift,m2shift,l1shift,l2shift=der_limits(
                                                  n1,n2,m1,m2,l1,l2,nghost)
         if "pp" in dst["data"].keys():
             pp = dst["data/pp"][n1shift:n2shift,m1shift:m2shift,l1shift:l2shift]
         else:
             calc_derived_data(src["data"], dst["data"], "pp", par,
                                 gd, l1, l2, m1, m2, n1, n2, nghost)
             pp = dst["data/pp"][n1shift:n2shift,m1shift:m2shift,l1shift:l2shift]
         var = -grad(pp, gd.dx, gd.dy, gd.dz,x=gd.x[l1shift:l2shift],y=gd.y[m1shift:m2shift],coordinate_system=par.coord_system)
         if "rho" in src["data"].keys():
             rho = dst["data/rho"][n1shift:n2shift,m1shift:m2shift,l1shift:l2shift]
         elif "lnrho" in src["data"].keys():
             rho = np.exp(dst["data/lnrho"][n1shift:n2shift,m1shift:m2shift,l1shift:l2shift])
         else:
             rho = 1.
         var /= rho
         n1r,m1r,l1r = under_limits(n1,m1,l1,n1shift,m1shift,l1shift,nghost)
         return var[:,n1r:n2-n1+n1r,m1r:m2-m1+m1r,l1r:l2-l1+l1r]
コード例 #7
0
def fluid_reynolds(uu,
                   param,
                   grid,
                   lnrho=list(),
                   shock=list(),
                   nghost=3,
                   lmix=True,
                   quiet=True):
    """
    Computes the fluid Reynolds number from the advective and effective
    viscous expressions in the momentum equation.

    call signature:

    fluid_reynolds(uu, ivisc, grid, rho=None, shock=None, nghost=3)

    Keyword arguments:

     *uu*:
       The velocity field [3,mz,my,mx] from the simulation data

     *param*:
       The Param simulation object with viscosity data information

     *grid*:
       The Grid simulation object

     *lnrho*:
       The log density field if it is non-uniform

     *shock*:
       The shock variable if shock viscosity is applied

     *nghost*:
       The number of ghost zones appropriate to the order of accuracy

     *lmix*:
       Option not to include hyper values when Laplacian values present
    """
    #viscous forces
    th2 = 2. / 3
    th1 = 1. / 3
    fvisc = np.zeros_like(uu)
    #molecular viscosity contribution
    ldel2, lshock, lhyper3 = False, False, False
    for ivisc in param.ivisc:
        if not 'shock' in ivisc and not 'hyper' in ivisc\
                                and not '\n' in ivisc:
            ldel2 = True
        if 'shock' in ivisc:
            lshock = True
        if 'hyper3' in ivisc:
            lhyper3 = True

    if ldel2:
        if lhyper3:
            lhyper3 = lhyper3 == lmix
        del2u = np.zeros_like(uu)
        for j in range(0, 3):
            del2u[j] = del2(uu[j],
                            grid.dx,
                            grid.dy,
                            grid.dz,
                            x=grid.x,
                            y=grid.y,
                            coordinate_system=param.coord_system)
            del2u[j, :nghost, nghost:-nghost,
                  nghost:-nghost] = del2u[j, -2 * nghost:-nghost,
                                          nghost:-nghost, nghost:-nghost]
            del2u[j, -nghost:, nghost:-nghost,
                  nghost:-nghost] = del2u[j, nghost:2 * nghost, nghost:-nghost,
                                          nghost:-nghost]
            del2u[j, nghost:-nghost, :nghost,
                  nghost:-nghost] = del2u[j, nghost:-nghost,
                                          -2 * nghost:-nghost, nghost:-nghost]
            del2u[j, nghost:-nghost, -nghost:,
                  nghost:-nghost] = del2u[j, nghost:-nghost, nghost:2 * nghost,
                                          nghost:-nghost]
            del2u[j, nghost:-nghost,
                  nghost:-nghost, :nghost] = del2u[j, nghost:-nghost,
                                                   nghost:-nghost,
                                                   -2 * nghost:-nghost]
            del2u[j, nghost:-nghost, nghost:-nghost,
                  -nghost:] = del2u[j, nghost:-nghost, nghost:-nghost,
                                    nghost:2 * nghost]
        for ivisc in param.ivisc:
            ivisc = str.strip(ivisc, '\n')
            if 'nu-const' not in ivisc and 'shock' not in ivisc\
                                   and 'hyper' not in ivisc and len(ivisc) > 0:
                print(
                    'fluid_reynolds WARNING: ' + ivisc + ' not implemented\n' +
                    'terms may be missing from the standard rate of strain tensor'
                )
        fvisc = fvisc + param.nu * del2u
        del (del2u)
    tmp0 = grad(uu[0],
                grid.dx,
                grid.dy,
                grid.dz,
                x=grid.x,
                y=grid.y,
                coordinate_system=param.coord_system)
    for j in range(0, 3):
        tmp0[j, :nghost, nghost:-nghost,
             nghost:-nghost] = tmp0[j, -2 * nghost:-nghost, nghost:-nghost,
                                    nghost:-nghost]
        tmp0[j, -nghost:, nghost:-nghost,
             nghost:-nghost] = tmp0[j, nghost:2 * nghost, nghost:-nghost,
                                    nghost:-nghost]
        tmp0[j, nghost:-nghost, :nghost,
             nghost:-nghost] = tmp0[j, nghost:-nghost, -2 * nghost:-nghost,
                                    nghost:-nghost]
        tmp0[j, nghost:-nghost, -nghost:,
             nghost:-nghost] = tmp0[j, nghost:-nghost, nghost:2 * nghost,
                                    nghost:-nghost]
        tmp0[j, nghost:-nghost,
             nghost:-nghost, :nghost] = tmp0[j, nghost:-nghost, nghost:-nghost,
                                             -2 * nghost:-nghost]
        tmp0[j, nghost:-nghost, nghost:-nghost,
             -nghost:] = tmp0[j, nghost:-nghost, nghost:-nghost,
                              nghost:2 * nghost]
    tmp1 = grad(uu[1],
                grid.dx,
                grid.dy,
                grid.dz,
                x=grid.x,
                y=grid.y,
                coordinate_system=param.coord_system)
    for j in range(0, 3):
        tmp1[j, :nghost, nghost:-nghost,
             nghost:-nghost] = tmp1[j, -2 * nghost:-nghost, nghost:-nghost,
                                    nghost:-nghost]
        tmp1[j, -nghost:, nghost:-nghost,
             nghost:-nghost] = tmp1[j, nghost:2 * nghost, nghost:-nghost,
                                    nghost:-nghost]
        tmp1[j, nghost:-nghost, :nghost,
             nghost:-nghost] = tmp1[j, nghost:-nghost, -2 * nghost:-nghost,
                                    nghost:-nghost]
        tmp1[j, nghost:-nghost, -nghost:,
             nghost:-nghost] = tmp1[j, nghost:-nghost, nghost:2 * nghost,
                                    nghost:-nghost]
        tmp1[j, nghost:-nghost,
             nghost:-nghost, :nghost] = tmp1[j, nghost:-nghost, nghost:-nghost,
                                             -2 * nghost:-nghost]
        tmp1[j, nghost:-nghost, nghost:-nghost,
             -nghost:] = tmp1[j, nghost:-nghost, nghost:-nghost,
                              nghost:2 * nghost]
    tmp2 = grad(uu[2],
                grid.dx,
                grid.dy,
                grid.dz,
                x=grid.x,
                y=grid.y,
                coordinate_system=param.coord_system)
    for j in range(0, 3):
        tmp2[j, :nghost, nghost:-nghost,
             nghost:-nghost] = tmp2[j, -2 * nghost:-nghost, nghost:-nghost,
                                    nghost:-nghost]
        tmp2[j, -nghost:, nghost:-nghost,
             nghost:-nghost] = tmp2[j, nghost:2 * nghost, nghost:-nghost,
                                    nghost:-nghost]
        tmp2[j, nghost:-nghost, :nghost,
             nghost:-nghost] = tmp2[j, nghost:-nghost, -2 * nghost:-nghost,
                                    nghost:-nghost]
        tmp2[j, nghost:-nghost, -nghost:,
             nghost:-nghost] = tmp2[j, nghost:-nghost, nghost:2 * nghost,
                                    nghost:-nghost]
        tmp2[j, nghost:-nghost,
             nghost:-nghost, :nghost] = tmp2[j, nghost:-nghost, nghost:-nghost,
                                             -2 * nghost:-nghost]
        tmp2[j, nghost:-nghost, nghost:-nghost,
             -nghost:] = tmp2[j, nghost:-nghost, nghost:-nghost,
                              nghost:2 * nghost]
    #effect of compressibility
    if len(lnrho) > 0:
        divu = div(uu,
                   grid.dx,
                   grid.dy,
                   grid.dz,
                   x=grid.x,
                   y=grid.y,
                   coordinate_system=param.coord_system)
        divu[:nghost, nghost:-nghost,
             nghost:-nghost] = divu[-2 * nghost:-nghost, nghost:-nghost,
                                    nghost:-nghost]
        divu[-nghost:, nghost:-nghost,
             nghost:-nghost] = divu[nghost:2 * nghost, nghost:-nghost,
                                    nghost:-nghost]
        divu[nghost:-nghost, :nghost,
             nghost:-nghost] = divu[nghost:-nghost, -2 * nghost:-nghost,
                                    nghost:-nghost]
        divu[nghost:-nghost, -nghost:,
             nghost:-nghost] = divu[nghost:-nghost, nghost:2 * nghost,
                                    nghost:-nghost]
        divu[nghost:-nghost,
             nghost:-nghost, :nghost] = divu[nghost:-nghost, nghost:-nghost,
                                             -2 * nghost:-nghost]
        divu[nghost:-nghost, nghost:-nghost,
             -nghost:] = divu[nghost:-nghost, nghost:-nghost,
                              nghost:2 * nghost]
        gradlnrho = grad(lnrho,
                         grid.dx,
                         grid.dy,
                         grid.dz,
                         x=grid.x,
                         y=grid.y,
                         coordinate_system=param.coord_system)
        for j in range(0, 3):
            gradlnrho[j, :nghost, nghost:-nghost,
                      nghost:-nghost] = gradlnrho[j, -2 * nghost:-nghost,
                                                  nghost:-nghost,
                                                  nghost:-nghost]
            gradlnrho[j, -nghost:, nghost:-nghost,
                      nghost:-nghost] = gradlnrho[j, nghost:2 * nghost,
                                                  nghost:-nghost,
                                                  nghost:-nghost]
            gradlnrho[j, nghost:-nghost, :nghost,
                      nghost:-nghost] = gradlnrho[j, nghost:-nghost,
                                                  -2 * nghost:-nghost,
                                                  nghost:-nghost]
            gradlnrho[j, nghost:-nghost, -nghost:,
                      nghost:-nghost] = gradlnrho[j, nghost:-nghost,
                                                  nghost:2 * nghost,
                                                  nghost:-nghost]
            gradlnrho[j, nghost:-nghost,
                      nghost:-nghost, :nghost] = gradlnrho[j, nghost:-nghost,
                                                           nghost:-nghost,
                                                           -2 * nghost:-nghost]
            gradlnrho[j, nghost:-nghost, nghost:-nghost,
                      -nghost:] = gradlnrho[j, nghost:-nghost, nghost:-nghost,
                                            nghost:2 * nghost]
        Sglnrho = np.zeros_like(uu)
        Sglnrho[0] = dot(tmp0,gradlnrho) +\
                        (tmp0[0]+tmp1[0]+tmp2[0]-th2*divu)*gradlnrho[0]
        Sglnrho[1] = dot(tmp1,gradlnrho) +\
                        (tmp0[1]+tmp1[1]+tmp2[1]-th2*divu)*gradlnrho[1]
        Sglnrho[2] = dot(tmp2,gradlnrho) +\
                        (tmp0[2]+tmp1[2]+tmp2[2]-th2*divu)*gradlnrho[2]
        graddivu = grad(divu,
                        grid.dx,
                        grid.dy,
                        grid.dz,
                        x=grid.x,
                        y=grid.y,
                        coordinate_system=param.coord_system)
        for j in range(0, 3):
            graddivu[j, :nghost, nghost:-nghost,
                     nghost:-nghost] = graddivu[j, -2 * nghost:-nghost,
                                                nghost:-nghost, nghost:-nghost]
            graddivu[j, -nghost:, nghost:-nghost,
                     nghost:-nghost] = graddivu[j, nghost:2 * nghost,
                                                nghost:-nghost, nghost:-nghost]
            graddivu[j, nghost:-nghost, :nghost,
                     nghost:-nghost] = graddivu[j, nghost:-nghost,
                                                -2 * nghost:-nghost,
                                                nghost:-nghost]
            graddivu[j, nghost:-nghost, -nghost:,
                     nghost:-nghost] = graddivu[j, nghost:-nghost,
                                                nghost:2 * nghost,
                                                nghost:-nghost]
            graddivu[j, nghost:-nghost,
                     nghost:-nghost, :nghost] = graddivu[j, nghost:-nghost,
                                                         nghost:-nghost,
                                                         -2 * nghost:-nghost]
            graddivu[j, nghost:-nghost, nghost:-nghost,
                     -nghost:] = graddivu[j, nghost:-nghost, nghost:-nghost,
                                          nghost:2 * nghost]
        fvisc = fvisc + param.nu * (th1 * graddivu + Sglnrho)
        del (Sglnrho)
    elif param.ldensity:
        print('fluid_reynolds WARNING: no lnrho provided\n' +
              'rate of strain tensor likely incomplete')
    #shock contribution
    if lshock:
        if len(shock) == 0:
            print('fluid_reynolds WARNING: no shock provided\n' +
                  'rate of strain tensor likely incomplete')
        else:
            shock[:nghost, nghost:-nghost,
                  nghost:-nghost] = shock[-2 * nghost:-nghost, nghost:-nghost,
                                          nghost:-nghost]
            shock[-nghost:, nghost:-nghost,
                  nghost:-nghost] = shock[nghost:2 * nghost, nghost:-nghost,
                                          nghost:-nghost]
            shock[nghost:-nghost, :nghost,
                  nghost:-nghost] = shock[nghost:-nghost, -2 * nghost:-nghost,
                                          nghost:-nghost]
            shock[nghost:-nghost, -nghost:,
                  nghost:-nghost] = shock[nghost:-nghost, nghost:2 * nghost,
                                          nghost:-nghost]
            shock[nghost:-nghost,
                  nghost:-nghost, :nghost] = shock[nghost:-nghost,
                                                   nghost:-nghost,
                                                   -2 * nghost:-nghost]
            shock[nghost:-nghost, nghost:-nghost,
                  -nghost:] = shock[nghost:-nghost, nghost:-nghost,
                                    nghost:2 * nghost]
            divugradlnrho = np.zeros_like(uu)
            gradshock = grad(shock,
                             grid.dx,
                             grid.dy,
                             grid.dz,
                             x=grid.x,
                             y=grid.y,
                             coordinate_system=param.coord_system)
            for j in range(0, 3):
                gradshock[j, :nghost, nghost:-nghost,
                          nghost:-nghost] = gradshock[j, -2 * nghost:-nghost,
                                                      nghost:-nghost,
                                                      nghost:-nghost]
                gradshock[j, -nghost:, nghost:-nghost,
                          nghost:-nghost] = gradshock[j, nghost:2 * nghost,
                                                      nghost:-nghost,
                                                      nghost:-nghost]
                gradshock[j, nghost:-nghost, :nghost,
                          nghost:-nghost] = gradshock[j, nghost:-nghost,
                                                      -2 * nghost:-nghost,
                                                      nghost:-nghost]
                gradshock[j, nghost:-nghost, -nghost:,
                          nghost:-nghost] = gradshock[j, nghost:-nghost,
                                                      nghost:2 * nghost,
                                                      nghost:-nghost]
                gradshock[j, nghost:-nghost,
                          nghost:-nghost, :nghost] = gradshock[j,
                                                               nghost:-nghost,
                                                               nghost:-nghost,
                                                               -2 *
                                                               nghost:-nghost]
                gradshock[j, nghost:-nghost, nghost:-nghost,
                          -nghost:] = gradshock[j, nghost:-nghost,
                                                nghost:-nghost,
                                                nghost:2 * nghost]
            for j in range(0, 3):
                divugradlnrho[j] = param.nu_shock*divu*gradshock[j] +\
                          param.nu_shock*shock*(divu*gradlnrho[j] + graddivu[j])
            del (divu, gradshock, gradlnrho, graddivu)
            fvisc = fvisc + divugradlnrho
            del (divugradlnrho)
    if lhyper3:
        #deluij5 = np.zeros_like([uu,uu,uu])
        #uij5glnrho to be included
        del6u = np.zeros_like(uu)
        for j in range(0, 3):
            del6u[j] = del6(uu[j], grid.dx, grid.dy, grid.dz)
            del6u[j, :nghost, nghost:-nghost,
                  nghost:-nghost] = del6u[j, -2 * nghost:-nghost,
                                          nghost:-nghost, nghost:-nghost]
            del6u[j, -nghost:, nghost:-nghost,
                  nghost:-nghost] = del6u[j, nghost:2 * nghost, nghost:-nghost,
                                          nghost:-nghost]
            del6u[j, nghost:-nghost, :nghost,
                  nghost:-nghost] = del6u[j, nghost:-nghost,
                                          -2 * nghost:-nghost, nghost:-nghost]
            del6u[j, nghost:-nghost, -nghost:,
                  nghost:-nghost] = del6u[j, nghost:-nghost, nghost:2 * nghost,
                                          nghost:-nghost]
            del6u[j, nghost:-nghost,
                  nghost:-nghost, :nghost] = del6u[j, nghost:-nghost,
                                                   nghost:-nghost,
                                                   -2 * nghost:-nghost]
            del6u[j, nghost:-nghost, nghost:-nghost,
                  -nghost:] = del6u[j, nghost:-nghost, nghost:-nghost,
                                    nghost:2 * nghost]
            #del6 for non-cartesian tba
            #del6u[j] = del6(uu[j],grid.dx,grid.dy,grid.dz,x=grid.x,y=grid.y,
            #                coordinate_system=param.coord_system)
            fvisc = fvisc + param.nu_hyper3 * del6u
        del (del6u)
    fvisc2 = np.sqrt(dot2(fvisc))
    #advective forces
    advec = np.zeros_like(uu)
    advec[0] = dot(uu, tmp0)
    advec[1] = dot(uu, tmp1)
    advec[0] = dot(uu, tmp2)
    del (tmp0, tmp1, tmp2)
    advec2 = np.sqrt(dot2(advec))
    del (advec)
    #avoid division by zero
    if fvisc2.max() > 0:
        fvisc2[np.where(fvisc2 == 0)] = fvisc2[np.where(fvisc2 > 0)].min()
        Re = advec2 / fvisc2
        #set minimum floor to exclude zero-valued Re
        Re[np.where(Re == 0)] = Re[np.where(Re > 0)].min()
    else:
        Re = advec2
        print('Re undefined')
    return Re