|
| 1 | +from pathlib import Path |
| 2 | +from typing import ClassVar, Optional |
| 3 | + |
| 4 | +import numpy as np |
| 5 | +from numpy.typing import NDArray |
| 6 | +from xattree import dict_to_array_converter |
| 7 | + |
| 8 | +from flopy4.mf6.constants import FILL_DNODATA |
| 9 | +from flopy4.mf6.package import Package |
| 10 | +from flopy4.mf6.spec import array, field |
| 11 | + |
| 12 | + |
| 13 | +class Drn(Package): |
| 14 | + multi_package: ClassVar[bool] = True |
| 15 | + |
| 16 | + auxiliary: Optional[list[str]] = array(block="options", default=None) |
| 17 | + auxmultname: Optional[str] = field(block="options", default=None) |
| 18 | + auxdepthname: Optional[str] = field(block="options", default=None) |
| 19 | + boundnames: bool = field(block="options", default=False) |
| 20 | + print_input: bool = field(block="options", default=False) |
| 21 | + print_flows: bool = field(block="options", default=False) |
| 22 | + save_flows: bool = field(block="options", default=False) |
| 23 | + ts_filerecord: Optional[Path] = field(block="options", default=None) |
| 24 | + obs_filerecord: Optional[Path] = field(block="options", default=None) |
| 25 | + mover: bool = field(block="options", default=False) |
| 26 | + dev_cubic_scaling: bool = field(default=False, block="options") |
| 27 | + maxbound: Optional[int] = field(block="dimensions", default=None, init=False) |
| 28 | + elev: Optional[NDArray[np.float64]] = array( |
| 29 | + block="period", |
| 30 | + dims=("nper", "nnodes"), |
| 31 | + default=None, |
| 32 | + converter=dict_to_array_converter, |
| 33 | + reader="urword", |
| 34 | + ) |
| 35 | + cond: Optional[NDArray[np.float64]] = array( |
| 36 | + block="period", |
| 37 | + dims=("nper", "nnodes"), |
| 38 | + default=None, |
| 39 | + converter=dict_to_array_converter, |
| 40 | + reader="urword", |
| 41 | + ) |
| 42 | + aux: Optional[NDArray[np.float64]] = array( |
| 43 | + block="period", |
| 44 | + dims=( |
| 45 | + "nper", |
| 46 | + "nnodes", |
| 47 | + ), |
| 48 | + default=None, |
| 49 | + converter=dict_to_array_converter, |
| 50 | + reader="urword", |
| 51 | + ) |
| 52 | + boundname: Optional[NDArray[np.str_]] = array( |
| 53 | + block="period", |
| 54 | + dims=( |
| 55 | + "nper", |
| 56 | + "nnodes", |
| 57 | + ), |
| 58 | + default=None, |
| 59 | + converter=dict_to_array_converter, |
| 60 | + reader="urword", |
| 61 | + ) |
| 62 | + |
| 63 | + def __attrs_post_init__(self): |
| 64 | + # TODO set up on_setattr hooks for period block |
| 65 | + # arrays to update maxbound? for now do it here |
| 66 | + # in post init. but this only works when values |
| 67 | + # are set in the initializer, not when they are |
| 68 | + # set later. |
| 69 | + if self.head is None: |
| 70 | + maxhead = 0 |
| 71 | + else: |
| 72 | + head = self.head if self.head.data.shape == self.head.shape else self.head.todense() |
| 73 | + maxhead = len(np.where(head != FILL_DNODATA)) |
| 74 | + if self.cond is None: |
| 75 | + maxcond = 0 |
| 76 | + else: |
| 77 | + cond = self.cond if self.cond.data.shape == self.cond.shape else self.cond.todense() |
| 78 | + maxcond = len(np.where(cond != FILL_DNODATA)) |
| 79 | + if self.aux is None: |
| 80 | + maxaux = 0 |
| 81 | + else: |
| 82 | + aux = self.aux if self.aux.data.shape == self.aux.shape else self.aux.todense() |
| 83 | + maxaux = len(np.where(aux != FILL_DNODATA)) |
| 84 | + if self.boundname is None: |
| 85 | + maxboundname = 0 |
| 86 | + else: |
| 87 | + boundname = ( |
| 88 | + self.boundname |
| 89 | + if self.boundname.data.shape == self.boundname.shape |
| 90 | + else self.boundname.todense() |
| 91 | + ) |
| 92 | + maxboundname = len(np.where(boundname != "")) |
| 93 | + |
| 94 | + self.maxbound = max(maxhead, maxcond, maxaux, maxboundname) |
0 commit comments