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

added linear dz in vertical grid #724

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions compass/ocean/vertical/grid_1d/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from compass.ocean.vertical.grid_1d.index_tanh_dz import (
create_index_tanh_dz_grid,
)
from compass.ocean.vertical.grid_1d.linear_dz import create_linear_dz_grid
from compass.ocean.vertical.grid_1d.tanh_dz import create_tanh_dz_grid


Expand All @@ -32,6 +33,13 @@ def generate_1d_grid(config):
if grid_type == 'uniform':
vert_levels = section.getint('vert_levels')
interfaces = _generate_uniform(vert_levels)
elif grid_type == 'linear_dz':
vert_levels = section.getint('vert_levels')
bottom_depth = section.getfloat('bottom_depth')
linear_dz_rate = section.getfloat('linear_dz_rate')
interfaces = create_linear_dz_grid(vert_levels,
bottom_depth,
linear_dz_rate)
elif grid_type == 'tanh_dz':
vert_levels = section.getint('vert_levels')
min_layer_thickness = section.getfloat('min_layer_thickness')
Expand Down
38 changes: 38 additions & 0 deletions compass/ocean/vertical/grid_1d/linear_dz.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import numpy
import numpy as np


def create_linear_dz_grid(num_vert_levels, bottom_depth,
linear_dz_rate):
"""
Creates the linear vertical grid for MPAS-Ocean and
writes it to a NetCDF file

Parameters
----------
num_vert_levels : int
Number of vertical levels for the grid

bottom_depth : float
bottom depth for the chosen vertical coordinate [m]

linear_dz_rate : float
rate of layer thickness increase (for linear_dz) [m]

Returns
-------
interfaces : numpy.ndarray
A 1D array of positive depths for layer interfaces in meters
"""

nz = num_vert_levels
layerThickness = [(bottom_depth / nz) - (np.floor(nz / 2) - k) *
linear_dz_rate for k in np.arange(0, nz)]
min_layer_thickness = layerThickness[0]
max_layer_thickness = layerThickness[-1]
print('Linear dz vertical grid')
print(f'min layer thickness: {min_layer_thickness}; '
f'max layer thickness {max_layer_thickness} in m;')
interfaces = - np.append([0], np.cumsum(layerThickness))

return interfaces
Loading