Ignore:
Timestamp:
10/09/18 14:28:53 (6 years ago)
Author:
dubos
Message:

devel/Python : moved DYNAMICO_Format to meshes.py + cleanup

File:
1 edited

Legend:

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

    r747 r756  
    22from dynamico import unstructured as unst 
    33from dynamico import time_step 
     4from dynamico import precision as prec 
    45 
    56import math as math 
     
    78import numpy as np 
    89import netCDF4 as cdf 
    9  
    10 class DYNAMICO_Format(meshes.Mesh_Format): 
    11     """ Netcdf input file handling. 
    12     Creates a dictionary of names corresponding to original data file.""" 
    13  
    14     start_index=1 # indexing starts at 1 as in Fortran 
    15     translate = { 'down_up':'edge_down_up', 'left_right':'edge_left_right' } #new name is edge_left_right 
    16  
    17     def __init__(self,gridfilename): 
    18         try: 
    19             self.nc = cdf.Dataset(gridfilename, "r") 
    20             print('#NC4: Opening file:',gridfilename) 
    21         except RuntimeError: 
    22             print """ Unable to open grid file %s, maybe you forgot to download it ? 
    23             To do so, go to the 'Python/' dir and execute './get_MPAS_grids.sh'. 
    24             """ % gridfile 
    25             raise 
    26     def get_pdim(self,comm,name): 
    27         if name in self.translate: name = self.translate[name] 
    28         return parallel.PDim(self.nc.dimensions[name], comm) 
    29     def getvar(self,name): 
    30         if name in self.translate: name = self.translate[name] 
    31         return self.nc.variables[name][:] 
    32     def get_pvar(self,pdim,name): 
    33         # provides parallel access to a NetCDF variable, with name translation 
    34         # first deal with special cases 
    35         if name == 'edge_deg': return parallel.CstPArray1D(pdim, np.int32, 2) 
    36         # general case 
    37         if name in self.translate: name = self.translate[name] 
    38         return parallel.PArray(pdim, self.nc.variables[name]) 
    39     def normalize(self, mesh, radius): pass 
    4010 
    4111#--------------------------------- Main program ----------------------------- 
     
    4515dx,dy=Lx/nx,Ly/ny 
    4616 
    47 filename, llm, nqdyn, g, f, radius = 'cart128.nc', 1, 1, 1., 1., None 
     17filename, llm, nqdyn, g, f, radius = 'cart_128.nc', 1, 1, 1., 1., None 
    4818unst.setvar('g',g) 
    4919 
    5020print 'Reading Cartesian mesh ...' 
    51 meshfile = DYNAMICO_Format(filename) 
    52 #print("#NC4: check point: 0") 
    53 #print(meshfile) 
     21meshfile = meshes.DYNAMICO_Format(filename) 
    5422 
    5523def coriolis(lon,lat): 
     
    5826mesh=meshes.Unstructured_Mesh(meshfile, llm, nqdyn, radius, coriolis) 
    5927caldyn = unst.Caldyn_RSW(mesh) 
    60 #print(caldyn.__dict__.keys()) 
    6128 
    6229xx = (mesh.lat_i-nx/2.)*dx 
     
    6734h0 = 1+0.1*(np.exp(-2.*(x1*x1+yy*yy))+ 
    6835            np.exp(-2.*(x2*x2+yy*yy))) 
    69 flow0=meshes.asnum([h0,u0]) 
    70  
    71 #print('h0 : ', h0[1234]-1.) 
    72 #print('h0 : ', h0[2345]-1.) 
     36flow0=prec.asnum([h0,u0]) 
    7337 
    7438cfl = .8 
     
    9155for i in range(10): 
    9256    h,u=flow 
    93     flow, fast, slow = caldyn.bwd_fast_slow(flow, unst.zero_num) 
     57    flow, fast, slow = caldyn.bwd_fast_slow(flow, prec.zero) 
    9458    junk, du_fast = fast 
    9559    dh, du_slow = slow 
Note: See TracChangeset for help on using the changeset viewer.