|
| 1 | +from polaris.config import PolarisConfigParser |
| 2 | +from polaris.ocean.resolution import resolution_to_subdir |
| 3 | +from polaris.tasks.ocean.drying_slope.baroclinic import Baroclinic |
| 4 | +from polaris.tasks.ocean.drying_slope.barotropic import Barotropic |
| 5 | +from polaris.tasks.ocean.drying_slope.convergence import Convergence |
| 6 | +from polaris.tasks.ocean.drying_slope.decomp import Decomp |
| 7 | +from polaris.tasks.ocean.drying_slope.init import Init |
| 8 | + |
| 9 | + |
| 10 | +def add_drying_slope_tasks(component): |
| 11 | + """ |
| 12 | + Add tasks for different drying slope tests to the ocean component |
| 13 | +
|
| 14 | + component : polaris.ocean.Ocean |
| 15 | + the ocean component that the tasks will be added to |
| 16 | + """ |
| 17 | + config_filename = 'drying_slope.cfg' |
| 18 | + |
| 19 | + for coord_type in ['sigma', 'single_layer']: |
| 20 | + group_dir = f'planar/drying_slope/{coord_type}' |
| 21 | + |
| 22 | + # The config file lives in the coord_type directory because |
| 23 | + # config options change between coordinate types |
| 24 | + config = PolarisConfigParser(filepath=f'{group_dir}/{config_filename}') |
| 25 | + config.add_from_package('polaris.ocean.convergence', 'convergence.cfg') |
| 26 | + config.add_from_package( |
| 27 | + 'polaris.ocean.tasks.drying_slope', config_filename |
| 28 | + ) |
| 29 | + if coord_type == 'single_layer': |
| 30 | + config.set( |
| 31 | + 'vertical_grid', |
| 32 | + 'vert_levels', |
| 33 | + '1', |
| 34 | + comment='Number of vertical levels', |
| 35 | + ) |
| 36 | + config.set('vertical_grid', 'coord_type', 'z-level') |
| 37 | + else: |
| 38 | + config.set('vertical_grid', 'coord_type', 'sigma') |
| 39 | + |
| 40 | + case_dir = f'{group_dir}/barotropic' |
| 41 | + for resolution in [0.25, 1.0]: |
| 42 | + resdir = resolution_to_subdir(resolution) |
| 43 | + indir = f'{case_dir}/{resdir}' |
| 44 | + |
| 45 | + # Add one init step per resolution in barotropic |
| 46 | + init_dir = f'{indir}/init' |
| 47 | + if init_dir in component.steps: |
| 48 | + init = component.steps[init_dir] |
| 49 | + else: |
| 50 | + init = Init( |
| 51 | + component=component, |
| 52 | + resolution=resolution, |
| 53 | + name=f'init_{resdir}', |
| 54 | + subdir=init_dir, |
| 55 | + baroclinic=False, |
| 56 | + ) |
| 57 | + init.set_shared_config(config, link=config_filename) |
| 58 | + |
| 59 | + for method in ['standard', 'ramp']: |
| 60 | + if coord_type == 'single_layer': |
| 61 | + default = Barotropic( |
| 62 | + component=component, |
| 63 | + resolution=resolution, |
| 64 | + subdir=f'{indir}/{method}', |
| 65 | + init=init, |
| 66 | + method=method, |
| 67 | + coord_type=coord_type, |
| 68 | + drag_type='constant', |
| 69 | + ) |
| 70 | + else: |
| 71 | + default = Barotropic( |
| 72 | + component=component, |
| 73 | + resolution=resolution, |
| 74 | + subdir=f'{indir}/{method}', |
| 75 | + init=init, |
| 76 | + method=method, |
| 77 | + coord_type=coord_type, |
| 78 | + ) |
| 79 | + default.set_shared_config(config, link=config_filename) |
| 80 | + component.add_task(default) |
| 81 | + |
| 82 | + if method == 'ramp': |
| 83 | + loglaw = Barotropic( |
| 84 | + component=component, |
| 85 | + resolution=resolution, |
| 86 | + subdir=f'{indir}/{method}', |
| 87 | + init=init, |
| 88 | + method=method, |
| 89 | + drag_type='loglaw', |
| 90 | + coord_type=coord_type, |
| 91 | + ) |
| 92 | + loglaw.set_shared_config(config, link=config_filename) |
| 93 | + component.add_task(loglaw) |
| 94 | + |
| 95 | + if ( |
| 96 | + method == 'ramp' |
| 97 | + and resolution == 1.0 |
| 98 | + and coord_type == 'sigma' |
| 99 | + ): |
| 100 | + decomp = Decomp( |
| 101 | + component=component, |
| 102 | + resolution=resolution, |
| 103 | + indir=indir, |
| 104 | + init=init, |
| 105 | + method=method, |
| 106 | + coord_type=coord_type, |
| 107 | + ) |
| 108 | + decomp.set_shared_config(config, link=config_filename) |
| 109 | + component.add_task(decomp) |
| 110 | + |
| 111 | + # Add convergence test only for sigma coordinate |
| 112 | + if coord_type == 'sigma': |
| 113 | + method = 'ramp' |
| 114 | + task_dir = f'{case_dir}/convergence/{method}' |
| 115 | + convergence = Convergence( |
| 116 | + component=component, |
| 117 | + subdir=task_dir, |
| 118 | + group_dir=group_dir, |
| 119 | + config=config, |
| 120 | + method=method, |
| 121 | + ) |
| 122 | + convergence.set_shared_config(config, link=config_filename) |
| 123 | + component.add_task(convergence) |
| 124 | + |
| 125 | + if coord_type != 'single_layer': |
| 126 | + case_dir = f'{group_dir}/baroclinic' |
| 127 | + forcing_type = 'linear_drying' |
| 128 | + resolution = 1.0 |
| 129 | + resdir = resolution_to_subdir(resolution) |
| 130 | + indir = f'{case_dir}/{resdir}' |
| 131 | + method = 'ramp' |
| 132 | + |
| 133 | + # Create a new initial condition for the baroclinic case |
| 134 | + init = Init( |
| 135 | + component=component, |
| 136 | + indir=indir, |
| 137 | + resolution=resolution, |
| 138 | + baroclinic=True, |
| 139 | + ) |
| 140 | + init.set_shared_config(config, link=config_filename) |
| 141 | + |
| 142 | + baroclinic = Baroclinic( |
| 143 | + component=component, |
| 144 | + resolution=resolution, |
| 145 | + init=init, |
| 146 | + subdir=f'{indir}/{method}', |
| 147 | + coord_type=coord_type, |
| 148 | + method=method, |
| 149 | + forcing_type=forcing_type, |
| 150 | + ) |
| 151 | + baroclinic.set_shared_config(config, link=config_filename) |
| 152 | + component.add_task(baroclinic) |
0 commit comments