|
| 1 | +import mpas_tools.mesh.creation.mesh_definition_tools as mdt |
| 2 | +import numpy as np |
| 3 | +from geometric_features import read_feature_collection |
| 4 | +from mpas_tools.cime.constants import constants |
| 5 | +from mpas_tools.mesh.creation.signed_distance import ( |
| 6 | + signed_distance_from_geojson, |
| 7 | +) |
| 8 | + |
| 9 | +from compass.mesh import QuasiUniformSphericalMeshStep |
| 10 | + |
| 11 | + |
| 12 | +class FRIS01to60BaseMesh(QuasiUniformSphericalMeshStep): |
| 13 | + """ |
| 14 | + A step for creating SO12to60 meshes |
| 15 | + """ |
| 16 | + def setup(self): |
| 17 | + """ |
| 18 | + Add some input files |
| 19 | + """ |
| 20 | + |
| 21 | + self.add_input_file(filename='atlantic.geojson', |
| 22 | + package=self.__module__) |
| 23 | + |
| 24 | + self.add_input_file(filename='high_res_region.geojson', |
| 25 | + package=self.__module__) |
| 26 | + |
| 27 | + self.add_input_file(filename='fris_v1_transition.geojson', |
| 28 | + package=self.__module__) |
| 29 | + |
| 30 | + self.add_input_file(filename='fris_v1_peninsula_12km_v2.geojson', |
| 31 | + package=self.__module__) |
| 32 | + |
| 33 | + self.add_input_file( |
| 34 | + filename='fris_v1_peninsula_12km_transition.geojson', |
| 35 | + package=self.__module__) |
| 36 | + |
| 37 | + self.add_input_file(filename='fris_v1.geojson', |
| 38 | + package=self.__module__) |
| 39 | + |
| 40 | + super().setup() |
| 41 | + |
| 42 | + def build_cell_width_lat_lon(self): |
| 43 | + """ |
| 44 | + Create cell width array for this mesh on a regular latitude-longitude |
| 45 | + grid |
| 46 | +
|
| 47 | + Returns |
| 48 | + ------- |
| 49 | + cellWidth : numpy.array |
| 50 | + m x n array of cell width in km |
| 51 | +
|
| 52 | + lon : numpy.array |
| 53 | + longitude in degrees (length n and between -180 and 180) |
| 54 | +
|
| 55 | + lat : numpy.array |
| 56 | + longitude in degrees (length m and between -90 and 90) |
| 57 | + """ |
| 58 | + |
| 59 | + dlon = 0.1 |
| 60 | + dlat = dlon |
| 61 | + earth_radius = constants['SHR_CONST_REARTH'] |
| 62 | + nlon = int(360. / dlon) + 1 |
| 63 | + nlat = int(180. / dlat) + 1 |
| 64 | + lon = np.linspace(-180., 180., nlon) |
| 65 | + lat = np.linspace(-90., 90., nlat) |
| 66 | + |
| 67 | + cellWidthSouth = mdt.EC_CellWidthVsLat(lat, cellWidthEq=30., |
| 68 | + cellWidthMidLat=45., |
| 69 | + cellWidthPole=45., |
| 70 | + latPosEq=7.5, latWidthEq=3.0) |
| 71 | + |
| 72 | + cellWidthNorth = mdt.EC_CellWidthVsLat(lat, cellWidthEq=30., |
| 73 | + cellWidthMidLat=60., |
| 74 | + cellWidthPole=35., |
| 75 | + latPosEq=7.5, latWidthEq=3.0) |
| 76 | + |
| 77 | + # Transition at Equator |
| 78 | + latTransition = 0.0 |
| 79 | + latWidthTransition = 2.5 |
| 80 | + cellWidthVsLat = mdt.mergeCellWidthVsLat( |
| 81 | + lat, |
| 82 | + cellWidthSouth, |
| 83 | + cellWidthNorth, |
| 84 | + latTransition, |
| 85 | + latWidthTransition) |
| 86 | + |
| 87 | + _, cellWidth = np.meshgrid(lon, cellWidthVsLat) |
| 88 | + |
| 89 | + cellWidthAtlantic = mdt.EC_CellWidthVsLat(lat, cellWidthEq=30., |
| 90 | + cellWidthMidLat=30., |
| 91 | + cellWidthPole=35., |
| 92 | + latPosEq=7.5, latWidthEq=3.0) |
| 93 | + |
| 94 | + cellWidthAtlantic = mdt.mergeCellWidthVsLat( |
| 95 | + lat, |
| 96 | + cellWidthSouth, |
| 97 | + cellWidthAtlantic, |
| 98 | + latTransition, |
| 99 | + latWidthTransition) |
| 100 | + |
| 101 | + _, cellWidthAtlantic = np.meshgrid(lon, cellWidthAtlantic) |
| 102 | + |
| 103 | + fc = read_feature_collection('atlantic.geojson') |
| 104 | + |
| 105 | + atlantic_signed_distance = signed_distance_from_geojson( |
| 106 | + fc, lon, lat, earth_radius, max_length=0.25) |
| 107 | + |
| 108 | + trans_width = 400e3 |
| 109 | + trans_start = 0. |
| 110 | + weights = 0.5 * (1 + np.tanh((atlantic_signed_distance - trans_start) / |
| 111 | + trans_width)) |
| 112 | + |
| 113 | + cellWidth = cellWidthAtlantic * (1 - weights) + cellWidth * weights |
| 114 | + |
| 115 | + fc = read_feature_collection('high_res_region.geojson') |
| 116 | + |
| 117 | + so_signed_distance = signed_distance_from_geojson(fc, lon, lat, |
| 118 | + earth_radius, |
| 119 | + max_length=0.25) |
| 120 | + |
| 121 | + # Equivalent to 20 degrees latitude |
| 122 | + trans_width = 1600e3 |
| 123 | + trans_start = 500e3 |
| 124 | + dx_min = 12. |
| 125 | + |
| 126 | + weights = 0.5 * (1 + np.tanh((so_signed_distance - trans_start) / |
| 127 | + trans_width)) |
| 128 | + |
| 129 | + cellWidth = dx_min * (1 - weights) + cellWidth * weights |
| 130 | + |
| 131 | + # Add high res FRIS region transition |
| 132 | + dx_min_fris = 1. # minimum resolution within the FRIS cavity |
| 133 | + |
| 134 | + fc = read_feature_collection('fris_v1_transition.geojson') |
| 135 | + |
| 136 | + so_signed_distance = signed_distance_from_geojson(fc, lon, lat, |
| 137 | + earth_radius, |
| 138 | + max_length=0.25) |
| 139 | + |
| 140 | + # Equivalent to 600 km |
| 141 | + trans_width = 600e3 |
| 142 | + trans_start = 0 |
| 143 | + dx_min = dx_min_fris |
| 144 | + |
| 145 | + weights = 0.5 * (1 + np.tanh((so_signed_distance - trans_start) / |
| 146 | + trans_width)) |
| 147 | + |
| 148 | + cellWidth = dx_min * (1 - weights) + cellWidth * weights |
| 149 | + |
| 150 | + # Add 12 km sharp correction west of the peninsula |
| 151 | + fc = read_feature_collection('fris_v1_peninsula_12km_v2.geojson') |
| 152 | + |
| 153 | + so_signed_distance = signed_distance_from_geojson(fc, lon, lat, |
| 154 | + earth_radius, |
| 155 | + max_length=0.25) |
| 156 | + |
| 157 | + # Equivalent to 10 km |
| 158 | + trans_width = 10e3 |
| 159 | + trans_start = 0 |
| 160 | + dx_min = 12. |
| 161 | + |
| 162 | + weights = 0.5 * (1 + np.tanh((so_signed_distance - trans_start) / |
| 163 | + trans_width)) |
| 164 | + |
| 165 | + cellWidth = dx_min * (1 - weights) + cellWidth * weights |
| 166 | + |
| 167 | + # Add 12 km transition correction west of the peninsula |
| 168 | + fc = read_feature_collection( |
| 169 | + 'fris_v1_peninsula_12km_transition.geojson') |
| 170 | + |
| 171 | + so_signed_distance = signed_distance_from_geojson(fc, lon, lat, |
| 172 | + earth_radius, |
| 173 | + max_length=0.25) |
| 174 | + |
| 175 | + # Equivalent to 150 km |
| 176 | + trans_width = 150e3 |
| 177 | + trans_start = 0 |
| 178 | + dx_min = 12. |
| 179 | + |
| 180 | + weights = 0.5 * (1 + np.tanh((so_signed_distance - trans_start) / |
| 181 | + trans_width)) |
| 182 | + |
| 183 | + cellWidth = dx_min * (1 - weights) + cellWidth * weights |
| 184 | + |
| 185 | + # Add high res FRIS region inner |
| 186 | + fc = read_feature_collection('fris_v1.geojson') |
| 187 | + |
| 188 | + so_signed_distance = signed_distance_from_geojson(fc, lon, lat, |
| 189 | + earth_radius, |
| 190 | + max_length=0.25) |
| 191 | + |
| 192 | + # Equivalent to 100 km (0 should be enough given the setup but to be |
| 193 | + # safe) |
| 194 | + trans_width = 100e3 |
| 195 | + trans_start = 0 |
| 196 | + dx_min = dx_min_fris |
| 197 | + |
| 198 | + weights = 0.5 * (1 + np.tanh((so_signed_distance - trans_start) / |
| 199 | + trans_width)) |
| 200 | + |
| 201 | + cellWidth = dx_min * (1 - weights) + cellWidth * weights |
| 202 | + |
| 203 | + return cellWidth, lon, lat |
0 commit comments