.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/example_vertical_mixing.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_gallery_example_vertical_mixing.py: Vertical mixing =============== .. GENERATED FROM PYTHON SOURCE LINES 6-11 .. code-block:: Python import numpy as np from datetime import datetime, timedelta from opendrift.models.oceandrift import OceanDrift .. GENERATED FROM PYTHON SOURCE LINES 12-13 Configuration. Edit this section to see the differences. .. GENERATED FROM PYTHON SOURCE LINES 13-29 .. code-block:: Python N = 10000 # Number of particles seed_depth = -10 # meters hours = 2 # Number of hours to mix particles sea_floor_depth = 100 # m timestep_seconds = 60 # Timestep for vertical mixing terminal_velocity = 0 # Neutral particles #terminal_velocity = 0.005 # Rising particles #terminal_velocity = -0.005 # Sinking particles # Profile of diffusivities z = np.arange(0, -40, -1) diffusivity = np.ones(z.shape)*.01 # Constant diffusivity diffusivity[z<-20] = 0.001 # uncomment to reduce mixing below 20m .. GENERATED FROM PYTHON SOURCE LINES 30-31 Preparing mixing timestep .. GENERATED FROM PYTHON SOURCE LINES 31-50 .. code-block:: Python time = datetime(2020, 1, 1, 0) o = OceanDrift(loglevel=20) o.set_config('drift:vertical_mixing', True) o.set_config('vertical_mixing:diffusivitymodel', 'environment') o.set_config('vertical_mixing:timestep', timestep_seconds) o.set_config('environment:fallback:land_binary_mask', 0) o.seed_elements(lon=4, lat=60, z=seed_depth, time=time, number=N, terminal_velocity=terminal_velocity) o.time = time o.time_step = timedelta(hours=hours) o.release_elements() o.environment = np.array(list(zip(np.ones(N)*sea_floor_depth, np.zeros(N))), dtype=[('sea_floor_depth_below_sea_level', np.float32), ('sea_surface_height', np.float32)]).view(np.recarray) o.environment.ocean_mixed_layer_thickness = np.ones(N)*50 o.environment_profiles = { 'z': z, 'ocean_vertical_diffusivity': np.tile(diffusivity, (N, 1)).T} .. rst-class:: sphx-glr-script-out .. code-block:: none 11:35:58 INFO opendrift.models.basemodel:533: OpenDriftSimulation initialised (version 1.11.2 / v1.11.2-30-g8806683) 11:35:58 INFO opendrift.models.basemodel.environment:218: Adding a dynamical landmask with max. priority based on assumed maximum speed of 1.0 m/s. Adding a customised landmask may be faster... 11:36:03 INFO opendrift.models.basemodel.environment:245: Fallback values will be used for the following variables which have no readers: 11:36:03 INFO opendrift.models.basemodel.environment:248: x_sea_water_velocity: 0.000000 11:36:03 INFO opendrift.models.basemodel.environment:248: y_sea_water_velocity: 0.000000 11:36:03 INFO opendrift.models.basemodel.environment:248: sea_surface_height: 0.000000 11:36:03 INFO opendrift.models.basemodel.environment:248: x_wind: 0.000000 11:36:03 INFO opendrift.models.basemodel.environment:248: y_wind: 0.000000 11:36:03 INFO opendrift.models.basemodel.environment:248: upward_sea_water_velocity: 0.000000 11:36:03 INFO opendrift.models.basemodel.environment:248: ocean_vertical_diffusivity: 0.000000 11:36:03 INFO opendrift.models.basemodel.environment:248: sea_surface_wave_significant_height: 0.000000 11:36:03 INFO opendrift.models.basemodel.environment:248: sea_surface_wave_stokes_drift_x_velocity: 0.000000 11:36:03 INFO opendrift.models.basemodel.environment:248: sea_surface_wave_stokes_drift_y_velocity: 0.000000 11:36:03 INFO opendrift.models.basemodel.environment:248: sea_surface_wave_period_at_variance_spectral_density_maximum: 0.000000 11:36:03 INFO opendrift.models.basemodel.environment:248: sea_surface_wave_mean_period_from_variance_spectral_density_second_frequency_moment: 0.000000 11:36:03 INFO opendrift.models.basemodel.environment:248: sea_surface_swell_wave_to_direction: 0.000000 11:36:03 INFO opendrift.models.basemodel.environment:248: sea_surface_swell_wave_peak_period_from_variance_spectral_density: 0.000000 11:36:03 INFO opendrift.models.basemodel.environment:248: sea_surface_swell_wave_significant_height: 0.000000 11:36:03 INFO opendrift.models.basemodel.environment:248: sea_surface_wind_wave_to_direction: 0.000000 11:36:03 INFO opendrift.models.basemodel.environment:248: sea_surface_wind_wave_mean_period: 0.000000 11:36:03 INFO opendrift.models.basemodel.environment:248: sea_surface_wind_wave_significant_height: 0.000000 11:36:03 INFO opendrift.models.basemodel.environment:248: surface_downward_x_stress: 0.000000 11:36:03 INFO opendrift.models.basemodel.environment:248: surface_downward_y_stress: 0.000000 11:36:03 INFO opendrift.models.basemodel.environment:248: turbulent_kinetic_energy: 0.000000 11:36:03 INFO opendrift.models.basemodel.environment:248: turbulent_generic_length_scale: 0.000000 11:36:03 INFO opendrift.models.basemodel.environment:248: ocean_mixed_layer_thickness: 50.000000 11:36:03 INFO opendrift.models.basemodel.environment:248: sea_floor_depth_below_sea_level: 10000.000000 .. GENERATED FROM PYTHON SOURCE LINES 51-52 Calculate vertical mixing, and return particle depths at all positions .. GENERATED FROM PYTHON SOURCE LINES 52-58 .. code-block:: Python print('Calculating...') depths = o.vertical_mixing(store_depths=True) print('Making animation...') o.animate_vertical_distribution(depths=depths) .. rst-class:: sphx-glr-script-out .. code-block:: none Calculating... Making animation... 11:36:04 INFO opendrift.models.basemodel:4563: Saving animation to /root/project/docs/source/gallery/animations/example_vertical_mixing_0.gif... 11:36:20 INFO opendrift.models.oceandrift:722: Time to make animation: 0:00:16.519617 .. GENERATED FROM PYTHON SOURCE LINES 59-60 .. image:: /gallery/animations/example_vertical_mixing_0.gif .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 23.503 seconds) .. _sphx_glr_download_gallery_example_vertical_mixing.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: example_vertical_mixing.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: example_vertical_mixing.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_