|
| 1 | +from collections import namedtuple |
| 2 | + |
| 3 | + |
| 4 | +import pytest |
| 5 | +import numpy as np |
| 6 | + |
| 7 | +from itzi.providers.domain_data import DomainData |
| 8 | + |
| 9 | + |
| 10 | +Domain5by5Data = namedtuple( |
| 11 | + "Domain5by5Data", |
| 12 | + [ |
| 13 | + "domain_data", # DomainData instance |
| 14 | + "arr_dem_flat", # DEM with z=0 |
| 15 | + "arr_dem_high", # DEM with z=132 |
| 16 | + "arr_n", # Manning's n = 0.05 |
| 17 | + "arr_start_h", # Initial depth: 0.2 at center [2,2] |
| 18 | + "arr_start_wse", # Initial WSE: 132.2 at center [2,2] |
| 19 | + "arr_mask", # All False (no mask) |
| 20 | + "arr_bctype", # Boundary condition type for open boundaries |
| 21 | + "arr_rain", # Rainfall in m/s |
| 22 | + "arr_inf", # Infiltration in m/s |
| 23 | + "arr_loss", # Losses in m/s |
| 24 | + "arr_inflow", # Inflow in m/s |
| 25 | + ], |
| 26 | +) |
| 27 | + |
| 28 | + |
| 29 | +@pytest.fixture(scope="module") |
| 30 | +def domain_5by5() -> Domain5by5Data: |
| 31 | + """Create a 5x5 domain with all base arrays. |
| 32 | +
|
| 33 | + This fixture provides the foundational data for all 5x5 tests: |
| 34 | + - 5x5 grid at 10m resolution |
| 35 | + - Domain extends: north=50, south=0, east=50, west=0 |
| 36 | + - Total area: 2500 m² |
| 37 | + """ |
| 38 | + # Domain dimensions |
| 39 | + rows, cols = 5, 5 |
| 40 | + north, south, east, west = 50.0, 0.0, 50.0, 0.0 |
| 41 | + |
| 42 | + # Create DomainData |
| 43 | + domain_data = DomainData( |
| 44 | + north=north, south=south, east=east, west=west, rows=rows, cols=cols, crs_wkt="" |
| 45 | + ) |
| 46 | + |
| 47 | + # DEM arrays |
| 48 | + arr_dem_flat = np.zeros(domain_data.shape, dtype=np.float32) |
| 49 | + arr_dem_high = np.full(domain_data.shape, 132.0, dtype=np.float32) |
| 50 | + |
| 51 | + # Manning's n |
| 52 | + arr_n = np.full(domain_data.shape, 0.05, dtype=np.float32) |
| 53 | + |
| 54 | + # Initial water depth: 0.2m at center cell [2, 2], 0 elsewhere |
| 55 | + arr_start_h = np.zeros(domain_data.shape, dtype=np.float32) |
| 56 | + arr_start_h[2, 2] = 0.2 |
| 57 | + |
| 58 | + # Initial water surface elevation: 132.2m at center cell [2, 2] |
| 59 | + # (high DEM + 0.2m depth) |
| 60 | + arr_start_wse = np.zeros(domain_data.shape, dtype=np.float32) |
| 61 | + arr_start_wse[2, 2] = 132.2 |
| 62 | + |
| 63 | + # No mask - whole domain active |
| 64 | + arr_mask = np.full(domain_data.shape, False, dtype=np.bool_) |
| 65 | + |
| 66 | + # Boundary condition type: 2 (open) at all 16 edge cells |
| 67 | + arr_bctype = np.zeros(domain_data.shape, dtype=np.float32) |
| 68 | + # Top and bottom rows |
| 69 | + arr_bctype[0, :] = 2 |
| 70 | + arr_bctype[4, :] = 2 |
| 71 | + # Left and right columns (excluding corners already set) |
| 72 | + arr_bctype[:, 0] = 2 |
| 73 | + arr_bctype[:, 4] = 2 |
| 74 | + |
| 75 | + # Rate arrays in m/s |
| 76 | + # Rainfall: 10 mm/h = 10/(1000*3600) m/s |
| 77 | + arr_rain = np.full(domain_data.shape, 10.0 / (1000 * 3600), dtype=np.float32) |
| 78 | + # Infiltration: 2 mm/h = 2/(1000*3600) m/s |
| 79 | + arr_inf = np.full(domain_data.shape, 2.0 / (1000 * 3600), dtype=np.float32) |
| 80 | + # Losses: 1.5 mm/h = 1.5/(1000*3600) m/s |
| 81 | + arr_loss = np.full(domain_data.shape, 1.5 / (1000 * 3600), dtype=np.float32) |
| 82 | + # Inflow: 0.1 m/s (already in m/s) |
| 83 | + arr_inflow = np.full(domain_data.shape, 0.1, dtype=np.float32) |
| 84 | + |
| 85 | + return Domain5by5Data( |
| 86 | + domain_data=domain_data, |
| 87 | + arr_dem_flat=arr_dem_flat, |
| 88 | + arr_dem_high=arr_dem_high, |
| 89 | + arr_n=arr_n, |
| 90 | + arr_start_h=arr_start_h, |
| 91 | + arr_start_wse=arr_start_wse, |
| 92 | + arr_mask=arr_mask, |
| 93 | + arr_bctype=arr_bctype, |
| 94 | + arr_rain=arr_rain, |
| 95 | + arr_inf=arr_inf, |
| 96 | + arr_loss=arr_loss, |
| 97 | + arr_inflow=arr_inflow, |
| 98 | + ) |
0 commit comments