# 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 ModflowGwfgnc(MFPackage):
    """
    ModflowGwfgnc defines a GNC package.

    Parameters
    ----------
    parent_model_or_package
        Parent_model_or_package that this package is a part of. Package is automatically
        added to parent_model_or_package when it is initialized.
    loading_package : bool, default False
        Do not set this parameter. It is intended for debugging and internal
        processing purposes only.
    print_input : keyword
        keyword to indicate that the list of gnc information will be written to the
        listing file immediately after it is read.
    print_flows : keyword
        keyword to indicate that the list of gnc flow rates will be printed to the
        listing file for every stress period time step in which 'budget print' is
        specified in output control.  if there is no output control option and
        'print_flows' is specified, then flow rates are printed for the last time step
        of each stress period.
    explicit : keyword
        keyword to indicate that the ghost node correction is applied in an explicit
        manner on the right-hand side of the matrix.  the explicit approach will likely
        require additional outer iterations.  if the keyword is not specified, then the
        correction will be applied in an implicit manner on the left-hand side.  the
        implicit approach will likely converge better, but may require additional
        memory.  if the explicit keyword is not specified, then the bicgstab linear
        acceleration option should be specified within the linear block of the sparse
        matrix solver.
    numgnc : integer
        is the number of gnc entries.
    numalphaj : integer
        is the number of contributing factors.
    gncdata : [(cellidn, cellidm, cellidsj, alphasj)]
        * cellidn : integer
                is the cellid of the cell, :math:`n`, in which the ghost node is located. For a
                structured grid that uses the DIS input file, CELLIDN is the layer, row, and
                column numbers of the cell.   For a grid that uses the DISV input file, CELLIDN
                is the layer number and CELL2D number for the two cells.  If the model uses the
                unstructured discretization (DISU) input file, then CELLIDN is the node number
                for the cell.
        * cellidm : integer
                is the cellid of the connecting cell, :math:`m`, to which flow occurs from the
                ghost node. For a structured grid that uses the DIS input file, CELLIDM is the
                layer, row, and column numbers of the cell.   For a grid that uses the DISV
                input file, CELLIDM is the layer number and CELL2D number for the two cells.
                If the model uses the unstructured discretization (DISU) input file, then
                CELLIDM is the node number for the cell.
        * cellidsj : [integer]
                is the array of CELLIDS for the contributing j cells, which contribute to the
                interpolated head value at the ghost node. This item contains one CELLID for
                each of the contributing cells of the ghost node. Note that if the number of
                actual contributing cells needed by the user is less than NUMALPHAJ for any
                ghost node, then a dummy CELLID of zero(s) should be inserted with an
                associated contributing factor of zero. For a structured grid that uses the DIS
                input file, CELLID is the layer, row, and column numbers of the cell.   For a
                grid that uses the DISV input file, CELLID is the layer number and cell2d
                number for the two cells.  If the model uses the unstructured discretization
                (DISU) input file, then CELLID is the node number for the cell.
        * alphasj : [double precision]
                is the contributing factors for each contributing node in CELLIDSJ. Note that
                if the number of actual contributing cells is less than NUMALPHAJ for any ghost
                node, then dummy CELLIDS should be inserted with an associated contributing
                factor of zero.  The sum of ALPHASJ should be less than one.  This is because
                one minus the sum of ALPHASJ is equal to the alpha term (alpha n in equation
                4-61 of the GWF Model report) that is multiplied by the head in cell n.


    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`.

    """

    gncdata = ListTemplateGenerator(("gwf6", "gnc", "gncdata", "gncdata"))
    package_abbr = "gwfgnc"
    _package_type = "gnc"
    dfn_file_name = "gwf-gnc.dfn"
    dfn = [
        ["header"],
        [
            "block options",
            "name print_input",
            "type keyword",
            "reader urword",
            "optional true",
        ],
        [
            "block options",
            "name print_flows",
            "type keyword",
            "reader urword",
            "optional true",
        ],
        [
            "block options",
            "name explicit",
            "type keyword",
            "tagged true",
            "reader urword",
            "optional true",
        ],
        [
            "block dimensions",
            "name numgnc",
            "type integer",
            "reader urword",
            "optional false",
        ],
        [
            "block dimensions",
            "name numalphaj",
            "type integer",
            "reader urword",
            "optional false",
        ],
        [
            "block gncdata",
            "name gncdata",
            "type recarray cellidn cellidm cellidsj alphasj",
            "shape (maxbound)",
            "reader urword",
        ],
        [
            "block gncdata",
            "name cellidn",
            "type integer",
            "shape",
            "tagged false",
            "in_record true",
            "reader urword",
            "numeric_index true",
        ],
        [
            "block gncdata",
            "name cellidm",
            "type integer",
            "shape",
            "tagged false",
            "in_record true",
            "reader urword",
            "numeric_index true",
        ],
        [
            "block gncdata",
            "name cellidsj",
            "type integer",
            "shape (numalphaj)",
            "tagged false",
            "in_record true",
            "reader urword",
            "numeric_index true",
        ],
        [
            "block gncdata",
            "name alphasj",
            "type double precision",
            "shape (numalphaj)",
            "tagged false",
            "in_record true",
            "reader urword",
        ],
    ]

    def __init__(
        self,
        parent_model_or_package,
        loading_package=False,
        print_input=None,
        print_flows=None,
        explicit=None,
        numgnc=None,
        numalphaj=None,
        gncdata=None,
        filename=None,
        pname=None,
        **kwargs,
    ):
        """Initialize ModflowGwfgnc."""
        super().__init__(
            parent=parent_model_or_package,
            package_type="gnc",
            filename=filename,
            pname=pname,
            loading_package=loading_package,
            **kwargs,
        )

        self.print_input = self.build_mfdata("print_input", print_input)
        self.print_flows = self.build_mfdata("print_flows", print_flows)
        self.explicit = self.build_mfdata("explicit", explicit)
        self.numgnc = self.build_mfdata("numgnc", numgnc)
        self.numalphaj = self.build_mfdata("numalphaj", numalphaj)
        self.gncdata = self.build_mfdata("gncdata", gncdata)

        self._init_complete = True


