|
1 | 1 | from pprint import pprint |
2 | 2 |
|
| 3 | +import numpy as np |
3 | 4 | import pytest |
4 | 5 |
|
5 | 6 | from flopy4.mf6.codec import dumps, loads |
6 | 7 | from flopy4.mf6.converter import COMPONENT_CONVERTER |
7 | 8 |
|
| 9 | +DNODATA = 3.0e30 |
| 10 | + |
8 | 11 |
|
9 | 12 | def test_loads_dis_generic_simple(): |
10 | 13 | mf6_input = """ |
@@ -322,6 +325,80 @@ def test_dumps_chd_2(): |
322 | 325 | pprint(loaded) |
323 | 326 |
|
324 | 327 |
|
| 328 | +def test_dumps_rch(): |
| 329 | + from flopy4.mf6.gwf import Dis, Gwf, Rch |
| 330 | + |
| 331 | + dis = Dis(nlay=1, nrow=20, ncol=30) |
| 332 | + gwf = Gwf(dis=dis) |
| 333 | + |
| 334 | + boundaries = {} |
| 335 | + for row in range(5, 15): |
| 336 | + boundaries[(0, row, 0)] = 100.0 |
| 337 | + for row in range(8, 12): |
| 338 | + boundaries[(0, row, 29)] = 95.0 |
| 339 | + for col in range(10, 20): |
| 340 | + boundaries[(0, 19, col)] = 98.0 |
| 341 | + |
| 342 | + rch = Rch( |
| 343 | + parent=gwf, recharge={0: boundaries}, print_input=True, save_flows=True, dims={"nper": 1} |
| 344 | + ) |
| 345 | + |
| 346 | + dumped = dumps(COMPONENT_CONVERTER.unstructure(rch)) |
| 347 | + print("RCH dump:") |
| 348 | + print(dumped) |
| 349 | + |
| 350 | + period_section = dumped.split("BEGIN PERIOD 1")[1].split("END PERIOD 1")[0].strip() |
| 351 | + lines = [line.strip() for line in period_section.split("\n") if line.strip()] |
| 352 | + |
| 353 | + assert len(lines) == 24 |
| 354 | + assert "100.0" in dumped # Left boundary |
| 355 | + assert "95.0" in dumped # Right boundary |
| 356 | + assert "98.0" in dumped # Bottom boundary |
| 357 | + assert "1e+30" not in dumped |
| 358 | + assert "1.0e+30" not in dumped |
| 359 | + |
| 360 | + loaded = loads(dumped) |
| 361 | + print("RCH load:") |
| 362 | + pprint(loaded) |
| 363 | + |
| 364 | + |
| 365 | +def test_dumps_rcha(): |
| 366 | + from flopy4.mf6.gwf import Dis, Gwf, Rcha |
| 367 | + |
| 368 | + dis = Dis(nlay=1, nrow=20, ncol=30) |
| 369 | + gwf = Gwf(dis=dis) |
| 370 | + |
| 371 | + boundaries = np.full((20, 30), DNODATA, dtype=float) |
| 372 | + for row in range(5, 15): |
| 373 | + boundaries[row, 0] = 100.0 |
| 374 | + for row in range(8, 12): |
| 375 | + boundaries[row, 29] = 95.0 |
| 376 | + for col in range(10, 20): |
| 377 | + boundaries[19, col] = 98.0 |
| 378 | + |
| 379 | + rch = Rcha( |
| 380 | + parent=gwf, recharge={0: boundaries}, print_input=True, save_flows=True, dims={"nper": 1} |
| 381 | + ) |
| 382 | + |
| 383 | + dumped = dumps(COMPONENT_CONVERTER.unstructure(rch)) |
| 384 | + print("RCH dump:") |
| 385 | + print(dumped) |
| 386 | + |
| 387 | + period_section = dumped.split("BEGIN PERIOD 1")[1].split("END PERIOD 1")[0].strip() |
| 388 | + lines = [line.strip() for line in period_section.split("\n") if line.strip()] |
| 389 | + |
| 390 | + assert len(lines) == 24 |
| 391 | + assert "100.0" in dumped # Left boundary |
| 392 | + assert "95.0" in dumped # Right boundary |
| 393 | + assert "98.0" in dumped # Bottom boundary |
| 394 | + assert "1e+30" not in dumped |
| 395 | + assert "1.0e+30" not in dumped |
| 396 | + |
| 397 | + loaded = loads(dumped) |
| 398 | + print("RCH load:") |
| 399 | + pprint(loaded) |
| 400 | + |
| 401 | + |
325 | 402 | def test_dumps_wel_with_aux(): |
326 | 403 | from flopy4.mf6.gwf import Dis, Gwf, Wel |
327 | 404 |
|
|
0 commit comments