66from numpy .typing import NDArray
77from xattree import xattree
88
9- from flopy4 .mf6 .constants import FILL_DNODATA
9+ from flopy4 .mf6 .attr_hooks import update_maxbound
1010from flopy4 .mf6 .converters import dict_to_array
1111from flopy4 .mf6 .package import Package
1212from flopy4 .mf6 .spec import array , field
1313
1414
15- def _update_maxbound (instance , attribute , new_value ):
16- """Update maxbound when period block arrays change."""
17- if hasattr (instance , "_updating_maxbound" ):
18- return new_value
19-
20- # Calculate maxbound from all relevant arrays
21- maxbound_values = []
22-
23- # Check elev array
24- elev_val = (
25- new_value if attribute and attribute .name == "elev" else getattr (instance , "elev" , None )
26- )
27- if elev_val is not None :
28- elev = elev_val if elev_val .data .shape == elev_val .shape else elev_val .todense ()
29- maxbound_values .append (len (np .where (elev != FILL_DNODATA )[0 ]))
30-
31- # Check cond array
32- cond_val = (
33- new_value if attribute and attribute .name == "cond" else getattr (instance , "cond" , None )
34- )
35- if cond_val is not None :
36- cond = cond_val if cond_val .data .shape == cond_val .shape else cond_val .todense ()
37- maxbound_values .append (len (np .where (cond != FILL_DNODATA )[0 ]))
38-
39- # Check aux array
40- aux_val = new_value if attribute and attribute .name == "aux" else getattr (instance , "aux" , None )
41- if aux_val is not None :
42- aux = aux_val if aux_val .data .shape == aux_val .shape else aux_val .todense ()
43- maxbound_values .append (len (np .where (aux != FILL_DNODATA )[0 ]))
44-
45- # Check boundname array
46- boundname_val = (
47- new_value
48- if attribute and attribute .name == "boundname"
49- else getattr (instance , "boundname" , None )
50- )
51- if boundname_val is not None :
52- boundname = (
53- boundname_val
54- if boundname_val .data .shape == boundname_val .shape
55- else boundname_val .todense ()
56- )
57- maxbound_values .append (len (np .where (boundname != "" )[0 ]))
58-
59- # Update maxbound if we have values
60- if maxbound_values :
61- instance ._updating_maxbound = True
62- try :
63- instance .maxbound = max (maxbound_values )
64- finally :
65- delattr (instance , "_updating_maxbound" )
66-
67- return new_value
68-
69-
7015@xattree
7116class Drn (Package ):
7217 multi_package : ClassVar [bool ] = True
@@ -88,15 +33,15 @@ class Drn(Package):
8833 default = None ,
8934 converter = Converter (dict_to_array , takes_self = True , takes_field = True ),
9035 reader = "urword" ,
91- on_setattr = _update_maxbound ,
36+ on_setattr = update_maxbound ,
9237 )
9338 cond : Optional [NDArray [np .float64 ]] = array (
9439 block = "period" ,
9540 dims = ("nper" , "nnodes" ),
9641 default = None ,
9742 converter = Converter (dict_to_array , takes_self = True , takes_field = True ),
9843 reader = "urword" ,
99- on_setattr = _update_maxbound ,
44+ on_setattr = update_maxbound ,
10045 )
10146 aux : Optional [NDArray [np .float64 ]] = array (
10247 block = "period" ,
@@ -107,7 +52,7 @@ class Drn(Package):
10752 default = None ,
10853 converter = Converter (dict_to_array , takes_self = True , takes_field = True ),
10954 reader = "urword" ,
110- on_setattr = _update_maxbound ,
55+ on_setattr = update_maxbound ,
11156 )
11257 boundname : Optional [NDArray [np .str_ ]] = array (
11358 block = "period" ,
@@ -118,15 +63,14 @@ class Drn(Package):
11863 default = None ,
11964 converter = Converter (dict_to_array , takes_self = True , takes_field = True ),
12065 reader = "urword" ,
121- on_setattr = _update_maxbound ,
66+ on_setattr = update_maxbound ,
12267 )
12368
12469 def __attrs_post_init__ (self ):
125- # Trigger maxbound calculation on initialization
12670 if (
12771 self .elev is not None
12872 or self .cond is not None
12973 or self .aux is not None
13074 or self .boundname is not None
13175 ):
132- _update_maxbound (self , None , None )
76+ update_maxbound (self , None , None )
0 commit comments