OpenDrift / opendrift

Open source framework for ocean trajectory modelling
https://opendrift.github.io
GNU General Public License v2.0
249 stars 120 forks source link

how to set 'ocean_vertical_diffusivity' to a constant value #389

Closed simonweppe closed 3 years ago

simonweppe commented 4 years ago

Hi team,

In some applications, I need to set 'ocean_vertical_diffusivity' to a constant value. I used to do something like this : o.set_config('vertical_mixing:diffusivitymodel', 'environment') o.fallback_values['ocean_vertical_diffusivity'] = 0.001 # m2/s It did the trick, but since this new commit https://github.com/OpenDrift/opendrift/commit/c59f8dde68e2c2effb2d7400433d26fb9ff818e3 (I think), the model now switches to Large1994 instead, since that bit below becomes false.

'ocean_vertical_diffusivity' in self.environment_profiles and self.environment_profiles['ocean_vertical_diffusivity'].min() != self.fallback_values['ocean_vertical_diffusivity'] or self.environment_profiles['ocean_vertical_diffusivity'].max() != self.fallback_values['ocean_vertical_diffusivity']:

Maybe an option to retain that feature would be to set the default 'ocean_vertical_diffusivity' to 0 ? and check if self.environment_profiles['ocean_vertical_diffusivity'].min() !=0 rather than fall back ? It does mean that the fallback will be zero if it is not specified otherwise by user, which may not be ideal. Other option would be to have a diffusivity_model = 'constant', which then would always use the fallback ?

Let me know which approach seems best to you and I could make small pull request for that.

knutfrode commented 4 years ago

I agree, the logic here is not too logical. But yes, the idea behind that change was that if one uses o.set_config('vertical_mixing:diffusivitymodel', 'environment') and there are no readers to provide diffusivity (often the case), then it would be better to use a parameterisation based on wind (eg. Large1994) than a constant fallback value. Thus Large1994 is set to override fallback_values if environment is chosen and diffusivity is missing for all particles. But of course, this behaviour might not be always desired.

Yes, maybe another option diffusivity_model = 'constant' would be useful. You are welcome to make a pull request, otherwise I can anyway implement this change tomorrow.

Note btw that the mixing scheme was greatly simplified yesterday, and I expect this to be quite a bit faster for cases with many particles, where mixing might be a bottleneck comparable to obtaining data from readers. https://github.com/OpenDrift/opendrift/pull/388/files

simonweppe commented 4 years ago

Hi Knut - Thanks, I've just made one pull request for this, but feel free to re-arrange if you like.

And great for the vertical_mixing() simplififcation, indeed saving a lot of lines !


From: Knut-Frode Dagestad notifications@github.com Sent: Wednesday, October 7, 2020 10:56 AM To: OpenDrift/opendrift opendrift@noreply.github.com Cc: simonweppe simon@metocean.co.nz; Author author@noreply.github.com Subject: Re: [OpenDrift/opendrift] how to set 'ocean_vertical_diffusivity' to a constant value (#389)

I agree, the logic here is not too logical. But yes, the idea behind that change was that if one uses o.set_config('vertical_mixing:diffusivitymodel', 'environment') and there are no readers to provide diffusivity (often the case), then it would be better to use a parameterisation based on wind (eg. Large1994) than a constant fallback value. Thus Large1994 is set to override fallback_values if environment is chosen and diffusivity is missing for all particles. But of course, this behaviour might not be always desired.

Yes, maybe another option diffusivity_model = 'constant' would be useful. You are welcome to make a pull request, otherwise I can anyway implement this change tomorrow.

Note btw that the mixing scheme was greatly simplified yesterday, and I expect this to be quite a bit faster for cases with many particles, where mixing might be a bottleneck comparable to obtaining data from readers. https://github.com/OpenDrift/opendrift/pull/388/files

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/OpenDrift/opendrift/issues/389#issuecomment-704574419, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABXQTU6EGOAVGPIRDZ4IRBTSJOHAXANCNFSM4SFVQ4DQ.

gauteh commented 3 years ago

Closing, solved.