コード例 #1
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]
コード例 #2
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]
コード例 #3
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]
コード例 #4
0
ファイル: rhs_terms.py プロジェクト: pencil-code/pencil-code
 def resistive(src, dst, key, par, gd, l1, l2, m1, m2, n1, n2, nghost):
     if key == "etadel2a":
         n1shift,n2shift,m1shift,m2shift,l1shift,l2shift=der_limits(
                                                  n1,n2,m1,m2,l1,l2,nghost)
         if "ax" in src["data"].keys():
             aa = np.array([
                   src["data/ax"][n1shift:n2shift,m1shift:m2shift,l1shift:l2shift],
                   src["data/ay"][n1shift:n2shift,m1shift:m2shift,l1shift:l2shift],
                   src["data/az"][n1shift:n2shift,m1shift:m2shift,l1shift:l2shift]
                   ])
             if par.eta == 0.:
                 print("no resistivity used setting etadel2a=0 in resistive")
                 var = np.zeros_like(aa)
             else:
                 var = par.eta*del2(aa, gd.dx, gd.dy, gd.dz,x=gd.x[l1shift:l2shift],y=gd.y[m1shift:m2shift],coordinate_system=par.coord_system)
         else:
             print("no vector potential for resistive calculation")
             for key in src["data"].keys():
                 if len(src["data"][key].shape) == 3:
                     var = np.zeros([3,src["data"][key].shape[0],
                                       src["data"][key].shape[1],
                                       src["data"][key].shape[2] ])
                     break
         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]
コード例 #5
0
ファイル: rhs_terms.py プロジェクト: pencil-code/pencil-code
 def curletadel2a(src, dst, key, par, gd, l1, l2, m1, m2, n1, n2, nghost):
     if key == "curletadel2a":
         n1shift,n2shift,m1shift,m2shift,l1shift,l2shift=der_limits(
                                                  n1,n2,m1,m2,l1,l2,nghost)
         if "etadel2a" in dst["calc"].keys():
             tmp = dst["calc/etadel2a"][:,n1shift:n2shift,
                                     m1shift:m2shift,
                                     l1shift:l2shift]
         else:
             tmp = induction(src, dst, "etadel2a", par, gd, n1shift, n2shift,
                             m1shift, m2shift, l1shift, l2shift, nghost)
         var = curl(tmp, gd.dx, gd.dy, gd.dz,x=gd.x[l1shift:l2shift],y=gd.y[m1shift:m2shift],coordinate_system=par.coord_system)
         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]
コード例 #6
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]
コード例 #7
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]
コード例 #8
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]