Changeset 825 for codes/icosagcm/devel/Python/dynamico/meshes.py
- Timestamp:
- 04/30/19 18:14:37 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
codes/icosagcm/devel/Python/dynamico/meshes.py
r807 r825 1 from __future__ import absolute_import 2 3 from dynamico.dev import unstructured as unst 4 1 5 import time 2 6 import math … … 8 12 from matplotlib.collections import PatchCollection 9 13 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 14 from dynamico import parallel 15 from dynamico.util import list_stencil, BaseClass, inverse_list 16 from dynamico import getargs 17 from dynamico.parmetis import partition_mesh 18 16 19 log_master, log_world = getargs.getLogger(__name__) 17 20 INFO, DEBUG, ERROR = log_master.info, log_master.debug, log_world.error … … 19 22 20 23 radian=180/math.pi 21 24 22 25 #------------------- Hybrid mass-based coordinate ------------- 23 26 … … 73 76 return [ np.asarray(x) for x in bp_il, mass_dak, mass_dbk ] 74 77 78 #----------------------- Base class for "user" meshes --------- 79 80 class BaseMesh(BaseClass): 81 def zeros(self,dims): return np.zeros([n for n in dims if n>1]) # overriden by meshes.dev.DevMesh 82 75 83 #----------------------- Cartesian mesh ----------------------- 76 84 … … 90 98 return z.transpose() 91 99 92 class Cartesian_Mesh(Base _class):100 class Cartesian_Mesh(BaseMesh): 93 101 def __init__(self,nx,ny,llm,nqdyn,Lx,Ly,f): 94 102 dx,dy = Lx/nx, Ly/ny … … 273 281 f.close() 274 282 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)) 282 290 def ucomp(self,u): 283 291 return u[range(0,2*self.nx,2),:] if self.ny==1 else u[:,range(0,2*self.nx,2),:] … … 293 301 #---------------------- DYNAMICO format for fully unstructured mesh and curvilinear meshes ---------------------- 294 302 295 class Mesh_Format(Base _class):303 class Mesh_Format(BaseMesh): 296 304 def getdims(self,*names): return [len(self.nc.dimensions[name]) for name in names] 297 305 def get_pdims(self,comm,*names): return [self.get_pdim(comm,name) for name in names] … … 399 407 return ne 400 408 401 class Abstract_Mesh(Base _class):409 class Abstract_Mesh(BaseMesh): 402 410 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,)) 409 417 def ucov2D(self, ulon, ulat): 410 418 return self.de*(ulon*np.cos(self.angle_e)+ulat*np.sin(self.angle_e)) 411 419 def ucov3D(self, ulon, ulat): 412 ucov = zeros((self.edge_num,ulon.shape[1]))420 ucov = self.zeros((self.edge_num,ulon.shape[1])) 413 421 for edge in range(self.edge_num): 414 422 angle=self.angle_e[edge] … … 518 526 def partition_metis(self): 519 527 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()) 521 530 self.edge_owner = parallel.LocPArray1D(self.dim_edge, edge_owner) 522 531 primal_owner = partition_from_stencil(self.edge_owner, self.primal_deg, self.primal_edge) … … 563 572 564 573 class Local_Mesh(Abstract_Mesh): 574 Halo_Xchange = parallel.Halo_Xchange # overriden in dev.meshes 565 575 def __init__(self, pmesh, llm, nqdyn, mapping): 566 576 comm, dim_primal, primal_owner, dim_edge, edge_owner, dim_dual, dual_owner = pmesh.members( … … 620 630 # construct own dual mesh for XIOS output 621 631 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) 623 633 dual_own_loc = [dict_V1[i] for i in dual_own_glo] 624 634 … … 655 665 self.to_dynamico() 656 666 # 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( 658 668 42, dim_primal, cells_C1, get_all_cells(primal_owner)) 659 self.com_edges = parallel.Halo_Xchange(669 self.com_edges = self.Halo_Xchange( 660 670 73, dim_edge, edges_E2, get_all_edges(edge_owner)) 661 671 self.com_primal.set_dynamico_transfer('primal')
Note: See TracChangeset
for help on using the changeset viewer.