class GwfgncPackages(MFChildPackages):
    """
    GwfgncPackages is a container class for the ModflowGwfgnc class.
    """

    package_abbr = "gwfgncpackages"

    def initialize(
        self,
        print_input=None,
        print_flows=None,
        explicit=None,
        numgnc=None,
        numalphaj=None,
        gncdata=None,
        filename=None,
        pname=None,
    ):
        """
        Initialize a new ModflowGwfgnc package, removing any sibling
        child packages attached to the same parent package.

        See :class:`ModflowGwfgnc` for parameter definitions.
        """
        new_package = ModflowGwfgnc(
            self._cpparent,
            print_input=print_input,
            print_flows=print_flows,
            explicit=explicit,
            numgnc=numgnc,
            numalphaj=numalphaj,
            gncdata=gncdata,
            filename=filename,
            pname=pname,
            child_builder_call=True,
        )
        self.init_package(new_package, filename)

    def append_package(
        self,
        print_input=None,
        print_flows=None,
        explicit=None,
        numgnc=None,
        numalphaj=None,
        gncdata=None,
        filename=None,
        pname=None,
    ):
        """
        Add a new ModflowGwfgnc package to the container.

        See :class:`ModflowGwfgnc` for parameter definitions.
        """
        new_package = ModflowGwfgnc(
            self._cpparent,
            print_input=print_input,
            print_flows=print_flows,
            explicit=explicit,
            numgnc=numgnc,
            numalphaj=numalphaj,
            gncdata=gncdata,
            filename=filename,
            pname=pname,
            child_builder_call=True,
        )
        self._append_package(new_package, filename)
