Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Formula for vertical levels? #53

Closed
navidcy opened this issue Jun 22, 2023 · 5 comments · Fixed by #106
Closed

Formula for vertical levels? #53

navidcy opened this issue Jun 22, 2023 · 5 comments · Fixed by #106
Labels
question ❓ Further information is requested

Comments

@navidcy
Copy link
Contributor

navidcy commented Jun 22, 2023

Are the vertical levels here defined recursively?

def dz(npoints, ratio, target_depth, min_dz=0.0001, tolerance=1):
"""Generate a hyperbolic tangent thickness profile for the
experiment. Iterates to find the mininum depth value which gives
the target depth within some tolerance
Args:
npoints (int): Number of vertical points
ratio (float): Ratio of largest to smallest layer
thickness. Negative values mean higher resolution is at
bottom rather than top of the column.
target_depth (float): Maximum depth of a layer
min_dz (float): Starting layer thickness for iteration
tolerance (float): Tolerance to the target depth.
Returns:
numpy.array: An array containing the thickness profile.
"""
profile = min_dz + 0.5 * (np.abs(ratio) * min_dz - min_dz) * (
1 + np.tanh(2 * np.pi * (np.arange(npoints) - npoints // 2) / npoints)
)
tot = np.sum(profile)
if np.abs(tot - target_depth) < tolerance:
if ratio > 0:
return profile
return profile[::-1]
err_ratio = target_depth / tot
return dz(npoints, ratio, target_depth, min_dz * err_ratio)

And maximum rate of change of the vertical spacing occurs at the mid-depth (exactly)?

@navidcy navidcy added the question ❓ Further information is requested label Jun 22, 2023
@navidcy
Copy link
Contributor Author

navidcy commented Jun 23, 2023

cc @kialstewart

@navidcy
Copy link
Contributor Author

navidcy commented Jun 23, 2023

note to self after chatting w @kialstewart: 10.1016/j.ocemod.2017.03.012 might be relevant; see section 2

@ashjbarnes
Copy link
Collaborator

Ok so I took Kial's formula, but modified it so that the free parameter is different. From memory I think you give it number of layers, depth, ratio of the biggest to smallest ratio and then it chooses where to place the first layer.

Vertical levels aren't defined recursively, but the equation is solved by recursively searching for the solution. After I wrote this code I realised that you can solve it directly but it worked and apparently I never bothered changing it.

@ashjbarnes
Copy link
Collaborator

What would resolve this @navidcy? This is the vertical coordinate that I use for my experiments and so currently is the only one implemented. Future updates will implement more grid generation options - see issue #69 so this one isn't intended to be perfect or one size fits all

@navidcy
Copy link
Contributor Author

navidcy commented Dec 17, 2023

A description in the docstring explaining how these levels are computed?

My problem wasn't that it wasn't as generic as possible. My main issue was that I couldn't understand what was happening.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question ❓ Further information is requested
Projects
None yet
2 participants