def run_northsea_mp(outfile, nemo_res='0083', cmems=False, stokes=False, diffusion=0, run3D=False): fieldset = get_nemo_fieldset(nemo_res, run3D) if cmems: set_cmems(fieldset) if stokes: set_stokes(fieldset) if diffusion > 0: set_diffusion(fieldset, diffusion) set_unbeaching(fieldset) pset = get_particle_set(fieldset, run3D) kernel = pset.Kernel(AdvectionRK4_3D) if run3D else pset.Kernel( AdvectionRK4) BeachTesting = BeachTesting_3D if run3D else BeachTesting_2D kernel += pset.Kernel(BeachTesting) + pset.Kernel(UnBeaching) if stokes: kernel += pset.Kernel(StokesDrag) + pset.Kernel(BeachTesting) if diffusion > 0: kernel += pset.Kernel(BrownianMotion2D) + pset.Kernel(BeachTesting) kernel += pset.Kernel(Ageing) pfile = ParticleFile(outfile, pset) pfile.write(pset, pset[0].time) tic = timelib.time() ndays = 365 * 4 + 100 for d in range(ndays / 2): day = 2 * d print('running %d / %d [time %g s]: %d particles ' % (day, ndays, timelib.time() - tic, len(pset))) pset.execute(kernel, runtime=delta(days=2), dt=900, verbose_progress=False, recovery={ErrorCode.ErrorOutOfBounds: DeleteParticle}) pfile.write(pset, pset[0].time)
lonv = np.arange(-6, 10.1, .2) latv = np.arange(50, 63, .2) lon, lat = np.meshgrid(lonv, latv) lon = lon.flatten() lat = lat.flatten() time = time0 * np.ones(lon.shape) pset = ParticleSet.from_list(field_set, JITParticle, lon=lon, lat=lat, time=time) kernel = AdvectionRK4 timer.particlefile = timer.Timer('ParticleFile', parent=timer.root) outfile = __file__[:-3] pfile = ParticleFile(outfile, pset) pfile.write(pset, pset[0].time) timer.particlefile.stop() tic = timelib.time() ndays = 60 timer.run = timer.Timer('Execution', parent=timer.root, start=False) for d in range(ndays): print('running %d / %d: time %g' % (d + 1, ndays, timelib.time() - tic)) timer.run.start() pset.execute( kernel, runtime=86400, dt=900) #, recovery={ErrorCode.ErrorOutOfBounds: DeleteParticle}) timer.run.stop() timer.particlefile.start() pfile.write(pset, pset[0].time) timer.particlefile.stop()