Ignore:
Timestamp:
04/30/19 18:14:37 (5 years ago)
Author:
dubos
Message:

devel/Python : moved Fortran bindings and *.pyx to dynamico/dev module + necessary changes to test/py/*.py

File:
1 edited

Legend:

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

    r807 r825  
     1from __future__ import absolute_import      
     2 
     3from dynamico.dev import unstructured as unst 
     4 
    15import time 
    26import math 
     
    812from matplotlib.collections import PatchCollection 
    913 
    10 import unstructured as unst 
    11 import parallel 
    12 from util import list_stencil, Base_class, inverse_list 
    13 from precision import zeros 
    14  
    15 import getargs 
     14from dynamico import parallel 
     15from dynamico.util import list_stencil, BaseClass, inverse_list 
     16from dynamico import getargs 
     17from dynamico.parmetis import partition_mesh 
     18 
    1619log_master, log_world = getargs.getLogger(__name__) 
    1720INFO, DEBUG, ERROR = log_master.info, log_master.debug, log_world.error 
     
    1922 
    2023radian=180/math.pi 
    21    
     24 
    2225#------------------- Hybrid mass-based coordinate ------------- 
    2326 
     
    7376    return [ np.asarray(x) for x in bp_il, mass_dak, mass_dbk ] 
    7477 
     78#----------------------- Base class for "user" meshes --------- 
     79 
     80class BaseMesh(BaseClass): 
     81    def zeros(self,dims): return np.zeros([n for n in dims if n>1]) # overriden by meshes.dev.DevMesh 
     82 
    7583#----------------------- Cartesian mesh ----------------------- 
    7684 
     
    9098    return z.transpose() 
    9199 
    92 class Cartesian_Mesh(Base_class): 
     100class Cartesian_Mesh(BaseMesh): 
    93101    def __init__(self,nx,ny,llm,nqdyn,Lx,Ly,f): 
    94102        dx,dy = Lx/nx, Ly/ny 
     
    273281        f.close() 
    274282 
    275     def field_theta(self,n=1): return zeros((n,self.nqdyn,self.ny,self.nx,self.llm)) 
    276     def field_mass(self,n=1): return zeros((n,self.ny,self.nx,self.llm)) 
    277     def field_z(self,n=1): return zeros((n,self.ny,self.nx,self.llm)) 
    278     def field_w(self,n=1): return zeros((n,self.ny,self.nx,self.llm+1)) 
    279     def field_u(self,n=1): return zeros((n,self.ny,2*self.nx,self.llm)) 
    280     def field_ps(self,n=1): return zeros((n,self.ny,self.nx)) 
    281     def field_ucomp(self,n=1): return zeros((n,self.ny,self.nx,self.llm)) 
     283    def field_theta(self,n=1): return self.zeros((n,self.nqdyn,self.ny,self.nx,self.llm)) 
     284    def field_mass(self,n=1): return self.zeros((n,self.ny,self.nx,self.llm)) 
     285    def field_z(self,n=1): return self.zeros((n,self.ny,self.nx,self.llm)) 
     286    def field_w(self,n=1): return self.zeros((n,self.ny,self.nx,self.llm+1)) 
     287    def field_u(self,n=1): return self.zeros((n,self.ny,2*self.nx,self.llm)) 
     288    def field_ps(self,n=1): return self.zeros((n,self.ny,self.nx)) 
     289    def field_ucomp(self,n=1): return self.zeros((n,self.ny,self.nx,self.llm)) 
    282290    def ucomp(self,u):  
    283291        return u[range(0,2*self.nx,2),:] if self.ny==1 else u[:,range(0,2*self.nx,2),:] 
     
    293301#---------------------- DYNAMICO format for fully unstructured mesh and curvilinear meshes ---------------------- 
    294302 
    295 class Mesh_Format(Base_class): 
     303class Mesh_Format(BaseMesh): 
    296304    def getdims(self,*names): return [len(self.nc.dimensions[name]) for name in names] 
    297305    def get_pdims(self,comm,*names): return [self.get_pdim(comm,name) for name in names] 
     
    399407    return ne 
    400408 
    401 class Abstract_Mesh(Base_class): 
     409class Abstract_Mesh(BaseMesh): 
    402410    def to_dynamico(self): pass 
    403     def field_theta(self,n=1): return zeros((n,self.nqdyn,self.primal_num,self.llm)) 
    404     def field_mass(self,n=1):  return zeros((n,self.primal_num,self.llm)) 
    405     def field_z(self,n=1):     return zeros((n,self.dual_num,self.llm)) 
    406     def field_w(self,n=1):     return zeros((n,self.primal_num,self.llm+1)) 
    407     def field_u(self,n=1):     return zeros((n,self.edge_num,self.llm)) 
    408     def field_ps(self,n=1):    return zeros((n,self.primal_num,)) 
     411    def field_theta(self,n=1): return self.zeros((n,self.nqdyn,self.primal_num,self.llm)) 
     412    def field_mass(self,n=1):  return self.zeros((n,self.primal_num,self.llm)) 
     413    def field_z(self,n=1):     return self.zeros((n,self.dual_num,self.llm)) 
     414    def field_w(self,n=1):     return self.zeros((n,self.primal_num,self.llm+1)) 
     415    def field_u(self,n=1):     return self.zeros((n,self.edge_num,self.llm)) 
     416    def field_ps(self,n=1):    return self.zeros((n,self.primal_num,)) 
    409417    def ucov2D(self, ulon, ulat):  
    410418        return self.de*(ulon*np.cos(self.angle_e)+ulat*np.sin(self.angle_e)) 
    411419    def ucov3D(self, ulon, ulat): 
    412         ucov = zeros((self.edge_num,ulon.shape[1])) 
     420        ucov = self.zeros((self.edge_num,ulon.shape[1])) 
    413421        for edge in range(self.edge_num): 
    414422            angle=self.angle_e[edge] 
     
    518526    def partition_metis(self): 
    519527        INFO('Partitioning with ParMetis...') 
    520         edge_owner = unst.partition_mesh(self.trisk_deg, self.trisk, self.comm.Get_size()) 
     528        edge_owner = partition_mesh(self.comm, self.trisk_deg, self.trisk) 
     529#        edge_owner = unst.partition_mesh(self.trisk_deg, self.trisk, self.comm.Get_size()) 
    521530        self.edge_owner = parallel.LocPArray1D(self.dim_edge, edge_owner) 
    522531        primal_owner = partition_from_stencil(self.edge_owner, self.primal_deg, self.primal_edge) 
     
    563572 
    564573class Local_Mesh(Abstract_Mesh): 
     574    Halo_Xchange = parallel.Halo_Xchange # overriden in dev.meshes 
    565575    def __init__(self, pmesh, llm, nqdyn, mapping): 
    566576        comm, dim_primal, primal_owner, dim_edge, edge_owner, dim_dual, dual_owner = pmesh.members( 
     
    620630        # construct own dual mesh for XIOS output 
    621631        dual_own_glo = find_my_cells(dual_owner) 
    622         dual_own_glo = np.asarray(primal_own_glo, dtype=np.int32) 
     632        dual_own_glo = np.asarray(dual_own_glo, dtype=np.int32) 
    623633        dual_own_loc = [dict_V1[i] for i in dual_own_glo] 
    624634         
     
    655665        self.to_dynamico() 
    656666        # setup halo transfers - NB : llm must be set before we call set_dynamico_transfer 
    657         self.com_primal = parallel.Halo_Xchange( 
     667        self.com_primal = self.Halo_Xchange( 
    658668            42, dim_primal, cells_C1, get_all_cells(primal_owner)) 
    659         self.com_edges = parallel.Halo_Xchange( 
     669        self.com_edges = self.Halo_Xchange( 
    660670            73, dim_edge, edges_E2, get_all_edges(edge_owner)) 
    661671        self.com_primal.set_dynamico_transfer('primal') 
Note: See TracChangeset for help on using the changeset viewer.