def get_diffusivity_profile(self, model): depths = self.environment_profiles['z'] wind, depth = np.meshgrid(self.wind_speed(), depths) if model == 'windspeed_Large1994': return verticaldiffusivity_Large1994(wind, depth) elif model == 'windspeed_Sundby1983': return verticaldiffusivity_Sundby1983(wind) elif model == 'gls_tke': if not hasattr(self, 'gls_parameters'): self.logger.info('Searching readers for GLS parameters...') for reader_name, reader in self.readers.items(): if hasattr(reader, 'gls_parameters'): self.gls_parameters = reader.gls_parameters self.logger.info('Found gls-parameters in ' + reader_name) break # Success if not hasattr(self, 'gls_parameters'): self.logger.info('Did not find gls-parameters in any readers.') self.gls_parameters = None windstress = np.sqrt(self.environment.surface_downward_x_stress**2 + self.environment.surface_downward_y_stress**2) return gls_tke(windstress, depth, self.sea_water_density(), self.environment.turbulent_kinetic_energy, self.environment.turbulent_generic_length_scale, gls_parameters) else: raise ValueError('Unknown diffusivity model: ' + model)
def test_vertical_diffusivity(self): windspeeds = np.arange(0, 20, 5) depths = np.arange(0, 80, 5) wind, depth = np.meshgrid(windspeeds, depths) KLarge = verticaldiffusivity_Large1994(wind, depth) KSundby = verticaldiffusivity_Sundby1983(wind, depth) self.assertAlmostEqual(KLarge.min(), 0, 3) self.assertAlmostEqual(KLarge.max(), 0.2017, 3) self.assertAlmostEqual(KSundby.min(), 0, 3) self.assertAlmostEqual(KSundby.max(), 0.0585, 3)
#%% # Plot the depth dependence of vertical diffusivity from the various analytical methods import numpy as np import matplotlib.pyplot as plt from opendrift.models.physics_methods import verticaldiffusivity_Sundby1983, verticaldiffusivity_Large1994, verticaldiffusivity_stepfunction depth = np.linspace(0, 60, 100) windspeed = np.arange(0, 20, 5) colors = ['r', 'g', 'b', 'k'] for w, c in zip(windspeed, colors): plt.plot(np.ones(depth.shape)*verticaldiffusivity_Sundby1983(w, depth, 50), depth, c + '-', label='Sundby, wind = %sm MLD=50' % w) plt.plot(verticaldiffusivity_Large1994(w, depth, 50), depth, c + '--', label='Large, wind = %s, MLD=50' % w) plt.plot(verticaldiffusivity_Large1994(w, depth, 20), depth, c + '-.', label='Large, wind = %s, MLD=20' % w) plt.plot(verticaldiffusivity_stepfunction(depth), depth, '-m', label='Stepfunction') plt.xlabel('Vertical diffusivity [m/s2]') plt.ylabel('Depth [m]') plt.gca().set_ylim([0, depth.max()]) plt.gca().set_xlim([0, None]) plt.gca().invert_yaxis() plt.legend() plt.show()