|
8 | 8 | get_disu_kwargs, |
9 | 9 | get_disv_kwargs, |
10 | 10 | get_lni, |
| 11 | + get_shared_face_3d, |
11 | 12 | uniform_flow_field, |
12 | 13 | ) |
13 | 14 |
|
@@ -186,3 +187,207 @@ def test_uniform_flow_field(qx, qy, qz, nlay, nrow, ncol): |
186 | 187 |
|
187 | 188 | # TODO: check flowja |
188 | 189 | # print(flowja.shape) |
| 190 | + |
| 191 | + |
| 192 | +def test_get_shared_face_3d_structured_horizontal(): |
| 193 | + """Test get_shared_face_3d for horizontal barrier in structured grid. |
| 194 | +
|
| 195 | + Tests same layer, adjacent cells. |
| 196 | + """ |
| 197 | + from flopy.discretization import StructuredGrid |
| 198 | + |
| 199 | + # Create a simple 2x2x1 structured grid |
| 200 | + nlay, nrow, ncol = 1, 2, 2 |
| 201 | + delr = np.array([1.0, 1.0]) |
| 202 | + delc = np.array([1.0, 1.0]) |
| 203 | + top = np.array([[10.0, 10.0], [10.0, 10.0]]) |
| 204 | + botm = np.array([[[0.0, 0.0], [0.0, 0.0]]]) |
| 205 | + |
| 206 | + grid = StructuredGrid(delc=delc, delr=delr, top=top, botm=botm) |
| 207 | + |
| 208 | + # Test horizontal barrier between cells (0, 0, 0) and (0, 0, 1) |
| 209 | + # These are horizontally adjacent |
| 210 | + cellid1 = (0, 0, 0) |
| 211 | + cellid2 = (0, 0, 1) |
| 212 | + |
| 213 | + face = get_shared_face_3d(grid, cellid1, cellid2) |
| 214 | + |
| 215 | + assert face is not None |
| 216 | + assert len(face) == 4 # Vertical face should have 4 vertices |
| 217 | + |
| 218 | + # Check that face is vertical (two z-coordinates: top and bottom) |
| 219 | + z_coords = sorted({v[2] for v in face}) |
| 220 | + assert len(z_coords) == 2 |
| 221 | + assert z_coords[0] == 0.0 # bottom |
| 222 | + assert z_coords[1] == 10.0 # top |
| 223 | + |
| 224 | + # Check x-coordinate is at the shared boundary (x=1.0) |
| 225 | + x_coords = {v[0] for v in face} |
| 226 | + assert 1.0 in x_coords |
| 227 | + |
| 228 | + |
| 229 | +def test_get_shared_face_3d_structured_vertical(): |
| 230 | + """Test get_shared_face_3d for vertical barrier in structured grid. |
| 231 | +
|
| 232 | + Tests different layers, same horizontal position. |
| 233 | + """ |
| 234 | + from flopy.discretization import StructuredGrid |
| 235 | + |
| 236 | + # Create a simple 2x2x2 structured grid (2 layers) |
| 237 | + nlay, nrow, ncol = 2, 2, 2 |
| 238 | + delr = np.array([1.0, 1.0]) |
| 239 | + delc = np.array([1.0, 1.0]) |
| 240 | + top = np.array([[10.0, 10.0], [10.0, 10.0]]) |
| 241 | + botm = np.array([[[5.0, 5.0], [5.0, 5.0]], [[0.0, 0.0], [0.0, 0.0]]]) |
| 242 | + |
| 243 | + grid = StructuredGrid(delc=delc, delr=delr, top=top, botm=botm) |
| 244 | + |
| 245 | + # Test vertical barrier between cells (0, 0, 0) and (1, 0, 0) |
| 246 | + # These are vertically adjacent |
| 247 | + cellid1 = (0, 0, 0) |
| 248 | + cellid2 = (1, 0, 0) |
| 249 | + |
| 250 | + face = get_shared_face_3d(grid, cellid1, cellid2) |
| 251 | + |
| 252 | + assert face is not None |
| 253 | + assert len(face) == 2 # Horizontal face should have 2 vertices (the edge) |
| 254 | + |
| 255 | + # Check that face is horizontal (all z-coordinates the same at interface) |
| 256 | + z_coords = {v[2] for v in face} |
| 257 | + assert len(z_coords) == 1 |
| 258 | + assert next(iter(z_coords)) == 5.0 # Interface between layers |
| 259 | + |
| 260 | + |
| 261 | +def test_get_shared_face_3d_vertex(): |
| 262 | + """Test get_shared_face_3d for vertex grid.""" |
| 263 | + from flopy.discretization import VertexGrid |
| 264 | + |
| 265 | + # Create a simple 2-cell vertex grid |
| 266 | + nlay = 2 |
| 267 | + ncpl = 2 |
| 268 | + |
| 269 | + # Two square cells side by side |
| 270 | + vertices = [ |
| 271 | + [0, 0.0, 0.0], |
| 272 | + [1, 1.0, 0.0], |
| 273 | + [2, 2.0, 0.0], |
| 274 | + [3, 0.0, 1.0], |
| 275 | + [4, 1.0, 1.0], |
| 276 | + [5, 2.0, 1.0], |
| 277 | + ] |
| 278 | + |
| 279 | + cell2d = [ |
| 280 | + [0, 0.5, 0.5, 4, 0, 1, 4, 3], |
| 281 | + [1, 1.5, 0.5, 4, 1, 2, 5, 4], |
| 282 | + ] |
| 283 | + |
| 284 | + top = np.array([10.0, 10.0]) |
| 285 | + botm = np.array([[5.0, 5.0], [0.0, 0.0]]) |
| 286 | + |
| 287 | + grid = VertexGrid(vertices=vertices, cell2d=cell2d, top=top, botm=botm, nlay=nlay) |
| 288 | + |
| 289 | + # Test horizontal barrier between cells (0, 0) and (0, 1) in same layer |
| 290 | + cellid1 = (0, 0) |
| 291 | + cellid2 = (0, 1) |
| 292 | + |
| 293 | + face = get_shared_face_3d(grid, cellid1, cellid2) |
| 294 | + |
| 295 | + assert face is not None |
| 296 | + assert len(face) == 4 # Vertical face |
| 297 | + |
| 298 | + # Test vertical barrier between cells (0, 0) and (1, 0) in different layers |
| 299 | + cellid1 = (0, 0) |
| 300 | + cellid2 = (1, 0) |
| 301 | + |
| 302 | + face = get_shared_face_3d(grid, cellid1, cellid2) |
| 303 | + |
| 304 | + assert face is not None |
| 305 | + assert len(face) == 2 # Horizontal face |
| 306 | + |
| 307 | + # Check all z-coordinates are the same (interface elevation) |
| 308 | + z_coords = {v[2] for v in face} |
| 309 | + assert len(z_coords) == 1 |
| 310 | + assert next(iter(z_coords)) == 5.0 |
| 311 | + |
| 312 | + |
| 313 | +def test_get_shared_face_3d_unstructured(): |
| 314 | + """Test get_shared_face_3d for unstructured grid with explicit 3D vertices.""" |
| 315 | + from flopy.discretization import UnstructuredGrid |
| 316 | + |
| 317 | + # Create a simple 2-cell unstructured grid with 3D vertices |
| 318 | + # Two hexahedral cells stacked vertically |
| 319 | + vertices = [ |
| 320 | + # Bottom layer vertices (z=0) |
| 321 | + [0, 0.0, 0.0, 0.0], |
| 322 | + [1, 1.0, 0.0, 0.0], |
| 323 | + [2, 1.0, 1.0, 0.0], |
| 324 | + [3, 0.0, 1.0, 0.0], |
| 325 | + # Middle layer vertices (z=5) |
| 326 | + [4, 0.0, 0.0, 5.0], |
| 327 | + [5, 1.0, 0.0, 5.0], |
| 328 | + [6, 1.0, 1.0, 5.0], |
| 329 | + [7, 0.0, 1.0, 5.0], |
| 330 | + # Top layer vertices (z=10) |
| 331 | + [8, 0.0, 0.0, 10.0], |
| 332 | + [9, 1.0, 0.0, 10.0], |
| 333 | + [10, 1.0, 1.0, 10.0], |
| 334 | + [11, 0.0, 1.0, 10.0], |
| 335 | + ] |
| 336 | + |
| 337 | + iverts = [ |
| 338 | + [0, 1, 2, 3, 4, 5, 6, 7], # Bottom cell |
| 339 | + [4, 5, 6, 7, 8, 9, 10, 11], # Top cell |
| 340 | + ] |
| 341 | + |
| 342 | + xc = np.array([0.5, 0.5]) |
| 343 | + yc = np.array([0.5, 0.5]) |
| 344 | + top = np.array([10.0, 10.0]) |
| 345 | + botm = np.array([0.0, 5.0]) |
| 346 | + |
| 347 | + grid = UnstructuredGrid( |
| 348 | + vertices=vertices, |
| 349 | + iverts=iverts, |
| 350 | + xcenters=xc, |
| 351 | + ycenters=yc, |
| 352 | + top=top, |
| 353 | + botm=botm, |
| 354 | + ncpl=[2], |
| 355 | + ) |
| 356 | + |
| 357 | + # Test shared face between two vertically stacked cells |
| 358 | + cellid1 = (0,) |
| 359 | + cellid2 = (1,) |
| 360 | + |
| 361 | + face = get_shared_face_3d(grid, cellid1, cellid2) |
| 362 | + |
| 363 | + assert face is not None |
| 364 | + assert len(face) == 4 # Should have 4 shared vertices at the interface |
| 365 | + |
| 366 | + # Check all shared vertices are at z=5.0 (the interface) |
| 367 | + z_coords = {v[2] for v in face} |
| 368 | + assert len(z_coords) == 1 |
| 369 | + assert next(iter(z_coords)) == 5.0 |
| 370 | + |
| 371 | + |
| 372 | +def test_get_shared_face_3d_error_cases(): |
| 373 | + """Test error handling in get_shared_face_3d.""" |
| 374 | + from flopy.discretization import StructuredGrid |
| 375 | + |
| 376 | + nlay, nrow, ncol = 1, 2, 2 |
| 377 | + delr = np.array([1.0, 1.0]) |
| 378 | + delc = np.array([1.0, 1.0]) |
| 379 | + top = np.array([[10.0, 10.0], [10.0, 10.0]]) |
| 380 | + botm = np.array([[[0.0, 0.0], [0.0, 0.0]]]) |
| 381 | + |
| 382 | + grid = StructuredGrid(delc=delc, delr=delr, top=top, botm=botm) |
| 383 | + |
| 384 | + # Test with same cellid |
| 385 | + with pytest.raises(ValueError, match="cellid1 and cellid2 must be different"): |
| 386 | + get_shared_face_3d(grid, (0, 0, 0), (0, 0, 0)) |
| 387 | + |
| 388 | + # Test with non-adjacent cells (should return None) |
| 389 | + cellid1 = (0, 0, 0) |
| 390 | + cellid2 = (0, 1, 1) # Diagonally opposite, not adjacent |
| 391 | + |
| 392 | + face = get_shared_face_3d(grid, cellid1, cellid2) |
| 393 | + assert face is None |
0 commit comments