{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Vertical mixing\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import numpy as np\nfrom datetime import datetime, timedelta\nfrom opendrift.models.oceandrift import OceanDrift" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Configuration. Edit this section to see the differences.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "N = 10000 # Number of particles\nseed_depth = -10 # meters\nhours = 2 # Number of hours to mix particles\nsea_floor_depth = 100 # m\ntimestep_seconds = 60 # Timestep for vertical mixing\n\nterminal_velocity = 0 # Neutral particles\n#terminal_velocity = 0.005 # Rising particles\n#terminal_velocity = -0.005 # Sinking particles\n\n# Profile of diffusivities\nz = np.arange(0, -40, -1)\n\ndiffusivity = np.ones(z.shape)*.01 # Constant diffusivity\ndiffusivity[z<-20] = 0.001 # uncomment to reduce mixing below 20m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Preparing mixing timestep\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "time = datetime(2020, 1, 1, 0)\no = OceanDrift(loglevel=20)\no.set_config('drift:vertical_mixing', True)\no.set_config('vertical_mixing:diffusivitymodel', 'environment')\no.set_config('vertical_mixing:timestep', timestep_seconds)\no.set_config('environment:fallback:land_binary_mask', 0)\no.seed_elements(lon=4, lat=60, z=seed_depth, time=time, number=N, terminal_velocity=terminal_velocity)\no.time = time\no.time_step = timedelta(hours=hours)\no.release_elements()\no.environment = np.array(list(zip(np.ones(N)*sea_floor_depth, np.zeros(N))),\n dtype=[('sea_floor_depth_below_sea_level', np.float32),\n ('sea_surface_height', np.float32)]).view(np.recarray)\no.environment.ocean_mixed_layer_thickness = np.ones(N)*50\no.environment_profiles = {\n 'z': z,\n 'ocean_vertical_diffusivity':\n np.tile(diffusivity, (N, 1)).T}" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Calculate vertical mixing, and return particle depths at all positions\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "print('Calculating...')\ndepths = o.vertical_mixing(store_depths=True)\n\nprint('Making animation...')\no.animate_vertical_distribution(depths=depths)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n\n" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.6" } }, "nbformat": 4, "nbformat_minor": 0 }