|
25 | 25 | gridlist_to_disv_gridprops, |
26 | 26 | to_cvfd, |
27 | 27 | ) |
| 28 | +from flopy.utils.gridutil import get_disu_kwargs, get_disv_kwargs |
28 | 29 | from flopy.utils.triangle import Triangle |
29 | 30 | from flopy.utils.voronoi import VoronoiGrid |
30 | 31 |
|
@@ -178,6 +179,92 @@ def test_get_cell_vertices(): |
178 | 179 | mg.get_cell_vertices(nn=0) |
179 | 180 |
|
180 | 181 |
|
| 182 | +def test_structured_grid_get_cell_vertices(): |
| 183 | + """Test StructuredGrid.get_cell_vertices() with various input forms""" |
| 184 | + delr, delc = np.array([10.0] * 3), np.array([10.0] * 4) |
| 185 | + sg = StructuredGrid(delr=delr, delc=delc) |
| 186 | + |
| 187 | + # Test node kwarg |
| 188 | + v1 = sg.get_cell_vertices(node=0) |
| 189 | + expected = [ |
| 190 | + (np.float64(0.0), np.float64(40.0)), |
| 191 | + (np.float64(10.0), np.float64(40.0)), |
| 192 | + (np.float64(10.0), np.float64(30.0)), |
| 193 | + (np.float64(0.0), np.float64(30.0)), |
| 194 | + ] |
| 195 | + assert v1 == expected |
| 196 | + |
| 197 | + # Test positional args (i, j) |
| 198 | + v2 = sg.get_cell_vertices(3, 0) |
| 199 | + |
| 200 | + # Test cellid as tuple (i, j) |
| 201 | + v3 = sg.get_cell_vertices((3, 0)) |
| 202 | + assert v2 == v3, "Positional and tuple forms should match" |
| 203 | + |
| 204 | + # Test cellid as 3-element tuple (layer, i, j) - layer ignored |
| 205 | + v4 = sg.get_cell_vertices(cellid=(0, 3, 0)) |
| 206 | + assert v2 == v4, "2-element and 3-element forms should match" |
| 207 | + |
| 208 | + # Test named i, j kwargs (backward compatibility) |
| 209 | + v5 = sg.get_cell_vertices(i=3, j=0) |
| 210 | + assert v2 == v5, "Named i,j should match" |
| 211 | + |
| 212 | + |
| 213 | +def test_vertex_grid_get_cell_vertices(): |
| 214 | + """Test VertexGrid.get_cell_vertices() with various input forms""" |
| 215 | + disv_props = get_disv_kwargs(2, 10, 10, 10.0, 10.0, 100.0, [50.0, 0.0]) |
| 216 | + # Remove nvert which is not needed for VertexGrid constructor |
| 217 | + disv_props.pop("nvert", None) |
| 218 | + vg = VertexGrid(**disv_props) |
| 219 | + |
| 220 | + # Test cell2d index as positional arg |
| 221 | + v1 = vg.get_cell_vertices(5) |
| 222 | + |
| 223 | + # Test (layer, cell2d) tuple - layer ignored for 2D vertices |
| 224 | + v2 = vg.get_cell_vertices((0, 5)) |
| 225 | + assert v1 == v2, "cell2d and (layer, cell2d) should match" |
| 226 | + |
| 227 | + # Test named cellid kwarg |
| 228 | + v3 = vg.get_cell_vertices(cellid=5) |
| 229 | + assert v1 == v3, "Positional and kwarg should match" |
| 230 | + |
| 231 | + # Test node number (>= ncpl, should be converted to cell2d) |
| 232 | + # Node 105 = layer 1, cell2d 5 (ncpl=100) |
| 233 | + v4 = vg.get_cell_vertices(node=105) |
| 234 | + |
| 235 | + # Verify it's the same as (1, 5) |
| 236 | + v5 = vg.get_cell_vertices((1, 5)) |
| 237 | + assert v4 == v5, "Node and (layer, cell2d) should match" |
| 238 | + |
| 239 | + |
| 240 | +def test_unstructured_grid_get_cell_vertices(): |
| 241 | + """Test UnstructuredGrid.get_cell_vertices() with various input forms""" |
| 242 | + disu_props = get_disu_kwargs( |
| 243 | + 1, 10, 10, 10.0, 10.0, 100.0, [0.0], return_vertices=True |
| 244 | + ) |
| 245 | + # Extract only the parameters needed for UnstructuredGrid |
| 246 | + ug = UnstructuredGrid( |
| 247 | + vertices=disu_props["vertices"], |
| 248 | + cell2d=disu_props["cell2d"], |
| 249 | + top=disu_props["top"], |
| 250 | + ) |
| 251 | + |
| 252 | + # Test node as positional arg |
| 253 | + v1 = ug.get_cell_vertices(5) |
| 254 | + |
| 255 | + # Test (node,) single-element tuple |
| 256 | + v2 = ug.get_cell_vertices((5,)) |
| 257 | + assert v1 == v2, "Int and tuple forms should match" |
| 258 | + |
| 259 | + # Test node kwarg |
| 260 | + v3 = ug.get_cell_vertices(node=5) |
| 261 | + assert v1 == v3, "cellid and node should match" |
| 262 | + |
| 263 | + # Test cellid kwarg |
| 264 | + v4 = ug.get_cell_vertices(cellid=5) |
| 265 | + assert v1 == v4, "Positional and kwarg should match" |
| 266 | + |
| 267 | + |
181 | 268 | def test_get_lrc_get_node(): |
182 | 269 | nlay, nrow, ncol = 3, 4, 5 |
183 | 270 | nnodes = nlay * nrow * ncol |
|
0 commit comments