def main(): parser = ArgumentParser() parser.add_argument('-g', '--grid-params', type=FileType('r'), required=True) parser.add_argument('--part-quant', default=1) parser.add_argument('--isec', default=4) parser.add_argument('--idir', default=0) parser.add_argument('--nqua', default=1) parser.add_argument('--ist1', default=10) parser.add_argument('--ist2', default=10) parser.add_argument('--jst1', default=50) parser.add_argument('--jst2', default=50) parser.add_argument('--kst1', default=5) parser.add_argument('--kst2', default=5) args = parser.parse_args() read_params(args.grid_params) tm.mod_param.partquant = args.part_quant tm.mod_param.partquant = args.part_quant tm.mod_seed.isec = args.isec tm.mod_seed.idir = args.idir tm.mod_seed.nqua = args.nqua tm.mod_seed.seedtype = 1 tm.mod_seed.ist1 = args.ist1 tm.mod_seed.ist2 = args.ist2 tm.mod_seed.jst1 = args.jst1 tm.mod_seed.jst2 = args.jst2 tm.mod_seed.kst1 = args.kst1 tm.mod_seed.kst2 = args.kst2 tm.init_params2() tm.coordinat() tm.mod_grid.kmt[:] = tm.mod_param.km if tm.mod_seed.nqua == 1: # number of trajectories (per time resolution) # num=NTRACMAX tm.mod_seed.num = tm.mod_param.partquant elif tm.mod_seed.nqua == 2: tm.mod_param.voltr = tm.mod_param.partquant elif tm.mod_seed.nqua == 3: tm.mod_param.voltr = tm.mod_param.partquant tm.mod_traj.trj[:] = 0 tm.mod_traj.nrj[:] = 0 tm.init_seed() tm.mod_seed.seed(0, 0) print tm.mod_seed.seed_ijk print tm.mod_traj.trj
def setup_tracmass(self, seed_locations): tm.mod_seed.nqua = 4 tm.mod_param.partquant = 1 tm.mod_grid.subgrid = 0 tm.mod_param.kriva = 1 tm.mod_domain.timax = 3650.0 tm.loop.writedata = self.writedata tm.loop.readfields = self.readfields #Constants in this run tm.mod_param.lbt = 1 tm.mod_param.nend = tm.mod_param.lbt + 1 tm.mod_param.ntracmax = seed_locations.shape[0] + 1 tm.init_params2() tm.coordinat() tm.mod_time.intrun = self.ntimesteps - 1 if self.start > self.end: #Backward self.mod_seed.nff = 2 self.mod_time.intstep = -1 tm.mod_time.intstart = self.ntimesteps tm.mod_time.intend = 0 else: #Forward tm.mod_time.intstep = 1 tm.mod_seed.nff = 1 tm.mod_time.intstart = 0 tm.mod_time.intend = self.ntimesteps tm.mod_grid.kmt[:] = tm.mod_param.km if tm.mod_seed.nqua == 1: # number of trajectories (per time resolution) # num=NTRACMAX tm.mod_seed.num = tm.mod_param.partquant elif tm.mod_seed.nqua == 2: tm.mod_param.voltr = tm.mod_param.partquant elif tm.mod_seed.nqua == 3: tm.mod_param.voltr = tm.mod_param.partquant tm.mod_grid.kmt[:] = tm.mod_param.km tm.mod_time.intspin = 1 tm.mod_seed.idir = 0 tm.allocate_seed(seed_locations.shape[0]) tm.mod_seed.isec = 5 tm.mod_seed.seed_ijk[:, :] = 2 tm.mod_seed.seed_xyz[:, :] = seed_locations tm.mod_seed.seed_set[:] = [tm.mod_seed.isec, tm.mod_seed.idir] self.trajectory = [list() for _ in range(seed_locations.shape[0])]
def main(): parser = ArgumentParser() parser.add_argument('-r', '--run-params', type=FileType('r')) parser.add_argument('-g', '--grid-params', type=FileType('r')) parser.add_argument('-s', '--set', nargs=2, action='append') parser.add_argument('--seed') parser.add_argument('--exit') parser.add_argument('--path') parser.add_argument('--start') parser.add_argument('--end') parser.add_argument('--delta-hours') parser.add_argument('--delta-minutes') parser.add_argument('--delta-seconds') parser.add_argument('--print-state', action='store_true') args = parser.parse_args() read_params(args.run_params) read_params(args.grid_params) tm.init_params2() tm.coordinat() setup() tm.mod_grid.kmt[:] = tm.mod_param.km tm.allocate_seed(1) tm.mod_seed.isec = 5 tm.mod_seed.seed_ijk[:,:] = 2 tm.mod_seed.seed_xyz[:,:] = [[9.125, 49.125, 4.5]] tm.mod_seed.seed_set[:] = [tm.mod_seed.isec, tm.mod_seed.idir] if args.print_state: print_state() return print tm.mod_traj.trj.shape print tm.mod_traj.trj[:1,:] def writedata(*args): print tm.mod_traj.trj[:1,:] print tm.writedata2(*args) tm.loop.writedata = tm.writedata2 tm.loop.readfields = tm.tes_readfields tm.loop() print "Done!"
def main(): tm.init_params() tm.coordinat() writesetup() print 'tm.time.intmin', tm.mod_time.intmin print 'tm.time.intmax', tm.mod_time.intmax if tm.mod_seed.nff == 1: #Forward print "Forward" tm.mod_time.intstart = tm.mod_time.intmin tm.mod_time.intend = tm.mod_time.intmax else: #Backward print "Backward" tm.mod_time.intstart = tm.mod_time.intmin tm.mod_time.intend = tm.mod_time.intmax print "tm.time.intstart", tm.mod_time.intstart print "tm.time.intend", tm.mod_time.intend tm.init_seed() filename = abspath(join(curdir, 'results-old', 'data')) print "filename", filename print "tm.mod_seed.nqua", tm.mod_seed.nqua if tm.mod_seed.nqua == 1: # number of trajectories (per time resolution) # num=NTRACMAX print "tm.params.part_quant", tm.mod_param.partquant, tm.mod_seed.num tm.mod_seed.num = tm.mod_param.partquant elif tm.mod_seed.nqua == 2: tm.mod_param.voltr = tm.mod_param.partquant elif tm.mod_seed.nqua == 3: tm.mod_param.voltr = tm.mod_param.partquant tm.fortran_file(56, filename + '_run.asc') # trajectory path tm.fortran_file(57, filename + '_out.asc') # exit position tm.fortran_file(58, filename + '_in.asc') # entrance position tm.fortran_file(59, filename + '_err.asc') # Error position tm.loop.readfields = readfields print_state() # tm.loop() print "Done!"
def readfields(self): """ Robert focus your effort here. You must access and set the uflux and vflux variables. """ # Here are the relevant fortran modules. Static variables are contained within param = tm.mod_param time = tm.mod_time grid = tm.mod_grid vel = tm.mod_vel FIXME_AREA = 1000000 if time.ints == time.intstart: print time.ints vel.hs[:] = 0 print vel.uflux.shape print vel.vflux.shape print self.u.shape print self.v.shape vel.uflux[:] = 0 vel.vflux[:] = 0 vel.uflux[:-1, :, :, 1] = self.u[time.ints].transpose(2, 1, 0) * FIXME_AREA vel.vflux[:, :-2, :, 1] = self.v[time.ints].transpose(2, 1, 0) * FIXME_AREA grid.kmt[:] = param.km tm.coordinat() # Assign vel.uflux[:, :, :, 0] = vel.uflux[:, :, :, 1] vel.vflux[:, :, :, 0] = vel.vflux[:, :, :, 1] vel.uflux[:-1, :, :, 1] = self.u[time.ints].transpose(2, 1, 0) * FIXME_AREA vel.vflux[:, :-2, :, 1] = self.v[time.ints].transpose(2, 1, 0) * FIXME_AREA print "ints", time.ints
def readfields(): param = tm.mod_param coord = tm.mod_coord time = tm.mod_time grid = tm.mod_grid tm.mod_name vel = tm.mod_vel tm.mod_dens tm.tes_readfields() return time.ihour = time.ihour + 6 if time.ihour == 24: time.ihour = 0 time.iday = time.iday + 1 if time.iday > coord.idmax[time.imon-1, time.iyear-1000]: # if time.iday > 30: time.iday = 1 time.imon = time.imon + 1 if time.imon == 13: time.imon = 1 time.iyear = time.iyear + 1 if time.iyear > time.yearmax: time.iyear = time.yearmin # recycle over gcm outputdata # print time.ints, time.intstart # return deg = 6371229.* (math.pi / 180.) if time.ints == time.intstart: print "Init Fields" vel.hs[:] = 0 vel.uflux[:] = 0 vel.vflux[:] = 0 grid.kmt[:] = param.km coord.dxdeg = coord.dx * deg coord.dydeg = coord.dy * deg time.iyear = time.startyear time.imon = time.startmon time.iday = time.startday time.ihour = time.starthour print 'iyear=', time.iyear, time.imon, time.iday, time.ihour, coord.dxdeg, coord.dydeg tm.coordinat() vel.uflux[:, :, :, 0] = vel.uflux[:, :, :, 1] vel.vflux[:, :, :, 0] = vel.vflux[:, :, :, 1] time.ntime = 1000000 * time.iyear + 10000 * time.imon + 100 * time.iday + time.ihour time.omtime = time.ints / 5. + 1. cox = 0.5 + 0.5 * np.cos(time.omtime) coy = 0.5 + 0.5 * np.cos(time.omtime + np.pi) # ! cox = 0.d0 ! stationary uwe = -0.4 dl = time.ints * 0.01 * np.pi ii = np.cos(np.pi * (np.arange(param.imt) - param.imt / 2.) / (param.imt) + dl).reshape([param.imt, 1, 1]) jj = np.sin(-np.pi * (np.arange(param.jmt) - param.jmt / 2.) / (param.jmt)).reshape([1, param.jmt, 1]) vel.uflux[:, :, :, 1] = ((coord.dy * deg * cox * grid.dz) * (ii * jj + (uwe + np.cos(time.omtime)))) ii = np.sin(np.pi * (np.arange(param.imt) - param.imt / 2.) / (param.imt) + dl).reshape([param.imt, 1, 1]) jj = np.cos(np.pi * (np.arange(param.jmt) - param.jmt / 2.) / (param.jmt)).reshape([1, param.jmt, 1]) vel.vflux[:, 1:, :, 1] = ((coord.dx * deg * coy * grid.dz) * (ii * jj + np.sin(time.omtime))) vel.vflux[:, 0, :, :] = 0. vel.vflux[:, param.jmt, :, :] = 0. import pickle pickle.dump(vel.uflux, open('vel.uflux-new.picle', 'w')) return