Changeset 795


Ignore:
Timestamp:
01/09/19 16:26:50 (5 years ago)
Author:
jisesh
Message:

unstructured/Python : bugfix logging + more diagnostics

Location:
codes/icosagcm/devel/Python
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • codes/icosagcm/devel/Python/dynamico/getargs.py

    r790 r795  
    1010add("--mpi_ni", type=int, default=1, help="number of x processors") 
    1111add("--mpi_nj", type=int, default=1, help="number of y processors") 
    12 add("--log",type=str,default='DEBUG',choices=('DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'), 
    13                     help="Set verbosity level of logging") 
    1412add("--hydrostatic", action='store_true') 
    1513add("--llm", type=int) 
     
    2018def noop(*args, **kwargs): pass 
    2119 
     20def ignore_first(fun): 
     21    def f(self, *args, **kwargs) : fun(*args, **kwargs) 
     22    return f 
     23 
    2224class Logger: 
    23     debug, info, error = logging.debug, logging.info, logging.error 
     25    debug, info, error = [ ignore_first(fun) for fun in  
     26                           logging.info, logging.warning, logging.error ] 
    2427    def __init__(self, modulename): 
    2528        arglist = parser.parse_args() 
     
    2831        else: 
    2932            print('Debug ON for module %s'%modulename) 
     33        config_log() 
    3034 
    31 def config_log(**kwargs): 
    32     arglist = parser.parse_args() 
    33     loglevel = getattr(logging, arglist.log.upper()) 
    34     logging.basicConfig(level=loglevel, **kwargs) 
     35def config_log(*args, **kwargs): 
     36    logging.basicConfig(level='INFO', *args, **kwargs) 
  • codes/icosagcm/devel/Python/test/py/Baroclinic_3D_ullrich.py

    r794 r795  
    11from __future__ import print_function 
     2from __future__ import division 
     3 
    24from dynamico import getargs 
    35 
     
    1315getargs.add("--ny", type=int, default=30) 
    1416getargs.add("--betaplane", action='store_true') 
     17 
     18getargs.add("--kappa_divgrad",  type=float, default=3.0e15) 
     19getargs.add("--kappa_curlcurl", type=float, default=3.0e15) 
     20 
    1521getargs.defaults(dt=360., llm=50) 
     22 
     23getargs.config_log(filename='out.log',filemode='w') # must be done before calling Logger() 
     24#    getargs.config_log(filename='out.log',filemode='w', 
     25#                    format='%(processName)s:%(name)s:%(filename)s:%(module)s:%(funcName)s:%(lineno)d:%(levelname)s:%(message)s' ) 
    1626 
    1727logging = getargs.Logger('main') 
     
    136146    return thermo, mesh, params, prec.asnum([mass_ik,Sik,u_ek,Phi_il,Wil]), gas 
    137147 
    138 def diagnose(Phi,S,m,W): 
     148def diagnose(Phi,S,m,W,u): 
    139149    s=S/m 
     150    curl_vk = curl(mesh, u) 
     151    abs_vort_vk = mesh.field_z() # absolute vorticity 
     152    un = mesh.field_u() 
     153    v = mesh.field_mass() # specific volume 
     154    w = mesh.field_mass() 
     155    z = mesh.field_mass() 
    140156    for l in range(llm): 
    141157        v[:,l]=(Phi[:,l+1]-Phi[:,l])/(g*m[:,l]) 
    142158        w[:,l]=.5*params.g*(W[:,l+1]+W[:,l])/m[:,l] 
    143159        z[:,l]=.5*(Phi[:,l+1]+Phi[:,l])/params.g 
     160        un[:,l]=u[:,l]/mesh.de 
     161        abs_vort_vk[:,l]=curl_vk[:,l] + mesh.fv 
    144162    gas = thermo.set_vs(v,s) 
    145     return gas, w, z 
     163    ps = gas.p[:,0]+ .5*g*m[:,0] 
     164    return gas, w, z, ps, un, curl_vk, abs_vort_vk 
    146165 
    147166class myDavies(Davies): 
     
    153172    comm = client.comm 
    154173    mpi_rank, mpi_size = comm.Get_rank(), comm.Get_size() 
    155 #    getargs.config_log(filename='out.log',filemode='w', 
    156 #                    format='%(processName)s:%(name)s:%(filename)s:%(module)s:%(funcName)s:%(lineno)d:%(levelname)s:%(message)s' ) 
    157174 
    158175    logging.info('%d/%d starting'%(mpi_rank,mpi_size)) 
    159176 
    160     g, Lx, Ly = 9.81, 4e7, 6e6 
     177    g, Lx, Ly = 9.80616, 4e7, 6e6 
    161178    nx, ny, llm = args.nx, args.ny, args.llm 
    162179    dx = Lx/nx 
     
    170187    #    print('WARNING: Davies_N1 not equal to Davies_N2; average value will be used') 
    171188 
    172  
    173189    unst.setvar('g',g) 
    174190     
     
    198214        scheme = time_step.ARK2(None, dt) 
    199215        if args.hydrostatic: 
    200             caldyn_step = unst.caldyn_step_HPE(mesh,scheme,1, caldyn_thermo,caldyn_eta,thermo,params,params.g) 
     216            caldyn_step = unst.caldyn_step_HPE(mesh,scheme,1, caldyn_thermo,caldyn_eta, 
     217                                               thermo,params,params.g) 
    201218        else: 
    202             caldyn_step = unst.caldyn_step_NH(mesh,scheme,1, caldyn_thermo,caldyn_eta,thermo,params,params.g) 
    203         davies = myDavies(args.Davies_N1, args.Davies_N2, mesh.lon_i, mesh.lat_i, mesh.lon_e,mesh.lat_e) 
     219            caldyn_step = unst.caldyn_step_NH(mesh,scheme,1, caldyn_thermo,caldyn_eta, 
     220                                              thermo,params,params.g) 
     221        davies = myDavies(args.Davies_N1, args.Davies_N2,  
     222                          mesh.lon_i, mesh.lat_i, mesh.lon_e,mesh.lat_e) 
    204223#        print('mask min/max :', davies.beta_i.min(), davies.beta_i.max() ) 
    205224        logging.debug('mask min/max :') 
    206225        logging.debug('%f'% davies.beta_i.min()) 
    207226        logging.debug('%f'% davies.beta_i.max()) 
     227 
    208228        def next_flow(m,S,u,Phi,W): 
    209229            # junk,fast,slow = caldyn.bwd_fast_slow(flow, 0.) 
    210230            caldyn_step.mass[:,:], caldyn_step.theta_rhodz[:,:], caldyn_step.u[:,:] = m,S,u 
    211231            caldyn_step.geopot[:,:], caldyn_step.W[:,:] = Phi,W 
    212             #Relaxation zone inside the domain 
    213             kappa = 3.26e+15 #nonhyd=>#Y3.3#Y3.27#Y3.26#Y3.255#dblchkd;N3.25#N3.2#N3.0#Y3.4#dx**4/432000. 
    214             #Relaxation zone outside the domain 
    215             #kappa = 3.6e+15 #nonhyd=>#Y3.3#Y3.27#Y3.26#Y3.255#dblchkd;N3.25#N3.2#N3.0#Y3.4#dx**4/432000. 
    216             #print('Kappa=',kappa) 
    217232            for i in range(nt): 
    218233                caldyn_step.next() 
     
    226241                unst.ker.dynamico_curl_laplacian(u,lapu) 
    227242                unst.ker.dynamico_curl_laplacian(lapu,bilapu) 
    228                 caldyn_step.theta_rhodz[:] = S - dt*kappa*bilaps*m # Euler step 
    229                 caldyn_step.u[:] = u - dt*kappa*bilapu # Euler step 
     243                caldyn_step.theta_rhodz[:] = S - dt*args.kappa_divgrad*bilaps*m # Euler step 
     244                caldyn_step.u[:] = u - dt*args.kappa_curlcurl*bilapu # Euler step 
    230245 
    231246            return (caldyn_step.mass.copy(), caldyn_step.theta_rhodz.copy(), caldyn_step.u.copy(), 
     
    241256        title_format = 'Specific entropy at t=%g s (J/K/kg)' 
    242257 
    243     w=mesh.field_mass() 
    244     z=mesh.field_mass() 
    245  
    246258    #T, nslice, dt = 3600., 1, 3600. 
    247259    Nslice = args.N 
    248260 
     261    temp_v = mesh.field_z(),      
     262 
    249263    with xios.Context_Curvilinear(mesh,1, 24*3600) as context: 
    250264        # now XIOS knows about the mesh and we can write to disk 
    251         v = mesh.field_mass() # specific volume (diagnosed) 
    252          
    253265        for i in range(Nslice+1): 
    254266            context.update_calendar(i+1) 
    255267 
    256268            # Diagnose quantities of interest from prognostic variables m,S,u,Phi,W 
    257             gas, w, z = diagnose(Phi,S,m,W) 
    258             ps = caldyn_step.ps 
    259             curl_vk = curl(mesh, u) 
     269            gas, w, z, ps, un, zeta_vk, zeta_abs_vk = diagnose(Phi,S,m,W,u) 
    260270            KE_ik = KE(mesh,u) 
    261271            du_fast, du_slow = caldyn_step.du_fast[0,:,:], caldyn_step.du_slow[0,:,:]  
     
    277287 
    278288            context.send_field_primal('div_slow', div_slow) 
    279 #            context.send_field_primal('div_slow', div(mesh,hflux) ) 
    280  
    281             context.send_field_dual('curl', curl_vk) 
     289 
     290            context.send_field_dual('curl', zeta_vk) 
     291            context.send_field_dual('curl_abs', zeta_abs_vk) 
    282292 
    283293            print( 'ptop, model top (m) :', unst.getvar('ptop'), Phi.max()/unst.getvar('g')) 
  • codes/icosagcm/devel/Python/test/python.sh

    r790 r795  
    2121    shift 
    2222    rm -f xios_client*.* 
    23     mpirun -np $NB_MPI python -u $* | tee dynamico.log 
     23    mpirun -np $NB_MPI python -u $* 2>&1 | tee dynamico.log 
    2424} 
    2525 
  • codes/icosagcm/devel/Python/test/xml/field_def_simple.xml

    r787 r795  
    1313      <field_group axis_ref="lev">  
    1414        <field id="curl" /> 
     15        <field id="curl_abs" /> 
    1516      </field_group> 
    1617    </field_group> 
  • codes/icosagcm/devel/Python/test/xml/filedef_simple.xml

    r787 r795  
    2121      <field field_ref="theta" /> 
    2222      <field field_ref="curl" /> 
     23      <field field_ref="curl_abs" /> 
    2324      <field field_ref="div_fast" /> 
    2425      <field field_ref="div_slow" /> 
Note: See TracChangeset for help on using the changeset viewer.