Skip to content

Commit 0daf920

Browse files
mjrenomjreno
authored andcommitted
add rcha baseline
1 parent 42291e3 commit 0daf920

File tree

3 files changed

+144
-1
lines changed

3 files changed

+144
-1
lines changed

flopy4/mf6/gwf/__init__.py

100644100755
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@
1313
from flopy4.mf6.gwf.ic import Ic
1414
from flopy4.mf6.gwf.npf import Npf
1515
from flopy4.mf6.gwf.oc import Oc
16+
from flopy4.mf6.gwf.rch import Rch
17+
from flopy4.mf6.gwf.rcha import Rcha
1618
from flopy4.mf6.gwf.wel import Wel
1719
from flopy4.mf6.model import Model
1820
from flopy4.mf6.spec import field, path
1921
from flopy4.mf6.utils import open_cbc, open_hds
2022
from flopy4.utils import to_path
2123

22-
__all__ = ["Gwf", "Chd", "Dis", "Drn", "Ic", "Npf", "Oc", "Wel"]
24+
__all__ = ["Gwf", "Chd", "Dis", "Drn", "Ic", "Npf", "Oc", "Rch", "Rcha", "Wel"]
2325

2426

2527
def convert_grid(value):
@@ -76,6 +78,8 @@ def budget(self):
7678
oc: Oc = field(block="packages")
7779
npf: Npf = field(block="packages")
7880
chd: list[Chd] = field(block="packages")
81+
rch: list[Rch] = field(block="packages")
82+
rcha: list[Rcha] = field(block="packages")
7983
wel: list[Wel] = field(block="packages")
8084
drn: list[Drn] = field(block="packages")
8185
output: Output = attrs.field(

flopy4/mf6/gwf/rcha.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
from pathlib import Path
2+
from typing import ClassVar, Optional
3+
4+
import numpy as np
5+
from attrs import Converter
6+
from numpy.typing import NDArray
7+
from xattree import xattree
8+
9+
from flopy4.mf6.converter import structure_array
10+
from flopy4.mf6.package import Package
11+
from flopy4.mf6.spec import array, field, path
12+
from flopy4.utils import to_path
13+
14+
15+
@xattree
16+
class Rcha(Package):
17+
multi_package: ClassVar[bool] = True
18+
fixed_cell: bool = field(block="options", default=False)
19+
auxiliary: Optional[list[str]] = array(block="options", default=None)
20+
auxmultname: Optional[str] = field(block="options", default=None)
21+
print_input: bool = field(block="options", default=False)
22+
print_flows: bool = field(block="options", default=False)
23+
save_flows: bool = field(block="options", default=False)
24+
ts_filerecord: Optional[Path] = path(
25+
block="options", default=None, converter=to_path, inout="filein"
26+
)
27+
obs_filerecord: Optional[Path] = path(
28+
block="options", default=None, converter=to_path, inout="fileout"
29+
)
30+
irch: Optional[NDArray[np.int64]] = array(
31+
block="period",
32+
dims=(
33+
"nper",
34+
# "ncpl",
35+
"nrow",
36+
"ncol",
37+
),
38+
default=1,
39+
converter=Converter(structure_array, takes_self=True, takes_field=True),
40+
)
41+
recharge: Optional[NDArray[np.float64]] = array(
42+
block="period",
43+
dims=(
44+
"nper",
45+
# "ncpl",
46+
"nrow",
47+
"ncol",
48+
),
49+
default=None,
50+
converter=Converter(structure_array, takes_self=True, takes_field=True),
51+
)
52+
aux: Optional[NDArray[np.float64]] = array(
53+
block="period",
54+
dims=(
55+
"nper",
56+
# "ncpl",
57+
"nrow",
58+
"ncol",
59+
),
60+
default=None,
61+
converter=Converter(structure_array, takes_self=True, takes_field=True),
62+
)

test/test_codec.py

100644100755
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
from pprint import pprint
22

3+
import numpy as np
34
import pytest
45

56
from flopy4.mf6.codec import dumps, loads
67
from flopy4.mf6.converter import COMPONENT_CONVERTER
78

9+
DNODATA = 3.0e30
10+
811

912
def test_loads_dis_generic_simple():
1013
mf6_input = """
@@ -322,6 +325,80 @@ def test_dumps_chd_2():
322325
pprint(loaded)
323326

324327

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+
325402
def test_dumps_wel_with_aux():
326403
from flopy4.mf6.gwf import Dis, Gwf, Wel
327404

0 commit comments

Comments
 (0)