Changeset 642 for codes/icosagcm/devel/Python/src
- Timestamp:
- 12/19/17 15:26:51 (7 years ago)
- Location:
- codes/icosagcm/devel/Python/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
codes/icosagcm/devel/Python/src/functions.h
r639 r642 7 7 void dynamico_init_params(void); 8 8 9 void dynamico_ARK_step(double *mass_col, double *rhodz, double *theta_rhodz, 9 void dynamico_ARK_step(int nstep, 10 double *mass_col, double *rhodz, double *theta_rhodz, 10 11 double *u, double *geopot, double *w, 11 12 double *theta, double *ps, double *pk, double *hflux, double *qv, -
codes/icosagcm/devel/Python/src/unstructured.pyx
r640 r642 18 18 19 19 cdef extern from "functions.h": 20 cdef void dynamico_ARK_step(double *mass_col, double *rhodz, double *theta_rhodz, 20 cdef void dynamico_ARK_step(int nstep, 21 double *mass_col, double *rhodz, double *theta_rhodz, 21 22 double *u, double *geopot, double *w, 22 23 double *theta, double *ps, double *pk, double *hflux, double *qv, … … 78 79 cdef dbl_ptr ptr2(double[:,:] data) : return &data[0,0] 79 80 cdef dbl_ptr ptr3(double[:,:,:] data) : return &data[0,0,0] 81 cdef dbl_ptr ptr4(double[:,:,:,:] data) : return &data[0,0,0,0] 80 82 cdef dbl_ptr ptr(data): 81 83 n=data.ndim … … 83 85 if n==2 : return ptr2(data) 84 86 if n==3 : return ptr3(data) 85 87 if n==4 : return ptr4(data) 88 if n>4: raise IndexError 89 86 90 cdef alloc(dbl_ptr *p, allocator, n=1): 87 91 data=allocator(n) … … 93 97 94 98 cdef class Caldyn_step: 99 # number of time steps to do at each invocation of advance() 100 cdef int nstep 95 101 # pointer to allocated arrays 96 cdef dbl_ptr p_mass, p_theta_rhodz, p_u, p_geopot, p_ w# prognostic102 cdef dbl_ptr p_mass, p_theta_rhodz, p_u, p_geopot, p_W # prognostic 97 103 cdef dbl_ptr p_mass_col, p_dmass_col, p_ps, p_theta, p_pk, p_hflux, p_qv # diagnostic 98 104 cdef dbl_ptr p_drhodz, p_dtheta_rhodz, p_du_fast, p_du_slow # tendencies 99 105 cdef dbl_ptr p_dPhi_fast, p_dPhi_slow, p_dW_fast, p_dW_slow # tendencies 100 106 # allocated arrays, must remain referenced or segfault 101 cdef readonly np.ndarray mass, theta_rhodz, u, geopot, w107 cdef readonly np.ndarray mass, theta_rhodz, u, geopot, W 102 108 cdef readonly np.ndarray mass_col, dmass_col, ps, theta, pk, hflux, qv 103 109 cdef readonly np.ndarray drhodz, dtheta_rhodz, du_fast, du_slow 104 110 cdef readonly np.ndarray dPhi_fast, dPhi_slow, dW_fast, dW_slow 105 111 106 def __init__(self,mesh,time_scheme): 112 def __init__(self,mesh,time_scheme, nstep): 113 self.nstep=nstep 107 114 # self.mesh=mesh 108 115 fps, ftheta, fmass = mesh.field_ps, mesh.field_theta, mesh.field_mass … … 113 120 cdef double[:,:] cflj_ = time_scheme.cfjl 114 121 ns = time_scheme.nstage 115 nb_stage[0]= ns 122 nb_stage[0]=ns 123 116 124 cdef int i,j 117 125 for i in range(ns): … … 123 131 # prognostic/diagnostic 124 132 self.ps = alloc(&self.p_ps, fps) 125 self.mass_col, self.dmass_col = alloc(&self.p_mass_col, fps), alloc(&self.p_dmass_col, fps ),133 self.mass_col, self.dmass_col = alloc(&self.p_mass_col, fps), alloc(&self.p_dmass_col, fps,ns), 126 134 self.mass, self.theta_rhodz = alloc(&self.p_mass, fmass), alloc(&self.p_theta_rhodz, fmass), 127 135 self.theta, self.pk = alloc(&self.p_theta, fmass), alloc(&self.p_pk, fmass), 128 self.geopot, self. w = alloc(&self.p_geopot, fw), alloc(&self.p_w, fw),136 self.geopot, self.W = alloc(&self.p_geopot, fw), alloc(&self.p_W, fw), 129 137 self.hflux, self.u = alloc(&self.p_hflux, fu), alloc(&self.p_u, fu) 130 138 self.qv = alloc(&self.p_qv,fz) … … 137 145 # global elapsed 138 146 # time1=time.time() 139 check_ptr('mass', self.p_mass, self.mass) 140 check_ptr('u', self.p_u, self.u) 141 dynamico_ARK_step(self.p_mass_col, self.p_mass, self.p_theta_rhodz, 142 self.p_u, self.p_geopot, self.p_w, 147 dynamico_ARK_step(self.nstep, 148 self.p_mass_col, self.p_mass, self.p_theta_rhodz, 149 self.p_u, self.p_geopot, self.p_W, 143 150 self.p_theta, self.p_ps, self.p_pk, self.p_hflux, self.p_qv, 144 151 self.p_dmass_col, self.p_drhodz, self.p_dtheta_rhodz, … … 148 155 #time2=time.time() 149 156 #if time2>time1: elapsed=elapsed+time2-time1 150 def setup_TRSW(self): 151 setvars(('hydrostatic','caldyn_thermo','caldyn_eta'), 152 (True,thermo_boussinesq,eta_lag)) 153 dynamico_init_params() 154 def setup_HPE(self, caldyn_thermo, caldyn_eta, g, BC,thermo): 155 setvars(('hydrostatic','caldyn_thermo','caldyn_eta', 156 'g','ptop','Rd','cpp','preff','Treff'), 157 (True,caldyn_thermo,caldyn_eta, 158 g,BC.ptop,thermo.Rd,thermo.Cpd,thermo.p0,thermo.T0)) 159 dynamico_init_params() 160 def setup_NH(self, caldyn_thermo, caldyn_eta, g, BC,thermo): 161 setvars(('hydrostatic','caldyn_thermo','caldyn_eta', 162 'g','ptop','Rd','cpp','preff','Treff', 163 'pbot','rho_bot'), 164 (False,caldyn_thermo,caldyn_eta, 165 g,BC.ptop,thermo.Rd,thermo.Cpd,thermo.p0,thermo.T0, 166 BC.pbot.max(), BC.rho_bot.max())) 167 dynamico_init_params() 168 157 158 def caldyn_step_TRSW(mesh,time_scheme,nstep): 159 setvars(('hydrostatic','caldyn_thermo','caldyn_eta'), 160 (True,thermo_boussinesq,eta_lag)) 161 dynamico_init_params() 162 return Caldyn_step(mesh,time_scheme, nstep) 163 def caldyn_step_HPE(mesh,time_scheme,nstep, caldyn_thermo,caldyn_eta, thermo,BC,g): 164 setvars(('hydrostatic','caldyn_thermo','caldyn_eta', 165 'g','ptop','Rd','cpp','preff','Treff'), 166 (True,caldyn_thermo,caldyn_eta, 167 g,BC.ptop,thermo.Rd,thermo.Cpd,thermo.p0,thermo.T0)) 168 dynamico_init_params() 169 return Caldyn_step(mesh,time_scheme, nstep) 170 def caldyn_step_NH(mesh,time_scheme,nstep, caldyn_thermo, caldyn_eta, thermo,BC,g): 171 setvars(('hydrostatic','caldyn_thermo','caldyn_eta', 172 'g','ptop','Rd','cpp','preff','Treff','pbot','rho_bot'), 173 (False,caldyn_thermo,caldyn_eta, 174 g,BC.ptop,thermo.Rd,thermo.Cpd,thermo.p0,thermo.T0, 175 BC.pbot.max(), BC.rho_bot.max())) 176 dynamico_init_params() 177 return Caldyn_step(mesh,time_scheme, nstep) 178 169 179 #----------------------------- Base class for dynamics ------------------------ 170 180 … … 212 222 213 223 class Caldyn_HPE(Caldyn): 214 def __init__(self,caldyn_thermo,caldyn_eta, mesh, metric,thermo,BC,g):224 def __init__(self,caldyn_thermo,caldyn_eta, mesh,thermo,BC,g): 215 225 Caldyn.__init__(self,mesh) 216 226 setvars(('hydrostatic','caldyn_thermo','caldyn_eta', … … 231 241 232 242 class Caldyn_NH(Caldyn): 233 def __init__(self,caldyn_thermo,caldyn_eta, mesh, metric,thermo,BC,g):243 def __init__(self,caldyn_thermo,caldyn_eta, mesh,thermo,BC,g): 234 244 Caldyn.__init__(self,mesh) 235 245 setvars(('hydrostatic','caldyn_thermo','caldyn_eta',
Note: See TracChangeset
for help on using the changeset viewer.