# autogenerated file, do not modify

from os import PathLike, curdir
from typing import Union

from flopy.mf6.data.mfdatautil import ArrayTemplateGenerator, ListTemplateGenerator
from flopy.mf6.mfpackage import MFChildPackages, MFPackage


class ModflowGwfdisu(MFPackage):
    """
    ModflowGwfdisu defines a DISU package.

    Parameters
    ----------
    model
        Model that this package is a part of. Package is automatically
        added to model when it is initialized.
    loading_package : bool, default False
        Do not set this parameter. It is intended for debugging and internal
        processing purposes only.
    length_units : string
        is the length units used for this model.  values can be 'feet', 'meters', or
        'centimeters'.  if not specified, the default is 'unknown'.
    nogrb : keyword
        keyword to deactivate writing of the binary grid file.
    grb_filerecord : (grb6_filename)
        * grb6_filename : string
                defines a binary grid output file. If this option is not provided, the output
                file will have the same name as the discretization input file, plus extension
                '.grb'.

    xorigin : double precision
        x-position of the origin used for model grid vertices.  this value should be
        provided in a real-world coordinate system.  a default value of zero is
        assigned if not specified.  the value for xorigin does not affect the model
        simulation, but it is written to the binary grid file so that postprocessors
        can locate the grid in space.
    yorigin : double precision
        y-position of the origin used for model grid vertices.  this value should be
        provided in a real-world coordinate system.  if not specified, then a default
        value equal to zero is used.  the value for yorigin does not affect the model
        simulation, but it is written to the binary grid file so that postprocessors
        can locate the grid in space.
    angrot : double precision
        counter-clockwise rotation angle (in degrees) of the model grid coordinate
        system relative to a real-world coordinate system.  if not specified, then a
        default value of 0.0 is assigned.  the value for angrot does not affect the
        model simulation, but it is written to the binary grid file so that
        postprocessors can locate the grid in space.
    vertical_offset_tolerance : double precision
        checks are performed to ensure that the top of a cell is not higher than the
        bottom of an overlying cell.  this option can be used to specify the tolerance
        that is used for checking.  if top of a cell is above the bottom of an
        overlying cell by a value less than this tolerance, then the program will not
        terminate with an error.  the default value is zero.  this option should
        generally not be used.
    export_array_ascii : keyword
        keyword that specifies input griddata arrays should be written to layered ascii
        output files.
    nodes : integer
        is the number of cells in the model grid.
    nja : integer
        is the sum of the number of connections and nodes.  when calculating the total
        number of connections, the connection between cell n and cell m is considered
        to be different from the connection between cell m and cell n.  thus, nja is
        equal to the total number of connections, including n to m and m to n, and the
        total number of cells.
    nvert : integer
        is the total number of (x, y) vertex pairs used to define the plan-view shape
        of each cell in the model grid.  if nvert is not specified or is specified as
        zero, then the vertices and cell2d blocks below are not read.  nvert and the
        accompanying vertices and cell2d blocks should be specified for most
        simulations.  if the xt3d or save_specific_discharge options are specified in
        the npf package, then this information is required.
    top : [double precision]
        is the top elevation for each cell in the model grid.
    bot : [double precision]
        is the bottom elevation for each cell.
    area : [double precision]
        is the cell surface area (in plan view).
    idomain : [integer]
        is an optional array that characterizes the existence status of a cell.  if the
        idomain array is not specified, then all model cells exist within the solution.
        if the idomain value for a cell is 0, the cell does not exist in the
        simulation.  input and output values will be read and written for the cell, but
        internal to the program, the cell is excluded from the solution.  if the
        idomain value for a cell is 1 or greater, the cell exists in the simulation.
        idomain values of -1 cannot be specified for the disu package.
    iac : [integer]
        is the number of connections (plus 1) for each cell.  the sum of all the
        entries in iac must be equal to nja.
    ja : [integer]
        is a list of cell number (n) followed by its connecting cell numbers (m) for
        each of the m cells connected to cell n. the number of values to provide for
        cell n is iac(n).  this list is sequentially provided for the first to the last
        cell. the first value in the list must be cell n itself, and the remaining
        cells must be listed in an increasing order (sorted from lowest number to
        highest).  note that the cell and its connections are only supplied for the gwf
        cells and their connections to the other gwf cells.  also note that the ja list
        input may be divided such that every node and its connectivity list can be on a
        separate line for ease in readability of the file. to further ease readability
        of the file, the node number of the cell whose connectivity is subsequently
        listed, may be expressed as a negative number, the sign of which is
        subsequently converted to positive by the code.
    ihc : [integer]
        is an index array indicating the direction between node n and all of its m
        connections.  if ihc = 0 then cell n and cell m are connected in the vertical
        direction.  cell n overlies cell m if the cell number for n is less than m;
        cell m overlies cell n if the cell number for m is less than n.  if ihc = 1
        then cell n and cell m are connected in the horizontal direction.  if ihc = 2
        then cell n and cell m are connected in the horizontal direction, and the
        connection is vertically staggered.  a vertically staggered connection is one
        in which a cell is horizontally connected to more than one cell in a horizontal
        connection.
    cl12 : [double precision]
        is the array containing connection lengths between the center of cell n and the
        shared face with each adjacent m cell.
    hwva : [double precision]
        is a symmetric array of size nja.  for horizontal connections, entries in hwva
        are the horizontal width perpendicular to flow.  for vertical connections,
        entries in hwva are the vertical area for flow.  thus, values in the hwva array
        contain dimensions of both length and area.  entries in the hwva array have a
        one-to-one correspondence with the connections specified in the ja array.
        likewise, there is a one-to-one correspondence between entries in the hwva
        array and entries in the ihc array, which specifies the connection type
        (horizontal or vertical).  entries in the hwva array must be symmetric; the
        program will terminate with an error if the value for hwva for an n to m
        connection does not equal the value for hwva for the corresponding n to m
        connection.
    angldegx : [double precision]
        is the angle (in degrees) between the horizontal x-axis and the outward normal
        to the face between a cell and its connecting cells. the angle varies between
        zero and 360.0 degrees, where zero degrees points in the positive x-axis
        direction, and 90 degrees points in the positive y-axis direction.  angldegx is
        only needed if horizontal anisotropy is specified in the npf package, if the
        xt3d option is used in the npf package, or if the save_specific_discharge
        option is specified in the npf package.  angldegx does not need to be specified
        if these conditions are not met.  angldegx is of size nja; values specified for
        vertical connections and for the diagonal position are not used.  note that
        angldegx is read in degrees, which is different from modflow-usg, which reads a
        similar variable (anglex) in radians.
    vertices : [(iv, xv, yv)]
        * iv : integer
                is the vertex number.  Records in the VERTICES block must be listed in
                consecutive order from 1 to NVERT.
        * xv : double precision
                is the x-coordinate for the vertex.
        * yv : double precision
                is the y-coordinate for the vertex.

    cell2d : [(icell2d, xc, yc, ncvert, icvert)]
        * icell2d : integer
                is the cell2d number.  Records in the CELL2D block must be listed in
                consecutive order from 1 to NODES.
        * xc : double precision
                is the x-coordinate for the cell center.
        * yc : double precision
                is the y-coordinate for the cell center.
        * ncvert : integer
                is the number of vertices required to define the cell.  There may be a
                different number of vertices for each cell.
        * icvert : [integer]
                is an array of integer values containing vertex numbers (in the VERTICES block)
                used to define the cell.  Vertices must be listed in clockwise order.


    filename : str or PathLike, optional
        Name or path of file where this package is stored.
    pname : str, optional
        Package name.
    **kwargs
        Extra keywords for :class:`flopy.mf6.mfpackage.MFPackage`.

    """

    grb_filerecord = ListTemplateGenerator(
        ("gwf6", "disu", "options", "grb_filerecord")
    )
    top = ArrayTemplateGenerator(("gwf6", "disu", "griddata", "top"))
    bot = ArrayTemplateGenerator(("gwf6", "disu", "griddata", "bot"))
    area = ArrayTemplateGenerator(("gwf6", "disu", "griddata", "area"))
    idomain = ArrayTemplateGenerator(("gwf6", "disu", "griddata", "idomain"))
    iac = ArrayTemplateGenerator(("gwf6", "disu", "connectiondata", "iac"))
    ja = ArrayTemplateGenerator(("gwf6", "disu", "connectiondata", "ja"))
    ihc = ArrayTemplateGenerator(("gwf6", "disu", "connectiondata", "ihc"))
    cl12 = ArrayTemplateGenerator(("gwf6", "disu", "connectiondata", "cl12"))
    hwva = ArrayTemplateGenerator(("gwf6", "disu", "connectiondata", "hwva"))
    angldegx = ArrayTemplateGenerator(("gwf6", "disu", "connectiondata", "angldegx"))
    vertices = ListTemplateGenerator(("gwf6", "disu", "vertices", "vertices"))
    cell2d = ListTemplateGenerator(("gwf6", "disu", "cell2d", "cell2d"))
    package_abbr = "gwfdisu"
    _package_type = "disu"
    dfn_file_name = "gwf-disu.dfn"
    dfn = [
        ["header"],
        [
            "block options",
            "name length_units",
            "type string",
            "reader urword",
            "optional true",
        ],
        [
            "block options",
            "name nogrb",
            "type keyword",
            "reader urword",
            "optional true",
        ],
        [
            "block options",
            "name grb_filerecord",
            "type record grb6 fileout grb6_filename",
            "reader urword",
            "tagged true",
            "optional true",
        ],
        [
            "block options",
            "name grb6",
            "type keyword",
            "in_record true",
            "reader urword",
            "tagged true",
            "optional false",
        ],
        [
            "block options",
            "name fileout",
            "type keyword",
            "in_record true",
            "reader urword",
            "tagged true",
            "optional false",
        ],
        [
            "block options",
            "name grb6_filename",
            "type string",
            "preserve_case true",
            "in_record true",
            "reader urword",
            "optional false",
            "tagged false",
        ],
        [
            "block options",
            "name xorigin",
            "type double precision",
            "reader urword",
            "optional true",
        ],
        [
            "block options",
            "name yorigin",
            "type double precision",
            "reader urword",
            "optional true",
        ],
        [
            "block options",
            "name angrot",
            "type double precision",
            "reader urword",
            "optional true",
        ],
        [
            "block options",
            "name vertical_offset_tolerance",
            "type double precision",
            "reader urword",
            "optional true",
            "default 0.0",
            "mf6internal voffsettol",
        ],
        [
            "block options",
            "name export_array_ascii",
            "type keyword",
            "reader urword",
            "optional true",
            "mf6internal export_ascii",
        ],
        [
            "block options",
            "name crs",
            "type string",
            "shape lenbigline",
            "preserve_case true",
            "reader urword",
            "optional true",
            "prerelease true",
        ],
        [
            "block dimensions",
            "name nodes",
            "type integer",
            "reader urword",
            "optional false",
        ],
        [
            "block dimensions",
            "name nja",
            "type integer",
            "reader urword",
            "optional false",
        ],
        [
            "block dimensions",
            "name nvert",
            "type integer",
            "reader urword",
            "optional true",
        ],
        [
            "block griddata",
            "name top",
            "type double precision",
            "shape (nodes)",
            "reader readarray",
        ],
        [
            "block griddata",
            "name bot",
            "type double precision",
            "shape (nodes)",
            "reader readarray",
        ],
        [
            "block griddata",
            "name area",
            "type double precision",
            "shape (nodes)",
            "reader readarray",
        ],
        [
            "block griddata",
            "name idomain",
            "type integer",
            "shape (nodes)",
            "reader readarray",
            "layered false",
            "optional true",
        ],
        [
            "block connectiondata",
            "name iac",
            "type integer",
            "shape (nodes)",
            "reader readarray",
        ],
        [
            "block connectiondata",
            "name ja",
            "type integer",
            "shape (nja)",
            "reader readarray",
            "numeric_index true",
            "jagged_array iac",
        ],
        [
            "block connectiondata",
            "name ihc",
            "type integer",
            "shape (nja)",
            "reader readarray",
            "jagged_array iac",
        ],
        [
            "block connectiondata",
            "name cl12",
            "type double precision",
            "shape (nja)",
            "reader readarray",
            "jagged_array iac",
        ],
        [
            "block connectiondata",
            "name hwva",
            "type double precision",
            "shape (nja)",
            "reader readarray",
            "jagged_array iac",
        ],
        [
            "block connectiondata",
            "name angldegx",
            "type double precision",
            "optional true",
            "shape (nja)",
            "reader readarray",
            "jagged_array iac",
        ],
        [
            "block vertices",
            "name vertices",
            "type recarray iv xv yv",
            "shape (nvert)",
            "reader urword",
            "optional true",
        ],
        [
            "block vertices",
            "name iv",
            "type integer",
            "in_record true",
            "tagged false",
            "reader urword",
            "optional false",
            "numeric_index true",
        ],
        [
            "block vertices",
            "name xv",
            "type double precision",
            "in_record true",
            "tagged false",
            "reader urword",
            "optional false",
        ],
        [
            "block vertices",
            "name yv",
            "type double precision",
            "in_record true",
            "tagged false",
            "reader urword",
            "optional false",
        ],
        [
            "block cell2d",
            "name cell2d",
            "type recarray icell2d xc yc ncvert icvert",
            "shape (nodes)",
            "reader urword",
            "optional true",
        ],
        [
            "block cell2d",
            "name icell2d",
            "type integer",
            "in_record true",
            "tagged false",
            "reader urword",
            "optional false",
            "numeric_index true",
        ],
        [
            "block cell2d",
            "name xc",
            "type double precision",
            "in_record true",
            "tagged false",
            "reader urword",
            "optional false",
        ],
        [
            "block cell2d",
            "name yc",
            "type double precision",
            "in_record true",
            "tagged false",
            "reader urword",
            "optional false",
        ],
        [
            "block cell2d",
            "name ncvert",
            "type integer",
            "in_record true",
            "tagged false",
            "reader urword",
            "optional false",
        ],
        [
            "block cell2d",
            "name icvert",
            "type integer",
            "shape (ncvert)",
            "in_record true",
            "tagged false",
            "reader urword",
            "optional false",
            "numeric_index true",
        ],
    ]

    def __init__(
        self,
        model,
        loading_package=False,
        length_units=None,
        nogrb=None,
        grb_filerecord=None,
        xorigin=None,
        yorigin=None,
        angrot=None,
        vertical_offset_tolerance=0.0,
        export_array_ascii=None,
        nodes=None,
        nja=None,
        nvert=None,
        top=None,
        bot=None,
        area=None,
        idomain=None,
        iac=None,
        ja=None,
        ihc=None,
        cl12=None,
        hwva=None,
        angldegx=None,
        vertices=None,
        cell2d=None,
        filename=None,
        pname=None,
        **kwargs,
    ):
        """Initialize ModflowGwfdisu."""
        super().__init__(
            parent=model,
            package_type="disu",
            filename=filename,
            pname=pname,
            loading_package=loading_package,
            **kwargs,
        )

        self.length_units = self.build_mfdata("length_units", length_units)
        self.nogrb = self.build_mfdata("nogrb", nogrb)
        self.grb_filerecord = self.build_mfdata("grb_filerecord", grb_filerecord)
        self.xorigin = self.build_mfdata("xorigin", xorigin)
        self.yorigin = self.build_mfdata("yorigin", yorigin)
        self.angrot = self.build_mfdata("angrot", angrot)
        self.vertical_offset_tolerance = self.build_mfdata(
            "vertical_offset_tolerance", vertical_offset_tolerance
        )
        self.export_array_ascii = self.build_mfdata(
            "export_array_ascii", export_array_ascii
        )
        self.nodes = self.build_mfdata("nodes", nodes)
        self.nja = self.build_mfdata("nja", nja)
        self.nvert = self.build_mfdata("nvert", nvert)
        self.top = self.build_mfdata("top", top)
        self.bot = self.build_mfdata("bot", bot)
        self.area = self.build_mfdata("area", area)
        self.idomain = self.build_mfdata("idomain", idomain)
        self.iac = self.build_mfdata("iac", iac)
        self.ja = self.build_mfdata("ja", ja)
        self.ihc = self.build_mfdata("ihc", ihc)
        self.cl12 = self.build_mfdata("cl12", cl12)
        self.hwva = self.build_mfdata("hwva", hwva)
        self.angldegx = self.build_mfdata("angldegx", angldegx)
        self.vertices = self.build_mfdata("vertices", vertices)
        self.cell2d = self.build_mfdata("cell2d", cell2d)

        self._init_complete = True
