Ignore:
Timestamp:
10/05/18 13:42:49 (6 years ago)
Author:
dubos
Message:

devel/unstructured : more fixes to mixed precision

Location:
codes/icosagcm/devel/Python/test/py
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • codes/icosagcm/devel/Python/test/py/DCMIP2008c5.py

    r687 r747  
    136136plt.savefig('fig_DCMIP2008c5/Ai.png'); plt.close() 
    137137 
    138  
    139 if False: # time stepping in Python 
     138if False: # time stepping in Python => set precision to np_num 
    140139    caldyn = unst.Caldyn_HPE(caldyn_thermo,caldyn_eta, mesh,thermo,params,params.g) 
    141     scheme = time_step.ARK2(caldyn.bwd_fast_slow, dt, a32=0.7) 
     140    scheme = time_step.ARK2(caldyn.bwd_fast_slow, dt, precision=unst.np_num, a32=0.7) 
    142141    def next_flow(m,S,u):  
    143142        m,S,u = scheme.advance((m,S,u),nt) 
     
    179178z, vol = mesh.field_mass(), mesh.field_mass() 
    180179m,S,u,Phi,W = flow0  
     180 
     181print 'types of m,S,u :', m.dtype, S.dtype, u.dtype 
     182 
    181183caldyn_step.geopot[:,0]=Phi[:,0] 
    182184plots(0) 
  • codes/icosagcm/devel/Python/test/py/NH_3D_bubble.py

    r656 r747  
    44from dynamico import DCMIP 
    55from dynamico import meshes 
     6from dynamico import precision as prec 
    67from dynamico.meshes import Cartesian_mesh as Mesh 
    78import math as math 
     
    5152    params.rho_bot = 1e6/gas_bot.v 
    5253     
    53     return thermo, mesh, params, (mass_ik,Sik,ujk,Phi_il,Wil), gas 
     54    return thermo, mesh, params, prec.asnum([mass_ik,Sik,ujk,Phi_il,Wil]), gas 
    5455 
    5556#Lx, nx, llm, thetac, T, Nslice, courant = 2000., 100, 50, 30., 5., 10, 2.8 
     
    6364# compute hybrid coefs from initial distribution of mass 
    6465mass_bl,mass_dak,mass_dbk = meshes.compute_hybrid_coefs(flow0[0]) 
     66print 'Type of mass_bl, mass_dak, mass_dbk : ', [x.dtype for x in mass_bl, mass_dak, mass_dbk] 
    6567unst.ker.dynamico_init_hybrid(mass_bl,mass_dak,mass_dbk) 
    6668 
  • codes/icosagcm/devel/Python/test/py/RSW_2D.py

    r632 r747  
    1818 
    1919x1,x2,yy = mesh.xx[:,:,0]-1., mesh.xx[:,:,0]+1., mesh.yy[:,:,0] 
    20 h0 = 1+0.1*(np.exp(-2.*(x1*x1+yy*yy))+ 
     20h0, u0 = mesh.field_mass(), mesh.field_u()  # flow initally at rest 
     21h0[:] = 1+0.1*(np.exp(-2.*(x1*x1+yy*yy))+ 
    2122            np.exp(-2.*(x2*x2+yy*yy))) 
    22 u0 = mesh.field_u()  # flow initally at rest 
    2323flow0=(h0,u0) 
    2424 
     
    3232scheme = time_step.ARK2(caldyn.bwd_fast_slow, dt) 
    3333 
     34print 'types : yy, u0, h0, u0', yy.dtype, u0.dtype, h0.dtype, u0.dtype 
     35 
    3436flow=flow0 
    3537for i in range(10): 
    3638    h,u=flow 
     39    print 'types : h,u', h.dtype, u.dtype 
    3740    caldyn.bwd_fast_slow(flow, 0.) 
    3841    plt.figure(); plt.pcolor(mesh.x,mesh.y,caldyn.qv) 
     
    4851        unst.elapsed=0. 
    4952        flow = scheme.advance(flow,N) 
     53        h,u=flow 
     54        print 'types : h,u', h.dtype, u.dtype 
    5055        # flops 
    5156        # mass flux : 1add+1mul per edge          =>  4 
  • codes/icosagcm/devel/Python/test/py/RSW_2D_mesh.py

    r719 r747  
    4545dx,dy=Lx/nx,Ly/ny 
    4646 
    47 filename, llm, nqdyn, g, f, radius = 'cart128.nc', 1, 1, 1., 1., 1. 
     47filename, llm, nqdyn, g, f, radius = 'cart128.nc', 1, 1, 1., 1., None 
    4848unst.setvar('g',g) 
    4949 
     
    6464 
    6565x1,x2,yy = xx-1., xx+1., yy 
     66u0 = mesh.field_u()  # flow initally at rest 
    6667h0 = 1+0.1*(np.exp(-2.*(x1*x1+yy*yy))+ 
    6768            np.exp(-2.*(x2*x2+yy*yy))) 
    68 u0 = mesh.field_u()  # flow initally at rest 
    69 flow0=(h0,u0) 
     69flow0=meshes.asnum([h0,u0]) 
    7070 
    7171#print('h0 : ', h0[1234]-1.) 
     
    7979dt=T/N 
    8080print N,dt,Lx/nx 
    81 scheme = time_step.ARK2(caldyn.bwd_fast_slow, dt) 
     81#scheme = time_step.ARK2(caldyn.bwd_fast_slow, dt, precision=unst.np_num) 
     82scheme = time_step.RK4(caldyn.bwd_fast_slow, dt, precision=unst.np_num) 
    8283 
    8384flow=flow0 
     
    9091for i in range(10): 
    9192    h,u=flow 
    92     flow, fast, slow = caldyn.bwd_fast_slow(flow, 0.) 
     93    flow, fast, slow = caldyn.bwd_fast_slow(flow, unst.zero_num) 
    9394    junk, du_fast = fast 
    9495    dh, du_slow = slow 
     
    102103    plt.figure(); plt.pcolor(x,y,reshape(caldyn.qv)) 
    103104    plt.colorbar(); plt.title('potential vorticity') 
    104     plt.savefig('fig_RSW_2D_mesh/%02d.png'%i) 
     105    plt.savefig('fig_RSW_2D_mesh/%03d.png'%i) 
     106    plt.close() 
    105107#    plt.figure(); plt.pcolor(mesh.x,mesh.y,h) 
    106108#    plt.colorbar(); plt.title('h') 
     
    112114        unst.elapsed=0. 
    113115        flow = scheme.advance(flow,N) 
     116#        flow = scheme.advance(flow,5) 
    114117        # flops 
    115118        # mass flux : 1add+1mul per edge          =>  4 
  • codes/icosagcm/devel/Python/test/py/RSW_MPAS_W02.py

    r680 r747  
    11print 'Loading DYNAMICO modules ...' 
    22from dynamico import unstructured as unst 
     3from dynamico.precision import asnum 
    34from dynamico.meshes import MPAS_Format, Unstructured_Mesh 
    45from dynamico import time_step 
     
    3435dt = T/nt 
    3536#scheme = time_step.RKn_simple(1,caldyn.bwd_fast_slow, dt) 
    36 scheme = time_step.RK4(caldyn.bwd_fast_slow, dt) 
     37scheme = time_step.RK4(caldyn.bwd_fast_slow, dt, precision=unst.np_num) 
    3738     
    3839print dx, dt, dt*c0/dx 
     
    6162fu_perp = mesh.ucov2D(0.*ulon,2*Omega*np.sin(mesh.lat_e)*ulon) 
    6263 
    63 flow = (Phi0,mesh.ucov2D(ulon,0.*ulon)) 
     64flow = asnum([Phi0, mesh.ucov2D(ulon,0.*ulon)]) 
     65print 'type of Phi0,u0 : ', flow[0].dtype, flow[1].dtype 
     66 
    6467for i in range(N): 
    6568    h,u=flow 
  • codes/icosagcm/devel/Python/test/py/bubble.py

    r631 r747  
    1 import math as math 
    2 import numpy as np 
    3 import matplotlib.pyplot as plt 
    4 import matplotlib.animation as manimation 
    5  
    61from dynamico.meshes import Cartesian_mesh as Mesh 
    72import dynamico.dyn as dyn 
     
    105import dynamico.advect as advect 
    116from dynamico import unstructured as unst 
     7 
     8import math as math 
     9import numpy as np 
     10import matplotlib.pyplot as plt 
     11import matplotlib.animation as manimation 
     12 
    1213 
    1314def reldiff(a,b): 
  • codes/icosagcm/devel/Python/test/py/slice_GW_NH.py

    r666 r747  
    2929 
    3030    u0=mesh.field_u()  
    31     u0[:,range(0,2*nx,2),:] = u*mesh.dx # Doppler shift by u 
     31    u0[range(0,2*nx,2),:] = u*mesh.dx # Doppler shift by u 
    3232    flow0=(m0ik,S0ik,u0,Phi0_il,0*Phi0_il) 
    3333 
     
    8181        plt.figure(figsize=(12,3)) 
    8282        ucomp = mesh.ucomp(u) 
    83         plt.pcolor(xx,zz,ucomp[0,:,:]/dx) 
     83        plt.pcolor(xx,zz,ucomp[:,:]/dx) 
    8484        plt_axes() 
    8585        plt.title("u(t = %f s)" % ((i+1)*dt*nt)) 
  • codes/icosagcm/devel/Python/test/py/slice_GW_hydro.py

    r656 r747  
    2323 
    2424    u0=mesh.field_u() 
    25     u0[:,range(0,2*nx,2),:] = 100.*mesh.dx # Doppler shift 100 m/s 
     25    u0[range(0,2*nx,2),:] = 100.*mesh.dx # Doppler shift 100 m/s 
    2626    flow0=(m0ik,S0ik,u0) 
    2727 
     
    6060        plt.figure(figsize=(12,3)) 
    6161        ucomp = mesh.ucomp(u) 
    62         plt.pcolor(xx,zz,ucomp[0,:,:]/dx) 
     62        plt.pcolor(xx,zz,ucomp[:,:]/dx) 
    6363        plt.ylim(0,10.) 
    6464        plt.colorbar() 
Note: See TracChangeset for help on using the changeset viewer.